<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Kv-Cache on lo0 — Tech Blog</title><link>https://blog.lo0.es/en/tags/kv-cache/</link><description>Recent content in Kv-Cache on lo0 — Tech Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Fri, 11 Sep 2026 00:30:00 +0200</lastBuildDate><atom:link href="https://blog.lo0.es/en/tags/kv-cache/index.xml" rel="self" type="application/rss+xml"/><item><title>Prefix routing: what LiteLLM does not do, who does, and how much it really improves</title><link>https://blog.lo0.es/en/posts/prefix-routing-what-litellm-does-not-do/</link><pubDate>Fri, 11 Sep 2026 00:30:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/prefix-routing-what-litellm-does-not-do/</guid><description>&lt;blockquote>
&lt;p>Fifth article in the operational track of the control layer. &lt;a href="https://blog.lo0.es/en/posts/litellm-langfuse-operational-pair/">The pair with Langfuse&lt;/a> covered observability, &lt;a href="https://blog.lo0.es/en/posts/litellm-day-2-high-availability/">the proxy&amp;rsquo;s day 2&lt;/a> covered availability, &lt;a href="https://blog.lo0.es/en/posts/litellm-virtual-keys-budgets-limits/">virtual keys&lt;/a> covered governance and &lt;a href="https://blog.lo0.es/en/posts/humans-agents-same-gateway-priority-traffic-separation/">humans and agents&lt;/a> covered the coexistence of two classes of traffic. Here a claim of mine from June gets taken apart. Everything that follows is verified against LiteLLM 1.102.0 (commit of 10 September 2026), vLLM 0.29.0 and the main branches of production-stack, llm-d and Dynamo from the second week of September 2026.&lt;/p>
&lt;/blockquote>
&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>&lt;strong>LiteLLM does not do prefix-aware routing, neither in the open version nor in the paid one.&lt;/strong> It is not a licensing question. A search across the whole tree for &lt;code>kv_aware&lt;/code>, &lt;code>cache_aware&lt;/code>, &lt;code>radix&lt;/code>, &lt;code>prefix_cache&lt;/code> and &lt;code>block_hash&lt;/code> returns zero matches in the router. Nor is there any call from the router to &lt;code>/metrics&lt;/code> or to any vLLM endpoint. In June I wrote the opposite in &lt;a href="https://blog.lo0.es/en/posts/llm-inference-router-l7-switchboard/">the inference router article&lt;/a> and I was wrong.&lt;/p>
&lt;p>&lt;strong>What LiteLLM has is affinity, which is a different thing.&lt;/strong> Four pre-call checks pin a request to a replica by session identifier, by key hash, by previous response identifier or by exact hash of a marked prefix. None is active by default. Affinity distributes conversations; prefix routing distributes prefixes shared between different conversations, which is the case that multiplies throughput.&lt;/p>
&lt;p>&lt;strong>The only one that looks at the prompt is fragile in three ways.&lt;/strong> If the client does not send &lt;code>cache_control&lt;/code>, the key comes out null and the check does nothing. If the cut point goes in the last turn, which is what the automatic injection does by default, the key changes on every turn and it never hits. And the pin&amp;rsquo;s TTL is 300 seconds hardcoded in two lines, while the provider offers one-hour caches.&lt;/p>
&lt;p>&lt;strong>The engine does not answer questions, it publishes events.&lt;/strong> There is no vLLM endpoint you can ask whether it has a prefix. What there is, is a ZMQ socket that emits stored and removed blocks in msgpack, switched off by default, with silent discarding when the consumer does not keep up. A router that wants to be exact has to replicate the engine&amp;rsquo;s hash in full: chained SHA256, deterministic seed, block granularity and the extra keys in their order.&lt;/p>
&lt;p>&lt;strong>And by default it does not publish the hits, only the additions.&lt;/strong> The index of a router that only listens drifts away from the engine&amp;rsquo;s real LRU without noticing. To see the hits you have to ask for it request by request with &lt;code>kv_cache_report_mode: full&lt;/code>.&lt;/p>
&lt;p>&lt;strong>The three routers that do do it are very different from each other.&lt;/strong> The vLLM production-stack one indexes chunks of 128 raw characters in a trie that is never purged, models no eviction and dies on every restart. The llm-d one offers an approximate mode and an exact event-driven one, all its plugins are in alpha or beta, and its default tokeniser does not produce real tokens. NVIDIA Dynamo&amp;rsquo;s keeps an event-driven radix tree with a weighted cost function, and ships with the parameter that avoids starving a freshly scaled replica switched off.&lt;/p>
&lt;p>&lt;strong>The big improvements only appear in the best possible case.&lt;/strong> The two- and three-digit numbers are published by the projects themselves, with synthetic shared prefixes and a round-robin balancer as the reference. The most complete independent measurement, from Meta, obtains 2.3 times more throughput and also identifies load regimes where affinity leaves capacity at between half and two thirds of the reference. Another, on a multi-region deployment with 89 % reuse, measures single-digit improvements.&lt;/p>
&lt;p>&lt;strong>The correct architecture has two layers, not one.&lt;/strong> LiteLLM on top for identity, budget and audit, pointing at a single destination per model group. The KV-aware router underneath, inside the engine&amp;rsquo;s domain. Mixing it into a single piece is not an option that exists today.&lt;/p>
&lt;h2 id="you-are-here-between-the-gateway-and-the-engine">You are here: between the gateway and the engine&lt;/h2>
&lt;p>This article occupies the gap between two layers that already have an article of their own. Above, &lt;a href="https://blog.lo0.es/en/posts/llm-inference-router-l7-switchboard/">the L7 switchboard&lt;/a> and the gateway that has been operated since the first article in this track. Below, &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">the fundamentals of the KV cache&lt;/a> and &lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">hit rate engineering&lt;/a>.&lt;/p>
&lt;p>The gap is the piece that decides which replica each request goes to, knowing what each replica has in memory. It is the only function in the stack that cannot be resolved in the gateway or in the engine separately.&lt;/p>
&lt;h2 id="the-analogy-the-library-with-four-counters">The analogy: the library with four counters&lt;/h2>
&lt;p>A library with four counters. Each librarian has in front of them a pile of the books they have consulted lately. When a reader comes in asking for the third volume of an encyclopaedia, if that volume is in the pile at counter two, serving them there takes seconds. At any other counter someone has to go down to the store room.&lt;/p>
&lt;p>A normal balancer sends the reader to the counter with the shortest queue. It is the right decision if all the counters are interchangeable, and it is the wrong decision here, because they are not: what distinguishes them is not the queue, it is the pile.&lt;/p>
&lt;p>Session affinity resolves one specific case of this. The returning reader is always sent to the same counter, because they will probably ask for the fourth volume of the same encyclopaedia. It works, and it does not resolve the general case: when a hundred different readers ask for the same third volume, session affinity spreads them across the four counters and four librarians go down to the store room for the same book.&lt;/p>
&lt;p>Prefix routing is looking at what the reader asks for before assigning them a counter. It has two costs that the analogy makes visible straight away. The first is that somebody has to keep track of what is in each pile, and that bookkeeping takes work. The second is that if everybody asks for the third volume, counter two becomes the library&amp;rsquo;s only desk while the other three look on.&lt;/p>
&lt;h2 id="the-correction-what-i-wrote-in-june">The correction: what I wrote in June&lt;/h2>
&lt;p>In the inference router article, on 2 June 2026, I closed the prefix routing section with this sentence: &amp;ldquo;vLLM Production Stack router implements it natively. NVIDIA Dynamo too. LiteLLM in its enterprise version has a beta.&amp;rdquo;&lt;/p>
&lt;p>The first two hold up. The third is false and was no less false in June. While preparing &lt;a href="https://blog.lo0.es/en/posts/humans-agents-same-gateway-priority-traffic-separation/">the humans and agents article&lt;/a> the first hint appeared, and full verification against 1.102.0 confirms it.&lt;/p>
&lt;p>Case-insensitive search over &lt;code>litellm/&lt;/code>, &lt;code>enterprise/&lt;/code> and &lt;code>gateway/&lt;/code>, for the terms &lt;code>kv_aware&lt;/code>, &lt;code>kv-aware&lt;/code>, &lt;code>cache_aware&lt;/code>, &lt;code>cache-aware&lt;/code>, &lt;code>radix&lt;/code>, &lt;code>prefix_cache&lt;/code>, &lt;code>prefix-cache&lt;/code>, &lt;code>kv_cache&lt;/code>, &lt;code>block_hash&lt;/code>, &lt;code>prefix_hash&lt;/code>, &lt;code>prefix_score&lt;/code> and &lt;code>longest_prefix&lt;/code>: zero matches. Search for &lt;code>vllm&lt;/code> inside &lt;code>litellm/router.py&lt;/code>, &lt;code>litellm/router_strategy/&lt;/code> and &lt;code>litellm/router_utils/&lt;/code>: zero. Search for &lt;code>num_requests_waiting&lt;/code>, &lt;code>gpu_cache_usage&lt;/code> or any scraping of the backends&amp;rsquo; &lt;code>/metrics&lt;/code> from the router: zero. LiteLLM&amp;rsquo;s router never asks the engine anything.&lt;/p>
&lt;p>Search for &lt;code>premium_user&lt;/code> in the files where those checks would live: a single result, and it is about something else. There is no paid version with this feature. The only routing piece that is behind a licence is per-tag budgets, in &lt;code>litellm/router_strategy/budget_limiter.py&lt;/code>.&lt;/p>
&lt;p>Where the error came from. LiteLLM&amp;rsquo;s documentation has an entry on dynamic TPM and RPM allocation marked as beta and enterprise, and a pre-call check called &lt;code>prompt_caching&lt;/code>. Skim-read and added together, they give the impression of prefix routing in beta. Read in the code, &lt;code>prompt_caching&lt;/code> is something else, and it deserves a section of its own because it is still recommended for this problem.&lt;/p>
&lt;h2 id="what-litellm-does-have-four-affinities">What LiteLLM does have: four affinities&lt;/h2>
&lt;p>The &lt;code>optional_pre_call_checks&lt;/code> field accepts eight values. None is enabled by default: &lt;code>apply_default_settings&lt;/code> passes an empty list. One of the eight, &lt;code>forward_client_headers_by_model_group&lt;/code>, is declared in the type and in the interface schema and is consumed by no branch of the code. It is a dead value.&lt;/p>
&lt;p>The four that pin a request to a replica are these.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Check&lt;/th>
&lt;th>What it pins&lt;/th>
&lt;th>Where it stores it&lt;/th>
&lt;th>TTL&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>session_affinity&lt;/code>&lt;/td>
&lt;td>Session identifier&lt;/td>
&lt;td>Redis with a Lua script, mirrored in memory&lt;/td>
&lt;td>&lt;code>deployment_affinity_ttl_seconds&lt;/code>, 3600 by default, refreshed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>deployment_affinity&lt;/code>&lt;/td>
&lt;td>API key hash&lt;/td>
&lt;td>Same&lt;/td>
&lt;td>Same&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>responses_api_deployment_check&lt;/code>&lt;/td>
&lt;td>&lt;code>previous_response_id&lt;/code>&lt;/td>
&lt;td>Same&lt;/td>
&lt;td>Same&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>prompt_caching&lt;/code>&lt;/td>
&lt;td>Exact hash of a marked prefix&lt;/td>
&lt;td>&lt;code>DualCache&lt;/code>&lt;/td>
&lt;td>&lt;strong>300 s, hardcoded&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The other four are &lt;code>router_budget_limiting&lt;/code>, &lt;code>encrypted_content_affinity&lt;/code>, &lt;code>enforce_model_rate_limits&lt;/code> and the dead value.&lt;/p>
&lt;h3 id="prompt_caching-why-it-is-no-use-for-this">&lt;code>prompt_caching&lt;/code>: why it is no use for this&lt;/h3>
&lt;p>The key is a SHA256 over the serialisation of the cacheable prefix, and &amp;ldquo;cacheable prefix&amp;rdquo; means everything up to and including the last block marked with &lt;code>cache_control: {&amp;quot;type&amp;quot;: &amp;quot;ephemeral&amp;quot;}&lt;/code>. Three consequences, checked by running the functions in isolation over the repository&amp;rsquo;s code.&lt;/p>
&lt;p>If the request carries no &lt;code>cache_control&lt;/code>, the extraction returns an empty list, the key comes out null and the check pins nothing. Automatic injection of cut points is only enabled with &lt;code>litellm.enable_anthropic_prompt_caching&lt;/code>, which defaults to false, and only for Anthropic and Bedrock providers.&lt;/p>
&lt;p>If the cut point is in the system prompt, the key does not change when turns are added and the pin works. This is the good case and it requires the client to mark it deliberately.&lt;/p>
&lt;p>If the cut point is in the last message, the key changes on every turn and the pin never hits. And this is exactly the default case of the automatic injection, which places one point on the &lt;code>system&lt;/code> and another at index &lt;code>-1&lt;/code>. Since the second is the last, the cacheable prefix becomes the whole conversation.&lt;/p>
&lt;p>On top of that there is the TTL. Two lines with &lt;code>ttl=300&lt;/code>, one of them with the comment &lt;code># store for 5 minutes&lt;/code>. There is no parameter to change it. Issue 28427 has had it open for months with no response from the maintainers, and it points to the mismatch with the one-hour ephemeral caches that LiteLLM itself knows how to request via &lt;code>cache_control.ttl: &amp;quot;1h&amp;quot;&lt;/code>.&lt;/p>
&lt;p>There is a nuance the issue does not capture and that makes diagnosis worse: in the default case the pin does not even last five minutes, because the key changes first.&lt;/p>
&lt;h3 id="session_affinity-the-one-to-use">&lt;code>session_affinity&lt;/code>: the one to use&lt;/h3>
&lt;p>For conversations, this is the right piece and it is reasonably built. The session identifier is looked for in this exact order of headers:&lt;/p>
&lt;ol>
&lt;li>&lt;code>x-litellm-trace-id&lt;/code>&lt;/li>
&lt;li>&lt;code>x-litellm-session-id&lt;/code>&lt;/li>
&lt;li>Any &lt;code>x-&amp;lt;vendor&amp;gt;-session-id&lt;/code>, with the regular expression &lt;code>^x-.+-session-id$&lt;/code> and a value of at least eight alphanumeric characters&lt;/li>
&lt;li>Only if the &lt;code>User-Agent&lt;/code> is Codex&amp;rsquo;s: &lt;code>session-id&lt;/code>, &lt;code>session_id&lt;/code>, &lt;code>thread-id&lt;/code>, &lt;code>conversation_id&lt;/code>&lt;/li>
&lt;li>Plain &lt;code>x-session-id&lt;/code>, for opencode&lt;/li>
&lt;/ol>
&lt;p>And if nothing matches, two fallbacks: a &lt;code>metadata.user_id&lt;/code> in Anthropic format, and the W3C &lt;code>baggage&lt;/code> with &lt;code>session.id=&lt;/code>. The third point is the one that captures Claude Code with nothing configured.&lt;/p>
&lt;p>Storage is a Lua script in Redis that does &lt;code>GET&lt;/code>, &lt;code>SET NX EX&lt;/code> and &lt;code>EXPIRE&lt;/code>, so the first writer wins and the TTL is refreshed on every request that confirms the pin. It is an inactivity TTL, not a total session duration. Without Redis it degrades to a pod-local reservation, which is atomic but not shared.&lt;/p>
&lt;p>A detail of the pipeline order that already came up in the previous article and still holds: the affinity checks run inside &lt;code>async_get_healthy_deployments&lt;/code> before tag filtering. If the pin returns a single deployment and that deployment does not satisfy the request&amp;rsquo;s tag, the later filter removes it and the request fails. Affinity gets no vote on the tags.&lt;/p>
&lt;h3 id="the-routers-that-do-read-the-prompt-and-why-they-are-no-good">The routers that do read the prompt, and why they are no good&lt;/h3>
&lt;p>LiteLLM has four pieces that read message content: &lt;code>AutoRouter&lt;/code> with semantic matching, &lt;code>RequestComplexityRouter&lt;/code>, &lt;code>AdaptiveRouter&lt;/code> and &lt;code>QualityRouter&lt;/code>. They all live in &lt;code>async_pre_routing_hook&lt;/code>, which runs before looking for healthy deployments.&lt;/p>
&lt;p>The reason they do not solve this problem is in what they choose. All four choose a &lt;strong>model group&lt;/strong>, not a replica. They decide whether an easy question goes to the thirty-billion-parameter model or to the small one. None has access to the replica list or knows what is in each one&amp;rsquo;s memory.&lt;/p>
&lt;h3 id="what-did-land-admission-control">What did land: admission control&lt;/h3>
&lt;p>A minor correction to the previous article, which placed this in the 1.101 branch as an upcoming feature. In 1.102.0 it is already there, in &lt;code>litellm/proxy/middleware/admission_control_middleware.py&lt;/code>, with the three settings in &lt;code>general_settings&lt;/code>: &lt;code>max_in_flight_requests_per_worker&lt;/code>, &lt;code>max_queued_requests_per_worker&lt;/code> and &lt;code>admission_queue_timeout_seconds&lt;/code>, the last with a default value of 1.0 seconds.&lt;/p>
&lt;p>It stays inactive as long as the first one is not declared. It exposes an authenticated &lt;code>/health/backlog&lt;/code> and the three metrics &lt;code>litellm_admission_admitted_requests&lt;/code>, &lt;code>litellm_admission_queued_requests&lt;/code> and &lt;code>litellm_admission_rejected_requests_total&lt;/code>, the last with a reason label. It is a per-process semaphore, not coordinated across pods.&lt;/p>
&lt;h2 id="what-the-engine-exposes-upwards">What the engine exposes upwards&lt;/h2>
&lt;p>Before looking at the routers that do do this, you have to understand what raw material they work with. The natural question would be whether vLLM has an endpoint you can ask about a prefix. It does not.&lt;/p>
&lt;p>The only cache router in the entry points is &lt;code>vllm/entrypoints/serve/dev/cache/api_router.py&lt;/code>, and it only exposes destructive writes: &lt;code>POST /reset_prefix_cache&lt;/code>, &lt;code>/reset_mm_cache&lt;/code> and &lt;code>/reset_encoder_cache&lt;/code>. All three are behind &lt;code>VLLM_SERVER_DEV_MODE=1&lt;/code> and do not exist in a normal deployment. There is no read.&lt;/p>
&lt;p>What there is, is an event stream.&lt;/p>
&lt;h3 id="the-zmq-stream">The ZMQ stream&lt;/h3>
&lt;p>It is enabled with &lt;code>--kv-events-config&lt;/code>, and it is off by default. The configuration accepts a publisher (&lt;code>null&lt;/code> or &lt;code>zmq&lt;/code>), an endpoint (by default &lt;code>tcp://*:5557&lt;/code>, which binds), an optional replay endpoint, the number of batches retained for that replay (10,000), and a high water mark limit of 100,000.&lt;/p>
&lt;p>That limit is the one that matters operationally: above it, ZMQ discards events if the consumer does not keep up. Silently.&lt;/p>
&lt;p>The transport is a PUB socket with msgpack serialisation and three-part frames: topic, eight-byte sequence number and payload. The sequence number lets a subscriber ask for replay from where it left off through the optional ROUTER socket. With data parallelism the port shifts by rank, so you have to subscribe to &lt;code>5557+rank&lt;/code>.&lt;/p>
&lt;p>Three event types. &lt;code>BlockStored&lt;/code> carries the hashes, the parent hash, the token identifiers, the block size, the LoRA adapter name, the extra keys, the medium (GPU, CPU or storage) and a session identifier. &lt;code>BlockRemoved&lt;/code> carries only hashes. &lt;code>AllBlocksCleared&lt;/code> carries no payload and is emitted when the prefix cache is reset.&lt;/p>
&lt;p>They are published once per scheduler step, only if there are events. With the feature switched off the cost is zero. With it switched on, the full token identifiers of each block travel over the wire, so bandwidth scales with tokens per second and not with requests per second.&lt;/p>
&lt;p>An example in vLLM&amp;rsquo;s own repository declares itself experimental on its eighth line.&lt;/p>
&lt;h3 id="the-hash-that-has-to-be-replicated">The hash that has to be replicated&lt;/h3>
&lt;p>An exact router does not receive the engine&amp;rsquo;s state, it reconstructs it. For that it has to compute the same hashes, and the engine computes them like this:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># vllm/v1/core/kv_cache_utils.py&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">hash_block_tokens&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">hash_function&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">parent_block_hash&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">curr_block_token_ids&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">extra_keys&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="ow">not&lt;/span> &lt;span class="n">parent_block_hash&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">parent_block_hash&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">NONE_HASH&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">hash_function&lt;/span>&lt;span class="p">((&lt;/span>&lt;span class="n">parent_block_hash&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nb">tuple&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">curr_block_token_ids&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="n">extra_keys&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>It is chained: each hash identifies the complete prefix up to that boundary, not the isolated block. The default algorithm is SHA256, configurable with &lt;code>--prefix-caching-hash-algo&lt;/code> among four values.&lt;/p>
&lt;p>Five things a router has to get right for its hashes to match the engine&amp;rsquo;s:&lt;/p>
&lt;p>The seed. Since 0.29, &lt;code>NONE_HASH&lt;/code> is deterministic from a fixed seed, so two different processes produce the same hashes with nothing configured. It is a silent change of semantics from earlier versions, which required setting &lt;code>PYTHONHASHSEED&lt;/code>. With the &lt;code>xxhash&lt;/code> algorithms it is still needed.&lt;/p>
&lt;p>The block size. By default 16 tokens, but the attention backend can override it if the user did not pass &lt;code>--block-size&lt;/code>: 256 with sliding-window sparse attention, 64 with ROCm&amp;rsquo;s AITER, 64 or more with FlashAttention on XPU. A router must not assume 16, it has to read it from the event.&lt;/p>
&lt;p>The hashing granularity, which is not necessarily the physical block size. There is &lt;code>--prefix-match-unit&lt;/code>, which with several cache groups resolves to the greatest common divisor of the cacheable groups&amp;rsquo; sizes.&lt;/p>
&lt;p>The extra keys, in their order: LoRA adapter name (by name, not by identifier), multimodal identifiers with their relative offset inside the block, &lt;code>cache_salt&lt;/code> only in block zero, and the hash of the prompt embeddings. Sampling parameters do not go in, which is correct: the prefix KV does not depend on the temperature.&lt;/p>
&lt;p>And truncation. By default the hashes travel over the wire as 64-bit integers truncated from a SHA256, not as the full bytes. It can be disabled with &lt;code>VLLM_KV_EVENTS_USE_INT_BLOCK_HASHES=0&lt;/code>. With the default value, a router has a theoretical collision risk that the engine does not have.&lt;/p>
&lt;h3 id="the-hits-are-invisible-by-default">The hits are invisible by default&lt;/h3>
&lt;p>This is the detail that takes the most effort to discover and has the most consequences. The events are incremental: only what gets newly cached is announced. A reused block generates no event.&lt;/p>
&lt;p>A router that only listens sees the additions and the removals, but does not see the hits. Its notion of what is recent and what is cold drifts away from the engine&amp;rsquo;s real LRU with nothing to warn it.&lt;/p>
&lt;p>A full mode exists, and it is per request. &lt;code>sampling_params.extra_args[&amp;quot;kv_cache_report_mode&amp;quot;] = &amp;quot;full&amp;quot;&lt;/code> makes &lt;code>BlockStored&lt;/code> events be emitted for blocks that were hits too. The function&amp;rsquo;s docstring says so plainly: it generates events so that external consumers, &amp;ldquo;for example a gateway&amp;rdquo;, know which blocks were reused. That is to say: for this to work, the router has to inject a parameter into every request it forwards.&lt;/p>
&lt;h3 id="the-metrics-and-what-broke">The metrics, and what broke&lt;/h3>
&lt;p>For aggregate measurement two counters remain: &lt;code>vllm:prefix_cache_queries_total&lt;/code> and &lt;code>vllm:prefix_cache_hits_total&lt;/code>, both in tokens and not in requests, with model and engine labels. There are two equivalents for the external connector, which allow a hit in HBM to be distinguished from one brought in from CPU or NVMe.&lt;/p>
&lt;p>And there are two removals that break existing configurations. &lt;code>vllm:gpu_prefix_cache_hit_rate&lt;/code> no longer exists: zero appearances in the repository. It was deprecated in 0.8, hidden in 0.9 and removed in 0.10. And &lt;code>vllm:gpu_cache_usage_perc&lt;/code> was renamed to &lt;code>vllm:kv_cache_usage_perc&lt;/code>, which breaks Grafana panels and autoscalers that depended on the old name.&lt;/p>
&lt;p>The hit rate has to be derived in PromQL with &lt;code>rate()&lt;/code> over the two counters. The one that appears in the text log is something else: it uses a window of the last thousand requests.&lt;/p>
&lt;p>And it has a bias you need to know about before taking decisions with it. When a request is evicted, its blocks return to the free queue keeping the hash, so the later reprefill finds them again and &lt;strong>counts as a hit&lt;/strong>. A high hit rate can mean useful reuse between users or it can mean the engine is evicting and recomputing in a loop. The internal statistics separate the two things with a &lt;code>preempted&lt;/code> field, which is not exposed as a Prometheus metric.&lt;/p>
&lt;h3 id="the-last-token">The last token&lt;/h3>
&lt;p>A small detail with an effect on long conversations: the maximum hit length is the request&amp;rsquo;s token count minus one. There is always something to recompute in order to get logits. Since the reservation requires alignment to the block size, in practice that can force recomputing the whole final block. With blocks of 16 it is noise. With a backend that prefers 256, it is up to 256 tokens recomputed per turn.&lt;/p>
&lt;h2 id="the-ones-that-do-do-it">The ones that do do it&lt;/h2>
&lt;h3 id="vllm-production-stack">vLLM production-stack&lt;/h3>
&lt;p>Eight routing logics in a single &lt;code>--routing-logic&lt;/code> selector: &lt;code>roundrobin&lt;/code>, &lt;code>session&lt;/code>, &lt;code>kvaware&lt;/code>, &lt;code>loadaware&lt;/code>, &lt;code>prefixaware&lt;/code>, &lt;code>disaggregated_prefill&lt;/code>, &lt;code>disaggregated_prefill_orchestrated&lt;/code> and &lt;code>priority&lt;/code>. Two of them, &lt;code>loadaware&lt;/code> and &lt;code>priority&lt;/code>, are not in the Helm chart&amp;rsquo;s enum and are only enabled through &lt;code>extraArgs&lt;/code>.&lt;/p>
&lt;p>The naming trap is that &lt;code>prefixaware&lt;/code> and &lt;code>kvaware&lt;/code> are radically different things.&lt;/p>
&lt;p>&lt;code>prefixaware&lt;/code> is a hash trie in the router&amp;rsquo;s process. It chunks the prompt string every 128 &lt;strong>characters&lt;/strong>, not tokens, and hashes each chunk with 64-bit xxhash. Its own docstring says so: the chunk size is &amp;ldquo;in number of characters&amp;rdquo;. That 128 is hardcoded, there is no flag or Helm value to change it.&lt;/p>
&lt;p>Four consequences come out of that. &lt;code>--prefix-min-match-length&lt;/code> is measured in characters and is quantised to multiples of 128. A shared prefix that differs by one character inside the first chunk breaks the whole match, because there is no partial match inside a chunk. For chat, it concatenates the content of all the messages with newlines and without applying the chat template, so the indexed string is not what the engine tokenises. And the tie-break between tied replicas is &lt;code>random.choice&lt;/code>, without looking at load.&lt;/p>
&lt;p>The trie has no notion of saturation. A popular prefix concentrates all the traffic on the same replica indefinitely. The docstring assumes the simplified model and declares it: &amp;ldquo;we assume there is no prefix cache eviction&amp;rdquo;.&lt;/p>
&lt;p>It has no pruning either. &lt;code>HashTrie&lt;/code> only has insertion and longest prefix lookup; there is no deletion method. When a replica disappears, its URLs stay forever in every node&amp;rsquo;s sets, and filtering happens at query time. It works, and the trie grows monotonically: each distinct prompt adds its length divided by 128 permanent nodes, with no bound, no TTL and no LRU. The router&amp;rsquo;s memory limit in the chart is 1,000 MiB. By contrast, the round-robin router in the same file does bound its caches to 1,024 entries.&lt;/p>
&lt;p>And it dies on every restart: it is in-process memory state, with no snapshot and no initial load.&lt;/p>
&lt;p>&lt;code>kvaware&lt;/code> and &lt;code>loadaware&lt;/code> are better and have a different price. They do not index themselves: they ask the LMCache controller, which knows about real tokens. That requires &lt;code>lmcache==0.3.11&lt;/code> and &lt;code>vllm==0.13.0&lt;/code> pinned exactly, and the official router image drags in the whole of vLLM. The limitation to read before planning anything: they only look at &lt;code>request_json.get(&amp;quot;prompt&amp;quot;, &amp;quot;&amp;quot;)&lt;/code>, with an open TODO for chat completions. With &lt;code>/v1/chat/completions&lt;/code>, both tokenise an empty string.&lt;/p>
&lt;p>&lt;code>loadaware&lt;/code> is the only one of the three that breaks affinity on saturation, with the formula &lt;code>score = relative_match - beta * relative_load&lt;/code> and &lt;code>beta = 1.0&lt;/code> by default. The authors&amp;rsquo; own reading: a replica at twice the average load loses the equivalent of a full cache hit. The guide suggests 0.25 to favour cache and 2.0 to favour balancing.&lt;/p>
&lt;p>On published results, the documentation&amp;rsquo;s benchmarking file literally says that the measurement platform is coming soon. The project blog&amp;rsquo;s two posts claim between three and ten times lower response latency, and only one declares a partial configuration: Llama 3.1 70B on four nodes with tensor parallelism 2 over 80 GB A100s, inputs of 9K tokens and outputs of 10, against AIBrix 0.2.0 and a flat deployment. Charts with no labelled points, no absolute figures and no declaration of which routing logic was used in each.&lt;/p>
&lt;h3 id="llm-d">llm-d&lt;/h3>
&lt;p>There has been a reorganisation here that invalidates a good part of the third-party documentation. The Endpoint Picker code left the Gateway API Inference Extension repository and was merged into llm-d&amp;rsquo;s, which has been renamed to llm-d Router. The Kubernetes project keeps the &lt;code>InferencePool&lt;/code> API and a lightweight reference EPP that does nothing about prefixes. If you look for KV-aware routing in the extension&amp;rsquo;s repository, today it is not there.&lt;/p>
&lt;p>The &lt;code>InferencePool&lt;/code> is at &lt;code>v1&lt;/code> and is GA. The other two APIs moved to the &lt;code>llm-d.ai&lt;/code> group at &lt;code>v1alpha2&lt;/code>, and when they coexist with the old ones the EPP prefers the new ones and ignores the old.&lt;/p>
&lt;p>Scoring is a weighted sum. The default weights, when no configuration is passed: queue 2, KV utilisation 2, prefix 3. Any scorer referenced without a weight counts as 1.0. There is no configuration through environment variables: the old &lt;code>ENABLE_*_SCORER&lt;/code> no longer exist, everything goes in an &lt;code>EndpointPickerConfig&lt;/code> in YAML.&lt;/p>
&lt;p>The prefix scorer consumes an attribute published by a producer, and there are two producers.&lt;/p>
&lt;p>The &lt;strong>approximate&lt;/strong> one computes the hashes in the EPP itself without talking to the engine, and keeps a local LRU per pod and block pair that is populated after the decision. It is an approximation by construction. It has a hard floor: a configured block size below 64 tokens is raised to 64 at request time, because the index stores one entry per pod and block and going down to 16 would multiply memory by four.&lt;/p>
&lt;p>The &lt;strong>exact&lt;/strong> one builds the real index from the engine&amp;rsquo;s ZMQ events, with one subscriber per pod that is installed and torn down with the endpoint&amp;rsquo;s registration and deregistration. It has adapters for vLLM and SGLang, deduplicates evictions by reference counting, and the replay buffer that allows the index to be rebuilt after an EPP restart requires vLLM 0.26.0 or above.&lt;/p>
&lt;p>The trap is in the tokeniser. The EPP tokenises through a plugin, and the default backend is &lt;code>estimate&lt;/code>: byte packing with no tokeniser, roughly 4 bytes per token, with identifiers that do not correspond to real engine tokens. The exact scorer needs real tokens, and for that you have to explicitly configure the &lt;code>vllm&lt;/code> backend, which does HTTP against the engine&amp;rsquo;s &lt;code>/v1/completions/render&lt;/code> endpoints. If it is omitted, the auto-created &lt;code>estimate&lt;/code> satisfies the dependency and the system &lt;strong>degrades silently&lt;/strong>.&lt;/p>
&lt;p>On maturity, the file itself declares it: all in-tree plugins are in alpha or beta, and they will be promoted to stable when the project approaches 1.0. An alpha plugin configured without the corresponding flag makes the EPP fail to start.&lt;/p>
&lt;p>And on replicas, the warning is explicit: active-active mode should be avoided with approximate prefix routing, because the EPP replicas do not share state and each one only sees the traffic it has served itself, which significantly degrades the hit rate. The exact index is safe in high availability, and even so the reference guides fix a single replica because the accounting of in-flight requests is local to the process.&lt;/p>
&lt;p>The cost is the best documented in the whole field, and it deserves a table. Simulator with Qwen3 8B, 100 pods, 100K input tokens:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Requests/s&lt;/th>
&lt;th>Cap on tokens to match&lt;/th>
&lt;th>Peak CPU&lt;/th>
&lt;th>Peak memory&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>5.0&lt;/td>
&lt;td>4,096&lt;/td>
&lt;td>1.19 cores&lt;/td>
&lt;td>0.26 GiB&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>5.0&lt;/td>
&lt;td>100,000&lt;/td>
&lt;td>3.82 cores&lt;/td>
&lt;td>0.65 GiB&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>98.7&lt;/td>
&lt;td>4,096&lt;/td>
&lt;td>35.17 cores&lt;/td>
&lt;td>2.46 GiB&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>98.8&lt;/td>
&lt;td>100,000&lt;/td>
&lt;td>46.50 cores&lt;/td>
&lt;td>3.41 GiB&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>With outputs of 10K tokens at 50 requests per second, 32.53 cores and 12.54 GiB. The maintainers&amp;rsquo; sizing rule is half a core to one core per request per second on large agentic loads. And idle consumption scales with the number of pods because of continuous scraping: with 100 pods, about 7.5 cores with no traffic.&lt;/p>
&lt;h3 id="nvidia-dynamo">NVIDIA Dynamo&lt;/h3>
&lt;p>A precise event-driven index, with a global radix tree in each frontend&amp;rsquo;s process. Since all the replicas consume the same event plane, there is no need to synchronise routers with each other for the prefix state.&lt;/p>
&lt;p>The cost function is explicit and weighted. It discounts from the prefill the blocks that overlap in GPU, host and disk with different weights (1.0 for the overlap credit, 0.75 for host, 0.25 for disk), and adds the potential decode blocks and the active requests.&lt;/p>
&lt;p>There is a parameter to look at before deploying: &lt;code>--router-kv-overlap-score-credit-decay&lt;/code> is at &lt;strong>0&lt;/strong> by default, that is, disabled. Its description says what it is for: preventing loaded, cache-rich replicas from winning again and again while the freshly autoscaled ones receive too little traffic. With the default value, a new pod has no cache, therefore never wins the scoring, therefore never generates cache.&lt;/p>
&lt;p>The approximate mode exists (&lt;code>--no-router-kv-events&lt;/code>, with a TTL of 120 seconds) and the documentation says it is not the recommended route in production.&lt;/p>
&lt;p>Dynamo is the most honest project in its measurement methodology: its comparison guide recommends contrasting &lt;code>--router-mode random&lt;/code> against &lt;code>kv&lt;/code> over the public Mooncake trace from FAST'25, with a declared cache ratio of 59 %, and it generates the table locally instead of publishing a number.&lt;/p>
&lt;h3 id="the-rest-of-the-field">The rest of the field&lt;/h3>
&lt;p>&lt;strong>SGLang&lt;/strong> has renamed its router to &lt;code>sgl-model-gateway&lt;/code>, version 0.3.2 within SGLang 0.5.19. Its &lt;code>cache_aware&lt;/code> policy is an approximate radix tree over raw characters, with switching to shortest queue when the system is unbalanced according to two combined thresholds. One detail that can cost an afternoon: the Rust defaults and the Python CLI defaults &lt;strong>do not match&lt;/strong>, and on the maximum tree size they differ by four orders of magnitude (10,000 nodes against 2^26).&lt;/p>
&lt;p>&lt;strong>AIBrix&lt;/strong> 0.7.0 offers a standard mode with a local hash table and a KV event synchronisation mode behind a flag and a build tag, with vLLM 0.7.0 or above.&lt;/p>
&lt;p>&lt;strong>Ray Serve LLM&lt;/strong> has &lt;code>PrefixCacheAffinityRouter&lt;/code> with an explicit alpha API warning, a character-based prefix tree in a decoupled actor, and its imbalance threshold at infinity by default, that is, out of the box it never breaks affinity on load.&lt;/p>
&lt;p>&lt;strong>Envoy AI Gateway&lt;/strong> 1.1.0 implements none of this and delegates to &lt;code>InferencePool&lt;/code> and the EPP. &lt;strong>KServe&lt;/strong> the same, with its &lt;code>LLMInferenceService&lt;/code> at &lt;code>v1alpha1&lt;/code>. &lt;strong>Mooncake Conductor&lt;/strong> is still an unimplemented proposal.&lt;/p>
&lt;h3 id="comparison-table">Comparison table&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Project&lt;/th>
&lt;th>Version and date&lt;/th>
&lt;th>Index&lt;/th>
&lt;th>Where it lives&lt;/th>
&lt;th>Kubernetes&lt;/th>
&lt;th>Declared maturity&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>production-stack &lt;code>prefixaware&lt;/code>&lt;/td>
&lt;td>main branch, 09-Sep-2026&lt;/td>
&lt;td>Approximate, character trie, no eviction&lt;/td>
&lt;td>Router process&lt;/td>
&lt;td>Optional&lt;/td>
&lt;td>WIP in the README&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>production-stack &lt;code>kvaware&lt;/code>/&lt;code>loadaware&lt;/code>&lt;/td>
&lt;td>same&lt;/td>
&lt;td>Exact via LMCache controller&lt;/td>
&lt;td>LMCache controller&lt;/td>
&lt;td>Optional&lt;/td>
&lt;td>No chat completions&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>llm-d Router approximate&lt;/td>
&lt;td>v0.10.0, 17-Aug-2026&lt;/td>
&lt;td>Approximate, LRU per pod&lt;/td>
&lt;td>EPP process&lt;/td>
&lt;td>Yes&lt;/td>
&lt;td>Beta, active-active discouraged&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>llm-d Router exact&lt;/td>
&lt;td>same&lt;/td>
&lt;td>Exact through ZMQ events&lt;/td>
&lt;td>EPP process&lt;/td>
&lt;td>Yes&lt;/td>
&lt;td>Beta&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>NVIDIA Dynamo&lt;/td>
&lt;td>v1.4.2, 27-Aug-2026&lt;/td>
&lt;td>Exact, event-driven radix tree&lt;/td>
&lt;td>Frontend process&lt;/td>
&lt;td>No&lt;/td>
&lt;td>GA with experimental subsystems&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>SGLang &lt;code>sgl-model-gateway&lt;/code>&lt;/td>
&lt;td>0.3.2, 03-Sep-2026&lt;/td>
&lt;td>Approximate, character radix&lt;/td>
&lt;td>Gateway process&lt;/td>
&lt;td>No&lt;/td>
&lt;td>Default policy&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>AIBrix&lt;/td>
&lt;td>v0.7.0, 16-Jun-2026&lt;/td>
&lt;td>Both&lt;/td>
&lt;td>Gateway plugin&lt;/td>
&lt;td>Yes&lt;/td>
&lt;td>Synchronisation behind a flag&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Ray Serve LLM&lt;/td>
&lt;td>Ray 2.58&lt;/td>
&lt;td>Approximate, characters&lt;/td>
&lt;td>Ray actor&lt;/td>
&lt;td>No&lt;/td>
&lt;td>Declared alpha&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Envoy AI Gateway&lt;/td>
&lt;td>v1.1.0, 21-Aug-2026&lt;/td>
&lt;td>None of its own&lt;/td>
&lt;td>Delegates to EPP&lt;/td>
&lt;td>Yes&lt;/td>
&lt;td>Stable 1.x API&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="how-much-it-really-improves">How much it really improves&lt;/h2>
&lt;p>Here two types of source have to be separated.&lt;/p>
&lt;p>&lt;strong>The projects&amp;rsquo; own numbers.&lt;/strong> Red Hat published the llm-d case in May: Qwen3 32B, eight vLLM pods over 16 H100s with tensor parallelism 2, synthetic shared-prefix load with 150 groups of five prompts, 6,000 tokens of system prompt, 1,200 of question and 1,000 of output. Result: up to 109 % more throughput and up to 99 % less TTFT, around 200 concurrent users within SLO against around 20. The repository&amp;rsquo;s result files give more detail: peak throughput from 6,986 to 14,892 output tokens per second, p90 TTFT from 135.5 seconds to 0.26.&lt;/p>
&lt;p>That same file publishes the regression, and that is why it is worth reading: p50 inter-token latency rises by 22.4 % with vLLM and by 45.4 % with SGLang. The trade-off is declared: routing by affinity concentrates more concurrent work on the pods with a warm cache.&lt;/p>
&lt;p>It is the best possible case. A synthetic shared prefix and a reference that is a flat Kubernetes &lt;code>Service&lt;/code>.&lt;/p>
&lt;p>&lt;strong>The independent measurements.&lt;/strong> There are three and they say different things.&lt;/p>
&lt;p>&lt;em>CacheRoute&lt;/em>, from Meta, August 2026, is the most complete. Llama 3.3 70B in fp8, 30 targets with tensor parallelism 2 over 60 H100s, a semi-synthetic trace from production telemetry with 128,824 business keys, and all the alternatives reimplemented in the same harness instead of comparing against a dumb balancer. It obtains 176 requests per second with a p99 SLO of 3.5 seconds against 76 for the best competitor, and a hit rate of 93.2 % against 72.0 %.&lt;/p>
&lt;p>And it publishes two negative findings that nobody else publishes. There are load regimes where affinity &lt;strong>reduces&lt;/strong> capacity to between half and two thirds of the reference, to the point that the authors make a mirrored-traffic trial mandatory before deploying. And growing the fleet can cool a prefix even though total cache capacity grows, because the time between revisits stretches beyond the eviction window. Scaling horizontally can make the hit rate worse.&lt;/p>
&lt;p>&lt;em>GORGO&lt;/em>, June 2026, measures on a multi-region deployment with a dataset where intra-user prefix reuse is 89.4 % and the average prompt is almost 18,000 tokens. An improvement of 6.9 to 15.5 % in p95 TTFT. With extremely high reuse, the improvement is single-digit, because network latency and queuing dominate.&lt;/p>
&lt;p>&lt;em>LAAR&lt;/em>, from IBM Research Tokyo, April 2026, is the uncomfortable counterpoint: in its comparison, session affinity routing was the &lt;strong>worst&lt;/strong> of the baselines, and at 64K contexts a load-based routing gives lower absolute latency at the cost of fewer hits.&lt;/p>
&lt;p>The joint reading fits in three conditions. The big improvements require high, concentrated prefix reuse, long prompts, and a weak reference. Take away any of the three and the numbers deflate.&lt;/p>
&lt;h2 id="the-five-failure-modes">The five failure modes&lt;/h2>
&lt;p>&lt;strong>Hot spot from affinity.&lt;/strong> The busiest bucket inherits the load&amp;rsquo;s skew, and tail latency starts following the hottest target instead of the fleet average. Mitigations exist in the four main products and in three of the four they ship &lt;strong>switched off&lt;/strong>: Dynamo&amp;rsquo;s credit decay at 0, Ray&amp;rsquo;s imbalance threshold at infinity, and production-stack&amp;rsquo;s &lt;code>prefixaware&lt;/code> with none at all.&lt;/p>
&lt;p>&lt;strong>Starvation of the freshly scaled pod.&lt;/strong> A new pod has no cache, so it never wins the scoring, so it never warms up. Dynamo documents it as the reason for the decay parameter. I found no primary documentation from any of the projects about the specific interaction with KEDA.&lt;/p>
&lt;p>&lt;strong>Cost of the index.&lt;/strong> The llm-d numbers in the previous table are the best public reference that exists. Raising the cap on tokens to match from 16,384 to 400,000 can more than double the EPP&amp;rsquo;s CPU with little traffic.&lt;/p>
&lt;p>&lt;strong>Traffic with unique prefixes.&lt;/strong> Each project degrades to something different. SGLang routes to the smallest tree, which is not the same as the least loaded. Ray falls back to power of two choices. Dynamo has an explicit preset, &lt;code>--load-aware&lt;/code>, to say &amp;ldquo;I want the load model without reuse&amp;rdquo;. And production-stack&amp;rsquo;s &lt;code>prefixaware&lt;/code> keeps inserting into the trie, that is, keeps paying the cost while receiving nothing.&lt;/p>
&lt;p>&lt;strong>Sibling bursts.&lt;/strong> Parallel sampling, best of N, or an agent that opens five branches at once. With event-driven routing, no engine has yet emitted the block stored event, all the siblings score zero overlap, and the prefix is precomputed on every replica. Dynamo has a prediction TTL for this; the others do not.&lt;/p>
&lt;h2 id="the-architecture-that-comes-out-of-all-of-the-above">The architecture that comes out of all of the above&lt;/h2>
&lt;p>Two layers, with the responsibilities separated.&lt;/p>
&lt;p>On top, LiteLLM, with what it does do well: non-forgeable identity through the virtual key, budgets, spend logging, concurrency limits, fallback between providers and API unification. For the gateway, each model group has &lt;strong>a single destination&lt;/strong>: the URL of the router below.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">model_list&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">model_name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">qwen-30b&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">litellm_params&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">model&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">hosted_vllm/Qwen3-30B&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">api_base&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">http://kv-router.inferencia.svc:8000/v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">api_key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">os.environ/VLLM_KEY&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">router_settings&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">routing_strategy&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">simple-shuffle&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">num_retries&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">optional_pre_call_checks&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;session_affinity&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">deployment_affinity_ttl_seconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">3600&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">general_settings&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">max_in_flight_requests_per_worker&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">64&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">max_queued_requests_per_worker&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">64&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">admission_queue_timeout_seconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">1.0&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Below, the KV-aware router, inside the engine&amp;rsquo;s domain, talking to the vLLM replicas and consuming their events.&lt;/p>
&lt;p>Four consequences of this separation that have to be accepted before building it.&lt;/p>
&lt;p>Per-replica visibility in LiteLLM is lost. For the gateway there is a single deployment, so its cooldowns, its per-deployment counters and its strategies stop meaning anything. Observability of which replica served what goes downstairs.&lt;/p>
&lt;p>Retries stack up. The client SDK retries, LiteLLM retries, and the router below may have its own failover. In &lt;a href="https://blog.lo0.es/en/posts/humans-agents-same-gateway-priority-traffic-separation/">the previous article&lt;/a> 45 calls per turn came out with three layers; with four it is worse. Lowering &lt;code>num_retries&lt;/code> in the gateway to 1, or to 0, is the sensible decision when there is a router below that already retries.&lt;/p>
&lt;p>LiteLLM&amp;rsquo;s session affinity stops making sense for the KV, because it no longer chooses a replica. It is kept if it is used for something else, such as pinning a conversation to a specific provider.&lt;/p>
&lt;p>And the choice of the router below conditions the rest of the cluster far more than the gateway&amp;rsquo;s does. llm-d requires Kubernetes 1.32 or above, Gateway API, the inference extension and a conformant Gateway. Dynamo does not require Kubernetes. production-stack has a Helm chart and works outside it. That decision is the expensive one, not the gateway&amp;rsquo;s.&lt;/p>
&lt;h2 id="when-not-to-build-this">When not to build this&lt;/h2>
&lt;p>Three cases where the correct answer is not to do it, at least not yet.&lt;/p>
&lt;p>&lt;strong>A single replica per model.&lt;/strong> With one replica, the engine&amp;rsquo;s prefix cache already does all the work and there is nothing to route. That is the case for a good part of the &lt;a href="https://blog.lo0.es/en/posts/vllm-kubernetes-llm-inference-that-scales/">four H100&lt;/a> deployments with one large model and tensor parallelism.&lt;/p>
&lt;p>&lt;strong>Low or scattered prefix reuse.&lt;/strong> Before building anything, the measurement is &lt;code>rate(vllm:prefix_cache_hits_total[5m]) / rate(vllm:prefix_cache_queries_total[5m])&lt;/code> per replica, with a mental correction for the bias from reprefills after eviction. If it is already high with blind distribution, reuse is concentrated inside each conversation, and there LiteLLM&amp;rsquo;s session affinity costs one line of configuration and resolves the case.&lt;/p>
&lt;p>&lt;strong>Traffic where the network dominates.&lt;/strong> The GORGO result is the warning: with enormous prompts and a distributed deployment, the improvement is eaten up by queuing and network latency.&lt;/p>
&lt;p>The case where it does pay off is specific: several replicas of the same model, a large system prompt shared between different users, or a RAG with a corpus of documents that repeat across requests. There the prefill saved is real and it is most of the work.&lt;/p>
&lt;h2 id="checklist">Checklist&lt;/h2>
&lt;ul>
&lt;li>Measure the current hit rate per replica with the two vLLM counters before touching anything, and check whether the engine is evicting with &lt;code>vllm:num_preemptions_total&lt;/code>.&lt;/li>
&lt;li>Check that prefix caching is switched on. It is no longer &lt;code>--enable-prefix-caching&lt;/code> that switches it on: the default value is derived from the model and the log of the decision is at DEBUG level. What is actionable today is &lt;code>--no-enable-prefix-caching&lt;/code> to switch it off.&lt;/li>
&lt;li>Audit the prompts before routing: a timestamp or a session identifier at the start of the system prompt breaks the match from block zero and no routing layer fixes it.&lt;/li>
&lt;li>If the KV event stream is enabled, size the bandwidth by tokens per second and watch discarding at the high water mark. With data parallelism, subscribe to one port per rank.&lt;/li>
&lt;li>If an exact router is chosen, verify the vLLM version against the one the replay buffer requires.&lt;/li>
&lt;li>If llm-d is chosen, explicitly configure the &lt;code>vllm&lt;/code> tokenisation backend. The default &lt;code>estimate&lt;/code> does not fail, it degrades.&lt;/li>
&lt;li>If production-stack is chosen with &lt;code>kvaware&lt;/code> or &lt;code>loadaware&lt;/code>, check first whether the traffic goes through &lt;code>/v1/chat/completions&lt;/code>, because today it does not work there.&lt;/li>
&lt;li>Review the load-based affinity-breaking parameter, because in three of the four main projects it ships disabled.&lt;/li>
&lt;li>Lower &lt;code>num_retries&lt;/code> in LiteLLM when there is a router below that already does failover.&lt;/li>
&lt;li>Trial with mirrored traffic before changing production. It is the explicit recommendation of the only independent measurement that went looking for bad regimes, and found them.&lt;/li>
&lt;/ul>
&lt;h2 id="traps-and-things-that-are-not-what-they-seem">Traps and things that are not what they seem&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>LiteLLM has no prefix routing in any version.&lt;/strong> Neither the open one nor the paid one. I got it wrong in June.&lt;/li>
&lt;li>&lt;strong>&lt;code>prompt_caching&lt;/code> does nothing if the client does not send &lt;code>cache_control&lt;/code>&lt;/strong>, and with the default automatic injection it fails on every turn because it marks the last message.&lt;/li>
&lt;li>&lt;strong>That pin&amp;rsquo;s TTL is 300 hardcoded seconds&lt;/strong>, incompatible with the one-hour caches that LiteLLM itself knows how to request.&lt;/li>
&lt;li>&lt;strong>production-stack&amp;rsquo;s &lt;code>prefixaware&lt;/code> indexes characters, not tokens&lt;/strong>, in non-configurable chunks of 128, and its trie is never purged and models no eviction.&lt;/li>
&lt;li>&lt;strong>production-stack&amp;rsquo;s &lt;code>kvaware&lt;/code> and &lt;code>loadaware&lt;/code> do not support chat completions.&lt;/strong> They tokenise an empty string.&lt;/li>
&lt;li>&lt;strong>The default tokeniser in llm-d&amp;rsquo;s EPP is a byte estimate&lt;/strong>, and with it the exact scorer degrades silently.&lt;/li>
&lt;li>&lt;strong>llm-d&amp;rsquo;s active-active mode is discouraged with approximate prefixes&lt;/strong>, and the reference guides fix one replica even with the exact one.&lt;/li>
&lt;li>&lt;strong>Dynamo&amp;rsquo;s overlap credit decay ships at zero&lt;/strong>, which can leave a freshly autoscaled replica with no traffic.&lt;/li>
&lt;li>&lt;strong>The SGLang router&amp;rsquo;s default values differ between the Rust and the Python CLI&lt;/strong>, by as much as four orders of magnitude.&lt;/li>
&lt;li>&lt;strong>&lt;code>vllm:gpu_prefix_cache_hit_rate&lt;/code> no longer exists&lt;/strong> and &lt;code>vllm:gpu_cache_usage_perc&lt;/code> is now called &lt;code>vllm:kv_cache_usage_perc&lt;/code>. Old panels and autoscalers are measuring nothing.&lt;/li>
&lt;li>&lt;strong>The hit rate counts the reprefill after eviction as a hit.&lt;/strong> A high number can be reuse or it can be thrashing.&lt;/li>
&lt;li>&lt;strong>KV events do not publish the hits by default&lt;/strong>, only the additions, unless full mode is requested request by request.&lt;/li>
&lt;li>&lt;strong>The hashes travel truncated to 64 bits&lt;/strong> unless it is disabled with an environment variable.&lt;/li>
&lt;li>&lt;strong>The default block size is 16, and the attention backend can change it&lt;/strong> without anyone asking.&lt;/li>
&lt;li>&lt;strong>The Endpoint Picker left the Gateway API Inference Extension repository.&lt;/strong> Looking for it there today leads nowhere.&lt;/li>
&lt;/ul>
&lt;h2 id="closing">Closing&lt;/h2>
&lt;p>June&amp;rsquo;s error has a reading that goes beyond the erratum. It came from reading a product&amp;rsquo;s documentation and not its code, and from the fact that LiteLLM&amp;rsquo;s documentation uses the word &amp;ldquo;caching&amp;rdquo; in a pre-call check that does something else. The distance between what a name suggests and what a function does is, at this point in the track, the most repeated pattern of the whole series.&lt;/p>
&lt;p>The architectural conclusion is that KV-aware routing is not a gateway function. It is not one today in LiteLLM and probably should not be: it requires keeping an index synchronised with each engine&amp;rsquo;s memory, replicating its hash function, consuming an event stream and sizing CPU per request per second. That belongs to the engine&amp;rsquo;s domain, not to that of identity and budget.&lt;/p>
&lt;p>What remains is a two-part decision. The first is whether the traffic deserves it, and that is answered with two Prometheus counters and without installing anything. The second is which of the three routers fits the cluster you already have, and there the deciding variable is not the hit rate but whether you are willing to bring in Gateway API and the inference extension, or to pin vLLM 0.13.0, or to operate a Dynamo frontend.&lt;/p>
&lt;p>And the honesty the material demands: the only independent measurement that specifically went looking for regimes where this makes things worse found them, and they are not marginal. Half to two thirds of reference capacity is a serious regression. That no project publishes that side of the curve does not mean it does not exist in theirs.&lt;/p>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/humans-agents-same-gateway-priority-traffic-separation/">Humans and agents on the same gateway&lt;/a>, the session affinity and the pipeline order taken as read here, and the rest of what the gateway can do with two classes of traffic.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/llm-inference-router-l7-switchboard/">The LLM inference router&lt;/a>, the June article this one corrects, and the router&amp;rsquo;s other four functions that remain valid.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">Prefix cache: hit rate engineering&lt;/a>, the template audit to do before even considering routing anything.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache: fundamentals&lt;/a>, what exactly it is that you are trying not to recompute.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/long-context-kv-offloading-notebook-desk/">Long context and KV offloading&lt;/a>, LMCache and the memory hierarchy that &lt;code>kvaware&lt;/code> and Dynamo&amp;rsquo;s per-tier weights depend on.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/optimising-prefill-vllm-knobs-ttft-will-not-forgive/">Prefill optimisations in vLLM&lt;/a>, the specific work saved when routing gets it right.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">The vLLM scheduler step&lt;/a>, the loop where the KV events are published, once per step.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/instrumenting-vllm-otel-measuring-optimisations/">OTel instrumentation in vLLM&lt;/a>, the engine&amp;rsquo;s metrics, including the ones that have changed name.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/choosing-oss-gateway-llm-inference/">Choosing the switchboard&lt;/a>, why the gateway is chosen on licence and fit before features, which is exactly what this article illustrates again.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/vllm-kubernetes-llm-inference-that-scales/">vLLM on Kubernetes&lt;/a>, the replica deployment that everything above operates on.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/sizing-agents-decode-bottleneck/">Sizing for agents&lt;/a>, why without this article&amp;rsquo;s session affinity the capacity calculation describes a different system, with the prefix hit rate measured in production.&lt;/li>
&lt;/ul>
&lt;h2 id="sources">Sources&lt;/h2>
&lt;ul>
&lt;li>LiteLLM, &lt;em>Router - Load Balancing&lt;/em> (estrategias, comprobaciones previas, afinidad): &lt;a href="https://docs.litellm.ai/docs/routing">https://docs.litellm.ai/docs/routing&lt;/a>.&lt;/li>
&lt;li>LiteLLM, código: &lt;code>litellm/router.py&lt;/code>, &lt;code>litellm/router_utils/prompt_caching_cache.py&lt;/code>, &lt;code>litellm/router_utils/pre_call_checks/prompt_caching_deployment_check.py&lt;/code>, &lt;code>litellm/router_utils/pre_call_checks/deployment_affinity_check.py&lt;/code>, &lt;code>litellm/proxy/litellm_pre_call_utils.py&lt;/code>, &lt;code>litellm/proxy/middleware/admission_control_middleware.py&lt;/code>: &lt;a href="https://github.com/BerriAI/litellm">https://github.com/BerriAI/litellm&lt;/a>.&lt;/li>
&lt;li>LiteLLM, incidencia 28427, TTL de afinidad por caché de prompts fijado a cinco minutos: &lt;a href="https://github.com/BerriAI/litellm/issues/28427">https://github.com/BerriAI/litellm/issues/28427&lt;/a>.&lt;/li>
&lt;li>vLLM, código: &lt;code>vllm/v1/core/kv_cache_utils.py&lt;/code>, &lt;code>vllm/v1/core/block_pool.py&lt;/code>, &lt;code>vllm/v1/core/kv_cache_manager.py&lt;/code>, &lt;code>vllm/distributed/kv_events.py&lt;/code>, &lt;code>vllm/config/kv_events.py&lt;/code>, &lt;code>vllm/v1/metrics/loggers.py&lt;/code>, &lt;code>vllm/v1/metrics/stats.py&lt;/code>: &lt;a href="https://github.com/vllm-project/vllm">https://github.com/vllm-project/vllm&lt;/a>.&lt;/li>
&lt;li>vLLM, &lt;em>KV offloading usage&lt;/em> (niveles CPU, filesystem y objeto; compartición entre procesos): &lt;a href="https://docs.vllm.ai/en/latest/features/kv_offloading_usage.html">https://docs.vllm.ai/en/latest/features/kv_offloading_usage.html&lt;/a>.&lt;/li>
&lt;li>vLLM, notas de la versión 0.29.0 (semilla determinista, seguimiento de propiedad en eventos, flags de admisión): &lt;a href="https://github.com/vllm-project/vllm/releases/tag/v0.29.0">https://github.com/vllm-project/vllm/releases/tag/v0.29.0&lt;/a>.&lt;/li>
&lt;li>vLLM, RFC 16669, publicación de bloques KV y métricas: &lt;a href="https://github.com/vllm-project/vllm/issues/16669">https://github.com/vllm-project/vllm/issues/16669&lt;/a>.&lt;/li>
&lt;li>vLLM production-stack, código: &lt;code>src/vllm_router/routers/routing_logic.py&lt;/code>, &lt;code>src/vllm_router/prefix/hashtrie.py&lt;/code>, &lt;code>src/vllm_router/parsers/parser.py&lt;/code>: &lt;a href="https://github.com/vllm-project/production-stack">https://github.com/vllm-project/production-stack&lt;/a>.&lt;/li>
&lt;li>LMCache Lab, resultados de production-stack frente a AIBrix (parte interesada): &lt;a href="https://blog.lmcache.ai/en/2025/03/06/open-source-llm-inference-cluster-performing-10x-faster-than-sota-oss-solution/">https://blog.lmcache.ai/en/2025/03/06/open-source-llm-inference-cluster-performing-10x-faster-than-sota-oss-solution/&lt;/a>.&lt;/li>
&lt;li>llm-d Router, código y documentación de operaciones (pesos por defecto, dimensionamiento del EPP, aviso de activo-activo): &lt;a href="https://github.com/llm-d/llm-d-router">https://github.com/llm-d/llm-d-router&lt;/a>.&lt;/li>
&lt;li>llm-d, guía de enrutado preciso por prefijo y resultados publicados (parte interesada): &lt;a href="https://github.com/llm-d/llm-d">https://github.com/llm-d/llm-d&lt;/a>.&lt;/li>
&lt;li>llm-d Router, incidencia 1290, estado de prefijo no compartido entre réplicas del EPP: &lt;a href="https://github.com/llm-d/llm-d-router/issues/1290">https://github.com/llm-d/llm-d-router/issues/1290&lt;/a>.&lt;/li>
&lt;li>Red Hat, &lt;em>Same 16 GPUs, twice the users&lt;/em> (parte interesada): &lt;a href="https://www.redhat.com/en/blog/same-16-gpus-twice-users-inference-aware-routing-llm-clusters">https://www.redhat.com/en/blog/same-16-gpus-twice-users-inference-aware-routing-llm-clusters&lt;/a>.&lt;/li>
&lt;li>Kubernetes SIG Network, Gateway API Inference Extension (traslado del EPP y del BBR): &lt;a href="https://github.com/kubernetes-sigs/gateway-api-inference-extension">https://github.com/kubernetes-sigs/gateway-api-inference-extension&lt;/a>.&lt;/li>
&lt;li>NVIDIA Dynamo, diseño y ajuste del router KV: &lt;a href="https://github.com/ai-dynamo/dynamo">https://github.com/ai-dynamo/dynamo&lt;/a>.&lt;/li>
&lt;li>SGLang, &lt;code>sgl-model-gateway&lt;/code>: &lt;a href="https://github.com/sgl-project/sglang/tree/main/sgl-model-gateway">https://github.com/sgl-project/sglang/tree/main/sgl-model-gateway&lt;/a>.&lt;/li>
&lt;li>AIBrix, enrutado por caché de prefijo: &lt;a href="https://github.com/vllm-project/aibrix/blob/main/pkg/plugins/gateway/algorithms/prefix_cache_readme.md">https://github.com/vllm-project/aibrix/blob/main/pkg/plugins/gateway/algorithms/prefix_cache_readme.md&lt;/a>.&lt;/li>
&lt;li>Ray Serve LLM, enrutado consciente de prefijo (API en alfa): &lt;a href="https://docs.ray.io/en/latest/serve/llm/user-guides/prefix-aware-routing.html">https://docs.ray.io/en/latest/serve/llm/user-guides/prefix-aware-routing.html&lt;/a>.&lt;/li>
&lt;li>Huang Cheng (Meta), &lt;em>CacheRoute&lt;/em>, agosto de 2026: &lt;a href="https://arxiv.org/html/2608.19677">https://arxiv.org/html/2608.19677&lt;/a>.&lt;/li>
&lt;li>Yuan et al., &lt;em>DualMap&lt;/em>, febrero de 2026: &lt;a href="https://arxiv.org/abs/2602.06502">https://arxiv.org/abs/2602.06502&lt;/a>.&lt;/li>
&lt;li>Ricci Toniolo et al., &lt;em>GORGO&lt;/em>, junio de 2026: &lt;a href="https://arxiv.org/html/2602.11688">https://arxiv.org/html/2602.11688&lt;/a>.&lt;/li>
&lt;li>Yoshimura, Chiba y van de Beek, &lt;em>Accuracy Is Speed&lt;/em> (EuroMLSys &amp;lsquo;26), abril de 2026: &lt;a href="https://arxiv.org/html/2604.15732v1">https://arxiv.org/html/2604.15732v1&lt;/a>.&lt;/li>
&lt;/ul></description></item><item><title>Serving reasoning models: the invisible scratchpad that decides your latency and your bill</title><link>https://blog.lo0.es/en/posts/serving-reasoning-models-invisible-scratchpad-latency-bill/</link><pubDate>Fri, 12 Jun 2026 05:30:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/serving-reasoning-models-invisible-scratchpad-latency-bill/</guid><description>&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>A reasoning model generates, before the answer you see, a &lt;strong>thinking block&lt;/strong>, hundreds or thousands of tokens enclosed between &lt;code>&amp;lt;think&amp;gt;&lt;/code> and &lt;code>&amp;lt;/think&amp;gt;&lt;/code>, that the user does not read but that &lt;strong>consumes the same compute, the same VRAM and the same bill&lt;/strong> as any other token. Serving them in production is not &amp;ldquo;serving a bigger model&amp;rdquo;: it is serving a model whose cost per request is &lt;strong>variable and, by default, uncontrolled&lt;/strong>. Three levers change the equation: choosing well between &lt;strong>think / non-think mode&lt;/strong> (the hybrid models of 2026 allow it within the same weights), setting a &lt;strong>reasoning budget&lt;/strong> (&lt;code>thinking_token_budget&lt;/code> in vLLM, s1-style &lt;em>budget forcing&lt;/em>) and &lt;strong>measuring the impact on the KV cache&lt;/strong> (a 30k-token reasoning chain can eat ~9 GB of KV in FP16). Managed well, you gain accuracy where it matters; managed badly, you pay up to &lt;strong>113× more energy&lt;/strong> for an answer that did not need that much thinking.&lt;/p>
&lt;hr>
&lt;h2 id="the-analogy">The analogy&lt;/h2>
&lt;p>Picture a candidate sitting a competitive exam. Before writing the good answer on the official sheet, they fill three sheets of scratch paper: they try approaches, correct themselves, discard. Those scratch sheets are not handed in, the board only reads the final answer, but the candidate has spent ink, time and half an hour of the exam on them.&lt;/p>
&lt;p>A reasoning model does exactly that. The &lt;code>&amp;lt;think&amp;gt;…&amp;lt;/think&amp;gt;&lt;/code> block is the scratch paper: it reasons out loud, contradicts itself, backtracks, and finally emits the &amp;ldquo;clean&amp;rdquo; answer. The production problem is that &lt;strong>you pay for the scratch paper too&lt;/strong>: every reasoning token takes a slot in the batch, grows the KV cache and adds to the bill just like an output token. And, like any nervous candidate, the model tends to &lt;strong>overthink&lt;/strong>: it writes five sheets when one would have done.&lt;/p>
&lt;p>The operational question in this post is not &amp;ldquo;does it reason well?&amp;rdquo;, but &amp;ldquo;how much scratch paper do I let it write, and when do I take the pen away?&amp;rdquo;.&lt;/p>
&lt;hr>
&lt;h2 id="what-changes-when-the-model-thinks">What changes when the model &amp;ldquo;thinks&amp;rdquo;&lt;/h2>
&lt;p>In a normal model, a request is: prompt → output tokens. In a reasoning model the sequence has two stretches:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Reasoning block&lt;/strong> (&lt;code>&amp;lt;think&amp;gt; … &amp;lt;/think&amp;gt;&lt;/code>): the chain of thought (CoT). Long, variable, normally hidden from the end user.&lt;/li>
&lt;li>&lt;strong>Final answer&lt;/strong>: what the user sees.&lt;/li>
&lt;/ol>
&lt;p>vLLM models this explicitly. When started with a &lt;em>reasoning parser&lt;/em>, the output carries a &lt;code>reasoning_content&lt;/code> field separate from &lt;code>content&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-32B &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --reasoning-parser deepseek_r1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The parser detects the thinking delimiters and separates both stretches in the API response (&lt;a href="https://docs.vllm.ai/en/stable/features/reasoning_outputs/">vLLM · Reasoning Outputs&lt;/a>). This matters for serving for one practical reason: if your gateway or your UI does not separate &lt;code>reasoning_content&lt;/code> from &lt;code>content&lt;/code>, you will end up showing the scratch paper, or, worse, recording it in logs and traces without meaning to.&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1rem auto;">
&lt;svg viewBox="0 0 780 210" role="img" aria-label="Anatomy of a request to a reasoning model: prompt, thinking block with budget, final answer" xmlns="http://www.w3.org/2000/svg">
&lt;defs>&lt;marker id="rzm" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="currentColor"/>&lt;/marker>&lt;/defs>
&lt;style>.bx{fill:none;stroke:currentColor;stroke-width:1.3}.dsh{fill:none;stroke:currentColor;stroke-width:1.3;stroke-dasharray:5 3}.tl{font:600 12px sans-serif;fill:currentColor}.ts{font:11px sans-serif;fill:currentColor}.ar{fill:none;stroke:currentColor;stroke-width:1.3;marker-end:url(#rzm)}&lt;/style>
&lt;text x="20" y="28" class="tl">Request&lt;/text>
&lt;rect class="bx" x="20" y="38" width="120" height="50" rx="6"/>
&lt;text x="32" y="60" class="ts">prompt + system&lt;/text>
&lt;text x="32" y="76" class="ts">(visible · billable)&lt;/text>
&lt;path class="ar" d="M140,63 L180,63"/>
&lt;text x="190" y="28" class="tl">Reasoning block &amp;lt;think&amp;gt; … &amp;lt;/think&amp;gt;&lt;/text>
&lt;rect class="dsh" x="190" y="38" width="360" height="80" rx="6"/>
&lt;text x="204" y="60" class="ts">hundreds–thousands of tokens HIDDEN from the user&lt;/text>
&lt;text x="204" y="78" class="ts">grow the KV cache · add to the bill as output&lt;/text>
&lt;text x="204" y="96" class="ts">cap: thinking_token_budget → forces &amp;lt;/think&amp;gt;&lt;/text>
&lt;path class="ar" d="M550,78 L590,78"/>
&lt;text x="600" y="28" class="tl">Answer&lt;/text>
&lt;rect class="bx" x="600" y="38" width="150" height="80" rx="6"/>
&lt;text x="612" y="64" class="ts">final content&lt;/text>
&lt;text x="612" y="82" class="ts">(all the user&lt;/text>
&lt;text x="612" y="98" class="ts">ever sees)&lt;/text>
&lt;text x="20" y="150" class="tl">Cost per request = prompt + reasoning + answer&lt;/text>
&lt;text x="20" y="172" class="ts">Reasoning is invisible in the UI but NOT on the GPU or in the bill. It is the variable that unbalances your cost per request.&lt;/text>
&lt;text x="20" y="192" class="ts">Operational rule: separate reasoning_content from content at the gateway, and set a thinking budget per route.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;hr>
&lt;h2 id="the-2026-landscape-from-the-model-that-always-reasons-to-the-switchable-hybrid">The 2026 landscape: from the model that &amp;ldquo;always reasons&amp;rdquo; to the switchable hybrid&lt;/h2>
&lt;p>The first generation (o1, DeepSeek-R1, QwQ-32B) were models that always reasoned. In 2026 the dominant pattern is the hybrid: a single set of weights that switches between &lt;em>think&lt;/em> and &lt;em>non-think&lt;/em>.&lt;/p>
&lt;ul>
&lt;li>DeepSeek-V3.1 introduced a hybrid reasoning architecture in a single model: &lt;code>DeepSeek-V3.1-Think&lt;/code> for complex problems and a faster direct mode for the trivial, switchable by the user (&lt;a href="https://www.infoq.com/news/2025/09/deepseek-v31-hybrid/">InfoQ&lt;/a>). Important for serving: reasoning is off by default and is turned on with &lt;code>thinking=True&lt;/code> in &lt;code>chat_template_kwargs&lt;/code>.&lt;/li>
&lt;li>Qwen3 brings &lt;em>Hybrid Thinking Modes&lt;/em> and an explicit Thinking Budget to bound the reasoning compute; in its series thinking is on by default (like QwQ-32B).&lt;/li>
&lt;li>gpt-oss shows a different reasoning structure from the R1/Qwen family, which in practice means that &lt;strong>the parser and the delimiters are not universal&lt;/strong>: each family has its own.&lt;/li>
&lt;/ul>
&lt;p>The architectural consequence is clear: in 2026 you no longer decide &amp;ldquo;a model that reasons&amp;rdquo; vs &amp;ldquo;one that does not&amp;rdquo;, but &lt;strong>when you let the same model reason&lt;/strong>. That turns reasoning into a &lt;em>routing&lt;/em> and budgeting decision, not a model-catalogue one. It connects directly with &lt;a href="https://blog.lo0.es/en/posts/llm-inference-router-l7-switchboard/">the L7 inference router&lt;/a>: the &amp;ldquo;cheap&amp;rdquo; route turns thinking off; the &amp;ldquo;expensive&amp;rdquo; one turns it on with a cap.&lt;/p>
&lt;hr>
&lt;h2 id="the-economics-why-the-scratch-paper-drives-up-the-bill">The economics: why the scratch paper drives up the bill&lt;/h2>
&lt;p>Here is the heart of the problem. Reasoning tokens are invisible to the user but real in compute and in billing. Providers charge them as output tokens; API providers bill those &lt;em>reasoning tokens&lt;/em> at the output price, not for free (&lt;a href="https://medium.com/@Elongated_musk/test-time-compute-quietly-changed-the-economics-of-inference-9d0b8d77641c">Test-Time Compute Quietly Changed the Economics of Inference&lt;/a>). On-premise there is no external invoice, but there is a cost: they occupy batch slots, KV VRAM and watts.&lt;/p>
&lt;p>The billable cost (or the equivalent cost in GPU·hours) of a request is:&lt;/p>
$$\text{compute tokens} = \text{prompt} + \underbrace{\text{reasoning tokens}}_{\text{hidden, variable}} + \text{visible answer}$$
&lt;p>The middle term is the one that runs out of control. On hard tasks the reasoning/visible-answer ratio can be enormous, and empirical analysis has measured up to 113× the energy cost against standard inference on certain coding tasks (&lt;a href="https://towardsdatascience.com/inference-scaling-test-time-compute-why-reasoning-models-raise-your-compute-bill/">Towards Data Science · Inference Scaling&lt;/a>).&lt;/p>
&lt;p>And it does not always buy accuracy. The overthinking phenomenon is documented: more thinking does not guarantee a better answer, and beyond a certain point it makes things worse. There is work showing that &lt;strong>shorter chains are up to 34.5 % more accurate&lt;/strong> than the longest one sampled for the same question (&lt;a href="https://arxiv.org/pdf/2505.17813">Don&amp;rsquo;t Overthink it&lt;/a>), plus studies on the &amp;ldquo;mirage&amp;rdquo; of test-time scaling (&lt;a href="https://arxiv.org/pdf/2506.04210">Mirage of Test-Time Scaling&lt;/a>) and on when &lt;em>more thinking hurts&lt;/em> (&lt;a href="https://arxiv.org/html/2604.10739v1">When More Thinking Hurts&lt;/a>). The first large-scale study of test-time scaling, more than &lt;strong>30 billion tokens&lt;/strong> generated with 8 open-source LLMs from 7B to 235B across 4 reasoning datasets, systematises where it scales and where it does not (&lt;a href="https://arxiv.org/abs/2512.02008">The Art of Scaling Test-Time Compute&lt;/a>).&lt;/p>
&lt;p>The operational reading: &lt;strong>reasoning is a cost you have to budget for, not a &amp;ldquo;more quality&amp;rdquo; switch you leave on full all the time.&lt;/strong>&lt;/p>
&lt;hr>
&lt;h2 id="controlling-the-thinking-budget">Controlling the thinking budget&lt;/h2>
&lt;p>Three mechanisms, from coarsest to finest.&lt;/p>
&lt;h3 id="1-switching-think--non-think">1. Switching think / non-think&lt;/h3>
&lt;p>The cheapest thing is not to reason when it is not needed. On hybrid models, turn thinking off for classification, extraction, formatting, trivial answers:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># DeepSeek-V3.1: reasoning OFF by default; turned on explicitly&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">chat_template_kwargs&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;thinking&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">True&lt;/span>&lt;span class="p">}&lt;/span> &lt;span class="c1"># only on the &amp;#34;hard&amp;#34; route&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This is 80 % of the saving for 20 % of the effort: route by difficulty and reserve thinking for what actually pays for it.&lt;/p>
&lt;h3 id="2-setting-a-cap-thinking_token_budget">2. Setting a cap: &lt;code>thinking_token_budget&lt;/code>&lt;/h3>
&lt;p>vLLM ships a &lt;em>sampling parameter&lt;/em> &lt;code>thinking_token_budget&lt;/code> that counts reasoning tokens and, on reaching the limit, forces the block to close (&lt;code>reasoning_end_str&lt;/code>, typically &lt;code>&amp;lt;/think&amp;gt;&lt;/code>), making the model answer straight away. If it is not specified, there is no limit other than &lt;code>max_tokens&lt;/code> (&lt;a href="https://github.com/vllm-project/vllm/pull/37112">PR #37112&lt;/a>, &lt;a href="https://shuyo.wordpress.com/2026/03/26/adding-reasoning-budget-to-vllm-reasoning-token-limit/">implementation note&lt;/a>). Underneath, a &lt;code>ReasoningBudgetLogitsProcessor&lt;/code> injects something like &lt;em>&amp;ldquo;Let me stop thinking and answer now.&lt;code>&amp;lt;/think&amp;gt;&lt;/code>&amp;rdquo;&lt;/em> when the cap is reached.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Define the delimiters of the reasoning block&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">vllm serve Qwen/Qwen3-32B &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --reasoning-parser qwen3 &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --reasoning-config &lt;span class="s1">&amp;#39;{&amp;#34;reasoning_start_str&amp;#34;:&amp;#34;&amp;lt;think&amp;gt;&amp;#34;,&amp;#34;reasoning_end_str&amp;#34;:&amp;#34;&amp;lt;/think&amp;gt;&amp;#34;}&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// per request: cut the scratch paper off at 1024 tokens
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;messages&amp;#34;&lt;/span>&lt;span class="p">:[&lt;/span>&lt;span class="err">...&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="nt">&amp;#34;thinking_token_budget&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1024&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-budget-forcing-state-of-the-art">3. Budget forcing (state of the art)&lt;/h3>
&lt;p>The technique that popularised fine-grained control is &lt;strong>budget forcing&lt;/strong>, from the s1 paper: to spend &lt;em>less&lt;/em>, thinking is terminated by forcing the end delimiter; to spend &lt;em>more&lt;/em>, the end is suppressed and the word &amp;ldquo;Wait&amp;rdquo; is appended, which pushes the model to review and often correct its own reasoning. With this, &lt;code>s1-32B&lt;/code> (a Qwen2.5-32B-Instruct fine-tuned on just 1,000 examples) &lt;strong>beat o1-preview by as much as 27 %&lt;/strong> on AIME24/MATH (&lt;a href="https://arxiv.org/abs/2501.19393">s1: Simple Test-Time Scaling&lt;/a>). The serving lesson: the budget is not only a cost cap, it is a &lt;strong>bidirectional quality lever&lt;/strong>.&lt;/p>
$$\text{accuracy} \approx f(\text{reasoning tokens}) \quad\text{with a maximum, not monotonic}$$
&lt;p>The curve rises, saturates and on many tasks falls. Your job is to operate it near the knee, not at the extreme.&lt;/p>
&lt;hr>
&lt;h2 id="the-impact-almost-nobody-measures-the-kv-cache">The impact almost nobody measures: the KV cache&lt;/h2>
&lt;p>This is where reasoning really bites serving. Every token of scratch paper &lt;strong>is one more token in the KV cache&lt;/strong>. A long reasoning chain inflates the working memory just like a long input context.&lt;/p>
&lt;p>The KV size grows linearly with the sequence (reasoning included):&lt;/p>
$$\text{KV bytes} = 2 \times L \times h_{kv} \times d_{head} \times s \times b$$
&lt;p>where \(L\) is layers, \(h_{kv}\) KV heads (few, with GQA), \(d_{head}\) the per-head dimension, \(s\) the sequence length and \(b\) the bytes per element. The term reasoning blows up is \(s\): a &amp;ldquo;normal&amp;rdquo; 500-token answer and one with 8,000 tokens of thinking do not take up the same space, not by a long way.&lt;/p>
&lt;p>The real numbers are frightening: for a distilled reasoning model with standard attention such as &lt;code>DeepSeek-R1-Distill-Llama-70B&lt;/code>, &lt;strong>a single 30,000-token reasoning chain consumes ~9 GB of KV in FP16&lt;/strong>, which quantising the KV to FP8 reduces to ~4.5 GB, one of the highest-impact optimisations for chain-of-thought workloads (&lt;a href="https://www.spheron.network/blog/kv-cache-optimization-guide/">Spheron · KV Cache Optimization&lt;/a>). Multiply that by concurrency and you understand why a cluster that served 200 simultaneous requests of a &amp;ldquo;normal&amp;rdquo; model drops to 40 with the same model reasoning.&lt;/p>
&lt;p>Two state-of-the-art nuances worth knowing:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Prefix caching is not free here.&lt;/strong> The empirical study of reasoning-model serving finds that &lt;em>prefix caching&lt;/em> clearly improves speed on models of 14B or more, but hurts on 7B models (cache management costs more than it saves) (&lt;a href="https://arxiv.org/pdf/2510.18672">Reasoning Language Model Inference Serving Unveiled&lt;/a>). And since the bulk of the reasoning cost sits in the decode (generating tokens one by one), prefix caching, which only speeds up the prefill, barely touches the expensive phase. It connects with &lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">prefix cache: engineering the hit rate&lt;/a>.&lt;/li>
&lt;li>&lt;strong>Reasoning-specific KV compression.&lt;/strong> Techniques such as R-KV have appeared, compressing the KV by exploiting the redundancy typical of chains of thought (the model repeats itself and rambles), recovering memory without touching quality (&lt;a href="https://arxiv.org/pdf/2505.24133">R-KV&lt;/a>).&lt;/li>
&lt;/ul>
&lt;p>The most profitable and available lever today is still &lt;strong>KV in FP8&lt;/strong> (see &lt;a href="https://blog.lo0.es/en/posts/fp8-end-to-end-enable-measure-quality-decide/">FP8 end to end&lt;/a>) combined with a reasoning budget that avoids 30k-token tails in the first place.&lt;/p>
&lt;hr>
&lt;h2 id="reasoning--structured-output-order-matters">Reasoning + structured output: order matters&lt;/h2>
&lt;p>If you serve &lt;em>structured output&lt;/em> (JSON with a schema) and reasoning at the same time, there is a subtle trap: the grammar must not be applied during the thinking block. The model needs free text to reason; forcing the schema inside the &lt;code>&amp;lt;think&amp;gt;&lt;/code> breaks the reasoning. vLLM solves it by having the structured-output engine (xgrammar) use the reasoner&amp;rsquo;s &lt;code>end_token_id&lt;/code> to skip the constraint while the block lasts and apply it only to the final answer (&lt;a href="https://docs.vllm.ai/en/stable/features/reasoning_outputs/">vLLM · Reasoning Outputs&lt;/a>). If you build this by hand on another engine, remember: &lt;strong>first let it think, then impose the form&lt;/strong>. It links with &lt;a href="https://blog.lo0.es/en/posts/structured-output-bitmask-outlines-xgrammar-llguidance/">structured output&lt;/a>.&lt;/p>
&lt;hr>
&lt;h2 id="reference-architecture">Reference architecture&lt;/h2>
&lt;p>On the blog&amp;rsquo;s example cluster, a node of 4×H100 SXM (80 GB, NVLink), a sensible topology for serving reasoning without wrecking the SLO:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>A cheap difficulty classifier&lt;/strong> up front (a small model or rules) that picks the route. Most of the traffic does not need to think.&lt;/li>
&lt;li>&lt;strong>Fast route (non-think):&lt;/strong> the same hybrid model with reasoning off. Low TTFT, predictable cost.&lt;/li>
&lt;li>&lt;strong>Reasoning route (think):&lt;/strong> reasoning on &lt;strong>with &lt;code>thinking_token_budget&lt;/code> by default&lt;/strong> (say 1–2k tokens) and the option to raise it per request for the genuinely hard cases.&lt;/li>
&lt;li>KV in FP8 in the engine on the reasoning route, plus per-request reasoning-length metrics exported to your observability (&lt;a href="https://blog.lo0.es/en/posts/instrumenting-vllm-otel-measuring-optimisations/">instrumenting vLLM with OTel&lt;/a>).&lt;/li>
&lt;/ol>
&lt;p>To prototype this routing outside the cluster, an RTX 5090 (Blackwell, 32 GB) serves a 7–14B reasoning model and lets you validate parsers, budgets and the &lt;code>reasoning_content&lt;/code>/&lt;code>content&lt;/code> separation before touching the H100s. Do not expect to serve a 32B in &lt;em>think&lt;/em> mode at high concurrency on a consumer card: the reasoning KV eats the 32 GB in no time.&lt;/p>
&lt;p>Sizing starts, as always, from an SLO; the difference is that now the &amp;ldquo;answer size&amp;rdquo; in your &lt;a href="https://blog.lo0.es/en/posts/capacity-planning-on-premise-llm-inference/">capacity planning&lt;/a> has to count the scratch paper, not just the visible answer.&lt;/p>
&lt;hr>
&lt;h2 id="operational-pitfalls-and-honest-scepticism">Operational pitfalls (and honest scepticism)&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>Leaking &lt;code>reasoning_content&lt;/code>.&lt;/strong> If the gateway does not separate it, you end up showing or logging the scratch paper, which may contain wrong attempts, sensitive data or language you do not want in your UI. Always separate it at L7.&lt;/li>
&lt;li>&lt;strong>Serving reasoning &amp;ldquo;just in case&amp;rdquo;.&lt;/strong> Overthinking is real and sometimes lowers accuracy. Do not turn &lt;em>think&lt;/em> on by default: turn it on per route, with a budget.&lt;/li>
&lt;li>&lt;strong>Forgetting the KV.&lt;/strong> The most common mistake: sizing concurrency from the length of the visible answer. The KV is dictated by the total sequence, reasoning included. Measure p50/p95 &lt;code>reasoning tokens&lt;/code> per endpoint.&lt;/li>
&lt;li>&lt;strong>Prefix caching as a silver bullet.&lt;/strong> On small models it can make things worse, and in any case it does not touch the decode, which is where the reasoning cost goes.&lt;/li>
&lt;li>&lt;strong>Assuming universal delimiters.&lt;/strong> R1, Qwen3 and gpt-oss do not share a reasoning structure. Use the right &lt;code>--reasoning-parser&lt;/code> per family and test &lt;em>streaming&lt;/em> (the parser has to separate correctly token by token).&lt;/li>
&lt;li>&lt;strong>Believing more compute = more intelligence.&lt;/strong> The state of the art (s1, short-m@k, &amp;ldquo;When More Thinking Hurts&amp;rdquo;) points the other way in many cases: there is a knee, and operating beyond it is burning watts. Test-time compute is a tool with diminishing, and sometimes negative, returns, not a linear lever.&lt;/li>
&lt;/ol>
&lt;p>A note of caution for June 2026: the field of reasoning control (budget forcing, reasoning-specific KV compression, thinking &lt;em>early-exit&lt;/em>) moves fast and almost all of it is very recent. The specific figures, the 113×, the 34.5 %, the 9 GB, depend on model, task and configuration; take them as an &lt;strong>order of magnitude for design&lt;/strong>, not as constants. Measure on your own workload before committing to SLOs.&lt;/p>
&lt;hr>
&lt;h2 id="closing">Closing&lt;/h2>
&lt;p>Serving a reasoning model means serving a model whose cost per request &lt;strong>you decide with the thinking budget&lt;/strong>, not the catalogue. The chain goes: route by difficulty → turn &lt;em>think&lt;/em> off where it adds nothing → set &lt;code>thinking_token_budget&lt;/code> by default on the route that thinks → quantise the KV to FP8 → measure reasoning length as a first-class metric. Do that, and reasoning becomes a capability you pay for only when it buys accuracy. Do not, and your cluster will serve a fifth of the users while the model fills sheets of scratch paper nobody is going to read.&lt;/p>
&lt;h2 id="sources">Sources&lt;/h2>
&lt;ul>
&lt;li>vLLM · Reasoning Outputs — &lt;a href="https://docs.vllm.ai/en/stable/features/reasoning_outputs/">https://docs.vllm.ai/en/stable/features/reasoning_outputs/&lt;/a>&lt;/li>
&lt;li>vLLM PR #37112 · reasoning_budget — &lt;a href="https://github.com/vllm-project/vllm/pull/37112">https://github.com/vllm-project/vllm/pull/37112&lt;/a>&lt;/li>
&lt;li>Adding Reasoning Budget to vLLM — &lt;a href="https://shuyo.wordpress.com/2026/03/26/adding-reasoning-budget-to-vllm-reasoning-token-limit/">https://shuyo.wordpress.com/2026/03/26/adding-reasoning-budget-to-vllm-reasoning-token-limit/&lt;/a>&lt;/li>
&lt;li>s1: Simple Test-Time Scaling — &lt;a href="https://arxiv.org/abs/2501.19393">https://arxiv.org/abs/2501.19393&lt;/a>&lt;/li>
&lt;li>The Art of Scaling Test-Time Compute — &lt;a href="https://arxiv.org/abs/2512.02008">https://arxiv.org/abs/2512.02008&lt;/a>&lt;/li>
&lt;li>Don&amp;rsquo;t Overthink it (short-m@k) — &lt;a href="https://arxiv.org/pdf/2505.17813">https://arxiv.org/pdf/2505.17813&lt;/a>&lt;/li>
&lt;li>Mirage of Test-Time Scaling — &lt;a href="https://arxiv.org/pdf/2506.04210">https://arxiv.org/pdf/2506.04210&lt;/a>&lt;/li>
&lt;li>When More Thinking Hurts — &lt;a href="https://arxiv.org/html/2604.10739v1">https://arxiv.org/html/2604.10739v1&lt;/a>&lt;/li>
&lt;li>Reasoning Language Model Inference Serving Unveiled — &lt;a href="https://arxiv.org/pdf/2510.18672">https://arxiv.org/pdf/2510.18672&lt;/a>&lt;/li>
&lt;li>R-KV: Redundancy-aware KV Cache Compression — &lt;a href="https://arxiv.org/pdf/2505.24133">https://arxiv.org/pdf/2505.24133&lt;/a>&lt;/li>
&lt;li>Spheron · KV Cache Optimization Guide (2026) — &lt;a href="https://www.spheron.network/blog/kv-cache-optimization-guide/">https://www.spheron.network/blog/kv-cache-optimization-guide/&lt;/a>&lt;/li>
&lt;li>Test-Time Compute Quietly Changed the Economics of Inference — &lt;a href="https://medium.com/@Elongated_musk/test-time-compute-quietly-changed-the-economics-of-inference-9d0b8d77641c">https://medium.com/@Elongated_musk/test-time-compute-quietly-changed-the-economics-of-inference-9d0b8d77641c&lt;/a>&lt;/li>
&lt;li>Inference Scaling (Test-Time Compute) · Towards Data Science — &lt;a href="https://towardsdatascience.com/inference-scaling-test-time-compute-why-reasoning-models-raise-your-compute-bill/">https://towardsdatascience.com/inference-scaling-test-time-compute-why-reasoning-models-raise-your-compute-bill/&lt;/a>&lt;/li>
&lt;li>DeepSeek-V3.1 Hybrid Reasoning · InfoQ — &lt;a href="https://www.infoq.com/news/2025/09/deepseek-v31-hybrid/">https://www.infoq.com/news/2025/09/deepseek-v31-hybrid/&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Long context and KV offloading: when the notebook does not fit on the desk</title><link>https://blog.lo0.es/en/posts/long-context-kv-offloading-notebook-desk/</link><pubDate>Fri, 12 Jun 2026 05:00:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/long-context-kv-offloading-notebook-desk/</guid><description>&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>Serving long context &lt;strong>is not serving a smarter model, it is managing a notebook that does not fit on the desk&lt;/strong>. The context window is set by the model (and extended with RoPE scaling / YaRN), but the cost of serving it is set by the &lt;strong>KV cache&lt;/strong>, which grows linearly with sequence length and, in production, &lt;strong>explodes&lt;/strong>: a 300k-token contract on Llama 3 70B eats ~93 GB of KV, more than an entire H100, and a million tokens asks for ~125 GB. When the KV does not fit in HBM, there are only two ways out: &lt;strong>recompute&lt;/strong> (extremely expensive, attention is quadratic) or &lt;strong>offload&lt;/strong> the KV to a cheaper memory hierarchy: DRAM, NVMe, network. The 2026 OSS state of the art, &lt;strong>LMCache&lt;/strong>, &lt;strong>Mooncake&lt;/strong> (Kimi&amp;rsquo;s platform) and &lt;strong>NVIDIA Dynamo/KVBM&lt;/strong>, turns that offload into a &lt;strong>first-class KV layer&lt;/strong>, with reuse across requests, &lt;em>prefill/decode disaggregation&lt;/em> and cache-aware &lt;em>routing&lt;/em>. Reported results: &lt;strong>3×–10×&lt;/strong> less latency with LMCache and up to &lt;strong>+525 %&lt;/strong> throughput in long-context scenarios with Mooncake. The price: every memory hop adds transfer latency, so offloading &lt;strong>only pays off when what you save by not recomputing beats what it costs to move the bytes&lt;/strong>.&lt;/p>
&lt;hr>
&lt;h2 id="the-analogy">The analogy&lt;/h2>
&lt;p>A researcher works at a small desk. On it fit the papers they are pulling from &lt;strong>right now&lt;/strong>, which is the GPU&amp;rsquo;s HBM, blazingly fast but tiny. When the case is long (a thousand-page file, a million-token context), the papers do not fit. There are three options:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Throw papers away and ask the archive for them again every time they are needed.&lt;/strong> That is recomputing the KV: correct, but agonisingly slow, because &amp;ldquo;asking the archive&amp;rdquo; in an LLM means running the whole prompt through attention again, and attention is &lt;strong>quadratic&lt;/strong>.&lt;/li>
&lt;li>&lt;strong>Put a shelf next to the desk&lt;/strong> (the CPU&amp;rsquo;s DRAM) and, further out, &lt;strong>a store room in the basement&lt;/strong> (NVMe) and &lt;strong>a depot in another building&lt;/strong> (network/object). Moving papers between the desk and the shelf costs seconds, not hours. That is &lt;strong>hierarchical KV offloading&lt;/strong>.&lt;/li>
&lt;li>&lt;strong>Have two researchers split the work:&lt;/strong> one reads and marks up the whole file (prefill), then passes their notes to the second, who only drafts (decode). That is the &lt;strong>KVCache-centric disaggregated architecture&lt;/strong>.&lt;/li>
&lt;/ol>
&lt;p>This post is about options 2 and 3, the ones that make long context viable in production. Option 1 is what you pay by default if you do nothing.&lt;/p>
&lt;hr>
&lt;h2 id="part-1--why-long-context-is-a-memory-problem">Part 1 · Why long context is a memory problem&lt;/h2>
&lt;h3 id="the-kv-cache-grows-with-the-sequence">The KV cache grows with the sequence&lt;/h3>
&lt;p>For every token that goes in or out, the model stores its &lt;em>key&lt;/em> and &lt;em>value&lt;/em> vectors in each layer so it does not have to recompute them. The size is:&lt;/p>
$$\text{KV bytes} = 2 \times L \times h_{kv} \times d_{head} \times s \times b$$
&lt;p>with \(L\) layers, \(h_{kv}\) KV heads (few, with GQA), \(d_{head}\) the per-head dimension, \(s\) the sequence length and \(b\) the bytes per element. Everything is a model constant &lt;strong>except \(s\)&lt;/strong>: the KV is &lt;strong>linear in context length&lt;/strong>. Doubling the context doubles the KV. That is the basis of &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache: the working memory of inference&lt;/a>.&lt;/p>
&lt;h3 id="the-numbers-are-frightening">The numbers are frightening&lt;/h3>
&lt;p>At production scale, that linear term turns brutal:&lt;/p>
&lt;ul>
&lt;li>A &lt;strong>300k-token contract&lt;/strong> on &lt;strong>Llama 3 70B&lt;/strong> consumes &lt;strong>~93 GB&lt;/strong> of KV alone, &lt;strong>more than the 80 GB of an entire H100&lt;/strong> (&lt;a href="https://www.digitalocean.com/community/tutorials/long-context-inference-production-cost">DigitalOcean · Long-Context Inference Cost&lt;/a>).&lt;/li>
&lt;li>A &lt;strong>1M-token context&lt;/strong> needs &lt;strong>~125 GB&lt;/strong> of KV, which exceeds both an RTX 4090 (24 GB) and an 80 GB A100 (&lt;a href="https://introl.com/blog/long-context-llm-infrastructure-million-token-windows-guide">Introl · Long-Context LLM Infrastructure&lt;/a>).&lt;/li>
&lt;li>Even a &lt;strong>7B at 128k&lt;/strong> climbs to &lt;strong>~14 GB&lt;/strong> of KV (against ~6 GB at 4k).&lt;/li>
&lt;/ul>
&lt;p>The KV stops being an implementation detail and becomes &lt;strong>the resource that dictates your concurrency&lt;/strong>.&lt;/p>
&lt;h3 id="and-on-top-of-that-attention-is-quadratic">And on top of that, attention is quadratic&lt;/h3>
&lt;p>The KV is linear, but the &lt;strong>compute of attention is quadratic&lt;/strong> in length. When the prompt reaches 1M tokens, generating each token can take on the order of &lt;strong>1.765 seconds, with more than 96 % of the latency spent in attention&lt;/strong> (&lt;a href="https://introl.com/blog/long-context-llm-infrastructure-million-token-windows-guide">Introl&lt;/a>). The aggregate effect is a &lt;strong>throughput collapse of 10×–100×&lt;/strong> against short contexts. This is why long context is not &amp;ldquo;fixed&amp;rdquo; with more VRAM alone: there is a memory problem (KV) &lt;strong>and&lt;/strong> a compute problem (attention) at the same time.&lt;/p>
&lt;h3 id="extending-the-window--serving-it-cheaply">Extending the window ≠ serving it cheaply&lt;/h3>
&lt;p>A common confusion: &amp;ldquo;my model supports 1M of context&amp;rdquo; does not mean &amp;ldquo;I can serve 1M cheaply&amp;rdquo;. The window is &lt;strong>extended&lt;/strong> with &lt;em>RoPE scaling&lt;/em> techniques such as &lt;strong>YaRN&lt;/strong>, the practical option for &lt;em>fine-tuning&lt;/em> open source models to long context: it needs &lt;strong>10× fewer training tokens and 2.5× fewer steps&lt;/strong> than naive RoPE interpolation, and it took LLaMA-2 from 4k to 32k and 128k (&lt;a href="https://arxiv.org/html/2402.13753v1">YaRN/LongRoPE&lt;/a>). But that solves the model &lt;strong>attending&lt;/strong> to long context, not the KV &lt;strong>fitting on your GPU&lt;/strong>. According to the 2026 round-ups, May 2026 marked the first generation of open &lt;strong>million-token&lt;/strong> models (with families supporting 256k extensible to 1M via YaRN) (&lt;a href="https://letsdatascience.com/blog/long-context-models-working-with-1m-token-windows">letsdatascience&lt;/a>). Treat it as a trend, not a closed spec, and verify capabilities per concrete model.&lt;/p>
&lt;hr>
&lt;h2 id="part-2--the-kv-memory-hierarchy">Part 2 · The KV memory hierarchy&lt;/h2>
&lt;p>The core idea of offloading is old in systems: &lt;strong>hierarchical caching&lt;/strong>. &amp;ldquo;Hot&amp;rdquo; KV (what is in use) lives in HBM; &amp;ldquo;warm&amp;rdquo; KV drops to DRAM; &amp;ldquo;cold&amp;rdquo; KV to NVMe; &amp;ldquo;shared across nodes&amp;rdquo; to network or object storage. Every hop multiplies capacity and divides bandwidth.&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1rem auto;">
&lt;svg viewBox="0 0 780 300" role="img" aria-label="KV cache memory hierarchy: HBM, DRAM, NVMe and network/object, with increasing capacity and decreasing bandwidth" xmlns="http://www.w3.org/2000/svg">
&lt;style>.bx{fill:none;stroke:currentColor;stroke-width:1.3}.tl{font:600 13px sans-serif;fill:currentColor}.ts{font:11px sans-serif;fill:currentColor}.ar{fill:none;stroke:currentColor;stroke-width:1.2;stroke-dasharray:4 3;marker-end:url(#kvm)}&lt;/style>
&lt;defs>&lt;marker id="kvm" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="currentColor"/>&lt;/marker>&lt;/defs>
&lt;text x="20" y="26" class="tl">Hot · fast · small&lt;/text>
&lt;rect class="bx" x="20" y="36" width="430" height="44" rx="6"/>
&lt;text x="34" y="55" class="tl">GPU HBM&lt;/text>
&lt;text x="34" y="72" class="ts">~80 GB · several TB/s · the active KV lives here&lt;/text>
&lt;rect class="bx" x="20" y="92" width="500" height="44" rx="6"/>
&lt;text x="34" y="111" class="tl">CPU DRAM&lt;/text>
&lt;text x="34" y="128" class="ts">hundreds of GB–TB · tens–hundreds GB/s · warm KV, reuse across requests&lt;/text>
&lt;rect class="bx" x="20" y="148" width="570" height="44" rx="6"/>
&lt;text x="34" y="167" class="tl">NVMe SSD (local)&lt;/text>
&lt;text x="34" y="184" class="ts">TB · GB/s · cold KV, persistent prefixes, long sessions&lt;/text>
&lt;rect class="bx" x="20" y="204" width="640" height="44" rx="6"/>
&lt;text x="34" y="223" class="tl">Network / object (RDMA, S3, Redis)&lt;/text>
&lt;text x="34" y="240" class="ts">~unlimited · hundreds MB–GB/s · KV shared across cluster nodes&lt;/text>
&lt;path class="ar" d="M690,58 L690,226"/>
&lt;text x="700" y="120" class="ts" transform="rotate(90 700 120)">+capacity&lt;/text>
&lt;text x="700" y="200" class="ts" transform="rotate(90 700 200)">−bandwidth&lt;/text>
&lt;text x="20" y="276" class="ts">KV drops a level as it cools. Fetching it back from a lower level costs a transfer,&lt;/text>
&lt;text x="20" y="292" class="ts">but it is ALWAYS cheaper than recomputing it (quadratic attention) if the prefix is reused.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;h3 id="working-out-when-offloading-pays-off">Working out when offloading pays off&lt;/h3>
&lt;p>Offloading is not magic: moving KV from DRAM/NVMe back to HBM costs time. The rule is simple. &lt;strong>Offloading pays off when the cost of recomputing exceeds the cost of transferring&lt;/strong>:&lt;/p>
$$t_{recompute}(s) \;>\; t_{transfer} = \frac{\text{KV bytes}}{BW_{enlace}}$$
&lt;p>Since \(t_{recompute}\) grows with attention (quadratic) and \(t_{transfer}\) grows only with the size of the KV (linear) divided by the link bandwidth, &lt;strong>the longer the context, the more the balance tips in favour of offloading&lt;/strong>. That is why offloading is &lt;em>the&lt;/em> lever for long context: it is exactly where recomputing becomes unbearable. The LMCache documentation says it without hedging: offloading &lt;strong>only helps when the recomputation it avoids is larger than the overhead it introduces&lt;/strong> (&lt;a href="https://levelup.gitconnected.com/vllm-prefix-caching-vs-lmcache-benchmarking-kv-reuse-tradeoffs-944fbaf98b56">LMCache benchmark&lt;/a>).&lt;/p>
&lt;hr>
&lt;h2 id="part-3--kv-offloading-in-practice-oss">Part 3 · KV offloading in practice (OSS)&lt;/h2>
&lt;h3 id="the-limit-of-out-of-the-box-prefix-caching">The limit of out-of-the-box prefix caching&lt;/h3>
&lt;p>vLLM already caches prefixes in HBM (see &lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">prefix cache: hit rate engineering&lt;/a> and &lt;a href="https://blog.lo0.es/en/posts/pagedattention-vllm-block-manager/">PagedAttention&lt;/a>). The problem: &lt;strong>it only lives in HBM&lt;/strong>, which is small. When the useful KV exceeds HBM, it is evicted and, on the next request, has to be recomputed. &lt;strong>There is no speedup even with prefix caching enabled&lt;/strong>, because the cache is no longer there (&lt;a href="https://levelup.gitconnected.com/vllm-prefix-caching-vs-lmcache-benchmarking-kv-reuse-tradeoffs-944fbaf98b56">vLLM vs LMCache benchmark&lt;/a>). Native prefix caching is necessary but &lt;strong>insufficient&lt;/strong> for long context.&lt;/p>
&lt;h3 id="lmcache-the-persistent-kv-layer">LMCache: the persistent KV layer&lt;/h3>
&lt;p>&lt;strong>LMCache&lt;/strong> adds persistent storage backends to vLLM&amp;rsquo;s prefix cache (and also supports SGLang and NVIDIA Dynamo as engines). It pulls the KV out of HBM and &lt;strong>shares it across engines and across queries&lt;/strong>, covering a &lt;strong>three-level hierarchy: GPU HBM, CPU DRAM and NVMe SSD&lt;/strong>, with additional backends for Redis/Valkey, Mooncake, InfiniStore, S3 and NIXL/GDS (&lt;a href="https://github.com/LMCache/LMCache">GitHub LMCache&lt;/a>, &lt;a href="https://arxiv.org/pdf/2510.09665">arXiv 2510.09665&lt;/a>). Because DRAM/NVMe hold &lt;strong>far more&lt;/strong> KV than HBM, the &lt;em>hit ratio&lt;/em> rises, and LMCache reports &lt;strong>3×–10× less latency&lt;/strong> combined with vLLM. Against vLLM&amp;rsquo;s basic CPU offload, LMCache loads the KV &lt;strong>at chunk level with high-performance CUDA kernels&lt;/strong>, which cuts transfer overhead.&lt;/p>
&lt;p>A minimal start, offloading to CPU:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># vLLM with LMCache as the KV layer (offload to DRAM)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">pip install lmcache
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">LMCACHE_CONFIG_FILE&lt;/span>&lt;span class="o">=&lt;/span>lmcache.yaml &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span>vllm serve meta-llama/Llama-3.1-70B-Instruct &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --tensor-parallel-size &lt;span class="m">4&lt;/span> &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --kv-transfer-config &lt;span class="s1">&amp;#39;{&amp;#34;kv_connector&amp;#34;:&amp;#34;LMCacheConnector&amp;#34;,&amp;#34;kv_role&amp;#34;:&amp;#34;kv_both&amp;#34;}&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># lmcache.yaml — hierarchy HBM -&amp;gt; DRAM -&amp;gt; NVMe&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">chunk_size&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">256&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">local_cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># warm KV in DRAM&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">max_local_cpu_size&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">200&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># GB&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">local_disk&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;file:///nvme/lmcache&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># cold KV on NVMe&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">max_local_disk_size&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">2000&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># GB&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Offloading to CPU adds moderate overhead but &lt;strong>retains a good part of the benefit&lt;/strong> against recomputing (&lt;a href="https://docs.lmcache.ai/getting_started/quickstart/offload_kv_cache.html">LMCache docs&lt;/a>). Mind the physical path: that HBM↔DRAM↔NVMe traffic goes over PCIe and across NUMA nodes. It is worth reading &lt;a href="https://blog.lo0.es/en/posts/pcie-topology-gpudirect-p2p-acs-security-guard/">PCIe topology, GPUDirect and ACS&lt;/a> and &lt;a href="https://blog.lo0.es/en/posts/numa-hugepages-cpu-isolation-gpu-waits-kernel/">NUMA, hugepages and CPU isolation&lt;/a>, because a badly wired offload can eat its own gain.&lt;/p>
&lt;h3 id="combine-it-with-fp8">Combine it with FP8&lt;/h3>
&lt;p>Offloading reduces &lt;strong>where&lt;/strong> the KV lives; quantization reduces &lt;strong>how much&lt;/strong> it weighs. They are orthogonal and they add up: KV in FP8 halves the size (see &lt;a href="https://blog.lo0.es/en/posts/fp8-end-to-end-enable-measure-quality-decide/">FP8 end-to-end&lt;/a>), which means half the bytes to transfer on every offload. In long context, &lt;strong>FP8 + offload&lt;/strong> is the default combination.&lt;/p>
&lt;hr>
&lt;h2 id="part-4--kvcache-centric--disaggregated-architecture">Part 4 · KVCache-centric / disaggregated architecture&lt;/h2>
&lt;p>The next level is not just offloading KV, but &lt;strong>redesigning serving around the KV&lt;/strong>.&lt;/p>
&lt;h3 id="mooncake-kimis-platform">Mooncake (Kimi&amp;rsquo;s platform)&lt;/h3>
&lt;p>&lt;strong>Mooncake&lt;/strong>, the serving platform behind &lt;strong>Kimi&lt;/strong> (Moonshot AI), is the reference &lt;strong>KVCache-centric disaggregated&lt;/strong> architecture: it separates the &lt;strong>prefill&lt;/strong> and &lt;strong>decode&lt;/strong> clusters, and exploits the &lt;strong>underused CPU, DRAM and SSD resources&lt;/strong> of the GPU cluster to build a distributed KV cache. Its core is a &lt;strong>KVCache-centric scheduler&lt;/strong> that maximises throughput while respecting SLOs, with a &lt;strong>prediction-based early rejection policy&lt;/strong> for overloaded scenarios (&lt;a href="https://arxiv.org/abs/2407.00079">arXiv 2407.00079&lt;/a>, &lt;a href="https://www.usenix.org/conference/fast25/presentation/qin">USENIX FAST'25&lt;/a>). The long-context numbers are striking: up to &lt;strong>+525 % throughput&lt;/strong> in certain simulated scenarios while respecting the SLO, and in production Kimi handles &lt;strong>115 % and 107 % more requests&lt;/strong> on A800 and H800 clusters respectively against previous systems. The title of their FAST talk sums it up: &lt;em>&amp;ldquo;Trading More Storage for Less Computation&amp;rdquo;&lt;/em>, exactly the rule from Part 2.&lt;/p>
&lt;h3 id="nvidia-dynamo-and-kvbm">NVIDIA Dynamo and KVBM&lt;/h3>
&lt;p>&lt;strong>NVIDIA Dynamo&lt;/strong> is the open source distributed serving framework with &lt;strong>prefill/decode disaggregation&lt;/strong>, dynamic GPU scheduling and &lt;strong>KV-aware routing&lt;/strong>: the &lt;em>PrefillRouter&lt;/em> computes &lt;strong>overlap scores&lt;/strong> between the incoming request and the KV blocks already cached, and routes to the GPUs that &lt;strong>already have&lt;/strong> the relevant KV, avoiding recomputation (&lt;a href="https://docs.dynamo.nvidia.com/dynamo/design-docs/disaggregated-serving">Dynamo · Disaggregated Serving&lt;/a>, &lt;a href="https://docs.nvidia.com/dynamo/latest/user-guides/kv-cache-aware-routing">Dynamo · KV-aware routing&lt;/a>). KV transfer between prefill and decode is handled by &lt;strong>NIXL&lt;/strong> directly GPU-to-GPU over the best available transport (NVLink, InfiniBand). And its offload manager, &lt;strong>KVBM (KV Block Manager)&lt;/strong>, has a three-layer architecture (LLM runtime, logical block management, NIXL transport) that &lt;strong>offloads cold KV to CPU RAM, NVMe or network storage&lt;/strong> to free up HBM (&lt;a href="https://docs.nvidia.com/dynamo/backends/v-llm/kv-cache-offloading">Dynamo · KV Cache Offloading&lt;/a>). This connects with &lt;a href="https://blog.lo0.es/en/posts/disaggregated-serving-prefill-decode-specialised-pods/">disaggregated serving: prefill and decode in specialised pods&lt;/a>.&lt;/p>
&lt;p>The &lt;strong>llm-d&lt;/strong> project walks the same road, from vLLM&amp;rsquo;s prefix caching to KV-aware distributed scheduling (&lt;a href="https://llm-d.ai/blog/kvcache-wins-you-can-see">llm-d · KV-Cache Wins You Can See&lt;/a>).&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1rem auto;">
&lt;svg viewBox="0 0 780 250" role="img" aria-label="KVCache-centric disaggregated architecture: KV-aware router, prefill cluster, tiered distributed KV cache and decode cluster" xmlns="http://www.w3.org/2000/svg">
&lt;style>.bx{fill:none;stroke:currentColor;stroke-width:1.3}.dsh{fill:none;stroke:currentColor;stroke-width:1.3;stroke-dasharray:5 3}.tl{font:600 12px sans-serif;fill:currentColor}.ts{font:11px sans-serif;fill:currentColor}.ar{fill:none;stroke:currentColor;stroke-width:1.3;marker-end:url(#dgm)}&lt;/style>
&lt;defs>&lt;marker id="dgm" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="currentColor"/>&lt;/marker>&lt;/defs>
&lt;rect class="bx" x="20" y="40" width="120" height="46" rx="6"/>
&lt;text x="32" y="60" class="tl">KV-aware router&lt;/text>
&lt;text x="32" y="77" class="ts">overlap score&lt;/text>
&lt;path class="ar" d="M140,63 L185,63"/>
&lt;rect class="bx" x="185" y="40" width="150" height="46" rx="6"/>
&lt;text x="197" y="60" class="tl">PREFILL cluster&lt;/text>
&lt;text x="197" y="77" class="ts">reads+marks up context&lt;/text>
&lt;path class="ar" d="M260,86 L260,120"/>
&lt;rect class="dsh" x="120" y="120" width="430" height="50" rx="6"/>
&lt;text x="134" y="140" class="tl">Distributed KV cache (HBM · DRAM · NVMe · network)&lt;/text>
&lt;text x="134" y="158" class="ts">KVBM / LMCache / Mooncake store · reuse across requests and nodes&lt;/text>
&lt;path class="ar" d="M410,120 L410,86"/>
&lt;rect class="bx" x="430" y="40" width="150" height="46" rx="6"/>
&lt;text x="442" y="60" class="tl">DECODE cluster&lt;/text>
&lt;text x="442" y="77" class="ts">only generates tokens&lt;/text>
&lt;path class="ar" d="M335,63 L430,63"/>
&lt;text x="600" y="50" class="ts">NIXL: direct&lt;/text>
&lt;text x="600" y="66" class="ts">GPU↔GPU KV transfer&lt;/text>
&lt;text x="600" y="82" class="ts">(NVLink/IB)&lt;/text>
&lt;text x="20" y="200" class="ts">KV stops being a by-product of decode and becomes the first-class citizen: the router routes by&lt;/text>
&lt;text x="20" y="216" class="ts">KV overlap, prefill and decode are separated, and the distributed cache avoids recomputing shared prefixes.&lt;/text>
&lt;text x="20" y="232" class="ts">It is "trading storage for computation": you store more KV so you compute less attention.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;hr>
&lt;h2 id="part-5--reference-architecture">Part 5 · Reference architecture&lt;/h2>
&lt;p>On the blog&amp;rsquo;s example cluster, a node with &lt;strong>4×H100 SXM (80 GB, NVLink)&lt;/strong>, &lt;strong>local NVMe&lt;/strong> and plenty of DRAM, a sensible stack to serve long context without recomputing pointlessly:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>KV in FP8&lt;/strong> in the engine (vLLM), to start with half the bytes.&lt;/li>
&lt;li>&lt;strong>LMCache as the KV layer&lt;/strong> with a DRAM→NVMe hierarchy, so that long prefixes (a manual, a code base, a case file) &lt;strong>are cached once and reused&lt;/strong> across sessions without recomputation.&lt;/li>
&lt;li>&lt;strong>KV-aware routing&lt;/strong> (Dynamo or llm-d) if you have several nodes: send the request to the GPU that already holds the prefix, not to any GPU at all.&lt;/li>
&lt;li>&lt;strong>Prefill/decode disaggregation&lt;/strong> once the prefill of enormous contexts starts stealing decode from the other requests. Prefilling 300k tokens monopolises the GPU and kills everyone&amp;rsquo;s latency.&lt;/li>
&lt;li>&lt;strong>Metrics&lt;/strong> for KV &lt;em>hit ratio&lt;/em>, bytes transferred per level and prefill/decode ratio, exported to your observability stack (&lt;a href="https://blog.lo0.es/en/posts/instrumenting-vllm-otel-measuring-optimisations/">instrumenting vLLM with OTel&lt;/a>). Without those three metrics, offloading is faith, not engineering.&lt;/li>
&lt;/ol>
&lt;p>To &lt;strong>prototype&lt;/strong> the stack, validating the LMCache config, the backend formats, the hit/miss behaviour, an &lt;strong>RTX 5090 (Blackwell, 32 GB)&lt;/strong> with NVMe is more than enough to serve a 7–14B and watch offloading work at contexts of 32–128k. Do not expect to serve 1M on a consumer card: the long-context problem is precisely that neither the KV nor the attention fit on small hardware. Real sizing starts from the SLO and from the context-length distribution of your traffic, not from the model&amp;rsquo;s maximum window, and that is where it links to &lt;a href="https://blog.lo0.es/en/posts/capacity-planning-on-premise-llm-inference/">capacity planning&lt;/a>.&lt;/p>
&lt;hr>
&lt;h2 id="part-6--operational-pitfalls-and-honest-scepticism">Part 6 · Operational pitfalls (and honest scepticism)&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>Believing that native prefix caching is enough.&lt;/strong> It only lives in HBM; in long context it is evicted and you recompute. You need a persistent layer (LMCache/KVBM) for the cache to survive.&lt;/li>
&lt;li>&lt;strong>Offloading without measuring the break-even.&lt;/strong> If your prefixes &lt;strong>are not reused&lt;/strong>, offloading only adds transfer latency without saving recomputation. Offloading shines with &lt;strong>shared prefixes&lt;/strong> (RAG over the same corpus, agents with the same system prompt, long sessions), not with one-off, never-repeated requests.&lt;/li>
&lt;li>&lt;strong>Forgetting that attention is still quadratic.&lt;/strong> Offloading fixes the &lt;strong>memory&lt;/strong> of the KV, not the &lt;strong>compute&lt;/strong> of attention. For real 1M tokens you also need efficient attention, &lt;em>sparse attention&lt;/em> or retrieval approaches (RetrievalAttention, ShadowKV); offloading on its own does not bring down the 1.765 s/token.&lt;/li>
&lt;li>&lt;strong>Wiring the offload badly.&lt;/strong> HBM↔DRAM↔NVMe crosses PCIe and NUMA. An offload that crosses the wrong NUMA node or saturates a PCIe lane can be &lt;strong>slower than recomputing&lt;/strong>. Measure the link&amp;rsquo;s real bandwidth, not the datasheet figure.&lt;/li>
&lt;li>&lt;strong>Treating the figures as constants.&lt;/strong> The 93 GB, the +525 %, the 3–10× all depend on model, length, hardware and reuse pattern. They are &lt;strong>orders of magnitude for design&lt;/strong>; measure on your own load.&lt;/li>
&lt;li>&lt;strong>Trusting million-token model specs without verifying.&lt;/strong> The landscape of open 1M models is very recent (2026) and moves fast; the specific names and limits change between versions. Verify the window &lt;strong>and the cost of serving it&lt;/strong> per model, do not take the headline on trust.&lt;/li>
&lt;/ol>
&lt;p>A note of caution for June 2026: the distributed KV layer (LMCache, Mooncake, KVBM, NIXL, llm-d) is &lt;strong>setting right now&lt;/strong>, with APIs and backends that change release by release. It is exactly the kind of piece worth assembling behind an abstraction (vLLM&amp;rsquo;s &lt;em>kv_connector&lt;/em>) rather than coupling to a single vendor.&lt;/p>
&lt;hr>
&lt;h2 id="closing">Closing&lt;/h2>
&lt;p>Long context is a problem of &lt;strong>memory and compute at the same time&lt;/strong>, and the KV cache is the bottleneck of both. The window is a gift from the model; serving it cheaply is systems engineering: &lt;strong>quantise the KV (FP8), offload it by tiers (HBM→DRAM→NVMe→network) with a persistent layer, and reorganise serving around the KV&lt;/strong> (aware routing, separated prefill/decode) when scale demands it. The rule that governs it all is Mooncake&amp;rsquo;s: &lt;strong>trade storage for computation&lt;/strong>. You store more KV in cheap places so you do not recompute expensive attention. Do it well and a 4×H100 node serves contexts that, by recomputing, would not even get started. Do it badly, or not at all, and every long request reads the whole case file from scratch again, while the GPU drowns in a quadratic attention you had already paid for once.&lt;/p>
&lt;h2 id="sources">Sources&lt;/h2>
&lt;ul>
&lt;li>LMCache · GitHub — &lt;a href="https://github.com/LMCache/LMCache">https://github.com/LMCache/LMCache&lt;/a>&lt;/li>
&lt;li>LMCache: An Efficient KV Cache Layer (arXiv 2510.09665) — &lt;a href="https://arxiv.org/pdf/2510.09665">https://arxiv.org/pdf/2510.09665&lt;/a>&lt;/li>
&lt;li>LMCache · Offload KV cache to CPU (docs) — &lt;a href="https://docs.lmcache.ai/getting_started/quickstart/offload_kv_cache.html">https://docs.lmcache.ai/getting_started/quickstart/offload_kv_cache.html&lt;/a>&lt;/li>
&lt;li>vLLM Prefix Caching vs. LMCache: Benchmarking KV Reuse Tradeoffs — &lt;a href="https://levelup.gitconnected.com/vllm-prefix-caching-vs-lmcache-benchmarking-kv-reuse-tradeoffs-944fbaf98b56">https://levelup.gitconnected.com/vllm-prefix-caching-vs-lmcache-benchmarking-kv-reuse-tradeoffs-944fbaf98b56&lt;/a>&lt;/li>
&lt;li>Mooncake: A KVCache-centric Disaggregated Architecture (arXiv 2407.00079) — &lt;a href="https://arxiv.org/abs/2407.00079">https://arxiv.org/abs/2407.00079&lt;/a>&lt;/li>
&lt;li>Mooncake · USENIX FAST'25 (Trading More Storage for Less Computation) — &lt;a href="https://www.usenix.org/conference/fast25/presentation/qin">https://www.usenix.org/conference/fast25/presentation/qin&lt;/a>&lt;/li>
&lt;li>Mooncake · GitHub — &lt;a href="https://github.com/kvcache-ai/Mooncake/">https://github.com/kvcache-ai/Mooncake/&lt;/a>&lt;/li>
&lt;li>NVIDIA Dynamo · Disaggregated Serving (docs) — &lt;a href="https://docs.dynamo.nvidia.com/dynamo/design-docs/disaggregated-serving">https://docs.dynamo.nvidia.com/dynamo/design-docs/disaggregated-serving&lt;/a>&lt;/li>
&lt;li>NVIDIA Dynamo · KV-aware routing (docs) — &lt;a href="https://docs.nvidia.com/dynamo/latest/user-guides/kv-cache-aware-routing">https://docs.nvidia.com/dynamo/latest/user-guides/kv-cache-aware-routing&lt;/a>&lt;/li>
&lt;li>NVIDIA Dynamo · KV Cache Offloading / KVBM (docs) — &lt;a href="https://docs.nvidia.com/dynamo/backends/v-llm/kv-cache-offloading">https://docs.nvidia.com/dynamo/backends/v-llm/kv-cache-offloading&lt;/a>&lt;/li>
&lt;li>llm-d · KV-Cache Wins You Can See — &lt;a href="https://llm-d.ai/blog/kvcache-wins-you-can-see">https://llm-d.ai/blog/kvcache-wins-you-can-see&lt;/a>&lt;/li>
&lt;li>Long-Context Inference at Scale: The Hidden Infrastructure Cost · DigitalOcean — &lt;a href="https://www.digitalocean.com/community/tutorials/long-context-inference-production-cost">https://www.digitalocean.com/community/tutorials/long-context-inference-production-cost&lt;/a>&lt;/li>
&lt;li>Long-Context LLM Infrastructure · Introl — &lt;a href="https://introl.com/blog/long-context-llm-infrastructure-million-token-windows-guide">https://introl.com/blog/long-context-llm-infrastructure-million-token-windows-guide&lt;/a>&lt;/li>
&lt;li>YaRN / LongRoPE (arXiv 2402.13753) — &lt;a href="https://arxiv.org/html/2402.13753v1">https://arxiv.org/html/2402.13753v1&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Multimodal on-premise: serving a VLM with vLLM (vision + language)</title><link>https://blog.lo0.es/en/posts/multimodal-on-premise-serving-vlm-vllm/</link><pubDate>Thu, 11 Jun 2026 11:40:00 +0000</pubDate><guid>https://blog.lo0.es/en/posts/multimodal-on-premise-serving-vlm-vllm/</guid><description>&lt;blockquote>
&lt;p>Third batch of an operational series on squeezing a generic on-premise LLM cluster of 4×H100 SXM. Its sibling pieces in this batch are &lt;a href="https://blog.lo0.es/en/posts/finops-multi-tenancy-gpu-cluster-who-pays/">FinOps and GPU multi-tenancy with LiteLLM&lt;/a>, which puts a price on every token, and a visual token costs the same as a text one, and &lt;a href="https://blog.lo0.es/en/posts/speeding-up-model-cold-start-minutes-to-seconds/">Speeding up cold start with Tensorizer&lt;/a>, which matters twice as much here because a VLM loads two models (the vision encoder and the LLM). If the VLM ends up feeding a document assistant, that end-to-end setup with LibreChat and RAG is another story (in preparation).&lt;/p>
&lt;/blockquote>
&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>A vision-language model (VLM) is not magic: it is a normal LLM with a &lt;strong>sensory organ&lt;/strong> bolted on the front. Three pieces in series: a &lt;strong>vision encoder&lt;/strong> (a ViT) that looks at the image, a &lt;strong>projector&lt;/strong> or connector (typically an MLP) that translates the encoder&amp;rsquo;s output into the LLM&amp;rsquo;s embedding space, and the usual &lt;strong>LLM&lt;/strong>, which receives those embeddings as if they were just more tokens. The consequence that governs the entire operational design is brutal in its simplicity: &lt;strong>an image becomes visual tokens, and those tokens cost exactly the same as text tokens&lt;/strong>. A high-resolution document page is not &amp;ldquo;a couple of image tokens&amp;rdquo;: it is &lt;strong>hundreds or thousands&lt;/strong> of tokens entering the context, inflating the prefill (compute-bound) and occupying KV cache (memory-bound) just as if you had pasted a thousand words. In Qwen2.5-VL the arithmetic is literal: the number of visual tokens is $H\times W / (14\times14\times4)$, so an $896\times896$ image is &lt;strong>1,024 tokens&lt;/strong> and an A4 page scanned at a decent resolution easily reaches &lt;strong>1,500–2,500 tokens&lt;/strong> for the image alone. This post opens up the anatomy, works through the token-cost maths and translates it into TTFT and VRAM on an 80 GB H100, explains vLLM&amp;rsquo;s multimodal support (&lt;code>--limit-mm-per-prompt&lt;/code>, pixel budget via &lt;code>mm_processor_kwargs&lt;/code>, chat template) and answers the question that really matters: &lt;strong>classic OCR or VLM&lt;/strong>. The short answer: use Tesseract/PaddleOCR for the bulk of documents with clean text, and reserve the VLM, expensive in tokens and in GPU, for the subset that genuinely needs it: complex layout, nested tables, handwriting, stamps, charts. On the generic 4×H100 SXM cluster, with FP8 so it fits.&lt;/p>
&lt;h2 id="the-analogy-the-reader-who-sees-the-page-versus-the-one-who-only-hears-the-transcript">The analogy: the reader who sees the page versus the one who only hears the transcript&lt;/h2>
&lt;p>Picture two experts you ask to review a scanned contract. To the first you read the contract aloud, a blind transcript, word by word. It is fast, efficient, and for 90 % of the clauses it is enough: the text is the text. But there are things you cannot read out: that the signature at the end is handwritten and does not match the typed name; that there is a &amp;ldquo;PAID&amp;rdquo; stamp struck diagonally across the amount; that the table on page 3 has a merged cell that changes who each row applies to; that there is a pen annotation in the margin. The blind transcript loses all of that or flattens it into gibberish.&lt;/p>
&lt;p>To the second expert you hand the whole page, to look at. They see the signature, they see the stamp, they understand the structure of the table because they perceive the lines and the cells, they read the marginal note. They grasp the document as a visual object with layout, not as a river of characters. They are strictly more capable.&lt;/p>
&lt;p>Why not always use the second one, then? Because &lt;strong>seeing costs more mental bandwidth&lt;/strong>. The first expert receives the contract as a flow of words: cheap, linear. The second receives it as an image that their brain has to parcel up, attend to region by region, and reconstruct. They process a great deal more information per page, most of which, in a clean text document, is redundant with what the transcript would already have given them. If you only need to read the clauses, hiring the expert-who-sees for every page is overpaying for capability you do not use.&lt;/p>
&lt;p>That is the entire thesis of this post. The VLM is the expert who sees; OCR is the blind transcript; and &amp;ldquo;mental bandwidth&amp;rdquo; is &lt;strong>tokens&lt;/strong>. The engineering consists of sending the expert-who-sees only the pages where seeing changes the answer, and resolving the rest with the cheap transcript.&lt;/p>
&lt;h2 id="anatomy-of-a-vlm-encoder-projector-llm">Anatomy of a VLM: encoder, projector, LLM&lt;/h2>
&lt;p>A modern VLM of the Qwen-VL family (&lt;a href="https://huggingface.co/docs/transformers/model_doc/qwen2_5_vl">Qwen2.5-VL model card&lt;/a>; &lt;a href="https://arxiv.org/abs/2511.21631">Qwen3-VL Technical Report&lt;/a>) is made up of three blocks in series:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Vision encoder (ViT).&lt;/strong> A Vision Transformer that receives the image, cuts it into patches and produces an embedding per patch (or per group of patches). In Qwen2.5-VL it is a dynamic-resolution ViT: it accepts images of arbitrary size, resizing them to multiples of 28 and splitting them into 14×14 pixel patches, with &lt;em>window attention&lt;/em> to speed up the processing of large images. There is no &amp;ldquo;canonical size&amp;rdquo; everything is squashed to: a large image produces more patches than a small one.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Projector / connector.&lt;/strong> The ViT&amp;rsquo;s embedding space is not the LLM&amp;rsquo;s. The projector acts as the translator. In Qwen2.5-VL it is elegant and cheap: it groups every 2×2 block of adjacent patches (four ViT tokens), concatenates them and projects them with a two-layer MLP into a single fused token in the LLM&amp;rsquo;s dimension. That fusion factor of 4 is the reason for the $4$ that appears in the denominator of the token formula below: four ViT patches collapse into one visual token that the LLM sees.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>The LLM.&lt;/strong> The usual language transformer. It receives a sequence of embeddings that is a mixture of text tokens (from your prompt) and visual tokens (from the image), all in the same space, and does what it knows how to do: attention over the complete sequence and autoregressive generation. To the LLM, a visual token and a text token are indistinguishable in cost: both go through the same QKV projections, both occupy an entry in the KV cache, both take part in the $O(C^2)$ attention.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;div class="diagram" style="max-width:820px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 820 320" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="VLM pipeline: image, vision encoder, projector, visual tokens, LLM, answer">
&lt;defs>&lt;marker id="vlm1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="currentColor"/>&lt;/marker>&lt;/defs>
&lt;text x="410" y="22" text-anchor="middle" font-size="15" font-weight="700" fill="currentColor">The VLM pipeline: where the token budget explodes&lt;/text>
&lt;rect x="20" y="60" width="120" height="64" fill="none" stroke="#3b82f6" stroke-width="1.6"/>
&lt;text x="80" y="86" text-anchor="middle" font-size="12" font-weight="700" fill="currentColor">Image&lt;/text>
&lt;text x="80" y="104" text-anchor="middle" font-size="11" fill="currentColor">A4 page&lt;/text>
&lt;text x="80" y="118" text-anchor="middle" font-size="11" fill="currentColor">~1100×1500 px&lt;/text>
&lt;rect x="175" y="60" width="130" height="64" fill="none" stroke="#8b5cf6" stroke-width="1.6"/>
&lt;text x="240" y="82" text-anchor="middle" font-size="12" font-weight="700" fill="currentColor">ViT encoder&lt;/text>
&lt;text x="240" y="100" text-anchor="middle" font-size="11" fill="currentColor">14×14 patches&lt;/text>
&lt;text x="240" y="114" text-anchor="middle" font-size="11" fill="currentColor">window attn&lt;/text>
&lt;rect x="340" y="60" width="130" height="64" fill="none" stroke="#f59e0b" stroke-width="1.6"/>
&lt;text x="405" y="82" text-anchor="middle" font-size="12" font-weight="700" fill="currentColor">Projector&lt;/text>
&lt;text x="405" y="100" text-anchor="middle" font-size="11" fill="currentColor">2×2 fusion → MLP&lt;/text>
&lt;text x="405" y="114" text-anchor="middle" font-size="11" fill="currentColor">÷4 tokens&lt;/text>
&lt;rect x="505" y="60" width="140" height="64" fill="none" stroke="#ef4444" stroke-width="1.6"/>
&lt;text x="575" y="82" text-anchor="middle" font-size="12" font-weight="700" fill="currentColor">Visual tokens&lt;/text>
&lt;text x="575" y="100" text-anchor="middle" font-size="11" fill="currentColor">~1500–2500&lt;/text>
&lt;text x="575" y="114" text-anchor="middle" font-size="11" fill="currentColor">enter the context&lt;/text>
&lt;rect x="680" y="60" width="120" height="64" fill="none" stroke="#22c55e" stroke-width="1.6"/>
&lt;text x="740" y="86" text-anchor="middle" font-size="12" font-weight="700" fill="currentColor">LLM&lt;/text>
&lt;text x="740" y="104" text-anchor="middle" font-size="11" fill="currentColor">attention over&lt;/text>
&lt;text x="740" y="118" text-anchor="middle" font-size="11" fill="currentColor">text + vision&lt;/text>
&lt;path d="M140,92 L175,92" stroke="currentColor" stroke-width="1.6" fill="none" marker-end="url(#vlm1)"/>
&lt;path d="M305,92 L340,92" stroke="currentColor" stroke-width="1.6" fill="none" marker-end="url(#vlm1)"/>
&lt;path d="M470,92 L505,92" stroke="currentColor" stroke-width="1.6" fill="none" marker-end="url(#vlm1)"/>
&lt;path d="M645,92 L680,92" stroke="currentColor" stroke-width="1.6" fill="none" marker-end="url(#vlm1)"/>
&lt;text x="155" y="44" text-anchor="middle" font-size="11" fill="currentColor">pixels&lt;/text>
&lt;text x="322" y="44" text-anchor="middle" font-size="11" fill="currentColor">~8400 patches&lt;/text>
&lt;text x="487" y="44" text-anchor="middle" font-size="11" fill="currentColor">÷4&lt;/text>
&lt;text x="410" y="185" text-anchor="middle" font-size="13" font-weight="700" fill="currentColor">Here the budget explodes: the image is already text to the LLM&lt;/text>
&lt;rect x="120" y="205" width="580" height="26" fill="none" stroke="currentColor" stroke-width="1"/>
&lt;rect x="120" y="205" width="80" height="26" fill="#22c55e"/>
&lt;rect x="200" y="205" width="500" height="26" fill="#ef4444"/>
&lt;text x="160" y="222" text-anchor="middle" font-size="11" fill="#ffffff">prompt ~80 tok&lt;/text>
&lt;text x="450" y="222" text-anchor="middle" font-size="11" fill="#ffffff">visual tokens from the image ~1500–2500 tok&lt;/text>
&lt;text x="410" y="262" text-anchor="middle" font-size="12" fill="currentColor">prefill = process ALL of this (compute-bound) · KV cache = store ALL of this (memory-bound)&lt;/text>
&lt;text x="410" y="284" text-anchor="middle" font-size="12" fill="currentColor">in Qwen2.5-VL: visual tokens = H × W / (14 × 14 × 4)&lt;/text>
&lt;text x="410" y="304" text-anchor="middle" font-size="11" fill="currentColor">896×896 → 1024 tok · one image ≈ a long paragraph… or five pages of text&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>The idea to internalise: &lt;strong>the encoder and the projector are the sensory organ, but the inference cost lives in the LLM&lt;/strong>, and that cost is paid in tokens. The ViT adds a fixed prefill overhead (processing the image once), but the recurring bill, the LLM prefill and the KV cache throughout the whole generation, is set by the number of visual tokens the projector spits out. That is why the control lever is not &amp;ldquo;which encoder&amp;rdquo;, but &lt;strong>how many pixels you let through&lt;/strong>.&lt;/p>
&lt;h2 id="the-maths-what-it-costs-to-see-a-page">The maths: what it costs to see a page&lt;/h2>
&lt;p>Let us put numbers on &amp;ldquo;an image costs many tokens&amp;rdquo;, with the real Qwen2.5-VL formula (&lt;a href="https://qwenlm.github.io/blog/qwen2.5-vl/">Qwen team, Qwen2.5-VL blog&lt;/a>):&lt;/p>
$$N_{\text{tok}} = \frac{H \times W}{14 \times 14 \times 4} = \frac{H \times W}{784}$$
&lt;p>where $H$ and $W$ are height and width in pixels (rounded to the multiple of 28 the ViT imposes). The $14\times14$ is the patch size; the $\times4$ is the projector&amp;rsquo;s 2×2 fusion. A sanity check against the model card figure: an $896\times896$ image gives&lt;/p>
$$N_{\text{tok}} = \frac{896 \times 896}{784} = \frac{802{,}816}{784} = 1{,}024 \text{ tokens.}$$
&lt;p>It checks out. Now an A4 page scanned at a resolution reasonable for reading small text, say $1120 \times 1568$ px (approximate height $\times$ width, already rounded to multiples of 28):&lt;/p>
$$N_{\text{tok}} = \frac{1120 \times 1568}{784} = \frac{1{,}756{,}160}{784} \approx 2{,}240 \text{ tokens.}$$
&lt;p>&lt;strong>A single page is ~2,240 visual tokens&lt;/strong> before you write a word of prompt. For context: that is roughly what 1,700 words of Spanish text would take up (at ~1.3 tokens/word). If that A4 page contains 600 words of actual text, the VLM is paying &lt;strong>almost 4× in tokens&lt;/strong> to see it rather than read its transcript. If the page is a dense table or a handwritten document that OCR cannot read, that 4× is justified. If it is a paragraph of clean text, it is pure waste.&lt;/p>
&lt;p>Qwen2.5-VL lets you control this with &lt;code>min_pixels&lt;/code> / &lt;code>max_pixels&lt;/code>: the number of tokens per image is dynamic and ranges from about 4 up to 16,384 by default, adjustable with those parameters (&lt;a href="https://huggingface.co/docs/transformers/model_doc/qwen2_5_vl">HF Qwen2.5-VL docs&lt;/a>). Lowering &lt;code>max_pixels&lt;/code> cuts tokens at the expense of resolution, and of the ability to read the fine print. It is exactly the lever of &amp;ldquo;how much mental bandwidth do I give the expert&amp;rdquo;.&lt;/p>
&lt;h3 id="from-token-cost-to-ttft">From token cost to TTFT&lt;/h3>
&lt;p>Visual tokens are not free in latency. The prefill, processing the whole context before the first token, is compute-bound and its cost grows with the context length $C$ (linear in the projections, quadratic in the attention); this is worked through in detail in &lt;a href="https://blog.lo0.es/en/posts/vllm-attention-backend-flashattention-flashinfer-prefill-decode-asymmetry/">vLLM&amp;rsquo;s attention backend&lt;/a>. Every visual token enters that $C$.&lt;/p>
&lt;p>Let us model the TTFT as the time to process the prefill tokens at a given prefill throughput. Take a VLM of around 7–8B on an H100 with an illustrative prefill throughput of ~12,000 tok/s (an example figure; measure it, do not assume it, and it depends on how much the ViT forward pass weighs on top). For a request with an 80-token text prompt plus one page at 2,240 visual tokens:&lt;/p>
$$\text{TTFT} \approx \frac{80 + 2240}{12{,}000 \text{ tok/s}} \approx \frac{2320}{12{,}000} \approx 0{.}19 \text{ s}$$
&lt;p>plus the fixed cost of the vision encoder&amp;rsquo;s forward pass over the ~9,000 ViT patches (another compute-bound slice of prefill). Now five pages in the same request (a short PDF):&lt;/p>
$$\text{TTFT} \approx \frac{80 + 5 \times 2240}{12{,}000} = \frac{11{,}280}{12{,}000} \approx 0{.}94 \text{ s}$$
&lt;p>The TTFT multiplies almost fivefold, because the visual tokens completely dominate the context. And attention scales as $O(C^2)$: five pages are not &amp;ldquo;5× more expensive&amp;rdquo; in the attention component, but ~25× relative to one. The operational lesson: &lt;strong>the number of images and their resolution are your TTFT budget&lt;/strong>, not a detail. Lowering &lt;code>max_pixels&lt;/code> from 2,240 to, say, 1,100 tokens/page (lower resolution, enough for large text) cuts the prefill almost in half.&lt;/p>
&lt;h3 id="vram-the-vlms-weights-and-what-is-left-for-kv">VRAM: the VLM&amp;rsquo;s weights and what is left for KV&lt;/h3>
&lt;p>On an 80 GB H100 SXM, let us budget a VLM of the Qwen-VL family. Take an 8B (LLM) plus the vision encoder (a ViT of a few hundred million parameters; call the whole thing ~8.5B effective parameters for weight purposes). In BF16 (2 bytes/parameter):&lt;/p>
$$M_{\text{BF16}} \approx 8{.}5 \times 10^9 \times 2 \text{ B} \approx 17 \text{ GB.}$$
&lt;p>In FP8 (1 byte/parameter), the weights halve (&lt;a href="https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct-FP8">Qwen3-VL-8B-Instruct-FP8&lt;/a>, with reported quality almost identical to BF16):&lt;/p>
$$M_{\text{FP8}} \approx 8{.}5 \times 10^9 \times 1 \text{ B} \approx 8{.}5 \text{ GB.}$$
&lt;p>For an 8B model this fits comfortably in BF16 on an H100; FP8 matters more for leaving VRAM free for KV cache, and here the KV is the problem, because visual tokens inflate it. The detail of end-to-end FP8 (weights and KV) is in &lt;a href="https://blog.lo0.es/en/posts/fp8-end-to-end-enable-measure-quality-decide/">FP8 end to end&lt;/a>. What is relevant: one page is ~2,240 KV entries; serving several sessions that send long documents consumes KV at a rate a text-only case would never see. With a 32B VLM in FP8 (~32 GB of weights) on an 80 GB H100 you are left with ~45 GB for KV and activations, which with long multimodal contexts run out sooner than &amp;ldquo;text-only&amp;rdquo; intuition suggests. The rule: with a VLM, &lt;strong>plan the VRAM counting the visual tokens in the KV, not just the weights&lt;/strong>.&lt;/p>
&lt;h2 id="serving-a-vlm-with-vllm">Serving a VLM with vLLM&lt;/h2>
&lt;p>vLLM supports image multimodal input natively for the Qwen-VL family and many other VLMs (&lt;a href="https://docs.vllm.ai/en/stable/features/multimodal_inputs/">Multimodal Inputs, vLLM docs&lt;/a>). The gears that matter:&lt;/p>
&lt;p>&lt;strong>&lt;code>--limit-mm-per-prompt&lt;/code>.&lt;/strong> Limits how many multimodal items each prompt accepts, per modality. By default the limit is generous (999 per modality), but in production it is worth setting it low, &lt;code>--limit-mm-per-prompt '{&amp;quot;image&amp;quot;: 2}'&lt;/code>, because every accepted image reserves token and KV budget. If you set a limit of 8 images and someone sends 8 A4 pages, that is ~18,000 visual tokens in a single request: it blows up &lt;code>max_model_len&lt;/code> or the KV. The limit is a budget firebreak, not a cosmetic restriction. (A curious case: setting it to &lt;code>0&lt;/code> for a modality lets you pass &lt;em>precomputed embeddings&lt;/em> without loading the encoder module, saving VRAM, useful if you do the vision encoding outside vLLM.)&lt;/p>
&lt;p>&lt;strong>Pixel budget via &lt;code>mm_processor_kwargs&lt;/code>.&lt;/strong> Here the token formula connects with the configuration. When serving Qwen2.5-VL you pass, for example, &lt;code>--mm-processor-kwargs '{&amp;quot;min_pixels&amp;quot;: 12544, &amp;quot;max_pixels&amp;quot;: 254016}'&lt;/code> (&lt;a href="https://docs.vllm.ai/en/latest/examples/offline_inference/vision_language_multi_image/">vLLM Qwen2.5-VL discussion&lt;/a>). With $254{,}016$ maximum pixels per image, the token ceiling per image is $254{,}016 / 784 \approx 324$ tokens, an aggressive trim that keeps the cost in check at the price of not being able to read very small print. &lt;strong>This is the dial that really governs your token bill&lt;/strong>: raise it for dense documents, lower it for images where fine detail does not matter.&lt;/p>
&lt;p>&lt;strong>The chat template and the image placeholder.&lt;/strong> The model&amp;rsquo;s processor (loaded via &lt;code>AutoProcessor&lt;/code>) inserts special tokens marking where the image goes in the sequence: in Qwen2.5-VL the sequence &lt;code>&amp;lt;|vision_start|&amp;gt;&amp;lt;|image_pad|&amp;gt;&amp;lt;|vision_end|&amp;gt;&lt;/code>, where &lt;code>&amp;lt;|image_pad|&amp;gt;&lt;/code> expands to the exact number of visual tokens the image produced. vLLM applies this template automatically; it is worth knowing there is a documented quirk, the image block tends to be placed before the user&amp;rsquo;s text in the sequence order, regardless of where you put it in the content (&lt;a href="https://github.com/vllm-project/vllm/issues/15125">issue #15125, vllm-project/vllm&lt;/a>), which rarely causes trouble but is worth bearing in mind if the image/text order is semantically important for your prompt.&lt;/p>
&lt;p>&lt;strong>Current models.&lt;/strong> As of June 2026, the reference open family is Qwen3-VL (dense 2B/4B/8B/32B variants and MoE 30B-A3B / 235B-A22B, interleaved contexts of up to 256K tokens combining text, image and video), with published FP8 checkpoints of almost identical quality to BF16 (&lt;a href="https://arxiv.org/abs/2511.21631">Qwen3-VL Technical Report, arXiv 2511.21631&lt;/a>; &lt;a href="https://docs.vllm.ai/projects/recipes/en/latest/Qwen/Qwen3-VL.html">Qwen3-VL Usage Guide, vLLM recipes&lt;/a>). Qwen2.5-VL remains perfectly serviceable and its token formula is the one we have used because it is public and clean; the cost figures are of the same order in both generations.&lt;/p>
&lt;h2 id="classic-ocr-vs-vlm-when-to-use-which">Classic OCR vs VLM: when to use which&lt;/h2>
&lt;p>Here is the decision that pays the bill. Parsing documents to feed them into a &lt;a href="https://blog.lo0.es/en/posts/end-to-end-document-ingestion-pdf-to-indexed-chunk/">document ingestion&lt;/a> pipeline has two paths, and choosing the split between them well is the difference between a healthy cluster and a choking one.&lt;/p>
&lt;p>&lt;strong>Classic OCR (Tesseract, PaddleOCR).&lt;/strong> Text-recognition engines that run &lt;strong>on CPU&lt;/strong>, are cheap, fast and mature. Tesseract is the portable workhorse (edge, offline kiosks, embedded scanners). PaddleOCR is more capable on layout and Asian scripts, with its PP-Structure module for preserving structure, extracting tables and detecting key-value fields (&lt;a href="https://www.codesota.com/ocr/paddleocr-vs-tesseract">PaddleOCR vs Tesseract, CodeSOTA 2026&lt;/a>). On clean, well-scanned text, classic OCR is hard to beat on cost per page: zero GPU, millisecond latency, very high throughput. Its weakness is the &amp;ldquo;hard&amp;rdquo; document: complex multi-column layout, tables with merged cells, handwriting, stamps, charts, poor scan quality. There, pipeline-based OCR either fails or returns gibberish that destroys the structure.&lt;/p>
&lt;p>&lt;strong>VLM.&lt;/strong> It takes the image of the document and generates structured markdown or HTML in a single end-to-end pass, understanding the layout because it &lt;em>sees&lt;/em> it. It shines exactly where classic OCR struggles: nested tables, reading charts, handwriting, understanding the spatial relationship between elements. The price is the one we have been calculating all through this post: expensive in tokens and in GPU. Worth noting a 2026 nuance: the frontier has moved. VLM models specialised in document parsing have appeared, compact (~1–3B), open source, scoring very high on benchmarks such as OmniDocBench (PaddleOCR-VL in the 94–96 point band; dots.ocr 3B at ~88 with full markdown including tables) (&lt;a href="https://parsli.co/blog/llm-ocr-vs-traditional-ocr">LLM-OCR vs Traditional OCR, Parsli 2026&lt;/a>; &lt;a href="https://www.e2enetworks.com/blog/complete-guide-open-source-ocr-models-2025">Open-Source OCR Models, E2E 2025&lt;/a>). In other words: for pure parsing, today you may not want a 32B generalist VLM, but a small specialised VLM-OCR. But &lt;strong>it is still GPU and it still pays tokens per image&lt;/strong>: the cost calculation does not disappear, the model just gets cheaper.&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 780 300" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Decision tree: classic OCR versus VLM">
&lt;defs>&lt;marker id="ocr1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="currentColor"/>&lt;/marker>&lt;/defs>
&lt;text x="390" y="24" text-anchor="middle" font-size="15" font-weight="700" fill="currentColor">Classic OCR or VLM? Per-document triage&lt;/text>
&lt;rect x="290" y="44" width="200" height="40" rx="6" fill="none" stroke="currentColor" stroke-width="1.5"/>
&lt;text x="390" y="62" text-anchor="middle" font-size="12" fill="currentColor">Is the text clean and&lt;/text>
&lt;text x="390" y="77" text-anchor="middle" font-size="12" fill="currentColor">the layout simple?&lt;/text>
&lt;rect x="60" y="130" width="280" height="60" fill="none" stroke="#22c55e" stroke-width="1.6"/>
&lt;text x="200" y="152" text-anchor="middle" font-size="12" font-weight="700" fill="currentColor">YES → classic OCR (CPU)&lt;/text>
&lt;text x="200" y="170" text-anchor="middle" font-size="11" fill="currentColor">Tesseract / PaddleOCR · cheap · ms · no GPU&lt;/text>
&lt;text x="200" y="184" text-anchor="middle" font-size="11" fill="currentColor">80–90 % of documents land here&lt;/text>
&lt;rect x="440" y="130" width="280" height="60" fill="none" stroke="#ef4444" stroke-width="1.6"/>
&lt;text x="580" y="152" text-anchor="middle" font-size="12" font-weight="700" fill="currentColor">NO → VLM (GPU)&lt;/text>
&lt;text x="580" y="170" text-anchor="middle" font-size="11" fill="currentColor">tables, handwriting, stamps, charts, layout&lt;/text>
&lt;text x="580" y="184" text-anchor="middle" font-size="11" fill="currentColor">token-expensive · save it for the hard subset&lt;/text>
&lt;path d="M340,84 L200,130" stroke="#22c55e" stroke-width="1.6" fill="none" marker-end="url(#ocr1)"/>
&lt;path d="M440,84 L580,130" stroke="#ef4444" stroke-width="1.6" fill="none" marker-end="url(#ocr1)"/>
&lt;text x="250" y="112" text-anchor="middle" font-size="11" fill="currentColor">yes&lt;/text>
&lt;text x="530" y="112" text-anchor="middle" font-size="11" fill="currentColor">no&lt;/text>
&lt;text x="390" y="226" text-anchor="middle" font-size="13" font-weight="700" fill="currentColor">The optimal split: cheap triage first, VLM only for what needs it&lt;/text>
&lt;text x="390" y="250" text-anchor="middle" font-size="11" fill="currentColor">a light classifier (any tables? low OCR confidence? handwriting?) picks the route&lt;/text>
&lt;text x="390" y="270" text-anchor="middle" font-size="11" fill="currentColor">so the VLM only touches 10–20 % of pages, and the GPU does not drown in clean text&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>&lt;strong>The split rule.&lt;/strong> It is not &amp;ldquo;OCR or VLM&amp;rdquo; as a global choice, but &lt;strong>per-document triage&lt;/strong>. Run everything through a cheap first filter: classic OCR already returns a confidence score; if it is high and the document has no tables or visual elements, the OCR transcript will do and you have spent CPU. If confidence is low, there are tables, there is handwriting or there are graphical elements, escalate that page to the VLM. In a typical corpus, 80–90 % of pages are resolved with cheap OCR and only the rest consumes GPU. This is what makes an on-premise VLM sustainable: &lt;strong>you do not serve everything with it&lt;/strong>, you use it as the expensive specialist you send only the hard cases.&lt;/p>
&lt;h2 id="applied-to-the-generic-4h100-cluster">Applied to the generic 4×H100 cluster&lt;/h2>
&lt;p>How this fits into a cluster of 4×H100 SXM 80GB:&lt;/p>
&lt;p>&lt;strong>Where to place the VLM.&lt;/strong> A VLM deserves &lt;strong>a whole H100&lt;/strong> or a large slice, for a VLM-specific reason that text-only intuition does not anticipate: &lt;strong>the token cost per image means not many concurrent sessions fit&lt;/strong>. If each request brings one or several pages, each consumes thousands of KV tokens; the KV cache runs out with few simultaneous sessions. Compared with a text-only chat service where dozens of short conversations fit per GPU, a document service saturates the KV with a handful of heavy requests. That is why it makes no sense to carve the GPU finely for the VLM with aggressive MIG (GPU sharing is covered in &lt;a href="https://blog.lo0.es/en/posts/sharing-one-gpu-time-slicing-mps-mig/">sharing a GPU: time-slicing, MPS and MIG&lt;/a>): the bottleneck is not idle compute but the KV, and a small slice runs out of KV before it makes use of the compute.&lt;/p>
&lt;p>&lt;strong>FP8 so it fits and to free up KV.&lt;/strong> Serve the VLM in FP8: at equal reported quality, the weights take up half and you leave the maximum VRAM for the KV cache, which is the scarce resource with multimodal contexts. For a 32B in FP8 (~32 GB) on an H100, those ~45 GB free for KV are what determine how many concurrent pages you can handle.&lt;/p>
&lt;p>&lt;strong>The VLM only for the subset that needs it.&lt;/strong> The most important architectural piece: &lt;strong>do not put the VLM on the critical path of every document&lt;/strong>. The triage from the previous section lives upstream; the bulk (clean text) is resolved with OCR/PaddleOCR on CPU, and in a cluster with 4×H100 there is probably spare CPU to run it in parallel with the GPUs, and only the hard subset reaches the VLM. This frees the H100s for what really needs them and keeps a reasonable cost per document. It connects directly with &lt;a href="https://blog.lo0.es/en/posts/finops-multi-tenancy-gpu-cluster-who-pays/">FinOps and GPU multi-tenancy with LiteLLM&lt;/a>: when you put a price on every token, a visual token costs the same as a text one, so a page through the VLM can cost 4× its transcript, and that should show up in the chargeback of the team that decides to send everything to the VLM for convenience.&lt;/p>
&lt;p>&lt;strong>Double cold start.&lt;/strong> An operational detail that bites: a VLM loads two models into memory, the vision encoder and the LLM, so its cold start is heavier than that of an equivalent LLM. If you are going to do model swapping or on-demand scaling, fast loading matters twice as much; that is where &lt;a href="https://blog.lo0.es/en/posts/speeding-up-model-cold-start-minutes-to-seconds/">speeding up cold start with Tensorizer&lt;/a> comes in. If instead you serve several models on one GPU by rotating them, the swap+sleep pattern (&lt;a href="https://blog.lo0.es/en/posts/serving-several-models-single-gpu-co-residency-swapping-sleep-mode/">serving several models on one GPU&lt;/a>) has to account for the VLM taking up more room and loading more slowly.&lt;/p>
&lt;p>&lt;strong>Consumer GPU, for reference.&lt;/strong> If someone wants to prototype outside the cluster, an RTX 5090 (Blackwell, 32 GB) comfortably serves a 7–8B VLM in FP8 (~8.5 GB of weights) with KV to spare for a few pages per request; a 32B in FP8 (~32 GB) no longer fits with useful KV on that card and calls for the H100. The 5090 is good for validating the triage pipeline and the prompt; the real service belongs on the H100s.&lt;/p>
&lt;h2 id="what-we-have-not-covered">What we have not covered&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Video.&lt;/strong> Qwen3-VL handles video with dynamic FPS sampling; each frame is an image and the token cost multiplies by the number of sampled frames. One minute of video can be tens of thousands of tokens. It is the most expensive multimodal beast and deserves its own analysis.&lt;/li>
&lt;li>&lt;strong>Prefix caching of images.&lt;/strong> If the same image (a logo, a template) appears in many requests, can its KV be cached? It depends on the backend and on the stability of the placeholder; it connects with the &lt;a href="https://blog.lo0.es/en/posts/vllm-attention-backend-flashattention-flashinfer-prefill-decode-asymmetry/">attention backend&lt;/a>.&lt;/li>
&lt;li>&lt;strong>Evaluation.&lt;/strong> How to measure that the VLM extracts the table correctly (it is not enough for it to &amp;ldquo;look right&amp;rdquo;): faithfulness against a set with structured ground truth.&lt;/li>
&lt;li>&lt;strong>Fine-tuning the VLM&lt;/strong> for a specific document domain (invoices, particular forms), which can put part of the domain&amp;rsquo;s &amp;ldquo;knowing how to see&amp;rdquo; into the weights and reduce what the prompt has to explain.&lt;/li>
&lt;/ul>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/finops-multi-tenancy-gpu-cluster-who-pays/">FinOps and GPU multi-tenancy with LiteLLM&lt;/a> — sibling piece in this batch: when you put a price on every token, a visual token costs the same as a text one, and a page through the VLM can cost 4× its transcript. Chargeback is what disciplines VLM usage.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/speeding-up-model-cold-start-minutes-to-seconds/">Speeding up cold start with Tensorizer&lt;/a> — sibling piece: a VLM loads two models (encoder + LLM), so its start-up is heavier and fast loading matters twice as much.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/end-to-end-document-ingestion-pdf-to-indexed-chunk/">Document ingestion: from PDF to indexed chunk&lt;/a> — the pipeline where the OCR/VLM triage fits: the bulk through cheap OCR, the hard subset through the VLM.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/sharing-one-gpu-time-slicing-mps-mig/">Sharing a GPU: time-slicing, MPS and MIG&lt;/a> — why a small slice is no use to the VLM: the bottleneck is the KV that visual tokens eat, not idle compute.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/serving-several-models-single-gpu-co-residency-swapping-sleep-mode/">Serving several models on one GPU: swap + sleep&lt;/a> — rotating the VLM with other models, allowing for the fact that it takes up more VRAM and loads more slowly because of its double model.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/vllm-attention-backend-flashattention-flashinfer-prefill-decode-asymmetry/">vLLM&amp;rsquo;s attention backend&lt;/a> — the compute-bound prefill that every visual token fattens; why five pages cost not 5× but ~25× in attention.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/fp8-end-to-end-enable-measure-quality-decide/">FP8 end to end: weights and KV&lt;/a> — serving the VLM in FP8 so it fits and, above all, to free up the KV cache that multimodal contexts exhaust sooner than expected.&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>vLLM, &lt;em>Multimodal Inputs&lt;/em> (&lt;code>limit_mm_per_prompt&lt;/code>, precomputed embeddings): &lt;a href="https://docs.vllm.ai/en/stable/features/multimodal_inputs/">https://docs.vllm.ai/en/stable/features/multimodal_inputs/&lt;/a>&lt;/li>
&lt;li>vLLM, &lt;em>Vision Language Multi Image&lt;/em> (&lt;code>mm_processor_kwargs&lt;/code>, min/max pixels): &lt;a href="https://docs.vllm.ai/en/latest/examples/offline_inference/vision_language_multi_image/">https://docs.vllm.ai/en/latest/examples/offline_inference/vision_language_multi_image/&lt;/a>&lt;/li>
&lt;li>vLLM, &lt;em>Qwen3-VL Usage Guide&lt;/em> (recipes): &lt;a href="https://docs.vllm.ai/projects/recipes/en/latest/Qwen/Qwen3-VL.html">https://docs.vllm.ai/projects/recipes/en/latest/Qwen/Qwen3-VL.html&lt;/a>&lt;/li>
&lt;li>Qwen team, &lt;em>Qwen2.5-VL&lt;/em> (blog, token formula, dynamic resolution): &lt;a href="https://qwenlm.github.io/blog/qwen2.5-vl/">https://qwenlm.github.io/blog/qwen2.5-vl/&lt;/a>&lt;/li>
&lt;li>&lt;em>Qwen2.5-VL&lt;/em> (Transformers docs, min/max pixels, token range): &lt;a href="https://huggingface.co/docs/transformers/model_doc/qwen2_5_vl">https://huggingface.co/docs/transformers/model_doc/qwen2_5_vl&lt;/a>&lt;/li>
&lt;li>&lt;em>Qwen3-VL Technical Report&lt;/em>, arXiv 2511.21631: &lt;a href="https://arxiv.org/abs/2511.21631">https://arxiv.org/abs/2511.21631&lt;/a>&lt;/li>
&lt;li>&lt;em>Qwen3-VL-8B-Instruct-FP8&lt;/em> (FP8 with quality almost identical to BF16): &lt;a href="https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct-FP8">https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct-FP8&lt;/a>&lt;/li>
&lt;li>vLLM issue #15125 (image placeholder order): &lt;a href="https://github.com/vllm-project/vllm/issues/15125">https://github.com/vllm-project/vllm/issues/15125&lt;/a>&lt;/li>
&lt;li>&lt;em>PaddleOCR vs Tesseract&lt;/em>, CodeSOTA 2026: &lt;a href="https://www.codesota.com/ocr/paddleocr-vs-tesseract">https://www.codesota.com/ocr/paddleocr-vs-tesseract&lt;/a>&lt;/li>
&lt;li>&lt;em>LLM-Based OCR vs Traditional OCR&lt;/em>, Parsli 2026: &lt;a href="https://parsli.co/blog/llm-ocr-vs-traditional-ocr">https://parsli.co/blog/llm-ocr-vs-traditional-ocr&lt;/a>&lt;/li>
&lt;li>&lt;em>Open-Source OCR Models 2025&lt;/em>, E2E Networks: &lt;a href="https://www.e2enetworks.com/blog/complete-guide-open-source-ocr-models-2025">https://www.e2enetworks.com/blog/complete-guide-open-source-ocr-models-2025&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>The pantry of pigeonholes: PagedAttention and the vLLM block manager</title><link>https://blog.lo0.es/en/posts/pagedattention-vllm-block-manager/</link><pubDate>Mon, 08 Jun 2026 05:20:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/pagedattention-vllm-block-manager/</guid><description>&lt;blockquote>
&lt;p>Part of the &lt;em>under the engine&lt;/em> series. The &lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">scheduler post&lt;/a> ended with a loose end: the scheduler has a second budget, the &lt;strong>KV blocks&lt;/strong>, and when they run out it preempts. This post opens up that budget. It is the piece the &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache post&lt;/a> took for granted, &lt;em>what&lt;/em> gets stored, in order to explain &lt;em>how it is managed in memory&lt;/em>. And it is the one the &lt;a href="https://blog.lo0.es/en/posts/flashattention-librarian-io-awareness-async-blackwell-asymmetry/">FlashAttention post&lt;/a> had been promising for months.&lt;/p>
&lt;/blockquote>
&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>The &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache&lt;/a> grows a little with every token generated, and the problem was never its &lt;strong>total size&lt;/strong> but the &lt;strong>way it is reserved&lt;/strong>. The first servers asked, per request, for a contiguous chunk of HBM the size of the maximum possible context. Since almost no request reaches that maximum, the result was catastrophic: &lt;strong>60-80% of the HBM wasted&lt;/strong> on fragmentation. PagedAttention applies to the KV the oldest and most battle-tested idea in operating systems, &lt;strong>paging&lt;/strong>: split the KV into &lt;strong>fixed-size blocks&lt;/strong> (16 tokens by default), store them in non-contiguous HBM wherever there is room, and keep a &lt;strong>block table&lt;/strong> that translates each sequence&amp;rsquo;s &lt;em>logical&lt;/em> block into its &lt;em>physical&lt;/em> one. Waste falls to &lt;strong>~4%&lt;/strong> (only the last block, half-filled). And since each block can be identified by the &lt;strong>hash of its content&lt;/strong>, two requests that share a prefix point at the &lt;strong>same physical block&lt;/strong> and share memory, with &lt;strong>copy-on-write&lt;/strong> when one of them diverges: that is the engine of &lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">prefix caching&lt;/a>. This post explains fragmentation with numbers, the block manager, the block table, COW, the block-size trade-off, the 10 knobs and the trap of confusing &lt;em>&amp;ldquo;fragmentation solved&amp;rdquo;&lt;/em> with &lt;em>&amp;ldquo;zero waste&amp;rdquo;&lt;/em>. On the generic 4×H100 SXM cluster.&lt;/p>
&lt;h2 id="where-you-are-the-pantry-underneath-the-scheduler">Where you are: the pantry, underneath the scheduler&lt;/h2>
&lt;p>Go back to the kitchen of the &lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">previous post&lt;/a>. The front-of-house manager assembles trays, but behind him there is a pantry where the ingredients each table accumulates over its meal are stored, its KV cache. The question in this post is how that pantry is organised.&lt;/p>
&lt;p>The naive way: each table gets a whole contiguous shelf, sized for the greediest imaginable customer. The problem is obvious: a table that orders little leaves almost all of its shelf empty, but that shelf is already reserved and nobody else can use it. With many tables, the pantry fills up with half-empty shelves and no new table fits, even though the gaps added together leave plenty of room.&lt;/p>
&lt;p>The PagedAttention way: the pantry is divided into &lt;strong>small, identical pigeonholes&lt;/strong>. Each table is given the pigeonholes it needs, one at a time, wherever there is room, and they do not have to be next to each other. A &lt;strong>map book&lt;/strong> records which physical pigeonholes each table has and in what order. When a table leaves, its pigeonholes go back to the pile. There are no half-empty shelves: the only waste is the last pigeonhole of each table, the half-filled one. That is, almost literally, the virtual memory of an operating system applied to the KV cache.&lt;/p>
&lt;h2 id="why-contiguous-memory-fragmented">Why contiguous memory fragmented&lt;/h2>
&lt;p>Reserving contiguously and up front produces three distinct kinds of waste:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Reservation fragmentation.&lt;/strong> You set aside space for &lt;code>max_model_len&lt;/code> (8192 tokens, say) even though the request will use 800. Reserved and never used.&lt;/li>
&lt;li>&lt;strong>Internal fragmentation.&lt;/strong> Within what you reserved, everything above what you actually use at any given moment.&lt;/li>
&lt;li>&lt;strong>External fragmentation.&lt;/strong> Gaps between contiguous reservations that are too small for a new request, even though added together they would be plenty.&lt;/li>
&lt;/ol>
&lt;p>The original vLLM paper measured that earlier systems &lt;strong>wasted 60% to 80%&lt;/strong> of the KV memory through these three routes (&lt;a href="https://arxiv.org/pdf/2309.06180">Kwon et al., SOSP 2023&lt;/a>). That is: on a GPU with room for 100 real requests, only 20-40 fitted. Paging attacks all three at once. It eliminates reservation waste (on-demand allocation) and external waste (blocks need not be contiguous), and leaves only a remainder of the internal kind: the last partial block.&lt;/p>
&lt;h2 id="the-mechanism-blocks-block-table-and-the-kernel-gather">The mechanism: blocks, block table and the kernel gather&lt;/h2>
&lt;p>The KV of a sequence is chopped into &lt;strong>logical blocks&lt;/strong> of $b$ tokens (by default $b = 16$). Each logical block is mapped, via the &lt;strong>block table&lt;/strong>, to a &lt;strong>physical block&lt;/strong> somewhere in the HBM. The block table is the &amp;ldquo;map book&amp;rdquo;: a per-request list of which physical block corresponds to each logical one (&lt;a href="https://docs.vllm.ai/en/v0.6.1/automatic_prefix_caching/details.html">vLLM implementation&lt;/a>).&lt;/p>
&lt;svg viewBox="0 0 720 250" xmlns="http://www.w3.org/2000/svg" font-family="sans-serif" font-size="12" role="img" aria-label="Logical blocks, block table and non-contiguous physical blocks">
&lt;text x="20" y="20" fill="currentColor" font-size="13">Request A — logical blocks (sequence order)&lt;/text>
&lt;rect x="20" y="30" width="50" height="34" fill="none" stroke="#2563eb" stroke-width="1.5"/>&lt;text x="45" y="52" text-anchor="middle" fill="#2563eb">L0&lt;/text>
&lt;rect x="75" y="30" width="50" height="34" fill="none" stroke="#2563eb" stroke-width="1.5"/>&lt;text x="100" y="52" text-anchor="middle" fill="#2563eb">L1&lt;/text>
&lt;rect x="130" y="30" width="50" height="34" fill="none" stroke="#2563eb" stroke-width="1.5"/>&lt;text x="155" y="52" text-anchor="middle" fill="#2563eb">L2&lt;/text>
&lt;rect x="185" y="30" width="50" height="34" fill="none" stroke="#2563eb" stroke-width="1.5" stroke-dasharray="4 3"/>&lt;text x="210" y="52" text-anchor="middle" fill="#2563eb">L3*&lt;/text>
&lt;text x="20" y="100" fill="currentColor" font-size="13">block table: L0→F7 · L1→F2 · L2→F9 · L3→F4 (last one, half-filled)&lt;/text>
&lt;text x="20" y="135" fill="currentColor" font-size="13">Physical HBM — pigeonholes wherever there is room (non-contiguous)&lt;/text>
&lt;rect x="20" y="150" width="40" height="34" fill="none" stroke="currentColor"/>&lt;text x="40" y="171" text-anchor="middle" fill="currentColor" font-size="10">F0&lt;/text>
&lt;rect x="65" y="150" width="40" height="34" fill="#16a34a" opacity="0.7"/>&lt;text x="85" y="171" text-anchor="middle" fill="currentColor" font-size="10">F2·L1&lt;/text>
&lt;rect x="110" y="150" width="40" height="34" fill="none" stroke="currentColor"/>&lt;text x="130" y="171" text-anchor="middle" fill="currentColor" font-size="10">F3&lt;/text>
&lt;rect x="155" y="150" width="40" height="34" fill="#f59e0b" opacity="0.7"/>&lt;text x="175" y="171" text-anchor="middle" fill="currentColor" font-size="10">F4·L3&lt;/text>
&lt;rect x="200" y="150" width="40" height="34" fill="none" stroke="currentColor"/>&lt;text x="220" y="171" text-anchor="middle" fill="currentColor" font-size="10">F5&lt;/text>
&lt;rect x="290" y="150" width="40" height="34" fill="#16a34a" opacity="0.7"/>&lt;text x="310" y="171" text-anchor="middle" fill="currentColor" font-size="10">F7·L0&lt;/text>
&lt;rect x="380" y="150" width="40" height="34" fill="#16a34a" opacity="0.7"/>&lt;text x="400" y="171" text-anchor="middle" fill="currentColor" font-size="10">F9·L2&lt;/text>
&lt;text x="20" y="220" fill="currentColor" font-size="11">The attention kernel does a gather: it walks the block table and reads F7,F2,F9,F4 as if they were contiguous.&lt;/text>
&lt;text x="20" y="238" fill="#f59e0b" font-size="11">* Only F4 is half-filled: that is the only waste (≈ half a block per sequence).&lt;/text>
&lt;/svg>
&lt;p>The key point is that the attention kernel knows how to read like that. Instead of assuming a contiguous KV tensor, the PagedAttention kernel receives the block table and does a &lt;strong>gather&lt;/strong>: for each sequence it walks its physical blocks in logical order and reads K and V as if they were together. That is why PagedAttention is not just a data structure: it is a &lt;strong>kernel&lt;/strong> that knows how to attend over paged memory. And that is why the &lt;a href="https://blog.lo0.es/en/posts/flashattention-librarian-io-awareness-async-blackwell-asymmetry/">attention backend&lt;/a> and the block manager are tied together, the second deciding where the KV lives and the first knowing how to read it from there.&lt;/p>
&lt;h2 id="the-block-manager-the-pantry-librarian">The block manager: the pantry librarian&lt;/h2>
&lt;p>The &lt;strong>block manager&lt;/strong> (in V1, the &lt;code>KVCacheManager&lt;/code>) is the one that keeps the map book. Its responsibilities:&lt;/p>
&lt;ul>
&lt;li>Maintain a pool of free physical blocks (a queue of available blocks).&lt;/li>
&lt;li>Allocate blocks to a sequence as it grows (a new block every $b$ tokens).&lt;/li>
&lt;li>Free the blocks when the sequence finishes or is preempted.&lt;/li>
&lt;li>Maintain the block tables (logical→physical) of each request.&lt;/li>
&lt;li>Manage prefix caching: detect blocks with identical content and share them.&lt;/li>
&lt;li>When free blocks run out, tell the scheduler to preempt (see &lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">the scheduler post&lt;/a>).&lt;/li>
&lt;/ul>
&lt;p>When the block manager says &amp;ldquo;no blocks left&amp;rdquo;, the scheduler has to take somebody off the train. That is why the two budgets, tokens and blocks, are the two hands of the same engine.&lt;/p>
&lt;h2 id="prefix-caching-sharing-pigeonholes-with-copy-on-write">Prefix caching: sharing pigeonholes with copy-on-write&lt;/h2>
&lt;p>Here is the elegant part. If two requests start with the same prefix, the same system prompt, the same context document, the first KV blocks of both are identical byte for byte. Why compute and store them twice?&lt;/p>
&lt;p>vLLM gives each block a &lt;strong>hash&lt;/strong> summarising its content (the tokens that formed it, plus the hash of the previous block, so that the hash captures position). It keeps a global table of blocks by hash. When a new request produces a block whose hash already exists, it allocates no new memory: it points its block table at the physical block that was already there (&lt;a href="https://docs.vllm.ai/en/v0.8.1/design/automatic_prefix_caching.html">automatic prefix caching, vLLM&lt;/a>).&lt;/p>
&lt;svg viewBox="0 0 720 200" xmlns="http://www.w3.org/2000/svg" font-family="sans-serif" font-size="12" role="img" aria-label="Prefix caching with copy-on-write">
&lt;text x="20" y="20" fill="currentColor" font-size="13">Common prefix (system prompt) shared between A and B&lt;/text>
&lt;rect x="20" y="35" width="55" height="34" fill="#16a34a" opacity="0.7"/>&lt;text x="47" y="56" text-anchor="middle" fill="currentColor" font-size="10">F1&lt;/text>
&lt;rect x="80" y="35" width="55" height="34" fill="#16a34a" opacity="0.7"/>&lt;text x="107" y="56" text-anchor="middle" fill="currentColor" font-size="10">F2&lt;/text>
&lt;text x="200" y="56" fill="currentColor">← A and B both point here (shared memory)&lt;/text>
&lt;path d="M47 90 V70" stroke="#2563eb" stroke-width="1.5" marker-end="url(#b)"/>&lt;text x="47" y="105" text-anchor="middle" fill="#2563eb" font-size="10">A&lt;/text>
&lt;path d="M107 90 V70" stroke="#7c3aed" stroke-width="1.5" marker-end="url(#b)"/>&lt;text x="120" y="105" text-anchor="middle" fill="#7c3aed" font-size="10">B&lt;/text>
&lt;text x="20" y="140" fill="currentColor" font-size="13">A and B diverge → copy-on-write: B copies the block before writing&lt;/text>
&lt;rect x="20" y="150" width="55" height="30" fill="#2563eb" opacity="0.7"/>&lt;text x="47" y="169" text-anchor="middle" fill="currentColor" font-size="10">F3·A&lt;/text>
&lt;rect x="90" y="150" width="55" height="30" fill="#7c3aed" opacity="0.7"/>&lt;text x="117" y="169" text-anchor="middle" fill="currentColor" font-size="10">F8·B (copy)&lt;/text>
&lt;defs>&lt;marker id="b" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto">&lt;path d="M0 0 L8 4 L0 8 z" fill="currentColor"/>&lt;/marker>&lt;/defs>
&lt;/svg>
&lt;p>&lt;strong>Copy-on-write&lt;/strong> is the safeguard: while A and B share a block, neither can modify it. The moment one of the two needs to write something different into that block (because their sequences diverge, or in &lt;em>parallel sampling&lt;/em> / beam search where several branches share a prefix), the block manager copies the block for that branch and only then writes (&lt;a href="https://docs.vllm.ai/en/v0.6.1/automatic_prefix_caching/details.html">details, vLLM&lt;/a>). It is the same COW that &lt;code>fork()&lt;/code> uses in an OS: share until somebody writes.&lt;/p>
&lt;p>The saving is direct: if 50 requests share a system prompt of 1,000 tokens, instead of 50 copies of that prefix&amp;rsquo;s KV there is one. How to maximise that saving in practice is the subject of the &lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">prefix cache hit rate post&lt;/a>.&lt;/p>
&lt;h2 id="the-maths-that-matter-how-much-kv-how-many-blocks">The maths that matter: how much KV, how many blocks&lt;/h2>
&lt;p>&lt;strong>KV bytes per token.&lt;/strong> For a transformer block with $L$ layers, $h_{kv}$ KV heads (GQA), per-head dimension $d$ and $s$ bytes per element (2 in FP16):&lt;/p>
$$\text{KV/token} = 2 \cdot L \cdot h_{kv} \cdot d \cdot s$$
&lt;p>For a Llama-70B ($L=80$, $h_{kv}=8$, $d=128$, FP16):&lt;/p>
$$\text{KV/token} = 2 \cdot 80 \cdot 8 \cdot 128 \cdot 2 = 327680 \text{ bytes} \approx 320 \text{ KB}$$
&lt;p>A block of 16 tokens takes up $16 \times 320\,\text{KB} = 5.12$ MB.&lt;/p>
&lt;p>&lt;strong>How many requests fit.&lt;/strong> If after loading the weights ~120 GB of the node&amp;rsquo;s 320 are left for KV:&lt;/p>
$$\text{KV tokens} = \frac{120 \cdot 10^9}{327680} \approx 366000 \text{ tokens} \approx 22900 \text{ blocks}$$
&lt;p>With average contexts of 4,000 tokens (250 blocks each), that is ~90 concurrent requests. That number, not &lt;code>max_num_seqs&lt;/code>, is the real concurrency ceiling, and it is exactly the &amp;ldquo;block budget&amp;rdquo; of the &lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">scheduler&lt;/a>.&lt;/p>
&lt;p>&lt;strong>The waste that remains.&lt;/strong> PagedAttention does not get to zero: each sequence wastes, on average, half a block (the last one, half-filled). With 16-token blocks and sequences of 4,000, that is $8 / 4000 = 0.2\%$ per sequence, and the famous aggregate &amp;ldquo;~4%&amp;rdquo; from the paper includes other overheads. The lesson: the waste does not disappear, it is &lt;strong>bounded&lt;/strong> to the size of one block.&lt;/p>
&lt;h2 id="the-block-size-trade-off">The block-size trade-off&lt;/h2>
&lt;p>The &lt;code>block_size&lt;/code> (16 by default) is a trade-off, not a magic constant:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Block&lt;/th>
&lt;th>Advantage&lt;/th>
&lt;th>Drawback&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Small (8)&lt;/td>
&lt;td>less internal waste; finer-grained prefix sharing&lt;/td>
&lt;td>more block table entries; more management and gather overhead&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Large (32)&lt;/td>
&lt;td>fewer metadata; more efficient gather&lt;/td>
&lt;td>more waste in the last block; prefix caching shares at a coarser grain (fewer hits)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>A large block shares worse: prefix caching can only reuse complete and identical blocks, so with 32-token blocks two prompts that agree on 20 tokens share nothing (they do not fill a common block), whereas with 8-token blocks they share two blocks. The default of 16 is the point vLLM found reasonable for most workloads; it is worth testing if your workload has short, heavily repeated prefixes.&lt;/p>
&lt;h2 id="the-10-knobs">The 10 knobs&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>#&lt;/th>
&lt;th>Knob&lt;/th>
&lt;th>What it controls&lt;/th>
&lt;th>Cost if you overdo it&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1&lt;/td>
&lt;td>&lt;code>block_size&lt;/code>&lt;/td>
&lt;td>tokens per block&lt;/td>
&lt;td>waste / overhead (see table)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2&lt;/td>
&lt;td>&lt;code>enable_prefix_caching&lt;/code>&lt;/td>
&lt;td>sharing blocks by hash&lt;/td>
&lt;td>almost none; usually on&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>3&lt;/td>
&lt;td>&lt;code>gpu_memory_utilization&lt;/code>&lt;/td>
&lt;td>how many physical blocks there are&lt;/td>
&lt;td>OOM if too high&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>4&lt;/td>
&lt;td>&lt;code>kv_cache_dtype&lt;/code> (FP8)&lt;/td>
&lt;td>bytes per KV element&lt;/td>
&lt;td>quality (measure, do not assume)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>5&lt;/td>
&lt;td>&lt;code>swap_space&lt;/code>&lt;/td>
&lt;td>blocks that fit on the host (SWAP)&lt;/td>
&lt;td>PCIe traffic on preemption&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>6&lt;/td>
&lt;td>&lt;code>max_model_len&lt;/code>&lt;/td>
&lt;td>maximum length per request&lt;/td>
&lt;td>fewer requests if too high&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>7&lt;/td>
&lt;td>eviction policy&lt;/td>
&lt;td>who gets blocks taken away&lt;/td>
&lt;td>prefix cache hit rate&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>8&lt;/td>
&lt;td>sliding window&lt;/td>
&lt;td>discarding old KV&lt;/td>
&lt;td>quality on long contexts&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>9&lt;/td>
&lt;td>TP / KV sharding&lt;/td>
&lt;td>splitting the KV across GPUs&lt;/td>
&lt;td>NVLink traffic&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>10&lt;/td>
&lt;td>num_gpu_blocks (override)&lt;/td>
&lt;td>forcing the block count&lt;/td>
&lt;td>OOM or underuse&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="how-it-connects-to-the-rest-of-the-stack">How it connects to the rest of the stack&lt;/h2>
&lt;p>&lt;strong>With the scheduler.&lt;/strong> The &amp;ldquo;block budget&amp;rdquo; of the &lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">scheduler&lt;/a> is administered by this block manager. When it says there are no blocks, the scheduler preempts (RECOMPUTE by default).&lt;/p>
&lt;p>&lt;strong>With the KV cache.&lt;/strong> The &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache post&lt;/a> explains &lt;em>what&lt;/em> each token stores; this one, &lt;em>how&lt;/em> it is placed in memory without fragmenting.&lt;/p>
&lt;p>&lt;strong>With prefix caching.&lt;/strong> COW and block hashes are the mechanism; &lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">hit rate engineering&lt;/a> is how to squeeze it (prompt structure, prefix-aware routing).&lt;/p>
&lt;p>&lt;strong>With KV quantisation.&lt;/strong> Moving the KV to &lt;a href="https://blog.lo0.es/en/posts/fp8-end-to-end-enable-measure-quality-decide/">FP8&lt;/a> halves the bytes/token: the same node holds twice the tokens. It is the most direct lever on concurrency.&lt;/p>
&lt;p>&lt;strong>With the attention backend.&lt;/strong> The &lt;a href="https://blog.lo0.es/en/posts/flashattention-librarian-io-awareness-async-blackwell-asymmetry/">FlashAttention/FlashInfer&lt;/a> kernel has to know how to attend over paged blocks; the block manager decides where they live, the kernel knows how to read them.&lt;/p>
&lt;p>&lt;strong>With disaggregated serving.&lt;/strong> Moving a request from a prefill pool to a decode pool in &lt;a href="https://blog.lo0.es/en/posts/disaggregated-serving-prefill-decode-specialised-pods/">disaggregated serving&lt;/a> is, at bottom, &lt;strong>transferring its KV blocks&lt;/strong> between engines, over NVLink or over the network.&lt;/p>
&lt;p>&lt;strong>With multi-LoRA.&lt;/strong> In &lt;a href="https://blog.lo0.es/en/posts/multi-lora-serving-shared-base-concurrent-adapters-sgmv-kernel/">multi-LoRA serving&lt;/a>, the base shares prefix KV between requests from different adapters as long as the prefix is identical.&lt;/p>
&lt;h2 id="traps-and-things-that-are-not-what-they-seem">Traps and things that are not what they seem&lt;/h2>
&lt;p>&lt;strong>&amp;ldquo;PagedAttention eliminates waste.&amp;rdquo;&lt;/strong> It &lt;strong>bounds&lt;/strong> it, it does not eliminate it. What remains is the last partial block per sequence (~half a block) plus the block table metadata. It is ~4% instead of 60-80%, but it is not zero. Sizing as if it were zero leaves you without a cushion.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;Bigger blocks always perform better.&amp;rdquo;&lt;/strong> The gather is somewhat more efficient, yes, but you lose &lt;em>sharing&lt;/em> granularity: prefix caching shares worse and the waste in the last block grows. On workloads with many short repeated prefixes, small blocks can win.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;Prefix caching shares KV between users, that is a privacy problem.&amp;rdquo;&lt;/strong> It shares only blocks that are &lt;strong>identical token by token&lt;/strong> (same system prompt, same document). It does not expose one user&amp;rsquo;s content to another: if the tokens do not match, there is no common block. What is worth watching is &lt;strong>information leaking through timing side channels&lt;/strong> (a hit is faster than a miss), relevant only in very adversarial multi-tenant scenarios.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;FP8 in the KV is free: twice the concurrency.&amp;rdquo;&lt;/strong> It does double the tokens that fit, yes, but KV in FP8 &lt;strong>degrades quality&lt;/strong> measurably on long contexts. It is a real lever, not a free lunch: quality has to be measured (&lt;a href="https://blog.lo0.es/en/posts/fp8-end-to-end-enable-measure-quality-decide/">FP8 end-to-end&lt;/a>), not assumed.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;Going back to contiguous memory would be simpler and almost as good.&amp;rdquo;&lt;/strong> That is nostalgia for the contiguous tensor. The &amp;ldquo;simple&amp;rdquo; option reintroduces 60-80% fragmentation: on a GPU, that is the difference between 30 and 90 concurrent requests. The complexity of the block table pays for itself many times over.&lt;/p>
&lt;p>&lt;strong>SWAP versus RECOMPUTE when preempting.&lt;/strong> Configuring a lot of &lt;code>swap_space&lt;/code> &amp;ldquo;so as not to lose KV&amp;rdquo; puts gigabyte transfers over &lt;a href="https://blog.lo0.es/en/posts/pcie-topology-gpudirect-p2p-acs-security-guard/">PCIe&lt;/a> on the critical path. In V1, RECOMPUTE is usually better; swap is for specific cases.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>The bottleneck in serving an LLM was never only how much memory you have, but &lt;strong>how you hand it out&lt;/strong>. The first servers treated the KV cache as a contiguous shelf per client and threw two thirds of the HBM in the bin without it showing up on any dashboard. PagedAttention stole from the operating system its best idea of fifty years ago, paging, and applied it at the exact place where it hurt: small pigeonholes, a map book, on-demand allocation and, as a bonus, the possibility that two requests starting the same way share the same pigeonholes until they stop resembling each other. The result is not magic: the waste is still there, but bounded to the size of one block instead of to the size of the worst imaginable case. And that difference, from 70% to 4%, is what turned a GPU serving thirty clients into one serving ninety, without touching the hardware. The pantry did not get bigger; it got better organised.&lt;/p>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/vllm-scheduler-step-maitre-d-each-round/">The pass: the vLLM scheduler step&lt;/a> — the block budget this block manager administers; when it runs out, preemption.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache: the working memory&lt;/a> — &lt;em>what&lt;/em> each token stores, the data that gets paged here.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/prefix-cache-hit-rate-engineering/">Prefix cache hit rate engineering&lt;/a> — how to squeeze the block sharing that COW makes possible.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/flashattention-librarian-io-awareness-async-blackwell-asymmetry/">FlashAttention v1/v2/v3/v4&lt;/a> — the kernel that knows how to attend over paged KV.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/fp8-end-to-end-enable-measure-quality-decide/">FP8 end-to-end: weights and KV&lt;/a> — halving the bytes/token and doubling concurrency, while measuring quality.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/disaggregated-serving-prefill-decode-specialised-pods/">Disaggregated serving: prefill and decode separated&lt;/a> — moving a request between pools is transferring its KV blocks.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/pcie-topology-gpudirect-p2p-acs-security-guard/">PCIe, GPUDirect P2P and ACS&lt;/a> — where the blocks travel when SWAP happens or KV moves between GPUs.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/multi-lora-serving-shared-base-concurrent-adapters-sgmv-kernel/">Multi-LoRA serving&lt;/a> — sharing a prefix between requests from different adapters.&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>W. Kwon et al., &lt;em>Efficient Memory Management for Large Language Model Serving with PagedAttention&lt;/em> (SOSP 2023): &lt;a href="https://arxiv.org/pdf/2309.06180">https://arxiv.org/pdf/2309.06180&lt;/a>.&lt;/li>
&lt;li>vLLM, &lt;em>Automatic Prefix Caching&lt;/em> (design, block hashing): &lt;a href="https://docs.vllm.ai/en/v0.8.1/design/automatic_prefix_caching.html">https://docs.vllm.ai/en/v0.8.1/design/automatic_prefix_caching.html&lt;/a>.&lt;/li>
&lt;li>vLLM, &lt;em>Automatic Prefix Caching — Implementation&lt;/em> (block table, COW): &lt;a href="https://docs.vllm.ai/en/v0.6.1/automatic_prefix_caching/details.html">https://docs.vllm.ai/en/v0.6.1/automatic_prefix_caching/details.html&lt;/a>.&lt;/li>
&lt;li>H. Elshafie, &lt;em>Paged Attention from First Principles: A View Inside vLLM&lt;/em>: &lt;a href="https://hamzaelshafie.bearblog.dev/paged-attention-from-first-principles-a-view-inside-vllm/">https://hamzaelshafie.bearblog.dev/paged-attention-from-first-principles-a-view-inside-vllm/&lt;/a>.&lt;/li>
&lt;li>&lt;em>vAttention: Dynamic Memory Management for Serving LLMs without PagedAttention&lt;/em> (alternative, critical context): &lt;a href="https://arxiv.org/pdf/2405.04437">https://arxiv.org/pdf/2405.04437&lt;/a>.&lt;/li>
&lt;/ul></description></item><item><title>Disaggregated serving: prefill and decode in specialised pods</title><link>https://blog.lo0.es/en/posts/disaggregated-serving-prefill-decode-specialised-pods/</link><pubDate>Fri, 22 May 2026 01:00:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/disaggregated-serving-prefill-decode-specialised-pods/</guid><description>&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>LLM inference has two phases with opposite profiles: &lt;strong>prefill&lt;/strong> (processing the whole prompt in one go) is compute-bound, &lt;strong>decode&lt;/strong> (generating token by token) is memory-bandwidth-bound. Running them on the same GPU forces a choice between two incompatible optimal hardware profiles, and leaves between 60 % and 80 % of peak capacity unused. The industry consolidated the pattern in 2026: &lt;strong>disaggregated serving&lt;/strong>, separate pods for each phase, connected by a KV cache transfer channel (NIXL over UCX, RDMA, or NCCL as a fallback). DistServe demonstrated 7.4× more request rate at the same SLO; NVIDIA Dynamo 1.0 (GA at GTC 2026) takes the pattern to production at datacenter scale. Mixing heterogeneous hardware, H100 for prefill and commodity GPUs for decode, cuts up to 48 % off the cost per token. This article explains the why, the how, and the numbers that matter for a typical on-premise infrastructure.&lt;/p>
&lt;h2 id="you-are-here-deploy">You are here: Deploy&lt;/h2>
&lt;p>Disaggregated serving is an architectural decision in the &lt;strong>Deploy&lt;/strong> stage of the &lt;a href="https://blog.lo0.es/en/posts/six-stage-llmops-pipeline-architecture-and-deep-dive/">six-stage LLMOps pipeline&lt;/a>. It does not change the model, it does not change the data, it does not change the evals. It only changes &lt;strong>how inference pods are spread over the GPU hardware&lt;/strong>. But that change moves aggregate throughput between 2× and 7×.&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1rem auto;">
&lt;svg viewBox="0 0 780 90" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="you are here: Deploy">
&lt;style>.box{stroke:#444;stroke-width:1.4;rx:6}.active{fill:#ff8a4c;stroke-width:3}.idle{fill:#f4f4f4}.lbl{font:600 12px sans-serif;fill:#222}.arr{stroke:#666;stroke-width:1.4;fill:none;marker-end:url(#dsm)}.cyc{stroke:#888;stroke-width:1.2;fill:none;stroke-dasharray:4 2;marker-end:url(#dsm)}&lt;/style>
&lt;defs>&lt;marker id="dsm" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#666"/>&lt;/marker>&lt;/defs>
&lt;text x="390" y="20" text-anchor="middle" class="lbl">You are here: DEPLOY · prefill/decode pod topology and KV cache transfer&lt;/text>
&lt;rect x="30" y="35" width="110" height="35" class="box idle"/>&lt;text x="85" y="58" text-anchor="middle" class="lbl">1 · Data&lt;/text>
&lt;rect x="155" y="35" width="110" height="35" class="box idle"/>&lt;text x="210" y="58" text-anchor="middle" class="lbl">2 · Tune&lt;/text>
&lt;rect x="280" y="35" width="110" height="35" class="box idle"/>&lt;text x="335" y="58" text-anchor="middle" class="lbl">3 · Eval&lt;/text>
&lt;rect x="405" y="35" width="110" height="35" class="box active"/>&lt;text x="460" y="58" text-anchor="middle" class="lbl">4 · Deploy&lt;/text>
&lt;rect x="530" y="35" width="110" height="35" class="box idle"/>&lt;text x="585" y="58" text-anchor="middle" class="lbl">5 · Observe&lt;/text>
&lt;rect x="655" y="35" width="110" height="35" class="box idle"/>&lt;text x="710" y="58" text-anchor="middle" class="lbl">6 · Retrain&lt;/text>
&lt;path class="arr" d="M140,52 L155,52"/>&lt;path class="arr" d="M265,52 L280,52"/>&lt;path class="arr" d="M390,52 L405,52"/>&lt;path class="arr" d="M515,52 L530,52"/>&lt;path class="arr" d="M640,52 L655,52"/>
&lt;path class="cyc" d="M710,72 L710,82 L85,82 L85,72"/>
&lt;/svg>
&lt;/div>
&lt;h2 id="the-analogy-the-kitchen-with-two-brigades">The analogy: the kitchen with two brigades&lt;/h2>
&lt;p>A serious industrial kitchen, any kitchen serving more than 50 covers a night, runs with two distinct brigades and two physically separate spaces.&lt;/p>
&lt;p>The &lt;strong>prep brigade&lt;/strong> starts at dawn. Its job is the &lt;em>mise en place&lt;/em>: chopping, marinating, blanching, boiling stocks, preparing complex components. Equipment: good knives, big burners, convection ovens, 40-litre pots. It is capacity-intensive work and it is done in one batch. When it finishes, everything is left in labelled trays ready to use.&lt;/p>
&lt;p>The &lt;strong>service brigade&lt;/strong> comes in mid-afternoon. Its job is service: taking the trays from prep, heating portions, plating, running the pass. Equipment: salamanders, small griddles, thin spatulas, plenty of crockery. It is wrist work, rhythm work, not-failing-the-customer-who-has-the-plate-in-front-of-them work. Capacity per hour matters less than latency per plate.&lt;/p>
&lt;p>If you make &lt;strong>the same person&lt;/strong> do prep and service, both suffer. The cook is idle while doing mise en place in the middle of the afternoon. They have to stop and plate up when five orders land at once. Their working kit is designed for one or the other, not for both.&lt;/p>
&lt;p>Serious kitchens solved this decades ago: separate brigades, separate spaces, separate equipment. The only thing that crosses between them is the trays of mise en place.&lt;/p>
&lt;p>The &lt;strong>trays are the KV cache&lt;/strong>. The separation is &lt;strong>disaggregated serving&lt;/strong>. The handover from prep to service is the &lt;strong>KV cache transfer&lt;/strong>, solved today with NIXL over RDMA. And the specialised pods are the two brigades with their optimal kit.&lt;/p>
&lt;h2 id="quick-recap-prefill-and-decode">Quick recap: prefill and decode&lt;/h2>
&lt;p>A request to an LLM always goes through two phases:&lt;/p>
&lt;p>&lt;strong>Prefill.&lt;/strong> Take the complete prompt (say, 4,000 tokens) and process it in a single pass through all the layers of the model. The result is the KV cache of those 4,000 tokens (see the &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">previous article on KV cache&lt;/a> if you want to recall exactly what it holds). This step is massively parallel: all the tokens go through the attention matrices at once, which translates into huge, dense matrix multiplications. The GPU sits at 90-95 % compute utilisation. &lt;strong>TTFT&lt;/strong> (time to first token) is determined by this phase.&lt;/p>
&lt;p>&lt;strong>Decode.&lt;/strong> Once the KV cache is ready, the model generates tokens one by one. Each new token is a pass through all the layers with a single query vector, reading the whole accumulated KV cache to compute attention. There is no parallelism between tokens (each one depends on the previous). What limits you here is not compute but bandwidth: every step has to read the model&amp;rsquo;s full weights from HBM. The GPU sits at 20-40 % compute utilisation, but at 90 % HBM utilisation. &lt;strong>TBT&lt;/strong> (time between tokens) is determined by this phase.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Phase&lt;/th>
&lt;th>Characteristic&lt;/th>
&lt;th>Bottleneck&lt;/th>
&lt;th>Key metric&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Prefill&lt;/td>
&lt;td>Massive parallel compute over N tokens at once&lt;/td>
&lt;td>TFLOPS (compute)&lt;/td>
&lt;td>TTFT&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Decode&lt;/td>
&lt;td>Streaming weights from HBM, 1 token at a time&lt;/td>
&lt;td>HBM bandwidth&lt;/td>
&lt;td>TBT (inter-token latency)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;div class="diagram" style="max-width: 720px; margin: 1.5rem auto;">
&lt;svg viewBox="0 0 720 290" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Compute vs bandwidth utilisation in prefill and decode">
&lt;style>
.bar { stroke: #333; stroke-width: 1; }
.b-compute { fill: #2a9d8f; }
.b-bandwidth { fill: #e76f51; }
.b-low { fill-opacity: 0.35; }
.ax { stroke: #333; stroke-width: 1.5; }
.grid { stroke: #ddd; stroke-width: 1; stroke-dasharray: 3,3; }
.lbl { font: 600 13px sans-serif; fill: #222; }
.lbl-sm { font: 11px sans-serif; fill: #444; }
.tag { font: 600 12px sans-serif; }
&lt;/style>
&lt;text x="360" y="22" text-anchor="middle" class="lbl">GPU utilisation during each phase (typical order of magnitude)&lt;/text>
&lt;line class="ax" x1="100" y1="240" x2="100" y2="60"/>
&lt;line class="ax" x1="100" y1="240" x2="680" y2="240"/>
&lt;line class="grid" x1="100" y1="78" x2="680" y2="78"/>
&lt;line class="grid" x1="100" y1="114" x2="680" y2="114"/>
&lt;line class="grid" x1="100" y1="150" x2="680" y2="150"/>
&lt;line class="grid" x1="100" y1="186" x2="680" y2="186"/>
&lt;text x="90" y="63" text-anchor="end" class="lbl-sm">100%&lt;/text>
&lt;text x="90" y="117" text-anchor="end" class="lbl-sm">75%&lt;/text>
&lt;text x="90" y="153" text-anchor="end" class="lbl-sm">50%&lt;/text>
&lt;text x="90" y="189" text-anchor="end" class="lbl-sm">25%&lt;/text>
&lt;text x="90" y="243" text-anchor="end" class="lbl-sm">0%&lt;/text>
&lt;text x="240" y="270" text-anchor="middle" class="lbl">PREFILL&lt;/text>
&lt;text x="240" y="284" text-anchor="middle" class="lbl-sm">compute-bound&lt;/text>
&lt;text x="540" y="270" text-anchor="middle" class="lbl">DECODE&lt;/text>
&lt;text x="540" y="284" text-anchor="middle" class="lbl-sm">memory-bound&lt;/text>
&lt;rect x="160" y="69" width="65" height="171" class="bar b-compute"/>
&lt;text x="193" y="62" text-anchor="middle" class="tag" fill="#2a9d8f">95%&lt;/text>
&lt;text x="193" y="255" text-anchor="middle" class="lbl-sm">compute&lt;/text>
&lt;rect x="245" y="132" width="65" height="108" class="bar b-bandwidth b-low"/>
&lt;text x="278" y="125" text-anchor="middle" class="tag" fill="#e76f51">60%&lt;/text>
&lt;text x="278" y="255" text-anchor="middle" class="lbl-sm">HBM&lt;/text>
&lt;rect x="460" y="177" width="65" height="63" class="bar b-compute b-low"/>
&lt;text x="493" y="170" text-anchor="middle" class="tag" fill="#2a9d8f">35%&lt;/text>
&lt;text x="493" y="255" text-anchor="middle" class="lbl-sm">compute&lt;/text>
&lt;rect x="545" y="78" width="65" height="162" class="bar b-bandwidth"/>
&lt;text x="578" y="71" text-anchor="middle" class="tag" fill="#e76f51">90%&lt;/text>
&lt;text x="578" y="255" text-anchor="middle" class="lbl-sm">HBM&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>The asymmetry is structural: prefill burns compute and leaves memory half idle, decode does the opposite. &lt;strong>A GPU designed to be excellent at both at once is a GPU designed to be badly used all the time.&lt;/strong>&lt;/p>
&lt;h2 id="why-putting-them-on-the-same-gpu-is-a-bad-deal">Why putting them on the same GPU is a bad deal&lt;/h2>
&lt;p>Until 2023, the universal assumption was to run prefill and decode &lt;strong>in the same inference process, on the same GPU&lt;/strong>. The engine scheduler (vLLM, TGI, Triton) decided on each cycle whether to prefill a new request or decode the ones already in flight. The intuition was that sharing hardware saves money.&lt;/p>
&lt;p>The intuition is wrong. The problem has three faces:&lt;/p>
&lt;p>&lt;strong>Latency interference.&lt;/strong> When the engine decides to prefill a new request, it &lt;strong>interrupts&lt;/strong> every decode in progress. That pushes up the TBT of the other requests. The user who was watching tokens flow smoothly down the screen notices a stall of several hundred milliseconds. This is known as &lt;em>prefill-decode interference&lt;/em> and it degrades the experience visibly as concurrency rises.&lt;/p>
&lt;p>&lt;strong>Sub-optimal hardware for each phase.&lt;/strong> An H100 SXM has 989 TFLOPS BF16 of compute and 3.35 TB/s of HBM3. It is excellent for prefill, where compute is the limit. For decode, where the only thing that matters is bandwidth, those 989 TFLOPS are 60-70 % wasted. Conversely, a GPU with less compute but similar relative bandwidth (RTX 4090, L40S) would handle decode just as well for a fraction of the price.&lt;/p>
&lt;p>&lt;strong>Low aggregate utilisation.&lt;/strong> In real workloads with Llama 3 70B and 512-token outputs, &lt;strong>around 80 % of the wall-clock is spent in decode&lt;/strong>. That means 80 % of your H100 cluster budget is doing memory reads, not calculations. It is like paying for a Ferrari to use it in a car park queue.&lt;/p>
&lt;h2 id="the-idea-specialised-pods-kv-cache-as-the-deliverable">The idea: specialised pods, KV cache as the deliverable&lt;/h2>
&lt;p>Disaggregated serving breaks the inference cycle into two distinct services:&lt;/p>
&lt;p>&lt;strong>Prefill pod.&lt;/strong> Receives the prompt, runs the prefill, produces the KV cache. Hardware: high-compute GPUs (H100, H200, B200). Optimised for aggressive batching and throughput, not for individual latency: if 32 prompts arrive within 100 ms, it processes them together.&lt;/p>
&lt;p>&lt;strong>Decode pod.&lt;/strong> Receives the already-built KV cache, runs the token-by-token generation, streams to the client. Hardware: GPUs with good bandwidth but ideally cheaper per TFLOPS (RTX 4090, L40S, A100, even A30 depending on the case). Optimised for per-token latency (low TBT).&lt;/p>
&lt;p>Between the two: a &lt;strong>KV cache transfer&lt;/strong> over the network, which can be node-local (shared memory, NVLink), intra-rack (RDMA with InfiniBand or RoCE) or cross-rack (NIXL over UCX). The cost of this transfer scales linearly with context length, and it is the economic crux of the scheme.&lt;/p>
&lt;div class="diagram" style="max-width: 720px; margin: 1.5rem auto;">
&lt;svg viewBox="0 0 720 340" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Monolithic vs disaggregated architecture">
&lt;style>
.node { stroke: #333; stroke-width: 1.5; }
.n-mono { fill: #ffe9d6; }
.n-prefill { fill: #d9f5d6; }
.n-decode { fill: #d6eaff; }
.n-router { fill: #fffae6; }
.lbl { font: 600 13px sans-serif; fill: #222; }
.lbl-sm { font: 11px sans-serif; fill: #444; }
.lbl-section { font: 700 14px sans-serif; fill: #222; }
.arr { stroke: #444; stroke-width: 1.6; fill: none; marker-end: url(#ah4); }
.arr-int { stroke: #c1121f; stroke-width: 1.4; fill: none; stroke-dasharray: 5,3; marker-end: url(#ah4r); }
&lt;/style>
&lt;defs>
&lt;marker id="ah4" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#444"/>&lt;/marker>
&lt;marker id="ah4r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="5" markerHeight="5" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#c1121f"/>&lt;/marker>
&lt;/defs>
&lt;text x="170" y="25" text-anchor="middle" class="lbl-section">Monolithic (aggregated)&lt;/text>
&lt;rect x="40" y="50" width="260" height="220" rx="10" class="node n-mono"/>
&lt;text x="170" y="78" text-anchor="middle" class="lbl">Single GPU&lt;/text>
&lt;text x="170" y="98" text-anchor="middle" class="lbl-sm">scheduler decides each cycle:&lt;/text>
&lt;rect x="65" y="115" width="100" height="40" rx="5" class="node n-prefill"/>
&lt;text x="115" y="140" text-anchor="middle" class="lbl-sm">prefill&lt;/text>
&lt;rect x="180" y="115" width="100" height="40" rx="5" class="node n-decode"/>
&lt;text x="230" y="140" text-anchor="middle" class="lbl-sm">decode&lt;/text>
&lt;path class="arr-int" d="M165,128 L180,128"/>
&lt;path class="arr-int" d="M180,145 L165,145"/>
&lt;text x="170" y="180" text-anchor="middle" class="lbl-sm" fill="#c1121f">interference on every switch&lt;/text>
&lt;text x="170" y="200" text-anchor="middle" class="lbl-sm">→ TBT rises when prefill arrives&lt;/text>
&lt;text x="170" y="230" text-anchor="middle" class="lbl-sm">one HW optimal for both:&lt;/text>
&lt;text x="170" y="250" text-anchor="middle" class="lbl-sm">impossible&lt;/text>
&lt;text x="540" y="25" text-anchor="middle" class="lbl-section">Disaggregated&lt;/text>
&lt;rect x="370" y="50" width="150" height="100" rx="10" class="node n-prefill"/>
&lt;text x="445" y="80" text-anchor="middle" class="lbl">prefill pod&lt;/text>
&lt;text x="445" y="102" text-anchor="middle" class="lbl-sm">H100 / H200 / B200&lt;/text>
&lt;text x="445" y="120" text-anchor="middle" class="lbl-sm">high compute, aggressive&lt;/text>
&lt;text x="445" y="138" text-anchor="middle" class="lbl-sm">batching&lt;/text>
&lt;rect x="560" y="50" width="150" height="100" rx="10" class="node n-decode"/>
&lt;text x="635" y="80" text-anchor="middle" class="lbl">decode pod&lt;/text>
&lt;text x="635" y="102" text-anchor="middle" class="lbl-sm">4090 / L40S / A100&lt;/text>
&lt;text x="635" y="120" text-anchor="middle" class="lbl-sm">high bandwidth, stable&lt;/text>
&lt;text x="635" y="138" text-anchor="middle" class="lbl-sm">TBT&lt;/text>
&lt;path class="arr" d="M520,100 L560,100"/>
&lt;text x="540" y="92" text-anchor="middle" class="lbl-sm">KV cache&lt;/text>
&lt;text x="540" y="115" text-anchor="middle" class="lbl-sm">NIXL/RDMA&lt;/text>
&lt;rect x="450" y="180" width="180" height="50" rx="8" class="node n-router"/>
&lt;text x="540" y="200" text-anchor="middle" class="lbl">router (vLLM/Dynamo)&lt;/text>
&lt;text x="540" y="218" text-anchor="middle" class="lbl-sm">routes prompts and streams&lt;/text>
&lt;path class="arr" d="M445,150 L500,180"/>
&lt;path class="arr" d="M635,150 L580,180"/>
&lt;text x="540" y="260" text-anchor="middle" class="lbl-sm" fill="#2a9d8f">→ stable TBT, low TTFT&lt;/text>
&lt;text x="540" y="280" text-anchor="middle" class="lbl-sm">cost: KV cache transfer&lt;/text>
&lt;text x="540" y="298" text-anchor="middle" class="lbl-sm">~5-50 ms depending on interconnect&lt;/text>
&lt;/svg>
&lt;/div>
&lt;h2 id="the-transfer-protocol-the-economics-of-movement">The transfer protocol: the economics of movement&lt;/h2>
&lt;p>The KV cache transferred for a Llama 3 70B with 4K of context weighs roughly &lt;strong>2.6 GB&lt;/strong> (80 layers × 8 KV heads × 128 dim × 4,096 tokens × 2 (K and V) × 2 bytes in BF16). Moving 2.6 GB between two GPUs is not trivial:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Channel&lt;/th>
&lt;th style="text-align:right">Effective bandwidth&lt;/th>
&lt;th style="text-align:right">Time for 2.6 GB&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Intra-node NVLink (NVSwitch)&lt;/td>
&lt;td style="text-align:right">~450 GB/s&lt;/td>
&lt;td style="text-align:right">~6 ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Shared memory (same node, PCIe 5)&lt;/td>
&lt;td style="text-align:right">~60 GB/s&lt;/td>
&lt;td style="text-align:right">~45 ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>RDMA InfiniBand 400 Gbps&lt;/td>
&lt;td style="text-align:right">~50 GB/s&lt;/td>
&lt;td style="text-align:right">~55 ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>RDMA RoCE 200 Gbps&lt;/td>
&lt;td style="text-align:right">~25 GB/s&lt;/td>
&lt;td style="text-align:right">~105 ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TCP/IP 10 GbE&lt;/td>
&lt;td style="text-align:right">~1 GB/s&lt;/td>
&lt;td style="text-align:right">~2.6 s&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The immediate reading: above InfiniBand grade, the transfer is comfortable. Below it, it ruins the very TTFT we are trying to improve. &lt;strong>Disaggregated serving is only viable with a decent interconnect.&lt;/strong> It is not a pattern for clusters built out of consumer Ethernet switches.&lt;/p>
&lt;p>NVIDIA answered this with &lt;strong>NIXL&lt;/strong> (NVIDIA Inference Transfer Library), released in mid-2025: a library that abstracts the transport (UCX, NCCL, direct RDMA verbs, shared memory) and picks the best available path automatically. vLLM has integrated it since late 2025 through the &lt;code>NixlConnector&lt;/code>. It is now the de facto default for new deployments.&lt;/p>
&lt;h2 id="real-implementations-in-may-2026">Real implementations in May 2026&lt;/h2>
&lt;p>The pattern&amp;rsquo;s path over two years:&lt;/p>
&lt;pre tabindex="0">&lt;code>2024 Jan · DistServe (HKU + UCSD): 7.4× requests at the same SLO
2024 May · SplitWise (Microsoft): variant with heterogeneous hardware
2024 Dec · experimental vLLM disagg (SharedStorage + PyNcclConnector)
2025 Mar · NIXL release (NVIDIA): unified transfer library
2025 Jul · stable vLLM NixlConnector
2025 Nov · SGLang, llm-d, MoonCake adopt the pattern
2026 Mar · NVIDIA Dynamo 1.0 GA (GTC 2026): production-ready at datacenter scale
&lt;/code>&lt;/pre>&lt;p>As of today, &lt;strong>the pattern is the default&lt;/strong> in any serious serving framework. The ones still monolithic are the small ones or the educational ones.&lt;/p>
&lt;p>Three realistic options for an on-premise infrastructure:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>vLLM disagg with NixlConnector.&lt;/strong> The most open route, requiring two sets of vLLM pods to be deployed (one with &lt;code>--kv-transfer-config '{&amp;quot;kv_role&amp;quot;:&amp;quot;producer&amp;quot;}'&lt;/code>, another with &lt;code>&amp;quot;kv_role&amp;quot;:&amp;quot;consumer&amp;quot;&lt;/code>) plus a proxy router. Enough for clusters of 4-16 GPUs.&lt;/li>
&lt;li>&lt;strong>SGLang with disagg.&lt;/strong> Conceptually equivalent, better performance on some MoE workloads.&lt;/li>
&lt;li>&lt;strong>NVIDIA Dynamo 1.0.&lt;/strong> The one taking over at datacenter scale. It covers routing, KV cache management, monitoring and scheduling in a single control plane. Heavier, but the reference solution if your cluster grows beyond 32 GPUs.&lt;/li>
&lt;/ol>
&lt;h2 id="the-numbers-that-matter">The numbers that matter&lt;/h2>
&lt;p>What disaggregation unlocks, in direct terms:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Metric&lt;/th>
&lt;th>Aggregated (monolithic)&lt;/th>
&lt;th>Disaggregated&lt;/th>
&lt;th>Improvement&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Goodput (req/s at the SLO)&lt;/td>
&lt;td>baseline&lt;/td>
&lt;td>1.4 – 2×&lt;/td>
&lt;td>up to 2×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TTFT under high load&lt;/td>
&lt;td>rises sharply from QPS 4&lt;/td>
&lt;td>stable up to QPS 7+&lt;/td>
&lt;td>~2×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Request rate at the same SLO (DistServe paper)&lt;/td>
&lt;td>baseline&lt;/td>
&lt;td>7.4×&lt;/td>
&lt;td>7.4×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>MoE throughput on Blackwell (Dynamo, GB300 NVL72)&lt;/td>
&lt;td>baseline (Hopper)&lt;/td>
&lt;td>up to 50×&lt;/td>
&lt;td>depends on the model&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Cost per token (heterogeneous H100 + commodity)&lt;/td>
&lt;td>baseline (all H100)&lt;/td>
&lt;td>-48 %&lt;/td>
&lt;td>almost half&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>These numbers have to be read carefully: the most spectacular ones (7× and 50×) need specific hardware (Blackwell GB200/GB300 NVL72) and specific models (large MoE). The &lt;strong>realistic range for a typical on-premise setup is 1.4-2× in goodput and -30 to -50 % in cost per token&lt;/strong>, depending on how heterogeneous the GPU mix is and how optimised the KV cache transfer is.&lt;/p>
&lt;h2 id="heterogeneity-the-radical-version">Heterogeneity: the radical version&lt;/h2>
&lt;p>The logical next step, proposed by SplitWise in 2024 and matured in 2025-2026 (Cronus, Tessera and others), is to &lt;strong>mix GPU types&lt;/strong>: expensive high-compute GPUs for prefill, commodity GPUs with good bandwidth for decode.&lt;/p>
&lt;p>Indicative cost (typical market prices in mid-2026):&lt;/p>
&lt;ul>
&lt;li>&lt;strong>H100 SXM&lt;/strong>: ~30-40 kUSD capex, ~3-4 USD/h amortised. Compute-heavy profile.&lt;/li>
&lt;li>&lt;strong>L40S&lt;/strong>: ~8-10 kUSD capex, ~1.5 USD/h. Intermediate profile, 864 GB/s of bandwidth.&lt;/li>
&lt;li>&lt;strong>RTX 4090&lt;/strong>: ~1.5 kUSD capex, ~0.30 USD/h. Modest compute profile but 1 TB/s of GDDR6X bandwidth, enough for decode of models up to ~30B parameters.&lt;/li>
&lt;/ul>
&lt;p>A realistic mixed cluster for serving an 8B model:&lt;/p>
&lt;pre tabindex="0">&lt;code>2× RTX 4090 (prefill batch) → ~3,000 USD capex, ~0.60 USD/h
4× RTX 4090 (decode pool) → ~6,000 USD capex, ~1.20 USD/h
TOTAL → ~9,000 USD capex, ~1.80 USD/h
&lt;/code>&lt;/pre>&lt;p>Against the monolithic alternative with equivalent throughput:&lt;/p>
&lt;pre tabindex="0">&lt;code>2× H100 SXM (all in one) → ~70,000 USD capex, ~7 USD/h
&lt;/code>&lt;/pre>&lt;p>The same throughput at a fraction of the capex and a quarter of the hourly cost, &lt;strong>at the price of operational complexity&lt;/strong>: you now have two pools to coordinate, a transfer network to look after, and a scheduler that is not trivial.&lt;/p>
&lt;p>For larger models (Llama 3 70B), the decode pool no longer fits on a single 4090 (the model does not fit in 24 GB, not even quantised to INT4 with headroom). There the sensible mix is H100 for prefill plus L40S or A100 80GB for decode, with a typical saving of 30-40 % over the all-H100 option.&lt;/p>
&lt;h2 id="applied-to-typical-on-premise-hardware">Applied to typical on-premise hardware&lt;/h2>
&lt;h3 id="case-1--one-or-two-rtx-4090s-monolithic-still-wins">Case 1 — One or two RTX 4090s: monolithic still wins&lt;/h3>
&lt;p>With a single GPU there is no disaggregation to speak of: the pattern needs at least two GPUs in separate pods. With two 4090s you can technically try it (one for prefill, one for decode with the KV cache transferred over PCIe 5 or basic RDMA), but the transfer overhead eats the gain for small models where prefill is already fast.&lt;/p>
&lt;p>&lt;strong>Recommendation:&lt;/strong> stay monolithic (traditional vLLM, &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">properly configured with a quantised KV cache&lt;/a>). The next justifiable level of complexity is a cluster with a fast interconnect.&lt;/p>
&lt;h3 id="case-2--4h100-sxm-cluster-320-gb-nvlink-the-sweet-spot">Case 2 — 4×H100 SXM cluster (320 GB, NVLink): the sweet spot&lt;/h3>
&lt;p>The minimum realistic configuration for serious disaggregation, serving a 70B model in production:&lt;/p>
&lt;pre tabindex="0">&lt;code>2× H100 (TP=2) → 2 prefill pods
2× H100 (TP=2) → decode pods with several instances sharing TP
NIXL over NVLink → KV cache transfer &amp;lt;6 ms
Router (vLLM or Dynamo) → prompt distribution and streaming
&lt;/code>&lt;/pre>&lt;p>Realistic expected result: goodput &lt;strong>1.6-1.9× relative to the same cluster running monolithic&lt;/strong>, with TTFT stable up to loads of QPS 7-8 (against the QPS 4 at which the monolithic setup starts to degrade).&lt;/p>
&lt;p>If the heterogeneous mix is possible (adding 4-8 L40S to the cluster to make the decode pool), the cost per token drops a further 25 % to 35 %, while still serving the 70B model whole.&lt;/p>
&lt;h2 id="position-within-the-architecture">Position within the architecture&lt;/h2>
&lt;p>Disaggregated serving is a &lt;strong>cross-cutting layer&lt;/strong> over almost everything discussed in previous articles. It touches:&lt;/p>
&lt;ul>
&lt;li>The &lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache&lt;/a> because it is the artefact transferred between pods. Without a solid grasp of how much the cache weighs and how it grows with context, you cannot size the transfer.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/continuous-fine-tuning-production-real-traffic-deployed-adapter/">Continuous fine-tuning&lt;/a> because multi-LoRA hot-swap keeps its semantics: each pod (prefill or decode) loads the adapters separately, and the router decides which adapter to apply in each phase.&lt;/li>
&lt;li>Cluster topology: it changes the recommended HW, the networking required and the cost model.&lt;/li>
&lt;/ul>
&lt;p>If you are designing an inference infrastructure for 2026 from scratch, &lt;strong>disaggregation stops being optional&lt;/strong> for any cluster beyond 4 GPUs of capacity. If you are modernising an existing one, it is the upgrade with the best return per euro invested, provided the networking between pods is decent (intra-node NVLink or intra-rack RDMA as a minimum).&lt;/p>
&lt;h2 id="what-we-have-not-covered-upcoming-articles">What we have not covered (upcoming articles)&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>NIXL in detail&lt;/strong>: how it picks the optimal transport, how UCX is configured, what happens when RDMA fails and you have to fall back to TCP.&lt;/li>
&lt;li>&lt;strong>Routing scheduler&lt;/strong>: how the orchestrator decides which pod gets which request, dynamic batching, priority handling.&lt;/li>
&lt;li>&lt;strong>Multi-tenant disagg&lt;/strong>: KV cache isolation between tenants, per-adapter ACLs, multi-LoRA over specialised pods.&lt;/li>
&lt;li>&lt;strong>Disagg + prefix caching&lt;/strong>: how it combines with the KV cache reuse pattern when several prompts share a prefix (a common system prompt).&lt;/li>
&lt;li>&lt;strong>Disagg at the edge / local inference&lt;/strong>: viability on home hardware (4090 + Mac Studio, for example), where the transfer depends on Thunderbolt or residential Ethernet.&lt;/li>
&lt;/ul>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/six-stage-llmops-pipeline-architecture-and-deep-dive/">The six-stage LLMOps pipeline&lt;/a> — the master map the Deploy stage belongs to. This post digs into one concrete architectural decision within that stage.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/gpu-cluster-as-multi-tenant-platform/">The GPU cluster as a multi-tenant platform&lt;/a> — the Gateway/Quota/Isolation/Observability layered pattern on top of which the disaggregation described here sits: the H100 cluster serving several tenants combines both patterns.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/llm-inference-operators-kubernetes/">LLM inference operators on Kubernetes&lt;/a> — the operators (vLLM Production Stack, NVIDIA Dynamo, llm-d, OME) that materialise the specialised prefill and decode pods in Kubernetes.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/">KV cache: the working memory that holds up LLM inference&lt;/a> — the exact artefact transferred between pods, with the full formula for its size.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/pagedattention-vllm-block-manager/">PagedAttention from the inside: blocks, page table, eviction and the state of the art of KV cache in 2026&lt;/a> — the KV cache mechanics that disaggregation exploits at block level, and the landscape of derived optimisations (vAttention, LMCache, RadixAttention).&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/continuous-fine-tuning-production-real-traffic-deployed-adapter/">Continuous fine-tuning in production&lt;/a> — how multi-LoRA hot-swap coexists with disaggregation: each pod loads adapters separately, the router chooses.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/quantization-llm-inference-fp8-int4-gguf/">Quantization for LLM inference: FP8, INT4 and GGUF&lt;/a> — the two pools (prefill and decode) can be quantised asymmetrically: prefill keeps more precision, decode prioritises throughput. The maths and the formats are there.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/speculative-decoding-fundamentals-maths-state-of-play/">Speculative decoding: the secretary who anticipates what the boss is going to say&lt;/a> — speculative only helps in the decode phase (it does not touch prefill); disaggregation makes it easier by isolating the decode pool where the technique can be applied without contaminating the prefill one.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/flashattention-librarian-io-awareness-async-blackwell-asymmetry/">FlashAttention v1/v2/v3/v4: the librarian who never clears the desk&lt;/a> — the kernel each pod uses underneath. Prefill (compute-bound) and decode (memory-bound) benefit from FA3/FA4 in different ways and allow a backend to be chosen per phase.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/moe-inference-fundamentals-expert-parallel-deepseek-economics/">MoE inference: the call centre with 256 specialists&lt;/a> — the real DeepSeek-V3 deployment combines &lt;strong>EP=32 in prefill (4 nodes) with EP=144 in decode (18 nodes)&lt;/strong>: disaggregation is the prerequisite that allows expert parallelism to be specialised per phase.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/multi-lora-serving-shared-base-concurrent-adapters-sgmv-kernel/">Multi-LoRA serving: the single translator with a thousand glossaries&lt;/a> — once pods are separated, adapters are managed per pool; the 2026 strategy is to replicate hot ones on every pod (prefill and decode) and evict cold ones.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/continuous-batching-orca-vllm-chunked-prefill-goodput/">Continuous batching&lt;/a> — the layer underneath. DistServe is the paper that contributed the goodput metric and the idea of disaggregating prefill/decode; understanding the iterative scheduler is a prerequisite to understanding why the separation unlocked additional gains.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/capacity-planning-on-premise-llm-inference/">Capacity planning for on-premise LLM inference&lt;/a> — disaggregation appears as the third sizing lever when the workload&amp;rsquo;s prefill/decode mix is asymmetric; when to apply it and how much it saves are quantified there.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/nvlink-nvswitch-nccl-cable-every-token-crosses/">NVLink, NVSwitch and NCCL: the cable every token travels down&lt;/a> — moving the KV cache between the prefill pool and the decode pool travels over the same interconnect as the all-reduces and competes with them; designing the disaggregation without counting that transfer cost is the classic trap.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/network-numa-cilium-ebpf-dranet-fourth-leg-pinning/">The kitchen door the maître never looked at: network NUMA, Cilium eBPF and DRANET&lt;/a> — when that KV cache crosses by RDMA across nodes, a badly placed NIC pays for it in latency; the fourth leg (NIC↔GPU locality via DRANET) is what keeps separating prefill and decode from being expensive in transfer.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/pantry-lift-from-disk-to-hbm-why-the-kitchen-opens-late/">From disk to HBM: cold start and model loading&lt;/a> — bringing up decode pools on demand pays the cold start of loading the model into every new pod; the elasticity of the pattern depends on how fast they start.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/sms-cuda-streams-cuda-graphs-inference/">SM, CUDA streams and CUDA graphs&lt;/a> — pure decode pods are the ideal case for &lt;code>FULL_DECODE_ONLY&lt;/code>: they maximise the benefit of the CUDA graph in the most launch-bound phase.&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>Zhong et al., &lt;em>DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving&lt;/em> (OSDI 2024).&lt;/li>
&lt;li>Patel et al., &lt;em>SplitWise: Efficient Generative LLM Inference Using Phase Splitting&lt;/em> (ISCA 2024).&lt;/li>
&lt;li>NVIDIA, &lt;em>NVIDIA Dynamo 1.0: Production-Ready Disaggregated Inference&lt;/em> (GTC 2026, March): &lt;a href="https://developer.nvidia.com/blog/nvidia-dynamo-1-production-ready/">https://developer.nvidia.com/blog/nvidia-dynamo-1-production-ready/&lt;/a>.&lt;/li>
&lt;li>NVIDIA, &lt;em>NIXL: NVIDIA Inference Transfer Library&lt;/em> — official documentation.&lt;/li>
&lt;li>vLLM, &lt;em>Disaggregated Prefilling&lt;/em>: &lt;a href="https://docs.vllm.ai/en/stable/features/disagg_prefill/">https://docs.vllm.ai/en/stable/features/disagg_prefill/&lt;/a>.&lt;/li>
&lt;li>vLLM, &lt;em>NixlConnector Usage Guide&lt;/em>: &lt;a href="https://docs.vllm.ai/en/stable/features/nixl_connector_usage/">https://docs.vllm.ai/en/stable/features/nixl_connector_usage/&lt;/a>.&lt;/li>
&lt;li>Hao AI Lab, &lt;em>Disaggregated Inference: 18 Months Later&lt;/em> (UCSD, 2025) — technical retrospective on the DistServe paper.&lt;/li>
&lt;/ul></description></item><item><title>KV cache: the working memory that holds up LLM inference</title><link>https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/</link><pubDate>Mon, 18 May 2026 10:00:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/kv-cache-working-memory-llm-inference/</guid><description>&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>The KV cache is the &lt;strong>working memory&lt;/strong> a language model keeps during a conversation. Without it, every new token would force a recomputation of the whole conversation from the start, at a cost that is &lt;strong>quadratic&lt;/strong> in the length of the text. With it, the cost is linear, but in exchange the cache &lt;strong>lives in VRAM and grows with every token&lt;/strong>. In practice, it is not the model that limits how much context you can serve: it is the KV cache. On an RTX 4090 running Llama 3 8B, the model fits in 16 GB and barely leaves room for ~64 K tokens of cache in total, adding up all the simultaneous sessions. Understanding that number is the difference between promising a client &amp;ldquo;128 K of context&amp;rdquo; and actually delivering it.&lt;/p>
&lt;h2 id="you-are-here-deploy">You are here: Deploy&lt;/h2>
&lt;p>This post opens the series on LLM inference fundamentals. Within the &lt;a href="https://blog.lo0.es/en/posts/six-stage-llmops-pipeline-architecture-and-deep-dive/">six-stage LLMOps pipeline&lt;/a> that articulates the whole system, the KV cache lives in the &lt;strong>Deploy&lt;/strong> stage: it is the piece that dictates how much traffic fits in your inference engine and, therefore, how much platform you can offer on top of it.&lt;/p>
&lt;div class="diagram" style="max-width:780px;margin:1rem auto;">
&lt;svg viewBox="0 0 780 90" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="you are here: Deploy">
&lt;style>.box{stroke:#444;stroke-width:1.4;rx:6}.active{fill:#ff8a4c;stroke-width:3}.idle{fill:#f4f4f4}.lbl{font:600 12px sans-serif;fill:#222}.arr{stroke:#666;stroke-width:1.4;fill:none;marker-end:url(#kvm)}.cyc{stroke:#888;stroke-width:1.2;fill:none;stroke-dasharray:4 2;marker-end:url(#kvm)}&lt;/style>
&lt;defs>&lt;marker id="kvm" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#666"/>&lt;/marker>&lt;/defs>
&lt;text x="390" y="20" text-anchor="middle" class="lbl">You are here: DEPLOY · KV cache as the VRAM bottleneck&lt;/text>
&lt;rect x="30" y="35" width="110" height="35" class="box idle"/>&lt;text x="85" y="58" text-anchor="middle" class="lbl">1 · Data&lt;/text>
&lt;rect x="155" y="35" width="110" height="35" class="box idle"/>&lt;text x="210" y="58" text-anchor="middle" class="lbl">2 · Tune&lt;/text>
&lt;rect x="280" y="35" width="110" height="35" class="box idle"/>&lt;text x="335" y="58" text-anchor="middle" class="lbl">3 · Eval&lt;/text>
&lt;rect x="405" y="35" width="110" height="35" class="box active"/>&lt;text x="460" y="58" text-anchor="middle" class="lbl">4 · Deploy&lt;/text>
&lt;rect x="530" y="35" width="110" height="35" class="box idle"/>&lt;text x="585" y="58" text-anchor="middle" class="lbl">5 · Observe&lt;/text>
&lt;rect x="655" y="35" width="110" height="35" class="box idle"/>&lt;text x="710" y="58" text-anchor="middle" class="lbl">6 · Retrain&lt;/text>
&lt;path class="arr" d="M140,52 L155,52"/>&lt;path class="arr" d="M265,52 L280,52"/>&lt;path class="arr" d="M390,52 L405,52"/>&lt;path class="arr" d="M515,52 L530,52"/>&lt;path class="arr" d="M640,52 L655,52"/>
&lt;path class="cyc" d="M710,72 L710,82 L85,82 L85,72"/>
&lt;/svg>
&lt;/div>
&lt;h2 id="the-analogy-the-speaker-with-amnesia">The analogy: the speaker with amnesia&lt;/h2>
&lt;p>Imagine you are at a two-hour technical conference. Every time the speaker is about to say a new sentence, he &lt;strong>mentally rewinds the whole talk from the beginning&lt;/strong>, reassembles the thread, and only then carries on. His next sentence requires recalling the previous one; the one after that, the two before it; an hour in, every new word costs him an hour of recap. A conference like that would be materially impossible.&lt;/p>
&lt;p>Now imagine the same speaker with a notebook in which he jots down, as he goes, the two or three key ideas of each sentence: subject, object, link to what came before. Before each new sentence he glances at the notebook and continues. His next word only costs a glance at the notebook, not a rewind of the entire talk.&lt;/p>
&lt;p>That notebook, in a transformer, is called the &lt;strong>KV cache&lt;/strong>. Without it, conversational language models would be unworkable. With it, they are commercial products. But the notebook &lt;strong>weighs something&lt;/strong>, and understanding how much, where and why is what separates an inference infrastructure that works from one that falls over at the third concurrent client.&lt;/p>
&lt;h2 id="the-mechanism-itself-in-plain-terms">The mechanism itself (in plain terms)&lt;/h2>
&lt;p>A transformer generates text &lt;strong>one token at a time&lt;/strong>. To decide the next token, the model applies a mechanism called &lt;strong>attention&lt;/strong> over all previous tokens: it asks &amp;ldquo;which parts of the earlier context are relevant for predicting what comes next?&amp;rdquo;.&lt;/p>
&lt;p>Internally, each input token is projected into three vectors:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Q&lt;/strong> (Query): &amp;ldquo;what I am looking for&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>K&lt;/strong> (Key): &amp;ldquo;what this token offers&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>V&lt;/strong> (Value): &amp;ldquo;what information this token carries&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>The attention of the current token against the context is computed by multiplying its &lt;strong>Q&lt;/strong> against the &lt;strong>K&lt;/strong> of all previous tokens, normalising with softmax, and weighting the corresponding &lt;strong>V&lt;/strong>. The result is a contextualised representation of the current token.&lt;/p>
&lt;div class="diagram" style="max-width: 720px; margin: 1.5rem auto;">
&lt;svg viewBox="0 0 720 260" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Diagram of the attention computation with Q, K, V">
&lt;style>
.box { fill: #f4f4f4; stroke: #333; stroke-width: 1.5; }
.box-q { fill: #ffe9d6; }
.box-k { fill: #d6eaff; }
.box-v { fill: #d9f5d6; }
.lbl { font: 600 13px sans-serif; fill: #222; }
.lbl-sm { font: 11px sans-serif; fill: #444; }
.arr { stroke: #444; stroke-width: 1.4; fill: none; marker-end: url(#ah); }
&lt;/style>
&lt;defs>
&lt;marker id="ah" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">
&lt;path d="M0,0 L10,5 L0,10 z" fill="#444"/>
&lt;/marker>
&lt;/defs>
&lt;text x="360" y="22" text-anchor="middle" class="lbl">Attention computation for token N&lt;/text>
&lt;rect x="40" y="60" width="120" height="40" rx="6" class="box box-q"/>
&lt;text x="100" y="85" text-anchor="middle" class="lbl">Q (token N)&lt;/text>
&lt;text x="100" y="115" text-anchor="middle" class="lbl-sm">"what I seek"&lt;/text>
&lt;rect x="280" y="60" width="160" height="40" rx="6" class="box box-k"/>
&lt;text x="360" y="85" text-anchor="middle" class="lbl">K (tokens 1..N)&lt;/text>
&lt;text x="360" y="115" text-anchor="middle" class="lbl-sm">from the cache&lt;/text>
&lt;rect x="560" y="60" width="120" height="40" rx="6" class="box box-v"/>
&lt;text x="620" y="85" text-anchor="middle" class="lbl">V (tokens 1..N)&lt;/text>
&lt;text x="620" y="115" text-anchor="middle" class="lbl-sm">from the cache&lt;/text>
&lt;path class="arr" d="M160,80 L280,80"/>
&lt;path class="arr" d="M440,80 L560,80"/>
&lt;p>&lt;text x="220" y="74" text-anchor="middle" class="lbl-sm">Q·Kᵀ → softmax&lt;/text>
&lt;text x="500" y="74" text-anchor="middle" class="lbl-sm">× V&lt;/text>&lt;/p>
&lt;rect x="240" y="170" width="240" height="44" rx="6" class="box"/>
&lt;text x="360" y="197" text-anchor="middle" class="lbl">representation of token N&lt;/text>
&lt;path class="arr" d="M620,100 C620,150 480,150 480,170"/>
&lt;path class="arr" d="M100,100 C100,150 240,150 240,170"/>
&lt;/svg>
&lt;/div>
&lt;p>Here is the key point: to predict token N, I only need the &lt;strong>new Q&lt;/strong> (that of token N) and the &lt;strong>K, V of all previous tokens&lt;/strong>. The K and V of tokens 1..N-1 have not changed since the previous iteration. Recomputing them would be throwing work away.&lt;/p>
&lt;p>&lt;strong>The KV cache is exactly that: the memory that holds the K and V of every token already processed, in every layer of the model, so they never have to be recomputed.&lt;/strong>&lt;/p>
&lt;h2 id="why-it-exists-the-quadratic-cost-without-it">Why it exists: the quadratic cost without it&lt;/h2>
&lt;p>Generating a text of N tokens involves N steps. At step &lt;code>i&lt;/code>, attention is computed over &lt;code>i&lt;/code> previous tokens. Without a cache, at every step you recompute the K, V of the &lt;code>i-1&lt;/code> previous tokens &lt;strong>plus&lt;/strong> those of the new one. The total count of attention computations grows as:&lt;/p>
$$\sum_{i=1}^{N} i = \frac{N(N+1)}{2} \approx \frac{N^2}{2}$$
&lt;p>With a KV cache, you only process the new token at each step: cost &lt;strong>linear in N&lt;/strong>.&lt;/p>
&lt;div class="diagram" style="max-width: 720px; margin: 1.5rem auto;">
&lt;svg viewBox="0 0 720 320" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Comparison of linear vs quadratic cost">
&lt;style>
.kv-ax { stroke: currentColor; stroke-width: 1.5; opacity: 0.4; fill: none; }
.kv-grid { stroke: currentColor; stroke-width: 1; stroke-dasharray: 4,4; opacity: 0.15; fill: none; }
.kv-lin { stroke: #2a9d8f; stroke-width: 3; fill: none; }
.kv-quad { stroke: #e76f51; stroke-width: 3; fill: none; }
.kv-lbl { font: 600 13px sans-serif; fill: currentColor; }
.kv-sm { font: 11px sans-serif; fill: currentColor; opacity: 0.6; }
.kv-note { font: italic 10px sans-serif; fill: currentColor; opacity: 0.45; }
.kv-tlin { fill: #2a9d8f; font: 700 12px sans-serif; }
.kv-tqud { fill: #e76f51; font: 700 12px sans-serif; }
&lt;/style>
&lt;!-- Title -->
&lt;p>&lt;text x="380" y="22" text-anchor="middle" class="kv-lbl">Cumulative compute to generate N tokens&lt;/text>
&lt;text x="380" y="38" text-anchor="middle" class="kv-note">(schematic scale — exact data is in the table)&lt;/text>&lt;/p>
&lt;!-- Axes -->
&lt;line class="kv-ax" x1="80" y1="260" x2="680" y2="260"/>
&lt;line class="kv-ax" x1="80" y1="55" x2="80" y2="260"/>
&lt;!-- Axis labels -->
&lt;p>&lt;text x="380" y="295" text-anchor="middle" class="kv-sm">tokens generated (N)&lt;/text>
&lt;text x="25" y="158" text-anchor="middle" class="kv-sm" transform="rotate(-90 25 158)">attention operations&lt;/text>&lt;/p>
&lt;!-- X ticks -->
&lt;p>&lt;text x="80" y="277" text-anchor="middle" class="kv-sm">0&lt;/text>
&lt;text x="230" y="277" text-anchor="middle" class="kv-sm">1K&lt;/text>
&lt;text x="380" y="277" text-anchor="middle" class="kv-sm">2K&lt;/text>
&lt;text x="530" y="277" text-anchor="middle" class="kv-sm">3K&lt;/text>
&lt;text x="680" y="277" text-anchor="middle" class="kv-sm">4K&lt;/text>&lt;/p>
&lt;!-- Grid -->
&lt;line class="kv-grid" x1="80" y1="210" x2="680" y2="210"/>
&lt;line class="kv-grid" x1="80" y1="160" x2="680" y2="160"/>
&lt;line class="kv-grid" x1="80" y1="110" x2="680" y2="110"/>
&lt;line class="kv-grid" x1="80" y1="60" x2="680" y2="60"/>
&lt;!-- Linear curve (with KV cache): O(N) — gentle, visible slope -->
&lt;path class="kv-lin" d="M80,260 L680,215"/>
&lt;!-- Quadratic curve (without KV cache): O(N²) — starts flat, rises fast -->
&lt;path class="kv-quad" d="M80,260 C250,258 420,200 680,58"/>
&lt;!-- Curve labels -->
&lt;p>&lt;text x="570" y="208" class="kv-tlin">with KV cache&lt;/text>
&lt;text x="570" y="222" class="kv-tlin">O(N) — linear&lt;/text>&lt;/p>
&lt;p>&lt;text x="440" y="95" class="kv-tqud">without KV cache&lt;/text>
&lt;text x="440" y="109" class="kv-tqud">O(N²) — quadratic&lt;/text>
&lt;/svg>&lt;/p>
&lt;/div>
&lt;p>The concrete numbers are devastating:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:right">Tokens generated&lt;/th>
&lt;th style="text-align:right">Without KV cache (operations)&lt;/th>
&lt;th style="text-align:right">With KV cache&lt;/th>
&lt;th style="text-align:right">Ratio&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:right">128&lt;/td>
&lt;td style="text-align:right">8,256&lt;/td>
&lt;td style="text-align:right">128&lt;/td>
&lt;td style="text-align:right">64×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">1,024&lt;/td>
&lt;td style="text-align:right">524,800&lt;/td>
&lt;td style="text-align:right">1,024&lt;/td>
&lt;td style="text-align:right">512×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">4,096&lt;/td>
&lt;td style="text-align:right">8,390,656&lt;/td>
&lt;td style="text-align:right">4,096&lt;/td>
&lt;td style="text-align:right">2,048×&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">32,768&lt;/td>
&lt;td style="text-align:right">536,887,296&lt;/td>
&lt;td style="text-align:right">32,768&lt;/td>
&lt;td style="text-align:right">16,384×&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>At 32 K tokens, &lt;strong>the cache saves you four orders of magnitude&lt;/strong> of compute. This is not an optimisation: it is what makes conversational inference possible.&lt;/p>
&lt;h2 id="the-price-how-heavy-the-backpack-is">The price: how heavy the backpack is&lt;/h2>
&lt;p>The KV cache is paid for in VRAM. The formula, per &lt;strong>sequence&lt;/strong>, is:&lt;/p>
&lt;pre tabindex="0">&lt;code>KV_size = 2 · n_layers · n_kv_heads · head_dim · context_len · bytes_per_param
↑
K and V
&lt;/code>&lt;/pre>&lt;p>Per &lt;strong>token&lt;/strong> (dropping &lt;code>context_len&lt;/code>), it is a constant of the model itself. Let us look at real numbers:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Model&lt;/th>
&lt;th style="text-align:right">n_layers&lt;/th>
&lt;th style="text-align:right">n_kv_heads&lt;/th>
&lt;th style="text-align:right">head_dim&lt;/th>
&lt;th style="text-align:right">Bytes/token (BF16)&lt;/th>
&lt;th style="text-align:right">GB at 8 K ctx&lt;/th>
&lt;th style="text-align:right">GB at 32 K&lt;/th>
&lt;th style="text-align:right">GB at 128 K&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Llama 3 8B (hypothetical MHA)&lt;/td>
&lt;td style="text-align:right">32&lt;/td>
&lt;td style="text-align:right">32&lt;/td>
&lt;td style="text-align:right">128&lt;/td>
&lt;td style="text-align:right">524,288&lt;/td>
&lt;td style="text-align:right">4.00&lt;/td>
&lt;td style="text-align:right">16.00&lt;/td>
&lt;td style="text-align:right">64.00&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Llama 3 8B (real GQA)&lt;/strong>&lt;/td>
&lt;td style="text-align:right">32&lt;/td>
&lt;td style="text-align:right">8&lt;/td>
&lt;td style="text-align:right">128&lt;/td>
&lt;td style="text-align:right">131,072&lt;/td>
&lt;td style="text-align:right">&lt;strong>1.00&lt;/strong>&lt;/td>
&lt;td style="text-align:right">&lt;strong>4.00&lt;/strong>&lt;/td>
&lt;td style="text-align:right">&lt;strong>16.00&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Llama 3 70B (GQA)&lt;/td>
&lt;td style="text-align:right">80&lt;/td>
&lt;td style="text-align:right">8&lt;/td>
&lt;td style="text-align:right">128&lt;/td>
&lt;td style="text-align:right">327,680&lt;/td>
&lt;td style="text-align:right">2.50&lt;/td>
&lt;td style="text-align:right">10.00&lt;/td>
&lt;td style="text-align:right">40.00&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Qwen3 8B (GQA)&lt;/td>
&lt;td style="text-align:right">36&lt;/td>
&lt;td style="text-align:right">8&lt;/td>
&lt;td style="text-align:right">128&lt;/td>
&lt;td style="text-align:right">147,456&lt;/td>
&lt;td style="text-align:right">1.12&lt;/td>
&lt;td style="text-align:right">4.50&lt;/td>
&lt;td style="text-align:right">18.00&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Mistral 7B (GQA)&lt;/td>
&lt;td style="text-align:right">32&lt;/td>
&lt;td style="text-align:right">8&lt;/td>
&lt;td style="text-align:right">128&lt;/td>
&lt;td style="text-align:right">131,072&lt;/td>
&lt;td style="text-align:right">1.00&lt;/td>
&lt;td style="text-align:right">4.00&lt;/td>
&lt;td style="text-align:right">16.00&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Two immediate readings:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Without GQA there is no 128 K worth talking about.&lt;/strong> A Llama 3 8B with classic multi-head attention would need 64 GB of KV cache alone for a single sequence with 128 K tokens. In other words, &lt;strong>it does not fit on any consumer GPU&lt;/strong>. That is why Meta, Mistral and the rest adopted Grouped Query Attention.&lt;/li>
&lt;li>&lt;strong>The KV cache can be larger than the model.&lt;/strong> Llama 3 8B in BF16 takes ~16 GB. With 128 K of context, its cache is another 16 GB. A single session ties with the model in VRAM.&lt;/li>
&lt;/ol>
&lt;div class="diagram" style="max-width: 720px; margin: 1.5rem auto;">
&lt;svg viewBox="0 0 720 280" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Growth of the KV cache with context length">
&lt;style>
.ax { stroke: #333; stroke-width: 1.5; }
.grid { stroke: #ddd; stroke-width: 1; stroke-dasharray: 3,3; }
.l8b { stroke: #2a9d8f; stroke-width: 2.5; fill: none; }
.l70b { stroke: #e76f51; stroke-width: 2.5; fill: none; }
.lq8 { stroke: #6a4c93; stroke-width: 2.5; fill: none; stroke-dasharray: 5,3; }
.lim { stroke: #c1121f; stroke-width: 1.5; stroke-dasharray: 4,4; }
.lbl { font: 600 13px sans-serif; fill: #222; }
.lbl-sm { font: 11px sans-serif; fill: #555; }
.tag { font: 600 11px sans-serif; }
&lt;/style>
&lt;text x="360" y="20" text-anchor="middle" class="lbl">KV cache (GB) vs context length (1 sequence, BF16)&lt;/text>
&lt;line class="ax" x1="80" y1="240" x2="680" y2="240"/>
&lt;line class="ax" x1="80" y1="40" x2="80" y2="240"/>
&lt;line class="grid" x1="80" y1="190" x2="680" y2="190"/>
&lt;line class="grid" x1="80" y1="140" x2="680" y2="140"/>
&lt;line class="grid" x1="80" y1="90" x2="680" y2="90"/>
&lt;p>&lt;text x="75" y="244" text-anchor="end" class="lbl-sm">0&lt;/text>
&lt;text x="75" y="194" text-anchor="end" class="lbl-sm">10&lt;/text>
&lt;text x="75" y="144" text-anchor="end" class="lbl-sm">20&lt;/text>
&lt;text x="75" y="94" text-anchor="end" class="lbl-sm">30&lt;/text>
&lt;text x="75" y="44" text-anchor="end" class="lbl-sm">40 GB&lt;/text>&lt;/p>
&lt;p>&lt;text x="80" y="258" text-anchor="middle" class="lbl-sm">0&lt;/text>
&lt;text x="180" y="258" text-anchor="middle" class="lbl-sm">8K&lt;/text>
&lt;text x="305" y="258" text-anchor="middle" class="lbl-sm">32K&lt;/text>
&lt;text x="430" y="258" text-anchor="middle" class="lbl-sm">64K&lt;/text>
&lt;text x="680" y="258" text-anchor="middle" class="lbl-sm">128K&lt;/text>&lt;/p>
&lt;!-- Available VRAM limit on an RTX 4090 (~8 GB free after the model) -->
&lt;line class="lim" x1="80" y1="200" x2="680" y2="200"/>
&lt;text x="680" y="196" text-anchor="end" class="tag" fill="#c1121f">≈ VRAM free after loading an 8B on a 4090&lt;/text>
&lt;!-- Llama 3 8B GQA: linear, 1 GB @8K, 16 GB @128K -->
&lt;path class="l8b" d="M80,240 L180,235 L305,220 L430,200 L680,160"/>
&lt;!-- Qwen3 8B GQA -->
&lt;path class="lq8" d="M80,240 L180,234 L305,217 L430,194 L680,150"/>
&lt;!-- Llama 3 70B GQA -->
&lt;path class="l70b" d="M80,240 L180,228 L305,190 L430,140 L680,40"/>
&lt;p>&lt;text x="690" y="160" class="tag" fill="#2a9d8f">Llama 3 8B&lt;/text>
&lt;text x="690" y="148" class="tag" fill="#6a4c93">Qwen3 8B&lt;/text>
&lt;text x="690" y="42" class="tag" fill="#e76f51">Llama 3 70B&lt;/text>
&lt;/svg>&lt;/p>
&lt;/div>
&lt;p>The dashed red line marks the realistic VRAM available on an RTX 4090 after loading the model. &lt;strong>Any model whose curve crosses that line will not be able to serve that context&lt;/strong> without additional strategies: cache quantisation, offload, partitioning.&lt;/p>
&lt;h2 id="inference-is-memory-bound-not-compute-bound">Inference is memory-bound, not compute-bound&lt;/h2>
&lt;p>There is a common misconception: thinking that &amp;ldquo;fast GPU = fast inference&amp;rdquo;. In the regime where inference services with a KV cache actually operate, &lt;strong>what gets measured is memory bandwidth&lt;/strong>. Every new token requires reading the K and V of all previous tokens from HBM. The compute is modest; the data movement is massive.&lt;/p>
&lt;p>That is why an H100 SXM (3.35 TB/s of HBM3) can be 2-3× faster than an A100 (1.55-2 TB/s) &lt;strong>without the clock frequency or the core count fully explaining the difference&lt;/strong>. Bandwidth explains it.&lt;/p>
&lt;p>And that is also why offers of &amp;ldquo;cheap GPUs with plenty of VRAM but slow HBM&amp;rdquo; (some variants with GDDR6 or LPDDR5) disappoint in inference with long contexts: they have room to store the cache but take forever to re-read it.&lt;/p>
&lt;h2 id="tricks-to-make-the-notebook-thinner">Tricks to make the notebook thinner&lt;/h2>
&lt;p>Three techniques, in chronological order, have progressively flattened the size of the KV cache:&lt;/p>
&lt;p>&lt;strong>Multi-Head Attention (MHA).&lt;/strong> The original transformer design (Vaswani et al., 2017). Every attention head has its own K and V. Expensive in cache but theoretically maximal in expressiveness. It is what models had until around 2023.&lt;/p>
&lt;p>&lt;strong>Multi-Query Attention (MQA).&lt;/strong> A single K and V shared by all heads. It reduces the cache by a factor of &lt;code>n_heads&lt;/code>. It works reasonably well but degrades generation quality on some benchmarks.&lt;/p>
&lt;p>&lt;strong>Grouped Query Attention (GQA).&lt;/strong> The middle ground that won. Heads are grouped: in Llama 3 8B, 32 query heads share K, V in groups of 4, giving 8 KV groups. It cuts the cache 4× relative to MHA with almost identical quality. It has been the de facto standard since 2024.&lt;/p>
&lt;p>&lt;strong>Multi-Head Latent Attention (MLA).&lt;/strong> DeepSeek-V2/V3&amp;rsquo;s innovation: instead of storing K, V per head, it compresses the state into a smaller latent vector and projects out to K, V on the fly. The cache can come down to 70 bytes/token, two orders of magnitude less than GQA. It is the main reason DeepSeek-V3 (671 B parameters, 37 B active) is servable on affordable infrastructure.&lt;/p>
&lt;div class="diagram" style="max-width: 640px; margin: 1.5rem auto;">
&lt;svg viewBox="0 0 640 200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="KV cache reduction by technique">
&lt;style>
.bar { stroke: #333; stroke-width: 1; }
.b-mha { fill: #e76f51; }
.b-gqa { fill: #f4a261; }
.b-mqa { fill: #e9c46a; }
.b-mla { fill: #2a9d8f; }
.lbl { font: 600 13px sans-serif; fill: #222; }
.lbl-sm{ font: 11px sans-serif; fill: #444; }
&lt;/style>
&lt;text x="320" y="20" text-anchor="middle" class="lbl">KB of cache per token (Llama 3 8B equivalent, BF16)&lt;/text>
&lt;rect x="200" y="40" width="380" height="22" class="bar b-mha"/>
&lt;text x="170" y="56" text-anchor="end" class="lbl-sm">MHA (32 KV heads)&lt;/text>
&lt;text x="595" y="56" class="lbl-sm">512 KB&lt;/text>
&lt;rect x="200" y="76" width="95" height="22" class="bar b-gqa"/>
&lt;text x="170" y="92" text-anchor="end" class="lbl-sm">GQA (8 KV heads)&lt;/text>
&lt;text x="310" y="92" class="lbl-sm">128 KB&lt;/text>
&lt;rect x="200" y="112" width="12" height="22" class="bar b-mqa"/>
&lt;text x="170" y="128" text-anchor="end" class="lbl-sm">MQA (1 KV head)&lt;/text>
&lt;text x="225" y="128" class="lbl-sm">16 KB&lt;/text>
&lt;rect x="200" y="148" width="3" height="22" class="bar b-mla"/>
&lt;text x="170" y="164" text-anchor="end" class="lbl-sm">MLA (DeepSeek-V3)&lt;/text>
&lt;text x="215" y="164" class="lbl-sm">~0.5 KB (real V3)&lt;/text>
&lt;/svg>
&lt;/div>
&lt;blockquote>
&lt;p>&lt;strong>Note:&lt;/strong> the MLA bar is illustrative, using typical values published by DeepSeek; the exact implementation depends on the latent size. What matters is the order of magnitude.&lt;/p>
&lt;/blockquote>
&lt;p>On top of this comes a fourth, orthogonal technique: &lt;strong>quantising the cache&lt;/strong> to FP8, INT8 or even INT4. vLLM and TensorRT-LLM already support it in production. Going from BF16 (2 bytes) to FP8 (1 byte) &lt;strong>halves the cache&lt;/strong> at a small cost in quality. Going to INT4 divides it by four, at a somewhat higher cost.&lt;/p>
&lt;h2 id="the-next-dragon-fragmentation">The next dragon: fragmentation&lt;/h2>
&lt;p>So far we have talked about the cache as if it were a contiguous block. In practice, an inference server handles &lt;strong>dozens of simultaneous sessions&lt;/strong>, each with its own cache growing at a different rate. Naive allocation, reserving the maximum possible per session, &lt;strong>wastes between 60 % and 80 % of the VRAM&lt;/strong> according to the original PagedAttention paper.&lt;/p>
&lt;div class="diagram" style="max-width: 720px; margin: 1.5rem auto;">
&lt;svg viewBox="0 0 720 240" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="KV cache fragmentation: naive vs PagedAttention">
&lt;style>
.used { fill: #2a9d8f; stroke: #1a6e63; stroke-width: 1; }
.free { fill: #f0e7d8; stroke: #aaa; stroke-width: 1; }
.blk { stroke: #555; stroke-width: 0.5; }
.lbl { font: 600 13px sans-serif; fill: #222; }
.lbl-sm { font: 11px sans-serif; fill: #444; }
&lt;/style>
&lt;text x="180" y="22" text-anchor="middle" class="lbl">Naive allocation (contiguous)&lt;/text>
&lt;text x="540" y="22" text-anchor="middle" class="lbl">PagedAttention (blocks)&lt;/text>
&lt;!-- Naive: 4 sessions reserve the maximum, use little -->
&lt;p>&lt;text x="30" y="60" class="lbl-sm">session A&lt;/text>
&lt;rect x="90" y="48" width="50" height="18" class="used"/>
&lt;rect x="140" y="48" width="180" height="18" class="free"/>&lt;/p>
&lt;p>&lt;text x="30" y="92" class="lbl-sm">session B&lt;/text>
&lt;rect x="90" y="80" width="25" height="18" class="used"/>
&lt;rect x="115" y="80" width="205" height="18" class="free"/>&lt;/p>
&lt;p>&lt;text x="30" y="124" class="lbl-sm">session C&lt;/text>
&lt;rect x="90" y="112" width="100" height="18" class="used"/>
&lt;rect x="190" y="112" width="130" height="18" class="free"/>&lt;/p>
&lt;p>&lt;text x="30" y="156" class="lbl-sm">session D&lt;/text>
&lt;rect x="90" y="144" width="35" height="18" class="used"/>
&lt;rect x="125" y="144" width="195" height="18" class="free"/>&lt;/p>
&lt;p>&lt;text x="180" y="190" text-anchor="middle" class="lbl-sm">→ ~70 % of VRAM reserved and empty&lt;/text>&lt;/p>
&lt;!-- PagedAttention: small blocks, dense occupancy -->
&lt;g transform="translate(400,40)">
&lt;!-- 8 blocks x 5 rows -->
&lt;g>
&lt;!-- row 1 -->
&lt;rect x="0" y="0" width="30" height="20" class="used blk"/>
&lt;rect x="30" y="0" width="30" height="20" class="used blk"/>
&lt;rect x="60" y="0" width="30" height="20" class="used blk"/>
&lt;rect x="90" y="0" width="30" height="20" class="used blk"/>
&lt;rect x="120" y="0" width="30" height="20" class="used blk"/>
&lt;rect x="150" y="0" width="30" height="20" class="used blk"/>
&lt;rect x="180" y="0" width="30" height="20" class="used blk"/>
&lt;rect x="210" y="0" width="30" height="20" class="used blk"/>
&lt;pre>&lt;code> &amp;lt;rect x=&amp;quot;0&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;30&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;60&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;90&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;120&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;150&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;180&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;free blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;210&amp;quot; y=&amp;quot;22&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;free blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;0&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;30&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;60&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;used blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;90&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;free blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;120&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;free blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;150&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;free blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;180&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;free blk&amp;quot;/&amp;gt;
&amp;lt;rect x=&amp;quot;210&amp;quot; y=&amp;quot;44&amp;quot; width=&amp;quot;30&amp;quot; height=&amp;quot;20&amp;quot; class=&amp;quot;free blk&amp;quot;/&amp;gt;
&amp;lt;/g&amp;gt;
&lt;/code>&lt;/pre>
&lt;/g>
&lt;text x="540" y="190" text-anchor="middle" class="lbl-sm">→ &amp;lt; 4 % waste (vLLM paper)&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>&lt;strong>PagedAttention&lt;/strong>, the idea from Kwon et al. (2023) that gave rise to vLLM, solves this by borrowing a technique from operating systems: divide the VRAM into small &lt;strong>blocks&lt;/strong> (typically 16 tokens) and keep a &lt;strong>page table&lt;/strong> mapping logical to physical blocks per session. A session no longer reserves one huge contiguous block: it grows one block at a time, and the blocks can be scattered across the VRAM. The result is an effective occupancy of 90 % instead of 30 %, and therefore &lt;strong>2-4× more aggregate throughput&lt;/strong> on the same hardware.&lt;/p>
&lt;p>PagedAttention deserves an article of its own. I am noting it down for the next one.&lt;/p>
&lt;h2 id="applied-to-generic-on-premise-hardware">Applied to generic on-premise hardware&lt;/h2>
&lt;p>Let us come down to concrete cases.&lt;/p>
&lt;h3 id="case-1--rtx-4090-24-gb-ada-lovelace">Case 1 — RTX 4090 (24 GB, Ada Lovelace)&lt;/h3>
&lt;p>A typical configuration with Qwen3-8B BF16:&lt;/p>
&lt;pre tabindex="0">&lt;code>Model in BF16: ~16 GB
Activations + overhead: ~2 GB
VRAM available for KV cache: ~6 GB (with margin)
&lt;/code>&lt;/pre>&lt;p>At 144 KB/token (Qwen3-8B GQA), that comes to &lt;strong>~43 K total tokens of cache&lt;/strong> distributed across all simultaneous sessions. In practice:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:right">Concurrency&lt;/th>
&lt;th style="text-align:right">Maximum context per session&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:right">1&lt;/td>
&lt;td style="text-align:right">32,768&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">4&lt;/td>
&lt;td style="text-align:right">8,192&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">8&lt;/td>
&lt;td style="text-align:right">4,096&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">16&lt;/td>
&lt;td style="text-align:right">2,048&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>If you need to advertise &amp;ldquo;we support 32 K of context&amp;rdquo; with concurrency of 4 or more, you have to &lt;strong>quantise the cache&lt;/strong> (FP8 brings it down to 72 KB/token, doubling capacity) or &lt;strong>move up the model range&lt;/strong> (a 4B with GQA and a quantised cache would have room to spare).&lt;/p>
&lt;h3 id="case-2--cluster-of-4h100-320-gb-total-nvlink">Case 2 — Cluster of 4×H100 (320 GB total, NVLink)&lt;/h3>
&lt;p>With tensor parallel = 4 and Llama 3 70B BF16:&lt;/p>
&lt;pre tabindex="0">&lt;code>Model in BF16: ~140 GB (35 GB/GPU)
vLLM overhead per GPU: ~2 GB
VRAM free for KV per GPU: ~43 GB → ~172 GB aggregate
&lt;/code>&lt;/pre>&lt;p>At 320 KB/token (Llama 3 70B GQA), that comes to &lt;strong>~537 K total tokens of cache&lt;/strong>. Ample margin for long contexts with high concurrency:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align:right">Concurrency&lt;/th>
&lt;th style="text-align:right">Maximum context per session&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align:right">4&lt;/td>
&lt;td style="text-align:right">134,000&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">16&lt;/td>
&lt;td style="text-align:right">33,500&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align:right">64&lt;/td>
&lt;td style="text-align:right">8,375&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>For DeepSeek-V3 671 B with MLA the economics change radically, because the cache is ~100× thinner. What limits you is no longer the cache but the VRAM of the model itself (quantised to FP8 it is ~335 GB, so it fits on 4×H100 with room for the KV cache).&lt;/p>
&lt;h3 id="operational-implications">Operational implications&lt;/h3>
&lt;p>Three observations we repeat in every consulting engagement:&lt;/p>
&lt;p>First, &lt;strong>the maximum context a model advertises is not the one you can serve on your hardware&lt;/strong>. Llama 3 8B &amp;ldquo;supports&amp;rdquo; 128 K, but on a 4090 with 4 simultaneous sessions your effective context is ~8 K. It is trivial to check before promising it to a client.&lt;/p>
&lt;p>Second, &lt;strong>quantising the KV cache is one of the optimisations with the best cost/benefit ratio in the ENS context&lt;/strong>. It does not touch the weights, it does not affect audit reproducibility, and it doubles capacity. vLLM supports it via &lt;code>--kv-cache-dtype fp8&lt;/code>.&lt;/p>
&lt;p>Third, &lt;strong>if the SLAs dictate long contexts with many concurrent users, GQA is necessary but not sufficient&lt;/strong>. In the medium term you need to look at models with MLA or attention variants with compression.&lt;/p>
&lt;h2 id="what-we-have-not-covered-upcoming-articles">What we have not covered (upcoming articles)&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>PagedAttention&lt;/strong> and its implementation in vLLM: blocks, page table, eviction.&lt;/li>
&lt;li>&lt;strong>Prefix caching&lt;/strong>: when several requests share the system prompt, there is no need to recompute the K, V of the common part.&lt;/li>
&lt;li>&lt;strong>Speculative decoding&lt;/strong> and its interaction with the cache.&lt;/li>
&lt;li>&lt;strong>Cache offloading&lt;/strong>: moving cold blocks to RAM or NVMe, a key technique for contexts above 1 M.&lt;/li>
&lt;/ul>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/six-stage-llmops-pipeline-architecture-and-deep-dive/">The six-stage LLMOps pipeline&lt;/a> — the master map of the system in production, in which the Deploy stage is one box out of six. This post goes into one of the critical decisions inside Deploy.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/pagedattention-vllm-block-manager/">Inside PagedAttention: blocks, page table, eviction and the state of the art of the KV cache in 2026&lt;/a> — a theoretical deep dive at block level plus a survey of derived optimisations (vAttention, EvicPress, RadixAttention, speculative decoding). It continues this post from the academic theory.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/continuous-fine-tuning-production-real-traffic-deployed-adapter/">Continuous fine-tuning in production: from real traffic to the deployed adapter&lt;/a> — how the loop between inference and incremental training closes on the same stack (vLLM + Postgres), with VRAM budgets that explicitly include the KV cache during eval.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/disaggregated-serving-prefill-decode-specialised-pods/">Disaggregated serving: prefill and decode in specialised pods&lt;/a> — the KV cache stops being a private GPU buffer and becomes the artefact transferred between pods. Here the cache size formula determines the economics of the transfer.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/gpu-cluster-as-multi-tenant-platform/">The GPU cluster as a multi-tenant platform&lt;/a> — how the cluster becomes a service with tenants, gateway, quotas and isolation. That is where the KV cache stops being only a performance resource and becomes a platform matter.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/vllm-kubernetes-llm-inference-that-scales/">vLLM on Kubernetes: the LLM inference piece that does scale&lt;/a> — the engine that materialises everything discussed here, deployed on K8s with tensor parallel and autoscaling.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/quantization-llm-inference-fp8-int4-gguf/">Quantization for LLM inference: FP8, INT4 and GGUF&lt;/a> — KV cache quantisation (&lt;code>--kv-cache-dtype=fp8/int4&lt;/code>), mentioned here as the fourth orthogonal technique, is taken apart there with the maths, the formats and the measurable loss.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/speculative-decoding-fundamentals-maths-state-of-play/">Speculative decoding: the secretary who anticipates what the boss will say&lt;/a> — the memory-bound decode regime caused by the KV cache is exactly what speculative decoding exploits: a forward pass with γ tokens costs almost the same as one with a single token.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/flashattention-librarian-io-awareness-async-blackwell-asymmetry/">FlashAttention v1/v2/v3/v4: the librarian who never clears the desk&lt;/a> — the kernel that sweeps the KV cache against Q on every iteration without materialising the N×N matrix. The compute layer underneath the cache.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/moe-inference-fundamentals-expert-parallel-deepseek-economics/">MoE inference: the call centre with 256 specialists&lt;/a> — attention is still dense in every MoE of 2026 (Mixtral, DeepSeek, Qwen3, Llama 4, Kimi K2), so the KV cache keeps its shape; DeepSeek&amp;rsquo;s MLA is the orthogonal optimisation that compresses it ~10× to make long context viable on modest clusters.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/continuous-batching-orca-vllm-chunked-prefill-goodput/">Continuous batching&lt;/a> — the iterative scheduler manages the dynamic allocation of the KV cache across requests; without PagedAttention, continuous batching would fragment the HBM, and without continuous batching the KV cache would be underused because of padding.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/capacity-planning-on-premise-llm-inference/">Capacity planning for on-premise LLM inference&lt;/a> — the KV cache is the dominant component of the VRAM budget when sizing a cluster from an SLO; the spreadsheet is built there step by step.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/optimising-prefill-vllm-knobs-ttft-will-not-forgive/">Optimising prefill in vLLM&lt;/a> — the four concrete knobs (chunked prefill, prefix caching, FP8 KV, max-model-len) that turn KV cache theory into production parameters for the RTX 4090 and the L40.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/optimising-decode-vllm-squeezing-every-token-small-hardware/">Optimising decode in vLLM&lt;/a> — how &lt;code>--gpu-memory-utilization&lt;/code>, speculative decoding and an FP8 KV cache combine to squeeze small hardware during the generation phase.&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>Vaswani et al., &lt;em>Attention Is All You Need&lt;/em> (NeurIPS 2017) — foundational transformer paper.&lt;/li>
&lt;li>Ainslie et al., &lt;em>GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints&lt;/em> (EMNLP 2023).&lt;/li>
&lt;li>Kwon et al., &lt;em>Efficient Memory Management for Large Language Model Serving with PagedAttention&lt;/em> (SOSP 2023) — original vLLM paper.&lt;/li>
&lt;li>DeepSeek-AI, &lt;em>DeepSeek-V2 Technical Report&lt;/em> (2024) — introduction of Multi-Head Latent Attention.&lt;/li>
&lt;li>Official vLLM documentation: &lt;a href="https://docs.vllm.ai/">https://docs.vllm.ai/&lt;/a>.&lt;/li>
&lt;li>Llama 3 model card (Meta): GQA specs, n_layers, n_kv_heads.&lt;/li>
&lt;/ul></description></item></channel></rss>