Skip to content
BIASED

Distributed training

Block 1 of 6~3 min

Count state and allocation lifetimes

Adding workers changes two things at once: where the training state lives and which computations must exchange results. A model can fit across three devices yet run slower because every layer waits for communication. Another can finish a step faster while silently changing the loss normalization. We need a memory ledger, a computation contract and a schedule before a device count is meaningful.

This note uses original scalar data, integer vectors and hypothetical byte counts. A standard-library program executes the reductions, matrix identities, dependency schedule and gradient recomputation. It does not run PyTorch, NCCL or a GPU, and its slot counts are not measured accelerator timings.

Start with the operation that must remain unchanged

A training step reads a specified batch, computes a loss and gradients, then updates parameters and optimizer state. Distributing that step should preserve the intended objective unless a deliberate algorithm change is being evaluated. Identical filenames or equal parameter counts do not establish this: data sampling, gradient normalization and update timing matter.

First establish a small reference calculation. Compare distributed outputs and gradients against it on permitted fixed inputs. Then measure device memory, time spent computing, time waiting for collectives and input-pipeline stalls. An out-of-memory failure and low utilization require different interventions. A faster step also does not guarantee less time to the required validation quality if the effective batch or optimizer behaviour changed.

For the following memory exercise, stipulate a model with twelve million trainable scalar parameters. That is a sizing input, not an actual trained network. Separate it from the six scalar records used to check gradient averaging: each small case isolates one mechanism instead of pretending to benchmark a full training system.

Count every state and its lifetime

Assume a particular mixed-precision layout: two bytes per working parameter, four per gradient, four for a master parameter and eight for the two optimizer moments. The last three arrays are explicitly full precision. Thus persistent model-related storage is

M=N(2+4+4+8)=18N bytes.M=N(2+4+4+8)=18N\text{ bytes}.

For N=12000000N=12000000, this is 216 MB in decimal units. A different gradient dtype, optimizer, master-copy policy or parameter aliasing changes the ledger. There is no universal bytes-per-parameter constant for mixed precision. Count actual allocations in the implementation being considered.

This ledger excludes activations retained for backward, temporary kernel workspaces, collective buffers, allocator overhead and input batches. Peak memory depends on which objects coexist. Adding the largest independent measurements from different times can overestimate the peak; ignoring a temporarily gathered parameter block can underestimate it. A useful profile records allocation lifetimes around forward, backward and the optimizer step.

Reducing a local microbatch often reduces activations while leaving parameter and optimizer storage unchanged. Sharding optimizer state addresses a different part of the ledger. Activation recomputation trades extra work for fewer retained intermediates. These choices can be combined, but each needs its own measured effect and correctness check.

Answers are saved on the server and tied to this browser until you sign in.

Go deeper — optional

Code and labs do not count toward the main percentage or the certificate.

  • Preserve gradients across a distributed layoutoptional

    All timings are abstract slots and traffic is stipulated payload bytes. No GPU, distributed runtime or tensor package is used. Persistent storage and temporary replay buffers are distinct counts, not measured peak memory.

    ~20 min · easier on a computer · The corresponding lesson and basic Python functions.

    Self-check in the notebook — not part of mastery or the certificate.