Selecting a GPU for Local LLM Deployment: A VRAM-First Practical Guide
This article explains why video memory (VRAM) capacity is the primary constraint when choosing a GPU for running large language models locally. It breaks down how to estimate VRAM usage from model weights, KV cache, and runtime overhead, provides a practical estimation formula and code snippet, and offers a step-by-step selection strategy that prioritizes capacity over raw speed. Aimed at engineers and hobbyists, the guide focuses on inference workloads, comparing typical quantization formats and their memory footprints across common model sizes.
1. Define the Problem First: VRAM Is the First Threshold for Local Deployment
When running large models locally, inference requires the model weights and intermediate states to reside in GPU memory (VRAM). If VRAM is insufficient, the model may fail to load. If portions of the data are forced into system RAM, generation speed degrades noticeably. Therefore, the first step in GPU selection is to verify that VRAM capacity can accommodate the target model, before comparing compute speed, memory bandwidth, or cost.
Two workload types must be distinguished. Inference (generating answers, processing text) is most sensitive to VRAM capacity. Training or full fine-tuning requires far more VRAM than inference, often exceeding what a personal machine can provide. This article focuses on inference.
2. How to Estimate VRAM Consumption
VRAM usage is composed of three main parts: model weights, KV cache, and runtime overhead.
2.1 Weight Occupancy
Weight usage is calculated as:
VRAM for weights ≈ number of parameters × bytes per parameter
Bytes per parameter depends on the numeric precision. Approximate values for common precisions are:
| Precision | Bytes per Parameter | 7B Model | 13B Model | 70B Model |
|---|---|---|---|---|
| FP16 | 2 | ~14 GB | ~26 GB | ~140 GB |
| INT8 | 1 | ~7 GB | ~13 GB | ~70 GB |
| INT4 | 0.5 | ~3.5 GB | ~6.5 GB | ~35 GB |
These values include only the weights themselves; other overheads are not counted.
2.2 KV Cache
The KV cache stores the keys and values of historical tokens during the attention computation. Its size grows linearly with the context length. The approximate formula is:
KV Cache ≈ 2 × layers × KV heads × head dimension × context length × batch size × bytes per element
This item is the most easily overlooked. For the same model, expanding the context from 4K to 32K increases the KV cache by 8 times. Long-document processing and long multi-turn conversations can quickly inflate this portion of memory.
2.3 Runtime Overhead
During inference, activation tensors, framework-internal buffers, and memory fragmentation also consume VRAM. As an empirical rule, reserve a margin of 15% to 30%. This ratio is based on engineering practice and its actual value depends on the runtime environment and inference method.
2.4 Estimation Example
The following schematic code can quickly estimate required VRAM:
def estimate_vram_gb(params_b, bytes_per_param, layers, kv_heads,head_dim, ctx_len, batch=1, kv_bytes=2, margin=0.2):"""Rough estimation of VRAM usage for inference.Args:params_b: number of parameters in billions (e.g., 7 for 7B)bytes_per_param: bytes per weight parameter (e.g., 2 for FP16, 1 for INT8, 0.5 for INT4)layers: number of transformer layerskv_heads: number of KV attention headshead_dim: dimension of each attention headctx_len: maximum context length in tokensbatch: inference batch size (default 1)kv_bytes: bytes per KV cache element (default 2 for FP16)margin: extra safety margin as a fraction (default 0.2)Returns:estimated total VRAM in GB"""weights_gb = params_b * bytes_per_paramkv_gb = 2 * layers * kv_heads * head_dim * ctx_len * batch * kv_bytes / 1e9total_gb = (weights_gb + kv_gb) * (1 + margin)return total_gb
This function multiplies the sum of weights and KV cache by a safety factor. For a 7B model in FP16 with typical attention parameters (e.g., 32 layers, 32 KV heads, head_dim 128, context 4096), the result would be roughly 14 GB + 1.07 GB ≈ 15 GB, plus margin → about 18 GB.
3. VRAM-First Selection Strategy: A Four-Step Path
3.1 Step 1: Fix the Model Set
Before choosing a GPU, list the models you actually need to run. For each model, note the parameter size and the maximum context length required for your tasks (e.g., 8K, 32K, or 128K). If you plan to use quantization, decide which precision is acceptable (INT4/INT8). The exact benchmark values from online sources may not match your runtime, so use them only as a starting point.
3.2 Step 2: Compute the Total VRAM Demand
Use the estimation method from the previous section. In practice, the formula above provides a good upper bound. Always include the KV cache for the worst-case context length you expect, not just the default value. Then apply the safety margin to cover activation memory and framework overhead. If you want to keep the model in FP16 but the VRAM only fits an INT8 version, the required card tier changes.
3.3 Step 3: Match Available GPU Cards
Compare the estimated VRAM requirement against the actual memory of candidate GPUs. Consumer cards commonly come in 8 GB, 12 GB, 16 GB, or 24 GB configurations. Professional cards may offer 48 GB or more. If the target model requires more than 24 GB, a single consumer card is insufficient. In that case, you may need to use a professional card, a multi-GPU setup, or offload some layers to CPU (which will reduce speed). Remember that memory bandwidth also matters: cards with the same VRAM but different bandwidth will show noticeable speed differences. After ensuring the capacity fits, you can then compare tokens per second.
3.4 Step 4: Validate with Real-World Testing
Selection is not complete after reading specifications. After installing the chosen GPU, test it with the actual model and a realistic workload. Measure generation speed, memory usage, and stability under long contexts. Adjust quantization or context length if necessary. The theoretical estimate is only a guide; real deployments always involve unexpected overhead.
4. Quantization: A Practical Tool That Adds Complexity
Quantization reduces VRAM usage by lowering the bytes per parameter (e.g., from FP16 to INT8 or INT4). This directly impacts the weight portion, which is often the largest chunk. However, quantization also affects model quality and may slightly reduce accuracy. Use it when the model barely fits, but keep a margin for the KV cache and runtime overhead. In practice, many local deployments use INT4/INT8 to fit larger models on consumer GPUs. The decision should be based on your tolerance for quality loss versus the cost of buying a larger card.
5. Frequently Overlooked Factors
5.1 Context Length Is Not Fixed
Even if you initially plan for 8K context, some tasks like code repository analysis or long summaries may need 32K. The KV cache grows linearly, so a model that fits at 8K may become too large at 32K. Always check the maximum context length you will realistically use, and provision accordingly.
5.2 Batch Size
Inference can be run with a batch size greater than 1, especially in server scenarios. The KV cache formula scales with batch size. For personal local use, a batch size of 1 is usually sufficient, but if you plan to serve multiple requests concurrently, account for the multiplied KV cache.
5.3 Memory Fragmentation and Framework Overhead
Different inference frameworks (e.g., llama.cpp, vLLM, transformers) have different overheads. Some allocate additional memory for CUDA graphs or intermediate buffers. The 15–30% margin is a safe bet, but you may need to increase it for very long contexts or complex models.
5.4 System RAM Swap Is Not a Solution
Some people try to use system RAM as overflow storage. While this prevents a crash, generation speed drops dramatically because the PCIe bandwidth is far lower than VRAM bandwidth. If your workload requires stable speed, always keep VRAM within the card’s physical limit.
6. Conclusion: First Ensure Capacity, Then Optimize Speed
The practical approach is simple: estimate the VRAM requirements of your target models, add a safety margin, and select a card whose memory comfortably exceeds that number. Only then should you compare compute throughput (TOPS) and memory bandwidth to get the best price-to-performance ratio. This VRAM-first strategy avoids the painful experience of owning a fast card that cannot run your model at all. By following the estimation method and the four-step selection path, you can confidently choose a GPU for local LLM inference.
