LLM GPU VRAM Requirement Calculator

This calculator adds up the four things that occupy GPU memory when you run a language model: the weights, the KV cache, the gradient and optimizer state if you are training, and the framework overhead nobody budgets for. Enter the parameter count, the precision you plan to load at, the architecture numbers from the model config and your context length, and it returns the total in GiB and the number of GPUs that implies. It also sweeps every precision so you can see what quantisation actually buys — and where it stops helping.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Parameter countIn billions, as the model card states it — 8 for Llama-3-8B, 70 for a 70B model.8 B
Weight precisionHow each weight is stored in memory. Most open-weight models ship in bf16.fp16 / bf16 — 2 bytes
What you are doingInference budgets a KV cache; the two training modes budget gradients, optimizer states and retained activations instead.Inference / serving
Transformer layersnum_hidden_layers in the model config.32
Hidden sizehidden_size in the config — the residual stream width.4096
Key/value headsnum_key_value_heads. With grouped-query attention this is smaller than the number of attention heads.8
Head dimensionUsually hidden size divided by the number of attention heads.128
Context length in tokensThe longest prompt plus generation you intend to support, per sequence.8192
Concurrent sequencesRequests in flight at once for serving, or the micro-batch size for training.1
KV cache precisionThe cache is usually kept at fp16 even when the weights are quantised.fp16 / bf16 — 2 bytes
Trainable share for LoRAAdapter parameters as a percentage of the base model — typically 0.1% to 1%.0.5 %
Framework and workspace overheadAllowance for the CUDA context, kernel workspaces and allocator fragmentation, as a percentage of the weights.15 %
Usable memory per GPUUsable, not marketed: an 80 GB card reports about 79.2 GiB and the driver keeps a little of that.80 GiB

It returns

  • Total VRAM required — Weights plus cache plus training state plus overhead.
  • Weight memory
  • KV cache
  • Gradients and optimizer states
  • Activations and framework overhead
  • GPUs needed
  • Headroom left on those GPUs

The formula

VRAM=Nb+2LHkvdhsBbkv+14Ntrain+O
bytes/token=2LHkvdhbkv
G=totalper GPU

In plain text: VRAM = params·b + 2·L·Hₖᵥ·dₕ·s·B·bₖ + trainable·14 + overhead

  • NParameter count (parameters)
  • bBytes per weight: 4 for fp32, 2 for fp16/bf16, 1 for int8, 0.5 for int4 (bytes)
  • LNumber of transformer layers (count)
  • HₖᵥKey/value heads (fewer than attention heads under grouped-query attention) (count)
  • dₕHead dimension (count)
  • sContext length in tokens (tokens)
  • BConcurrent sequences (count)
  • bₖᵥBytes per cached value, usually 2 (bytes)
  • NₜᵣₐᵢₙTrainable parameters — all of them for a full fine-tune, the adapters only for LoRA (parameters)
  • ORetained activations plus framework and allocator overhead (bytes)

Divide the byte total by 1024³ to get GiB. The leading 2 in the cache term is because both a key and a value are stored for every token in every layer.

Updated Category Model Memory & GPU Sizing Verified against published test cases Reading time 11 min

The four things that occupy a GPU when you run a model

People size GPUs by parameter count alone, and then run out of memory at 3,000 tokens of context. Parameter count sets only the first of four terms. What actually has to fit is the weights, the KV cache that grows with every token you process, the gradient and optimizer state if you are training, and a layer of framework overhead that is real, unglamorous and consistently forgotten.

The weights are the easy part: multiply the parameter count by the bytes per weight. A bf16 model needs two bytes per parameter, so 8 billion parameters is 16 billion bytes, which is 14.90 GiB once you divide by 1024³. That division is the first place estimates go wrong — GPU memory is quoted in GiB by every tool that reports it, while model sizes are quoted in decimal billions, and the two differ by 7.4%.

The KV cache is the term that surprises people. During generation the model keeps the key and value vectors for every token it has already seen, in every layer, so it does not have to recompute attention over the whole prefix at each step. That is a per-token, per-sequence cost, and at long context it can exceed the weights. Training replaces this term with a much larger one: gradients, Adam moments and master weights, which together run to 14 bytes per trainable parameter.

Where each term comes from

Weights. Parameter count times bytes per parameter. Quantisation is exactly linear here: int8 halves fp16, int4 halves int8. Nothing else in the budget shrinks when you quantise the weights, which is why the total never falls as fast as the headline claim.

KV cache. Two tensors (a key and a value) per token, per layer, per key/value head, each of head-dimension length: 2 × layers × kv_heads × head_dim × tokens × sequences × bytes. The kv_heads figure is the one to check in the config. Under multi-head attention it equals the number of attention heads; under grouped-query attention, which nearly every recent open-weight model uses, it is much smaller — 8 instead of 32 on Llama-3-8B, cutting the cache by a factor of four. That reduction is the main reason GQA exists.

Training state. Mixed-precision training with Adam keeps, per trainable parameter, a 2-byte gradient, a 4-byte fp32 master copy of the weight, and two 4-byte Adam moments — 14 bytes on top of the 2-byte working weight, so 16 bytes per parameter in total. That is why a full fine-tune of a 7B model needs roughly eight times the memory of serving it, and why LoRA works: freeze the base, train adapters worth well under 1% of the parameters, and the 14-byte term applies only to them.

Activations and overhead. The backward pass needs activations from the forward pass. With gradient checkpointing you keep roughly one hidden-state tensor per layer, which is batch × tokens × hidden × layers × 2 bytes; without it the figure is several times larger and depends on the implementation. On top of that sits the CUDA context, kernel workspaces and allocator fragmentation, budgeted here as a percentage of the weights — 10–20% is a workable allowance for a typical serving stack.

Worked example: serving an 8B model at 8k context

Take a Llama-3-8B-class model: 8.03 billion parameters, 32 layers, hidden size 4,096, 8 key/value heads, head dimension 128. You want to serve it in bf16 at 8,192 tokens of context, one request at a time, on a single 80 GiB card.

  1. Weights. 8 × 10⁹ × 2 bytes = 16 × 10⁹ bytes. Divide by 1024³ = 1,073,741,824: 14.901 GiB.
  2. KV cache per token. 2 × 32 layers × 8 kv heads × 128 × 2 bytes = 131,072 bytes = 128 KiB per token.
  3. KV cache total. 131,072 × 8,192 tokens × 1 sequence = 1,073,741,824 bytes = exactly 1.000 GiB.
  4. Overhead. 15% of the weights = 0.15 × 14.901 = 2.235 GiB.
  5. Total. 14.901 + 1.000 + 2.235 = 18.136 GiB, so one 80 GiB card with 61.86 GiB to spare.

That headroom is not wasted — it is what lets you raise the batch size. Each additional concurrent sequence at 8k context costs another 1.000 GiB, so the same card holds roughly 60 concurrent 8k sequences before memory, rather than compute, becomes the limit.

Push the context instead and the arithmetic changes character. At 131,072 tokens the cache is 16 × 1.000 = 16.000 GiB, slightly more than the weights themselves, and the total reaches 33.136 GiB. At that point quantising the weights to int4 would save 11.18 GiB while halving the KV cache precision would save 8 GiB — and the second option leaves the model’s output quality alone in a way the first does not.

Reading the result and deciding what to change

Compare the total against usable memory, not marketed memory. A card sold as 80 GB reports about 79.2 GiB, the driver and CUDA context hold some of that before your process allocates anything, and PyTorch’s caching allocator fragments over long-running serving. Leaving 10% clear of the number this calculator produces is a reasonable operating margin; running at 98% will work in a benchmark and fail in production.

Read the component breakdown before you decide what to cut, because the biggest term tells you which lever works. If the weights dominate, quantisation helps and context reduction does almost nothing. If the KV cache dominates — which the calculator flags explicitly when it exceeds the weights — quantising further is close to pointless, and the effective moves are a shorter context, a smaller batch, an fp8 cache, or a model with fewer KV heads.

When the answer is more than one GPU, treat the number as a floor. Tensor parallelism replicates some buffers and adds communication workspace on every device, so a model that computes to 1.4 GPUs does not run on two GPUs at 70% each. Pipeline parallelism adds activation buffers between stages. In both cases the practical requirement lands above the arithmetic.

For training, the single most useful comparison is LoRA against a full fine-tune on the same model. At 0.5% trainable parameters, the 14-byte term applies to 1/200th of the network, so the gradient and optimizer memory falls by the same factor — on a 7B model that is roughly 98 GiB down to 0.5 GiB. The frozen base still has to be resident, so LoRA does not make the weights free, but it removes the term that made full fine-tuning impossible on one card.

Weight memory alone, by model size and precision

Parameter count × bytes per parameter ÷ 1024³. Add the KV cache and overhead on top of every figure here.
Parametersfp32 (4 B)fp16 / bf16 (2 B)int8 (1 B)int4 (0.5 B)
1B3.73 GiB1.86 GiB0.93 GiB0.47 GiB
7B26.08 GiB13.04 GiB6.52 GiB3.26 GiB
8B29.80 GiB14.90 GiB7.45 GiB3.73 GiB
13B48.43 GiB24.21 GiB12.11 GiB6.05 GiB
70B260.77 GiB130.39 GiB65.19 GiB32.60 GiB
405B1,508.71 GiB754.35 GiB377.18 GiB188.59 GiB

Every row is a multiple of the 1B row, because the relationship is exactly linear. The 70B int4 row at 32.60 GiB is why two 24 GiB consumer cards are the usual floor for running a 70B model locally.

GB and GiB are not the same, and it matters here

Model sizes are quoted in decimal billions of parameters, and GPU memory is reported in binary gibibytes. One GiB is 1,073,741,824 bytes, 7.4% more than a decimal gigabyte. An 8B bf16 model is 16 decimal GB of weights and 14.90 GiB — the same quantity described two ways. This calculator works in GiB throughout, because that is what nvidia-smi, PyTorch and every allocator error message report. If you compare a GiB figure against a GB card specification you will conclude a model fits when it does not.

Assumptions this calculator makes, and what it leaves out

  • It assumes gradient checkpointing when training. Without it, retained activations are several times larger and depend heavily on the implementation and on whether attention is computed with a fused kernel.
  • It assumes Adam or AdamW. SGD with momentum keeps far less state; 8-bit optimizers cut the moment tensors to a quarter of the fp32 figure.
  • It assumes one device holds everything. ZeRO stage 2 and 3, and FSDP, shard the optimizer states, gradients and eventually the parameters across devices, dividing the largest training term rather than replicating it.
  • It assumes a dense model. A mixture-of-experts model must hold all expert weights in memory even though only a few are active per token, so size it by total parameters, not active ones.
  • It ignores paged and shared caches. Serving stacks that page the KV cache or share prefixes across requests use less than the per-sequence arithmetic suggests when prompts overlap.
  • It ignores speculative decoding and draft models. A draft model is a second set of weights and a second cache, both of which have to fit alongside the target.
  • It says nothing about speed. Fitting in memory and running fast are separate questions; memory bandwidth, not capacity, usually sets tokens per second once the model fits.

If you do not know the parameter count — or you want to know how it splits between attention, feed-forward and embeddings — derive it from the config with the transformer parameter count calculator, then bring the total back here. For a closer look at the term that dominates long-context serving, the KV cache size calculator handles paged allocation and per-request budgeting in more detail than the single line in this budget.

Memory is only one of the two constraints on a training run; the other is arithmetic, which the training compute calculator estimates from tokens and parameters. When you are sizing a multi-GPU job, the scaling you actually get is bounded by the serial fraction of the work, which is the question Amdahl’s law answers. And once the model is trained and served, whether it is any good is a different measurement entirely — that is what the F1 and classification metrics calculator is for.

Frequently asked questions

How much VRAM do I need to run a 70B model?

About 33 GiB at int4 with a short context, 65 GiB at int8, and 130 GiB at bf16 before you add anything else. The int4 figure is 35 × 10⁹ bytes ÷ 1024³ = 32.60 GiB of weights, so two 24 GiB cards is the usual minimum for local use and a single 80 GiB card is comfortable. At bf16 you need at least two 80 GiB cards. Add the KV cache on top: at 4,096 tokens with 8 KV heads and 80 layers it is 1.25 GiB per sequence.

Why does my model use more memory than the parameter count suggests?

Three reasons, in order of size. The KV cache grows with context length and batch size and is invisible until you send a long prompt. Framework overhead — CUDA context, kernel workspaces, allocator fragmentation — typically adds 10–20% of the weight figure. And GiB is 7.4% larger than GB, so a “16 GB” model is 14.9 GiB and a “16 GB” card is about 15.8 GiB usable. The gap between naive and real is routinely 25% or more.

How is the KV cache size calculated?

2 × layers × kv_heads × head_dim × tokens × sequences × bytes per value. The leading 2 is the key and the value. For a 32-layer model with 8 KV heads of dimension 128 at fp16, that is 131,072 bytes — 128 KiB — per token per sequence, so 8,192 tokens costs exactly 1 GiB. Check num_key_value_heads rather than num_attention_heads in the config: with grouped-query attention they differ, usually by a factor of four.

Does quantisation reduce the KV cache?

Not by itself. Weight quantisation and cache quantisation are separate settings, and loading int4 weights leaves an fp16 cache exactly as large as it was. Several serving stacks support an fp8 or int8 cache as its own option, which halves that term. This matters most at long context: when the calculator reports that the cache exceeds the weights, further weight quantisation moves the total very little while cache precision moves it a lot.

How much VRAM does LoRA fine-tuning need compared with a full fine-tune?

Roughly the inference footprint plus a few gigabytes, instead of eight times the inference footprint. A full fine-tune keeps 14 bytes of gradient, master weight and Adam state per parameter on top of the 2-byte working weight, which is 16 bytes per parameter in total. LoRA freezes the base and applies that 14-byte cost only to the adapters — often 0.5% of the parameters — so on a 7B model the state term falls from about 98 GiB to under 1 GiB. The frozen base still has to be resident.

Can I split a model across two GPUs?

Yes, and the calculator tells you how many devices the memory requires, but treat that as a floor. Tensor parallelism splits each layer across devices and adds communication buffers and some replicated state on every one of them; pipeline parallelism assigns whole layers to devices and adds activation buffers between stages. Both work best over a fast interconnect — across PCIe rather than NVLink, a two-way split can cost more in communication than it gains in capacity.

What does the overhead percentage actually cover?

The CUDA context and driver allocations that exist before your model loads, the scratch workspaces cuBLAS and attention kernels request, temporary tensors during a forward pass, and fragmentation in the caching allocator over a long-running process. Fifteen percent of the weight memory is a reasonable default for a typical serving stack. Raise it if you run many concurrent variable-length requests, since fragmentation grows with allocation churn; lower it for a single static batch shape.

Does this apply to mixture-of-experts models?

Only if you enter the total parameter count rather than the active one. An MoE model routes each token to a few experts, so its compute cost resembles a much smaller dense model, but every expert weight must be resident in memory or streamed in on demand. Size the weights from the total, and treat the KV cache term exactly as described here — it depends on layers and KV heads, which routing does not change.

Why does the calculator report GiB rather than GB?

Because every tool you will compare the answer against reports GiB. nvidia-smi, PyTorch’s allocator, and CUDA out-of-memory messages all use 1024-based units, while model sizes and card marketing use 1000-based ones. Converting once, here, avoids a 7.4% error in the direction that makes things look like they fit. If you need decimal GB, multiply the result by 1.0737.

References