Repository navigation
Fix TP deadlock in unified radix cache writing_check / loading_check - #27489
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the writing_check and loading_check methods in unified_radix_cache.py by removing early returns that depend on local state variables (ongoing_write_through and ongoing_load_back). This ensures that all ranks consistently participate in collective communication operations (like all_reduce), preventing potential hangs when states diverge across ranks. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/tag-and-rerun-ci |
|
/rerun-group radix_cache/unified_radix_tree hicache |
|
Results for 🚀 🚀 🚀 🚀 🚀 |
…he writing_check Complement to sgl-project#27489 (which fixed UnifiedRadixCache only). Related: sgl-project#26923, sgl-project#26921. writing_check conditionally skipped the all_reduce when ongoing_write_through was empty. ongoing_write_through can diverge across ranks (e.g. write_backup returning 0 on a subset under host memory pressure), so the skip desyncs the NCCL op sequence -> deadlock under TP > 1. HiMambaRadixCache: - make all_reduce unconditional in writing_check - add all_reduce(MIN) sync to loading_check (previously had none) HiRadixCache: - make all_reduce unconditional in writing_check (loading_check already had all_reduce via sgl-project#27285) Both now match UnifiedRadixCache (sgl-project#27489). Co-Authored-By: Claude <[email protected]>
…-project#601 and sgl-project#628 Merge target: d958a63 "Return bad request for malformed DSV4 tool arguments (sgl-project#602)". Excludes b4de164 (sgl-project#601 "Fix DSV4 C128 state mapping lifecycle") and f59f166 (sgl-project#628 "Sync clean SM90 FP8+FP4 MegaMoE from main") per user instruction. Brings in 13 upstream commits including: - 3e31718 [HiCache] DeepSeek-V4 host-mem L2 + NVMe/disk L3 (sgl-project#564) - 6dddb6d Fix DSv4 draft extend replay forward batch (sgl-project#569) - 9d212a9 add observability (sgl-project#570) - 104a38d Bytedance/deepseek v4 fix draft extend padding (sgl-project#573) - d958a63 Return bad request for malformed DSV4 tool arguments (sgl-project#602) - 8 docker/codex build hardening commits Conflict resolutions (all 8 files stability-critical, memory-related): 1. tree_component.py / full_component.py / swa_component.py / mamba_component.py -- commit_hicache_transfer signature: keep HEAD's typed (insert_result, pool_storage_result) kwargs. Callers in unified_radix_cache.py explicitly pass these; their **kw variant is strictly a superset but less safe. Also drop their side's manual `kw.get(...)` extraction in mamba PREFETCH branch since the params are now directly bound. 2. hybrid_cache_controller.py -- extra_host_mem_release_queues type annotation: keep HEAD's Queue[torch.Tensor] (more precise). 3. swa_memory_pool.py -- their side added a full duplicate SWATokenToKVPoolAllocator class inline in this file, but our fork moved the class to allocator/swa.py in an earlier refactor. Drop their duplicate; instead apply sgl-project#573's free_swa fix (guard against negative sentinels and out-of-range indices, expand page-aligned free) directly to allocator/swa.py where the class actually lives. 4. hybrid_pool_assembler.py: - kvcache.compress_state_pools indexing: keep either form (addition is commutative); use HEAD's ordering for local consistency. - C128 state pool registration: keep HEAD's explicit non-registration with the "C128 State pool intentionally not registered" comment. Our HEAD's upstream sgl-project#27293 deliberately opted out; their side (from before sgl-project#601) still registers it. Silently reintroducing the pool would regress the fix and pressure host memory. - attach_hybrid_pool_to_unified_cache body: keep HEAD's _select_strategy(...).build() dispatch (from upstream sgl-project#26295) over their 245-line inline if-elif chain. Our _DeepSeekV4Strategy already handles the deepseek_v4 stack; the strategy signature already accepts storage_backend / storage_extra_config / storage_prefetch_threshold. 5. unified_radix_cache.py (24 conflicts) -- keep HEAD wholesale: - HEAD has 10 methods theirs lacks (all from upstream sgl-project#26881, sgl-project#27285, sgl-project#27391, sgl-project#27489, sgl-project#27554, sgl-project#27655 L3 support + our PR sgl-project#27010 port: prefetch_sync_thread, ack-driven sync, handle_prefetch_result, _drain_async_work, _finish_write_through_ack, etc.) - Their only extra method (terminate_prefetch(rid)) was deliberately removed by our PR sgl-project#27010 port. - HEAD's load_back_threshold=10 matches hi_mamba_radix_cache and hiradix_cache (theirs=256 was an inconsistent local tuning). - HEAD passes total_len to InsertResult (dataclass field exists) and priority to UnifiedTreeNode (LRU correctness). - HEAD's write_backup early-returns on written==0 (upstream sgl-project#27108 safety fix); theirs drops the check. - HEAD's _drain_queue is blocking with qsize MIN-reduce (our PR sgl-project#27010's lockstep drain); theirs is old get_nowait+Empty pattern that would desync PP/TP. - sgl-project#564's L2/L3 additions in this file are functionally covered by upstream sgl-project#26881 (already in HEAD via ep_main). No net feature loss from taking HEAD. Verified: AST parse OK for all 9 mem_cache files, compileall exit=0 on managers + mem_cache trees. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Motivation
A permanent TP deadlock has been observed in
UnifiedRadixCache.writing_checkafter a long run with HiCache enabled. py-spy fingerprint:all_reduce → writing_check → check_hicache_events → get_new_batch_prefill_raw → event_loop_overlapbroadcast → broadcast_pyobj → recv_requests → event_loop_overlap(next iteration)TP0 entered the all_reduce in
writing_checkwhile TP1-3 took the early-return path on emptyongoing_write_throughand advanced to the next event-loop iteration'srecv_requestsbroadcast. Mismatched collectives → 300s watchdog → process kill.loading_checkhas the same anti-pattern (early-return on emptyongoing_load_backbefore an all_reduce) and is fixed alongside.Fix
Always enter the all_reduce regardless of local queue state. An empty local queue contributes 0 to the MIN-reduce; the
while finish_count > 0loop becomes a no-op. Cheap and collective-safe.Tradeoff
Removing the early-return does not address the underlying source of cross-rank
ongoing_write_throughdivergence (e.g.write_backupreturning 0 on a subset of ranks when host-pool alloc or aux-pool alloc fails). With this fix the process no longer deadlocks, but the divergent entries can be left undrained — manifesting as slow host-pool / lock-ref leak rather than a hard hang. A follow-up will makewrite_backupenqueue decisions themselves collective-consistent.CI States
Latest PR Test (Base): 🚫 Run #27088062621
Latest PR Test (Extra): ❌ Run #27088062560