M5-053M5: NLP & Large Language ModelsDPO Family (DPO / KTO / ORPO)Medium
⚡Flashcard Drill➔Mastery:

SFT and DPO Hybrid Training Strategies

📐 Mathematical Definition
L=LDPO+αLSFT(yw);α≈0.01∼0.1\mathcal{L}=\mathcal{L}_{\text{DPO}}+\alpha\mathcal{L}_{\text{SFT}}(y_w);\qquad \alpha\approx0.01\sim0.1
⚡ One-Sentence Core Answer
Co-training DPO with an auxiliary SFT loss over winning completions prevents likelihood displacement and language degeneration by anchoring the policy to high generative probability on positive demonstrations.

📌 Key Takeaways

  • •
    The degeneration problem: pure DPO loss optimizes relative margins log⁡(π(yw)/π(yl))\log(\pi(y_w)/\pi(y_l)) and often decreases the absolute probability of both completions, causing perplexity to explode and language fluency to degrade
  • •
    Co-training objective: adds a weighted SFT loss term on winning responses: Lhybrid=LDPO+γLSFT(x,yw)\mathcal{L}_{\text{hybrid}} = \mathcal{L}_{\text{DPO}} + \gamma \mathcal{L}_{\text{SFT}}(x, y_w)
  • •
    Empirical stability: stabilizes training across multiple epochs, maintains low validation perplexity, and preserves pre-trained knowledge representations

📐 Mathematical Derivations

Mathematical Mechanism: 1. Likelihood Displacement in Pure DPO: DPO gradient with respect to policy θ\theta: ∇θLDPO=−βσ(r^l−r^w)[∇θlog⁡πθ(yw∣x)−∇θlog⁡πθ(yl∣x)]\nabla_\theta \mathcal{L}_{\text{DPO}} = -\beta \sigma(\hat{r}_l - \hat{r}_w) \left[ \nabla_\theta \log \pi_\theta(y_w \mid x) - \nabla_\theta \log \pi_\theta(y_l \mid x) \right] If log⁡πθ(yw)\log \pi_\theta(y_w) drops by 2 nats while log⁡πθ(yl)\log \pi_\theta(y_l) drops by 6 nats, DPO loss decreases by 4 nats. The policy satisfies the relative preference margin while simultaneously becoming less likely to generate the correct answer ywy_w in greedy decoding! 2. Hybrid SFT + DPO Formulation: Adding supervised cross-entropy over ywy_w: Lhybrid(θ)=LDPO(θ)+γ⋅E(x,yw)[−∑t=1∣yw∣log⁡πθ(yw,t∣x,yw,<t)]\mathcal{L}_{\text{hybrid}}(\theta) = \mathcal{L}_{\text{DPO}}(\theta) + \gamma \cdot \mathbb{E}_{(x, y_w)} \left[ -\sum_{t=1}^{|y_w|} \log \pi_\theta(y_{w, t} \mid x, y_{w, <t}) \right] The gradient of the hybrid loss becomes: ∇θLhybrid=−(βσ(r^l−r^w)+γ)∇θlog⁡πθ(yw)+βσ(r^l−r^w)∇θlog⁡πθ(yl)\nabla_\theta \mathcal{L}_{\text{hybrid}} = -\left( \beta \sigma(\hat{r}_l - \hat{r}_w) + \gamma \right) \nabla_\theta \log \pi_\theta(y_w) + \beta \sigma(\hat{r}_l - \hat{r}_w) \nabla_\theta \log \pi_\theta(y_l) Because the coefficient on ∇θlog⁡πθ(yw)\nabla_\theta \log \pi_\theta(y_w) is strictly larger than on yly_l by margin γ>0\gamma > 0, the optimizer is mathematically forced to increase the absolute generation probability of the winning response.

🏭 Production Trade-offs

Deep Dive & Engineering Trade-offs: ① Hyperparameter Tuning $\gamma$: Setting γ∈[0.1,0.5]\gamma \in [0.1, 0.5] provides optimal regularization. If γ\gamma is too small (<0.05<0.05), likelihood displacement still occurs; if γ\gamma is too large (>1.0>1.0), SFT dominates and preference separation is muted. ② Pre-training Data Replay Integration: In addition to LSFT(yw)\mathcal{L}_{\text{SFT}}(y_w), adding 5%5\% pre-training general text replay (Lpretrain\mathcal{L}_{\text{pretrain}}) completely protects against catastrophic forgetting during extended alignment. ③ Two-Phase vs Single-Phase: Standard practice runs sequential SFT followed by DPO. Hybrid co-training allows teams to run SFT and DPO simultaneously in a single unified training stage (as in ORPO), cutting post-training compute time in half. ④ Validation Metric Monitoring: During hybrid training, track both preference classification accuracy and validation cross-entropy loss on clean held-out text; a healthy run exhibits rising accuracy and steady or decreasing perplexity. ⑤ Interview Strategy: Explain why pure DPO suffers from likelihood displacement, write out the hybrid gradient showing how γ\gamma forces positive updates on ywy_w, and cite empirical stability gains.
⚠️ Common Interview Pitfalls
  • ✕
    Training pure DPO for multiple epochs without an SFT regularizer, leading to sudden language collapse
  • ✕
    Setting γ\gamma so large that preference alignment is drowned out by supervised imitation
  • ✕
    Computing the SFT regularizer on both winning ywy_w and losing yly_l responses (must apply strictly to ywy_w)
🎯 Interviewer Follow-up Inquiries
  • ?
    How does the auxiliary SFT coefficient γ\gamma prevent the model from drifting into repetitive degeneration loops?
  • ?
    What is the mathematical relationship between hybrid SFT+DPO and Odds Ratio Preference Optimization (ORPO)?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

Explore the comprehensive technical article, exam cards, and global architecture tree.

← PreviousM5-052: Length Bias in DPO and Length Control Methods📋Back to BankNext →M5-054: Mathematical Formulation of GRPO Advantage Estimation and Loss
中文速览与面试要点

解释 DPO 与 SFT 的混合训练策略。

在 DPO 损失中混入一定比例的 SFT 损失(对好回答的 NLL),可防止似然位移、保持生成质量与语言能力。

核心要点

  • 数学机理: 动机 ——纯 DPO 只约束'好回答相对坏回答的 log-ratio',故可通过'同时降低两者的绝对概率'来增大比值( 似然位移 ),导致 (a) 生成质量下降(绝对概率低)、(b) 语言能力退化(输出不自然)、(c) 灾难性遗忘。 混合策略 ——在 DPO 损失中加入 SFT 损失 (对 好回答 y_w 的负对数似然):L=L_DPO + α·L_SFT(y_w),其中 L_SFT(y_w)=−log π_θ(y_w|x)。 作用机制 ——SFT 项 直接提高好回答的绝对概率 (而非仅相对),从而 (a) 锚定绝对概率(防似然位移)、(b) 保持生成质量与流畅性、(c) 缓解遗忘。 α 的选择 ——(a) α 太小 (如 0.001)无效果(DPO 主导);(b) α 太大 (如 1)则退化为 SFT(失去偏好优化效果);(c) 常用 0.01~0.1 (TRL 的 DPO 支持 sft_loss 混合)。 其他等价/相关做法 :(a) 两阶段 ——先 SFT、再纯 DPO(简单但可能在 DPO 阶段仍出现似然位移);(b) 参考模型的锚定 ——DPO 的 log-ratio 已含 π_ref(提供一定锚定),但不够(因为 π_ref 固定,不能阻止 π_θ 绝对概率下降);(c) RPO/IPO 等变体 ——用有界目标从结构上防止过度优化。 实证 ——多个工作显示'DPO + SFT 混合'在生成质量与流畅性上优于纯 DPO,且对'语言退化'有显著缓解。 注意 ——混合 SFT 也会 (a) 稍微削弱偏好优化的强度、(b) 增加一个超参 α;但收益通常大于成本。
  • 深度剖析与工程权衡:① '似然位移'是混合 SFT 的直接动机 ——理解这一点是掌握该技巧的关键;它说明'相对偏好'与'绝对质量'是两个维度,需分别优化。② α 的调参经验 ——实践中常从 0.01~0.05 起步,观察'输出长度/流畅性/偏好准确率'三个指标;若流畅性下降则增大 α。③ 与'两阶段训练'的对比 ——两阶段(SFT → DPO)更简单,但 DPO 阶段仍可能破坏 SFT 学到的流畅性;混合(同时优化)能在训练过程中持续锚定。故混合更稳健。④ 与'online DPO'的关系 ——online DPO 用当前策略的数据,似然位移的风险相对小(因为数据与策略分布一致);但混合 SFT 仍是有益的补充。⑤ '遗忘'的检测 ——混合 SFT 能缓解遗忘,但仍需在 通用基准 上验证(如 MMLU、常识推理);若遗忘明显,可增大 α 或混入通用数据。⑥ 面试要点 ——被问'DPO 训练要注意什么',应给出' 似然位移 → 混合 SFT 损失(对 y_w 的 NLL,α≈0.01~0.1)→ 锚定绝对概率、保持流畅性 ',并说明'α 太小无效、太大退化为 SFT';能解释'似然位移的机制(同时降低两者以增大比值)'是深度理解的标志。
  • 纯 DPO 会导致似然位移(好回答绝对概率下降)
  • 混入 SFT 损失(对 y_w 的 NLL)可锚定绝对概率
  • α 常取 0.01~0.1;也可用'先 SFT 再 DPO'的两阶段

常见陷阱

  • 纯 DPO 训练导致输出不自然(似然位移)
  • α 设得过大使 DPO 退化为 SFT