Unit 2 of 9 · about 4 hours · derive

Collective contracts and the latency-bandwidth cost model

Volume tells you the bytes on the wire and latency tells you the floor for small messages. Without both terms you cannot say whether a collective is latency-bound or bandwidth-bound.

You'll be able to

  • State the NCCL contract for each collective: same count and datatype on every rank, rank-ordered outputs, and root as a rank rather than a device.
  • Derive per-rank volume and - time for all-gather, reduce-scatter and ring all-reduce, and predict the latency-bandwidth crossover for a stated size.

Covers

Rank, group, shape, dtype and ordering contractsLatency-bandwidth cost model and message-size crossover
1

Read

In this order, only the parts listed

0 of 3 done

  1. Collective contractsNCCL

    AllReduce, AllGather, ReduceScatter and AlltoAll: every rank passes the same count and datatype; AllGather orders output by rank; Reduce followed by Broadcast equals AllReduce; ReduceScatter followed by AllGather equals AllReduce

  2. Volume reasoning without latencyCS336 Assignment 2 - Section 8.1 Communication Primitives

    Section 8.1 Communication Primitives (pp. 40 to 41): ring all-gather and ring reduce-scatter at seconds, ring all-reduce as their sum, and Problem (alternate_ring_all_reduce)

  3. Size-dependent selection knobsNCCL

    NCCL_ALGO with Ring, Tree, CollNet variants, NVLS, NVLSTree and PAT plus per-collective syntax; NCCL_PROTO with LL, LL128 and Simple; the tuner picks the small-versus-large crossover by size and topology (the old NCCL_LL_THRESHOLD and NCCL_TREE_THRESHOLD were removed in NCCL 2.5)

2

Focus on

  • The contract is strict: mismatched counts, datatypes or call order across ranks is undefined behaviour including hangs, not a checked error. Root arguments name ranks, so a remapped rank-to-device layout changes which device is root.
  • CS336 sizes its model with per-device egress and no latency term, so is exact only for large messages. Add the latency term for small ones: with .
  • The crossover separates the regimes. With microseconds and GB/s the crossover sits at 1 MB: below it startup dominates, above it bytes dominate.
  • Small messages favour low-latency protocols (LL, LL128) and, at larger rank counts, tree; large messages favour ring with Simple. NCCL's tuner chooses per size and topology because one setting cannot win at both ends.
Common mistakes · 3
  • Reading the CS336 volume as a complete time model. It drops , so it underpredicts small messages by orders of magnitude; that gap is exactly what LL/LL128 and tree selection address.
  • Assuming the alternate ring algorithm from the CS336 problem is competitive. It sends full per step for seconds, a factor of about worse than the chunked ring; chunking is what buys the saving.
  • Treating bus bandwidth and algorithm bandwidth as the same number. The fit must use bytes on the wire per rank, not , or the fitted is wrong by the volume factor.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive ring all-reduce time as reduce-scatter plus all-gather: . Then compute the crossover size where the latency and bandwidth terms are equal for a stated and .
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What does the alternate ring all-reduce cost, and why?Answer

    seconds. Each of the steps transmits a full size- buffer instead of a size- chunk, so no factor appears.

  2. 2.With microseconds and GB/s, where is the crossover?Answer

    bytes, or 1 MB. Messages far below 1 MB are latency-bound; far above are bandwidth-bound.

  3. 3.Why must every rank pass the same count and datatype?Answer

    The collective is one matched operation across ranks. A mismatch breaks the pairing the implementation assumes, which the NCCL page defines as undefined behaviour including hangs and data corruption.

  4. 4.All-gather output differs across two runs with identical inputs. What changed?Answer

    The rank-to-device mapping. AllGather orders output by rank index, so remapping ranks permutes which device's block lands where.

  5. 5.Which algorithm and protocol should a 16 KB and a 400 MB all-reduce end up with, and why?Answer

    A low-latency protocol (LL or LL128), with tree at larger rank counts, for 16 KB, because startup dominates; ring with Simple for 400 MB, because balanced links dominate. The tuner makes this choice per size, so override it only with a measured reason.

5

Practice

  • TensorTonic: Simulate Distributed Collectives

    Implement simulate_collectives for all_gather, all_reduce, reduce_scatter and all_to_all over rank-ordered tensors: rank-ordered concatenation, elementwise sums, equal contiguous chunks and source-ordered blocks

  • TensorTonic: Calculate Collective Effective Bandwidth

    Implement collective_bandwidth: modeled bytes per rank with for all-reduce and 1 otherwise, divided by the duration

    The problem calls the ring wire bytes algorithm_bytes. nccl-tests reserves algorithm bandwidth for and calls the wire-corrected rate bus bandwidth, so name the convention whenever you compare the two.

You're done when

You derive the ring all-reduce time and the crossover without notes, and both TensorTonic problems agree with your hand computation.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 11 more in the section
  • NCCLNVIDIA · required

    Study the collective API, communicator and topology behavior, then run a bounded nccl-tests message-size sweep when multiple GPUs are available. Correlate algorithm bandwidth, bus bandwidth and rank timelines with the - model.

  • CS336 Assignment 2 - Section 8.1 Communication PrimitivesStanford University · support

    Work alternate_ring_all_reduce and the communication-volume reasoning in Section 8.1 as a written check on your cost model.

Also in this section

  • AI Systems Performance Engineering - Chapters 4, 15, 17 and 18Chris Fregly · primary

    Read Chapter 4 on distributed networking communication, the parallelism parts of Chapter 15, and Chapters 17 and 18 on disaggregated prefill and decode and KV-cache transfer. Re-derive every volume and crossover for the hardware you actually have.

  • AI Systems Performance Engineering companion code - Chapters 4, 15 and 17Chris Fregly · support

    Use compatible examples from code/ch04, code/ch15 and code/ch17 for NCCL, topology, overlap and disaggregated inference. Run preflight checks, lock and record clocks through the harness, and mark unsupported transport or topology paths as explicit blockers.

  • AI Performance Engineering - Distributed InferenceWafer · reference

    A curated index. Use Section 5 only to find primary papers for a communication mechanism you are measuring.

  • UCSD CSE 291A/DSC 291 (Spring 2026) PA2 Part 2 - Tensor Parallel CommunicationUC San Diego · required

    Build all-reduce and all-to-all from point-to-point MPI calls (Section 2.1), then the data split, layer initialization and naive model-parallel forward and backward communication (Sections 2.2 to 2.5) against the provided mpi-test.py cases and pytest files. It runs on CPU processes with Open MPI and mpi4py.

  • TensorTonic Language Modeling from Scratch - collective problemsTensorTonic · support

    Solve Simulate Distributed Collectives, Calculate Collective Effective Bandwidth, Synchronize Data-Parallel Gradients and Reconstruct a Column-Parallel MLP Layer after the collective units.

  • GPU MODE - Collective CommunicationGPU MODE · support

    Use Lectures 17, 67, 70 and 78 for NCCL, NVSHMEM, fault-tolerant collectives and multi-GPU Triton. Implement or inspect one communication mechanism only after the volume and topology model is written.

  • DistServeDistServe Authors · required

    Study prefill-decode interference, phase-specific parallelism and goodput optimization. Build a small simulator or measured two-pool experiment and test the key-value transfer crossover rather than reproducing the complete serving system.

  • NVIDIA Inference Xfer LibraryNVIDIA · support

    Inspect memory registration, transfer backends and metadata APIs as the state-movement layer for disaggregation. Run only supported local transports and compare measured transfer setup and steady-state cost with the model.

  • DeepEPDeepSeek · depth

    Reconstruct expert dispatch and combine paths, low-latency versus high-throughput modes and hardware assumptions. Test a small supported path only after a standard collective baseline and load-skew model exist.

  • Splitwise: Efficient Generative LLM Inference Using Phase SplittingMicrosoft Research · support

    Read arXiv:2311.18677v2 (ISCA 2024) for the phase characterization and the homogeneous and heterogeneous cluster designs. Test the throughput, cost and power claims as hardware-specific results, and compare its placement with DistServe on your workload.

  • Mooncake: Trading More Storage for Less ComputationUSENIX FAST 25 · support

    Study the KVCache-centric disaggregated architecture, the global cache with its transfer engine, and the prefill scheduling with early rejection. Test the effective-capacity claims as trace-specific results.