LLM Inference Costs Explained: Hardware, Batching, and Expert Architectures
This article explains why LLM serving costs depend on system design rather than parameter count alone. It examines the different optimization goals of training and inference, how batching reuses model weights and why larger batches are not always better, how mixture-of-experts architectures reduce activated computation while adding scheduling and communication costs, why rack-level interconnect boundaries matter, and why low-latency serving can be more expensive. It also discusses how to interpret public pricing, how training-data scale relates to service cost, and practical steps developers can take to profile workloads, isolate bottlenecks, run comparable tests, and optimize effective work.
1. Understanding LLM Costs Requires More Than Counting Parameters
Why do models in the same category offer different speeds and prices? Why does adding more compute hardware not always increase throughput proportionally? Why do sparse models activate only part of their parameters on each request yet still require complex cluster deployment?
The common answer is that a large model is not an isolated mathematical function. It is a system composed of compute, storage, communication, and scheduling.
Parameter scale determines part of the compute demand, but it does not independently determine serving cost. Actual operation is also constrained by the following factors:
- Whether model weights can reside in device memory;
- How many requests can be combined in each computation;
- How long the input context and output sequence are;
- Whether intermediate data must be exchanged across devices;
- Whether the service promises low time to first token and low inter-token latency;
- Whether the cluster can maintain high utilization when request volume fluctuates.
When analyzing inference economics, therefore, it is useful to separate two questions: how much computation a single request requires, and whether that computation can be executed efficiently. The former is mainly determined by the model and task. The latter depends heavily on system design.
2. Training and Inference: Same Model, Different Optimization Goals
1. Training Prioritizes Sustained Throughput
Training typically requires forward computation, backpropagation, and parameter updates. In addition to model weights, it may store gradients, optimizer states, and intermediate activations, so its memory and communication requirements are usually higher than those of inference alone.
Training jobs can often organize data in advance and use larger batches to improve device utilization. As long as overall training time and resource consumption remain acceptable, per-sample processing latency is usually not the primary goal.
For common dense models, training compute can be understood with a rough relationship:
Training compute ≈ coefficient × parameter count × training tokens
The coefficient varies with network architecture, training method, and statistical conventions. For mixture-of-experts models, it is also necessary to distinguish total parameter count from the number of parameters actually activated per token. Total parameter count cannot be directly substituted into the same estimate.
2. Inference Balances Latency, Throughput, and Stability
Online inference usually includes two phases with different characteristics.
Input processing phase: The model processes the context provided by the user and establishes the state needed for subsequent generation. Input tokens have substantial parallelism, and longer inputs may produce larger matrix operations.
Step-by-step generation phase: The model usually generates output sequentially, with each step depending on what has already been generated. The per-step computation for a single request is limited and is more likely to be affected by weight reads and access to historical state.
Therefore, fast input processing does not guarantee fast output generation. High overall throughput does not guarantee low response latency for an individual user.
Developers should at least track the following separately:
- Time to first token: the time from submitting a request to receiving the first output token;
- Inter-token latency: the time between adjacent output tokens;
- Request completion time: the total time from submission to completion;
- System throughput: requests or tokens processed per unit time;
- Tail latency: response time at high percentiles.
These metrics may conflict with one another. A single average cannot adequately describe service quality.
3. Why Batching Can Significantly Reduce Unit Cost
1. The Core Benefit Is Reusing Weight Reads
During low-batch step-by-step generation, a device may need to read a large number of model weights while performing computation for only a small number of requests. In this case, compute units may not be fully busy, and memory data movement may become the main bottleneck.
When multiple requests are combined, the same set of weights can serve more tokens. Matrix operations become larger, increasing the effective computation performed for each data read.
A simplified lower bound for per-step latency is:
Step latency ≥ max(required compute ÷ effective compute throughput, bytes moved ÷ effective memory bandwidth)
This is not a complete performance prediction formula, but it helps identify bottlenecks. If data movement time is clearly greater than compute time, adding more compute capacity alone may have limited effect. Increasing batch size appropriately is often more likely to improve utilization.
2. Larger Batches Are Not Always Better
Batching gains have limits. As concurrent requests increase, the system must also store more historical attention state, namely the key-value cache. This memory usage usually grows with the number of active requests and context length.
Excessively large batches can lead to:
- Increased queueing time while waiting for requests to form a batch;
- More memory occupied by the key-value cache;
- Longer per-step computation time;
- Uneven scheduling when long and short requests are mixed;
- Worse tail latency during peak periods.
The goal is therefore not the maximum batch size, but a higher effective batch size under latency constraints.
Continuous batching is a common approach: completed requests leave, new requests join promptly, and resource idleness caused by waiting for an entire batch to finish is reduced. It still must handle differences in request length, cache capacity, and fairness.
3. Extreme Cost Differences Are Not a Universal Law
There may be a significant efficiency gap between low and high batch sizes, but the exact multiplier depends on model architecture, device type, context length, parallelism strategy, and load conditions.
Claims that “a single request must be several times more expensive” without these conditions risk turning an estimate from a specific environment into a universal law. In engineering practice, teams should measure the curves among batch size, throughput, and latency, then evaluate the actual benefit.
4. Mixture-of-Experts: Less Computation, More Scheduling and Communication
1. Total Parameters and Activated Parameters Must Be Separated
A mixture-of-experts architecture organizes some network layers into multiple expert modules, and a routing mechanism selects a small number of experts for each token to participate in computation.
Its value is that the model’s total capacity can increase without requiring every token to access every expert. As a result, total parameter count can be significantly larger than the number of parameters actually used in each forward computation.
This does not mean the other experts have no cost. Experts not called by a given token still need to be stored and may serve other tokens. Deployment must consider both activated computation and how all weights are stored.
2. Expert Parallelism Requires Exchanging Tokens Across Devices
When different experts are distributed across different devices, a typical execution flow is:
- The routing module determines the target expert for each token;
- The intermediate representation corresponding to each token is sent to the device hosting the expert;
- Each expert processes the data it receives;
- The computation results are returned and merged.
This type of data exchange often has all-to-all communication characteristics. Its efficiency depends not only on single-link bandwidth but also on network topology, congestion, message size, and routing distribution.
If expert load is imbalanced, some devices receive many tokens while others remain relatively idle. Even if total computation is not large, the entire computation step may be limited by the slowest device.
The number of experts, the number of experts selected per token, load-balancing mechanisms, and communication strategy therefore need to be designed together.
5. Rack Boundaries Are Performance Constraints, Not Hard Architectural Ceilings
1. Why High-Speed Interconnect Domains Matter
Devices within the same high-speed interconnect domain usually have higher bandwidth and lower communication latency. Once data crosses this boundary, it may enter networks at different levels, and communication cost changes accordingly.
For expert layers that frequently exchange intermediate representations, the network may become a bottleneck once the share of cross-domain communication rises.
This does not justify the conclusion that “a mixture-of-experts model can only be deployed within a single rack.” Rack scale and cross-domain performance differences are not fixed constants, nor are they equivalent to a theoretical upper limit on model scale.
A more accurate statement is that the size of the high-speed interconnect domain affects the range within which a given expert partitioning scheme can operate efficiently.
2. Communication Cost Should Be Analyzed with Traffic and Topology
A rough communication time model is:
Communication time ≈ startup overhead on the critical path + data volume ÷ effective bandwidth
Effective bandwidth is usually lower than nominal bandwidth and is affected by concurrent communication, link sharing, protocol overhead, and network congestion. When multiple communication paths can proceed in parallel, startup times for all messages cannot simply be added together.
The share of cross-domain traffic also cannot be assumed to be a fixed ratio. It depends on expert distribution, token routing, expert replication, and topology-aware scheduling.
3. Common Optimization Directions
To mitigate communication bottlenecks, consider:
- Placing frequently collaborating modules on nearby devices where possible;
- Using hierarchical parallelism to distinguish intra-domain and cross-domain communication;
- Replicating heavily loaded experts appropriately;
- Improving routing balance while satisfying model quality constraints;
- Overlapping communication and computation to hide some waiting time.
Each method has costs. For example, replicating experts increases memory requirements, and emphasizing routing locality may change the expert selection distribution. Teams must therefore validate throughput, latency, and model quality together rather than optimizing only communication bytes.
6. Why Low-Latency Serving Can Be More Expensive
Faster serving does not necessarily mean that more computation was used for each inference. It may also mean that the serving system sacrificed resource utilization.
To shorten response time, the system may need to reduce batching waits, use smaller effective batches, reserve idle capacity, or avoid competition with other requests for resources. The result is that device costs remain unchanged while fewer requests share those costs.
A simplified relationship for unit cost is:
Unit output cost ≈ total serving cost per unit time ÷ effective output per unit time
Total serving cost also includes networking, storage, scheduling, fault redundancy, and other overhead. Speed improvements and price increases therefore do not necessarily have a linear relationship.
Conversely, tasks that can tolerate longer waits may reduce cost through asynchronous execution, batch submission, and more flexible scheduling. This requires the serving side to actually improve resource utilization. Simply delaying the return of results does not automatically reduce computation overhead.
For tasks such as offline document processing and batch information extraction, latency is often highly elastic. For interactive question answering, queueing time directly affects user experience. These two types of workloads should use different strategies.
7. Public Pricing Provides Clues, Not Proof of Hidden Architecture
Public API pricing can help formulate system hypotheses, but it cannot by itself reveal the exact parameter count, number of experts, or deployment topology of a model.
Prices are also affected by:
- Resource procurement and operating costs;
- Service quality and capacity guarantees;
- Cache reuse ratio;
- Input and output length distributions;
- Pricing strategy and business objectives;
- Resource utilization at different times.
The same pricing pattern may correspond to multiple implementations. For example, lower input pricing may be related to input processing efficiency, cache benefits, or commercial pricing choices.
Rigorous analysis should distinguish three levels:
Observable facts: prices, response times, throughput, error rates.
System hypotheses: small batches, more reserved capacity, possible communication limits.
Information that cannot be confirmed: specific model architecture, training data scale, and true internal costs.
Only by clearly labeling speculation as speculation can we avoid presenting “a plausible explanation” as “something already proven.”
8. Training Data Scale: Compute-Optimal Is Not Necessarily Service-Optimal
Discussions of training data volume also need to clarify what “optimal” means.
Under a fixed training compute budget, there is a tradeoff between parameter scale and number of training tokens: a model that is too large with insufficient data, or a model that is too small and trained for too long, may both reduce the efficiency of budget use.
A model intended for long-term serving, however, must also consider the many inference requests over its lifecycle. In some cases, increasing investment during training to obtain a usable capability from a smaller model may reduce subsequent serving costs.
This does not guarantee that longer training is always better. The quality, repetition level, and task distribution of additional data, as well as the marginal benefit of continued training, all affect the final result.
Therefore, price or hardware utilization alone cannot confirm how many times the theoretically optimal data volume a model used. A more reasonable judgment should consider the training budget, model quality, and cumulative inference cost together.
9. How Developers Can Turn Analysis into Actionable Optimization
1. Build a Real Workload Profile First
Track input length, output length, arrival rate, and latency requirements, rather than only recording total request volume. Pay particular attention to distinguishing short-input/long-output, long-input/short-output, interactive requests, and offline tasks.
Average length is often insufficient for capacity planning. High-percentile lengths and peak concurrency should also be observed.
2. Separate Bottlenecks by Stage
If time to first token is high, focus on queueing, input processing, and long-context overhead. If inter-token latency is high, focus on batch size, weight reads, cache access, and cross-device communication.
When throughput has stopped growing, increasing concurrency further may only lengthen the queue.
3. Use Comparable Test Conditions
During load testing, fix the task set, length distribution, and quality requirements, and record the following together:
- Input and output token throughput;
- Percentiles for time to first token and inter-token latency;
- Request success rate and timeout rate;
- Memory usage and device utilization;
- Network traffic and communication waiting;
- Comprehensive cost per successfully completed task.
If a test compares only output tokens per second while ignoring changes in answer length and quality, the cost conclusion may be distorted.
4. Prioritize Optimizing Effective Work
Reducing irrelevant context, avoiding unnecessary long outputs, reusing shared prefixes that meet permission requirements, and selecting appropriate models for tasks of different difficulty are often more direct than blindly adding capacity.
Cache design must also define expiration, invalidation conditions, and tenant isolation. No performance optimization should come at the cost of leaking data across users.
Conclusion
The core of LLM inference is finding a balance among computation, memory, communication, and service commitments. Batching improves weight reuse, expert architectures reduce part of the computation, high-speed interconnects support cross-device collaboration, and low-latency requirements often compress the space available for resource sharing.
For developers, the most valuable step is not guessing hidden architecture from a price number. It is building a verifiable workload model, identifying the real bottlenecks, and comparing costs under consistent quality and latency goals. Only then can an understanding of underlying mechanisms translate into stable and sustainable engineering gains.
