← All posts

Model development

Post 3 of 26

Data mixtures and repetition: deciding how often the model sees each source

Posts in this series · 26

The previous post built one corpus from the web. Real pre-training draws from several: filtered web text, code, books, papers, mathematics, and text in many languages. They differ enormously in size. There is far more web text than mathematics, and far more English than Khmer. So a second decision sits on top of corpus construction: how often should the model see each source?

That decision is made with sampling weights, and it is easy to underestimate. The weights decide which kinds of text dominate the loss, and, because small sources run out, how many times some text is repeated. This post turns weights into exposure, shows the standard ways of setting them, and separates what is known about repetition from what has to be measured.

From weights to exposure

Suppose you will train on a budget of BB tokens, and source ss contains nsn_s tokens and is sampled with weight wsw_s, where the weights sum to 1. Then

tokens seen from s=wsB,passes over s=wsBns.\text{tokens seen from } s = w_s B, \qquad \text{passes over } s = \frac{w_s B}{n_s}.

Take three illustrative sources and a budget of 100 billion tokens:

SourceSizeWeightTokens seenPasses
Web400B70%70B0.175
Code50B20%20B0.4
Books5B10%10B2

The web is barely sampled, under a fifth of it is ever seen, while the books are read twice. Nothing in the weights says “repeat the books”: it follows from asking a small source for a tenth of a large budget. Exposure is the product of three numbers, and changing any one of them, the weight, the budget or the source size, changes it.

The same arithmetic explains why sizes must be counted in the tokens of the tokenizer you will train with: the same text can be 1 billion tokens under one tokenizer and 3 billion under another, especially across languages. That is the subject of the next post.

Three ways to set weights

Proportional sampling sets each weight to the source’s share of all tokens, ws=ns/∑knkw_s = n_s / \sum_k n_k. Every source is then seen the same number of times, here 100/455≈0.22100 / 455 \approx 0.22 passes each. It is the natural default, and it gives small sources almost no weight: the books get about 1% of training.

Uniform sampling gives every source the same weight. It treats sources as equally important, and it repeats small ones heavily.

Temperature sampling interpolates. Raise each proportional share psp_s to the power 1/τ1/\tau and renormalize:

ws=ps1/τ∑kpk1/τ.w_s = \frac{p_s^{1/\tau}}{\sum_k p_k^{1/\tau}} .

Temperature sampling is mostly used for languages, and the numbers show why it is delicate. Take a high-resource language with 400 billion tokens, a low-resource one with 4 billion, and a budget of 220 billion:

RuleLow-resource weightLow-resource tokens seenPasses over it
Proportional, τ=1\tau = 14/404≈1%4/404 \approx 1\%2.2B0.54
τ=2\tau = 2: weights ∝400:4=20:2\propto \sqrt{400} : \sqrt{4} = 20 : 22/22≈9%2/22 \approx 9\%20B5
Uniform, τ→∞\tau \to \infty50%110B27.5

With τ=2\tau = 2 the small language gets nine times more exposure than proportional sampling gives it, at the price of being read five times. Uniform sampling would read it 27 times.

Capping repetition. UniMax makes the cap explicit: give every source the same share of the budget, except that no source may be repeated more than NN times; whatever a capped source cannot use is shared among the rest (UniMax, §3, Algorithm 1). With N=4N = 4 in the example, the low-resource language gets 4×4=164 \times 4 = 16 billion tokens, exactly 4 passes, and the remaining 204 billion go to the high-resource language. In UniMax’s experiments this beat temperature sampling across the model sizes it tested (UniMax, abstract).

Everyday picture: a library reading list for a year. Proportional sampling has you read whatever the library holds most of; uniform sampling gives the one slim volume of poetry as much time as the entire history section, so you reread it dozens of times. A cap says: read the poetry at most four times and spend the rest of the year elsewhere.

What repeating data costs

A pass is not free and not worthless. Repeating a source gives the model more gradient steps on text it has already fitted, so each repetition teaches less than fresh text, and heavily repeated text is more likely to be memorized.

How much less? The clearest evidence is Muennighoff et al. (2023). With data held fixed and compute increased, they found that up to about 4 passes changed the final loss negligibly compared with the same amount of fresh data, and that further repetition gave rapidly diminishing returns, approaching zero value around 40 passes in their experiments (abstract and Fig. 1). That result is for their models (up to 9 billion parameters), their data and their measure (validation loss). It is a strong prior for planning, not a law: a high-quality source may be worth repeating more than a mediocre one, and downstream behaviour can respond differently from loss.

Two practical consequences follow:

Try it: predict the change. In the three-source example you raise books from 10% to 30% of the 100-billion-token budget, taking the difference from the web. How many passes over the books now, and how much web text is seen?

Answer. Books: 0.3×100/5=60.3 \times 100 / 5 = 6 passes, up from 2. Web: 0.5×100=500.5 \times 100 = 50 billion tokens, an eighth of the web. The change triples the repetition of the small source and cuts web exposure by 20 billion tokens. Whether that helps depends on whether a fourth, fifth and sixth reading of the books is worth more than 20 billion new web tokens, which is exactly what a small ablation at this budget can tell you.

Changing the mixture over time

Weights do not have to be fixed for the whole run. A common pattern is to finish training with a short phase that upsamples high-quality data while the learning rate decays to zero, often called annealing.

Llama 3 is a well-documented example. Its main mix was roughly 50% general knowledge, 25% mathematics and reasoning, 17% code and 8% multilingual text, chosen with a classifier that downsampled over-represented web categories and with small-model experiments used to predict large-model performance (Llama 3, §3.1.2). At the end of pre-training it upsampled very high-quality sources (§3.4.3). Annealing on high-quality code and mathematics improved the 8-billion-parameter model on GSM8K and MATH validation sets by 24.0% and 6.4%, but gave negligible gains for the 405-billion-parameter model (§3.1.3). The effect of a mixture change can depend on model scale.

Llama 3 also used annealing as a cheap test of data value: take a half-trained model, anneal it over 40 billion tokens with 30% of the weight on a candidate dataset, and see whether evaluations improve (§3.1.3). That is far cheaper than a full training run per candidate source.

Choosing weights in practice

Most weights are set by a combination of judgement and small experiments: train small models on a few mixtures, compare them on the evaluations you care about, and pick the best. Two assumptions hide in that procedure, as CS336’s data lecture points out: that the small-scale comparison picks the right mixture, and that the best mixture at small scale is still best at large scale. Scale-dependent effects like Llama 3’s annealing result are a reason to check the second at least once near the real scale. Methods that optimize mixtures with proxy models or regression exist (see further reading); they automate the search but rest on the same assumptions.

What to remember

Try it yourself

Sources

Further reading