VRAM Estimation and Model Selection for Local Deployment of Open-Source LLMs
This article explains how to estimate VRAM usage for local LLM deployment by breaking it into model weights, KV cache, and runtime overhead. It provides INT4 reference figures for 2B to 30B models, guidance for selecting discrete GPUs and unified-memory devices, troubleshooting steps for out-of-memory issues, and considerations for using cloud GPU resources alongside local hardware.
1. What Makes Up VRAM Usage
Parameter count alone is not enough when evaluating local deployment. Actual VRAM usage mainly comes from three parts.
1. Model weights
Weights are the most fundamental part. The calculation is parameter count multiplied by the number of bytes per parameter. Take a 30B model as an example: with BF16, each parameter occupies 2 bytes, so the theoretical weight size is about 60GB. With INT4 quantization, common formats average about 4.5 bits per parameter, including additional data such as group scales, so the pure weights are about 15–18GB.
2. KV Cache
KV Cache stores the attention keys and values for historical tokens. It grows approximately linearly with context length and concurrent batch size. It can be estimated with the following formula:
KV Cache bytes ≈ 2 × layers × KV heads × head dimension × context length × batch size × bytes per element
The factor 2 represents the two caches, K and V. As conversation turns increase or input becomes longer, KV Cache expands quickly. In long-context scenarios, it often becomes the bottleneck. However, its growth is linear, not exponential.
3. Runtime overhead
The inference framework itself also occupies VRAM, including the CUDA context, internal framework buffers, activations, and memory fragmentation. In actual deployment, it is usually necessary to reserve 1–3GB.
2. VRAM Reference by Model Tier
The table below estimates usage with INT4 quantization, context within about 4K tokens, and a single batch.
| Model tier | INT4 pure weights | Total usage (estimated) | Notes |
|---|---|---|---|
| 2B level | About 1–1.5GB | About 2–4GB | Suitable for validating a minimal runnable path or simple text processing on low-compute devices |
| 4B level | About 2–2.5GB | About 4–6GB | The preferred starting point for most developers on consumer devices |
| 20B level MoE | About 10–12GB | About 12–16GB | Sparse activation reduces computation, but the weights still need to be fully loaded |
| 30B level | About 15–18GB | About 18–24GB | Better performance on code generation and complex reasoning, with higher VRAM requirements |
The values above are estimates based on common quantization formats and default settings of inference frameworks. Actual usage is affected by framework version, KV Cache format, context length, and batch size. Before deployment, measure peak VRAM in the target environment.
3. Discrete GPU Selection and Practice
On a PC or workstation, the VRAM capacity of a discrete GPU determines the upper limit of deployable models.
1. 6GB level (entry-level GPU)
Prioritize 4B-level models. The weights of a larger quantized model may barely fit, but the first conversation turn may trigger VRAM overflow, so this is not recommended. Limit context to within 2048 tokens and disable unnecessary extensions.
2. 8GB level (mid-range GPU)
4B-level models run relatively comfortably and are the main choice at this tier. The weights of a 20B-level MoE model are already close to or exceed 8GB, so deployment at this tier is not recommended.
3. 12GB level (high-end mainstream GPU)
You can cautiously try the INT4 version of a 20B-level MoE model, with weights of about 10–12GB. Very little VRAM remains, so limit context to within 2K, use a single batch, and measure peak VRAM. Being able to start the model does not mean it can run stably. If generation speed suddenly drops significantly, it usually means VRAM is full and the system is swapping memory.
4. 16GB level
A 20B-level MoE model can run relatively stably while retaining some KV Cache space. The INT4 weights of a 30B-level model already require 15–18GB, leaving insufficient margin, so deployment is not recommended.
5. 24GB and above (flagship GPU)
A 30B-level model is a suitable candidate, but total usage is about 18–24GB, which is still tight. When enabling long context above 8K or multi-turn deep conversations, KV Cache will noticeably compete for space, so the VRAM allocation ratio between weights and cache needs to be planned in advance. On some tasks, its output quality can approach that of medium-sized cloud instances; specific results need to be tested with your own tasks.
4. Deployment Considerations for Unified Memory Devices
Devices using ARM architecture and unified memory design share the same memory pool between CPU and GPU. These devices do not focus on discrete VRAM but on total unified memory capacity and bandwidth.
Two points need attention. First, the system and other applications occupy shared memory, so the capacity actually available to the model must deduct this portion. Second, memory bandwidth determines generation speed. At the same capacity, token generation speed on unified memory devices is usually lower than on discrete GPUs.
- 16GB unified memory: Start with a 4B-level model. A 20B-level model can theoretically be loaded, but bandwidth limits make generation very slow and the experience limited.
- 32GB unified memory: 4B-level models can run smoothly, and a 20B-level MoE model can be tried. Compared with the 16GB version, it can hold more applications at the same time, providing a better multitasking experience.
- 64GB and above unified memory: Both 20B and 30B-level models can run. For developers with high data privacy requirements who do not want to build a discrete GPU workstation, these devices offer some cost-effectiveness.
When benchmarking, record the full scope, including input length, output length, quantization format, and framework version. A single token/s value cannot be reproduced or compared.
5. Troubleshooting VRAM Overflow
When encountering insufficient VRAM, check item by item using the table below.
| Symptom | Possible cause | Action |
|---|---|---|
| Error when loading the model | Weights themselves exceed available VRAM | Use a smaller model or a lower-bit quantization version |
| Error on the first conversation turn | Context or batch settings are too large | Reduce context length and set batch to 1 |
| Error midway through a long conversation | KV Cache grows with turns | Limit historical turns or truncate earlier context |
| Sudden significant drop in speed | VRAM is full, causing memory swapping or offloading | Reduce context and close simultaneously running programs |
Note that lowering quantization precision affects output quality, and offloading layers to memory significantly reduces speed. Before making adjustments, first confirm which item is the bottleneck, then change items one by one and record the results.
6. Using Cloud Compute Alongside Local Hardware
When local hardware cannot meet model fine-tuning or high-concurrency inference needs, consider container platforms and GPU instances from compliant cloud providers. A common approach is to complete preprocessing or complex inference for large-parameter models in the cloud while keeping lightweight tasks running locally.
Before using cloud services, evaluate the following risks:
- Cost: GPU instances are billed by duration, and idle resources still incur charges. Set usage alerts.
- Latency: Network round trips affect the interactive experience. For scenarios with high real-time requirements, prioritize local execution.
- Data compliance: Uploading data to the cloud may involve cross-border transfer and privacy protection requirements. Desensitize sensitive data first and confirm compliance with applicable regulations.
- Access permissions: Model weights stored in object storage should have access control to avoid public access.
Conclusion
Local LLM deployment requires considering parameter count, quantization method, VRAM capacity, and memory bandwidth together. Official theoretical values usually include only weights; actual usage also adds KV Cache and runtime overhead. It is recommended to measure peak VRAM on the target device using the methodology in this article, and then select the model and configuration based on the measurement results.
