Repository navigation
fix(single-controller): wire fused linear logprobs into the SC loss - #5514
Merged
Merged
Conversation
With policy.megatron_cfg.use_fused_linear_logprobs=true the Megatron worker reads the flag from its own config and returns [B, S] per-token logprobs instead of vocabulary logits, but SingleController built ClippedPGLossFn without the flag. The training loss then treated the logprobs as logits. Legacy GRPO passes the flag explicitly. - Pass use_fused_linear_logprobs to ClippedPGLossFn in SC setup, using the same condition as legacy GRPO (Megatron enabled and the flag set). - Port legacy GRPO's guards into SC config validation: reject fused linear logprobs with sequence packing and with top-k/top-p training-time filtering. - Add an SC nightly for the qwen3-30ba3b fused-linear-logprobs recipe (3n8g: SC has no colocated vLLM, and one optimizer step per rollout batch, so train_global_batch_size=128). It keeps the legacy nightly's logprob-error and reward assertions and adds the data-plane hash checks. Raise the nightly GPU-hour cap by its 18 hours. Refs #5044 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
yuki-97
reviewed
Dec 2, 2026
yuki-97
left a comment
Contributor
There was a problem hiding this comment.
Thanks for fixing fused linear logprobs on the SingleController. This PR passes the flag to the loss the controller builds and adds the nightly twin of the legacy fused recipe.
Scope: the whole diff, at d230cee
Checked:
- The flag reaches every consumer of the trainer forward on the SingleController (split train path,
StreamingObjectiveLosswrapper, warm-up pass, PPO actor); the prev/reference logprob passes read the worker config.wrapper.py:59-62 - Packing and top-k/top-p were the only fused guards that lived in legacy GRPO setup; the CP,
overlap_param_gather, draft andfp32_lm_headchecks already reach the SingleController through shared policy and Megatron setup code. - The new recipe with the driver's overrides passes
validate_single_controller_config(packing off,top_knull,top_p1.0, 16 x 8 =train_global_batch_size128), and it inherits the legacy fused recipe like the other SingleController twins of legacy nightlies. - The nightly GPU-hour budget rises by exactly this entry's cost.
Remaining comments are on:
- Results of the legacy fused nightly next to the SingleController run in the description.
- Temperature with fused linear logprobs.
nit
- One shared fused helper and guard for legacy GRPO and the SingleController.
- Logprob shape in the
uses_fused_linear_logprobsdocstring.
nemo-rl-review: kind=expert harness=claude-code/2.1.334 model=claude-fable-5-2 effort=medium review-pr-team=v3 reviewed=d230cee
4 of 21 tasks
…re the fused checks Under policy.megatron_cfg.use_fused_linear_logprobs the model output is the gathered per-token logprob, and apply_temperature_scaling divides it in place by policy.generation.temperature. Both trainers then computed log_softmax(z)[y] / T instead of log_softmax(z / T)[y]. Reject a temperature other than 1.0 with the flag on, and document the limit in the GRPO guide. Move uses_fused_linear_logprobs and _validate_fused_linear_logprobs_config to grpo.py, next to _validate_seq_logprob_error_in_loss, and call them from both legacy GRPO setup and SingleController validation. Legacy GRPO now raises ValueError instead of AssertionError for these settings. The score-centering check uses the shared predicate too. Add direct unit tests for both functions, which also cover the legacy path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Resolve the nightly GPU-hour cap conflict: main's #5433 lowered it to 5226, and this branch's SC fused-linear-logprobs nightly adds 18, so the cap is 5244. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Contributor
Author
|
/ok to test 88a07b7 |
yuki-97
approved these changes
Dec 3, 2026
jalbericiola
added a commit
to jalbericiola/NemoRL
that referenced
this pull request
Dec 3, 2026
Main now rejects policy.megatron_cfg.use_fused_linear_logprobs with any sequence packing in validate_single_controller_config (NVIDIA-NeMo#5514): the fused forward rolls labels over the whole packed row. That check runs before validate_shared_prefix_config. The design doc listed the rule of this branch among the settings that only lack a run on a model. Its row moves to the table of rules with a reason. The comment of the rule in nemo_rl/models/policy/shared_prefix.py and the comment in its test follow. No rule and no error text changes. Signed-off-by: Jorge Albericio <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
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 and why
Makes
policy.megatron_cfg.use_fused_linear_logprobswork on the SingleController (SC) path, closes a temperature gap the fused path has in both trainers, and adds an SC nightly. Part of the SC parity tracker #5044 (section 3, "Fused linear logprobs").The SC bug. With the flag on, the Megatron worker reads it from its own config and runs the patched
GPTModel.forward(patch_gpt_model_forward_for_linear_ce_fusion). That forward returns per-token logprobs ([B, S-1]) instead of vocabulary logits. The training loss only treats the output as logprobs when the loss function hasuse_fused_linear_logprobsset (loss_input.py,wrapper.py). Legacy GRPO passes the flag toClippedPGLossFn; SC built it without the flag, so the SC training loss treated the fused logprobs as vocabulary logits.The temperature gap (both trainers).
apply_temperature_scalingdivides the model output in place bypolicy.generation.temperature. Under the flag that output is already the gathered logprob, so both trainers computedlog_softmax(z)[y] / Tinstead oflog_softmax(z / T)[y]. The fused kernel takes no temperature, so this combination is now rejected.Changes
use_fused_linear_logprobstoClippedPGLossFn.uses_fused_linear_logprobs(policy_config)and_validate_fused_linear_logprobs_config(policy_config)live ingrpo.py, next to_validate_seq_logprob_error_in_loss, and both trainers call them. The validator raisesValueErrorbefore any workers start for fused linear logprobs combined with:policy.generation.temperature != 1.0(new, see above).ValueErrorrather thanAssertionErrorfor these settings. The SC score-centering / sampler-replay check uses the shared predicate too.docs/guides/grpo.md: the fused notes list the temperature limit.grpo-qwen3-30ba3b-3n8g-megatron_fused_linear_logprobs-single-controller, inheriting from the legacy fused recipe:train_global_batch_size128 instead of 64: SC requires one optimizer step per rollout batch (16 prompts × 8 generations). Multiple minibatches per step are listed as "not planned" in SingleController parity with legacy GRPO/PPO: remaining features and validation gaps #5044.in_ordersampler with zero lookahead, and checkpointing off, as in the other SC nightlies.Unit tests
tests/unit/single_controller/test_setup.py: SC setup passes the flag to the loss (fails on main); SC validation accepts a supported config, rejects packing, top-k, top-p and a non-1.0 temperature, and skips the checks when Megatron is off.tests/unit/algorithms/test_grpo.py: direct tests of the shared predicate and validator, which also cover the legacy path.Issues
Part of #5044.
Convergence / perf / functionality proof
The new SC nightly and the legacy nightly it is the twin of, each run for 10 steps on 8×H100 nodes (SC on 3 nodes, legacy on 2). The legacy run used this PR's code, so it also exercises legacy GRPO through the shared validator. Both pass all of their nightly assertions.
train/token_mult_prob_error(< 1.1)train/token_mult_prob_errorat step 10 (< 1.1)train/rewardat step 10 (> 0.1)train/rewardover 10 stepsPer-step
train/token_mult_prob_error; the two runs differ by at most 0.0016 at any step:Notes on the comparison:
token_mult_prob_erroris the like-for-like metric: both runs use the same fused kernel and vLLM.train_global_batch_size64), SC takes 1 (128).temperature: 1.0, so the temperature check does not change their behavior. The SC run predates the review commit, which only moves validation code and adds that check.Needs upstream changes
None.
PR commands and CI
CI:Lfast: the default for most PRs. Runs a fast test subset.CI:L1: dependency or container changes (pyproject.toml,uv.lock,Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.CI:docs: docs-only changes. Runs doc tests only./ok to test <full-commit-sha>: start CI for that commit. Post again after each push./nightly-ci test-case=<test>: run NVIDIA's nightly CI for the PR head; eligible teams only./review: automated review comments. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.🤖 Generated with Claude Code