22/34
Part 5 of 7 · Alignment and growthLearn and do

vLLM grows a request's cache by one same-size block at a time, from anywhere

Real systems often avoid growing in place altogether. vLLM is one example.

A pool of same-size blocks
01234567
block
c1c2c0

c0, c1 and c2 are one request's cache, and the block table maps them to blocks 7, 2 and 5. To grow, c3 takes any free block, such as 0. The block numbers are made up for the picture.

vLLM is a serving engine for large language models. It doesn't grow a request's cache of attention keys and values, the KV cache, in place at all.

It takes one contiguous chunk of GPU memory for caches and cuts it into blocks of one fixed size. Each request gets a block table that says where its first block sits, its second, and so on. A cache grows by one block from anywhere there's room, so it never needs the run right after it. And since all blocks are the same size, any free block fits.

Its paper: "Separating logical and physical KV blocks allows vLLM to dynamically grow the KV cache memory without reserving it for all positions in advance, which eliminates most memory waste in existing systems." The price is each request's last block, partly empty.

When an interviewer asks how a model server grows a cache, give this answer before growing in place. The KV cache lesson covers it as paged attention.

blocks_needed(tokens, block_size) and wasted(tokens, block_size) count the same-size blocks a request's cache fills, and the empty slots in its last block, the price vLLM pays. Write both.