What actually happens between the moment you hit enter on a chatbot prompt and the moment words start appearing on your screen? It feels instant, but behind that cursor blink sits a chain of tightly coupled steps, each with its own hardware demands, failure modes, and tuning knobs. That chain is the AI inference pipeline, and understanding it is the difference between a model that feels snappy and one that makes users wait.
This article walks through the pipeline stage by stage, explains why the same model can run ten times faster on one setup than another, and covers the mistakes teams make when they first try to serve a model in production.
What the inference pipeline actually is
Training a model is a one-time (if expensive) event. Inference is the permanent one. The inference pipeline is the full path a request travels through a deployed model: intake, tokenization, scheduling and batching, model execution, sampling, detokenization, and response delivery. Some of those stages are pure software plumbing. Others determine whether you need one GPU or eight. (Inference (Wikipedia))
The mental model that helps most: think of the pipeline as two very different workloads stitched together. The first, prefill, processes the entire input prompt at once. It is compute-bound and parallel, because every prompt token can be handled simultaneously. The second, decode, generates output one token at a time. It is memory-bandwidth-bound and strictly sequential, because each new token depends on the last.
That asymmetry drives nearly every serving optimization in existence. Almost everything clever about inference engineering is an attempt to make the sequential part cheaper or to keep the hardware busy while it grinds through tokens.
Stage by stage through the pipeline

Request intake and tokenization
A request arrives with a prompt, a max-token limit, and often sampling parameters like temperature. The tokenizer converts text into token IDs. This stage is cheap, but it is not free at scale, and it is a common source of quiet bugs: mismatched tokenizer versions between training and serving can degrade output quality in ways that look like model problems rather than pipeline problems.
Batching and scheduling
This is where most of the performance is won or lost. Early serving systems waited for a full batch of requests before running a decode step, which meant a short request could sit behind a long one. Modern systems use continuous batching, scheduling new requests into a running batch at every decode step rather than waiting for the whole batch to finish. The effect on utilization is large, and it is now the default approach in serious serving stacks.
Model execution: prefill and decode
The model runs the prompt through its layers (prefill), then generates tokens one at a time (decode). During decode, the model reuses key and value tensors computed for earlier tokens rather than recomputing them. This KV cache is the single biggest memory consumer in LLM serving, and its footprint grows with both context length and batch size.
That growth is why capacity planning is not just about model weights. A model that fits comfortably in memory at a batch size of one can run out of room at a batch size of thirty-two. Anyone sizing hardware should read up on why memory capacity matters for inference planning before ordering GPUs.
Sampling and detokenization
Once the model produces logits for the next token, the sampler picks one according to the configured strategy. Greedy decoding takes the highest-probability token; temperature and top-p sampling introduce controlled randomness. The chosen token is appended, converted back to text, and streamed to the client.
Where the time actually goes
Latency in an inference pipeline is usually described with a handful of metrics, and the definitions matter more than people expect.
| Metric | What it measures | Typical bottleneck |
|---|---|---|
| Time to first token (TTFT) | Request arrival to first output token | Prefill compute, queueing |
| Inter-token latency (ITL) | Gap between successive output tokens | Decode memory bandwidth |
| Tokens per second | Aggregate throughput across requests | Batch size, GPU utilization |
| End-to-end latency | Full request to final token | Everything above combined |
A critical trap: metric definitions differ between tools. Some frameworks include queueing time in TTFT; others start the clock when the request begins execution. Comparing published benchmark numbers across frameworks without checking these definitions produces confident, wrong conclusions. If you are setting up your own measurements, a walkthrough of how to measure inference latency end to end will save you from re-learning this the hard way.
The other structural point is that throughput and latency pull against each other. Larger batches raise tokens per second and lower cost per token, but they also raise inter-token latency for everyone in the batch. There is no universal right answer; there is only the answer that fits your workload, which is exactly the trade-off covered in choosing between batch and real-time inference.
Techniques that change the shape of the pipeline
KV cache management
Because the KV cache is the memory bottleneck, how you store it matters. PagedAttention, introduced with the vLLM serving system in 2023, manages the cache in fixed-size blocks rather than contiguous allocations, cutting fragmentation and allowing far higher batch sizes at the same memory budget. It is one of the clearest examples of a systems-level idea producing a step-change in serving throughput.
Speculative decoding
Speculative decoding, published by Leviathan and colleagues in 2023, uses a small draft model to propose several tokens, which the larger target model then verifies in a single pass. Under stated conditions it preserves the target model’s output distribution while reducing latency, because verification is parallel and cheap relative to generation. The catch: it only pays off when the draft model’s guesses are accepted often, and it consumes extra compute. On tasks where the small model diverges quickly, it can slow things down.
Quantization
Serving in 8-bit or 4-bit precision reduces memory footprint and can raise throughput substantially. Methods like GPTQ, AWQ, and SmoothQuant each take a different approach to minimizing accuracy loss. The honest summary is that accuracy trade-offs are task-dependent and often reported on narrow benchmarks. A quantization recipe that looks free on a multiple-choice evaluation may quietly hurt a structured extraction task. Test on your own data.
Serving frameworks
vLLM, NVIDIA TensorRT-LLM, Triton Inference Server, and Hugging Face Text Generation Inference are the widely used options. Features and performance change fast enough that version-specific documentation is the only reliable reference. For model interchange, the Open Neural Network Exchange format provides an open specification for representing models across runtimes, which helps when the training stack and the serving stack do not come from the same vendor.
A practical mental model for architects
When teams plan a deployment, the pipeline view pays off fastest in architecture decisions. The split between synchronous, user-facing inference and asynchronous, throughput-oriented jobs is usually the first fork in the road, and it is worth thinking through deliberately rather than defaulting to real-time for everything.
A useful checklist before committing to a design:
- Estimate peak concurrent requests and average prompt and output lengths.
- Compute KV cache memory at your target batch size, not at batch size one.
- Decide which metrics you will hold yourself to, and define them precisely.
- Choose a serving framework based on your hardware and model format, then benchmark on your own traffic.
- Load-test with realistic sequence-length distributions, not uniform ones.
Step five catches more teams than any other. Synthetic benchmarks with identical prompt lengths produce flattering numbers that collapse under real traffic, where a few very long prompts can dominate queueing behavior. (NIST Artificial Intelligence overview)
Common mistakes in practice
Sizing for weights only. Model weights are the easy number to find and the least interesting one for capacity planning. The KV cache, activations, and fragmentation overhead routinely add far more than expected.
Benchmarking without pinning versions. A framework upgrade can move throughput by double-digit percentages in either direction. Record the exact version with every benchmark result, or the numbers become folklore.
Ignoring the tokenizer. Tokenizer mismatches and truncation bugs are boring and expensive. Validate that prompt token counts match what you expect before blaming the model.
Treating TTFT as the whole story. A system with excellent time to first token and poor inter-token latency feels worse than the reverse for long outputs, because users read as tokens arrive. Streaming interfaces change which metric users actually perceive.
Skipping the queueing model. At high load, latency is dominated by queueing, not by the model. A pipeline that performs beautifully at 30 percent utilization can fall apart at 80 percent.
Where the pipeline is heading
The broad direction is toward more specialization inside the pipeline rather than a single monolithic model call. Prefill and decode have such different hardware profiles that splitting them across different machines is an active area of systems work. Speculative methods, structured output constraints, and caching of shared prompt prefixes all push in the same direction: do less redundant work per token.
For teams building on top of these systems, the practical implication is that the pipeline is now a design surface, not a fixed cost. You can choose where to spend compute, where to spend memory, and where to accept a latency penalty in exchange for throughput. The broader architectural patterns for doing this well are laid out in a practical enterprise guide to AI inference architecture, which is worth reading alongside this piece.
Conclusion
The AI inference pipeline is less mysterious once you see it as two workloads in a trench coat: a parallel, compute-hungry prefill phase and a sequential, memory-hungry decode phase. Nearly every technique that matters, from continuous batching to PagedAttention to speculative decoding, exists to reconcile those two profiles under real traffic.
The teams that get this right tend to share habits rather than secrets. They define their metrics precisely, they benchmark on their own data with pinned versions, they plan memory around the KV cache instead of the weights, and they test under load that resembles production rather than a clean synthetic curve. None of that is exotic. It is just the difference between reading about the pipeline and actually running one.
FAQ
What is an AI inference pipeline?
It is the complete path a request takes through a deployed model: intake, tokenization, batching and scheduling, model execution (prefill and decode), sampling, detokenization, and response delivery. Each stage has distinct hardware demands, and the pipeline as a whole determines latency and cost.
Why is decoding slower than prefill?
Prefill processes the whole prompt in parallel, so it uses the GPU’s compute efficiently. Decode generates one token at a time, and each step depends on the previous one, so it cannot be parallelized the same way. Decode is typically limited by memory bandwidth rather than raw compute, which is why it dominates latency for long outputs.
What is the KV cache and why does it matter?
The KV cache stores key and value tensors for tokens already processed, so the model does not recompute them at every step. It is essential for reasonable decoding speed, but its memory footprint grows with context length and batch size, making it the main constraint on how many requests a server can handle at once.
Does quantization always make inference faster?
It usually reduces memory use and can raise throughput, but the speedup depends on the hardware, the method, and whether the workload is memory-bound. Accuracy trade-offs vary by task, and results reported on narrow benchmarks do not always transfer. Validate on your own evaluation set before committing.
What is continuous batching?
Continuous batching schedules new requests into a running batch at each decode step instead of waiting for the current batch to finish. It keeps the hardware busy and improves utilization substantially, and it is now standard in modern LLM serving systems.
How should I choose between batch and real-time inference?
Start from the user experience requirement. If a human is waiting on the output, real-time serving with tight latency targets is required. If the output feeds a downstream job, batch processing usually wins on cost per token. Many systems need both, routed by workload type rather than forced into one path.







