induwara.lk
induwara.lkAI · GPU memory

LLM Training Memory (VRAM) Calculator

Estimate the GPU memory to train or fully fine-tune a transformer LLM — split into weights, gradients, Adam optimizer states, and activations — then shard it across GPUs with ZeRO and check whether it fits a 4090, A100, or H100. Formulas cited, runs in your browser.

By Induwara AshinsanaUpdated Jul 18, 2026
Training memory estimate
Formulas cited · EleutherAI + ZeRO
Popular setups

Mixed-precision AdamW (16 B/param) — see the byte-per-param table below.

Set more than 1 GPU for ZeRO sharding to reduce per-GPU memory.

Recompute activations in the backward pass to trade compute for memory. Cuts activation memory to ≈ 2·s·b·h per layer.

Total training memory (1 device)
148 GiB
Weights + gradients + optimizer + activations. Add ≈ 1.00 GiB CUDA/framework overhead.
Per-GPU memory
148 GiB
Model states replicated on every GPU (pure data-parallel).

Memory breakdown (single device)

ComponentMemoryShare
Model weights (2 B/param)14.9 GiB10.09%
Gradients (2 B/param)14.9 GiB10.09%
Optimizer states (12 B/param)89.4 GiB60.53%
Activations28.5 GiB19.29%
Total148 GiB100%

Cross-check: the ZeRO closed form K·Ψ = 16 B/param × 8B = 119 GiB of model states, matching the weights + gradients + optimizer rows above to the byte.

Does per-GPU memory fit these cards?

GPUVRAMFitHeadroom
RTX 4090 24 GB24 GiB7×124 GiB over
A100 40 GB40 GiB4×108 GiB over
A100 80 GB80 GiB2×67.7 GiB over
H100 80 GB80 GiB2×67.7 GiB over

A ✕ with an N× means the per-GPU footprint needs that many cards of this type (add more data-parallel GPUs, a higher ZeRO stage, or gradient checkpointing). Leave ~1–2 GiB spare for the CUDA context and fragmentation.

Gradient checkpointing
Turning it on would cut activations by about 28.0 GiB.
Per-GPU by ZeRO stage
  • None (pure data-parallel)148 GiB
  • ZeRO Stage 1148 GiB
  • ZeRO Stage 2148 GiB
  • ZeRO Stage 3 (FSDP)148 GiB

All equal at 1 GPU — ZeRO only helps once you shard across ≥ 2 GPUs.

Estimates use closed-form formulas from EleutherAI's Transformer Math 101, the ZeRO paper (model states + sharding) and Korthikanti et al. (activations). Real usage varies with framework buffers (DeepSpeed/FSDP), kernel workspaces, and fragmentation. Model specs verified from official model cards. This v1 covers data-parallel + ZeRO stages only — not tensor/pipeline parallelism.

How it works

Training memory is dominated by four parts. This calculator computes each in bytes from published transformer formulas and shows the result in GiB (1 GiB = 2³⁰ bytes), the unit GPU VRAM is actually sized in.

Model states — weights, gradients, optimizer. The ZeRO paper models these as a fixed number of bytes per parameter. For mixed-precision AdamW that is 2 + 2 + 12 = 16 bytes/param: a 2-byte FP16 weight, a 2-byte FP16 gradient, and 12 bytes of Adam state (a 4-byte FP32 master copy plus the first and second moments, m and v, at 4 bytes each). Full FP32 AdamW is also 16 bytes/param (4 + 4 + 8); 8-bit Adam compresses the moments to 10 bytes/param. Multiply by the parameter count Ψ and you have the model state: K · Ψ.

Activations. These scale with sequence length and batch, not parameter count, and often dominate for smaller models. Using the per-layer formula from Korthikanti et al. (no recomputation):

act_per_layer = s · b · h · (34 + 5 · a · s / h)

where s is sequence length, b the micro-batch, h the hidden size, and a the number of attention heads. Total activations are that times the number of layers L. With gradient (activation) checkpointing, only one input tensor per layer is stored and the rest are recomputed in the backward pass, cutting activations to about L · 2 · s · b · h bytes.

Sharding across GPUs. With plain data-parallel training the full model state sits on every GPU. ZeRO partitions it instead: Stage 1 shards the optimizer states, Stage 2 also the gradients, and Stage 3 (equivalent to PyTorch FSDP) the weights too — so across N GPUs Stage 3 divides the whole 16-bytes/param state by N. Activations are never sharded by ZeRO; they stay per-GPU. The single-device total is the sum of the four parts; the per-GPU figure applies the sharding you choose. Add roughly 1 GiB for the CUDA context and framework buffers on top.

Worked examples

Llama 3 8B · full fine-tune · mixed AdamW · 1 GPU

s = 2048, b = 1, no checkpointing

  1. Weights: 2 × 8e9 = 16.0e9 B = 14.9 GiB
  2. Gradients: 2 × 8e9 = 16.0e9 B = 14.9 GiB
  3. Optimizer (Adam): 12 × 8e9 = 96.0e9 B = 89.4 GiB
  4. Model states total: 16 × 8e9 = 128e9 B = 119.2 GiB
  5. Activations: inner = 34 + 5·(32·2048)/4096 = 114
  6. → 2048·1·4096·114 × 32 layers = 30.6e9 B = 28.5 GiB
  7. Total ≈ 147.7 GiB → does not fit one 80 GiB card ✗

Same model with ZeRO-3 across 2 GPUs + checkpointing

Shows how sharding + recompute bring it down

  1. ZeRO-3 shards model states: 119.2 / 2 = 59.6 GiB per GPU
  2. Checkpointing activations: 32 · 2 · 2048 · 1 · 4096 = 0.5 GiB
  3. Per-GPU ≈ 59.6 + 0.5 = 60.1 GiB → fits A100/H100 80 GiB ✓
  4. Without checkpointing: 59.6 + 28.5 = 88.1 GiB → still over 80 GiB ✗

GPT-2 124M · mixed AdamW · 1 GPU

s = 1024, b = 8 — activations dominate

  1. Model states: 16 × 0.124e9 = 1.984e9 B = 1.85 GiB
  2. Activations: inner = 34 + 5·(12·1024)/768 = 114
  3. → 1024·8·768·114 × 12 layers = 8.6e9 B = 8.01 GiB
  4. Total ≈ 9.86 GiB → fits an RTX 4090 (24 GiB) ✓
  5. Note: activations (8.0 GiB) exceed model states (1.85 GiB) here.

Frequently asked questions

Sources & references

Formulas and byte-per-parameter figures on this page were last cross-checked against the sources above on 2026-07-18. Estimates are close but not exact — framework buffers, attention kernels, and fragmentation move real usage by 10–20%.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.