Memory has four parts: weights, gradients, optimizer states, and activations.
With mixed precision and Adam, a rule of thumb is about 16 bytes per parameter: 2 for BF16 weights, 2 for gradients, 4 for FP32 master weights, and 8 for the two Adam moments. A 7B model needs roughly 112 GB before counting activations.
Activations grow with batch size and sequence length; gradient checkpointing, smaller micro-batches and shorter sequences reduce them.
LoRA cuts gradient and optimizer memory to the adapter parameters only; QLoRA also shrinks the stored base weights to about 0.5 bytes per parameter.
Loading…