Chapter 0 · Pipeline Overview¶
0.1 What stages does an LLM go through from scratch to deployment, and what problem does each stage solve? ★★★¶
One-sentence answer
A modern LLM typically goes through data preparation, pretraining, mid-training, supervised fine-tuning (SFT), preference optimization and reinforcement learning (RL), distillation, evaluation and deployment. The pretraining-type stages give the model knowledge and capabilities from massive amounts of text; the post-training stages turn a base model that can only continue text into an assistant that follows instructions, matches human preferences and reasons; and distillation, evaluation and deployment deliver the model reliably at a controlled cost.
I will address this in three parts: where the model's capabilities come from, how its behavior is shaped, and how the model is delivered for use.
(1) Capabilities come from data preparation, pretraining and mid-training; these three steps determine what the model knows and what it can do.
- Data preparation: raw text is collected from web pages, code, books, papers and other sources, then cleaned, deduplicated, quality-filtered and mixed, yielding a training corpus on the order of ten trillion tokens. The quality and composition of the data largely determine the ceiling of the model's capabilities (see Chapter 1).
- Pretraining: next-token prediction on this corpus, that is, predicting the next token from the preceding text. To predict the next token accurately, the model must learn grammar, factual knowledge, code and patterns of reasoning. This is the most compute-intensive stage, and its product is called the base model (see Chapter 2).
- Mid-training: near the end of pretraining, the data switches to more carefully curated math, code, reasoning and long-document data, combined with learning-rate annealing, and the context length is extended to tens of thousands or even more than a hundred thousand tokens, thereby laying the foundation for post-training (see Chapter 4).
(2) Behavior is shaped by SFT, preference optimization and RL; these three steps determine how the model uses these capabilities.
A base model has rich knowledge, but it can only keep writing. For example, if asked "What is the capital of France?", it may well continue with more similar questions, because on the web a question is often followed by more questions. This is why post-training is needed:
- SFT (supervised fine-tuning): training continues on written "prompt–response" demonstrations, with the loss computed only on the response. The model thereby learns the conversation format and how to follow instructions; in essence, this is imitation (see Chapter 5).
- Preference optimization: comparisons between responses (A is better than B) are collected, and either a reward model is trained first and then optimized against with RL (that is, RLHF), or DPO trains directly on the preference data. The model thereby learns to choose, among several responses that are all "correct", the one that is more helpful and safer (see Chapter 6 and Chapter 7).
- RL with verifiable rewards (RLVR): on tasks such as math and code whose correctness can be checked automatically, reinforcement learning uses "whether the answer is correct" as the reward. The model thereby learns to produce long chains of reasoning, self-checking and backtracking; this is the core of reasoning models such as o1 and DeepSeek-R1 (see Chapter 8).
(3) Delivery is completed by distillation, evaluation and deployment; these three steps determine whether the model can be used cheaply and reliably.
- Distillation: a small model (the student) is trained on data generated by, or the output distributions of, a large model (the teacher), so that the small model reaches capabilities close to the large model at a much lower inference cost (see Chapter 9).
- Evaluation: evaluation is not the last step but runs through the entire process. During pretraining it is used to monitor training and compare data; during post-training it is used to select checkpoints and to detect capability regressions and safety problems (see 0.6).
- Deployment: inference cost and latency are reduced through quantization, KV cache management, speculative decoding and similar techniques, and safety safeguards are added; see the "Inference, Evaluation and Deployment" direction.
In summary: pretraining determines the ceiling of the model's capabilities, post-training determines how those capabilities are invoked and presented, and distillation and deployment determine the cost of use.
The stages at a glance:
| Stage | Input data | Training objective | Output |
|---|---|---|---|
| Data preparation | Raw web pages, code, books, papers, etc. | None (cleaning, deduplication, filtering, mixing) | A training corpus on the order of ten trillion tokens |
| Pretraining | The training corpus | Next-token prediction | Base model |
| Mid-training | Curated math, code, reasoning and long-document data | Next-token prediction | A base model with stronger key capabilities and longer context |
| SFT | "Prompt–response" demonstrations | Cross-entropy computed only on the response | An initial chat model that follows instructions |
| Preference optimization | Comparisons between responses | Reward maximization under a KL constraint, or the DPO loss | A chat model better aligned with human preferences |
| RLVR | Tasks with reference answers or test cases | Maximize a verifiable reward | Reasoning model |
| Distillation | Teacher-generated data or output distributions | Imitate the teacher's outputs | A small model with capabilities close to the teacher |
Going deeper: the products of each stage, using DeepSeek as an example
(1) One base model gives rise to several post-trained versions.
DeepSeek-V3-Base is the base model after pretraining (including context extension). SFT and RL on top of it produce the chat model DeepSeek-V3 (DeepSeek-AI 2024); large-scale RLVR on top of it produces the reasoning models DeepSeek-R1-Zero and DeepSeek-R1; and SFT of Qwen2.5 and Llama on about 800K samples generated by R1 produces the small DeepSeek-R1-Distill models (DeepSeek-AI 2025).
| Product | Stages it went through | Type |
|---|---|---|
| DeepSeek-V3-Base | Data preparation → pretraining (14.8T tokens) → context extension to 128K | Base model |
| DeepSeek-V3 | V3-Base → SFT (about 1.5M samples) → RL (GRPO) | Chat model |
| DeepSeek-R1-Zero | V3-Base → RLVR directly, without SFT | Reasoning model (poor readability) |
| DeepSeek-R1 | V3-Base → cold-start SFT → reasoning RL → rejection sampling and SFT → RL for all scenarios | Reasoning model |
| DeepSeek-R1-Distill-Qwen-32B, etc. | Qwen2.5 or Llama → SFT on R1's ~800K samples | Small reasoning model obtained by distillation |
(2) The stages feed back into one another: models from later stages produce data for other stages.
In DeepSeek-V3's SFT data, the reasoning portion was generated precisely by an internal DeepSeek-R1 model (DeepSeek-AI 2024). Llama 3's post-training was iterated for six rounds, each round using the model from the previous round to sample and filter the training data for the next round (Dubey et al. 2024). The actual process is therefore more like a loop than a one-directional pipeline.
(3) The same question gets different treatment from models at different stages.
Take "What is the capital of France?" as an example. A base model may continue with "What is the capital of Germany? What is the capital of Italy?"; a model after SFT answers "Paris" directly; after preference optimization, the length, tone and safety of the answer better match people's preferences; and a reasoning model first produces a thinking process and then gives the answer, which on such a simple question actually spends unnecessary tokens.
Follow-up questions
Follow-up 1: Which of these stages is the most important?
Pretraining determines the ceiling, post-training determines how much of that ceiling is realized, and neither can replace the other. On the one hand, post-training can hardly fill in knowledge missing from pretraining: Gekhman et al. (2024) found that models learn new facts through fine-tuning slowly, and that once they do, their tendency to hallucinate increases. On the other hand, without post-training, the capabilities of a base model are hard to use conveniently. For reasoning, the prevailing view is that RL mainly elicits and amplifies capabilities the base model already has, so the stronger the base model, the higher the ceiling RL can reach (see Chapter 8).
Follow-up 2: Why is post-training often iterated over multiple rounds?
Because post-training data can be produced by the current best model, so as the model improves, the data improves with it. In Llama 3, for example, each round first trains a reward model, then has the current model sample several responses per prompt and uses the reward model to pick the best as SFT data (that is, rejection sampling), and then runs SFT and DPO in turn; the resulting new model is used for sampling in the next round, for six rounds in total (Dubey et al. 2024). In addition, each round can add targeted data for weak areas identified by evaluation.
Follow-up 3: Why do we say evaluation runs through the whole process rather than being the last step?
Because almost every stage's decisions depend on evaluation. The data mixture is determined by evaluation results from small-model experiments, anomalies during pretraining are detected through the loss and downstream metrics, and post-training relies on evaluation to select checkpoints and detect regressions. If evaluation were done only once at the end, by the time a problem was found it could no longer be rolled back cheaply (see 0.6 for details).
Common mistakes
- Do not say "SFT teaches the model knowledge": Knowledge comes mainly from pretraining; SFT mainly teaches the conversation format and behavior, and forcing new knowledge in through fine-tuning may actually increase hallucination.
- Do not conflate RLHF with RL in general: In RLHF the reward comes from a reward model trained on human preferences, whereas in RLVR the reward comes from automatic checks by rules or programs; in modern pipelines the two usually coexist.
- Do not describe the process as a strictly one-directional pipeline: In practice, post-training is iterated over multiple rounds, and models from later stages also produce data for other stages.
0.2 How do the stages differ in data volume, share of compute and training objective? ★★¶
One-sentence answer
From pretraining to post-training, the data volume drops from ten trillion tokens to thousands to millions of samples, while the quality requirements and acquisition cost of each sample rise stage by stage; compute has traditionally gone overwhelmingly to pretraining, but with the arrival of reasoning models the share of RL is rising quickly; and the training objective shifts from next-token prediction on all tokens to an SFT loss computed only on the response, a preference loss, and an RL objective that maximizes reward.
I will address this in three parts: data volume, share of compute and training objective.
(1) The data volume decreases stage by stage, while the quality and acquisition cost of each sample increase.
Pretraining uses web pages, code and books on the order of ten trillion tokens; for example, Llama 3 used about 15.6T tokens and Qwen3 about 36T tokens. Mid-training typically ranges from tens of billions to a few trillion tokens; SFT generally uses thousands to millions of demonstrations; preference data usually consists of tens of thousands to a million comparisons; and RLVR often uses only thousands to tens of thousands of prompts, but each prompt is sampled repeatedly. The data volume decreases because later-stage data is more expensive: pretraining data can be crawled from the web, whereas demonstrations and preferences require human annotation or generation by a strong model, and verifiable tasks additionally require reliable answers or test cases. At the same time, the purpose of the later stages is mainly to shape behavior and elicit capabilities rather than to inject knowledge, so they do not need as much data.
(2) Compute has traditionally gone overwhelmingly to pretraining, but the share of RL is rising quickly.
Take DeepSeek-V3: of roughly 2.79M H800 GPU hours in total, pretraining accounts for about 95.5%, context extension for about 4.3%, and post-training for only about 0.2% (DeepSeek-AI 2024). Reasoning models, however, have changed this ratio. Every RL step must first have the model generate responses autoregressively (called rollouts); the responses of reasoning models run to thousands or even tens of thousands of tokens, and each prompt is sampled multiple times, so generation is very expensive. At the same time, OpenAI reported that o1's performance keeps improving with more RL training compute, which has led labs to keep increasing their investment in RL. For example, DeepSeek-V3.2's post-training compute budget already exceeds 10% of the pretraining cost (DeepSeek-AI 2025).
(3) The training objective gradually shifts from "fitting the data distribution" to "optimizing a reward".
- Pretraining and mid-training: next-token prediction on all tokens, that is, maximizing the likelihood of the training text, with the goal of fitting the data distribution itself.
- SFT: the loss is still cross-entropy, but it is computed only on the response, with the prompt excluded by a loss mask; the goal is to imitate the responses in the demonstrations.
- Preference optimization: RLHF first trains a reward model from comparison data with the Bradley–Terry model and then maximizes the reward under a KL constraint; DPO rewrites this objective as a classification-style loss computed directly on preference pairs.
- RLVR: directly maximizes a reward given by rules or programs, for example 1 point for a correct answer and 0 otherwise.
The most fundamental difference among these objectives is where the training data comes from. Pretraining, SFT and offline DPO learn from fixed data prepared in advance (off-policy), so the model never sees what happens after it makes a mistake; RLHF and RLVR learn from responses sampled by the current model itself (on-policy), so the model can see and correct its own mistakes, at the price of having to generate at every step.
In summary: the later the stage, the less but more refined the data, and the closer the supervision signal is to the final goal; and the rise of RL is making the compute distribution more balanced than "almost all in pretraining".
Comparing the stages:
| Stage | Typical data volume | Share of compute | Training objective | Data source |
|---|---|---|---|---|
| Pretraining | On the order of ten trillion tokens | Traditionally the vast majority (about 95% for DeepSeek-V3) | Next-token prediction on all tokens | Fixed corpora such as web pages |
| Mid-training | Tens of billions to a few trillion tokens | Small (about 5%–10% of training FLOPs for OLMo 2) | Next-token prediction | Fixed curated corpora |
| SFT | Thousands to millions of demonstrations | Very small | Cross-entropy only on the response | Demonstrations written by humans or strong models |
| Preference optimization | Tens of thousands to a million comparisons | Very small | Reward maximization under a KL constraint, or the DPO loss | Comparisons labeled by humans or AI |
| RLVR | Thousands to tens of thousands of prompts, each sampled repeatedly | Rising quickly (over 10% of pretraining for DeepSeek-V3.2) | Maximize a verifiable reward | The model's own samples |
Going deeper: the objective of each stage, and actual numbers on the compute distribution
(1) The objectives of the stages: the form shifts from likelihood to reward.
Pretraining and mid-training minimize the negative log-likelihood over all positions:
where \(x_t\) is the \(t\)-th token, \(x_{<t}\) are all the tokens before it, \(T\) is the sequence length, and \(\theta\) are the model parameters. SFT uses the same form, but sums only over the tokens of the response \(y\), with the prompt \(x\) serving only as the condition:
RLHF and RLVR maximize the expected reward under a KL constraint:
where \(\mathcal{D}\) is the distribution of prompts, \(\pi_\theta\) is the policy being trained (that is, the model itself), \(\pi_{\text{ref}}\) is the reference model (usually the SFT model), and \(\beta\) controls the strength of the KL constraint. In RLHF, \(r\) is a learned reward model; in RLVR, \(r\) is a score given by rules or programs (some RLVR recipes drop the KL term). DPO rewrites this objective as a loss computed directly on preference pairs:
where \(y_w\) is the preferred response, \(y_l\) is the dispreferred response, and \(\sigma\) is the sigmoid function (see Chapter 7 for the derivation).
(2) Actual numbers on the compute distribution: post-training compute relative to pretraining rose from about 0.2% to over 10% within one year.
| Model | Pretraining | Post-training / RL | Notes |
|---|---|---|---|
| DeepSeek-V3 (DeepSeek-AI 2024) | 2,664K GPU hours, plus 119K for context extension | 5K GPU hours, about 0.2% of pretraining | Excludes prior research and ablation experiments |
| DeepSeek-R1 (DeepSeek-AI 2025) | Reuses V3-Base | About 147K GPU hours (R1-Zero about 101K, R1 about 41K, SFT data creation about 5K), about 5% of V3's total training | Figures from an appendix of the paper's updated version |
| Olmo 3 Think 32B (Olmo et al. 2025) | About 47 days (including mid-training and long-context extension) | About 9 days (SFT about 2 days, DPO about 18 hours, RL about 5 days) | Wall-clock time on up to 1024 H100s |
| DeepSeek-V3.2 (DeepSeek-AI 2025) | — | Post-training compute budget exceeds 10% of the pretraining cost | The paper gives only the ratio |
(3) RL compute is growing so quickly because generation is the main cost.
Each step of pretraining and SFT needs only one forward and one backward pass, and all positions in a sequence can be computed in parallel; each RL step, by contrast, must first generate complete responses autoregressively, and generation proceeds one token at a time, which makes it hard to fully use the GPU's parallelism. The responses of reasoning models run to thousands or tens of thousands of tokens, and each prompt must also be sampled as a group of responses to estimate the advantage (how much better a response is than average), so generation is often the most time-consuming part of RL training.
Follow-up questions
Follow-up 1: Post-training uses so little compute; why is its effect so pronounced?
Because post-training mainly adjusts how the model uses capabilities it already has, rather than learning new knowledge. LIMA (Zhou et al. 2023) obtained a well-performing conversational model with SFT on only 1,000 curated demonstrations, which led the authors to propose the "superficial alignment hypothesis": a model's knowledge and capabilities are acquired almost entirely in pretraining, and alignment mainly teaches the model which format and style to answer in. Changing the output style requires far smaller updates than learning knowledge, so a small amount of compute can produce a pronounced change. This hypothesis does not fully hold for reasoning, however: the gains from reasoning RL keep growing with compute, which is precisely why the share of RL compute is rising.
Follow-up 2: How should the "data volume" of the RL stage be measured?
Both the number of prompts and the total number of sampled tokens should be considered; looking only at the number of prompts severely underestimates it. For example, Qwen3's reasoning RL stage used only 3,995 "query–verifier" pairs (Yang et al. 2025), but each query is sampled repeatedly during training, and each generation may run to thousands of tokens. The total number of tokens actually processed in the RL stage is therefore far larger than the number of prompts suggests, which is also why it is so compute-intensive.
Follow-up 3: SFT and RL train the same model; why is one called off-policy and the other on-policy?
The difference lies in whether the training data is generated by the current model itself. In SFT the responses are written by others, and during training the model always sees the correct preceding text (teacher forcing), never seeing how to continue after making a mistake of its own; this is called exposure bias. In RL the responses are sampled by the current model, so the model sees its own mistakes and is corrected by the low reward. This is one reason RL can bring improvements that SFT struggles to provide (see the discussion of on-policy distillation in Chapter 9).
Common mistakes
- Do not conclude that post-training is unimportant because its share of compute is small: Post-training determines whether the model can be used at all, and the RL compute of reasoning models has already reached a substantial fraction of pretraining.
- Do not compare the data volumes of pretraining and SFT directly in tokens: SFT is usually measured in samples and computes the loss only on the response, so the two are measured differently.
- Do not call DPO an on-policy method: Standard offline DPO uses preference pairs collected in advance and is off-policy; only online or iterative DPO constructs preference pairs from the current model's samples.
0.3 Using Llama 3, DeepSeek-V3/R1 and Qwen3 as examples, what does a complete modern training recipe look like? ★★¶
One-sentence answer
All three share the same skeleton: pretraining on ten-plus to tens of trillions of tokens, annealing on high-quality data and extending the context near the end of pretraining, and then post-training with SFT plus preference optimization or RL. They differ in emphasis: Llama 3 is a dense model whose post-training iterates "reward model + rejection-sampling SFT + DPO" for six rounds; DeepSeek uses MoE and FP8 to lower the cost of pretraining and trains the reasoning model R1 with large-scale RLVR; and Qwen3 uses a four-stage post-training to fuse thinking and non-thinking modes into one model, and uses distillation to train its small models.
I will go through the three models in turn and then summarize what they have in common.
(1) Llama 3: a scaled-up dense model, plus simple, stable and iterable post-training.
Llama 3's flagship is a 405B-parameter dense Transformer pretrained on about 15.6T tokens (Dubey et al. 2024). Pretraining has three steps: the bulk of training is done with a shorter context; the context is then extended from 8K to 128K in six stages; and finally, over the last 40M tokens, the learning rate is annealed linearly to 0 while the highest-quality data is upsampled. Post-training is deliberately kept simple: each round first trains a reward model, then uses it to pick the best response from several samples of the current model as SFT data (rejection sampling), and then runs DPO, for six rounds in total. The paper states explicitly that they tried PPO but found that DPO required less compute for large models and also performed better.
(2) DeepSeek-V3 and R1: low-cost MoE pretraining, plus reasoning training centered on RL.
DeepSeek-V3 is an MoE model with 671B total parameters, of which only 37B are activated per token; it is pretrained on 14.8T tokens and uses FP8 mixed-precision training, multi-token prediction and other techniques to reduce cost and improve efficiency, after which YaRN extends the context in two steps from 4K to 32K and then to 128K (DeepSeek-AI 2024). On the same base model, DeepSeek-R1 follows a route centered on RL (DeepSeek-AI 2025). R1-Zero does no SFT at all and runs GRPO directly with rule-based rewards; long chains of reasoning and self-reflection emerge on their own, but the outputs are hard to read and often mix Chinese and English. To fix these problems, R1 uses four stages:
- Cold-start SFT: SFT on thousands of readable long-CoT (chain-of-thought) examples, to fix the output format first.
- Reasoning RL: GRPO with rule-based rewards on math, code and similar tasks, plus a language-consistency reward that reduces language mixing.
- Rejection sampling and SFT: the model after RL is used to sample and filter about 600K reasoning samples, which are combined with about 200K non-reasoning samples to redo SFT on the base model.
- RL for all scenarios: reasoning tasks continue to use rule-based rewards, while general tasks use reward models to assess helpfulness and harmlessness.
Finally, these roughly 800K samples were also used directly to distill small models from the Qwen2.5 and Llama families.
(3) Qwen3: staged pretraining, post-training that fuses thinking modes, and distillation for small models.
Qwen3 is pretrained on about 36T tokens covering 119 languages and dialects, in three stages: a general stage of over 30T tokens; a reasoning stage of about 5T tokens that raises the share of STEM, code, reasoning and synthetic data and speeds up learning-rate decay; and a long-context stage that extends the context to 32K (Yang et al. 2025). The flagship models' post-training has four stages: a long-CoT cold start, reasoning RL, thinking mode fusion (using /think and /no_think flags so that one model supports both a thinking and a non-thinking mode), and general RL. For the small dense models from 0.6B to 14B and the 30B-A3B MoE model, Qwen3 no longer repeats all four stages but instead runs off-policy distillation followed by on-policy distillation, which the paper reports requires only about 1/10 of the GPU hours of the four-stage training.
In summary: the shared skeleton of the three is "large-scale pretraining → high-quality annealing and long-context extension → SFT as the foundation, with preference optimization or RL on top"; they differ mainly in architecture (dense or MoE), in the core post-training algorithm (DPO or RL), and in whether reasoning is trained specifically.
Comparing the three recipes:
| Llama 3 | DeepSeek-V3 / R1 | Qwen3 | |
|---|---|---|---|
| Architecture | Dense, 405B | MoE, 671B total and 37B activated | Dense (0.6B–32B) and MoE (30B-A3B, 235B-A22B) |
| Pretraining data | About 15.6T tokens | 14.8T tokens | About 36T tokens, 119 languages and dialects |
| Annealing and long context | Annealing over the last 40M tokens; 8K to 128K in six steps | Two-step YaRN extension, 4K → 32K → 128K | A reasoning stage of about 5T tokens; extension to 32K |
| Core of post-training | Reward model + rejection-sampling SFT + DPO, six rounds | V3: SFT + GRPO; R1: cold start → reasoning RL → rejection-sampling SFT → RL for all scenarios | Cold start → reasoning RL → thinking mode fusion → general RL |
| Small models | 8B and 70B also fully pretrained, on far more tokens than compute-optimal | SFT distillation on R1's data | Off-policy distillation → on-policy distillation |
Going deeper: details worth remembering from the three recipes, and changes after 2025
(1) Llama 3: choosing the scale with scaling laws, and finishing with annealing and checkpoint averaging (Dubey et al. 2024).
| Aspect | Details |
|---|---|
| Scale decision | A two-step method predicts downstream performance: first fit compute against the negative log-likelihood on benchmarks, then fit the negative log-likelihood against accuracy; extrapolation suggested about 402B parameters and 16.55T tokens, and 405B was chosen in the end |
| Compute | About \(3.8\times10^{25}\) FLOPs, on up to 16K H100s |
| Data mix | About 50% general knowledge, 25% math and reasoning, 17% code, 8% multilingual |
| Annealing | Over the last 40M tokens the learning rate is decayed linearly to 0, and several checkpoints from the annealing phase are averaged (Polyak averaging) to produce the final pretrained model |
| Post-training | Rejection sampling draws 10–30 responses per prompt and lets the reward model pick; at each of the RM, SFT and DPO stages, models trained with different data or hyperparameters are weight-averaged |
(2) DeepSeek: read the cost figures carefully (DeepSeek-AI 2024; DeepSeek-AI 2025).
| Aspect | Details |
|---|---|
| V3 training cost | About 2.788M H800 GPU hours, about $5.576M at $2 per GPU hour; the paper states explicitly that this excludes prior research and ablation experiments on architectures, algorithms and data |
| V3's SFT data | About 1.5M samples; the reasoning data was generated by an internal DeepSeek-R1 model and filtered by rejection sampling |
| R1-Zero | AIME 2024 pass@1 rose from 15.6% to 71.0%, and to 86.7% with majority voting |
| R1's cost | An appendix of the paper's updated version gives about 147K H800 GPU hours, about $294K (excluding V3-Base itself) |
| Distillation comparison | DeepSeek-R1-Distill-Qwen-32B, trained with SFT on R1's data, reaches 72.6% on AIME 2024, whereas DeepSeek-R1-Zero-Qwen-32B, trained with large-scale RL directly on the same base model, reaches only 47.0% |
(3) Qwen3: data engineering and thinking mode fusion (Yang et al. 2025).
| Aspect | Details |
|---|---|
| Data sources | Qwen2.5-VL recognizes text in a large volume of PDF-like documents; Qwen2.5, Qwen2.5-Math and Qwen2.5-Coder generate trillions of tokens of synthetic data |
| Data mix | Over 30T tokens are labeled along several dimensions such as educational value, domain and safety, and the mixture is optimized at the instance level through ablations on small proxy models |
| Long context | The RoPE base is raised from 10,000 to 1,000,000 (ABF), and at inference time YaRN and Dual Chunk Attention extend the usable length by a further factor of four |
| Reasoning RL | Only 3,995 "query–verifier" pairs, with GRPO as the algorithm |
| Thinking budget | When the thinking length reaches a user-set limit, thinking is forcibly stopped and an instruction saying "time is limited, answer directly" is inserted; the paper notes that this ability emerges naturally after thinking mode fusion |
| Distillation versus RL | On Qwen3-8B, starting from the same off-policy-distilled checkpoint, RL took 17,920 GPU hours, whereas on-policy distillation took only 1,800 GPU hours and performed better |
(4) Changes after 2025: investment in RL keeps growing, and how to organize thinking modes is still being explored.
- The share of RL compute keeps rising: DeepSeek-V3.2's post-training compute budget exceeds 10% of the pretraining cost, and its post-training uses "specialist distillation + mixed RL" (DeepSeek-AI 2025).
- Hybrid and separate models coexist: DeepSeek-V3.1 switches between thinking and non-thinking modes within one model via the chat template, whereas Qwen went back to training separate Instruct and Thinking models in Qwen3-2507.
- Pretraining puts more emphasis on stability and token efficiency: Kimi K2 (about 1T total and 32B activated parameters) was pretrained on 15.5T tokens without a single loss spike thanks to the MuonClip optimizer, and improved token efficiency by rephrasing knowledge and math data (Kimi Team 2025).
Follow-up questions
Follow-up 1: Why did Llama 3 choose DPO rather than PPO?
Mainly for reasons of compute and stability. In the paper's own words, they explored on-policy algorithms such as PPO but found that DPO required less compute for large-scale models and performed better, especially on instruction-following benchmarks such as IFEval. PPO must maintain four models at once (the policy, the reference model, the reward model and the value model) and must generate online, which makes it hard to tune; DPO only needs supervised-style training on preference pairs. The weakness of DPO's offline training is in turn partly offset by the iterative process in which each round resamples with the latest model and builds new data.
Follow-up 2: What is the relationship between DeepSeek-V3 and DeepSeek-R1?
They share the same base model and supply data to each other. R1 is trained on top of DeepSeek-V3-Base; conversely, the reasoning portion of V3's SFT data was generated by an internal R1 model. This shows that in a real pipeline, reasoning ability can first be trained through RL in a dedicated model and then distilled back into the general model in the form of data.
Follow-up 3: Why does Qwen3 train its small models with distillation rather than RL?
Because distillation is cheaper and also works better. In terms of efficiency, on Qwen3-8B on-policy distillation took only about 1/10 of the GPU hours of RL. In terms of mechanism, a small model is weak and rarely samples a correct answer on hard problems, so its RL reward is almost always 0 and the learning signal is very sparse; on-policy distillation, by contrast, has the teacher provide a full probability distribution at every token the student itself generates, which is a much denser signal (see Chapter 9).
Common mistakes
- Do not say DeepSeek-V3 was trained "for only $5.576M": This is only an estimate of the formal training run at $2 per GPU hour, and the paper states explicitly that it excludes prior research and ablation experiments.
- Do not say DeepSeek-R1 was trained with pure RL: The pure-RL model is R1-Zero; R1 includes two rounds of SFT and two rounds of RL.
- Do not say Llama 3 used PPO for RLHF: Llama 3's preference optimization used DPO; PPO was only tried.
- Do not describe Qwen3's reasoning stage as post-training: This stage of about 5T tokens still uses next-token prediction and belongs to pretraining (mid-training); only the data is switched to reasoning-type data.
0.4 What are the differences among base models, instruct (chat) models and reasoning models? ★★¶
One-sentence answer
The knowledge of all three comes mainly from the same pretraining; they differ in the behavior shaped by post-training: a base model only continues text; an instruct model, after SFT and preference optimization, follows instructions in a conversational format and answers directly; and a reasoning model, after further large-scale RLVR or distillation from a reasoning model, first produces a long chain of thought before answering, trading more inference-time compute for higher accuracy.
I will address this in three parts: how they are trained, how their behavior and uses differ, and how the boundaries among the three are changing.
(1) Training: the three are products from different points of the same pipeline.
- Base model: it has gone through pretraining only (usually including mid-training), and its training objective is next-token prediction, so what it has learned is "given the preceding text, what is web text most likely to say next".
- Instruct model: SFT and preference optimization on top of the base model teach it the chat template (a format that uses special tokens to separate system, user and assistant), instruction following, refusal of harmful requests, and stopping generation at the right point.
- Reasoning model: on top of that, large-scale RL on verifiable tasks such as math and code, or distillation on long chains of thought generated by a reasoning model, teaches it to think at length before giving an answer, including trying multiple approaches, self-verifying and backtracking.
(2) Behavior and uses: the three respond to the same input in fundamentally different ways.
A base model treats the input as text to be continued; it is best used through few-shot examples, and it is the starting point for further training and research, for example for studying the effect of pretraining data or, as with R1-Zero, for starting RL directly from the base model. An instruct model treats the input as an instruction and answers directly with low latency, which suits everyday conversation and most tasks. A reasoning model first produces a thinking process of thousands or even tens of thousands of tokens, so it is clearly stronger on math, programming and complex planning, but its latency and token cost are also much higher; on simple questions it may also "think too much" and waste compute (Chen et al. 2024).
(3) The boundaries are blurring: hybrid reasoning models try to put both modes into one model.
Because thinking and non-thinking modes each have their strengths, many models try to merge them. For example, Qwen3 uses "thinking mode fusion" so that a single model decides whether to think based on a /think or /no_think flag, and it supports limiting the token budget for thinking; DeepSeek-V3.1 switches between the two modes through different chat templates; and gpt-oss lets the system prompt set the reasoning effort to one of three levels, low, medium or high (OpenAI 2025). Merging has a cost, however: when the Qwen team released Qwen3-2507 in July 2025, it switched to training separate Instruct and Thinking models, on the grounds that this gives the best quality. This shows that accommodating both behaviors in one model still involves trade-offs today.
In summary: the difference among base, instruct and reasoning models lies not in "how much they know" but in "how they respond": continuing the text, answering directly, or thinking first and then answering.
Comparing the three types of models:
| Base model | Instruct (chat) model | Reasoning model | |
|---|---|---|---|
| Training received | Pretraining (including mid-training) | Plus SFT and preference optimization | Plus large-scale RLVR or reasoning distillation |
| How it reads the input | Text to be continued | An instruction | A problem that requires thinking first |
| Typical output | A continuation that often does not stop on its own | A direct answer | A long chain of thought plus a final answer |
| How it is used | Few-shot prompts; a starting point for further training | Chat template | Chat template; the thinking budget can be controlled |
| Strengths | Distribution closest to the raw data, suited to research and fine-tuning | Low latency, general purpose | Stronger on math, code and complex tasks |
| Costs | Cannot converse directly | Limited reasoning depth on hard problems | High latency and token cost; may think too much |
Going deeper: chat templates and thinking mode fusion
(1) Both instruct and reasoning models depend on a chat template, whose special tokens tell the model who is speaking.
Below is a ChatML-style template (the format used by the Qwen series). A reasoning model's response begins with a thinking block, and the final answer is given after the thinking ends:
<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
What is the capital of France?<|im_end|>
<|im_start|>assistant
<think>
The user asks for the capital of France. That is Paris.
</think>
The capital of France is Paris.<|im_end|>
A base model has never seen this format, so it is usually used and evaluated with few-shot plain-text prompts, for example by first giving several "Question: … Answer: …" pairs and then letting the model continue with the next answer.
(2) Qwen3's thinking mode fusion: training two behaviors with one format (Yang et al. 2025).
- Training data: thinking and non-thinking data are mixed together for SFT; non-thinking samples keep an empty thinking block in the response, so that the two modes share a consistent format.
- Switching: a /think or /no_think flag is added to the user message or the system message; without a flag, the model defaults to thinking mode.
- Thinking budget: when the thinking length reaches a user-set limit, the system forcibly stops the thinking, inserts an instruction asking the model to give its answer directly, and lets the model answer based on the thinking so far. The paper notes that this ability to "answer even when thinking is incomplete" was not trained explicitly but emerged naturally after thinking mode fusion.
(3) The three types of models are also evaluated differently.
Base models are usually evaluated with few-shot prompts, and for multiple-choice questions the log-likelihoods of the options are often compared instead of having the model generate an answer; instruct models are evaluated zero-shot in the conversational format, with attention to instruction following and human preference; and for reasoning models, the effect of inference-time compute such as thinking length and number of samples must be taken into account, so pass@1 averaged over multiple samples is commonly reported (for benchmarks and evaluation methods, see the "Inference, Evaluation and Deployment" direction).
Follow-up questions
Follow-up 1: Why do many studies run experiments directly on base models?
Because a base model's distribution is closer to the raw data and has not been altered by post-training, which makes it easier to isolate the factor under study. For example, when studying the effect of pretraining data, post-training would introduce additional variables; when studying whether RL can elicit reasoning, an R1-Zero-style experiment must start from the base model to rule out the influence of SFT data. In addition, post-training often reduces output diversity (Kirk et al. 2023) and affects calibration: the GPT-4 technical report showed that the pretrained model's confidence in its own answers was well calibrated, whereas calibration dropped markedly after post-training (OpenAI 2023).
Follow-up 2: How can one model support both a thinking and a non-thinking mode?
The key is to mix the two kinds of data during training in a unified format and to distinguish them with explicit flags. In Qwen3, for example, non-thinking samples keep an empty thinking block and thinking samples contain the full thinking process; the two are distinguished by the /think and /no_think flags and trained together in SFT and the subsequent RL. At inference time, inserting an empty thinking block into the template is enough to skip thinking.
Follow-up 3: Is a reasoning model better than an instruct model on every task?
No. On math, code and planning tasks that require multi-step reasoning, reasoning models are clearly stronger; but on simple factual questions or casual conversation, the extra thinking only adds latency and cost, and overthinking can occur (Chen et al. 2024). The Qwen team's return to separate Instruct and Thinking models also shows that the two behaviors involve trade-offs. In practice, therefore, the mode is often chosen according to task difficulty, or the thinking budget is capped.
Common mistakes
- Do not say an instruct model "knows more" than a base model: Their knowledge is essentially the same, and post-training may even degrade some capabilities, the so-called alignment tax (Ouyang et al. 2022).
- Do not say a reasoning model just adds "think step by step" to the prompt: Its long chains of thought are trained through RL or reasoning distillation, and they differ fundamentally from prompted CoT in length, behavior and effectiveness.
- Do not say base models are useless: A base model is the common starting point of all post-trained versions and an important object for research on pretraining and RL, and with few-shot prompts it can also accomplish many tasks.
0.5 Why is modern training split into so many stages instead of being done in one step? ★¶
One-sentence answer
Because the data scale, data quality, training objective and computational pattern required by different capabilities differ greatly, they cannot all be optimized at once with a single objective on a single dataset. Splitting into stages lets each step use the most suitable data and objective, lets each later stage build on the previous one, and makes it easier to evaluate, reuse and iterate on each stage separately.
I will address this in three parts: data and objectives are incompatible, the stages depend on one another, and there are engineering considerations of cost and risk.
(1) The data and objectives of the different stages cannot simply be merged.
Pretraining needs data on the order of ten trillion tokens, which only cheap, noisy sources such as web pages can provide; demonstrations, preferences and verifiable tasks, by contrast, amount to only thousands to millions of samples and are expensive to obtain. If the latter were mixed directly into pretraining, their share of the total would be tiny, and their effect would be diluted by the vast amount of web data. At the same time, the objectives are computed differently: next-token prediction can be parallelized efficiently on fixed data, whereas RL requires the model to learn while generating, which makes each step far more expensive and impossible to run at the scale of ten trillion tokens. The natural approach is therefore to learn knowledge first with a cheap objective on massive data, and then to shape behavior with expensive objectives on a small amount of data.
(2) Each later stage depends on the output of the previous one, so the order cannot be changed arbitrarily.
RL learns from the model's own samples and has a learning signal only when some of the samples receive a positive reward; RL therefore needs a starting point that already answers in the right format and is occasionally correct, which is precisely what SFT provides. SFT in turn depends on the knowledge accumulated in pretraining: it can teach the model how to answer with only a small amount of data because the model already knows the answers. By the same logic, high-quality data is used at the end of pretraining rather than at the beginning because during learning-rate decay the model is most strongly shaped by recent data, so using it then yields the highest return. This forms a causal chain: pretraining provides knowledge, mid-training strengthens key capabilities, SFT provides the format and a starting point, and RL improves further on that basis.
(3) Splitting into stages is more controllable and more economical from an engineering standpoint.
- Easier reuse: pretraining is the most expensive and is usually done only once; one base model can give rise to instruct, reasoning, code and other versions, while post-training can be redone repeatedly.
- Easier evaluation and diagnosis: each stage has its own evaluation metrics, so when a problem appears it is easy to tell which stage caused it.
- Easier iteration: post-training can proceed in multiple rounds, each round using the current best model to generate new data and adding data for weaknesses found during evaluation.
In summary: the essence of staging is to train each capability with the most suitable data, objective and timing, while separating the expensive, hard-to-redo parts from the cheap parts that can be iterated repeatedly.
Going deeper: the cost of staging, and the shifting boundaries between stages
(1) The main cost of staging is forgetting: a later stage can weaken capabilities gained in an earlier one.
InstructGPT found that after RLHF the model's performance declined on some public NLP datasets, which the authors called the alignment tax; they reduced this regression by mixing gradients that increase the likelihood of the pretraining data into the PPO updates (called PPO-ptx) (Ouyang et al. 2022). Similarly, mixing some old data into SFT (replay) and adding a KL constraint relative to the reference model in RL are both ways to control forgetting between stages.
(2) The boundaries between stages are becoming blurred.
- Mid-training absorbs some post-training data: many teams add synthetic Q&A, instruction data and data containing reasoning traces to mid-training so that the model becomes familiar with such content early (see Chapter 4).
- SFT is no longer a mandatory stage: R1-Zero skipped SFT and ran RL directly from the base model, still obtaining strong reasoning ability, though with poor readability.
- Post-training itself is being subdivided: Qwen3's flagship models have four post-training stages, and DeepSeek-V3.2 first trains specialist models for different domains, distills them into one model, and then runs mixed RL.
(3) Whether a stage is necessary depends on the evaluation results after removing it.
| Stage removed | Real example | Result |
|---|---|---|
| SFT | DeepSeek-R1-Zero | Reasoning still emerges through RL, but the output is hard to read and mixes Chinese and English |
| RL | Instruct models trained with SFT only, or distilled models trained with SFT only (e.g. DeepSeek-R1-Distill) | Usable models can be obtained; small models distilled from a strong teacher can even outperform direct RL |
| Pretraining | None | Post-training data is far too small for the model to acquire knowledge and language ability, so pretraining cannot be omitted |
Follow-up questions
Follow-up 1: Could instruction data be mixed directly into pretraining to do everything in one step?
This can be done partially, but it cannot replace post-training. In fact, many teams already mix instruction and Q&A data into mid-training, which familiarizes the model with the question-answer form earlier. However, post-training has two components that the pretraining objective cannot provide: strict, consistent conversation formats and behavioral norms, which require dedicated training with the loss computed only on the response; and the signals of preference optimization and RL, which rely on comparisons between responses or on scoring the model's own samples rather than on imitating fixed text.
Follow-up 2: Could SFT be skipped and RL done directly?
Yes, but at a cost. DeepSeek-R1-Zero ran RL with rule-based rewards directly on the base model, and behaviors such as long chains of thought and self-checking emerged on their own, but the outputs were hard to read and often mixed Chinese and English. DeepSeek-R1 therefore first ran a cold-start SFT on thousands of high-quality long-CoT examples and then ran RL; the paper reports that this not only improved readability but also gave better final performance.
Follow-up 3: What problems does staged training bring, and how can they be mitigated?
Mainly forgetting and distribution mismatch between stages. The data distribution of a later stage differs from that of the earlier one, so the model may lose existing capabilities while adapting to the new objective; common mitigations include mixing in old data, adding a KL constraint to the reference model, and controlling the learning rate and number of training steps. In addition, the more stages there are, the more hyperparameters must be tuned and the more evaluations must be run, so whether to add a stage should be decided by evaluation results.
Common mistakes
- Do not say staging is just a historical habit: It is jointly determined by the data scale, the way objectives are computed, and the dependencies between stages.
- Do not say more stages are always better: Each additional stage brings a risk of forgetting and extra tuning cost.
- Do not say the stages do not affect one another: Later stages can weaken capabilities gained in earlier ones, which must be controlled with methods such as mixing in old data and KL constraints.
0.6 How do you evaluate and make decisions during training (when to stop, when to adjust the data mixture, how to select checkpoints)? ★¶
One-sentence answer
Most key decisions are made through small-scale experiments before large-scale training begins: scaling laws determine the model size and number of training tokens, and small-model ablations or annealing experiments determine the data mixture. During training, the loss and a set of high signal-to-noise evaluation metrics are monitored continuously to detect anomalies and, when necessary, to adjust the data mixture; checkpoints are selected based on held-out validation sets and multi-dimensional downstream evaluations, often with checkpoint averaging to improve stability.
I will address this in three parts: when to stop, when to adjust the data mixture, and how to select checkpoints.
(1) When to stop: the training length is largely fixed in advance; during training the main decisions are when to start decaying the learning rate and whether to roll back when anomalies occur.
The token budget for large-scale pretraining is usually set before training starts, jointly by scaling laws and inference cost (see Chapter 2), rather than by stopping when the validation loss stops decreasing as in traditional small-model training, because within a single epoch the loss almost always keeps decreasing. The WSD (warmup-stable-decay) learning-rate schedule makes this decision more flexible: a constant learning rate is used most of the time, with rapid decay only over the last 10%–20% or so of steps, so one can keep training and decide later, based on budget and results, when to enter the decay phase (Hu et al. 2024; Hägele et al. 2024). In addition, if a loss spike occurs, that is, the loss suddenly rises sharply, the common practice is to roll back to a checkpoint from before the anomaly and skip the data batches that triggered the problem (see Chapter 3).
(2) When to adjust the data mixture: mainly through small-scale experiments, with only well-founded adjustments during large-scale training.
- Small-model ablations before training: small models are trained on different mixtures, their evaluation results are compared, and the conclusions are carried over to the large model. DataDecide (Magnusson et al. 2025) found that comparing two datasets at a single small scale of 150M correctly predicts which dataset is better at the 1B scale about 80% of the time.
- Annealing experiments during training: take a half-trained model, run a short learning-rate anneal on a mixture that includes the candidate data, and observe how the downstream metrics change. Llama 3 annealed an 8B model trained to 50% over 40B tokens, with the new dataset given 30% of the weight, to assess the value of new datasets (Dubey et al. 2024).
- Adjusting based on monitoring: Llama 3 adjusted the mixture several times during pretraining, for example raising the share of non-English and math data, adding more recent web data in the later stages to advance the knowledge cutoff, and downsampling data subsets later identified as lower quality.
(3) How to select checkpoints: with held-out validation sets and multi-dimensional evaluation rather than a single metric.
In pretraining, the final model is usually the checkpoint at the end of annealing, with several checkpoints from the annealing phase averaged; this is how Llama 3 obtained its final pretrained model. In post-training, the validation loss is often not a good indicator: InstructGPT found that the SFT model's validation loss started rising after one epoch, yet further training still improved the reward model score and human preference ratings, so they selected checkpoints by the reward model score on the validation set (Ouyang et al. 2022). In practice, selection usually combines evaluations along several dimensions, such as knowledge, reasoning, code, instruction following and safety, and the validation sets used for decisions must be kept separate from the test sets used to report final results; otherwise the model overfits to the test sets.
In summary: decisions during training depend on "small-scale experiments + reliable evaluation", and whether an evaluation is reliable depends on whether its metrics give stable, discriminative signals on small models and early checkpoints.
Going deeper: how to make evaluation give reliable signals early and at small scale
(1) The accuracy of small models and early checkpoints is often near chance, so continuous metrics should be used instead.
On multiple-choice questions, a weak model's accuracy may stay near chance however it improves, so it cannot be used to tell which of two datasets is better. There are two common remedies:
- Use continuous metrics: for example, the probability of the correct answer, or the bits-per-byte on the reference answer (the negative log-likelihood normalized by bytes). DataDecide found that with such continuous likelihood metrics, on tasks including MMLU, ARC, HellaSwag, MBPP and HumanEval, over 80% of comparisons can be predicted correctly using only 0.01% of the target compute (Magnusson et al. 2025).
- Change the question format: OLMES points out that models that have not yet learned the multiple-choice format are better evaluated in the cloze format, that is, by directly comparing the likelihoods of the option texts rather than having the model output an option letter; it therefore evaluates each model in both formats and takes the better one (Gu et al. 2024).
(2) Choose benchmarks by their signal-to-noise ratio.
Heineman et al. (2025) define a benchmark's "signal" as its ability to separate different models and its "noise" as the random fluctuation of scores between adjacent checkpoints, and find that benchmarks with higher signal-to-noise ratios lead to more reliable decisions in small-scale experiments. Ways to raise the signal-to-noise ratio include replacing accuracy with better metrics such as perplexity or bits-per-byte, removing noisy subtasks, and averaging the scores of several adjacent checkpoints.
(3) Metrics commonly monitored during training.
| Stage | Monitored metrics | Main use |
|---|---|---|
| Pretraining | Training loss, loss or bits-per-byte on per-domain validation sets, gradient norm | Detect loss spikes and divergence, judge whether domains are learned evenly |
| Pretraining | A set of high signal-to-noise downstream evaluations (continuous metrics) | Compare data and mixtures, predict final performance |
| SFT / DPO | Multi-dimensional downstream evaluations, reward model score | Select checkpoints, detect capability regressions |
| RL | Training reward and performance on a held-out set, response length, entropy, KL relative to the reference model | Detect reward hacking, entropy collapse and training instability |
(4) The classic way of handling loss spikes. When PaLM encountered loss spikes during training, it restarted from a checkpoint roughly 100 steps before the spike began and skipped roughly 200–500 data batches, after which the loss did not spike again at the same point (Chowdhery et al. 2022). They also found that training on the same data batches from a different, earlier checkpoint did not produce a spike, so spikes result from the combination of specific data batches with a particular parameter state, rather than from "bad data" alone.
Follow-up questions
Follow-up 1: The MMLU score of early checkpoints is near chance; how can you tell whether training is going well?
Look at continuous metrics rather than accuracy. The training loss, the bits-per-byte on per-domain validation sets, and the probability of the correct answer all change smoothly during training; even while accuracy is still at chance, these metrics show whether the model is improving. Alternatively, the cloze format can replace the multiple-choice format in evaluation, sidestepping the problem that the model has not yet learned the multiple-choice format.
Follow-up 2: What should you do when a loss spike occurs during training?
Roll back first, then investigate the data and hyperparameters. The common practice is to roll back to a checkpoint from before the spike, skip the data batches that triggered it, and lower the learning rate if necessary; if spikes recur, the remedy has to come from the architecture and optimizer, for example by normalizing or clipping the attention logits (see Chapter 3).
Follow-up 3: Which metrics should be monitored during RL training?
At a minimum, monitor both the training reward and performance on a held-out set, and watch the response length, entropy and KL. If the training reward keeps rising while performance on the held-out set stalls or even declines, reward hacking is often occurring; if the entropy drops rapidly, the model's ability to explore is weakening, which is called entropy collapse; and abnormal growth or shrinkage of response length is also a common sign that something is wrong with training (see Chapter 8).
Common mistakes
- Do not say "the checkpoint with the lowest validation loss is the best one": In post-training, downstream performance and human preference can keep improving while the validation loss rises; InstructGPT's SFT is one example.
- Do not use the test sets for reporting final results to select checkpoints or tune the mixture: This overfits to the test sets, and the reported scores will be higher than the true level.
- Do not make data decisions based on the multiple-choice accuracy of early checkpoints: At that point the accuracy is near chance and the noise far exceeds the signal, so continuous metrics should be used instead.