The sizing formula
Model weights take a fixed number of bytes per parameter, set by precision:GGUF Q4_K_M is mixed precision and averages out to about 0.5–0.56 bytes per parameter rather than a flat 0.5, because K-quants assign different bit-widths to different tensors — see Quantization for how to read those names.
Multiply parameter count by bytes-per-parameter to get raw weight size, then add roughly 20% on top for the KV cache, activations, and framework overhead at a modest context length:
29 GB at bf16, ~15 GB at 8-bit, and ~9.5 GB at 4-bit — see the Hugging Face guide to optimizing LLMs. Longer context adds more KV cache on top of that 1.2× baseline; see KV cache and context for why that scales the way it does.
This formula is a planning estimate for weight size, not ground truth. The real number is the actual
GGUF file size for the exact quantization you plan to run, plus the KV cache for your target context length. See the GPU model-fit guide for worked examples and an interactive estimator.What’s actually competing for memory
Three things share the same pool of VRAM (or unified memory):- Model weights — fixed once the model is loaded, unaffected by prompt length.
- KV cache — grows with context length and batch size; see KV cache and context.
- Activations and framework overhead — smaller working memory needed during each forward pass, roughly what the
1.2×factor in the formula above accounts for.
Offloading: when a model doesn’t fully fit
If a model’s weights don’t fit entirely in your GPU’s VRAM, backends likellama.cpp let you split the model between GPU and CPU instead of failing outright. This is controlled with the --n-gpu-layers (short form -ngl) flag: it sets how many of the model’s layers get loaded onto the GPU, with the rest staying in system RAM.
- Full offload (
-nglset high enough to cover every layer): the entire model runs on the GPU, at full GPU speed. - Partial offload: some layers run on the GPU, the rest run on the CPU using system RAM. This lets a model larger than your VRAM actually load and run, at a cost.
- No offload (
-ngl 0): the whole model runs on CPU only.
llama.cpp underneath.
How unified memory changes the picture
On systems with unified memory — Apple Silicon and AMD’s Strix Halo platform — the CPU and GPU share a single memory pool instead of the GPU having its own separate, smaller VRAM. This changes the offloading calculus:- Capacity: a unified-memory system can load a much larger model than a discrete GPU with fixed VRAM, because the “VRAM” pool can be as large as the machine’s total RAM (up to the portion assigned to graphics use).
- Bandwidth: that same pool runs at lower bandwidth than dedicated GDDR memory on a discrete GPU. A model that fits entirely in unified memory still decodes more slowly than the same model fitting entirely in a discrete GPU’s VRAM, because decode speed tracks bandwidth, not just capacity.
Go deeper
How inference works
Why decode is memory-bandwidth-bound in the first place.
KV cache and context
The part of memory usage that grows with your conversation, not just your model.
Quantization
Shrink bytes-per-parameter to change the sizing formula’s biggest input.
GPU model-fit guide
VRAM tables, an interactive estimator, and what fits on common hardware.
Once it fits and runs
Sizing and offloading get a model running on your hardware, whether that’s fully on GPU or split with the CPU. Once it’s answering requests onlocalhost, the next step is reaching it from anywhere else.
Give it a stable endpoint
Tokios doesn’t pick, host, or fine-tune the model — once it runs locally, Tokios turns it into a stable, authenticated endpoint you can call from anywhere.