From b62b21e7f4e2d81e6b14babe6ca3b036f9890326 Mon Sep 17 00:00:00 2001 From: Shuwen Wang <47200617+alphabetc1@users.noreply.github.com> Date: Thu, 1 Oct 2026 10:22:30 +0800 Subject: [PATCH] [HiCache][PD] fix: keep decode load-back polling out of rank-local collectives (#41393) --- .../srt/disaggregation/decode_hicache_mixin.py | 9 ++------- .../srt/mem_cache/unified_radix_cache.py | 18 ++++++------------ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/python/sglang/srt/disaggregation/decode_hicache_mixin.py b/python/sglang/srt/disaggregation/decode_hicache_mixin.py index e5a51fb926..7d75dfa79f 100644 --- a/python/sglang/srt/disaggregation/decode_hicache_mixin.py +++ b/python/sglang/srt/disaggregation/decode_hicache_mixin.py @@ -288,13 +288,8 @@ class DecodeHiCacheTransferMixin: ): dr.hicache_restore_status = HiCacheRestoreResult.READY - # Phase B: queue new load_back ops if the next slot is free. - # The (producer_index + 1) check ensures we never overwrite a still-in-flight slot: - # if a previous req holds that slot and isn't done, its event won't be signaled. - counter = self.tree_cache.cache_controller.layer_done_counter - if not self.tree_cache.is_load_back_event_done( - (counter.producer_index + 1) % counter.num_counters - ): + # Phase B: queue new load_back ops if the next slot is free on every rank. + if not self.tree_cache.has_free_load_back_slot(): return queued = [ dr diff --git a/python/sglang/srt/mem_cache/unified_radix_cache.py b/python/sglang/srt/mem_cache/unified_radix_cache.py index bf81330713..0e502fe1ac 100644 --- a/python/sglang/srt/mem_cache/unified_radix_cache.py +++ b/python/sglang/srt/mem_cache/unified_radix_cache.py @@ -3533,25 +3533,19 @@ class UnifiedRadixCache(BasePrefixCache): return 0 def is_load_back_event_done(self, consumer_index: int) -> bool: - """Return True after the local load-back event is complete. - - Lets the disagg decode restore state machine - (``DecodeHiCacheTransferMixin``) gate on load-back completion; the - controller-level ``layer_done_counter`` event is shared across cache - implementations, while the tree-side bookkeeping runs in - ``loading_check``. - """ + """Return True after this rank's load-back event is complete.""" if consumer_index < 0 or self.cache_controller is None: return True finish_event = self.cache_controller.layer_done_counter.events[ consumer_index ].finish_event - if not finish_event.query(): - return False + return finish_event.query() - self.loading_check() - return True + def has_free_load_back_slot(self) -> bool: + """Acks are reaped in lockstep, so every rank agrees on this.""" + cc = self.cache_controller + return len(cc.ack_load_queue) < cc.layer_done_counter.num_counters # ---- Query / Inspection APIs ---- # These APIs exist for compatibility with other RadixTree implementations.