Local LLM Deployment: Tuning VRAM Usage and Inference Performance
Default parameters are rarely optimal when you move a locally deployed large language model from a quick test into production or long-term daily use. This article presents six practical tuning points for local inference on consumer GPUs with 8GB to 24GB of VRAM, covering both dense and Mixture-of-Experts (MoE) architectures. It starts with a static VRAM budget, then explains MoE expert-layer offloading, KV cache precision trade-offs, binary-search probing for the real context limit, parallel slot reduction for single-user workloads, and batch size benchmarking. It also covers context management for long conversations and ends with an executable tuning checklist. The goal is to turn hardware headroom into usable throughput by replacing guesswork with repeatable benchmarks.
1. Background: Running Is Not the Same as Running Well
Local deployment of large language models has become dramatically easier over the past two years. Inference runtimes have compressed “download weights, start a service, call an endpoint” into a handful of commands, so even non-specialists can have a conversational local model running within half an hour. Once you move into production or long-term personal use, however, a common problem appears: default parameters are almost never optimal.
Defaults are designed to start on as much hardware as possible, which makes them conservative, generic, and wasteful. A safe context length, a compatibility-friendly cache precision, parallel slots preset for concurrent users, and every expert layer loaded into VRAM may all be fine on a high-end multi-GPU server. On an 8GB to 24GB consumer GPU, the same choices can leave half the VRAM idle while the other half is used inefficiently, with several-fold differences in throughput.
This article uses a capable general-purpose LLM in two variants, dense and Mixture-of-Experts (MoE), to discuss six tuning points that are easy to overlook but deliver the most direct gains.
2. Build a VRAM Budget Before Touching Parameters
The first step is not changing parameters but accounting for VRAM. On a single GPU, VRAM is divided among four consumers:
- Model weights: roughly parameter count multiplied by bytes per parameter. An 8B model at 8-bit quantization takes about 8GB; 4-bit quantization can compress it to 4–5GB.
- KV cache: grows linearly with context length and often exceeds the weights themselves in long-context scenarios.
- Runtime activations and compute buffers: tied to batch size and sequence length, highly variable but not negligible.
- Framework overhead: CUDA context, VRAM fragmentation, communication buffers, typically a few hundred MB.
A practical approach is to do a static budget before launch and leave 10%–15% headroom:
available VRAM = total VRAM - system/display usage - safety marginrequired VRAM = weights + KV_cache(ctx) + activation buffers + framework overhead
If this inequality does not hold, every “speed-up trick” that follows is meaningless. Fit first, then go fast is the first principle of local inference tuning.
3. Mixture-of-Experts: The Offloading Strategy Decides Everything
MoE models have a very large total parameter count, but each token activates only a small subset of expert networks. This creates an important optimization opportunity: you do not need to put all expert weights in VRAM.
Consider a MoE model with 30B total parameters and 3B activated parameters on an 8GB GPU. Two strategies differ sharply:
| Strategy | VRAM usage | Measured throughput |
|---|---|---|
| All layers resident in VRAM | ~7.5GB (93%) | ~3 tok/s |
| Attention layers only in VRAM, expert layers in host memory | ~2.6GB (32%) | ~21 tok/s |
The second option saves about two-thirds of VRAM while improving throughput roughly 7-fold. The reason: attention layers participate in computation at every layer and are extremely bandwidth-sensitive, so they must stay in VRAM. Expert layers are sparse and activated on demand; most experts do not participate at all in the forward pass of a single token, so running them on the host CPU costs far less than the overflow and paging caused by cramming all weights into VRAM.
Three engineering steps are required:
- Identify tensor roles: weight names in inference frameworks usually carry semantic prefixes. Attention weights and expert weights (following a naming pattern like
ffn_.*_exps) can be distinguished this way, with the former marked GPU-resident and the latter marked offloadable. - Configure at layer granularity, not as a whole: offloading is a per-layer decision, not all-or-nothing.
- Validate with measurements: expert counts and routing activation ratios differ across models, so the optimal split point differs too and must be based on benchmark results.
Note that this capability is a general feature of low-level inference frameworks and is not exposed by every graphical tool, so manual configuration is often required.
4. KV Cache Precision: An Underrated Throughput Lever
KV cache VRAM usage can be estimated as:
KV_MB = 2 × layers × kv_heads × head_dim × ctx × bytes / 1024²
The factor 2 accounts for the K and V caches, and bytes is determined by cache precision. On the same 8GB GPU running an 8B dense model, different cache configurations perform roughly as follows:
| Cache configuration | Context/slots | Throughput |
|---|---|---|
| High precision + high precision, 4 slots | 8K | ~19 tok/s |
| 8-bit + 4-bit, 1 slot | 8K | ~38 tok/s |
| Half precision + half precision, 1 slot | 8K | ~52 tok/s |
| Half precision + half precision, 1 slot | 64K (auto-detected) | ~26 tok/s |
Three conclusions follow.
First, half precision is the best choice when it fits in VRAM, nearly 3 times faster than low-bit quantization. Low-bit quantization saves VRAM but adds dequantization compute overhead, which is not worth it when bandwidth is not the bottleneck.
Second, there is a clear trade-off between context length and throughput. Half precision reaches about 52 tok/s at 8K context but drops to about 26 tok/s at 64K, an inevitable result of linear cache growth.
Third, the correct decision order is “calculate first, downgrade later”: use the formula to compute half-precision cache usage at the target context, keep half precision if it fits, and only then step down to 8-bit and 4-bit, rather than starting with the most VRAM-efficient option.
5. Skip Formula-Based Prediction and Use Binary Probing for the Context Limit
Some community formulas claim to predict how much context the remaining VRAM can support after loading a model. The problem is that they are empirical models fitted at a specific cache precision; switching cache precision or architecture amplifies the error. In practice, a formula that predicted only 4K of context has coexisted with stable operation at 64K. Underestimating is harmful too, because it makes users give up more than half of the usable window.
A more reliable approach treats the inference service as a black box and binary-searches for the real limit:
upper = min(model native context length, 65536)lower = 4096repeat at most 5 times:mid = (upper + lower) / 2start the inference service with ctx=midif VRAM overflow: upper = midelse: lower = mid, record this configuration as the current bestreturn lower
This method relies on no theoretical model; the result is the combined ground truth of hardware, driver, framework version, and quantization format. Five iterations are enough to converge the error to within one part in a thousand, while starting an inference service typically costs seconds.
6. Parallel Slots: An Invisible Halving for Single Users
Most inference frameworks enable 4 parallel slots by default to support concurrent requests from multiple users. But KV cache in VRAM is partitioned per slot: 4 slots split the available context into 4 parts and also compress the batch size per slot.
For single-user interaction, reducing slots to 1 raised measured throughput from about 18.5 tok/s to about 38.2 tok/s, nearly doubling it. The reason is straightforward: in a single-request scenario, extra slots carry no load but keep consuming VRAM and scheduling overhead.
The decision rule is clear:
- Local single-user use, desktop assistants, single-machine agents → set slots to 1;
- Serving multiple terminals at once or running concurrency stress tests → set slots to the concurrency level and accept lower single-request throughput;
- When unsure, benchmark with
concurrency = 1as a baseline, then increase gradually and watch for the throughput inflection point.
7. Batch Size: Measurements Beat Theory
Two batch-related parameters, micro-batch size and batch size, determine how many tokens are sent to the compute units per scheduling round. Larger batches improve GPU utilization but consume more activation VRAM, with diminishing returns at long context.
Measured patterns:
- At 8K context: a larger micro-batch is about 7.6% faster than a smaller one;
- At 64K context: a larger micro-batch is about 21.6% faster.
In other words, the longer the context, the more benefit from increasing batch size, but there is no universal optimum across models and GPUs. The right approach is to treat it as a hyperparameter to benchmark: fix other settings, sweep two or three candidate values, and take the highest throughput. This sweep can be fully automated and costs far less than running long-term on a suboptimal configuration.
8. Long-Conversation Context Management: Do Not Let the Model Summarize Itself
The context window eventually fills up. A seemingly natural solution is to call the local model to summarize the conversation history near the limit, then continue with the compressed version. In practice this fails quickly: a single inference slot is blocking, so the summarization request competes with the main conversation request for the same execution queue. The main path waits for the summary while the summary is squeezed by the main path’s VRAM usage, ending in a timeout cascade.
Three more robust engineering options exist:
- Sliding window with fixed retention: keep only the most recent N turns verbatim and discard older content without semantic compression. Simplest to implement and predictable in behavior.
- Rule-based truncation: trim from the oldest messages by token count, preserving the system prompt and key structured information such as tool call results.
- Externalized memory: write history to local files or a vector store and retrieve relevant parts when needed, instead of stuffing everything into the context.
The core principle: context management should happen outside the inference service, handled by the application layer with deterministic logic, avoiding extra forward computation in the inference engine.
9. Putting It Together: An Actionable Tuning Checklist
Chaining the above into a workflow, a local model deployment can follow this order:
- Static budget: estimate weights, cache, activations, and framework overhead; confirm it fits.
- Architecture check: for MoE, first split off expert layers and pin attention layers in VRAM.
- Cache precision decision: compute half-precision cache usage at the target context; keep half precision if it fits, otherwise step down.
- Slot reduction: set slots to 1 for a single user.
- Context probing: binary-search the limit in at most 5 rounds and record the best value.
- Batch sweep: compare two or three micro-batch values at the probed context.
- Freeze the configuration: write final parameters into a startup script or config file under version control so defaults cannot overwrite them.
- Re-test continuously: after any driver, framework, or quantization format change, rerun steps 5 and 6.
10. Beyond Local: Dividing Work Between Local Inference and Cloud Services
Local deployment keeps data in-house, works offline, and has zero marginal cost; its weaknesses are limited VRAM, limited throughput, and no elasticity. A mature setup is usually hybrid: local handles sensitive data preprocessing, intent recognition, format conversion, and high-frequency lightweight tasks; heavy workloads such as complex reasoning, long-document analysis, and batch generation go to pay-as-you-go cloud inference services. The two sides are decoupled through a message queue, exchange large files via object storage, and are observed end to end with monitoring, alerting, and logging for latency and failure rate. General capabilities offered by Baidu AI Cloud in such hybrid architectures, including container platforms hosting inference services, object storage for models and datasets, and monitoring and alerting that covers latency metrics, can serve as a reference implementation path.
Conclusion
Performance gaps in local LLM deployment rarely come from the model itself; the vast majority come from parameter configuration. The VRAM budget determines feasibility, offloading strategy and cache precision determine throughput, slots and batch size determine stability, and “measure instead of guess” is the methodology throughout. Turn every tuning session into a repeatable benchmark script, and hardware gains can truly become a usable experience.
