Skip to content

VRAM Calculator

Estimate the GPU memory an LLM needs for inference: weights by parameter count and precision, KV cache by context length, and overhead.

Calculator Details

GPU memory needed:17.49 GiBSee results ↓

Model size in billions of parameters: 8 for an "8B" model, 70 for a "70B".

FP32 = 4 bytes per weight, FP16/BF16 = 2, FP8/INT8 = 1, 4-bit = 0.5. Custom for formats such as GGUF (enter effective bits per weight).

Prompt plus output tokens held in the KV cache per sequence.

Sequences served at the same time; each has its own KV cache.

Memory per GPU as the card states it (a "24 GB" card has 24 GiB), in the size units chosen below.

Model shape (from its config.json)

Transformer layers (num_hidden_layers in config.json). Llama 3.1 8B: 32.

Key/value heads (num_key_value_heads); fewer than attention heads with grouped-query attention. Llama 3.1 8B: 8.

hidden_size ÷ num_attention_heads (4,096 ÷ 32 = 128 for Llama 3.1 8B).

Your Results

GPU memory needed: 17.49 GiB

GPU memory needed

17.49 GiB

Fits: 6.509 GiB to spare

Weights

14.9 GiB

16 bits per weight

KV cache

1 GiB

128 KiB per token at 16-bit

Overhead

1.59 GiB

10% assumption

Longest context that fits

56,664 tokens

The model needs about 17.49 GiB: 14.9 GiB of weights at 16 bits, 1 GiB of KV cache and 1.59 GiB of overhead. It fits, with 6.509 GiB to spare; the longest context that fits is about 56,664 tokens.

Compare scenarios

Save these inputs as a scenario, change them, and compare the results side by side.

Loading, available in a moment

What the memory holds

What the memory holds

Detailed Breakdown

Total memory at each weight precision (24 GiB × 1 available)
WeightsTotalFits?
FP3233.88 GiBNo
FP16 / BF16 (you)17.49 GiBYes
FP8 / INT89.3 GiBYes
4-bit5.2 GiBYes

Same KV cache and overhead in every row; only the weight precision changes.

How This Calculator Works

How the memory is estimated

weights = parameters × bits per weight ÷ 8

KV cache = 2 × layers × KV heads × head dim × context × batch × KV bits ÷ 8

total = (weights + KV cache) × (1 + overhead)

weights = 8 billion × 16 ÷ 8 = 16,000,000,000 bytes

KV = 2 × 32 × 8 × 128 × 8,192 × 1 × 16 ÷ 8 = 1,073,741,824 bytes

total = (16,000,000,000 + 1,073,741,824) × (1 + 10%) = 18,781,116,006 bytes = 17.49 GiB

The KV cache stores a key and a value vector for every token, layer and KV head, so it grows with context length and batch size. The overhead percentage is an assumption for the CUDA context, activations and fragmentation: measure your server and adjust it.

Frequently Asked Questions

How much VRAM does a 7B or 8B model need?

For the weights alone, parameters × bytes per weight: 8 billion × 2 bytes = 16 GB (14.9 GiB) in FP16/BF16, 8 GB at 8-bit and about 4 GB at 4-bit. Add the KV cache for your context (1 GiB for 8,192 tokens on Llama 3.1 8B in BF16) and some overhead. In BF16 with a 10% allowance that is about 17.5 GiB, so it fits a 24 GB card but not a 16 GB one.

How much VRAM does a 70B model need?

About 140 GB of weights in FP16/BF16, 70 GB at 8-bit and 35 GB at 4-bit, before the KV cache. That means two 80 GB GPUs for 16-bit inference, or one 48 GB card for a 4-bit quantised model with a modest context.

What is the KV cache?

While generating, the model keeps a key and a value vector for every token it has seen, in every layer, so it does not recompute them. Its size is 2 × layers × KV heads × head dimension × tokens × bytes per value. It grows with context length and with the number of sequences served at once, and on long contexts it can exceed the weights.

Where do I find layers, KV heads and head dimension?

In the model’s config.json on its model page: num_hidden_layers, num_key_value_heads, and hidden_size divided by num_attention_heads (or head_dim when it is given). Models with grouped-query attention have fewer KV heads than attention heads, which shrinks the KV cache.

Is a 24 GB graphics card 24 GB or 24 GiB?

GPU memory is built in powers of two, so a card sold as “24 GB” holds 24 GiB (25.8 billion bytes), and tools such as nvidia-smi report it in MiB. That is why this calculator shows GiB by default; switch to decimal GB if you are comparing with a figure in billions of bytes.

Why is the overhead percentage an assumption?

The CUDA context, temporary activations, the inference server’s own buffers and memory fragmentation vary with the software, batch size and GPU. There is no single published figure, so the calculator applies a percentage you can change; measure your setup and enter what you see.

Does this work for training or fine-tuning?

No. Training also stores gradients and optimizer states (often several times the weights) and activations for back-propagation. This calculator covers inference only.

An inference estimate: weights (parameters × bits ÷ 8) plus the KV cache (2 × layers × KV heads × head dimension × tokens × batch × bits ÷ 8) plus an overhead percentage that is an assumption, not a measurement. Defaults describe Llama 3.1 8B (Meta's published architecture). Not included: training memory (gradients, optimizer states), sliding-window and latent-attention caches, mixture-of-experts offloading, per-GPU duplication when a model is split, and the scale overhead of each quantisation format (enter effective bits per weight).

VRAM Calculator: GPU Memory for Running an LLM

By FindMySum · Last reviewed

A VRAM calculator estimates how much GPU memory a large language model needs to answer requests. Three things fill that memory: the model's weights, the key-value (KV) cache that holds the conversation in progress, and working space for the runtime. The first two can be calculated from published numbers; the third depends on your software, so this page treats it as a stated assumption you can change. The worked example uses the defaults: Llama 3.1 8B in BF16 with an 8,192-token context on a 24 GiB card.

The formula

weights = parameters × bits per weight ÷ 8

KV cache = 2 × layers × KV heads × head dimension × context tokens × batch × KV bits ÷ 8

total = (weights + KV cache) × (1 + overhead %)

The 2 in the KV cache is one key vector and one value vector per token, per layer, per KV head.

Worked example: Llama 3.1 8B

Meta's published architecture for Llama 3.1 8B has 32 layers, 32 attention heads, 8 key-value heads and a model dimension of 4,096, so each head has 4,096 ÷ 32 = 128 dimensions.

  1. Weights: 8 billion × 16 bits ÷ 8 = 16,000,000,000 bytes (14.9 GiB).
  2. KV cache per token: 2 × 32 × 8 × 128 × 2 bytes = 131,072 bytes (128 KiB).
  3. KV cache for 8,192 tokens: 131,072 × 8,192 = 1,073,741,824 bytes (exactly 1 GiB).
  4. With a 10% overhead assumption: (16,000,000,000 + 1,073,741,824) × 1.1 = 18,781,116,006 bytes, 17.49 GiB.

That fits a 24 GiB card with about 6.5 GiB to spare, and the calculator shows the longest context that would fit with the same settings: about 56,700 tokens.

Precision changes everything

WeightsBytes per parameter8B model70B model
FP32432 GB280 GB
FP16 / BF16216 GB140 GB
FP8 / INT818 GB70 GB
4-bit0.54 GB35 GB

Quantised formats also store scale factors for each small block of weights, so a "4-bit" file often works out at 4.5 to 5 bits per weight. Choose the custom option and enter the effective figure, which you can get by dividing the file size in bits by the parameter count.

The KV cache grows with use

Weights are fixed; the KV cache grows with every token of context and every sequence served at once. Models with grouped-query attention, like Llama 3.1, share each KV head among several attention heads, which is why 8 KV heads appear in the formula rather than 32. Even so, at 128,000 tokens the cache for one Llama 3.1 8B sequence is 15.6 GiB in BF16, nearly as much as the weights. Serving four sequences at once multiplies it by four. Servers that store the cache in 8-bit halve it.

The overhead assumption

Every runtime needs memory beyond weights and cache: the CUDA context, temporary activations during each step, buffers and fragmentation. There is no single published figure, because it depends on the GPU, driver, inference engine and batch size. The calculator applies a percentage, 10% by default, as a visible assumption rather than a hidden constant. Load the model once, read the memory in use from your monitoring tool, and adjust.

GB or GiB?

GPU memory comes in binary sizes, so a card sold as "24 GB" holds 24 GiB, 25.8 billion bytes, and monitoring tools report MiB. The calculator defaults to GiB for that reason and offers decimal GB as a labelled choice; the byte counts never change.

Beyond inference

Training and fine-tuning need far more: gradients, optimizer states and saved activations can take several times the weights. This calculator covers inference only. Once the model fits, the tokens per second calculator estimates how quickly it answers, and the vector storage calculator sizes the embeddings a retrieval system keeps beside it.

More questions

Can I run a model that does not fit in VRAM?

Some runtimes can keep part of the model in system RAM and move layers to the GPU as needed. It works, but generation slows sharply, often by several times, because system memory and the PCIe link are much slower than GPU memory.

Does a longer context need more VRAM even if I send short prompts?

Many inference servers reserve KV cache memory for the full configured context length when they start. Lowering the maximum context in the server settings frees that memory if your prompts are short.

How much does 8-bit KV cache save?

Half of the KV cache. For Llama 3.1 8B at 32,768 tokens that is 2 GiB instead of 4 GiB per sequence, at a small cost in accuracy that many servers find acceptable for long contexts.

Do two 12 GB cards equal one 24 GB card?

For capacity, roughly, if the inference software splits the model across both. Each card also keeps its own runtime buffers, and the cards exchange data during generation, so expect a little less usable memory and some speed loss compared with one larger card.

Why does the same model need different memory in different tools?

Tools differ in how they store quantised weights, how much KV cache they reserve in advance, and how big their workspace buffers are. That variation is what the overhead percentage stands for; measure your tool once and set it accordingly.

Sources

This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.

Spotted a wrong result or a bug? Report a problem

May we count your visits with Invoker Analytics? It keeps a random visitor number in your browser. Your calculator inputs are never sent. Privacy policy