Skip to content

fix(nemo-gym): clamp max_new_tokens to prompt + output <= max_model_len - #2514

Merged
terrykong merged 3 commits into
mainfrom
yukih/gym-max-tokens
May 29, 2026
Merged

terrykong merged 3 commits into
mainfrom
yukih/gym-max-tokens

Conversation

@yuki-97

@yuki-97 yuki-97 commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Changes

  • vllm_worker_async.py: add _set_max_tokens / _clamp_max_tokens helpers; apply clamping in _preprocess_chat for both the normal path and the prefix-replacement path.
  • rollouts.py: always write generation_config["max_new_tokens"] into responses_create_params["max_output_tokens"] (remove the is not None guard since it's always not None).
  • Revert config/test changes from fix(nemo-gym): plumb max_new_tokens into row-level max_output_tokens #2365: grpo_nanov3.yaml, grpo_workplace_assistant_nemotron_nano_v2_9b.yaml, tests/functional/grpo_async_gym.sh.

Test plan

  • tests/functional/grpo_async_gym.sh passes without overriding max_new_tokens.
  • Behavior is consistent with pre-2365.

cc @binhu-nv

@yuki-97
yuki-97 requested review from a team as code owners May 17, 2026 13:07
@copy-pr-bot

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

@yuki-97 yuki-97 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label May 17, 2026
@yuki-97

yuki-97 commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 81c371f

seonjinn added a commit that referenced this pull request May 20, 2026
Drops PR #2280 selective recompute overrides (structurally infeasible at
TP=4 EP=8 PP=8 on Qwen3-235B per job 11941263 OOM finding: selective scope
strictly < full uniform N=1 memory savings).

Isolates PR #2514 (max_tokens clamp) effect vs HybridEP+to60 baseline 11891376
(median 413.95s/step). Target: cut exposed_gen long-tail from clamp logic in
vllm_worker_async + rollouts.py active set.

Signed-off-by: seonjinn <[email protected]>
seonjinn added a commit that referenced this pull request May 20, 2026
Scale EP 8 to 32 to reduce per-GPU expert activation memory ~4x, enabling
selective recompute [core_attn,moe_act] to fit at expert FC2 forward (job
11941263 OOMd by 226 MiB at EP=8 PP=8).

Megatron constraint: EP * ETP = world_train / PP. With cluster.num_nodes=40,
inference=8 -> train=32 nodes -> 256 train GPUs. PP=8 -> EP_max=32 (ETP=1).

Trade: 4x training nodes vs current 16-node baseline (8 train + 8 inf).
Per-job cost rises 2.5x but unlocks selective recompute scope that the 8-train
budget structurally cannot fit.

Signed-off-by: seonjinn <[email protected]>
seonjinn added a commit that referenced this pull request May 20, 2026
A/B with submit_hybridep_pr2514_timeout60.sh to isolate Gym PR #2514
max_tokens clamp effect on H100 long-tail. No HybridEP, no PR #2280.
Both variants share branch sj/super-v3-perf-patch+pr2280+pr2514 so PR #2514
NeMo-RL patch (vllm_worker_async.py + rollouts.py) applies automatically.
20 steps, timeout60, 16n x 8 H100.

Signed-off-by: seonjinn <[email protected]>
yuki-97 added 2 commits May 27, 2026 05:53
…e_length"

This reverts commit 90973ba.

Signed-off-by: Yuki Huang <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
@yuki-97
yuki-97 force-pushed the yukih/gym-max-tokens branch from 81c371f to 49437fd Compare May 27, 2026 13:03
@yuki-97

yuki-97 commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 49437fd

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: PR #2514 — fix(nemo-gym): clamp max_new_tokens to prompt + output <= max_model_len

Clean, well-structured fix that reverts the hardcoded max_new_tokens from #2365 and replaces it with proper clamping logic. The approach matches vLLM's native async behavior (allowed_new_tokens). YAML config changes are consistent with the established ${policy.max_total_sequence_length} pattern used across all other GRPO configs.

Summary:

  • Clamping logic in _set_max_tokens / _clamp_max_tokens is correct
  • The is not None guard removal in rollouts.py is safe (max_new_tokens is a required int in GenerationConfig)
  • Both the normal path and prefix-replacement path correctly clamp after prompt tokenization
  • One minor suggestion below regarding the or operator for extracting max tokens

Generated by Claude Code

Signed-off-by: Yuki Huang <[email protected]>
@yuki-97

yuki-97 commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2affac8

@terrykong
terrykong merged commit 9b39c07 into main May 29, 2026
36 of 37 checks passed
@terrykong
terrykong deleted the yukih/gym-max-tokens branch May 29, 2026 05:04
yuki-97 added a commit that referenced this pull request Jun 1, 2026
Signed-off-by: Yuki Huang <[email protected]>

This branch was previously deployed

2 inactive deployments
public — 2affac82 Deployed May 28, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #477
nemo-ci — 2affac82 Deployed May 28, 2026 by copy-pr-bot[bot] via fast_L1_Functional_Tests_GPU #11751
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.

2 participants