Repository navigation
perf(vllm): derive required prefix token IDs in Gym - #2836
Draft
jthomson04 wants to merge 2 commits into
Draft
jthomson04 wants to merge 2 commits into
jthomson04 wants to merge 2 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. |
jthomson04
marked this pull request as ready for review
August 31, 2026 17:20
This was referenced Sep 1, 2026
jthomson04
force-pushed
the
perf/native-vllm-prefix-pinned
branch
from
September 8, 2026 17:15
1691e89 to
0ebcb5b
Compare
Signed-off-by: jthomson04 <[email protected]>
…newest turn Gate required_prefix_token_ids derivation behind a new derive_prefix_token_ids_from_messages flag (default false). Stock vLLM ignores the field, but strict frontends such as Dynamo reject unknown request fields, and the field is also forwarded to /tokenize. Keep the flag apart from supply_prefix_token_ids, which owns the field when enabled, and never put the token array in an external-staging body. Derive only from the newest assistant message. If it has no token bundle, send no prefix instead of falling back to an older turn's tokens, which may no longer be a prefix of the prompt. Signed-off-by: jthomson04 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
jthomson04
force-pushed
the
perf/native-vllm-prefix-pinned
branch
from
October 12, 2026 16:34
0ebcb5b to
9691c00
Compare
jthomson04
added a commit
to jthomson04/RL
that referenced
this pull request
Oct 12, 2026
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]>
jthomson04
added a commit
to jthomson04/RL
that referenced
this pull request
Oct 12, 2026
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]>
jthomson04
added a commit
to jthomson04/RL
that referenced
this pull request
Oct 12, 2026
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]>
jthomson04
added a commit
to jthomson04/RL
that referenced
this pull request
Oct 13, 2026
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]>
jthomson04
added a commit
to jthomson04/RL
that referenced
this pull request
Oct 13, 2026
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]>
jthomson04
added a commit
to jthomson04/RL
that referenced
this pull request
Oct 13, 2026
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]>
This was referenced Oct 22, 2026
yaoyu-33
marked this pull request as draft
November 18, 2026 02:16
Contributor
|
We’re doing some cleanup of the open PR list. This PR has had no activity for over a month, so I’ve moved it back to draft. If this change is still needed, please resolve any merge conflicts and mark the PR ready for review again when it’s ready to merge. Thanks! |
This branch was previously 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
derive_prefix_token_ids_from_messagesflag (defaultfalse) to the vLLM model config.prompt_token_ids + generation_token_idsasrequired_prefix_token_idsbefore forwarding a native vLLM request.This is the Gym side of a native NeMo-RL vLLM request-path optimization. It does not change stored session messages or response token metadata.
Linked NeMo-RL PR: NVIDIA-NeMo/RL#3892. #1784 stacks on this PR.
Why message-derived prefixes alongside
supply_prefix_token_idsreturn_token_id_information), so no ledger lookup is needed.Rules
Unsupported parameter(s). So the field is only sent when the backend splices the prefix. NeMo-RL's vLLM server and Dynamo token wrapper do.return_token_id_information=true. It rejects the flag together withsupply_prefix_token_ids(that mechanism owns the field when enabled) or withuse_completions_api=true.prefix_requested. Prefix-supply verification is unchanged.Tests
main;responses_api_models/vllm_model/tests/gives 418 passed./tokenizeover HTTP;pre-commitpasses on the changed range.Validation
Before the rebase, the combined NeMo-RL and Gym change passed a real Nano V3.5 TP4 smoke with first-turn and multi-turn requests. The full 48-GPU native vLLM 0.26 workload completed four optimizer steps with 144 trajectories per step and no prefix fallback.