The publication AI reads — a remote MCP server, nothing to install.Connect your agent →
Inference and deployment·Updated

Inference and serving: how LLMs answer at scale

The gap between a demo and a product is what happens to memory and GPUs under load.

What happens when a model answers?

Inference is the process of running a trained model to produce an answer, as opposed to training it. For a large language model, answering a prompt means generating tokens one at a time. Each one is chosen by looking at every token that came before it (Kwon et al., 2023, the vLLM paper).

That sequential habit is the whole problem. Each new token depends on all previous ones, specifically on cached key and value vectors from the attention mechanism. So generation cannot be parallelised the way training can. The vLLM paper notes this makes the workload memory-bound: it leans on GPU memory bandwidth far more than on raw compute, which leaves expensive accelerators underused.

Prefill versus decode: why are they different?

The vLLM paper splits a request into two phases. The prompt phase, often called prefill, takes the entire input prompt at once and computes the probability of the first output token, generating key and value vectors for every prompt token in the process. Because all prompt tokens are known upfront, this step runs as matrix-matrix multiplication and uses GPU parallelism efficiently.

The autoregressive generation phase, or decode, then produces the remaining tokens one by one. Each step takes a single new token as input and reuses the key and value vectors cached from every prior step. It computes only the next token's. This step relies on matrix-vector multiplication, which the vLLM paper describes as less efficient. It accounts for most of a request's latency, because the steps cannot run in parallel.

Why does batching matter, and what makes it hard?

Batching, or processing several requests together, improves GPU use because the cost of moving model weights is shared across them, the vLLM paper explains. But naive batching is awkward for two reasons. Requests arrive at different times, so waiting for a full batch delays early ones. And requests have wildly different prompt and output lengths, so padding them to match wastes both compute and memory.

Fine-grained approaches such as iteration-level scheduling, cited in the vLLM paper as used by the Orca system (Yu et al., 2022), batch at the level of a single decoding step rather than a whole request. Finished requests leave the batch and new ones join after each iteration, without waiting for the entire batch to complete. Specialised GPU kernels remove the need for padding.

What limits batch size: the KV cache problem

Even with fine-grained batching, the number of requests a server can handle together is capped by GPU memory. Mostly this means the key-value cache, or KV cache, that holds each request's attention history. The vLLM paper gives a concrete figure: a single token's KV cache for a 13-billion-parameter OPT model takes 800 kilobytes, and a full 2,048-token request can need 1.6 gigabytes.

Systems that store each request's KV cache in one contiguous memory block waste much of it, the vLLM paper found. Pre-allocating for a request's maximum possible length left only 20.4% to 38.2% of reserved memory actually holding token data in the systems it tested. PagedAttention addresses this by splitting the KV cache into fixed-size blocks that need not sit next to each other in memory, borrowing the page-table idea from operating systems. Built into the vLLM engine, this nearly eliminates that waste and lets the KV cache be shared across sequences from the same request, such as parallel samples or beam-search candidates.

Latency versus throughput: what's the trade-off?

Latency is how long one request takes to answer; throughput is how many requests a server completes per unit of time. The two pull in opposite directions. Larger batches raise throughput by keeping the GPU busier, but can slow any individual request's turn in the queue. The vLLM paper reports that its system raised throughput by 2 to 4 times over FasterTransformer and Orca while holding the same level of latency. The gain grew larger for longer sequences, bigger models, and more complex decoding methods such as beam search.

A separate inefficiency sits inside the attention computation itself. The FlashAttention paper (Dao et al., 2022) found that standard attention implementations read and write a full sequence-length-squared matrix to the GPU's high-bandwidth memory, the slower of its two memory tiers. This dominates runtime for memory-bound operations like softmax. FlashAttention restructures the computation to tile it through fast on-chip memory instead, cutting those memory accesses without changing the result. It reports up to 3 times faster attention for sequence lengths up to 2,048 on an A100 GPU.

What do serving engines actually do?

A serving engine is the software layer that takes incoming requests, batches them, manages GPU memory, and runs the model's forward passes efficiently. vLLM, described in the PagedAttention paper, pairs a centralised scheduler with a KV-cache manager that allocates and frees fixed-size memory blocks on demand. It uses a first-come-first-served policy and preempts whole sequences together when memory runs short.

FlashAttention operates one level down, as a GPU kernel that any engine's attention layer can use; the vLLM paper's own prefill step uses a conventional self-attention algorithm of this kind. Both papers point to the same lesson. GPU memory management, not raw compute, usually decides how many requests a given set of accelerators can serve at once.

Key terms

KV cache
The cached key and value vectors from a sequence's earlier tokens, stored so the attention mechanism does not recompute them for every new token.
Prefill
The phase of generation that processes the full input prompt at once, computing the first output token's probability in parallel across all prompt tokens.
Decode
The autoregressive phase that generates each remaining output token one at a time, dependent on all previous tokens in the sequence.
PagedAttention
An attention algorithm that stores a sequence's key-value cache in non-contiguous, fixed-size memory blocks, inspired by operating-system virtual memory paging.
Iteration-level scheduling
A batching technique that adds and removes requests from a batch after every decoding step rather than waiting for the whole batch to finish.
HBM (high-bandwidth memory)
The larger, slower tier of GPU memory, as distinct from the smaller, much faster on-chip SRAM.
Throughput
The number of requests or tokens a serving system completes per unit of time, as distinct from the latency of any single request.

Latest developments

Inference and serving in the news

·llama.cpp releases

llama.cpp ships faster Q8 dequantisation for Intel SYCL backend

A narrow patch, but one of thousands quietly shaping local inference speed

·Hugging Face

Dharma-AI Says Tokenizer Rebuild Cut Inference Cost 77%

Rebuilding a model's tokenizer, not the model, did most of the work

·llama.cpp releases

llama.cpp adds dp4a GEMM kernels to OpenCL backend

A narrow kernel patch, but one more sign mobile GPU inference keeps getting cheaper

·llama.cpp releases

llama.cpp fixes a silent NEON fp32-to-fp16 bug on ARM CPUs

A hardware conversion instruction sat unused while software quietly took over

·Hugging Face

Hugging Face adds native TPU backend via TorchTPU

PyTorch users can now skip torch_xla and JAX to run models on Google's chips

·Hugging Face

PyTorch 2.15 brings FP8 and much faster LLM decoding to Apple's MPS

Hugging Face's Metal kernels cut video VAE memory from 270 GiB to 8 GiB

·AWS Machine Learning

AWS adds bi-directional KV transfer to vLLM for agentic chat

Decode nodes now hand KV cache back to prefill, cutting repeat computation

·AWS Machine Learning

AWS adds structured outputs for Claude models on Bedrock

Constrained decoding promises schema-perfect JSON, no retries required

·arXiv cs.AI

Study finds mobile NPUs waste most of their edge on LLMs

Framework choice, not chip design, decides who wins the phone AI race

·arXiv cs.AI

New CUDA kernels speed Llama inference on Hopper GPUs

FP8 prefill and INT4 decode cut latency, at a small cost in accuracy

·AWS Machine Learning

AWS adds push-based KV transfer to vLLM for faster inference

A new connector cuts time-to-first-token by moving setup work off the critical path

·arXiv cs.CL

A few prompt tokens explain most MoE prefill speed-up losses

Cutting experts during prefill is cheap, but it damages specific tokens, not the whole prompt

·llama.cpp releases

llama.cpp fuses qwen4exp activation chain on CUDA

A four-kernel gating step becomes one, matching an earlier Vulkan fix

·llama.cpp releases

llama.cpp adds Q1_0, Q2_0 quant support for Hexagon NPUs

Snapdragon devices get another notch of compression for on-device inference

·llama.cpp releases

llama.cpp adds in-app model discovery and download resume

A built-in Hub browser, resumable downloads, and an HTML sanitization fix

·llama.cpp releases

llama.cpp patches Hexagon NPU attention bug in b11696

A single fix for Qualcomm's HMX flash-attention sinks ships in the latest build

·llama.cpp releases

llama.cpp b11690 trims memory copies in speculative decoding cache

A single-line fix, but it is the kind that adds up at scale

·arXiv cs.LG

Meta details how it made AMD GPUs production-ready for training

Porting recommendation models from Nvidia to AMD took more than a driver swap

·Hugging Face

IBM packs chat, decisions and speech into one Granite endpoint

Granite Switch 4.1 adds adapters, not GPUs, to cover three task types

·llama.cpp releases

llama.cpp v0.7.0 adds MoE GPU cache, new default server port

A new expert cache and port change reshape how MoE models get served

Written from the documents above by The Neural Net’s automated desk (claude-sonnet-5, theneuralnet/guides@1) without human review, and updated as news on this topic publishes. How this works.