Skip to content

perf(vllm): flat logprobs and output-loop yielding for generation actor - #4820

Merged
yuki-97 merged 13 commits into
mainfrom
sniverty/vllm-flat-logprobs-output-loop-yield
Oct 30, 2026
Merged

yuki-97 merged 13 commits into
mainfrom
sniverty/vllm-flat-logprobs-output-loop-yield

Conversation

@snivertynv

@snivertynv snivertynv commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do

Two opt-in settings under policy.generation.vllm_cfg that keep the async vLLM generation actor responsive when it carries a large generation backlog (many requests with logprobs in flight, e.g. async GRPO with a deep staleness lag):

Key Default Effect Requires
flat_logprobs false Requests that ask for logprobs (and not prompt logprobs) store them in vLLM's FlatLogprobs (a few flat lists per request) instead of a dict plus one Logprob object per generated token. Same values; attach_token_information_to_chat_response_choices reads them the same way. async_engine: true, expose_http_server: true
output_loop_yield_budget_ms null (off) output_handler yields to the event loop once per engine step, and the output-socket reader after this many ms of continuous work (20 works well). async_engine: true

Both are validated at VllmGeneration setup and raise if set without their prerequisites, instead of being silently ignored.

#4634 (merged) skips building the OpenAI choice.logprobs objects for captured responses. This PR addresses the two remaining sources of actor stalls under a backlog: the objects vLLM keeps per token for logprobs during generation, and output loops that never yield.

How to enable

policy:
  generation:
    vllm_cfg:
      async_engine: true
      expose_http_server: true
      flat_logprobs: true
      output_loop_yield_budget_ms: 20

or ++policy.generation.vllm_cfg.flat_logprobs=true ++policy.generation.vllm_cfg.output_loop_yield_budget_ms=20.

Why

Under a large backlog the generation actor's event loop stopped serving Ray calls for minutes, so refit calls and their replies queued behind generation output:

  • Full (gen2) GC pauses over the per-token dict + Logprob objects held the GIL for up to ~25 s. With flat storage these disappear.
  • Output loops that never yield: AsyncLLM's socket reader and output_handler run on the actor's event loop; with a backlog they always find their next message waiting, and awaiting an already-completed future doesn't yield, so they held the loop for minutes at a time.

Yielding the reader on every message was tried first: it starved the reader against output_handler's per-step work and moved the backlog into the socket. The budget gives the reader a fair share while bounding how long either loop holds the event loop. The reader tells a waited receive from a waiting message by whether the zmq.asyncio receive future is already done.

Results

Large multi-node async GRPO run (lag 64), same layout and code, one run per arm. All arms serve rollouts through NeMo-Gym via the async engine's exposed HTTP server, so the flat-logprobs path is exercised. These runs used environment-variable versions of the same changes; "lean" = flat logprobs plus skipping choice.logprobs, the part #4634 now does.

Arm Refit time per step Actor event-loop stalls Generated tokens, first 30 min
neither 331 s at step 1, then hung 622 (max 375 s) 2.11 B
#4634 only (no flat, no yield) hung at step 1 179 (max 102 s) by step 1 —
lean + output-loop yield (budget 20 ms) 2.5–44 s, all 6 steps 1 (11 s) 2.70 B

The remaining refit outliers (up to ~44 s) are on the refit reply path through the actor; a follow-up routes refits through a second EngineCore client.

Behaviour and safety

  • Both settings are off by default; nothing changes unless enabled.
  • flat_logprobs is not applied to requests that ask for prompt logprobs: vLLM's clamp_prompt_logprobs edits per-position copies of FlatLogprobs, so -inf prompt logprobs would reach JSON serialization.
  • output_loop_yield_budget_ms raises at engine setup if the installed vLLM lacks the AsyncMPClient internals it patches (checked against the pinned vLLM 0.29.0), and a vLLM-marked canary test fails if a vLLM bump moves the calls it relies on.
  • The output_handler patch is applied once per process on AsyncMPClient; the reader patch is per-instance on that client's output socket, so other ZMQ users are unaffected.

Tests

  • tests/unit/models/generation/test_vllm_patches.py (install_output_loop_yield, which lives in vllm/patches.py): per-step yield, one-time class patch, reader budget (yield after budget on waiting messages, restart after a pending receive), fail-loud on missing internals, budget validation. CPU-only, uses a stand-in for vllm.v1.engine.core_client. Plus a vllm-marked canary against the pinned vLLM and pyzmq.
  • tests/unit/models/generation/test_vllm_flat_logprobs.py (vllm-marked): generate() sets flat_logprobs only when enabled and logprobs, but not prompt logprobs, are requested.
  • tests/unit/models/generation/test_vllm_config.py: setup validation rejects each unsupported combination and accepts the supported ones.
  • Existing _AsyncLLMHTTPClient tests pass the new required keyword.
  • The GRPO, PPO and distillation exemplars and their reference configs document both keys and their prerequisites.

🤖 Generated with Claude Code

…ration actor

Two opt-in vllm_cfg settings that keep the async vLLM generation actor
responsive under a large generation backlog:

* flat_logprobs: requests that ask for logprobs store them in vLLM's
  FlatLogprobs instead of a dict plus one Logprob object per generated token.
  Same values; removes the long full-GC pauses over those objects.
* output_loop_yield_budget_ms: output_handler yields once per engine step and
  the output-socket reader after this many ms of continuous work, so neither
  loop can hold the actor's event loop for minutes. Fails at engine setup if
  the installed vLLM lacks the AsyncMPClient internals it patches.

Both default to off. Builds on #4634, which skips the OpenAI choice.logprobs
objects for captured responses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Sriharsha Niverty <[email protected]>
@copy-pr-bot

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

@snivertynv snivertynv changed the title perf(vllm): flat logprobs and output-loop yielding for the async generation actor perf(vllm): flat logprobs and output-loop yielding for generation actor Oct 20, 2026
@snivertynv snivertynv self-assigned this Oct 20, 2026
@snivertynv snivertynv added the CI:L1 Run doctests, unit tests, and functional tests label Oct 20, 2026
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test a5aaaaa

@snivertynv
snivertynv marked this pull request as ready for review October 21, 2026 08:55
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test d05ab24

@macandro96 macandro96 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 this. The write-up is clear, and the refit result (hung → seconds) is a big win. We checked the mechanism against vLLM 0.29.0 / pyzmq 27.2.0: the per-instance recv_multipart override sticks, the DP clients inherit get_output_async, and FlatLogprobs gives identical values through attach_token_information_to_chat_response_choices and the captured-response bypass.

Inline: a CI gap (the flat_logprobs test never runs), setup-time validation for both knobs, a canary against vLLM drift, an exact signal for the reader budget, and three smaller items.

Upstream — no action needed for this PR. vLLM main (40210d8) still has the reader loop that never yields, output_handler yielding only between chunks, and clamp_prompt_logprobs mutating temporaries under FlatLogprobs. Filing one vLLM issue for these would give the patch a removal path; related upstream work: vllm-project/vllm#57442, #60542, #62446, #31605.

Generated by Claude Code

snivertynv and others added 2 commits October 22, 2026 01:18
* Reader budget: tell a waited receive from a waiting message by the
  zmq.asyncio future's done() instead of a 0.5 ms timing heuristic, which
  misfired when another thread held the GIL.
* flat_logprobs: leave requests that ask for prompt logprobs unflattened.
  vLLM's clamp_prompt_logprobs edits per-position copies of FlatLogprobs, so
  -inf prompt logprobs would reach JSON serialization (HTTP 500).
* Validate both settings at VllmGeneration setup: flat_logprobs requires
  async_engine and expose_http_server; output_loop_yield_budget_ms requires
  async_engine and a positive value. Document the prerequisites.
* Mark the flat_logprobs test vllm so the vLLM shard runs it, and add a
  vllm-marked canary that fails if the pinned vLLM moves the output-loop
  calls the patch relies on.
* Document the ValueError in install_output_loop_yield.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Sriharsha Niverty <[email protected]>
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test ffb77b8

@snivertynv

Copy link
Copy Markdown
Contributor Author

Thanks for this. The write-up is clear, and the refit result (hung → seconds) is a big win. We checked the mechanism against vLLM 0.29.0 / pyzmq 27.2.0: the per-instance recv_multipart override sticks, the DP clients inherit get_output_async, and FlatLogprobs gives identical values through attach_token_information_to_chat_response_choices and the captured-response bypass.

Inline: a CI gap (the flat_logprobs test never runs), setup-time validation for both knobs, a canary against vLLM drift, an exact signal for the reader budget, and three smaller items.

Upstream — no action needed for this PR. vLLM main (40210d8) still has the reader loop that never yields, output_handler yielding only between chunks, and clamp_prompt_logprobs mutating temporaries under FlatLogprobs. Filing one vLLM issue for these would give the patch a removal path; related upstream work: vllm-project/vllm#57442, #60542, #62446, #31605.

Generated by Claude Code

Thanks for the review and the pointers. Agreed that a single vLLM issue covering the three upstream behaviors is the way to retire this patch eventually.

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 16b2235

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 787401b

macandro96 added a commit that referenced this pull request Oct 23, 2026
Port RL #4820 at 787401b onto the working checkpoint stack. Preserve direct route snapshots, completion retention, incremental route caching and guarded cut admission. Keep both options disabled unless explicitly configured, validate supported async HTTP combinations, and log their activation.

Validation: 19 focused CPU tests passed; one installed-vLLM check skipped on the login node. Eight portable-recipe tests passed; Ruff and production syntax checks passed. GPU validation will use the 88-node comparison run.
Signed-off-by: Anish Mahishi <[email protected]>
macandro96
macandro96 previously approved these changes Oct 25, 2026

@macandro96 macandro96 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.

Mostly lgtm! some pending items include updating pr description and adding comments on exemplary configs. Maybe @yfw or @terrykong can take a final pass?

… yield in the exemplar

flat_logprobs requires async_engine and expose_http_server, and does not apply
to requests asking for prompt logprobs; output_loop_yield_budget_ms requires
async_engine. Say so next to both keys in grpo_math_1B.yaml and its reference
config.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Sriharsha Niverty <[email protected]>
@snivertynv

Copy link
Copy Markdown
Contributor Author

Mostly lgtm! some pending items include updating pr description and adding comments on exemplary configs. Maybe @yfw or @terrykong can take a final pass?

All fixes should be in now @macandro96 . Thanks for reviewing.

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 0f08a00

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 2eeb001

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test f386235

@terrykong terrykong added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Oct 29, 2026
@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test e1b5dd7

@yuki-97 yuki-97 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 this perf improvement, it is a big one: under a lag-64 backlog refit goes from hanging at step 1 to completing every step. The PR bounds how long vLLM's output loops can hold the generation actor's event loop and stores logprobs flat, both as opt-in knobs with setup-time validation.

Great to see the baseline vs. patched refit timings from the lag-64 run posted in the description: the effect of the yield reads off clearly.

Scope: flat_logprobs, the output-loop yield patch, config validation, exemplar and tests, at e1b5dd7

Checked:

  • Patched call sites against pinned vLLM 0.29.0 — output_handler awaits get_output_async per step and the reader looks up recv_multipart per message, so both patches take effect
  • DP clients — DPAsyncMPClient / DPLBAsyncMPClient do not override get_output_async, so the class patch covers them
  • flat_logprobs scope — requests asking for prompt logprobs are excluded, so vLLM's -inf clamp cannot reach JSON
  • Reader budget — resets after a real wait via future.done(), so an idle reader never yields extra
  • Misconfiguration — unsupported combinations raise at setup in validate_vllm_async_actor_settings, beside the quantization validator
  • Earlier review threads — all addressed at head, including the two still open (prerequisites now in the exemplar comments, request path now in Results)

nit

  • Shorten the long in-function comments in the flat-logprobs and yield code
  • Add the two new keys to the PPO and distillation exemplars
  • Move the output-loop yield patch into patches.py

Comment thread examples/configs/grpo_math_1B.yaml Resolved
…eys in all exemplars

Address review nits on #4820:
- Move install_output_loop_yield into vllm/patches.py beside the other runtime
  vLLM patches, and its tests into test_vllm_patches.py.
- Shorten in-function comments in generate() and the yield patch.
- Add flat_logprobs and output_loop_yield_budget_ms to the PPO and distillation
  exemplars and their reference configs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Sriharsha Niverty <[email protected]>
@snivertynv

Copy link
Copy Markdown
Contributor Author

Thanks for this perf improvement, it is a big one: under a lag-64 backlog refit goes from hanging at step 1 to completing every step. The PR bounds how long vLLM's output loops can hold the generation actor's event loop and stores logprobs flat, both as opt-in knobs with setup-time validation.

Great to see the baseline vs. patched refit timings from the lag-64 run posted in the description: the effect of the yield reads off clearly.

Scope: flat_logprobs, the output-loop yield patch, config validation, exemplar and tests, at e1b5dd7

Checked:

  • Patched call sites against pinned vLLM 0.29.0 — output_handler awaits get_output_async per step and the reader looks up recv_multipart per message, so both patches take effect
  • DP clients — DPAsyncMPClient / DPLBAsyncMPClient do not override get_output_async, so the class patch covers them
  • flat_logprobs scope — requests asking for prompt logprobs are excluded, so vLLM's -inf clamp cannot reach JSON
  • Reader budget — resets after a real wait via future.done(), so an idle reader never yields extra
  • Misconfiguration — unsupported combinations raise at setup in validate_vllm_async_actor_settings, beside the quantization validator
  • Earlier review threads — all addressed at head, including the two still open (prerequisites now in the exemplar comments, request path now in Results)

nit

  • Shorten the long in-function comments in the flat-logprobs and yield code
  • Add the two new keys to the PPO and distillation exemplars
  • Move the output-loop yield patch into patches.py

Appreciate the review @yuki-97 . Addressed your feedback with the latest commit. Would love to get this in since the perf and refit impact both are quite good.

@snivertynv

Copy link
Copy Markdown
Contributor Author

/ok to test 6e9c9dd

@yuki-97 yuki-97 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.

LGTM, thanks @snivertynv

@yuki-97
yuki-97 enabled auto-merge (squash) October 30, 2026 15:26
@yuki-97
yuki-97 merged commit 1c40201 into main Oct 30, 2026
94 checks passed
@yuki-97
yuki-97 deleted the sniverty/vllm-flat-logprobs-output-loop-yield branch October 30, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants