Room means KV cache memory, not a count of requests
Capacity means KV cache memory. A request with a 2,000-token prompt and max_tokens of 4,096 can grow to 6,096 tokens of cache.
Llama 3 8B's cache takes 128 KiB a token, as the KV cache lesson works out. That lesson also finds about 65 GiB left for the cache on an 80 GiB GPU.
| Reserve per request | Tokens | Size | How many fit in 65 GiB |
|---|---|---|---|
| the most it might need | 2,000 + 4,096 = 6,096 | 6,096 × 128 KiB = 762 MiB | 66,560 MiB ÷ 762 MiB = 87 |
| what it usually needs | 2,400 | 2,400 × 128 KiB = 300 MiB | 66,560 MiB ÷ 300 MiB = 221 |
The second row assumes the average request really ends at 2,400 tokens.
So admit on the expected size, and let memory grow in pages, as vLLM's paged attention does. Keep preemption, evicting a running sequence to free its memory, as the safety valve when many sequences run long at once.
The constants in the editor are the numbers from the table: 128 KiB of cache per token, and 65 GiB free. Write take(queue, free_kib): pull from the front of the queue while the next request's cache fits in what's still free, and return how many the worker takes. Each queue item is the tokens of cache that request will hold.