advanced25 min studyLesson 481 in Engineering

Collective semantics and participation

Specify the communicator, tensor contract, reduction meaning, and completion point before tuning distributed training communication.

On this page

What you’ll understand

  • Distinguish collective results from their physical communication algorithm.
  • Check rank participation and operation-specific buffer contracts.
  • Compute a weighted global gradient when local batch sizes differ.

A collective is an agreement among a defined set of participants about a distributed operation. It is not merely a faster copy call. AllReduce, AllGather, and ReduceScatter produce different layouts and meanings, and their implementations can change without changing that contract. Correct training starts by specifying which ranks participate, what every element represents, and when the resulting buffer may safely be consumed.

A communicator defines the participants and their order

A rank identifies a participant within a communicator, rather than a universal physical GPU number. Rank-to-device mapping affects roots, gathered layout, and topology. In the NCCL 2.32.3 documentation used here, each participating rank is associated with its selected CUDA device and operations must follow the supported communicator rules. Do not assign the same device repeatedly as different ordinary ranks of one communicator and assume that this creates extra independent hardware. Initialization and recovery are distributed protocols whose membership must agree before data movement is meaningful.

Every required rank must make a matching call in the collective sequence. NCCL's documented equal-count collectives require the matching count and datatype contract, while MPI 4.1 has operation-specific type-signature and count rules, including variable-count routines. Equal buffer byte totals alone do not prove compatibility. Distinguish element counts, datatype widths, reduction operation, root where applicable, and communicator identity. A rank using a tensor from a different training step can violate the logical contract even when its count and datatype happen to match.

yi=∑r=0p−1xr,i,n=Nsy_i=\sum_{r=0}^{p-1}x_{r,i},\qquad n=Ns
For a sum AllReduce over p agreed ranks, each input has N compatible elements and y_i is the reduced element received by every rank. s is bytes per element and n is per-rank tensor bytes. Small exact examples ignore floating-point reassociation and overflow; n is not total fabric traffic.↔ Scroll wide equations horizontally.

Reduction semantics must match the learning objective

A sum AllReduce returns sums; a framework may divide later to obtain an average, but that normalization is another operation. If every worker contributes a mean gradient over an equal local batch, averaging rank means gives the mean over all samples. Unequal local batch sizes require appropriate weighting. Padding, masked tokens, and gradient accumulation can change the effective sample count further. Define whether the objective averages examples, valid tokens, or another unit before assuming that division by communicator size implements the intended global loss.

Floating-point addition is not associative. Different legal algorithm orders can produce small numerical differences, so bitwise reproducibility is a separate requirement from the logical sum contract and numerical-tolerance checks. Datatype choice also changes payload and accumulation behavior. Compare final training correctness and convergence under the selected numerical rules instead of treating identical bandwidth with a lower-precision datatype as a free improvement. A user-defined MPI reduction has its own associativity and commutativity contract; an algorithm requiring commutativity cannot be applied indiscriminately.

gglobal=∑rbrgr∑rbrg_{\rm global}=\frac{\sum_r b_r g_r}{\sum_r b_r}
g_r is a local mean gradient and b_r its positive contributing sample count under the same per-sample objective. The expression gives the sample-weighted mean, componentwise. It assumes each local mean uses the stated denominator and excludes incompatible loss scaling or masked-count conventions.↔ Scroll wide equations horizontally.

Enqueued work and available participants are not completion

NCCL collective calls use CUDA streams; successful posting is not equivalent to device completion. Preserve the documented stream dependencies and buffer lifetime before an optimizer reads reduced gradients or a producer overwrites send storage. MPI nonblocking completion has its own request and buffer rules, so do not transfer one API's completion assumptions to another. A collective also need not behave as a general barrier for unrelated actions. Name the exact local completion observation and what, if anything, it establishes about peers.

The reliability instrument deliberately exposes a misleading analogy. Reset, set both n=5 and k=1, predict four available replicas and a majority threshold of three, then Play or Step. Separately Reset, set both n=5 and k=0, predict five available, then Play or Step. A majority is still available in the first display, but an unchanged five-rank collective cannot silently omit its missing rank. This toy majority counter does not run NCCL, establish matching calls, or perform membership recovery. Explain why coordinated creation of a different supported communicator changes the contract rather than repairing an old call by wishful counting.

Unequal local batches need weighted aggregation

Three training ranks compute local mean gradients 1, 3, and 5 for local batch sizes 64, 32, and 32. Treat gradients as exact scalars for this exercise and assume one shared per-sample objective.

  1. Recover each local gradient sum: 64×1=64, 32×3=96, and 32×5=160. Their sum is 320, while total sample count is 64+32+32=128.

  2. A sum reduction of the weighted numerators and counts yields a global sample mean of 320/128=2.5. The collective must carry the intended quantities and compatible datatypes.

  3. Averaging the three unweighted rank means gives (1+3+5)/3=3, a different objective weighting. Matching tensor shape does not correct that normalization error.

The result

Collective participation and correct payload semantics are both necessary. The communication library cannot infer how a training objective should weight unequal contributions.

Explore the model

Interactive lab

Interactive lab · reliability

A majority is not enough for an unchanged collective

Reset, set both n=5 and k=1, predict four available and majority three, then Play or Step. Separately Reset, set both n=5 and k=0, predict five available, then Play or Step. The toy majority count neither executes a five-rank collective nor validates calls or coordinated communicator recovery.

A majority is not enough for an unchanged collectiveA replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Current readings: Available replicas: 4 of 5; Majority needed: 3; Majority available?: Yes. All parameters are adjustable with the labeled controls below.Majority available · need 3 of 5Playback highlights fixed statesR1 · upR2 · upR3 · upR4 · upR5 · downCyan mark: majority threshold
AvailableUnavailableMajority threshold
Available replicas
4 of 5
Majority needed
3
Majority available?
Yes
t = 0 s

A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forCollective membership is a semantic contract, and availability of a majority does not authorize skipping required ranks.

Check your understanding

One rank is absent from an unchanged eight-rank AllReduce communicator. What can the seven remaining ranks assume?

Try it yourself

Each of eight ranks contributes 2,000,000 four-byte elements to an AllReduce. What is the per-rank logical tensor size? Why is eight times that number not a universal network-byte formula?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Multiply element count by element width, then distinguish endpoint tensors from routed algorithm traffic.

Compare with the solution

Each tensor is 8,000,000 bytes. Eight inputs occupy 64,000,000 logical input bytes across endpoints, but actual transfers depend on the chosen algorithm, topology, protocol, and whether counters include sends, receives, or fabric hops. The logical input total alone does not describe all communication work.

Take it with you

  • Specify communicator membership, sequence, datatype, count, and tensor meaning.
  • Weight reductions according to the actual objective rather than rank count alone.
  • Respect stream or request completion before reusing communication buffers.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.