Skip to content

[Unified Tree] Support Branching-Point Caching for the SWA Component - #34565

Merged
ispobock merged 43 commits into
sgl-project:mainfrom
Chen-0210:cjc/unified-swa-branching
Sep 5, 2026
Merged

ispobock merged 43 commits into
sgl-project:mainfrom
Chen-0210:cjc/unified-swa-branching

Conversation

@Chen-0210

@Chen-0210 Chen-0210 commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

With out-of-window SWA slot freeing now enabled by default in #34653, chunked prefill releases SWA states outside the last sliding window. This significantly reduces swa memory usage, but later requests branching from an earlier shared prefix may still have reusable Full KV while the corresponding swa state is no longer available, forcing unnecessary prefix recomputation.

Modifications

Reuse most of the existing mamba branching for SWA: and preserve the SWA cache at that boundary when releasing out-of-window slots, and has no effect when the SGLANG_OPT_UNIFIED_CACHE_FREE_OUT_OF_WINDOW_SLOTS is disabled.


■■  SWA slots retained
□   SWA slots released
P   SWA branching point


1. Compute the chunk containing the branching point

Chunk 1              Chunk 2              Current Chunk
[□□□□□□□□□□□□□□■■][□□□□□□□□□□□□□□■■][■■■■■■P■■■■■■■■■■]


2. Call free_out_of_window_slots() before insertion

Chunk 1              Chunk 2              Current Chunk
[□□□□□□□□□□□□□□■■][□□□□□□□□□□□□□□■■][□□□□■■P■■■■■■■■■■]


3. Insert the branch, then call cleanup_after_caching_req()

Chunk 1              Chunk 2              Current Chunk
[□□□□□□□□□□□□□□■■][□□□□□□□□□□□□□□■■][□□□□■■P□□□□□□□□■■]

Add four relevant tests covering Device and Host Full KV branching, EAGLE insertion boundaries, and releasing unused SWA slots after branch insertion.

Accuracy Tests

Speed Tests and Profiling

Server

SGLANG_ENABLE_UNIFIED_RADIX_TREE=True \
SGLANG_OPT_UNIFIED_CACHE_FREE_OUT_OF_WINDOW_SLOTS=True \
sglang serve \
  --model-path deepseek-ai/DeepSeek-V4-Flash-0731 \
  --trust-remote-code \
  --tp 2 \
  --moe-runner-backend flashinfer_mxfp4 \
  --speculative-algorithm DSPARK \
  --disable-flashinfer-autotune \
  --swa-full-tokens-ratio 0.1 \
  --mem-fraction-static 0.85 \
  --max-total-tokens 524288 \
  --max-running-requests 16 \
  --chunked-prefill-size 16384 \
  --enable-cache-report \
  --enable-metrics \
  --enable-metrics-for-all-schedulers \
  --host 127.0.0.1 \
  --port 30003

Internal Shared-Prefix Simulates

python -m sglang.benchmark.serving \
  --flush-cache \
  --model deepseek-ai/DeepSeek-V4-Flash-0731 \
  --host 127.0.0.1 \
  --port 30003 \
  --backend sglang-oai-chat \
  --dataset-name generated-shared-prefix \
  --num-prompts 64 \
  --gsp-num-groups 8 \
  --gsp-prompts-per-group 8 \
  --gsp-system-prompt-len 24576 \
  --gsp-question-len 8192 \
  --gsp-output-len 128 \
  --gsp-range-ratio 1 \
  --request-rate 2 \
  --max-concurrency 8 \
  --seed 42 \
  --temperature 0 \
  --top-p 1 \
  --extra-request-body '{"top_k":-1}' \
  --cache-report
OOW Free Version Token Hit Rate (%) Cached Tokens Mean TTFT (ms) P95 TTFT (ms) Input Throughput (tok/s)
Off Baseline 19.80 424,448 2,222.69 4,589.32 42,061.50
Off This PR 26.90 576,000 1,621.12 3,283.54 51,059.49
On Baseline 43.81 939,264 1,569.93 3,427.47 66,310.37
On This PR 60.75 1,302,528 1,069.58 2,372.52 70,509.72

Public AgentX Scenario

aiperf profile \
  --scenario inferencex-agentx-mvp \
  --url http://127.0.0.1:30003 \
  --model deepseek-ai/DeepSeek-V4-Flash-0731 \
  --endpoint-type chat \
  --public-dataset semianalysis_cc_traces_weka_062126_256k \
  --concurrency 32 \
  --use-server-token-count \
  --benchmark-duration 1800 \
  --random-seed 20260707

Overall Results

OOW Free Version Token Hit Rate (%) Cached Tokens Mean TTFT (ms) P95 TTFT (ms) Input Throughput (tok/s)
Off Baseline 5.41 3,271,424 27,739.82 48,244.48 32,863.50
Off This PR 6.06 3,741,952 26,914.22 43,031.56 33,571.43
On Baseline 94.90 171,954,176 628.74 1,302.54 99,014.00
On This PR 94.96 172,511,232 625.07 1,214.13 99,273.44

The overall AgentX results are similar because most requests continue existing conversations and already have reusable SWA states. The patch introduces no significant performance regression.

The disabled runs used the same 1,800-second duration. Baseline and This PR completed 716 and 729 requests respectively, so these aggregate results represent fixed-duration workload behavior rather than a request-for-request comparison.

Newly Forked Subagent Requests

This subset includes the first request from each new subagent (43 requests).

OOW Free Version Token Hit Rate (%) Cached Tokens
Off Baseline 22.13 263,680
Off This PR 17.31 206,336
On Baseline 50.26 628,736
On This PR 54.13 677,120

For new subagent requests, the patch improves the token hit rate by 3.87 percentage points and adds 48,384 cached tokens.

With slot freeing disabled, a few first requests lose large cache hits and lower the result for this subset. The overall run still improves because it also includes later requests that can reuse the newly created branching points.

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 #33893909201
Latest PR Test (Extra): ⏳ Run #34116727761
Latest PR Test (AMD ROCm 7.2): 🚫 Run #33893909236

@Chen-0210 Chen-0210 changed the title [HiCache][SWA] Support branching-point caching in Unified Radix Cache [HiCache]Support swa branching-point caching in Unified Radix Cache Aug 12, 2026
@Chen-0210

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Aug 13, 2026
@Chen-0210 Chen-0210 changed the title [HiCache]Support swa branching-point caching in Unified Radix Cache [Unified Tree] Support Branching-Point Caching for the SWA Component Aug 13, 2026
@Chen-0210

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Chen-0210

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Chen-0210

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@Chen-0210
Chen-0210 force-pushed the cjc/unified-swa-branching branch from 7b01a3d to 22a279b Compare August 17, 2026 04:01
@alphabetc1

Copy link
Copy Markdown
Collaborator

/rerun-group radix_cache/unified_radix_tree

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-group radix_cache/unified_radix_tree:

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

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_hicache_pp_kl.py
cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_cp.py
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

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

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

🚀 8-gpu-h200 (3 tests): ✅ View workflow run

cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_dsv4_pp.py
cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_glm52.py
cd test/ && python3 registered/radix_cache/unified_radix_tree/test_unified_radix_cache_kl_mimo.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

🚀 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

@alphabetc1

Copy link
Copy Markdown
Collaborator

/rerun-group hicache

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-group hicache:

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

cd test/ && python3 registered/hicache/test_hicache_spec_file_storage.py
cd test/ && python3 registered/hicache/test_hicache_variants.py

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

cd test/ && python3 registered/hicache/test_hicache_spec_mooncake_storage.py
cd test/ && python3 registered/hicache/test_hicache_storage_3fs_backend.py
cd test/ && python3 registered/hicache/test_hicache_storage_file_backend.py
cd test/ && python3 registered/hicache/test_hicache_storage_mooncake_backend.py
cd test/ && python3 registered/hicache/test_hicache_storage_runtime_attach_detach.py

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

cd test/ && python3 registered/hicache/test_hicache_storage.py

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

cd test/ && python3 registered/hicache/test_pp_with_hicache.py
cd test/ && python3 registered/hicache/test_qwen35_hicache.py

⛔ registered/hicache/test_hicache_storage_umbp_backend.py: test/registered/hicache/test_hicache_storage_umbp_backend.py is registered for AMD (suite nightly-amd-8-gpu-mi35x-deepseek-v4-flash), not for CUDA or CPU; rerun-test.yml has no AMD job. Rerun it with /rerun-failed-ci, or dispatch the AMD workflow manually.

# Conflicts:
#	python/sglang/srt/mem_cache/unified_cache/unified_tree_core.py
#	python/sglang/srt/mem_cache/unified_cache/unified_tree_core_interface.py
#	python/sglang/srt/mem_cache/unified_radix_cache.py
@ispobock
ispobock merged commit 3a770da into sgl-project:main Sep 5, 2026
247 of 265 checks passed
StevenChenSE pushed a commit to StevenChenSE/sglang that referenced this pull request Sep 6, 2026
@Chen-0210
Chen-0210 deleted the cjc/unified-swa-branching branch September 7, 2026 09:41
@alphabetc1 alphabetc1 added the release-highlight Candidate PR for release note highlight label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail high priority release-highlight Candidate PR for release note highlight run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants