Skip to content
Skip to lesson
Back to Topics
LearnGPU Systems & LLM InferenceKV Cache & PagedAttention
HardInference Optimization15 min read

KV Cache & PagedAttention

Paging packs growing KV state into reusable blocks, but a full pool, a shared prefix, and a slow first token are three different problems.

On this page

A coding assistant receives a repository question with system instructions, file excerpts, a failing test, and earlier tool results. Every generated token must attend back to that history. Recomputing every earlier attention projection on every step would turn a response into quadratic replay.

Instead, the engine retains each attention layer's Key (KK) and Value (VV) vectors in GPU HBM as the . Each decode step projects only the newest token, appends (kt,vt)(k_t, v_t), and reads the cached history. and shrink each token's footprint, yet placement remains the bottleneck: variable-length requests can strand 60% to 80% of VRAM inside oversized contiguous reservations. (introduced in ) adapts operating-system paging to store KV state in fixed-size reusable blocks, unlocking near-zero fragmentation, copy-on-write branching, and cross-request prefix caching (RadixAttention and chained block hashes).[1][2]

Why the KV cache exists

In full causal , generating token t+1t+1 attends over positions 1…t1 \dots t:[3]

Attention(qt,K1:t,V1:t)=softmax ⁣(qtK1:tTdk)V1:t\text{Attention}(q_t, K_{1:t}, V_{1:t}) = \text{softmax}\!\left(\frac{q_t K_{1:t}^T}{\sqrt{d_k}}\right) V_{1:t}

Without a cache, generating TT tokens recomputes 1+2+⋯+T=O(T2)1 + 2 + \cdots + T = O(T^2) Key/Value projections. Caching writes ktk_t and vtv_t once per position (O(T)O(T) projections total), though full causal decode still reads all tt cached positions at step tt, making long-context decode memory-bandwidth bound.[1]

Three aligned decode snapshots show one new K/V pair at steps one, two, and five. Earlier pairs stay in the cache and each query reads the visible prefix; future slots remain empty. Full-model Llama 3 8B payloads are 128, 256, and 640 KiB. Pair boxes are a single-head schematic.
One new token's K/V pair appends per decode step while the query reads the entire visible history (Llama 3 8B adds 128 KiB per token).

KV cache memory analysis

Every cached token stores both KK and VV across every layer and KV head:

Bytes per token=2×nlayers×nkv-heads×dhead×Pbytes\text{Bytes per token} = 2 \times n_{\text{layers}} \times n_{\text{kv-heads}} \times d_{\text{head}} \times P_{\text{bytes}}

In , nkv-heads=nheadsn_{\text{kv-heads}} = n_{\text{heads}}. Under , multiple query heads share one KV head: Llama 3 70B has 64 query heads and 8 KV heads, cutting FP16 KV storage 8×8\times from 2.5 MiB/token down to 320 KiB/token (1.25 GiB at 4K context, 10 GiB at 32K, 40 GiB at 128K).[4][5]

ArchitectureLayersKV Headsdheadd_{\text{head}}Cache/token (FP16)4K Context32K Context
Llama 3 8B (GQA)328128128 KiB512 MiB4 GiB
Llama 3 70B (GQA)808128320 KiB1.25 GiB10 GiB
GPT-3 175B (MHA)96961284.5 MiB18 GiB144 GiB
Three equal-width bars partition the same 40 GiB payload-only KV pool. Llama 3 8B fits 80 half-GiB requests, Llama 3 70B fits 32 1.25-GiB requests, and the extrapolated GPT-3 175B shape fits two 18-GiB requests with 4 GiB free. Segment sizes use one common 0-to-40-GiB scale.
Raw full-retention KV capacity inside a 40 GiB pool at 4,096 tokens: 80 Llama 3 8B requests, 32 Llama 3 70B requests, or 2 MHA 175B requests.
calculate-kv-cache-footprint.py
def cache_gib(layers: int, kv_heads: int, head_dim: int, bytes_per_value: int, tokens: int) -> float:
    return (2 * layers * kv_heads * head_dim * bytes_per_value * tokens) / (1024 ** 3)

for label, heads in [("MHA-64", 64), ("GQA-8", 8), ("MQA-1", 1)]:
    print(f"{label}: {cache_gib(80, heads, 128, 2, 4096):.2f} GiB at 4K tokens")
Output
MHA-64: 10.00 GiB at 4K tokens
GQA-8: 1.25 GiB at 4K tokens
MQA-1: 0.16 GiB at 4K tokens

Memory fragmentation and PagedAttention

Early serving engines avoided repeated reallocation by reserving one contiguous buffer sized for max_model_len (e.g., 8,192 tokens) when each request arrived. That static reservation created three distinct forms of waste totaling 60% to 80% of KV VRAM:[1][6]

  1. Internal fragmentation: A request reserves 8,192 slots and stops at token 600, locking 7,592 unused slots until exit.
  2. Reservation waste: Even slots that a sequence will eventually reach sit idle for hundreds of decode steps.
  3. External fragmentation: Variable-sized reservations free scattered holes that cannot satisfy a larger contiguous allocation.
Dynamic block assignment lets C enter the 10-block pool while A and B are growing, whereas upfront max-length reservations lock C out.

PagedAttention borrows operating-system virtual memory paging:[1]

  • Logical blocks divide each request's token positions into fixed-size pages of BB tokens (commonly B=16B = 16).
  • Physical blocks form a uniform pool of fixed-size VRAM slots that need not be contiguous.
  • A per-request block table translates logical position ii to (block_table[⌊i/B⌋],  i mod B)(\text{block\_table}[\lfloor i / B \rfloor],\; i \bmod B).
With block size four and valid length five, A maps logical block zero to physical block 19 and logical block one to physical block 7. Positions 0 through 3 fill block 19; position 4 maps by divmod(4, 4) = (1, 0) to block 7 slot 0. The other three slots in block 7 remain owned by A but invalid for attention. B owns separate physical block 12.
Request A's block table `[19, 7]` preserves logical token order across scattered physical blocks while `valid_length = 5` excludes the three trailing empty slots in block 7.

Paging eliminates external fragmentation inside the uniform pool and caps per-request waste to at most B−1B - 1 unfilled slots in the final block (0%0\% at exact multiples of BB, 6.25%6.25\% at 120 tokens with B=16B=16). Choosing BB trades finer sharing and lower tail waste (smaller BB) against smaller block tables and more regular vector loads (larger BB; vLLM's sweet spot is typically 16 or 32).

Paged kernels vs. contiguous virtual memory (vAttention)

PagedAttention requires attention kernels that follow the block table per warp. In vLLM's original microbenchmark, block-table indirection added 20% to 26% attention-kernel latency over FasterTransformer's contiguous kernel, while recovered VRAM unlocked larger batches for 2–4×2\text{--}4\times higher end-to-end throughput.[1] vAttention takes the opposite trade-off: it reserves contiguous virtual address ranges and commits physical GPU pages on demand via CUDA virtual-memory APIs, letting unmodified contiguous attention kernels run while shifting complexity into driver page management.[7]

Also keep PagedAttention distinct from [8] and FlashInfer:[9] PagedAttention is a KV memory layout and allocator, whereas FlashAttention/FlashInfer are IO-aware GPU attention kernels that read tiled Q/K/V (including paged KV layouts) with minimal HBM round-trips.

Block manager implementation and read parity

The CPU-side manager below tracks free physical block IDs and per-request block tables, then verifies that gathering KK and VV through scattered blocks reproduces contiguous attention exactly while excluding invalid trailing slots:

implementation-sketch.py
class PagedKVCacheManager:
    def __init__(self, num_blocks: int, block_size: int):
        self.block_size = block_size
        self.free_blocks: list[int] = list(range(num_blocks))
        self.block_tables: dict[str, list[int]] = {}
        self.seq_lens: dict[str, int] = {}

    def allocate(self, request_id: str) -> None:
        if request_id in self.block_tables:
            raise ValueError(f"request already allocated: {request_id}")
        if not self.free_blocks:
            raise MemoryError("KV block pool exhausted")
        self.block_tables[request_id] = [self.free_blocks.pop()]
        self.seq_lens[request_id] = 0

    def append_slot(self, request_id: str) -> tuple[int, int]:
        blocks = self.block_tables[request_id]
        idx = self.seq_lens[request_id]
        if idx > 0 and idx % self.block_size == 0:
            if not self.free_blocks:
                raise MemoryError("KV block pool exhausted")
            blocks.append(self.free_blocks.pop())
        self.seq_lens[request_id] = idx + 1
        return blocks[-1], idx % self.block_size

    def free(self, request_id: str) -> None:
        if request_id in self.block_tables:
            self.free_blocks.extend(self.block_tables.pop(request_id))
            del self.seq_lens[request_id]

manager = PagedKVCacheManager(num_blocks=20, block_size=4)
manager.allocate("A")
slots = [manager.append_slot("A") for _ in range(5)]
manager.allocate("B")
b_slot = manager.append_slot("B")
manager.free("A")
print("A slots:", slots, "| B slot:", b_slot, "| free after freeing A:", len(manager.free_blocks))
Output
A slots: [(19, 0), (19, 1), (19, 2), (19, 3), (18, 0)] | B slot: (17, 0) | free after freeing A: 19
compare-paged-and-contiguous-attention.py
import numpy as np

pool = PagedKVCacheManager(num_blocks=4, block_size=2)
k_pool = np.full((4, 2, 2), 1000.0, dtype=np.float64)
v_pool = np.full((4, 2, 2), 999.0, dtype=np.float64)
k_seq = np.array([[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]], dtype=np.float64)
v_seq = np.array([[2.0, 1.0], [0.0, 3.0], [4.0, 2.0]], dtype=np.float64)

def write(req, kv_k, kv_v):
    b, o = pool.append_slot(req)
    k_pool[b, o], v_pool[b, o] = kv_k, kv_v

def read(req):
    n = pool.seq_lens[req]
    return k_pool[[pool.block_tables[req][i // 2] for i in range(n)], [i % 2 for i in range(n)]], \
           v_pool[[pool.block_tables[req][i // 2] for i in range(n)], [i % 2 for i in range(n)]]

def attend(q, k, v):
    s = (k @ q) / np.sqrt(k.shape[-1])
    w = np.exp(s - np.max(s))
    return (w / w.sum()) @ v

pool.allocate("A"); write("A", k_seq[0], v_seq[0])
pool.allocate("B"); write("B", np.array([-1.0, 0.0]), np.array([-5.0, -5.0]))
write("A", k_seq[1], v_seq[1]); write("A", k_seq[2], v_seq[2])

q = np.array([1.0, 0.5], dtype=np.float64)
expected = attend(q, k_seq, v_seq)
actual = attend(q, *read("A"))
assert pool.block_tables["A"] == [3, 1] and np.allclose(actual, expected, atol=1e-12)
assert not np.allclose(attend(q, k_pool[[3, 3, 1, 1], [0, 1, 0, 1]], v_pool[[3, 3, 1, 1], [0, 1, 0, 1]]), expected)
print("A table:", pool.block_tables["A"], "| output:", tuple(round(float(x), 6) for x in actual))
Output
A table: [3, 1] | output: (2.461842, 1.90474)
Spatial block-table mapping for paged KV read parity (block size 2). Left block tables show A table [3, 1] with valid_length = 3 and B table [2]. Arrows connect A logical block 0 to physical block #3 (valid positions p0 and p1) and A logical block 1 to physical block #1 (valid position p2 in slot 0; invalid sentinel K=(1000,1000), V=(999,999) in slot 1 excluded by valid_length). B maps to physical block #2. Bottom readout confirms q=(1, 0.5) gives identical paged and contiguous attention output (2.461842, 1.904740).
A's block table `[3, 1]` reproduces contiguous attention `(2.461842, 1.904740)` while `valid_length = 3` excludes the sentinel tail and B's block.

Copy-on-write branching and prefix caching

Block tables unlock two distinct kinds of KV sharing: intra-request branching (beam search, Best-of-N parallel sampling) via reference-counted Copy-on-Write (CoW), and cross-request reuse via prefix caching / RadixAttention.

Copy-on-write for shared partial blocks

When branches A and B fork from one prompt, both block tables point to the same physical blocks with ref_count = 2. Full shared blocks stay read-only while each branch appends into its own new block. The subtle bug sits in a shared partial block: if A and B share 3 slots of a 4-slot block, letting both write into slot 3 lets B overwrite A's token in place. Trigger CoW whenever ref_count > 1: copy the 3 valid slots into a private block for A, decrement the original block's count to 1, and let B write the original in place.[1]

isolate-shared-partial-block-writes.py
storage = [[10, 20, 30, None], [None] * 4]
tail_blocks, refs, free = {"A": 0, "B": 0}, {0: 2, 1: 0}, [1]

def append_fourth(branch, val):
    old = tail_blocks[branch]
    if refs[old] > 1:
        new = free.pop()
        storage[new] = storage[old][:3] + [None]
        tail_blocks[branch] = new
        refs[old] -= 1
        refs[new] = 1
    storage[tail_blocks[branch]][3] = val

append_fourth("A", 90)
append_fourth("B", 80)
print("isolated branches:", {k: storage[b] for k, b in tail_blocks.items()}, "| refs:", refs)
Output
isolated branches: {'A': [10, 20, 30, 90], 'B': [10, 20, 30, 80]} | refs: {0: 1, 1: 1}
A and B begin on shared physical block 0 with values 10, 20, 30 and one empty slot, reference count two. Without copy-on-write, B overwrites A’s appended 90 with 80. In the safe branch A copies only the three valid values to block 1 and writes 90; B keeps block 0 and writes 80. Each block then has one owner.
Copy-on-write clones the three valid slots into block 1 for branch A before writing 90, leaving B as sole owner of block 0.

Prefix caching, RadixAttention, and cache-hit TTFT math

In causal self-attention, position tt depends only on positions 0…t0 \dots t. When separate requests share an identical prefix (system prompt, repository guide, tool schemas), prefix caching (called prompt caching on hosted APIs) keeps those completed KV blocks reusable across requests. Editing even one token near position 0 invalidates every downstream block!

Serving engines index reusable prefixes in two main ways:

EngineIndexing structureLookup and eviction
vLLM (Automatic Prefix Caching)[10]Hash table over fixed-size PagedAttention blocksChains each block hash Hk=hash(serialize(Hk−1,token_idsk,extrask))H_k = \text{hash}(\text{serialize}(H_{k-1}, \text{token\_ids}_k, \text{extras}_k)) including LoRA ID and cache_salt; evicts unreferenced blocks via LRU
SGLang ()[2]Compressed (token trie)Traverses shared token edges, splits edges on divergence, and evicts unreferenced leaves via LRU

Suppose 100 requests share a 1,000-token prompt with 16-token blocks: 62 complete blocks (992 tokens) are shared once while each request keeps 1 private tail block (8 tokens), dropping occupied prefix blocks from 6,300 to 162 (97.4% reduction). Even on an exact 1,008-token match, vLLM recomputes the final block so it can emit next-token logits.[11]

For 100 compatible requests with a warm full-attention 1,000-token prefix and 16-token blocks, one shared run occupies 62 full blocks and the requests keep 100 private tail blocks: 162 occupied blocks instead of 6,300. At prompt lengths 1,000, 1,008, and 1,009, the aligned hit rule reuses 992, 992, and 1,008 tokens and recomputes 8, 16, and 1.
Complete blocks share across requests while each request keeps a private tail block; even an exact 1,008-token match recomputes its last 16-token block for next-token logits.

On prefill latency, consider three requests sharing a 6,000-token guide with question tails of 48, 37, and 51 tokens: fresh prefill drops from 18,136 tokens to 6,136 tokens (saving 12,000 prefill tokens). Warm prefill can drop from 1,220 ms to 170 ms (saving 1,050 ms on ), while decode latency stays unchanged (880 ms) because decode still reads the cached prefix.

Four operational rules govern production prefix caching:

  1. Static-first prompt layout and hosted break-even economics: Put immutable instructions, guides, and tool schemas first, and dynamic timestamps, retrieved chunks, and user queries last. On hosted APIs with a cache write surcharge (e.g., 1.25×1.25\times for 5-min TTL or 2.0×2.0\times for 1-hour TTL) and discounted reads (0.10×0.10\times),[12][13] full-prefix break-even reads equal: Break-Even Reads=⌈Write Rate−1.01.0−Read Rate⌉\text{Break-Even Reads} = \left\lceil \frac{\text{Write Rate} - 1.0}{1.0 - \text{Read Rate}} \right\rceil That repays a 1.25×1.25\times write in 1 read and a 2.0×2.0\times write in 2 reads. Beware partial hits: paying 1.25×1.25\times writes on an initial 6,000-token call and then reusing only 1,024 of 6,000 tokens (with 1.25×1.25\times writes on the remaining 4,976 tokens) across three follow-up calls costs 10.3% more than uncached input! Always report volume-weighted token hit ratio (∑cached/∑prompt\sum \text{cached} / \sum \text{prompt}) rather than binary request hits, and normalize provider schemas (OpenAI input_tokens includes cached_tokens; Anthropic input_tokens excludes cache_read_input_tokens).
  2. Cached does not mean occupied: Completed requests leave blocks cached but unreferenced on the free queue. In a 1,000-block pool with 450 referenced, 400 cached-unreferenced, and 150 free blocks, 550 blocks are allocatable without preempting active requests.
  3. Prefix-affinity routing vs. queueing inversion: Sending repeat prefixes to one warm replica saves cold warmups, yet if queueing on a hot worker jumps from 20 ms to 1,200 ms while prefill drops from 1,220 ms to 170 ms, client TTFT actually gets 130 ms slower (1,370 ms vs. 1,240 ms). Pair prefix affinity with queue-depth caps or bounded-load consistent hashing.[14]
  4. Server-derived tenant isolation: Because cache hits return faster, sharing prefixes across untrusted tenants opens a timing side-channel. Bind cache_salt strictly from server-verified authentication, never from raw client headers.[10]
prefix-hash-and-economics.py
def chain(salt: str, blocks: list[str]) -> list[str]:
    parent, out = salt, []
    for blk in blocks:
        parent = sha256(json.dumps([parent, blk], separators=(",", ":")).encode()).hexdigest()
        out.append(parent)
    return out

v1 = chain("tenant-a", ["sys", "guide-v1", "tools"])
v2 = chain("tenant-a", ["sys", "guide-v2", "tools"])
tb = chain("tenant-b", ["sys", "guide-v1", "tools"])
print("v1 vs v2 hits:", [a == b for a, b in zip(v1, v2)], "| cross-tenant collision:", any(a == b for a, b in zip(v1, tb)))

# 3 requests sharing 6,000 prefix tokens + tails [48, 37, 51]
tails = [48, 37, 51]
print(f"Fresh prefill tokens: {sum(6000 + t for t in tails)} -> {6000 + sum(tails)} (saved {2 * 6000})")
print(f"Break-even reads (1.25x / 2.0x write, 0.10x read): {ceil(0.25 / 0.90)} / {ceil(1.0 / 0.90)}")

usage = [(0, 6000)] + [(1024, 4976)] * 3
uncached = sum(r + w for r, w in usage)
cached = sum(0.10 * r + 1.25 * w for r, w in usage)
print(f"Partial-hit trap: uncached={uncached} vs cached={cached:.1f} ({cached / uncached - 1:+.1%})")
Output
v1 vs v2 hits: [True, False, False] | cross-tenant collision: False
Fresh prefill tokens: 18136 -> 6136 (saved 12000)
Break-even reads (1.25x / 2.0x write, 0.10x read): 1 / 2
Partial-hit trap: uncached=24000 vs cached=26467.2 (+10.3%)

Preemption, pool exhaustion, and continuous batching

PagedAttention pairs naturally with (iteration-level scheduling from Orca[15]): as soon as a short request emits EOS, its blocks return to the pool and a waiting request enters on the next iteration instead of waiting for the longest sequence in a static batch.

When the block pool fills completely under heavy load, two invariants protect correctness and recovery:

  1. Failed allocation must preserve state: A rejected append_slot leaves block tables, lengths, and ownership untouched, and duplicate free() calls must never insert a physical block ID into the free list twice (which would alias two live customers onto the same KV memory).
  2. Recompute vs. swap preemption: vLLM V1 defaults to recomputation (releasing preempted blocks and replaying tokens on resume, spending GPU FLOPs rather than PCIe bandwidth), whereas legacy V0 also supported CPU swapping (moving blocks over PCIe to host RAM and back).[1][16] Optional KV-offloading connectors also allow tiering reusable blocks to CPU/SSD (as in Mooncake[17]).
retry-after-block-pool-exhaustion.py
tiny = PagedKVCacheManager(num_blocks=2, block_size=4)
tiny.allocate("A"); tiny.allocate("B")
for _ in range(4):
    tiny.append_slot("A")

before = (tuple(tiny.free_blocks), {k: tuple(v) for k, v in tiny.block_tables.items()}, dict(tiny.seq_lens))
try:
    tiny.append_slot("A")
except MemoryError as err:
    print("blocked:", err)
assert (tuple(tiny.free_blocks), {k: tuple(v) for k, v in tiny.block_tables.items()}, dict(tiny.seq_lens)) == before

tiny.free("B"); tiny.free("B")  # Idempotent release prevents double-free aliasing.
assert tiny.free_blocks == [0]
print("retry after freeing B:", tiny.append_slot("A"), "| A table:", tiny.block_tables["A"])
Output
blocked: KV block pool exhausted
retry after freeing B: (0, 0) | A table: [1, 0]
A two-block, four-slot manager starts with A owning block 1 at length four and B owning empty block 0 at length zero. A fifth append raises MemoryError because the free list is empty and leaves both tables, lengths, and blocks unchanged. Freeing B twice returns block 0 once; retry writes slot (0, 0), giving A table [1, 0] and length five.
A failed append leaves A and B intact; idempotent release returns block 0 once so A's retry succeeds cleanly.

Capacity levers beyond paging

Paging eliminates fragmentation waste, not raw KV bytes per token. When every request fills its context window (e.g., Llama 3 70B at 128K = 40 GiB in FP16), shrink or relocate the state using complementary levers:

LeverWhat it changesPrimary trade-off
GQA / MQA / MLA[4][18]Architectural KV heads or low-rank latent cacheFixed at model architecture/training time
KV Quantization (FP8 / KIVI)[19]Stored precision per value (FP8 halves raw bytes)Requires kernel support, scale factors, and accuracy validation
Token Eviction (SnapKV / H2O)[20][21]Drops low-attention KV positions from historyLossy; can drop facts needed by later turns
Chunked Prefill & Disaggregation[22][23]Bounds prefill interference with active decode stepsDisaggregation adds RDMA KV transfer and pool coordination
Tensor Parallelism (TP)[1]Shards KV heads across ranks (only when n_kv_heads % TP == 0)Always budget per rank; indivisible TP replicates KV heads
Check your understanding

Mastery Check

Check each question as you go, or answer all of them and check together. Score 75% or higher to complete this lesson.

0 of 6 answered
1.A model has 40 layers, 16 query heads, 4 KV heads, head dimension 64, and FP16 cache values. How much raw KV cache does one 4,096-token request need?
2.A paged KV cache uses 16-slot blocks, positions start at 0, and a request's block table is [7, 2, 9]. Where does the kernel read K and V for position 35?
3.Three beam-search branches are the only owners of a single 8-slot KV block. The engine uses copy-on-write, and each branch appends a different token. How many physical blocks hold the branches' tokens after all three appends if the block starts with 7 tokens? How many if it starts with 8?
4.Fifty requests start with the same 500-token prompt. The engine shares only complete 32-token blocks between requests, and all of those blocks are already cached. How many physical blocks hold this prompt's K/V state across the fifty requests?
5.A hosted prompt cache charges 2.5x base input price to write an entry and 0.40x to read it. How many full-prefix cache reads are needed to break even, and why can prefix-affinity routing still worsen client TTFT?
6.A KV pool is full, so the scheduler preempts a request with 6,400 cached tokens at 320 KiB per token. The CPU link moves 2,500 MiB/s in either direction. If the scheduler drops the cache, the GPU replays all 6,400 tokens at 12,800 tokens/s. How much time does round-trip swapping take versus GPU replay?

6 questions remaining.

References

Efficient Memory Management for Large Language Model Serving with PagedAttention.

Kwon, W., et al. · 2023 · SOSP 2023

https://arxiv.org/abs/2309.06180

SGLang: Efficient Execution of Structured Language Model Programs

Zheng, L., Yin, L., Xie, Z., et al. · 2023 · arXiv:2312.07104

https://arxiv.org/abs/2312.07104

Attention Is All You Need.

Vaswani, A., et al. · 2017

https://arxiv.org/abs/1706.03762

GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints.

Ainslie, J., et al. · 2023 · EMNLP 2023

https://arxiv.org/abs/2305.13245

The Llama 3 Herd of Models.

Dubey, A., et al. · 2024 · arXiv preprint

https://arxiv.org/abs/2407.21783

vLLM: Easy, Fast, and Cheap LLM Serving with PagedAttention

vLLM Team · 2023

https://vllm.ai/blog/2023-06-20-vllm

vAttention: Dynamic Memory Management for Serving LLMs without PagedAttention

Prabhu, R., Nayak, A., Mohan, J., Ramjee, R., & Panwar, A. · 2024

https://arxiv.org/abs/2405.04437

FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness

Dao, T., Fu, D. Y., Ermon, S., Rudra, A., Ré, C. · 2022 · NeurIPS 2022

https://arxiv.org/abs/2205.14135

FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving.

Ye, Z., et al. · 2025

https://arxiv.org/abs/2501.01005

Automatic Prefix Caching

vLLM · 2026

https://docs.vllm.ai/en/stable/design/prefix_caching/

vLLM v0.28.0: KV Cache Manager

vLLM Contributors · 2026

https://github.com/vllm-project/vllm/blob/v0.28.0/vllm/v1/core/kv_cache_manager.py

OpenAI API Pricing

OpenAI · 2026

https://developers.openai.com/api/docs/pricing

Anthropic Model Pricing

Anthropic · 2026

https://platform.claude.com/docs/en/about-claude/pricing

Consistent Hashing with Bounded Loads

Mirrokni, V., Thorup, M., & Zadimoghaddam, M. · 2018 · SODA 2018

https://arxiv.org/abs/1608.01350

Orca: A Distributed Serving System for Transformer-Based Generative Models.

Yu, G.-I., et al. · 2022 · OSDI 2022

https://www.usenix.org/conference/osdi22/presentation/yu

Optimization and Tuning.

vLLM · 2026

https://docs.vllm.ai/en/latest/configuration/optimization.html

Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving.

Qin, R., et al. · 2024

https://arxiv.org/abs/2407.00079

DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model

DeepSeek-AI · 2024

https://arxiv.org/abs/2405.04434

KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache

Liu, Z., Chen, B., Hu, X., et al. · 2024 · arXiv preprint

https://arxiv.org/abs/2402.02750

SnapKV: LLM Knows What You are Looking for Before Generation

Li, Y., Huang, Y., Yang, B., et al. · 2024

https://arxiv.org/abs/2404.14469

H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models

Zhang, Z., Sheng, Y., Zhou, T., et al. · 2023

https://arxiv.org/abs/2306.14048

SARATHI: Efficient LLM Inference by Piggybacking Decodes with Chunked Prefills

Agrawal, A., et al. · 2023 · arXiv preprint

https://arxiv.org/abs/2308.16369

DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving.

Zhong, Y., et al. · 2024 · OSDI 2024

https://arxiv.org/abs/2401.09670

Discussion

Questions and insights from fellow learners.

Discussion loads when you reach this section.