Repository navigation
perf(vllm): flat logprobs and output-loop yielding for generation actor - #4820
Conversation
…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]>
|
/ok to test a5aaaaa |
|
/ok to test d05ab24 |
macandro96
left a comment
There was a problem hiding this comment.
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
* 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]>
|
/ok to test ffb77b8 |
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. |
|
/ok to test 16b2235 |
|
/ok to test 787401b |
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
left a comment
There was a problem hiding this comment.
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]>
All fixes should be in now @macandro96 . Thanks for reviewing. |
|
/ok to test 0f08a00 |
|
/ok to test 2eeb001 |
|
/ok to test f386235 |
|
/ok to test e1b5dd7 |
yuki-97
left a comment
There was a problem hiding this comment.
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_handlerawaitsget_output_asyncper step and the reader looks uprecv_multipartper message, so both patches take effect - DP clients —
DPAsyncMPClient/DPLBAsyncMPClientdo not overrideget_output_async, so the class patch covers them flat_logprobsscope — requests asking for prompt logprobs are excluded, so vLLM's-infclamp 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
…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]>
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. |
|
/ok to test 6e9c9dd |
yuki-97
left a comment
There was a problem hiding this comment.
LGTM, thanks @snivertynv
What does this PR do
Two opt-in settings under
policy.generation.vllm_cfgthat 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):flat_logprobsfalseFlatLogprobs(a few flat lists per request) instead of a dict plus oneLogprobobject per generated token. Same values;attach_token_information_to_chat_response_choicesreads them the same way.async_engine: true,expose_http_server: trueoutput_loop_yield_budget_msnull(off)output_handleryields 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: trueBoth are validated at
VllmGenerationsetup and raise if set without their prerequisites, instead of being silently ignored.#4634 (merged) skips building the OpenAI
choice.logprobsobjects 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
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:
dict+Logprobobjects held the GIL for up to ~25 s. With flat storage these disappear.output_handlerrun 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 thezmq.asyncioreceive 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.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
flat_logprobsis not applied to requests that ask for prompt logprobs: vLLM'sclamp_prompt_logprobsedits per-position copies ofFlatLogprobs, so-infprompt logprobs would reach JSON serialization.output_loop_yield_budget_msraises at engine setup if the installed vLLM lacks theAsyncMPClientinternals 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.output_handlerpatch is applied once per process onAsyncMPClient; 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 invllm/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 forvllm.v1.engine.core_client. Plus avllm-marked canary against the pinned vLLM and pyzmq.tests/unit/models/generation/test_vllm_flat_logprobs.py(vllm-marked):generate()setsflat_logprobsonly 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._AsyncLLMHTTPClienttests pass the new required keyword.🤖 Generated with Claude Code