3.3.11 · D4Deep Learning Frameworks

Exercises — Distributed training overview

2,964 words13 min readBack to topic

This page is a self-testing ladder. Each problem states what you know and asks one clean question. Solutions are hidden inside collapsible callouts — try first, then reveal. Levels climb from "can you name it?" up to "can you design a real system?".

Everything here builds on the parent overview. If a symbol feels unfamiliar, that is a signal to re-read the relevant callout there before pushing on.

Figure — Distributed training overview
Figure s03 — Communication cost plotted against device count . The teal line is linear ring all-reduce ; the plum line is tree-based ; the dotted orange line is the (unrealistic) constant assumption we sometimes use for clean arithmetic. Reading it: both real curves climb as GPUs are added, so the "constant " is an optimistic floor, not the truth.


Level 1 — Recognition

Can you name the mechanism and read the vocabulary?

L1.1 — Match the strategy

Each device holds a full copy of the model but sees a different slice of the mini-batch. Name this strategy, and name the collective operation that averages the gradients.

Recall Solution

Data parallelism. The averaging step is the all-reduce operation: every device ends up holding the same summed-and-divided gradient . Why not model parallelism? In model parallelism no device has a full copy — the giveaway phrase here is "full copy of the model."

L1.2 — Read the picture

Look at the figure below. One coloured band shows layers 0–11 living on GPU 0, the next band shows layers 12–23 on GPU 1, and so on. Is this tensor parallelism or pipeline parallelism? What is the idle-time problem it creates called?

Figure — Distributed training overview
Figure s01 — Pipeline parallelism. Four coloured horizontal bands each represent one GPU holding a contiguous group of layers (GPU 0 holds layers 0–11, GPU 1 holds 12–23, and so on). The downward arrows on the right show activations being passed device-to-device as data flows through the layer groups in order.

Recall Solution

This is pipeline parallelism (the model is split vertically by layers — inter-layer splitting). Tensor parallelism would split a single layer's matrix across devices (intra-layer). The idle-time problem is the pipeline bubble: while GPU 0 works on batch 1, GPUs 1–3 have nothing yet to do, so they sit idle until data reaches them.

L1.3 — Sync or async?

A worker reads parameters , computes a gradient, but by the time it pushes the update the global model is already at . Which training mode is this, and what is the name for that gradient?

Recall Solution

This is asynchronous SGD. The gradient is a stale gradient — it was computed against an out-of-date copy of the weights. In synchronous SGD every device waits, so staleness cannot happen.


Level 2 — Application

Plug into the formulas.

L2.1 — Effective batch size

You run data parallelism on GPUs, each processing a micro-batch of images (no accumulation, so ). What effective batch size does the optimizer "see"?

Recall Solution

All 8 gradients get averaged into one update, so the math is identical to training on a single batch of 128 images on one (imaginary huge) GPU.

L2.2 — Gradient accumulation steps

Your GPU can only fit a batch of , but you want the training behaviour of on a single GPU (). How many micro-batches must you accumulate before each optimizer step?

Recall Solution

You run 16 forward+backward passes, averaging their gradients , then do one weight update. Why divide by 16? Each micro-batch gradient is already the average loss-gradient over its own 2 samples. If you just summed the 16 of them, the total would be 16× too large — as if the learning rate were secretly multiplied by 16. Dividing by restores the correct per-sample average, so the accumulated gradient has exactly the same scale as a real batch-of-32 gradient computed in one shot. That scale-matching is the whole point: same works unchanged. It is equivalent to batch 32, just 16× slower per update.

L2.3 — Speedup from the formula

Using with ms, , and ms, compute the actual speedup .

Recall Solution

Per-device compute: ms. So instead of the ideal , communication drags you down to about .


Level 3 — Analysis

Compare, diagnose, reason about behaviour.

L3.1 — Efficiency drop

From L2.3 you found with . Compute the scaling efficiency. Then explain in one sentence why doubling to (same ms) will make efficiency worse, not better.

Recall Solution

At : compute per device ms, so , and efficiency (50%). Why worse: as grows, the shared compute term shrinks toward zero, but the "constant" ms does not (and in reality it grows with ) — communication becomes a larger fraction of each iteration, so efficiency falls.

L3.2 — Bandwidth swap

BERT-Large has 340M float32 parameters. Each gradient is one float32 (4 bytes). Compute the raw gradient volume in gigabytes (use bytes). Then, if a 10 Gbit/s link gives ms and you upgrade to a 100 Gbit/s link, estimate the new and the new speedup with ms, .

Recall Solution

Volume bytes GB. Communication time is inversely proportional to bandwidth. A faster link gives roughly less time: New speedup: , efficiency (95%). Lesson: the algorithm never changed — only the interconnect. Communication is a hardware bottleneck as much as a software one.

L3.3 — Why the pipeline stalls

A pipeline splits a model over 4 devices. The first micro-batch takes 4 "stage-times" to reach the last device. If you push only 1 micro-batch through, how many of the stage-time slots are actually doing useful work, and what fraction is bubble?

Figure — Distributed training overview
Figure s02 — Pipeline-bubble grid. Rows are the 4 GPUs, columns are 4 time slots. Only the diagonal cells (teal, labelled "work") do useful computation — one busy device per time slot. All 12 off-diagonal cells (hatched, labelled "idle") are the bubble: devices waiting for data to arrive or having already finished.

Recall Solution

With a single micro-batch, exactly 4 slots are busy (the diagonal in the figure — each device works exactly once). The other slots are idle. Bubble fraction (75% idle!). This is why real pipeline training pushes many micro-batches in flight — the fixed startup/drain bubble gets amortised over more useful work, shrinking the idle fraction.


Level 4 — Synthesis

Design a scheme by combining pieces.

L4.1 — Hybrid layout

You must train a 100B-parameter model on 64 GPUs, arranged as 8 nodes × 8 GPUs. The model needs 8-way splitting just to fit in memory. Describe the hybrid layout: how many data-parallel replicas do you get, and what runs inside each replica?

Recall Solution

Use 8-way model parallelism inside each node (the model is spread over the 8 GPUs of one node so it fits), then replicate that whole node 8 times across the 8 nodes as data parallelism.

  • Data-parallel replicas: replicas.
  • Inside each replica: 8-way model parallelism. Gradients are all-reduced across the 8 replicas; within a replica the GPUs cooperate on one forward/backward of the split model.

L4.2 — Memory-and-batch plan

GPT-2 (1.5B params) OOMs at batch 2 on your 16 GB GPU, but batch 1 fits. You have 4 such GPUs and want an effective batch of 32. Combine data parallelism and gradient accumulation to hit exactly 32. Give the numbers.

Recall Solution

Here all three multipliers of are in play. Per GPU, max micro-batch that fits: . Across GPUs (data parallel), one synced step processes samples. To reach , accumulate over steps: accumulation steps. Plan: each GPU runs 8 forward/backward passes of batch 1, averaging its own 8 gradients; then one all-reduce across the 4 GPUs; then one weight update. Effective batch . ✓

L4.3 — When does async win?

You have a cluster where one "straggler" GPU is 3× slower than the others. In synchronous SGD, every iteration waits for it. Argue whether asynchronous SGD helps, and name its cost.

Recall Solution

Sync SGD is limited by the slowest device: every iteration pays the straggler's time. With a 3× slower GPU, the whole cluster runs at (roughly) the straggler's pace — the fast GPUs idle. Async SGD helps here: workers push updates whenever ready, so fast GPUs are not blocked by the straggler → better hardware utilization. The cost: stale gradients — a fast worker may apply a gradient computed against outdated weights, which can slow or destabilise convergence. So async trades deterministic correctness for throughput.


Level 5 — Mastery

One integrated question, reasoned end to end.

L5.1 — Full system budget

A team trains a model where a single full iteration would take ms on one device. They scale to data-parallel GPUs. The gradient tensor is 2 GB, and their interconnect moves 40 GB/s during all-reduce (treat ). (a) Compute . (b) Compute and efficiency. (c) They consider adding gradient accumulation of micro-batches to grow the effective batch — does that change per update, and what happens to communication frequency? Reason it out.

Recall Solution

(a) (b) Per-device compute ms. (c) Gradient accumulation runs forward/backward passes before a single all-reduce. Why does the single-device baseline become larger? Because "one update" now means processing as many samples (). To compare fairly, the baseline must also do that same total work on one device — and a lone GPU doing 4× the samples takes 4× the time, so its per-update time is ms. We scale the numerator precisely because the unit of work per update grew.

  • Compute per update grows 4× (four micro-batches), but communication happens once per update instead of once per micro-batch → the all-reduce is amortised over 4× more compute.
  • The ratio shrinks, so efficiency improves even though wall-clock per update goes up.
  • Numerically, per update: distributed time ms versus one-device baseline ms, giving ratio , efficiency (94%). Big-picture insight: accumulation is a lever that trades update frequency for communication efficiency — fewer, bigger updates make the fixed sync cost matter less.

Recall Quick self-check ledger (reveal after finishing)

L2.1 :: B = 128 L2.2 :: a = 16 accumulation steps L2.3 :: S ≈ 2.667 L3.1 :: efficiency ≈ 0.667 at k=4, drops to 0.5 at k=8 L3.2 :: 1.36 GB; new comm 5 ms; S ≈ 3.81, efficiency ≈ 0.95 L3.3 :: 4 useful slots, bubble fraction 0.75 L4.2 :: b=1, k=4, a=8 accumulation steps L5.1 :: T_comm = 50 ms; S = 4.8; efficiency 0.8; with accum ratio ≈ 5.65, eff ≈ 0.94

Connections

  • Parent: Distributed training overview
  • The gradient being averaged comes from 3.9-Gradient-descent-optimizers on top of 3.1-Neural-network-basics.
  • Big batches interact with 3.3.5-Batch-normalization statistics.
  • Model-parallel giants like Transformers motivate tensor/pipeline splits.
  • Hardware context: 4.2-GPU-acceleration and 5.1-Training-at-scale.