6.1.7 · D3Scaling & Efficient Architectures

Worked examples — Model parallelism (tensor, pipeline)

2,182 words10 min readBack to topic

This page is the "hit every case" workout for the parent topic. Before we compute anything, let us list every kind of situation model parallelism can throw at you, so no scenario surprises you later.

We use only ideas already built in the parent note. A quick reminder of the two symbols that carry this whole page:


The scenario matrix

Every problem in this topic is one of the cells below. The last column names the example that covers it.

Case class What makes it tricky Covered by
Tensor split — column-parallel forward need full , concat outputs Ex 1
Tensor split — row-parallel forward need all-reduce (a sum) Ex 2
Tensor split — backward all-reduce on input grad chain rule sums over slices Ex 3
Degenerate input: "parallelism" that does nothing Ex 4
Degenerate input: not divisible by uneven slices / padding Ex 4
Pipeline bubble — naive () worst-case idle time Ex 5
Pipeline bubble — limiting efficiency ceiling of 100% Ex 5
Pipeline memory: GPipe vs 1F1B activation storage vs Ex 6
Real-world word problem: does GPT fit? mix TP + PP + memory budget Ex 7
Exam twist: combined TP×PP×DP world size which numbers multiply? Ex 8

Now we walk each cell.


Forecast: guess the two numbers first — how many columns of per device, and how many columns of each device produces?

Look at the figure: the tall weight block is sliced by a vertical chalk line into and .

Figure — Model parallelism (tensor, pipeline)
  1. Slice the columns. , each (since ). Why this step? Column splitting is the "clean" split: each output column of depends only on the matching column of , so no device needs another device's weights.
  2. Broadcast the input. Both devices receive the full . Why this step? Every output column is a combination of all input features, so can't be sliced here — only can.
  3. Local matmul. Device computes . Why this step? This is exactly the associativity fact from the parent note.
  4. Concatenate. .

Verify: shapes: has rows and cols; . ✓ Weight memory per device numbers vs single-device — exactly . ✓


Forecast: in Ex 1 we concatenated. Guess: do we concatenate or sum here?

Look at the figure — the horizontal slice of pairs with a matching vertical slice of .

Figure — Model parallelism (tensor, pipeline)
  1. Slice rows of and columns of together. with , and with . Why this step? A row of multiplies a column of ; if we cut 's rows we must cut 's columns to keep the dot products aligned.
  2. Local matmul. Device computes — note is already full size, not a slice. Why this step? Each device produces a partial contribution to every entry of , not a separate piece.
  3. All-reduce (a sum). . Why this step? The matrix product is a sum over the shared inner dimension ; splitting that dimension splits the sum, so we must add the partial sums back — this is the "all-reduce" of the parent note.

Verify: . That is precisely . ✓ This is why the Transformer MLP uses column-parallel on then row-parallel on : the row-parallel step's all-reduce is the single needed communication — see Transformer Architecture.


Forecast: which direction (forward or backward) needed communication in Ex 1? Guess whether the other direction needs it now.

  1. Recall the rule. . Why this step? Chain rule: to push the error one layer earlier we multiply by the transposed weights.
  2. Substitute the split. . Why this step? A column split of makes a row split — so the product becomes a sum over devices.
  3. All-reduce. Device computes locally, then sum across devices. Why this step? Forward concat ⇒ backward all-reduce. The communication just moved to the other pass.

Verify: shapes: is , correct for . ✓ Also is , matching 's shape, and needs no communication. ✓


Forecast: guess (a) the memory saving when , and (b) whether can give equal slices.

  1. (a) . Memory saving : no saving. One device holds all weights and does the whole matmul. Why this step? is the "identity" of tensor parallelism — the framework runs but there is literally one slice, so there is no concat, no all-reduce, no benefit. Always sanity-check that your split count exceeds 1 before blaming communication overhead.
  2. (b) , . is not an integer. Why this step? Slices must be whole columns. Real frameworks (Megatron-LM) require divisible by , or they pad up to the next multiple.
  3. The fix. Pad to so each device gets columns; the extra output column is masked/ignored.

Verify: (a) saving ratio . ✓ (b) integer; padding overhead wasted columns. ✓


Forecast: guess the idle fraction at , and what number the fraction approaches for huge .

Look at the figure: red gaps are idle "bubble" time; feeding more micro-batches shrinks them.

Figure — Model parallelism (tensor, pipeline)
  1. Naive, . . Why this step? With one big batch, three of four stages sit idle waiting in line — 75% waste, the worst case named in the parent note.
  2. . . Why this step? Chopping into 16 parcels keeps late stages busy while early stages still work; idle drops to ~16%.
  3. Limit . . Why this step? As grows the fill/drain cost is amortised over more work, so utilization approaches 100% — the ceiling you can never quite reach but can approach.

Verify: ; ; and . ✓ Efficiency (=bubble) rises . ✓


Forecast: GPipe does all forwards then all backwards; 1F1B interleaves. Guess which one stores units and which stores .

  1. GPipe. All forwards run before any backward, so stage-0 must keep activations for all micro-batches → units. Why this step? Backward needs the forward activations; if backward is postponed to the very end, nothing can be freed early. Memory .
  2. 1F1B (PipeDream). In steady state each stage holds at most micro-batches' activations, so units. Why this step? Interleaving "1 forward, 1 backward" frees a micro-batch's activations as soon as its backward completes; only the in-flight ones () remain. Memory .
  3. Ratio. GPipe / 1F1B more memory for the same schedule. Why this step? This factor is the entire reason 1F1B exists — see Activation Checkpointing for the orthogonal compute-for-memory trade.

Verify: GPipe ; 1F1B ; ratio . ✓ Uses Gradient Accumulation-style micro-batch splitting, but memory behaviour differs by schedule.


Forecast: guess the total training memory in GB first, then how many ways you must slice it.

  1. Total memory. B GB. Why this step? Adam's optimizer states dominate — this is the "2.1 TB" arithmetic of the parent note at smaller scale. See GPU Memory Hierarchy.
  2. Per-device with split . Need , i.e. . Why this step? Tensor parallelism slices all of weights, grads and optimizer states by , so the requirement is a simple division.
  3. Smallest integer. . Why this step? must be a whole device count; is the least integer . With Mixed Precision Training (2 B weights) the budget would shrink and could drop.

Verify: . ✓ And , so fails — is indeed minimal. ✓


Forecast: guess whether the three numbers add or multiply.

  1. Total world size. GPUs. Why this step? The three parallelisms are orthogonal axes: every (tensor-slice, pipeline-stage, replica) triple is a distinct GPU, so counts multiply, not add.
  2. How many hold "stage 0, slice 0". Fix the tensor slice ( choice) and the pipeline stage ( choice); only the data-replica axis is free → GPUs. Why this step? Data parallelism duplicates the exact same slice across replicas; those are the copies that must sync gradients via all-reduce.
  3. Sanity of the split. Each GPU holds of the model (TP splits within a stage, PP splits across stages; DP does not shrink per-GPU model size). Why this step? Only TP and PP reduce the model footprint; DP trades memory for throughput.

Verify: . ✓ Replicas of one specific slice . ✓ Model fraction per GPU . ✓


Recall Quick self-test

Column-parallel forward reassembles with ::: concatenation (no communication in forward) Row-parallel forward reassembles with ::: an all-reduce (a sum across devices) Naive pipeline bubble fraction with ::: GPipe activation memory scales with ::: (number of micro-batches) 1F1B activation memory scales with ::: (number of pipeline stages) Combining TP, PP, DP multiplies world size to :::