The moment a model spans GPUs, part of every step is spent talking instead of computing. How much depends on which collective operations the parallelism strategy needs, how big each message is, and which link carries it. This lesson covers NCCL and its collectives, a simple latency-plus-bandwidth model for predicting communication time, why decode-time tensor parallelism is latency-bound while prefill is bandwidth-bound, how to measure links with nccl-tests, and the settings that most often break multi-node jobs.
- Name the NCCL collectives and which parallelism strategy uses each
- Estimate communication time with a latency plus size-over-bandwidth model
- Explain why small decode messages make TP latency-bound
- Benchmark GPU links with nccl-tests and read algorithm versus bus bandwidth
- Diagnose common multi-node networking failures from NCCL logs
NCCL and the collectives
NCCL (NVIDIA Collective Communications Library) is what inference engines and training frameworks call to move data between GPUs. It discovers the topology (NVLink, NVSwitch, PCIe, InfiniBand, RoCE), picks algorithms such as ring or tree, and runs the transfers as GPU kernels, which is why they appear on Nsight timelines. AMD's equivalent is RCCL.
| Collective | What it does | Used by |
|---|---|---|
| All-reduce | Every GPU ends with the sum of everyone's data | Tensor parallelism (per layer) |
| All-gather | Every GPU ends with everyone's pieces concatenated | TP variants, sequence parallelism |
| Reduce-scatter | Sum, then each GPU keeps one slice | TP variants |
| All-to-all | Each GPU sends a different chunk to every other | Expert parallelism token routing |
| Send / receive | Point-to-point transfer | Pipeline stages, KV transfer |
Predicting communication time
A useful first model: time = alpha + size / bandwidth. Alpha is a fixed latency per operation (launch, synchronisation, link latency); the second term is the transfer. Large messages are dominated by bandwidth, small ones by alpha. A ring all-reduce across N GPUs moves about 2 x (N-1)/N times the message size through each GPU, which is why nccl-tests reports bus bandwidth (busbw), corrected for that factor, alongside raw algorithm bandwidth.
hidden size 8192, batch 32, FP16 activations:
message = 32 x 8192 x 2 bytes = 512 KiB per all-reduce
80 layers x 2 all-reduces = 160 all-reduces per decode step
if each takes ~20 us on NVLink -> ~3.2 ms per step
if each takes ~100 us on a slower path -> ~16 ms per step
(compare a decode step of ~20-30 ms: the slow path eats most of it)Decode messages are small and frequent, so tensor parallelism at decode time is latency-bound: what matters is how fast each tiny all-reduce completes, which NVLink and NVSwitch do in microseconds and network links cannot match. Prefill messages are large (thousands of tokens), so prefill is bandwidth-bound. Engines and libraries fight the latency term with fused communication kernels and by overlapping communication with computation.
Measuring links with nccl-tests
Before trusting a multi-GPU deployment, measure the fabric. NVIDIA's nccl-tests sweep message sizes and report latency and bandwidth per collective. Run them on every new node type and after any driver, firmware or network change.
# all-reduce from 8 bytes to 1 GiB, doubling each step, on 8 local GPUs
./build/all_reduce_perf -b 8 -e 1G -f 2 -g 8
# multi-node with MPI: 64 ranks, 8 per node, one GPU per rank
mpirun -np 64 -N 8 ./build/all_reduce_perf -b 8 -e 8G -f 2 -g 1- Look at small-message latency (top rows) for decode-time TP and large-message busbw (bottom rows) for prefill and KV transfer.
- Compare busbw with the link's rated bandwidth; a large shortfall points at topology, configuration or a faulty link.
- Inside a node, numbers should reflect NVLink; if they look like PCIe, the GPUs are not using NVLink.
Designing to keep communication off the critical path
Communication cost is not fixed; architecture choices move it. Keep the most frequent, latency-sensitive collectives on the fastest links: tensor parallelism inside an NVLink domain, never across a datacenter network. Send the less frequent, larger transfers, pipeline activations and KV-cache handoffs, over the inter-node fabric, where bandwidth matters more than latency.
Batch size also changes the picture. Larger decode batches make each all-reduce message bigger but amortise the fixed latency over more tokens, so communication per token falls. Overlap helps too: modern engines start sending one layer's results while computing the next, hiding part of the cost. When you see NCCL kernels taking a large share of a profiled step, the usual fixes, in order, are a smaller TP size with more replicas, keeping TP within NVLink, and only then faster or more network links.
For expert parallelism the all-to-all exchange is both large and frequent, and uneven expert popularity makes some GPUs wait for others. Rack-scale NVLink domains, careful expert placement and load balancing exist largely to tame this. If you serve large mixture-of-experts models, budget as much engineering time for the network as for the GPUs.
When multi-node goes wrong
Set NCCL_DEBUG=INFO and read the start-up lines: NCCL prints which transports it chose for each GPU pair (P2P over NVLink, SHM, NET over IB or Socket). Most failures are visible there.
| Symptom | Likely cause | First fix |
|---|---|---|
| Transport shows NET/Socket instead of IB | RDMA devices not visible or not selected | Expose IB devices to the container; set NCCL_IB_HCA |
| Hang at initialisation | Wrong network interface or blocked ports | Set NCCL_SOCKET_IFNAME to the right interface; open ports |
| Bandwidth far below rated | PCIe topology, GPUDirect RDMA off, MTU | Check nvidia-smi topo -m, enable GPUDirect, fix MTU |
| Intermittent slowdowns | Link errors or congestion | Check NVLink and NIC error counters; look at fabric congestion |
In containers and Kubernetes, multi-node GPU jobs typically need host networking or an RDMA-capable network plugin, the InfiniBand devices mounted, and enough locked memory. Validate with nccl-tests inside the same pod spec you will use for serving.