Skip to content

feat(trtllm): Gym rollout fixes, validation sampling, dummy-weight startup - #4123

Merged
yuki-97 merged 22 commits into
mainfrom
erinh/trtllm-mlperf-mislan
Nov 5, 2026
Merged

yuki-97 merged 22 commits into
mainfrom
erinh/trtllm-mlperf-mislan

Conversation

@hchings

@hchings hchings commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

TRT-LLM generation fixes and features for NeMo-Gym GRPO runs (HTTP-server sampling parity, validation-only sampling, fastokens, dummy-weight startup), plus GRPO validation and Megatron checkpoint fixes found along the way.

Changes

TRT-LLM HTTP server / Gym rollouts

  • Align the HTTP server's sampling params with the direct generate path (top_k, logprobs_simple_format) and use generate_async.
  • Support validation-only sampling (generation.val_temperature / val_top_p) on TRT-LLM: the server accepts either the train or the validation sampling profile and serves the one the request pins; grpo.setup() now allows val sampling overrides for both vLLM and TRT-LLM NeMo-Gym rollouts. val_top_k overrides are rejected.
  • Enable fastokens for the HTTP-server tokenizer, and fail fast if NRL_USE_FASTOKENS=1 but the patch did not take effect (matching any fastokens. shim rather than a private class name).

TRT-LLM engine

  • Start the engine on dummy weights during training, like vLLM: configure_generation_config sets trtllm_cfg.load_format ("dummy" for training, "auto" for eval, always "dummy" for precision=fp8), skipping a full checkpoint read that the first refit overwrites anyway.
  • Stop logging the full placement group from every generation worker.

GRPO

  • validate() now scores exactly min(max_val_samples, len(val_dataset)) prompts. Previously max_val_samples // val_batch_size silently dropped a partial last batch (e.g. 251 prompts in batches of 126 scored only 126). The same applies to validate_sync, and avg_length is weighted by rollouts per batch so a partial batch does not count as a full one.

Megatron

  • Free cached CUDA blocks before torch_dist checkpoint save, so NCCL's save-planning gather doesn't fail with unhandled cuda error on a full device.

Docs / tests

  • The PD-disagg nightly script exports UCX_NET_DEVICES=all so NIXL KV transfer uses the RDMA HCAs; noted in docs/design-docs/pd-disaggregation-rollout.md.

Issues

Usage

policy:
  generation:
    backend: trtllm
    val_temperature: 0.1   # validation-only sampling on the NeMo-Gym path
    val_top_p: 0.95

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • New/updated unit tests: tests/unit/algorithms/test_grpo.py (test_validate_scores_exactly_max_val_samples), tests/unit/models/generation/trtllm/test_trtllm_http_server.py, tests/unit/models/generation/trtllm/test_trtllm_generation.py, tests/unit/models/generation/trtllm/test_trtllm_worker_startup.py (real-engine HTTP server with fastokens), tests/unit/utils/test_fastokens.py, and test_validate_sync_scores_exactly_max_val_samples in test_grpo.py.

🤖 Generated with Claude Code

@hchings hchings self-assigned this Sep 14, 2026
@copy-pr-bot

copy-pr-bot Bot commented Sep 14, 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.

@hchings
hchings force-pushed the erinh/trtllm-mlperf-mislan branch 3 times, most recently from ca59235 to b8e883e Compare October 6, 2026 05:36
@hchings
hchings marked this pull request as ready for review October 6, 2026 05:39
@hchings hchings added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 8, 2026
@hchings
hchings requested review from shuyixiong and yuki-97 October 8, 2026 19:57
@hchings
hchings force-pushed the erinh/trtllm-mlperf-mislan branch 5 times, most recently from d6b6fbc to 741f12b Compare October 8, 2026 22:53
@hchings hchings changed the title feat(trtllm): Rubin build support and rollout fixes feat(trtllm): Gym rollout fixes, validation sampling, editable venv Oct 8, 2026
@hchings
hchings force-pushed the erinh/trtllm-mlperf-mislan branch from 741f12b to 0ef8188 Compare October 9, 2026 06:13
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 9, 2026
Comment thread nemo_rl/utils/venvs.py Resolved
@hchings hchings changed the title feat(trtllm): Gym rollout fixes, validation sampling, editable venv feat(trtllm): Gym rollout fixes, validation sampling, editable venv Oct 9, 2026
@hchings
hchings force-pushed the erinh/trtllm-mlperf-mislan branch 2 times, most recently from 6d2db31 to 7d72619 Compare October 21, 2026 03:26
@hchings
hchings force-pushed the erinh/trtllm-mlperf-mislan branch from 7d72619 to 50a63ca Compare October 30, 2026 05:02
Comment thread ray.sub Resolved
@hchings
hchings force-pushed the erinh/trtllm-mlperf-mislan branch from 50a63ca to 097ac40 Compare October 30, 2026 05:48
@shuyixiong shuyixiong changed the title feat(trtllm): Gym rollout fixes, validation sampling, editable venv feat(trtllm): Gym rollout fixes, validation sampling, dummy-weight startup Oct 30, 2026

@shuyixiong shuyixiong 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 this PR. Validation-only sampling on TRT-LLM, the validate() fix with a test that fails on the old code, the keyword-only server arguments, and the pure _request_matches_profile helper are all good additions.

The main ask is C1: with disaggregation on, the new load_format never reaches the prefill and decode engines, so bf16 loses the dummy-weight startup and precision: fp8 + disaggregation now fails at startup. C2 is next: the new seed variable has no reader at the pinned TensorRT-LLM.

  1. (C1) load_format is set after resolve_role_overrides, so disaggregated engines get "auto"; set it first, move the key out of the per-role knobs, and add a disaggregated test.
  2. (C2) Nothing reads NEMO_RL_TRTLLM_SEED at the pinned TensorRT-LLM; remove it and the torch import.
  3. (C3) No test checks which sampling profile the chat route serves; a route test is included.
  4. (C4) No test shows trtllm + NeMo-Gym now passes the validation-sampling check in setup(); a test is included.
  5. (C5) Move the fastokens check into nemo_rl/utils/fastokens.py and drop _tokenizer_backend_name from the HTTP server.
  6. (C6) Shorten the 8-line sampling comment in the chat handler to two lines.
  7. (C7) Drop the history from the val_sampling_config comment in the worker.
  8. (C8) grpo_sync's validate_sync still drops the partial last validation batch; apply the same fix there (pre-existing).

Other notes:

  • No existing thread needs a reply. The nemo_rl/utils/venvs.py thread is about code that was reverted and can be resolved.
  • CI Lint and unit tests have not run on this PR yet; please trigger them.
  • Could you add the engine startup time with dummy vs real weights from one run? It would show the benefit of the dummy-weight startup.

Generated by Claude Code

Comment thread nemo_rl/models/generation/__init__.py Resolved
Comment thread tests/unit/algorithms/test_grpo.py Resolved
Comment thread nemo_rl/algorithms/grpo.py Resolved
@hchings
hchings force-pushed the erinh/trtllm-mlperf-mislan branch from 96e084e to 0459baf Compare October 30, 2026 21:09
@hchings
hchings requested a review from shuyixiong October 30, 2026 23:43
@hchings

hchings commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0459baf

shuyixiong and others added 13 commits November 3, 2026 19:17
configure_generation_config gave vllm_cfg["load_format"] the value
"auto" if is_eval else "dummy" but left trtllm_cfg alone, so a TRT-LLM
engine read the full checkpoint at startup even though refit_policy_generation
overwrites every weight before the trajectory collector is allowed to issue
its first request. On a 397B engine that read is minutes of startup the run
throws away.

Mirror the vLLM contract: set trtllm_cfg["load_format"] in
configure_generation_config and pass it through to the AsyncLLM constructor.
precision="fp8" stays "dummy" in both modes -- the engine is built with the
quantized layout the BF16 refit populates, and configure_fp8_llm_kwargs
already rejects anything else -- so this changes nothing for FP8.

Evaluation keeps "auto": it has no refit to supply weights.

Signed-off-by: Erin Ho <[email protected]>
The guard pinned the exact private class name
`fastokens._compat._TokenizerShim`. fastokens 0.3.1 renamed it to
`fastokens._ConfiguredTokenizerShim`, so `patch_transformers()` succeeded but
the worker still refused to start:

  RuntimeError: NRL_USE_FASTOKENS=1, but the TRT-LLM HTTP tokenizer backend
  is 'fastokens._ConfiguredTokenizerShim'; expected
  'fastokens._compat._TokenizerShim'

What the check is for is whether the monkey-patch landed at all, so match on
the `fastokens.` module prefix instead of an internal class name that moves
with every release.

Signed-off-by: Erin Ho <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
Signed-off-by: Erin Ho <[email protected]>
Signed-off-by: Erin Ho <[email protected]>
Co-authored-by: Erin Ho <[email protected]>
Co-authored-by: Erin Ho <[email protected]>
…DITABLE)

Remove NRL_TRTLLM_EDITABLE from this PR. This reverts 5a6e571,
8df2eaf and 097ac40: the editable-install hooks in
nemo_rl/utils/venvs.py, tools/build-editable-trtllm.sh, and the
docs/docker.md section describing them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
Signed-off-by: Jeremi Piotrowski <[email protected]>
(cherry picked from commit 34116c2)
Signed-off-by: shuyixiong <[email protected]>
Each TrtllmAsyncGenerationWorker printed pg and pg.bundle_specs at init. The
bundle spec list has one entry per bundle in the placement group, so each
line grows with the job and every worker prints its own copy: on a 256-node
run that is 192 lines of ~67 KB, 12 MB of a 15 MB log. Keep bundle_indices,
which is the part that differs per worker.

(cherry picked from commit 770b644)
Signed-off-by: shuyixiong <[email protected]>
Signed-off-by: Erin Ho <[email protected]>
validate() runs max_val_samples / val_batch_size batches. Flooring that
silently drops a partial last batch (251 prompts in batches of 126 scored
only 126), and the round-up from 02f4007 overshoots the cap whenever the
validation set is larger than max_val_samples (max 200 in batches of 126
scored 252).

Keep the round-up so the partial last batch is scored, and trim the last
batch to the prompts still left under the cap, so exactly
min(max_val_samples, len(val_dataset)) prompts are scored. The trim runs
before repeat_interleave, so a prompt's generations are never split.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
…n sampling changes

- Set load_format before resolve_role_overrides so the prefill and decode
  engines inherit it under disaggregation (bf16 loaded the full checkpoint,
  fp8 failed at startup). It now defaults via setdefault and is a shared
  setting, not a per-role override.
- Drop NEMO_RL_TRTLLM_SEED and the torch import: nothing reads the variable.
- Move the fastokens backend check to nemo_rl.utils.fastokens as
  check_fastokens_applied and move its tests next to the other fastokens tests.
- Add tests for the train/validation sampling profile the chat route serves,
  for accepting TRT-LLM validation sampling on the Gym path, and for the
  disaggregated load_format.
- Round up and trim the last validation batch in grpo_sync.validate_sync, as
  validate() does.
- Shorten two code comments.

Signed-off-by: Erin Ho <[email protected]>

@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 adding TRT-LLM validation sampling and avoiding redundant checkpoint loading during training.

Thanks also for reporting the GB200 sampling-route and real-engine fastokens HTTP checks.

Scope: TRT-LLM Gym sampling and startup, GRPO validation limits, Megatron checkpoint cache release, and launcher environment forwarding, at fd0230e

Checked:

  • Sampling profiles — traced Gym validation parameters through the worker to the HTTP sampling profile selected for generation.
  • Dummy startup — checked the pinned loader contract, prefill/decode inheritance, and initial refit before rollout dispatch.
  • Tokenizer initialization — checked the environment override, locked fastokens backend, and patch-before-construction ordering.
  • Checkpoint lifecycle — cache release follows prior asynchronous-save finalization and CUDA synchronization.

Validation: Static source inspection only; no local project or GPU tests run. Current head checks contain no L0/L1 test results.

Remaining comments are on:

  • Sample-weighted validation response lengths and partial-batch regression coverage.
  • Recipe-specific UCX requirements and the scope of launcher changes.
  • Checkpoint OOM evidence and removal of diagnostic-only logging.

nit

  • Required validation profiles and a single source for weight-loading defaults.
  • Shared validation-sampling documentation.
  • Function-local comment length and PR-description accuracy.

Generated by Codex

Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread nemo_rl/algorithms/grpo.py Resolved
Comment thread nemo_rl/models/generation/__init__.py Resolved
Comment thread nemo_rl/algorithms/grpo_sync.py Resolved
Comment thread ray.sub Resolved
…LM server

- weight validate/validate_sync avg_length by rollouts per batch; add
  validate_sync partial-batch/cap tests and a weighted avg_length assertion
- make val_sampling_config required in the TRT-LLM HTTP server
- read trtllm_cfg.load_format directly in the worker (no second default)
- document val_temperature/val_top_p support for TRT-LLM in GenerationConfig
- keep only gc.collect + empty_cache before checkpoint save
- revert the ray.sub env-forward option; export UCX_NET_DEVICES=all in the
  PD-disagg nightly script and document it
- shorten function-local comments

Signed-off-by: Erin Ho <[email protected]>
@hchings
hchings requested a review from yuki-97 November 5, 2026 00:11
@hchings

hchings commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4db1b83

yuki-97
yuki-97 previously approved these changes Nov 5, 2026
@yuki-97
yuki-97 enabled auto-merge (squash) November 5, 2026 06:43
configure_generation_config now reads generation.trtllm_cfg for the trtllm
backend, so the test config copied from the vLLM one needs that block.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
@shuyixiong

Copy link
Copy Markdown
Contributor

/ok to test 58561ca

@shuyixiong

Copy link
Copy Markdown
Contributor

/ok to test d477124

@yuki-97
yuki-97 merged commit 5e5065b into main Nov 5, 2026
95 checks passed
@yuki-97
yuki-97 deleted the erinh/trtllm-mlperf-mislan branch November 5, 2026 12:51
isomap added a commit to isomap/RL that referenced this pull request Nov 5, 2026
Conflicts:
- grpo.py: keep _validate_val_sampling and accept trtllm as main (NVIDIA-NeMo#4123)
  does. The TRT-LLM server picks the train or validation profile by
  temperature/top_p like the vLLM one, so the val_top_k rule applies to
  both; main's "val_top_k is not supported" check is dropped.
- loss_input.py: keep the replay/non-replay split; pass main's (NVIDIA-NeMo#4973)
  reuse_logits_storage on the non-replay logprob call.
- vllm/config.py: keep resolve_vllm_logprobs_mode and main's
  resolve_vllm_kv_cache_dtype (NVIDIA-NeMo#5028).
- test_model_utils.py: keep both sides' new tests.
- interfaces.py comment and test_setup_accepts_val_sampling_on_gym_path
  updated to the val_top_k rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hayate Iso <[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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants