Module 5 · Evaluation & deployment
High-performance serving with vLLM and TGI
6 min read
A fine-tuned model is only worth something if it answers quickly, to many users, at a controlled cost. The Transformers generate function, used in Forge for evaluation, is not built for that: it processes a fixed batch, waits for the longest answer, wastes memory. Serving engines — vLLM first among them — multiply throughput significantly on the same GPU. This lesson explains why, and how to serve a fine-tuned model, with or without an adapter. Note: vLLM requires a more recent GPU than the course's and a Linux system; the commands in this lesson were not executed on Forge's hardware.
What limits throughput
Generating a token requires reading all of the model's weights: the operation is limited by memory bandwidth, not by compute. Serving one request at a time therefore leaves the GPU largely idle. The solution is to process many requests together — but each request has its own length, and each occupies a KV cache that grows with every token (lesson 1.3).
Two techniques make the difference:
| Technique | Problem solved | Principle |
|---|---|---|
| Continuous batching | With a fixed batch, short requests wait for the longest | At each generation step, finished requests leave and new ones enter |
| PagedAttention | A KV cache reserved in one block wastes memory (fragmentation, reservation at the maximum) | The cache is split into pages allocated on demand, like an operating system's virtual memory |
The result: many more simultaneous requests in the same memory, and a GPU kept busy all the time.
Serving with vLLM
vLLM exposes an API compatible with OpenAI's: existing clients work without change. The commands are in serving/serve.sh, the client in serving/client.py.
# Modèle fusionné (adaptateur LoRA intégré aux poids, leçon 5.3)
vllm serve ./runs/merged --served-model-name nimbus-tri --max-model-len 2048
# Ou : modèle de base + adaptateurs LoRA chargés à côté, choisis requête par requête
vllm serve Qwen/Qwen2.5-0.5B-Instruct --enable-lora \
--lora-modules tri=./runs/sft-lora reponses=./runs/dpo-sigmoid-0.1 --max-lora-rank 16
(First a merged model, with the LoRA adapter folded into the weights; or the base model with LoRA adapters loaded alongside, chosen request by request.)
from openai import OpenAI
from forge.config import SYSTEM_PROMPT
message = "Bonjour, la lampe Halo ne s'allume plus du tout, est-ce pris en charge ?"
client = OpenAI(base_url="http://localhost:8000/v1", api_key="inutile-en-local")
response = client.chat.completions.create(
model="tri", # le nom de l'adaptateur : le même serveur sert plusieurs spécialisations
messages=[{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": message}],
temperature=0, max_tokens=64,
)
print(response.choices[0].message.content)
The model field names the adapter: the same server serves several specializations. Multiple adapters are LoRA's economic argument in production: a single base model in memory, dozens of specializations (per task, per customer), each a few dozen MB.
Merged or adapter?
| Merged model | Base + adapters | |
|---|---|---|
| Latency | Minimal | Slightly higher (adapter computation) |
| Memory | One model per specialization | One base model for all |
| Update | Republish the full model | Replace a file of a few MB |
| Quantization | Direct (AWQ, GPTQ, GGUF) | Quantized base + full-precision adapters |
On Forge, Transformers inference of an unmerged DoRA adapter took 465 ms per message, versus 155 ms for LoRA: some variants are expensive as long as they are not merged. Always measure in the production configuration.
Other engines
| Engine | Strengths | Typical use |
|---|---|---|
| vLLM | Throughput, continuous batching, multiple LoRAs, wide choice of models and formats | Production GPU server |
| SGLang | Very fast, cache reuse across requests, fast structured outputs | GPU server, workloads with shared prefixes |
| TGI (Hugging Face) | Integration with the Hugging Face ecosystem | Historical; Hugging Face now points towards vLLM and SGLang — check its status before starting |
| llama.cpp / Ollama | CPU, Mac, small GPUs; quantized GGUF format | Local workstation, embedded, low volume |
For Forge's triage task (short JSON outputs), the engine's structured outputs — generation constrained by a JSON schema — guarantee format validity even when the model errs. vLLM and SGLang offer them; it is a cheap safeguard to add on top of fine-tuning.
Measuring a server
The indicators that matter to the user and to the budget:
| Indicator | Definition |
|---|---|
| TTFT (time to first token) | Delay before the first token: what a user of a streaming interface perceives |
| TPOT (time per output token) | Time per subsequent generated token: the reading speed |
| Throughput | Tokens generated per second, all users combined: what sets the cost |
| p95 / p99 latency | The time of the slowest requests, under real load |
These indicators degrade with load: measure them with a realistic traffic generator (production prompt and answer lengths, number of simultaneous requests), not with an isolated request. vLLM provides benchmarking tools for this.
The deployment checklist
- Same chat template as in training (lesson 2.3): the server applies it, check which one.
- Same generation parameters as in evaluation (temperature 0 for a classification task).
- Non-regression evaluation on the server itself: quantization and different kernels can change outputs.
- Limits: maximum context length, number of simultaneous requests, timeout.
- Observability: latencies, throughput, error rate, and a sample of requests for continuous evaluation.
Key takeaways
- Generation is limited by memory bandwidth: serve many requests together.
- Continuous batching and PagedAttention multiply throughput on the same GPU; vLLM and SGLang implement them.
- vLLM exposes an OpenAI-compatible API and serves several LoRA adapters on a single base model.
- Merge for latency, keep adapters for flexibility; measure in the production configuration.
- Measure TTFT, TPOT, throughput and p95 under realistic load, and rerun the evaluation on the server.
Practice
- On a Linux machine with a recent GPU, serve the merged model from
examples/08_merge_quantize.pywith vLLM and query it with the OpenAI client. - Serve the base model with two adapters (triage and replies) and check that each behaves as in Forge.
- Measure TTFT and throughput with 1, 8 and 32 simultaneous requests: from what point does latency degrade?