Your model plus optimiser state exceeds one GPU’s memory. List the options, from cheapest to most complex.
Answer
Model answer, written in a candidate's voice
In short
- Cheap single-GPU wins first: bf16, small micro-batches + gradient accumulation, activation checkpointing; these mainly cut activation memory.
- Rough budget: ~16 bytes/param for bf16 weights + grads + fp32 master + Adam m and v (same as fp32 Adam), plus activations; e.g. 7B x 16 B = 112 GB.
- Then shard across GPUs: ZeRO-1 (optimiser states), ZeRO-2 (+ gradients), FSDP/ZeRO-3 (full sharding, ~16/N bytes/param per GPU); plain data parallelism does not reduce per-GPU memory.
- Add CPU/NVMe offload or 8-bit/factored optimiser states when still too big, accepting slower steps.
- For very large layers/depth, use tensor parallelism (within layers) and pipeline parallelism (across stages).
In full
The first thing I’d do is not buy hardware: switch to bf16 autocast, use small micro-batches with gradient accumulation, and enable activation checkpointing, accepting some recompute. Those three mainly shrink activation memory, though, not the model-plus-optimiser state. The rough budget for mixed-precision training with Adam is about 16 bytes per parameter, which is the same as plain fp32 Adam, plus activations:
So if weights and optimiser state alone do not fit, I’d shard across GPUs: ZeRO-1 for optimiser states, ZeRO-2 adding gradients, then FSDP/ZeRO-3 for full parameter sharding, which brings the state to roughly 16/N bytes per parameter on each of N GPUs. Plain data parallelism does not help, because every replica holds the full state. If still over budget, CPU/NVMe offload, or 8-bit or factored optimiser states, can help but trade speed or some numerical risk for memory. Tensor and pipeline parallelism are the last resort for very large layers or depth, splitting individual layers or the model across devices at the cost of more complexity and communication.
What a strong answer covers
- Mixed precision (bf16), gradient accumulation (small micro-batches), activation checkpointing.
- Optimiser-state sharding (ZeRO-1/2), full sharding (FSDP/ZeRO-3), CPU/NVMe offload.
- Tensor and pipeline parallelism for very large layers or depth.
- Rough memory arithmetic: weights + gradients + Adam states ≈ 16 bytes/param in mixed precision, plus activations.
Common mistakes
- forgetting optimiser-state memory
- assuming data parallelism alone reduces per-GPU memory.