Prerequisite: next-token prediction · Next: one update, two means
Suppose two independent weather reports arrive: rain stops EOS and wind from the west at noon EOS. As before, each word and each EOS counts as one token; there is no start marker. The reports occupy ten positions however we lay them out. What changes if we put them in the same row?
| Layout | Can wind attend to rain? |
Scored targets |
|---|---|---|
| Separate rows | No | 2 + 6 = 8 |
| One continuous stream | Yes | 9 |
| Packed, independent reports | No | 2 + 6 = 8 |
The ninth prediction is EOS → wind. In a continuous stream that is a real training target. To keep the reports independent, block attention across the boundary and drop that target from the loss. Doing only the first still asks the last position of the first report to predict the opening word of the second. A kernel can take sequence lengths instead of a full attention mask; NeMo's packing guide shows how.
For the position-by-position packing diagram, keep these two checks in mind: what can the position see, and does its prediction count? Or take the eight independent targets straight to one training update. The rest of this note works backward to where a corpus comes from, then follows it through mixing, packing and training.
Preserve provenance before transforming text
In one lineRecord source, hash and version before cleaning, so bad filtering can be traced. Crawling grants no training rights; split validation by source.
Suppose the sources are web pages, code, and technical documentation. Preserve source, collection time, content hash, language, and processing version before removing navigation menus, broken encodings, and repeated templates.
Keeping only the final strings makes a faulty parser difficult to audit. It also hides which languages and domains a filter removed. Being able to download text is not permission to train on it: check licensing, privacy, and deletion requirements first.
| Operation | Intended target | Possible collateral damage |
|---|---|---|
| Format and language checks | Broken extraction and out-of-scope text | Mixed languages and unusual symbols |
| Quality filtering | Boilerplate and meaningless concatenation | Dialects, short documents, specialist writing |
| Exact deduplication | Identical documents | Repetition that carries useful context |
| Near deduplication | Slightly edited mirrors | Similar documents with different conclusions |
RefinedWeb provides a public study of filtering and deduplication, not a universal filter recipe. Inspect samples from both retained and rejected documents.
Split training and validation at an appropriate source, duplicate-cluster, or temporal level. Randomly placing near-identical documents on opposite sides creates leakage. Benchmark paraphrases and leaked answers also evade simple exact matching.
Mixture weights determine what gets repeated
In one lineChanging the mixture changes repetition: in a 20M-token budget, making code 30% reads its 1M unique tokens 6 times, raising memorization risk.
Imagine 8 million unique web tokens, 1 million code tokens, and 1 million documentation tokens after deduplication. Proportional sampling gives 80/10/10. Changing the training mixture to 50/30/20 makes code appear more often.
With a 20-million-token training budget:
| Source | Unique tokens | Sampled tokens | Average reuse |
|---|---|---|---|
| Web | 8 million | 10 million | 1.25 |
| Code | 1 million | 6 million | 6 |
| Documentation | 1 million | 4 million | 4 |
Repeating code is not acquiring five million independent new code tokens. Oversampling can shift capabilities while increasing memorization and overfitting. Compare mixtures at a controlled token or compute budget, and inspect domain-level validation rather than only the mixture average.
These are token proportions. Sampling documents instead changes the realized token mixture when document lengths differ.
Packing is more than reducing padding
In one lineCross-document attention in a packed sequence is a training choice. Attention masks set what is visible; loss masks set what is scored.
Two tokenized documents become:
Document 1: [A, B, EOS]
Document 2: [C, D, EOS]
Packed: [A, B, EOS, C, D, EOS]
May C attend to A and B? That is part of the training definition:
- Continuous stream: an ordinary causal mask allows cross-document attention. EOS indicates a boundary but does not enforce one.
- Independent-document packing: a block-diagonal causal mask restricts C to document 2. Whether position IDs reset is a separate convention that must match the implementation.
To avoid training the cross-document prediction of C after EOS, also mask that loss term. Attention masks determine visibility; loss masks determine scored targets. They are not interchangeable. The first token of a document may be unscored or predicted from its own BOS, depending on the format.
| Input position | Next target | Continuous stream may score | Independent documents, no BOS here |
|---|---|---|---|
| A | B | Yes | Yes |
| B | EOS | Yes | Yes |
| EOS | C | Yes | No |
| C | D | Yes | Yes |
| D | EOS | Yes | Yes |
Padding must not become an ordinary target. Printing tokens, labels, document IDs, and masks for one example is more informative than observing a decreasing loss.
What is averaged in one update?
In one lineIf microbatches hold different numbers of valid targets, averaging their means changes the objective. Divide by the update's total valid tokens.
For valid positions $\mathcal V$, the token-mean loss is
$$ \mathcal L=-\frac{1}{|\mathcal V|} \sum_{t\in\mathcal V}\log p_\theta(x_{t+1}\mid x_{\le t}). $$
When microbatches hold different numbers of valid targets, averaging each one first and then averaging those means optimizes a different objective; gradient accumulation has the same issue. One training update works through it with 2 and 8 tokens: the token mean is 2.6, while averaging the two means gives 2.
A typical update fixes the valid-token denominator for its accumulation window, accumulates correctly weighted gradients, unscales and clips when needed, then steps the optimizer. See distributed training for synchronization and normalization across devices.
Why consider the schedule and budget together?
In one lineWarmup and decay cannot fix bad data or masks. 6ND counts matrix work, not time; Chinchilla is about splitting a given budget, not a fixed ratio.
Warmup gradually increases the learning rate; a specified decay schedule follows. Neither repairs broken masks or poor data. Record whether the schedule advances by optimizer steps or consumed tokens, especially when changing batch sizes or resuming a run.
A rough estimate for dominant dense Transformer training matrix work is $C\approx6ND$, with $N$ parameters and $D$ training tokens. Long-context attention, recomputation, communication, and hardware utilization are outside that simple estimate. FLOPs are not elapsed time; converting them into time needs an estimate of hardware utilization, see MFU and HFU.
Chinchilla studies allocation between model size and data under a training compute budget. It is not a law prescribing one tokens-per-parameter ratio for every project. Data quality, repetition, availability, and eventual inference volume also matter.
For example, 262,144 valid targets per global update over 1,000 updates gives 262,144,000 targets. A measured one-second step time supports an estimate of the training segment's duration. A guessed step time does not establish a GPU budget.
What makes a run reproducible?
In one lineSave optimizer, scheduler, RNG state and data position, not just weights. Before scaling, check a tiny batch fits and a resumed step matches.
Save model, optimizer, scheduler, random states, data recipe, and data position together; mixed precision may also require scaler state. Loading weights and restarting at “step 1,001” need not continue the same trajectory.
Fix tokenizer, split, masks, and scoring unit for validation. Inspect code, language, and length slices separately. Token perplexity is not directly comparable across tokenizers. Also evaluate actual tasks: better text prediction does not automatically imply better instruction following.
Three cheap checks come first: can the model fit a tiny batch; does changing padding leave valid-token loss unchanged; and does one resumed update match uninterrupted training within the chosen tolerance? Scale up after these pass.