Low-Cost Large Model Inference in High-Concurrency Scenarios

    This article explains how to reduce large model inference costs under high concurrency by focusing on cost per token, time to first token, and throughput stability. It covers sparse architectures that decouple total parameters from activated parameters, a cost model that separates input, output, and cache-hit pricing, prefix caching practices, effective use of long context and multimodal inputs, and reliability measures such as multi-level caching, batching, and tier routing. Readers will find practical guidance and code examples for building a cost-efficient inference stack.

    1. Background: Why Cost per Token Drives Architecture Decisions

    Once a team embeds large model capabilities into real business workflows, it quickly becomes clear that scalability depends less on the model’s upper capability limit than on three engineering metrics: cost per token, time to first token, and throughput stability. Common scenarios such as intelligent customer service, code assistance, document review, and content moderation share the same traits: high request volume, long single inputs, relatively short outputs, and many requests sharing the same system prompt or knowledge context. Cost therefore becomes a linear function of “input tokens × unit price,” and any optimization on the input side yields a proportional reduction in spend.

    The industry generally responds in three ways: structural optimization on the model side, inference optimization on the serving side, and usage governance on the calling side. Only by combining all three can costs be pushed into a range the business can sustain.

    2. Sparse Architectures: Decoupling Total Parameters from Activated Parameters

    A recent class of cost-efficient models follows a notable technical path: roughly 224B total parameters, of which about 64B are memory-oriented sparse parameters, with only about 12B parameters activated per forward pass, while supporting multimodal input and million-token context lengths. The key point is not the parameter count itself, but the decoupling of “capacity” from “compute.”

    • Capacity sets the knowledge ceiling: a large total parameter count provides broader knowledge storage, determining how many facts the model can retain.
    • Activation determines per-call cost: only a small subset of parameters participates in each forward pass, directly governing compute consumption and latency.
    • Sparsity carries engineering costs: routing and parameter loading demand more memory and bandwidth, so the “low cost” shows up in the metered unit price rather than in trivially low deployment costs.

    The takeaway: when evaluating such models, treat “parameter scale” and “billing unit price” separately. The former is a capability prior; the latter is what appears on the bill.

    3. Cost Model: Breaking the Bill into Optimizable Items

    Using publicly listed tiers from a cloud provider as an example, prices for the same model can differ by an order of magnitude across tiers: the low tier charges about CNY 0.02 for input (cache hit), CNY 0.5 for input, and CNY 2 for output per million tokens; the high tier charges roughly CNY 0.3, CNY 6, and CNY 18 respectively. These numbers carry three engineering implications:

    1. Output costs 3–4 times more than input, making output length control the highest-leverage optimization.
    2. Cache-hit input can cost as little as 1/20 of regular input, making prefix reuse the biggest lever.
    3. A “capability level vs. cost” gradient exists across tiers, so requests should be routed by task difficulty rather than served uniformly.

    A simplified cost estimate:

    1. cost per call ≈ input tokens × input unit price
    2. + output tokens × output unit price
    3. - cached input tokens × (input unit price - cache unit price)

    4. Prefix Caching: Turning Repeated Context into a Sunk Cost

    Prefix caching pays off only when requests share a stable prefix. Typical reusable prefixes include system instructions, tool definitions, few-shot examples, and long document bodies. Key practices:

    • Order sensitivity: caching matches by prefix, so any change to preceding content invalidates the entire segment. Place volatile fields (timestamps, session IDs, random values) at the end.
    • Stable serialization: fix JSON key order, spacing, and line breaks to avoid cache misses caused by serialization differences.
    • Lifecycle alignment: caches have a survival window, so batch offline jobs should be submitted together, while online paths should limit how often the prefix changes.
    1. # Example: stable prefix + volatile suffix
    2. SYSTEM = "You are a document review assistant. Follow these rules:\n" + RULES # long and stable
    3. def build_messages(doc, question):
    4. return [
    5. {"role": "system", "content": SYSTEM},
    6. {"role": "user", "content": f"Document body:\n{doc}\n\nQuestion: {question}"},
    7. ]

    5. Context and Multimodal Inputs: Using Long Windows Correctly

    The value of a million-token context lies in “whole-package input,” but long contexts bring attention dilution and higher latency. Recommendations:

    • Retrieval first: narrow the candidate set with retrieval, then let the long window perform global reasoning instead of blindly filling it.
    • Positional layout: place critical instructions at the beginning and end, and put expendable background material in the middle.
    • Multimodal preprocessing: compress images to the necessary resolution and transcribe audio before input to reduce wasted tokens.

    6. Stability and Governance: Making Low Cost Sustainable

    Low cost does not mean low reliability. Engineering needs supporting measures: multi-level caching (in-application cache plus platform-side cache), semantic deduplication, batching and asynchronous queues, routing by difficulty to different tiers, and a usage dashboard built on logging services and monitoring alerts. For capacity planning, run dedicated stress tests on the memory and bandwidth demands of sparse models, and use three metrics—time to first token, cost per thousand tokens, and cache hit rate—for canary comparisons.

    7. Implementation Pattern

    The recommended flow is: first build an offline evaluation set to quantify the accuracy–cost curve across tiers; then extract and fix stable prefixes; next integrate caching and batching; finally validate unit cost and latency with canary traffic. If an organization already uses general capabilities from Baidu AI Cloud (such as object storage, message queues, container platforms, logging services, and monitoring alerts), these steps can map directly to managed components, reducing self-managed operations. Overall, sparse architecture + cache reuse + output constraints + tier routing are the four main lines for pushing large model inference costs into a business-viable range today.