TL;DR
The model reads text through the Llama 3.2 tokenizer, whose vocabulary has 128,256 tokens. Pretraining used 2,600,591,645 tokens of FineWeb-Edu, after dropping the 1,141 documents (0.044%) that shared 10 consecutive words with a test question. For SFT I kept 55,083 of NVIDIA’s 73,643 new GSM8K-style questions; about 11% had no exact answer, so I dropped them. The RL curriculum has four tiers built from training splits only, with a test set held out at every tier. NVIDIA’s decontamination had kept changed-number copies of test questions, and two of my own filters passed their unit tests while wrong.
What you’ll learn
- What a tokenizer does, and how to check one against your data.
- How to turn web text into Megatron training files: masking, decontamination, a hash split and tokenizing.
- How to turn synthetic math data into exact-answer SFT data, and why every filter needs its own spot check.
- How to build an RL curriculum whose test questions never leak into training.
- Which data checks to run before a long GPU run.
Tokenizers, briefly
What a tokenizer does
A language model never sees characters. A tokenizer cuts text into pieces called tokens and maps each one to an integer id from a fixed list, the vocabulary. The model reads ids and, at every position, predicts the id of the next token. The vocabulary size \(V\) fixes the size of the embedding and the output layer, two of the model’s largest matrices.
Most modern tokenizers use byte-pair encoding (BPE). Training starts from single bytes and keeps merging the most frequent adjacent pair into a new token. Common words end up as one token and rare words as several. Because the base units are bytes, any text can be encoded, so no “unknown” token is needed.
Here is one question from our SFT data: 48 Llama 3.2 tokens, with a 66-token worked answer.
{"id": "0007c485660204e0", "question": "A theater performance had an audience of 240 people. The theater company had given 30 complimentary tickets to local arts students and 40 tickets to staff members. The remaining audience members were paying customers. How many paying customers attended the performance?", "response": "<think>\nThe theater company gave 30 + 40 = 70 tickets away for free.\nThere were 240 people in the audience.\nSo, the number of paying customers is 240 - 70 = 170.\nThus, 170 paying customers attended the performance.\n</think>\n<answer>170</answer>", "answer": "170", "votes": 31, "passing_solutions": 31, "question_tokens": 48, "response_tokens": 66, "source": "nvidia/OpenMathInstruct-2:augmented_gsm8k"}
Ours: Llama 3.2, and why
My launch scripts start from the tested recipe in Hugging Face’s MoE training handbook [1]. It says: “We will use FineWeb-Edu and the Llama 3.2 tokenizer.” I kept both. I took the ungated copy unsloth/Llama-3.2-1B [2], where the handbook’s “comparison found matching vocabulary and token IDs” with Meta’s original.
What the tokenizer file holds:
- 128,000 BPE tokens plus 256 special tokens: 128,256 in all.
<|end_of_text|>, id 128001. I append it after every pretraining document and every SFT answer, so the model learns where text stops.- A rule that splits runs of digits into chunks of at most three before the BPE merges. So a long number is always several tokens.
A large vocabulary is not free, because each id owns one vector of the hidden size:
where \(V\) is the vocabulary size and \(d = 2{,}048\) is the model’s hidden size.
In words: the token table holds about 263M parameters, and our model ties the input and output matrices, so this one table serves both.
That is most of the 416M parameters every GPU holds outside the experts (Part 2 has the full count).
Checking the tokenizer against our data
FineWeb-Edu counts its tokens with GPT-2’s tokenizer, not ours. On a sample of 1,000 documents, Llama 3.2 gave 0.9804 tokens per GPT-2 token. So the five files I downloaded held about
where \(N_{\text{GPT-2}}\) is the files’ token count by FineWeb-Edu’s own count and \(r\) is the measured ratio.
In words: the download held about 3.68B tokens in our tokenizer, comfortably above the 2.5B target before any filtering.
Every data manifest records the tokenizer file’s SHA-256. The GPU node downloads the same three files at a pinned revision and checks them. The tokenizer is Llama 3.2 material under Meta’s community licence, whose attribution terms apply if trained weights are ever released.
The pretraining data: FineWeb-Edu
What I used
Pretraining needs a lot of clean, varied text. FineWeb-Edu [3] is a public English web dataset. Hugging Face’s Smol training playbook names it, with DCLM, among “the strongest open English web datasets at the time of training” [4].
I took the sample/10BT subset: 14 files, 28.52 GB, about 10B tokens. I downloaded files 000 to 004 (10.76 GB) in 9 min 03 s, and all five matched the Hub’s listed size and SHA-256. They hold 3,661,000 documents.
Preparation, step by step
code/scripts/prepare_pretrain_data.py treats each document in file order:
- Mask e-mail addresses (as
email@example.com) and IPv4 addresses (as0.0.0.0). - Drop the document if any 10 consecutive words also occur in a question of any held-out test set.
- Put it in validation if
int(sha1(id)[:8], 16) % 100 == 0: a fixed 1% of documents, the same on every rebuild. - Tokenize it with Llama 3.2, add no special tokens, then append
<|end_of_text|>. - Write Megatron’s
.bin/.idxfiles with Megatron’s own builder.
It stops at a token target. Its manifest records the SHA-256 of every input file, the tokenizer and the script itself.
The math: the n-gram overlap test
Step 2 is the decontamination rule, and the same rule cleans the RL curriculum below. Write a text \(x\) as its words: lower-cased runs of letters and digits. Its set of \(n\)-grams is
where \(w = (w_1, \dots, w_{|w|})\) are the words of \(x\) and \(n\) is the window length.
In words: \(G_n(x)\) is every run of \(n\) consecutive words in the text.
A document \(d\) is dropped when
where \(\mathcal{T}\) is the set of questions in the six held-out test sets (GSM8K, MATH, MAWPS, MultiArith, ASDiv, SVAMP).
In words: if any 10-word window of the document appears in any test question, the document goes.
The union on the right holds 212,854 distinct 10-grams. The rule over-matches stock phrases. In the pilot, pages were dropped for strings like “is equal to the sum of the squares of the”, found in a MATH test question.
I kept the rule as written: at 0.03% of documents it lost almost nothing, and over-dropping is the safe side.
Tests, then a pilot
Five unit tests came first. They cover the masking, the split, the token-target stop and the 10-word rule (a 9-word match is not flagged). One runs end to end on a 300-document synthetic file, read back with Megatron’s reader.
Testing found two bugs. The worker pool could not pickle the script’s function. It also forked a process that already ran threads, which can deadlock, so it now uses spawn.
| Measure | Pilot (stopped at 20M tokens) |
|---|---|
| Documents read / dropped | 21,000 / 7 (0.033%) |
| Training tokens | 21,174,966 (20,788 documents) |
| Validation tokens | 197,770 (205 documents, 0.98%) |
| Time | 22.1 s, about 0.96M training tokens/s |
The full build
The full run took 910.6 s on the laptop with 7 worker processes and exited cleanly. It averaged 2.86M training tokens/s, three times the pilot’s rate. A 22-second pilot never reaches steady speed, so my 45-minute estimate was wrong.
| Measure | Full build |
|---|---|
| Row groups read | 2,622 of 3,661 (stopped at the target) |
| Documents read | 2,622,000 |
| Dropped by the 10-gram rule | 1,141 (0.044%) |
| E-mails / IPs masked | 75,946 / 21,665 |
| Training | 2,594,765 documents, 2,600,591,645 tokens |
| Validation | 26,094 documents (1.00%), 26,012,769 tokens |
The file sizes check the token counts. Token ids run up to 128,255, beyond the 65,535 that 16 bits can hold. So each token is stored as a 4-byte integer:
where \(N_{\text{tokens}}\) is the training split’s token count.
In words: the training file is exactly 4 bytes per token, and the validation file matches too: 104,051,076 bytes for 26,012,769 tokens.
Pretraining used these tokens in about one pass: 634,880 sequences of 4,096 tokens, or 1,240 steps of 512 sequences (Part 6). Files 000 to 002 and part of 003 were used; the rest is spare.
One check I skipped: reading real documents back through Megatron’s reader and decoding them. Only the synthetic unit test did that.
The SFT data
What it had to teach
Supervised fine-tuning (SFT) trains on question and answer pairs, with the loss on the answer only. Ours had one job: teach the answer format the RL reward reads, <think>…</think> then <answer>X</answer>. The RL checker compares final answers exactly (Part 8), so every SFT label had to be exactly right too.
The choice
My plan named no dataset. The obvious candidates each had a problem:
- GSM8K train is my RL curriculum’s hard tier.
- MetaMathQA is rewritten from GSM8K and MATH training questions, so it repeats RL questions.
- NuminaMath’s
orca_math: a search found MultiArith and MAWPS test questions in it word for word (not re-checked). - Templating my own RL datasets would use up RL and test questions.
I chose the augmented_gsm8k part of OpenMathInstruct-2 (Toshniwal et al., 2024) [5, 6]. Its questions are new, and its teacher is open-weight (Llama-3.1-405B-Instruct). Each question also carries the teacher’s own vote count, a confidence signal the others lack.
What the sources say
- The labels are votes. The paper says “we instead use majority voting among the 32 generations as a proxy for the ground-truth answer” [5]. The card: “For augmented problems, it is the majority-voting answer.” [6]
- There is no minimum vote. For an 8B student, minimum votes of 0, 8, 16 and 24 gave MATH validation accuracies of 50.1, 49.2, 44.4 and 42.0. The data shrank from 381K to 160K examples, and the authors chose 0.
- Four test sets were checked. Their decontamination, a MiniLM retriever plus a Llama-405B judge, “removes about 50K questions out of the 569K new questions synthesized” [5]. It covered GSM8K, MATH, AMC 2023 and AIME 2024, so four of my six test sets were never checked.
In 100 real rows, all answers parsed as one number, but 16 were not integers, including rounded repeats such as 66.67. One solution wrote “we round this to 26” for “2/3 of 40 chicks”, which has no whole answer.
The build rules
My starting recipe was simple: one solution per question, shortest first; decontaminate; strip LaTeX; one template; spot-check 50 rows. Checking it against the data changed most steps. code/scripts/prepare_sft_data.py lists every rule in its docstring.
| Step | Rule as built | Why |
|---|---|---|
| Labels | keep a question only if at least 16 of the teacher’s 32 samples agreed | a weak student needs clean labels more than hard questions |
| Arithmetic | every equation in the kept solution must be exactly true in fraction arithmetic; no rounding wording | the checker compares exactly, so 66.67 for 200/3 would teach a wrong label |
| LaTeX | convert light LaTeX to text and replace \boxed{X} with X in place; drop the rest |
the answers are plain numbers; the LaTeX is in the working |
| Overlap | exact or 10-gram match with any test or RL question; a numbers-masked 10-gram rule; an embedding search against all six test sets | changing the numbers defeats a plain 10-gram rule |
| Length | the shortest passing solution, at most 768 tokens | verbose solutions hurt SFT, and 768 is where the RL length penalty starts |
| Checks | 50 kept rows solved blind, and 10 drops per filter read | an error rate needs an interval, and each filter needs its precision measured |
The numbers-masked rule applies test (4) after replacing every number with a placeholder:
where \(w_i\) is the \(i\)-th word of the question.
In words: the same wording with different numbers counts as an overlap.
The embedding search uses the retriever the dataset’s authors used, multi-qa-MiniLM-L6-cos-v1 [7]. It compares two questions’ sentence vectors by their cosine:
where \(u\) and \(v\) are the embeddings of a training question and a test question.
In words: how nearly the two questions point in the same direction in embedding space.
A question is dropped if its cosine to the nearest test question reaches 0.90, or 0.80 when both share an answer. I wrote these thresholds down before computing any similarity.
Build 1, and what reading the drops showed
The question filters ran first. Of 73,643 questions (2,111,683 solutions), 68,644 had one numeric answer and at least 16 of 32 votes. The overlap rules left 63,247, and the embedding search 63,224. After the solution checks, build 1 kept 60,379 questions.
Of 1,895,559 solutions checked, 73.6% passed. LaTeX rejected 16.0%, rounding wording 6.7%, a false equation 2.1%, and an equation true only after rounding 1.5%. The 16% LaTeX rate was far above what the 100-row sample suggested, so I treated it as suspect. Seeded samples of every filter’s drops were then read one by one.
Trap 1: two filters passed their unit tests and were wrong
- The LaTeX filter threw away money problems. 9 of 10 sampled rejects were good solutions. The teacher marks money amounts with a lone
$sign, on lines that also hold$…$math. My converter counted an odd number of$signs and rejected the whole solution. - The “false equation” filter caught no real slips. Of 10 sampled, 8 were machine floats (“2/3 * 7.5 = 0.6666666666666666 * 7.5 = 5”), which exact arithmetic cannot match. The other 2 read a label or a coefficient as a number.
Build 2 fixed both: a $ pair counts as math only if the text between them has a digit and no English word. LaTeX rejections fell from 303,597 to 7,481, and 593 money questions came back.
It happened again in build 4, where a new rule stripped unit words to read arithmetic “as a person would”. Then 7 to 8 of 10 sampled “false equation” flags were false. It read “gives x − 8 = 12” as “3 − 8 = 12”, and about 970 more questions lost every solution. Build 5’s fix: that reading may flag a step as rounded, never as false.
The unit tests passed throughout, because they tested the rules I wrote. Only real samples showed the teacher’s conventions.
Trap 2: decontamination that keeps changed-number copies
Across all 73,643 questions, 78 shared a 10-word run with my test sets, 52 of them with GSM8K test. Of 10 sampled, 2 were real copies of GSM8K test questions with new numbers. One test question begins “A plane travels 1200 miles in 3 hours. At the same rate…”; its copy, “A bus travels 280 miles in 4 hours. At the same rate…”.
NVIDIA’s judge explains why they passed. Its prompt, in the authors’ NeMo-Skills code [8], defines a duplicate:
“If the two problems are very similar and if they produce the same answer, we consider them to be the same problem.”
New numbers give a new answer, so by that definition a changed-number copy is a different problem. My rules dropped 5,126 questions for an exact or 10-gram overlap, 226 more under the numbers-masked rule and 23 under the embedding rule. Of the 5,126, 5,042 overlapped my RL hard tier, which holds GSM8K train, the authors’ seed set.
The numbers-masked rule has low precision. In a sample of 10 drops, about 1 was borderline; the rest were generic phrases like “N quarters, N dimes, N nickels and N pennies”. I kept it, since it removes only 0.3% of questions.
One limit remains. The closest kept questions (cosine 0.889 to 0.899) were the same topic but different problems: sentence embeddings separate topics, not problems.
Trap 3: about 11% of the questions have no exact answer
Looking at examples found a rounded label that every check had missed. A question with 32 of 32 votes asks for an average; the kept answer says “11/3 hours”, then labels it 3.67. Under an exact checker, a model answering 11/3 would be marked wrong. Build 3 added a rule: reject a solution whose computed value differs from a decimal label but rounds to it.
A blind check of build 3 found more of the kind. Its procedure was fixed before build 2. Fifty kept questions were drawn at random and solved from the question text alone, with the answers saved before any label was seen.
- 44 of 50 agreed; 4 labels were not exact (two rounded, two ill-posed), and 2 were ambiguous but defensible.
- One cut-off sentence was NVIDIA’s own: “Thus, Rachel is \boxed{6} years ol”.
- My converter had turned the mixed number
9\frac{1}{3}into “9(1/3)”, which reads as 9 × 1/3. - Of 1,508 questions with a single passing solution, 7 of 8 sampled were rounded or ill-posed.
The pattern: when the teacher keeps having to round, the question has no exact answer. Build 5 added a question-level rule:
where a rejection counts as rounding if the solution has rounding wording, a rounded equation, a rounded label or a machine float.
In words: if the teacher itself had to round in at least half of its attempts, the question is unfit for exact-answer training.
It dropped 7,997 of the 73,643 questions, about 11%. Among those, the median share of rounding rejections was 0.92. Of 12 sampled drops, 11 were ill-posed: “a fifth of 48 CDs”, “25 herbs divided evenly among 6 planters”, “two-thirds of an 800-meter bridge”. The exception had an exact answer, 221/4 = 55.25 pounds.
Matching the authors’ own recipe
I also read the authors’ own preparation code, NeMo-Skills at commit bcf059af55c2 [8]. Its SFT step drops contaminated questions, anything over 1,024 tokens and solutions under 200 characters. It also cuts each solution after its final \boxed{} line. Builds 3 to 5 apply all four steps, plus my checks.
I did not run their code as is: it writes \boxed{} answers, not my reward’s format, and skips my extra test sets.
Five builds, and when to stop
| Build | Questions kept | What changed | What the check found |
|---|---|---|---|
| 1 | 60,379 | the rules above | LaTeX and “false equation” filters mostly wrong |
| 2 | 60,972 | currency-aware $; labels skipped; machine floats rejected |
8 of 10 “false equation” rejects now real |
| 3 | 60,385 | the authors’ trim and 200-character minimum; the rounded-label rule | blind check: 4 of 50 labels not exact |
| 4 | 59,420 | arithmetic read “as a person would”; mixed numbers rejected | 7 to 8 of 10 “false equation” flags false |
| 5 | 55,083 | rule (8); the unit-stripping reading may only flag rounding | blind check: 0 of 50 wrong |
A blind check gives an error rate with an interval, not a certainty. With 0 errors in \(n\) questions, the exact (Clopper–Pearson) 95% upper bound is
where \(n = 50\) is the number of questions checked and \(\alpha = 0.05\) for a 95% interval.
In words: if the true error rate were above 7.1%, a sample of 50 would show no error less than 2.5% of the time.
Before build 5 ran, I wrote the stopping rule. A fresh blind check of 50 new questions decides: build 5 is frozen unless it shows a systematic bug, and more than 2 errors are documented.
All 50 agreed, so the label error rate lies in [0%, 7.1%] at 95%, against build 3’s 4 of 50. Ten kept responses read in full were complete, with exact arithmetic. The known limits: questions needing rounding are mostly excluded, and the label checks cover 100 questions in all.
The final set, in Megatron’s format
The frozen set has 55,083 questions: 53,970 for training and 1,113 for validation. Its answers are 49,321 integers, 5,743 decimals and 19 fractions. The responses average 107.5 tokens (median 100, maximum 441), 5.92M tokens in all. The theater question above is one line of the final training file, exactly as stored.
The template. I used Megatron’s identity prompt format, which joins the messages’ text and adds nothing. The default format writes Nemotron’s special markers, which Llama 3.2’s vocabulary lacks. The default format needs a chat template, which our base tokenizer lacks too.
The question turn is the question plus a newline. The response turn is <think>…</think>\n<answer>X</answer> plus <|end_of_text|>, the model’s only stop signal: Megatron never adds it itself.
I checked the conversion on all 55,083 examples with the real tokenizer and Megatron’s own calls. The turns’ tokens always joined into the whole conversation, and no end token was missing or doubled. Examples ran to a median of 154 tokens (99th percentile 305, maximum 548).
Two silent bugs turned up on the way.
- The pad token. Megatron’s
identityformat pads with<unk>, which Llama 3.2 does not have, so SFT would crash at the first padding. Had a tokenizer mapped it to a real token, that token would silently drop out of the loss. Our Megatron patch uses the tokenizer’s own pad token (id 128004) and refuses a pad equal to the end token. - Padding. Megatron turns each JSONL line into one 4,096-token row, so one example per line would waste most of every row.
where \(L_{\text{example}}\) is the median example length and \(L_{\text{row}} = 4{,}096\) tokens.
In words: about 96% of every row would have been padding.
So code/scripts/make_megatron_sft.py packs examples greedily into 4,096-token lines after a fixed shuffle (seed 1234). Each example starts with an empty system turn, where Megatron splits a line into conversations.
| File | Examples | Lines | Examples per line | Fill |
|---|---|---|---|---|
| train | 53,970 | 2,210 | 24.4 | 97.8% |
| validation | 1,113 | 46 | 24.2 | 96.0% |
The line count sets the SFT run’s length:
where an epoch is one pass over the 2,210 training lines and each step takes 64 rows.
In words: three epochs take 104 steps packed, against about 2,530 unpacked.
Part 7 covers the SFT run itself.
The RL curriculum
What a curriculum is for
In RL with a right-or-wrong reward, the model samples several answers per question. It learns from the difference between the right and wrong ones (Part 9). A question it always fails, or always solves, teaches nothing. A curriculum orders questions by difficulty, so training can start where the model sometimes succeeds.
The tiers
code/rl/curriculum_data.py builds four tiers from public datasets, each loaded at a pinned revision.
| Tier | Training sources (training splits only) | Items kept | Held-out tests, never trained on |
|---|---|---|---|
| warm-up | generated arithmetic, levels 1 and 2 of code/rl/curriculum.py (“What is 58 + 27 − 19?”) | 2,000 | — |
| easy | MAWPS train, MultiArith train | 1,195 | MAWPS test (520), MultiArith test (180) |
| medium | ASDiv (80%), SVAMP train | 1,905 | ASDiv’s other 20% (407), SVAMP test (300) |
| hard | MATH levels 1–3 train, GSM8K train | 10,400 | GSM8K test (1,319), MATH test (5,000) |
MATH answers that are not plain numbers keep their LaTeX: 874 in the hard tier and 1,824 in MATH test.
Version 1 leaked nothing, but tested too little
The first build used every split and held out only GSM8K test and MATH test, so the easy and medium tiers had no test set. Version 2 trains on training splits only and holds out a test split at every tier. ASDiv ships one 2,305-problem split, so 20% goes to test by a hash of the normalized question.
Removing test questions from training data
The curriculum applies rule (4) to questions, plus an exact match after normalizing. A training question is dropped if its text equals a test question’s, or if the two share any 10-gram. The same function later cleaned the SFT data against the test sets and every RL question. Tiers are cleaned easiest first, so a question shared by two tiers stays in the easier one.
Version 2 started from 1,509 easy, 2,391 medium and 10,975 hard items. It removed 59 duplicates and 1,316 overlaps with held-out sets: MultiArith 278, SVAMP 326, ASDiv 126, MAWPS 14, MATH 555 and GSM8K 17. By the audit’s rebuild (not re-checked), most of the 744 easy and medium removals overlap the dataset’s own test split: SVAMP 318, MultiArith 258, ASDiv 31. The datasets overlap: MultiArith is part of MAWPS, and SVAMP is built from ASDiv problems.
Later changes
- 28 problems with a fooled checker. An audit of the answer checker (Part 8) found 28 LaTeX problems where it accepted an altered answer, 6 of them real holes. The 9 in the hard tier are dropped from training; the 19 in MATH test are left out of its score.
- A dev split. A fixed 2% of every tier, chosen by hash, is never trained on and serves the in-run checks.
- The controller. Every 50 RL steps the mean solve rate moves the mix: above 0.8, half a tier harder; below 0.1, half a tier easier.
In the main run, RL trained on the medium tier (Part 9).
The data checks before the GPU run
Each check below ran on the laptop before the 8×H100 run.
- Checksums. All 37 downloaded files matched their published SHA-256.
- The answer checker on every problem. It scored 23,226 problems with constructed right, wrong and junk answers. No numeric gold answer of 20,528 was rejected, no wrong numeric answer passed, and 6 of 2,698 LaTeX problems had real holes.
- The score of always giving one answer. Answering “1” to every SVAMP test question scores 8.33%, and “9” to every MultiArith question 7.78%. Results on those sets must be read against these floors (Part 13).
- The RL prompt is the SFT prompt. code/scripts/check_prompt_tokens.py builds both tokenizers with Megatron’s own classes. On all 23,226 questions it found 0 mismatches and 0 prompts starting with a beginning-of-text token. The GPU node runs it again, since its tokenizer libraries differ.
- The SFT conversion on every example, as described above.
- The upload, file by file. I uploaded the prepared files once to a private dataset repository: 26 files, 10.6 GB, in 15 min 22 s. All 26 matched the local copies afterwards. On the GPU node, the files were checked again after copying to RAM: 21 of 21 matched their SHA-256. Why RAM: on network storage, the data loader stalled the first training run (Part 6).
Run it yourself
Hardware and time. Everything here ran on a laptop with an RTX 3060 (6 GB); only the SFT embedding search used the GPU. Measured times:
- FineWeb-Edu download: 9 min 03 s; preparation: 910.6 s with 7 workers.
- OpenMathInstruct-2 download: 8 minutes; the SFT build: 851.6 s.
- The checker audit: 128 s.
Commands, from the repository root. MEGATRON_PATH is a Megatron-LM checkout at commit d6316eb45 with code/patches/megatron-d6316eb45.patch applied (the setup guide).
# 1. The tokenizer: three files at a pinned revision
hf download unsloth/Llama-3.2-1B tokenizer.json tokenizer_config.json special_tokens_map.json \
--revision 9535bd9b1d1dea6acafbdc4813b728796aeb28da --local-dir data/tokenizer/llama-3.2
# 2. The RL curriculum and the six held-out test sets (dataset revisions pinned in the code)
(cd code && python scripts/build_curriculum.py)
# 3. FineWeb-Edu: five files, then 2.6B training tokens in Megatron's format
hf download HuggingFaceFW/fineweb-edu --repo-type dataset \
--include "sample/10BT/00[0-4]_00000.parquet" --local-dir data/fineweb-edu/raw
(cd code && python3 scripts/prepare_pretrain_data.py --input-dir ../data/fineweb-edu/raw/sample/10BT \
--tokenizer ../data/tokenizer/llama-3.2/tokenizer.json --heldout-dir ../data/curriculum \
--out-dir ../data/pretrain --max-train-tokens 2600000000 --workers 7)
# 4. The SFT set: download and verify, build, then pack for Megatron
bash code/scripts/download_openmathinstruct2.sh
(cd code && python3 scripts/prepare_sft_data.py \
--input-dir ../data/sft/openmathinstruct2/469216e3f46f4dacf476b382e192485ea51a143e \
--curriculum-dir ../data/curriculum --tokenizer ../data/tokenizer/llama-3.2/tokenizer.json --out-dir ../data/sft)
python -I code/scripts/make_megatron_sft.py --tokenizer data/tokenizer/llama-3.2 \
--inputs data/sft/sft_train.jsonl data/sft/sft_valid.jsonl --out-dir data/sft/megatron
# 5. The checks: the answer checker on every problem, then RL prompt = SFT prompt
(cd code && python3 scripts/audit_checker.py --curriculum ../data/curriculum --out ../logs/checker_audit)
python -I code/scripts/check_prompt_tokens.py "$MEGATRON_PATH" data/tokenizer/llama-3.2 data/curriculum/*.jsonl
What to expect (our numbers):
data/curriculum/report.json: easy 1,195, medium 1,905, hard 10,400, warm-up 2,000.data/pretrain/manifest.json: 2,600,591,645 training and 26,012,769 validation tokens; 1,141 documents dropped.data/sft/manifest.json: 55,083 questions (53,970 train, 1,113 valid); packing: 2,210 training lines at 97.8% fill.
Every number in this post is collected, with its source, in all results.
Config files: code/rl/curriculum_env.yaml (the RL environment) and code/rl/latex_flagged.json (the 28 flagged problems).
Code: code/scripts/prepare_pretrain_data.py, code/scripts/prepare_sft_data.py, code/scripts/download_openmathinstruct2.sh, code/scripts/make_megatron_sft.py, code/scripts/build_curriculum.py, code/rl/curriculum_data.py, code/rl/curriculum.py, code/scripts/audit_checker.py and code/scripts/check_prompt_tokens.py. Tests: code/tests/test_prepare_pretrain_data.py, code/tests/test_prepare_sft_data.py, code/tests/test_make_megatron_sft.py and code/tests/test_curriculum_data.py. The step-by-step version is the data guide.
What to take away
- Read real samples of every filter’s drops: two of my filters passed their unit tests and were still mostly wrong.
- “Decontaminated” depends on the definition. NVIDIA’s judge counts a changed-number copy of a test question as new; a numbers-masked n-gram rule catches it.
- Majority-vote labels can be confident and still wrong. When the teacher itself has to round, the question has no exact answer; about 11% of these did.
- Write the stopping rule before the last check. Build 5 was frozen by a rule fixed in advance, with a measured bound: 0 of 50 wrong, at most 7.1% at 95%.
- Check the plumbing token by token, and hold out a test set at every difficulty tier.
References
- N. Tazi, L. von Werra, T. Wolf, “The Ultimate MoE Training Handbook”, Hugging Face, 2026. https://huggingface.co/spaces/huggingface/moe-blogpost
- The Llama 3.2 tokenizer, ungated copy:
unsloth/Llama-3.2-1B. https://huggingface.co/unsloth/Llama-3.2-1B - FineWeb-Edu, Hugging Face. https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu
- Hugging Face, “The Smol Training Playbook”. https://huggingface.co/spaces/HuggingFaceTB/smol-training-playbook
- S. Toshniwal et al., “OpenMathInstruct-2: Accelerating AI for Math with Massive Open-Source Instruction Data”, arXiv:2410.01560, 2024. https://arxiv.org/abs/2410.01560
- OpenMathInstruct-2 dataset card, NVIDIA (CC BY 4.0). https://huggingface.co/datasets/nvidia/OpenMathInstruct-2
sentence-transformers/multi-qa-MiniLM-L6-cos-v1. https://huggingface.co/sentence-transformers/multi-qa-MiniLM-L6-cos-v1- NVIDIA NeMo-Skills, the authors’ data-preparation code (read at commit
bcf059af55c2). https://github.com/NVIDIA-NeMo/Skills
Cite this
@misc{aboagye2026minidsv4part03,
author = {Aboagye, Prince Osei},
title = {Mini DeepSeek V4, Part 3: Data and the tokenizer, and the traps inside public math data},
year = {2026},
howpublished = {\url{https://poaboagye.github.io/blog/03-data-and-tokenizer/}}
}