The Illustrated vLLM

Put the same model on the same GPU and swap the inference engine, and throughput can differ by 2–4× (measured in the vLLM paper at the same latency). These GPUs are often not using their full compute, while GPU memory (also called VRAM) is already “full”. This article answers: what fills GPU memory? How can vLLM fit several times as many requests into the same GPU memory?

There is only one clue: manage the KV Cache the way an operating system manages memory. We follow the method of “The Illustrated Transformer”: first look from the outside at how an inference server takes requests, then open its GPU memory, its scheduler, and the GPU, one step at a time.

This continues The Illustrated KV Cache and The Illustrated Prefix Caching: the first explains why K and V can be stored, the second explains how to reuse them across requests. This one explains how those K and V are actually laid out in GPU memory, and how an engine decides, at each step, who gets computed first.

Requests differ in length: short ones finish early, and long ones keep holding a slot

Let’s look from the outside first. An inference server is a “requests in, tokens out” interface. Requests arrive at different times. Some finish in 3 steps, some take 8. The figure below: batch size = 4 (at most 4 requests run in the same step), 6 requests (demo values). Three words are marked on the figure — each row on the left is one slot in the batch, and each column is one decode step (every request in the batch emits 1 token in that column), and the number on the colored bar is how many steps it generates.

Why do these three words show up? Because a GPU server has two facts that force you to think this way:

- Request: one question from one user. The server is not serving only you. Many people are asking at the same time, and each question is one request. - Decode step (also called an iteration): a large model emits only 1 token at a time. The next token cannot be computed until the previous one is out (autoregressive). So a 100-character answer runs the whole model from start to finish 100 times, and each run is one step. A step is the model’s smallest beat. - Batch size: at every step the GPU reads tens of GB of model weights once, and that cost is fixed. Taking a few more requests along costs almost no extra time, so computing them together is the best deal. But the number computed together has a cap (GPU memory cannot hold more people’s KV Cache), and that cap is the batch size. batch size = the number of requests the GPU serves in the same step (in vLLM this is the parameter max_num_seqs; in a real system it is also limited by KV Cache GPU memory, and is not a fixed value).

The figure uses 4 only so it fits on the page; a real server can be tens or hundreds. In one sentence: many requests wait in line, and each step lets only as many as the batch size advance, one cell each.

A–F in the figure are 6 requests from different users. The letters themselves mean nothing else: A is just saying hi, and the answer is short (3 steps); B is writing a long essay, and the answer is long (8 steps); C checks the weather (4 steps), D writes a summary (6 steps), E translates one sentence (4 steps), F replies “OK” (3 steps). The batch has only 4 slots at one time, so later arrivals have to wait. This figure only shows the problem: someone leaves early, someone keeps holding a slot. How a freed slot gets filled, and what the old method and the new method each do, is the next figure’s job.

4 checkout counters, 6 customers. The one buying 3 items leaves first and frees a counter; the one buying 8 keeps occupying one. When they are full, later people wait in the “queue” row.

Click Next step and read from left to right. Each letter is one user request: A says hi (3 steps), B writes a long essay (8 steps), C checks the weather (4 steps), D writes a summary (6 steps), E translates a sentence (4 steps), F says OK (3 steps). A and B arrive first. C and D fill all 4 rows of the batch. E arrives with no free slot and waits in the queue row. A runs only 3 steps; in the next column E sits down, and B’s colored bar keeps going through column 8. F cannot enter the batch until C leaves.

The problem is right here: at step 3 A leaves. At step 4, does that row sit empty and wait, or immediately let waiting E fill in? The next figure puts these two approaches side by side.

Click Next step and watch the key moments. Top row, static batch processing: after A leaves, that row stays empty (pink-gray = waste). E and F cannot enter until the slowest one, B, finishes the whole batch. Bottom row, continuous batch processing (continuous batching): the moment A leaves, E takes the slot. The orange outline marks what happens in this step.

Note: the same 6 requests take 12 steps with static batch processing, at about 58% batch utilization; continuous batch processing takes 8 steps, at about 88%. The more gray, the more the GPU sits idle — this is waste at the “scheduling” level, and it has not gotten to GPU memory yet. vLLM’s method is to decide again, at every step, who runs this step (the “scheduler” section later).

But continuous batch processing has one prerequisite: when a new request fills in, GPU memory must have room for its KV Cache. Next, look at GPU memory.

How many requests run at once depends on the roughly 30% of GPU memory left for the KV cache

Take the paper’s example: a 13B-parameter model on one 40GB A100 keeps model weights in about 65% (26GB) of GPU memory, close to 30% for the KV Cache, and the rest is intermediate results. The weights are fixed. The only part that can be given to more requests is this 30%. So how many requests you can serve at once is almost exactly how many requests the KV Cache region can hold.

Top row: what GPU memory is made of. Bottom row: inside the KV Cache region, the share that actually holds a token’s K and V. The earlier systems compared in the paper average only 20.4%–38.2%. vLLM reaches 96.3%.

How big is one token’s KV? (computed for the paper’s OPT-13B)

Criterion: each token stores one K and one V for every layer.

The 40GB in the paper is a 2023 A100. Cards today have much more GPU memory. The table below is GPU memory per card for a few common GPUs (checked on 2026-11-24; numbers follow the vendor’s official page, and unofficial sources are marked):

GPUGPU memory per cardNotes
NVIDIA A10040GB (the model used in the paper)From the vLLM paper; this article did not re-check other specs
NVIDIA H100 SXM80GB HBM3Secondary source, not checked page by page
NVIDIA H200141GB HBM3eNVIDIA official page
NVIDIA B200 (Blackwell)about 180–192GB HBM3eSources disagree (nameplate capacity and usable amount differ); follow the docs for the instance you use
NVIDIA B300 (Blackwell Ultra)288GB HBM3eTom’s Hardware report
NVIDIA Rubin (HGX Rubin NVL8)288GB HBM4, 22TB/sNVIDIA HGX page
AMD Instinct MI300X / MI325X / MI355X192GB / 256GB / 288GBAMD MI350 page
NVIDIA RTX 4090 / RTX 5090 (consumer)24GB / 32GB GDDR5090 from the NVIDIA official page; 4090 from a secondary source

Data-center cards have gone roughly from 80GB to 190–290GB. The larger the GPU memory, the larger the region left for the KV Cache after the model weights, and the more requests you can serve at once. But models are getting larger too, so the question “how much does the KV Cache take” has not gone away. The numbers have just moved to a larger scale.

On the API, max_tokens (also called max_completion_tokens) only limits, for this call, how many more tokens may be generated, and does not count the prompt. The 2048 above is the cap for the whole sequence: the prompt plus what still has to be generated. What the prompt already used, plus max_tokens, cannot exceed the model’s context. Static reservation still occupies KV by this whole-sequence cap. vLLM’s SamplingParams.max_tokens is also only “how many more to generate at most.”

Reserving the maximum length leaves only 20%–38% of KV GPU memory actually storing tokens

The previous section was this: when a slot in the batch frees, fill it immediately. But for this batch, how many slots it can have in total (the batch size), is set by how many requests’ KV Cache the GPU memory can hold. The old method wastes most of it right here and pushes the batch size very low. The two levels each handle one thing, and you have to solve both together for it to work:

What it managesProblem with the old methodNew method
SchedulingWhat to do when a slot in the batch is emptyLeave it empty and wait for the slowest requestFill a request in at every step (continuous batch processing)
GPU memoryHow many slots the batch can have at mostReserve the maximum length, waste GPU memory, and the batch size stays lowPaging allocates on demand, so the batch size can grow

Continuous batch processing without paging: the batch wants to fill a request in, but may fail because GPU memory is full of reservations. Paging without continuous batch processing: when a slot frees, you still wait for the whole batch to finish before filling it.

When a request comes in, the system does not know how long it will finally generate. The safest method is: first, for the maximum length (say 2048), carve out one contiguous region in GPU memory. This creates three kinds of waste (the paper’s categories):

WasteWhat it isWhy it happens
ReservationSlots kept for future tokens that are not used yetThis request is still generating, so other requests cannot use this region
Internal fragmentation2048 was reserved, only 200 was actually generated, and the remaining 1848 is never usedThe output length is not known in advance
External fragmentationFree space is enough in total, but it is cut into small pieces that cannot form one contiguous regionEvery request needs one contiguous region

Add these three up, and in the old systems only 20.4%–38.2% of KV GPU memory actually holds tokens (the previous figure). The root is the “contiguous” requirement: because every request needs one contiguous address range, you have to reserve, and so you have to waste.

PagedAttention cuts the KV Cache into small blocks and allocates them on demand, so waste shrinks to the leftover of the last block

Start with one question: a request’s KV Cache grows one token at a time, and nobody knows how long it will end up. The old method asks for one large region all at once, and the previous section already showed how wasteful that is. Can we give only as much as is used?

An analogy: you need to take notes, but you do not know how many pages you will write.

Map this analogy onto the KV Cache and you get the four words below (they are also the words on the figure):

This is the same idea as “paging” in how an operating system manages memory (block ≈ page, block table ≈ page table), so it is called PagedAttention.

How to read the figure: the top two rows are the logical blocks as request A (blue) and request B (orange) see them. The bottom row is the 8 real physical blocks in GPU memory. The lines in between are the block table. Click Next step. There are 5 steps in all:

  1. A arrives: the prompt has 6 tokens, so it takes only 2 notes (logical blocks 0 and 1). The catalog records them at physical blocks 7 and 1.
  2. B arrives: it takes 2 notes, placed at 4 and 6. A’s and B’s blocks are interleaved in GPU memory, but each one looks contiguous.
  3. A generates 2 more tokens: they are written into empty slots of the last note. No new note is taken.
  4. A’s last block is full: only then does it take one more block (logical block 2 → physical block 3), and the catalog gains one more line.
  5. A finishes: its 3 blocks return to the free pool at once (dashed boxes), and the next request can use them immediately. B is unaffected.

Click Next step and watch one step at a time. The top two rows are the contiguous logical blocks the two requests “think they see.” The bottom row is the 8 real physical blocks in the GPU. The lines in between are the block table (blue = A, orange = B). Cells with an orange outline are tokens newly written in this step: A’s and B’s blocks are interleaved in GPU memory, but each looks contiguous.

That removes all three kinds of waste from the previous section: no reservation (take only as much as you use); internal fragmentation is only the unfilled cells in the last block (at most 15 tokens, not thousands); external fragmentation is gone (every block is the same size, any free block can go to any request, and you never get “enough space in total, but no single contiguous region”).

Why can attention run on “scattered” blocks? (derived from the mechanism, not from a vendor document)

Criterion: each past token’s score q·kj uses only its own K. Where the other tokens sit, and whether they are next to each other, does not matter.

Store the same content once, and copy it only when it has to change

Paging also brings an unexpected benefit: several requests can point at the same physical block. Typical cases are parallel sampling (the same prompt, several candidate answers), beam search, and the prefix caching from the previous article. Their prompt K and V are identical, so there is no need to store several copies.

The hard part of sharing: whoever writes into a shared block affects the others. vLLM does what an operating system does. It keeps a reference count on each physical block, and checks before a write — if the count is greater than 1, copy-on-write first.

Click Next step. S1 writes first: block P1 is shared (ref=2), so it is copied to P2 and then written. When S2 writes, only S2 is still using P1 (ref=1), so S2 writes in place.

Prefix caching is an extension of the same mechanism: after a request finishes, physical blocks are not cleared at once. They stay in the pool under a “content hash.” If the start of the next request has the same hash, the block table points straight at those blocks, and nothing is recomputed. Details are in The Illustrated Prefix Caching.

The scheduler decides again at every step who runs, and frees space when there are not enough blocks

With blocks, we can say how the engine turns. In vLLM (V1) the engine core (EngineCore) does one thing: it calls step() over and over. Each step has three stages:

  1. Schedule: decide which requests run this step, and how many tokens each one computes.
  2. Forward: the GPU runs the model once and samples the next token.
  3. Postprocess: append the new token to the request, and check whether it has finished (EOS, a length limit, a stop string). If it has finished, return its blocks to the pool.

The scheduling stage has two queues: running (the ones being computed) and waiting (the ones waiting in line; first come, first served, FCFS, by default, or by priority). The scheduler first gives the next token to requests in running (a new block if one is needed), then pulls new requests from waiting. Every time it pulls one, it asks the block manager: are there enough blocks in the pool?

Click Next step. On the left is the block pool. On the right are the two queues. Watch step 4: the pool is empty, and the scheduler has to free space.

What if there are not enough blocks? Preemption

Criterion: the goal is to avoid interrupting requests that have already been running for a long time.

Split a long prompt into small chunks so requests that are already generating are not stuck behind it

Two words first. Prefill: once the user’s prompt arrives, the whole prompt (possibly thousands of tokens) is computed in one pass and written into the KV Cache. This step is parallel, computes many tokens at once, and is compute-bound.Decode: after that, tokens are generated one by one, and each request computes only 1 token per step.

What do “compute-bound” and “bandwidth-bound” mean? (an order-of-magnitude estimate)

Criterion: in one step, see whether the GPU is waiting on compute or waiting on data.

What is V1? vLLM has two generations of engine. The old one is called V0, the new one is called V1, and it rewrote the core loop and the scheduler (see the official blog “vLLM V1: A Major Upgrade to vLLM's Core Architecture”). The step() loop and the block management in this article are the V1 form.

Now a problem: if one step does only one kind of work, a very long prompt takes over the whole step. Requests that are already generating have to wait for it to finish before they can emit the next token, and the user sees the output stall for a moment.

V1’s method: the scheduler no longer separates a “Prefill step” and a “Decode step.” Instead it gives each step a fixed cap on work, called the token budget, for example at most 8 tokens per step. The order of assignment is: (1) each request that is decoding takes 1 token first (they only need 1 per step anyway); (2) the remaining budget goes to queued prompts, for Prefill.

Example: the budget is 8, 3 requests are decoding, and a new 20-token prompt arrives. Each step gives 3 tokens to Decode and the remaining 5 to the new prompt. 20 ÷ 5 = 4, so it finishes in 4 steps. During these 4 steps those 3 requests still emit 1 token every step, and none of them is interrupted. The long prompt is cut into small chunks and finished over several steps. That is Chunked Prefill. The official docs say it is on by default when it is feasible.

Drag the slider to change the token budget per step. The smaller the budget, the finer the prompt is sliced, and the more steps Prefill takes, but requests that are decoding are left alone at every step.

Budget size is a tradeoff between throughput and latency. A large budget means high GPU utilization and a fast Prefill, but each step takes longer. A small budget means a short step and smoother output, but Prefill is stretched over more steps.

The scheduler and the block manager work together inside the same loop

Put the earlier pieces together. Note that the KV cache manager and the scheduler live in the same loop: every time the scheduler assigns one token, it asks the block manager for a block, and the block manager tells the scheduler how many free slots remain.

vLLM’s main path (simplified). The API server handles HTTP, tokenization, and detokenization. Inside EngineCore are the scheduler and the block manager. What actually runs the model is the worker on the GPU. It uses the PagedAttention kernel, and CUDA graph to cut the overhead of launching kernels.

The figure leaves a lot out: tensor parallelism across several GPUs, several API processes, disaggregated Prefill/Decode deployment, speculative decoding, and more. “Further optimizations” later touches them.

The shorter the requests, the more paging fits beyond reservation; at the maximum length they tie

Back to the question at the start: how many more requests does this fit? Use the numbers above (a 12GB KV region, 0.8MB per token). The old method reserves the maximum length of 2048 and can hold only ⌊12000/1678⌋=7 of them. After paging, each request occupies only its real length (rounded up to a multiple of 16).

Drag the slider to change the average real length of a request. The shorter the request (relative to the maximum length), the more the old method wastes, and the larger the gain from paging. When the average length is close to 2048, the two are no different.

This is one source of the “2–4× throughput” in the paper: the same GPU memory can hold more requests at once, and the batch the GPU handles each step is larger, so the compute gets fed (derived from the mechanism, not from a vendor document; the paper’s 2–4× was measured on specific models, datasets, and the systems it was compared with).

Paging is not free

Criterion: any indirect addressing has a cost.

Six optimizations, each for one bottleneck, stacked on the main path

Each item below is an important feature in vLLM. This article only points out how it relates to the main path, and does not expand it.

When tuning, start from how many tokens the KV cache can hold

  1. Look first at how much the KV Cache can hold: the startup log reports the GPU KV Cache capacity (counted in tokens). This number, not “how large GPU memory is,” is the ceiling on how many requests can run at once.
  2. --gpu-memory-utilization: the fraction of GPU memory vLLM reserves for itself. After the weights and the intermediate results, the rest goes to the KV block pool. Turning it up means a larger block pool, but leave room for other processes.
  3. --max-model-len: the maximum number of tokens in a single request. Set it larger than you actually need, and the engine treats a single request as possibly expensive, which changes how many requests can be admitted at once. Set it to what the workload actually needs.
  4. --max-num-seqs and --max-num-batched-tokens: the first limits how many requests run at once. The second is the per-step token budget described above. They set the balance between throughput and latency.
  5. Send requests that share a prefix to the same instance: prefix caching works only inside a single engine. Put the prefix at the front of the prompt, and put content that changes (timestamps, usernames) at the end.
  6. Look at the metrics. Do not guess: watch the number of queued requests (waiting), how full the KV block pool is, and the preemption count. Frequent preemption means the block pool is too small or concurrency is too high.
  7. Defaults, and the differences between V0 and V1, change with the version: follow the official docs for the version you use. This article did not check every default.

Mark the parking lot into small spaces and hand them out as cars arrive, and almost nothing is wasted

  1. A GPU is like a big parking lot. Each car is a request that is in the middle of a chat.
  2. The old method: when a car arrives, no matter how big it is, first rope off a large contiguous stretch of spaces, in case it wants to grow. Most of the spaces stay empty, and other cars cannot get in.
  3. vLLM’s method: draw the lot into many small spaces. When a car arrives, give it one or two spaces first. When it needs more, give it one more. The spaces do not have to be next to each other.
  4. Each car holds a small slip that says “my space 1 is at 7, my space 2 is at 1…”. That slip is the block table.
  5. Two cars need to carry the same thing? Their slips point at the same space, and it is stored once. Whoever wants to change it gets a copy first.
  6. When a car leaves, its spaces free up at once for the next car. The lot has almost no waste, and several times as many cars can park.

GPU memory is the bottleneck: paging plus per-step scheduling lets the same GPU serve several times as many requests

Further reading