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

オープン
#23,029 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@bojiang-li がすでに取り組んでいます。

2026年11月29日 から。

  • #23034 @bojiang-li による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python, pytorch

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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).
主要言語
Python
スター
15.2k
フォーク
3k
平均マージ
2日 21時間
マージ済み PR(30日)
477

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/TensorRT-LLM のほかの issue

NVIDIA/TensorRT-LLM の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。