Adaptivity and Modularity for Efficient Generalization Over Task Complexity