LLM Inference Cost: The Underlying Logic of Hardware, MoE, and Batching
This article explains why frontier LLMs take their current shape in terms of architecture, pricing, and scaling speed, breaking down the factors that drive inference cost across four layers: hardware topology (scale-up domains vs. scale-out networking), Mixture-of-Experts (MoE) sparse activation and all-to-all communication, batch size and its effect on per-request economics, and training data scaling constraints. You'll get a practical checklist for evaluating MoE deployment, guidance on benchmarking and cost estimation, and quick answers to common questions about MoE cost, batch sizing, and whether fast mode is worth it.
LLM Inference Cost: The Underlying Logic of Hardware, MoE, and Batching
Why do frontier LLMs take the shape they do in terms of architecture, pricing, and scaling speed? How do you actually calculate MoE inference cost? How do you choose a batch size? What should you do when inference slows down? Is “fast mode” worth it? This article walks through the underlying logic of LLMs from training to inference across several layers: hardware topology, Mixture-of-Experts architecture, batching schedules, and training data constraints.
1. Start with the hardware: models don’t get big out of thin air
The first entry point for understanding large models isn’t the model architecture — it’s the hardware topology they run on.
Today’s mainstream LLM inference typically runs on GPU clusters. A common setup is “multiple GPUs within a single rack”: several GPUs integrated into one rack and connected by high-speed interconnect buses. In this topology, any two GPUs usually communicate in just a few hops, with low latency and high bandwidth. Engineers often call this high-bandwidth, low-latency GPU interconnect range a scale-up domain.
scale-up solves “multi-GPU collaboration within a rack”; scale-out solves “scaling across racks and nodes.” They aren’t the same layer of problem. Intra-rack communication is usually cheap, but once you cross out of the rack, you’re into a conventional data center network or an even more complex cross-domain network.
So here’s a first conclusion:
The architecture choice for a large model often isn’t determined by algorithm preference alone — it’s determined by how large a tightly-coupled computation the hardware topology can support.
High-speed intra-rack interconnect can make multiple GPUs work like a single larger accelerator; cross-rack communication, however, can become a bottleneck. In some deployment schemes, cross-rack network bandwidth may be roughly an order of magnitude lower than high-speed intra-rack interconnect, but the exact gap depends on the interconnect design, link hierarchy, congestion control, traffic patterns, and topology — it can’t be generalized.
This seemingly minor boundary difference directly affects expert-parallel efficiency in MoE models.
2. MoE: how sparse activation turns communication into the critical path
Frontier LLMs widely adopt the Mixture of Experts (MoE) architecture. The core idea of MoE is sparse activation: the model contains many expert subnetworks internally, but when processing each token, it routes only to a subset of experts rather than having all parameters participate in computation.
Take an open-source MoE model as an example: it might have 256 experts, but each token is routed to only about 32 of them each time. The benefit of this design is that the total parameter count can be very large, while the effective compute per token is mainly tied to the number of activated experts — striking a balance between model capacity and inference cost.
A naïve forward pass for MoE can be summarized with the following pseudocode:
def moe_forward(tokens, router, experts, top_k=32):# 1) Router computes gating scores for each token across all expertsgate_scores = router(tokens) # shape: [num_tokens, num_experts]# 2) Keep only the top-k scoring experts to achieve sparse activationtopk_idx, topk_weight = topk_softmax(gate_scores, k=top_k)# 3) Dispatch tokens to the corresponding experts, then combine outputs by weightoutputs = dispatch_and_combine(tokens, experts, topk_idx, topk_weight)return outputs
At the deployment level, the most natural approach is expert parallelism: place different experts on different GPUs, and route each token to whichever GPU holds the expert it’s assigned to. Since a token on any GPU may be routed to an expert on any other GPU, this pattern naturally forms all-to-all communication.
all-to-all communication is highly sensitive to hardware topology. If all the hit experts fall within the same scale-up domain, communication can stay relatively efficient; once expert placement spans across racks, the communication path can lengthen, and both latency and congestion risk rise.
Here it’s important to avoid an absolute claim: you can’t simply say “half of the tokens go cross-rack.” More realistically:
The cross-rack request ratio depends on routing distribution, expert placement, and load balancing — it may range from partial to the majority.
The determining factors include:
- Routing balance: if tokens concentrate heavily on a few hot experts, and those experts sit on cross-rack nodes, the cross-domain ratio rises.
- Expert placement strategy: whether frequently hit experts are placed within the same scale-up domain.
- Load balancing: whether long-tail requests overload certain GPUs or certain experts.
- Network quality: bandwidth, latency, packet loss, and congestion control on cross-rack links.
- Parallelism combinations: whether expert parallelism is mixed with tensor parallelism, pipeline parallelism, and other strategies, further amplifying communication paths.
So a more robust engineering conclusion is:
The rack’s physical boundary largely limits the sparsity and scale ceiling of MoE expert layers. Solutions that control larger high-speed interconnect domains are better positioned to deploy MoE models with higher sparsity and more experts while maintaining acceptable inference efficiency.
When evaluating MoE deployment, watch this checklist:
- Whether core experts are placed within the same high-speed interconnect domain wherever possible;
- Whether the cross-domain token ratio is observable;
- Whether all-to-all communication becomes a throughput bottleneck;
- Whether expert hotspots and load imbalance exist;
- Whether tail latency degrades noticeably due to cross-rack communication;
- Whether throughput, utilization, and per-token cost are measured on a unified basis.
3. Batching: the key variable behind inference cost differences
After understanding hardware and MoE, let’s turn to the economics of inference. Many developers ask: why is fast mode often more expensive, yet the speed gain isn’t fully proportional? Why can the cost difference between batch service and a single request be so large?
The core variable is batch size.
LLM inference is typically memory-bound. Each generated token requires moving the huge model weights from GPU memory to the compute units. If you process only one request at a time (batch size = 1), fixed costs like weight loading, memory access, and scheduling overhead are borne almost entirely by that single request, and hardware utilization tends to be low.
The essence of batching is to merge multiple requests into a single forward computation, so that expensive weight-loading and memory-access overhead is amortized across more requests.
A simplified formula:
per-request cost ≈ fixed overhead / batch_size + marginal compute cost
Here, fixed overhead includes weight loading, memory access, scheduling, and synchronization; marginal compute cost relates to sequence length, number of activated experts, model size, and so on. As batch size grows, fixed overhead is amortized and per-request cost usually drops. But this doesn’t hold indefinitely — the larger the batch size, the more constrained it becomes by GPU memory capacity, sequence length, latency targets, and throughput scheduling strategies.
A rough comparison of different batching strategies:
| Batch size | Fixed overhead amortization | Latency | Hardware utilization | Typical use case |
|---|---|---|---|---|
| batch = 1 | Almost no amortization | Lowest latency | Usually low | Interactive requests, latency-first |
| small batch | Partial amortization | Lower latency | Medium | Real-time chat, online inference |
| medium batch | Fairly well amortized | Controllable latency | Higher | Standard online serving |
| large batch | Highly amortized | Higher latency | High | Offline batch processing, throughput-first |
So when memory-bound and batching is insufficient, per-request cost can be one to several orders of magnitude higher than with full batching. But the specific multiple can’t be discussed out of context — at minimum you need to state:
- model size;
- input and output sequence length;
- GPU model and memory bandwidth;
- interconnect topology;
- batch size;
- number of concurrent requests;
- measurement basis: per-instance-hour cost, per-token cost, or per-request cost;
- whether queueing, scheduling, retries, and network overhead are included.
From this angle, pricing differences aren’t mysterious. Fast mode typically reduces queueing latency by shrinking batch size, or even handling some requests individually, which lowers hardware utilization and raises per-unit cost. Slow mode or offline mode allows requests to queue, accumulate into batches, and compute off-peak, so it can push costs lower — at the price of higher latency.
In other words, many price differences are buying latency, predictability, and resource reservation — not simply “more compute.”
4. The training side: more data isn’t always better
Beyond inference, the training side has similar first-principles constraints.
There’s a view that some frontier models’ pretraining data volume may significantly exceed the theoretically optimal ratio. The reasons aren’t surprising:
- Data ratios, curriculum schedules, and repetition epochs carry uncertainty, and more high-quality data is often more robust than precisely approximating the theoretical optimum;
- In a phase where compute is abundant and data is relatively available, trading data for performance is a common tradeoff;
- The training objective isn’t single-point convergence, but keeping the model stable across a broader distribution;
- Evaluation metrics, data quality, and task coverage affect actual gains — you can’t look only at the theoretical optimum.
But this also means diminishing marginal returns. As data scale keeps expanding, hardware efficiency, data quality, training strategy, parallelism approach, and evaluation systems become the new bottlenecks. For specific multiples or specific data volumes, without a public model, training framework, and measurement basis, they shouldn’t be taken as universal conclusions.
5. Practical advice for developers
Turning these principles into engineering practice yields a few actionable rules of thumb.
5.1 Confirm your deployment topology first
When designing MoE serving, don’t look only at model depth or expert count — first confirm:
- whether experts are distributed within the same high-speed interconnect domain;
- whether cross-rack communication is observable;
- whether all-to-all will become a bottleneck;
- whether expert placement, routing policy, or load balancing can lower the cross-domain ratio.
5.2 Treat batching as a first-class engineering variable
Batching isn’t simply “turn it up a notch.” It’s recommended to benchmark on a unified basis:
- fix input length and output length;
- sweep different batch sizes;
- record time-to-first-token, per-token latency, throughput, GPU utilization, memory usage, and cross-rack traffic;
- compute cost per million tokens or cost per request;
- compare latency targets against throughput targets rather than looking at a single metric.
5.3 Distinguish “expensive” from “fast”
Fast mode usually means lower latency and higher resource reservation; slow mode usually means higher throughput and lower cost. When estimating costs, don’t simply read the price difference as a performance difference — instead distinguish:
- latency targets;
- concurrency levels;
- batching strategy;
- resource reservation;
- service quality requirements.
5.4 Balance data and compute jointly on the training side
Data scale isn’t the only variable. Training plans should adjust dynamically against evaluation metrics, paying attention to data quality, training stability, inference cost, and room for later fine-tuning.
5.5 Use general cloud platform capabilities to reduce engineering complexity
For most teams, LLM training and inference don’t necessarily require building all the infrastructure from scratch. Mainstream cloud platforms can typically provide elastic GPU compute, container orchestration, object storage, monitoring and alerting, logging services, and networking capabilities, letting developers choose a managed or semi-managed approach suited to their workload.
6. Quick answers to common questions
Why is MoE inference expensive?
Because MoE’s sparse routing and expert parallelism add communication, scheduling, and load-balancing costs. If the cross-rack ratio is high, expert distribution is uneven, or the network is congested, costs are amplified further.
How do you choose a batch size?
Latency-sensitive online services usually pick a small batch or dynamic batching; offline tasks or throughput-first scenarios can use larger batches. The key is to benchmark against latency targets, memory capacity, and throughput targets.
Is fast mode worth it?
If the workload demands low time-to-first-token, low tail latency, or a good interactive experience, fast mode may be worth it; if it’s offline generation or a queueable task, slow batch processing is usually more economical.
Conclusion
From the physical boundary of a GPU rack, to MoE’s sparse activation, to the cost differences batching brings, many surface behaviors of frontier LLMs can be traced back to hardware topology, communication efficiency, and engineering economics. For developers, understanding these underlying constraints helps reduce blind trial-and-error in architecture selection, cost estimation, and performance optimization, leading to more robust and interpretable engineering decisions.
