ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Meta-Learning and Few-Shot Adaptation in Foundation Models
Chapter 1: Foundations of Meta-Learning Revisited
The Meta-Learning Problem Formulation
Taxonomy of Meta-Learning Approaches
Challenges in Applying Meta-Learning to Foundation Models
Evaluation Protocols for Few-Shot Learning
Chapter 2: Advanced Gradient-Based Meta-Learning
Model-Agnostic Meta-Learning (MAML)
First-Order MAML (FOMAML) and Reptile
Implicit MAML (iMAML)
Addressing Stability and Gradient Variance
Scalability Considerations for Foundation Models
Hands-on Practical: Implementing FOMAML for Model Adaptation
Chapter 3: Advanced Metric-Based Meta-Learning
Prototypical Networks Revisited
Relation Networks for Few-Shot Learning
Matching Networks with Attention
Deep Metric Learning Techniques
Adapting Metric Learning for High-Dimensional Embeddings
Practice: Implementing Prototypical Networks with Foundation Model Embeddings
Chapter 4: Optimization Perspectives on Meta-Learning
Meta-Learning as Bilevel Optimization
Algorithms for Solving Bilevel Problems
Connections to Hyperparameter Optimization
Meta-Learning Initialization Strategies
Theoretical Convergence Analysis
Chapter 5: Few-Shot Adaptation Strategies for Foundation Models
Parameter-Efficient Fine-Tuning (PEFT) Overview
Adapter Modules for Foundation Models
Low-Rank Adaptation (LoRA)
Prompt Tuning and Prefix Tuning
Comparing PEFT and Meta-Learning Approaches
Hybrid Adaptation Strategies
Hands-on Practical: Adapting a Foundation Model using LoRA
Chapter 6: Scaling Meta-Learning Implementations
Computational Challenges of Meta-Gradients
Memory Optimization Techniques
Distributed Meta-Learning Strategies
Efficient Task Sampling and Batching
Approximation Methods for Scalability
Benchmarking Scalable Implementations
Chapter 7: Advanced Topics and Theoretical Considerations
Bayesian Meta-Learning Approaches
Continual Meta-Learning
Meta-Learning for Reinforcement Learning
Generalization Bounds in Meta-Learning
Information Theoretic Perspectives
Open Problems and Research Directions

Model-Agnostic Meta-Learning (MAML)

Model-Agnostic Meta-Learning (MAML) stands as a prominent gradient-based meta-learning algorithm. Its central premise is to find a set of initial model parameters θ\thetaθ that are highly amenable to rapid adaptation. Instead of learning parameters that perform well on average across tasks, MAML learns parameters that require only a few gradient updates on a small amount of data from a new task to achieve good performance on that specific task.

Mathematical Formulation

Let's formalize this. We have a distribution of tasks p(T)p(\mathcal{T})p(T). During meta-training, we sample a batch of tasks {Ti}i=1B\{\mathcal{T}_i\}_{i=1}^B{Ti​}i=1B​. Each task Ti\mathcal{T}_iTi​ is associated with a loss function LTi\mathcal{L}_{\mathcal{T}_i}LTi​​ and typically has a support set DTisuppD_{\mathcal{T}_i}^{supp}DTi​supp​ for adaptation and a query set DTiqueryD_{\mathcal{T}_i}^{query}DTi​query​ for evaluating the adapted parameters.

The core idea involves a two-step optimization process:

  1. Inner Loop (Task-Specific Adaptation): For each task Ti\mathcal{T}_iTi​, starting from the shared initial parameters θ\thetaθ, we perform one or more gradient descent steps using the task's support set DTisuppD_{\mathcal{T}_i}^{supp}DTi​supp​. For a single gradient step with learning rate α\alphaα:

    θi′=θ−α∇θLTi(θ,DTisupp)\theta'_i = \theta - \alpha \nabla_\theta \mathcal{L}_{\mathcal{T}_i}(\theta, D_{\mathcal{T}_i}^{supp})θi′​=θ−α∇θ​LTi​​(θ,DTi​supp​)

    These adapted parameters θi′\theta'_iθi′​ are specific to task Ti\mathcal{T}_iTi​.

  2. Outer Loop (Meta-Optimization): The goal is to update the initial parameters θ\thetaθ to minimize the expected loss across tasks after adaptation. The meta-objective function is the sum (or average) of the losses computed using the adapted parameters θi′\theta'_iθi′​ on their respective query sets DTiqueryD_{\mathcal{T}_i}^{query}DTi​query​:

    min⁡θ∑Ti∼p(T)LTi(θi′,DTiquery)\min_\theta \sum_{\mathcal{T}_i \sim p(\mathcal{T})} \mathcal{L}_{\mathcal{T}_i}(\theta'_i, D_{\mathcal{T}_i}^{query})θmin​Ti​∼p(T)∑​LTi​​(θi′​,DTi​query​)

    Substituting the expression for θi′\theta'_iθi′​ (from the inner loop), the objective becomes:

    min⁡θ∑Ti∼p(T)LTi(θ−α∇θLTi(θ,DTisupp),DTiquery)\min_\theta \sum_{\mathcal{T}_i \sim p(\mathcal{T})} \mathcal{L}_{\mathcal{T}_i}(\theta - \alpha \nabla_\theta \mathcal{L}_{\mathcal{T}_i}(\theta, D_{\mathcal{T}_i}^{supp}), D_{\mathcal{T}_i}^{query})θmin​Ti​∼p(T)∑​LTi​​(θ−α∇θ​LTi​​(θ,DTi​supp​),DTi​query​)

The meta-parameters θ\thetaθ are updated using gradient descent based on this meta-objective, typically using a meta-learning rate β\betaβ:

θ←θ−β∇θ∑Ti∼p(T)LTi(θi′,DTiquery)\theta \leftarrow \theta - \beta \nabla_\theta \sum_{\mathcal{T}_i \sim p(\mathcal{T})} \mathcal{L}_{\mathcal{T}_i}(\theta'_i, D_{\mathcal{T}_i}^{query})θ←θ−β∇θ​Ti​∼p(T)∑​LTi​​(θi′​,DTi​query​)

The Meta-Gradient Computation

Calculating the meta-gradient ∇θ∑TiLTi(θi′,DTiquery)\nabla_\theta \sum_{\mathcal{T}_i} \mathcal{L}_{\mathcal{T}_i}(\theta'_i, D_{\mathcal{T}_i}^{query})∇θ​∑Ti​​LTi​​(θi′​,DTi​query​) is the most intricate part of MAML. Since θi′\theta'_iθi′​ depends on θ\thetaθ through a gradient update step, applying the chain rule involves differentiating the inner loop's gradient.

Let's examine a single task T\mathcal{T}T and simplify notation: Lsupp(θ)=LT(θ,DTsupp)L_{supp}(\theta) = \mathcal{L}_{\mathcal{T}}(\theta, D_{\mathcal{T}}^{supp})Lsupp​(θ)=LT​(θ,DTsupp​) and Lquery(θ′)=LT(θ′,DTquery)L_{query}(\theta') = \mathcal{L}_{\mathcal{T}}(\theta', D_{\mathcal{T}}^{query})Lquery​(θ′)=LT​(θ′,DTquery​). The adapted parameters are θ′=θ−α∇θLsupp(θ)\theta' = \theta - \alpha \nabla_\theta L_{supp}(\theta)θ′=θ−α∇θ​Lsupp​(θ). The meta-gradient for this task is:

∇θLquery(θ′)=∇θLquery(θ−α∇θLsupp(θ))\nabla_\theta L_{query}(\theta') = \nabla_\theta L_{query}(\theta - \alpha \nabla_\theta L_{supp}(\theta))∇θ​Lquery​(θ′)=∇θ​Lquery​(θ−α∇θ​Lsupp​(θ))

Applying the chain rule yields:

∇θLquery(θ′)=∇θ′Lquery(θ′)⋅∇θ(θ−α∇θLsupp(θ))\nabla_\theta L_{query}(\theta') = \nabla_{\theta'} L_{query}(\theta') \cdot \nabla_\theta (\theta - \alpha \nabla_\theta L_{supp}(\theta))∇θ​Lquery​(θ′)=∇θ′​Lquery​(θ′)⋅∇θ​(θ−α∇θ​Lsupp​(θ)) ∇θLquery(θ′)=∇θ′Lquery(θ′)⋅(I−α∇θ2Lsupp(θ))\nabla_\theta L_{query}(\theta') = \nabla_{\theta'} L_{query}(\theta') \cdot (I - \alpha \nabla_\theta^2 L_{supp}(\theta))∇θ​Lquery​(θ′)=∇θ′​Lquery​(θ′)⋅(I−α∇θ2​Lsupp​(θ))

Here, ∇θ′Lquery(θ′)\nabla_{\theta'} L_{query}(\theta')∇θ′​Lquery​(θ′) is the gradient of the query loss with respect to the adapted parameters θ′\theta'θ′, evaluated at θ′\theta'θ′. The term ∇θ2Lsupp(θ)\nabla_\theta^2 L_{supp}(\theta)∇θ2​Lsupp​(θ) is the Hessian matrix of the support set loss with respect to the initial parameters θ\thetaθ.

This calculation requires computing the gradient ∇θ′Lquery(θ′)\nabla_{\theta'} L_{query}(\theta')∇θ′​Lquery​(θ′), the Hessian ∇θ2Lsupp(θ)\nabla_\theta^2 L_{supp}(\theta)∇θ2​Lsupp​(θ), multiplying the Hessian by α\alphaα and the gradient vector, and performing a matrix subtraction and multiplication. This involves second-order derivatives, making standard MAML computationally demanding.

MAML Algorithm Pseudocode

Here is a simplified representation of the MAML algorithm:

Algorithm: MAML

Require: Distribution over tasks p(T)p(\mathcal{T})p(T) Require: Step sizes α,β\alpha, \betaα,β

  1. Initialize θ\thetaθ randomly
  2. while not converged do
  3. \hspace{0.5cm} Sample batch of tasks Ti∼p(T)\mathcal{T}_i \sim p(\mathcal{T})Ti​∼p(T) for i=1,…,Bi=1, \dots, Bi=1,…,B
  4. \hspace{0.5cm} for all Ti\mathcal{T}_iTi​ do
  5. \hspace{1cm} Evaluate ∇θLTi(θ,DTisupp)\nabla_\theta \mathcal{L}_{\mathcal{T}_i}(\theta, D_{\mathcal{T}_i}^{supp})∇θ​LTi​​(θ,DTi​supp​) using the support set
  6. \hspace{1cm} Compute adapted parameters θi′=θ−α∇θLTi(θ,DTisupp)\theta'_i = \theta - \alpha \nabla_\theta \mathcal{L}_{\mathcal{T}_i}(\theta, D_{\mathcal{T}_i}^{supp})θi′​=θ−α∇θ​LTi​​(θ,DTi​supp​) (Inner update)
  7. \hspace{0.5cm} end for
  8. \hspace{0.5cm} Update θ←θ−β∇θ∑i=1BLTi(θi′,DTiquery)\theta \leftarrow \theta - \beta \nabla_\theta \sum_{i=1}^B \mathcal{L}_{\mathcal{T}_i}(\theta'_i, D_{\mathcal{T}_i}^{query})θ←θ−β∇θ​∑i=1B​LTi​​(θi′​,DTi​query​) (Outer update, requires backpropagating through step 6 using query sets)
  9. end while
  10. Return θ\thetaθ

Computational Challenges

The primary computational challenge in MAML lies in the outer loop update (step 8), specifically the calculation of the meta-gradient involving second-order derivatives.

  1. Hessian Computation/Hessian-Vector Products: Explicitly forming the Hessian matrix ∇θ2Lsupp(θ)\nabla_\theta^2 L_{supp}(\theta)∇θ2​Lsupp​(θ) is computationally infeasible for deep learning models with millions or billions of parameters, as its size is d×dd \times dd×d, where ddd is the number of parameters. Fortunately, the meta-gradient calculation only requires the product of the Hessian and a vector (∇θ′Lquery(θ′)\nabla_{\theta'} L_{query}(\theta')∇θ′​Lquery​(θ′)). This Hessian-vector product (HVP) can often be computed efficiently without forming the full Hessian, typically using finite differences or automatic differentiation techniques (e.g., Pearlmutter's trick involving a second backward pass). However, even computing HVPs adds significant computational overhead compared to standard first-order gradient calculations.

  2. Memory Usage: Standard implementations using automatic differentiation frameworks require storing the computation graph of the inner loop update(s) to perform the backward pass for the outer loop gradient. This graph includes intermediate activations and gradients, substantially increasing memory requirements, especially when multiple inner loop steps are used or when dealing with large foundation models.

  3. Computational Graph: The overall computation involves a forward pass and backward pass for the inner loop (per task), followed by a forward pass using the adapted parameters on the query set, and finally a backward pass for the meta-gradient calculation which itself involves computation related to the inner loop's gradient. This nested structure contributes to the overall computational cost.

Relationship between meta-parameters (θ), task-adapted parameters (θ'_i), support/query losses, and gradient flow in MAML. The outer loop optimizes θ based on query set performance after adaptation, requiring backpropagation through the inner loop's gradient update step (red arrow), which involves second-order derivatives.

These computational demands motivate the development of approximations like First-Order MAML (FOMAML) and alternative approaches like Implicit MAML (iMAML), which we will examine next. Understanding the exact mechanism and cost of MAML provides the necessary foundation for appreciating these more scalable variants.

  • Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks, Chelsea Finn, Pieter Abbeel, Sergey Levine, 2017 Proceedings of the 34th International Conference on Machine Learning, Vol. 70 (PMLR) DOI: 10.5555/3305890.3306001 - Introduces the MAML algorithm, its mathematical formulation, and demonstrates its effectiveness across various domains.
  • Meta-Learning with Implicit Gradients, Aravind Rajeswaran, Chelsea Finn, Sham M. Kakade, Sergey Levine, 2019 Advances in Neural Information Processing Systems (NeurIPS), Vol. 32 (NeurIPS) DOI: 10.48550/arXiv.1909.04630 - Introduces Implicit MAML (iMAML) to address the computational challenges of standard MAML by using implicit differentiation for meta-gradient computation.
  • CS 330: Multi-Task and Meta-Learning (Course Materials), Chelsea Finn, 2023 (Stanford University) - Provides detailed lecture notes and explanations of meta-learning algorithms, including an in-depth treatment of MAML.

© 2026 ApX Machine Learning