Abstract
We present a simple yet theoretically motivated improvement to Supervised Fine-Tuning (SFT) for the Large Language Model (LLM), addressing its limited generalization compared to reinforcement learning (RL). Through mathematical analysis, we reveal that standard SFT gradients implicitly encode a problematic reward structure that may severely restrict the generalization capabilities of model. To rectify this, we propose Dynamic Fine-Tuning (DFT), stabilizing gradient updates for each token by dynamically rescaling the objective function with the probability of this token. Remarkably, this single-line code change significantly outperforms standard SFT across multiple challenging benchmarks and base models, demonstrating greatly improved generalization. Additionally, our approach shows competitive results in offline RL settings, offering an effective yet simpler alternative. This work bridges theoretical insight and practical solutions, substantially advancing SFT performance.
Introduction
Supervised Fine-Tuning (SFT) is the foundational step in aligning Large Language Models (LLMs) with human intent. By training on high-quality expert demonstrations using cross-entropy loss, models learn to mimic desired outputs. However, a persistent performance gap exists between SFT and Reinforcement Learning (RL) methods like PPO or DPO. While SFT excels at memorizing training data, it often struggles to generalize to novel reasoning tasks. This paper investigates the root cause of this disparity and introduces Dynamic Fine-Tuning (DFT), a mathematically grounded modification to the SFT objective that bridges the generalization gap with a single line of code.
The Theoretical Lens: SFT as Ill-Posed RL
To understand why SFT fails to generalize as effectively as RL, we analyze the SFT gradient through the lens of policy gradients. We demonstrate that the standard SFT gradient is mathematically equivalent to an on-policy RL gradient where the implicit reward is inversely proportional to the model's own probability ($1/P$).
This inverse relationship creates a significant stability issue: when a model is uncertain about a correct token (assigning it a low probability), the resulting gradient becomes excessively large. This forces the model to over-optimize for rare or difficult-to-predict tokens—including trivial punctuation or stop words—leading to unstable training dynamics and a tendency to memorize specific sequences rather than learning underlying reasoning patterns.
Dynamic Fine-Tuning (DFT)
To stabilize the learning process, we propose Reward Rectification. By multiplying the standard cross-entropy loss by the token's own probability, we effectively cancel out the $1/P$ term, resulting in a uniform reward structure. The DFT loss function is defined as:
$$\mathcal{L}_{DFT} = -\text{stop\_gradient}(P) \cdot \log(P)$$
By applying a stop_gradient to the probability multiplier, we ensure the model uses its current confidence to scale the importance of each update without attempting to "cheat" the loss by simply lowering its confidence. This simple change ensures that every expert token provides a stable, uniform signal to the model.
Experimental Evaluation
We evaluated DFT across a wide array of high-difficulty benchmarks using models such as Qwen2.5-Math-1.5B and Qwen2.5-Coder-7B. Training was conducted on datasets including NuminaMath-CoT (100k samples) for math and UltraFeedback for coding.
Key Results in Mathematical Reasoning
DFT demonstrated transformative gains in mathematical reasoning tasks. On the Qwen2.5-Math-1.5B base, DFT improved average accuracy from 18.01% to 31.58%. Notably, on the highly challenging OlympiadBench, where standard SFT actually degraded the base model's performance (from 15.88% to 12.63%), DFT reversed the trend, achieving 27.08% accuracy.
Efficiency and Convergence
Unlike iterative RL methods that require sampling multiple responses or maintaining reference models, DFT operates directly on the training set. It reaches peak performance significantly faster than standard SFT, often plateauing within just 120 training steps, as shown in the performance curves above.
Discussion and Insights
Bimodal Probability Distribution
Analysis of the models' internal states reveals that DFT induces a "polarizing" effect on token probabilities. The model becomes highly confident in substantive, semantic tokens while allowing "filler" tokens (e.g., "the", "let") to remain at lower probabilities. In contrast, standard SFT attempts to push all tokens toward high confidence, which exhausts the model's capacity and leads to overfitting.
The Knowledge Trade-off
While DFT excels at reasoning and generalization, it shows a limitation in learning new factual information. On the Natural Questions dataset, DFT underperformed compared to SFT. Because DFT down-weights updates for tokens the model is highly uncertain about, it is less effective at "force-feeding" the model entirely new facts that are not already present in its weights. This suggests that while DFT is superior for reasoning and alignment, standard SFT remains preferable for knowledge injection.
Conclusion
Dynamic Fine-Tuning (DFT) offers a powerful, theoretically motivated alternative to standard SFT. By rectifying the implicit reward structure of the cross-entropy loss, DFT enables LLMs to achieve RL-level generalization in reasoning tasks without the computational overhead or tuning complexity of traditional RL algorithms. This "one-line" solution represents a significant step forward in efficient LLM post-training.
Summary updated