Local LLM Inference Under Limited GPU Memory: Quantization and Tuning Practices
This article explains how to run large language model inference locally when GPU memory is limited. It covers the trade-off between memory usage and accuracy, practical use of 8-bit and 4-bit quantization, KV cache budgeting, context slots and concurrency planning, prefill versus decode performance, lightweight co-located guard models, MoE architectures, tool-call reliability for agents, model selection, and when to move workloads to the cloud.
1. Why run local inference on constrained hardware
Before discussing optimization techniques, it is useful to clarify why many teams choose to deploy LLM inference locally on owned or older hardware. The main motivations are usually:
- Cost control: Long-term inference on rented high-end accelerators can be expensive, while existing GPUs—including former data-center GPUs and consumer-grade GPUs—can be reused.
- Data sovereignty and privacy: Sensitive data can remain inside the local data center.
- Offline and edge scenarios: When network connectivity is limited, local inference may be the only viable option.
- Controllability: The team retains full control over weights, quantization, and context strategies.
In these scenarios, the central tension is between limited GPU memory and compute on one side, and the growing demands of larger models and longer contexts on the other. Most of the optimization techniques below are ways to balance that tension.
2. Quantization: the first trade-off between GPU memory and accuracy
GPU memory usage can be roughly divided into two parts: weight storage and KV cache storage. Weight storage can be approximated as:
weight GPU memory ≈ number of parameters (P) × bytes per parameter (b)
At FP16, b is about 2. For 8-bit integer quantization, commonly referred to as W8A16-type schemes, b is about 1. At 4-bit quantization, b is about 0.5. Therefore, moving from FP16 to 8-bit quantization roughly halves weight memory, while the accuracy loss is nearly negligible on many general-purpose tasks. This is why 8-bit quantization is a common starting point in resource-constrained environments. If GPU memory is even more limited, teams may go down to 4-bit quantization, but they should evaluate its impact on long-context retention and structured-output compliance.
One important point should be emphasized: quantization saves weight memory, not KV cache memory. In long-context scenarios, the KV cache is often the main source of GPU memory consumption. It grows roughly linearly with sequence length and is related to concurrency. In other words, how long a context you can enable and how many concurrent requests you can support depend heavily on how much memory you reserve for the KV cache.
3. Planning long context and concurrency slots
Many inference frameworks support dividing the total context into multiple “slots” and using multiple slots to serve concurrent sessions. The relationship can be understood conceptually as:
total context budget ≈ number of slots × usable context length per slot
There is a direct trade-off here: more slots mean stronger concurrency, but each request receives a shorter context; fewer slots mean longer context per request, but lower concurrency. Two practical points are worth emphasizing.
First, context length is not free. It directly increases KV cache usage. Blindly maximizing the total context window often reduces concurrency or causes GPU memory overflow.
Second, for agent applications, the initialization phase often needs to include a large amount of system prompts, tool definitions, and historical messages, sometimes reaching tens of thousands of tokens. This requires each slot to have sufficiently long and stable context capacity while maintaining low first-token latency.
The following illustrative configuration is pseudocode and only shows parameter relationships. It does not refer to any specific product:
context_slots: 3 # Number of concurrent slotsmax_context_per_slot: 262144 # Maximum context length per slotquantization: w8a16 # 8-bit integer quantization for weightsgpu_memory_budget_mb: 61000 # Available GPU memory budget per cardreserve_for_kv_cache: true # Explicitly reserve space for the KV cache
4. Understand prefill and decode: throughput and latency should be evaluated separately
One of the most common misunderstandings in inference performance is treating “token output speed” as the only metric. In reality, a request has two phases:
- Prefill (prompt processing): The input prompt is processed in parallel. This phase is compute-intensive and highly parallelizable, so it can achieve high throughput when handling long prompts, and users may barely notice the waiting.
- Decode (token-by-token generation): Tokens are generated one by one in an autoregressive manner. This phase is memory-access-intensive and serial, and is usually the real bottleneck. It determines the steady-state token generation speed.
This explains a common phenomenon: initializing a long context can achieve high throughput during prefill, but the generation phase may show a clear drop in speed. Common ways to optimize decode include improving batching efficiency, reusing the KV cache, and using architectures with fewer activated parameters to reduce computation per token. When evaluating a deployment plan, teams should record prefill throughput and decode steady-state speed separately, rather than summarizing performance as simply “fast”.
5. Co-locating multiple models: main model plus lightweight guard model
If there is spare GPU memory after quantizing the main model, a practical approach is to use the remaining memory to co-locate a lightweight model for tasks such as heartbeats, health checks, simple routing, or background guard duties. This enables tiered scheduling: less critical, less latency-sensitive work can be removed from the main path, allowing the main model to focus on high-value requests. When budgeting GPU memory, it is important to leave a safety margin so that the main and auxiliary models do not compete for memory and cause either model to be swapped out.
6. The value of MoE architectures on constrained hardware
Mixture-of-Experts (MoE) architectures, which have become popular in recent years, have a feature that is very friendly to constrained hardware: the total number of parameters is very large, but each token only activates a subset of experts. Because computation is determined by activated parameters, these models can maintain strong capabilities while often achieving better decode speed than dense models of comparable scale.
However, there is a trade-off: although compute is based on activated parameters, GPU memory still needs to hold all expert weights. Therefore, choosing an MoE model on constrained hardware is essentially trading larger GPU memory usage for faster and more compute-efficient inference. Whether this is worthwhile depends on whether GPU memory is sufficient.
7. The real threshold for agent scenarios: tool-call reliability
Many teams underestimate this point: in agent scenarios, whether a model can stably output strictly compliant structured calls—such as function/tool call names, parameters, and JSON formatting—is often more important than benchmark scores. A single formatting error can interrupt an entire automation workflow or cause a retry loop. Different models differ significantly in how well they follow structured-output requirements and tool schemas. Therefore, the first priority during model selection should be measuring tool-call success rate on your own tool set, not relying on general leaderboards.
Evaluation should cover at least:
- Single-tool call correctness
- Multi-tool selection accuracy
- Parameter completeness
- Stability under long context, especially when many tool definitions are included
8. Model selection is dynamic, not a one-time decision
Open-source models iterate quickly. Today’s best choice may be fully surpassed by new models within a few months. The observation that a new model release can quickly overshadow older models supports this point. A rational approach is to build your own evaluation baseline: create a fixed set of small regression tests covering tool-call success rate, long-context information retention, prefill/decode speed, and peak GPU memory, and run them quickly whenever considering a model switch. Decisions should be based on data rather than impressions. This allows teams to validate new models at low cost and avoid blindly chasing new models when the current solution is still sufficient.
9. Practical checklist
- Budget GPU memory first: List weights, KV cache, guard models, and safety margins clearly before deciding on quantization precision and context length.
- Start quantization at 8-bit: Accuracy loss is small and GPU memory usage is roughly halved. If memory is tight, move to 4-bit quantization and perform regression validation.
- Split context and concurrency by business needs: Determine how much context a single request needs and how many concurrent requests are required, then plan slots accordingly.
- Evaluate performance by phase: Monitor prefill throughput and decode steady-state speed separately. Do not summarize everything with one number.
- Keep guard and monitoring capabilities in place: Use a lightweight model or sidecar process for health checks so that failures in the main path can be detected quickly.
- Use evaluation to drive model selection: Prioritize tool-call success rate and maintain a repeatable regression test set.
10. When local resources are insufficient
If owned hardware truly cannot meet requirements for long context, high concurrency, or stability, some workloads can be moved to the cloud. General options include cloud GPU compute, containerized deployment, and model hosting or inference services. For example, cloud providers such as Baidu AI Cloud offer general-purpose infrastructure that can scale elastically and complement local deployment: local systems can handle sensitive and always-on workloads, while the cloud can take peak and heavy workloads. Regardless of whether the deployment is local or cloud-based, the same methodology applies: quantization, context planning, phase-based performance evaluation, and tool-call testing.
