LLM Inference Optimization: A Practical Guide to Higher Throughput and Lower Cost

    This guide explains how to evaluate and optimize large language model inference during a model generation shift. It covers the engineering signals behind retiring a flagship model, how to measure throughput (TPS), time to first token (TTFT), end-to-end latency, and per-task cost, where high TPS and low TTFT typically come from, how to control the cost of reasoning tokens, and a four-step migration workflow with resource governance practices for keeping bills predictable.

    1. The Engineering Signals Behind a Model Generation Shift

    A common pattern appears as inference services evolve: a vendor releases a smaller model built for high throughput and low latency while retiring the previous flagship. Cost-sensitive users are nudged toward the new model, and the remaining heavy traffic on the old model competes for training and R&D resources. Stripped of any specific product context, this pattern reveals three general engineering signals:

    1. The old flagship has a high compute cost per token, so continuing to serve online traffic at the margin is no longer economical.
    2. The new model involves substantial changes to architecture and inference infrastructure; otherwise it could not deliver both high output speed and low time to first token.
    3. Model lifecycle management has become routine; versions have defined retirement dates, and business systems must be portable.

    For developers, the real question is not “which model is stronger” but how to account for throughput gains, latency gains, and the total bill at the same time during a generation shift.

    2. Metrics: Breaking “Fast” into Measurable Quantities

    Evaluating an inference service requires distinguishing at least four metric categories; mixing them leads to misleading conclusions:

    • Throughput (TPS): output tokens per unit of time, which drives the feel of long-form generation.
    • Time to first token (TTFT): strongly tied to prefill compute, batching strategy, and network path; it determines whether interactive applications feel responsive.
    • End-to-end latency: TTFT plus total generation time, which is what users actually wait for.
    • Per-task cost: the sum of input tokens, output tokens, and reasoning tokens, each priced separately.

    Illustrative load-testing and measurement logic:

    1. # Pseudocode: collecting key metrics for a single request
    2. t0 = now()
    3. resp = client.chat(stream=True)
    4. ttft = None
    5. out_tokens = 0
    6. for chunk in resp:
    7. if ttft is None and chunk.has_content:
    8. ttft = now() - t0 # time to first token
    9. out_tokens += chunk.token_count
    10. total = now() - t0
    11. tps = out_tokens / max(total - ttft, 1e-6) # generation-phase throughput
    12. cost = in_tokens * p_in + out_tokens * p_out + think_tokens * p_think

    The key point: TTFT and TPS must be measured separately. Reporting only one of them easily leads to the wrong procurement decision.

    3. Architecture and Infrastructure: Where High TPS and Low TTFT Come From

    Without referring to any specific vendor implementation, the widely accepted techniques for faster inference include:

    • Attention mechanisms and sparsification, reducing repeated computation over long contexts.
    • Lighter model structures, reducing the parameter activation scale per token.
    • Continuous batching and paged memory management, improving GPU utilization.
    • Disaggregated prefill and decode deployment, so TTFT and TPS do not block each other.
    • Quantization and operator fusion, trading bandwidth for gains within an acceptable accuracy range.

    The engineering implication is direct: when a new model claims “high TPS + low TTFT,” it almost certainly comes with changes on both the architecture and infrastructure sides. If the old flagship’s architecture has not evolved accordingly, its cost-performance passively declines. That is the root of the generation gap, not an operational strategy issue.

    4. The Cost Trap of Reasoning Output

    A common side effect of newer models is “overthinking”: generating a large amount of intermediate reasoning tokens before answering. When it is fast enough, users may not notice, but the bill rises significantly because reasoning tokens are usually billed as output.

    Governance has three layers:

    1. Task tiering: disable or cap the reasoning budget for deterministic tasks such as extraction, classification, and formatting.
    2. Budget constraints: set an upper limit on reasoning length, truncating and falling back to a direct answer when exceeded.
    3. Cache reuse: cache results for high-frequency repeated prefixes to reduce repeated inference cost.
    1. # Example: configuring reasoning budgets by task type
    2. task_policy:
    3. extraction: { thinking: off, max_tokens: 512 }
    4. summarization:{ thinking: low, max_tokens: 2048 }
    5. reasoning: { thinking: high, max_tokens: 8192 }

    Conclusion: a new model lowers the per-token price but does not necessarily lower the total cost per task, so costs must be accounted for on a per-task basis.

    5. Migration Evaluation: What to Do Before the Old Model Retires

    Facing a defined retirement date, a four-step migration process is recommended:

    • Freeze a baseline: record inputs and outputs from real business samples to form a replayable evaluation set.
    • Dual-run comparison: run old and new models on the same sample set in parallel, comparing accuracy, format compliance, latency, and cost.
    • Canary rollout: ramp traffic gradually from 1% to 10% to 50%, keeping a one-click rollback switch.
    • Capacity reservation: higher throughput on the new model means each instance carries more load, so concurrency and rate-limit thresholds must be recalculated.

    An abstract multi-model routing example:

    1. def route(req):
    2. if req.task in ("chat", "agent"):
    3. return primary_model # primary high-throughput model
    4. if req.need_long_context:
    5. return fallback_model # long-context fallback path
    6. return primary_model

    The value of keeping an abstraction layer is that model version changes are contained in configuration, so business code does not need to be rewritten with each generation shift.

    6. Resource Governance: Preventing a Few Heavy Users from Affecting Everyone

    A common resource conflict during the old flagship stage is a small number of high-intensity callers crowding out shared compute. General solutions include setting token quotas and concurrency limits per tenant, isolating long-running tasks in separate queues, scheduling offline batch jobs during off-peak hours, and using monitoring and alerts to intervene early on abnormal traffic spikes. If the overall architecture already supports elastic scaling, container platforms and message queues can be combined to smooth peaks and fill valleys, turning burst traffic into controllable asynchronous tasks.

    7. Conclusion

    A model generation shift is fundamentally an engineering decision: trade architectural gains for lower unit cost, trade task tiering for lower reasoning overhead, and trade an abstraction layer for lower migration risk. Putting TTFT, TPS, reasoning tokens, and total cost on the same evaluation sheet is what keeps the business stable and the bill controllable through the rhythm of new models launching and old models retiring. On a cloud environment that supports unified multi-model access and elastic scaling (such as the relevant general capabilities of Baidu AI Cloud), these strategies are easier to put into practice.