Skip to content

[sgl] Window-aware LRU refresh for SWA prefix cache in unified cache - #26615

Merged
ispobock merged 13 commits into
sgl-project:mainfrom
bixue2010:bi/swa_lru
Jun 1, 2026
Merged

ispobock merged 13 commits into
sgl-project:mainfrom
bixue2010:bi/swa_lru

Conversation

@bixue2010

@bixue2010 bixue2010 commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Summary
Make the SWA (Sliding Window Attention) radix-cache LRU window-aware so that out-of-window SWA nodes can be evicted as they should be. This significantly improves SWA prefix-cache hit rate on long multi-turn workloads, with no behavior change for non-SWA components.

Problem
The radix cache uses LRU to evict SWA cache. On every prefix-cache match (and on every walk-down during insert), all matched ancestors are bumped to MRU. That is correct for the Full KV, but it is wrong for SWA, because for SWA only the last sliding_window_size tokens are actually reachable from any current decode step. As a result:

Very old SWA nodes (outside the active window of every live request) keep getting refreshed to MRU and never get evicted.
Genuinely-hot SWA cache from other branches gets pushed toward the LRU tail and is evicted first.
Under multi-turn pressure, the SWA pool fills up with cache that can no longer contribute to any hit, hit-rate degrades, and eviction churn goes up.

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ⏳ Run #26739938263
Latest PR Test (Extra): ✅ Run #26739938119

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@ispobock

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@ispobock ispobock added the run-ci-extra CI: also run the extra suite (requires run-ci) label May 29, 2026
@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label May 29, 2026
Comment thread test/registered/unit/mem_cache/test_unified_radix_cache_unittest.py Outdated
@ispobock

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

value = node.component_data[self.component_type].value
return len(value) if value is not None else 0

def refresh_lru_on_walkdown(self, node: UnifiedTreeNode) -> None:

@hzh0425 hzh0425 May 30, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we avoid adding too many new component interfaces here?
Could we instead merge them into a single interface and use a "phase" parameter to distinguish between different cases?

Additionally, it seems that refresh_lru_on_walkdown hasn't been implemented yet on swa_component

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to less inferfaces and use phrases.

add comment to indicate why we don't need to do anything in walkdown for swa to avoid confusing.

@bixue2010

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@hzh0425 hzh0425 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! LGTM

@hzh0425

hzh0425 commented May 31, 2026

Copy link
Copy Markdown
Collaborator

/rerun-group radix_cache/unified_radix_tree

@sgl-project sgl-project deleted a comment from github-actions Bot May 31, 2026
@github-actions

github-actions Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-group radix_cache/unified_radix_tree:

🚀 4-gpu-h100 (2 tests): ❌ View workflow run

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

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

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

🚀 8-gpu-h200 (1 test): ❌ View workflow run

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

@hzh0425

hzh0425 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-group radix_cache/unified_radix_tree

@github-actions

github-actions Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-group radix_cache/unified_radix_tree:

🚀 4-gpu-h100 (2 tests): ✅ View workflow run

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

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

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

🚀 8-gpu-h200 (1 test): ❌ View workflow run

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

@bixue2010

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@hzh0425

hzh0425 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/disaggregation/test_disaggregation_pp.py

@github-actions

github-actions Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/disaggregation/test_disaggregation_pp.py:

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

cd test/ && python3 registered/disaggregation/test_disaggregation_pp.py

@ispobock

ispobock commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-test test_unified_radix_cache_kl_hicache_nightly.py

@github-actions

github-actions Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_unified_radix_cache_kl_hicache_nightly.py:

🚀 8-gpu-h200 (1 test): ❌ View workflow run

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

@ispobock

ispobock commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

test_unified_radix_cache_kl_hicache_nightly.py failure seems not related to this PR.

@ispobock
ispobock merged commit 6965fe0 into sgl-project:main Jun 1, 2026
119 of 147 checks passed
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants