Choosing an LLM Inference Framework: Architecture, Optimization Techniques, and Benchmarking

    This article explains where LLM inference costs come from, how to standardize metrics for fair comparison, and how inference frameworks optimize operator, runtime, and scheduling layers. It covers operator-engine co-design, expert parallelism and load balancing for MoE models, and speculative decoding with acceptance rate, with emphasis on validating gains on your own models and hardware.

    1. Where Do LLM Inference Costs Come From?

    After a model is trained, it must serve external requests over the long term. In high-traffic scenarios, cumulative inference costs can exceed training costs. The exact cost depends on model size, traffic pattern, and hardware, so no fixed conclusion applies.

    In common per-request generation, each request exclusively occupies one or several GPUs. At low traffic, this approach is acceptable. As traffic grows, three problems appear. First, batch size is limited by GPU memory, so larger batches do not fit. Second, autoregressive generation outputs only one token at a time, so compute units often wait on memory reads and writes, resulting in low hardware utilization. Third, for mixture-of-experts (MoE) models, only a subset of experts is activated; communication between experts and load imbalance can amplify latency.

    Before evaluation, standardize metric definitions; otherwise results from different approaches cannot be compared. At minimum, record the following metrics:

    • Throughput: output tokens per second (tokens/s) and completed requests per second (req/s).
    • Time to first token (TTFT): time from request arrival to the first output token.
    • Time per output token (TPOT): average time per token in the generation phase.
    • Tail latency: P95 and P99 of end-to-end latency.
    • Unit cost: hardware cost per million output tokens, calculated as GPU-hour price divided by effective throughput, with appropriate unit conversion.

    2. Architecture and Key Techniques

    An inference framework is responsible for more than loading and running a model. It must optimize at the operator, runtime, and scheduling layers at the same time. The following sections describe each component’s role, key parameters, and validation methods. These are general mechanisms; specific implementations vary by framework and version. When choosing a framework, rely on the documentation and source code for the version you use.

    2.1 Operator and Engine Co-Design

    In traditional structures, the operator library and scheduler belong to different layers, and cross-layer calls introduce extra data copies and synchronization waits. One improvement is to make the scheduler aware of each operator’s location and dependencies, reducing unnecessary waiting. Basic operators such as attention, feed-forward networks, and normalization can be implemented specifically for target hardware. Some frameworks also use just-in-time (JIT) compilation to generate kernels for the hardware.

    The benefit of fusion depends on model size, hardware type, and request shape. For short inputs and small models, scheduling overhead is a larger share, so the benefit is usually more obvious. Benefits must be measured on your own model and hardware; results from others cannot be cited directly.

    2.2 Expert Parallelism and Load Balancing

    In MoE models, different experts can be placed on different devices. The framework maintains a global routing table that records the location of each expert. Based on the experts selected by each token, the scheduler packs activation data and sends it to the corresponding devices.

    Hot experts are prone to overload. Two common approaches address this.

    First, dynamic replication. When the load on an expert exceeds a threshold, it is copied to an idle device. The number of replicas and the trigger threshold must be adjusted according to traffic; too many replicas consume a large amount of GPU memory.

    Second, soft routing. A small random subset of tokens is assigned to experts with lower load. This ratio is an adjustable parameter. Start with a small ratio, such as 1% to 3%, increase it gradually, and verify quality on a validation set. If the drop in perplexity or downstream task accuracy exceeds the threshold set in advance by the team, disable soft routing and fall back to standard routing.

    To judge whether this mechanism is effective, examine two classes of metrics together. One is the expert utilization distribution: the ratio of maximum utilization to average utilization should drop significantly. The other is quality metrics, including perplexity and downstream task accuracy. Looking only at improved utilization does not give a complete conclusion.

    2.3 Speculative Decoding and Acceptance Rate

    Speculative decoding first uses a smaller model, or the first few layers of the same model, to quickly generate k candidate tokens.