Skip to content

Enable unified cache out-of-window slot freeing by default - #34653

Merged
ispobock merged 2 commits into
mainfrom
flip-free-out-of-window-default
Aug 13, 2026
Merged

ispobock merged 2 commits into
mainfrom
flip-free-out-of-window-default

Conversation

@ispobock

@ispobock ispobock commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Motivation

SGLANG_OPT_UNIFIED_CACHE_FREE_OUT_OF_WINDOW_SLOTS releases SWA slots that have already left the sliding window while a chunked prefill is being cached, instead of holding them until the request finishes. It has been opt-in since it landed; this makes it the default.

This is a default flip, so it changes behavior for every server running the unified radix cache with an SWA component. The single consumer is the chunked-prefill caching path in unified_radix_cache.py, gated behind SGLANG_ENABLE_UNIFIED_RADIX_TREE; passing False restores the old behavior.

The risk worth calling out is not the freeing itself but what it does to prefix reuse: how much SWA data stays resident decides how deep a later request can match, since a hit needs a full window of live SWA below the match point. Freeing earlier could in principle shorten that and silently cost cache hits.

Accuracy

test_unified_radix_cache_kl_hybrid_bitexact.py is the sharpest check available for this: it asserts prefill and decode score every token identically (kl_div floor 1e-9, measured exactly 0), and its hicache case additionally asserts the reused prefix length per request. One H200 (SM90, same architecture as the 1-gpu-large CI runner), both fixes in, flag defaulted on:

SELFCHECK flag_effective True

test_logprobs_match ... avg_kl_div=0.0 ok
test_prefill_cache_hit ... avg_kl_div=0.0 ok
test_decode_cache_hit ... avg_kl_div=0.0 ok
test_multiturn_decode_cache_hit_branching ... avg_kl_div=0.0 ok

Ran 4 tests in 427.750s

OK

The per-request cached_tokens assertion in the multi-turn case passes unchanged, so the reusable prefix does not shrink.

Two things this does not cover, and I would rather say so than imply otherwise: only the hybrid SWA + mamba configuration was measured, not the SWA-only or mamba-only models in the same directory, and the reason it originally shipped opt-in is not recorded anywhere I could find (the introducing commit carries no rationale). Running the full unified_radix_tree/ suite on this PR would close the first gap.


CI States

Latest PR Test (Base): ✅ Run #31661339455
Latest PR Test (Extra): ✅ Run #31661339489

@ispobock

ispobock commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_hybrid_bitexact.py
test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_swa.py
test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_mamba.py
test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_hybrid_bitexact.py:

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_hybrid_bitexact.py

@ispobock

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_swa.py

@ispobock

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py

@ispobock

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_mamba.py

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_swa.py:

🚀 2-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_swa.py

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py:

🚀 2-gpu-h100 (1 test): ❌ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_mamba.py:

🚀 4-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_mamba.py

@ispobock

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py:

🚀 2-gpu-h100 (1 test): ❌ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py

@ispobock

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@ispobock

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py:

🚀 2-gpu-h100 (1 test): ❌ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_full.py

@ispobock
ispobock merged commit ebc144c into main Aug 13, 2026
169 of 218 checks passed
@ispobock
ispobock deleted the flip-free-out-of-window-default branch August 13, 2026 06:31
ehuaa added a commit to ehuaa/sglang that referenced this pull request Aug 14, 2026
…EE_OUT_OF_WINDOW_SLOTS on

Frees out-of-window SWA slots when a chunked-prefill request is stashed into
the unified radix tree (`UnifiedRadixCache.cache_unfinished_req` ->
`SWAComponent.free_out_of_window_slots`). We do run UnifiedRadixCache
(`impl=UnifiedRadixCache`, components FULL+SWA), so the flag is live for us.

Measured no effect on our workload, in either direction. A/B on
DeepSeek-V4-Flash-0731 with in=13,513 (2 chunks at chunked_prefill_size=8192)
/ out=2048 / conc=32, with sgl-project#33805 also applied:

  on   1138.3 tok/s   prefill-phase swa peak 0.07
  off  1147.1 tok/s   prefill-phase swa peak 0.07

The chunking did happen (`#new-token: 8192` then `1792` per sequence), so this
is a real null result, not a missed code path. The reason is that
`max_prefill_tokens=16384` admits only one or two sequences per prefill batch,
so the out-of-window KV this frees is a per-request transient that never
accumulates across the batch -- and with sgl-project#33805 in place the decode side is
already reclaiming for every request that has moved on. It should matter with
a much wider prefill batch or much longer inputs.

Carried anyway to stay close to upstream default. Note the known issue behind
upstream sgl-project#34823: under EAGLE the new-leaf path computes
`split_pos = swa_evicted_seqlen - result.prefix_len`, mixing raw-token lengths
with bigram key units, and split_pos goes negative. That PR gates the option
off for EAGLE only and explicitly keeps it for DSpark/DFlash, which is what we
run -- but anyone switching this branch to EAGLE should set
SGLANG_OPT_UNIFIED_CACHE_FREE_OUT_OF_WINDOW_SLOTS=0 until sgl-project#34823 lands.
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
jakki-amd pushed a commit to jakki-amd/sglang that referenced this pull request Sep 9, 2026
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant