Repository navigation
[HiCache] Fix PP inconsistency with HiCache L3 (#22607) - #27010
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
@hzh0425 @ShangmingCai can you help review this ? |
|
/tag-and-rerun-ci |
| 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 :] | ||
| ) |
There was a problem hiding this comment.
Should we add operation.completed_tokens = ack.completed_tokens in between to avoid potential double free?
There was a problem hiding this comment.
Fixed. My code was buggy. Nice catch!
| 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] | ||
| ) |
There was a problem hiding this comment.
What about a partial fetch failure? Should we handle middle tokens by append_host_mem_release to prevent a memory leak?
There was a problem hiding this comment.
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.
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
|
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): |
|
Resolved conflicts again. |
|
Update to latest to take fix to failure |
|
Fixed a mis-spelled function calling due to code merge. ( |
|
I tested TP8 with GLM5.2-W4A8 and DSv4 Flash on H20x8 box. I found some interesting findings:
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 |
|
Let's merge this first and optimize the performance in next pr, Thanks @stepinto for the contribution and testing! |
| 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) |
There was a problem hiding this comment.
this has no sidercar "index"? lead to l3 cache hit is always zero?
There was a problem hiding this comment.
The indexer read are moved to _page_transfer_kv_batch in cache_controller.py. This is to fix a life-time issue #31668.
There was a problem hiding this comment.
The indexer read are moved to
_page_transfer_kv_batchincache_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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 doneThe 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,
There was a problem hiding this comment.
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 doneThe 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
There was a problem hiding this comment.
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 doneThe 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.



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.
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.
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_progressworks. 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 threadprefetch_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:
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:
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-rateis set to1so that L3 prefetch are performed and not limited by budget.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
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #32801836475
Latest PR Test (Extra): ✅ Run #32801836390
Latest PR Test (AMD ROCm 7.2): ❌ Run #32801836438