Triton monolithic head-loss kernel (#507)#558
Open
jlamypoirier wants to merge 1 commit into
Open
Conversation
jlamypoirier
added a commit
that referenced
this pull request
Jul 10, 2026
Bring main (via the updated compiled base) into the triton PR. The metrics rework and triton work merge cleanly; fix the leftover references to the renamed metrics enum (`GRPOMetricsLevel` -> `PolicyMetricsLevel`) in the triton child classification (`config.py`, `monolithic.py`). GSPO metrics are already rejected for any monolithic composite, so the triton path only rejects GRPO metrics (which it doesn't compute). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
73683f7 to
284fe2f
Compare
Add the triton implementation of the monolithic shared-softmax loss and its policy-metric support, on top of the compiled path: - The triton kernel fuses the label-based objective set (CE, z-loss, GRPO, GSPO) over one softmax, superposing their gradients. - Policy metrics: the kernel accumulates the entropy's `Σ exp·logits_norm` for free in the backward re-stream; the layer reduces the family eagerly. Metrics force the reduced forward pass so the softmax is available in every case. - `MonolithicLossConfig.use_triton` selects the path (default: use if available), with per-kind fusion limits validated at config time. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
32c3943 to
2368650
Compare
284fe2f to
8c9f052
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude Opus 4.8 (1M context) note: authored this PR.
Follow-up to #549, stacked on
jlp_monolithic_head_loss. Gives themonolithicloss a single Triton kernel for its shared-softmax path, alongside the existingtorch.compilepath.What it does
The
monolithicloss can now run its shared softmax on one@triton_jitkernel viause_triton, covering the label-based objective set: cross-entropy (label),z_loss, the GRPO objective, and the GSPO objective. Any subset sharing one softmax works (CE+z, GRPO+z, GSPO+z, …), at most one of each kind.Distillation and GRPO metrics have no Triton fused kernel yet — they are rejected at config time when
use_triton=True, and fall back to the compiled path whenuse_tritonis left at itsNone(auto) default. DPO stays separate as before.Design
Every enabled loss stores its own forward scalar, but the gradients superpose into two per-row coefficients:
so the gradient-write loop is loss-agnostic and each loss's math only contributes to the coefficients (z-loss adds to
prob_coeffonly; CE/GRPO/GSPO share the same label column). The kernel is gated purely by the presence of each loss's input/output pointers — no separate enable flags.Three dispatch cases mirror the existing per-loss Triton kernels:
GSPO's seam-argument assembly is factored out of
finishso the compiled and Triton paths share it.Config
use_triton: bool | NoneonMonolithicLossConfig:True— rejects unsupported children (distillation, GRPO-with-metrics, duplicate kinds) at validate time.None(default) — Triton on GPU only if every child is supported, else the compiled monolithic.False— always compiled.Validation
Numerically validated on CPU via the Triton interpreter (
TRITON_INTERPRET=1):test_lm_headfused_tritonconfigs — 36/36 (single-pass and the GSPO seam, across masking / splits / bf16 / logit scaling / softcap).test_monolithic_loss_tritonfunctional — 20/20.world_size=2monolithic-tritonsubtest for the tensor-parallel path — passing.Caveat: this is interpreter-only so far; validation on compiled Triton on a GPU is still pending.
Follow-ups: distillation in the Triton kernel, and the GRPO/GSPO metrics rework.
🤖 Generated with Claude Code