Local LLM Inference Speed: Benchmarking and Tuning Guide
This article explains why LLM inference speed must be discussed under explicit test conditions, breaks tokens/s into measurable prefill throughput, decode throughput, and first-token latency, and analyzes how context length, quantization precision, speculative decoding, and multimodal vision attachment affect performance. It also provides a benchmark script skeleton, a rough VRAM estimation formula, a bottleneck troubleshooting order, and general cloud deployment advice.
1. Why Speed Needs a Structured Discussion
When deploying large models locally, the question developers ask each other most often is about generation speed, measured in tokens per second. That number is almost meaningless without its test conditions. At least six variables determine throughput: model parameter count and activated parameter size, numerical precision and quantization scheme, context window occupancy, whether a multimodal vision encoder is enabled, whether speculative decoding is used, and the runtime’s batching and VRAM scheduling strategy.
The rule of thumb from the original discussion: on a certain inference runtime, using a flagship consumer GPU, loading a model quantized one-to-one from the official weights, with a large context window and both multi-token prediction and vision enabled, generation speed lands roughly in the 120–150 tokens/s range, which is broadly consistent with the runtime’s own claims. Abstracted into a more useful engineering judgment: as long as VRAM capacity is sufficient and memory bandwidth is not saturated, the extra overhead from long context and multimodal attachment erodes pure text decode speed only slightly. The real bottleneck is usually VRAM capacity and memory bandwidth.
2. Splitting tokens/s into Three Measurable Metrics
A blanket tokens/s figure mixes three different kinds of performance: prefill throughput, decode throughput, and end-to-end first-token latency. Measure them separately.
- Prefill throughput: tokens per second that can be processed for long inputs, mainly affected by compute and matrix-multiply efficiency.
- Decode throughput: speed of the autoregressive token-by-token generation stage, mainly affected by VRAM bandwidth and the number of weight bytes moved per step.
- First-token latency and streaming interval: these determine the interactive feel; with long contexts, first-token latency often matters more to experience than steady-state speed.
A reproducible benchmark script skeleton is below. Fix input and output lengths and take the median over multiple runs:
import time, statisticsdef bench(model, prompt_tokens, gen_tokens=256, repeats=3):samples = []for _ in range(repeats):# Warm up to avoid first-load and graph-build effectsmodel.generate(prompt_tokens, max_new_tokens=16)t0 = time.perf_counter()out = model.generate(prompt_tokens, max_new_tokens=gen_tokens)dt = time.perf_counter() - t0samples.append(gen_tokens / dt)return statistics.median(samples), outtps, _ = bench(model, prompt_tokens=[REDACTED], gen_tokens=256)print(f"decode tps ≈ {tps:.1f}")
3. How the Four Key Variables Work
3.1 Context Length
Context itself does not participate in a full per-token recomputation during decode, but the key-value cache grows linearly with length, consuming VRAM and increasing memory access per step. At context lengths in the hundreds of thousands of tokens, the cache can occupy several GB of VRAM; only when it approaches the capacity limit does the runtime frequently trigger cache eviction or chunked scheduling, and speed then drops noticeably. So “long context plus fast decode” holds only when there is VRAM headroom.
3.2 Quantization Precision
A quantization scheme that reproduces the official weights one-to-one aims to shrink weight size while losing as little output quality as possible. Weight quantization directly reduces the bytes moved per step, a linear gain for decode throughput; but if the quantization format lacks efficient operator support, dequantization overhead can offset part of the gain. The engineering recommendation: prefer bit widths that the runtime natively supports with mature kernels, rather than chasing lower bits blindly.
3.3 Multi-Token Prediction Speculative Decoding
Speculative decoding guesses several upcoming tokens in a lightweight way, then has the main model verify them in one pass; if accepted, multiple tokens are produced in a single step. Its benefit depends heavily on the draft hit rate: it speeds up structured, highly repetitive text noticeably, while on high-entropy creative text the gain narrows and it can even become slightly slower due to failed verification. When evaluating, record both the acceptance rate and the average accepted length.
3.4 Multimodal Vision Attachment
The vision encoder and projection layer only participate in prefill when image input is present, and barely participate in pure text decode. So attaching vision capability has little effect on steady-state decode speed; the main costs are resident VRAM usage and first-image prefill latency.
4. Estimating VRAM Capacity Quantitatively
Use a rough formula first to judge feasibility:
Weight VRAM ≈ parameter count × bytes per parameterCache VRAM ≈ 2 × layers × hidden dimension × context length × bytes per element × batch sizeTotal ≈ weight VRAM + cache VRAM + runtime and framework overhead (reserve 10%–20%)
If total usage exceeds available VRAM, discussing speed is pointless; lower the bit width, shorten the context, or reduce batch size first. If total usage stays below 70% of available capacity over time, there is headroom to try a larger context or higher concurrency.
5. Bottleneck Troubleshooting Order
- Confirm whether VRAM capacity is the limit, and watch for cache eviction.
- Confirm whether the decode stage is memory-bandwidth bound, and whether weight size and measured speed are inversely proportional.
- Check whether operators and kernels are taking the optimized path, avoiding fallback to generic implementations.
- Measure the speculative decoding acceptance rate and decide whether to keep the mechanism.
- Fix input and output lengths, close unrelated background processes, and take the median over multiple runs before comparing across configurations.
6. General Cloud Deployment Advice
If local GPU capacity is insufficient, move to cloud compute. In practice, model weights are usually placed on high-bandwidth storage, an inference service is launched through a container platform, monitoring and alerting collect throughput, latency, and VRAM watermarks, and a logging service retains benchmark and production sampling data, forming a “baseline–benchmark–regression” loop. Baidu AI Cloud’s general capabilities, such as its container platform, object storage, logging service, and monitoring and alerting, can carry this evaluation workflow and make speed data comparable across different configurations.
7. Conclusion
Speed is not an isolated number but the combined result of precision, context, acceleration mechanisms, and VRAM headroom. Only by measuring metrics separately, writing conditions clearly, and calculating capacity properly can tokens/s turn from a topic of comparison into a reproducible, regression-testable engineering baseline.
