From 6dd2f774de8d61d1b79beb6c5299cf377f797167 Mon Sep 17 00:00:00 2001 From: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Date: Thu, 2 Apr 2026 08:44:55 +0800 Subject: [PATCH] [HiCache & PD]Fixed detailed cache hit breakdown in PD scenarios. (#21764) --- python/sglang/srt/disaggregation/decode.py | 3 +++ python/sglang/srt/disaggregation/utils.py | 3 +++ .../scheduler_output_processor_mixin.py | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/python/sglang/srt/disaggregation/decode.py b/python/sglang/srt/disaggregation/decode.py index 92bb34bf1..1af8afb98 100644 --- a/python/sglang/srt/disaggregation/decode.py +++ b/python/sglang/srt/disaggregation/decode.py @@ -959,6 +959,9 @@ class DecodeTransferQueue: # Case 3: Success - commit the transfer decode_req.req.output_ids.append(output_id[0].item()) decode_req.req.cached_tokens = cached_tokens[0].item() + decode_req.req.cached_tokens_device = cached_tokens[1].item() + decode_req.req.cached_tokens_host = cached_tokens[2].item() + decode_req.req.cached_tokens_storage = cached_tokens[3].item() if not self.spec_algorithm.is_none(): decode_req.req.output_topk_p = output_topk_p decode_req.req.output_topk_index = output_topk_index diff --git a/python/sglang/srt/disaggregation/utils.py b/python/sglang/srt/disaggregation/utils.py index 636b86986..d7956a604 100644 --- a/python/sglang/srt/disaggregation/utils.py +++ b/python/sglang/srt/disaggregation/utils.py @@ -251,6 +251,9 @@ class MetadataBuffers: self.output_ids[req.metadata_buffer_index][0] = req.output_ids[0] self.cached_tokens[req.metadata_buffer_index][0] = req.cached_tokens + self.cached_tokens[req.metadata_buffer_index][1] = req.cached_tokens_device + self.cached_tokens[req.metadata_buffer_index][2] = req.cached_tokens_host + self.cached_tokens[req.metadata_buffer_index][3] = req.cached_tokens_storage if req.return_logprob: if req.output_token_logprobs_val: # not none or empty list self.output_token_logprobs_val[req.metadata_buffer_index][0] = ( diff --git a/python/sglang/srt/managers/scheduler_output_processor_mixin.py b/python/sglang/srt/managers/scheduler_output_processor_mixin.py index 570cc81c2..ef31d34d6 100644 --- a/python/sglang/srt/managers/scheduler_output_processor_mixin.py +++ b/python/sglang/srt/managers/scheduler_output_processor_mixin.py @@ -55,15 +55,10 @@ class SchedulerOutputProcessorMixin: """Get detailed cache breakdown for a request, if available. Returns: - - None if HiCache is not enabled - - {"device": X, "host": Y} if HiCache enabled but L3 storage is not - - {"device": X, "host": Y, "storage": Z, "storage_backend": "..."} if L3 enabled + - None if no cached tokens at all + - {"device": X, "host": Y} without storage breakdown + - {"device": X, "host": Y, "storage": Z} with storage breakdown """ - # Only show details if HiCache is enabled - if not getattr(self, "enable_hierarchical_cache", False): - return None - - # Only show if there are any cached tokens if ( req.cached_tokens_device > 0 or req.cached_tokens_host > 0 @@ -78,6 +73,13 @@ class SchedulerOutputProcessorMixin: details["storage"] = req.cached_tokens_storage details["storage_backend"] = self._get_storage_backend_type() return details + + if req.cached_tokens > 0: + return { + "device": req.cached_tokens, + "host": 0, + } + return None def process_batch_result_prebuilt(self: Scheduler, batch: ScheduleBatch):