LLM Inference Optimization: From Brute-Force Compute to System-Level Engineering

    Large language model inference speed has evolved from a demo metric into a production requirement. This article explains why the same model can deliver vastly different tokens/s depending on deployment, breaks down the key metrics—TTFT, TPOT, throughput, and P99 latency—and examines optimization across four layers: model, inference system, parallelism topology, and hardware. It also covers benchmarking, observability, and capacity planning practices, with a framework-agnostic pseudocode example for scheduling and benchmarking.

    1. The Key Shift in the Second Half: Speed Is Now a Production Metric

    Early competition among large language models centered on parameter counts, knowledge coverage, and benchmark scores—essentially, “can the model do it?” In the second half of the race, the question becomes “can the model do it stably, cheaply, and with low latency?” As capability gaps between models narrow, inference speed, time-to-first-token, per-request cost, and concurrency capacity directly determine product experience and commercial viability. A slow model, even with higher answer quality, struggles to fit into real-time interactive scenarios such as search, customer support, coding assistance, and content generation.

    As a result, “tokens per second” is no longer just a showcase number—it is a core metric that connects user experience, compute cost, and system architecture. In public practice, order-of-magnitude differences across deployment setups for the same model are not uncommon: some setups deliver only tens of tokens/s on a single stream, while specially optimized inference systems can reach hundreds or even thousands of tokens/s. This shows that speed is not an inherent property of model weights alone, but the combined result of model architecture, inference system, hardware resources, and deployment strategy.

    2. First, Define “Fast”: Single-Stream Speed, Throughput, and Latency Are Not the Same

    Before discussing inference speed, several frequently conflated metrics must be distinguished:

    • Single-stream output speed: tokens generated per second for a single request—this shapes the user’s perceived “typing speed.”
    • Time to first token (TTFT): the time from sending a request to receiving the first token, determining whether interactions feel responsive.
    • Time per output token (TPOT): the average interval between adjacent tokens during generation, affecting the fluency of long-form output.
    • System throughput: total tokens or requests completed per unit of time, which determines cost per unit of compute.
    • P99 latency: the high-percentile latency, which determines worst-case user experience and timeout risk in production.

    These metrics involve trade-offs. Increasing batch size improves throughput but can raise per-stream latency; aggressive quantization reduces memory footprint and compute but may hurt quality; running more replicas reduces queuing delay but increases resource cost. A production system should not chase a single peak number, but instead find the balance among throughput, latency, and cost under SLO constraints.

    3. Why the Same Model Gets Faster with a Different Deployment: A Four-Layer View

    Differences in inference speed typically come from coordinated optimization across four layers.

    1. Model layer: eliminate wasted computation

    Model-layer optimizations include sparsification, quantization, distillation, speculative decoding, and structured output. Sparsification activates only a subset of parameters per forward pass, reducing compute; quantization compresses weights or activations from high precision to low precision, easing memory bandwidth pressure; speculative decoding uses a smaller or faster draft model to guess multiple tokens, which the target model then verifies in parallel, reducing serial generation steps; structured output constrains decoding to cut invalid candidates. The common goal is to reduce the compute and memory access required per token without significantly degrading quality.

    2. Inference system layer: keep the hardware busy

    The inference system handles request scheduling, batching, KV cache management, and memory allocation. Continuous batching lets new requests join dynamically while others are still generating, avoiding the idle waste of traditional static batching; paged KV cache management reduces fragmentation in long-context scenarios; prefix caching reuses computation for shared system prompts or common context; sensible preemption and rescheduling policies prevent long requests from monopolizing resources. System-layer optimizations often leave model weights untouched yet deliver significant speedups.

    3. Parallelism and deployment topology layer: match the model to the right resource mix

    When a large model doesn’t fit on a single GPU, tensor parallelism, pipeline parallelism, or expert parallelism is required. Tensor parallelism splits a single layer’s computation across devices, pipeline parallelism assigns different layers to different devices, and expert parallelism routes work for sparse expert architectures. Higher parallelism means higher communication overhead, so deployment topology must match the hardware’s interconnect capability. In addition, multiple replicas, dynamic routing, tiering of hot and cold models, and edge/cloud co-deployment all affect end-to-end speed.

    4. Hardware and compilation layer: reduce data movement and startup overhead

    Operator fusion, graph optimization, memory reuse, asynchronous copies, and compile-time code generation reduce kernel launches and memory transfers. For autoregressive generation, memory bandwidth and high-speed interconnects often matter more than peak compute. Inference services must also watch CPU-side preprocessing, network transfer, serialization, and queuing time, so the GPU doesn’t sit idle waiting on the CPU or the network.

    4. Engineering in Practice: Replace “Feels Fast” with Benchmarks and Observability

    Speed optimization cannot rely on a one-off demo; it requires reproducible benchmarking. Fix the model version, input length distribution, output length distribution, concurrency level, and hardware specs, then measure TTFT, TPOT, single-stream tokens/s, system throughput, and P99 latency separately. For capacity planning, estimate KV cache usage based on “worst-case input length + maximum output length + safety margin,” and set replica counts and queuing policies according to your request arrival model.

    On general-purpose cloud platforms such as Baidu AI Cloud, you can run inference services on a container platform, manage model files and benchmark data with object storage, and collect latency, error rates, GPU memory utilization, and queue depth through logging and monitoring services. Production environments should also define degradation policies: when queues grow too long, shorten maximum output length, switch to a smaller model, lower the batching limit, or serve cached results. The following framework-agnostic pseudocode illustrates how to organize scheduling configuration and benchmarking.

    1. # Pseudocode: inference service configuration and benchmarking framework
    2. class InferenceConfig:
    3. max_batch_tokens = 32768
    4. prefill_chunk_size = 2048
    5. kv_cache_dtype = "fp8" # generic low-precision cache example
    6. enable_prefix_cache = True
    7. max_output_tokens = 1024
    8. p99_latency_slo_ms = 3000
    9. class Request:
    10. def __init__(self, prompt_tokens, max_new_tokens):
    11. self.prompt_tokens = prompt_tokens
    12. self.max_new_tokens = max_new_tokens
    13. self.arrive_time = None
    14. self.first_token_time = None
    15. self.finish_time = None
    16. class Scheduler:
    17. def admit(self, request, running, waiting):
    18. # Simplified policy: prioritize running requests, cap the waiting queue
    19. if len(waiting) > 200:
    20. return False
    21. if sum(r.prompt_tokens + r.max_new_tokens for r in running) > 28000:
    22. return False
    23. return True
    24. def benchmark(engine, workload, concurrency):
    25. results = []
    26. for batch in workload.split_by_concurrency(concurrency):
    27. for req in batch:
    28. req.arrive_time = now_ms()
    29. outputs = engine.generate(batch, config=InferenceConfig)
    30. for req, out in zip(batch, outputs):
    31. ttft = out.first_token_time - req.arrive_time
    32. tpot = (out.finish_time - out.first_token_time) / max(1, out.token_count - 1)
    33. results.append({
    34. "ttft_ms": ttft,
    35. "tpot_ms": tpot,
    36. "tokens_per_s": out.token_count / ((out.finish_time - req.arrive_time) / 1000),
    37. })
    38. return summarize(results) # report mean, P50, P95, P99, and throughput

    5. Conclusion: The Speed Race Is Ultimately a Systems Engineering Race

    Improving LLM inference speed is not about simply stacking compute or swapping in a different model—it is the coordinated result of model architecture, inference systems, parallelism strategies, hardware interconnects, and operational engineering. In the second half of the game, competitiveness will shift from “who has the bigger model” to “who can deliver stable output at acceptable quality, predictable latency, and controllable cost.” For developers and enterprises, building metric awareness, benchmarking capability, and observability matters more than chasing single-point peak numbers. Only by treating speed as a production SLO can you truly turn LLM capability into a sustainable product experience.