What we are talking about
Training a model produces a weight file. That file is useless as it stands: it has to be put behind a network interface that applications can call, usually over HTTP, HyperText Transfer Protocol, the protocol of the web. You send text, you get generated text back.
That sounds simple, and it is not, because this service has properties no ordinary web service has: each request occupies the hardware for several seconds, its duration is unknown when it arrives (nobody knows how many words the model will write) and it consumes an amount of memory that grows throughout its processing.
The four constraints
The delay before the first word. The user stares at an empty screen between submitting a question and the first word appearing. That delay is called TTFT, time to first token. It depends on the length of the input text and above all on time spent queuing.
Throughput. The number of tokens produced per second across all requests. This determines how many users one machine can serve, and therefore the cost.
Cost. A data-centre graphics card rented, at the time of writing, for something in the order of a few dollars an hour depending on provider and commitment length. The consequence is brutal: the card is the line item, and every percent of its time spent idle is money burned.
Memory. This is the constraint that governs everything else. A 7-billion-parameter model stored in FP16 takes 2 bytes per parameter, so 2 × 7 billion = 14 gigabytes before it has processed a single request. On top of that sits the attention cache (the keys and values already computed, kept so they need not be recomputed for every new token) which grows with every token produced and every request served. The full accounting is in Inference memory optimization.
We would like a short delay, high throughput and low cost all at once. That is not possible, and the conflict is arithmetic: processing more requests together raises total throughput and lengthens the time each request takes to produce its words. The trade-off is laid out in Continuous batching; a server does not remove it, it lets you choose where to set the dial.
Why a naive server fails
Naive serving means calling the generation function in a loop: one request at a time, the rest wait. The problem is not one of elegance, it is quantifiable, and the number is in Continuous batching: a request processed on its own exploits less than 1% of the card's compute, because the time goes into streaming the model weights out of memory rather than into calculating. It takes roughly 150 requests processed together before the chip stops waiting on data. This is the underlying argument set out in Quantization: the concepts: inference is limited by memory bandwidth.
Put differently, a naive server does not leave 90% of the card unused: it leaves more than 99%. The whole craft of model serving consists in recovering that remainder.
What a server must provide
This is the part of the page that will still be true when the tool names have changed. Seven functions, in the order a request meets them.
1. A queue and admission control. Requests arrive faster than they are processed. They have to be queued, and above all the server has to know how to refuse: accepting a request it cannot serve for lack of memory is worse than rejecting it outright, because it will take other in-flight requests down with it. A serious server declares its capacity and refuses beyond it.
2. Grouping requests. Processing them in batches, and recomposing the batch at every token produced rather than waiting for the whole batch to finish. This is by far the highest-return lever. See Continuous batching.
3. Fine-grained cache memory management. Since the final length of a response is unknown, reserving worst-case memory up front wastes enormous amounts. The solution, borrowed from operating systems, is to cut the cache into fixed-size pages handed out on demand. See PagedAttention.
4. Progressive delivery of the response. Returning words as they come instead of waiting for the end. Technically this is not an optimization (the computation is identical) but it changes perception entirely: the user starts reading while the model is still writing.
5. Monitoring, on the right quantities. A poorly instrumented model server is unmanageable, because the usual web-service indicators say nothing useful here. What has to be measured separately: the delay before the first token, the average interval between two tokens, the number of queued requests, and how full the attention cache is, that last quantity is the server's real fuel gauge, because it is what saturates first and triggers the rejections.
6. Version management. A model changes: new release, new settings, new quantized format. You need to serve two versions in parallel, shift traffic gradually, and roll back without interruption. This is ordinary operations work, except with load times of tens of seconds and tens of gigabytes to move.
7. A stable interface. The interface defined by OpenAI has become the de facto convention. A server that exposes it is interchangeable: change the address in the client code and nothing else changes. That compatibility is not a commercial detail, it is what makes the choice of engine reversible.
Engine feature lists change every month. These seven requirements do not. Faced with an unfamiliar engine, the useful question is not "is it fast?" but "which of these seven does it not provide, and can I live without it?"
vLLM
vLLM, born at the University of California, Berkeley, is the most widely used serving engine. Its original contribution is PagedAttention, paged management of the attention cache.
The idea in one sentence: instead of reserving for each request a contiguous block of memory sized for the longest possible response, the cache is cut into small fixed-size pages, handed out one at a time as needed, with a lookup table recording where each page actually sits. It is operating-system virtual memory, transposed.

The original paper (Efficient Memory Management for Large Language Model Serving with PagedAttention (Kwon et al., 2023)) reports throughput 2 to 4 times higher at the same latency, and it names the baseline: against FasterTransformer and Orca, that is, against systems that were already doing continuous batching. That is what makes the number readable. The authors also put the cache memory wasted by earlier systems at 60 to 80%, against near-zero waste in theirs.
The mechanism, and the page sharing between requests that follows from it, are detailed in PagedAttention.
On the server side, one command exposes a model from the Hugging Face Hub behind an OpenAI-compatible interface:
vllm serve mistralai/Mistral-7B-v0.1 \
--host 0.0.0.0 --port 8000 \
--tensor-parallel-size 2 \
--enable-prefix-caching \
--max-model-len 32768
The four options say most of what sizing means: which address to listen on, how many cards to split the model across, whether to reuse the cache of shared request prefixes, and what maximum context length to plan for. That last value directly determines the memory reserved for the cache, and therefore how many simultaneous requests are possible.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
response = client.chat.completions.create(
model="mistralai/Mistral-7B-v0.1",
messages=[{"role": "user", "content": "Explain model serving"}],
stream=True,
)
The point of that second block: this is OpenAI's own client library, called unmodified, with only the address changed. That is requirement seven from the list above, in practice.
TGI
TGI, Text Generation Inference, is the server published by Hugging Face. Its positioning is the shortest path between a model on the Hub and a production interface.

What TGI specifically brings:
- one-command deployment, as a container, for any model on the Hub;
- automatic splitting of the model across several cards (see Tensor parallelism);
- direct reading of several quantized weight formats (see AWQ and GPTQ);
- progressive token delivery;
- statistical watermarking of generated text: a slight, controlled distortion of how words are drawn, leaving a statistical signature in the text that is invisible to a reader but detectable by whoever holds the key. It lets you verify after the fact that a text came from your model.
docker run --gpus all -p 8080:80 \
ghcr.io/huggingface/text-generation-inference:latest \
--model-id mistralai/Mistral-7B-v0.1 \
--num-shard 2 \
--quantize awq
The techniques a server puts to work
A production server combines several techniques covered elsewhere in this course. They are listed here so the map is legible, not re-explained.
| Technique | What it attacks | Lesson |
|---|---|---|
| Key-value cache | recomputing attention over the whole past at every token | Key-value cache |
| Continuous batching | the card sitting idle between requests | Continuous batching |
| Paged cache | memory reserved in advance for nothing | PagedAttention |
| FlashAttention | memory round trips during the attention computation | FlashAttention |
| Speculative decoding | the strictly sequential nature of generation | Speculative decoding |
| Quantization | the volume of weights to stream out of memory | Quantization: the concepts |
A word on that last row, because it explains why all the others work. Speculative decoding has a small fast model propose several words ahead, then has the large model check those proposals in a single pass. It pays off because checking five words at once costs almost the same as checking one: either way all the model's weights have to be streamed out of memory, and that is what takes the time. An accept-reject mechanism guarantees that the final text follows the large model's distribution exactly: the output is identical, not approximate.

The founding paper (Fast Inference from Transformers via Speculative Decoding (Leviathan et al., 2022)) measures a 2x to 3x speedup, and states its conditions: on the T5-XXL model, against the standard T5X implementation, with identical outputs. That gain does not transfer as-is to another model: it depends entirely on how often the small model guesses right, hence on how close the two models are and how hard the text is. Measured acceptance rates are discussed in Speculative decoding.
Choosing an engine
At the time of writing, the widely used engines (vLLM, TGI, SGLang, TensorRT-LLM behind Triton) all cover functions 1 to 4 and 7 on the list. That is no longer a differentiator. The detailed comparison, with what actually separates them, is in Serving frameworks compared.
As a first approximation:
- vLLM is the default choice: broad feature coverage, large community, fast-moving.
- TGI gets running faster when you already work inside the Hugging Face ecosystem.
- Triton with TensorRT-LLM earns its place when you have to serve heterogeneous models (text, vision, classifiers) on an NVIDIA fleet known in advance, and you have the team to operate it. See TensorRT-LLM.
Numeric rankings of these tools deserve suspicion. A speedup figure means nothing without its hardware, model size, sequence lengths, how many requests are processed together, what precision, and above all the baseline it is measured against. Two claims of a factor of 8 may be measured, one against a naive loop and the other against an already-optimized system: they are not comparable. See the worked discussion in Continuous batching.
What to take away
Serving a language model is not a web-server problem, it is a scheduling problem under a memory constraint. A single request leaves more than 99% of the card unused; the entire job is filling that void without blowing up the attention cache, whose final size is unknown.
The techniques change; the list of seven functions does not: queuing with deliberate refusal, continuous grouping, paged cache, progressive delivery, monitoring the right quantities, version management, a stable interface. That is the grid to apply to any engine, familiar or not.
1. Why is serving requests one at a time, in a simple loop, so costly?
2. The server is nearly out of memory and a new request arrives. What should it do, and why?
3. Does streaming the answer (words sent as they are produced) speed up processing?
4. Which quantity does the page call the true fuel gauge of a model server?
5. Two engines each advertise being 8 times faster. Can you conclude they are equivalent?