Rishabh Misra’s Post

KV Cache is the silent killer eating your inference budget alive. If a 10-page document crashed your "production-ready" RAG system, this is likely the reason! I saw this exact failure pattern scaling recommendation systems at Twitter. Managing state is everything. In LLMs, that state is the KV Cache. The "Re-Reading" Problem: Without caching, LLMs re-compute attention for every previous token to generate the next word. It’s like re-reading a novel from page one every time you turn the page. The KV Cache stores vectors to solve this, but this "solution" creates a massive hidden tax. The Math is Unforgiving. For Llama-3 70B model with FP16 precision: → The Baseline: Model weights alone might take ~140GB (across GPUs). → The Cache: A single 4,000-token context consumes huge chunks of remaining VRAM. → The Reality: On an 80GB H100, after loading weights, you are fighting for scraps. The Real Bottleneck is *Fragmentation*. Traditionally, the cache requires contiguous memory blocks. Since you don't know if a response is 5 tokens or 500, you must over-allocate "just in case." This turns expensive GPU memory into "Swiss Cheese" - riddled with holes and reserved (but empty) slots. You end up with 50% of VRAM technically "free," but unusable because it's fragmented. We are facing a storage problem disguised as a math problem. The fix? Borrowing "Virtual Memory" logic from Operating Systems to "defrag" GPUs in real-time. It’s called PagedAttention. This is Part 2 of a deep dive into inference optimization. In the next one, I'll break down how PagedAttention can take GPU utilization from 40% to 92%.

  • No alternative text description for this image

Read about the LLM optimization physics bottleneck in part 1 here https://www.linkedin.com/posts/misrarishabh_ai-machinelearning-llm-activity-7419038510155759616-iJQw to gain more context on this series!

The OS analogy lands perfectly. Curious if you will cover prefix caching in part 3 - reusing KV blocks across requests with shared system prompts is where PagedAttention really shines for production RAG.

Great post - this is a part that many overlook, but is critical.

Informative post, thank you for sharing!

See more comments

To view or add a comment, sign in

Explore content categories