AI Video Academy · How LLMs Work · advanced

What Is the KV Cache?

Prefill, decode, and why generating each new token is fast.

0:48 · captions in English · instrumental music, no narration

Transcript

Why does the first token take longest, and the rest stream quickly?

Prefill processes the whole prompt in parallel and stores keys and values. Decoding then adds one token per step.

Without a cache, every step recomputes the whole sequence. With a cache, only the new token is processed.

The cache trades memory for speed and grows with context length.

The KV cache stores keys and values once, so each new token is cheap.

Experiment with this concept in PromptFlowEngine.