Repository navigation
docs: document token_level_loss in the GRPO guide - #3656
Merged
Merged
Conversation
yfw
reviewed
Aug 17, 2026
Collaborator
Author
|
/ok to test 8a6f950 |
terrykong
enabled auto-merge (squash)
August 17, 2026 20:40
Adds a Loss Normalization section to docs/guides/grpo.md covering what token_level_loss controls: the reduction applied to the per-token loss (and the KL penalty), not the per-token quantity itself. The section includes the two reduction formulas, a worked example contrasting a 10-token and a 1000-token response, a table writing out the full objective for GRPO/PPO/DAPO, CISPO, GSPO and REINFORCE/RLOO under both settings, a table of the losses that fix their normalization as a class attribute, and a table of which reported metrics follow the flag. Also fixes the REINFORCE/RLOO formula in the ClippedPGLossFn docstring, which wrote the objective in terms of pi_theta where the code uses log pi_theta, and links to the new section from the dapo and cispo guides, where the parameter was previously mentioned without explanation. Closes #1274 Signed-off-by: Terry Kong <[email protected]>
- Separate the two epsilon symbols with a comma instead of a slash.
GitHub's math renderer does not close an inline span when the next
character is a slash immediately followed by another '$', so
$...$/$...$ rendered the second symbol as literal text.
- Name $\ell_{i,t}$ the per-token objective rather than a per-token
quantity, and drop the leading minus from the two reductions and the
objective table so the sign convention matches the L(theta) formula
earlier in the same section, which is written without one.
Signed-off-by: Terry Kong <[email protected]>
The link was pinned to e983576, a commit this branch was never based on. That SHA is in main's history and the line range happens to be correct there, but pinning to the branch's actual base is verifiable. Re-pinned to 4a1454b; confirmed L335-L371 is the metric_normalizations table at that commit and that the ref resolves. Signed-off-by: Terry Kong <[email protected]>
terrykong
force-pushed
the
terryk/docs-token-level-loss
branch
from
August 17, 2026 21:54
8a6f950 to
44cdeae
Compare
Collaborator
Author
|
/ok to test 44cdeae |
yfw
approved these changes
Aug 17, 2026
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.
What
Closes #1274.
token_level_losshad no explanation anywhere in the docs — it appeared only as a bare line in config blocks (dapo.md,cispo.md,ppo.md,prorlv2.md) and in ~30 example YAMLs. This adds a Loss Normalization section todocs/guides/grpo.md, placed under## Lossbefore the "Improvements to the GRPO Loss Formulation" subsections — it is not an optional stability add-on like those, it is a property of the baseline loss that the existingContents of the new section
trueand 50%/50% underfalse, so short-response tokens carry ~100× the per-token weight under sequence-level.ClippedPGLossFn.__init__.token_level_lossis a field ofClippedPGLossConfigonly; SFT, DPO/RM, distillation, the PPO critic, cross-tokenizer distillation and Eagle3 draft training all fixloss_typeas a class attribute. Setting it in an SFT config does nothing, which is worth saying out loud.loss,kl_penalty), which are always token-normalized, which key off a different parameter (sampling_importance_ratio,is_oob_ratio), and which are not normalized at all. Relevant when comparing runs across the setting.Also in this PR
loss_functions.py:206): the REINFORCE/RLOO objective was written as:541setsratios = curr_logprobs— the raw log-probability, notexp(). The new table is derived from the code, so leaving the docstring disagreeing with it would have been confusing. Corrected todapo.md:86andcispo.md:56to the new section. Those are the two pages where a reader meets this parameter first and currently gets no explanation — the same gap the issue reports.No changes to
ppo.md(it already defers wholesale to the GRPO guide) ordocs/index.md(no new file;grpo.mdis already in the toctree).Verification
The docs build could not be run locally —
uv.lockonly supports Linux and this is macOS — so the MyST-level checks were done directly:mdit_py_plugins.anchors.slugify:Loss Normalization (\token_level_loss`)→loss-normalization-token_level_loss, matching the links fromdapo.mdandcispo.md.myst_heading_anchors = 5inconf.py:68covers the###/####` levels used.markdown-it-py+dollarmath: all 3 tables parse with the intended cell counts, and all inline/display math tokenizes. Table cells use\lvert/\rvertrather than bare|, which would otherwise split the rows.:528-534, CISPO against:545, the clipped surrogate against:547-551, REINFORCE against:541-542.sft.py:229,dpo.py:284,rm.py:263,distillation.py:641,ppo.py:377,xtoken_off_policy_distillation.py:479,wrapper.py:251).ruff format --checkandruff checkpass on the modified Python file.The permalink to
metric_normalizationsis SHA-pinned rather thanblob/main, since a line-anchored link tomainbreaks silently as code shifts.