Local LLM Deployment in Practice: VRAM, Quantization, and Inference Stability
This article explains how to approach local LLM deployment by estimating VRAM requirements, selecting quantization levels, measuring inference latency and throughput separately, and diagnosing compatibility issues in chat templates and tokenizers. It also covers the operational trade-offs of local deployment and the need for reproducible benchmarks and structured validation.
1. Applicable Scenarios and Costs of Local Deployment
Local deployment of large language models offers three main benefits. First, data does not leave the local network, which helps meet privacy and compliance requirements. Second, the inference path is shorter, so external network fluctuations do not affect service availability. Third, for long-term, high-frequency usage, the cost per call may be lower than that of a usage-based external API.
These benefits come with clear costs. The team must handle hardware procurement, driver and runtime environment maintenance, model version upgrades, and troubleshooting. Open-source models also often lag behind top-tier hosted services in complex reasoning and long-context processing. Before starting a project, you should answer three questions: Is the call volume stable? Must the data remain on-premises? Does the team have the ability to maintain continuous operations? If two of the three answers are no, a hosted solution is usually more appropriate.
2. VRAM Estimation: Do the Math Before Choosing Hardware
VRAM is the first barrier to whether a model can run. The VRAM occupied by model weights can be calculated directly:
Weight VRAM ≈ number of parameters × bytes per parameter
For a model with about 26 billion parameters, the approximate weight footprint at different precisions is as follows:
- 16-bit floating point (2 bytes per parameter): about 48 GiB
- 8-bit integer (1 byte per parameter): about 24 GiB
- 4-bit integer (0.5 bytes per parameter): about 12 GiB
In addition to weights, inference also requires KV cache. KV cache grows linearly with context length and the number of concurrent requests, and can be calculated as follows:
KV cache ≈ 2 × layers × KV heads × head dimension × context length × concurrency × bytes per element
For actual estimation, the number of layers, KV heads, and head dimension should be read from the model configuration file. During runtime, space must also be reserved for activations and framework overhead. As a rule of thumb, reserve 10% to 20% of the total as headroom. The following pseudocode shows the complete estimation logic:
function estimate_vram_gb(params_b, bits, layers, kv_heads, head_dim,ctx_len, batch, kv_bytes = 2):weights = params_b * 1e9 * bits / 8 / 1024^3kv_cache = 2 * layers * kv_heads * head_dim * ctx_len * batch * kv_bytes / 1024^3return (weights + kv_cache) * 1.15 # Reserve about 15% overhead
For a GPU with 16 GB of VRAM, 4-bit weights take about 12 GiB, leaving only 3 to 4 GiB. This remaining space must hold both KV cache and activations, so context length and concurrency will be significantly limited. This conclusion comes from estimation; actual performance still needs to be validated with the target model and runtime.
3. Quantization: Trade Accuracy for Resources and Validate the Loss
Quantization is the process of mapping weights from high-precision values to lower-bit representations. It is the most common way to reduce VRAM usage in local deployment, but its costs need to be understood.
Common trade-offs are as follows:
- 16-bit preserves the most numerical precision and consumes the most resources, making it suitable as a quality baseline.
- 8-bit usually causes only a small quality loss on most general tasks and is a cost-effective compromise.
- 4-bit significantly compresses VRAM, but is more prone to degradation on numerically sensitive tasks such as long-chain reasoning, precise formatted output, and fine-grained multilingual expression.
Quantization schemes should not be judged by subjective impressions. The correct approach is to run both the original-precision and quantized versions on the same test set and compare metrics such as accuracy, format validity rate, and repetition rate. Pay particular attention to the fact that quantized versions may produce repeated sentences, drift, or gibberish in long conversations. These problems are often not obvious in the first few turns and must be found through specially designed multi-turn tests.
4. Inference Performance: Separate Latency from Throughput
Performance metrics are easy to confuse, so their definitions should be clarified first:
- Time to first token (TTFT): the wait time from when a user sends a request to when the first token appears. It is mainly affected by input length and prefill computation.
- Generation speed: the rate at which a single request continuously outputs tokens, often expressed in tokens/s. It is mainly limited by VRAM bandwidth.
- Throughput: the total number of tokens generated by all concurrent requests per unit of time. It is affected by batching strategy and concurrency scheduling.
Interactive conversations care more about TTFT and generation speed, while offline batch jobs care more about throughput. The optimization directions for these two scenarios are different, so you should not look at only one number.
Measurements should be taken under fixed conditions to avoid irreproducible results. The recommended measurement process is as follows:
For each configuration:1. Run 3 warm-up rounds and discard the results.2. Use a fixed prompt set with several short, medium, and long inputs.3. Record the time to first token, number of output tokens, and total time for each request.4. Compute the mean and P95 at concurrency 1, 4, and 8.5. Record peak VRAM and runtime version for reproducibility.
Performance can vary greatly across inference runtimes and hardware combinations, so it is not appropriate to directly apply someone else’s data. Measure on your own hardware and under realistic workloads.
5. Compatibility Issues: Chat Templates and Tokenizers
Many cases of “abnormal model output” originate in the runtime environment rather than the weights themselves. Common causes fall into the following four categories:
- Inconsistent chat templates. If the role markers used during training differ from the format assembled during inference, the model may treat system instructions as ordinary text or fail to stop properly at the end of a response.
- Incorrect special token and stop word configuration. The generation process may not terminate, or control markers may remain in the output.
- Tokenizer version mismatch. The same text is split differently, causing length calculation deviations and abnormal output.
- Tool-call format parsing failure. The structured content output by the model does not conform to the agreed JSON format, and the parser reports an error directly.
For troubleshooting, follow this order. First, confirm that the model weights, tokenizer, and chat template come from the same release version. Then use the reference examples provided by the model publisher to compare outputs for the same input. Finally, fix the random seed and sampling parameters, and eliminate variables one by one.
The output of tool calls should be structurally validated. Example:
```text
Input: user request + list of tool definitions
Expected output: parseable as {“name”: string, “ar…
