Dive into Deep Learning · §20.4
Data Mixtures
domain weights · temperature and repetition · proxy regression · DoReMi · annealing · transfer
The problem
Olmo 3’s pretraining mixture, from its dataset card:
| source | share |
|---|---|
| web (Common Crawl) | 76% |
| scientific PDFs | 14% |
| code | 7% |
| mathematics web pages | 2.6% |
Nobody derives these numbers, and nobody can afford to try every candidate at full scale.
Domain weights are hyperparameters. Fit them on small proxy runs.
Goals
Running example: 65 runs of a 4.6M-parameter GPT, 2^{24} tokens each, on web text (FineWeb-Edu), Python (CodeParrot, permissive licences) and mathematics (FineMath).
Where this fits
| step | section |
|---|---|
| get text | Document Extraction from Web Crawls |
| choose text | Quality Filtering |
| Deduplication and Decontamination | |
| mix text | Data Mixtures |
| Synthetic and Rephrased Data | |
| cut text | Tokenizers at Scale |
Comparable losses
The uniform mixture, one proxy:
| web | code | math | |
|---|---|---|---|
| bytes per token | 4.56 | 2.42 | 3.00 |
| bits per token | 8.73 | 5.13 | 6.63 |
| bits per byte | 1.92 | 2.12 | 2.21 |
\textrm{bpb} = \frac{\sum \textrm{NLL (nats)}}{\ln 2 \cdot \#\textrm{UTF-8 bytes}}
Bits per byte do not depend on the tokenizer. Hold fixed: tokenizer, model, tokens, schedule, evaluation sets, data order.
Many sources
p_i \propto n_i^{\alpha}; epochs e_i = p_i D / n_i \propto n_i^{\alpha - 1}.
Ten languages, 10^{10} documents drawn:
| language | documents | share, \alpha = 1 | share, \alpha = 0.3 | epochs, \alpha = 0.3 |
|---|---|---|---|---|
| English | 25.9B | 0.915 | 0.345 | 0.13 |
| Hindi | 22M | 0.0008 | 0.042 | 18.7 |
| Swahili | 1.2M | 0.00004 | 0.017 | 143 |
\alpha = 0.7 (multilingual BERT), 0.3 (XLM-R, mT5). Sampling does not create data; it chooses what is repeated.
Repetition
U unique tokens, E epochs, R = E - 1 repeats:
D' = U + U R^* \bigl(1 - e^{-R/R^*}\bigr), \qquad R^* \approx 15.4
| epochs | D' / (UE) |
|---|---|
| 4 | 0.93 |
| 4.8 | 0.91 |
| \infty | D' \to 16.4\, U |
Small R: D' \approx UE. Large R: further epochs add nothing (Muennighoff et al.’s fit).
Check
Use D' = U + U R^* (1 - e^{-R/R^*}) with R^* = 15.4 and R = 142.
Answer. e^{-142/15.4} \approx 10^{-4}, so D' \approx 16.4\,U: about 11% of 143 fresh copies. Most of Swahili’s share at \alpha = 0.3 is wasted; UniMax caps the epochs per language instead.
The method
| runs | mixtures | purpose |
|---|---|---|
| 15 training | 6 Dirichlet(1), 6 Dirichlet(0.3), 3 corners | fit |
| 4 held out | Dirichlet(1), another seed | judge the fit |
| 9 pure, 7 uniform | one domain; seeds | matrix; noise |
| 3 × 3 seeds | uniform, selected, DoReMi | arms |
| 2 × 3 seeds | anneal on math, then back to uniform | annealing |
| 9 + 4 | half the rate; 4× the steps | checks |
Why mixing is a choice
Bits per byte of the pure-domain proxies:
| trained on | web | code | math |
|---|---|---|---|
| web | 2.05 | 5.23 | 3.31 |
| code | 2.57 | 2.02 | 3.06 |
| math | 2.15 | 3.46 | 2.24 |
Off-diagonal costs are large and asymmetric. FineMath is English prose about mathematics: on web text its proxy is much nearer the web proxy than the code proxy is.
Do curves cross?
For every pair of the 15 training mixtures, compare the t_{\textrm{dep}} loss at 25% of the run and at its end.
| pairs | |
|---|---|
| all pairs | 105 |
| order swaps | 10 |
| swaps beyond 2\sqrt2 seed SDs at both points | 0 |
At this scale a short run ranks mixtures as a full one does. Whether a small model ranks them as a large one does is another question.
The noise floor
No predictor beats \sigma, the noise of the held-out run itself. Least squares, n runs, p parameters, correct model:
\mathbb{E}\bigl[(\hat y - y)^2\bigr] = \sigma^2 \bigl(1 + \mathbf{x}^\top (\mathbf{X}^\top \mathbf{X})^{-1} \mathbf{x}\bigr)
Average over the design: \operatorname{tr} of the hat matrix is p, so \sigma^2 (1 + p/n).
Three regressions
Mixing law: b_i(\mathbf w) = c_i + k_i \exp\bigl(\sum_j t_{ij} w_j\bigr).
| held-out RMSE (bpb) | web | code | math |
|---|---|---|---|
| ridge | 0.03 | 0.06 | 0.07 |
| gradient boosting | 0.01 | 0.03 | 0.05 |
| mixing law | 0.003 | 0.12 | 0.04 |
| floor | 0.01 | 0.01 | 0.01 |
The law fails on code, whose loss drops steeply near zero code weight. More runs lower the floor, not the bias.
Choosing
Minimize the fitted t_{\textrm{dep}} loss inside the hull of the training mixtures:
| regression | (web, code, math) |
|---|---|
| mixing law (fixed in advance) | (0.34, 0.31, 0.35) |
| ridge | (0.10, 0.80, 0.10), a corner |
| gradient boosting | (0.24, 0.55, 0.22) |
200 bootstrap refits: web 0.25 to 0.38, code 0.24 to 0.43.
In the fitted law, web loss barely moves with web weight; code and math fall with theirs. The runs fix a neighbourhood, not a point.
Check
Ridge predicts each b_i as linear in \mathbf w. The choice minimizes \sum_i t_i b_i(\mathbf w) over the hull of the training mixtures.
Answer. A sum of linear functions is linear, and a linear function on a polytope is minimized at a vertex. Ridge can never select an interior mixture; the mixing law’s exponentials can.
A different objective
\min_\theta \max_{\boldsymbol\alpha \in \Delta} \sum_i \alpha_i (\ell_i(\theta) - \ell_{\textrm{ref},i}); excess g_i clipped at 0 per token.
\alpha_{t+1,i} = \frac{\alpha_{t,i}\, e^{\eta g_{t,i}}}{\sum_j \alpha_{t,j}\, e^{\eta g_{t,j}}}
| web | code | math | |
|---|---|---|---|
| weight at step 65 | 0.03 | 0.75 | 0.22 |
| weight at step 129 | 0.15 | 0.25 | 0.60 |
| average over 256 steps | 0.17 | 0.47 | 0.36 |
Arms
Three seeds each, paired with uniform; real only if all three differences share a sign and the mean exceeds 2\sigma_{\textrm{seed}} (about 0.01).
| arm minus uniform | t_{\textrm{dep}} | t_{\textrm{avg}} | code |
|---|---|---|---|
| regression’s choice | about −0.007 | about −0.008 | 0.00 |
| DoReMi | about +0.015 | about −0.025 | −0.10 |
DoReMi lowers code loss and raises web loss: worse on the web-heavy target, at the edge of the noise; better on the average.
Annealing
Benchmark gains may be recency. Check held-out loss of the domain, then train on and see whether the gain survives.
A released mixture
| source | pool (tokens) | mix (tokens) | epochs |
|---|---|---|---|
| Common Crawl | 8.14T | 4.51T | 0.55 |
| code (Stack-Edu) | 137B | 409B | 3.0 |
| arXiv | 21.4B | 50.9B | 2.4 |
| FineMath 3+ | 34.1B | 151B | 4.4 |
Check
4.2M of the 4.6M parameters are embeddings; it sees about 4 tokens per parameter, against about 20 for compute-optimal training. What can its ranking of mixtures tell you about a 1B model?
Answer. A hypothesis, not a measurement. It has learned which tokens follow which, not long-range structure; a larger model may value code and math differently. RegMix checked its choice against 64 mixtures trained at the large size.
Transfer
A test at half the T2 tokens: 20.3M parameters, 2^{26} tokens, 46 minutes on four RTX 4090s. The full T2 campaign (2^{27} tokens) has not been run.
| 4.6M proxy | 20.3M proxy | |
|---|---|---|
| peak learning rate | 2 \times 10^{-3} | 10^{-3} |
| selected for t_{\textrm{dep}} | (0.34, 0.31, 0.35) | (0.44, 0.27, 0.30) |
| selected minus uniform | within noise | about −0.01, all 3 seeds |
| DoReMi weights | (0.17, 0.47, 0.36) | (0.29, 0.30, 0.41) |
Rank correlation of 22 shared mixtures: 0.70.
Recap
Next: making unique tokens for domains that are too small.