Methodology
How to calculate the memory (VRAM) a local LLM needs
The "estimated memory requirement" on this site starts from the actual file size listed on Hugging Face and adds the KV cache, which grows with the length of the conversation, along with a few other parts. We publish the full formula and all of its assumptions.
Formula v1 Last updated
In short: the memory requirement is the sum of four parts
Estimated memory = model file size + KV cache + compute buffer + reserve
- Model file (weights) Measured 5.03 GB
- KV cache Estimated 4.83 GB
- Compute buffer Estimated 0.31 GB
- Headroom (runtime etc.) Estimated 0.54 GB
The model file size is the actual size of Qwen3-8B-Q4_K_M.gguf (5,027,784,512 bytes, checked 2026-09-26). Everything else is an estimate from the formulas below.
1. Model file size Measured
llama.cpp-based tools load the GGUF file into memory as is, so the memory used by the model weights is almost the same as the file size.
This site uses the file size returned by Hugging Face (the actual value, in bytes).
If the file is split, as in -00001-of-00003.gguf, we use the total of all parts.
For image input, add the mmproj too
Models that accept image input (such as Gemma 3) also load a separate file, mmproj-*.gguf.
The mmproj (F16) for Gemma 3 27B is 858 MB. You do not need it if you do not use images.
Units: 1 GB = 109 bytes
This matches how Hugging Face displays sizes. An "8GB" GPU has 8 × 10243 bytes (about 8.59 GB), so when this site decides whether a model fits, it compares the numbers in bytes.
2. KV cache Estimated
Each time an LLM generates a token, it refers to the "keys" (K) and "values" (V) of all previous tokens. The KV cache stores them so they do not have to be recomputed every time, and it grows in proportion to the context length (the number of tokens handled).
Formula
KV cache = 2 (K and V) × layers × KV heads × head_dim × context length × bytes per element
Bytes per element is 2 for f16. As in llama.cpp, the context length is rounded up to a multiple of 256.
The values in the formula come from the original model's config.json
| Value in the formula | config.json key | Qwen3-8B |
|---|---|---|
| Layers | num_hidden_layers | 36 |
| KV heads | num_key_value_heads (if absent, num_attention_heads) |
8 |
| head_dim | head_dim (if absent, hidden_size ÷ num_attention_heads) |
128 |
For Qwen3-8B, each token takes 2 × 36 × 8 × 128 × 2 bytes = 147,456 bytes (144 KiB). At 32K tokens (32,768) that is 4,831,838,208 bytes = 4.83 GB (exactly 4.5 GiB). Source: config.json of Qwen/Qwen3-8B (checked 2026-09-26)
3. Sliding window layers only need the window
Gemma 3 and gpt-oss have sliding window attention (SWA) layers that only look at a fixed number of recent tokens (the window). For these layers, llama.cpp allocates the KV cache not for the context length but only for "window + 512", rounded up to a multiple of 256 (512 is the default n_ubatch, the number of tokens processed at once).
SWA length = min(context length, window + 512), rounded up to a multiple of 256
Gemma 3 27B
5 of every 6 layers use a sliding window (window 1024)
- Full layers
- 10
- SWA layers
- 52
- Window
- 1,024
Source: config.json of unsloth/gemma-3-27b-it (checked 2026-09-26)
gpt-oss-20b
Half of the layers use a sliding window of 128
- Full layers
- 12
- SWA layers
- 12
- Window
- 128
Source: config.json of openai/gpt-oss-20b (checked 2026-09-26)
Gemma 3 27B (Q4_K_M): how much accounting for SWA changes the result
| Context | KV (with SWA) | KV (if all layers kept full context) | Memory needed Estimated |
|---|---|---|---|
| 8,192 | 1.33 GB | 4.16 GB | 18.9 GB |
| 32,768 | 3.34 GB | 16.6 GB | 21.0 GB |
| 131,072 | 11.4 GB | 66.6 GB | 29.0 GB |
gpt-oss-20b has a small window of 128, so even at its maximum of 131,072 tokens the KV cache is 3.24 GB (of which the SWA layers take 19 MB), and the estimated memory requirement is 15.8 GB (Q4_K_M, 11.6 GB).
4. KV cache quantization (q8_0, q4_0)
llama.cpp can shrink the KV cache itself by quantizing it (--cache-type-k q8_0 --cache-type-v q8_0).
Quantized types store 32 elements together as one block, so the bytes per element are as follows.
f16
2 bytes per element
2bytes/element
100% of f16 (this site's default)
q8_0
34 bytes per 32 elements
1.0625bytes/element
53% of f16
q4_0
18 bytes per 32 elements
0.5625bytes/element
28% of f16
Quantizing the V cache requires Flash Attention (--flash-attn on).
The change in accuracy from quantization differs between models and this site has not measured it, so the tables use f16 as the default and list q8_0 and q4_0 for reference.
5. Compute buffer and reserve Estimated
Compute buffer = vocabulary size × 512 × 4 bytes
At startup, llama.cpp allocates a working area to hold the output for up to 512 tokens processed at once (for each token, the probabilities of the next token: vocabulary size × 4 bytes). It is larger for models with bigger vocabularies: 311 MB for Qwen3-8B (vocabulary 151,936), and 537 MB for Gemma 3 27B (vocabulary 262,208).
Reserve = 512 MiB (fixed)
This covers memory used by the GPU driver and runtime, plus other small working areas. Because it varies a lot between setups, we use a fixed value, and we will revise it as we collect values measured on our own PC.
6. Quick reference by context length (Qwen3-8B Q4_K_M)
Estimated memory requirements for a model with a file size of 5.03 GB Measured , as the context length and KV cache type change. Each model's page also has a table calculated with the same formula.
| Context | KV f16 | KV q8_0 | KV q4_0 |
|---|---|---|---|
| 4,096 | 6.48 GB | 6.20 GB | 6.05 GB |
| 8,192 | 7.08 GB | 6.52 GB | 6.22 GB |
| 16,384 | 8.29 GB | 7.16 GB | 6.56 GB |
| 32,768 | 10.7 GB | 8.44 GB | 7.23 GB |
| 40,960 max | 11.9 GB | 9.08 GB | 7.57 GB |
All values are Estimated .
7. Assumptions, and when they do not hold
These estimates assume llama.cpp (b11639, as of October 2026) running with the settings below, which are the defaults of llama-server and llama-cli.
- All layers are offloaded to the GPU (unified memory on a Mac) Keeping some layers on the CPU side reduces what the GPU needs, at the cost of speed.
- Only one conversation is processed at a time Increasing the number of parallel sequences (-np) in llama-server increases the KV cache of the SWA layers with the number of sequences.
- n_ubatch = 512 (default), Flash Attention enabled With Flash Attention turned off, the compute buffer grows considerably at long context lengths.
- The context length is the value given in each row of the table Ollama and LM Studio decide the context length in their own settings. Check the length you use in the settings and look at the row for that value.
Cross-checking against llama.cpp
We have confirmed that the KV cache and the fixed-size state held by layers such as linear attention match, to the byte, what llama.cpp itself actually allocates. Here is how we checked. We converted the config.json of each listed model into only the settings part of a GGUF using llama.cpp's official conversion code, had llama.cpp create a context without loading any weights, and read out the amount it allocated. We tested four context lengths: 4,096, 8,192, 32,768 and 131,072 tokens.
- • Version used: llama.cpp b11639 (October 14, 2026). We will check again when the version changes.
- • Not verified: the compute buffer and reserve (the values in section 5). These remain estimates until we measure them by actually running on a GPU.
- • SWA layers are assumed to allocate only the window, as llama-server and llama-cli do by default (with
--swa-fullthe full context is allocated).
Models that hold the KV cache differently
For the following models, we checked llama.cpp's implementation (how it allocates the KV cache) and then applied the same formula layer by layer.
- Models combining linear attention (Qwen3.5, Qwen3-Next, etc.)
- Only the regular attention layers hold a KV cache (usually one layer in four). The remaining linear attention layers hold a state of fixed size that does not depend on the length of the conversation. The state size per layer is ((convolution width − 1) × (d_inner + 2 × K heads × K head dimension) + K head dimension × d_inner) × 4 bytes, and we add it to the estimated memory requirement (d_inner = V heads × V head dimension). A key feature is that even for long conversations the KV cache is about 1/4 that of a regular model.
- Linear attention + sparse attention (Qwen3.8-Flash-Next, etc.)
- In addition to the linear attention model above, each regular attention layer holds an indexer cache (1 head × indexer_head_dim, K only) used to choose which tokens to attend to, with the same length as the KV cache. It also holds a fixed state of (ple_conv_kernel_size − 1) × ngram_size × hc_count × hidden_size × 4 bytes as the convolution history of the n-gram embeddings (PLE).
- Models combining convolutions (LFM2 family)
- Only the regular attention layers hold a KV cache; the convolution layers hold a fixed state of hidden_size × (conv_L_cache − 1) × 4 bytes.
- Gemma 4
- The SWA layers and the layers that keep the full context have different numbers of KV heads and different head_dim (num_global_key_value_heads and global_head_dim in config.json). We calculate the KV cache with the width of each layer. In E2B, E4B and similar variants, the last layers (num_kv_shared_layers) reuse the KV cache of earlier layers, so nothing is allocated for them. Likewise, in Gemma 3n the last layers do not allocate a KV cache.
- DeepSeek V4
- It has a dedicated KV cache. In addition to the KV (K only) for the most recent 128 tokens, some layers hold K compressed 4 tokens into 1 plus an indexer K used to choose where to read from, and other layers hold K compressed 128 tokens into 1. We also add the fixed state used by the compression mechanism. As a result, the KV cache stays small even for long conversations, around 1 GB even at 131,072 tokens (most of the memory requirement is the model file itself).
- Models combining Mamba2 (Nemotron-H family)
- Only the attention layers hold a KV cache; the Mamba2 layers hold a fixed state of ((conv_kernel − 1) × (d_inner + 2 × n_groups × ssm_state_size) + ssm_state_size × d_inner) × 4 bytes (d_inner = mamba_num_heads × mamba_head_dim).
- Chunked attention (Llama 4)
- Three out of every four layers only look within chunks of 8,192 tokens. llama.cpp allocates the same amount for these layers as for SWA (chunk length + 512), so we use the same formula.
- Embedding models (EmbeddingGemma, etc.)
- They read the text in one pass and turn it into numbers without generating a continuation, so they have no KV cache.
8. Models we do not estimate
For models that hold the KV cache differently from the formulas above, we do not show an estimate, to avoid showing wrong numbers (the reason is given on the model's page). The same applies when the original model's config.json cannot be retrieved (for example, models that require agreeing to terms before access). However, for models where we could read the settings at the start of the GGUF file (the very values llama.cpp reads), we estimate from those. For MLA models (DeepSeek V3, Kimi K2, GLM-5.3, etc.), we use the GGUF settings to identify when the model was converted (the shape of the KV) before estimating.
| Type | Reason | model_type in config.json |
|---|---|---|
| MLA | This model uses MLA (attention that stores a compressed KV). Depending on when the GGUF was converted, the KV cache size differs by about 70x, so we do not estimate it until we have read the GGUF file's settings. | deepseek_v2, deepseek_v3, deepseek_v32, kimi_k2, glm_moe_dsa, glm5_next_text, kimi_linear, bailing_hybrid, glm4_moe_lite |
| Hybrid | This model combines attention with a state space model (such as linear attention). It keeps state other than the KV cache, so memory is not estimated. | falcon_h1, jamba, mamba |
model_types we can estimate: llama, mistral, mixtral, qwen2, qwen2_moe, qwen3, qwen3_moe, phi3, qwen3_vl_text, granite, ministral3, hunyuan_v1_dense, qwen2_5_vl, qwen2_5_omni_text, qwen3_vl_moe_text, qwen3_omni_moe_text, glm4, glm4v_text, smollm3, hy_v3, k2_horizon, chatglm, nanbeige, gemma2, gemma3, gemma3_text, gpt_oss, muse_glimmer_text, spark2_5, laguna, cohere2_moe, mellum, afmoe, step3p5, llama4_text, qwen3_next, qwen3_5_text, qwen3_5_moe_text, qwen4_exp_text, gemma4_text, gemma4_unified_text, lfm2, lfm2_moe, embedding_gemma2_text, jina_embeddings_v5, gemma3n_text, mimo_v2, nemotron_h, deepseek_v4
Telling "estimated" from "measured"
- Measured
- Actual values listed on Hugging Face (such as file size).
- Estimated
- Values from the formulas on this page. They vary with your runtime environment and settings.
- Measured (1 setup)
- Values measured by actually running the model on our own PC. The result is from the one setup we measured.
FAQ
How do you calculate the memory (VRAM) a local LLM needs?
Take the size of the model file (GGUF) and add the KV cache, the compute buffer and a reserve. The KV cache is "2 × layers × KV heads × head_dim × context length × bytes per element", so it grows in proportion to the context length. For example, running the Q4_K_M of Qwen3-8B (5.03 GB) at 32K tokens comes to an estimated 10.7 GB.
If the file is smaller than my VRAM, will it run?
The file size alone is not enough. The KV cache grows with the length of the conversation (the context length); for Qwen3-8B it needs about 4.83 GB at 32K tokens. You can reduce the requirement by setting a shorter context or by quantizing the KV cache to q8_0.
How much does a q8_0 or q4_0 KV cache save?
Compared with f16, q8_0 is about 53% (34/64) and q4_0 is about 28% (18/64). In llama.cpp you set this with --cache-type-k / --cache-type-v, and quantizing V requires Flash Attention. The effect on accuracy differs between models, so this site uses f16 as the default.
MoE models (such as Qwen3-30B-A3B) have few active parameters. Do they need less memory?
When all layers are offloaded to the GPU, the whole model file is loaded into memory, including the experts that are not used, so the memory requirement is determined by the file size. Settings that keep some experts in CPU-side memory (such as --n-cpu-moe in llama.cpp) reduce what the GPU needs, but this estimate does not assume such settings.
Do Ollama and LM Studio give the same numbers?
This estimate follows the way llama.cpp allocates memory. Ollama and LM Studio also use llama.cpp-based machinery internally, but their defaults for context length, number of parallel sequences, Flash Attention and so on differ, so actual usage will vary. Always leave some headroom when choosing.
What is the difference between "estimated" and "measured"?
The file size is the actual size listed on Hugging Face (measured). The memory requirement is an estimate from the formula on this page. Values obtained by actually running a model on our own PC are shown separately from the estimate, as "measured (one setup)".