[Bug] TorchDist subgroup broadcast/gather passes group-local root=0/dst=0 as global rank, crashing non-zero subgroups and hanging tp_cp_broadcast

Đang mở
#23,029 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@bojiang-li đang làm issue này rồi.

Từ ngày 29/11/2026.

  • #23034 của @bojiang-li — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python, pytorch

Hướng nghiên cứu

Read tensorrt_llm/_torch/distributed/communicator.py, especially TorchDist subgroup gather and broadcast methods and the CUDA object-collective helpers. First trace how callers pass group-local roots, then run a multi-process test with nonzero subgroups; done means gather and broadcast work across the described TP, PP, and CP layouts without rank errors or hangs. The issue links open pull request #23034, so work may already be underway.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Pytorch Scale-out
Summary

In tensorrt_llm/_torch/distributed/communicator.py (commit 1aa0192e62d219599930f125ada7067081fb44b7, present at HEAD), TorchDist subgroup broadcast and gather collectives pass group-local root=0 / dst=0 directly as PyTorch global ranks and compare torch.distributed.get_rank() == root/dst:

# tensorrt_llm/_torch/distributed/communicator.py:1741-1801, 1839-1884
@log_op
def tp_gather(self, obj, dst=0):
    global_rank = torch.distributed.get_rank()
    if isinstance(obj, torch.Tensor):
        if global_rank == dst:
            output_list = [
                torch.empty_like(obj)
                for _ in range(self.mapping.tp_group_pg.size())
            ]
        else:
            output_list = None
        dist.gather(obj, output_list, dst=dst, group=self.mapping.tp_group_pg)
        return output_list
    elif (vote_pg := self._cuda_obj_pg("tp")) is not None:
        return self._cuda_gather_object(obj, vote_pg, dst)
    else:
        ...
        if global_rank == dst:
            output_list = [None] * self.mapping.tp_group_pg.size()
        else:
            output_list = None
        dist.gather_object(obj, output_list, dst=dst, group=self.mapping.tp_group_pg)
        return output_list

@log_op
def tp_broadcast(self, obj, root=0, **kwargs):
    if isinstance(obj, torch.Tensor):
        dist.broadcast(obj, src=root, group=self.mapping.tp_group_pg)
        return obj
    elif (vote_pg := self._cuda_obj_pg("tp")) is not None:
        return self._cuda_broadcast_object(obj, vote_pg, root)
    else:
        ret = [obj]
        torch.distributed.broadcast_object_list(
            ret, src=root, group=self.mapping.tp_group_pg, device=torch.device("cpu")
        )
        return ret[0]

The identical pattern appears in cp_broadcast (1788-1801), pp_gather (1840-1867), pp_broadcast (1870-1883), _cuda_gather_object (1361-1368, is_dst = torch.distributed.get_rank() == dst), and _cuda_broadcast_object (1398-1479, is_root = torch.distributed.get_rank() == root and dist.broadcast(..., src=root, group=pg)).

Unlike MPIDist (914-935), where root=0/dst=0 on tp_comm/pp_comm/cp_comm is group-local rank 0 (and callers such as AutoTuner._broadcast_cache_data at autotuner.py:3179, py_executor.py:282, py_executor.py:8059-8076, and glm_5_3_flash_nvfp4__sm_10x__tp4/modeling.py:402 rely on group-local root=0), PyTorch's dist.broadcast(..., group=pg), dist.broadcast_object_list(..., group=pg), dist.gather(..., group=pg), and dist.gather_object(..., group=pg) require src/dst to be a global rank belonging to pg.

Consequently, under any 2D/3D parallelism where a subgroup excludes global rank 0 (PP > 1, TP > 1; TP > 1, CP > 1; or ADP + PP > 1):

  1. Every non-zero subgroup (e.g., PP stage >= 1 TP groups [2, 3], TP rank >= 1 PP groups [1, 3]) immediately crashes with ValueError: Global rank 0 is not part of group.
  2. In Distributed.tp_cp_broadcast(obj, root=0) under PP=1, TP=2, CP=2 (tp0=[0, 2], tp1=[1, 3], cp0=[0, 1], cp1=[2, 3]), ranks 1 and 3 crash in tp_broadcast, rank 2 succeeds in tp_broadcast and crashes in cp_broadcast, and rank 0 succeeds in tp_broadcast and hangs inside cp_broadcast waiting on crashed rank 1.
Affected Location
  • Repository: NVIDIA/TensorRT-LLM (1aa0192e62d219599930f125ada7067081fb44b7, present at HEAD)
  • File & lines:
    • tensorrt_llm/_torch/distributed/communicator.py:1361-1368,1398-1479,1742-1883 (TorchDist._cuda_gather_object, _cuda_broadcast_object, tp_gather, tp_broadcast, cp_broadcast, pp_gather, pp_broadcast)
Minimal Standalone Reproduction
import datetime, types
import torch.distributed as dist
import torch.multiprocessing as mp
from tensorrt_llm._torch.distributed.communicator import TorchDist

def worker(rank, port):
    dist.init_process_group(
        "gloo", init_method=f"tcp://127.0.0.1:{port}", rank=rank, world_size=4,
        timeout=datetime.timedelta(seconds=3),
    )
    # Example 1: PP=2, TP=2 -> tp0=[0,1], tp1=[2,3], pp0=[0,2], pp1=[1,3]
    tp0, tp1 = dist.new_group([0, 1]), dist.new_group([2, 3])
    pp0, pp1 = dist.new_group([0, 2]), dist.new_group([1, 3])
    mapping = types.SimpleNamespace(
        tp_size=2, cp_size=1, pp_size=2,
        tp_group_pg=tp0 if rank in (0, 1) else tp1,
        pp_group_pg=pp0 if rank in (0, 2) else pp1,
        cp_group_pg=None,
    )
    td = TorchDist(mapping)
    print(rank, td.pp_broadcast(rank in (0, 1), root=0))
    print(rank, td.tp_cp_broadcast({"tactic": rank}, root=0))

Observed behavior / output (4-process Gloo execution against verbatim communicator.py):

  • Under PP=2, TP=2:
    • Ranks 1 and 3 (pp1=[1, 3]) immediately raise ValueError: Global rank 0 is not part of group in pp_broadcast(..., root=0) and pp_gather(..., dst=0).
    • Ranks 2 and 3 (tp1=[2, 3]) immediately raise ValueError: Global rank 0 is not part of group in tp_cp_broadcast(..., root=0) and tp_gather(..., dst=0).
  • Under PP=1, TP=2, CP=2:
    • tp_broadcast(..., root=0) crashes on ranks 1 and 3 (tp1=[1, 3]); cp_broadcast(..., root=0) crashes on ranks 2 and 3 (cp1=[2, 3]).
    • Calling td.tp_cp_broadcast({"k": rank}, root=0) crashes ranks 1, 2, 3 with ValueError: Global rank 0 is not part of group while rank 0 hangs inside cp_broadcast (alive_after_timeout = [True, False, False, False]).
  • Note: _cuda_broadcast_object and _cuda_gather_object share the exact same torch.distributed.get_rank() == root/dst and raw src=root/dst=dst bug on the CUDA object-collective fast path (hardware-gated for live CUDA/NCCL execution).
Suggested Fix
  1. Resolve group-local root/dst to the corresponding global rank via global_root = dist.get_global_rank(pg, root) (and global_dst = dist.get_global_rank(pg, dst)) before passing src/dst to dist.broadcast, dist.broadcast_object_list, dist.gather, dist.gather_object, _cuda_broadcast_object, and _cuda_gather_object.
  2. In tp_gather, pp_gather, _cuda_gather_object, and _cuda_broadcast_object, check group membership via group-local rank (dist.get_rank(pg) == local_root or torch.distributed.get_rank() == global_root) rather than comparing global rank directly against 0.
  3. Add a multi-GPU unit test covering PP=2, TP=2 and PP=1, TP=2, CP=2 (extending test_ops.py, which currently only tests PP=1, TP=1, CP=2).
Ngôn ngữ chính
Python
Star
15.2k
Fork
3k
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
477

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NVIDIA/TensorRT-LLM

Tất cả issue của NVIDIA/TensorRT-LLM

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.