What this lesson covers
Previously we looked at replicas and the architectures for serving a model across them. Each replica is run by a program called an inference engine. This lesson covers what an engine does with a request, how its configuration divides a GPU’s memory among requests, and a few engines that are widely used.
What is an inference engine?
An inference engine is the program that runs a model on a GPU. When it starts, it reads the model’s parameters, also called its weights, from a file into the GPU’s memory, which takes seconds for a small model and minutes for a large one. This is the time a replica spends loading the model in a cold swap.
The engine then accepts requests from applications and tokenizes each prompt. A part of it called the scheduler selects the requests that run at every step, which is where continuous batching takes place, and the model runs their prefill and decode on the GPU. The engine usually sends each reply back one token at a time.
Applications send their requests through an API, or application programming interface, which is the set of requests a program accepts from other programs. Most engines accept the format that OpenAI defined for its own service, known as an OpenAI-compatible API, so an application written for one engine usually works with another.
Engine configuration
An operator starts an engine with a configuration, in which the model and its precision, the context length and the number of slots set how the GPU’s memory is divided. The model and its precision set the memory the model takes, the context length is the largest number of tokens that one request’s prompt and reply can hold together, and the number of slots is the most requests the engine runs at once.
Most engines reserve the memory left after the model when they start and use it for KV caches. Some engines give each slot room for a request at the full context length, which is what the diagram below shows. Others, such as vLLM, share the memory among the requests and allocate it in small blocks as each one grows. In both cases a longer context length leaves room for fewer requests, and a lower precision leaves room for more.
Widely used engines
Most engines are open source, which means their code is published for anyone to use and change.
- Runs on
- NVIDIAAMDIntel
- Strengths
- + Widely used on data center GPUs+ Supported by most serving frameworks
- Weaknesses
- − Disaggregated serving is marked experimental
- Runs on
- NVIDIAAMDIntel
- Strengths
- + Disaggregated serving is built in+ A replica can change role in place, as an early option
- Weaknesses
- − A smaller community than vLLM
- Runs on
- NVIDIA
- Strengths
- + Optimized by NVIDIA for its own GPUs+ Supports disaggregated serving
- Weaknesses
- − Runs on NVIDIA GPUs only
- Runs on
- Most personal computers
- Strengths
- + Runs with little setup+ Fits a model by lowering its precision or splitting it between the GPU and the CPU
- Weaknesses
- − Built for one computer, with aggregated serving by default
vLLM, SGLang and TensorRT-LLM are built for data center GPUs and many concurrent requests, while llama.cpp is built for a single computer and runs on consumer GPUs and on CPUs.
Recap
An inference engine loads a model into a GPU’s memory, accepts requests through an API and generates each reply. Its configuration sets the model’s precision, the context length and the number of slots, and the memory left after the model has to hold the KV cache of every request in progress. vLLM, SGLang and TensorRT-LLM are widely used on data center GPUs, and llama.cpp on personal computers.
The next lesson covers serving frameworks.
Athrael.net