Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
The Llama 3 herd,
explained.
The most interesting number in the Llama 3 paper isn't the parameter count — it's 15 trillion tokens. Scaling law orthodoxy says an 8-billion-parameter model should see about 160 billion tokens; Llama 3 fed it nearly a hundred times that. That looks wasteful, until you remember the model is trained once and answered billions of times. The right thing to optimize isn't the training bill — it's the lifetime bill. And once you count inference, over-training a small model is the frugal choice. Here's the arithmetic behind the herd.
What changes against Llama 2: the compute-optimal point is deliberately ignored
Rung 1 trains on 2 trillion tokens. This rung trains on 15 trillion, and the small models in the family are pushed furthest past where the compute-optimal allocation says to stop. That is not an accident or a bigger budget applied uniformly; it is a deliberate rejection of the objective that allocation optimises, and the reasoning is the most useful thing on this rung.
Compute-optimal scaling answers: given a fixed training budget, what model size and token count minimise loss? That is the right question if training is the cost you care about. For a model you intend to serve billions of times, it is the wrong question, because the lifetime compute is dominated by inference, and inference cost is set by the model's size — every query pays for every parameter, forever.
So the trade inverts. Spend more training compute than is optimal, on a smaller model, to get a model that is cheaper on every request it will ever answer. Stated in the units the scaling ladder uses: Chinchilla's ratio is roughly twenty training tokens per parameter, and an 8B model trained on 15 trillion tokens is at something closer to two thousand — two orders of magnitude past compute-optimal, on purpose. Training-optimal and inference-optimal are different objectives, and this rung is where the industry publicly picked the second one.
A herd, not a hero
Llama 3 is a family — an 8B, a 70B, and a flagship 405B — all dense, decoder-only transformers. Architecturally it is almost boringly conventional: the same transformer block, rotary position embeddings, grouped-query attention to shrink the KV cache, a bigger vocabulary. No exotic mechanism, no mixture-of-experts in the main models. If you were grading on novelty, you'd shrug.
But the paper's real contribution is a method thesis: quality at a given size comes overwhelmingly from data — how much, and how clean — and from a willingness to spend training compute lavishly to make the deployed model small. Llama 3 trained on ~15T tokens with aggressive filtering, dedup, and quality classifiers, and it deliberately pushed the smaller models far past the "optimal" token count. To see why that isn't a mistake, we need the scaling law it's departing from.
Spend extra training compute to over-train a small model on far more data than Chinchilla suggests, because the model is trained once but served billions of times — and inference, not training, dominates the lifetime bill.
The Chinchilla point
The Chinchilla scaling laws answered a specific question: given a fixed training compute budget, how should you split it between model size and training tokens to get the best model? Their empirical answer was a clean rule of thumb — scale parameters and tokens together, roughly 20 tokens per parameter. Under that rule an 8B model "should" see about 160B tokens; anything past that is, by Chinchilla's accounting, a poor use of the training budget, since the same FLOPs would buy more quality spent on a larger model.
Llama 3's 8B saw ~15T tokens — call it ~94× the Chinchilla-optimal count. By the training-compute yardstick, that is deep into diminishing returns: those last trillions of tokens each nudge quality only a little. So why do it? Because Chinchilla optimizes the wrong bill.
Trained once, served forever
Chinchilla counts only the training FLOPs. But a production model's compute has two parts, and they're paid on wildly different schedules. Training is a one-time cost. Inference is paid per query, forever, and a popular model answers billions of them. For a heavily-served model the inference total swamps the training total.
Both costs scale with parameters. Training a dense transformer costs about 6ND FLOPs (N params, D tokens); each token of inference costs about 2N FLOPs. Crucially, inference cost is proportional to N, the thing you deploy. So a smaller model is permanently cheaper to run — every query, forever. Over-training is the price you pay once, in training, to buy a smaller N at a target quality, and thereby cut the inference cost you pay always. This is the inference-optimal frontier, and it sits at a smaller model + more tokens than Chinchilla's training-optimal one.
The lifetime bill
Write the total lifetime compute as training plus inference over Q queries (each generating about t tokens):
First term: one-time training on D tokens. Second term: inference, paid per query, and it grows without bound as Q grows. Both are proportional to N — so shrinking the model helps both, but it helps the inference term Q times as often.
Now the key move. Over-training raises D (the training term) to buy a smaller N at fixed quality. That trade is worth it once the inference term dominates — i.e. once the model is served enough. Set the two terms equal to find the crossover query count:
Past Q* queries, inference has cost more than the entire training run — so any parameter you can shave off (paid for with extra tokens D) is repaid many times over. With D≈15T and t≈10³, Q*≈4.5×10¹⁰: beyond ~45 billion queries, inference rules the bill. A widely-deployed model blows past that quickly, which is exactly why over-training the small models is the frugal choice. The runnable version below computes the over-training ratio and shows inference overtaking training.
How Meta trained the Llama 3 herd
"The Llama 3 Herd of Models" comes from the Llama team at Meta, released in July 2024, and describes the 8B, 70B and 405B models released as Llama 3.1. All three are dense Transformers; the report chose that over mixture-of-experts to keep training stable at scale.
- Build the data. About 15T multilingual tokens after PII and safety filtering, a custom HTML extractor, deduplication at the URL, document (MinHash) and line level, heuristic filters, and model-based quality classifiers, including a fastText classifier and RoBERTa-based classifiers trained on Llama 2's quality judgments. The final mix is roughly 50% general knowledge, 25% math and reasoning, 17% code and 8% multilingual text.
- Size the flagship with a scaling law. IsoFLOP sweeps from 6×10^18 to 10^22 FLOPs, with models from 40M to 16B parameters, locate the compute-optimal token count at each budget. Extrapolated to the flagship's 3.8×10^25 FLOPs, almost 50 times the largest Llama 2, the fit points to about a 402B model on 16.55T tokens. A second step maps compute to the normalized log-likelihood of correct benchmark answers, and that log-likelihood to accuracy, fitted with both the sweep models and Llama 2 models; it forecast the 405B model's ARC-Challenge score closely.
- Pretrain the 405B model. AdamW at a peak rate of 8×10^−5, warmed up over 8,000 steps and decayed by cosine to 8×10^−7. The batch grows during training, from 4M tokens in 4,096-token sequences, to 8M tokens in 8,192-token sequences, to 16M. Documents packed into one sequence are masked so they cannot attend to each other, and the vocabulary has 128K tokens.
- Extend the context in six stages. From 8K to 128K tokens over about 800B tokens, moving to the next stage only when short-context performance has fully recovered and needle-in-a-haystack retrieval is perfect at the current length.
- Anneal. Over the final 40M tokens the learning rate falls linearly to zero while high-quality sources are upsampled, and checkpoints from the annealing phase are averaged (Polyak averaging) to give the final pretrained model.
- Post-train in six rounds. Each round trains a reward model on human preference pairs, now with an edited-response tier above the chosen one and without Llama 2's margin term; samples 10 to 30 responses per prompt and keeps the reward model's best (rejection sampling); fine-tunes on those plus synthetic data; then runs DPO on fresh preference pairs. Models from runs with different data or hyperparameters are averaged at each stage.
Why DPO, and how it was modified
Meta chose DPO over PPO because it needed less compute at this scale and did better, especially on instruction-following benchmarks such as IFEval. Two changes made it stable. Formatting tokens, the header and end-of-turn tokens shared by chosen and rejected answers, are masked out of the loss, because their contradictory gradients caused tail repetition and abruptly ended answers. And a negative log-likelihood term on the chosen answer, weighted 0.2, keeps the model from lowering the probability of good answers while it pushes rejected ones down.
Running on 16K GPUs
The 405B run used up to 16K H100 GPUs with four kinds of parallelism, tensor, pipeline, context and fully sharded data parallelism, at 38 to 43% model FLOPs utilization. Over one 54-day period there were 466 job interruptions, 419 of them unexpected and about 78% of those traced to confirmed or suspected hardware faults, yet effective training time stayed above 90%.
The DPO loss Llama 3 used, with its two changes
For a prompt x with a chosen response yw and a rejected one yl, Llama 3's post-training minimizes the DPO loss plus a likelihood term on the chosen response:
πθ,πref— the model being trained and the frozen fine-tuned model of the same roundβ = 0.1— how far the policy may move from the reference to separate the pairα = 0.2— the weight on the chosen answer's negative log-likelihood term- masking — header and end-of-turn tokens, shared by yw and yl, are left out of both log-probabilities
The first term only cares about the gap between chosen and rejected, so it can fall while both answers become less likely, a known way for DPO to degrade. The α term holds up the chosen answer's likelihood, so the gap opens mostly by pushing the rejected answer down. With α = 0 this is plain DPO; as β grows, the model stays closer to πref and learns less from each pair. Masking matters because a token present in both answers is pushed up through yw and down through yl at once, and Meta traced tail repetition and abruptly ended answers to that conflict.
What the Llama 3 report measured
The report compares the herd with Llama 2 and with contemporary models, including GPT-4, GPT-4o and Claude 3.5 Sonnet for the 405B, on knowledge, code, math, reasoning, tool use, long-context and multilingual benchmarks, plus human preference evaluations.
| Item | Llama 2 70B | Llama 3 405B |
|---|---|---|
| Pretraining tokens | 2T | 15.6T |
| Context | 4,096 | 8K, extended to 128K |
| Vocabulary | 32k | 128K |
| Post-training | rejection sampling, then PPO | rejection sampling, SFT and DPO, six rounds |
| Training compute | — | 3.8×10^25 FLOPs, about 50× Llama 2's largest |
| MMLU, 5-shot, instruct model | — | 87.3 |
| GSM8K, 8-shot chain of thought | — | 96.8 |
| HumanEval, 0-shot | — | 89.0 |
Meta's reading is that the 405B model is close to the leading closed models of mid-2024 on most benchmarks, and that the 8B and 70B models lead their size classes, the payoff of training them far past their compute-optimal token counts.
Negative results and limits. Annealing on small amounts of high-quality code and math raised the 8B model's GSM8K score by 24.0 points and MATH by 6.4, but gave the 405B model negligible gains, which the authors read as the flagship not needing in-domain examples to perform well. PPO was dropped because it cost more compute and did worse on instruction following. Removing the reward-model margin was itself a negative result for Llama 2's design: it stopped helping once preference data was scaled. Human evaluations against GPT-4o and Claude 3.5 Sonnet were mixed rather than clear wins. And reliability was a real cost: 419 unexpected interruptions in 54 days, most of them hardware.
What the authors admit, and what happened next
The returns are admitted to be diminishing — the loss curve keeps improving well past the compute-optimal point, which is the finding, but it improves slowly, so the strategy only makes sense when amortised over a very large number of queries. For anyone training a model they will serve occasionally, this is the wrong advice, and the conditional is the point rather than a caveat.
The data mixture is given only coarsely (roughly 50% general knowledge, 25% math and reasoning, 17% code, 8% multilingual, with no sources named), and 15 trillion tokens raises questions about the supply of text that the report does not settle — how much of that volume is high-quality, how much is repeated, and what the ceiling is. The data-quality argument on the scaling ladder is the other half of this conversation.
How it held up: over-training became standard practice for any model intended for deployment, and the framing — that a scaling law optimises an objective you must choose deliberately — is one of the most transferable ideas here. Read together, this rung and Chinchilla make the site's best case for why reading order matters: neither is wrong, they optimise different things, and knowing which is which is the entire skill.
Over-train, then count the bill
The whole argument is arithmetic. Chinchilla says ~20 tokens per parameter, so an 8B model is "optimal" at 160B tokens — but Llama 3 fed it 15T, an over-training ratio near 94×. Training costs 6ND once; inference costs 2N per token, per query, forever, and it scales with the parameter count you deploy — so an 8B is permanently cheaper to run than a 70B. Compute the ratio, compare per-query cost across sizes, and watch inference overtake training at high query volume. Change the token count or query volume and see the trade-off move.
Write the body of inference_cost. Everything else in the file is
already written; this is the function the paper is about. Press ▶ Run to check it against
the 5 assertions below — they start red.
- Chinchilla-optimal tokens are 20 per parameter
- Llama 3 8B on 15T is over-trained past 90x
- Training cost follows the 6ND rule
- Inference per query scales with params so a smaller model is cheaper
- At high query volume inference dominates the one-time training cost
Why it mattered
Llama 3 crystallized a shift in how the field thinks about scaling. Chinchilla was framed as "the" scaling law, but it answered a training-only question. Llama 3 (and its Llama 2 predecessor) made the inference-optimal view standard practice: because deployment cost, not training cost, dominates the lifetime of a popular model, the industry now routinely over-trains smaller models on trillions of tokens. The "right" model size shrank, and token counts exploded.
It also mattered as open weights. A frontier-class model whose weights anyone could download and fine-tune reset the ecosystem — it became the default base for countless downstream models, from multimodal systems to domain fine-tunes, precisely because a strong, cheap-to-serve base is the most useful thing you can hand the community. The paper's quiet lesson is that the frontier isn't only pushed by new mechanisms; sometimes it's pushed by taking a known recipe and being ruthless about data, scale, and the bill you'll actually pay.
Over-training isn't free quality — returns per token diminish, and some capabilities need a bigger model no matter how much data you pour in. The herd exists because the inference-optimal size depends on how heavily you plan to serve it.
Questions people ask about Llama 3
Did Llama 3 use PPO or DPO for post-training?
DPO. Each of Llama 3's six post-training rounds trained a reward model on human preferences, used it to pick the best of several sampled responses per prompt, fine-tuned on those selections plus synthetic data, and then ran Direct Preference Optimization on preference pairs. Meta reported choosing DPO over PPO because it needed less compute for models this large and performed better, especially on instruction-following benchmarks like IFEval. It modified DPO in two ways: formatting tokens shared by chosen and rejected answers were masked out of the loss, and a negative log-likelihood term on the chosen answer, weighted 0.2, was added, with β set to 0.1. Llama 2, by contrast, used rejection sampling followed by PPO.
How was the Llama 3 405B model trained?
In three pretraining phases followed by six post-training rounds. The main phase trained a dense 405B Transformer on 15.6T tokens at an 8K context, using AdamW with a peak learning rate of 8e-5 and a batch that grew from 4M to 16M tokens, on up to 16K H100 GPUs with tensor, pipeline, context and data parallelism. A long-context phase then extended the window from 8K to 128K tokens in six stages over about 800B tokens. Finally, annealing over the last 40M tokens decayed the learning rate to zero on upsampled high-quality data, and checkpoints were averaged. The total was about 3.8e25 FLOPs, a budget Meta's scaling-law forecast matched to a model of about 402B parameters.
How did Meta use scaling laws to choose the 405B size?
With a two-step forecast. First, IsoFLOP experiments at budgets from 6e18 to 1e22 FLOPs, training models from 40M to 16B parameters, located the compute-optimal number of training tokens at each budget; extrapolating that fit to the flagship's 3.8e25 FLOPs pointed to about 402B parameters trained on 16.55T tokens. Second, because loss alone does not say how a model will score on tasks, Meta related compute to the normalized log-likelihood of correct answers on benchmarks, and that log-likelihood to accuracy, using both the small sweep models and older Llama 2 models. The forecast predicted the 405B model's ARC-Challenge accuracy closely, which is the evidence the two-step method works.
Why does Llama 3 train small models far past the Chinchilla-optimal point?
Because the small models are meant to be served, and serving cost depends on model size, not on how many tokens the model saw in training. Meta's own scaling-law analysis placed the 405B flagship near compute-optimal for its budget, but the 8B and 70B models were trained on the same roughly 15T tokens, far more than a compute-optimal allocation would give them. The report says the resulting models perform better than compute-optimal models at the same inference budget. Returns per extra token diminish, so the strategy pays off only when a model answers enough queries to amortize the extra training compute, which for widely used open models it does.
How often did Llama 3 405B training get interrupted?
Often. During one 54-day snapshot of pretraining on up to 16K H100 GPUs, Meta counted 466 job interruptions: 47 planned, for maintenance such as firmware upgrades, and 419 unexpected. About 78% of the unexpected ones were confirmed or suspected hardware problems, with GPU faults the largest category. Despite this, automation kept effective training time above 90%, and only three interruptions needed significant manual intervention. The report also notes subtler effects at this scale, such as throughput varying by one or two percent over the day with temperature, and the data center's power draw swinging by tens of megawatts when thousands of GPUs pause and resume together.
4 questions to test what you just read
Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.
Chinchilla's rule is about 20 tokens per parameter. How many tokens per parameter did the 405B flagship see, and how does that compare with the 8B model's ratio?
Show answer
15.6T ÷ 405B ≈ 39 tokens per parameter, about twice Chinchilla's rule and close to the report's own compute-optimal forecast. The 8B model saw roughly 15T ÷ 8B ≈ 1,900, nearly 50 times the flagship's ratio, which is where the over-training lives.
In a DPO pair, the chosen and rejected answers both end with the same end-of-turn token. Without masking, what signal does that token get, and what failure did Meta see?
Show answer
It sits in both answers, so the loss pushes its probability up through yw and down through yl at once, a contradictory signal on the token that decides when an answer stops. Meta saw tail repetition and abruptly generated termination tokens, and fixed it by masking formatting tokens out of the loss.
Annealing on high-quality math raised the 8B model's GSM8K score by 24.0 points but did almost nothing for the 405B. Which model makes the better instrument for judging a candidate dataset, and why?
Show answer
The smaller model: it responds to small amounts of in-domain data that the flagship no longer needs, so its gain is a visible signal of the data's value. Meta used exactly this, annealing a partly trained 8B model on candidate data to judge it, instead of spending a large run to find out.
Meta reported 419 unexpected interruptions in 54 days. On average, how often is that, and why does it argue for automated recovery over people?
Show answer
419 ÷ 54 ≈ 7.8 per day, roughly one every three hours, around the clock. A human-in-the-loop restart at that rate would lose hours every day; automated detection and restart kept effective training time above 90%, with only three cases needing significant manual work.
The open-weights line
Five releases you can actually download, in the order each one answered the last. This is where "what does a frontier recipe look like" is documented in public.
- 1Llama 22023
- 2Llama 32024
- 3Qwen32025
- 4Kimi K22025
- 5Kimi K32026
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Paper Breakdowns
- Attention Is All You NeedThe paper that introduced the Transformer — the architecture underneath GPT, BERT, Claude, and Gemini. Self-attention, Query/Key/Value, multi-head attention, positional encoding, and the real BLEU results, explained in depth with analogies and animated visuals, not just equations.Read →
- BERTThe paper that made "pre-train once, fine-tune anywhere" the default for NLP. Bidirectional context, masked language modeling, next-sentence prediction, the [CLS]/[SEP] tokens, and the GLUE sweep — explained with analogies, not just equations.Read →
- Chain-of-Thought PromptingShow a model a few worked examples with their reasoning and it starts solving problems it used to fail. Why reasoning emerges only at scale, the GSM8K jump, zero-shot "Let's think step by step", and how CoT seeded modern reasoning models.Read →
- LoRAThe paper that made fine-tuning affordable. Freeze the giant pretrained model and train two tiny low-rank matrices instead — up to 10,000x fewer trainable parameters, no extra inference latency, and swappable per-task adapters. The road to QLoRA and PEFT.Read →
- Direct Preference OptimizationRLHF without the RL. Align a model to human preference pairs with one simple classification-style loss — no separate reward model, no unstable reinforcement learning. Why "your LM is secretly a reward model", and how DPO became the default alignment method.Read →
- ChinchillaThe compute-optimal scaling law that said models were too big. Parameters and training tokens should scale together — ~20 tokens per parameter — so a 70B model trained on 1.4T tokens beat the 280B giants. Why every model since trains on trillions of tokens.Read →