6.1.7 · D4Scaling & Efficient Architectures

Exercises — Model parallelism (tensor, pipeline)

2,202 words10 min readBack to topic

This page is a self-test. Each problem states everything it needs; the solution is hidden inside a collapsible callout so you can try first, then check. Work them in order — they climb from "can you name it" up to "can you design a system."

Parent: Model Parallelism (Tensor, Pipeline).

Before we start, we lock the symbols so nothing appears un-earned:

The core memory arithmetic we reuse everywhere:


Level 1 — Recognition

Exercise 1.1 (L1)

A single linear layer computes . One sentence: does tensor parallelism cut within this layer, or does it place this whole layer on one device and the next layer elsewhere?

Recall Solution

Tensor parallelism cuts within the layer — every device keeps a slice of the same weight matrix. Placing whole layers on different devices is pipeline parallelism (inter-layer). Mnemonic: Tensor = Thin slices of one matrix; Pipeline = Piles of layers.

Exercise 1.2 (L1)

A 7-billion-parameter model is stored in FP16. How many gigabytes do the parameters alone take? (Use bytes.)

Recall Solution

. Why FP16 = 2 bytes: 16 bits = 2 bytes; that is the whole reason mixed precision (Mixed Precision Training) halves weight memory versus FP32.

Exercise 1.3 (L1)

In the GPipe timeline, symbols and appear. What does each stand for, and why must every finish before its matching starts?

Recall Solution

= forward pass of micro-batch ; = backward pass of micro-batch . The backward pass needs the loss, which only exists after the forward pass has produced an output. So always precedes — cause before effect.


Level 2 — Application

Exercise 2.1 (L2)

A layer has (so , ). We do a column-wise split across devices. Give the shape of each device's slice and the shape of the local output if the batch is .

Recall Solution

Column split cuts the output dimension: each device holds columns. Full output is , glued along columns (all-gather). See figure below.

Exercise 2.2 (L2)

A Transformer MLP block uses and with . Split across devices (column-parallel , row-parallel ). How many parameters does one device store for this block, and what fraction of the full block is that?

Recall Solution

Full block parameters (ignore bias): Total params. Both are split by , so one device stores params of the block.

Exercise 2.3 (L2)

GPipe with stages and micro-batches. Compute the bubble fraction .

Recall Solution

Meaning ~16% of GPU time is idle bubble; ~84% is useful work.


Level 3 — Analysis

Exercise 3.1 (L3)

For a column-parallel layer, the input gradient is . Explain in words why a sum (all-reduce) is unavoidable here, referencing the figure — and state what communication the forward pass needed by contrast.

Recall Solution

Look at figure s01: each output column block depends on the full input . So when gradient flows back, every column block pushes a correction onto every input feature. Each device only knows its own and , so it can only compute one term — a partial answer. The true is the sum of all partials, so devices must add their contributions: all-reduce. Forward, by contrast, produced independent column blocks that only needed to be glued (all-gather), not summed. Asymmetry: forward = concat, backward-to-input = sum.

Exercise 3.2 (L3)

Two engineers debate. A: "GPipe with is strictly better than because the bubble is smaller." B: "Not free." Quantify both bubble fractions for , and state the cost B is pointing at.

Recall Solution

So does slash bubble from ~27% to ~9%. But GPipe stores activations for all micro-batches until the backward sweep. Activation memory scales linearly in : needs 4× the activation memory of . B's point: efficiency bought with memory. Fix uses Activation Checkpointing to recompute activations instead of storing them.

Exercise 3.3 (L3)

The bubble fraction has a limit as . Find it, and explain physically what it means to "keep adding micro-batches forever."

Recall Solution

Physically: with infinitely many micro-batches, the pipeline stays permanently full — no stage ever waits, so idle time → 0% of a job that runs forever. In reality is capped by memory (Ex 3.2) and by the mini-batch size, so we approach 0 but never reach it. The figure shows the curve flattening toward zero.


Level 4 — Synthesis

Exercise 4.1 (L4)

A 20B-parameter model is trained with Adam in FP32. Compute total memory for (a) parameters, (b) Adam optimizer states, (c) grand total including gradients (FP32). Then state the minimum number of 80 GB GPUs needed if you split evenly by tensor parallelism (ignore activations). Use bytes.

Recall Solution

params.

  • (a) Parameters FP32: bytes .
  • (b) Adam states = 8 bytes/param: .
  • Gradients FP32 = 4 bytes/param: .
  • (c) Grand total . Split evenly across GPUs of 80 GB each: GPUs minimum (ignoring activations; real systems need more headroom).

Exercise 4.2 (L4)

Design question. You have pipeline stages, mini-batch , micro-batch size (so ). Steady-state 1F1B (PipeDream 1F1B) stores only micro-batches' worth of activations instead of . If one micro-batch's activations cost GB, how much activation memory does 1F1B save versus GPipe at peak?

Recall Solution
  • GPipe peak: stores all .
  • 1F1B steady state: stores .
  • Saving (a reduction). Why: 1F1B runs a backward as soon as a forward completes, freeing that micro-batch's activations early instead of hoarding all forwards first.

Level 5 — Mastery

Exercise 5.1 (L5)

Combined regime. A cluster has GPUs arranged as tensor-parallel groups of inside pipeline stages of (so ). The MLP block per stage uses one all-reduce (tensor, cost ) and the pipeline sends activations times (cost per hop). For micro-batches, write the total communication count in terms of , and explain which cost you would attack first if .

Recall Solution
  • Tensor communication happens inside every micro-batch's forward and backward on every stage. Per micro-batch: forward all-reduce + backward all-reduce = all-reduces per MLP block. Over micro-batches this is all-reduce events per stage.
  • Pipeline communication: activations hop between adjacent stages times per micro-batch forward, and again on backward → hops per micro-batch, total.
  • If : attack the tensor all-reduce first. It fires times and is the expensive one. Practical fixes: keep tensor-parallel groups inside a single node (NVLink is fast), raise pipeline (cheap ), and use Mixed Precision Training to halve bytes moved in each all-reduce.

Exercise 5.2 (L5)

Efficiency budget. GPipe with , . (a) Bubble fraction. (b) If activation checkpointing adds 33% recompute overhead but lets you double to within the same memory, compute the new bubble. (c) Net: does the trade help throughput? Give the useful-work fraction each way (useful = , discounted by recompute overhead where present).

Recall Solution

(a) : bubble . Useful work . (b) : bubble . Raw useful . (c) Checkpointing recompute makes each unit of forward work cost . Effective throughput scale useful-fraction overhead: Conclusion: despite the smaller bubble, the 33% recompute tax outweighs the bubble savings here — raw throughput drops (~0.82 → ~0.68). Checkpointing wins only when the alternative is not fitting at all (out-of-memory), not as a pure speed play. This is the deep point: Activation Checkpointing trades compute for memory, not for speed.


Recall Quick self-check clozes

Tensor parallelism cuts the weight matrix within one layer; pipeline parallelism cuts the model across layers (depth-wise). Column split of makes output blocks that are combined by all-gather (concatenate); the input gradient is combined by all-reduce (sum). GPipe bubble fraction ::: Adam optimizer state cost per parameter ::: 8 bytes (2 states × 4 bytes) 1F1B stores activations for ::: micro-batches, not