---
title: 'Meta-SGD: A Meta-Learning Algorithm'
url: https://www.emergentmind.com/topics/meta-sgd
type: topic
---

# Meta-SGD: A Meta-Learning Algorithm

Meta-SGD is a meta-learning algorithm that enables rapid adaptation to new tasks by learning a parameter initialization and a per-parameter update rule within an SGD-like framework. Designed for few-shot learning, Meta-SGD combines the computational simplicity of model-agnostic meta-learning (MAML) with the flexibility of learning both step-sizes and update directions. It supports both supervised and reinforcement learning scenarios, demonstrating efficacy across regression, classification, and control tasks [1707.09835].

## 1. Meta-Learning Objective and Formalism

Meta-SGD operates under a meta-learning paradigm where a distribution over tasks, \(p(\mathcal{T})\), is assumed. Each task \(\mathcal{T}\) provides a small training set, \(\mathrm{train}(\mathcal{T})\), and a corresponding test set, \(\mathrm{test}(\mathcal{T})\). The empirical losses are defined as

\[
\mathcal{L}_{\mathrm{train}(\mathcal{T})}(\theta) = \frac{1}{|\mathrm{train}(\mathcal{T})|}\sum_{(x, y)\in\mathrm{train}(\mathcal{T})}\ell(f_\theta(x), y),
\]
\[
\mathcal{L}_{\mathrm{test}(\mathcal{T})}(\theta) = \frac{1}{|\mathrm{test}(\mathcal{T})|}\sum_{(x, y)\in\mathrm{test}(\mathcal{T})}\ell(f_\theta(x), y).
\]

Meta-SGD introduces two meta-parameters: an initialization vector \(\theta \in \mathbb{R}^D\) and an element-wise step-size vector \(\alpha \in \mathbb{R}^D\). The adaptation for a sampled task is

\[
\theta' = \theta - \alpha \odot \nabla_\theta \mathcal{L}_{\mathrm{train}(\mathcal{T})}(\theta),
\]

where \(\odot\) denotes element-wise multiplication. The meta-objective is to minimize the expected test loss after this adaptation:

\[
\boxed{
\min_{\theta, \alpha}\;
\mathbb{E}_{\mathcal{T}\sim p(\mathcal{T})} \left[
\mathcal{L}_{\mathrm{test}(\mathcal{T})}
\bigl(
\theta - \alpha \odot \nabla_\theta \mathcal{L}_{\mathrm{train}(\mathcal{T})}(\theta)
\bigr)
\right]
}
\]

## 2. Meta-SGD Update Derivation

### a. Inner-Loop Adaptation

For each task, the adaptation step is computed using the current meta-parameters:

\[
g = \nabla_\theta \mathcal{L}_{\mathrm{train}(\mathcal{T})}(\theta)
\]
\[
\theta' = \theta - \alpha \odot g
\]

The vector \(\alpha\) is learned to encode both directionality and magnitude of the update.

### b. Outer-Loop Meta-Update

Performance is evaluated on the test set for each task after the inner-loop adaptation. Aggregating over a batch of tasks, the meta-parameters are updated as follows:

\[
(\theta, \alpha) \leftarrow (\theta, \alpha)
- \beta \; \nabla_{(\theta, \alpha)}
\sum_{i=1}^B
\mathcal{L}_{\mathrm{test}(\mathcal{T}_i)}(\theta_i'),
\]

where \(\beta\) is the meta-step size.

### c. Meta-Gradient Through Adaptation

Gradients are backpropagated through the inner-loop adaptation using the chain rule, yielding:

\[
\frac{\partial \mathcal{L}_{\mathrm{test}}(\theta')}{\partial \theta}
=
\Bigl( I - \operatorname{diag}(\alpha)\, \nabla^2_\theta \mathcal{L}_{\mathrm{train}}(\theta) \Bigr)^{\!\top}
\nabla_{\theta'} \mathcal{L}_{\mathrm{test}}(\theta')
\]
\[
\frac{\partial \mathcal{L}_{\mathrm{test}}(\theta')}{\partial \alpha}
=
- \bigl[\nabla_\theta \mathcal{L}_{\mathrm{train}}(\theta)\bigr]
\odot
\nabla_{\theta'} \mathcal{L}_{\mathrm{test}}(\theta')
\]

This approach leverages automatic differentiation frameworks for efficient meta-gradient computation.

## 3. Comparisons to Alternative Meta-Learners

The distinguishing characteristics of Meta-SGD, MAML, and Meta-LSTM are summarized as follows:

| Algorithm    | Learned Parameters            | Update Dynamics         | Computational Complexity            |
|--------------|------------------------------|------------------------|-------------------------------------|
| MAML         | \(\theta\)                   | Fixed scalar \(\alpha\) (hyperparameter) | Simple, end-to-end, global rate      |
| Meta-LSTM    | Via RNN: \(\theta\), update | RNN-parameterized      | Flexible, but high cost              |
| Meta-SGD     | \(\theta\), elementwise \(\alpha\) | SGD-like, per-coordinate rate & direction | Simple, efficient, per-coordinate |

- **MAML** learns only the initialization \(\theta\), with a global, hand-chosen step-size hyperparameter \(\alpha\). While broadly applicable, its capacity is constrained by the fixed update structure.
- **Meta-LSTM** employs an RNN or LSTM to generate parameter updates, enabling high optimizer flexibility at the cost of significant computational overhead, scalability challenges, and complicated training.
- **Meta-SGD** simultaneously learns the initialization and a vector of step-sizes (including possible sign changes), providing higher capacity than MAML while retaining the implementation simplicity and scalability.

## 4. Algorithmic Implementation

The meta-learning loop for supervised few-shot learning is as follows (using LaTeX pseudocode):

```
\begin{algorithm}[h]
\caption{Meta-SGD for Supervised Few-Shot Learning}
\label{alg:meta-sgd}
\begin{algorithmic}[1]
\Require Task distribution $p(\mathcal{T})$, meta‐step size $\beta$
\State Initialize meta‐parameters $\theta,\alpha$
\While{not converged}
  \State Sample batch $\{\mathcal{T}_i\}_{i=1}^B\sim p(\mathcal{T})$
  \For{$i=1,\dots,B$}
    \State Compute training loss        $L^{\rm tr}_i = \mathcal{L}_{\mathrm{train}(\mathcal{T}_i)}(\theta)$
    \State $g_i \gets \nabla_\theta L^{\rm tr}_i$
    \State Adapted params:       $\theta_i' \gets \theta - \alpha \odot g_i$
    \State Compute test loss       $L^{\rm te}_i = \mathcal{L}_{\mathrm{test}(\mathcal{T}_i)}(\theta_i')$
  \EndFor
  \State $\displaystyle
    (\theta,\alpha)\;\gets\;
    (\theta,\alpha)\;-\;\beta\;\nabla_{(\theta,\alpha)}\!\sum_{i=1}^B L^{\rm te}_i$
\EndWhile
\State \Return Meta-learner $(\theta,\alpha)$
\end{algorithmic}
\end{algorithm}
```

At meta-test time, adaptation on a new task involves one application of the learned update.

## 5. Experimental Protocols and Performance

Experiments on regression, classification, and reinforcement learning underline the adaptability and empirical superiority of Meta-SGD in few-shot regimes.

### Regression: Sine-Wave Fitting
- Task: Fit \(y(x) = A\sin(\omega x + b)\) for \((A, \omega, b)\) sampled uniformly.
- Network: 1–40–40–1 (ReLU).
- Inner adaptation: one-shot.
- Meta-SGD (element-wise \(\alpha\)) outperforms MAML (fixed \(\alpha = 0.01\)) in MSE.

| Meta-train | Model    | 5-shot test          | 20-shot test         |
|------------|----------|----------------------|----------------------|
| 5-shot     | MAML     | 1.13 ± 0.18          | 0.71 ± 0.12          |
|            | Meta-SGD | **0.90 ± 0.16**      | **0.50 ± 0.10**      |
| 20-shot    | MAML     | 1.29 ± 0.20          | 0.48 ± 0.08          |
|            | Meta-SGD | **1.01 ± 0.17**      | **0.31 ± 0.05**      |

### Classification: Omniglot and MiniImageNet

- Encoder: 4-layer (conv3×3–BN–ReLU–pool).
- Both 1-shot/5-shot, 5-way/20-way experiments.

| Model      | Omniglot 5-way 1-shot | Omniglot 20-way 5-shot | MiniImageNet 5-way 1-shot | MiniImageNet 20-way 5-shot |
|------------|----------------------|------------------------|---------------------------|----------------------------|
| Matching   | 98.1%                | 98.5%                  | 43.6%                     | 22.7%                      |
| MAML       | 98.7%                | 98.9%                  | 48.7%                     | 19.3%                      |
| Meta-LSTM  | —                    | —                      | 43.4%                     | 26.1%                      |
| Meta-SGD   | **99.53%**           | **98.97%**             | **50.5%**                 | **28.9%**                  |

### Reinforcement Learning: 2D Navigation

- Policy: Gaussian action output.
- Task: Navigation in \([-0.5,0.5]^2\), fixed and varying start.
- Outer-loop: TRPO.

| Model      | Fixed start         | Varying start        |
|------------|---------------------|----------------------|
| MAML       | −9.12 ± 0.66        | −10.71 ± 0.76        |
| Meta-SGD   | **−8.64 ± 0.68**    | **−10.15 ± 0.62**    |

## 6. Limitations and Open Problems

- **Computational Expense**: Meta-training entails numerous simulated inner-loop updates across tasks, which is computationally intensive for large models or extended unrolled adaptation.
- **Generalization Beyond \(p(\mathcal{T})\)**: Performance may degrade on test tasks that differ substantially from training distribution, suggesting limited extrapolation capability.
- **Scalability to Many-Shot Regimes**: Single-step adaptation may underfit when tasks have rich support; multi-step or hierarchical meta-learning approaches may be required.
- **Task Heterogeneity**: Effective handling of highly diverse families of tasks (e.g., spanning multiple modalities) with a single meta-learner is an unresolved challenge.

These issues remain significant avenues for the development of more scalable and robust meta-learning algorithms [1707.09835].

Source: https://www.emergentmind.com/topics/meta-sgd