Repository navigation
perf(vllm): optimize native HTTP request processing - #3892
Open
jthomson04 wants to merge 12 commits into
Open
jthomson04 wants to merge 12 commits into
jthomson04 wants to merge 12 commits into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
Author
|
/ok to test 0d4404d |
jthomson04
force-pushed
the
perf/native-vllm-http-path
branch
from
August 31, 2026 17:29
0d4404d to
dc2ed1c
Compare
Contributor
Author
|
/ok to test dc2ed1c |
|
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
force-pushed
the
perf/native-vllm-http-path
branch
from
September 8, 2026 17:15
dc2ed1c to
f118f06
Compare
Contributor
Author
|
/ok to test f118f06 |
jthomson04
force-pushed
the
perf/native-vllm-http-path
branch
from
October 12, 2026 17:25
f118f06 to
c14cedc
Compare
Contributor
Author
|
/ok to test c14cedc |
Contributor
Author
|
/ok to test a416788 |
Signed-off-by: jthomson04 <[email protected]>
Pin 3rdparty/Gym-workspace/Gym to 9691c00178df (NVIDIA-NeMo/Gym#2836, two commits on Gym main 75bb53e6d4). That PR adds the opt-in VLLMModelConfig.derive_prefix_token_ids_from_messages flag, which sends the newest assistant turn's exact prompt + generation tokens as required_prefix_token_ids. Relocked with uv 0.11.28, the version CI installs. Every lock change comes from Gym's own pyproject: aiohttp>=3.14.4 (sglang keeps 3.14.3, so aiohttp forks), anyio>=4.15.1, PyJWT>=2.15.1, jinja2, jsonschema, and the dropped mlflow/mlflow-skinny dependencies. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
nemo_rl.models.generation.vllm.vllm_worker_async imports orjson at module top, and nemo_rl.models.generation.vllm imports that module, so every import of nemo_rl.models.generation needs orjson in the base venv. orjson was only a constraint, never a requirement. Under the previous base, nothing in the base venv pulled it in, so the earlier CI run of this PR failed test collection in nearly every L0 unit job with "ModuleNotFoundError: No module named 'orjson'". On current main it arrives only transitively through swanlab 0.10.0, which would break again if swanlab dropped it. Declare it directly with the existing CVE floor. Relocking also lets uv resolve a single aiohttp (3.14.5) instead of the 3.14.3/3.14.5 fork from the previous commit. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's test_vllm_generation_selects_worker_extension pins the exact RayWorkerBuilder kwargs, and this PR adds use_fastokens to the async builder call. Pass use_fastokens=True and expect it in the kwargs, so the test also checks that VllmGeneration forwards the flag to async actors. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
vLLM 0.29's ChatCompletionResponse.prompt_logprobs is list[dict[int, Logprob] | None]. JSONResponse (json.dumps) writes int keys as strings, but orjson.dumps raises JSONEncodeError on them, so a request that sets prompt_logprobs would turn into a 500 on the orjson path. Pass OPT_NON_STR_KEYS to match json.dumps. On a 20k-token response payload it costs 0.4 us per call (103.9 us vs 104.3 us). Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
NVIDIA-NeMo/Gym#2836 makes Gym's message-derived required_prefix_token_ids opt-in through VLLMModelConfig.derive_prefix_token_ids_from_messages (default false). NeMo-RL's native vLLM HTTP server implements that field, so setup_nemo_gym_config now turns the flag on in the env.nemo_gym policy_model overlay when the generation backend is vllm. Dynamo is left to its own PR, and megatron is unchanged. - An explicit derive_prefix_token_ids_from_messages in the overlay wins. - The flag stays off when the overlay sets supply_prefix_token_ids, which owns the same field and which Gym rejects alongside it. - A sharded job without a policy_model overlay gets the flag through common_overrides. A new top-level overlay would have no shard owner and fail the shard plan. - Token capture turns off return_token_id_information on the actor, and Gym rejects derivation without it, so the actor now turns the flag off there too. External staging supplies the prefix from the ledger. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a Gym request has no required_prefix_token_ids, the native server scanned back for any message carrying prompt_token_ids. If the newest assistant message had no tokens (it was injected, edited, or regenerated), the scan used an older turn's tokens, which are no longer a prefix of the rendered prompt. NVIDIA-NeMo/Gym#2836 fixed the same bug in Gym's derivation. Match Gym's rule: look only at the newest assistant message, and send no prefix when it has no token information. The rule lives in _message_prefix_token_ids so it can be tested without the vLLM request classes. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only GRPO passed policy.tokenizer.use_fastokens to VllmGeneration, so the single-controller, distillation and PPO paths silently ignored it for the async vLLM HTTP tokenizer. Pass it at every construction site and make it a required keyword-only argument so a new caller cannot drop it again. Eval and the research template forward their tokenizer config; the refit verifier passes False because its inline config has no such key and it runs the sync engine. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Type the message-copy, orjson request and orjson response helpers, with _parse_orjson_request generic over the pydantic request class it returns. The message-copy docstring said vLLM normalizes the copied containers in place, which is not what vLLM 0.29 does: it renders from conversation dicts it builds itself, and its only in-place write to request messages is the idempotent parse of tool_calls[].function.arguments. Say that instead. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move the shard-aware lookup of the Gym policy model's vllm_model overlay into _gym_policy_model_overlay, byte-identical to the copy that NVIDIA-NeMo#3856 and NVIDIA-NeMo#3763 add, so the three PRs merge onto one helper. _enable_gym_prefix_derivation now only decides the flag. The helper treats a null overlay level as empty and rejects a non-mapping one with a ValueError. Before, an unsharded policy_model: null (or a null nested level) failed with an AttributeError. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dynamo case asserted that setup_nemo_gym_config leaves env.nemo_gym untouched. The Dynamo setup in NVIDIA-NeMo#3856 and NVIDIA-NeMo#3763 writes its own policy model overlay there, and NVIDIA-NeMo#3763 sets derive_prefix_token_ids_from_messages for Dynamo too, so neither that assertion nor a narrower one on the flag would survive those PRs. Pin only megatron, whose Gym overlay nothing touches. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
GRPO's init_vllm reads policy.tokenizer.use_fastokens since this PR started forwarding it, and this test's mock policy config had no tokenizer block, so its two non-error cases failed with KeyError: 'tokenizer'. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
jthomson04
force-pushed
the
perf/native-vllm-http-path
branch
from
October 13, 2026 16:43
a416788 to
2318cba
Compare
Contributor
Author
|
/ok to test 2318cba |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
policy.tokenizer.use_fastokenssetting to native async vLLM actors, and apply Fastokens before vLLM creates its tokenizer and HTTP renderer.tool_callslists.orjson, and serialize non-streaming success and error responses with it. Pydantic validation and streaming are unchanged.OPT_NON_STR_KEYS, so int-keyed dicts such asprompt_logprobsserialize as they did withjson.dumps.orjsonas a direct dependency. It was only a constraint, which broke L0 test collection on the previous CI run.derive_prefix_token_ids_from_messagesis set, sosetup_nemo_gym_configturns that flag on for the native vLLM backend.This targets
maindirectly and does not depend on NeMo-RL #3761.Gym dependency
3rdparty/Gym-workspace/Gymis pinned to9691c00178df341833428ae002f8a66699f85019, the head of NVIDIA-NeMo/Gym#2836 (two commits on Gymmain75bb53e6d4). The previous pin was17abf2dd. Theuv.lockchanges come from Gym's own pyproject. Before merge, the pin must move to the Gymmaincommit that contains #2836.How NeMo-RL sets
derive_prefix_token_ids_from_messages:env.nemo_gympolicy_modeloverlay, for thevllmbackend only. Dynamo is handled in refactor(dynamo): move native token response handling to Gym #3763.setdefault, so an explicit value in the recipe wins.supply_prefix_token_ids. That option owns the same request field, and Gym rejects the two together.policy_modeloverlay, it's set throughcommon_overrides, so every shard gets it without an unclaimed overlay.return_token_id_information. Gym rejects derivation without token information, and external staging supplies the prefix from the ledger.End-to-end result (vLLM 0.26, measured before the rebase)
These numbers come from the original branch on vLLM 0.26, before it was rebased onto
mainwith vLLM 0.29.0. They have not been re-measured on 0.29.Matched 48-GPU Nano V3.5 native vLLM 0.26 runs used:
Generated work differed by 6.18%, so the raw rollout-wall result is only directional. The token-normalized result and per-call metrics account for that difference.
model-call timeis client-observed request time, not vLLM engine-only execution time.The optimized native result also closely matched the retained optimized Dynamo aggregate result:
3.1943versus3.1986seconds per call, and77.26versus77.16generated tokens per model-call second.vLLM 0.29.0 check
The optimization mirrors vLLM's chat preprocessing, so it was re-checked against v0.29.0:
OnlineRenderer.preprocess_chathas the same signature. Its only new branch reads prompt ids fromkv_transfer_params, which NeMo-RL does not send.tool_calls[].function.argumentsin place. 0.29 now turns malformed JSON into{}instead of raising. The rewrite is idempotent, so rendering the prefix from the shallow copy gives the same result as a deep copy (checked on CPU with 0.29.0).extra="allow") and needs no validation context.VLLM_USE_FASTOKENShook is unchanged, so the early Fastokens patch still covers the config-only setting.Validation
After the rebase, CPU only:
311 passed:test_vllm_generation.py: the PR's tests, the newest-assistant fallback tests, int-key serialization, and main's HTTP 400 handler tests adapted to the raw-request route.test_nemo_gym.py(including the newsetup_nemo_gym_configflag tests),test_nemo_gym_utils.py,test_nemo_gym_shards.py,test_vllm_chat_template_wiring.pyandtest_fastokens.py.98 passedwith--nemo-gym-only:test_nemo_gym_token_capture.py(with a new token-capture spinup test),test_captured_media.py,test_nemo_gym.py,test_nemo_gym_utils.py.44 passedwith--vllm-only:test_vllm_import_targets.pyagainst vLLM 0.29.0.10 passed: the newvllm_modeltests from perf(vllm): derive required prefix token IDs in Gym Gym#2836 at the pinned SHA.test_vllm_http_serverandtest_nemo_gym_sanityare left to CI.Before the rebase, on vLLM 0.26:
/tokenizerecovery, no prefix fallback, and no token-ID or log-probability mismatch.Scope
setup_nemo_gym_configsets the Gym flag.orjsonbecomes a direct dependency (it was already in the lock).🤖 Generated with Claude Code