Why LLM Inference Costs Can Differ by 20x

    This article breaks down why two LLM services with similar capabilities can differ in inference cost by as much as 20x. It shows that the real cost of a request is a multiplicative result of four layers: model-side compression and sparsification, inference engine and scheduling efficiency, cache reuse and request tiering, and elastic compute on the cloud. It also explains how to measure quality, latency, cost, and stability with a reproducible evaluation framework instead of relying on subjective experience.

    1. The Starting Point: Why the Same Capability Can Cost 20x More

    When people discuss LLM capability, they often judge it by subjective experience: if an answer does not look polished, they assume the technology is behind. Switching to the engineering side reveals something different. The real cost of a single request is determined jointly by dozens of factors, not by one single point such as “how smart the model is.”

    The cost of a typical inference request can be roughly broken down as:

    1. cost per request ≈ (compute unit price × actual occupancy time × concurrency redundancy factor + storage and bandwidth + operations amortization) / effective request count

    This formula makes three things clear: the compute unit price is determined by hardware and procurement scale; the actual occupancy time is determined by inference engine efficiency; and the effective request count is determined by cache hit rate and batching efficiency. A 20x gap usually does not come from pushing one single factor to the extreme, but from the multiplicative result of optimizing all four at the same time.

    2. Layer One: Model-Side Compression and Sparsification

    The first layer of engineering innovation is “doing the same work with less.” Common and widely accepted techniques in the industry include:

    • Knowledge distillation: use a large model to produce high-quality labels, then train a small model to handle high-frequency, simple requests, forming a large-small model routing scheme.
    • Quantization: reduce weights from high precision to low-precision representations, cutting memory usage and memory access overhead, at the cost of having to evaluate accuracy regression.
    • Sparsification: a mixture-of-experts structure activates only part of the parameters in each forward pass, decoupling total parameter count from per-request compute.
    • Efficiency-oriented architecture design: such as variations of multi-head attention and position encoding extrapolation schemes, mainly aimed at preventing long context from causing a linear explosion in memory cost.

    It is important to stress that all of these techniques involve trade-offs in accuracy and stability, and there is no such thing as “zero-cost reduction.” A rigorous approach is to build an offline evaluation set and quantify the gain and regression of each optimization step.

    3. Layer Two: Inference Engine and Scheduling Efficiency

    With the same model and hardware, throughput can differ significantly between different serving implementations. The core variables are:

    1. Continuous batching: combine requests arriving at different times into the same batch, avoiding the idle time caused by static batching.
    2. KV cache management: paged memory management reduces fragmentation, so long-context requests do not monopolize one contiguous block of memory.
    3. Operator and kernel optimization: fusion and customization for hot operators such as attention and normalization.
    4. Parallelism strategy: the combination of tensor parallelism, pipeline parallelism, and expert parallelism determines multi-GPU utilization.
    5. Scheduling and prioritization: separate interactive requests from offline batch jobs into different pools, so long tasks do not block short requests.

    Illustrative server-side pseudocode:

    1. def schedule(requests, kv_pool, max_batch_tokens):
    2. batch, tokens = [], 0
    3. for r in sorted(requests, key=lambda x: x.priority): # interactive requests first
    4. need = r.prompt_tokens + r.max_new_tokens
    5. if tokens + need > max_batch_tokens or not kv_pool.allocatable(need):
    6. yield batch # trigger one forward pass
    7. batch, tokens = [], 0
    8. batch.append(r); tokens += need
    9. if batch:
    10. yield batch

    The value of this logic is that throughput is not bought by adding more GPUs, but gained by “not wasting” resources.

    4. Layer Three: Cache Reuse and Request Tiering

    In enterprise scenarios, requests are highly repetitive. Reusable layers include:

    • Exact cache: identical prompts directly hit the stored result.
    • Prefix cache: long common prefixes such as system prompts, knowledge base fragments, and tool descriptions are computed only once.
    • Semantic cache: reuse results for approximate questions after vector retrieval, which requires a similarity threshold and an invalidation policy.
    1. hit condition: sim(query, cached) ≥ τ and context version matches → reuse

    In engineering practice, version numbers and tenant isolation must be in place; otherwise, serious problems such as cross-tenant data leakage can occur. Caching is the key lever for increasing the “effective request count.”

    5. Layer Four: Compute Elasticity and General Cloud Capabilities

    Another layer of cost reduction comes from the infrastructure principle of “letting different parties do the work.” A common practice is to separate stateful and stateless parts: the stateless inference layer scales elastically on a container platform, burst traffic is smoothed by a queue, sessions and results land in object storage, and tracing and metrics go into logging services and monitoring and alerting systems. The general-purpose capabilities offered by Baidu AI Cloud in these categories are usually organized along these layers as well, making it easier to pay according to business peaks and troughs rather than holding idle compute over the long term.

    6. How to Evaluate Scientifically: Do Not Replace Metrics with Experience

    It is recommended to build a four-dimension evaluation table, with a reproducible measurement method for each dimension:

    Dimension Metric Measurement
    Quality Task set pass rate Regression on a fixed evaluation set
    Latency Time to first token / overall latency percentiles Load testing tools reporting P50/P95
    Cost Cost per thousand requests Bill divided by effective request count
    Stability Error rate and degradation trigger rate Monitoring and alerting dashboard

    Only when quality and latency do not degrade can a cost reduction be counted as a real gain.

    7. Conclusion: Capability Is Proven, the Ecosystem Is the Variable

    Building a usable, low-cost LLM product is essentially engineering innovation at the methodology level: breaking “doing it better” into four measurable layers of optimization. The real gap often lies not in a single technique, but in whether the evaluation system, cache governance, elastic scheduling, and engineering standards form a coherent whole. The advice for developers is straightforward: build evaluation and observability first, then compression and scheduling, and finally use elastic resources to absorb fluctuations. The cost curve will naturally fall into a reasonable range.