Engineering Guide to Ultra-Fast LLM Inference

    This guide explains how to treat generation speed as a first-class selection criterion for large language models. It defines TTFT, per-request generation rate, and throughput, then covers the main factors that affect speed, a reproducible benchmarking method, scenario-based trade-offs, common cloud building blocks, and pitfalls to avoid.

    1. When Speed Becomes a First-Class Concern

    Over the past year, competition among large language models has shifted from “can it do the task” to “is it practical to use.” In real products, a capable model still fails the user experience if the first token takes seven or eight seconds, or if generating a short piece of code takes half a minute. Coding assistants lose their completion rhythm, multi-step tool calls in an AI agent stretch out, and conversational search or customer-support apps feel less fluent.

    Output speed is therefore no longer a side metric. It sits alongside capability and cost when choosing a model. In engineering discussions, however, “speed” is ambiguous. Before comparing systems, the metrics and their definitions have to be aligned. Otherwise, claims that a model is “unbelievably fast” are not comparable.

    2. Three Numbers, Three Meanings

    Time to first token (TTFT)

    TTFT is the time from sending a request to receiving the first token. It is driven mainly by the prefill stage, when the model reads the full prompt and runs the forward pass. Longer prompts and higher concurrency increase TTFT. Interactive applications are highly sensitive to it and usually aim for roughly one-second-level latency.

    Per-request generation rate (TPOT / ITL)

    After the first token, this is the average interval between tokens, often reported in tokens per second. It is determined by the decode stage: autoregressive, token-by-token generation. Memory bandwidth, KV cache size, and batching strategy have the largest effect.

    Overall throughput

    Throughput is the total number of tokens a service produces for all concurrent requests in a unit of time. It measures cluster efficiency and unit cost, and it often trades off against per-request speed. A larger batch raises total throughput but slows individual requests.

    A common mistake is to compare a community screenshot showing “thousands of tokens per second” with an official benchmark average. The former is often an ideal case: a short prompt, low concurrency, and resources dedicated to a single user. The latter is a statistical result under a standardized load test. They are not comparable.

    3. What Actually Determines Generation Speed

    • Model size and architecture. Parameter count, number of layers, and the attention implementation directly set the compute per step. Mixture-of-experts (MoE) models usually use less compute for the same number of active parameters.
    • Quantization and precision. Lower-bit quantization reduces memory use and bandwidth pressure, and it speeds up decoding in particular. Accuracy loss still has to be measured.
    • KV cache management. Paged caches and prefix caching can sharply cut prefill cost for repeated context. The gain is largest for fixed system prompts and long-document question answering.
    • Speculative decoding. A smaller model or a draft head proposes several tokens, and the main model verifies them in parallel. This can raise decode speed while preserving the output distribution.
    • Continuous batching and scheduling. Continuous batching lets new requests join without waiting for a whole batch to finish. The scheduler sets the balance between TTFT and throughput.
    • Kernels and runtime optimization. Fused operators, efficient attention kernels, graph capture, and compilation often deliver sizable, stable speedups.
    • Deployment topology. Whether the service runs in the same region as the inference engine, how many network hops are involved, and whether traffic crosses the public internet all show up in TTFT.

    4. How to Run a Trustworthy Benchmark

    Do not rely on unverified “leaked numbers” or screenshots from informal tests. A credible performance conclusion needs a reproducible experiment:

    1. Fix the variables. Hold the prompt-length distribution, maximum output length, temperature, and other sampling parameters constant.
    2. Sweep concurrency. Measure, for example, 1, 4, 8, 16, and 32 concurrent requests, and plot TTFT and generation rate against concurrency.
    3. Separate workloads. Report short Q&A, long-document summarization, and code generation separately. Do not mix them into one average.
    4. Repeat and report percentiles. Publish the median and P90/P99, not only the best run.
    5. Record quality at the same time. A speed gain that lowers usability is not an engineering win.

    The following is a schematic client-side skeleton. Names are generic, and the snippet is pseudocode:

    1. import time, statistics
    2. def bench(client, prompt, max_tokens=512, runs=5):
    3. ttft_list, tps_list = [], []
    4. for _ in range(runs):
    5. t0 = time.perf_counter()
    6. first = None
    7. n = 0
    8. for chunk in client.stream_chat(prompt, max_tokens=max_tokens):
    9. if first is None:
    10. first = time.perf_counter()
    11. n += count_tokens(chunk)
    12. total = time.perf_counter()
    13. ttft_list.append((first - t0) * 1000) # ms
    14. tps_list.append(n / (total - first)) # tokens/s
    15. return {
    16. "ttft_p50_ms": statistics.median(ttft_list),
    17. "tps_p50": statistics.median(tps_list),
    18. "tps_min": min(tps_list),
    19. }

    5. Scenario Trade-offs: Faster Is Not Always the Right Fit

    • Coding assistants and code completion. Both TTFT and generation rate matter. Context is often repeated project code, so prefix caching pays off strongly. A stable rate around 900 tokens per second is more valuable in production than an occasional peak. Variance matters more than the peak.
    • Agent orchestration. One task includes multiple model calls and tool executions. End-to-end latency is the sum of those stages, so TTFT and tool parallelism should come before the generation rate of any single stage.
    • Long documents and offline batches. Throughput comes first. Larger batches and a higher TTFT are acceptable when they lower cost.
    • High-value reasoning tasks. Spend the budget on capability. Speed is secondary.

    6. A Practical Combination of Cloud Capabilities

    A high-speed inference service in the cloud can be assembled from general-purpose building blocks: a container platform to run inference instances and scale them; object storage for model weights and datasets; a message queue to absorb bursts and decouple offline batch jobs; and logging plus monitoring and alerting to collect TTFT, generation rate, and error rate, and to alarm on thresholds. General cloud product categories from providers such as Baidu AI Cloud can cover these stages. Specifications and pricing should be taken from the official documentation.

    7. Three Pitfalls

    1. Treating community rumors as a selection basis. Data from unofficial channels lacks a defined methodology and should not be used for capacity planning.
    2. Looking only at the mean. Long-tail requests dominate perceived latency. P99 is the floor for an SLA.
    3. Treating speed and quality as opposites. Speculative decoding, quantization, and similar techniques should be accepted only if the output distribution and usability do not regress.

    8. Conclusion

    Claims of “unnaturally fast” models spread because they touch a real pain point. What engineering teams can actually rely on is a clear metric definition, a reproducible benchmark, an explicit scenario trade-off, and a complete observability setup. With that method in place, you can quickly judge whether a new model belongs in the production path, no matter how the underlying models change.