Will it fit? VRAM and GPU layers calculator
Choose a model (or paste a Hugging Face GGUF link), your GPU memory and context size: the calculator shows how much VRAM the weights, KV cache and buffers need, how many layers fit, and the KoboldCpp settings to use.
Checked against KoboldCpp 1.124.2 · updated 13 Nov 2026
- lab-lnx: Linux test VM · 4 vCPU · 15 GB · no GPU
- sw-vulkan: Software Vulkan (Mesa lavapipe) · reports exact VRAM allocations, speeds meaningless
VRAM and model fit calculator
Layers, memory breakdown and launch values for your model, card and context.
Extras: side models, --lowvram, --moecpu
Llama 3.1 8B Instruct Q4_K_M · 16K context · KV f16
Fits completely
All 32 layers fit on the GPU, with the context and buffers.
Launch values
- --gpulayers 33
- --contextsize 16384
KoboldCpp counts one extra layer for the output layer, so --gpulayers 33 puts all 32 repeating layers on the GPU (F65). Leaving --gpulayers on auto (-1) lets autofit choose; it keeps a 1 GB padding and may offload fewer layers than this calculation. GPU layers guide
koboldcpp --model Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf --gpulayers 33 --contextsize 16384
How to read the result
The big line is one of four states.
- Fits completely. Every layer, the context and the buffers fit on the GPU. This is the fastest way to run a model.
- Fits with N of M layers on the GPU. The first N layers run on the GPU and the other layers run on the CPU from system RAM. It works, and it is slower, because the CPU layers set the pace. More layers on the GPU means faster output. See GPU layers.
- Runs on the CPU only. Nothing fits on the GPU with this context, or there is no GPU.
- Doesn’t fit in GPU and RAM. The model needs more memory than the GPU and system RAM together offer. The list under the result shows what to change and how much each change saves.
Below the line, the bar shows where the memory goes. This is a measured example (F36): Llama 3.1 8B Q4_K_M with 8K of context on a 12 GB card, using the allocation sizes KoboldCpp logged.
- Model weights 3.9 GB
- KV cache 1.0 GB
- Compute buffer 124 MB
- Free 5.4 GB
- Model weights are the layers on the card. They are the biggest block and depend on the quantisation.
- KV cache is the memory for the conversation so far. It grows with the context you ask for. See the formula below.
- Compute buffer is working space for each batch of tokens. It is small next to the other two.
- Other models are a vision projector, Whisper or an image model, if you turned them on.
- A hatched block means memory that does not fit anywhere.
The launch values are what to give KoboldCpp: How many model layers to offload to the GPU. -1 (default) turns on autofit; 0 keeps everything on the CPU.Default -1Launcher Quick Launch tab: GPU Layers (layer-count hint shown next to it)Since v1.23betaAll details for the layers, Maximum context window in tokens to allocate (256-524288). Bigger values need more RAM/VRAM; default 16384 in 1.124.Default 16384Launcher Quick Launch tab: Context Size (slider)Since v1.20All details for the context and KV-cache data type: f16 (default), bf16, q8_0, q5_1 or q4_0. Quantizing saves memory; without flash attention only K is quantized. Old numeric values 0-3 still accepted.Default f16Launcher Context tab: Quantize KV Cache (slider)Since v1.67All details when you chose a smaller cache. Leaving How many model layers to offload to the GPU. -1 (default) turns on autofit; 0 keeps everything on the CPU.Default -1Launcher Quick Launch tab: GPU Layers (layer-count hint shown next to it)Since v1.23betaAll details at its default of -1 is often fine: autofit picks a number for you. The calculator is for the cases where you want to know in advance, want the largest context a card can hold, or want to check a model before you download it.
How much VRAM does context use? The KV cache formula
The KV cache stores the keys and values the model has already computed, so it does not redo them for every new token. Its size follows one formula, in words:
2 (keys and values) × layers × context tokens × KV heads × head size × bytes per value
KoboldCpp allocates the context you ask for plus 256 tokens F06, and the default context is 16384 F05. For Qwen2.5-0.5B (24 layers, 2 KV heads of 64 values) at 16384 that is 16640 cells, 2 × 24 × 16640 × 2 × 64 × 2 bytes = 195 MiB at f16, and KoboldCpp’s log says KV buffer size = 195.00 MiB F10. The table is computed by the same code the calculator runs, and the build stops if it ever stops matching the logged sizes.
| Context you ask for | Cells allocated (+256) | Logged KV buffer size | Calculated |
|---|---|---|---|
| 4,096 | 4,352 | 51.00 MiB | 51.00 MiB |
| 16,384 | 16,640 | 195.00 MiB | 195.00 MiB |
| 131,072 | 131,328 | 1539.00 MiB | 1539.00 MiB |
| 32,768, KV q4_0 | 33,024 | 108.84 MiB | 108.84 MiB |
A bytes-per-value of 2 is f16. The quantised caches use less: q8_0 is 1.0625 bytes, q5_1 is 0.75 and q4_0 is 0.5625. In the same test, peak memory at 32K of context fell from 976 MB to 794 MB with q8_0 and to 698 MB with q4_0 F10. A quantised cache needs flash attention, which is on by default F09; with it off, only the K cache is quantised.
Two kinds of models change the arithmetic. A sliding-window model such as Gemma 2 keeps the full context in only some layers; the rest keep a window of tokens, so its cache is much smaller at long context. A mixture-of-experts model has its own attention sizes, and its weights split into attention and expert parts, which is what Keeps the MoE expert weights of the first N layers (all if no number) in system RAM, freeing VRAM for big MoE models.Default 0Launcher Context tab: MoE CPU LayersSince v1.97All details moves to system RAM. The calculator handles both when it can read the layout from the file header, and tells you when it cannot.
Is 8 GB, 12 GB, 16 GB or 24 GB of VRAM enough?
It depends on the model and the context. These tables are calculated by the calculator with the defaults (Windows desktop reserve of 512 MB, safety margin of 1024 MB, KV cache f16, 32 GB of RAM). They show the largest quantisation that fits completely. “Tight” means less than 5% of the usable memory is left. These are calculated values: we have not yet measured these cards, so treat them as a guide and use the calculator for your exact case.
At 8K of context
| Model | 8 GB | 12 GB | 16 GB | 24 GB |
|---|---|---|---|---|
| Qwen2.5 0.5B Instruct | fits Q8_0 | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Llama 3.2 3B Instruct | fits Q8_0 | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Qwen2.5 7B Instruct | fits Q6_K | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Llama 3.1 8B Instruct | tight Q6_K | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Qwen3 8B | fits Q5_K_M | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Gemma 2 9B It | tight IQ4_XS | tight Q8_0 | fits Q8_0 | fits Q8_0 |
| Mistral Nemo Instruct 12B | doesn't fit | fits Q6_K | fits Q8_0 | fits Q8_0 |
| Qwen2.5 14B Instruct | doesn't fit | tight Q5_K_M | fits Q6_K | fits Q8_0 |
| Qwen3 30B-A3B (MoE) | doesn't fit | doesn't fit | doesn't fit | fits Q5_K_M |
| Qwen2.5 32B Instruct | doesn't fit | doesn't fit | doesn't fit | fits Q4_K_M |
| Llama 3.3 70B Instruct | doesn't fit | doesn't fit | doesn't fit | doesn't fit |
At 16K of context
| Model | 8 GB | 12 GB | 16 GB | 24 GB |
|---|---|---|---|---|
| Qwen2.5 0.5B Instruct | fits Q8_0 | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Llama 3.2 3B Instruct | fits Q8_0 | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Qwen2.5 7B Instruct | fits Q6_K | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Llama 3.1 8B Instruct | fits Q4_K_M | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Qwen3 8B | tight Q4_K_M | fits Q8_0 | fits Q8_0 | fits Q8_0 |
| Gemma 2 9B It | doesn't fit | fits Q6_K | fits Q8_0 | fits Q8_0 |
| Mistral Nemo Instruct 12B | doesn't fit | fits Q5_K_M | fits Q8_0 | fits Q8_0 |
| Qwen2.5 14B Instruct | doesn't fit | fits IQ4_XS | fits Q6_K | fits Q8_0 |
| Qwen3 30B-A3B (MoE) | doesn't fit | doesn't fit | doesn't fit | tight Q5_K_M |
| Qwen2.5 32B Instruct | doesn't fit | doesn't fit | doesn't fit | tight Q4_K_M |
| Llama 3.3 70B Instruct | doesn't fit | doesn't fit | doesn't fit | doesn't fit |
Two rules of thumb fall out of the tables. A 7B to 9B model at a 4-bit quantisation fits an 8 GB card with room for a normal context. The step to 12 GB buys a 12B to 14B model or a longer context; 16 GB and 24 GB make 30B-class models practical. For what to run, see Which model should I use? and quantisation.
What GPU layers are
A language model is a stack of identical layers, 32 in a typical 8B model. Every layer you put on the GPU runs fast; every layer you leave behind runs on the CPU, from system RAM, and sets the speed of the whole answer. “N of M layers on the GPU” is the split.
How many model layers to offload to the GPU. -1 (default) turns on autofit; 0 keeps everything on the CPU.Default -1Launcher Quick Launch tab: GPU Layers (layer-count hint shown next to it)Since v1.23betaAll details sets the number. -1, the default, asks KoboldCpp to work it out with autofit, and 0 keeps everything on the CPU. KoboldCpp also accepts -ngl and --n-gpu-layers as other names for the same flag. The GPU layers guide covers how to choose the number by hand and how to check it worked.
What this LLM VRAM calculator assumes
Each assumption is labelled with how we know it: measured in our own runs, upstream (from KoboldCpp’s own help or source), or estimate.
| Assumption | Value | Basis |
|---|---|---|
| Weights per layer, output and embedding sizes | Summed from the file’s tensor table | Exact, read from the header |
| KV cache | The formula above, context + 256 cells | Measured, matches logged sizes (F10, F36) |
| Compute buffer on the card | A base that grows with model size, plus 2 bytes × batch per cell | Estimate, calibrated on two measured models (F36, F42) |
| Output matrix | In system RAM unless you tick “count it on the GPU” | Measured on a software Vulkan device (F36, F42). A real card may place it on the GPU: tick the box to be cautious |
| Token embedding table | Always in system RAM | Measured (F36) |
| Desktop reserve | 512 MB per card on Windows and Linux, 0 on macOS | Estimate, editable |
| Safety margin | 1024 MB per card | Upstream: --autofitpadding default (visible in our logs) |
| Quantised KV cache | Needs flash attention (on by default); with it off only K is quantised | Upstream help text, F09 |
| Apple Silicon | One memory pool; the GPU may use about two thirds of RAM up to 36 GB and three quarters above | Estimate until we measure it on a Mac |
| Several GPUs | Layers split in proportion to memory; each card holds its own compute buffer | Estimate |
| System RAM check | CPU-side weights, KV and host buffers against RAM minus 3 GB for the system | Estimate |
| Side models | Whisper from the whisper.cpp memory table; image models are rough preset sizes; vision projector and others by file size | Estimate, you can type your own sizes |
Accuracy and our tests
We tested the calculator in the following ways.
- KV cache sizes. The formula reproduces the sizes KoboldCpp logged for Qwen2.5-0.5B exactly: 51.00, 195.00 and 1539.00 MiB at 4096, 16384 and 131072 tokens, and 108.84 MiB at 32768 with q4_0 F10.
- Predicted against measured memory. The table compares the calculator’s prediction with the allocations logged in five of our runs. All are within 10%. These runs used a software Vulkan device in our lab, so they check the arithmetic and not real-card behaviour.
| Case | Model | Context | Layers on GPU | Predicted | Measured | Error | Result |
|---|---|---|---|---|---|---|---|
| F36-8b-8k | Llama 3.1 8B Instruct Q4_K_M | 8,192 | 32/32 | 5173.0 MiB | 5172.8 MiB | +0.0% | F36 |
| F36-8b-32k | Llama 3.1 8B Instruct Q4_K_M | 32,768 | 32/32 | 8269.0 MiB | 8268.8 MiB | +0.0% | F36 |
| F42-05b-4k | Qwen2.5 0.5B Instruct Q4_K_M | 4,096 | 24/24 | 328.1 MiB | 326.6 MiB | +0.4% | F42 |
| F42-05b-8k | Qwen2.5 0.5B Instruct Q4_K_M | 8,192 | 24/24 | 380.1 MiB | 378.6 MiB | +0.4% | F42 |
| F42-05b-32k | Qwen2.5 0.5B Instruct Q4_K_M | 32,768 | 24/24 | 692.1 MiB | 690.6 MiB | +0.2% | F42 |
- Header reading. The reader parses 13 test headers: four quantisations of one real model, a real vision-model text part, a real vision projector, a real embedding model, and synthetic headers built from public model configs for a dense 8B, a sliding-window 9B, a mixture-of-experts 30B, a tied-embedding model and a two-part split. Sizes from the real files add up to the real file sizes within 1.5%, the difference being the vocabulary stored in the full header.
- Network. In the browser test, local-file reading made no request at all, and a pasted link made requests only to huggingface.co.
- Local file speed. A 20 GB file reads in well under a second, because only the header is read.
Known limits. We do not have a real GPU, so the “predicted layers within ±2 of the maximum measured” check on real cards (T-MEM-01) has not been run, and the tool says “calculated” rather than “calibrated on a card”. Brand-new architectures with unknown keys may be sized wrongly, and the tool says so when it falls back to a guess. Image model sizes are presets.
Your files stay on your computer
Local file. When you pick a .gguf file, your browser reads only its first few megabytes with the File API, enough for the header and tensor list. The file is not uploaded and the page makes no network request while reading it. Hugging Face link. Your browser asks huggingface.co for the first few megabytes with an HTTP range request; the model weights are not downloaded and no other site is contacted. The page’s security policy allows these requests on this page only. See the privacy page.
Frequently asked questions
How many GPU layers should I use in KoboldCpp?
As many as fit in your GPU memory after the context and buffers are counted. The calculator above gives the number for your exact model, context and card. You can also leave --gpulayers at -1, the default, and KoboldCpp's autofit picks a value for you; it keeps 1024 MB free by default, so it can choose fewer layers than the calculator.
How much VRAM does a 16K context need?
It depends on the model, because the cache grows with layers, KV heads and head size. For Llama 3.1 8B, 8K of context needs a 1,056 MiB KV cache and 32K needs 4,128 MiB, so 16K needs about 2,080 MiB at f16. Quantising the cache to q8_0 roughly halves that. Pick your model in the calculator to see the figure for it.
Is 8 GB of VRAM enough for a local LLM?
Yes for 7B to 9B models at a 4-bit quantisation with a normal context, and no for anything much bigger without moving layers to the CPU. The tables on this page show which listed models fit completely on 8, 12, 16 and 24 GB at 8K and 16K of context.
Why does KoboldCpp's autofit choose fewer layers than this calculator?
Autofit leaves a padding of free VRAM (1024 MB by default, set with --autofitpadding) and the calculator's default safety margin matches it. If you see a bigger gap, the padding you use differs, a side model such as a vision projector or image model is loaded, or the real compute buffer is larger than our estimate. Compare the offloaded layers line in your log with the result here.
Does this calculator work for Ollama or LM Studio?
The weights and KV cache arithmetic apply to any GGUF runner, because it comes from the model file. The flags, the 256-token context padding and the 1024 MB padding are KoboldCpp's, so the layer count can differ in other programs.
Is my model file uploaded?
No. When you drop a file, your browser reads only the first few megabytes (the header) with the File API and nothing is sent anywhere. When you paste a Hugging Face link, your browser asks huggingface.co for the same few megabytes directly.