A Practical Guide to On-Device LLM Local Inference
This article explains how to run large language models locally on edge devices, covering why on-device inference is gaining attention, how to estimate memory budgets, how quantization and model formats affect the quality-size-speed tradeoff, and how to design reproducible benchmarks across three configurations. It also outlines the limits of dense models, sparse expert models, speculative decoding, and multi-token prediction, plus reusable evaluation practices for long-term stability testing.
1. Why On-Device Local Inference Is Back in Focus
Over the past two years, LLM capabilities have improved rapidly, but most inference still happens in remote data centers. Moving inference onto local devices is driven by three main factors: compliance and privacy requirements that keep data on the device, cost structures under sustained high-frequency usage, and availability in offline environments.
On-device inference is not simply “a smaller version of the cloud.” It is a rebalancing of engineering constraints—compute, memory bandwidth, power, and thermal limits are all fixed, so every configuration decision directly affects throughput and latency.
The first thing to understand is that the performance bottleneck in local inference is usually memory bandwidth, not compute. Autoregressive decoding reads the entire set of model weights for every token generated, so decoding speed is roughly proportional to “memory bandwidth / model size.” This explains why platforms with a unified memory architecture tend to perform relatively better with large models: the CPU and graphics compute units share the same high-bandwidth memory pool, avoiding repeated data transfers between dedicated VRAM and system memory.
2. Hardware and Memory Budget: Calculate Before You Start
Capacity estimation is mandatory before benchmarking. For a 7B-class model with 4-bit quantization, weights take roughly 4GB; a 30B-class MoE model at 4-bit takes about 16–18GB; dense models with tens of billions of parameters quickly exceed the memory limits of most edge devices. Use the following rough formulas for planning:
Weight footprint ≈ parameter count × bytes per parameterKV Cache ≈ 2 × layers × KV heads × head dimension × context length × precision bytes × concurrencyMinimum memory ≈ weight footprint + KV Cache + runtime overhead (about 10%–20%)
The value of the MoE architecture also becomes clear here: total parameter count determines memory usage, while activated parameter count determines the compute for a single forward pass. On memory-constrained edge devices, MoE can trade acceptable compute cost for stronger representational capacity.
3. Model Formats and Quantization: The Triangle of Precision, Size, and Speed
The mainstream approach to local deployment is to use a weight format like GGUF, which supports incremental loading and mixed quantization, together with a llama.cpp-style inference runtime. Quantization is not a single tier. Common choices include:
- Q4_K_M: the balance point between size and quality, the default first choice on-device;
- Q5_K_M / Q6_K: quality-first, used when the memory budget is sufficient;
- Q2_K and IQ-series low-bit: extreme compression with noticeable quality degradation, suitable only for feasibility validation.
Key reminder: quantization amplifies the accumulation of attention errors under long contexts, so benchmarks must fix the same quantization tier before comparing solutions horizontally; otherwise the conclusions are not trustworthy.
4. Benchmark Design for Three Configurations
This evaluation uses a local inference runtime as the common foundation. Model files are downloaded offline in advance and verified for integrity, so network fluctuations are not counted in the timing. The three configurations are: a dense model baseline, a sparse expert model paired with a speculative decoding draft scheme, and another new-architecture model paired with multi-token prediction. The metrics are fixed as: first-token latency, decoding throughput (tokens/s), peak VRAM/memory under long contexts, and spot checks of output quality.
# Example: fixed parameters to ensure comparability./infer -m model-a-q4_k_m.gguf -c 8192 -t 8 -ngl 99 --repeat-penalty 1.05 -p "Explain the difference between MoE and dense models"./infer -m model-b-q4_k_m.gguf -c 8192 -t 8 -ngl 99 --spec-draft draft.gguf./infer -m model-c-q4_k_m.gguf -c 8192 -t 8 -ngl 99 --mtp 2
5. Interpreting Results: Where Each Acceleration Approach Fits
The dense model baseline is the easiest to deploy and behaves predictably, making it a good reference. The sparse expert model has fewer activated parameters and decodes faster, but demands more memory capacity, and expert routing may be unstable with short prompts. Speculative decoding (a small model drafts, then the large model verifies in batches) and multi-token prediction belong to the same family of ideas—verifying multiple candidate tokens in a single forward pass. They deliver clear gains in batch generation and structured output, but the gains shrink on high-entropy creative tasks because the draft hit rate drops.
Three engineering points also matter: context length directly inflates the KV Cache, so long-document scenarios need headroom; offloading all compute layers to the graphics unit is not always optimal, and keeping some layers on the CPU is sometimes more stable; and sustained inference causes thermal throttling, so short-term peak numbers do not represent the real level of long-running service.
6. A Reusable Evaluation Methodology
It is advisable to turn evaluation into a scripted pipeline: fix the random seed and prompt set, repeat each configuration three times and take the median, record memory peaks and temperature, and write raw logs to object storage, combined with monitoring alerts and log services for long-term trend observation. If you later migrate to the cloud for hybrid inference, a container platform plus a message queue is enough to handle batch processing and elastic scaling, with no changes to the upper-layer application.
Overall, tuning on-device local inference is essentially a joint optimization of the “memory budget—quantization tier—acceleration strategy” triangle. Estimate quantization first, then validate on a small sample, and only then run long-duration stability tests. This path also applies in engineering practice around Baidu AI Cloud and can help teams reach trustworthy conclusions with lower trial-and-error cost.
