Skip to content

[HiCache] Fix PP inconsistency with HiCache L3 (#22607) - #27010

Merged
hzh0425 merged 25 commits into
sgl-project:mainfrom
stepinto:sglang_pp_bug4
Aug 25, 2026
Merged

hzh0425 merged 25 commits into
sgl-project:mainfrom
stepinto:sglang_pp_bug4

Conversation

@stepinto

@stepinto stepinto commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

When deploying HiCache and PP, multiple PP ranks go diverge and eventually cause sglang crash. The detailed reason was discussed in issue #22607.

Modifications

This patch introduces two kinds of synchronization mechanisms to fix the issue. I will illustrate this idea with an example of pp_size=2 and tp_size=1.

  1. pp_sync across scheduler threads. pp_sync is a new name introduced by this patch. PP0's scheduler thread determine the number of completion events in its local queues (ack_load_queue, ack_prefetch_queue, etc). Then, PP1 must consume the exact same number of events from its queues. This prevents divergence.

  2. all_reduce across prefetch threads. Consider a case that PP0 and PP1 have different lengths on their L3 storage for a given sequence. They have to reach an agreement on the length, by perform all_reduce(MIN). This behavior is consistent with TP.

This patch also changes how check_prefetch_progress works. Before this patch, it simply does all_reduce(MIN) to determine the final tokens prefetchted. However, this would not work on PP, as we cannot do that in the scheduler thread. This patch adds a new background thread prefetch_sync_thread, which does the all_reduce work instead.

Accuracy Tests

Added test_unified_radix_cache_hicache_pp_kl.py.

I have also tested SWE-bench verified with DSv4 flash model.

I ran two groups:

  • Group A: The baseline, commit 5747ed3, without this PR, TP=8, L3 enabled. Resolved 356/500.
  • Group B: This PR, PP=4, TP=2, L3 enabled. Resolved 353/500.

I analyzed the difference, and found 351 cases successful in both group, 5 are successful only in group A, and 2 are successful only in group B. The 7 cases that are successfuly in one group but failed in another, are due to container exits after a long time.

Here are commands for anyone has interested in reproducing this test. Hints to make L3 are in-use:

  • Use large number of workers (128), leading to large number of running requests.
  • Limit number of tokens in L1 and L2.
# Group A
sglang serve \
    --model=deepseek-ai/DeepSeek-V4-Flash \
    --tp-size 8 \
    --moe-runner-backend flashinfer_mxfp4 \
    --disable-cuda-graph \
    --mem-fraction-static 0.85 \
    --reasoning-parser deepseek-v4 \
    --tool-call-parser deepseekv4 \
    --host 0.0.0.0 \
    --port 30000 \
    --max-total-tokens=500000 \
    --swa-full-tokens-ratio=0.4 \
    --enable-metrics \
    --enable-hierarchical-cache \
    --hicache-storage-backend=mooncake \
    --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}'

# Group B
sglang serve \
    --model=deepseek-ai/DeepSeek-V4-Flash \
    --pp-size 4 \
    --tp-size 2 \
    --moe-runner-backend flashinfer_mxfp4 \
    --disable-cuda-graph \
    --mem-fraction-static 0.85 \
    --reasoning-parser deepseek-v4 \
    --tool-call-parser deepseekv4 \
    --host 0.0.0.0 \
    --port 30000 \
    --max-total-tokens=500000 \
    --swa-full-tokens-ratio=0.4 \
    --enable-metrics \
    --enable-hierarchical-cache \
    --hicache-storage-backend=mooncake \
    --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}'

# SWE bench agent
python -m minisweagent.run.benchmarks.swebench \
    --subset verified \
    --split test \
    -c swebench.yaml -c environment.container_timeout=24h \
    -o /root/swe_test/result \
    -m "openai/deepseek-ai/DeepSeek-V4-Flash" \
    -w 128

# SWE evaluation
python -m swebench.harness.run_evaluation \
    --predictions_path /root/swe_test/result/preds.json \
    --dataset_name princeton-nlp/SWE-Bench_Verified \
    --split test \
    --max_workers 32 \
    --run_id test-mini-swe-agent \
    --timeout 1200

Speed Tests and Profiling

I tested with L1 only, L1+L2 and L1+L2+L3. The size of L1 and L2 are configured not to hold all tokens. L3 is large enough to hold all tokens. request-rate is set to 1 so that L3 prefetch are performed and not limited by budget.

# L1
sglang serve \
  --model=Qwen/Qwen3-32B \
  --tp-size=2 \
  --pp-size=4 \
  --max-total-tokens=$((256*1024)) \
  --reasoning-parser qwen3 \
  --tool-call-parser qwen25 \
  --page-size=64 \
  --enable-metrics

# L2
sglang serve \
  --model=Qwen/Qwen3-32B \
  --tp-size=2 \
  --pp-size=4 \
  --max-total-tokens=$((256*1024)) \
  --reasoning-parser qwen3 \
  --tool-call-parser qwen25 \
  --page-size=64 \
  --enable-metrics \
  --enable-hierarchical-cache \
  --hicache-mem-layout=page_first 

# L3
sglang serve \
  --model=Qwen/Qwen3-32B \
  --tp-size=2 \
  --pp-size=4 \
  --max-total-tokens=$((256*1024)) \
  --reasoning-parser qwen3 \
  --tool-call-parser qwen25 \
  --page-size=64 \
  --enable-metrics \
  --enable-hierarchical-cache \
  --hicache-mem-layout=page_first \
  --hicache-storage-backend=mooncake \
  --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "256gb", "protocol": "tcp"}'

# Benchmark
python benchmark/hicache/bench_multiturn.py  \
    --num-clients=128 \
    --num-rounds=10 \
    --disable-auto-run  \
    --model=Qwen/Qwen3-32B  \
    --enable-round-barrier \
    --request-rate 1
L1
Per-round metrics:
  Round 0: Average TTFT = 0.14s, Cache Hit Rate = 0.000000 (128 requests, 128 clients)
  Round 1: Average TTFT = 0.17s, Cache Hit Rate = 0.470588 (128 requests, 128 clients)
  Round 2: Average TTFT = 0.18s, Cache Hit Rate = 0.653846 (128 requests, 128 clients)
  Round 3: Average TTFT = 0.26s, Cache Hit Rate = 0.630580 (128 requests, 128 clients)
  Round 4: Average TTFT = 0.77s, Cache Hit Rate = 0.363459 (128 requests, 128 clients)
  Round 5: Average TTFT = 1.22s, Cache Hit Rate = 0.239976 (128 requests, 128 clients)
  Round 6: Average TTFT = 1.44s, Cache Hit Rate = 0.146925 (128 requests, 128 clients)
  Round 7: Average TTFT = 1.94s, Cache Hit Rate = 0.143266 (128 requests, 128 clients)
  Round 8: Average TTFT = 2.01s, Cache Hit Rate = 0.055469 (128 requests, 128 clients)
  Round 9: Average TTFT = 8.92s, Cache Hit Rate = 0.035112 (128 requests, 128 clients)


L2
Per-round metrics:
  Round 0: Average TTFT = 0.15s, Cache Hit Rate = 0.000000 (128 requests, 128 clients)
  Round 1: Average TTFT = 0.17s, Cache Hit Rate = 0.470588 (128 requests, 128 clients)
  Round 2: Average TTFT = 0.18s, Cache Hit Rate = 0.653846 (128 requests, 128 clients)
  Round 3: Average TTFT = 0.19s, Cache Hit Rate = 0.742857 (128 requests, 128 clients)
  Round 4: Average TTFT = 0.18s, Cache Hit Rate = 0.795455 (128 requests, 128 clients)
  Round 5: Average TTFT = 0.23s, Cache Hit Rate = 0.830189 (128 requests, 128 clients)
  Round 6: Average TTFT = 0.19s, Cache Hit Rate = 0.854839 (128 requests, 128 clients)
  Round 7: Average TTFT = 0.70s, Cache Hit Rate = 0.652729 (128 requests, 128 clients)
  Round 8: Average TTFT = 1.16s, Cache Hit Rate = 0.474805 (128 requests, 128 clients)
  Round 9: Average TTFT = 1.86s, Cache Hit Rate = 0.379213 (128 requests, 128 clients)

L3
Per-round metrics:
  Round 0: Average TTFT = 0.19s, Cache Hit Rate = 0.000000 (128 requests, 128 clients)
  Round 1: Average TTFT = 0.19s, Cache Hit Rate = 0.470588 (128 requests, 128 clients)
  Round 2: Average TTFT = 0.25s, Cache Hit Rate = 0.653846 (128 requests, 128 clients)
  Round 3: Average TTFT = 0.20s, Cache Hit Rate = 0.742857 (128 requests, 128 clients)
  Round 4: Average TTFT = 0.23s, Cache Hit Rate = 0.795455 (128 requests, 128 clients)
  Round 5: Average TTFT = 0.25s, Cache Hit Rate = 0.830189 (128 requests, 128 clients)
  Round 6: Average TTFT = 0.21s, Cache Hit Rate = 0.854839 (128 requests, 128 clients)
  Round 7: Average TTFT = 0.25s, Cache Hit Rate = 0.873239 (128 requests, 128 clients)
  Round 8: Average TTFT = 0.26s, Cache Hit Rate = 0.887500 (128 requests, 128 clients)
  Round 9: Average TTFT = 0.29s, Cache Hit Rate = 0.898876 (128 requests, 128 clients)

It shows that, L1 and L2 hit ratios drop at round 4 and 7 respectively. L3 may hold all rounds.

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 #32801836475
Latest PR Test (Extra): ✅ Run #32801836390
Latest PR Test (AMD ROCm 7.2): ❌ Run #32801836438

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

@whybeyoung whybeyoung self-assigned this Jun 2, 2026
@whybeyoung whybeyoung linked an issue Jun 2, 2026 that may be closed by this pull request
11 tasks done
@stepinto
stepinto requested a review from alphabetc1 as a code owner June 3, 2026 02:07
@whybeyoung

Copy link
Copy Markdown
Collaborator

@hzh0425 @ShangmingCai can you help review this ?

@whybeyoung

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jun 3, 2026
Comment thread python/sglang/srt/managers/scheduler.py Resolved
Comment on lines +1506 to +1514
cc.mem_pool_host.free(
operation.host_indices[
operation.completed_tokens : ack.completed_tokens
]
)
if ack.completed_req:
cc.mem_pool_host.free(
operation.host_indices[ack.completed_tokens :]
)

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 add operation.completed_tokens = ack.completed_tokens in between to avoid potential double free?

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.

Fixed. My code was buggy. Nice catch!

Comment on lines -1288 to -1291
self.cache_controller.mem_pool_host.free(host_indices[:matched_length])
self.cache_controller.append_host_mem_release(
host_indices[min_completed_tokens:completed_tokens]
)

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.

What about a partial fetch failure? Should we handle middle tokens by append_host_mem_release to prevent a memory leak?

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.

Yes. There was a mem-leak in my code. Fixed it now.

Let us discuss the deallocation time.

In the revoke path, all memory is released by prefetch_thread_func.

In the non-revoke path, there are four pieces of memory:

0 .. matched_length .. completed_tokens ... storage_hit ... len(host_indices)

host_indices[0 : matched_length] is released in _handle_prefetch_result.

host_indices[matched_length : completed_tokens] is referenced by the radix tree, and not released.

host_indices[completed_tokens : storage_hit] released in _drain_ack_prefetch.

host_indices[storage_hit : ] released in prefetch_thread_func.

@huangtingwei9988

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

1 similar comment
@stepinto

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@guangpec-hash

Copy link
Copy Markdown

pp + L3 ,sglang v0.5.17 ,llm is deepseek-v4-flash have a cuda memory error , Scheduler hit an exception: Traceback (most recent call last):
File ".../scheduler.py", line 4984, in run_scheduler_process
scheduler.run_event_loop()
File ".../scheduler.py", line 4837, in dispatch_event_loop
scheduler.event_loop_pp_disagg_prefill()
File ".../scheduler_pp_mixin.py", line 345, in event_loop_pp_disagg_prefill
d2h_event.synchronize()
File ".../torch/cuda/streams.py", line 254, in synchronize
super().synchronize()
torch.AcceleratorError: CUDA error: an illegal memory access was encountered
Search for `cudaErrorIllegalAddress' ...

@stepinto

Copy link
Copy Markdown
Contributor Author

Resolved conflicts again.

@stepinto

Copy link
Copy Markdown
Contributor Author

Update to latest to take fix to failure test_import_surface.py at upstream.

@stepinto

Copy link
Copy Markdown
Contributor Author

Fixed a mis-spelled function calling due to code merge. (_revoke_pending_prefetch was renamed to revoke_pending_prefetch in main branch. This PR is calling with the original name.)

@stepinto

stepinto commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor Author

I tested TP8 with GLM5.2-W4A8 and DSv4 Flash on H20x8 box. I found some interesting findings:

  1. 27010 and baseline (bbbcbf9) produces similar TTFTs:
image image
  1. There is a potential optimization. check_prefetch_progress makes one more all-reduce even for wait_complete strategy or the prefetch has been completed. We could furture more make check_prefetch_progress free of all-reduce at all, by moving the timeout check to check_hicache_events. The effects of such optimization can be estimated as 20ms by column D, which does no all-reduce in check_prefetch_progress for wait_complete strategy.

  2. I think we could merge 27010 first and make two optimizations later. The first is to move all-reduce from check_prefetch_progress to the timeout branch in can_terminate_prefetch. This is a simple patch. Another is to do timeout check in check_hicache_events for all ongoing requests in a single all reduce, so that check_prefetch_progress will have no all-reduce at all.

My testing command are here, so that this could be reproduced by someone else.

nohup env HF_HUB_OFFLINE=1 \
SGLANG_ENABLE_UNIFIED_RADIX_TREE=1 \
sglang serve \
  --model-path=PhalaCloud/GLM-5.2-W4AFP8 \
  --tp-size=8 \
  --kv-cache-dtype fp8_e4m3 \
  --enable-hierarchical-cache \
  --hicache-storage-prefetch-policy wait_complete \
  --hicache-ratio=2 \
  --enable-metrics \
  --host=0.0.0.0 \
  --mem-fraction-static=0.75 \
  --hicache-ratio=2 \
  --reasoning-parser glm45 \
  --tool-call-parser glm47 \
  --hicache-storage-backend=mooncake \
  --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}' \
  > sglang.log 2>&1 &

nohup env HF_HUB_OFFLINE=1 \
    sglang serve \
    --model=deepseek-ai/DeepSeek-V4-Flash \
    --tp-size 8 \
    --moe-runner-backend flashinfer_mxfp4 \
    --disable-cuda-graph \
    --max-total-tokens=200000 \
    --mem-fraction-static 0.85 \
    --reasoning-parser deepseek-v4 \
    --tool-call-parser deepseekv4 \
    --host 0.0.0.0 \
    --port 30000 \
    --swa-full-tokens-ratio=0.4 \
    --hicache-ratio=2 \
    --enable-metrics \
    --enable-hierarchical-cache \
    --hicache-storage-backend=mooncake \
    --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}' \
    > sglang.log &


set -e
for i in $(seq 0 10); do
    python -m sglang.bench_serving  \
        --backend sglang \
        --flush-cache \
        --dataset-name random \
        --num-prompts 256 \
        --random-input 4096 \
        --random-output 1 \
        --random-range-ratio 1 \
        --model=deepseek-ai/DeepSeek-V4-Flash \
        --max-concurrency=16
done

@hzh0425

hzh0425 commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator
image

@hzh0425

hzh0425 commented Aug 25, 2026 •

Copy link
Copy Markdown
Collaborator

Let's merge this first and optimize the performance in next pr, Thanks @stepinto for the contribution and testing!

@hzh0425
hzh0425 merged commit 829138a into sgl-project:main Aug 25, 2026
402 of 435 checks passed
transfers_nonkv, operation.hash_value, kv_completed_pages
)
self._resolve_sidecar_nonkv_derived_pool_transfers(operation)
results = self.storage_backend.batch_get_v2(transfers_nonkv)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this has no sidercar "index"? lead to l3 cache hit is always zero?

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.

The indexer read are moved to _page_transfer_kv_batch in cache_controller.py. This is to fix a life-time issue #31668.

@MichoChan MichoChan Aug 27, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The indexer read are moved to _page_transfer_kv_batch in cache_controller.py. This is to fix a life-time issue #31668.

but i pick this pr and test, find the ack.pool_hits is empty, looks like ack.pool_hits is not set right in cache_controller or hybrid cache_controller ? this lead to the _clamp_prefetch_result return 0

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.

Do you have local changes? I have verified tihs test on my box just now. Could you try this with your code?

Code commit 829138a.

# sglang
nohup env HF_HUB_OFFLINE=1 \
SGLANG_ENABLE_UNIFIED_RADIX_TREE=1 \
sglang serve \
  --model-path=PhalaCloud/GLM-5.2-W4AFP8 \
  --pp-size=4 \
  --tp-size=2 \
  --max-total-tokens=$((512*1024)) \
  --enable-hierarchical-cache \
  --enable-metrics \
  --host=0.0.0.0 \
  --log-level=debug \
  --log-requests \
  --log-requests-format text \
  --log-requests-target stdout \
  --mem-fraction-static=0.75 \
  --hicache-ratio=2 \
  --reasoning-parser glm45 \
  --tool-call-parser glm47 \
  --hicache-storage-backend=mooncake \
  --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}' \
  > sglang.log &

set -e
for i in $(seq 0 10); do
    python benchmark/hicache/bench_multiturn.py  \
        --num-clients=1 \
        --num-rounds=1 \
        --disable-auto-run  \
        --model=PhalaCloud/GLM-5.2-W4AFP8  \
        --request-rate 1 \
        --request-length $((256*1024)) \
        --output-length 64
done

The test flushes L1&L2 cache each round. You should see, in round>1, there should be 99.9% cache hit ratio.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you have local changes? I have verified tihs test on my box just now. Could you try this with your code?

Code commit 829138a.

# sglang
nohup env HF_HUB_OFFLINE=1 \
SGLANG_ENABLE_UNIFIED_RADIX_TREE=1 \
sglang serve \
  --model-path=PhalaCloud/GLM-5.2-W4AFP8 \
  --pp-size=4 \
  --tp-size=2 \
  --max-total-tokens=$((512*1024)) \
  --enable-hierarchical-cache \
  --enable-metrics \
  --host=0.0.0.0 \
  --log-level=debug \
  --log-requests \
  --log-requests-format text \
  --log-requests-target stdout \
  --mem-fraction-static=0.75 \
  --hicache-ratio=2 \
  --reasoning-parser glm45 \
  --tool-call-parser glm47 \
  --hicache-storage-backend=mooncake \
  --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}' \
  > sglang.log &

set -e
for i in $(seq 0 10); do
    python benchmark/hicache/bench_multiturn.py  \
        --num-clients=1 \
        --num-rounds=1 \
        --disable-auto-run  \
        --model=PhalaCloud/GLM-5.2-W4AFP8  \
        --request-rate 1 \
        --request-length $((256*1024)) \
        --output-length 64
done

The test flushes L1&L2 cache each round. You should see, in round>1, there should be 99.9% cache hit ratio.

thanks, i am going to check my local code,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you have local changes? I have verified tihs test on my box just now. Could you try this with your code?

Code commit 829138a.

# sglang
nohup env HF_HUB_OFFLINE=1 \
SGLANG_ENABLE_UNIFIED_RADIX_TREE=1 \
sglang serve \
  --model-path=PhalaCloud/GLM-5.2-W4AFP8 \
  --pp-size=4 \
  --tp-size=2 \
  --max-total-tokens=$((512*1024)) \
  --enable-hierarchical-cache \
  --enable-metrics \
  --host=0.0.0.0 \
  --log-level=debug \
  --log-requests \
  --log-requests-format text \
  --log-requests-target stdout \
  --mem-fraction-static=0.75 \
  --hicache-ratio=2 \
  --reasoning-parser glm45 \
  --tool-call-parser glm47 \
  --hicache-storage-backend=mooncake \
  --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}' \
  > sglang.log &

set -e
for i in $(seq 0 10); do
    python benchmark/hicache/bench_multiturn.py  \
        --num-clients=1 \
        --num-rounds=1 \
        --disable-auto-run  \
        --model=PhalaCloud/GLM-5.2-W4AFP8  \
        --request-rate 1 \
        --request-length $((256*1024)) \
        --output-length 64
done

The test flushes L1&L2 cache each round. You should see, in round>1, there should be 99.9% cache hit ratio.

i find it, i don't set SGLANG_ENABLE_UNIFIED_RADIX_TREE, so my code would use hiradx_cache.py and clamp result with 0 index pool hits, so i think hiradix_cache also should don't use clamp result

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.

Do you have local changes? I have verified tihs test on my box just now. Could you try this with your code?
Code commit 829138a.

# sglang
nohup env HF_HUB_OFFLINE=1 \
SGLANG_ENABLE_UNIFIED_RADIX_TREE=1 \
sglang serve \
  --model-path=PhalaCloud/GLM-5.2-W4AFP8 \
  --pp-size=4 \
  --tp-size=2 \
  --max-total-tokens=$((512*1024)) \
  --enable-hierarchical-cache \
  --enable-metrics \
  --host=0.0.0.0 \
  --log-level=debug \
  --log-requests \
  --log-requests-format text \
  --log-requests-target stdout \
  --mem-fraction-static=0.75 \
  --hicache-ratio=2 \
  --reasoning-parser glm45 \
  --tool-call-parser glm47 \
  --hicache-storage-backend=mooncake \
  --hicache-storage-backend-extra-config '{"master_server_address": "127.0.0.1:50051", "local_hostname": "localhost", "metadata_server": "http://127.0.0.1:8080/metadata", "global_segment_size": "512gb", "protocol": "tcp"}' \
  > sglang.log &

set -e
for i in $(seq 0 10); do
    python benchmark/hicache/bench_multiturn.py  \
        --num-clients=1 \
        --num-rounds=1 \
        --disable-auto-run  \
        --model=PhalaCloud/GLM-5.2-W4AFP8  \
        --request-rate 1 \
        --request-length $((256*1024)) \
        --output-length 64
done

The test flushes L1&L2 cache each round. You should see, in round>1, there should be 99.9% cache hit ratio.

i find it, i don't set SGLANG_ENABLE_UNIFIED_RADIX_TREE, so my code would use hiradx_cache.py and clamp result with 0 index pool hits, so i think hiradix_cache also should don't use clamp result

Good. UnifiedRadixCache has been default since 35081.

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

Labels

bypass-fastfail hicache Hierarchical Caching for SGLang 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.

[PP + HiCache] HiCache Consistency Fix Plan