Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
AI and machine learning

How much VRAM does an LLM need? Weights, KV cache, quants

Work out the GPU memory a local LLM needs from weight size per quantization format, KV cache per token and runtime overhead, plus the flags that cut each.

CloudSat teamNovember 18, 20267 min read
Abstract illustration of a long memory bar split into colored blocks for weights, cache and overhead
On this pageThe three-line memory budget

A 4.6 GB model file does not run in 4.6 GB of video memory. What a running model needs is the sum of three things: its weights, a KV cache that grows with every token of context, and runtime overhead. Each one can be estimated before you download anything, and each one has its own knob. This guide gives you the arithmetic, then the flags.

The three-line memory budget

weights  = parameters × bits_per_weight ÷ 8
kv_cache = 2 × layers × kv_heads × head_dim × bytes_per_value × context_tokens × parallel_sequences
overhead = CUDA context + compute buffers + extras (vision encoder, other processes)

Weights are fixed once you choose a file. The KV cache depends on how you run the model. Overhead is smaller but never zero.

Line 1: weights and what the quant names mean

A GGUF file name such as Q4_K_M packs three ideas. Q4 is the nominal bit width. K means a k-quant: weights are grouped into small blocks, each with its own scale, so precision follows the local range of values. The suffix S, M or L says how many sensitive tensors are kept at a higher bit width. Q8_0 is a simpler 8-bit scheme with one scale per block, and the IQ types (i-quants) use an importance matrix computed from sample text to decide where precision matters most.

Because scales and mixed tensors add bits, the real average is above the nominal number. The llama.cpp project publishes these figures for Llama 3.1 8B:

Quant type Bits per weight File size
Q2_K 3.16 2.95 GiB
Q3_K_M 4.00 3.74 GiB
IQ4_XS 4.46 4.17 GiB
Q4_K_M 4.89 4.58 GiB
Q5_K_M 5.70 5.33 GiB
Q6_K 6.56 6.14 GiB
Q8_0 8.50 7.95 GiB
F16 16.00 14.96 GiB

To estimate any other model, multiply its parameter count by the bits per weight and divide by 8. A 70.6B model at Q4_K_M comes to about 43 GB, or 40 GiB.

Which format family to download

GGUF is not the only option. The right family depends on the engine you run and the hardware under it.

Format Runs on Engines What sets it apart
GGUF CPU, NVIDIA, AMD, Apple Silicon, or a mix llama.cpp, Ollama, LM Studio One file per quant level; layers can be split between GPU and system RAM
GPTQ GPUs vLLM, Transformers Post-training quantization calibrated on sample data
AWQ GPUs vLLM, Transformers Activation-aware: protects the weights that matter most to outputs
EXL3 (successor to EXL2) NVIDIA GPUs ExLlamaV3 Fractional bit rates, so you can size a file to fill your VRAM exactly
FP8, MXFP4, NVFP4 Recent NVIDIA GPUs vLLM, SGLang, TensorRT-LLM Formats the hardware computes in directly (FP4 needs Blackwell)

For a single user on one machine, GGUF is the most forgiving. For serving many users from a GPU server, the GPU-native formats in vLLM or SGLang usually make better use of the card.

Line 2: the KV cache

Every token in the context stores a key and a value vector in each layer. Most current models use grouped-query attention, which shares each key-value head among several query heads, so the cache uses the number of KV heads, not the full head count. You find the three numbers in the model's config.json:

jq '{layers: .num_hidden_layers, kv_heads: .num_key_value_heads, head_dim: (.head_dim // (.hidden_size / .num_attention_heads))}' config.json

Take Llama 3.1 8B: 32 layers, 8 KV heads, 128 dimensions per head. At FP16 (2 bytes per value), that is 2 × 32 × 8 × 128 × 2 = 131,072 bytes, or 128 KiB per token. Llama 3.1 70B has 80 layers with the same KV layout, so 320 KiB per token.

Context length Llama 3.1 8B (FP16 cache) Llama 3.1 70B (FP16 cache)
8,192 tokens 1 GiB 2.5 GiB
32,768 tokens 4 GiB 10 GiB
131,072 tokens 16 GiB 40 GiB

Multiply by the number of conversations you serve at the same time: four parallel users at 32K tokens on the 8B model need 16 GiB of cache. Some architectures store less per token, for example models that use sliding-window attention on part of their layers or DeepSeek's latent attention, so treat the formula as an upper bound for them.

Line 3: overhead

The CUDA context alone takes several hundred megabytes per GPU. Inference engines add compute buffers that grow with batch size. Multimodal models load a separate vision encoder. On a workstation, the desktop itself may hold part of the card. Leave a margin rather than planning to the last megabyte.

Worked budgets

Setup Weights KV cache Where it fits
8B, Q4_K_M, 8K context 4.6 GiB 1 GiB Any card with 8 GB or more
8B, Q8_0, 32K context 8 GiB 4 GiB 16 GB cards and up
70B, Q4_K_M, 8K context 40 GiB 2.5 GiB 48 GB or more: one 80 or 96 GB card, or two cards split by layer
70B, Q4_K_M, 128K context 40 GiB 40 GiB 96 GB, or 80 GB with an 8-bit KV cache

If a row lands above what you own, a CloudSat GPU server gives you 24 GB to 96 GB per card, and up to four A100 80 GB cards in one machine. The GPU buying guide compares those cards on bandwidth and number formats.

Cut memory with flags

llama.cpp

The llama-server default context size is 0, which means "use the model's training context". For Llama 3.1 that is 131,072 tokens and a 16 GiB cache you may not need. Set it explicitly, and quantize the cache:

llama-server -m Llama-3.1-8B-Instruct-Q4_K_M.gguf \
  -c 32768 -ngl all -fa on \
  --cache-type-k q8_0 --cache-type-v q8_0 \
  --host 127.0.0.1 --port 8080

-ngl sets how many layers go to the GPU (all, auto or a number), and a quantized V cache needs flash attention, hence -fa on.

Ollama

Ollama's FAQ lists a default context of 4,096 tokens, so long documents are cut unless you raise it. On Linux, set server-wide values with sudo systemctl edit ollama.service:

[Service]
Environment="OLLAMA_CONTEXT_LENGTH=16384"
Environment="OLLAMA_FLASH_ATTENTION=1"
Environment="OLLAMA_KV_CACHE_TYPE=q8_0"

Restart with sudo systemctl restart ollama, load a model, and run ollama ps. The processor column shows 100% GPU when everything fits, or a CPU/GPU split when part of the model spilled into system RAM. According to the FAQ, q8_0 uses about half the memory of f16 with very little quality loss, while q4_0 saves more but loses more precision at long contexts.

Read the model card before you download

Three details on the model page change the math:

  • Total versus active parameters. A mixture-of-experts model needs memory for all its experts, even though each token only uses a few. DeepSeek V4-Flash has 284B total and 13B active parameters: it computes like a small model but must be stored like a big one.
  • Native precision. OpenAI's gpt-oss-120b ships with MXFP4 expert weights, which is how its 117B parameters fit on a single 80 GB GPU.
  • Context length. A long advertised context is a maximum, not a requirement. Size the cache for the context you actually use.

FAQ

Why does a model use more memory than its file size?

The file holds only the weights. At run time the engine adds the KV cache for your context and its own buffers, and both grow with context length and parallel requests.

Can I run a model that is larger than my VRAM?

With GGUF, yes. Lower -ngl in llama.cpp, or let Ollama split automatically, and the remaining layers run from system RAM. It works, but those layers are limited by system memory bandwidth, so generation slows down sharply.

Does an 8-bit KV cache hurt answers?

Usually very little. It is the cheapest way to double the context you can afford. A 4-bit cache is a bigger trade, so test it on your own long prompts first.

Which quant level should I start with?

Q4_K_M is the common default for GGUF. Move up to Q5_K_M, Q6_K or Q8_0 when memory allows, and treat anything below 4 bits as a last resort, since quality drops faster there, especially on small models.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.