A Practical Guide to Large-Scale LLM Inference Deployment
This guide explains how to deploy large language model inference at scale by starting from deployment conditions and workload characteristics. It covers a four-layer reference architecture, execution-layer optimizations for operators, parallelism, and GPU memory, networking and communication design, scheduling and prefix caching, stability observability, and a cost model based on cost per million tokens. A final checklist helps teams reproduce configurations and prioritize the optimizations that most affect cost and user experience.
1. Background: Two Curves, Capability and Cost
A model’s capability boundary is determined by the model itself, but whether that capability can serve massive numbers of users at an acceptable cost depends on the engineering quality of the inference system. When request volume grows from single digits per second to tens of thousands, inference serving is no longer “one process plus one port.” It becomes a distributed system that spans nodes, racks, and even availability zones. End-to-end performance is then determined not by any single point but by the multiplicative effect of four factors: operator execution efficiency, inter-device communication, request scheduling, and cache management. If any one of them becomes the bottleneck, it consumes the gains from optimizing the others.
For this reason, performance optimization cannot stop at “run a benchmark and look at throughput.” It must be grounded in concrete deployment conditions: which class of accelerator is used, how many cards are installed per machine, how cards and machines are networked, how tensor parallelism and pipeline parallelism are partitioned, how the context-length distribution looks, and what the cache hit rate is. Optimization conclusions drawn without deployment conditions are essentially not reproducible.
2. Four Characteristics of Inference Workloads
To design a system, first characterize the workload. Online inference differs markedly from offline training, mainly in four ways:
- Two-phase behavior: The prefill phase is compute-intensive and processes an entire input at once; the decode phase is memory-access-intensive, generates token by token, and has low arithmetic intensity. The two phases have opposite hardware demands, and running them together causes mutual interference.
- Highly uneven lengths: Input and output lengths follow a long-tail distribution, and a few extremely long requests occupy slots for a long time, causing head-of-line blocking.
- Bursty arrivals: Traffic has clear peaks and troughs, so any static resource allocation inevitably leads to queuing at peak and waste at trough.
- State that cannot be recomputed: Session context and intermediate state cannot be migrated freely as with stateless services, and removing an instance means paying the cost of rebuilding context.
These four points determine all subsequent design trade-offs.
3. Reference Architecture: Layered Decoupling
A deployable large-scale inference architecture is usually divided into four layers:
- Access layer: Handles authentication, rate limiting, protocol conversion, and request shaping, smoothing bursty traffic into a relatively steady internal load.
- Scheduling layer: Maintains a global view and performs instance selection, batch orchestration, and priority isolation; it is the main lever for global throughput.
- Execution layer: Operator execution within a single machine, parallel partitioning, and GPU memory management; it determines the efficiency ceiling per card.
- State layer: Holds reusable data such as prefix caches, session context, and quantized weights; it determines the cost of long-tail requests.
The key value of layering lies in fault-domain isolation and independent evolution: adjusting a scheduling policy should not trigger recompilation of the execution layer, and expanding the cache should not affect the availability of the access layer.
4. Execution-Layer Optimization: Operators, Parallelism, and GPU Memory
4.1 Operators and Computation Graphs
Operator efficiency depends on the degree of fusion and on memory-access behavior. In practice, the three most reliably beneficial techniques are: fusing element-wise operations such as normalization, activation, and residual add into neighboring operators to reduce round trips to GPU memory; adopting memory-access-friendly attention implementations for the decode phase to avoid repeatedly moving the entire KV cache for a single token; and storing weights and activations in low precision uniformly while retaining higher precision at critical accumulation points, so as to increase effective bandwidth while keeping precision under control.
4.2 Combining Parallelism Strategies
The choice of parallelism is essentially a trade-off between communication volume and GPU memory capacity:
Tensor parallelism: partitions a single layer's weights, frequent communication, suited to high-bandwidth intra-machine interconnectPipeline parallelism: partitions layers, low communication volume but has bubbles, suited to cross-machineExpert parallelism: partitions the expert dimension, communication and load balancing are strongly correlatedData parallelism: multiple replicas, the simplest, improves utilization through scheduling
A common engineering practice is to use the high-bandwidth domain inside a machine for tensor parallelism, pipeline parallelism across machines, and data parallelism at the replica layer to serve different traffic shards.
4.3 GPU Memory and Batching
GPU memory is divided among three consumers: weights, the KV cache, and temporary buffers. A stable approach is paged KV management, which turns contiguous memory demand into small blocks allocated on demand, combined with block-level sharing to enable prefix reuse. In scheduling, separate resource pools for prefill and decode, or chunked scheduling within the same pool, reduce mutual interference.
5. Communication and Networking
Communication overhead is often underestimated. Three points need attention: first, topology awareness, placing parallel groups with frequent communication within the same high-bandwidth domain; second, overlap, hiding communication behind computation in time rather than waiting serially; third, compression and quantized transmission, trading controllable precision for throughput on bandwidth-constrained links. Once the networking scheme is fixed, the optimal parallel partitioning changes accordingly, so the two must be designed jointly rather than tuned separately.
6. Scheduling and Caching
The scheduling layer must solve three problems: queuing fairness (allocating slots by priority and quota so long requests do not starve short ones), batch efficiency (forming as large a batch as possible while meeting latency constraints), and elastic scaling (scaling based on queue length and cache-hit trends rather than CPU metrics alone).
The core of the caching layer is prefix reuse: persist the KV of common prefixes such as system prompts, templates, and long documents to external storage, and load it directly on a hit, which can significantly reduce repeated computation. The logic is illustrated below:
def schedule(req):prefix = cache.match(req.tokens) # skip part of prefill on a hitpool = "prefill" if req.need_prefill else "decode"if not admit(pool, req): # admission control to protect latencyreturn queue(req, priority=req.priority)return dispatch(pool, req, prefix)
7. Stability and Observability
Large-scale online services must distinguish throughput metrics from experience metrics: the former looks at tokens/s and utilization, while the latter looks at percentile values of time-to-first-token and inter-token interval, especially P99. The observability system should cover at least four signal types—request tracing, GPU memory and bandwidth watermarks, cache hit rate, and queueing duration—with an alert threshold set for each. For capacity planning, it is advisable to keep watermark headroom for bursts, together with priority degradation and request shaping, so that the core path is protected first under overload.
8. Cost Model
Unit cost should be expressed as “cost per million tokens,” determined jointly by chip utilization, cache hit rate, batch efficiency, and failure retry rate. The recommended optimization order is: first improve hit rate and batch efficiency (zero hardware cost), then adjust parallelism and networking (one-time engineering cost), and only then consider scaling out (ongoing cost). Reversing this order often results in “more hardware but unchanged utilization.”
9. Deployment Checklist
- Are the target deployment conditions clearly defined and recorded as a reproducible configuration?
- Are prefill and decode isolated or chunk-scheduled?
- Is KV managed in pages and does it support prefix reuse?
- Are parallel groups aligned with the high-bandwidth domain?
- Are alerts in place for P99 latency and queueing duration?
- Is cost per million tokens used as the unified optimization yardstick?
10. Conclusion
There is no single silver bullet for large-scale inference deployment. The methodology is: start from deployment conditions, use workload characteristics as the basis, jointly optimize across the four dimensions of operators, communication, scheduling, and caching, and measure the benefit of each step with a unified cost yardstick. With the general capabilities of cloud platforms such as Baidu AI Cloud, categories like container platforms, object storage, message queues, and monitoring and alerting can serve as standard components for building such a system, allowing teams to focus their effort on scheduling strategy and cache governance—the two areas that truly determine cost and experience.
