advanced27 min studyLesson 559 in Engineering

Activation and traffic budgets: count lifetimes as well as shards

Estimate payload, temporary gather peaks, and declared collective traffic while distinguishing per-rank bytes from aggregate network work.

On this page

What you’ll understand

  • Calculate local activation payload under an even placement.
  • Identify a peak where a shard and gathered buffer coexist.
  • Build strategy-specific communication estimates with explicit units and boundaries.

Sharding an activation can reduce its steady local payload while a later gather temporarily restores the full tensor. During that transition, both representations may coexist with backward state and communication buffers. Memory planning therefore needs a lifetime diagram, not only a global-size-divided-by-ranks formula. Traffic planning likewise needs a named algorithm and counting boundary: logical tensor bytes, bytes sent per rank, and summed network bytes are different quantities.

Payload is a component of the live-memory peak

A dense activation [M,H] has M×H elements. An even P-way token shard stores M×H/P elements per rank when the placement truly partitions those rows. Multiply by bytes per element for raw payload. Gradients, saved tensors, residuals, softmax statistics, masks, allocator overhead, and alignment are separate. A replicated activation instead retains the full payload. A sum-partial product can also have the full coordinate shape locally despite representing only a contribution, so placement must precede the memory calculation.

Suppose an all-gather materializes the full activation while the original shard stays alive. At that instant the counted payload is full plus shard, not simply full/P. A fused kernel or allocator reuse can change that lifetime, but such a reduction needs implementation evidence. Activation recomputation trades saved state for additional compute and possibly repeated communication. It does not remove every temporary, and its useful granularity depends on which tensors dominate the actual peak.

Mfull=MHs,Mshard=MHsP,Moverlap=Mfull+MshardM_{\rm full}=MHs,\qquad M_{\rm shard}=\frac{MHs}{P},\qquad M_{\rm overlap}=M_{\rm full}+M_{\rm shard}
M and H count tokens and features, s is bytes per element, and P is an even sharding degree. The overlap formula counts only one retained shard plus one full gathered buffer; it excludes other live tensors and assumes they are separate allocations.↔ Scroll wide equations horizontally.

A collective cost needs an actual algorithm

For an explicitly assumed ring all-gather of an evenly sharded tensor with full size B bytes, each rank sends and receives roughly(P−1)B/P payload bytes. A ring all-reduce of a full same-shaped sum-partial tensor has a different two-phase payload count. Other algorithms, links, protocols, chunking, and overlap change observed behavior. Never attach one per-layer communication number to tensor parallelism without naming forward/backward boundaries and whether sequence or context layouts change the operations.

A latency-bandwidth model adds message-step latency to byte-transfer cost, but effective bandwidth is measured at the relevant boundary. Aggregate send bytes sum contributions across ranks and do not equal time on one shared link. Concurrent compute can overlap some movement, while dependencies can leave another part exposed. Increasing parallel degree reduces some local compute and memory but can make fixed communication costs dominate. Measure representative tensor sizes and topology instead of extrapolating solely from an ideal byte count.

Tcomm≈nstepsα+BsentβT_{\rm comm}\approx n_{\rm steps}\alpha+\frac{B_{\rm sent}}{\beta}
α is seconds per assumed communication step, β is effective sent-payload bytes per second for the declared path, and B_sent is the corresponding per-rank count. The model excludes contention and overlap unless explicitly folded into measurements; it is not a universal collective timing law.↔ Scroll wide equations horizontally.

Report the peak and the exposed time separately

Collect traces that identify which allocations overlap during attention exchange, linear redistribution, and backward. A lower steady activation payload can still leave a larger transient peak if a full gather overlaps several saved buffers. For traffic, record group size, tensor dtype, exact layout transitions, sent/received definition, and whether reported time is total collective duration or the nonoverlapped portion of the iteration. Numerical correctness remains a gate: reducing traffic by omitting required gradient contributions is not an optimization.

The roofline lab is deliberately synthetic and concerns local compute/memory ceilings, not collective links. Reset, set I=4 FLOP/byte and B=80 GB/s, predict ceiling 320 GFLOP/s, then Play or Step. Its fixed compute ceiling is 1,000 GFLOP/s. No input describes network ranks, activation lifetimes, NCCL algorithms, or communication overlap. The lab helps keep byte and operation units explicit, while the worked memory-and-ring budget uses a different clearly stated communication model.

A gather peak and a four-rank ring estimate

An activation is[8,4] with two-byte elements and four even token shards. A separate full all-gather output coexists with the original local shard. Assume a ring all-gather and count payload only.

  1. The full tensor has 8×4=32 elements, or 64 bytes. Each rank’s shard has 8 elements, or 16 bytes.

  2. During the stated overlap, each rank retains 16+64=80 bytes for these two allocations. Reporting only the 16-byte steady shard would miss this counted peak.

  3. The ring estimate sends(P−1)B/P=3×64/4=48 bytes per rank and receives 48. Summed sent payload across four ranks is 192 bytes. Adding sent and received counts would be another metric, not the same 192-byte aggregate-send definition.

The result

The local memory peak and network payload arise from different accounting boundaries. Both remain lower-level components of a complete training budget.

Explore the model

Interactive lab

Interactive lab · roofline

Keep byte and operation units explicit

Reset, set I=4 FLOP/byte and B=80 GB/s, predict 320 GFLOP/s, then Play or Step. The 1,000 GFLOP/s compute peak is synthetic. This model has no network ranks, collectives, activation allocation, or overlap accounting.

Keep byte and operation units explicitSynthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Current readings: Attainable ceiling: 640 GFLOP/s; Ridge intensity: 12.5 FLOP/byte; Ceiling regime: Memory-bound ceiling. All parameters are adjustable with the labeled controls below.Hypothetical roofline upper bound: 640 GFLOP per second at operational intensity 8 FLOP per byte and bandwidth 80 gigabytes per second.0.1110641101001000Operational intensity · FLOP/byte · log scaleCeiling · GFLOP/s · log scalePeak: 1000
Attainable ceiling / kernelBandwidth roof / traceCompute ceiling
Attainable ceiling
640 GFLOP/s
Ridge intensity
12.5 FLOP/byte
Ceiling regime
Memory-bound ceiling
t = 0 s

Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. 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 forA useful resource estimate states its units and boundary before being compared with runtime evidence.

Check your understanding

Why can an all-gather increase a rank’s activation peak beyond the final full-tensor payload?

Try it yourself

A[16,8] activation uses two-byte elements and two token shards. A separate full gather coexists with the shard. Compute full, local, overlap, and per-rank ring all-gather sent payload.

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

Give me a hint

Count elements first, then use the declared two-allocation overlap and ring formula.

Compare with the solution

The full payload is 16×8×2=256 bytes. The shard is 128 bytes, and overlap is 384 bytes for these allocations. With P=2, ring sent payload is(P−1)B/P=128 bytes per rank, also 128 received. Protocol overhead, additional buffers, and real timing are excluded.

Take it with you

  • Peak memory depends on overlapping lifetimes, not only steady shard size.
  • Collective traffic needs a named strategy and sent/received boundary.
  • Synthetic ceilings and byte estimates complement measured exposed communication.

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.