Learning-Rate Schedules and Staged Pretraining: Cosine, WSD, and the Annealing Data Mix
The learning-rate curve looks like a tuning detail, but it decides two engineering facts: whether an intermediate checkpoint can be shipped, and whether you can safely change data, sequence length or budget midway through a run. This article aligns four public recipes (Llama 3, DeepSeek-V3, MiniCPM, OLMo 2) on one set of definitions and answers three questions: cosine or WSD for the main phase, how many tokens the annealing stage deserves, and what actually changes when you switch stages. The sequence-length dimension of the same problem is covered in The Cost Ledger of Long-Context Pretraining; debugging spikes is covered in Loss Spike Debugging.
1. Three questions to answer first
When people write a training plan, the learning-rate line usually holds a single number: peak 3e-4. What actually decides the outcome is three things, and the order matters.
- Where does this curve let you stop? A cosine schedule has exactly one endpoint; a model pulled from the middle of the curve is not comparable to anything. WSD lets you fork at any point in the stable phase and anneal afterwards, which yields a shippable model. This decides whether you can run ablations, add data midway, or continue training later.
- How many tokens should the decay stage get? Too few and the model never settles (MiniCPM's measurement: 2.5% is not enough); too many and you eat the main-phase budget. The fraction is not a constant — it shrinks as models and data quality grow.
- What changes at a stage boundary? The learning rate is only one item. Data mix, batch size, sequence length, auxiliary-loss weights and load-balancing bias are all in play. DeepSeek-V3 moved three of them in its final 500B tokens; changing only the learning rate produces a half-new, half-old state.
The short version: cosine versus WSD depends on whether you need to reuse intermediate artifacts; the annealing length depends on purpose (0.1%–0.3% to finish, 1%–10% to add capability); a stage switch needs a checklist, not a single learning-rate edit.
2. Four public recipes on one timeline
| Model | Warmup | Main-phase shape | Tail | Batch changes |
|---|---|---|---|---|
| Llama 3 405B | 8,000 steps | cosine, 8e-5 → 8e-7 over 1,200,000 steps | final 40M tokens linear to 0, sequence held at 128K | 4M → 8M (at 252M tokens) → 16M (at 2.87T tokens) |
| DeepSeek-V3 | 2,000 steps | 2.2e-4 constant to 10T tokens, then cosine down to 2.2e-5 over 4.3T tokens | last 500B: 333B at 2.2e-5, then 167B at 7.3e-6 | 3072 → 15360, ramped over the first 469B tokens |
| MiniCPM 2.4B | — | WSD: constant 0.01 through ~1T tokens | exponential f=0.5^((s-S)/T), T=5,000 steps (~20B tokens) | 3.93M tokens per step |
| OLMo 2 7B | 2,000 steps | cosine, peak 3e-4, calibrated to reach 10% of peak at 5T tokens | truncated at 4T, then mid-training with linear decay to 0 (50B tokens) | see Table 5 of the report |
A few details decide whether copying these recipes works.
- Llama 3's cosine targets 1% of peak (8e-5 → 8e-7), not 10%. The 10% setting belongs to its scaling-law experiments (peak 2e-4–4e-4, decayed to 0.1 of peak); the flagship used a much longer tail.
- Llama 3 couples weight decay to the learning rate: in the scaling-law runs, wd at each step is set to 0.1× the learning rate at that step. Change the schedule and the entire wd curve changes with it — an easy thing to drop when reproducing.
- DeepSeek-V3 spends 67.6% of its token budget on the constant segment (10T of 14.8T); cosine covers 29.1%; the last 3.4% is two constant plateaus. This is neither WSD nor cosine, but a hybrid of a long plateau, a short cosine, and a stepped tail.
- DeepSeek-V3 raises batch size 5× (3072 → 15360), which at 4K sequences is 12.6M → 62.9M tokens per step. Holding the learning rate while batch grows 5× shrinks the effective step per token, which is part of why the plateau can run to 10T.
- MiniCPM's peak of 0.01 is unusually high for a 2.4B model; it only holds together with a 3.93M-token batch. Copying the learning rate alone is meaningless.
3. Integrating the curve: why WSD is worse early and catches up at the end
You do not need the figures, only the area under the curve. Normalize peak to 1 and compare the mean learning rate over the same token budget T.
Cosine, starting at peak with a 0.1× floor — the long-tail shape Llama 3 uses:
WSD, with a stable phase of 90% and a linear decay of 10% to zero:
Over the same 1T tokens, WSD's mean learning rate is about 73% higher (0.95 / 0.55). That explains two observations: during the stable phase WSD's loss is higher (the model is still exploring rather than settling), and once decay begins the loss drops sharply, ending at or below cosine. MiniCPM describes this as "loss experiences a significant rapid decline" and attributes it to the collapse of weight-update magnitude alongside the learning rate: it measured the maximum element-wise weight change per layer in MiniCPM-2.4B and found updates track the learning rate, while the loss drop does not.
The engineering consequence is immediate: judging a change by "did the loss go down" during the stable phase will mislead you. At a high learning rate, loss sensitivity to data mix and small architectural tweaks is swamped — which is exactly why WSD supports forking and repeated annealing: comparisons happen after decay.
4. How many tokens the annealing stage deserves
The same word means different things across the four recipes, so align definitions first.
- Llama 3 annealing: the final 40M tokens, learning rate linear to zero, sequence held at 128K, with Polyak averaging of checkpoints. 40M / 15.6T = 0.26%. At 16M tokens per step that is 2–3 optimizer steps — its job is to average weights and finish the schedule, not to inject capability.
- DeepSeek-V3 tail: the final 500B / 14.8T = 3.4%, split into two plateaus (333B at 2.2e-5, 167B at 7.3e-6) with no zero endpoint. In the same window it dropped the MTP loss weight from 0.3 to 0.1 and the load-balancing bias update speed from 0.001 to 0 — three parts of one finishing move, not three unrelated tweaks.
- MiniCPM decay: the 0.036B wind-tunnel runs concluded that a decay of 10% of total tokens suffices and 2.5% falls short; but the 2.4B production run used only 20B (about 2%, against ~1T stable). The fraction shrinks with scale and cannot be copied as a constant.
- OLMo 2 mid-training: budgeted in FLOPs — pretraining ≥90%, mid-training 5%–10%. For 7B, 50B tokens is 1.2% of the 4.05T total; for 13B, a 300B run was also tried (about 5.4%).
A units warning: Llama 3 reports tokens, OLMo 2 reports FLOPs, and the two are not directly comparable. Change the sequence length and the FLOPs of the same token count multiply, which is why OLMo 2 expresses "how much compute the late stage gets". Pick one unit — FLOPs, or tokens at a fixed sequence length — before making budget claims, or you will conclude that OLMo 2's annealing is five times Llama 3's, which means nothing.
The only selection criterion is whether the tokens are there to finish or to add capability. Finishing needs 0.1%–0.3% (Llama 3's figure). Adding capability (math, code, multilingual, long context) needs 1%–10%, and the data mix must change — otherwise you are retraining the same distribution.
5. What a stage switch actually changes
Pull out every knob the four recipes turned at a boundary and you get a usable checklist.
- Data mix. Llama 3 adjusted during training: more non-English, upsampled math, fresher web data late, downsampled subsets later judged low quality. OLMo 2 switched to more strictly filtered web data plus academic, encyclopedic and synthetic math data for mid-training. The switch usually aligns with a learning-rate step but need not coincide exactly.
- Batch size and sequence length. Llama 3 doubled batch twice (252M and 2.87T tokens) for stability and efficiency, independent of the learning-rate stages; DeepSeek-V3 raised batch 5× within the first 469B tokens. Changing batch and learning rate at the same boundary makes failures unattributable — stagger them.
- Auxiliary-loss and regularizer weights. DeepSeek-V3's MTP weight 0.3 → 0.1 and load-balancing bias speed 0.001 → 0 both land in the last 500B. These "annealed weights" act like the learning rate: late in training you no longer want an auxiliary objective distorting the main one.
- Optimizer state. Adam moments should survive a stage boundary — a stage is a segment of one trajectory, not a restart. Reset only when the objective or architecture really changes (for example moving into SFT), and pair it with a short warmup.
- Checkpointing and EMA. DeepSeek-V3 maintains an exponential moving average of parameters asynchronously in CPU memory, with an explicit purpose: estimating post-decay performance early. Llama 3 Polyak-averages during annealing. Both address the same problem — the decay stage is short and noisy, so a single final checkpoint is unreliable.
- Evaluation baseline. A pre-decay checkpoint cannot be compared with a cosine endpoint. MiniCPM's figures show a visible step across the decay boundary; treating the pre-step point as "model capability" systematically underestimates it.
6. The annealing data mix: three measured results from microannealing
The annealing mix is one of the few hyperparameters that can be explored cheaply, precisely because the stage is short. OLMo 2 names the method microannealing: start from the finished pretraining checkpoint and run a ~200M-token annealing rehearsal instead of a 50B full run — more than two orders of magnitude cheaper — then pick the mix by target benchmarks. Three results are worth remembering.
- The domain share need not be large. On 7B, a math/web ratio of 35/65 gives GSM* 63.5, 10/90 gives 61, and the pre-annealing baseline is 28.5. Ten percent of domain data captures most of the gain; pushing the ratio higher starts crowding out general ability.
- A little duplication helps, a lot hurts. One copy of the math data → GSM* 61, two copies → 66, four copies → 65. When domain data is scarce, duplicating twice pays; at four copies it gives back.
- Rewriting beats piling up data. Math data whose answers were written as code gained substantially after rewriting into natural language; the same data unrewritten lost points. The bottleneck in annealing is usually whether the format matches the pretraining distribution, not volume.
MiniCPM took another route: mix high-quality SFT data directly into the decay stage (pretraining data plus SFT data), then run a separate ~6B-token SFT with the learning rate aligned to the end of annealing. Its assumption is that annealing is the overlap zone between pretraining and post-training — a reasonable fit for teams without a separate mid-training budget.
Two caveats. Microannealing results transfer only at the same checkpoint, tokenizer and sequence length; change the base model and you must rerun. And measure the target benchmark delta, not loss — annealing loss almost always drops, so the discrimination lives in task metrics.
7. Three ways to finish the tail: linear to zero, exponential, stepped constants
- Linear to zero: Llama 3's 40M tokens, OLMo 2's mid-training. The endpoint learning rate is exactly zero, so checkpoints are comparable and weight averaging is safe; the risk is that a very short decay writes the last few steps' gradient noise directly into the weights.
- Exponential: MiniCPM's f=0.5^((s-S)/T). Faster decay, a small non-zero endpoint, a good fit when the decay window is short but you still want to avoid a jitter at the very end.
- Stepped constants: DeepSeek-V3's 2.2e-5 → 7.3e-6. Easiest to implement (one number) and easiest to misuse: steps between plateaus create loss steps, and checkpoints from different plateaus are not directly comparable.
The criterion is simple: whether the endpoint is zero decides whether these checkpoints can be averaged or compared. Model soup and Polyak averaging require a zero-ending tail; a single-point delivery is fine with stepped constants.
8. Checkpoint selection, Polyak averaging and model soup
The three solve different problems and should not be conflated.
- Polyak averaging (Llama 3, during annealing): a running average over checkpoints inside the decay window suppresses end-of-run noise and yields a more stable delivery point. It assumes the learning rate is already low; otherwise you are averaging models at different temperatures.
- Model soup (OLMo 2, mid-training): run the same mix with different data orders, then average the weights. OLMo 2 reports soup results equal to or better than the single best checkpoint. The premise is identical mix, token count and learning-rate trajectory — it averages variance from data order, not bias from hyperparameters.
- EMA (DeepSeek-V3, throughout): maintained asynchronously during training, used mainly to preview post-decay performance — a decision tool, not a deliverable.
Implementation notes: summing in bf16 introduces visible rounding error, so accumulate in fp32 and cast back; and before averaging checkpoints from different stages, confirm parameter names and shapes match (averaging across an architecture change is not defined).
9. The loss step at a stage boundary: normal or broken
A loss step at the moment of a stage switch is expected; the question is whether it returns to trend.
- A learning-rate jump, a batch change or a data-distribution switch all produce one or more steps. Returning to the original trend within tens to hundreds of steps is normal; settling on a slightly lower or higher plateau is also normal, because the distribution changed.
- Sustained rise after the step, or repeated spikes on a batch timescale, should first raise suspicion of: bad samples in the data (duplicates, truncations, encoding errors), a broken packing boundary mask, position ids not reset across documents, or optimizer state wrongly reset at the switch.
- One easily missed stability detail: OLMo 2 reports that applying weight decay to embeddings drives the embedding norm down, the gradient norm up, and the spike score from 0.092 to 0.16. A global "wd 0.1" cannot be applied uniformly to all parameters.
- The learning-rate boundary is in the same report: peaks from 3e-4 up to 30e-4 were tried, and 30e-4 spiked during warmup and never fully recovered, so it was abandoned; 3e-4, 6e-4, 9e-4 and 12e-4 ended at virtually the same loss after decay. The safe band for peak learning rate is wider than folklore suggests; the hard boundary is warmup stability.
10. One-page recipe table
| Situation | Main phase | Tail | Key actions |
|---|---|---|---|
| From scratch, fixed budget, one deliverable | cosine to 1% of peak (Llama 3 style) | last 0.1%–0.3% linear to zero | decide wd coupling explicitly; raise batch in two steps for stability |
| Many forks, continued training, domain adaptation | WSD, constant stable phase | decay ≥10% (calibrated on small models), exponential or linear | always anneal from the last stable checkpoint to keep runs comparable |
| Add capability (math/code/multilingual) | cosine or WSD | mid-training at 1%–5% of budget, linear to zero | change the mix; pick ratios with ~200M-token microanneals first |
| Extend context | separate stage, fixed tokens per step | learning rate at the main phase's endpoint (DeepSeek used 7.3e-6) | see the long-context article for CP and masking |
| Before delivery | — | 40M–100B finishing anneal + Polyak/soup | zero-ending tail; average in fp32 |
11. Five traps
- Evaluating a pre-decay checkpoint as a product. A high stable-phase loss does not mean the model is bad, nor good — it means it has not settled.
- Changing total steps without rerunning cosine. Cosine is defined relative to the whole budget; change T and the curve shifts, invalidating every earlier checkpoint.
- Changing learning rate, batch and mix at the same boundary. Three simultaneous changes make failures unattributable; stagger at least one.
- Mixing token shares with FLOP shares. Change sequence length and the two diverge by a factor.
- Averaging weights when the tail never reached zero. You are averaging models at different temperatures, which usually ends worse than the single best point.
In one sentence: the shape of the curve decides where you may stop, the stage budget decides how much you pay to finish, and the switch checklist decides whether you end up with a half-new model. When the three line up, annealing is the last bit of gain rather than the last batch of incidents.
Further reading
- Pretraining Data Pipeline: the upstream of mixing and deduplication
- Pretraining Engineering: Checkpoints, Fault Tolerance and Stability: storage and recovery across stages
- The Cost Ledger of Long-Context Pretraining: the sequence dimension
- Scaling Law Ledger: how the token budget is set
- Loss Spike Debugging: locating spikes