Data Mixing Laws: Optimizing Data Mixtures by Predicting Language Modeling Performance
Jiasheng Ye, Peiju Liu, Tianxiang Sun, Jun Zhan, Yunhua Zhou, Xipeng Qiu
cs.CL, cs.AI, cs.LG
2024-03-26
Fudan researchers fit validation loss as a function of pretraining mixture proportions; nested with scaling laws, small-scale runs find a mixture worth 48% more tokens at 1B.
Pretraining corpora are mixtures: web text, code, papers, dialogue. The proportions decide what the final model is good at, and in practice they are set by heuristics. Teams upsample data they judge high-quality or underrepresented, and the exact criteria rarely leave the lab; The Pile, Llama, and Qwen all worked this way. Algorithms like DoReMi and DoGE automate the choice, but they optimize qualitatively, so you learn whether a mixture helped only after the run finishes. A pretraining run is expensive enough that a bad mixture is a sunk cost.
Scaling laws already show that loss follows predictable power laws in model size, data volume, and compute. This paper extends the question to proportions: is loss also a fittable function of mixture composition? The answer is yes, which makes it possible to score any mixture before training on it and simply pick the best one.
Four steps.
Finding the functional form. The pilot trains 70M and 160M models on two Pile subsets, Github and Pile-CC, under five proportions, 30B tokens each. For checkpoints of the same size and step count, subtracting a shared irreducible loss (the floor set by the entropy of the evaluation data) makes the log of the remaining loss linear in the proportion, giving Li(ri) = ci + ki·exp(t·ri).
Extending to many domains. Over a grid of 32 mixtures of Github, Books3, and Pile-CC, candidate forms follow two principles: compatibility (the form must reduce to the two-domain case) and symmetry (permuting domains must not change the shape). Among four candidates the paper adopts M4, Li(r) = ci + ki·exp(Σj tij·rj), which matches the best candidate's accuracy with fewer coefficients. The coefficients carry meaning: a negative tij says training domain j reduces validation loss on domain i. Fitted on five coarse domains of the Pile, the coefficient matrix is sparse, with most domains unrelated; interactions such as dialogue helping internet text and symbolic data hurting prose do exist.
Handling arbitrary validation sets. Validation data is often collected separately, so its composition is unknown. Implicit domain aggregation assumes the validation set decomposes into K implicit domains, treats their proportions as learnable parameters, and fits the total loss end to end. K just needs to exceed the true domain count; the default is K=30, and it beats explicit aggregation by known composition. Parameters grow quadratically with domain count, but sparsity plus regularization keeps the required sample count from growing the same way.
Nested scaling laws to keep it affordable. Fitting the mixing law at the target scale would mean dozens of 1B runs at 100B tokens. Instead the pipeline trains four small sizes (70M to 410M) for 30B tokens each on about 20 mixtures. For each mixture, a step law L(S)=E+A·S^α extrapolates to the target step count, then a size law extrapolates to the target model size; those predicted losses fit the mixing law, which is then optimized. The Chinchilla two-variable law is deliberately split into two one-variable power laws because fitting everything at once is unstable in practice. Mixtures are enumerated by repeatedly halving each domain's proportion; 40 are trained at 70M and the 20 with the lowest prediction error are kept.
On the three-domain experiment, mean absolute error on 8 held-out mixtures:
| Method | GitHub | Books3 | Pile-CC |
| Random guess | 0.876 | 0.133 | 0.105 |
| M4 (adopted) | 0.037 | 0.007 | 0.008 |
The main experiment trains a 1B model on RedPajama for 100B tokens and validates on the Pile, mimicking validation data collected separately from training data:
| Comparison | Result |
| Default mixture, same loss | Optimized mixture needs only 73% of the steps |
| Default mixture, same budget | Optimized mixture equals default trained with 48% more tokens |
| DoGE (Universal/OOD), DoReMi (RedPajama/Pile-adapted) | Optimized mixture reaches the lowest loss at the same budget |
For continual pretraining, a Pythia-70M model is further trained for 10B tokens on mixtures of the Pile and Python code. Fitting the two-domain formula on just 4 mixtures predicts the critical proportion at which loss on the original domain stays flat while loss on Python drops, avoiding catastrophic forgetting.
Mixture tuning becomes a regression problem instead of a craft. The pipeline's experimental cost is four small sizes at 30B tokens across about 20 mixtures, and it buys loss predictions for any mixture at the 1B, 100B-token target. Teams about to launch a pretraining run can spend a small amount of compute up front for confidence in the mixture; teams doing domain enhancement get a quantitative answer to how much domain data they can add before general capability degrades. The coefficient matrix doubles as a quantitative map of cross-domain interactions, raw material for designing multi-stage data schedules. Code and fitting data are public. The framing is a natural extension of scaling laws; the new part is being first to bring mixture proportions into quantitative prediction, and the evidence within the loss domain is solid.
The optimization target is loss on one fixed validation set. Change the validation distribution and the optimal mixture moves. How much of the gain over the default mixture comes from simply better matching the composition of the Pile validation set (code share, for instance) is not broken down, and there are no downstream benchmarks; the gap between loss and capability is left open.
The authors concede several points. The number of fitting samples required is hard to pin down and varies across datasets. The optimal mixture at small scale does not transfer to large scale, since cited studies show mixture rankings shift with model size and token count, which is exactly why the pipeline refits at the target scale; still, error accumulation across three stacked fits gets only a qualitative discussion. The continual pretraining experiment is one 70M model, two domains, and 10B tokens, far from practical scales.