DataFlex icon indicating copy to clipboard operation
DataFlex copied to clipboard

How should I balance learning rate and data sampling during CPT on multiple datasets?

Open jefcoder opened this issue 4 months ago • 1 comments

Hi everyone,

I'm doing continued pretraining on a mixture of eight open-source datasets.

The training is now in the late stage where the validation loss decreases very slowly. My objective is to minimize a weighted validation loss across all datasets.

I'm facing two related challenges.

1. Choosing the learning rate

Different datasets seem to prefer very different learning-rate regimes.

  • For very large datasets (e.g., FineWeb-Edu-scale datasets with more than 1T tokens), the validation loss continues to improve with a relatively large learning rate.
  • For smaller datasets (around 50B tokens), the validation loss only improves when the learning rate is extremely small.

Since my goal is to reduce the overall weighted loss as quickly as possible, I'm unsure how to choose a single learning rate that works well across all datasets.

Is this simply an unavoidable trade-off, or are there training strategies that work better in this setting? For example, do people modify the optimizer or training procedure to handle datasets that require different effective learning rates?

2. Dataset sampling

Another issue is the sampling ratio.

Some datasets contribute only 2–5% of the total weighted objective. When I sampled those datasets at only 2–5% of the training tokens, their validation loss gradually increases. My guess is that they receive too little exposure and are continually overwritten by updates from the larger datasets.

However, if I oversample those smaller datasets, I must reduce the sampling rate of the larger datasets, which could slow down optimization of the overall weighted objective.

How can I handle this trade-off?

I'd really appreciate hearing from anyone who has experience with large-scale continued pretraining or multi-domain LLM pretraining. I'm also open to paid consulting or collaboration.

jefcoder avatar Jul 06 '26 19:07 jefcoder

Hi @jefcoder,

Thanks for opening this issue and for sharing the training curves in detail. The setup you described is a very realistic continued-pretraining scenario, and the logs are helpful for diagnosing what is happening across domains.

From the screenshots, the global metrics are still improving: weighted_mean_loss, mean_loss, eval/weighted_mean_loss, eval/mean_loss, and eval/best_loss all keep drifting down. Around step 2850, the logged values are approximately weighted_mean_loss ≈ 1.43989 and mean_loss ≈ 1.10495.

However, the per-domain curves are clearly not moving in the same direction:

  • db-add-1/loss decreases quite cleanly, roughly from 2.0397 to 2.0355.
  • automathtext-v2/loss also decreases, roughly from 2.0196 to 2.0191.
  • ultradata-math-l3 slowly improves.
  • finewebedu/loss is mostly flat/noisy around 1.916.
  • openthoughts/loss increases from about 1.0102 to 1.0108.
  • nemotron-specialized-v1.2/loss also drifts upward, roughly from 0.7159 to 0.7162.
  • nemotron-specialized-v1.1/loss is mostly flat to slightly worse.

So this does not look like a pure learning-rate issue. The current run is still reducing the aggregate objective, but some specialized domains are being forgotten or overwritten. This is better viewed as a multi-domain data-mixture problem with learning-rate interaction.


1. Learning rate

With one shared model, a true per-dataset learning rate is usually not the cleanest solution, because all datasets update the same parameters. What matters per domain is closer to its effective update mass:

$$ u_i \approx \eta \cdot p_i \cdot c_i $$

where eta is the global learning rate, p_i is the sampling probability of domain i, and c_i is an optional domain loss weight.

When a smaller or more specialized dataset appears to require a much smaller learning rate, it often means that the global update direction is dominated by other domains. Lowering the global LR may reduce damage to those domains, but it will also slow down the domains that are still improving, such as db-add-1, automathtext-v2, and possibly the overall weighted objective.

If the final objective is strictly:

$$ J = \sum_i w_i L_i^{val} $$

then a low-weight domain is technically allowed to regress if the weighted improvement from other domains is larger. But if the requirement is “reduce weighted loss while not letting specialized domains degrade,” then the real objective includes an anti-forgetting or retention constraint. That distinction matters before deciding whether the current behavior is actually bad.


2. Sampling ratio

The sampling ratio does not have to equal the validation weight.

A domain with only 2-5% weight in the final objective may still need more than 2-5% of training tokens to avoid forgetting. Objective weight controls how much that domain matters during evaluation; sampling probability controls how much gradient budget it receives during training. These are related, but not identical.

A useful diagnostic is the weighted validation improvement per consumed token:

$$ s_i \approx w_i \cdot \frac{L_i(t-\Delta)-L_i(t)}{N_i(t)-N_i(t-\Delta)} $$

where N_i is the number of training tokens consumed from domain i.

If s_i is positive and large, that domain is giving good weighted loss reduction per token. If s_i is negative, the domain is getting worse and may need more exposure, lower destructive interference, a lower LR, or explicit retention weighting.

A static smoothed mixture can be useful as a quick sanity check, but it should not be the main strategy here. Two simple initializations are:

$$ p_i = \frac{w_i^\tau}{\sum_j w_j^\tau}, \quad 0.5 \le \tau \le 0.8 $$

or:

$$ p_i = \frac{\max(w_i, f)}{\sum_j \max(w_j, f)} $$

For 8 domains, a small floor is a reasonable initial probe when several specialized domains are drifting upward. This is mainly useful for initializing or debugging the dynamic mixer, not as the final recommended solution.


3. Recommended direction: dynamic mixture

Given the curves, the more appropriate strategy is to let the sampling distribution adapt during CPT.

A static mixture has one major weakness in this setting: the correct domain ratio is unlikely to stay constant throughout late-stage training. Early in the run, spending more tokens on large high-signal domains may be optimal. Later, once some domains begin to saturate and others begin to regress, the optimal mixture can shift. This is exactly the case shown by the current curves: some domains keep improving, while openthoughts and nemotron-specialized start to move upward.

So the practical recommendation is:

  1. Use a smoothed or floor-constrained distribution only as the initial mixture.
  2. Use a dynamic mixer to update domain proportions during training.
  3. Keep a nonzero floor / exploration mechanism so small domains do not disappear.
  4. Compare runs by the slope of the weighted validation objective over the same token budget.

The key question is not simply whether openthoughts or nemotron can be made better individually. The key question is:

Does dynamically increasing exposure to regressing domains improve the weighted validation-loss slope, or does it only improve those domains while slowing the total objective?


4. DataFlex mixture tools: ODM and DoReMi

This issue maps naturally to the two data-mixture methods currently supported in DataFlex: ODM and DoReMi. They address related but different parts of the mixture problem.

ODM is the more direct fit when the problem appears during the current training run. It updates the sampling distribution online, so it can react when a domain receives too little effective update mass or begins to regress. In this issue, the rising openthoughts and nemotron-specialized losses are exactly the kind of signal where an online mixer is more appropriate than a fixed sampling ratio.

A minimal ODM configuration direction would be:

train_type: dynamic_mix
component_name: odm
mixture_sample_rule: mixture
init_mixture_proportions: [ ... smoothed or floor-constrained initial proportions ... ]

warmup_step: 1000
update_step: 500
update_times: -1

The important ODM parameter here is min_exploration_rate. It prevents low-weight domains from vanishing in late-stage training. For 8 domains, the exploration floor should satisfy:

$$ K\epsilon < 1 $$

where K = 8 and epsilon = min_exploration_rate. Values around 0.01-0.03 can be used as initial probes, depending on how much minority-domain retention matters. These should be treated as tunable search values rather than fixed defaults.

A relevant implementation detail is that ODM needs a reliable domain-level reward/loss signal. In the current DataFlex implementation, the ODM path in MixTrainer stores a batch-level loss and a single domain_id from the batch. If batches contain mixed domains, the reward signal can become noisy. For ODM, domain-homogeneous batches are safer, or the reward update should be modified to compute per-domain losses inside the batch.

DoReMi is useful when a proxy/reference workflow is affordable. It is better suited for learning robust domain weights before a final expensive CPT run. Instead of directly reacting to every short-term validation fluctuation, DoReMi estimates excess-loss-based domain weights using a reference/proxy setup, then uses the learned weights for the final training mixture.

So the distinction is:

  • ODM: online adaptation during the same CPT run; more direct for under-exposure / forgetting during training.
  • DoReMi: proxy/reference-based mixture search; more useful when there is budget to learn a robust mixture before the final run.

For the current issue, ODM would usually be the first dynamic method to test, because the visible symptom is ongoing domain regression under a static or near-static mixture. DoReMi becomes more attractive if the goal is to run a more systematic mixture search before the final CPT run.

Relevant implementation links:


5. Suggested experiment plan

A compact experiment plan would be:

  1. Keep the global LR tied to the weighted validation objective rather than tuning it for one domain.
  2. Initialize the mixture with temperature smoothing or a small floor.
  3. Run ODM so the proportions can adapt online during CPT.
  4. Track both:
    • the total weighted validation loss;
    • per-domain validation loss slopes.
  5. Compare against the current static mixture over the same token budget.
  6. Consider DoReMi if a proxy/reference run is affordable and a more systematic final mixture search is desired.

For an exact weighted-validation-loss objective, a validation-slope-based mixer would also be a natural extension. A simple reward could be:

$$ r_i = w_i \cdot (L_i(t-\Delta)-L_i(t)) - \lambda \cdot g_i $$

where:

$$ g_i = \max(0, L_i(t)-L_i(t-\Delta)) $$

This reward directly combines weighted improvement and a forgetting penalty. It could be used to update domain sampling probabilities with a floor constraint.

Raw data is not necessary for a first diagnosis. The most useful next step would be to compare the current static mixture against an ODM run using the same token budget and the same evaluation protocol.

Hope this helps clarify the issue. If there are more questions or follow-up experiment results, feel free to share them here.

Walnutes avatar Jul 08 '26 08:07 Walnutes