Unit 3 of 9 · about 6 hours · derive, implement

Ring and tree all-reduce, all-gather and reduce-scatter volume

Data-parallel sync and tensor-parallel shards are these three collectives in different orders. The volume derivation decides the design; the MPI build makes the steps concrete without needing eight GPUs.

You'll be able to

  • Derive step counts and per-rank bytes for ring and tree all-reduce, all-gather and reduce-scatter, and state which regime each algorithm wins.
  • Implement all-reduce and all-to-all from point-to-point calls with correctness and timing checks against the library versions.
  • Decompose tensor-parallel forward and backward communication into all-gather, all-reduce and reduce-scatter pieces.

Covers

Ring and tree all-reduce algorithmsAll-gather and reduce-scatter communication volume
1

Read

In this order, only the parts listed

0 of 4 done

  1. Ring constructions and the alternate algorithmCS336 Assignment 2 - Section 8.1 Communication Primitives

    Section 8.1 Communication Primitives (pp. 40 to 41): ring all-gather chunk passing, ring reduce-scatter with partial sums, all-reduce as their composition, and Problem (alternate_ring_all_reduce)

  2. NCCL ring, tree, CollNet and PATAI Systems Performance Engineering - Chapters 4, 15, 17 and 18

    Chapter 4, NCCL Communication Algorithms: Ring bandwidth-optimality at data size over ranks per link, Tree in steps for small messages, CollNet leader hierarchy, PAT hybrid

  3. Collectives from point-to-point MPIUCSD CSE 291A/DSC 291 (Spring 2026) PA2 Part 2 - Tensor Parallel Communication

    Sections 2.0 and 2.1: mpi-test.py allreduce, allgather, reduce_scatter and split cases, then myAllreduce and myAlltoall in mpi_wrapper/comm.py from Send, Recv and Sendrecv only

  4. Point-to-point building blocksNCCL

    Two-sided communication: ncclSend and ncclRecv pairs compose ring steps; ordering across ranks follows the same matched-call discipline as collectives

2

Focus on

  • Ring all-reduce moves bytes per rank in steps: bandwidth-optimal because every link carries the same share. Tree all-reduce finishes in steps but leaves leaf links idle, so it wins small messages and loses large ones.
  • All-to-all is personalized, not a reduction: each rank sends a distinct chunk to every other rank. Reusing an all-reduce where an all-to-all belongs silently sums data that should stay separate.
  • Reduce-scatter followed by all-gather equals all-reduce, and each half costs per rank. Read any tensor-parallel layer as one of these halves: gather shards before shared compute, reduce partial outputs after sharded compute.
  • The PA2 restriction (no library collectives inside myAllreduce and myAlltoall) is the point: ring steps from Send and Recv expose the round structure that the volume formulas summarize.
Common mistakes · 3
  • Counting steps instead of bytes for large messages. Ring takes more steps than tree yet wins large transfers because balanced links dominate; step count alone picks tree everywhere.
  • Assuming tree links share load like ring links. Leaves send once upward and then wait, so quoting ring volume for a tree run overstates the link rate the measurement should show.
  • Calling myAlltoall with a reduction operator. All-to-all permutes blocks between ranks; applying MIN, SUM or MAX semantics to it corrupts every expert or shard assignment downstream.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive per-rank bytes and step counts for ring all-gather, ring reduce-scatter, ring all-reduce and the alternate algorithm for general and , then evaluate each at and GB and state the winner and its margin.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.At and GB, what does each rank send in ring all-reduce versus the alternate algorithm?Answer

    Ring: GB per rank. Alternate: GB per rank, twice as much, because it ships full buffers instead of chunks.

  2. 2.Why does tree all-reduce beat ring at 16 KB but lose at 400 MB?Answer

    At 16 KB the steps against dominate and tree starts fewer transfers. At 400 MB bytes dominate and ring keeps every link busy while tree leaves sit idle.

  3. 3.A tensor-parallel row needs full input on each rank from shards. Which collective, and what does each rank hold after?Answer

    All-gather: each rank starts with its input slice and ends with the full tensor ordered by rank, matching the PA2 naive_collect_forward_input exercise.

  4. 4.Each rank holds a same-shaped partial output that must be summed everywhere. Which collective?Answer

    All-reduce with SUM, matching naive_collect_forward_output over the fc_o input-dimension shards.

  5. 5.When is CollNet the right answer rather than plain ring or tree?Answer

    Across groups joined by slower links with reduction-capable fabric: ring or tree inside each fast group, then leader ranks exchange across groups so the slow fabric carries fewer rounds.

5

Practice

  • UCSD CSE 291A PA2 Part 2: Tensor Parallel Communication, Sections 2.1 to 2.5

    Section 2.1 myAllreduce and myAlltoall in mpi_wrapper/comm.py checked by mpirun -n 8 python mpi-test.py --test_case myallreduce and mpirun -n 8 python mpi-test.py --test_case myalltoall; Sections 2.2 to 2.5 split_data, get_info and naive forward/backward collects checked by tests/test_data_split.py, tests/test_get_info.py, tests/test_transformer_forward.py and tests/test_transformer_backward.py

    CPU-only with Open MPI and mpi4py in a throwaway venv; record the discussion2-1.txt timing comparison against the library versions. The remote grader needs a course token, so the local cases are the gate.

  • TensorTonic: Synchronize Data-Parallel Gradients

    Implement data_parallel_gradient_sync: average each parameter's gradient across ranks (a missing gradient counts as zero) and apply one SGD step to every replica; then state the ring all-reduce volume that sync moves

  • TensorTonic: Reconstruct a Column-Parallel MLP Layer

    Implement column_parallel_mlp: each rank computes on its column shard and the outputs concatenate in rank order, the step an all-gather performs; then state where a following row-parallel layer needs an all-reduce

You're done when

Your hand volumes match the PA2 timing ratios up to the expected constant, the local MPI cases pass, and you can place each PA2 collect call as a ring half without notes.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 9 more in the 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.

  • 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.

  • 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.

  • 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 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.

  • 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.