From d03182cd2d54ca7e670530f826b08146bc56728b Mon Sep 17 00:00:00 2001 From: Ke Bao Date: Mon, 8 Jun 2026 16:08:47 +0800 Subject: [PATCH] Fix TP deadlock in unified radix cache writing_check / loading_check (#27489) --- python/sglang/srt/mem_cache/unified_radix_cache.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/sglang/srt/mem_cache/unified_radix_cache.py b/python/sglang/srt/mem_cache/unified_radix_cache.py index 455a656fc..484b2b633 100644 --- a/python/sglang/srt/mem_cache/unified_radix_cache.py +++ b/python/sglang/srt/mem_cache/unified_radix_cache.py @@ -2258,9 +2258,8 @@ class UnifiedRadixCache(KVCacheEventMixin, BasePrefixCache): assert len(self.ongoing_write_through) == 0 return - if len(self.ongoing_write_through) == 0: - return - + # Every rank must enter the all_reduce below; ongoing_write_through can + # diverge across ranks (e.g. write_backup returning 0 on a subset). finish_count = 0 if self.pp_rank == 0: for _, finish_event, ack_list in cc.ack_write_queue: @@ -2283,8 +2282,10 @@ class UnifiedRadixCache(KVCacheEventMixin, BasePrefixCache): def loading_check(self) -> None: """Poll load-back completions.""" cc = self.cache_controller - if cc is None or not self.ongoing_load_back: + if cc is None: return + # Every rank must enter the all_reduce below; ongoing_load_back can + # diverge across ranks. finish_count = 0 if self.pp_rank == 0: for _, finish_event, ack_list in cc.ack_load_queue: