VRAM arithmetic for local models
How much memory a model and its context actually need, derived rather than guessed, and what happens at the moment it does not fit.
Almost every VRAM table on the web is somebody’s recollection. They disagree with each other by a factor of two, they rarely say which model of a given size they mean, and none of them shows the arithmetic — so when your card is 2 GiB short there is nothing to reason with. The numbers are not mysterious. A model’s weights occupy its parameter count times its bits per weight, divided by eight. Its context occupies two tensors per layer, sized by the number of key/value heads and the head dimension, times the context length. The runtime takes a fixed amount before either of those loads. That is the whole model of memory, and every page here is that equation with different numbers in it.
Both inputs are published. Parameter counts fall out of the shapes in a model’s own config; bits per weight is documented per quantization type by the tool that produces the file. So these pages derive rather than assert, and where a figure is an approximation they say which term was approximated. Nothing here was benchmarked — where a page needs a speed, it gives the bandwidth-bound ceiling and the command to measure the real thing on your own machine.
How Much VRAM a 7B Model Needs at Q4, Q5 and Q8
The weights term, the KV-cache term and the runtime term for a 7B-class model, each derived from published parameter shapes and llama.cpp's own bits-per-weight table.
10 min read
How Much VRAM a 13B Model Needs at Each Quant Level
Weights per quantization level for a 13B, and why the context term rather than the weights is what pushes it off a 12 GiB card.
10 min read
How Much VRAM a 34B Model Needs at Each Quant Level
Two different architectures are both called 34B; their weights differ by 2% and their context cost by 25%, and only one of them fits a 24 GiB card usefully.
10 min read
How Much VRAM a 70B Model Needs at Each Quant Level
Weights, context and per-card overhead for a 70B, checked against llama.cpp's own published file size, and the card counts each quant implies.
10 min read
Why a Mixture-of-Experts Model's VRAM Need Isn't Its Total Parameter Count
Active parameters set the speed and total parameters set the memory, and the gap between the two is why a sparse model is cheap to run and expensive to hold.
9 min read
Fitting a Model and Its Context Window in 8GB of VRAM
The budget equation solved for context length on an 8 GiB card, at each quant, with the runtime reserve stated as an assumption rather than hidden.
9 min read
Fitting a Model and Its Context Window in 12GB of VRAM
Why the extra 4 GiB over an 8 GiB card is better spent raising the quant of a smaller model than on stepping up to a 13B.
9 min read
Fitting a Model and Its Context Window in 24GB of VRAM
The three regimes a 24 GiB card supports — a 34B with short context, a 13B at full precision, or an 8B with a hundred thousand tokens — with the arithmetic for each.
10 min read
What Happens When a Model Doesn't Fit in VRAM
The two failure modes — a hard allocation error and a silent spill to system RAM — how to tell them apart, and the arithmetic behind the throughput cliff.
10 min read
How Much VRAM CUDA Reserves Before Your Model Even Loads
What occupies the card before any weights arrive, why the figure is machine-specific rather than a constant, and how to measure your own in two commands.
9 min read
Quantifying the Memory You Save Going From FP16 to Q4
The 4x reduction is 3.27x once the block overhead and the tensor mix are counted, and less again once the KV cache is in the total.
10 min read
How Many Parameters Fit in 16GB of Unified Memory at Q4
Inverting the weights formula gives a parameter ceiling, but the usable fraction of unified memory is machine-set and much less than the total.
9 min read
Why Local Inference Never Saturates a GPU at Batch Size One
Single-stream decode is bandwidth-bound by two orders of magnitude, so a GPU running flat out is doing almost no arithmetic — and the utilisation number you are reading does not measure arithmetic.
10 min read
The Memory Cost of Keeping a Context Window Full During a Long Chat
KV memory grows linearly with every token in the session, but under llama.cpp it is allocated up front — so the ceiling arrives as truncation, not as an out-of-memory error.
10 min read
Other topics
- LLM fundamentals & architecture
- Tokens, tokenization & context windows
- Prompt engineering
- Reasoning models & test-time compute
- Multimodal AI: vision, audio, video
- RAG & retrieval
- Embeddings & vector search
- AI agents & tool use
- Structured output & function calling
- Fine-tuning & post-training
- Local inference errors, string by string
- Running local models day to day
- Testing code that calls an LLM
- Snapshot and property testing for model output
- Regression suites for prompts
- Eval gates in CI
- Flaky tests against a model
- Determinism and the cost of testing
- Contract and streaming tests
- Testing tool calls and retrieval
- Inference, serving & latency
- Rolling out a prompt change
- Testing AI systems in practice
- Forecasting a time series
- Machine learning on tabular data
- Geospatial data and models
- Understanding audio that is not speech
- Understanding video
- Core computer vision tasks
- Machine learning on graphs
- Point clouds and 3D
- Evaluation, benchmarks & LLM-as-judge
- Sensor and IoT data
- Logs and event streams
- Models over biological sequences
- Machine learning on molecules
- Embedding and searching code
- Extracting invoices and purchase orders
- Receipts, statements and tax forms
- Insurance policies and contracts
- Deeds, court filings and patents
- Extracting from medical records
- Observability & LLMOps
- CVs, certificates and identity documents
- Shipping, customs and technical documents
- Meetings, email, chat and filled-in forms
- Building an extraction pipeline
- Business, property and inspection documents
- Contract clauses and insurance claims
- Regulated and compliance documents
- Consumer, travel and closing documents
- Mapping one chat API onto another
- SDK and framework migrations
- Hallucination & failure modes
- Re-embedding and model deprecation
- Cutting over between providers
- Parity gaps, shims and legacy endpoints
- Moving between model versions
- Migrating vector stores and caches
- Mapping capabilities and parameters
- Migrating pipelines and agents
- Contracts, runbooks and rollback
- Auditing a codebase before a cutover
- Compliance and fine-tune migration
- LLM cost engineering
- Routing, cost tracking and multi-tenancy
- What a migration does to your prompts
- AI security & prompt injection
- Privacy, compliance & data residency
- AI governance, policy & society
- Building reliable AI applications
- AI hardware, GPUs & compute
- Open-weight models & local inference
- AI for developers & coding agents
- AI in industry: vertical playbooks
- AGI, superintelligence, alignment & the long future
- Machine learning foundations
- NLP fundamentals & classical tasks
- Data engineering for AI
- Synthetic data & dataset curation
- AI product design & UX
- Search, ranking & recommendation
- Enterprise adoption & change management
- AI careers, skills & teams
- Reading AI research
- AI in science & discovery
- Robotics & embodied AI
- AI economics, markets & business models
- AI myths, hype & media literacy
- Context engineering
- Shipping AI features: patterns & anti-patterns
- Build it: end-to-end AI tutorials
- Python for AI: hands-on recipes
- TypeScript, React and the web
- Frameworks and SDKs
- Errors and troubleshooting
- AI facts, numbers and statistics
- The history of AI
- The maths behind AI
- Architectures beyond the transformer
- Reinforcement learning
- Diffusion and generative media
- Speech, audio and voice engineering
- Benchmarks, one at a time
- AI search visibility
- Infrastructure and operations
- Databases and storage for AI
- Knowledge graphs and structured knowledge
- Classical ML in production
- Regulation, jurisdiction by jurisdiction
- Prompt recipes and pattern library
- AI for people who do not write code
- Writing, media and creative work
- Edge and on-device AI
- Interpretability and model internals
- Field notes
- OpenAI model behaviour
- Claude model behaviour
- Gemini model behaviour
- Llama model behaviour
- Mistral model behaviour
- Qwen model behaviour
- DeepSeek model behaviour
- Cohere model behaviour
- Grok model behaviour
- Small model behaviour
- Hybrid model architectures
- Token cost by language and script
- Transliteration, romanization and script handling
- Locale-correct output
- Multilingual generation quality
- Multilingual pipelines
- The EU AI Act, article by article
- AI under the GDPR and EU data law
- US AI regulation, state and sector
- International AI governance and standards
- AI litigation and enforcement
- Running AI workloads on AWS
- Running AI workloads on Google Cloud
- Running AI workloads on Azure
- AI at the edge: Workers, Vercel and Netlify
- Serving models on Kubernetes
- Operating AI infrastructure
- Quantization formats and what they cost
- llama.cpp, flag by flag
- Ollama and the desktop local-model runtimes
- Local models on Apple Silicon
- Hardware for local inference
- Running speech and embedding models locally
- Model files, adapters and conversion