Skip to content

[P/D disagg] - support decode side radix cache - #19746

Merged
ShangmingCai merged 95 commits into
mainfrom
ishan/add-radix-cache-decode
May 1, 2026
Merged

ShangmingCai merged 95 commits into
mainfrom
ishan/add-radix-cache-decode

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Mar 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

In PD disaggregation, the decode worker can now use radix cache to reuse shared prefixes and request only the delta KV from prefill instead of transferring the full prefix on every turn.

This is enabled with --disaggregation-decode-enable-radix-cache on the decode server.

For now, this path is supported only with --disaggregation-transfer-backend nixl. server_args.py now rejects other transfer backends early when the decode radix cache flag is enabled. Mooncake support will follow in a separate PR.

Main Changes

  • Decode scheduler
    • Match incoming requests against the decode-side radix tree.
    • Lock matched prefix nodes for the request lifetime.
    • Pre-allocate only the delta KV pages beyond the matched prefix.
  • Decode -> prefill protocol
    • Plumb decode_prefix_len from decode to prefill for the NIXL path.
    • Allow full-prefix hits where decode may need no KV pages transferred.
  • Prefill transfer path
    • Initialize the sender with only the unsent delta pages.
    • Keep the chunked transfer cursor monotonic when decode already has part of the prefix.
    • Skip empty non-last chunks so the sender/receiver chunk protocol stays consistent.
  • Correctness / cleanup
    • Align matched prefix length to page boundaries for paged KV allocators.
    • Guard lock release / cleanup paths for transfer-failure cases.
    • Batch finished prebuilt frees through the free-group path.
  • CLI / config
    • The user-facing switch is --disaggregation-decode-enable-radix-cache.
    • Current validation requires --disaggregation-transfer-backend nixl when that flag is set.

Interface

Enable decode radix cache on the decode worker with:

--disaggregation-mode decode --disaggregation-transfer-backend nixl --disaggregation-decode-enable-radix-cache

Prefill continues to run with --disaggregation-transfer-backend nixl.

Note: DP attention is still experimental here. The flag is allowed, but good cache hit rates require prefix-aware DP routing.

Benchmark

Setup

  • Hardware: 1x NVIDIA B200 node (8 GPUs), single-node PD disaggregation via NIXL
  • Model: Qwen/Qwen3-32B, FP8 KV cache, 3P1D, TP=2 per worker
  • Workload: 20 unique ~50K-token prefixes + ~4.5K suffix (~91% prefix reuse), 1000 requests, concurrency 128

Results

Metric Baseline Decode Radix Cache Improvement
Request throughput (req/s) 1.21 1.59 1.32x
Output token throughput (tok/s) 430 566 1.32x
TTFT p50 (s) 73.2 9.0 8.1x
TTFT avg (s) 77.7 31.6 2.5x
Request latency p50 (s) 99.1 73.4 1.35x
ITL avg (ms) 65.6 130.6 0.50x
Benchmark duration (s) 827 628 1.32x

Decode-side logs show the reason for the throughput gain: baseline decode ran near KV capacity (token_usage ~ 0.99) and only fit ~37 running requests, while decode radix cache reduced duplicate prefix residency (token_usage ~ 0.75) and fit roughly 104-126 running requests. The ITL regression is expected from the larger decode batch.

Test Plan

  • Qwen3-0.6B local PD disagg sanity runs
  • MiniMax-M2.5 1P1D on B200
  • Qwen3-32B 3P1D on B200 (results above)
  • Guard decode radix cache behind nixl in server_args.py
  • Multi-node cross-host testing (RDMA transport)
  • Mooncake transfer backend support (separate PR)

@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!

@ishandhanani ishandhanani changed the title [Draft] [P/D disagg] - support decode side radix cache [P/D disagg] - support decode side radix cache Mar 3, 2026
@dongyibo

dongyibo commented Mar 3, 2026

Copy link
Copy Markdown

@ishandhanani Can this feature be understood as follows:
In a multi-turn dialogue scenario, the first round takes tokens 1, 2, 3 as input and outputs tokens 4, 5, 6.
The second round takes tokens 1, 2, 3, 4, 5, 6, 7, 8, 9 as input and outputs tokens 10, 11, 12.

Current status of pd-disagg:
In the first round, for the decode worker, the generated tokens 4, 5, 6 are not cached, and the KV cache of the input tokens 1, 2, 3 is not saved.
In the second round, the prefill worker needs to send the KV cache for all tokens 1, 2, 3, 4, 5, 6, 7, 8, and 9 to the decode worker.

Based on this PR's implementation:
In the first round, the decode worker saves the KV cache for tokens 1, 2, 3, 4, 5, and 6.
In the second round, the prefill worker only needs to send the KV cache for tokens 7, 8, and 9 to the decode worker.
Is my understanding correct?

@ishandhanani

ishandhanani commented Mar 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

@ishandhanani Can this feature be understood as follows: In a multi-turn dialogue scenario, the first round takes tokens 1, 2, 3 as input and outputs tokens 4, 5, 6. The second round takes tokens 1, 2, 3, 4, 5, 6, 7, 8, 9 as input and outputs tokens 10, 11, 12.

Current status of pd-disagg: In the first round, for the decode worker, the generated tokens 4, 5, 6 are not cached, and the KV cache of the input tokens 1, 2, 3 is not saved. In the second round, the prefill worker needs to send the KV cache for all tokens 1, 2, 3, 4, 5, 6, 7, 8, and 9 to the decode worker.

Based on this PR's implementation: In the first round, the decode worker saves the KV cache for tokens 1, 2, 3, 4, 5, and 6. In the second round, the prefill worker only needs to send the KV cache for tokens 7, 8, and 9 to the decode worker. Is my understanding correct?

Yep. This is correct

@ishandhanani

Copy link
Copy Markdown
Collaborator Author

/gemini review

@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!

- Set req.prefix_indices in _pre_alloc so init_next_round_input(None)
  computes extend_input_len correctly from the cached prefix length.
  Without this, prepare_for_prebuilt runs a full-length extend instead
  of a delta extend.

- Always call inc_lock_ref on the matched node (even on empty match)
  to match aggregated scheduler behavior. Prevents lock_ref underflow
  when cache_finished_req unconditionally calls dec_lock_ref.
@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!

@ishandhanani

ishandhanani commented Mar 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Next step is testing with a larger model on B200. And then step after (maybe in follow up) is to do the same for mooncake

@dongyibo

dongyibo commented Mar 4, 2026

Copy link
Copy Markdown

@ishandhanani There seems to be a constraint here:
For multiple decode workers, such as when decode is run with DP, it's best if the same DP rank is used for the entire conversation; otherwise, the cached KV cache cannot be utilized?

@nananall

nananall commented Mar 4, 2026

Copy link
Copy Markdown

Could you share the exact command you used to run this? I'd like to reproduce it and test it on my side.

@ishandhanani

ishandhanani commented Mar 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

@ishandhanani There seems to be a constraint here: For multiple decode workers, such as when decode is run with DP, it's best if the same DP rank is used for the entire conversation; otherwise, the cached KV cache cannot be utilized?

Theres a few things here.

  1. when running with multiple decode workers (standard data parallelism of workers) - I expect the router to pick the right decode worker based on kv load. The dynamo router handles this very well + performantly out of the box
  2. For DP attention - agreed. Right now I have not added support. Need to do this

@ishandhanani

Copy link
Copy Markdown
Collaborator Author

question: in the second round, Prefill woker will recompute 4,5,6 ? or use decode worker's 4,5,6 cache?

@NoCoder0, that depends on whether the decode node has supported HiRadix Cache. When it is done, prefill could use decode instance's 4, 5, 6. We used to let the decode instances put 4, 5, 6 into the HiCache + L3 through the offloading manager, but that is for the case when decode doesn't enable radix cache.

Yea what Shangming said is correct. Our current solution for P and D sharing cache is with the L3 offloading. For more agentic use cases, the OSL is usually small enough to where the additional incremental prefill shouldn't be too much of a it IMO

@dblate

dblate commented May 27, 2026

Copy link
Copy Markdown
Contributor

What space does the decode node use to cache the KV Cache? GPU memory or other space from HiCache?

@ShangmingCai

Copy link
Copy Markdown
Collaborator

What space does the decode node use to cache the KV Cache? GPU memory or other space from HiCache?

@dblate currently, we cache it in GPU mem, we will support HiCache for decode radix cache, after that, it could offload some kvcache to cpu mem/mooncake store/ssd.

ishandhanani added a commit to ishandhanani/sglang that referenced this pull request Jun 3, 2026
Decode-side radix cache (sgl-project#19746) previously rejected SWA hybrid models
(e.g. gpt-oss) at startup. Enable them: full-attention layers reuse the
matched radix prefix while the sliding-window state is transferred fresh
per turn.

- Cap prefix reuse at the sliding-window start so the window lands in the
  freshly allocated delta, and allocate via alloc_extend_swa_tail on radix
  hits (previously restricted to prefix_len == 0).
- Mark the non-window prefix swa_evicted_seqlen so cache_(un)finished_req
  inserts it as an SWA tombstone, keeping the SWA pool accounting balanced
  (otherwise swa_evictable over-counts and the idle leak check fires).
- Thread the SWA lock uuid from inc_lock_ref through every dec_lock_ref so
  swa_lock_ref does not underflow toward the root.
- Use SWA-aware full-pool size accessors for the decode budget/eviction.
- Keep DeepSeek-V4 (DSA), SWA-compress, and Mamba/SSM blocked.

cache_unfinished_req now passes swa_evicted_seqlen to insert, matching
cache_finished_req (0 in the aggregated path, so behavior there is unchanged).

Validated on gpt-oss-20b 1P1D (nixl and mooncake): multi-turn decode prefix
reuse, no memory leak at low (4x64) and high (32x192) concurrency with strict
idle checking, gsm8k 0.555 vs 0.54 baseline.
@ccilery

ccilery commented Jun 10, 2026

Copy link
Copy Markdown

What space does the decode node use to cache the KV Cache? GPU memory or other space from HiCache?

@dblate currently, we cache it in GPU mem, we will support HiCache for decode radix cache, after that, it could offload some kvcache to cpu mem/mooncake store/ssd.

@ShangmingCai --disaggregation-decode-enable-offload-kvcache cann't be satisfied?

@ShangmingCai

Copy link
Copy Markdown
Collaborator

What space does the decode node use to cache the KV Cache? GPU memory or other space from HiCache?

@dblate currently, we cache it in GPU mem, we will support HiCache for decode radix cache, after that, it could offload some kvcache to cpu mem/mooncake store/ssd.

@ShangmingCai --disaggregation-decode-enable-offload-kvcache can't be satisfied?

@ccilery, we prefer the decode radix cache + HiCache solution now. For now, we will not put much effort into the decode offload manager update.

@heziiop

heziiop commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Hi, @ishandhanani , this is a very useful feature that aligns perfectly with my use case. Are there any major roadblocks or difficulties in adding support for other transfer backends and speculative decoding to the decode radix cache?

@Darcy-Lee

Darcy-Lee commented Jul 10, 2026 •

Copy link
Copy Markdown

I have a quick question about the dataflow at the start of turn 2.

Scenario: A new request (tokens 1–9) triggers prefill.

  • Prefill Worker KV: [1, 2, 3]
  • Decoder KV: [1, 2, 3, 4, 5, 6]

Which behavior is correct?

A. Local Recomputation: Prefill hits cache for 1–3, locally recomputes KV for 4–6, and prefill 7–9. Only KV 7–9 is transferred to the decoder.

B. KV Transfer: The decoder transfers KV 4–6 to the prefill worker. The prefill worker only computes 7–9 (incurring communication cost, but potentially overlapped).

Prefill Worker: [1, 2, 3]
Decoder KV:   [1, 2, 3, 4, 5, 6]
New Request:    [1, 2, 3, 4, 5, 6, 7, 8, 9]
                         ^^^^^^^^
                  How are tokens 4-6 handled?

I've checked the source code and consulted the agent, but I'm still unclear on this specific dataflow. A brief correction would be greatly appreciated!

@ShangmingCai

ShangmingCai commented Jul 10, 2026 •

Copy link
Copy Markdown
Collaborator

@Darcy-Lee Currently, it is A.

efschu added a commit to efschu/htsglang that referenced this pull request Jul 18, 2026
…sts re-prefill chunk 1 forever until pool-exhaustion OOM

Root cause (UPSTREAM bug, introduced by PR sgl-project#19746 'decode side radix
cache'): Req.skip_radix_cache_insert (set iff bootstrap_host ==
FAKE_BOOTSTRAP_HOST, i.e. warmup requests) makes
maybe_cache_unfinished_req skip cache_unfinished_req entirely. For a
chunked prefill that call is not just a radix insert -- it is the
chunk->prefix conversion that advances req.prefix_indices. With it
skipped, PrefillAdder.add_chunked_req re-plans the SAME first chunk on
every pass (extend_range stays [0, chunk)), each pass allocates fresh KV
rows, #pending-token never decrements, and the token pool fills until
the fail-loud RuntimeError('Out of memory...') kills the scheduler.

This is Task sgl-project#99's 'Blocker 1': the historically reported 'admits only
~pool/4 tokens (usage 1.00 at 32.7k of a 131,080-row pool)' was a
32,768-token fake warm filling the 131,072-row pool after 64 re-prefills
of chunk 1 -- the multiplier is pool/chunk_size, not 4. Real-bootstrap
requests are unaffected (flag False; M2 temp-0 oracle incl. 28k needle
was bit-identical).

Fix: when the flag is set, perform the minimal ChunkCache-equivalent
prefix_indices advance (rows from req_to_token up to extend_range.end)
WITHOUT touching the tree. Rows stay request-owned and are freed at
completion via cache_finished_req(is_insert=False) (release_kv_cache
already routes the flag there). Non-disagg / real-bootstrap paths are
byte-identical (flag is False everywhere outside fake warmups).

Falsification test (A3B-AWQ TP=1 on the 5090, disagg-prefill server,
--disable-radix-cache, chunked_prefill_size 2048, fake-bootstrap sends):
- BEFORE (ctx 65,536, pool 219,948): 63,488-token send -> #pending-token
  frozen at 61,440, full token usage -> 1.00 after 108 batches (= pool /
  2048 re-prefills), scheduler crashes RuntimeError OOM
  ('Available tokens: 0'). Log: /tmp/pd99/b1_prefill.log
- AFTER (same config): #pending-token 61,440 -> 0 monotone, usage peaks
  0.29 (= 63,488/219,948 exactly), 200 OK in 5.13 s, pool fully released
  (second 16,384 warm: 200 in 0.80 s, starts at usage 0.07 = 16,384/pool).
  Log: /tmp/pd99/b1_prefill_after.log
- AFTER (ctx 131,072, pool 373,548): 122,880-token send -> 200 in
  16.48 s, usage fills to 0.33 (= 122,880/373,548) and releases to 0.00.
  Log: /tmp/pd99/b1_120k.log

Unblocks the eager fake-warm boot protocol needed for Blocker 2 (JIT/
workspace warm before the decode server boots).
@ConcentrativeMan

Copy link
Copy Markdown

Hi, @ishandhanani, this is a useful feature, why --disaggregation-decode-enable-radix-cache is incompatible with speculative decoding.

@zuchunshan

Copy link
Copy Markdown

ValueError: --disaggregation-decode-enable-radix-cache is incompatible with speculative decoding (--speculative-algorithm EAGLE)

efschu added a commit to efschu/htsglang that referenced this pull request Jul 22, 2026
…sts re-prefill chunk 1 forever until pool-exhaustion OOM

Root cause (UPSTREAM bug, introduced by PR sgl-project#19746 'decode side radix
cache'): Req.skip_radix_cache_insert (set iff bootstrap_host ==
FAKE_BOOTSTRAP_HOST, i.e. warmup requests) makes
maybe_cache_unfinished_req skip cache_unfinished_req entirely. For a
chunked prefill that call is not just a radix insert -- it is the
chunk->prefix conversion that advances req.prefix_indices. With it
skipped, PrefillAdder.add_chunked_req re-plans the SAME first chunk on
every pass (extend_range stays [0, chunk)), each pass allocates fresh KV
rows, #pending-token never decrements, and the token pool fills until
the fail-loud RuntimeError('Out of memory...') kills the scheduler.

This is Task sgl-project#99's 'Blocker 1': the historically reported 'admits only
~pool/4 tokens (usage 1.00 at 32.7k of a 131,080-row pool)' was a
32,768-token fake warm filling the 131,072-row pool after 64 re-prefills
of chunk 1 -- the multiplier is pool/chunk_size, not 4. Real-bootstrap
requests are unaffected (flag False; M2 temp-0 oracle incl. 28k needle
was bit-identical).

Fix: when the flag is set, perform the minimal ChunkCache-equivalent
prefix_indices advance (rows from req_to_token up to extend_range.end)
WITHOUT touching the tree. Rows stay request-owned and are freed at
completion via cache_finished_req(is_insert=False) (release_kv_cache
already routes the flag there). Non-disagg / real-bootstrap paths are
byte-identical (flag is False everywhere outside fake warmups).

Falsification test (A3B-AWQ TP=1 on the 5090, disagg-prefill server,
--disable-radix-cache, chunked_prefill_size 2048, fake-bootstrap sends):
- BEFORE (ctx 65,536, pool 219,948): 63,488-token send -> #pending-token
  frozen at 61,440, full token usage -> 1.00 after 108 batches (= pool /
  2048 re-prefills), scheduler crashes RuntimeError OOM
  ('Available tokens: 0'). Log: /tmp/pd99/b1_prefill.log
- AFTER (same config): #pending-token 61,440 -> 0 monotone, usage peaks
  0.29 (= 63,488/219,948 exactly), 200 OK in 5.13 s, pool fully released
  (second 16,384 warm: 200 in 0.80 s, starts at usage 0.07 = 16,384/pool).
  Log: /tmp/pd99/b1_prefill_after.log
- AFTER (ctx 131,072, pool 373,548): 122,880-token send -> 200 in
  16.48 s, usage fills to 0.33 (= 122,880/373,548) and releases to 0.00.
  Log: /tmp/pd99/b1_120k.log

Unblocks the eager fake-warm boot protocol needed for Blocker 2 (JIT/
workspace warm before the decode server boots).
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Sep 6, 2026
… output-token churn

Root cause (garbling + accept collapse correlated with batch-finish window,
1114-1120 UTC): decode-side radix cache (upstream sgl-project#19746) inserted the FULL
KV chain (req.origin_input_ids + req.output_ids) on EVERY decode batch via
maybe_cache_unfinished_req. Under 80RPM replay the decode output tokens are
almost never reused as a prefix (agent harness rewrites the last message), so
each batch built a fresh growing tree key -> continuous node churn -> L2
write_back/eviction pressure spikes exactly when many requests finish
(user observation: garble/accept dips preceded by a decode batch with many
running reqs completing). Clamping kv_len_to_handle to input length keeps the
tree key within origin_input_ids; after the first insert it is a no-op
(radix match reuses the existing path), so it neither wastes perf nor
generates churn. Prefill side unaffected (output_ids empty).

Verified: py_compile; deploy + run6 pending.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high priority run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.