Deploying Large Models Locally: Model Selection, VRAM Estimation, and Practical Setup
This article provides a practical guide to running large language models on local infrastructure. It covers three key aspects: sourcing reliable open-source models, estimating GPU memory requirements based on parameter count and quantization, and following a structured setup workflow. The content includes a memory estimation table, a reference Python script, and an explanation of the trade-offs of quantization, helping readers make informed decisions before deployment.
Running large models locally keeps data within an internal network, reduces per-call costs, and simplifies debugging and customization. However, the primary challenges are usually not software-related but involve three things: finding trustworthy model sources, verifying hardware suitability, and starting the service correctly. The following sections address each step in order.
1. Obtaining Models: Prioritize Trusted and Accessible Sources
Open-source models are generally published on comprehensive model hosting platforms. These platforms aggregate models across language, vision, audio, and other domains. Each model page typically includes a model card describing training data, parameter size, intended use cases, and license terms. When selecting a model, follow this checklist:
- License: Confirm whether commercial use is permitted, whether attribution is required, and whether usage is restricted to specific scenarios.
- Parameter scale and version: Distinguish between base models, instruction-tuned models, and chat models. These have different training objectives and are suited to different tasks.
- File integrity: After downloading, verify the checksums provided by the publisher to ensure the files are not corrupted or tampered with during transfer.
- File format: Prefer weight formats that do not execute arbitrary code when loaded. Some legacy serialization formats can execute code during loading, posing security risks.
If network access is unstable, domestic model hosting platforms or mirror sites can be used. The file content on mirrors is usually identical to the original, but checksums and license agreements should still be verified.
The unit “B” for parameter count stands for billion. For example, 7B means approximately 7 billion parameters, and 70B means approximately 70 billion. The parameter count directly determines the storage and VRAM occupied by the model weights, making it the starting point for hardware evaluation.
2. Checking Hardware: VRAM Is the Primary Constraint
During inference, model weights must be fully loaded into GPU memory. If VRAM is insufficient, the model cannot be loaded, or it must rely on system memory offloading, which significantly degrades performance. Therefore, the first step in judging local deployment feasibility is to look at VRAM capacity.
Without any quantization, the weight occupancy can be estimated with the following formula:
Model VRAM usage (GB) ≈ Parameter count (B) × Bytes per parameter
Under half precision (FP16 or BF16), each parameter takes 2 bytes, so the formula becomes “Parameter count (B) × 2”. Using three common model sizes as examples:
| Model Size | FP16 | INT8 Quantization | INT4 Quantization |
|---|---|---|---|
| 7B | ~14 GB | ~7 GB | ~3.5 GB |
| 13B | ~26 GB | ~13 GB | ~6.5 GB |
| 70B | ~140 GB | ~70 GB | ~35 GB |
These numbers are only the lower bound for the weights. Actual runtime requires additional VRAM, which mainly comes from three parts:
- KV cache: Stores intermediate results for the context, growing with context length and concurrent request count.
- Activations and temporary buffers: Temporary data produced during computation.
- Runtime overhead: VRAM occupied by the inference framework, drivers, and compute libraries.
As a rule of thumb, start with about 20% headroom over the weight estimate. Long contexts or high concurrency require more.
For example, with a 24 GB GPU: a 7B model in FP16 needs about 14 GB for weights, plus headroom ~17 GB, so it can run. A 13B model in FP16 needs about 26 GB, exceeding VRAM, but an INT4 version (~6.5 GB) can run. A 70B model even with INT4 needs ~35 GB, requiring multiple cards or a larger-memory GPU.
The following script uses only standard library functions to calculate weight occupancy for different sizes and precisions, allowing quick comparison before selection:
BYTES_PER_PARAM = {"fp16": 2.0, "int8": 1.0, "int4": 0.5}def weight_memory_gb(params_b: float, precision: str) -> float:"""Estimate VRAM used by model weights (GB), not including KV cache or runtime overhead."""return params_b * BYTES_PER_PARAM[precision]def estimate_with_margin(params_b: float, precision: str, margin: float = 0.2) -> float:"""Add empirical headroom to the weight estimate as a lower-bound reference for GPU selection."""return weight_memory_gb(params_b, precision) * (1 + margin)if __name__ == "__main__":for size in (7, 13, 70):for precision in ("fp16", "int8", "int4"):weights = weight_memory_gb(size, precision)total = estimate_with_margin(size, precision)print(f"{size}B {precision:>4}: weights ~{weights:.1f} GB, with margin ~{total:.1f} GB")
What Quantization Does and Its Trade-offs
Quantization converts weights from high precision to lower precision storage. It trades a certain amount of accuracy for reduced VRAM usage. Generally, INT8 introduces minimal accuracy loss, and the difference is almost imperceptible in most scenarios. INT4 is typically still usable for daily conversations and text processing, but on tasks such as complex reasoning, long-text understanding, and code generation, the performance degradation may be more noticeable.
When choosing a quantized version, you should compare it against your own task data.
