Module 7 · AI infrastructureLesson 74 of 887 minAdvanced
Model serving
Serving a model means running it behind an API for many users at once: the classic scaling problems, but with expensive GPUs.
Try it
Raise traffic until response times climb, then add GPU servers. Compare the two routing algorithms, and crash a GPU.
Training happens occasionally; inference (using the model) happens every time a user asks something. For most products, serving is where the cost and the engineering are.
The pieces
- Model server: loads the weights onto one or more GPUs and exposes an API. Popular engines: vLLM, TensorRT-LLM, SGLang, Hugging Face TGI, Triton.
- Router / gateway: authenticates, rate limits, and sends each request to a replica with capacity, often by queue depth rather than round robin, because request lengths vary wildly.
- Replicas: several copies of the model for capacity and redundancy.
- Autoscaler: adds replicas based on queue length or GPU utilization.
What's different from web serving
- Requests are long and varied: one request might take 50 ms, another 60 seconds.
- Cold starts are slow: loading 140 GB of weights takes minutes. Keep warm capacity and cache weights on local disks.
- GPUs are expensive and scarce: idle GPUs burn money; running out means queueing. Utilization matters a lot.
- Memory, not CPU, is the usual limit: how many concurrent requests fit depends on KV cache memory.
Metrics that matter
- Time to first token (TTFT): how long until text starts appearing. Driven by queueing and prefill.
- Inter-token latency / tokens per second per user: how fast the text flows.
- Throughput: total tokens per second per GPU, which drives cost.
- Queue length and GPU memory use: early warnings.
The next lessons cover the techniques that make serving efficient: quantization, batching, KV caching and paged memory.