Skip to content

feat(vllm-model): forward gym session id as backend conversation id - #3582

Merged
ananthsub merged 3 commits into
NVIDIA-NeMo:mainfrom
shuyixiong:shuyix/conversation_affinity
Sep 29, 2026
Merged

ananthsub merged 3 commits into
NVIDIA-NeMo:mainfrom
shuyixiong:shuyix/conversation_affinity

Conversation

@shuyixiong

@shuyixiong shuyixiong commented Sep 21, 2026 •

Copy link
Copy Markdown

What does this PR do?

Forward the Gym rollout session id to the vLLM backend as conversation_params.conversation_id,
so a disaggregated serving setup can pin every turn of a conversation to the ADP rank holding its
KV-cache prefix (conversation/rank affinity).

Validation

  • Added test_chat_completions_forwards_session_id_as_conversation_id in
    responses_api_models/vllm_model/tests/test_app.py, asserting conversation_params is
    forwarded from the Gym session id.
  • Not yet run locally (dev sandbox has no uv/venv). To validate:
    gym env test --resources-server vllm_model or
    pytest responses_api_models/vllm_model/tests/test_app.py -k conversation_id.
  • pre-commit run --files responses_api_models/vllm_model/**/* not yet run.

Rollouts

N/A — this only changes an outbound request field/header on the model server; no live
disaggregated-backend rollout has been run against it yet.

Compatibility and benchmark impact

Additive/backward-compatible: only sets conversation_params when a Gym session id is present
and no such field was already forwarded (see known limitation above). No benchmark results
affected.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

Expose the Gym rollout session as the vLLM backend's conversation_params.conversation_id
so a disaggregated serving setup can pin every turn of a conversation to the ADP rank
holding its KV-cache prefix (conversation/rank affinity).

Source: gitlab-master.nvidia.com/dl/mlperf/optimized qwen35_397b_grpo_trtllm patch
patches/gym/conversation-affinity.patch

Signed-off-by: shuyixiong <[email protected]>
Add coverage for the conversation-affinity change in the prior commit:
asserts conversation_params.conversation_id is set from the Gym session id.

Signed-off-by: shuyixiong <[email protected]>
@copy-pr-bot

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

@shuyixiong shuyixiong changed the title Shuyix/conversation affinity feat(vllm-model): forward gym session id as backend conversation id Sep 21, 2026
@shuyixiong
shuyixiong marked this pull request as ready for review September 22, 2026 03:47
@yaoyu-33 yaoyu-33 added area:model Model servers, inference providers, and model adapters complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Sep 22, 2026
shuyixiong added a commit to NVIDIA-NeMo/RL that referenced this pull request Sep 22, 2026
trtllm_http_server reads a conversation id that nothing populates today. Gym
is the only component that knows the rollout identity and no released Gym
sends it -- conversation_params appears nowhere in the tree, including upstream
main. It arrives with NVIDIA-NeMo/Gym#3582 ("forward gym session id as backend
conversation id"), still open, after which the Gym submodule pin has to be
bumped for this branch to see an id at all.

Until then a turn lands on an effectively random attention-DP rank and the
context engine re-prefills most of its history: 17-26% of turns find their
prefix on the serving rank versus 96-97% once the id flows, measured at
2P-DEP8 / conc 512. Nothing fails, so the note also says not to treat such a
run as a disaggregation baseline.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Sep 23, 2026
@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test 2f9f0bd

Comment thread responses_api_models/vllm_model/app.py Outdated
# as the backend's canonical conversation id so a disaggregated server can
# pin every turn of a conversation to the ADP rank holding its prefix.
_session_id = request.session.get(SESSION_ID_KEY)
if _session_id and not body_dict.get("conversation_params"):

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.

Could we make this opt-in? Gym's session middleware assigns a session ID to every request, so this currently adds the TensorRT-LLM-specific conversation_params extension to every vllm_model chat request. It is not part of the OpenAI Chat Completions schema, and strict OpenAI-compatible backends may reject it.

For example, add a disabled-by-default config field:

# VLLMModelConfig
forward_session_id_as_conversation_id: bool = False

Then gate the injection while preserving explicitly configured conversation_params:

if self.config.forward_session_id_as_conversation_id:
    session_id = request.session.get(SESSION_ID_KEY)
    if session_id and not body_dict.get("conversation_params"):
        body_dict["conversation_params"] = {
            "conversation_id": str(session_id)
        }

NeMo RL TRT-LLM deployments can enable it in their Gym model configuration:

policy_model:
  responses_api_models:
    vllm_model:
      forward_session_id_as_conversation_id: true

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 59ad82d

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Sep 23, 2026
@github-actions github-actions Bot added the sla:author-overdue Author response is over the one-business-day SLA label Sep 24, 2026
…nfig

conversation_params is a TensorRT-LLM extension outside the OpenAI Chat
Completions schema, and Gym's session middleware assigns a session id to
every request, so the previous unconditional injection sent a non-standard
field on every vllm_model chat request. Strict OpenAI-compatible backends
reject it.

Add VLLMModelConfig.forward_session_id_as_conversation_id (default False)
and gate the injection on it. Deployments that route on conversation/rank
affinity opt in via their Gym model config. When enabled, the session id is
authoritative and replaces any conversation_params merged in from
extra_body, matching the config-decides-it precedent of sampling_overrides.

Cover both paths in the existing test via parametrize: enabled forwards the
session id, disabled sends no conversation_params at all.

Addresses review feedback on NVIDIA-NeMo#3582.

Signed-off-by: shuyixiong <[email protected]>
@github-actions github-actions Bot removed the sla:author-overdue Author response is over the one-business-day SLA label Sep 28, 2026
@shuyixiong

Copy link
Copy Markdown
Author

/ok to test 59ad82d

@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test 59ad82d

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/36573935254

Merged via the queue into NVIDIA-NeMo:main with commit 9d01102 Sep 29, 2026
40 checks passed
shuyixiong added a commit to NVIDIA-NeMo/RL that referenced this pull request Oct 9, 2026
trtllm_http_server reads a conversation id that nothing populates today. Gym
is the only component that knows the rollout identity and no released Gym
sends it -- conversation_params appears nowhere in the tree, including upstream
main. It arrives with NVIDIA-NeMo/Gym#3582 ("forward gym session id as backend
conversation id"), still open, after which the Gym submodule pin has to be
bumped for this branch to see an id at all.

Until then a turn lands on an effectively random attention-DP rank and the
context engine re-prefills most of its history: 17-26% of turns find their
prefix on the serving rank versus 96-97% once the id flows, measured at
2P-DEP8 / conc 512. Nothing fails, so the note also says not to treat such a
run as a disaggregation baseline.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
shuyixiong added a commit to NVIDIA-NeMo/RL that referenced this pull request Oct 9, 2026
trtllm_http_server reads a conversation id that nothing populates today. Gym
is the only component that knows the rollout identity and no released Gym
sends it -- conversation_params appears nowhere in the tree, including upstream
main. It arrives with NVIDIA-NeMo/Gym#3582 ("forward gym session id as backend
conversation id"), still open, after which the Gym submodule pin has to be
bumped for this branch to see an id at all.

Until then a turn lands on an effectively random attention-DP rank and the
context engine re-prefills most of its history: 17-26% of turns find their
prefix on the serving rank versus 96-97% once the id flows, measured at
2P-DEP8 / conc 512. Nothing fails, so the note also says not to treat such a
run as a disaggregation baseline.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
shuyixiong added a commit to NVIDIA-NeMo/RL that referenced this pull request Oct 12, 2026
trtllm_http_server reads a conversation id that nothing populates today. Gym
is the only component that knows the rollout identity and no released Gym
sends it -- conversation_params appears nowhere in the tree, including upstream
main. It arrives with NVIDIA-NeMo/Gym#3582 ("forward gym session id as backend
conversation id"), still open, after which the Gym submodule pin has to be
bumped for this branch to see an id at all.

Until then a turn lands on an effectively random attention-DP rank and the
context engine re-prefills most of its history: 17-26% of turns find their
prefix on the serving rank versus 96-97% once the id flows, measured at
2P-DEP8 / conc 512. Nothing fails, so the note also says not to treat such a
run as a disaggregation baseline.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: shuyixiong <[email protected]>
jthomson04 added a commit to jthomson04/RL that referenced this pull request Oct 12, 2026
Replace the unmerged Gym session_id_header fork with Gym main's
forward_session_id_as_conversation_id (NVIDIA-NeMo/Gym#3582).

- Pin Gym to 75bb53e6d494437d616019040f22a9df7dcacd26 and relock.
- For the Dynamo backend, setup_nemo_gym_config enables
  forward_session_id_as_conversation_id on policy_model's vllm_model.
- The Dynamo token wrapper reads conversation_params.conversation_id,
  sends it as X-Dynamo-Session-ID, and strips conversation_params from
  the forwarded body, which Dynamo's frontend rejects as unsupported.
- Malformed conversation_params return 400. The incoming
  X-Dynamo-Session-ID header is no longer read.
- Build the wrapper's FastAPI app in _build_app so the handler can be
  tested without binding a port.

Signed-off-by: jthomson04 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
shuyixiong added a commit to NVIDIA-NeMo/RL that referenced this pull request Oct 13, 2026
trtllm_http_server reads a conversation id that nothing populates today. Gym
is the only component that knows the rollout identity and no released Gym
sends it -- conversation_params appears nowhere in the tree, including upstream
main. It arrives with NVIDIA-NeMo/Gym#3582 ("forward gym session id as backend
conversation id"), still open, after which the Gym submodule pin has to be
bumped for this branch to see an id at all.

Until then a turn lands on an effectively random attention-DP rank and the
context engine re-prefills most of its history: 17-26% of turns find their
prefix on the serving rank versus 96-97% once the id flows, measured at
2P-DEP8 / conc 512. Nothing fails, so the note also says not to treat such a
run as a disaggregation baseline.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: shuyixiong <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 59ad82d1 Deployed Sep 29, 2026 by copy-pr-bot[bot] via release / finalize / notify #3821
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters complexity:low Localized change in one scope with a small, straightforward review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants