Repository navigation
[rl] Turn the vLLM session KV holder on by default - #5902
felipemello1 wants to merge 6 commits into
Conversation
|
Reply from claude: @claude review |
|
Claude finished @felipemello1's task in 3m 1s —— View job Request changes: turning the holder on by default ships the eviction policy that #5477 measured as slower than no holder under KV pressure, and there's no holder-on result yet. See the review. |
There was a problem hiding this comment.
Verdict: Request changes -- this turns on, for every vLLM generator, an eviction policy that open PR #5477 measured as slower than no holder under KV pressure, and there is still no holder-on vs holder-off result.
What this PR does. VLLMEngine.Config.session_kv_holder now defaults to VLLMSessionKVHolder.Config() instead of None. The holder can't run with reset_kv_cache_on_model_state_dict_load=True, so the 7 batch-invariant alphabet_sort configs now set session_kv_holder=None. Four error messages now say how to turn the holder off. The config edits are mechanical, and I checked that no other in-repo config sets reset-KV.
Example.
Multi-turn recipe, KV pool too small for all sessions, no session_kv_holder override
before: holder off. Between turns, a session's blocks sit in vLLM's free queue
and other requests can take them.
after: holder on. Idle sessions keep their blocks. When the pool runs short,
_evict_until_free releases only sessions with no running request.
Running sessions' GDN state blocks stay pinned, and vLLM preempts
running requests instead (#5477: 187 vs 49 preemptions, 15% slower).
Batch-invariant recipe: must now also set session_kv_holder=None, or the
engine build raises.
Must fix
- PR description: the "Summary (human-written)" section is empty. Also, the only measured result is holder-off in both arms (92.8% vs 79.0% hit rate with different KV budgets), and "holder on" is pending. That shows a smaller cache loses hits. It doesn't show the holder wins them back, or that it wins on throughput. This PR changes the performance and memory of the main RL generator path, so it needs the on/off throughput number before it lands.
torchtitan/rl/generator/vllm/engine.py:112-- the default ships the eviction policy that #5477 measured at 9-15% slower than no holder under KV pressure. Land #5477 first (or fold it in), then measure (inline comment).
Should consider
torchtitan/rl/rollout/types.py:98:GenerateFnstill documentsrouting_session_id=Noneas "no affinity", andcontroller.py:553andactors/monarch/router.py:41passNonethrough. MeanwhileEngineRequest.routing_session_idandGenerator.generateare typedstr. With the holder on by default, everyNonerequest shares one holder key. Each one's prefill drops the previous hold, so those requests get no protection. A group that mixesNoneand string sessions also makessorted(released)inVLLMSessionKVHolder.releaseraiseTypeErrorinside the engine loop. No in-repo caller passesNone, so the smallest fix is to makerouting_session_id: strrequired along theGenerateFn-> router path. That removes the case instead of handling it.
Details
- Gate: the problem is real (between-turn blocks can be taken), and the layer is right (vLLM engine config). The default, though, depends on #5477's eviction change, which isn't on
mainyet:session_kv_holder.py:153still skips running sessions. - Golden numerics: the only RL loss golden (
rl_grpo_cuda.txt,rl_grpo_qwen3_0_6b_varlen_batch_invariant) runs batch-invariant with the holder now explicitly off, so it is unaffected. Non-batch-invariant runs will see different prefix hits, so their numerics differ from before. There is no golden for those, which is expected. generator.py:200: the vLLM hint in the generic batch-invariant error is fine.Generatoralready defaults toVLLMEngine.Config.
Not verified: holder behavior on GPT-OSS (sliding window), DeepSeek V3 (MLA), and generator DP=2. The RL CI (ciflow/rl) will exercise these first.
| session_kv_holder: VLLMSessionKVHolder.Config | None = field( | ||
| default_factory=VLLMSessionKVHolder.Config | ||
| ) |
There was a problem hiding this comment.
This makes the current eviction policy the default, and that policy has a measured regression. On main, VLLMSessionKVHolder._evict_until_free (session_kv_holder.py:153) never releases the hold of a session whose request is running. Your open #5477 measured the cost: when a multi-turn run outgrows GPU KV, the holder runs 9-15% slower than no holder (233.7 s vs 204.1 s, 187 vs 49 preemptions at 310 blocks). The cause is that the GDN prompt-end state blocks stay pinned and vLLM preempts running requests instead.
With this default, every multi-turn recipe that hits KV pressure (Terminal-Bench at gpu_memory_limit=0.33 is exactly that case) gets the slow path. Please land #5477 first, or fold it in. Then flip the default with a holder-on vs holder-off comparison of throughput, not only prefix hit rate, on that policy.
Under memory pressure _evict_until_free released idle sessions and skipped sessions whose request runs. Once that request decodes, the hold alone keeps its prompt-end GDN state (and possibly a duplicate block), so under heavy pressure those pinned blocks made vLLM preempt running requests instead. Release sessions with no running request first, as before, then running sessions' holds, oldest hold first, until the floor is met. 1 H100, Qwen3.5-4B-Base TP1, multi-turn A/B (main vs this, interleaved): 310 blocks 233.7 -> 210.1 s (-10.1%), 372 blocks -3.4%, 434 blocks -0.3%.
VLLMEngine.Config.session_kv_holder now defaults to VLLMSessionKVHolder.Config(). Configs with reset_kv_cache_on_model_state_dict_load=True (the batch-invariant alphabet_sort recipes) turn it off: the engine can't run the holder with them.
With the session KV holder on by default, a None key would put unrelated requests under one holder key. No caller passes None, so make the field a required str from GenerateFn to the inter-generator router.
7ea6075 to
cd137ad
Compare
With the session KV holder on by default, a rollout that ends during shutdown or after a generator crash released its session into a closed queue and raised. Nothing is held then, so drop the release.
|
Reply from claude: addressed the last review. #5477's eviction change is folded in, @claude review |
|
Claude finished @felipemello1's task in 1m 51s —— View job Approve (once the human-written Summary is filled in; a maintainer still needs to review). See the review. |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. Both earlier blockers are resolved: #5477's eviction change is folded in, and the body now has holder on/off throughput. A maintainer still needs to review, because this changes the default RL generator path.
What this PR does. It turns the vLLM session KV holder on by default. Under memory pressure, _evict_until_free now also releases running sessions' holds, after idle ones and oldest first. Before, it skipped them. Batch-invariant/reset-KV configs turn the holder off explicitly. routing_session_id is now a required str from GenerateFn to the router. Late session releases after the queue closes are dropped. The config and recipe edits are mechanical.
Example.
Multi-turn run, KV pool at the knee (358 blocks), no holder override
main (holder off): between turns, a session's blocks can be taken by other requests -> 177.3 s
main's holder (opt-in): running sessions' GDN holds stay pinned -> 28 preemptions, 185.5 s
this PR (default): idle holds go first, then running ones -> 0 preemptions, 167.9 s
Batch-invariant recipe: must set session_kv_holder=None, or the engine build raises
Earlier review
- Holder-on numbers missing: resolved (multi-turn and single-turn A/B in the body).
engine.py:112default ships the slow eviction policy: resolved.session_kv_holder.py:155now releases running sessions last.routing_session_id=Nonesharing one hold /sorted()TypeError: resolved. The type isstralongtypes.py:98->controller.py:553->inter_generator.py:276->router.py:41.IntraGeneratorRouter.reservekeepsstr | None, but it isn't on the holder path.
Must fix
- PR description: "Summary (human-written)" is still empty. The author has to write it before merge.
Should consider
torchtitan/rl/generator/engine_loop.py:223-- check-then-put race with the crash-pathclose(inline comment).- #5477 is still open, and this PR now contains its change. Close it (or mark it superseded) so the change doesn't land twice or conflict.
Questions
- Single-turn with 300-token prompts is +6.2% (167.5 vs 177.9 s). That is above the ~5% the body calls a tie, and the holder holds nothing there. The per-step CPU cost (~20 us at 256 running) doesn't account for ~10 s. Most in-repo recipes are single-turn, so this is the default path's common case. Is this noise (a rerun would tell), or is there a cost we can't see?
Details
- Eviction: a released running session keeps
held=Truein_live, so the same request doesn't re-hold every step. The next turn's request holds again at its prefill. The new test covers the 3 GDN state blocks freed, and the request's own references after release. - The no-running/waiting-head branch (
after_step,_heldorder) only fires with an emptyrunning, so the new order doesn't affect it. - Golden numerics: the only RL loss golden runs batch-invariant with the holder now off, so it is unchanged. Non-batch-invariant runs see different prefix hits, as the body says.
- Fakes in
test_verifiers.py:543,659still defaultrouting_session_id=None. They are harmless test doubles, and making them match the new signature is optional.
Not verified: holder behavior on GPT-OSS (sliding window), DeepSeek V3 (MLA), and generator DP=2. ciflow/rl runs these for the first time.
| # Nothing is held once the queue closes (shutdown or a crash): drop late releases. | ||
| if self._holds_session_kv and self._rank == 0 and not self._queue.closed: | ||
| self._queue.put(SessionReleaseMessage(group_ids=group_ids)) | ||
|
|
||
| def release_sessions(self, session_ids: list[str]) -> None: | ||
| """RANK 0: release the held KV of sessions whose rollout ended (a no-op unless the | ||
| engine holds session KV).""" | ||
| if self._holds_session_kv and self._rank == 0: | ||
| if self._holds_session_kv and self._rank == 0 and not self._queue.closed: | ||
| self._queue.put(SessionReleaseMessage(session_ids=session_ids)) |
There was a problem hiding this comment.
The crash case still races. release_sessions/release_groups run on the actor's thread, and the crash path closes the queue from the engine loop thread (self._queue.close(CloseMessage(), reason="engine loop crashed") at line 399). If the close lands between not self._queue.closed and put, put raises RuntimeError("engine loop crashed") under its lock. That is the same error this check is meant to drop. The window is small, but it is exactly the crash case the comment names.
Smallest fix: do the check under the queue's lock. For example, add EngineLoopQueue.put_unless_closed(message) -> None, which holds self._lock and returns early when closed (about 5 lines), and call it from both release methods instead of closed + put.
Checking closed before put left a window where a crash-path close landed in between and put raised. put(drop_if_closed=True) checks under the lock.
ccd1d80 to
2ba7ac1
Compare
|
Reply from claude:
@claude review |
|
Claude finished @felipemello1's task in 45s —— View job Approve (once the human-written Summary is filled in; a maintainer still needs to review). See the review. |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The race from the last review is fixed and the new commit adds no new problems. A maintainer still needs to review, because this changes the default RL generator path.
What changed since the last review. One commit (2ba7ac1). EngineLoopQueue.put takes a new drop_if_closed argument and checks _closed_reason under self._lock. close takes the same lock (engine_loop.py:657), so a close can't land between the check and the enqueue. Both release methods call put(..., drop_if_closed=True).
Example.
The actor thread calls release_sessions(["s0"]) while the engine loop thread crashes and calls close().
before (d8d35c9): checks closed=False -> close() runs -> put raises "engine loop crashed"
after (2ba7ac1): put takes the lock -> either enqueues before close, or sees closed and returns
Earlier review
- Check-then-put race in
release_sessions/release_groups: resolved (engine_loop.py:643-650). - Single-turn +6.2% at 300-token prompts: the author reads it as noise. The two adjacent pairs disagree (-1.1% and +14.2%), and the holder freed 0 blocks across 768 releases. That is plausible. A rerun with more interleaved cells is promised, and it would settle the question.
- #5477, which this PR now contains: left to Felipe.
Must fix
- PR description: "Summary (human-written)" is still empty. The author has to write it before merge.
Details
put's other callers keep the defaultdrop_if_closed=False, so requests sent after close still raise. Only releases are dropped, and that's right: nothing is held once the loop closes.test_session_releases_after_close_are_droppedcloses first and then releases. It guards the close-then-release ordering, not the interleaving, which is enough for a lock-protected check.- The at-scale Terminal-Bench numbers (hit rate 79.0% -> 92.1%, TTFT 435 -> 278 ms) come from two jobs started about 3 h apart, using main's eviction policy and no preemptions. They support the hit-rate claim. The throughput claim rests on the GB300 A/B.
Not verified: holder behavior on GPT-OSS (sliding window), DeepSeek V3 (MLA), and generator DP=2. ciflow/rl runs these for the first time.
| """Optional logger instantiated on TP rank 0 to export vLLM metrics.""" | ||
|
|
||
| session_kv_holder: VLLMSessionKVHolder.Config | None = None | ||
| session_kv_holder: VLLMSessionKVHolder.Config | None = field( |
There was a problem hiding this comment.
I wonder if we expect people to swap this config to do something customized. If not, maybe a flag disable_session_kv_holder is easier to read / use.
|
Reply from claude: superseded by #5919, which deletes the session KV holder and evicts an ended rollout's KV from vLLM's prefix cache instead. Closing. |
Summary (human-written)
Agent details
TLDR: The vLLM session KV holder is now on by default, and it no longer pins running sessions' blocks under memory pressure. On 1 GB300 (Qwen3.5-4B, multi-turn), it is 5.3% faster than no holder at the knee and ties at heavy pressure. main's holder is 8-10% slower than this one.
Problem
VLLMSessionKVHolderholds those blocks between turns. It is off unless a recipe sets it, and no recipe does._evict_until_freereleases idle sessions only. It never releases a session whose request is running. On hybrid models the holder is the only thing keeping that request's prompt-end GDN state block, so the blocks stay pinned and vLLM preempts running requests instead.Solution
_evict_until_freereleases sessions with no running request first, as before, then running sessions' holds, oldest first.VLLMEngine.Config.session_kv_holderdefaults toVLLMSessionKVHolder.Config().reset_kv_cache_on_model_state_dict_load=True: the engine raises. The 7 batch-invariant alphabet_sort configs that set reset now also setsession_kv_holder=None. The reset, batch-invariant, partial-block-hit and speculative-decoding errors say to set it to None.routing_session_idis a requiredstrfromGenerateFnto the inter-generator router. No caller passed None, and with the holder on, None would put unrelated requests under one hold.session_kv_holderitself.Results
NOTE:
kv_cache_usagenow reads higher on every run that isn't batch-invariant: held blocks count as used.You may ask:
Nonein the 7 configs keeps the rule visible.reset_prefix_cache, so reset-KV runs keep the holder? It's new engine behavior that needs its own bitwise check.Test plan
pytest tests/rl/unit_tests/cpu: 565 passed, 8 skipped.test_evict_until_free_releases_a_session_with_a_running_request_lastfails on main.test_session_releases_after_close_are_droppedfails without the close check.test_default_session_kv_holder_rejects_kv_cache_reset_on_model_state_dict_loadbuildsVLLMEngine.Config()and fails if the default goes back to None.routing_session_idtyping and the close check, which are CPU-tested). Before the eviction change was folded in:rl_grpo_qwen3_5_debug_varlenwith generator TP 2 on 4 GPUs, holder on by default, 5 steps, no errors.