LLM Inference and AI Infrastructure: How Serving Workloads Shape System Design
This article explains why LLM inference, not training, determines whether a model deployment succeeds in production. It covers how inference differs from training in goals and constraints, translates those constraints into four measurable infrastructure capabilities, and outlines the recommended order for cost optimization. Readers will learn how elastic compute, layered GPU memory management, continuous batching, and tail-latency observability work together to move a model from demo to production.
1. The Misread Deployment Order: Training Is Only the Starting Point
When enterprises first adopt large language models, resources and attention tend to concentrate on training: preparing corpora, designing the architecture, and tuning hyperparameters repeatedly until validation metrics look good enough to declare the project a success. Once the system starts receiving real production traffic, the problems surface all at once — time to first token is slow enough that users abandon the request, requests queue up and time out during peak hours, and the bill accumulates day by day until it becomes unsustainable. The model ends up demoted to a “technical showpiece” in a demo environment.
One judgment has long been overlooked: training is a one-time investment, while inference is a continuous expense. The cost of pretraining a model with hundreds of billions of parameters, plus cleaning and feeding petabyte-scale corpora, is locked in the moment training finishes. Inference is different — as long as the service is online, every request and every generated token consumes compute and incurs cost in real time. Over a one-year lifecycle, inference typically accounts for 70% to 90% of total spending, while training accounts for only 10% to 30%. In public industry discussions, a single training run for one generation of a large model has been cited in the tens of millions of dollars, while daily inference costs after launch can reach millions of dollars — meaning roughly ten days of serving can offset the entire training cost. The comparison makes the point: training investment sets the ceiling on capability, while inference efficiency determines whether the business model can close.
2. Why Inference Is Harder Than Training: A Completely Different Objective Function
Training pursues the upper bound of accuracy and can tolerate high consumption and long runtimes: a thousand-GPU cluster running continuously for weeks, offline data processing, no concurrency pressure. As long as the final metrics are met, the result can be reused by every subsequent request. Inference has an entirely different objective function. It must optimize efficiency, cost, and stability simultaneously, and it faces three constraints that do not exist during training.
The first is dynamic load. An education application may see evening request volumes several times higher than daytime volume; an e-commerce application may see peak promotional traffic on the order of ten times normal daily volume. The system must adapt to peak-to-trough swings in real time rather than provisioning resources statically against an average.
The second is the rigid boundary on latency. Latency is not a soft “lower is better” metric but a hard constraint with a business threshold. In customer service scenarios, once peak-hour response time exceeds a few hundred milliseconds, consultation conversion drops noticeably. In on-device conversation, a response slower than one second leads to a sharp decline in user retention. This means the optimization target is often tail latency (P95/P99), not average latency.
The third is the long tail and uncertainty. Input length distributions are highly uneven, and output length is unknown until generation completes. A single long request can occupy GPU memory for an extended period and block subsequent requests, creating head-of-line blocking.
3. Translating the Inference Problem into an Infrastructure Problem
In engineering terms, the constraints above reduce to four measurable infrastructure capabilities.
Elastic compute supply. Inference load is hard to predict, so a container platform with autoscaling is needed, along with a compute buffer. Queues and priorities should also separate online interactive traffic from offline batch traffic so the two do not crowd each other out.
Layered GPU memory and host memory management. GPU memory is the scarcest resource in inference. Allocation and reclamation of the KV cache must be managed centrally, paged management can reduce fragmentation, and inactive cache entries can be swapped out to host memory when necessary, trading larger batches for higher throughput.
Request scheduling and batching strategy. Static batching is simple but has poor tail latency. Continuous batching dynamically swaps requests in and out at each decoding step and can significantly improve GPU utilization. Illustrative pseudocode for the strategy:
# Pseudocode: expresses scheduling intent only, not a specific product APIwhile serving:batch = scheduler.form_batch(max_tokens=BUDGET)outputs = engine.step(batch) # advance all active sequences in one forward passfor seq in batch.finished(outputs):stream.send(seq) # return the first token ASAP to reduce perceived latencyscheduler.evict_or_swap(idle_seqs) # reclaim or swap out GPU memory to relieve head-of-line blocking
- Observability and capacity governance. You must collect metrics such as time to first token, inter-token generation interval, queueing time, batch size, cache hit rate, and cost per token. Combined with logging services and monitoring alerts, these metrics support a capacity model that turns “scale up” from a judgment call into a data-driven decision.
4. The Right Order for Cost Optimization
Cost reduction should not start with cutting compute. It should be ordered by leverage: first, model-side optimization (distillation, quantization, sparsification — reducing computation while keeping accuracy acceptable); then cache reuse (prefix caching, semantic caching, which stop repeated requests before they reach the model); then scheduling optimization (continuous batching, request prioritization, separating long and short requests); and only last, adjustments to resource specifications and elasticity policies. Reversing the order usually costs accuracy without a matching improvement in cost.
Architecturally, tiered inference is an option: a lightweight model handles high-frequency simple requests while complex requests are escalated to a larger model; on-device handles local lightweight conversation while the cloud handles long context and complex reasoning, with a unified gateway performing routing and rate limiting.
5. Conclusion
The dividing line for LLM deployment is not training but inference. Design inference as a first-class citizen — absorb peak and trough with elastic compute, raise throughput with layered GPU memory and continuous batching, constrain experience with tail-latency metrics, and measure operational quality with cost per token — and the model can genuinely move from demo to production. Baidu AI Cloud’s combination of capabilities across general infrastructure categories such as container platforms, object storage, and logging and monitoring is a common foundation choice for supporting this kind of inference system.
