Local LLM Inference Speed: Benchmarking and Optimization Guide

    This guide explains why tokens/s alone is an incomplete measure of local LLM performance, breaks speed into time-to-first-token (TTFT) and decode throughput (TPS), and walks through the main optimization levers: quantization formats, KV Cache sizing, speculative decoding, reasoning effort levels, and hardware memory bandwidth. It also includes a reproducible benchmark template and a practical tuning order for finding the right balance of speed, quality, and context capacity on existing hardware.

    1. Why “How Many Tokens/s?” Is Hard to Answer Directly

    When running large language models locally, the most common opening question is “What’s your generation speed?” The question itself lacks the necessary qualifiers, which makes answers hard to compare. To reach a meaningful conclusion, you need to state at least four things at once: model size and quantization format, context length, hardware platform and memory bandwidth, and the decoding strategy (whether speculative decoding is enabled, which reasoning effort level is used, and so on).

    Generation speed can be split into two completely different metrics. The first is time to first token (TTFT), which is mainly determined by the prefill stage and is strongly correlated with prompt length, batch size, and the attention implementation. The second is decode throughput (TPS), determined by token-by-token autoregressive generation and constrained mainly by VRAM bandwidth and weight-reading efficiency. The “tens of tps” people usually quote refers to the latter, while the interactive feel depends on both.

    The recommended measurement method: fix the prompt length and generation length, warm up for several rounds, take the median across multiple runs, and record VRAM usage and power draw at the same time.

    1. # Example: reproducible benchmark record template
    2. model = <model size>-<quantization format>
    3. ctx = 16384
    4. prompt_len = 512
    5. gen_len = 256
    6. ttft_ms = <time to first token>
    7. tps = <median decode throughput>
    8. vram_total = <VRAM usage>

    2. Quantization Formats: A Two-Way Trade-off Between Precision and Speed

    Quantization affects not only answer quality but also speed, because fewer bits mean less weight data to read. The industry’s commonly used Top-1 token agreement rate (the proportion of positions that match a high-precision reference output exactly) can serve as an engineering approximation:

    • 8-bit level: agreement rate around 99%, quality loss around 1%, effectively near-lossless;
    • 6-bit level: agreement rate around 98%, loss around 2%, a “near-lossless” compromise;
    • 4-bit level: agreement rate around 96%, loss around 4%, the mainstream choice for balancing speed and quality;
    • 3-bit level: agreement rate around 92%, loss around 8%, only marginally usable when VRAM is tight.

    It is worth stressing that a lower agreement rate does not mean “unusable,” but for tasks such as code comprehension, reconstructing obfuscated logic, and long-chain reasoning, errors from low bit widths get amplified along the reasoning chain. The practical recommendation: use 4-bit for interactive Q&A, and prefer 6-bit or higher when precise semantic reconstruction is involved.

    3. Context and KV Cache: The First Constraint in VRAM Planning

    The cost of long context comes mainly from the KV Cache, which grows roughly linearly with context length. For a 27B-class model, the KV Cache needs about 1GB of VRAM at 16K context and about 16GB at 256K context; with 8-bit quantization applied to the KV Cache, those requirements drop to roughly 0.5GB and 8GB.

    This gives the basic formula for capacity estimation:

    1. VRAM requirement ≈ weight size + KV Cache + runtime/compute buffers
    2. KV Cache ∝ layers × KV heads × head dimension × context length × number of sequences × bytes per element

    The engineering implication is straightforward: on a consumer GPU with 16GB of VRAM, running 4-bit weights while keeping tens of thousands of tokens of context is the comfort zone; to push context up to hundreds of thousands of tokens, you either quantize the KV Cache or move to a platform with more VRAM. In addition, disabling memory mapping and setting batch size and the number of concurrent sequences appropriately will all change actual peak usage, so measure rather than estimate.

    4. Decode Acceleration: Speculative Decoding and Reasoning Effort Levels

    Speculative decoding (a small model or an MTP-style draft head guesses several tokens first, then the large model verifies them in a batch) can significantly boost throughput in the bandwidth-bound decode stage. Its benefit depends on the draft hit rate: with a high hit rate it nearly doubles throughput, while with a low hit rate the verification overhead makes it slower instead. A common practice is to A/B test draft lengths between 1 and 3.

    Reasoning effort levels change the output length and therefore indirectly affect “effective speed.” Low levels suit structured, short-output tasks; high levels give better quality on complex reasoning but increase total time. When evaluating, distinguish between two perspectives: tokens per second and time to complete the task.

    5. Runtime and Hardware Platform: Bandwidth Sets the Ceiling

    The decode stage reads the entire set of weights for every token generated, so VRAM bandwidth is the theoretical ceiling. A 16GB consumer GPU with around 640GB/s of bandwidth reaching over 50 tps at 4-bit quantization is a reasonable range; a professional card with the same cores and bandwidth but double the VRAM offers advantages mainly in fitting larger models and longer contexts, not in raw speed.

    Integrated GPUs and unified-memory platforms are limited by memory bandwidth, and a 27B-class 4-bit model typically reaches only around 10 tps there. Since the graphics performance of integrated GPUs is close to that of some mobile SoCs, you can linearly extrapolate the relative throughput of multiple tiers by GPU scale (for example, on the order of 10/20/40/80 tps), but this is only an order-of-magnitude reference and real devices are the final word. If you use cloud compute, it is advisable to host the inference service on a general-purpose container platform or function compute, keep model weights in object storage, track latency and VRAM watermarks with monitoring and alerting services, and use the relevant general capabilities of Baidu AI Cloud to complete deployment and observability.

    6. A Practical Tuning Order

    1. First determine the task’s real needs for context and precision, then choose the quantization format, avoiding blindly chasing low bit widths;
    2. Fix the benchmark script and record four data points: TTFT, TPS, VRAM, and power;
    3. Enable attention optimizations, KV Cache quantization, and speculative decoding one at a time, changing only one thing and re-testing each time;
    4. Tune concurrency and batch size, and watch for the inflection points in throughput and latency;
    5. Only then consider switching hardware or adding VRAM, using the data above to validate the return on investment.

    With this workflow, most local deployment scenarios can find a reasonable balance of speed, quality, and context capacity on existing hardware.