gloo: `send`/`recv` draw from the same per-group tag counter as collectives, so an intervening send/recv desyncs the next `broadcast`/`all_reduce` → `TIMEOUT`
bug描述 Describe the Bug
Environment:
- paddle 3.2.2 (pip wheel), CPU-only build (
cuda: False,nccl: 0) - OS: Ubuntu, Linux 6.17, aarch64
- Python 3.12.14
- Backend: gloo, 4 ranks, single node, launched with
paddle.distributed.launch
Minimal repro (issue2_tag_desync.py, no external deps beyond paddle):
"""Minimal repro: gloo send/recv between two ranks desyncs the per-group
tag counter, and a later group-wide broadcast then TIMEOUTs.
"""
# paddlepaddle == 3.2.2
import paddle
import paddle.distributed as dist
g = dist.init_parallel_env()
rank = dist.get_rank()
t = paddle.to_tensor([rank * 1.0])
dist.broadcast(t, src=0, group=g)
print(f"[rank {rank}] broadcast #1 ok", flush=True)
# Only ranks 0 and 1 call next_tag() here; ranks 2 and 3 do not.
if rank == 0:
dist.send(paddle.to_tensor([1.0]), dst=1, group=g)
elif rank == 1:
recv_buf = paddle.to_tensor([0.0])
dist.recv(recv_buf, src=0, group=g)
# All 4 ranks now disagree on the next tag value -> TIMEOUT.
t2 = paddle.to_tensor([rank * 1.0])
dist.broadcast(t2, src=0, group=g)
print(f"[rank {rank}] broadcast #2 ok", flush=True)Command (4 ranks, one process each, CPU only):
export CUDA_VISIBLE_DEVICES="" GLOO_SOCKET_IFNAME=lo PADDLE_DISTRI_BACKEND=gloo
for r in 0 1 2 3; do
python3 -m paddle.distributed.launch --nnodes 4 --master 127.0.0.1:29751 \
--rank $r --log_dir log-$r issue2_tag_desync.py &
done
wait(As a control: removing the send/recv block and running just the two broadcast calls back to back completes both broadcasts on all 4 ranks every time.)
Actual output. This reproduces deterministically; all 4 ranks fail the second broadcast (rank 0 shown):
[rank 0] broadcast #1 ok
Traceback (most recent call last):
File "issue2_tag_desync.py", line 24, in <module>
dist.broadcast(t2, src=0, group=g)
File ".../paddle/distributed/communication/broadcast.py", line 74, in broadcast
return stream.broadcast(
File ".../paddle/distributed/communication/stream/broadcast.py", line 147, in broadcast
return _broadcast_in_dygraph(
File ".../paddle/distributed/communication/stream/broadcast.py", line 43, in _broadcast_in_dygraph
task = group.process_group.broadcast(tensor, src_rank_in_group, sync_op)
RuntimeError: [/paddle/third_party/gloo/gloo/transport/tcp/unbound_buffer.cc:136] TIMEOUT self_rank = 1 pair_rank = none peer_str = noneExpected: the second broadcast on the same group completes normally after an intervening send/recv between only two of the group's ranks.
其他补充信息 Additional Supplementary Information
Source (develop):
paddle/fluid/distributed/collective/process_group_gloo.h, line 187:uint64_t next_tag() { return _tag++; }_tagis a single per-ProcessGroupGloocounter with no cross-rank coordination.paddle/fluid/distributed/collective/process_group_gloo.cc: every operation exceptBarriercallsnext_tag()exactly once —Sendat line 269,Recvat line 314, and every other collective (Broadcast,AllReduce,AllGather,Reduce,Scatter,Gather) at lines 225, 379, 463, 516, 581, 643.
Send/Recv are only invoked by the two participating ranks, so only their _tag counters advance; a group-wide collective called by all ranks right after then computes a different tag on different ranks, and gloo waits for a message tagged for a peer that never sends it.
Torch's gloo send/recv (torch/csrc/distributed/c10d/ProcessGroupGloo.cpp, ProcessGroupGloo::send/::recv) take an explicit, caller-supplied tag parameter and never touch collectiveCounter_ (the counter nextTag() increments for actual collectives) — the two are fully independent, so p2p ops can never desync a later collective's tag there.
Suggested fix: give Send/Recv their own tag space, independent of the counter collectives use for next_tag() — e.g. a per-peer (src, dst) counter, or a caller-supplied tag as torch does (a single shared p2p counter would still desync as soon as one rank talks to two different peers).
Same code is present on v3.0.0 and v3.1.0, with line numbers shifted by at most 1.
Found while testing subgroup loading in fastsafetensors (foundation-model-stack/fastsafetensors).
Source: PaddlePaddle/Paddle