GPU-Only Local LLM Inference: A Practical Configuration Guide
This article explains why local LLM inference often falls back to CPU even when a dedicated GPU is available, and how to enforce GPU-only execution. It covers baseline diagnostics, VRAM estimation, hard offload limits, device isolation, quantization trade-offs, context length, batching, multi-GPU parallelism, observability, and common mistakes. Readers will learn a complete workflow for making local inference predictable and operable.
GPU-Only Local LLM Inference: A Practical Configuration Guide
1. The Root Cause: Why Inference Processes Secretly Use the CPU
When deploying large language models locally, a common complaint is that “even with a dedicated GPU, CPU usage spikes during inference and throughput stays low.” Solving this requires understanding the layered execution model of inference engines.
Mainstream local inference implementations (typically GGUF-format models paired with a C/C++ inference backend) split model weights and the KV cache into layers, then assign runnable layers to underlying compute devices at runtime. Three factors determine where a tensor lands:
- Device capability: whether the remaining VRAM can hold the layer’s weights and its corresponding cache;
- Backend availability: whether the vendor’s acceleration library is compiled into the binary and the driver is ready;
- Runtime parameters: context length, batch size, parallelism, the upper limit of offloaded layers, and so on.
If any one of these conditions is unmet, the engine falls back to host memory for the excess layers and computes them on the CPU. This is the root cause of “the GPU is working, but the CPU is also working hard”—it is not a bug, but a degradation strategy when VRAM is insufficient.
Therefore, “using only the GPU” is, in engineering terms, equivalent to one statement: make all computable layers fit in VRAM and prohibit any fallback.
2. Run Quantitative Diagnostics Before Changing Configuration
Blindly tweaking parameters is inefficient. Collect baseline data in the following order.
First, confirm that the acceleration backend is actually available. Most distributions provide device enumeration; the output must show the GPU model and total VRAM. If it is empty, the driver or acceleration library is missing, and all subsequent parameters are meaningless.
Second, estimate VRAM requirements. A practical approximation:
VRAM demand ≈ weight size + KV cache + compute buffer + safety marginweight size ≈ parameter count × bytes per parameter (e.g., ~1 byte/param at 8-bit)KV cache ≈ 2 × num layers × hidden dim × context length × batch size × bytes per elementcompute buffer ≈ hundreds of MB, increasing with batch sizesafety margin ≈ 10%~15% of total VRAM
Plug in the actual numbers and compare against total VRAM. If demand exceeds capacity, reduce context length and batch size first rather than precision—precision usually has a more direct impact on output quality.
Third, observe at runtime. Common general-purpose methods include the GPU vendor’s command-line query tool, system-level process monitoring, and the metrics endpoint exposed by the inference service itself. Watch three curves: whether VRAM usage stays stable near full capacity, whether GPU utilization stays high during the decode phase, and whether host memory and CPU usage remain persistently high.
3. Core Configuration Strategies for GPU Exclusivity
3.1 Disable Automatic Fallback and Set a Hard Offload Limit
Most inference backends allow explicitly specifying the “number of layers to place on the GPU.” Setting it to the model’s total layer count is a forcing measure: if VRAM is insufficient, the process errors out directly instead of silently degrading. This “fail fast” behavior is very valuable during capacity planning.
# Example: offload all layers to GPU, tighten context and batch size as neededrun-model \--model /models/your-model.gguf \--n-gpu-layers 999 \--ctx-size 4096 \--batch-size 256 \--threads 4
Note that --threads only affects CPU-side operators; in pure GPU mode it should stay low to avoid thread contention slowing down host-side scheduling.
3.2 Use Device Visibility for Physical Isolation
On a shared server, a more thorough approach is to make the process unable to see other devices at all. Restricting the enumerable acceleration devices via device visibility environment variables pins a process to a specific GPU:
export GPU_VISIBLE_DEVICES=1export ACCELERATOR_VISIBLE_DEVICES=1
This avoids multiple processes competing for VRAM and makes per-card quotas and cost accounting easier. When deploying with a container platform, writing the visibility declaration into the container orchestration’s resource requests achieves exclusivity at the scheduling level.
3.3 Precision and Quantization: Balancing Quality and Capacity
Quantization is the most effective knob for the VRAM budget. General rules of thumb:
- 8-bit quantization usually preserves near-original precision, with VRAM about half of half precision;
- 4-bit quantization uses less VRAM and suits consumer GPUs, but has a more noticeable impact on long-text inference and code generation quality;
- Keep KV cache precision consistent with weight precision to avoid the structural waste of “weights compressed very low while the cache eats up VRAM.”
3.4 Context Length: The Most Overlooked VRAM Black Hole
The KV cache grows linearly with context. Raising context from 2K to 32K can grow the cache portion more than tenfold, far exceeding the weights themselves. In production, set the limit according to the real business distribution rather than maxing it out by default; for long-document scenarios, segmented summarization or retrieval augmentation is more economical than simply extending context.
3.5 Concurrency and Batching
Batching improves throughput but also amplifies compute buffer and cache usage. When occupying a single card exclusively, use load testing to find the maximum batch size at which VRAM does not overflow, and set a request queue limit to prevent burst traffic from pushing the process into degradation or a crash.
4. Multi-GPU Scenarios: Parallelism Determines the Granularity of Exclusivity
With multiple GPUs, there are two typical partitioning approaches: intra-layer partitioning (tensor parallelism) involves frequent communication and is sensitive to interconnect bandwidth, making it suitable for servers with high-bandwidth interconnects; inter-layer partitioning (pipeline-style) is simple to implement with little communication, making it suitable for consumer multi-GPU setups. If the goal is “every card is fully utilized without overstepping,” inter-layer partitioning is easier to tune—just ensure the layers assigned to each card match its VRAM.
A practical checklist:
- Is VRAM usage balanced across cards, or is one card near overflow while another sits largely idle?
- Is the inter-card interconnect bandwidth a bottleneck, showing up as fluctuating utilization?
- Is any process unknowingly occupying a card that should be idle?
5. Observability and Long-Term Stability
A one-time successful configuration does not equal long-term stability. Wire three types of signals into logging and alerting:
- Alert when VRAM headroom drops below a threshold (e.g., less than 10% remaining)—this is a precursor to degradation;
- Alert when GPU utilization during decode stays persistently below expectations—this usually means it is still running on the CPU;
- Alert on sudden spikes in request latency and queue length—used to identify overly aggressive batch size settings.
Also retain the device enumeration and layer assignment records from the startup log; they are first-hand evidence for diagnosing “why it got slow” after the fact.
6. Common Mistakes
- Looking only at average GPU utilization: decode is memory-access intensive with large instantaneous fluctuations, so look at the distribution rather than the mean;
- Assuming “if VRAM isn’t full, everything must be on the GPU”: some backends reserve buffers, so confirm with the layer assignment log;
- Pursuing exclusivity when multiple processes share one card: VRAM is a hard constraint, and oversubscription inevitably causes random degradation;
- Increasing thread count to speed up GPU inference: wrong direction—it only adds host-side overhead.
7. The Cloud Equivalent
If local GPU resources are insufficient, the same logic can be migrated to the cloud: use a container platform with dedicated accelerator instances to host the inference service, declaring resource requests to achieve whole-card exclusivity; distribute model files and versions with object storage; and use logging and alerting to support the observability described above. Baidu AI Cloud typically provides a combination of general-purpose capabilities in such scenarios (container platform, object storage, logging, alerting) to support this, with specific specs and quotas subject to the official documentation.
Conclusion
“Making inference use only the GPU” is not a single switch, but a complete chain from quantitative diagnostics and capacity planning to parameter constraints and observability. There are only two core principles: first account for VRAM accurately, then prohibit all silent degradation. Meeting both is what makes local inference performance predictable and operable.
