---
title: "How much VRAM does an LLM need? Weights and KV cache · CloudSat"
description: "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."
url: https://cloudsat.io/learn/how-much-vram-does-an-llm-need
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[AI and machine learning](https://cloudsat.io/learn/topic/ai)

# 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 team November 18, 2026 7 min read

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

```text
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`:

```bash
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](https://cloudsat.io/gpu-servers) gives you 24 GB to 96 GB per card, and up to four A100 80 GB cards in one machine. The [GPU buying guide](https://cloudsat.io/learn/choose-a-gpu-for-ai-workloads) 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:

```bash
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`:

```ini
[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](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in AI and machine learning](https://cloudsat.io/learn/topic/ai)

- [How to choose a GPU for AI: VRAM first, then bandwidth](https://cloudsat.io/learn/choose-a-gpu-for-ai-workloads): AI and machine learning How to choose a GPU for AI: VRAM first, then bandwidth 7 min read
- [Ollama, LM Studio and AI workspaces: how the layers fit](https://cloudsat.io/learn/ollama-lm-studio-and-ai-workspaces): AI and machine learning Ollama, LM Studio and AI workspaces: how the layers fit 6 min read
- [LoRA, QLoRA or full fine-tuning: pick by memory and goal](https://cloudsat.io/learn/lora-qlora-or-full-fine-tuning): AI and machine learning LoRA, QLoRA or full fine-tuning: pick by memory and goal 6 min read
- [Self-hosted LLM or API: work out the real break-even](https://cloudsat.io/learn/self-hosted-llm-or-api-break-even): AI and machine learning Self-hosted LLM or API: work out the real break-even 7 min read
