LLM Inference Cost Optimization: From Peak Compute to Effective Throughput
Optimizing LLM inference costs requires more than comparing accelerator specifications. This article explains how prefill and decoding workloads, service targets, utilization, and total system costs shape inference economics. It also outlines a reproducible evaluation process for comparing hardware on cost per useful output while maintaining quality, latency, and production reliability.
1. Rethinking What Makes Inference Hardware Competitive
A common mistake when evaluating large language model inference infrastructure is to equate theoretical compute performance with business value: more compute should mean faster inference and lower costs. In practice, the relationship is not that simple.
LLM inference is an execution pipeline that combines computation, memory access, communication, scheduling, and request handling. A bottleneck anywhere in that pipeline can prevent other resources from operating efficiently. Theoretical compute performance describes an upper limit under a particular numerical precision and set of conditions. What businesses actually need to measure is how many useful requests a system can complete per unit of cost while meeting response-time, output-speed, and quality requirements.
Cost modeling can reveal a seemingly counterintuitive result: an accelerator with lower theoretical compute performance or memory bandwidth may still offer better economics for a particular inference workload because its resource cost is lower. That does not establish that the hardware is universally superior, nor does a margin calculated in a cost model represent an actual business result.
The more reliable conclusion is that inference hardware competitiveness must be defined by performance, cost, and service quality together—not by a single specification.
2. Prefill and Decoding: Two Workloads Within the Same Model
LLM response generation generally has two main stages: prefill and decoding. Their different resource requirements are fundamental to understanding inference costs.
Prefill: Processing Input and Building Context State
During prefill, the model processes the input text, computes intermediate states, and builds the key-value (KV) cache needed for subsequent generation. Because multiple input positions can be processed with some degree of parallelism, this stage typically has high compute intensity.
However, “compute-intensive” does not mean performance depends only on compute capacity. Input length, attention implementation, memory capacity, data layout, and communication between devices can all affect actual performance. Long contexts can also substantially increase attention-related overhead and cache requirements.
For users, prefill performance primarily affects time to first token (TTFT). Workloads involving long-document analysis, complex prompts, or extensive conversation histories therefore require careful evaluation of first-token latency with long inputs.
Decoding: Generating Output Step by Step
Decoding typically proceeds one generation step at a time. Each step requires access to model weights and existing context state. At low concurrency or small batch sizes, data movement can be more significant than computation, making memory bandwidth an important constraint.
Increasing concurrency and batching multiple requests can improve weight reuse and device efficiency. As batches grow, however, compute demand, cache capacity requirements, and scheduling pressure also increase. The bottleneck can shift, so it is inaccurate to describe every decoding workload as purely bandwidth-bound.
For users, decoding performance primarily determines how quickly an answer continues to stream. Service providers must also measure aggregate output throughput across requests and determine whether higher throughput comes at the expense of individual user experience.
Let the Workload Determine the Evaluation Focus
Long-input, short-output tasks call for particular attention to prefill efficiency and TTFT. Short-input, long-output tasks place greater emphasis on decoding efficiency, cache management, and sustained output speed.
If a service handles both, a benchmark with one fixed input and output length is insufficient. The test set should reflect the actual traffic distribution, including typical input and output lengths, long-tail requests, and bursts of concurrent traffic.
3. Why Peak Compute Does Not Equal Effective Throughput
Theoretical compute specifications usually depend on a particular numerical precision and computation mode. Whether real inference approaches that limit also depends on model operations, runtime implementation, and data organization.
First, not every operation can use the lowest available precision. Some computations may need to retain higher precision to control output-quality degradation. Comparing only low-precision peak performance while ignoring the actual precision mix can produce misleading results.
Second, data conversions between operations, memory reads and writes, and synchronization introduce overhead. Even powerful compute units may spend time waiting for data.
Third, multi-device deployments require communication between devices. When a model exceeds the capacity of one device, communication topology, parallelization strategy, and synchronization frequency all affect final throughput.
A fair evaluation should establish at least the following:
- Use the same model version, input and output length distributions, and quality criteria.
- Document precision and quantization choices so that quality degradation is not mistaken for a performance improvement.
- Record batch size, concurrency, cache configuration, and parallelization strategy.
- Apply the same latency limits and request-failure criteria.
- Report both the number of devices and the resources required by the complete serving system.
Different hardware platforms can use optimizations appropriate to their architectures; their low-level implementations do not need to be identical. Model quality, user experience, and cost-accounting boundaries must nevertheless remain comparable.
4. Calculating Cost per Useful Output
Evaluating inference economics starts with defining the cost boundary and then measuring useful output.
Total Cost of Ownership Goes Beyond Accelerator Prices
Self-hosted infrastructure typically requires accounting for hardware acquisition and depreciation, host systems and networking, facilities, electricity, cooling, maintenance, and operations. For rented resources, use the actual billing basis and verify whether supporting compute, storage, and network charges are included.
It is also important to distinguish two perspectives: the infrastructure provider’s resource costs and the rental price paid by the customer. The former may depend on procurement and operating assumptions; the latter may vary with rental duration, purchasing arrangements, and contract terms. They should not be treated as interchangeable.
Avoid double-counting. If a rental price already includes hardware depreciation and electricity, those costs should not simply be added again.
Effective Throughput Matters More Than Total Throughput
Cost per unit of useful output can be expressed as:
Cost per unit of useful output = Total cost during the evaluation period ÷ Useful output produced during the same period
“Useful output” should mean results that satisfy agreed conditions, such as successful request completion, acceptable output quality, and latency within the permitted range.
Counting only the tokens generated by a device, without accounting for timeouts, failures, and retries, overstates economic efficiency. If aggressive batching leaves many requests waiting too long, the increase in total throughput may not translate into deliverable business output.
For input-heavy workloads, record input and output costs separately or use a combined cost per successful request. Otherwise, a small output volume can make an output-only metric difficult to interpret.
Margin Figures Must Specify Their Accounting Scope
A simplified revenue contribution ratio can be written as:
Revenue contribution ratio = (Service revenue − Included costs) ÷ Service revenue
The meaning of this metric depends on which costs are included. If it subtracts only inference infrastructure costs, it is not a company’s net profit margin. Research and development, customer support, customer acquisition, administration, taxes, and other business expenses may remain outside the calculation.
Revenue also depends on the pricing structure. If input and output are priced differently, or if discounts, free allowances, and non-billable requests apply, revenue cannot be calculated simply by multiplying total generated tokens by one uniform price.
Any margin figure should therefore state the model, pricing assumptions, utilization, rental or depreciation period, service constraints, and cost scope. Without those conditions, the number does not support a general conclusion.
5. Utilization Matters, but Averages Are Not Enough
Device utilization affects how fixed costs are spread across requests. Resources that remain idle for extended periods can have a high cost per request even when their unit price is low.
However, utilization is not a single, uniform metric. Compute-unit activity, memory-bandwidth utilization, device-memory occupancy, and the proportion of time resources are allocated each describe different aspects of the system.
High device-memory occupancy may simply mean that weights and caches occupy substantial space; it does not prove that compute units are working efficiently. Conversely, low compute utilization may reflect a memory-bandwidth-bound workload rather than a configuration problem.
Businesses should use traffic patterns, queueing times, and actual throughput together to determine whether capacity is excessive. Two workloads with the same average demand can require very different capacity plans if their peak-to-trough patterns differ.
Practical optimization can focus on the following:
- Group requests by length and service tier to reduce interference between long and short tasks.
- Use dynamic batching to balance waiting time against throughput.
- Establish appropriate queueing, rate-limiting, and rejection policies for traffic bursts.
- Set scaling windows with model-loading time in mind, avoiding situations where resources are available but the service is not yet ready.
- Maintain necessary headroom for critical workloads rather than substituting maximum utilization for reliability targets.
6. Build a Reproducible Evaluation Process
Step 1: Define Service Targets
Specify TTFT, sustained output speed, total completion time, success rate, and quality requirements. Do not rely only on averages. Higher-percentile latency matters because long-tail performance often determines whether a system can deliver consistently.
Step 2: Build Representative Workloads
Tests should cover real input and output lengths, different concurrency levels, varying contexts, and request-arrival patterns. Fixed-concurrency tests help reveal system limits, while tests that submit requests at realistic arrival rates better represent production queueing pressure.
Step 3: Validate Quality
When changing precision, quantization, or execution strategies, use a consistent task set to check for quality changes. A cheaper configuration with unreliable results should not automatically be considered a successful optimization.
Step 4: Separate Cold Starts from Steady-State Operation
Model loading, compilation, and cache initialization can affect initial performance. Record cold-start and steady-state metrics separately rather than reporting only the most favorable run.
Step 5: Record System-Level Costs
Beyond accelerators, account for host processors, memory, networking, and required storage. Include these resources in the overall comparison when they create bottlenecks or represent significant costs.
Step 6: Run Sensitivity Analysis
Vary utilization, the input-to-output ratio, resource prices, and service pricing to see whether the conclusions remain stable. If a configuration is economical only within a narrow range of assumptions, describe that range instead of making an unconditional recommendation.
7. Turn Benchmark Results into Production Decisions
Hardware economics are only one part of infrastructure selection. Production deployment also requires evaluating model adaptation effort, debugging efficiency, monitoring, failure recovery, capacity availability, and migration costs.
Lower resource prices can be offset by additional adaptation work or operational complexity. Businesses should compare migration costs with long-term savings while considering deployment scale and the frequency of model updates.
A practical decision process is to first identify configurations that meet quality and service targets, then compare their cost per useful output, and finally validate stability and actual spending with a small share of production traffic.
When prefill and decoding have very different requirements, separate deployments may also be worth evaluating. That comparison must include context-state transfer, scheduling coordination, and additional network overhead. Whether separation is worthwhile should be determined through end-to-end testing, not inferred from the best isolated results for each stage.
8. Conclusion: Evaluate Inference Infrastructure by What It Delivers
The central question in LLM inference is not how much theoretical compute a device provides. It is whether the complete system can reliably complete tasks that meet quality and latency requirements at a sustainable cost.
Lower-cost hardware may offer better economics for some workloads. Higher-performance hardware may justify its cost for long inputs, strict latency targets, or high concurrency. Both claims require consistent accounting boundaries and tests based on real business workloads.
For developers and businesses, the most valuable asset is not a ranking of peak specifications but an evaluation process that evolves with the service: quality as a prerequisite, service targets as constraints, effective throughput as output, and complete costs as the denominator. This is how an advantage in a benchmark becomes a verifiable, repeatable engineering benefit.
