Pidoku
17vLLM: Scheduler and KV Cache
On this page

vLLM: Scheduler and KV Cache

Module 179 lessons~7h 45m

Lessons, in order

17.a One Scheduling StepScheduler.schedule() is the function vLLM calls once per engine step. It answers one question: which tokens does the GPU process next? 1h 17.b Chunked Prefill and the Token Budget--max-num-batched-tokens is the most consequential tuning flag in vLLM, and it is one number doing two opposite jobs. A request reading its prompt wants it large, so the prompt is read in … 50 min 17.c Priorities, Preemption and QueuesA request's memory need is unknown when it is admitted: nobody knows how long the answer will be. vLLM therefore admits requests optimistically and deals with the consequences. If running … 50 min 17.d Async Scheduling: Planning a Step Before the Last One FinishesTo keep the GPU from idling between steps, vLLM schedules step N+1 while step N is still running. But step N+1 of a generating request must feed the model the token that step N is about to … 55 min 17.e Blocks and the PoolAll the KV cache memory a vLLM engine will ever use is allocated once, at startup, and cut into fixed-size blocks. From then on, "memory management" means moving small Python objects between … 55 min 17.f Prefix CachingIn a causal language model, the keys and values computed for token i depend only on tokens 0 to i. Two prompts that begin with the same tokens therefore have identical KV cache contents for … 55 min 17.g Allocating Slots: One Call, TracedEvery time the scheduler wants to give a request some tokens, it makes one call: kv_cache_manager.allocate_slots(request, num_new_tokens, …). The answer is either the new blocks or None. … 45 min 17.h Sizing the Cache: From Gigabytes to BlocksThe number of blocks in the pool is fixed at startup and never changes. It is the result of one subtraction and one division: take the share of the GPU you allowed vLLM to use, subtract what … 50 min 17.i More Than One Kind of CacheSo far every layer needed the same thing from the cache: room for every token, forever. Many current models break that. Some layers look only at the most recent thousand tokens; some keep a … 45 min

About this module

The two parts that decide vLLM’s throughput: the scheduler (one step, chunked prefill and the token budget, priorities, preemption and asynchronous scheduling) and the KV cache manager (blocks and the pool, prefix caching, allocating slots, sizing the cache, and caches for hybrid models).

Lessons#

#LessonTime
17.aOne Scheduling Step60 min
17.bChunked Prefill and the Token Budget50 min
17.cPriorities, Preemption and Queues50 min
17.dAsync Scheduling: Planning a Step Before the Last One Finishes55 min
17.eBlocks and the Pool55 min
17.fPrefix Caching55 min
17.gAllocating Slots: One Call, Traced45 min
17.hSizing the Cache: From Gigabytes to Blocks50 min
17.iMore Than One Kind of Cache45 min

Previous: vLLM: Foundations and the Request Path · Next: vLLM: Model Execution and Features

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in