Skip to content

fix(token-capture): preserve explicit vLLM top logprobs requests - #4930

Merged
guyueh1 merged 3 commits into
NVIDIA-NeMo:mainfrom
guyueh1:codex/capture-http-top-logprobs
Oct 25, 2026
Merged

guyueh1 merged 3 commits into
NVIDIA-NeMo:mainfrom
guyueh1:codex/capture-http-top-logprobs

Conversation

@guyueh1

@guyueh1 guyueh1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Captured vLLM requests currently overwrite an explicit top_logprobs=K with zero after sampling overrides are applied. The capture handler now leaves that field unchanged. Final model request preprocessing normalizes missing/null counts to zero when logprobs are enabled, after request overrides and capture controls, while preserving explicit counts. With logprobs disabled, a missing/null count remains omitted. Ordinary enabled-logprobs requests now send an explicit zero instead of relying on vLLM's default.

This lets NeMo-RL request the same K over HTTP that vLLM collects, stage the arrays inside the worker, and strip them before HTTP response serialization. This is a companion dependency of NVIDIA-NeMo/RL#4818. No separate issue is needed for this narrowly scoped request-contract fix. Megatron capture behavior is unchanged. The serving worker must implement staging/stripping for auxiliary top-k arrays; this change does not itself implement that storage contract.

Validation:

  • 44 capture-handler tests pass, including leaving explicit/null counts unchanged, plus existing response stripping and failure handling.
  • 32 model-server logprob tests pass, including 18 cases checking counts from requests, extra_body, and sampling overrides with capture on and off, plus existing null-logprob and token-capture regressions.
  • pre-commit run --all-files passes; the guardwords hook reports its private catalog unavailable and skips its scan.
  • A real vLLM rollout has not run on this macOS host. This remains draft pending paired RL integration and rollout validation.

Preserves the worker-staging-before-acknowledgement contract introduced in #2823 and the null-logprob safety behavior from #1612. Based on the Gym revision pinned by the companion RL branch.

@copy-pr-bot

copy-pr-bot Bot commented Oct 22, 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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:model Model servers, inference providers, and model adapters bug Something isn't working labels Oct 22, 2026
@guyueh1
guyueh1 marked this pull request as ready for review October 22, 2026 20:51
@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test 1051d4d

@github-actions

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP

LGTM — no reliability concerns.

Reviewed all four changed files and traced request preparation through HTTP forwarding and capture-response cleanup. The vLLM capture handler preserves explicit counts, and final preprocessing normalizes missing/null counts after overrides and capture controls. Legacy token-echo capture and Megatron retain their existing zero-count behavior.

Validation was static only; I did not execute tests or the paired real-vLLM staging/stripping rollout.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@ananthsub ananthsub 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 the fix! removing the forced top_logprobs=0 from the vLLM capture handler lets the count from sampling_overrides survive, and the single normalization at the end of request preparation covers the null case for both capture and ordinary requests.

What I checked:

  • vLLM 0.29.0 (the version Gym pins, spot-checked on 0.30.0): a null count with logprobs on means no logprobs, and an omitted count defaults to 0, so sending an explicit 0 is equivalent. A count above 0 still requires logprobs=true, which the normalization never violates.
  • NeMo RL worker (NVIDIA-NeMo/RL#4818): the count K reaches the worker through sampling_overrides, and the worker requires logprobs=true and top_logprobs == K on the resolved request. That is exactly what the old overwrite broke. The worker also pops the top-k arrays before serialization and checks max_logprobs >= K at setup.
  • Tests: the new cases pass on the PR head, and the null-count cases fail on the previous code.

i've added some small inline comments added for defense in depth, but these are not blocking

@@ -339,7 +339,6 @@ def _prepare_admitted_request(
request_payload[NG_CAPTURE_FIELD] = admission.model_dump(mode="json")
request_payload.update(
logprobs=True,

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.

The new sampler_topk_token_ids and sampler_topk_logprobs message fields are not in the list that _strip_capture_transport_fields removes (TOKEN_FIELDS plus the Megatron transport fields). The companion NeMo RL worker pops them before serialization, so nothing leaks today. Consider adding both names to the strip as defense in depth, since a leaked tensor costs 8*T*K bytes per row on the agent hop.

@@ -339,7 +339,6 @@ def _prepare_admitted_request(
request_payload[NG_CAPTURE_FIELD] = admission.model_dump(mode="json")
request_payload.update(
logprobs=True,

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.

With top_logprobs=0 removed here, this handler no longer guarantees a logprob count on its own. The Megatron handler still sets it at line 374, while the vLLM path now relies on the final normalization in vllm_model. That works because only vllm_model builds this handler, but a sentence in the VLLMWorkerCaptureHandler docstring would record the dependency for the next caller.

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.

else:
body_dict = self._apply_prefix_supply(body_dict)

# Normalize after all request overrides and capture controls. vLLM treats

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.

Checked against vLLM 0.29.0: a null count with logprobs on resolves to no logprobs (chat_completion/protocol.py:724), and an omitted count defaults to 0, so normalizing to an explicit 0 is correct. One thing to be aware of: 0.29 added logprob_token_ids, and when a request sets it vLLM ignores top_logprobs entirely. Nothing in Gym or NeMo RL sets it today, but it would bypass the worker's top_logprobs == K check if a harness ever forwarded it.

assert "ng_capture" not in payload
assert payload["logprobs"] is True
assert payload["top_logprobs"] == 0
if metadata_field is None:

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.

metadata_field is None is standing in for "this is the vLLM backend" here. Consider parametrizing on the backend by name so the intent is explicit and the branch does not silently flip if the metadata field changes.

ananthsub
ananthsub previously approved these changes Oct 22, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the blocked Work cannot move forward until an external dependency is cleared label Oct 23, 2026
@guyueh1

guyueh1 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bbf3cff

@guyueh1
guyueh1 requested a review from ananthsub October 23, 2026 16:04
@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test bbf3cff

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 23, 2026 18:18
@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/40244245557

@guyueh1
guyueh1 removed this pull request from the merge queue due to a manual request Oct 25, 2026
@guyueh1
guyueh1 added this pull request to the merge queue Oct 25, 2026
@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/40244331503

Merged via the queue into NVIDIA-NeMo:main with commit d8f4db4 Oct 25, 2026
53 of 56 checks passed
@guyueh1
guyueh1 deleted the codex/capture-http-top-logprobs branch October 25, 2026 23:48

This branch was previously deployed

1 inactive deployment
public — bbf3cff4 Deployed Oct 23, 2026 by copy-pr-bot[bot] via release / finalize / notify #6906
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 blocked Work cannot move forward until an external dependency is cleared bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants