Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

GPU VRAM Calculator

Pick a model (Llama, Mistral, Qwen, Phi, Mixtral or custom architecture), a precision (FP16 / INT8 / INT4), a context length and batch size — and get the real VRAM requirement: weights, KV cache (GQA-aware), runtime overhead, and a fits-or-not verdict across common GPUs from a T4 to an H200.

18.4 GBTotal VRAM neededweights + KV + 15% overhead
15 GBWeights8.03B × 2 bytes
1 GBKV cache1 GB / seq × 1
120 GBFull fine-tune (rough)~16 B/param AdamW — why people use LoRA
Does it fit?
T4 · 16 GB 2× needed
L4 / RTX 4090 · 24 GB fits
RTX 5090 · 32 GB fits
A100 · 40 GB fits
A100 / H100 · 80 GB fits
H200 · 141 GB fits
Multi-GPU counts are naive capacity math — tensor parallelism adds its own overhead.

Serving an LLM needs memory for three tenants: the weights, the KV cache, and the runtime’s own overhead. Budgeting only for the weights is the classic mistake, and it surfaces as an out-of-memory error the first time someone sends a long prompt. This calculator sizes all three and checks the total against six common GPUs.

What it computes

weights    = params × bytes per param / 1,024³
kv/token   = 2 × layers × (hidden × kv_heads / heads) × 2 bytes
kv/seq     = kv/token × context / 1,024³
kv total   = kv/seq × concurrent sequences
overhead   = (weights + kv total) × overhead %
total      = weights + kv total + overhead
GPUs       = ⌈ total / VRAM ⌉      fits when total ≤ VRAM
  • Bytes per param is 2 for FP16 or BF16, 1 for INT8 and 0.5 for INT4. It applies to the weights only.
  • kv_heads / heads is the grouped-query attention ratio. Sharing each key-value head across several query heads shrinks the cache by that factor.
  • The KV cache is always sized at 2 bytes per value, and every concurrent sequence is assumed to hold a full-length context.
  • Overhead, 15% by default, covers activations, CUDA workspaces and allocator fragmentation.

Sizes are in 1,024-based gigabytes. The full fine-tune card is a separate reference: parameters times 16 bytes.

A worked example

The defaults are Llama 3.1 8B (8.03B parameters, 32 layers, hidden size 4,096, 32 heads, 8 KV heads) in FP16, an 8,192-token context, one sequence and 15% overhead.

  1. Weights: 8.03 × 10⁹ × 2 = 16.06 billion bytes = 14.96 GB, shown as 15 GB.
  2. KV dimension: 4,096 × 8 / 32 = 1,024, so 2 × 32 × 1,024 × 2 = 131,072 bytes per token.
  3. KV cache: 131,072 × 8,192 = 1,073,741,824 bytes, exactly 1 GB, for the single sequence.
  4. Overhead: (14.96 + 1) × 0.15 = 2.39 GB.
  5. Total: 14.96 + 1 + 2.39 = 18.35, shown as 18.4 GB. It does not fit a 16 GB T4 (2× needed) and fits every card from 24 GB up.
Change one inputKV cacheTotalSmallest card that fits
Defaults1 GB18.4 GB24 GB
INT4 weights1 GB5.5 GB16 GB
128K context16 GB35.6 GB40 GB
32 sequences at 8K32 GB54 GB80 GB

The last two rows are the point: past a few users or a long context, the cache costs more than the model.

Assumptions and limits

  • Every sequence at full context. Real traffic mixes short and long requests, and paged attention allocates cache as tokens arrive, so average use is lower than this worst case.
  • FP16 KV cache only. Engines that store the cache in FP8 or INT4 need half or a quarter of the KV figure.
  • A flat overhead. Activation memory depends on batch size and engine settings, and some engines reserve a fixed share of VRAM up front.
  • Naive multi-GPU counts. Splitting a model across cards adds communication buffers and duplicated pieces, so the count needed can be higher.
  • Mixture-of-experts models such as Mixtral need all experts in memory, which is why the preset uses the total of 46.7B parameters, not the active ones.

How to use the result

  • Leave headroom. Plan for the total to sit 10 to 20% below the card’s capacity, because drivers and the display or other processes take a share.
  • Size for the traffic you promise. Set concurrent sequences to your peak users and context to your longest supported prompt.
  • Quantize weights first. INT4 often moves a model down a whole card class; then reduce context or concurrency if the KV cache still dominates.
  • Prefer GQA models when long context matters, and check the KV row before buying bigger GPUs.

When to use it, and when not

Use it before you rent or buy. It answers the first question in any serving plan: which card class can hold this model, at this context, for this many users? It also shows which lever moves you down a card. Quantization shrinks only the weights; context and concurrency shrink only the cache.

Measure instead when you set production capacity. Serving engines allocate the cache in pages as tokens arrive, so the users a card really holds depend on how long your requests are, not on the worst case shown here. Load the model in the engine you will run, replay realistic traffic and read its memory figures. For training, use a fine-tuning estimator: gradients and optimizer state change the arithmetic completely.

Trade-offs and limits

Each simplification pushes the estimate one way. Knowing which way tells you how far to trust a near miss.

IgnoredReal need isHow far off, Llama 3.1 8B
Requests shorter than the full contextLower32 sequences averaging 2K tokens hold 8 GB of cache, not 32 GB
FP8 KV cacheLowerHalves the cache: 32 GB becomes 16 GB
Activations during a long prefillHigherGrows with prompt length × batch; the flat 15% can hide it
Splitting across GPUsHigherCommunication buffers on every card, on top of the total

Stress-test the KV row first. It is the only term that grows with traffic, and the one most likely to be wrong in both directions.

Common mistakes

  • Copying heads into KV heads. In the custom fields, setting KV heads equal to attention heads turns grouped-query attention off. For Llama 3.1 8B that makes the cache 524,288 bytes per token instead of 131,072, four times too big. Read num_key_value_heads from the model’s config, not num_attention_heads.
  • Assuming a smaller model has a smaller cache. Phi-3 mini has under half the parameters of Llama 3.1 8B but no GQA, so its cache is 393,216 bytes per token, three times Llama’s. At a 32K context that is 12 GB of cache against 7.1 GB of FP16 weights, 22.0 GB in total.
  • Using active parameters for a mixture-of-experts model. Mixtral routes each token through about 12.9B parameters, but all 46.7B must sit in memory. In FP16 that is 87.0 GB of weights, not 24.0 GB. Active parameters set the compute per token; total parameters set the memory.
  • Mixing decimal and binary gigabytes. 8.03B parameters × 2 bytes is 16.06 GB in decimal units and 14.96 GB in the 1,024-based units used here, a 7% gap. On a tight fit that gap decides whether the model loads, so compare like with like.
  • Reading “2× fits” as comfortable. Llama 3.1 70B in FP16 at 8K needs 154.1 GB, so two 80 GB cards leave 5.9 GB, under 4%, before any multi-GPU buffers. Plan for INT8, a shorter context or a third card.

Check yourself

What is Llama 3.1 70B’s KV cache per token, and per 8K sequence?

The KV dimension is 8,192 × 8 / 64 = 1,024, the same as the 8B model’s. So the cache is 2 × 80 × 1,024 × 2 = 327,680 bytes (320 KB) per token and exactly 2.5 GB per 8,192-token sequence. It is 2.5 times the 8B figure purely because 80 layers is 2.5 times 32.

How many concurrent 8K sequences of Llama 3.1 8B in INT4 fit a 24 GB card at 15% overhead?

Weights are 8.03 × 10⁹ × 0.5 / 1,024³ = 3.74 GB and each sequence adds 1 GB. Solve (3.74 + n) × 1.15 ≤ 24: n ≤ 17.1, so 17, at 23.85 GB. An 18th sequence makes 25.0 GB.

Mixtral 8x7B in INT4 at 8K for one user: does it fit a 24 GB card?

No. Weights are 46.7 × 10⁹ × 0.5 / 1,024³ = 21.75 GB. With 32 layers and 8 of 32 KV heads, the cache is 131,072 bytes per token, so 1 GB at 8K. (21.75 + 1) × 1.15 = 26.2 GB: over 24, so it needs the 32 GB card.

Llama 3.1 70B in INT8 at 8K for one user shows as fitting one 80 GB card. Should you ship it?

Weights are 65.75 GB and the cache 2.5 GB, so (65.75 + 2.5) × 1.15 = 78.5 GB. That fits, with 1.5 GB to spare: under 2%, far below the 10 to 20% headroom advised above, and with no room for a second user. Use INT4 (40.7 GB) or two cards.

24 GB card 80 GB card 1 seq × 8K weights 15 18.4 GB KV 1 + 2.4 32 seq × 8K weights 15 KV cache 32 7.0 54.0 GB 0 20 40 60 80 weights KV cache overhead 15%
Llama 3.1 8B in FP16 at 8K, from the tool’s own formula. With one user the weights are most of the 18.4 GB; with 32 users the KV cache, 32 GB, is more than twice the weights, and the total needs an 80 GB card.

How it works

  • Weights = parameters × bytes per parameter (FP16 = 2, INT8 = 1, INT4 = 0.5).
  • KV cache/token = 2 × layers × (hidden × kv-heads ÷ heads) × 2 bytes; GQA shrinks it.
  • Total = (weights + KV × concurrent sequences) × (1 + overhead %).
  • Architecture presets use the models’ published configs.

Frequently asked questions

How much VRAM does an LLM need?

Weights need the parameter count times the bytes per parameter: an 8B model is about 15 GB in FP16, 7.5 GB in INT8 and 3.7 GB in INT4. On top of that, every in-flight request holds a KV cache that grows with context length, plus runtime overhead for activations, buffers and fragmentation. With this tool’s defaults, Llama 3.1 8B in FP16 at an 8,192-token context for one user needs about 18.4 GB, so it fits a 24 GB card but not a 16 GB one.

What is the KV cache and why does it matter?

The KV cache stores the attention keys and values for every token in the context, so generation does not reprocess the whole prompt for each new token. It grows linearly with context length and with the number of concurrent sequences. For Llama 3.1 8B it is 128 KB per token, so 1 GB at 8K tokens and 16 GB at 128K, more than the 15 GB of FP16 weights. It is usually what limits how many users fit on one GPU.

How does quantization change the requirement?

INT8 halves and INT4 quarters the weight memory compared with FP16, usually with a modest quality cost. In this tool, Llama 3.1 70B at an 8K context needs about 154 GB in FP16, two 80 GB cards, but about 40.7 GB in INT4, which fits one 80 GB card or two 24 GB cards. The tool keeps the KV cache in FP16 regardless, so quantizing weights does not shrink context memory; KV-cache quantization is a separate technique.

How do I calculate KV cache size per token?

Multiply 2, for keys and values, by the number of layers, by the KV dimension, by the bytes per value. The KV dimension is the hidden size times the number of KV heads divided by the number of attention heads. Llama 3.1 8B has 32 layers, a 4,096 hidden size, 32 heads and 8 KV heads, so the KV dimension is 1,024 and the cache is 2 times 32 times 1,024 times 2 bytes, or 131,072 bytes per token at FP16.

Why does fine-tuning need so much more memory than inference?

Full fine-tuning with AdamW holds the weights, the gradients and two optimizer moments for every parameter, roughly 16 bytes per parameter before activations. That is about 120 GB for an 8B model, against about 15 GB to serve it in FP16. That gap is why parameter-efficient methods such as LoRA and QLoRA exist: they freeze the base weights and train small adapters, so the optimizer state stays tiny and the job fits on far less hardware.