[Bug] TorchDist.allgather splits Tensor vs non-Tensor into incompatible collectives and crashes on variable-shape tensors across ranks

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

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

@ankitgala007 がすでに取り組んでいます。

2026年11月28日 から。

  • #23020 @ankitgala007 による — オープン

評価

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

調査の方向性

Start at tensorrt_llm/_torch/distributed/communicator.py in TorchDist.allgather, and compare it with MPIDist.allgather. Run the issue’s two-rank Gloo reproduction for heterogeneous payload kinds and variable-shape tensors; the fix is done when both cases complete without a collective mismatch, hang, or Gloo abort.

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

説明

Pytorch Scale-out
Summary

In tensorrt_llm/_torch/distributed/communicator.py:1553-1566 (TorchDist.allgather, commit 350ca54f4533013b42ae49ab6517d19961115666), unlike its sibling MPIDist.allgather(obj) (which uniformly serializes arbitrary Python objects via pickle), TorchDist.allgather(obj) branches on local isinstance(obj, torch.Tensor):

if isinstance(obj, torch.Tensor):
    output_list = [torch.empty_like(obj) for _ in range(self.world_size)]
    dist.all_gather(output_list, obj)
    return output_list
elif vote_pg is not None:
    return self._cuda_allgather_object(obj, vote_pg)
else:
    obj_list = [None] * self.world_size
    dist.all_gather_object(obj_list, obj)
    return obj_list

This causes two failures when used as a drop-in counterpart to MPIDist.allgather:

  1. Cross-rank deadlock / C++ abort on Tensor vs None (or heterogeneous objects): If rank 0 passes a torch.Tensor and rank 1 passes None, rank 0 enters dist.all_gather while rank 1 enters dist.all_gather_object, aborting C++ Gloo with gloo::EnforceNotMet (op.nread == op.preamble.nbytes) or hanging indefinitely.
  2. Abort on variable-shape torch.Tensor payloads across ranks: [torch.empty_like(obj) for _ in range(world_size)] assumes every rank holds the exact same tensor shape and dtype. When tensor lengths differ across ranks (which MPIDist.allgather supports seamlessly), C++ Gloo aborts with op.nread == op.preamble.nbytes.
Affected Location
  • Repository: NVIDIA/TensorRT-LLM (350ca54f4533013b42ae49ab6517d19961115666, present at HEAD)
  • File & lines: tensorrt_llm/_torch/distributed/communicator.py:1553-1566 (TorchDist.allgather)
Minimal Standalone Reproduction
import datetime, torch, torch.distributed as dist

# Two ranks initialized with dist.init_process_group("gloo", ...):
# Case 1 (heterogeneous payload): rank 0 calls td.allgather(torch.tensor([1, 2])), rank 1 calls td.allgather(None)
# Case 2 (variable shape): rank 0 calls td.allgather(torch.arange(2)), rank 1 calls td.allgather(torch.arange(5))

Observed output under 2-rank Gloo spawn:
libc++abi: terminating due to uncaught exception of type gloo::EnforceNotMet: [enforce fail at .../gloo/transport/uv/pair.cc:253] op.nread == op.preamble.nbytes.

Suggested Fix

Either keep TorchDist.allgather(obj) consistent with MPIDist.allgather(obj) via all_gather_object (with a dedicated typed method or explicit uniform-tensor precondition when tensor-only fast-path all_gather is requested), or agree on shape/kind across ranks before choosing dist.all_gather vs dist.all_gather_object.

主要言語
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 を短くまとめたダイジェスト。