Lesson deck

Training at scale: memory arithmetic, parallelism, mixed precision and scaling laws flashcards

Reviewing needs JavaScript. You can read every card in the list below.

Loading your cards...

Back to the lesson13 cards in this deck

Read all 13 cards as a list
  1. Front
    How much memory per parameter does mixed-precision Adam need, and what is in it?
    Back
    16 bytes, before activations. 2 for fp16 weights, 2 for fp16 gradients, and 12 for optimizer states (an fp32 copy of the weights plus two fp32 Adam moments). A 7B model needs 112 GB of state; 1.5B needs 24 GB; 70B needs 1,120 GB. Activations, buffers and fragmentation come on top.
  2. Front
    Which memory line item grows with batch size and sequence length?
    Back
    Activations. Weights, gradients and optimizer states depend on the parameter count and the optimizer. So a model whose state fits can still run out of memory when you raise the batch, and the fixes (smaller micro-batch, checkpointing) target activations.
  3. Front
    What is the linear scaling rule, and why warmup?
    Back
    Multiply the batch by k, multiply the learning rate by k, keep other hyperparameters. It assumes the gradient barely changes over k steps, which fails early in training, so ramp the rate gradually to the target. In the ImageNet study it held from batch 64 to 8,192 and degraded after. Re-tune for adaptive optimizers.
  4. Front
    How do you accumulate gradients correctly, and what does it not fix?
    Back
    Add the per-sample gradients of each micro-batch and divide by the total number of samples once, so a short last chunk counts for its size. In the lesson script the weighted result matched -28.885, an unweighted mean gave -35.375 and an undivided sum -106.125. Batch norm still sees only the micro-batch. For token-level losses (causal LMs), sum the token losses and divide by the total non-padding tokens of the effective batch, not by an average of per-micro-batch means.
  5. Front
    Why master weights, loss scaling, and dynamic scale in fp16 training?
    Back
    Master weights, because 1.0 + 0.0001 rounds back to 1.0 in fp16, so small updates must accumulate in fp32 (100 updates give 1.0100 against 1.0). Loss scaling, because a gradient of 1e-8 flushes to 0 in fp16 and is kept at scale 1,024. Dynamic scale, because too large a scale overflows to infinity (max 65,504): skip the step and halve on overflow, double after a clean run.
  6. Front
    What does DDP do, and what does it not do?
    Back
    Every device holds a full model copy, runs its slice of the batch, and the gradients are averaged with a bucketed all-reduce overlapped with the backward pass, so all copies apply the same update. It does not reduce memory per device. Ring all-reduce time is about 2S/B almost regardless of the device count.
  7. Front
    What do the ZeRO stages shard, and what does FSDP call them?
    Back
    Stage 1 shards optimizer states, stage 2 adds gradients, stage 3 adds weights. For a 7B model on 8 devices that is 38.5, 26.2 and 14.0 GB against 112 GB. Stage 3 costs about 50% more communication in the paper. FSDP FULL_SHARD is the stage-3 analogue and SHARD_GRAD_OP the stage-2 analogue; HYBRID_SHARD shards in a node and replicates across nodes. PyTorch 2.15 also ships FSDP2 (fully_shard, per-parameter DTensor sharding) and suggests FSDP1 users consider migrating.
  8. Front
    Tensor versus pipeline parallelism. Where does each run, and what is the bubble?
    Back
    Tensor parallelism splits matrices inside a layer and communicates in every layer, so keep it inside a server. Pipeline parallelism splits layers into stages and passes activations. The bubble is the idle share, (p - 1) / (m + p - 1): 8 stages with 63 microbatches give 10%. More stages need more microbatches, so a bigger batch.
  9. Front
    What does activation checkpointing trade, and how much?
    Back
    Memory for compute. Keep k segment boundaries and recompute the rest in the backward pass. Peak is about k + n/k layer units, best near the square root of n (100 layers: 100 units down to 20). The price is one extra forward pass, about a third more compute if backward is twice forward. Chen et al. report about 30% more time.
  10. Front
    How do you tell a data-loader bottleneck, and how many workers do you need?
    Back
    Accelerator utilisation is low and step time falls when you add loader workers or does not depend on the model. A step takes max(compute, load / workers). With compute 0.25 s and load 0.9 s per worker, 1 to 4 workers give 0.9, 0.45, 0.3 and 0.25 s. Workers beyond 4 change nothing.
  11. Front
    What goes in a checkpoint, and how often should you write one?
    Back
    Weights, optimizer states, schedule and step position, data position and random states, written per shard in sharded training so they can reshard on load. First-order best interval is sqrt(2 x write x MTBF): 3 min write and a failure every 360 min give 46.5 min and about 13% of time lost. Reproducible experiments, not bit-identical runs.
  12. Front
    Estimate the cost of training a model.
    Back
    FLOPs about 6ND (N parameters, D tokens: 2N forward, 4N backward per token), days = FLOPs / (devices x peak x utilisation x 86,400). 7B parameters on 1T tokens is 4.2e22 FLOPs, 3.96 days on 1,024 devices at an assumed 300 TFLOP/s peak and 40% utilisation. State the assumptions. The rule ignores attention cost. Against the paper's 5.76e23 for Gopher's budget, 6ND is 12.5% low for Gopher and 2.1% high for Chinchilla.
  13. Front
    What did Kaplan and Hoffmann find about model size and data?
    Back
    Kaplan et al.: loss follows power laws in size, data and compute, and large models on modest data are compute-efficient. Hoffmann et al.: scale model size and tokens in equal proportion. Chinchilla (70B, 1.4T tokens) beat Gopher (280B, 300B tokens) at the same compute. About 20 tokens per parameter is that one result's ratio, not a law, and ignores serving cost.