Sam Babichenko

Reading notes / Dataset distillation

Matching training trajectories

Cazenavette et al., 2022; Cui et al., 2023

Data and losses
T\mathcal Treal training set
S\mathcal Sdistilled set, with fixed one-hot labels
θ\thetanetwork weights
ℓT,\ell_{\mathcal T}, ℓS\ell_{\mathcal S}average cross-entropy on the real and the distilled set
gT,g_{\mathcal T}, gSg_{\mathcal S}their gradients at the current weights
Unrolled and one-step matching
θ0\theta_0random initial weights
η~\tilde\etalearned step size of the unrolled run (Wang et al.)
θt\theta_tweights after tt steps on the distilled set (gradient matching)
DDper-output-unit cosine distance between gradients
η\etathe expert's step size, in the one-step case
Trajectory matching
θt∗\theta^*_tan expert's weights at checkpoint tt
θ^t+n\hat\theta_{t+n}the student's weights after nn steps from θt∗\theta^*_t
N,N, MMstudent steps, and expert updates they must cover
bn,b_n, ℓbn\ell_{b_n}synthetic batch at step nn and its cross-entropy
α\alphalearned student step size
LLnormalized endpoint distance, the loss on the pixels
T+T^+latest allowed start checkpoint
gn,g_n, G,G, Δ\Deltastep-nn gradient, their sum, the expert's displacement (TESLA)
Paper symbols
T,\mathcal T, S\mathcal Sthe trajectory-matching paper writes DrealD_{\rm real} and DsynD_{\rm syn}
α,\alpha, NNCui et al. write β\beta for the step size and TT for the number of steps
η~\tilde\etaWang et al. write η~\tilde\eta too, and x~\tilde x for the synthetic images

Context. learning a few synthetic training images per class that can replace a large real training set when a model is trained on them (Wang et al., 2018); a coreset, by contrast, keeps a subset of the real images. Reading note: Dataset distillation seeks a small synthetic set, typically 1 to 50 images per class, that trains a network from scratch nearly as well as the full dataset. Scoring a synthetic set directly requires differentiating through an entire training run, and memory grows linearly with the number of steps. Earlier work either unrolled a few steps (Wang et al., 2018) or matched one gradient step at a time (Zhao et al., 2021). Cazenavette et al. (2022) instead match a longer stretch of training. They start a student at a saved real-data checkpoint, take a few steps on the synthetic images, and optimize the pixels so it lands where the real run was several epochs later.

In practice, trajectory matching is the synthesis method that most clearly beats strong subsets of real images on small datasets at small budgets with one-hot labels. On CIFAR-10 at 10 images per class, a ConvNet trained on its synthetic set reaches 65.3% test accuracy, against 26.0% for 10 random real images per class and 84.8% for the full dataset. Re-evaluations with matched augmentation and stronger real subsets preserve a wide lead. The lead fades as budgets approach a few hundred images per class on CIFAR-10, as shown for gradient and distribution matching. It also vanishes on Tiny ImageNet once real images receive a teacher's soft labels. Scaling runs into storage for the real-data trajectories and memory for the unrolled student steps. Cui et al. (2023) remove the memory growth and reach ImageNet-1k at 64 × 64, where soft labels carry most of the accuracy.

Setting. Write the real training set, images with their class labels for the real training set and the distilled set: a few synthetic images per class, each with a fixed one-hot label; its pixels are what distillation optimizes for the distilled set, whose images carry fixed one-hot labels. At network weights the weights of the classifier being trained, a small ConvNet in most experiments here, let the average cross-entropy of the network with weights θ\theta over the real training set and the average cross-entropy of the network with weights θ\theta over the distilled set be the average cross-entropy on each set. Write their gradients as gTg_{\mathcal T}=∇ℓT(θ){}=\nabla\ell_{\mathcal T}(\theta) and gSg_{\mathcal S}=∇ℓS(θ){}=\nabla\ell_{\mathcal S}(\theta). Evaluation trains a fresh network from random initialization on S\mathcal S alone and scores it on the real test set, at budgets measured in the number of distilled images of each class (IPC in the papers); 10 images per class of CIFAR-10 is 100 images, 0.2% of its 50,000 training images.

The bilevel objective (Wang et al., 2018). Wang et al. treat the synthetic pixels and a learned step size the step size of the short training run on the synthetic images, learned along with them as parameters of a short run from random initial weights the network's initial weights, drawn from the usual random initialization. They minimize the trained network's expected loss on the real data:θ1=θ0−η~ ∇ℓS(θ0),min⁡S, η~ Eθ0 ℓT(θ1).\begin{aligned}\theta_1&=\theta_0-\tilde\eta\,\nabla\ell_{\mathcal S}(\theta_0),\\&\min_{\mathcal S,\,\tilde\eta}\ \mathbb E_{\theta_0}\,\ell_{\mathcal T}(\theta_1).\end{aligned}Over multiple steps on successive synthetic batches, backpropagation runs through every step, so memory and compute scale linearly with rollout length. Expanding ℓT(θ1)\ell_{\mathcal T}(\theta_1) to first order around θ0\theta_0 (derived here) givesℓT(θ1)=ℓT(θ0)−η~ gT⊤gS+O(η~2),\begin{aligned}\ell_{\mathcal T}(\theta_1)&=\ell_{\mathcal T}(\theta_0)-\tilde\eta\,g_{\mathcal T}^\top g_{\mathcal S}\\&\quad+O(\tilde\eta^2),\end{aligned}with both gradients evaluated at θ0\theta_0. To first order, one synthetic step lowers the real-data loss in proportion to gT⊤gSg_{\mathcal T}^\top g_{\mathcal S}, the alignment between the synthetic and real gradients.

Gradient matching (Zhao et al., 2021). Zhao et al. avoid unrolling by targeting gradient alignment directly at every step. As a network trains on the synthetic set, each step at weights the weights of the network after tt steps of training on the distilled set, during distillation updates the pixels so the synthetic gradient matches the real gradient:min⁡S Eθ0∑tD(gS(θt), gT(θt)).\min_{\mathcal S}\ \mathbb E_{\theta_0}\textstyle\sum_t D\big(g_{\mathcal S}(\theta_t),\,g_{\mathcal T}(\theta_t)\big).The distance a sum, over layers and output units, of one minus the cosine between the synthetic and the real gradient of that unit's incoming weights compares gradients per output unit, matched class by class. Each pixel update differentiates through only one gradient computation, so the step is cheap. Cazenavette et al. argue that matching one step at a time is short-sighted. Small single-step mismatches accumulate over long training runs, so a student trained on gradient-matched images can drift far from the real-data trajectory.

Matching a stretch of training (Cazenavette et al., 2022). Trajectory matching captures long-range progress without unrolling from initialization. It starts each student at a saved checkpoint from a real-data run, so a short, affordable stretch still trains on weights that real training actually visits. First, many networks trained on the real training set with their weights saved after every epoch; 200 for CIFAR, 100 for the ImageNet subsets train normally on T\mathcal T, saving their weights an expert's saved weights at checkpoint tt; the sequence θ0∗,θ1∗,…\theta^*_0,\theta^*_1,\dots is its trajectory after every epoch. Each distillation step picks an expert and a start checkpoint tt, initializes θ^t=θt∗\hat\theta_t=\theta^*_t, and runs the student for the number of student steps on synthetic batches in one distillation step; much smaller than MM steps with a learned step size the student's step size on the synthetic images, learned along with the pixels. Step nn uses an augmented synthetic batch the batch of synthetic images used at student step nn, passed through a random differentiable augmentation; ℓbn\ell_{b_n} is the cross-entropy on it with cross-entropy ℓbn\ell_{b_n}. The loss LL measures squared distance to the expert's weights the number of expert updates that the student's NN steps must cover; checkpoints are saved once per epoch, so in practice a few epochs updates later, normalized by how far the expert moved:θ^t+n+1=θ^t+n−α ∇ℓbn(θ^t+n),L=∥θ^t+N−θt+M∗∥2∥θt∗−θt+M∗∥2.\begin{aligned}\hat\theta_{t+n+1}&=\hat\theta_{t+n}-\alpha\,\nabla\ell_{b_n}(\hat\theta_{t+n}),\\L&=\frac{\|\hat\theta_{t+N}-\theta^*_{t+M}\|^2}{\|\theta^*_t-\theta^*_{t+M}\|^2}.\end{aligned}Backpropagating LL through all NN steps updates both the pixels and α\alpha. Because N≪MN\ll M, each synthetic step does the work of several real updates, and α\alpha adapts to that ratio.

Sampling stretches across many experts covers training from initialization up to a start-checkpoint cap the latest checkpoint a student may start from; set too high, the images learn from late stretches where the expert barely moves, and set too low, they never see the middle and late parts of training, skipping the very end of training where the expert barely moves. Dividing by ∥θt∗−θt+M∗∥2\|\theta^*_t-\theta^*_{t+M}\|^2 puts early and late stretches on the same scale. Without that normalization, late stretches where the expert moves little would produce small squared distances and weak gradients. Because every expert finishes training beforehand, distillation never touches real images while optimizing the synthetic pixels.

Gradient matching as the one-step case. Setting N=M=1N=M=1 connects the two methods directly. Take one student step and one full-batch expert step from the same weights θt\theta_t with expert step size the step size of the expert's training on real data; its single step here is η gT\eta\,g_{\mathcal T}, and minimize the normalized loss over α\alpha (derived here):L=∥αgS−ηgT∥2∥ηgT∥2,min⁡αL=1−(gS⊤gT)2∥gS∥2 ∥gT∥2=1−cos⁡2(gS,gT).\begin{aligned}L&=\frac{\|\alpha g_{\mathcal S}-\eta g_{\mathcal T}\|^2}{\|\eta g_{\mathcal T}\|^2},\\\min_\alpha L&=1-\frac{(g_{\mathcal S}^\top g_{\mathcal T})^2}{\|g_{\mathcal S}\|^2\,\|g_{\mathcal T}\|^2}\\&=1-\cos^2(g_{\mathcal S},g_{\mathcal T}).\end{aligned}The minimum occurs at α=η gS⊤gT/∥gS∥2\alpha=\eta\,g_{\mathcal S}^\top g_{\mathcal T}/\|g_{\mathcal S}\|^2, which is a positive step when gS⊤gT>0g_{\mathcal S}^\top g_{\mathcal T}>0. One-step trajectory matching therefore reduces to gradient matching with a single global cosine across all weights. Zhao et al. instead sum one cosine per output unit, and their ablation shows the difference. On MNIST at 1 image per class with a ConvNet, a single global cosine reaches 69.2% against 91.7% for the per-unit distance. They also match gradients at weights reached by training on the synthetic set rather than at saved expert checkpoints. Beyond one step, trajectory matching extends gradient matching to multi-step stretches anchored on real trajectories.

Small-dataset gains. In Cazenavette et al.'s evaluation, each distilled set trains five fresh width-128 ConvNets from scratch. On CIFAR-10 at 10 images per class, trajectory matching reaches 65.3%, against 52.1% for gradient matching with differentiable augmentation (Zhao and Bilen, 2021): the same random augmentation is applied to the real and the synthetic batch before their gradients are compared, 26.0% for random real images, and 84.8% for the full dataset. It also leads every compared method on CIFAR-100 and Tiny ImageNet at 1, 10, and 50 images per class. Cazenavette et al. also report the first distillation runs on 128 × 128 ImageNet subsets, reaching 63.0% on ImageNette at 10 images per class against 87.4% for the full subset.

Why longer stretches help. Ablations confirm that multi-step matching drives the gain over gradient matching. On CIFAR-100 at 1 image per class, accuracy is lowest when one student step matches a short expert stretch and highest when both NN and MM are large. In a direct trajectory test up to 1,000 steps, a fresh network trained on DSA images drifts farther from real-data checkpoints than one trained on trajectory-matched images as the horizon grows. Accuracy also rises with the number of stored experts, climbing sharply from 1 to 20 and leveling off near 200.

Where the lead fades: larger budgets. DC-BENCH (Cui et al., 2022) tunes the best augmentation per method and adds a coreset method: embed the real images with a network trained on them, then pick images one at a time, each as far as possible from those already picked selection as a stronger real-image baseline. On CIFAR-10 at 10 images per class, trajectory matching still leads clearly at 63.7% against 41.5% for K-center. Above about 200 images per class on CIFAR-10, every synthesis method DC-BENCH runs there, gradient and distribution matching, drops to the level of random selection. DC-BENCH drops trajectory matching past 50 images per class because its memory and runtime do not scale.

Where the lead fades: soft labels. Giving real subsets a teacher's soft labels erases the advantage on harder datasets. Dey et al. (2026) isolate label type on Tiny ImageNet at 10 images per class. With one-hot labels, trajectory matching beats K-center at 20.1% against 11.4%. Giving every image one fixed teacher soft label lifts K-center to 27.1% and random real images to 26.1%, matching trajectory matching's 26.1%. Qin et al. (2024) instead label random real images with an early-stopped expert at 10 images per class. Trajectory matching keeps a 19-point lead on CIFAR-10 while falling behind on Tiny ImageNet.

Resource costs and architecture transfer. Vanilla trajectory matching carries heavy storage and memory costs. The 200 CIFAR experts take about 8 GPU-hours total and 60 MB each. Backpropagation memory grows linearly with NN times the synthetic batch size, reaching 144 GB across six GPUs in the largest run. Because the images are fitted to one architecture's experts, accuracy also drops on other architectures. On CIFAR-10 at 10 images per class, accuracy falls from 64.3% on the distilling ConvNet to 46.4% on a ResNet.

Constant-memory trajectory matching (TESLA, Cui et al., 2023). Standard backpropagation holds the computation graph of all NN student steps at once, so memory grows with NN. Cui et al. remove that growth by rearranging the gradient. Write gng_n=∇ℓbn(θ^t+n){}=\nabla\ell_{b_n}(\hat\theta_{t+n}) for the student's gradient at step nn, GG=∑n<Ngn{}=\sum_{n\lt N}g_n for their sum, and Δ\Delta=θt∗−θt+M∗{}=\theta^*_t-\theta^*_{t+M} for the expert's displacement. Because the student ends at θt∗−αG\theta^*_t-\alpha G, differentiating each gng_n through its own batch givesθ^t+N−θt+M∗=Δ−αG,∥Δ−αG∥2=∥Δ∥2−2α Δ⊤G+α2∥G∥2,∂∥Δ−αG∥2∂bn=2α(αG−Δ)⊤∂gn∂bn.\begin{aligned}\hat\theta_{t+N}-\theta^*_{t+M}&=\Delta-\alpha G,\\\|\Delta-\alpha G\|^2&=\|\Delta\|^2-2\alpha\,\Delta^\top G\\&\quad+\alpha^2\|G\|^2,\\\frac{\partial\|\Delta-\alpha G\|^2}{\partial \htmlData{gr=g18}{b_n}}&=2\alpha(\alpha G-\Delta)^\top\frac{\partial g_n}{\partial b_n}.\end{aligned}A first pass runs the student forward to accumulate GG. A second pass recomputes each gng_n and backpropagates through one batch at a time, holding only a single step's graph. On ImageNet-1k with batch size 100 and 50 steps, peak memory drops from 79.9 GB to 13.9 GB at roughly the same time per iteration.

TESLA at ImageNet-1k scale. Alongside the constant-memory gradient, Cui et al. give each synthetic image a soft label from the expert at checkpoint t+Mt+M. On 64 × 64 ImageNet-1k at 10 images per class with a four-layer ConvNet, TESLA reaches 17.8% with expert soft labels against 4.4% with one-hot labels. Random real images reach 3.6% and the full dataset reaches 33.8%. Once memory stops blocking ImageNet scale, the soft labels carry most of the accuracy.

Terms

Trajectory matching
Start a student at an expert checkpoint θt∗\theta^*_t, take NN steps on synthetic images, and minimize ∥θ^t+N−θt+M∗∥2/∥θt∗−θt+M∗∥2\|\hat\theta_{t+N}-\theta^*_{t+M}\|^2/\|\theta^*_t-\theta^*_{t+M}\|^2 over the pixels.
Experts
Networks trained on the real data with a checkpoint every epoch; trained once, before distillation (about 200 suffice on CIFAR).
Normalization
Dividing by the expert's own movement keeps late, slow stretches of training informative.
One-step case
N=M=1N=M=1, step size optimized: 1−cos⁡2(gS,gT)1-\cos^2(g_{\mathcal S},g_{\mathcal T}), gradient matching with one cosine over all weights.
Unrolled objective
Wang et al.: min⁡ ℓT(θ0−η~∇ℓS(θ0))\min\ \ell_{\mathcal T}(\theta_0-\tilde\eta\nabla\ell_{\mathcal S}(\theta_0)); to first order it rewards gT⊤gSg_{\mathcal T}^\top g_{\mathcal S}.
Where it wins
Small datasets, 1 to 50 images per class, one-hot labels: CIFAR-10 at 10 per class, 65.3% against 26.0% for random real images.
Where it does not
Above about 200 images per class on CIFAR-10 (shown for gradient and distribution matching), and on Tiny ImageNet against real images that also get a teacher's soft labels.
TESLA
Constant memory: sum G=∑gnG=\sum g_n first, then backpropagate one batch at a time (exact to first order in α\alpha); plus expert soft labels.

Sources

Connected notes

  • Dividing the numerator of softmax attention by its L2 norm, which fixes the output's length, follows the softmax loss curve, while dividing by the sequence length behind a gate, with scores clamped at 5 and gradients clipped, still gives loss spikes.

  • In wide transformers trained with Adam, correlated queries and keys make attention logits grow like dheadd_{\rm head} by the LLN rather than dhead\sqrt{d_{\rm head}}, so μ\muP rescales logits by 1/dhead1/d_{\rm head} and hidden learning rates by 1/fan-in1/\text{fan-in} to keep scales bounded with width.

  • Because each depth-attention weight reads only the RMS-normalized key v^j\hat v_j, inflating a sublayer's output norm buys it no extra weight; combined with softmax weights summing to 1, Block AttnRes holds output magnitudes below 2 against roughly 12 in the 48B baseline and cuts the gradient ratio across depth from 30x to 8x.

  • Bounding the moving-average step weight in [0,1][0,1] keeps every centroid inside the convex hull of its assigned points at large batches, where uncapped SGD steps overshoot and collapse.

Threads