LLM Inference Framework Evaluation: A Methodology for Benchmarking and Tuning

    This article presents a reusable methodology for evaluating and tuning large language model inference frameworks. It explains why teams should define a metric contract instead of relying on a single tokens-per-second number, breaks down the four main sources of GPU memory usage, and shows how batching strategies such as continuous batching drive major throughput differences. It also covers when to apply quantization and parallelism, which observability metrics to collect, and how to run step-wise load tests to locate performance inflection points.

    When beta users begin sharing their hands-on experience with different LLM inference frameworks, the most interesting question is rarely about a specific implementation. Instead, it is about the common technical problems these practices reveal: why can throughput differ by several times on the same model and the same hardware? Why does GPU memory always become the bottleneck first? This article strips away product-specific details and abstracts these phenomena into a reusable methodology for evaluation and tuning.

    1. Define Evaluation Goals First: Do Not Summarize Everything With One Number

    Many teams focus only on “tokens per second” when selecting a framework, which is the easiest way to mislead a decision. The real performance of an inference service is determined by several interdependent metrics:

    • Throughput (tokens/s or requests/s): the total workload processed per unit of time;
    • Time to first token (TTFT): the time from when the user presses Enter to when the first token appears;
    • Time per output token (TPOT): the average generation speed during the decoding phase;
    • Tail latency (P95/P99): determines whether the experience breaks down during peak traffic;
    • GPU memory usage and stability: whether the service can run for a long time without crashing on the target GPU.

    It is recommended to write the business workload as an explicit “metric contract”, for example: average input of 2000 tokens, average output of 500 tokens, P99 time to first token below 800 milliseconds, and single-GPU memory usage not exceeding 90% of the limit. With such a contract in place, all subsequent comparisons become meaningful.

    2. GPU Memory: The Starting Point of All Optimization

    GPU memory during inference is mainly composed of four parts: model weights, the KV cache, runtime activations and temporary buffers, and the framework’s own overhead. Among them, the KV cache grows linearly with concurrency and context length, and is the most easily underestimated part.

    A rough estimation is as follows (illustrative only, not an exact formula):

    1. # Illustrates the order of magnitude only; rely on actual framework measurements
    2. kv_bytes = 2 * layers * kv_heads * head_dim * seq_len * batch * dtype_bytes

    Common engineering countermeasures include paged KV management to reduce fragmentation, prefix reuse so that an identical system prompt is computed only once, and swapping cold data out to host memory. A practical standard for judging whether a framework is mature is whether the memory curve stays flat during long stress tests, rather than slowly climbing until it crashes.

    3. Batch Scheduling: The Main Source of Throughput Differences

    Static batching requires the entire batch to wait for the slowest request, so short requests are held back by long ones. Continuous batching, on the other hand, re-forms the batch at every decoding step: completed requests exit immediately and new requests fill in immediately. This is the most common reason for several-fold throughput differences on the same hardware.

    1. Static batching: [====Request A====][====Request B====]
    2. Continuous batching: [==A==][==C==][==B==][==D==]

    Furthermore, scheduling the compute-intensive prefill phase separately from the memory-access-intensive decoding phase can prevent long inputs from blocking requests that are actively generating tokens, significantly improving P99 latency.

    4. Quantization and Parallelism: Choose the Right Fix for the Bottleneck

    More aggressive quantization is not always better. Low-bit quantization on the weight side mainly trades for memory and bandwidth gains, with relatively controllable impact on generation quality; KV cache quantization offers clear benefits in long-context, high-concurrency scenarios, but its impact on long-range consistency needs to be verified. Before going live, always run a quality regression on your own business evaluation set rather than relying only on general leaderboards.

    Parallelism strategies should also match the bottleneck: when single-machine multi-GPU memory is insufficient, prioritize tensor parallelism; when the model fits but throughput is insufficient, consider data parallelism with multiple replicas; when an extremely long context makes the KV cache unable to fit on a single GPU, then introduce context parallelism. The principle is to use measurement to locate the bottleneck first, then choose the parallelism dimension, avoiding unnecessary communication overhead introduced just to “look advanced”.

    5. Observability and Stress Testing

    Without measurement there is no optimization. It is recommended to collect at least: queue wait time, average and maximum sequence length within a batch, cache hit rate, peak GPU memory, and decoding time per step. Stress tests should cover three types of workloads: short input with short output, long input with short output, and long input with long output, gradually increasing the load to find the inflection point.

    1. # Illustrative: step-wise load increase to observe the latency inflection point
    2. for c in 8 16 32 64 128; do
    3. run_benchmark --concurrency "$c" --duration 120s
    4. done

    6. Deployment Recommendations

    If a team lacks the operational investment to build its own inference layer, it can also evaluate a combination of general cloud capabilities: using a container platform to host elastic replicas, object storage to store model files, and logging and monitoring services to close the observability loop. Baidu AI Cloud offers corresponding product forms in these general categories, which can be combined as needed.

    Overall, the right approach to evaluation is: first write a clear metric contract, then use stress tests to locate the bottleneck, and finally choose batching, quantization, and parallelism strategies based on that bottleneck. Solidifying this process into a repeatable workflow delivers more long-term value than chasing the benchmark score of any single framework.