# On First-Order Meta-Learning Algorithms

Reptile shows that simple first-order updates can learn fast-adapting initializations

Alex Nichol, Joshua Achiam, John Schulman · arXiv · 2018-3-8

- **Problem** MAML needs a outer gradient that differentiates through the inner-loop updates, which is costly when many gradient steps are needed at test time. Its first-order variant is cheaper but loses some gradient information.
- **Method** Reptile moves its initialization toward weights adapted on each sampled task.
- **Results** On Mini-ImageNet with transduction, Reptile reaches 49.97 ± 0.32% at 1-shot 5-way and 65.99 ± 0.58% at 5-shot 5-way, above MAML with transduction at 48.70 ± 1.84% and 63.11 ± 0.92%.

## The gap that meta-learned initializations address

Supervised learners usually need far more examples than people do before they perform at a comparable level, and the gap is widest when a new category arrives with only a handful of labeled images. Meta-learning answers this by optimizing the learning procedure itself over a distribution of tasks, instead of trying to reproduce Bayesian inference, which can be computationally intractable.

Two families of approaches have emerged: one stores the learning rule in the weights of a recurrent network that runs no gradient descent at test time, and the other learns an initialization that is fine-tuned on the new task.

Pretraining followed by fine-tuning belongs to the second family, but nothing guarantees that the pretrained starting point suits fine-tuning, and making it work often depends on ad-hoc tricks. MAML scores an initialization by how well it performs after fine-tuning, which means backpropagating through the optimization process, and that is a poor match where many gradient steps are needed at test time.

First-order MAML drops the second-derivative terms, which avoids that cost at the price of some lost gradient information, and the original authors found it nearly matched MAML on Mini-ImageNet.

This study builds on that observation by asking how far first-order updates can go. It introduces Reptile, which uses only first-order gradients and needs no training-test split within each task, and it offers an analysis of why first-order updates still produce fast adaptation.

## MAML's objective and the FOMAML shortcut

MAML looks for a starting vector φ such that, after k inner updates on a task τ, the loss is low. With the superscript k omitted, the objective is \\\[ \\min\_{\\phi}\\ \\mathbb{E}\_{\\tau}\\left\[ L\_{\\tau,B}\\big(U\_{\\tau,A}(\\phi)\\big) \\right\] \\\] The inner update U\_{τ,A} uses training samples A, while the outer loss L\_{τ,B} is evaluated on test samples B, so the outer step rewards generalization, much as cross-validation does.

The MAML gradient is \\(g\_{\\text{MAML}} = U'\_{\\tau,A}(\\phi)\\,L'\_{\\tau,B}(\\tilde\\phi)\\), where \\(\\tilde\\phi = U\_{\\tau,A}(\\phi)\\) and U' is the Jacobian of the update. The update adds a sequence of gradient vectors to the starting point, so FOMAML treats those gradients as constants and replaces the Jacobian with the identity; its outer gradient becomes \\(L'\_{\\tau,B}(\\tilde\\phi)\\).

Adam rescales the gradients elementwise, which the authors say does not change this argument. That gives a short recipe: sample a task, run the inner update, compute the gradient at the adapted point, and pass that gradient to the outer optimizer.

## One Reptile iteration and its batched form

Reptile keeps an initialization φ, samples a task τ with loss L\_τ, runs k steps of SGD or Adam from φ to get \\(\\tilde\\phi = U^k\_\\tau(\\phi)\\), and moves φ a fraction ε of the way toward \\(\\tilde\\phi\\), so \\\[ \\phi \\leftarrow \\phi + \\epsilon(\\tilde\\phi - \\phi) \\\] Because it needs no separate training and test batch for each task, Reptile does not require the split that FOMAML uses.

The displacement can also be fed to an adaptive optimizer such as Adam, and with SGD step size α the Reptile gradient is \\((\\phi-\\tilde\\phi)/\\alpha\\).

A batched version averages the displacements over n tasks in each iteration: \\\[ \\phi \\leftarrow \\phi + \\epsilon\\,\\frac{1}{n}\\sum\_{i=1}^{n}(\\tilde\\phi\_i - \\phi) \\\] Apart from the step size and how tasks are sampled, this matches SimuParallelSGD, a distributed method in which workers update locally and average their parameters infrequently.

With one gradient step per task, the update is stochastic gradient descent on the expected loss, which is the joint training objective. With more steps the expected update picks up higher-order derivatives of the loss, so it no longer equals a step on the expected loss, and Reptile can settle on a point far from the minimizer of the expected loss.

## Why a sine-wave task separates Reptile from joint training

Each task is a sine wave \\(f\_\\tau(x) = a\\sin(x+b)\\), with amplitude a drawn from U(\[0.1, 5.0\]) and phase b drawn from U(\[0, 2π\]). The learner sees p points drawn from U(\[−5, 5\]) and must predict the whole function, scored by the squared error integrated over \[−5, 5\]. The integral is evaluated with 50 equally spaced points.

Because the phase is random, the average task function is zero everywhere, so the expected loss is minimized by the zero function, and joint training learns no useful starting point. MAML and Reptile instead find an initialization that outputs roughly zero but whose internal features let a few gradient steps fit a sampled wave.

In the demonstration the network has layers 1 → 64 → 64 → 1, is trained on 10 sampled points, and takes 32 gradient steps. After Reptile training it fits the sampled sine wave and infers values away from the sampled points, while a randomly initialized network in the same setup does not.

## Taylor expansion of the meta-gradients

To explain Reptile, the authors expand its update with a Taylor series in the step size α, treating a task as a sequence of k minibatch losses L\_1 through L\_k rather than a training and test pair. Each SGD gradient is \\(g\_i = L'\_i(\\phi\_i)\\), the parameters step as \\(\\phi\_{i+1} = \\phi\_i - \\alpha g\_i\\), and the Hessian at the initial point is \\(H\_i = L''\_i(\\phi\_1)\\).

To first order, each SGD gradient equals the gradient at the initial point minus α times H\_i applied to the sum of the earlier gradients, so earlier minibatches leave a second-order imprint on later steps.

For k = 2, the MAML meta-gradient expands to \\(g\_2 - \\alpha H\_2 g\_1 - \\alpha H\_1 g\_2\\), the FOMAML gradient to \\(g\_2 - \\alpha H\_2 g\_1\\), and the Reptile update to \\(g\_1 + g\_2 - \\alpha H\_2 g\_1\\), each up to O(α²). The authors argue that the lone gradient terms move toward the minimum of the joint training problem, while the Hessian-gradient terms maximize inner products between gradients of different minibatches.

Averaging over minibatches and tasks leaves AvgGrad, the average gradient \\(\\mathbb{E}\_{\\tau,1}\[g\_1\]\\), and AvgGradInner, the average of \\(H\_2 g\_1\\), which equals half the expected gradient of \\(g\_1\\cdot g\_2\\) with respect to φ\_1. For k = 2 the expected meta-gradients are \\(\\mathbb{E}\[g\_{\\text{MAML}}\] = \\text{AvgGrad} - 2\\alpha\\,\\text{AvgGradInner}\\), \\(\\mathbb{E}\[g\_{\\text{FOMAML}}\] = \\text{AvgGrad} - \\alpha\\,\\text{AvgGradInner}\\), and \\(\\mathbb{E}\[g\_{\\text{Reptile}}\] = 2\\,\\text{AvgGrad} - \\alpha\\,\\text{AvgGradInner}\\).

For general k the AvgGradInner coefficients become 2(k−1)α for MAML, (k−1)α for FOMAML, and ½k(k−1)α for Reptile, while the AvgGrad coefficient for Reptile becomes k. Within this approximation, the ratio of the AvgGradInner coefficient to the AvgGrad coefficient is ordered MAML \> FOMAML \> Reptile, and it grows linearly in both α and k.

## Reptile as distance minimization to solution manifolds

The second argument treats each task τ as having a set \\(W\_\\tau\\) of optimal parameters and asks for an initialization that is close to every such set, by minimizing \\\[ \\mathbb{E}\_\\tau\\left\[\\tfrac{1}{2}D(\\phi,W\_\\tau)^2\\right\] \\\] For a non-pathological set S, the gradient of half the squared distance at almost every point is φ minus the projection of φ onto S, so the expected gradient is \\(\\mathbb{E}\_\\tau\[\\phi - P\_{W\_\\tau}(\\phi)\]\\).

A Reptile step is then \\(\\phi \\leftarrow (1-\\epsilon)\\phi + \\epsilon P\_{W\_\\tau}(\\phi)\\), which is a stochastic gradient step on this distance objective.

The exact projection cannot be computed, because it requires minimizing the task loss, so Reptile replaces it with the result of k gradient descent steps on L\_τ starting from φ. The distance objective differs from the expected loss: the expected loss has a high-dimensional set of minimizers, while the distance objective typically has a single minimizer.

The authors label this argument informal and weaker than the Taylor series analysis.

## Few-shot episodes and evaluation setup

Each K-shot, N-way task selects N classes from the meta-dataset and K + 1 examples per class, where K examples per class form the training set and one example per class forms the test set. In a 5-shot, 5-way task the model sees 25 examples and then classifies a 26th. Experiments use Omniglot and Mini-ImageNet, with the CNN architectures and data preprocessing of Finn et al.

Under transduction the model classifies the whole test set at once, and batch normalization statistics are shared across the test samples. Without transduction, the statistics come from all the training samples and a single test sample. Finn et al. use transduction when evaluating MAML.

The Adam statistics are not reset during training, but they are backed up and reset before test evaluation to avoid information leakage.

## Mini-ImageNet and Omniglot results

On Mini-ImageNet, Reptile + Transduction reaches 49.97± 0.32% at 1-shot 5-way and 65.99± 0.58% at 5-shot 5-way, the highest values in Table 1 and above MAML + Transduction at 48.70± 1.84% and 63.11± 0.92%. The MAML and first-order MAML results in that table are taken from Finn et al.

Without transduction, Reptile reaches 47.07± 0.26% at 1-shot 5-way and 62.74± 0.37% at 5-shot 5-way, slightly below the transductive MAML and first-order MAML rows. The authors describe MAML, FOMAML and Reptile as having very similar performance, with Reptile slightly ahead on Mini-ImageNet and slightly behind on Omniglot.

On Omniglot the Reptile row sits below both the MAML + Transduction and the 1st-order MAML + Transduction rows in all four columns; at 5-shot 5-way it is 98.90± 0.10% against 99.9± 0.1% for MAML + Transduction. First-order MAML results on Omniglot were generated with the code of Finn et al. using the MAML hyper-parameters.

Transduction raises Reptile in every Omniglot column, for example from 98.90± 0.10% to 99.48± 0.06% at 5-shot 5-way and from 95.39± 0.09% to 97.68± 0.04% at 1-shot 5-way. The authors connect the momentum finding to their analysis: with momentum a minibatch influences the next few steps, which weakens the effect that Reptile relies on sequential steps coming from different minibatches.

## Effect of combining inner-loop gradients

To keep the comparison clean, the runs use vanilla SGD in both loops, no meta-batches, and 5-shot 5-way Omniglot, and combinations with several terms are tried as both a sum and an average.

Using g\_1 alone is quite ineffective, which fits the fact that it optimizes the expected loss over all tasks. The two-step Reptile variant trails the two-step FOMAML variant by a noticeable margin, and the authors suggest this may come from Reptile putting less weight on AvgGradInner relative to AvgGrad.

Performance improves as more minibatch gradients are included, and the gain is larger for a sum over all gradients (Reptile) than for the final gradient alone (FOMAML). The authors read this as evidence that Reptile can benefit from many inner-loop steps.

## Minibatch overlap in the FOMAML inner loop

Shared-tail FOMAML draws the final inner-loop minibatch from the same data as the earlier minibatches, while separate-tail FOMAML draws it from a disjoint set. The authors view separate-tail FOMAML as the more faithful approximation to MAML, since its training-time optimization resembles test-time optimization, and they find it clearly better than shared-tail FOMAML.

With cycled minibatches, shared-tail FOMAML performs well up to four inner-loop iterations and drops starting at five, where the final minibatch overlaps the earlier ones. With random replacement the drop is gradual, and the authors hypothesize that this is because some samples in the final batch never appeared in the earlier batches.

With four inner-loop iterations fixed, batch sizes above 25 force the final batch of shared-tail FOMAML to contain samples from earlier batches. Separate-tail FOMAML and Reptile do not degrade as the number of inner-loop iterations or the batch size changes.

A smaller effective step size might explain the gap, but shared-tail FOMAML was equally poor at every step size in a thorough sweep. The authors offer a second explanation: after a few inner-loop steps on a sample, the loss gradient for that sample carries little useful information, so further steps bounce around a local optimum. All of these sweeps use 5-shot 5-way Omniglot.

## Limitations

The Taylor analysis holds only for small αk. The argument that Reptile finds a point close to all solution manifolds is informal and weaker than the Taylor series analysis.

Reptile has so far produced negative results in reinforcement learning, where joint training is a strong baseline. The few-shot evidence covers Omniglot and Mini-ImageNet, and the inner-loop gradient and overlap sweeps cover only 5-shot 5-way Omniglot.

The authors list open questions: whether deeper classifier architectures, regularization that narrows the gap between training and testing error, and few-shot density modeling would improve Reptile. The authors suggest the Taylor analysis may bear on stochastic gradient descent in general, but in this paper that remains a hypothesis.

## Paper info

- **Authors**: Alex Nichol, Joshua Achiam, John Schulman
- **Venue**: arXiv · Preprint
- **First published**: 2018-3-8
- **Added**: 2026-11-12
- **Updated**: 2018-10-22
- **Version**: v3
- **arXiv**: 1803.02999
- **Category**: cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1803.02999v3) · [PDF ↗](https://arxiv.org/pdf/1803.02999v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Alex Nichol, Joshua Achiam, John Schulman (2018). On First-Order Meta-Learning Algorithms. arXiv:1803.02999v3. https://arxiv.org/abs/1803.02999v3

**BibTeX**

```
@misc{nichol2018first,
  title = {{On First-Order Meta-Learning Algorithms}},
  author = {Alex Nichol and Joshua Achiam and John Schulman},
  year = {2018},
  eprint = {1803.02999},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1803.02999v3}
}
```

## Other paper commentary

- [A Tutorial on Principal Component Analysis](https://refivu.com/en/papers/6c1b9168-7aa0-40d4-97a5-859e8217739b-a-tutorial-on-principal-component-analysis.md)
- [Estimation and Inference of Heterogeneous Treatment Effects using Random Forests](https://refivu.com/en/papers/ee58e924-ae1d-4d66-9ec5-6c7d18a8692c-estimation-and-inference-of-heterogeneous-treatment-effects.md)
- [Popular Ensemble Methods: An Empirical Study](https://refivu.com/en/papers/5090a4a5-58f8-4919-88f2-f93e9b4007cb-popular-ensemble-methods-an-empirical-study.md)
- [A Survey on Multi-Task Learning](https://refivu.com/en/papers/98bc12a0-4d8a-482c-a7f3-4cb8b097be35-a-survey-on-multi-task-learning.md)
- [A Survey on Deep Transfer Learning](https://refivu.com/en/papers/70d5585b-a29e-478d-99ba-9a1b29ac99c1-a-survey-on-deep-transfer-learning.md)
- [Scalable and accurate deep learning for electronic health records](https://refivu.com/en/papers/80cf3810-6b7d-4305-b76c-de501726decd-scalable-and-accurate-deep-learning-for-electronic-health.md)
- [RAFT: Recurrent All-Pairs Field Transforms for Optical Flow](https://refivu.com/en/papers/14ee65d7-abd3-40c2-af3a-dcf58b84facf-raft-recurrent-all-pairs-field-transforms-for-optical.md)
- [StackGAN: Text to Photo-realistic Image Synthesis with Stacked Generative Adversarial Networks](https://refivu.com/en/papers/5f81473c-85d8-4d1a-acd2-1cc917ea3535-stackgan-text-to-photo-realistic-image-synthesis-with.md)
- [Adversarial Machine Learning at Scale](https://refivu.com/en/papers/fcc0e603-ae52-4f86-b341-4b1f8ee7d840-adversarial-machine-learning-at-scale.md)
- [LexRank: Graph-based Lexical Centrality as Salience in Text Summarization](https://refivu.com/en/papers/11b54298-bb68-4667-a225-10b7dade3a5a-lexrank-graph-based-lexical-centrality-as-salience-in.md)
- [Deep Laplacian Pyramid Networks for Fast and Accurate Super-Resolution](https://refivu.com/en/papers/640b6f7c-566c-4cc7-a351-edc07a5183c8-deep-laplacian-pyramid-networks-for-fast-and-accurate.md)
- [CosFace: Large Margin Cosine Loss for Deep Face Recognition](https://refivu.com/en/papers/43b1a508-8c6d-401d-a3af-ac7a5ed1803f-cosface-large-margin-cosine-loss-for-deep-face.md)

## Terms in this paper

- [ADAM](https://refivu.com/en/terms/0e9ad0199e08-adam)
- [Stochastic Gradient Descent](https://refivu.com/en/terms/a49650824022-stochastic-gradient-descent)
- [Batch Normalization](https://refivu.com/en/terms/2b3e5f8509f6-batch-normalization)
- [Hessian](https://refivu.com/en/terms/cb53640b58ff-hessian)
- [MAML](https://refivu.com/en/terms/ba693deb3cda-maml)
- [Omniglot](https://refivu.com/en/terms/207a37dcf16c-omniglot)
- [Meta-learning](https://refivu.com/en/terms/4463fb5203f7-meta-learning)
- [joint training](https://refivu.com/en/terms/cdf0dc15beb4-joint-training)
- [few-shot classification](https://refivu.com/en/terms/f633be9d0a73-few-shot-classification)
- [Reptile](https://refivu.com/en/terms/f38a32205ada-reptile)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/96fdc3b8-b749-4c6d-ac7d-17c8789f25d8-on-first-order-meta-learning-algorithms)
