Skip to content
Athrael.net logoAthrael.net

Introduction to GPU InferenceChapter 2: Serving inference

Inference engines

Lesson 2 of 4 · about 6 min

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.

Inside an inference engine
Requests
Inference engine
API
Scheduler
GPU
Replies
A
B
C
D
Each square in the scheduler is a slot, purple while its request runs prefill and teal while it runs decode. Each square under Replies is one token.

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.

Engine configuration on a 24 GB GPU
Precision
Context length
Requests
24 GB GPU
An 8 billion parameter model on a 24 GB GPU, in an engine that keeps a full context for each slot. Each cell is a quarter of a gigabyte. Grey cells hold the model, and each outlined group is a slot, which fills in purple with a request's prompt and in teal as its reply grows. The sizes are rounded.

Widely used engines

Most engines are open source, which means their code is published for anyone to use and change.

Inference engines
vLLM
Started at the University of California, Berkeley
Runs on
NVIDIAAMDIntel
Strengths
+ Widely used on data center GPUs+ Supported by most serving frameworks
Weaknesses
− Disaggregated serving is marked experimental
SGLang
Hosted by the non-profit organization LMSYS
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
TensorRT-LLM
Developed by NVIDIA
Runs on
NVIDIA
Strengths
+ Optimized by NVIDIA for its own GPUs+ Supports disaggregated serving
Weaknesses
− Runs on NVIDIA GPUs only
llama.cpp
An open-source project, used by applications such as Ollama
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
Each tab has one engine, with a drawing of one of its features.

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.