Skip to content

[rl] session KV holder: release running sessions' holds last, not never - #5477

Closed
felipemello1 wants to merge 2 commits into
mainfrom
felipemello1/session-kv-holder/1-release-running-holds
Closed

felipemello1 wants to merge 2 commits into
mainfrom
felipemello1/session-kv-holder/1-release-running-holds

Conversation

@felipemello1

Copy link
Copy Markdown
Contributor

NOTE: H100 numbers; needs retesting on Blackwell.

TLDR: With the session KV holder on, a multi-turn run that outgrows GPU KV ran 9-15% slower than with no holder: the holder never releases the holds of sessions whose request is running. Releasing them last cuts the heavy case by 10% (233.7 -> 210.1 s), back to about no-holder speed. Headroom: no recipe turns the holder on yet.

Problem

  1. Today. When free blocks drop under its floor, VLLMSessionKVHolder._evict_until_free releases idle sessions, idle longest first, and skips sessions whose request is running.
  2. Why the skip. The running request still references most of the held blocks, so releasing them frees little.
  3. What it misses. Once the request decodes, vLLM drops the prompt-end state block of its Gated-DeltaNet (GDN) layers; only the hold keeps it.
  4. How much. For running sessions, blocks that only the holder keeps averaged 29 of a 310-block pool (9%).
  5. The cost. Under heavy pressure the idle holds run out, those blocks stay pinned, and vLLM preempts running requests instead: 187 preemptions vs 49 with no holder, and 15% slower (233.7 vs 204.1 s).

Solution

  1. Release sessions with no running request first, as today; then the holds of running sessions, oldest hold first, until the floor is met.
  2. One loop in _evict_until_free: iterate sorted(self._held, key=running_sessions.__contains__) and drop the skip.
  3. The request keeps its own blocks (a release only lowers ref counts). The session stays unheld until its next prefill, so its next tool call is unprotected.
  4. Unchanged: the order of idle sessions, the floor, and everything when idle sessions alone restore the floor.

Results

1 H100, Qwen3.5-4B-Base TP1, FULL_DECODE_ONLY, 8 groups x 8 multi-turn rollouts (4 groups in flight, 4-10 turns, ~384-token replies, 512 tool tokens, ~2 s tool calls), KV pool set by kv_cache_memory_bytes. Wall time for the whole workload; main and this PR interleaved in one process, main/PR/PR/main (434 blocks has a third pair):

KV pool             main      this PR   delta     preemptions   no holder (1 rep)
310 blocks (heavy)  233.7 s   210.1 s   -10.1%    187 -> 52     204.1 s
372 blocks          193.4 s   186.8 s   -3.4%     52 -> 0       -
434 blocks (knee)   170.4 s   169.9 s   -0.3%     6 -> 0        177.7 s
                                        (3 pairs: -1.1, -1.4, +1.6%)
620, 1,241 blocks   no evictions in any cell, so the new path never runs
  • At 310 blocks the floor is never met, so every hold is released each step: the holder behaves like no holder (this PR is +2.9% over the 1-rep no-holder cell).
  • At the knee the trade is even: lost holds cost 14% more prefill tokens, and preemptions drop to 0. The holder still beats no holder there (169.9 vs 177.7 s).
  • Numerics: not compared. This changes which cached blocks vLLM may evict, not sampling or weights. A released session re-prefills like any prefix-cache miss, which isn't bitwise equal to a hit outside batch-invariant mode.

You may ask:

  • Why not release running holds only after a preemption? Measured on a prototype: about the same wall time (-7.3% at 310 blocks, +0.9% at 434), but it needs a scan for vLLM's internal preempted status.
  • Why not skip a hold taken in the same step (its release frees nothing yet)? The request drops its prompt-end state inside the next schedule, before vLLM checks free blocks. Released now, that block is free for that schedule; with a guard it frees one schedule later, which can turn a scheduled request into a preemption.

Test plan

  • pytest tests/rl/unit_tests/cpu/test_session_kv_holder.py: test_evict_until_free_releases_a_session_with_a_running_request_last replaces the skip test and fails on main.
  • pytest tests/rl/unit_tests/cpu/test_generator.py tests/rl/unit_tests/cpu/test_engine_loop.py
  • GPU: the A/B above.

Felipe Mello added 2 commits October 17, 2026 19:13
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%.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 18, 2026
@felipemello1

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant