Repository navigation
Conversation
|
@claude review |
There was a problem hiding this comment.
Verdict: Needs discussion -- The math is correct: below the bound the tail fold is exact for DPPO. But the only end-to-end run shows score centering does nothing for DPPO there (coefficient_l1 < 4e-10), so maintainers need to decide whether DPPO + score centering is worth supporting before it lands.
What this PR does. It lifts DPPOLoss's ban on score_centering.
log_token_weightgains atrainer_logprobsargument, so DPPO's weight can apply its drop rule (sign(A) * (p - q) > threshold). DAPO/GRPO, CISPO and IcePop ignore the argument (mechanical).- For the tail,
ScoreCenteringevaluates the weight atp_max = min(trainer tail mass, min_H q / rho). Under the tail model a tail token moves bysign(A) * (1 - rho) * p_v, which is linear inp_v. So if the token atp_maxis kept, every tail token is kept, andalpha = rho * min(1/rho, max_ratio)is exact. - Past the bound,
alpha = 0: the whole tail counts as dropped.
Example. k = 32, A = +1, threshold 0.2:
rho = 1.2, tail masses 0.0010 / 0.0012
-> (1 - 1.2) * p_max < 0: nothing dropped, alpha = 1.2 * (1/1.2) = 1 (exact, same as main's CISPO path)
rho = 0.1, trainer tail 0.5, min_H q = 0.03
-> p_max = min(0.5, 0.3) = 0.3, 0.9 * 0.3 = 0.27 > 0.2
-> alpha = 0, though tail tokens with p_v < 0.22 should keep weight min(10, 5) = 5
Before: DPPOLoss.Config(score_centering=...) raises ValueError.
Must fix
- The PR description has an empty "Summary (human-written)" section. Please fill it in.
- There is no evidence of value yet. The only run (
rl_dppo_score_centering_qwen3_0_6b_varlenvsrl_dppo_qwen3_0_6b_varlen) showscoefficient_l1 < 4e-10, with no token dropped or truncated, so score centering is a no-op for DPPO in that setting. The PR changes thelog_token_weightinterface on all five losses and adds a recipe for this combination. The description should name the setting where DPPO + score centering changes the update (stale or off-policy rollouts, a quantized generator, any run where DPPO actually drops tokens) and ideally show a run there. Without one, it is a supported combination with no measured effect. That run was also made at the commit before themin_H q / rhobound, so it doesn't cover HEAD's tail code (with top-k mass 1.00, neither bound binds).
Should consider
torchtitan/rl/trainer/losses/score_centering.py:148-- when the tail bound crosses and the "whole tail dropped" approximation turns on, no metric shows it (inline).torchtitan/rl/trainer/losses/dppo.py:84-- the drop rule is duplicated betweenlog_token_weightand_dropped, and the two computeqdifferently (inline).torchtitan/rl/trainer/losses/README.md:69-- this paragraph duplicates the newScoreCenteringdocstring paragraph (inline).
Questions
- Past the bound, is "whole tail dropped" (
alpha = 0) better than "whole tail kept" (alpha = rho * w(1/rho))? The large-p_vtail tokens, which carry most of the tail mass, are the ones dropped. But nothing in the PR shows which choice is closer to the full-vocabulary correction.
Details
- Bound check. Tail tokens lie outside the generator's top-k, so
q_v <= min_H q, and under the tail modelp_v = q_v / rho <= min_H q / rho. Alsop_v <= trainer tail mass.- With
A < 0,prob_change = (rho - 1) * p_v < rho * p_v = q_v <= 1/k, so for k = 32 it can never cross 0.2. - With
A > 0, crossing needs(1 - rho) / rho > 6.4, i.e.rho < 0.135. The "0.14" in the docs matches. - The bound depends on k: the user can configure
num_topk_logprobsdown to 1, wheremin_H qcan approach 1. The docs say "e.g. k = 32", which is fine.
- With
- Head coefficients.
log_token_weight(trainer - generator, A, trainer)rebuildsq = exp(log p - log r), which matches_droppedup to fp32 rounding. On masked rows the inputs are 0 andamingives 0. The coefficients are masked byrow_maskanyway, so no NaN reaches the loss. - Interface change. Adding
trainer_logprobsto every loss for one consumer is justified. The alternative(trainer_logprobs, generator_logprobs)signature would rebuild-log_rhoaslog p_max - (log p_max + log_rho)for the other losses, which changes their tail rounding (and gives NaN whenlog p_max = -inf). The current signature keeps CISPO/IcePop/DAPO bitwise unchanged. - TP / compile. The top-k logprobs are global after
compute_topk_logprobs,amin/minimumare local[T, k]ops, and there are no host syncs. - I found no remaining callers or subclasses of
log_token_weightbeyond the five losses and the test.
Not verified: I couldn't run the CPU tests in this environment, and I have no GPU run of the new recipe at HEAD.
| # tail token is outside the generator's top-k, q_v = rho * p_v <= min_H q. | ||
| log_max_tail_trainer_prob = torch.minimum( | ||
| log_trainer_tail_mass, generator_logprobs.amin(-1) - log_rho | ||
| ) | ||
| alpha = torch.exp( | ||
| log_rho | ||
| + log_token_weight(-log_rho, advantages, log_max_tail_trainer_prob) | ||
| ) |
There was a problem hiding this comment.
When the bound crosses, the approximation turns on with no signal. Past sign(A) * (1 - rho) * p_max > divergence_threshold, alpha becomes 0 for the row, so the whole tail counts as dropped. None of the metrics show when this happens: coefficient_l1 stays nonzero and the top-k masses don't say which rows crossed. The README calls this a documented approximation, but a user running stale or quantized rollouts, where rho can get small, has no way to tell whether it is active.
Two options:
- Report the fraction of loss rows whose tail weight is
-inf(e.g.score_centering/tail_zero_weight_frac). For IcePop that rows-outside-band case is exact, so the metric means "tail fully zero-weighted", not "approximate". - If that metric isn't wanted, say in the description why invisibility is fine here.
| # _dropped's rule, with p_gen = p / r. | ||
| prob_change = advantages.sign() * ( | ||
| torch.exp(trainer_logprobs) - torch.exp(trainer_logprobs - log_ratio) | ||
| ) | ||
| # The weight reads PolicyGradientLoss's ratio, whose |log r| is clamped. |
There was a problem hiding this comment.
The drop rule now lives in two places: here, and in _dropped (line 103). The two even compute q differently (exp(log p - log r) here, exp(log q) there). The gradient-match test guards them for now, but any change to the rule, such as the binary-KL TODO, has to edit both.
A small module-level _prob_change(trainer_logprobs, generator_logprobs, advantages) could serve both. log_token_weight would call it with trainer_logprobs - log_ratio, and _dropped with the ScoredTokens fields. That keeps one copy of the rule at about the same LoC.
| - `DPPOLoss`: its trust region makes a tail token's weight depend on its own `p_v`, but the | ||
| top-k tail model folds the tail with one weight. Under the tail model a tail token moves by | ||
| `(1 - rho) * p_v`, and `p_v` is at most `min(trainer tail mass, min_H q / rho)` (a tail | ||
| token is outside the generator's top-k), so the fold is exact unless that bound moves past | ||
| `divergence_threshold` (0.2). With k = 32, `min_H q <= 1/32`, so that needs `rho < 0.14` | ||
| with `A > 0` and a trainer tail above 0.2. Past it the whole tail counts as dropped. |
There was a problem hiding this comment.
This paragraph repeats ScoreCentering's new docstring paragraph (score_centering.py:46-52) almost word for word, including the k = 32 / rho < 0.14 derivation. Line 51 of this README already points readers to the docstring for the coefficient formula. Keeping the derivation in one place avoids the two copies drifting apart. One option is a one-line bullet here ("DPPOLoss: exact unless a tail token can move past divergence_threshold; see ScoreCentering"), with the derivation kept only in the docstring.
c74494a to
5db4552
Compare
|
@claude review again |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The stale-rollout run shows that score centering changes DPPO's update there, and the drop rule now has a single copy. What's left are edits to the description and the README. A maintainer still needs to review.
What changed since the last review (5db4552, one commit, force-pushed):
- Value: resolved. With
target_offpolicy_steps=3, the trust region drops 0.2-0.4% of tokens andcoefficient_l1is 2.4e-3 to 3.9e-3. So the combination is no longer a measured no-op. The reward gain over 3 seeds is within noise, and the description says so. - Duplicated drop rule: resolved.
_dropped(trainer_logprobs, generator_logprobs, advantages)now servestoken_loss,token_metricsandlog_token_weight.log_token_weightpasseslog q = log p - log r. - README duplicating the docstring: resolved. It is now a short pointer to
ScoreCentering's docstring, but the new wording is ambiguous (inline).
Example. Same as before. With k = 32 and A = +1, the tail at rho = 1.2 is kept, with alpha = 1 (exact). At rho = 0.1 with a trainer tail of 0.5, alpha = 0. Before this PR, DPPOLoss.Config(score_centering=...) raised.
Must fix
- The "Summary (human-written)" section is still empty (still open).
torchtitan/rl/trainer/losses/README.md:71-73-- "that needsrho < 0.14" reads as the condition for exactness rather than for crossing, and the tail-mass condition was dropped (inline, with a suggestion).
Should consider
torchtitan/rl/trainer/losses/score_centering.py:148-- still open, no change in code: no metric shows when the "whole tail dropped" approximation turns on. With top-k mass near 1.00 in every run so far, the bound has never bound. A user with a smallnum_topk_logprobsor a quantized generator has no signal that it does.
Questions
- Still open: past the bound, why is
alpha = 0(whole tail dropped) preferred overalpha = rho * w(1/rho)(whole tail kept)? - Was the stale-rollout run made at HEAD? Even if it was, top-k mass near 1.00 means neither tail bound binds there, so HEAD's
min_H q / rhopath has CPU test coverage only.
Details
_dropped's arguments inlog_token_weight. On the head,trainer_logprobs - (trainer_logprobs - generator_logprobs)equalsgenerator_logprobsup to fp32 rounding, which the gradient-match test covers. On the tail,q = p_max * rho, which matches the docstring.- Edge cases. A
-inftop-k generator logprob giveslog p_max = -inf, sop = q = 0: the token is not dropped andalphastays finite. Masked rows are zeroed byrow_mask. - Tests. The proportional-tail test moved from vocab 16 / top-4 to vocab 64 / top-16 with flatter logits, for every loss. At tail scale 0.5 it covers the below-bound case where the tail masses differ by more than the threshold. Past the bound (
alpha = 0), the approximation is not tested, which is reasonable since it isn't exact.
Not verified: I couldn't read replies on the earlier inline threads or run the CPU tests in this environment.
| - `DPPOLoss`: its trust region reads each tail token's own `p_v`, so the tail fold is exact | ||
| only while no tail token can move past `divergence_threshold` (see `ScoreCentering`'s | ||
| docstring). With k = 32 that needs `rho < 0.14` with `A > 0`. |
There was a problem hiding this comment.
After the trim, "that needs rho < 0.14" can be read the wrong way round. "That" is meant to be the crossing (a tail token moving past the threshold), but it reads as the condition for the fold to be exact. The trim also dropped the second condition (trainer tail mass above 0.2), which the docstring and the PR description both state. Saying what breaks exactness makes it unambiguous:
| - `DPPOLoss`: its trust region reads each tail token's own `p_v`, so the tail fold is exact | |
| only while no tail token can move past `divergence_threshold` (see `ScoreCentering`'s | |
| docstring). With k = 32 that needs `rho < 0.14` with `A > 0`. | |
| - `DPPOLoss`: its trust region reads each tail token's own `p_v`, so the tail fold is exact | |
| only while no tail token can move past `divergence_threshold` (see `ScoreCentering`'s | |
| docstring). With k = 32 a tail token can cross only if `rho < 0.14`, `A > 0` and the | |
| trainer's tail mass is above 0.2; past that the whole tail counts as dropped. |
5db4552 to
10c55ae
Compare
10c55ae to
27b167c
Compare
27b167c to
9d5cf4d
Compare
9d5cf4d to
d9bf505
Compare
DPPO's trust region makes a token's weight read p as well as p / q, so log_token_weight takes the token's trainer logprob. The top-k tail is folded with the weight at the tail's whole trainer mass: exact while the two tail masses differ by at most the trust-region threshold.
d9bf505 to
aa93828
Compare

Summary (human-written)
Why
DPPOLoss(#6376) rejects score centering (#6378). Score centering folds the generator's tail (the tokens outside its top-k) into the top-k with one weight, which needs every tail token to share a weight. Under the tail modelq_v = rho * p_vevery tail token has the ratio1 / rho, but DPPO also drops a token oncesign(A) * (p - q) > divergence_threshold, which readspitself. On a tail token that issign(A) * (1 - rho) * p_v.That term grows with
p_v, so the weight at the largestp_va tail token can have decides for every tail token. Under the tail model that isIf
sign(A) * (1 - rho) * p_maxstays within the threshold (0.2), no tail token is dropped under the tail model, every tail token getsmin(1 / rho, max_ratio), and the existing fold is exact for DPPO. With k = 32,min_H q <= 1/32, so crossing needsrho < 0.14withA > 0and a trainer tail mass above 0.2.Example. k = 32, top-k mass 0.999 on both sides (the default recipes' runs show 1.00):
What changed
PolicyGradientLoss.log_token_weight(log_ratio, advantages, trainer_logprobs): the weight may readlog p. DAPO/GRPO, CISPO and IcePop ignore it (del, mechanical).DPPOLoss.log_token_weight:_dropped's rule withq = p / r, elsemin(r, max_ratio)on the clamped ratio. Its__post_init__ban onscore_centeringis removed.ScoreCentering: passes the trainer's top-k logprobs for the head, andlog p_maxfor the tail weight. Docstring andlosses/README.mdstate when DPPO's fold is exact; past the bound the whole tail counts as dropped.rl_dppo_score_centering_qwen3_0_6b_varlenintorchtitan_recipes/tests/rl/(next to the other unverified loss recipes).Alternatives considered
[T, V_local]pass on every step for a case that needs a top-k missing > 20% of the mass.p_maxabove costs a[T, k]min.p_max: crosses the threshold as soon as the tail masses differ by 0.2, though no single tail token moves that far (the test below fails with it).Numerics
Losses other than DPPO: unchanged ops (they ignore the new argument).
DPPO without score centering: unchanged (
token_lossis untouched).DPPO with score centering, end to end:
rl_dppo_score_centering_qwen3_0_6b_varlenvsrl_dppo_qwen3_0_6b_varlen, 10 steps on real Qwen3-0.6B, seed 42, deterministic, lockstep, trainer TP=2 + generator TP=2 (4x GB300), compiled loss region, not batch-invariant. Both train with finite loss and gradients (mean reward 0.482 -> 0.260 vs 0.482 -> 0.255; ten lockstep steps don't compare learning). No sampled token is dropped or truncated, andcoefficient_l1stays below 4e-10: with the weight equal toralmost everywhere,q * w = pand the correction is ~0, as expected. (Run at the commit before themin_H q / rhobound; with top-k mass 1.00 neither bound binds.)DPPO with score centering under stale rollouts (
target_offpolicy_steps=3, mean policy age ~2.9 steps; the same setup as [rl] Score centering: generator top-k logprobs and ScoreCentering for PolicyGradientLoss #6378's table): the trust region drops 0.2-0.4% of tokens andcoefficient_l1is 2.4e-3 to 3.9e-3. So score centering does change DPPO's update there, unlike the lockstep run above. Mean reward over the last 20 of 100 steps, seeds 42/43/44: 0.454 / 0.451 / 0.458 with score centering, 0.455 / 0.437 / 0.421 without. Neither collapsed. That is slightly better and less spread, but too few seeds to claim a gain.Testing
test_score_centering.py:dppojoins the parametrized cases (with a tight trust region, threshold 0.15 andmax_ratio1.5, so the drift tests see dropped and truncated tokens):log_token_weightequals the gradienttoken_lossputs on each token's score, including the drop rule (catches a weight that drifts from_dropped).alpha.test_policy_loss_configs.pybuilds the new recipe.pytest tests/rl/unit_tests/cpu: 913 passed, 5 skippedKnown issues / follow-ups
Stacked on #6380; next: #6385 (top-k from the label logprob). Past the bound the fold treats the whole tail as dropped, an approximation the README documents.