DynaMiCS: Fine-tuning LLMs with Performance Constraints using Dynamic Mixtures

Eleonora Gualdoni, Sonia Laguna, Louis Bethune, Joao Monteiro, Pierre Ablin, Marco CuturiarXiv 2026

TL;DR

Fine-tuning Large Language Models (LLMs) on specialized tasks often degrades their general capabilities, like safety and common sense. This paper introduces DynaMiCS, an automated framework that dynamically adjusts data mixtures during fine-tuning to maximize target domain performance while explicitly enforcing constraints to prevent forgetting. It achieves superior task adaptation and reliable constraint satisfaction at a fraction of the cost of traditional trial-and-error grid searches.

What Problem Does This Paper Address?

When practitioners fine-tune a pre-trained LLM to excel at a specific domain (e.g., coding or mathematical reasoning), they face a frustrating trade-off: the model adapts quickly to the new task but often suffers from "catastrophic forgetting" or overfitting, losing its general knowledge, instruction-following skills, or safety guardrails.

To mitigate this, engineers typically mix specialized data with auxiliary, general-purpose datasets (like Wikipedia). However, finding the right data mixture is an expensive guessing game. Standard heuristics (like uniform or size-proportional mixing) are static and fail to account for how cross-domain impacts change during training. Meanwhile, existing automated data-mixing methods either require training expensive proxy models or cannot explicitly guarantee that critical baseline capabilities will be preserved.

Methods

The authors propose DynaMiCS (Dynamic Mixtures for Constraint Satisfaction), which frames multi-domain fine-tuning as a constrained optimization problem. Instead of guessing fixed weights, DynaMiCS dynamically updates the data mixture throughout training using a three-step loop:

  1. Slope Matrix Estimation: Periodically, the algorithm pauses training to run very short, isolated "probing" steps on each fine-tuning dataset. It measures how training on dataset $A$ affects the loss on evaluation domain $B$. These finite-difference measurements form a local "slope matrix" capturing cross-domain transfer and interference.
  2. Proxy Loss Optimization: Using this slope matrix, DynaMiCS solves a lightweight optimization problem over the probability simplex. The objective is to minimize target domain losses while keeping constrained domain losses below their pre-training reference levels.
  3. Dynamic Fine-Tuning: The model trains on the newly computed optimal mixture weights ($w^*$) for a set number of steps ($H_t$) before repeating the cycle.

Crucially, because it uses finite differences rather than backpropagated gradients to estimate domain impacts, DynaMiCS can optimize for non-differentiable constraints like downstream task accuracy.

Overview of the DynaMiCS framework, showing slope matrix estimation, proxy loss optimization, and the dynamic fine-tuning loop.

Datasets

The authors evaluated DynaMiCS across 50 distinct multi-domain fine-tuning scenarios using models like Qwen2.5-3B, Qwen3-8B, and Gemma3-12B.

  • Target Domains (to improve): Math (MetaMathQA, NuminaMath-CoT, GSM8K), Code (CodeFeedback), Instruction Following (AutoIF, OpenThoughts, OpenOrca), Multilingual (AyaDataset), Medical (MedicalFlashcards), Tool Use (GlaiveFunctionCalling), Science (MegaScience), Summarization (BillSum), and QA (RepliQA).
  • Non-Target Domains (regularizers): Wikipedia and FineWeb.
  • Constrained Domains (to preserve): Evaluation-only benchmarks including tinyMMLU, tinyTruthfulQA, tinyHellaswag, tinyAI2_ARC, NemotronSafety, SafetyQA, and BBQ.

Key Insights and Ideas

  • Cross-domain relationships are highly dynamic: A dataset that provides a helpful regularizing effect early in training might cause interference later on. Fixed-weight mixtures cannot adapt to these shifting landscapes.
  • Early updates are critical: The loss landscape changes most rapidly at the beginning of fine-tuning. Front-loading mixture updates (using a "warmup" schedule) allows the optimizer to gather crucial information early and avoid unstable trajectories that permanently violate constraints.
  • Optimization without gradients: By relying on finite-difference probing rather than gradients, DynaMiCS breaks free from the requirement of differentiable objectives. It can seamlessly handle hard constraints defined directly by downstream task accuracy rather than just perplexity.

Key Results

  • Reliable Constraint Satisfaction: Fixed-weight baselines frequently fail to find any feasible checkpoint that satisfies all safety and general knowledge constraints. DynaMiCS consistently finds valid solutions across diverse architectures.
  • Superior Performance: On Qwen3-8B, DynaMiCS achieved an 11% median perplexity reduction on target domains, whereas fixed-weight baselines achieved 0% because they failed the constraints entirely. On Gemma3-12B, DynaMiCS boosted target performance by an additional 5-6 percentage points over the best baselines.
  • Cost Efficiency: Finding a good fixed mixture via grid search typically requires running 10+ independent training runs (10x cost). DynaMiCS delivers better results in a single run with a compute overhead of only 1.4x to 1.7x of a standard baseline run.
  • Graceful Degradation: As the number of constraints scales up from 3 to 7, fixed baselines collapse to zero feasibility, while DynaMiCS maintains stable target gains.
Performance comparison showing median perplexity reduction vs. compute cost across different model families.

Limitations and Future Work

  • Locality Assumptions: DynaMiCS relies on a local linear approximation. If the update intervals are too long, or if the constraints are exceptionally tight (e.g., 10 simultaneous constraints), the linear model can mispredict long-term dynamics.
  • Additivity Assumption: The slope matrix assumes that cross-domain effects combine additively, ignoring potential complex interactions when multiple datasets are trained simultaneously.
  • Greedy Trajectories: Because updates are chosen greedily based on local estimates, the model can occasionally fall into early over-specialization traps. The authors note that incorporating back-tracking or evolutionary algorithms could help overcome this locality constraint in future iterations.

Summary updated

BibTeX
@misc{gualdoni2026dynamics,
  author = {Eleonora Gualdoni and Sonia Laguna and Louis Bethune and Joao Monteiro and Pierre Ablin and Marco Cuturi},
  title = {{DynaMiCS: Fine-tuning LLMs with Performance Constraints using Dynamic Mixtures}},
  year = {2026},
  eprint = {2605.10770},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.10770},
}
Figure