Skip to content

fix(single-controller): wire fused linear logprobs into the SC loss - #5514

Merged
yuki-97 merged 3 commits into
mainfrom
amahishi/sc-fused-linear-logprobs
Dec 3, 2026
Merged

yuki-97 merged 3 commits into
mainfrom
amahishi/sc-fused-linear-logprobs

Conversation

@macandro96

@macandro96 macandro96 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Makes policy.megatron_cfg.use_fused_linear_logprobs work 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 has use_fused_linear_logprobs set (loss_input.py, wrapper.py). Legacy GRPO passes the flag to ClippedPGLossFn; 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_scaling divides the model output in place by policy.generation.temperature. Under the flag that output is already the gathered logprob, so both trainers computed log_softmax(z)[y] / T instead of log_softmax(z / T)[y]. The fused kernel takes no temperature, so this combination is now rejected.

Changes

  • SC setup passes use_fused_linear_logprobs to ClippedPGLossFn.
  • uses_fused_linear_logprobs(policy_config) and _validate_fused_linear_logprobs_config(policy_config) live in grpo.py, next to _validate_seq_logprob_error_in_loss, and both trainers call them. The validator raises ValueError before any workers start for fused linear logprobs combined with:
    • sequence packing: the fused forward rolls labels across the whole packed row;
    • top-k/top-p training-time filtering: the fused path gathers logprobs from unfiltered logits;
    • policy.generation.temperature != 1.0 (new, see above).
  • Legacy GRPO now calls the shared validator instead of its inline asserts, so it raises ValueError rather than AssertionError for 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.
  • New nightly grpo-qwen3-30ba3b-3n8g-megatron_fused_linear_logprobs-single-controller, inheriting from the legacy fused recipe:
    • 3 nodes instead of 2: SC has no colocated vLLM, so generation gets its own node; training keeps the legacy recipe's 2 nodes and TP2/EP8.
    • train_global_batch_size 128 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.
    • Synchronous semantics via the in_order sampler with zero lookahead, and checkpointing off, as in the other SC nightlies.
    • Same assertions as the legacy nightly, plus the data-plane hash checks the SC nightlies use.
  • Nightly GPU-hour cap raised by this nightly's 18 GPU-hours (3 nodes × 8 GPUs × 45 min).

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.

Check (nightly threshold) Legacy (2n8g) SingleController (3n8g)
median train/token_mult_prob_error (< 1.1) 1.0216 1.0216
train/token_mult_prob_error at step 10 (< 1.1) 1.0213 1.0209
train/reward at step 10 (> 0.1) 0.523 0.484
median train/reward over 10 steps 0.497 0.492
data-plane hash mismatches (SC only) n/a 0 (384 rows checked)
steady-state step time ~59 s ~54 s

Per-step train/token_mult_prob_error; the two runs differ by at most 0.0016 at any step:

Step 1 2 3 4 5 6 7 8 9 10
Legacy 1.0213 1.0234 1.0197 1.0216 1.0215 1.0221 1.0212 1.0232 1.0220 1.0213
SC 1.0212 1.0218 1.0195 1.0211 1.0217 1.0222 1.0216 1.0232 1.0216 1.0209

Notes on the comparison:

  • token_mult_prob_error is the like-for-like metric: both runs use the same fused kernel and vLLM.
  • Both runs use seed 42 and see the same prompt batches, so rewards follow the same path. Later rewards are not strictly comparable: legacy takes 2 optimizer steps per rollout batch (train_global_batch_size 64), SC takes 1 (128).
  • Step time reflects placement, not the trainer: SC gives vLLM a dedicated node, while legacy shares 16 GPUs between generation and training.
  • Both runs use 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 label, exactly one:
    • 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. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

🤖 Generated with Claude Code

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]>
@copy-pr-bot

copy-pr-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Dec 2, 2026
@macandro96
macandro96 requested a review from yuki-97 December 2, 2026 00:23
@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:high Large or cross-cutting change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) labels Dec 2, 2026

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, StreamingObjectiveLoss wrapper, 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 and fp32_lm_head checks 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_k null, top_p 1.0, 16 x 8 = train_global_batch_size 128), 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_logprobs docstring.

nemo-rl-review: kind=expert harness=claude-code/2.1.334 model=claude-fable-5-2 effort=medium review-pr-team=v3 reviewed=d230cee

Comment thread tests/test_suites/nightly.txt Resolved
macandro96 and others added 2 commits December 2, 2026 09:15
…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]>
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 88a07b7

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) label Dec 2, 2026
@macandro96
macandro96 requested a review from yuki-97 December 2, 2026 21:19
@yuki-97
yuki-97 merged commit a92ea90 into main Dec 3, 2026
93 of 99 checks passed
@yuki-97
yuki-97 deleted the amahishi/sc-fused-linear-logprobs branch December 3, 2026 09:37
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) complexity:high Large or cross-cutting change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants