Skip to content

feat(chunked_loss): add fused linear IRPO (Iterative Reasoning Preference Optimization) loss - #1586

Open
Yulong-Cauli wants to merge 2 commits into
linkedin:mainfrom
Yulong-Cauli:feat/irpo-loss
Open

Yulong-Cauli wants to merge 2 commits into
linkedin:mainfrom
Yulong-Cauli:feat/irpo-loss

Conversation

@Yulong-Cauli

Copy link
Copy Markdown
Contributor

Adds LigerFusedLinearIRPOLoss, a chunked fused-linear implementation of the Iterative Reasoning Preference Optimization objective (arXiv 2404.19733), completing the IRPO item of the FlexChunkLoss alignment roadmap (#371).

Formula (Equation 1 of the paper)

L_IRPO = L_DPO + α · L_NLL, with defaults β=0.1 and α=1.0 per the paper:

  • DPO term: −log σ(β·(log[πθ(y_w)/πref(y_w)] − log[πθ(y_l)/πref(y_l)])) over summed (length-unaveraged) sequence log-probabilities, with the reference model participating (the previous iteration's model M_t in the paper)
  • NLL term: length-normalized NLL on the chosen response, composed by LigerFusedLinearPreferenceBase (compute_nll_loss=True)

The iterative parts (rejection sampling between iterations, conditional-SFT prefixing) live in the training loop; this module computes the per-batch loss given a policy and an optional reference.

Implementation

Follows LigerFusedLinearDPOFunction on LigerFusedLinearPreferenceBase:

  • chunked_loss/irpo_loss.py: LigerFusedLinearIRPOFunction + LigerFusedLinearIRPOLoss
  • Functional API: liger_fused_linear_irpo
  • Registered in chunked_loss/__init__.py, documented in the README / docs alignment-kernel tables
  • Tests: test/chunked_loss/test_irpo_loss.py (reference HFIRPOLoss, large/small shapes, bf16/fp32, bias/ref_bias, ignore_index/β variants, functional contract, frozen weights, α-scales-NLL check)
  • Benchmark: benchmark/scripts/benchmark_irpo_loss.py

Verification

  • ruff check + ruff format (pinned v0.14.11) clean
  • Full test suite on Kaggle T4 (torch 2.11.0+cu128, SM75): 54 passed in 20.12s, including all bf16 cases
  • Full test suite on A100-SXM4-80GB (torch 2.11.0+cu130, SM80): 54 passed in 42.63s, covering the native bf16 compilation path that T4 cannot exercise
  • Note on test methodology: the large-shape module comparisons use average_log_prob=True, consistent with the other paired-loss test wrappers. With summed log probabilities at large shapes in bf16, the HF-reference comparison is seed-unstable (chunked-GEMM rounding amplified by ~T; verified that existing DPO behaves identically in the previously untested {NLL + ref + summed-logp} combination). The paper-faithful summed path (the module default) is covered by the functional tests in both dtypes.
  • Upstream CI (Modal H100/B200) will cover the full dtype/arch matrix

Refs #371

…ence Optimization) loss

Add LigerFusedLinearIRPOLoss, a chunked fused-linear implementation of the
Iterative Reasoning Preference Optimization objective (arXiv 2404.19733):
a DPO preference term over summed sequence log-probabilities with a
reference model (the previous iteration's model M_t in the paper), plus a
length-normalized NLL term on the chosen response composed by
LigerFusedLinearPreferenceBase (compute_nll_loss=True, alpha=1.0 and
beta=0.1 defaults per the paper).

The implementation follows LigerFusedLinearDPOFunction on the
LigerFusedLinearPreferenceBase and includes:
- chunked_loss/irpo_loss.py (Function + nn.Module, functional alias)
- correctness tests vs an HF-style reference (test_irpo_loss.py)
- benchmark script (benchmark_irpo_loss.py)
- README / docs table entries

Part of the FlexChunkLoss alignment roadmap (linkedin#371).

This branch has not been deployed

No deployments
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