Dynamic Gradient Alignment for Online Data Mixing

Simin Fan, David Grangier, Pierre Ablin · DOI

Abstract

Training Large Language Models (LLMs) requires balancing diverse data sources to achieve specialized expertise without compromising general intelligence. Traditional static data mixing methods, such as importance sampling, often suffer from overfitting in data-constrained domains and fail to adapt to the model's evolving needs during training. We present Dynamic Gradient Alignment (DGA), an online algorithm that dynamically adjusts data mixture weights based on real-time gradient alignment with a target task. By incorporating Exponential Moving Average (EMA) regularization and a scalable distribution reweighting mechanism, DGA maintains stability even in low-data regimes and scales to hundreds of thousands of domains. Our results demonstrate that DGA outperforms uniform and static baselines, particularly in preventing loss spikes and improving validation performance across specialized benchmarks.

Introduction

The performance of an LLM is heavily dependent on its "data recipe"—the specific proportions of various datasets used during pre-training. While generic web data provides broad knowledge, specialized domains like medicine or law require careful integration. Current practices often rely on static importance sampling, which weights domains based on initial similarity to a target task. However, these methods are prone to the "overfitting trap," where small but relevant domains are sampled too frequently, leading to performance degradation. Furthermore, static mixtures cannot account for the model's changing learning state over time.

Dynamic Gradient Alignment (DGA)

To address these limitations, researchers from Apple and EPFL introduced Dynamic Gradient Alignment (DGA). The core principle of DGA is to prioritize data domains whose gradients align most closely with the gradient of the target task. If training on a specific domain produces weight updates in a direction beneficial to the target task, that domain's weight is increased.

Key Components

  • Online Mixture Updates: Unlike previous methods that require separate proxy models, DGA updates weights during the primary training run, allowing for real-time adaptation.
  • EMA Regularization: To prevent erratic shifts in the data distribution, an Exponential Moving Average (EMA) is applied to the weights. This ensures a smooth transition and preserves general knowledge.
  • Scalable Distribution Reweighting: For datasets with massive numbers of sub-domains (e.g., hundreds of thousands), DGA optimizes weights over a set of "basis" distributions rather than individual domains, ensuring computational efficiency.

Experimental Results

We evaluated DGA using the RedPajama-v2 corpus as the generic source and specialized subsets from The Pile (Math, Code, Medical, Legal, and Science) as targets.

Stability and Data Scarcity

A significant advantage of DGA is its robustness in data-constrained environments. In scenarios with limited tokens per domain, static importance sampling often leads to rapid overfitting and loss spikes. DGA, particularly with EMA, detects when a domain's gradient signal weakens due to overfitting and automatically reallocates weight to other beneficial sources.

Validation loss comparison across different token limits per domain. DGA w. ema shows superior stability in low-data regimes compared to importance sampling.

Performance and Scalability

DGA successfully managed mixtures involving up to 262,000 domains. On the MMLU benchmark, a 750M parameter model trained with DGA achieved 28.0% accuracy, significantly higher than the 26.1% achieved by uniform sampling. The method effectively finds a Pareto-optimal balance between specialized task performance and general language modeling capabilities.

Conclusion

Dynamic Gradient Alignment offers a robust, scalable solution for the online data mixing problem. By using gradients as a "compass," DGA adapts to the model's immediate learning needs and avoids the pitfalls of static weighting. Future work will explore the automatic discovery of basis distributions and further investigate the relationship between language modeling improvements and downstream reasoning performance.

Summary updated

BibTeX
@misc{fan2024dynamic,
  author = {Simin Fan and David Grangier and Pierre Ablin},
  title = {{Dynamic Gradient Alignment for Online Data Mixing}},
  year = {2024},
  eprint = {2410.02498},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.02498},
}
Figure