Reducing LLM Inference Cost: From Execution Efficiency to Communication Optimization
Large-model inference cost is better measured by the resources required per useful output than by peak chip performance. This article explains how to analyze prefill and decode bottlenecks, execution traces, operator fusion, low precision, mixture-of-experts communication, and hardware–software co-design, then validate savings with reproducible benchmarks.
1. The core of inference cost reduction is using fewer resources per useful output
Discussions of high-end AI chips often fall into a common trap: treating peak compute as equivalent to large-model serving capacity. The number of operations a chip can execute is not the same as the volume of useful output a system can deliver steadily every second.
Online large-model inference includes request intake, batching, model execution, cache management, cross-device communication, and result return. Waiting in any stage can leave other resources idle. Compute units may wait for weights to be read from memory, devices may wait for expert results, or the service may be unable to form a large enough batch because of latency targets.
Cost reduction should therefore focus on three questions:
- How much compute, memory access, and communication does each useful output require?
- Can those operations be organized into a more efficient execution process?
- Under a given quality-of-service target, how much sustained load can the system carry?
A simple metric provides a cost framework:
Cost per useful output = total service cost over a measurement period ÷ total useful output over that period.
Total service cost includes not only accelerators, but also hosts, networking, storage, energy, and operations. Useful output should exclude failed requests, ineffective retries, and results that miss business quality requirements.
This view prevents local operator speedups from being mistaken for system-wide savings, and it explains why model structure, chip design, and software scheduling must be analyzed together.
2. Separate prefill and decode before judging hardware bottlenecks
2.1 Prefill: process the input and build state for later generation
Prefill processes multiple input tokens, computes intermediate representations, and produces the key-value cache needed for later decoding. Because work across input positions is highly parallel, this stage usually forms larger matrix operations more easily.
“Prefill is compute-intensive” is only a general rule, not a substitute for measurement. The actual bottleneck also depends on input length, attention structure, batch size, and intermediate data movement. Long inputs can make attention-related compute, cache writes, or temporary memory use the main constraint.
Prefill optimization should therefore watch compute utilization, memory bandwidth, input processing speed, and time to the first output token together. Raising throughput while greatly delaying the first token may not suit interactive workloads.
2.2 Decode: generate step by step while repeatedly reading weights and history
Autoregressive decoding generates output from existing context one step at a time. Each step adds few tokens but may read a large amount of weights and historical cache. At small batch sizes, it is often limited by memory bandwidth, operator launch overhead, and scheduling overhead.
A larger batch lets multiple requests share the compute opportunity created by one weight read, but it also increases cache usage and can lengthen waiting time for an individual request.
The goal is not simply to enlarge the batch. It is to balance memory capacity, throughput, and the interval between output tokens. For long-context tasks, the cost of reading historical cache shifts that balance further.
2.3 Disaggregated deployment is not an automatic gain
Placing prefill and decode in different resource pools can match compute and bandwidth needs more closely and reduce interference between the two stages. It also introduces state transfer, network scheduling, and uneven pool utilization.
Whether to disaggregate depends on a comparison:
Do the gains from independent scheduling and better resource matching outweigh the cost of state transfer and added system complexity?
The design can be more valuable when inputs are long and the two stages have clearly different resource needs. With small request volume or insufficient networking, a shared deployment may be more economical.
3. Execution traces: turn “the device is busy” into an explainable timeline
Execution-trace analysis uses software and hardware observation to record events, timestamps, and related performance data, so the relationship among compute, data movement, and waiting can be understood.
Observation levels must be distinguished. Runtime traces can show task submission, operator execution, and communication events. Hardware performance counters can reflect some resource usage. True instruction-level observation depends on what the hardware and tools expose. An operator timeline alone does not justify a claim of instruction-level analysis.
A rigorous process drills down from the request to the device:
- Request level: record input length, output length, queue time, time to first output, and total latency.
- Execution level: identify operators, data movement, synchronization points, and communication.
- Hardware level: use available counters to observe compute units, memory, and interconnects.
- Instruction level: when observation is available, analyze instruction dependencies, pipeline stalls, and data-access behavior.
The point is not to collect as much data as possible. It is to answer specific questions: do compute gaps come from too little work, data that has not arrived, or synchronization? Is high bandwidth use moving necessary data, or repeatedly reading and writing intermediate results?
Collection itself can add overhead. Keep a baseline with analysis disabled, and compare performance across sampling intensities so measurement does not change the conclusion.
4. Operator fusion and low precision: optimize data flow, not just operation count
4.1 Why operator fusion can reduce overhead
Normalization, linear transforms, activations, and position-related processing often form a continuous data pipeline. If each step runs independently, intermediate results may be written to memory and read again by the next operation.
Fused operators can keep intermediate data on chip when conditions allow, reducing memory round trips, task launches, and synchronization. These gains matter especially in decode, where many operations are fine-grained.
Larger fusion is not always better. A fused implementation may use more registers or on-chip storage and reduce how much work can run at once. Complex control flow can also make maintenance and debugging harder. Compare end-to-end runtime, resource use, and numerical error before and after fusion, rather than counting operators alone.
4.2 Low-precision gains must hold across the full path
Lower precision for weights or some intermediate data can reduce storage and transfer, and can raise compute efficiency when the hardware supports it. Real gains depend on whether the execution path supports that precision end to end.
If every step needs extra conversion, restoration to higher precision, or a slow execution path, the theoretical gain can disappear. Low-precision optimization should evaluate:
- which formats are used for weights, activations, and cache;
- how much extra cost scaling and conversion add;
- whether critical numerical operations need higher-precision accumulation;
- whether quality stays stable for long context, multi-turn dialogue, and specialized tasks.
Validation should not stop at checking whether a single output matches. Also track task success rate, generation stability, and business quality, so the resources saved are redundant rather than useful capability.
5. Mixture-of-experts models: sparse compute does not mean cheap communication
A mixture-of-experts model uses routing to activate only some experts for each token. Total model capacity can grow while the compute activated per step stays limited.
When experts sit on multiple devices, processing one token may include routing, sending it to the target expert, expert compute, returning the result, and aggregation. Compute is sparse, but data movement can become more complex.
5.1 Uneven expert load amplifies tail latency
If some experts receive far more tokens, those devices become bottlenecks. Other devices may finish and still wait for the slower experts.
Optimization should look at the expert load distribution, not only average device utilization. General options include routing load constraints, expert placement changes, and replicating hot experts when resources allow. Each has a cost: replication adds storage and management overhead, while changing routing requires an assessment of model quality.
5.2 Communication optimization must balance message size and waiting time
Combining many small messages can cut communication startup cost, but waiting to gather more tokens can add latency. Sending and computing in chunks can let arrived data start early and create pipeline overlap.
Whether communication and compute actually overlap depends on data dependencies, execution resources, and the interconnect. The benefit cannot be inferred from the schedule alone. Confirm the overlap on a timeline, and check whether communication and compute contend for bandwidth or other resources.
5.3 Placement should match the real interconnect topology
Work that communicates often will wait longer if it crosses slower links. Placement of experts, model shards, and cache state should reflect device connectivity and common data flows.
The goal is not to eliminate all cross-device communication. It is to balance memory capacity, load balance, and link cost. Maximizing locality alone can overload some devices; spreading work evenly can create too much long-distance transfer.
6. Model and hardware co-design: make architectural choices executable
Model structure decides what must run. Hardware and the software stack decide how it runs. If the two are designed in isolation, algorithmic savings may never appear as serving savings.
Sparse attention, for example, can cut some computation, but indexing, data reorganization, and irregular access can be expensive enough that runtime does not fall. Compressing historical state can reduce storage while adding compute or weakening information retention.
Co-design should use end-to-end measurement as feedback:
Propose a structural change — check operator expression and execution support — analyze data flow — verify numerical quality — evaluate serving cost.
Optimization also needs a maintainable implementation path. Heavy dependence on a specific hardware behavior can raise later migration and upgrade costs. Long-term decisions should compare short-term performance gains and software maintenance cost in the same framework.
7. How to prove cost reduction: reproducible benchmarks and acceptance criteria
Any strong cost-reduction claim should state its measurement boundary. API list prices, device purchase cost, and actual inference cost are different concepts and cannot stand in for one another.
A benchmark should at least fix, or clearly disclose:
- model structure, parameter scale, and numerical precision;
- input and output length distributions;
- concurrency, request arrival pattern, and cache hit behavior;
- constraints on time to first output, inter-token interval, and tail latency;
- device count, network conditions, and software versions;
- failure rate, retry rate, and the quality acceptance method.
Test data should not be limited to idealized short requests. Long inputs, long outputs, traffic bursts, and switches between cold and warm caches often reveal production bottlenecks more clearly.
A practical loop has five steps:
Step 1: establish a baseline. Save unoptimized throughput, latency, cost, and quality.
Step 2: locate the bottleneck. Use execution traces to confirm whether the main limit is compute, memory access, communication, or scheduling.
Step 3: change one variable at a time. Validate one change before the next, so multiple changes do not hide the cause.
Step 4: run quality regression and stress tests. Check representative tasks, long context, and high concurrency.
Step 5: roll out to a small share of traffic. Alert on cost, latency, error rate, and quality, and keep a rollback path.
8. Conclusion: durable advantage comes from sustainable system efficiency
A cost advantage in large-model inference is not the direct result of a peak specification or a single benchmark score. It comes from model structure, execution, data movement, communication, and serving scheduling working together.
For developers, the most useful method is to break performance problems into observable execution behavior. For organizations, the priority is to keep lowering cost per useful output while meeting quality and latency requirements.
Only when an optimization can be reproduced, explained, and shown to hold under real business load does a local technical improvement become a reliable business gain.
