Education › Inference › Stage 5: Parallelism & GPU networking

GPU interconnects and communication cost

NVLink, PCIe, InfiniBand and RoCE, NCCL collectives, and how communication overhead caps scaling.

Advanced ~35 min read Module 10 of 15

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.

After this module you can
  • 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.

CollectiveWhat it doesUsed by
All-reduceEvery GPU ends with the sum of everyone's dataTensor parallelism (per layer)
All-gatherEvery GPU ends with everyone's pieces concatenatedTP variants, sequence parallelism
Reduce-scatterSum, then each GPU keeps one sliceTP variants
All-to-allEach GPU sends a different chunk to every otherExpert parallelism token routing
Send / receivePoint-to-point transferPipeline 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.

Decode-step TP traffic (illustrative model and timings)
text
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.

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.

SymptomLikely causeFirst fix
Transport shows NET/Socket instead of IBRDMA devices not visible or not selectedExpose IB devices to the container; set NCCL_IB_HCA
Hang at initialisationWrong network interface or blocked portsSet NCCL_SOCKET_IFNAME to the right interface; open ports
Bandwidth far below ratedPCIe topology, GPUDirect RDMA off, MTUCheck nvidia-smi topo -m, enable GPUDirect, fix MTU
Intermittent slowdownsLink errors or congestionCheck NVLink and NIC error counters; look at fabric congestion
Tip

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.

Hands-on practice

Measure your fabric before you trust it

  1. On a multi-GPU instance, build nccl-tests and run all_reduce_perf across all local GPUs from 8 bytes to 1 GiB.
  2. Record latency at 8 KiB to 1 MiB and busbw at 256 MiB and above.
  3. Run nvidia-smi topo -m and relate the numbers to the links shown.
  4. Restrict the test to two GPUs connected over PCIe (if any) and compare small-message latency.
  5. Using the decode traffic model above, estimate communication time per step for a model you care about at TP 2, 4 and 8.
  6. Write down the TP size beyond which communication would exceed 20% of a 25 ms step on your fabric.
Cheat sheet

GPU interconnects and communication cost — at a glance

Main things to focus on

  • NCCL picks transports and algorithms; collectives run as GPU kernels.
  • TP uses all-reduce; EP uses all-to-all; PP and KV transfer use send/recv.
  • Time ~ alpha + size / bandwidth: small messages are latency-bound.
  • Decode TP is latency-bound, so it needs NVLink-class links.
  • Measure with nccl-tests: latency for small sizes, busbw for large.
  • NCCL_DEBUG=INFO shows which transport was chosen.

Formulas

t = alpha + bytes / bandwidthLatency-bandwidth model
ring all-reduce traffic ~ 2(N-1)/N x sizePer GPU, why busbw differs from algbw
decode msg ~ batch x hidden x bytesTP all-reduce size per layer
collectives/step ~ 2 x layersTP all-reduces per forward pass

nccl-tests

all_reduce_perf -b 8 -e 1G -f 2 -g 8Sweep sizes on 8 local GPUs
alltoall_perf / sendrecv_perfOther collectives (EP, PP)
mpirun -np 64 -N 8 ... -g 1Multi-node run
busbw columnCompare with rated link bandwidth

NCCL environment

NCCL_DEBUG=INFOPrint topology and transport choices
NCCL_SOCKET_IFNAME=IFACEInterface for bootstrap and socket traffic
NCCL_IB_HCA=DEVICEWhich InfiniBand or RoCE adapters to use
NCCL_P2P_DISABLE=1Diagnostic only: force off GPU peer-to-peer

Links

NVLink / NVSwitchMicrosecond latency, high bandwidth, in node or rack domain
PCIeSlower GPU-GPU path through switches or CPU
InfiniBand / RoCE + GPUDirect RDMAInter-node, NIC reads GPU memory directly

Common pitfalls

  • Deploying TP across nodes without measuring small-message latency.
  • Containers that cannot see the InfiniBand devices, silently falling back to TCP sockets.
  • Reading algorithm bandwidth as if it were link bandwidth.
  • Skipping nccl-tests after driver, firmware or network changes.
  • Leaving NCCL_P2P_DISABLE set after debugging.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →