|
| 1 | +# PyTorch Collectives |
| 2 | + |
| 3 | +Small `torch.distributed` loops that drive sustained traffic over the |
| 4 | +intranode GPU interconnect — **XGMI** on AMD (RCCL) or **NVLink** on |
| 5 | +NVIDIA (NCCL). Run one in a shell and watch the `amdgpu<N>` / |
| 6 | +`nvidia<N>` rows in `rdmatop` from another. |
| 7 | + |
| 8 | +Collectives are symmetric: every GPU talks to every peer, so all |
| 9 | +interconnect rows light up with roughly equal TX/RX, and the per-peer |
| 10 | +detail pane shows traffic on every link. |
| 11 | + |
| 12 | +| Script | Collective | TX per GPU per iteration | |
| 13 | +|--------------------|-------------------------|-----------------------------| |
| 14 | +| `allgather.py` | `all_gather` | `(world-1) * buffer` | |
| 15 | +| `allreduce.py` | `all_reduce` | `~2*(world-1)/world * buffer` | |
| 16 | +| `alltoall.py` | `all_to_all_single` | `(world-1)/world * buffer` | |
| 17 | +| `reducescatter.py` | `reduce_scatter_tensor` | `(world-1)/world * buffer` | |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +- 2+ GPUs on one node with PyTorch matching your GPU stack: |
| 22 | + ```bash |
| 23 | + # AMD (ROCm) |
| 24 | + pip install torch --index-url https://download.pytorch.org/whl/rocm6.4 |
| 25 | + # NVIDIA (CUDA) |
| 26 | + pip install torch |
| 27 | + ``` |
| 28 | +- `rdmatop` built with the matching feature to see the GPU rows: |
| 29 | + ```bash |
| 30 | + cargo install --path . --features xgmi # AMD |
| 31 | + cargo install --path . --features nvlink # NVIDIA |
| 32 | + ``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +```bash |
| 37 | +cd examples/pytorch |
| 38 | +torchrun --nproc_per_node=8 allgather.py # 60s, 256 MiB/rank |
| 39 | +torchrun --nproc_per_node=8 allreduce.py --mb 512 --secs 300 |
| 40 | +torchrun --nproc_per_node=4 alltoall.py # only 4 GPUs |
| 41 | +torchrun --nproc_per_node=8 reducescatter.py |
| 42 | +``` |
| 43 | + |
| 44 | +Rank 0 prints an estimated per-GPU transmit rate each batch |
| 45 | +(`~N Gbps TX/GPU`, from the ring-algorithm model in the table above). |
| 46 | +Compare it against the per-row TX in `rdmatop`. |
| 47 | + |
| 48 | +## Notes |
| 49 | + |
| 50 | +- The printed rate is a ring-algorithm estimate; RCCL/NCCL may pick |
| 51 | + other algorithms, so treat it as a sanity reference. Ground truth on |
| 52 | + AMD is `amd-smi xgmi` accumulator deltas, which read the same |
| 53 | + counters `rdmatop` samples. |
| 54 | +- The `nccl` backend name is historical — on ROCm builds of PyTorch it |
| 55 | + is backed by RCCL, no code changes needed. |
| 56 | + |
| 57 | +## Related Links |
| 58 | + |
| 59 | +- [torch.distributed](https://pytorch.org/docs/stable/distributed.html) |
| 60 | + — collective API used by the scripts |
| 61 | +- [rccl](https://github.com/ROCm/rccl) — AMD collective library |
| 62 | +- [nccl](https://github.com/NVIDIA/nccl) — NVIDIA collective library |
0 commit comments