Low-Cost LLM Inference Architecture Evaluation: Methods and Practices
This article examines how to evaluate low-cost inference architectures for large language models. It covers model-level techniques such as hybrid attention, sparse mixture-of-experts, external memory and embedding tables, and KV cache compression; inference-time optimizations such as low-bit quantization, kernel fusion, and speculative decoding; a billing-oriented cost model with cache-hit pricing; and a practical framework for trustworthy evaluation using representative task sets, blind testing, and quality and efficiency metrics. The goal is to help engineering teams compare designs and optimizations with consistent assumptions and interpretable measurements.
1. Background: Why Low-Cost Inference Matters
Once large models move from experiments to production, inference costs often consume budget more continuously than training costs. Training is a one-time investment, while inference is billed by request and token; the higher the traffic, the larger the bill. Therefore, at the same output quality, how to reduce compute, memory, and latency overhead per token has become a core engineering problem.
Cost reduction can be approached at three levels. First, model architecture determines the theoretical upper bound of computation and memory usage. Second, inference engineering determines hardware utilization. Third, service pricing and caching strategy determine the unit cost users ultimately pay. These levels interact; focusing on only one metric can lead to wrong conclusions.
2. Main Technical Routes at the Model Architecture Level
2.1 Hybrid Attention
The computation of standard self-attention grows quadratically with sequence length, and the memory of the KV cache grows linearly with sequence length. Hybrid attention uses different types of attention across layers. For example, a few layers keep global attention to handle long-range dependencies, while the remaining layers use sliding-window, linear, or sparse attention to reduce overhead. The inter-layer ratio needs to be determined experimentally; a common design combines multiple local or linear attention layers with one global attention layer.
This type of design mainly saves computation and memory in long-context scenarios. When inputs are short, the benefit is limited. Evaluation should test according to the actual input-length distribution, rather than looking only at the maximum context length supported by the model.
2.2 Sparse Mixture-of-Experts (MoE)
MoE models split the feed-forward network into multiple experts, and a router selects only a few experts for each token to participate in computation. The model can therefore have a large total parameter count while keeping the activated parameter count per token small. Two concepts need to be distinguished here. Total parameters determine model capacity and storage requirements, while activated parameters determine the computation per token. The smaller the ratio between the two, the higher the computational efficiency is usually.
Routing design also affects efficiency. As the number of experts increases, each expert becomes more fine-grained, but routing communication and load imbalance problems also intensify. Engineering practice commonly uses auxiliary losses or other load-balancing strategies to make access to each expert approximately uniform. If some experts are overloaded for a long time, memory and communication bottlenecks during inference are amplified.
Some variants perform expert computation on compressed low-dimensional representations to reduce communication and storage overhead in expert layers. The actual benefit of such designs depends on the specific implementation and needs to be confirmed through benchmarking.
2.3 External Memory and Embedding Tables
Some designs place part of the parameters in lookup tables, for example by expanding the vocabulary or introducing n-gram-like embeddings. Lookup operations require little computation but increase storage. Their value is that they expand model memory capacity at low computational cost.
Deployment needs to address three issues: whether these parameters can be placed outside GPU memory, whether memory-access latency is acceptable, and whether the inference framework can efficiently manage this kind of memory. If lookup hits are scattered, latency may be higher than expected.
2.4 KV Cache Compression
During autoregressive generation, the Key and Value of every generated token need to be cached for reuse in later steps. The number of KV cache bytes per token can be estimated as follows:
KV bytes per token = 2 × layers × KV heads × head dimension × bytes per element
The coefficient 2 corresponds to the two tensors, Key and Value. With bf16, each element occupies 2 bytes. Suppose a model has 80 layers, 8 KV heads, and a head dimension of 128; then each token takes about 320 KB. With a 32k input context, the KV cache for a single sequence requires about 10 GB.
Common ways to reduce KV cache usage include reducing the number of KV heads (e.g., grouped-query attention), reducing the number of layers that need global caching, and applying low-bit quantization to KV. Concurrent requests and context length jointly determine memory pressure, so KV usage is often a key factor limiting service throughput.
3. Engineering Optimizations During Inference
3.1 Low-Bit Quantization
Quantizing weights from 16 bits to 4 bits theoretically reduces weight memory to about one quarter. Quantization introduces error, and the magnitude of the error depends on the quantization method, such as group quantization and per-channel scaling. After quantization, regression tests should be run on target tasks, especially tasks sensitive to numerical error such as mathematical reasoning and code generation.
3.2 Kernel Fusion
During decoding, every generated token requires executing many small operators. Each kernel launch has overhead, and reading and writing intermediate results to memory also slows things down. Fusing multiple operators into a larger kernel can reduce launch count and memory round trips. There are approaches in the industry that fuse an entire layer or even multiple layers into a single persistent kernel, often called megakernel technology. The benefit depends heavily on batch size and hardware, and is usually more pronounced at small batch sizes.
3.3 Speculative Decoding
Speculative decoding first uses a smaller draft model to quickly generate several candidate tokens, then the target model verifies them in one pass. Tokens that pass verification can be kept directly, reducing step-by-step forward computation in the target model. Its benefit depends on how closely the draft model matches the target model. If the acceptance rate is low, the extra draft computation can increase overhead.
3.4 Measuring Decode Speed Correctly
Decode speed is often measured in tokens per second, but there are two definitions. Single-request speed reflects the streaming output smoothness perceived by a user. System total throughput reflects the output capacity per unit of hardware. The two cannot be directly interchanged. When reporting numbers, batch size, input and output length, and concurrency must be stated; otherwise data from different sources cannot be compared.
4. Cost Model: Breaking Down the Billing Structure
Many services split fees into three parts: input that misses cache, input that hits cache, and output. The cost of a single request can be expressed as:
Single-request cost = (missed input tokens × input price + cached input tokens × cache-hit price + output tokens × output price) ÷ unit token count
The following example shows how to calculate single-request cost. The price parameters are for demonstration only and do not represent any actual quote.
def request_cost(input_tokens, cached_tokens, output_tokens,price_in, price_cache_hit, price_out,unit=1_000_000):"""price_* is the amount per unit of tokens.All prices are examples and are used only to demonstrate the calculation method."""if cached_tokens > input_tokens:raise ValueError("Cached tokens cannot exceed input tokens")miss_tokens = input_tokens - cached_tokenscost = (miss_tokens * price_in+ cached_tokens * price_cache_hit+ output_tokens * price_out) / unitreturn costif __name__ == "__main__":# Example: 8000 input tokens, 6000 of which hit cache, and 1000 output tokensc = request_cost(input_tokens=8000,cached_tokens=6000,output_tokens=1000,price_in=1.0,price_cache_hit=0.1,price_out=4.0,)print(f"Single-request cost: {c:.6f} (example units)")
From the calculation, cache hit rate has a large impact on total cost. If a business repeatedly uses the same system prompt or multi-turn conversation history, the prefix hit rate is high, and cost drops noticeably.
When using cache billing to estimate cost, also confirm the platform’s hit rules, including prefix matching method, minimum cache length, and cache expiration time. Different rules can lead to very different actual bills for the same batch of requests. In addition, time-of-day pricing, billing units, and whether tool-call fees are included can also affect cross-comparison results.
5. Designing Trustworthy Model Evaluations
5.1 Constructing the Task Set
Evaluation tasks should come from real business scenarios, not only public benchmarks. Tasks should be stratified by category, covering typical uses such as document processing, information extraction, code assistance, and data organization. Each category needs enough samples; otherwise anomalous results from individual tasks can dominate the overall conclusion.
5.2 Using Blind Testing
Reviewers should not know which model produced an output. Outputs should be randomly ordered, and reviewers’ preferences and reasons should be recorded. Blind testing reduces the influence of brand expectations and order effects on scoring.
5.3 Choosing Appropriate Metrics
At least three types of metrics should be recorded at the same time.
- Quality: score with a unified scale, such as a four-point satisfaction scale.
- Efficiency: use median latency, which is more robust than averages to a small number of very long tasks.
