Architecture Practices for High-Concurrency, Low-Cost LLM Inference
Cost-efficiency has become the core constraint for putting large language models into production. This article breaks down a reusable technical approach across four layers: model architecture (hybrid attention to shrink KV cache, sparse experts that decouple total and activated parameters, externalized memory, and scaling ladder experiments), training and alignment (self-distillation from a stronger teacher plus reinforcement learning that optimizes the task-completion-to-length ratio), evaluation (internal test sets built around real office and development deliverables, with unified cost accounting per completed task), and inference deployment (low-bit quantization, operator fusion and high-performance decoding kernels, continuous batching with paged KV management and prefix caching, plus elastic scaling and observability). It also presents a simplified cost and latency model showing that cache hit rate, output length, and decoding throughput are three orthogonal levers for reducing unit cost.
1. Background: Cost-Efficiency Is Now the Core Constraint for LLM Adoption
In enterprise applications, competition over model capability is shifting from “benchmark scores” to “cost per completed task.” A model may perform well on public evaluations, but if a single task consumes several times the output length and inference time a business budget allows, it will struggle to reach production. The industry has gradually converged on a shared view: an LLM inference solution should be assessed along four dimensions at once — intelligence level, end-to-end latency, cost per task, and deployment scalability.
Behind this constraint sit three hard engineering metrics:
- KV cache footprint: determines GPU memory usage and the concurrency ceiling for long-context scenarios;
- Output length: directly and linearly affects decoding time and billing cost;
- Decoding throughput: determines how much output each unit of compute produces.
The rest of this article uses “how to build a cost-efficient inference model” as the main thread and unpacks reusable techniques layer by layer.
2. Model Architecture: Compress Inference Overhead with Sparsity and Externalized Memory
2.1 Hybrid Attention to Reduce KV Cache
Standard multi-head attention caches the key-value pairs of all historical tokens, so memory usage grows linearly as context length increases. A common industry approach is to design attention in layers: some layers keep global attention to preserve long-range dependency modeling, while others use local windows or low-rank compressed attention that retain only a limited range of states. This hybrid structure can compress the KV cache to a fraction of its original size with almost no loss in long-document comprehension, which significantly raises the number of concurrent requests a single GPU can serve.
2.2 Sparse Experts and Decoupling Total Parameters from Activated Parameters
The core value of a sparse expert structure is decoupling “model capacity” from “compute per pass”: total parameter count determines knowledge capacity, while activated parameter count determines the compute and memory-access cost per token. In engineering practice, fine-grained expert partitioning is usually combined with a load-balancing loss to avoid routing collapse caused by a few experts overheating. Note that sparse structures shift pressure from compute to memory bandwidth and expert-parallel communication, so a sensible parallel partitioning strategy is required.
2.3 Externalized Memory: Moving Static Knowledge Out of Parameters
One direction worth attention is separating factual, enumerable knowledge from the parameters and placing it in an independent memory structure that is retrieved and injected on demand during inference. The benefits: parameter count does not have to grow linearly with knowledge volume, and knowledge updates require no retraining. The cost: a retrieval path and consistency-maintenance overhead are introduced. In practice, focus on retrieval hit rate, the context budget consumed by injected content, and cache invalidation strategy.
2.4 Validating Architectural Gains with a Scaling Ladder
Structural changes cannot be judged by a single point comparison. A more reliable approach is to build a scaling ladder: train short-horizon baselines across a set of model sizes from small to large, observe whether the target metrics (loss, downstream tasks, KV cache footprint) converge steadily with scale, and only then decide whether to scale up to the target size. This substantially reduces the risk that “a structure works on small models but fails on large ones.”
3. Training and Alignment: Inherit Capability First, Then Compress Output
3.1 Self-Distillation to Inherit a Stronger Model’s Capability
A common post-training path is to have a more capable teacher model generate high-quality trajectories and reasoning processes, then supervised fine-tune the student model on them, obtaining comprehensive capability close to the teacher at relatively low cost. Key engineering points include tiering data by difficulty, using rejection sampling to filter out low-quality trajectories, and retaining a certain proportion of real business data to avoid distribution drift.
3.2 Reinforcement Learning to Optimize the “Task Completion / Length” Ratio
Output length is often the largest cost variable. Including task correctness, format compliance, and a length penalty in the reward function at the same time can guide the model to significantly shorten redundant reasoning while maintaining success rate. In practice, prefer verifiable rewards (such as code execution results, table structure validation, and file artifact checks), and use an annealing schedule for the length penalty to avoid over-compression that damages accuracy early on.
Illustrative reward design:
def reward(resp, task):correctness = verify(task, resp) # 0~1, objective score for verifiable taskslength_pen = max(0, len(resp) - budget) / budgetfmt_pen = 0.0 if check_format(resp) else 1.0return correctness - alpha * length_pen - beta * fmt_pen
4. Evaluation: Make Metrics Reflect Real Work Products
Public leaderboards that are far removed from day-to-day work easily mask real experience problems. A more reliable approach is to build an internal evaluation set aimed at typical office and development tasks, covering document writing and editing, presentation generation and revision, human-AI collaborative writing, spreadsheet repair, and audio/video and visual understanding, while recording three kinds of metrics at the same time: artifact usability rate (human ratings), average output length per turn, and end-to-end latency plus cost per task.
Key evaluation design points:
- Task tiering: report short Q&A, single-turn generation, multi-turn revision, and tool-calling tasks separately;
- Unified cost accounting: bill per “completed task” rather than per token price;
- Human and automatic evaluation in parallel: automatic evaluation ensures regression efficiency, human evaluation calibrates real satisfaction.
5. Inference and Deployment: Raise Throughput, Lower Unit Price
- Low-bit quantization: quantizing weights to around 4 bits, combined with per-channel scaling and mixed precision for sensitive layers, can greatly reduce memory footprint and bandwidth pressure; watch closely for quality regression in long-context inference and numerically sensitive tasks after quantization.
- Operator fusion and high-performance decoding kernels: fusing small operators such as attention, normalization, and residual connections into a few large kernels reduces memory reads/writes and launch overhead, and is a key lever for improving decoding throughput.
- Scheduling and batching: continuous batching, paged KV management, and prefix cache reuse (caching hits for system prompts and long documents) can significantly lower average cost.
- Elasticity and observability: general cloud capabilities such as container platforms, log services, and monitoring and alerting can handle elastic scaling and full-chain tracing, automatically scaling up and down based on queue latency and memory watermark.
A simplified cost model helps with capacity planning:
cost per task ≈ (input tokens × input price + output tokens × output price) / cache hit rate correctionend-to-end latency ≈ queue time + input tokens / prefill throughput + output tokens / decode throughput
This shows that improving cache hit rate, compressing output length, and raising decoding throughput are three orthogonal levers for cutting cost and increasing efficiency.
6. Conclusion: Cost-Efficiency Is Systems Engineering, Not a Single Trick
Cost-efficient inference does not rely on any one piece of “black magic”; it is the combined result of architectural sparsity, training and alignment, evaluation calibration, and inference optimization. Practical advice for developers: first use a scaling ladder to validate the architecture, then use self-distillation plus verifiable reinforcement learning to compress output, then gate quality with an internal evaluation set that mirrors real tasks, and finally use low-bit quantization, operator fusion, and prefix caching to push unit cost into a range that supports large-scale deployment. Baidu AI Cloud can provide standardized support for the engineering implementation of such inference architectures through general capabilities (such as container platforms, object storage, and logging and monitoring services), helping teams refocus their optimization efforts on the model and the business itself.
