Skip to content

feat(trainer): IPO+KL — double-sided mask, KL only on kept tokens#2423

Draft
samsja wants to merge 5 commits intomainfrom
feat/ipo-double-sided
Draft

feat(trainer): IPO+KL — double-sided mask, KL only on kept tokens#2423
samsja wants to merge 5 commits intomainfrom
feat/ipo-double-sided

Conversation

@samsja
Copy link
Copy Markdown
Member

@samsja samsja commented May 5, 2026

Summary

Two modifications to the existing IPO+KL default loss (DPPO-Binary TV PG term + Kimi-K2.5 KL term):

  1. Double-sided importance-ratio masking (advantage-sign-agnostic): tokens whose ratio $r_t = \pi_{\text{train}}/\pi_{\text{infer}}$ falls outside $[\alpha, \beta]$ are dropped. Replaces the original advantage-conditioned probability-difference mask.
  2. KL only on kept tokens. Previously kl_loss = loss_mask * log_ratio**2 — KL was paid even on tokens excluded from the PG term. Now it's gated by keep_mask, so masked tokens contribute nothing to either term.

The PG-term shape (DPPO-Binary TV) and the KL form (Kimi-K2.5, $(\log r_t)^2$) are unchanged. adv_tau / teacher_tau (on-policy distillation) are also unchanged.

$$\mathcal{L}(\theta) = \sum_t \mathbb{1}[r_t \in [\alpha, \beta]] \cdot \mathbb{1}[\text{loss_mask}] \cdot \big(-\widehat{A}_t \cdot r_t + \tau_{\text{kl}} \cdot (\log r_t)^2\big)$$

Breaking config changes (trainer.loss)

Field Was Now
dppo_mask_low (default 0.2) prob-diff threshold importance-ratio lower bound α
dppo_mask_high (default 0.25.0) prob-diff threshold importance-ratio upper bound β

kl_tau (1e-3), adv_tau (1.0), teacher_tau (0.0) untouched.

Notes

  • Sibling PR feat(trainer): replace DPPO+KL default loss with IcePop #2401 (feat/icepop-loss) is pure IcePop, no KL term at all. This PR keeps the existing KL — useful if the KL signal turns out to add stability on top of the double-sided mask alone.
  • Field names kept (dppo_mask_*) to keep the diff against main minimal; only the semantic and one default change.
  • Test file untouched — existing smoke tests pass dppo_mask_high=10.0 as a kwarg, which still resolves to a valid (now ratio-based) value.

🤖 Generated with Claude Code

samsja and others added 4 commits May 5, 2026 14:19
Two modifications to the default IPO+KL loss:

1. Replace advantage-conditioned probability-difference masking with
   IcePop-style double-sided importance-ratio masking: tokens whose
   ratio π_train/π_infer falls outside [α, β] are dropped.
2. Apply the KL penalty only to unmasked (kept) tokens. Previously,
   `kl_loss = loss_mask * log_ratio**2` accumulated KL for tokens
   that contributed nothing to the PG term — now it's gated by
   `keep_mask`.

Breaking config changes (`trainer.loss`):
- removed: `dppo_mask_low`, `dppo_mask_high` (probability-diff thresholds)
- added: `ipo_ratio_low` (default: 0.2, α), `ipo_ratio_high`
  (default: 5.0, β) — importance-ratio bounds
- unchanged: `kl_tau`, `adv_tau`, `teacher_tau`

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per review: don't rename the fields. The semantics changed
(prob-diff threshold → importance-ratio bound), but reusing the
existing field names keeps the diff against main minimal.
`dppo_mask_high` default goes 0.2 → 5.0 to match the new ratio
semantic; `dppo_mask_low` stays at 0.2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per review: this isn't modified IPO. The DPPO probs-diff mask is
fully gone; what's left is IcePop's ratio mask plus a Kimi-K2.5 KL
term gated by the same mask. Update docstring and CHANGELOG entry
to reflect that.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@samsja samsja changed the title feat(trainer): IPO+KL with double-sided mask, KL only on unmasked tokens feat(trainer): IcePop + KL on unmasked tokens May 5, 2026
Per review: this is IPO — DPPO+KL with two mods (double-sided mask
+ KL on kept tokens only). Not IcePop; IcePop is the no-KL sibling
PR. Restore IPO+KL framing in docstring and CHANGELOG.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@samsja samsja changed the title feat(trainer): IcePop + KL on unmasked tokens feat(trainer): IPO+KL — double-sided mask, KL only on kept tokens May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant