Out-of-memory errors are the most common reason a first fine-tuning run fails, and the fix is usually arithmetic, not trial and error. Training memory has four parts — weights, gradients, optimizer state and activations — and each scales differently with the method you choose. Here is the accounting, the formula, and a computed table for common model sizes.
The per-parameter accounting#
Mixed-precision training with Adam keeps, for every trainable parameter, a bf16 weight (2 bytes), a bf16 gradient (2 bytes), and in fp32 a master copy of the weight plus Adam's first and second moments (4 + 4 + 4 = 12 bytes). That is the "16 bytes per parameter" figure from the ZeRO paper (Rajbhandari et al., 2019):
For a 70B model that is about 1.1 TB before a single activation is stored. LoRA freezes the base weights and trains low-rank adapters with parameters, so only the adapters carry gradients and optimizer state (Hu et al., 2021):
QLoRA stores the frozen base in 4-bit NF4 with double-quantised scales (Dettmers et al., 2023); we use 0.55 bytes per parameter to include quantisation constants and a few layers kept in higher precision. We take , which corresponds to rank-16 to rank-64 adapters on all linear layers for these sizes.
Activations#
Korthikanti et al. (2022) give the activation memory of one transformer layer, without recomputation, as
for sequence length , micro-batch , hidden size and attention heads. The second term is the attention score matrix; FlashAttention-style kernels never materialise it, leaving about . With activation checkpointing you store only each layer's input ( bytes) and recompute the rest during the backward pass, so total activation memory is roughly plus one live layer. We assume checkpointing, FlashAttention, and micro-batch 1.
Computed table#
| Model | Method | Weights | Grads | Optimizer | Activations | Total GB | Min. H100-80GB |
|---|---|---|---|---|---|---|---|
| 8B | Full fine-tuning | 16 | 16 | 96 | 1.6 | 129.6 | 2 |
| 8B | LoRA (bf16 base) | 16.1 | 0.1 | 0.5 | 1.6 | 18.3 | 1 |
| 8B | QLoRA (4-bit base) | 4.5 | 0.1 | 0.5 | 1.6 | 6.7 | 1 |
| 14B | Full fine-tuning | 29.6 | 29.6 | 177.6 | 2.7 | 239.5 | 4 |
| 14B | LoRA (bf16 base) | 29.7 | 0.1 | 0.9 | 2.7 | 33.5 | 1 |
| 14B | QLoRA (4-bit base) | 8.3 | 0.1 | 0.9 | 2.7 | 12.1 | 1 |
| 32B | Full fine-tuning | 65.6 | 65.6 | 393.6 | 3.4 | 528.2 | 8 |
| 32B | LoRA (bf16 base) | 65.9 | 0.3 | 2 | 3.4 | 71.6 | 1 |
| 32B | QLoRA (4-bit base) | 18.4 | 0.3 | 2 | 3.4 | 24.1 | 1 |
| 70B | Full fine-tuning | 141.2 | 141.2 | 847.2 | 6.5 | 1136.1 | 32 |
| 70B | LoRA (bf16 base) | 141.9 | 0.7 | 4.2 | 6.5 | 153.4 | 4 |
| 70B | QLoRA (4-bit base) | 39.5 | 0.7 | 4.2 | 6.5 | 51 | 1 |
Unsharded totals in GB. "Min. H100" assumes ZeRO-3 / FSDP sharding of weights, gradients and optimizer state across GPUs (activations not sharded) and leaves ~10% headroom per GPU; counts are rounded up to powers of two. Architecture shapes are approximate public configurations for dense models of each size.
How to read the numbers#
- Full fine-tuning is an optimizer-state problem. At 70B, 847.2 of 1136.1 GB is Adam state. Sharding it across GPUs is what ZeRO stage 1–3 and FSDP do; 8-bit optimizers cut the 12 bytes to about 6.
- LoRA is a weights problem. At 70B, 141.9 GB of the 153.4 GB total is the frozen model. Sharding the frozen weights (FSDP with LoRA) or quantising them (QLoRA) are the two levers.
- Activations are small with checkpointing at 4k context — under 7 GB here — but scale linearly with sequence length and batch. At 32k context and micro-batch 4, multiply by 32.
- QLoRA puts 70B on one GPU (51 GB), consistent with Dettmers et al.'s 65B-on-48GB result. The price is slower steps and a small quality cost from training against a quantised base.
Long context changes the picture#
Activation memory grows linearly with sequence length even with checkpointing, while weights and optimizer state don't change. For the 70B architecture above with micro-batch 1:
| Sequence length | Activations (checkpointed) | LoRA total | QLoRA total |
|---|---|---|---|
| 4,096 | 6.5 GB | 153 GB | 51 GB |
| 8,192 | 13.0 GB | 160 GB | 57 GB |
| 16,384 | 26.0 GB | 173 GB | 70 GB |
| 32,768 | 52.1 GB | 199 GB | 96 GB |
At 32k tokens QLoRA no longer fits on an 80 GB GPU, and the activation term becomes the reason to shard or to use sequence/context parallelism, which splits activations across GPUs along the sequence dimension (Korthikanti et al., 2022). If your training data is long documents, size hardware from this table, not from the 4k one.
RL adds an inference footprint#
GRPO and PPO generate rollouts during training, so the same job also needs inference memory: the KV cache. For grouped-query attention with key/value heads of dimension , the cache for one sequence is
For a 70B-class model with 80 layers, 8 KV heads of dimension 128 and 4k-token rollouts, that is about 1.34 GB per sequence; a group of 16 rollouts for 32 prompts is 687 GB of cache on top of everything else. This is why RL jobs usually run generation on separate inference workers (vLLM or SGLang) and why memory bandwidth, not FLOPs, often bounds their speed — see H100 vs H200 vs B200.
Fitting a run you thought wouldn't fit#
- Turn on activation checkpointing and FlashAttention before anything else.
- Reduce micro-batch to 1 and use gradient accumulation to keep the effective batch.
- Switch Adam to an 8-bit or paged variant if you're doing full fine-tuning.
- Shard with FSDP / ZeRO-3 across all GPUs in the node.
- Move to LoRA, then QLoRA, if the above still doesn't fit — and evaluate whether quality holds on your task.
Hardware choice follows from the table: see H100 vs H200 vs B200 for fine-tuning. For adapters vs full weights on quality, see LoRA vs full fine-tuning and the LoRA glossary entry.
Frequently asked questions#
How much GPU memory do I need to fine-tune a 70B model?
Full fine-tuning needs roughly 1.1 TB across the cluster (about 32 H100-80GB with sharding and headroom). LoRA needs about 150 GB (4 H100s with sharding). QLoRA fits in about 50 GB, so a single 80 GB GPU works.
How much VRAM do I need to fine-tune an 8B model?
About 130 GB for full fine-tuning (2 H100s with sharding), around 18 GB with LoRA, and around 7 GB with QLoRA at 4k context with activation checkpointing.
Why does full fine-tuning need 16 bytes per parameter?
Mixed-precision Adam stores a bf16 weight and gradient (4 bytes) plus an fp32 master weight and two fp32 optimizer moments (12 bytes).
research/cost_models.py in our research repository (Python, numpy, fixed seeds). See the methodology notes.References#
- Rajbhandari, S., Rasley, J., Ruwase, O., He, Y. (2019). ZeRO: Memory Optimizations Toward Training Trillion Parameter Models. arXiv:1910.02054. arxiv.org/abs/1910.02054
- Korthikanti, V. et al. (2022). Reducing Activation Recomputation in Large Transformer Models. arXiv:2205.05198 (MLSys 2023). arxiv.org/abs/2205.05198
- Hu, E. J. et al. (2021). LoRA: Low-Rank Adaptation of Large Language Models. arXiv:2106.09685. arxiv.org/abs/2106.09685
- Dettmers, T., Pagnoni, A., Holtzman, A., Zettlemoyer, L. (2023). QLoRA: Efficient Finetuning of Quantized LLMs. arXiv:2305.14314. arxiv.org/abs/2305.14314