Open the workspace
Research

How much GPU memory does fine-tuning need?

The memory formula for full fine-tuning, LoRA and QLoRA — weights, gradients, Adam state and activations — with a computed table for 8B to 70B models and the minimum H100 count for each.

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#

ModelMethodWeightsGradsOptimizerActivationsTotal GBMin. H100-80GB
8BFull fine-tuning1616961.6129.62
8BLoRA (bf16 base)16.10.10.51.618.31
8BQLoRA (4-bit base)4.50.10.51.66.71
14BFull fine-tuning29.629.6177.62.7239.54
14BLoRA (bf16 base)29.70.10.92.733.51
14BQLoRA (4-bit base)8.30.10.92.712.11
32BFull fine-tuning65.665.6393.63.4528.28
32BLoRA (bf16 base)65.90.323.471.61
32BQLoRA (4-bit base)18.40.323.424.11
70BFull fine-tuning141.2141.2847.26.51136.132
70BLoRA (bf16 base)141.90.74.26.5153.44
70BQLoRA (4-bit base)39.50.74.26.5511

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.

02004006008008B14B32B70BGB (unsharded)weightsgradientsoptimizer stateactivations
Figure 1. Full fine-tuning: optimizer state is three quarters of the memory. This is why sharding (ZeRO-3/FSDP) or adapters are not optional above ~8B.
0501001508B14B32B70BGB (unsharded)weightsgradientsoptimizer stateactivations
Figure 2. LoRA: the frozen bf16 weights dominate; optimizer state almost disappears. A 32B model fits on one 80 GB GPU only just.

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.
Rule of thumbFull fine-tuning: 16–18 GB per billion parameters across the cluster. LoRA: ~2.2 GB per billion plus activations. QLoRA: ~0.7 GB per billion plus activations.

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 lengthActivations (checkpointed)LoRA totalQLoRA total
4,0966.5 GB153 GB51 GB
8,19213.0 GB160 GB57 GB
16,38426.0 GB173 GB70 GB
32,76852.1 GB199 GB96 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#

  1. Turn on activation checkpointing and FlashAttention before anything else.
  2. Reduce micro-batch to 1 and use gradient accumulation to keep the effective batch.
  3. Switch Adam to an 8-bit or paged variant if you're doing full fine-tuning.
  4. Shard with FSDP / ZeRO-3 across all GPUs in the node.
  5. 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).

Reproduce thisEvery number and chart on this page is generated from research/cost_models.py in our research repository (Python, numpy, fixed seeds). See the methodology notes.

References#

  1. 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
  2. Korthikanti, V. et al. (2022). Reducing Activation Recomputation in Large Transformer Models. arXiv:2205.05198 (MLSys 2023). arxiv.org/abs/2205.05198
  3. Hu, E. J. et al. (2021). LoRA: Low-Rank Adaptation of Large Language Models. arXiv:2106.09685. arxiv.org/abs/2106.09685
  4. Dettmers, T., Pagnoni, A., Holtzman, A., Zettlemoyer, L. (2023). QLoRA: Efficient Finetuning of Quantized LLMs. arXiv:2305.14314. arxiv.org/abs/2305.14314

Bring a model and a metric.

Tell us what the model should get better at. A post-training engineer replies within one business day with a plan, a compute estimate and an eval design.