Lecture 10 · Data for Pre-Training

Scalable AI: Bridging Theory, Understanding, and Practice · Lecture 10。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: UC Berkeley EE 290/194 Scalable AI, Fall 2026 Lecture 9, Pre-Training (Part 2): Data for Pre-Training — sources, filtering, repetition, synthetic data, mixtures, and curation at scale (slides lecture9.pdf). Also drawn on: Spring 2026 Lecture 6 Part D (corpora as pipelines: C4, FineWeb, the curation pipeline, data KPIs) and Spring 2026 Lecture 7, Data Curation with NeMo Curator (NVIDIA guest lecture: throughput, streaming, autobalancing, the Nemotron-CC workflow, failure cases). The slides’ synthetic-data section is the subject of Lecture 11. Recommended reading (as cited on the slides): FineWeb (arXiv:2406.17557); DCLM (arXiv:2406.11794); Nemotron-CC (arXiv:2412.02595); Muennighoff et al., Scaling Data-Constrained Language Models (arXiv:2305.16264); Lee et al., Deduplicating Training Data Makes Language Models Better (arXiv:2107.06499); RegMix (arXiv:2407.01492) and DoReMi (arXiv:2305.10429); the NeMo Curator repository. Code: code/lecture10/ contains crawl.py (a toy web crawl with the truth attached to every page), curate.py (extraction, language ID, rules, quality models, MinHash + LSH) and seven demos. Models are trained with Lecture 9’s pretrain.py on Atlas World, so every filter is judged both against the true labels and by the model it trains. Reading time: ~2.5 hours for the prose; ~8 minutes to run all demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Size the data problem. Explain why current runs need 4–40T tokens, and why the largest filtered web datasets hold about one run’s worth.
  2. Design a curation pipeline. Order its stages from cheap to expensive: extraction → language ID → heuristic rules → dedup → quality models → mixing. Say what each stage removes, by mistake as well as on purpose.
  3. Judge a filter correctly. By what it keeps and, above all, by the model it trains (the ablation), not by how clean its output looks. Recognize that “quality” means whatever the filter compares against.
  4. Reason about quantity vs repetition. Use the data-constrained scaling results: about 4 epochs is nearly free, 16+ is not, and a repeated small subset hurts. Explain why heavy filtering stops paying as compute grows.
  5. Set and check a mixture. Know that facts are learned in proportion to frequency. Know how proxy models choose weights and why the choice must be verified at scale. Know why the best data goes at the end (annealing).
  6. Run curation as a system. Explain why throughput beats latency. Know how streaming, balancing and backpressure turn 13,000 s into 1,000 s, and why dedup is the hardest stage to scale.

0.2 Prerequisites and scope

  • Prerequisites: Lecture 9 (Atlas World, bits per byte, the floor, pretrain.py, ablations on small models).
  • Scope: sources and scale; text extraction; language ID; heuristic filters and their biases; learned quality classifiers (distillation from LLM judges, DCLM-style, perplexity); what filtering unsafe text does; repetition, epochs and data-constrained scaling; exact and fuzzy dedup; mixtures, proxy-model search and annealing; the cost and systems engineering of curation (NeMo Curator).
  • Not in scope today: synthetic data (rephrasing, distillation, model collapse; Lecture 11); post-training data (Lecture 17). The slide on filtering hazardous knowledge from pre-training data is not covered here.

0.3 Section → code map

SectionIdeaCode in code/lecture10/
§1how much data, from where01_sources_and_scale.py
§2.1a toy crawl with true labelscrawl.py
§2.2–2.4extraction, language ID, heuristic rules, the ablationcurate.py, 02_filters_vs_truth.py
§2.5–2.6learned quality filters and their disagreement03_quality_classifiers.py
§3.1–3.3repetition, epochs, filtering vs compute05_repetition_and_epochs.py
§3.4–3.6exact and fuzzy dedup, decontamination, global vs per-snapshot04_dedup_minhash.py
§4facts by frequency, proxy-model mixture search, annealing06_mixtures.py
§5FLOPs of curation; streaming, balancing, backpressure; measured stage costs07_curation_at_scale.py

0.4 Notation

  • NN = parameters, DD = training tokens.
  • Epoch (轮次) = training tokens / unique tokens.
  • pip_i = natural share of source ii; wiw_i = its sampling weight.
  • ss = Jaccard similarity; b×rb \times r = LSH bands × rows.
  • Junk = pages with no usable content (word salad, spam, repeated phrases, gibberish, fragments, template-only pages).

1. Sources and scale

1.1 Where data enters training

Pre-training uses web text, code, papers, books and math: 4–40T tokens today. Mid-training uses less data but higher quality (top web, math, code, synthetic): 50B–1T tokens. Post-training data (chat, reasoning, RL) comes in Part III.

Model reports describe the architecture in detail but say little about their data, because data is a competitive advantage. The Spring slides put it bluntly: for frontier models, data curation is often as important as architecture changes, and “bad data can waste compute faster than any systems inefficiency”.

1.2 Runs need far more data than Chinchilla said

Open models train on about 2.2× more tokens every year (slides). The reason is in the economics (demo 01):

  • Chinchilla’s optimum, about 20 tokens per parameter, counts only training cost.
  • A model is trained once and served for many tokens, so a smaller model trained on more data is often the better deal (Sardana et al.).
  • Llama 3 8B trained at 94× Chinchilla-optimal (15T tokens), and Qwen3 0.6B at about 3,000× (36T).
  • Each step past 20 tokens per parameter raises the amount of data a run needs.

The Spring guest lecture adds that MoE makes this worse. Data needs scale with total parameters while compute scales with active ones, and repetition hurts MoE models sooner (§3).

1.3 A filtered web dataset is about one training run

Dataset sizes have grown from BooksCorpus (0.8B words) and English Wikipedia (2.5B words, BERT’s diet) through C4 (156B tokens), The Pile (300B) and RefinedWeb (600B) to Dolma (3T), DCLM-Baseline (3.8T), Nemotron-CC (6.3T) and FineWeb (15T).

After filtering, the largest public web datasets hold about one run’s worth of tokens. The unfiltered pool, DCLM-Pool at 240T, is 16× larger. Villalobos et al. put the stock of public human text at about 300T tokens and project that runs use the whole stock around 2028. A 15T run on DCLM-Baseline alone would see each document 3.9 times. Section 3 asks whether that is a problem.

1.4 What a mixture is made of

Web text is 95.1% of OLMo 2’s pre-training mix (DCLM-Baseline, 3.71T of 3.90T tokens). The other sources are small but each is added on purpose:

sourcewhy add it
code (StarCoder, 83B)programming; rare on web pages
math (OpenWebMath, Algebraic Stack; 12B each)HTML extraction loses notation
papers (peS2o 59B, arXiv 21B)mostly PDFs, so missing from HTML crawls
Wikipedia (3.7B)clean, factual, broad

Common Crawl (通用网页爬取) has released a snapshot of about 2B pages roughly once a month since 2013, and it is the source of almost all web text. It ships raw HTML (WARC files) and its own extracted text (WET files). The slide shows one document from each stage of the same pipeline:

  • a raw C4 page that is a navigation menu and shopping cart;
  • a FineWeb page of chatty prose (passed rules and dedup);
  • a FineWeb-Edu page about deep-space communication (classifier score 3.9/5);
  • a Wikipedia stub about frogs.

The slide asks: is the FineWeb sample good training data? Is the Wikipedia sample better than the FineWeb-Edu one? These questions have no context-free answer. That is why the field answers them with ablations.

Every curation choice is tested with an ablation (消融实验). Fix the model and the training recipe, change only the data (one filter, one threshold, one dedup setting), and compare benchmark scores. The runs are kept small to keep this cheap (FineWeb used 1.71B parameters and 28B tokens), so the benchmarks must give signal at that scale (Lecture 9 §5.5). This lecture’s demos do exactly this on Atlas World: the same model, the same token budget, a different version of the data.


2. Filtering: which documents to keep

2.1 The pipeline, and a crawl whose truth we know

raw crawl (WARC) → text extraction → language ID → heuristic filters → dedup → quality classifiers → decontaminate, mix
                   └──────── CPU, per document, cheap ────────┘   └ global ┘  └ model inference (CPU or GPU) ┘

The curation pipeline keeps 1–10% of the crawl. In DCLM (reported), 240T tokens go in and 3.8T come out. By documents:

  • heuristic filters keep 19.9%;
  • dedup leaves 13.7%;
  • the quality classifier leaves 1.4%.

Keeping only English alone removes about half the documents. Stages are ordered from cheap to expensive, so the expensive models see the fewest documents.

To score every stage, crawl.py builds a toy crawl on top of Atlas World. Every page carries its site’s template lines (a link bar, a cookie notice, a footer) around its content, and its true kind is recorded:

kindwhat it istruth
goodan Atlas World document, one sentence per linereal content
noisya good document with typos and filler (“lol”, ”!!”)mediocre content
foreigna good document in “language B” (a letter cipher)real content, wrong language
shuffleda good document with its words in random orderjunk (word salad)
spamkeyword-stuffed shop textjunk
repeatedone phrase repeated dozens of times (“255 255 255 …”)junk
gibberishrandom characters (broken encodings)junk
shorta 1–4-word fragmentjunk
templateonly boilerplate (login, contact)junk

On top come exact and near duplicates, with heavy-tailed cluster sizes. The demos’ crawl has 7,500 pages from 6,000 unique ones.

2.2 Text extraction and language ID

Extraction (正文抽取). A WET-style dump strips tags but keeps menus, cookie notices and footers. FineWeb and DCLM found that extracting text from WARC with trafilatura beats using WET (same model and crawl; only the extraction differs).

curate.extract is a readability-style extractor: it drops link bars and known boilerplate lines. On the toy crawl (demo 02):

  • 23.3% of the words in the raw dump are site templates;
  • extraction returns the true content of 95.5% of good pages exactly (the rest are re-posts whose edited line differs by design);
  • training on the raw dump instead of extracted text costs +0.157 bits/byte on clean held-out text (1.011 vs 0.854), because the model spends capacity on menus.

Boilerplate is also extreme duplication, which shows up as memorization and loss spikes (Spring slides).

Language identification (语种识别, LID). curate.LangID is a character-trigram naive Bayes classifier trained on 300 documents per language. It detects 100% of foreign pages that contain words. It misses all foreign math pages, because digits look the same in every language. Real LID misfires the same way on code, math, short documents and transliterated text. Mixed-language pages need segment-level LID. Track the language proportions over time: a sudden drift usually indicates a pipeline regression.

2.3 Heuristic rules: sharp, cheap, and biased

The C4 rules, applied to one page on the slide:

  • drop lines without terminal punctuation, and cookie lines;
  • drop pages with fewer than 3 sentences;
  • drop pages containing a word from a bad-words list, or a {.

FineWeb ablated each C4 rule separately. Terminal punctuation helped most, but it removes about 30% of tokens, so FineWeb left it out. Gopher-style rules add fractions of symbols, mean word length, stop-word counts and repeated-line or n-gram statistics. Regexes find emails, phone numbers and IP addresses and mask them (Dolma).

Demo 02 applies six rules one at a time, on extracted text:

rulejunk removedgood pages removedworst-hit domain
min 3 lines64.5%15.6%math 20.5%
terminal punctuation84.9%0.0%—
bad-words list22.6%14.5%story 20.2%
symbol ratio10.0%0.0%—
repetition (≥ 10 back-to-back n-gram repeats)11.7%0.0%—
stop words (≥ 2)86.9%22.0%math 100%

Three lessons:

  • Every rule that catches a lot of junk also removes good text, unevenly.
  • The stop-word rule deletes every math page and 41% of code, which have few or no stop words.
  • The bad-words list removes 79.7% of benign market-topic pages and 0% of the other topics. “Cheap” is both a spam word and an ordinary word about markets. This is the mechanism behind the slide’s finding that C4’s word list disproportionately removed text about LGBTQ+ people and text in African American English (Dodge et al.). Blocklists are easy to implement and easy to miscalibrate.

The ablation decides (same model, same 512K-token budget; validation bits/byte on clean held-out text):

training datadocumentsstorywikimathcodeall
raw dump (WET-style)7,5000.9241.0831.6751.1271.011
extracted7,5000.8130.9021.4210.8130.854
extracted + LID + 3 light rules4,2970.7930.8221.3720.7800.819
+ all six rules2,3860.8720.8645.0870.7891.022

“All six rules” produces the cleanest-looking data and the worst model. The stop-word rule removed all math, so the model never learned arithmetic (5.087 bits/byte on math, where the floor is 0.891). Rules also leave junk behind: 10.5% of the light-rule output, almost all shuffled word salad, which has the right words, punctuation and length. Catching it needs a model of what good text looks like.

2.4 How filters have defined “good” text

Each generation of filter defined quality by what it compares a page against:

filterquality meansexample
GPT-2 WebText (2019)people link to itoutbound Reddit links
CCNet, GPT-3 (2019–20)it looks like Wikipedia and booksperplexity / classifier vs reference
FineWeb-Edu (2024)an LLM rates it educationaldistilled LLM judge
DCLM (2024)it looks like instruction datafastText: OH-2.5 + ELI5 vs random web
Nemotron-CC (2024)an ensemble of classifiers rates it highlyensemble + quality buckets

Since CCNet and GPT-3, the comparison has been made by a learned classifier.

2.5 Learned quality filters

Distilling an LLM judge into a cheap classifier (FineWeb-Edu):

  1. sample 460K pages;
  2. Llama-3-70B scores each one for educational value (0–5);
  3. train a small classifier (110M parameters) on the scores;
  4. score all 15T tokens and keep score ≥ 3, leaving 1.3T tokens.

Threshold 3 scored best among 2, 3 and 4 against unfiltered FineWeb (reported).

A cheap classifier can beat asking an LLM. DCLM trained the same model on the same pool and changed only the filter. A fastText bigram classifier (positives: instruction data and ELI5 answers; negatives: random web pages; keep the top-scored 10%) scored 30.2 on CORE, beating:

  • prompting an LLM to judge each document (AskLLM, 28.6);
  • perplexity filtering (29.0);
  • top-k logits (29.2);
  • BGE embeddings (27.2);
  • semantic dedup (27.1);
  • rules only (27.5);
  • PageRank top 20% (26.1).

The fastText classifier costs a fraction of AskLLM. Keeping the most-linked pages did worse than rules alone.

Perplexity filtering (困惑度过滤) keeps text that a reference LM finds likely. It removes gibberish and boilerplate. As the Spring slides warn, it also removes code, math and low-resource languages unless the reference model covers them. Nemotron-CC’s pipeline still uses it, as one stage among many.

Demo 03 runs these after the light rules (4,297 candidate pages), each keeping the top half:

filterjunk keptgood storygood wikigood mathgood codemodel (val bits/byte)
random half10.3%50%51%48%50%0.831
judge on every page (AskLLM-style)0.0%50%93%94%91%(not trained)
distilled judge classifier (800 labels)0.0%53%78%86%87%0.818
DCLM-style (wiki reference vs crawl)2.1%81%97%0%0%1.664
perplexity (bigram LM on wiki)0.0%95%99%0%0%1.573
oracle (true quality)0.0%70%69%69%75%0.796
  • The student is nearly as good as its teacher. The distilled classifier agrees with the truth on 82.2% of unseen pages, against 89.0% for the judge itself. Used to pick the top half, it is almost as clean (0.0% junk, 3.7% noisy, vs 0.0% and 2.9%). It costs one small forward pass per page instead of an LLM call.
  • “Quality” is whatever the reference is. The DCLM-style classifier was trained against wiki-style reference text, and the perplexity filter scored against a wiki bigram model. Both keep no math or code, and the models they train score 9–10 bits/byte on math. Real DCLM positives (instruction data) do contain code and math; a reference set without a domain silently deletes it. A filter is judged by the model it trains.

2.6 Classifiers disagree about quality

The learned filters’ kept halves overlap with Jaccard 32–75%, and only 30.3% of the pages any of them keeps is kept by all three (demo 03). On real data, Nemotron-CC found that among high-quality documents in one snapshot, only 10% were chosen by both FineWeb-Edu and DCLM (35% by FineWeb-Edu only, 54% by DCLM only).

FineWeb-Edu’s notion of quality favours education, history and health, and disfavours business, entertainment, travel and recipes. Each classifier encodes its own notion of quality; combining them (Nemotron-CC’s ensemble) finds more good documents. Two operational rules from the Spring slides:

  • Track the score distribution and the acceptance rate. Large shifts often mean an upstream extraction bug.
  • Prefer soft weighting (downsampling) to hard drops when you can: it gives smoother distributions (§3.3).

2.7 What filtering unsafe text does

Pipelines drop unsafe pages with URL blocklists and toxicity classifiers. The slide’s evidence, from Safety Pretraining (Maini et al.) and Korbak et al., is that removal has a cost:

  • Removal alone backfires. Training only on documents scored safe raised the attack success rate after benign fine-tuning, from 38.8% to 43.8%. The model never learned how to respond to unsafe content.
  • Rewriting works better. Keeping that content, rewritten with context and paired with refusals, lowered the rate to 23.0%; adding harm tags brought it to 20.0%.
  • Tagging helps generation. Tagging text <|good|>/<|bad|> and generating after <|good|> cut toxicity about 10×.

The defensive lesson matches §2.3: removing data removes what the data teaches, including how to recognize and respond to bad content. Curation choices for safety are ablated like any other.


3. Quantity, repetition and deduplication

3.1 Up to ~4 epochs, repeated data is almost as good as new data

With runs catching up with the stock of text, repetition is unavoidable. Muennighoff et al. trained many models on repeated data:

  • each repetition is worth less than the one before;
  • up to about 4 epochs, repeating is almost as good as new data;
  • past about 16 epochs the returns fall off quickly;
  • at 40 epochs, repeating is worthless.

So 4 passes over DCLM-Baseline cost little, but much longer runs need more unique tokens. The Spring guest lecture adds that past about 2 epochs repetition is even more detrimental for MoE models.

Demo 05 Part A (measured) spends the same 614K training tokens on 1/e1/e of the data, repeated ee times:

epochs1248163264
val bits/byte0.7690.7710.7740.7940.9391.9942.449
vs fresh data—+0.002+0.005+0.025+0.170+1.225+1.680
train loss (nats/token)1.7671.7521.7581.7161.3290.0660.015

This is the same shape, in miniature. At 32 epochs the training loss is near zero while held-out quality collapses: the model has memorized its training set.

3.2 Repeating a small subset many times hurts

Hernandez et al. trained on 90% unique data plus 10% from a small subset repeated many times. Repeating 0.1% of the data 100 times made an 800M model perform like a 400M model. Demo 05 Part B does the same in miniature: 90% fresh data plus 83 copies of a 738-token subset costs +0.007 bits/byte. That is more than repeating the whole dataset 4 times (+0.005), even though only 10% of the tokens are repeats.

Why repetition matters in practice: the web is full of repeated text. In C4 (Lee et al.):

  • most documents are unique, but some appear thousands of times;
  • 4.6% of C4’s validation documents have a near duplicate in training (contamination);
  • deduplication cut verbatim regurgitation of training text by 10×.

Duplicates cause three problems: repetition (a few documents repeated many times), contamination and memorization. Hence dedup (§3.4).

3.3 How much to filter depends on the budget

Soft filtering. Long runs keep more data and weight it by quality, instead of applying a hard threshold. Nemotron-CC uses an ensemble of classifiers to sort documents into quality buckets. It repeats the top buckets more and keeps some middle-quality data. It keeps 4× DCLM’s unique tokens at the same MMLU. An 8B model trained on 15T tokens (7.2T from Nemotron-CC) scored MMLU 70.3 vs Llama 3.1 8B’s 65.3 (reported).

With enough compute, filtering stops helping (Mohri, Duchi and Hashimoto, A Bitter Lesson for Data Filtering):

  • At low compute, filtered data wins. There are enough unique good tokens, and bad tokens waste the budget.
  • At high compute, the unfiltered pool wins. The filtered set has to be repeated many times, and each repeat is worth less.
  • Where the crossover sits. For all of DCLM-Pool they project the unfiltered pool overtaking the RefinedWeb filter at about 103010^{30} FLOPs. Frontier runs today are about 5×10265 \times 10^{26}, so filtering still pays, and pays less as budgets grow.

Demo 05 Part C reproduces the crossover in miniature: filtered = good pages only (81K tokens); unfiltered = good + noisy pages (170K tokens).

stepsepochs (filtered)epochs (unfiltered)filteredunfiltered
1001.30.61.1151.403
4005.12.40.7880.811
1,60020.29.60.9790.784

Better data also moves the compute-optimal point toward larger models. For a budget CC, the optimal sizes grow as N⋆∝CaN^\star \propto C^a and D⋆∝C1−aD^\star \propto C^{1-a}. Chinchilla’s “20 tokens per parameter” comes from fitting aa on one dataset. DeepSeek LLM refit aa on three datasets of increasing quality and got larger aa for better data (0.450 → 0.524 → 0.578). So more of the budget should go to parameters. Scaling-law fits do not transfer across datasets, which matches Lecture 9’s ladder.

3.4 Exact and fuzzy deduplication

Exact dedup (精确去重) hashes each document (MD5 in Curator) and keeps one per hash. It misses pages that differ only by a date or an ad.

Fuzzy dedup (模糊去重) with MinHash + LSH works in four steps:

  1. Shingles. Each document becomes a set of word 5-grams (shingles, 词片).
  2. MinHash. For a random hash function hh, P[min⁡h(A)=min⁡h(B)]=J(A,B)P[\min h(A) = \min h(B)] = J(A, B), the Jaccard similarity ∣A∩B∣/∣A∪B∣|A \cap B|/|A \cup B|. So b×rb \times r independent MinHashes form a signature whose agreement rate estimates JJ.
  3. LSH banding. Split the signature into bb bands of rr rows. Two documents become a candidate pair if all rr values agree in any band: P(candidate)=1−(1−sr)b.P(\text{candidate}) = 1 - (1 - s^r)^b.
  4. Clusters. The connected components of the candidate pairs (union-find, 并查集) are the duplicate clusters; keep one document per cluster.

bb and rr set the threshold and its sharpness. Demo 04 measures the curve on document pairs with controlled similarity:

Jaccard ss0.5–0.60.6–0.70.7–0.80.8–0.90.9–1.0
FineWeb 14 × 8 analytic / measured0.14 / 0.130.34 / 0.400.79 / 0.810.98 / 0.961.00 / 1.00
RefinedWeb 450 × 20 analytic / measured0.01 / 0.000.08 / 0.070.77 / 0.691.00 / 1.001.00 / 1.00

P=0.5P = 0.5 at s=0.68s = 0.68 for 14 × 8 and 0.720.72 for 450 × 20. RefinedWeb’s curve is much steeper, at 80× the hashing cost (9,000 vs 112 hashes per document).

Scored against the true clusters (7,500 pages; 2,265 true duplicates to remove, 468 of them near copies):

methodprecisionrecallnear copies found
exact (MD5 of extracted text)100%86.3%51.3%
MinHash 14 × 8 on extracted text93.3%95.8%84.0%
MinHash 14 × 8 on the raw page93.2%89.4%66.7%
MinHash 20 × 5 on extracted text93.4%97.4%89.3%

The 155 “mistakes” of MinHash on extracted text are all repeated-phrase pages of different lengths (“0 0 0 …”). Their shingle sets are identical: duplicates in content, just not in the crawl’s copy records. Run on raw pages, MinHash does worse. Template and date lines dilute the shingle sets of short pages, so recall drops, and it merges 34 pages whose only overlap is their site template. Dedup runs after extraction.

The clusters found are heavy-tailed: most pages are unique, and the largest cluster has 696 pages. Both kinds of dedup compare documents across the whole dataset, so neither can run one document at a time. This is what makes dedup the hardest stage to scale (§5).

3.5 Decontamination

Evaluation is part of the data pipeline (Spring slides). If training data contains your benchmarks or their near duplicates, scores are inflated. To guard against this:

  • build a “do-not-train” set from the benchmarks;
  • dedup against it at the n-gram level, not just the document level;
  • track provenance so a source can be removed retroactively.

Demo 04 plants 12 benchmark documents in the training crawl, half of them edited. An 8-gram overlap check (≥ 50% of a page’s 8-grams in the benchmark) catches all 12, with 5 false alarms. Lecture 9 §5.5 noted the real case: Marin 32B found GSM8K in its cooldown data.

3.6 Global dedup can remove the wrong copies

FineWeb found that global dedup across 96 snapshots gained little over no dedup. In one old snapshot, the 90% of documents that global dedup removed trained a better model than the 10% it kept. The explanation: pages that are never re-crawled tend to be low quality. Global dedup keeps those and removes good pages that were crawled again. FineWeb therefore dedups each snapshot separately.

Demo 04 Part E simulates this: good pages are re-crawled with probability 0.6 per snapshot, noisy 0.3, junk 0.05, and global dedup keeps the newest copy. In the oldest snapshot:

pagesgoodjunkmodel trained on them (bits/byte)
kept by global dedup7991.0%77.8%1.465
removed by global dedup1,18969.6%12.6%0.852

The re-crawl probabilities are assumptions, but the mechanism is general: a dedup policy is also a sampling policy, and which copy it keeps matters.


4. Mixtures

4.1 Models learn facts in proportion to how often they appear

Kandpal et al. took each TriviaQA question and counted the pre-training documents that mention it. Accuracy rises with that count at every model size, from BLOOM 560M to 176B. Rare facts would need an absurdly large model. The mixture decides which facts are common, so it decides what the model knows.

Atlas World mentions its 100 countries with Zipf frequency. Demo 06 Part A trains a model for 800 steps on the natural mix and tests all 400 facts (rank the right answer first among the relation’s candidates; chance 5.1%):

documents stating the fact01–23–56–1516–5051+
facts2591147873614
accuracy4.0%8.8%10.2%12.6%66.7%100%

Only 50 of the 400 facts are stated more than 15 times; overall accuracy is 18.2%. Knowledge follows frequency.

4.2 Mixture weights oversample small, valuable sources

Each next document comes from source ii with probability wiw_i instead of its natural share pip_i. GPT-3 cut Common Crawl and Books2, and boosted WebText2, Books1 and Wikipedia (demo 01):

  • Wikipedia is 0.6% of the tokens available but got a 3% weight, about 3 epochs;
  • Common Crawl got less than half an epoch.

A common rule, especially across languages (mT5, XLM-R), is temperature sampling: wi∝piαw_i \propto p_i^\alpha with α<1\alpha < 1, which flattens the mixture. With α=0.3\alpha = 0.3, GPT-3’s sources would give Wikipedia about 9 epochs. Upweighting repeats a small source, so its weight is capped at a few epochs: repetition is nearly free up to about 4 (§3.1).

4.3 Choosing mixture weights with small proxy models

The recipe:

  1. train many small models, each on a different mixture;
  2. fit a model of loss as a function of the weights;
  3. pick the mixture with the best predicted loss;
  4. train the large model on it.

RegMix fits a regression on 512 tiny models trained on random mixtures; its predicted ranking orders 64 mixtures correctly. DoReMi uses one 280M proxy; its weights gave an 8B model +6.5 points few-shot on the Pile. Both assume the best mixture for a small model stays best for a large one. Since the best filtering choice changes with compute (§3.3), the chosen mixture should be checked at scale.

Demo 06 Part B fits loss=c+∑dadlog⁡(wd+ϵ)\text{loss} = c + \sum_d a_d \log(w_d + \epsilon) to 24 tiny proxies (width 32, 200 steps; mean error 0.019 bits/byte). Minimizing ∑dadlog⁡wd\sum_d a_d \log w_d on the simplex gives wd∝−adw_d \propto -a_d in closed form. The proxies favour story and wiki and give math and code less weight than uniform. A plausible reason: proxies that small barely learn arithmetic or value tracking, so more of those domains does not help them. At 3× the width and 2.5× the steps:

mixtureweights story/wiki/math/codeproxy predictionlarge model (val bits/byte)
natural0.55 / 0.15 / 0.15 / 0.151.1340.795
uniform0.25 / 0.25 / 0.25 / 0.251.1270.792
proxy-chosen0.36 / 0.32 / 0.15 / 0.181.1120.797
best proxy run0.53 / 0.21 / 0.13 / 0.131.1240.799

The four land within 0.007 bits/byte of each other. Three samples of the same natural mix span 0.010. The differences are inside the noise floor, and the proxies’ ranking did not carry over (Spearman −0.60).

This is not a refutation of RegMix: at 512 proxies and real data its rank predictions held. But it is exactly the failure the slides warn about: a proxy that cannot learn a domain cannot value it, and a verification run without a noise floor (Lecture 8) would have declared a winner.

4.4 Save the best data for the end

While the learning rate decays, switch to higher-quality data:

  • the top quality buckets;
  • math and code;
  • instruction-style and synthetic text.

OLMo 2 7B trained on 3.9T tokens of mostly web text, then on 50B tokens of a curated mid-training mix (reported). An anneal continues a partly trained model on candidate data while the learning rate decays. Its effect shows up within tens of billions of tokens, far less than training from scratch, so anneals are how mid-training data is chosen. OLMo 2 ran 19 microanneals (130B tokens in total); adding math data lifted a 7B model’s GSM8K from 28.5 to 61. Llama 3’s final pre-training mix was 50% general, 25% math and reasoning, 17% code and 8% multilingual, chosen with small models and scaling laws.

Demo 06 Part C runs two otherwise identical 800-step WSD runs. In one, the final 160 steps (the decay) switch to a wiki- and math-heavy mix:

runstorywikimathcodeallfact accuracy
decay on the main mix0.7610.7061.3050.7300.76518.2%
decay on the high-quality mix0.7650.6741.2660.7360.76329.2%

Twenty percent of the steps lift fact accuracy by 11 points and improve math, at a 0.004 cost on story text.


5. Curation at scale

5.1 Running an LLM over the whole crawl costs more than training

Training costs about 6ND6ND FLOPs; inference about 2N2N per token. Demo 05 of Lecture 9 checked the training side; demo 07 here computes the curation side:

stepFLOPs× training an 8B model on 15T
70B judge labels 460K pages6.4e190.0001
110M classifier scores 15T tokens3.3e210.005
110M classifier scores 240T tokens5.3e220.07
12B model rephrases 1.8T tokens (output only)4.3e220.06
70B model scores all 240T tokens3.4e2547

This is why the pipeline runs rules first, then a small classifier distilled from an LLM. As a check, FineWeb-Edu reports 6,000 H100-hours for 15T tokens, about 15% of H100 peak. Small-model inference over short documents is far from the roofline.

5.2 Throughput, not latency

Curation processes billions of documents, so total throughput matters far more than the latency of one document. The Curator lecture’s example: you have 2 GPUs, and a sample takes 2 s on one GPU or 1.5 s on two. Giving each sample both GPUs makes one sample faster, but 1,000 samples take 1,500 s instead of 1,000 s (demo 07 Part B).

The worked example (from the slides): 1,000 inputs and 1 GPU with 102 GB. The three stages are language ID (0.5B model, 1 GB, 2 s), tokenization (CPU, 1 s) and a 5B model (10 GB, 10 s). Demo 07 simulates it:

plantotal timemodel workers busyGPU memorymax queue before the model
one input at a time through all stages13,000 s77%11 GB1
streaming, 1 copy per stage, unbounded queues10,004 s100%11 GB800
streaming, 1 copy per stage, queues capped at 810,004 s100%11 GB8
streaming + balanced copies (2, 1, 10)1,013 s99%102 GB1
  • Streaming (流式处理) lets an input move on as soon as a stage finishes it, so the stages overlap. Alone it is limited by the slowest stage.
  • Backpressure (背压) pauses a fast stage when the queue to a slow stage is full. Without it, the queue in front of the model grew to 800 inputs: memory filled with work the slow stage had not reached.
  • Balancing (负载均衡) gives each stage copies in proportion to its cost, so every stage runs at the same rate (1 input/s). It needs the memory to fit them: 2 × 1 GB + 10 × 10 GB = 102 GB.

The slide’s caveat: this assumes copies on the same GPU do not slow each other down, i.e. that one copy leaves most of the GPU’s compute idle. On real hardware, measure the rate per copy as you add copies.

5.3 NeMo Curator

NeMo Curator (v1.3) turns this into four abstractions:

  • a Task (a DocumentBatch: a table of documents, in practice a pandas DataFrame);
  • a Stage (takes and returns tasks, and declares its CPU/GPU resources);
  • a Pipeline (a list of stages);
  • an Executor (Cosmos-Xenna on Ray, Ray Actor Pool, or Ray Data), which runs the pipeline on a Ray cluster.

The executor measures each stage’s throughput and reassigns workers, so the balancing above happens without hand-tuning. Backpressure is built in, and GPU stages stay above 99% busy after warm-up (reported). Filters, classifiers and rephrasing handle one document at a time and stream this way. Deduplication cannot: it runs as a separate GPU workflow (MD5 grouping for exact; MinHash, LSH and a graph of duplicate relations for fuzzy) and is the hardest stage to scale.

Demo 07 Part D measures this lecture’s own stages per document on a laptop:

stagetime per document
extraction~4 µs
rules~19 µs
classifier~24 µs
language ID~69 µs
MinHash signatures~70 µs

A balanced deployment gives the slowest stages the most workers. The signatures stream; the bucketing and clustering do not.

The Nemotron-CC workflow in Curator:

  1. download and extract Common Crawl;
  2. language ID and filtering;
  3. Unicode fixing (I&#39;d → I'd);
  4. exact dedup;
  5. fuzzy dedup;
  6. 20+ heuristic filters (e.g. > 25% non-alphanumeric, > 20% URLs, or a word longer than 1,000 characters → discard);
  7. perplexity filtering;
  8. quality classification by an ensemble of FineWeb-style educational classifiers into buckets;
  9. synthetic data generation: a Wikipedia-style rephraser for low-quality documents; diverse QA pairs, distillation, knowledge extraction and knowledge lists for high-quality ones (Lecture 11).

Failure modes (both lectures):

symptomfix
OOM when reading input (e.g. 10 GB Parquet files; pyarrow “offset overflow”)reshard into ~256 MB files; fewer files per partition
OOM in classifier inferencelower the inference batch size
dead CPU workers or Ray subprocesseslimit the CPUs given to Ray; each worker has memory overhead

The design rules of thumb:

  1. Partitions should fail cheaply.
  2. Budget memory per stage, not globally.
  3. If you didn’t log it, you can’t debug it. Log throughput, memory and drop rates for every stage.
  4. Connect curation techniques to training outcomes.

Data KPIs (Spring slides): unique documents and tokens; domain and language distributions; classifier-score distributions; toxicity and PII hit rates; perplexity by domain; exact-duplicate rate and near-duplicate cluster sizes; n-gram overlap with eval sets. Treat the dataset as code: version it, test it, monitor it.


6. Summary

  1. Runs need more data than Chinchilla said (Llama 3 8B: 94× its optimum), and the largest filtered web datasets hold about one 15T run’s worth. Data is the least documented part of model reports.
  2. Curation is mostly deciding what to throw away, in stages ordered cheap to expensive (DCLM keeps 1.4% of documents). Each decision is an ablation on small models.
  3. Every filter removes good data too, unevenly. In the toy crawl, a stop-word rule deleted all math (5.087 bits/byte on math), and a blocklist removed 80% of one benign topic. Raw dumps cost +0.157 bits/byte against extracted text.
  4. “Quality” means whatever a filter was built to find. A distilled judge classifier trained the best non-oracle model. Wiki-referenced classifiers and perplexity filters deleted math and code entirely. Learned filters disagree (30% kept by all three; 10% by both FineWeb-Edu and DCLM on real data).
  5. Up to ~4 epochs repetition is nearly free (+0.005 bits/byte), 16+ is not (+0.170, then collapse). A small repeated subset hurts. Filtering stops paying as compute grows: filtered data won at 100 steps and lost at 1,600. Long runs keep more data and weight it by quality.
  6. Dedup: exact is precise but misses near copies. MinHash + LSH finds 96% at FineWeb’s 14 × 8 (threshold ≈ 0.68). Run it on extracted text, per snapshot, and decontaminate against benchmarks.
  7. Mixtures decide what the model knows. Facts stated 51+ times were 100% correct, 0 times 4%. Proxy-chosen weights must be verified at scale against a noise floor. Annealing on the best data during the decay lifted fact accuracy from 18% to 29% in 20% of the steps.
  8. At web scale, curation is a distributed system whose cost is set by model inference and global dedup. Streaming, balancing and backpressure turned 13,000 s into 1,013 s; dedup cannot stream.

7. Common pitfalls

  • Judging a filter by how clean its output looks instead of by the model it trains.
  • Keeping a rule because it removes junk, without checking which good data it removes (stop words vs math; blocklists vs topics and dialects).
  • Training a quality classifier on a reference set that lacks a domain you need.
  • Dedup on raw HTML or WET text (templates dilute and merge), or global dedup across snapshots without checking which copies are kept.
  • Forgetting decontamination after adding a new data source.
  • Treating mixture search with tiny proxies as final, or comparing mixtures without a noise floor.
  • Filtering as hard at 1e26 FLOPs as at 1e21: with enough compute, unique tokens matter more.
  • Optimizing the latency of one document instead of total throughput; unbounded queues between unbalanced stages.
  • 10 GB input files in a distributed pipeline.

8. Exercises

  1. Epochs. You plan an 8B model on 30T tokens; your filtered pool has 6T unique tokens. How many epochs? What do Muennighoff et al. suggest about the value of the repeated passes, and what would you do instead?
Answer

5 epochs. Up to about 4 epochs repeated tokens are nearly as valuable as new ones, and the 5th is somewhat less so. That is acceptable, but at the margin you would loosen the filter (soft filtering: keep middle-quality buckets at lower weight, à la Nemotron-CC) or add rephrased synthetic data (Lecture 11) to raise the unique tokens, rather than repeat the top bucket many times.

  1. The LSH curve. With b=20b = 20, r=5r = 5, what is the probability that documents with s=0.8s = 0.8 become candidates? With s=0.4s = 0.4? Compare with FineWeb’s 14 × 8.
Answer

1−(1−0.85)20=1−(1−0.328)20=1−0.67220≈0.99961 - (1 - 0.8^5)^{20} = 1 - (1 - 0.328)^{20} = 1 - 0.672^{20} \approx 0.9996. At s=0.4s = 0.4: 1−(1−0.01024)20≈0.1861 - (1 - 0.01024)^{20} \approx 0.186. For 14 × 8: s=0.8→1−(1−0.168)14≈0.924s = 0.8 \to 1 - (1 - 0.168)^{14} \approx 0.924; s=0.4→1−(1−0.00066)14≈0.009s = 0.4 \to 1 - (1 - 0.00066)^{14} \approx 0.009. So 20 × 5 is looser: higher recall (demo 04: 97.4% vs 95.8%) and more false candidates at moderate similarity, which then cost more verification.

  1. Rule audit. A new rule “drop documents where fewer than 70% of tokens are dictionary words” removes 30% of the crawl. What two measurements would you make before adopting it?
Answer

(1) What it removes, broken down by domain, language and topic, with samples read by a human: code, math, names, technical text and other languages will fail a dictionary test. (2) An ablation: the same small model and token budget, with and without the rule, scored on per-domain validation loss and early-signal benchmarks. Adopt it only if the model improves without a regression on a domain you need.

  1. Temperature sampling. Three languages have 900B, 90B and 10B tokens. With α=0.5\alpha = 0.5, what are the sampling weights? For a 300B-token run, how many epochs does the smallest language get?
Answer

p=0.9,0.09,0.01p = 0.9, 0.09, 0.01; p0.5=0.949,0.300,0.100p^{0.5} = 0.949, 0.300, 0.100; normalized w=0.703,0.222,0.074w = 0.703, 0.222, 0.074. The smallest gets 0.074×300B=22.2B0.074 \times 300\text{B} = 22.2\text{B} tokens = 2.2 epochs, within the “nearly free” range. With α=0.3\alpha = 0.3 it would get more (weight 0.147, 44B tokens, about 4.4 epochs), approaching the point where repetition costs.

  1. The cost of a judge. Labelling 1M documents (1,000 tokens each) with a 70B model, and training a 150M classifier on them, then scoring 20T tokens: compare the FLOPs with scoring all 20T tokens with the 70B model.
Answer

Labelling: 2×70B×109=1.4×10202 \times 70\text{B} \times 10^9 = 1.4 \times 10^{20}. Scoring with the classifier: 2×150M×2×1013=6×10212 \times 150\text{M} \times 2 \times 10^{13} = 6 \times 10^{21} (training the classifier is negligible). Total ≈ 6.1×10216.1 \times 10^{21}. Scoring everything with the 70B model: 2×70B×2×1013=2.8×10242 \times 70\text{B} \times 2 \times 10^{13} = 2.8 \times 10^{24}, about 460× more.

  1. Balancing. A pipeline has stages taking 0.5 s (CPU), 4 s (GPU model A, 8 GB) and 12 s (GPU model B, 20 GB) per item on a 80 GB GPU. What copy counts balance it, and what throughput do you get?
Answer

Balance to the same per-stage rate: copies ∝ time, i.e. 1 : 8 : 24 for a rate of 2 items/s. That needs 8×8+24×20=5448 \times 8 + 24 \times 20 = 544 GB, which does not fit. Under 80 GB, maximize rr subject to 4r×8+12r×20≤804r \times 8 + 12r \times 20 \le 80 GB: 272r≤80272 r \le 80, so r≈0.29r \approx 0.29 items/s (e.g. 1 copy of A and 3 of B: rates 0.25 and 0.25 items/s with 68 GB). More GPUs or smaller models raise it. Measure the per-copy rate, since copies may contend.

  1. Why per-snapshot? Explain in two sentences why global dedup across crawl snapshots can lower data quality, and propose a dedup policy that avoids it.
Answer

Good pages tend to be re-crawled in later snapshots while low-quality pages appear once. So global dedup removes good pages from each old snapshot (they reappear elsewhere) and keeps the never-re-crawled junk, biasing the kept set. Dedup within each snapshot (FineWeb), or dedup globally but choose which copy to keep by quality score rather than by order.

Assignment 2 (pre-train from scratch on one 8×H100 node) depends on data choices made before the run:

  • which public corpus or mixture to start from;
  • whether to filter further or weight by quality;
  • how many epochs your token budget implies;
  • which domains your evaluation needs (do not filter them away);
  • what to anneal on at the end.

The Spring 2026 course also had a NeMo Curator lab: build usable pre-training datasets with Curator’s stages. No assignment solutions are given here; crawl.py and curate.py are independent of the course materials.

10. Research directions

  • Filtering that scales with compute. If filtering pays less as budgets grow, what replaces it: soft weighting, quality-aware curricula, rephrasing (Lecture 11)? How should the optimal filter strength be predicted from the budget?
  • Proxies that can see every domain. Mixture search fails when proxies cannot learn a domain. Can mixtures be chosen from per-domain scaling curves rather than from one small model’s loss?
  • Auditing filter bias. Blocklists and classifiers remove text about some topics, groups and dialects. Cheap, systematic audits of what each filter removes, by slice, before it is adopted.
  • Dedup policies as sampling policies. Which copy a dedup keeps changes the data distribution (FineWeb’s global-dedup finding). Quality-aware and temporally aware dedup.
  • Curation systems. Streaming global dedup; autobalancing across heterogeneous CPU/GPU stages; making curation runs as reproducible and versioned as training runs.

11. Further reading

  • FineWeb (arXiv:2406.17557): extraction, dedup per snapshot, FineWeb-Edu.
  • DCLM (arXiv:2406.11794): the filter ablations (Table 4), the funnel.
  • Nemotron-CC (arXiv:2412.02595): classifier ensembles, quality buckets, soft filtering, rephrasing.
  • C4 / T5 (arXiv:1910.10683) §2.2; Dodge et al., Documenting Large Webtext Corpora (arXiv:2104.08758).
  • Lee et al., Deduplicating Training Data Makes Language Models Better (arXiv:2107.06499).
  • Muennighoff et al. (arXiv:2305.16264); Hernandez et al. (arXiv:2205.10487); Villalobos et al. (arXiv:2211.04325).
  • Mohri, Duchi, Hashimoto, A Bitter Lesson for Data Filtering (arXiv:2605.19407).
  • Kandpal et al., Large Language Models Struggle to Learn Long-Tail Knowledge (arXiv:2211.08411).
  • DoReMi (arXiv:2305.10429); RegMix (arXiv:2407.01492); OLMo 2 §4 (mid-training, microanneals).
  • Maini et al., Safety Pretraining (arXiv:2504.16980).
  • NeMo Curator (github.com/NVIDIA-NeMo/Curator): the quickstart tutorial and the Nemotron-CC workflow.

12. Next lecture

Lecture 11 · Synthetic Data for Pre-Training. Filtering only removes; the stock of human text is finite. Lecture 11 covers making new training data with models:

  • rephrasing web pages into new forms that carry the same facts;
  • textbook-style generation from seed topics, and its narrow coverage;
  • distillation, where the teacher writes the targets;
  • the quality control and reproducibility of generation pipelines;
  • model collapse when models train on their own outputs.

It starts from this lecture’s crawl.


术语表 (Glossary, English → 中文)

English中文
pre-training / mid-training data预训练数据 / 中期训练数据
Common Crawl / WARC / WET / snapshot通用网页爬取 / 原始网页存档 / 纯文本导出 / 快照
curation pipeline / funnel数据整理流水线 / 漏斗
ablation消融实验
text extraction / boilerplate正文抽取 / 模板噪声
language identification (LID)语种识别
heuristic filter / terminal punctuation / stop words / blocklist启发式过滤 / 句末标点 / 停用词 / 屏蔽词表
filter bias过滤偏差
quality classifier / LLM judge / distillation质量分类器 / 大模型评审 / 蒸馏
reference data (positives) / random web (negatives)参考数据(正例) / 随机网页(负例)
perplexity filter困惑度过滤
hard filtering / soft filtering / quality bucket硬过滤 / 软过滤 / 质量分桶
data-constrained scaling / epoch / repetition数据受限缩放 / 轮次 / 重复
memorization / regurgitation记忆 / 逐字复现
exact / fuzzy deduplication精确 / 模糊去重
shingle / MinHash / LSH / band / row词片 / 最小哈希 / 局部敏感哈希 / 带 / 行
Jaccard similarity / candidate pair / connected component / union-find杰卡德相似度 / 候选对 / 连通分量 / 并查集
contamination / decontamination测试集污染 / 去污染
mixture weights / temperature sampling数据配比权重 / 温度采样
proxy model / mixture search / rank invariance代理模型 / 配比搜索 / 排序不变性
annealing / microanneal退火 / 微退火
long-tail knowledge长尾知识
throughput / latency吞吐量 / 延迟
streaming / backpressure / load balancing / autobalancing流式处理 / 背压 / 负载均衡 / 自动均衡
executor / stage / task / partition执行器 / 阶段 / 任务 / 分区
provenance / data versioning数据溯源 / 数据版本管理
← 返回课程目录