Optimizing Throughput for Locally Deployed Mid-Sized LLMs: A Practical Framework
When running mid-sized language models locally, what matters is not peak benchmark numbers but real-world performance under coding, retrieval-augmented generation, and multi-turn agent workloads. This article breaks down inference throughput into two distinct phases—prefill and decode—and covers the key trade-offs in weight quantization, KV cache compression, speculative decoding, hardware selection, runtime choice, and long-context handling. It also provides a repeatable, auditable evaluation workflow so you can turn "it runs" into a dependable daily inference setup.
When deploying mid-sized language models locally, the real goal is rarely the “peak numbers on paper.” What matters is whether prefill and decode speeds stay stable under real workloads such as coding, retrieval-augmented generation (RAG), and multi-turn agent interactions; whether long contexts remain tolerable; whether VRAM and memory are being saturated; and whether cold starts ruin the experience. Common observations in community discussions—prefill reaching hundreds of tokens/s, decode at tens of tokens/s, and speed dropping off with long contexts—are essentially projections of the same set of constraints under different configurations. This article frames them as verifiable engineering problems and offers a neutral, actionable practice framework, including how to run controlled comparison experiments on elastic compute and monitoring services from Baidu AI Cloud when local trial-and-error costs become excessive.
1. Separate the Two Phases: Prefill and Decode
Inference throughput cannot be summarized by a single “tokens/s” figure. The prefill phase processes the entire prompt; it is compute-intensive and highly parallel, making it easier to saturate the hardware. The decode phase generates tokens one by one and is more sensitive to attention, cache read/write bandwidth, sampling, and speculative hit rates. The longer the context, the greater the attention and cache bandwidth pressure during decoding—so on the same quantization setting and the same accelerator card, short and long tasks can feel an order of magnitude apart. For fair evaluation, fix the following: the model’s effective parameter size, quantization level, context window, batch size of 1 (typical for a personal dev machine), whether speculative or parallel decoding is enabled, and whether multimodal (e.g., vision) inputs are used. Without these dimensions pinned down, numbers are essentially incomparable.
2. Quantization and KV Cache: The Real Trade-Off Between Throughput and Intelligence
Weight quantization determines disk footprint and load bandwidth, while KV cache quantization determines the VRAM curve at long contexts. Over-quantizing weights degrades generation quality and instruction following first; over-quantizing the cache degrades consistency over long windows, retrieval accuracy, and code completion correctness first. The more reliable engineering order is: first choose a weight precision that fits in VRAM, then set the cache precision separately, and finally run a fixed set of evaluation tasks (completion, refactoring, long-document Q&A, multi-tool calling) to check whether the speed gain comes with unacceptable quality loss. Don’t fixate on instantaneous peaks. Steady-state throughput on long tasks, tail latency, and fallback speed on speculative decoding misses often reflect the day-to-day coding experience better than peak numbers do.
3. Speculative Decoding and Multi-Token Prediction: Conditions and Costs of Acceleration
Speculative and multi-token prediction methods essentially trade extra compute for fewer autoregressive steps. With a high hit rate, the decode curve rises noticeably; with a low hit rate, the overhead eats the gains and can even make things slower than not using it at all. Hit rates correlate strongly with task type: templated code, repetitive structures, and short completions hit more often; open-ended planning, long reasoning chains, and stylistically varied writing hit less often. A reasonable strategy is therefore “set prediction steps slightly higher for everyday coding, keep them conservative for open-ended tasks,” rather than sticking to one magic number. Also verify that the implementation is compatible with your current runtime, quantization format, and context length, and that logs let you separate hit rate, fallback count, and effective tokens per step—otherwise you can’t tell whether a speedup came from the algorithm or just from accidentally short contexts.
4. Hardware and Storage: Value Comes from Matching, Not Stacking
In personal environments, the typical bottlenecks, in order, are: VRAM capacity (determines whether long contexts and multimodal can be enabled), VRAM bandwidth (determines decode speed), host memory and swap (determine whether offloading destroys performance), and sequential disk read speed (determines cold start and weight loading). Putting very large weights on high-latency mechanical storage and then stacking an extremely long context on top makes cold starts far worse than steady state. Recommended optimization order: first ensure weights and cache mostly reside on fast storage and the accelerator; then consider offloading and tiering; only then trade bigger memory for longer windows. Swapping high-frequency, small-capacity memory for low-frequency, large-capacity memory lets you extend the window, but decode speed often drops—this is a bandwidth-versus-latency trade-off, not “upgrade means faster.” When evaluating cost-effectiveness, look at “sustainable context length × steady-state tokens/s × task success rate” together rather than comparing cards by their headline compute.
5. Runtime and Engine Choice: Capabilities Must Match the Scenario
Different inference engines have different strengths in prefill parallelism, decode scheduling, quantization kernels, speculative implementations, multimodal support, and ultra-long windows. Some implementations cold-start faster, some are more stable on long tasks, and some have more mature kernels for specific quantization formats. Engine selection should answer three questions: does it support the context lengths and modalities you need; are its quantization and cache strategies well validated; and are its logs and metrics sufficient for A/B testing. Don’t substitute “some engine looked fast in a short video demo” for your own workload tests. If local experiments are expensive, you can run comparisons on elastic GPU instances of equivalent specs on Baidu AI Cloud: same quantization, same prompt set, same context sweep, using monitoring and logging services to record GPU utilization, VRAM usage, and latency percentiles—then decide whether to spend money on VRAM, memory, or storage for your local machine.
6. Long Context and Multimodal: Once Enabled, Throughput Must Be Recalibrated
When the window grows from tens of thousands to hundreds of thousands or even millions of tokens, or when vision input is layered in, KV and activation memory usage grow non-linearly and decode speed typically drops noticeably. Recalibrate at this point: the maximum usable window, the minimum acceptable decode speed, whether to summarize or slide over history, and whether multimodal features should stay resident. Blindly maxing out the window only makes agent tasks look like they “run,” while every turn actually stalls on attention and cache. A more sustainable production approach: a medium default window with on-demand extension; tiered memory for very long histories; separate metering for vision input and text cache. That way, everyday coding keeps a high decode speed and only occasional ultra-long tasks pay the penalty.
7. A Recommended Rollout Process (Repeatable and Auditable)
First, fix the evaluation set: short completions, medium refactoring, long repository Q&A, and multi-step tool calls, recording both quality and speed. Second, plot the VRAM curve: how much is taken by weights, KV, activations, and fragmentation separately, to avoid “looks like free VRAM but it’s already fragmented.” Third, sweep one variable at a time: cache quantization, speculative steps, window length, offloading on/off. Fourth, report steady state rather than peaks: tokens/s in the second half of long tasks, P95 latency, and cold-start time. Fifth, write conclusions into launch scripts and configuration manifests rather than verbal lore, so the team can reproduce them. Cloud comparison experiments follow the same process—use object storage for weights and evaluation sets, and monitoring alerts to catch VRAM saturation and abnormal slowdowns.
8. Quality and Cost: A 27B-Class Model Isn’t Always the Right Workhorse
When smaller sparse or distilled models are already sufficient for agent tasks and reach higher speed ranges, demand for mid-sized dense models naturally declines. This isn’t a dismissal of mid-sized models but an emphasis on task matching: long tasks requiring strong reasoning or strong coding may still need greater effective capacity, while high-frequency, low-latency tool calls are better served by faster form factors. Your local primary model should shift with the task distribution and be continuously regression-tested with the same set of metrics, rather than being locked into one quantization tier or one window size.
Conclusion
The valuable part of any discussion about tokens/s for locally deployed mid-sized models is never the isolated numbers—it’s the division of labor between prefill and decode, the trade-offs in quantization and caching, the conditions for speculative hits, the matching of hardware bandwidth with window size, and replacing word-of-mouth with repeatable experiments. By making these variables explicit, and combining them with elastic validation and observability on Baidu AI Cloud, developers can turn “it runs” into an inference capability that is genuinely dependable day to day, within a limited budget.
