LLM Pretraining & Scaling Laws

LLM Pretraining & Scaling Laws

Pretraining is the expensive part: take a randomly-initialized transformer and run next-token prediction over trillions of tokens until it becomes a base model — a raw next-token predictor with broad world knowledge but no instruction-following. Everything in llm-alignment-post-training.md, llm-fine-tuning-peft.md, and reasoning-models.md starts from this checkpoint. This reference answers the four questions that define a pretraining run: what objective, what data, how big / how long (scaling laws + the compute budget), and how do I know it worked (base-model eval).

The one identity that anchors everything here — C ≈ 6ND. A dense transformer with N parameters trained on D tokens costs about 6ND floating-point operations. That single equation is the budget line: every scaling-law result (Kaplan, Chinchilla, data-constrained, inference-aware) is an answer to “given a fixed C, how do I split it between N and D to minimize loss?” Hold C = 6ND and the whole field becomes a constrained-optimization story. The 2022 → 2026 arc is the field realizing that the loss-optimal split (N : D) and the deployment-optimal split are different things — and that data, not parameters, is now the binding constraint.

Scope boundary (read first)


1. Pretraining objectives — what loss is the model minimizing?

The objective decides what the base model is good at before any post-training. Five matter (2024–2026).

Decision in practice (2026): generative LLMs use CLM, often + FIM (especially for code), trained on packed sequences (multiple documents concatenated to a fixed context length with separators — packing keeps GPUs full; whether to mask cross-document attention is a live choice). MLM is for encoders. UL2/prefix-LM matter mostly historically and for encoder-decoder niches.


2. The pretraining data pipeline — curation, dedup, quality filtering

Data quality, not architecture, is the dominant lever on a fixed compute budget. The canonical open reference is FineWeb (Penedo et al. 2024, arXiv:2406.17557): 15T GPT-2 tokens from 96 Common Crawl snapshots (2013–early 2024), with every design choice ablated (each stage shown to monotonically improve downstream benchmarks). The pipeline stages:

  1. Text extraction. Pull main content from raw HTML/WARC (FineWeb uses trafilatura); good extraction beats Common Crawl’s own WET text.
  2. Language ID + filtering. Classifier-based language detection; keep target languages above a confidence threshold.
  3. Quality / heuristic filtering. Rule-based filters (line-length, symbol-to-word ratio, fraction of duplicate lines, bad-words, repetition) à la MassiveText/Gopher and C4. Removes boilerplate, SEO spam, gibberish.
  4. Deduplication (the single highest-impact stage). Near-dedup with MinHash + LSH on n-gram shingles (FineWeb: per-snapshot MinHash dedup). Removes the long tail of near-identical pages. Counter-intuitive finding from FineWeb: global cross-snapshot dedup can hurt — it disproportionately removes recently re-crawled, often higher-quality content and over-upweights ancient low-quality pages; per-snapshot dedup worked better. Dedup also matters because repeated data interacts with epoch-counting (§5).
  5. Model-based quality classification. Train a lightweight classifier to score “is this high-quality / educational?” FineWeb-Edu is a 1.3T-token subset filtered by an educational-quality classifier (a linear/small head trained on Llama-3-70B annotations of educational value). Models pretrained on FineWeb-Edu show large gains on knowledge/reasoning benchmarks (MMLU, ARC) versus unfiltered FineWeb — strong evidence that aggressive quality filtering pays off, even at the cost of raw token count.

Synthetic data is now a standard ingredient (rephrased web, textbook-style generation à la Phi, distilled chains). Risk: model collapse (degenerate distributions when training on too much un-curated model output across generations) — mitigate by anchoring to real data and limiting synthetic share.

Cross-ref: the tokenization algorithm (how text becomes IDs) is in transformer-architecture.md §10. Tokenizer training (choosing the vocab, the corpus to train it on) is §4 here because it is a data decision.


3. Data mixtures & domain weighting — how much of each source?

Once you have cleaned sources (web, code, books, arXiv, Wikipedia, math, multilingual), you must choose mixture proportions (domain weights). This is a first-class hyperparameter — getting it wrong wastes compute.

Practical pattern: set a base mixture (heuristic or DoReMi-derived), then upsample high-value domains (code, math, curated/synthetic) during the annealing phase (§9) rather than uniformly — the decay phase is where domain emphasis is cheapest and most effective (the MiniCPM/Yi-Lightning recipe).


4. Tokenizer training & eval-set decontamination

Tokenizer training (a data decision; algorithm → transformer-architecture.md). Before pretraining you train the tokenizer on a sample of the corpus and freeze it; vocab choice then constrains everything.

Eval-set decontamination (do not skip — it is how you avoid lying to yourself). Web-scale corpora contain copies of benchmark test sets; if MMLU/GSM8K leak into pretraining, your eval is inflated.


5. Scaling laws I — Kaplan vs Chinchilla (compute-optimal allocation)

Scaling laws predict loss as a smooth power law in model size N, data D, and compute C, and tell you how to split a fixed C between N and D.


6. Scaling laws II — data-constrained & inference-aware (why Chinchilla is not the answer in 2026)

Chinchilla is training-compute-optimal, not deployment-optimal, and assumes unlimited unique data. Both assumptions break in practice.

Synthesis of the three regimes: Chinchilla (balanced) is the textbook answer when data and inference are free. Inference-aware (over-train a small model) is the answer when you will serve at scale. Data-constrained (repeat ≤4 epochs, prefer smaller models) is the answer when you are out of unique tokens. Mid-2026 frontier runs live at the intersection: small-ish models, heavily over-trained, on heavily-filtered + synthetic data, a few epochs at most.


7. The compute budget — C ≈ 6ND and how to use it

The arithmetic that turns all of the above into a project plan.


8. Emergent abilities & the “mirage” debate


9. Learning-rate schedules at scale — cosine vs WSD, and the annealing phase

The LR schedule is a pretraining-specific lever with a surprising amount of pull on the final loss.


10. Continual & domain-adaptive pretraining

You rarely retrain from scratch to add a domain, a language, or fresher data. Continual pretraining (CPT) = keep doing next-token prediction on a new corpus starting from an existing base checkpoint. (Distinct from fine-tuning/PEFT, which uses supervised data → llm-fine-tuning-peft.md.)

Where CPT meets the schedule: re-warm/re-decay is literally a fresh WSD/cosine cycle (§9); the new domain data is often introduced in the decay/annealing phase for the same reason §9 gives.


11. Evaluating a base (pre-instruct) model

A base model is a raw next-token predictor — it does not follow instructions or chat. Evaluating it requires different methods than an aligned model, and confusing the two is a common error.


Anti-patterns (the costly mistakes)

Troubleshooting

References (primary; 2024–2026 unless seminal)

Scaling laws

  1. Kaplan et al. (2020), Scaling Laws for Neural Language Models — arXiv:2001.08361.
  2. Hoffmann et al. (2022), Training Compute-Optimal Large Language Models (Chinchilla, ≈20 tok/param) — arXiv:2203.15556.
  3. Muennighoff et al. (2023), Scaling Data-Constrained Language Models (≤4 epochs ≈ free, decay to ~40) — arXiv:2305.16264; JMLR 26 (2025) 24-1000.
  4. Sardana & Frankle (2023/2024), Beyond Chinchilla-Optimal: Accounting for Inference in LM Scaling Laws — arXiv:2401.00448.
  5. Porian et al. (2024), Resolving Discrepancies in Compute-Optimal Scaling of Language Models — arXiv:2406.12907 (NeurIPS 2024). Besiroglu et al. (2024), Chinchilla Scaling: A replication attempt — arXiv:2404.10102.
  6. Casson (2023), Transformer FLOPs (the 6ND / 2N-per-token derivation) — adamcasson.com.

Objectives 7. Bavarian et al. (2022, OpenAI), Efficient Training of Language Models to Fill in the Middle (FIM, PSM/SPM, FIM-for-free) — arXiv:2207.14255. 8. Tay et al. (2022, Google), UL2: Unifying Language Learning Paradigms (Mixture-of-Denoisers, R/S/X, mode-switch) — arXiv:2205.05131.

Data pipeline & mixtures 9. Penedo et al. (2024, HuggingFace), The FineWeb Datasets: Decanting the Web… (15T tokens, ablated pipeline, FineWeb-Edu 1.3T) — arXiv:2406.17557. 10. Xie et al. (2023), DoReMi: Optimizing Data Mixtures Speeds Up LM Pretraining (Group DRO proxy reweighting) — arXiv:2305.10429 (NeurIPS 2023). 11. Yang et al. (2023), Rethinking Benchmark and Contamination for LMs with Rephrased Samples (n-gram decontamination is fragile) — arXiv:2311.04850. Survey: Benchmark Data Contamination of LLMs — arXiv:2406.04244. 12. Tokenizer training: Tokenizer Choice for LLM Training: Negligible or Crucial? — arXiv:2310.08754; Diminishing Returns of Tokenization Training Data — arXiv:2502.20273.

LR schedules, curriculum, continual pretraining 13. Hu et al. (2024), MiniCPM (Warmup-Stable-Decay; ~192× data/model ratio) — arXiv:2404.06395. River-valley landscape view of WSD — arXiv:2410.05192. 14. Gupta et al. (2023), Continual Pre-Training of LLMs: How to (re)warm your model? — arXiv:2308.04014. 15. Ibrahim et al. (2024), Simple and Scalable Strategies to Continually Pre-train LLMs (re-warm + re-decay + replay = match full retrain) — arXiv:2403.08763. 16. How Learning Rate Decay Wastes Your Best Data in Curriculum-Based LLM Pretraining — arXiv:2511.18903. Mid-Training of LLMs: A Survey — arXiv:2510.06826.

Emergence & base-model evaluation 17. Wei et al. (2022), Emergent Abilities of Large Language Models — arXiv:2206.07682. 18. Schaeffer et al. (2023), Are Emergent Abilities of Large Language Models a Mirage? (metric artifact; NeurIPS 2023 Outstanding Paper) — arXiv:2304.15004. 19. EleutherAI, Language Model Evaluation Harness (lm-eval) — github.com/EleutherAI/lm-evaluation-harness. Base-vs-instruct few-shot: arXiv:2601.13244, arXiv:2501.08716.

Compiled via /dr deep-research, 2026-05-31. Scaling-law constants, token/param ratios, and dataset sizes are research findings, not laws of nature — re-derive against your own data, tokenizer, and hardware. For the transformer block, tokenizer algorithms, and attention internals see transformer-architecture.md; for spending the 6ND budget across a cluster (FSDP/ZeRO/parallelism) see distributed-training.md.