Skip to content

fix(nemo-gym): plumb max_new_tokens into row-level max_output_tokens - #2365

Merged
yuki-97 merged 6 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/fix-async-rollout-max-seq-len
May 11, 2026
Merged

yuki-97 merged 6 commits into
NVIDIA-NeMo:mainfrom
jthomson04:jthomson04/fix-async-rollout-max-seq-len

Conversation

@jthomson04

Copy link
Copy Markdown
Contributor

Summary

  • run_async_nemo_gym_rollout previously asserted max_seq_len is None and discarded generation_config["max_new_tokens"], leaving every row's responses_create_params with whatever max_output_tokens the agent template happened to set (often unset). With no per-request cap, generations could exceed the configured budget and either run away or get killed by vLLM after wasting compute.
  • Drop the assert max_seq_len is None and document why we accept max_seq_len for API parity without translating it into row-level max_tokens (the semantics differ — total sequence length vs. max new tokens).
  • Write generation_config["max_new_tokens"] into each row's responses_create_params["max_output_tokens"], taking min with any existing per-row value so per-agent overrides still win when stricter.
  • Update the four call sites (grpo train, grpo validate, async trajectory collector, run_grpo_nemo_gym.py example) to pass master_config["policy"]["max_total_sequence_length"] instead of None so the rollout parameter actually reflects the configured cap.
  • Update test_run_async_nemo_gym_rollout to verify max_output_tokens gets populated from generation_config["max_new_tokens"].

Test plan

  • tests/unit/experience/test_rollouts.py::test_run_async_nemo_gym_rollout passes (asserts max_output_tokens is set on every row after the rollout).
  • Run a NeMo-Gym GRPO recipe end-to-end and confirm generations respect policy.generation.max_new_tokens (no runaway sequences) and that the call sites no longer trip the removed assertion.

🤖 Generated with Claude Code

@jthomson04
jthomson04 requested review from a team as code owners April 29, 2026 21:27
@copy-pr-bot

copy-pr-bot Bot commented Apr 29, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 1ad93f4

ananthsub
ananthsub previously approved these changes May 7, 2026
@ananthsub ananthsub added the CI:L1 Run doctests, unit tests, and functional tests label May 7, 2026
Comment thread nemo_rl/experience/rollouts.py Resolved
yuki-97
yuki-97 previously approved these changes May 7, 2026
Comment thread nemo_rl/experience/rollouts.py Resolved
@yuki-97 yuki-97 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 May 7, 2026
@yuki-97

yuki-97 commented May 7, 2026

Copy link
Copy Markdown
Contributor

/ok to test 97da8ed

@jthomson04
jthomson04 dismissed stale reviews from yuki-97 and ananthsub via 73a1465 May 7, 2026 22:25
@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-rollout-max-seq-len branch from 73a1465 to fcd79aa Compare May 7, 2026 22:28
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test fcd79aa

@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-rollout-max-seq-len branch from 4566b2e to 646769b Compare May 7, 2026 23:04
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 646769b

yuki-97
yuki-97 previously approved these changes May 8, 2026
@yuki-97
yuki-97 enabled auto-merge (squash) May 8, 2026 03:53
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test 646769b

jthomson04 and others added 4 commits May 9, 2026 11:09
`run_async_nemo_gym_rollout` previously asserted `max_seq_len is None`
and discarded `generation_config["max_new_tokens"]`, leaving every row's
`responses_create_params` with whatever `max_output_tokens` the agent
template happened to set (often unset, leading to runaway generations
that exceeded the configured cap).

Drop the assertion, document why we accept `max_seq_len` for API parity
without translating it (semantics differ from row-level `max_tokens`),
and write `generation_config["max_new_tokens"]` into each row's
`responses_create_params["max_output_tokens"]`, taking the min with any
existing per-row value.

Update the four call sites in grpo / async / nemo-gym example to pass
`master_config["policy"]["max_total_sequence_length"]` instead of `None`
so the rollout parameter actually reflects the configured cap.

Update `test_run_async_nemo_gym_rollout` to verify `max_output_tokens`
gets populated from `generation_config["max_new_tokens"]`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Pre-set one row's max_output_tokens to a looser value than max_new_tokens
to exercise the min() clamp-down branch alongside the existing
no-override branch. Uses max_new_tokens + 1 so the effective generation
cap is unchanged and the rollout's golden token-count assertions still hold.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
- Move the max_seq_len API-parity comment to the top of run_async_nemo_gym_rollout so it is visible on entry (per yuki-97).
- Warn when the policy max_total_sequence_length is greater than the
  generation engine's max_model_len so users notice the mismatch instead
  of silently relying on engine-side truncation (per ananthsub).
- Update test_run_async_nemo_gym_rollout to pass the engine's max_model_len
  for max_seq_len so the assertion still holds without firing the new warning.

Signed-off-by: jthomson04 <[email protected]>
Collapse the multi-line `assert row[...] == max_new_tokens` so
ruff-format leaves the file unchanged on CI.

Signed-off-by: jthomson04 <[email protected]>
@jthomson04
jthomson04 force-pushed the jthomson04/fix-async-rollout-max-seq-len branch from 646769b to aaa1f0e Compare May 9, 2026 18:09
@copy-pr-bot

copy-pr-bot Bot commented May 9, 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.

@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test aaa1f0e

@yuki-97

yuki-97 commented May 11, 2026

Copy link
Copy Markdown
Contributor

hi @jthomson04 , there's a fail test ./tests/functional/grpo_async_gym.sh, could you help to fix it?

The nemo-gym recipe YAMLs previously set
max_new_tokens = max_model_len = max_total_sequence_length. That was fine
while run_async_nemo_gym_rollout dropped max_new_tokens on the floor, but
now that this PR plumbs it into responses_create_params.max_output_tokens,
every vLLM request asks for the entire context as output and there is no
room left for the prompt — vLLM rejects with VLLMValidationError, the
async buffer never fills, and the run hangs.

Set max_new_tokens to a literal 8192 in the two nemo-gym recipes and add
a per-run max_new_tokens=128 override to grpo_async_gym.sh so the
smoke test (max_total_sequence_length=512) still leaves room for prompts.

Signed-off-by: jthomson04 <[email protected]>
…el_len

The warning branch in run_async_nemo_gym_rollout had no coverage in the
PR (codecov/patch flagged it). Add a focused unit test that fakes
policy_generation.cfg, passes max_seq_len > max_model_len to trigger the
warning, and lets the next stop_strings assert fire so the test stays GPU-free.

Signed-off-by: jthomson04 <[email protected]>
@jthomson04

Copy link
Copy Markdown
Contributor Author

/ok to test e00c954

@yuki-97
yuki-97 merged commit e3696a5 into NVIDIA-NeMo:main May 11, 2026
27 checks passed
zswerth pushed a commit to zswerth/RL that referenced this pull request May 12, 2026
…VIDIA-NeMo#2365)

Signed-off-by: jthomson04 <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: zswerth <[email protected]>

This branch was previously deployed

1 inactive deployment
nemo-ci — e00c9545 Deployed May 11, 2026 by copy-pr-bot[bot] via Docs_Tests #11287
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants