What Is LLM Inference? How AI Models Generate Responses
LLM inference transforms static model weights into real-time responses through continuous batching, compute-bound prefill, and memory-bound token decoding.
Highlights
3 clips · 3 min of 8 min-
- Processing individual requests wastes massive GPU resources and tanks throughput.
- Continuous batching slots new requests in as soon as older ones finish to keep hardware near full utilization.
-
- Prefill reads the entire prompt at once to build the KV cache, making it compute-bound.
- Decode generates tokens one by one and relies on the KV cache, making it memory bandwidth-bound.
-
- Time to first token (TTFT) measures the duration of the prefill phase.
- Inter-token latency (ITL) measures the speed of each step in the decode phase.
That’s all the highlights.
Questions this video answers
9 · every answer cites the moment it was said01 What does an inference engine do? 2 sources · 1:16
An inference engine takes static model weights and turns them into a system that can serve requests reliably and at scale. It manages GPU resources, schedules incoming requests, and decides how to process work together. Examples of inference engines include vLLM, Ollama, and Llama CPP.
02 Why do inference engines use OpenAI compatible endpoints? 2 sources · 1:45
Most inference engines expose standard OpenAI compatible endpoints so developers can use the same request format regardless of the underlying model. This makes it easy to swap one model for another in an application without rewriting any code.
03 How does tokenization impact prompt costs? 2 sources · 2:15
Tokenization breaks text into tokens and maps each one to an arbitrary token ID that the model processes. This step dictates your prompt cost because you are billed per token. While larger vocabularies represent text more efficiently with fewer tokens, they introduce computational overhead during training.
04 How does continuous batching optimize GPU usage? 2 sources · 3:49
Processing individual requests one by one wastes enormous amounts of GPU resources and tanks system throughput. Continuous batching groups requests together and immediately slots a new request in as soon as a previous one finishes. This mechanism keeps GPUs running near full utilization at all times.
05 What happens during the prefill phase? 2 sources · 4:40
During the prefill phase, the model reads the entire prompt at once to build an understanding of it and lays down a key value cache. This step requires huge bursts of parallel math, making it compute-bound and limited by raw hardware computation capacity.
06 Why is the KV cache necessary for long conversations? 2 sources · 4:40
The KV cache acts as a running memory of everything the model has read so far in the conversation. Without it, the model would have to reprocess your entire conversation over again for every single token it wants to output.
07 How does the decode phase generate tokens? 2 sources · 5:19
The decode phase generates the model's response one token at a time through repeated forward passes that produce a probability distribution over the vocabulary. Each generated token depends on the previous ones and requires referencing the entire KV cache.
08 Why is the decode phase memory bandwidth bound? 2 sources · 6:07
Unlike the prefill phase which demands raw compute, the decode step is limited by how fast data can move out of memory rather than raw math capacity. Prefill wants raw compute, while decode wants fast memory access.
09 What do TTFT and ITL measure? 2 sources · 6:25
Time to first token measures how long the prefill step takes before the user receives the first token. Inter token latency measures the time delay between individual tokens received by the user during the decode phase.
Section-by-section summary
5 parts
Inference costs and engine basics
Inference occurs every time a model generates a response, eventually costing more over time than the initial training phase. Inference engines like vLLM or Ollama manage these requests to ensure reliable and scalable serving.
Tokenization and hardware routing
Incoming requests are sent to OpenAI-compatible endpoints and translated into token IDs via tokenization, which dictates prompt costs. The inference router then directs the request to the most optimized available hardware.
Continuous batching maximizes GPU utilization
Processing single requests sequentially destroys system throughput. Modern engines use continuous batching to dynamically slot new requests in as soon as active ones complete.
Prefill and decode computational differences
Inference splits into a compute-bound prefill phase that builds a KV cache and a memory-bound decode phase that generates tokens sequentially. The KV cache prevents conversations from slowing down as context length grows.
Benchmarking latency metrics
System performance is evaluated using time to first token for prefill speed and inter-token latency for decode speed. Together, these metrics define the real-time responsiveness experienced by users.
n next · p previous clip · t highlights/full
< > slower/faster · / search what was said
-
Inference engine2× · first 1:16
Software that manages a pile of weights to serve requests reliably and at scale.
-
Tokenization1× · first 2:15
The process of breaking text into tokens and mapping each to an arbitrary token ID.
-
Continuous batching1× · first 4:00
A scheduling technique where completed requests are immediately replaced by new ones to keep GPUs utilized.
-
Prefill phase4× · first 4:25
The compute-bound phase where the model reads the entire prompt at once and builds the KV cache.
-
KV cache3× · first 4:40
A running memory of everything the model has read so far in the conversation.
-
Decode phase4× · first 4:25
The memory bandwidth-bound phase where the model generates response tokens one at a time.
-
Time to first token1× · first 6:25
The latency metric showing how long the prefill step takes to deliver the first token.
-
Inter token latency1× · first 6:35
The latency metric measuring the time interval between tokens during the decode phase.
1,128 words · about 5 min to read
Inference costs and engine basics
Training a Frontier model can cost hundreds of millions of dollars and take months. But once that model is produced, it's just a huge set of numbers sitting idly in memory. A model doesn't know how to do anything on its own. So what's going on behind the scenes to bring that model to life? That process is called inference. And LLM inference is behind most modern chatbots, code assistants, and agentic applications today.
Inference happens every single time someone sends a message to the model as opposed to training which only happens once. A trained model is a static pile of weights or specialized numbers that are tuned during the training process to represent information. Inference is the process of taking that train model and running it against new input to produce some sort of output.
Inference surprisingly usually costs more over time than training as it reoccurs with every single request. As time goes on, it becomes more and more crucial to serve models as efficiently as possible to reduce this cost. Today, we'll look at what really happens between prompt and response and how you can make that serving process as fast and cheap as possible. The software that manages inference is called an inference engine.
And its job is to take a pile of weights and turn it into something that can serve requests reliably, quickly, and at scale. That means scheduling incoming requests, managing GPU resources, and deciding how to process work together. If you've ever heard of vLLM, Ollama, or Llama CPP, these are all examples of inference engines. Let's take a look at what happens when you send a message to an LLM.
Tokenization and hardware routing
Most inference engines expose a standard OpenAI compatible endpoint, which means you can use the same request format to send your query regardless of which model is running under the hood. This is super helpful when you have an application built to call one model and want to easily swap in another without rewriting any code. But before that request even enters the data center, we need to translate it into a format that the model can understand.
This process is called tokenization. Breaking your text into tokens which might be entire words, just a piece of a word or some punctuation and mapping each one to an arbitrary token ID. The model never really sees these words, only the stream of IDs. Though it takes next to no processing power. This step defines how much your prompt will cost as its build per token.
Models with larger vocabularies can represent text more efficiently using fewer tokens per prompt, but a larger vocabulary adds computational overhead in the training process. Your request needs to be processed on physical hardware. In most cases, that hardware lives in a data center. Once your request arrives at the data center, it will be authenticated via an API key or token, something that proves you're allowed to use those GPU resources.
Continuous batching maximizes GPU utilization
Next, you'll be routed to specific hardware. The inference router looks at your prompt, how long it is, what content it contains, and routes it to available hardware that's most optimized for your request at that time. However, your request isn't the only one coming in, and sending each request through the model individually would be like a bakery using an industrial oven on a single pastry at a time.
It would waste enormous amounts of GPU resources and would tank the systems throughput or how many requests a system can carry at once.
1 Highlight · Continuous batching for high GPU throughput
Batching groups requests together so the GPU processes them as one larger more efficient unit of work Not all requests take the same amount of time to process. So modern engines use continuous batching. As soon as one request finishes, another one will be slotted in to take its place. That way GPUs sit near full utilization at all times. A scheduler will handle this batching process and get your requests routed to the hardware where the real computation is performed and your response is generated. Let's double click into this last step.
Prefill and decode computational differences
2 Highlight · Prefill versus decode phase bottlenecks
LLM inference contains two distinct phases, prefill and decode. Once your request reaches the model, it enters the prefill phase. Prefill is where the model reads the entire prompt at once and builds an understanding of it, laying down what's called the key value or KV cache.
A running memory of everything it's read so far. Without it, the model would have to reprocess your entire conversation over again for each token it wants to output. It's the reason your conversations don't get exponentially slower as they get longer. This step is computebound, meaning it takes huge bursts of parallel math. So its speed is limited by how much raw computation the hardware can support at once.
Next, that KV cache is passed over to the decode phase. Decode is where the model's response is generated one token at a time. On each step of decode, the model runs a forward pass and produces a probability distribution over every token in its vocabulary. Essentially, this is a ranked list of what token could potentially come next.
Once a token gets selected from the distribution, it gets appended to the sequence and the entire process starts over again with each token generated. Each token depends on the ones before it, and for each step, the model also has to refer back to this entire KV cache to remember the information it learned in prefill. This step is memory bandwidth bound, meaning its speed isn't limited by how much math it can do, but by how fast data can move out of memory.
Prefill wants raw compute, while decode wants fast memory access. This is also where two common benchmarking numbers come from. Time to first token or TTFT
Benchmarking latency metrics
3 Highlight · Time to first token and inter-token latency
is how long it takes for the first token to be received by the user. This effectively shows you how long your prefill step is taking. And inter token latency or ITL, this is the time it takes between tokens to be received by the user. This essentially shows how long each step of your decode phase is taking.
Together, these make up most of what people mean by an LLM's latency. Inference is how a static trained model actually generates a response. Every request is scheduled into batches to keep hardware busy across uneven requests. Requests are routed to hardware, moved through a computebound prefill phase, and a memory bandwidthbound decode phase. Put together, this is the machinery that sits between a trained model and a product people can actually use in real time.
Hit me with any follow-up questions in the comments or let me know which part of your inference stack you're already optimizing.


