From e77bfba24d892563fb2d91192e8841b0c59c7828 Mon Sep 17 00:00:00 2001 From: Ke Bao Date: Fri, 10 Apr 2026 11:40:54 +0800 Subject: [PATCH] Fix NCCL AllGather hanging issue for Qwen3 Next MTP (#22458) --- python/sglang/srt/speculative/eagle_info.py | 19 +++++++++++++++++++ .../sglang/srt/speculative/eagle_info_v2.py | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/python/sglang/srt/speculative/eagle_info.py b/python/sglang/srt/speculative/eagle_info.py index ddb475299..c1eee1298 100644 --- a/python/sglang/srt/speculative/eagle_info.py +++ b/python/sglang/srt/speculative/eagle_info.py @@ -7,8 +7,13 @@ import torch import torch.nn.functional as F from sglang.srt.constrained.base_grammar_backend import BaseGrammarObject +from sglang.srt.distributed import get_tp_group from sglang.srt.environ import envs from sglang.srt.layers.attention.utils import create_flashinfer_kv_indices_triton +from sglang.srt.layers.dp_attention import ( + get_attention_tp_group, + is_dp_attention_enabled, +) from sglang.srt.layers.logits_processor import LogitsProcessorOutput from sglang.srt.layers.sampler import apply_custom_logit_processor from sglang.srt.managers.overlap_utils import FutureIndices @@ -377,6 +382,20 @@ class EagleVerifyInput(SpecInput, EagleVerifyInputV2Mixin): deterministic=True, ) + # Sync sampling results across TP ranks: different GPUs may + # produce slightly different target_probs due to floating-point + # non-determinism in softmax/top_k/top_p, causing different + # sampled tokens. Broadcast from rank 0 to ensure consistency. + tp_group = ( + get_attention_tp_group() + if is_dp_attention_enabled() + else get_tp_group() + ) + if tp_group.world_size > 1: + tp_group.broadcast(predict, src=0) + tp_group.broadcast(accept_index, src=0) + tp_group.broadcast(accept_length, src=0) + if SIMULATE_ACC_LEN > 0.0: # Do simulation accept_index = generate_simulated_accept_index( diff --git a/python/sglang/srt/speculative/eagle_info_v2.py b/python/sglang/srt/speculative/eagle_info_v2.py index 7c90f83b7..1be28c38f 100644 --- a/python/sglang/srt/speculative/eagle_info_v2.py +++ b/python/sglang/srt/speculative/eagle_info_v2.py @@ -8,6 +8,11 @@ import torch.nn.functional as F import triton import triton.language as tl +from sglang.srt.distributed import get_tp_group +from sglang.srt.layers.dp_attention import ( + get_attention_tp_group, + is_dp_attention_enabled, +) from sglang.srt.layers.logits_processor import LogitsProcessorOutput from sglang.srt.managers.schedule_batch import ModelWorkerBatch, ScheduleBatch from sglang.srt.managers.utils import get_alloc_len_per_decode @@ -412,6 +417,20 @@ class EagleVerifyInputV2Mixin: deterministic=True, ) + # Sync sampling results across TP ranks: different GPUs may + # produce slightly different target_probs due to floating-point + # non-determinism in softmax/top_k/top_p, causing different + # sampled tokens. Broadcast from rank 0 to ensure consistency. + tp_group = ( + get_attention_tp_group() + if is_dp_attention_enabled() + else get_tp_group() + ) + if tp_group.world_size > 1: + tp_group.broadcast(predict, src=0) + tp_group.broadcast(accept_index, src=0) + tp_group.broadcast(accept_length, src=0) + if SIMULATE_ACC_LEN > 0: # Do simulation accept_index = generate_simulated_accept_index(