Repository navigation
refactor(vllm): share the per-sample rollout pipeline and chat token helpers - #4978
Conversation
…helpers Split generate_async's per-sample work into building the result (request_pipeline.rollout_result: sampled logprobs, router-replay route alignment and its fallback warning) and assembling the output tensors (rollout_output). The rollout token budget and SamplingParams become worker methods (_rollout_max_new_tokens, _rollout_sampling_params). vllm/utils gains off_policy_sampling_error (the chat endpoint's on-policy checks, unchanged) and chat_routed_experts / chat_generation_tokens (the loop bodies of the attach_* response helpers). No behaviour change for native vLLM: the new generate_async wiring tests pass against both the old and the new implementation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
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. |
|
/ok to test e0d3789 |
Restacks onto NVIDIA-NeMo#4954 after NVIDIA-NeMo#4905's split (vLLM refactor NVIDIA-NeMo#4978, Dynamo core NVIDIA-NeMo#4905, NeMo-Gym through Dynamo NVIDIA-NeMo#4979) and the Gym#4817/#5161 rebase. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
#4905 was split at review request: the vLLM refactor is #4978, #4905 is now Dynamo core, and NeMo-Gym through Dynamo is #4979. This PR now stacks on #4979. Gym is re-pinned to Gym#5161's head aa808b7, rebased onto Gym main 5911d628c on top of Gym#4817's b0e681c. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
jthomson04
left a comment
There was a problem hiding this comment.
Self-review with the review team. The refactor preserves behaviour:
- Base and head
generate_asyncgive identical tensors on 53 synthetic vLLM outputs, and bit-identical ones on 8 real vLLM 0.29 rollouts (Qwen3-0.6B). - 1152 chat sampling combinations give the same accept/reject and the same message text.
- Every vLLM 0.29 assumption was checked against the v0.29.0 source.
- The new
generate_asynctests also pass against main's original code. - All 13 new tests run in the non-vLLM step of the L0 vLLM unit lanes.
Worth keeping: the result/output split (rollout_result / rollout_output), the on-policy check becoming a pure function with its own test, and generate_async going from about 290 lines to about 110.
PR description fix (no line to anchor it on). The "Why" says #4905 reuses these seams, but #4905 reuses only request_pipeline and the two _rollout_* methods (_rollout_max_new_tokens, _rollout_sampling_params). off_policy_sampling_error, chat_routed_experts and chat_generation_tokens get their second caller in #4979 (L529, L791, L794, L808, L814). Suggested replacement text:
#4905 serves rollouts from the same engine through Dynamo's frontend and reuses
request_pipelineand the two_rollout_*methods; #4979 serves NeMo Gym's chat calls through it and reusesoff_policy_sampling_error,chat_routed_expertsandchat_generation_tokens.
Inline comments:
- (C1) Move the generate, check and result steps into one worker method that both hosts call, so #4905 stops copying them.
- (C2) Add a route test for the on-policy assert and the
top_k = -1pin; no test reaches either line today. - (C3) Drop
rollout_output'spad_token_id: it never reaches the output. - (C4) Run the nothing-fits test with speculative decoding too, the only case where the
allowed_new_tokens > 0check matters. - (C5) Say in the docstring that, for
top_k=None, None means on-policy only once the caller sendstop_k=-1. - (C6) Assert the exact output keys, so R3 stats keys can't leak into non-R3 rollouts unnoticed.
- (C7) Give the R3 pipeline test the route shape vLLM 0.29 actually produces.
Generated by Claude Code
Address review on this PR: - _serve_rollout runs a rollout's whole sequence (budget, nothing-fits, SamplingParams, generate, prompt check, result), so every host that serves a rollout from this engine calls one method instead of copying the steps. It replaces _rollout_sampling_params. - generate_async asserts a single sample, so it no longer fans out per-sample tasks: it formats the prompt, calls _serve_rollout and yields the output. vLLM still aborts the request on cancellation. - rollout_output drops pad_token_id, whose fill never reached the output. - off_policy_sampling_error documents that vLLM fills unset top_p/top_k from generation_config.json, so callers must pin top_k=-1. - chat_routed_experts drops a dead isinstance check. - Tests: a route test for the on-policy assert and the top_k pin; the budget tests fold into one parametrization that covers a full context with speculative decoding; the wiring test asserts the exact output keys and a missing logprob; the R3 pipeline test uses vLLM 0.29's route shape. Two pipeline tests the wiring tests now cover are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
/ok to test 3928525 |
Brings in NVIDIA-NeMo#4978's review fixes through the stack. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
…engine Brings in #4978's review fixes. The engine's rollout path now calls the worker's _serve_rollout instead of re-typing its steps, and the driver drops rollout_output's removed pad_token_id. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
Resolve nemo_rl/models/generation/vllm/utils.py: keep this branch's chat_generation_tokens and main's attach_sampler_topk_logprobs_to_chat_response_choices (NVIDIA-NeMo#4818). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
…on04/dynamo-native-engine Makes NVIDIA-NeMo#4978's head an ancestor of this branch so it can be this PR's base; the tree is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
/ok to test c2e4ef9 |
Restack on NVIDIA-NeMo#4905 6a02b99 (NeMo RL main 6e68b17, NVIDIA-NeMo#4978 c2e4ef9). The L0 vLLM shard lists keep main's test_score_centering.py and this branch's test_swe1_dynamo_config.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
yuki-97
left a comment
There was a problem hiding this comment.
Merge blockers — please rebase on main; the PR is 11 commits behind and the "Check if PR branch is up to date" job allows at most 10.
Thanks for extracting the shared async vLLM rollout pipeline and chat helpers for reuse by the Dynamo integration.
The before/after comparisons and detailed self-review make the preserved behavior clear; thanks for sharing them.
Scope: Async vLLM rollout and chat-helper refactor, at c2e4ef9
Checked:
- Request behavior — context budgets, speculative lookahead, stop strings and prompt validation retain their previous behavior.
- Output contracts — sampled logprobs, truncation, R3 alignment and chat-choice mapping match the original paths.
- Cancellation — direct awaiting still reaches vLLM's request-abort handler.
- CI execution — all 13 added test cases passed in the current-head vLLM unit job logs.
nit
- Shorten the route-encoding and sampling-profile comments.
- Limit the pipeline docstrings to their actual callers and explain the final output's downstream use.
- Rename
off_policy_sampling_errortocheck_sampling_param, assert inside the helper and update the affected tests.
Generated by Codex
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
- check_sampling_param replaces off_policy_sampling_error and raises ValueError itself, with the same messages in the same order. It raises rather than asserts so a server that answers an off-policy request with a client error can catch it; the native chat handler still fails with a 500, as its assert did. - Shorten the route-encoding and sampling-profile comments to one line. - The pipeline docstrings name their actual callers and what the final RequestOutput is for. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
/ok to test e798c86 |
…on04/dynamo-native-engine Brings in NVIDIA-NeMo#4978's review fixes and its merge of upstream/main 7b3d9e6. - L0 vLLM shard lists: this PR's list plus main's test_chat_template_parity_common.py. - test_grpo.py: the legacy backend=dynamo setup tests this PR removes stay removed, including main's new turn_checkpointing_enabled line in one. - test_outdated_config_checks.py: this PR's Dynamo checks plus main's rollout-recovery checks. - _serve_rollout's docstring names the Dynamo engine module rather than this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
…n04/dynamo-gym Brings in NVIDIA-NeMo#4978's review fixes and upstream/main 7b3d9e6 through NVIDIA-NeMo#4905. - L0 vLLM shard lists: this PR's swe1 config test plus main's test_chat_template_parity_common.py. - test_nemo_gym_utils.py: this PR's Dynamo dialect test next to main's turn-checkpointing tests. - build_nemo_gym_actors/build_nemo_gym_config now require turn_checkpointing_enabled; this PR's two new calls pass False. - The Gym path calls NVIDIA-NeMo#4978's check_sampling_param, which raises ValueError, and still answers an off-policy call with InvalidArgument. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
…on04/dynamo-native-engine Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
/ok to test d67311f |
check_sampling_param raises ValueError since the review rename. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
…on04/dynamo-native-engine Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
/ok to test d15b6f4 |
Resolve utils.py: main's encode_for_wire (NVIDIA-NeMo#4345) moves into chat_routed_experts, which the chat attach loop now calls. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
|
/ok to test 1fe249f |
…on04/dynamo-native-engine Resolve import blocks in nemo_gym.py and routed_experts_codec.py: keep NVIDIA-NeMo#4905's Dynamo imports beside main's (via NVIDIA-NeMo#4978) new ones. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
…n04/dynamo-gym Resolve the nemo_gym.py import block: keep main's NEMO_GYM_* keys (via NVIDIA-NeMo#4978 and NVIDIA-NeMo#4905) beside NVIDIA-NeMo#4979's native_default_chat_template_kwargs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
NVIDIA-NeMo#4978 landed on main as aa06ca0. The conflicts in request_pipeline.py, vllm_worker_async.py and test_vllm_request_pipeline.py keep NVIDIA-NeMo#4905's versions, which already build on NVIDIA-NeMo#4978's head (1fe249f). Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict in vllm_worker_async.py: main (NVIDIA-NeMo#4978) moved the chat route's sampling check into check_sampling_param, which forced top_k=-1. Sampler replay serves the matched profile's top_k, so check_sampling_param now returns that top_k (top_k or val_top_k, -1 when None) and rejects a request top_k that differs from it. The route keeps the branch's min_p, penalty and logit-bias rejections. test_check_sampling_param and the route's rejection test are updated to match. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hayate Iso <[email protected]>
What
This PR refactors the async vLLM worker without changing what it does. It was split out of #4905 at review request so it can merge on its own. Nothing here imports Dynamo or NeMo Gym.
VllmAsyncGenerationWorkerImpl._serve_rollout(new) serves one rollout from this engine:_rollout_max_new_tokens: the context window plus the speculative-decoding lookahead clamp);SamplingParams;llm.generate;generate_asyncasserts a single sample, so it no longer fans out per-sample tasks. It formats the prompt, calls_serve_rolloutand yields the output. vLLM still aborts the request when the caller cancels.nemo_rl/models/generation/vllm/request_pipeline.py(new) separates building the result from assembling the output:rollout_resultbuilds the result: the sampled logprobs, router-replay (R3) route alignment, and the R3 fallback warning. It returns aRolloutResult.rollout_outputassembles the output tensors from that result.nemo_rl/models/generation/vllm/utils.py:off_policy_sampling_errorholds the chat endpoint's on-policy sampling checks. They are unchanged, still asserted, and run in the same order.chat_routed_expertsandchat_generation_tokensare the loop bodies ofattach_routed_experts_to_chat_response_choicesandattach_token_information_to_chat_response_choices.Why
#4905 serves rollouts from the same engine through Dynamo's frontend and reuses
request_pipelineand_serve_rollout. #4979 serves NeMo Gym's chat calls through it and reusesoff_policy_sampling_error,chat_routed_expertsandchat_generation_tokens.Behaviour
Native vLLM behaves the same. The new
generate_asyncand chat-route tests pass against both main's original code and this branch. They cover:top_k=-1pin.There are four small differences, all harmless for real vLLM outputs:
completion.logprobswithhasattr.request_pipelinelogger, without the always-0 sample index.output_idsis built withtorch.cat, so when no new token fits it is a new tensor rather than a view of the input row.rollout_outputtakes nopad_token_id; its fill never reached the output.Tests
test_async_vllm_generate_async_*intest_vllm_generation.py(new): thegenerate_asyncwiring, with the budget cases in one parametrization.test_chat_handler_rejects_off_policy_sampling_and_pins_top_kintest_vllm_generation.py(new).tests/unit/models/generation/test_vllm_request_pipeline.py(new): R3 alignment and stats with vLLM 0.29's route shape, and R3 missing routes.test_off_policy_sampling_errorintest_vllm_utils.py.Stack
This PR → #4905 (Dynamo core) → #4979 (NeMo Gym through Dynamo).
🤖 Generated with Claude Code