Reduce the batch size and use gradient accumulation to keep the effective batch size.
Use mixed precision (BF16 or FP16), activation (gradient) checkpointing, and a memory-efficient attention such as FlashAttention.
Shorten sequence length or crop images, use a smaller model or LoRA, and use an 8-bit or paged optimizer.
For larger models, shard across GPUs (data, tensor, pipeline parallelism, or ZeRO and FSDP) and offload to CPU as a last resort.
Profile first: parameters, gradients, optimizer states and activations each take memory, and Adam alone adds about two extra copies of the weights.
Loading…