Skip to content

feat(grpo): add full-group std, vLLM per-sample caps, placeholder prompt checks - #5092

Merged
yuki-97 merged 20 commits into
mainfrom
task/grpo-full-group-std-vllm-fixes
Dec 1, 2026
Merged

yuki-97 merged 20 commits into
mainfrom
task/grpo-full-group-std-vllm-fixes

Conversation

@vmendelev

@vmendelev vmendelev commented Nov 5, 2026 •

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

What and why

GRPO training of speech models (#4748) needs three options that are not speech-specific, so this PR adds them to core. All three are opt-in and off by default, so current behavior is unchanged.

  • Full-group std: grpo.adv_estimator.full_group_std: true normalizes GRPO advantages by the sample std (correction=1) of all valid rewards in the group, instead of the per-rollout leave-one-out std. The baseline is unchanged. Constant groups and masked rows get zero advantage. It requires normalize_rewards: true and use_leave_one_out_baseline: true, since without leave-one-out the per-rollout std already covers the whole group. Other estimators reject it, and the default null leaves it off. The advantage estimator applies it on every training path.
  • Per-sample output caps: a data processor can set extra_env_info["max_new_tokens_for_sample"]. On both the legacy and SingleController rollout paths, the sync and async vLLM workers then generate at most min(max_new_tokens, cap) tokens for that sample, still bounded by the remaining context and the speculative-decoding margin. In multi-turn rollouts the cap applies to each turn. Samples without a cap keep max_new_tokens. Dynamo serving and other generation backends raise UnsupportedOutputCap instead of dropping the cap, and the error stops the run rather than ending, retrying or skipping only that sample.
  • Placeholder-aware prompt validation: policy.generation.vllm_cfg.expanded_placeholder_token names a media placeholder that the learner prompt keeps as one token while vLLM expands it into a contiguous run. Rollout prompt validation then accepts exactly that one expansion. When unset, prompts must still be token-identical.
  • Shared vLLM fixes:
    • Generation-only vllm_kwargs.hf_overrides keys are merged with policy.hf_config_overrides instead of being replaced, at every entry point (GRPO, PPO, distillation, single-controller setup). Policy keys win on shared keys.
    • Unquantized refit no longer imports the FP8 module.

Docs: docs/guides/grpo.md gains a "Full-group standard deviation" subsection with a worked example, and a note on per-sample caps next to DatumSpec. The new vllm_cfg key is documented in VllmSpecificArgs and set to null in the base configs, which also say how vllm_kwargs.hf_overrides merges with policy.hf_config_overrides, and docs/guides/dynamo-generation.md lists caps as unsupported.

Usage

grpo:
  adv_estimator:
    name: grpo
    full_group_std: true
policy:
  generation:
    vllm_cfg:
      expanded_placeholder_token: "<|audio|>"
# In a data processor: cap this sample's response length (vLLM backend only).
datum["extra_env_info"]["max_new_tokens_for_sample"] = 256

Issues

Part of the split agreed in #4748: generic pieces go to core, and the Transcribe-specific recipe moves to research/.

Convergence / perf / functionality proof

N/A for convergence and speed: the three features are off by default, and unit tests pin the default behavior. Without opting in, behavior changes only where it was broken: generation-only hf_overrides keys that were silently dropped now reach vLLM.

Functionality is covered by new unit tests:

  • tests/unit/algorithms/test_full_group_std.py
  • tests/unit/experience/test_rollout_output_caps.py
  • TestOutputCaps in tests/unit/experience/test_rollout_generation_failures.py, for SingleController caps and the run-terminal UnsupportedOutputCap
  • test_sync_rollout_forwards_output_caps_to_vllm and test_async_rollout_forwards_output_caps_to_vllm in tests/unit/experience/test_rollouts.py
  • tests/unit/models/generation/test_vllm_output_limits.py, which covers sync caps with and without cap_max_tokens_to_context and the async cap
  • The placeholder tests in tests/unit/models/generation/test_vllm_prompt_validation.py, on both the sync and async workers
  • The hf_overrides merge tests in tests/unit/models/generation/test_vllm_config.py
  • test_vllm_dynamo_rejects_per_sample_output_caps and test_vllm_dynamo_output_cap_rejection_stops_async_rollout in tests/unit/models/generation/test_vllm_generation.py
  • tests/unit/models/generation/test_vllm_unquantized_refit.py

Checks run locally:

  • At 882a48a7e, the current head, which addresses the Nov 28 review and merges main at 02eb4d933: 4705 unit tests across tests/unit/experience, tests/unit/algorithms, tests/unit/single_controller/test_setup.py, the rollout reassembler, the config tests and the vLLM cap, prompt-validation and config tests pass. 6 draft-loss and x_token tests that this PR does not touch fail only because the local environment lacks Megatron. The vllm-marked tests in the touched vLLM test files (211) and the Dynamo tests (11) pass. Pre-commit and ruff pass on the changed files, and pyrefly reports no new errors in them.
  • At 138ed912f, which fixes the two self-review findings and merges main at d2313cca4: 1658 unit tests (all of tests/unit/experience, tests/unit/single_controller/test_setup.py, the rollout reassembler, and the cap and prompt-validation tests) and the Dynamo cap tests pass. Pre-commit and ruff pass on the changed files, and pyrefly reports 0 errors over the whole project.
  • At 0721c31c78, which merges main at da067f1331: pyrefly 1.4.0 over the whole project, ruff check and ruff format --check (0.9.9) on the changed files, and 485 focused unit tests (this PR's tests, test_setup.py, the hf-override handoff tests and the advantage-stage test). All pass.
  • At 7deed809f, before the two latest merges of main: the default unit lane passed (1285 passed, 1 skipped). On vLLM 0.33.0, main's pin, the fast generation tests passed (44) and the GPU vLLM lane had 226 passed and 1 failed. The failure, test_vllm_policy_generation_with_fastokens_enabled, fails while Ray starts its worker in my local environment, before any code from this PR runs.

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.
  • /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

@vmendelev vmendelev added the CI:L1 Run doctests, unit tests, and functional tests label Nov 5, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 5, 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.

@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test 5e9a0f8

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 5, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 5, 2026 12:36
@terrykong terrykong added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Nov 5, 2026
@vmendelev vmendelev changed the title feat(grpo): add full-group std, per-sample vLLM output caps and placeholder-aware prompt validation feat(grpo): add full-group std, vLLM per-sample caps, placeholder prompt checks Nov 10, 2026
@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test f340c3d

@vmendelev vmendelev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self-review before human review, as requested on #4748.

The PR adds three opt-in features and keeps current behavior by default. The full-group std estimator, the per-sample output caps on the sync path and the placeholder-aware prompt check are each covered by focused unit tests. CI lint, semantic-title and DCO checks pass at this head.

  1. (C1) Per-sample max_output_tokens caps are dropped on every async-rollout path, and non-vLLM backends do not raise there.
  2. (C2) full_group_std: true with normalize_rewards: false is accepted but has no useful effect.
  3. (C3) Low priority: unquantized refit still imports the FP8 module in _weight_update_lifecycle.

Scope: this review covers three findings. Four review lanes (RL expert, bug finder, test agent, design reviewer) were stopped before they finished, so the review is not a full pass. The three findings come from their partial notes and repro logs; each was checked against the code at this head and challenged by one devil's-advocate pass. The lanes ran as independent Cursor subagents, not as a Claude Code agent team. None of the three findings affected the research recipe's GPU validation in #4748, which uses the sync rollout path, keeps normalize_rewards: true, and imports FP8 without error.

Generated by Claude (Cursor agent) using the review-pr-team skill

Comment thread nemo_rl/experience/rollouts.py Resolved
@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test c5d1c14

@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test 1e79ee1

@yuekaizhang yuekaizhang 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 — this is a clean split out of #4748. Solid points worth calling out: defaults are pinned by tests, the new validators reject misconfiguration loudly, and output_limits.py as a pure module makes the cap logic testable without an engine.

I also ran the suites on an 8xH100 node against the locked env (vLLM 0.29.0 / torch 2.13): 161 passed in the default lane and 215 passed in the vLLM lane — including test_vllm_unquantized_refit.py, which is vllm-marked and therefore wasn't covered by your local runs, and the three suites listed as "not verified locally" in the PR description (test_vllm_backend.py, test_vllm_refit_loader.py, test_vllm_utils.py). All green.

3 action items as inline comments (hf_overrides sibling call sites; sync/async cap divergence on exhausted context; Dynamo silently dropping caps). A few smaller suggestions I'll leave for a follow-up pass: eager validation of expanded_placeholder_token at _load_model time instead of first generate, zeroing invalid rows via is_trivial_distribution instead of the exact-float std > 0 contract, documenting that the cap is per-turn in multi-turn rollouts, and a couple of test gaps (notably: the [1] entry in the invalid-caps parametrize only passes via the length-mismatch branch — cap=1 is never actually tested as valid).

Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread nemo_rl/experience/rollouts.py Resolved
…holder-aware prompt validation

- adv_estimator.full_group_std normalizes GRPO advantages by the sample std of
  all valid rewards in the group (default off); applied in grpo and grpo_sync.
- extra_env_info["max_output_tokens"] caps one sample's response length in the
  sync and async vLLM workers, composed with the context and speculative limits;
  other backends raise.
- vllm_cfg.expanded_placeholder_token lets rollout prompt validation accept a
  single declared media-placeholder expansion.
- Generation-only vllm_kwargs.hf_overrides are merged with policy overrides
  instead of being replaced; unquantized refit no longer imports FP8; the
  mm_device_do_normalize default is only set when vLLM supports it.

Signed-off-by: Valentin Mendelev <[email protected]>
Async rollouts built each turn without extra_env_info, so max_output_tokens caps never reached generation and non-vLLM backends never raised. Pass the sample metadata into the turn and check the backend once per batch, where the error cannot be swallowed by the per-turn handler.

Signed-off-by: Valentin Mendelev <[email protected]>
Without reward normalization the full-group std is never applied, so reject the combination instead of accepting a no-op.

Signed-off-by: Valentin Mendelev <[email protected]>
_weight_update_lifecycle imported the FP8 module on every standard refit. Import it only when the model has a quant_config, and cover the lifecycle in the unquantized refit test.

Signed-off-by: Valentin Mendelev <[email protected]>
@vmendelev
vmendelev force-pushed the task/grpo-full-group-std-vllm-fixes branch from 1e79ee1 to 7deed80 Compare November 16, 2026 16:47
@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test 7deed80

@vmendelev

Copy link
Copy Markdown
Contributor Author

@yuekaizhang thanks for the review and the H100 run. I rebased the PR onto main, which is now on vLLM 0.33, and replied in the three threads. From the smaller suggestions:

  • The [1] case is now an explicit length-mismatch test, plus a test that a cap of 1 is valid (1db4350).
  • grpo.md says the cap applies to each turn in multi-turn rollouts (7deed80).

I left load-time expanded_placeholder_token validation and the is_trivial_distribution zeroing for the follow-up pass, as you suggested.

@github-actions github-actions Bot added the CI:L1 Run doctests, unit tests, and functional tests label Nov 23, 2026
@github-actions

Copy link
Copy Markdown

CI label: CI:Lfast, set automatically (default for code and main CI changes).

  • Removed CI:L1 added by yuekaizhang: only repo maintainers can change the CI label or skip CI.
    If this label is wrong, ask a maintainer to set the right one.

main renamed VllmGeneration.dynamo_frontend_url to the dynamo_frontend_urls tuple (#5115), so the test no longer routed through Dynamo and failed on the missing async_engine key.

Signed-off-by: Valentin Mendelev <[email protected]>
@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test 97e439a

@github-actions github-actions Bot added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Nov 23, 2026
yuekaizhang and others added 3 commits November 25, 2026 23:06
The Dynamo frontend and non-vLLM backends reject per-sample
max_output_tokens caps, but the native multi-turn turn handler caught the
ValueError and returned an empty, zero-reward rollout. Raise
UnsupportedOutputCap (a ValueError) at both rejections and re-raise it
past the per-turn catch, with a regression test through
_run_multi_turn_rollout_async.

Signed-off-by: Valentin Mendelev <[email protected]>
test_output_limits.py and test_rollout_prompt_validation.py matched no
unit-test shard: the vLLM base run selects test_vllm*.py, the Models
shard ignores generation/, and the tests carry no backend marker.
Contents unchanged.

Signed-off-by: Valentin Mendelev <[email protected]>

@vmendelev vmendelev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The pure cap helper and shared HF override merger keep these changes testable and consistent across entry points.

  1. (C4) Async multi-turn rollouts swallow driver-side cap rejection and return empty responses.
  2. (C5) Unit CI skips 30 new regression cases.

Four collaborating agents plus the lead covered seven review roles. Repository pre-commit checks and 569 focused/base unit tests passed locally. Fresh real-engine vLLM/refit tests were not run; the linked research training results use an older stack.

nemo-rl-review: kind=self harness=codex/0.159.2 model=gpt-6.1-sol effort=medium review-pr-team=v3 reviewed=6834488

Comment thread nemo_rl/experience/rollouts.py Resolved
@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test 9161821

…std-vllm-fixes

Signed-off-by: Valentin Mendelev <[email protected]>

# Conflicts:
#	tests/unit/single_controller/test_setup.py
@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test 138ed91

yuekaizhang
yuekaizhang previously approved these changes Nov 26, 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.

Merge blockers — please rebase on main; the PR is 15 commits behind and the "Check if PR branch is up to date" job allows at most 10.

Thanks for moving the generic pieces of #4748 into core: a full-group std option for GRPO, per-sample output caps for vLLM rollouts and placeholder-aware prompt validation, each off by default.

Thanks also for the two self-review rounds done before this pass.

Scope: the whole diff, at 138ed91

Checked:

  • Full-group std math — groups with zero or one valid row never reach the new block, and the worked example in grpo.md recomputes to the stated numbers.
  • validate_rollout_prompt — it accepts exactly one run of the declared placeholder and rejects every other difference.
  • Cap plumbing on the legacy paths — caps stay with their rows through sharding, and a rejected cap cancels the sibling rollout tasks without leaving anything held.
  • Shared vLLM fixes — all four setup paths go through merge_vllm_hf_overrides, and the quant_config is None guards take the path an unquantized model already took.
  • Earlier review threads — all eight asks hold at this head, and the new and renamed test files pass in the head's CI lanes.

Remaining comments are on:

  • Per-sample caps on SingleController rollouts.
  • full_group_std together with use_leave_one_out_baseline: false.
  • full_group_std arguments in the legacy trainers that nothing reads.
  • Test coverage of caps on the sync path.
  • The vLLM version check around mm_device_do_normalize.

nit

  • Hard-wrapped paragraphs in grpo.md.
  • expanded_placeholder_token in the base configs.
  • Test file placement.
  • An outdated comment in rollouts.py.
  • A note in the base configs on how vllm_kwargs.hf_overrides is merged.
  • The name of the per-sample cap key.
  • A duplicated cap validation in the async worker.

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

Comment thread nemo_rl/experience/rollouts.py Resolved
Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread docs/guides/grpo.md Resolved
Comment thread nemo_rl/experience/rollouts.py Resolved
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026
- Apply per-sample output caps on SingleController rollouts, and stop the
  run on an unsupported cap instead of retrying or skipping the sample.
- Rename the per-sample cap key to max_new_tokens_for_sample.
- Reject adv_estimator.full_group_std unless use_leave_one_out_baseline is
  true (default null), and drop the unused full_group_std trainer arguments.
- Validate caps once inside per_request_output_limits.
- Restore the unconditional mm_device_do_normalize default for vLLM 0.33.
- Add expanded_placeholder_token and the hf_overrides merge comment to the
  base configs.
- Cover sync-path caps, and move the placeholder and hf_overrides tests next
  to the modules they test.

Signed-off-by: Valentin Mendelev <[email protected]>
@vmendelev

Copy link
Copy Markdown
Contributor Author

/ok to test 882a48a

@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 Nov 30, 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 resolving the comments from the previous review.

Scope: fix commits 29d930a through 882a48a, checked against the open threads from the previous review, plus a scan of the changed files for new issues.

Checked:

  • SingleController caps — the cap is read from the sample's current extra_env_info on every turn and reaches the async vLLM worker; Megatron, SGLang and Dynamo raise UnsupportedOutputCap, which stops the run without a retry or a skip. rollout_manager.py:760
  • full_group_std — null by default and rejected when set with use_leave_one_out_baseline: false; no shipped config that turns leave-one-out off resolves to a set value. advantage_estimator.py:93
  • Moved tests — the placeholder and hf_overrides tests pass in the vLLM unit shards at 882a48a, and the worker test now also runs the async worker with expanded_placeholder_token set. test_vllm_prompt_validation.py:174
  • Merge of main — it did not touch the cap, estimator or hf_overrides code paths.

LGTM — no remaining findings from this re-review.

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

@yuki-97
yuki-97 merged commit 3a276d5 into main Dec 1, 2026
129 of 152 checks passed
@yuki-97
yuki-97 deleted the task/grpo-full-group-std-vllm-fixes branch December 1, 2026 05:32
mxinO added a commit that referenced this pull request Dec 1, 2026
Resolve conflicts with #5092:
- grpo.py, distillation.py: build vLLM hf_overrides with main's
  merge_vllm_hf_overrides (a new dict, so real quant can still add
  quantization_config without touching the policy's overrides); distillation
  keeps it before the real-quant policy is built.
- vllm_backend.py: skip the FP8 reload conversion for real-quant weights or
  when vLLM has no quant_config.
- test_vllm_backend.py: give the fake-quant FP8 reload test a quant_config, as
  main's FP8 reload tests now do.

Signed-off-by: Meng Xin <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Dec 2, 2026
NVIDIA-NeMo#5092 added merge_vllm_hf_overrides and called it at the same four entry
points (GRPO, PPO, distillation, SingleController setup) with a shallow
merge where the policy value wins on a shared key. Keep main's name,
signature and call sites, and give it this PR's reviewed behaviour:
nested sub-configs merge key by key, and a leaf set to different values
on both sides raises at setup.

Drop merge_policy_hf_overrides and move its tests into
test_vllm_config.py next to main's. Main's policy-wins tests (helper and
SingleController) now use non-conflicting keys, and the base and
reference config comments describe the error instead of "policy wins".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pa8JdzpuUd2BVbxJ8Anoba
Signed-off-by: Shubhankar Tripathy <[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) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants