LLM Inference Deployment Guide: Pipeline, Architecture, and Efficiency Acceptance Checklist
Training is a one-time investment, but inference is a continuous cost that ultimately determines whether a large model is affordable to run. This guide treats inference as a systems engineering problem—model compression + inference engine + compute scheduling + storage provisioning—and walks through the full inference pipeline and how to troubleshoot common bottlenecks, the three-layer AI Infra architecture of compute, software, and storage, cloud–edge–device layered deployment, and a pre-launch acceptance checklist. It explains how to balance the efficiency–cost–stability triangle and validate every optimization against concrete metrics such as TTFT, TPS, P95/P99 latency, memory usage, and failure rate.
The bottom line: inference decides whether a model is affordable to run
Training is a one-time investment: once a compute cluster finishes its run and produces weights, that cost is fixed. Inference is a continuous expense—as long as the service is running, every request and every generated token consumes compute in real time.
Importantly, there is no universal fixed ratio between the two cost buckets; it depends heavily on the business. In some public cases or specific high-concurrency online services, inference can account for a much larger share of lifecycle cost than training; in low-frequency internal tools or batch workloads, the opposite is often true. Any ratio must be measured against your own request volume, GPU utilization, model size, and context length—do not apply industry numbers blindly.
The link between latency and business metrics should be conditioned the same way. In strongly interactive scenarios (customer-support chat, code completion, real-time assistants), response latency is often strongly correlated with conversion and retention. In weakly interactive scenarios (offline summarization, batch moderation), users are not sensitive to second-level latency. The right approach is to establish your own business baseline first, then validate latency thresholds with load tests and canary experiments—rather than copying a “300 ms / 1 s” rule of thumb.
The takeaway: inference is not a model trick but a systems engineering effort combining model compression + inference engine + compute scheduling + storage provisioning, and it must be tightly coupled with the three-layer AI Infra architecture.
Training vs. inference: different goals, different engineering
The goal of training is to approach the upper bound of accuracy; it can tolerate high compute consumption and long runtimes. The goal of inference is to balance efficiency, cost, and stability at the same time, and it must respond in real time.
| Dimension | Training | Inference |
|---|---|---|
| Core goal | Accuracy ceiling | Efficiency / cost / stability triangle |
| Load profile | Static, offline batch processing | Dynamic, peak-to-trough ratio can be several times |
| Latency requirement | No real-time constraint | Both first token and generation speed must be controlled |
| Cost structure | One-time investment | Continuously accumulates with request volume |
| Resource form | Large-scale training clusters | Multiple online replicas + elastic scaling |
| Monitoring focus | Loss, throughput, convergence | TTFT, TPS, P95/P99, failure rate |
| Failure impact | Can be re-run; affects schedule | Directly affects online availability |
It is precisely these three factors—dynamic load (an education model’s weekday-evening traffic can be several times its daytime load, and an e-commerce peak can be several times the daily average; measure the actual multipliers yourself), low-latency constraints, and 24/7 long-run stability—that elevate inference from “getting the model to run” to “running the system well.”
Breaking down the inference pipeline: five stages and common failures
User request│▼[1] Request preprocessing / tokenization│▼[2] Scheduling & batching│▼[3] Model forward pass (two phases: Prefill + Decode)│▼[4] Output sampling (greedy / Top-K / Top-P)│▼[5] Post-processing / streaming response
- Prefill phase: processes all input tokens in parallel; compute-intensive; determines time to first token (TTFT).
- Decode phase: generates one token at a time via autoregression; memory-bound; determines generation speed (TPS) and overall throughput.
How do you troubleshoot common issues?
- Slow first token? Check the Prefill time share first. Long inputs (large prompts, long context, too much RAG-pasted content) → compress the context and enable prefix-cache reuse; Prefill and Decode interfering with each other (decode blocked by a large batch of prefills) → enable chunked prefill or pool-based scheduling.
- Out of memory? First calculate KV Cache usage with the formula below, then try in order: weight quantization (FP16→INT8/INT4), KV Cache quantization, paged memory management, limiting max context and concurrency, tensor parallelism across multiple GPUs.
- Tuning continuous batching? Focus on three parameters:
max_batch_size(too small leaves the GPU idle; too large increases queuing and memory pressure),max_tokens(overly long sequences occupy slots for a long time), and the memory watermark threshold. The goal of tuning is not maximum throughput but the best throughput under a P95 latency constraint. - Generation slowed down but GPU utilization is low? Usually memory-bound or scheduling overhead; check whether the batch is too small, whether KV Cache is frequently swapped in and out, or whether some operators are not fused.
How the AI Infra three-layer architecture supports inference
The real source of inference efficiency is the deep coupling of compute, software, and storage; a weak link in any layer becomes the bottleneck.
Compute layer: hardware sets the physical ceiling on efficiency
Inference demands different things from hardware than training does; memory often becomes the bottleneck before peak compute does:
- Memory capacity and bandwidth: in the Decode phase, every generated token reads the weights and KV Cache, so memory bandwidth usually matters more than peak FLOPS.
- Memory footprint estimate: per-layer KV Cache ≈ 2 (K and V) × number of tokens × hidden dimension × bytes per element; total ≈ number of layers × 2 × hidden dimension × bytes per element × number of tokens × concurrency. For example, with 32 layers, hidden dimension 4096, FP16, and 4096 tokens per sequence, each sequence’s KV Cache is about 2 GB, and 32 concurrent sequences take about 64 GB—and that is before counting the weights themselves. Doing this calculation during capacity planning avoids most “OOM on launch” incidents.
- Precision tradeoffs: FP16 / INT8 / INT4 quantization can significantly reduce memory usage and boost throughput, but there is some accuracy loss; decide the level after regression testing against your business evaluation set.
- Heterogeneous collaboration: cloud-scale compute handles heavy inference and training; device-side lightweight compute handles low-latency local inference.
Software layer: the inference engine is the efficiency multiplier
On the same hardware, different inference engines can produce end-to-end performance that differs by several times. Key capabilities include model compression (quantization, pruning, distillation), KV Cache optimization (paged memory management, prefix-cache reuse), and dynamic batching and parallelism (tensor parallelism, pipeline parallelism).
The core idea of continuous batching (the code below only illustrates the scheduling idea; it does not include authentication, exception handling, batch capacity management, model loading, or memory-limit checks, and cannot be run directly):
def continuous_batching(request_queue, max_batch_size, max_tokens, model):running = []while request_queue or running:# While the queue is non-empty and the batch is not full, add new requestswhile len(running) < max_batch_size and request_queue:running.append(request_queue.pop(0))# Run one decode step for all active requestsfinished = []for seq in running:token_id = model.decode_step(seq) # returns the next token's idif token_id == model.eos_token_id: # use an explicit EOS check instead of "is EOS"finished.append(seq)elif seq.length >= max_tokens:finished.append(seq)for seq in finished:running.remove(seq) # freed slots go to new requestsyield batch_output(running)
How do you choose an inference engine? Evaluate across six dimensions, not throughput alone:
| Evaluation dimension | Questions to ask |
|---|---|
| Throughput | What is tokens/s at the target concurrency? |
| TTFT | Does first-token latency meet the target under long inputs? |
| Memory efficiency | Does it support paged KV Cache and prefix reuse? |
| Parallelism strategy | Does it support tensor/pipeline parallelism and multi-machine deployment? |
| Compatibility | Are the target model architecture, quantization format, and operators covered? |
| Operational cost | Does it support canary, metrics export, hot updates, and autoscaling? |
Practical advice: load-test with your real traffic distribution (input-length distribution, output-length distribution, peak-to-trough ratio) first, then decide the engine and parameters; don’t make decisions directly from public benchmark numbers.
Storage layer: data supply must not become the bottleneck
Model weights, KV Cache, and externally retrieved knowledge all depend on storage and data pathways. Common bottlenecks and where to check:
- Slow weight loading (shows up as long replica startup time and scaling that can’t keep up) → check object storage bandwidth and parallel download strategy; consider local caching, pre-baked images, and readiness-probe tuning.
- Slow KV Cache swap in/out (shows up as latency jitter in long-context scenarios) → check memory watermark, offload strategy, and host memory / high-speed interconnect bandwidth.
- High external retrieval latency (shows up as large TTFT fluctuations) → check the vector database’s P99 latency and retrieval truncation length; consider parallel retrieval or adding a cache.
The goal is to avoid leaving the GPU idle waiting for data—when the GPU is waiting on IO, you pay for compute and get zero output.
Cloud–edge–device: layered deployment and unified operations
Inference compute is moving from a single form toward a heterogeneous “cloud-scale compute + device-side lightweight compute” extension. The cloud handles large-model heavy inference, offline batch processing, and high-concurrency online services, pursuing extreme throughput and cost amortization; the device handles latency-sensitive lightweight inference, pursuing low latency, privacy protection, and offline availability.
This layering is not a simple division of labor; it requires the infrastructure to provide unified scheduling, monitoring, and operations. The value of common capabilities offered by mainstream cloud platforms or providers—container orchestration, monitoring and alerting, logging, elastic scaling—is precisely that it lets developers focus on the inference logic itself rather than underlying resource management. When selecting a platform, base the decision on whether these capabilities are covered (rather than the brand).
Pre-launch acceptance checklist: from “works” to “affordable”
The moat of inference efficiency comes from three things working together: controllable cost (elastic scaling; avoid paying long-term for a peak), acceptable experience (Prefill/Decode optimization, KV Cache reuse, nearby edge inference), and reliable stability (multiple replicas, canary releases, end-to-end monitoring). Use the checklist below to tick off each item:
- TTFT (time to first token): P50 / P95 targets and measured values; load-test long-input scenarios separately.
- TPS (generation speed): record per-request tokens/s and whole-machine aggregate throughput separately.
- End-to-end latency: P95 / P99, including queuing time—not just model computation time.
- Memory usage: peak usage and KV Cache share; leave a safety margin (reserve headroom for burst concurrency).
- Queue length and queuing time: set limits and alert thresholds to avoid unbounded request buildup.
- Failure rate: timeout rate, 5xx rate, truncation rate, with retry and fallback strategies.
- Scaling thresholds: trigger on queue length or GPU utilization, with a defined cooldown to prevent scaling oscillation.
- Rollback plan: model versions and engine configurations can be switched back quickly; canary batches and observation windows are defined.
In one sentence: LLM inference is never an isolated model trick, but a systems engineering effort of model compression, inference engine, compute scheduling, and storage provisioning. Only by tightly binding it to the AI Infra compute–software–storage three-layer architecture and measuring every optimization against metrics can you turn inference from “works” into something that is “easy to use, durable, and affordable.”
