Summary
No hosted endpoint serves Gemma 4 31B fast enough for us, so we serve it ourselves on NVIDIA B200 GPUs with NVFP4 weights and an FP8 KV cache. In production, a reply takes about 300 ms at the median, and in our load tests one GPU holds 130 concurrent sessions with a median under 600 ms. We reached 130 sessions per GPU in steps: more cache for the full-attention layers, one prefill per turn instead of two, full CUDA graphs, a second cache tier in CPU memory, longer speculative drafts extended by prompt lookup, and larger cache pages.
In a cascaded stack, keeping time to first audio (TTFA) under 1 second requires keeping each component under a tight budget. We want our LLM to return a first sentence within 350 ms median and a full response in 600 ms median.
After we chose Gemma 4 on its capabilities, we needed to serve it within that time budget. Since no provider has an option that meets our requirements, we decided to try and do it ourselves. After a month of experiments, we managed to reach our target while maintaining a high GPU utilization by leveraging what we know about our usage patterns and optimizing around it. In production, a full reply now takes about 300 ms at the median, half our budget.
Workload
A game session is a sequence of agent and player turns. Most agent turns include one or several calls to our main LLM. The prompt holds the system prompt, contextual instructions and session history, so it can grow quite long. In production, the median request has about 22,000 input tokens. Most of it repeats from one turn to the next. You can see it in the graph above: select Cache hit rate as a metric, and observe how most calls within a session are above 95% hit rate, with occasional drops to 50-80%. These drops indicate changes in the instruction context, typically when navigating from one scene to the other. Now select Input tokens: within a session, the prompt grows roughly linearly, by about 750 tokens per minute of play. Most requests fall between 15,000 and 31,000 tokens, and the longest reach about 51,000. About 8,000 of those are the episode’s shared prefix, identical for every child playing it.
Replies are short: about 65 output tokens at the median, typically between 20 and 160, and rarely more than 300. We disable reasoning to keep them that way.
This shape has three consequences.
- The fixed cost per call matters more than tokens per second: prefill of the uncached suffix usually takes under 10 ms, decoding a 65-token reply about 100 ms. Everything else is an almost constant overhead.
- Under load, cache is the bottleneck: cache eviction is costly, since recomputing a 20k-token prefix takes over a second. Sometimes it’s hidden behind audio playback, but most of the time it means a sharp increase in our p95 TTFA.
- Capacity is limited by latency, not throughput: as we add sessions, the GPU still has throughput to spare, but calls that arrive together slow each other down, and the median crosses our target first.
Lab notesRule of thumb: latency of one call
A linear fit over 30,000 production replies from November 13 to 18 gives (R² 0.62):
The fixed part covers the network, tokenization and launching the prefill. On SGLang in September, the same fit gave 228 ms, 2.85 ms and 0.052 ms: the changes below almost halved the cost of each output token.
The network matters as much as the GPU here. About a fifth of a median reply, roughly 60 ms, is spent between our agent and the inference engine: the network both ways and the HTTP handling on each side. Until mid-November, it was about 110 ms, a third of the reply. Two changes saved about 50 ms per request: HTTP/2 over long-lived keep-alive connections, and no TCP slow start after idle (net.ipv4.tcp_slow_start_after_idle=0). Between two turns of a game, a connection sits idle long enough for the kernel to shrink its sending window back to the start, so each reply paid extra round trips just to send a prompt of tens of kilobytes.
Traffic is strongly diurnal: outside holidays, children play in the morning, in the evening, on Wednesdays and weekends. And, since we only sell in France for now, almost all of our users are in the same timezone. Over a week, the average load is 30% of the busiest hour, and close to zero between 22:00 and 7:00. The steepest rise is about 40% of the weekly peak within an hour, on free-day mornings. A replica takes 2 to 5 minutes to start, so we add GPUs before the ones we have fill up.
Benchmark
Most of the measurements below come from our load-testing bench, which replays recorded sessions with the exact same timing as in production. Our replay corpus is 120 recorded sessions from ten episodes (this matters because different episodes have different cache prefixes). Each simulated player sends the recorded request at the recorded pace, including prefill requests our prod agent sends while audio is playing, so our measured load uses the same cache pattern as in production. When a simulated session ends, we start another one to maintain the same volume of sessions per unit of time. Each request has a 30 s timeout (instead of 2 s in production), so that we can measure exact latency when a replica is overloaded.
A configuration holds a number of sessions when its median end-to-end latency stays within 600 ms (we allow 10% of noise), fewer than 5% of calls take over 2 s, and no call errors or session fails. We report the highest number that holds.
We’re mainly interested in three latency metrics.
- TTFT, time to first token: request sent to the first content token.
- TTFS, time to first sentence: request sent to the first segment we can send to TTS (we typically end on end of sentence punctuation, scene transitions, audio tags, listening windows).
- E2E, end to end: request sent to the complete reply.
We also report output tokens per second per GPU, the cache hit rate, and the share of calls over 2 s (those calls would have timed out in production).
Key drivers
We first served Gemma 4 on two B200s (TP=2). Five days later we moved to a single GPU (TP=1) with 4-bit weights. Since then, in our replay, one GPU went from about 33 to about 90 concurrent sessions under our 600 ms median objective by early October, and to 130 by November. The first gains came from giving more cache memory to full-attention tokens, switching from SGLang to vLLM, and dropping one of our two prefill requests. The next ones came from full CUDA graphs, a second cache tier in CPU memory, and longer drafts. In November, larger cache pages and a cheaper drafter step took it to 130. We run our own fork of vLLM, now built on v0.33.0, to get some of them (see Inference engine).
Speculative decoding
We use speculative decoding1 with the drafter Google ships with Gemma 4, a small multi-token prediction (MTP) model that reads the main model’s own cache. We started with three draft tokens per step: the model kept about three tokens per step instead of one, which increased decoding speed by 1.4× at 16 concurrent requests (1.6× for a single request), for 8 ms more TTFT.
Longer drafts are a trade-off. Each extra draft token costs one more pass of the drafter, about 0.43 ms on a B200, and each extra token to verify makes the main model’s step about 0.13 ms longer. On our replies, the drafter’s guesses stay good deep into the draft, so drafting more pays up to 7 to 9 tokens: at 90 sessions, the median drops from 674 ms with three draft tokens to 545 ms with nine.
Piecewise and full CUDA graphs
A CUDA graph records the GPU kernels of a forward pass once, then replays them with a single launch, which saves the CPU from launching each kernel. vLLM captures graphs in two modes. A full graph covers the whole step, attention included. A piecewise graph covers what sits between attention layers, and attention runs outside the graph, launched from Python for each of Gemma’s 60 layers.
vLLM treats Gemma 4 as a model whose image tokens attend to each other in both directions. For that mask, it picks an attention backend that can’t run inside a graph, so decoding falls back to piecewise graphs, even for requests without any image. Turning off image and audio inputs, as the published recipe does, isn’t enough: video inputs have to go too. --language-model-only turns off all three. You can’t keep FlashInfer in that mode either: with --attention-backend FLASHINFER and without --language-model-only, vLLM refuses to start.
This is easy to miss. The server starts and replies are correct. The startup log does say it, in one warning among a few hundred lines: CUDAGraphMode.FULL_AND_PIECEWISE is not supported with TritonFlashInferBackend backend (support: AttentionCGSupport.NEVER); setting cudagraph_mode=PIECEWISE. Otherwise, the server is just slower. At 70 sessions, full graphs cut the engine’s time per request from 384 to 324 ms, and sped up decoding from 283 to 346 tokens per second per user.
Prompt lookup
Our replies copy a lot from their prompt: character names, instructions, and the tags the prompt spells out. Most reply tokens sit in a span of 8 or more tokens that also appears in the call’s prompt.
Prompt lookup drafts by finding the last few tokens elsewhere in the conversation and proposing what followed them. Used instead of Gemma’s drafter, it lost (589 against 545 ms): the drafter already reads the prompt through the cache, so it copies well where lookup fires. Used after it, lookup helps: the drafter proposes nine tokens, then lookup fills slots 10 to 15 when the draft’s last tokens match the conversation. The model keeps 5.1 tokens per step instead of 4.7, decoding is 7% faster, and the median drops from 545 to 538 ms. Fifteen is the limit: FlashInfer’s decode kernel verifies at most 16 tokens at a time for Gemma’s 512-dimension heads. This extension is our own contribution, living in our vLLM fork.
What didn’t help:
- other drafters: DFlash decodes 25 to 30% faster but delays the first token and uses memory we need for the prefix cache. RedHat’s public DSpark drafter accepted 17% of drafted tokens in an offline test. We did some preliminary work on training a DSpark drafter on our own sessions, without conclusive results yet.
- draft trees: proposing a few alternative continuations per step would keep slightly more tokens in an offline replay (5.15 against 4.96 per step), but vLLM removed tree attention. And it seems like too much complexity for little gain.
- sampled drafts instead of the drafter’s most likely tokens: no gain.
Lab notesDrafters we tried
| Drafter | Result |
|---|---|
| Gemma’s drafter, 3 tokens | 3.4 tokens kept per step at 10 sessions; decoding 1.4× faster at 16 requests |
| Gemma’s drafter, 9 tokens + prompt lookup to 15 | 5.1 tokens kept per step at 90 sessions; production |
| DFlash, blocks of 8 and 16 tokens | 4.6 tokens per step and faster decoding, but first sentence 406 against 351 ms at 25 sessions, and 30% of calls over 2 s at 40 sessions |
| RedHat’s DSpark | 17% of drafted tokens accepted, offline |
| DSpark trained on our sessions | Preliminary work, no gain yet |
A cheaper drafter step
Each draft token reads the drafter’s own output layer, a 262,144 × 1,024 matrix. In November, we stored it in 4-bit, like the main model’s feed-forward layers. The main model still checks every token with its own 16-bit output layer, so replies don’t change. We also start each draft from the request’s last accepted token, without a prefill pass of the drafter first, as proposed in vLLM PR #60689. Together, at 100 sessions, they took the median from 449 to 388 ms.
Quantization
4-bit weights and an 8-bit KV cache2 more than double the cache one B200 can hold, with an acceptable quality loss on our benchmarks.
Lab notesLatency and quality by precision
| One call at a time | 14 sessions | 10 requests/s | |
|---|---|---|---|
| 4-bit weights, 8-bit cache | 393 / 483 | 486 / 1,451 | 546 / 655 |
| 4-bit weights, 16-bit cache | 406 / 559 | 565 / 2,153 | 1,333 / 2,644 |
| 16-bit weights, 16-bit cache | 479 / 617 | 698 / 7,556 | 760 / 1,006 |
The larger cache matters most under load: at 14 sessions, the share of the prompt served from cache rises from 85% to 95%. On quality, the 4-bit model passed 68.1% of Archie Bench cases, against 70.7% for the 16-bit model served by a hosted provider. The 95% interval on that difference runs from −3.3 to +6.7 points, and the same 16-bit model measured twice differed by 1.5 points.
| BF16 | NVFP4 + FP8 KV | |
|---|---|---|
| Archie Bench (pass rate) | 70.7% | 68.1% |
| Archie Bench (exemplary rate) | 58.9% | 57.4% |
| French lexical integrity (pass rate) | 99.5% | 99.0% |
NVIDIA’s 4-bit checkpoint keeps the attention projections in 16-bit, and decoding reads every weight at each step. Since late October, we serve our own variant of it on Hugging Face, with those projections in FP8 and every other tensor unchanged. It weighs 22.5 GiB instead of 30.4, leaves room for about 46,000 more tokens of cache, and took the median at 90 sessions from 513 to 454 ms, with the same scores on our benchmarks.
Increasing cache hit rate
A typical prompt holds about 27,000 tokens, and about 97% of it was already processed on the previous turn. As long as the KV cache has headroom, each call only processes the player’s last utterance, then decodes 30 to 120 tokens; the decoding part takes roughly 100 to 350 ms. Our latency objective thus breaks when we miss KV cache.
This section explores various ways to increase cache hit rate.
Prefilling
Our agent knows how the next prompt starts before the child speaks: the history, its own reply, and the instructions for what comes next. So right after each reply, while the audio plays, it sends that prompt to the server with no output requested. By the time the child answers, the real call only has to process the transcript. Since we rent the GPU by the hour, this costs no money, although it uses capacity: a prefill can delay a real call. Our fork now schedules real calls ahead of prefills, which ask for zero output tokens and skip drafting. The same idea works at the start of a session: preparing the episode’s opening prompt before the first call cut the first answer from 868 to 322 ms.
The agent also sent a second prefill when the child stopped speaking, before the transcript arrived. That hook dates back to when we used a hosted provider, where it opened the connection early to save a handshake. With our own server, it mostly re-sent a prompt the first prefill had already cached, and it reached the GPU at the worst moment, a fraction of a second before the real call; a quarter of them were cancelled by the real call. Dropping it costs each call about 200 extra tokens (about 10 ms) and, on vLLM at 55 sessions, more than halved the share of slow calls. On SGLang it made no difference.
| Prefills sent (vLLM, 55 sessions) | Median | Over 2 s | GPU busy |
|---|---|---|---|
| Both | 567 ms | 3.9% | 65% |
| End of speech only | 585 ms | 5.2% | 58% |
| Post-reply only | 537 ms | 1.7% | 52% |
Full-attention and sliding-window cache
Gemma 4 has two kinds of attention layers. Fifty of them only look at the last 1,024 tokens (sliding window attention), and ten look at the whole conversation (full attention) [1]. SGLang keeps one cache per kind and splits the memory with a single setting, --swa-full-tokens-ratio. With the default 0.8, 89% of the cache memory goes to the sliding-window layers. Above 35 sessions, the full-attention cache runs out and the hit rate goes down (at 40 sessions, 88% instead of 94%). At 0.4, a single B200 can reach 45 sessions while maintaining its cache hit rate. At 0.2, the sliding-window cache runs out first.
vLLM sizes the two caches itself. For each request, it reserves sliding-window memory for one window plus the tokens being processed, and gives the rest to full attention. Given 95% of the GPU’s memory, it counts room for about 961,000 tokens (15 conversations at the 64k-token limit) without any tuning, about three times SGLang’s full-attention cache at its default split. Quite convenient!
A cache tier in CPU memory
Even with about a million tokens of cache on the GPU, a busy replica evicts prefixes while children think. At 70 sessions, a call that came 30 to 60 s after the session’s previous one had lost about 2,400 of its cached tokens, and calls after longer pauses lost more. The machine around the GPU has far more memory than the GPU itself, and vLLM can keep a second tier of cache there: blocks evicted from the GPU stay in CPU memory, and a later call loads them back instead of recomputing them.
Out of the box, that tier served nothing. In its default (eager) mode, vLLM copies every block to the CPU as it’s written. Our initial CPU tier was smaller than the GPU cache, so blocks left the CPU tier before the GPU evicted them. Lazy mode, which copies blocks only when they’re about to leave the GPU, fits our case better, but it served no hits either.
The cause was the order of vLLM’s free queue, the list of cached blocks that no running request uses, from evicted first to most recently used. In lazy mode, vLLM copied the blocks at the eviction end to the CPU, then put them back at the other end, as if they had just been used. The GPU then evicted other blocks instead, ones the CPU didn’t hold, and the copier moved on to copy those. We fixed it in vLLM PR #59383, merged in November: copied blocks go back to the eviction end.
Two more pieces come from other people’s work, which we backported to our fork: joint GPU and CPU prefix lookup (#57325), without which 68% of CPU lookups stopped at a block that was still on the GPU, and Prometheus metrics for the CPU tier (#57251).
At 90 sessions, we use a 180 GiB tier. It holds about 1.3 million tokens and adds about 15% of the replica’s price. Doubling it gained little for 18% more. The misses that remain, about 425 tokens per call, come from prompts that differ from their prefill, not from eviction.
Lab notesCPU tier size at 90 sessions
| CPU tier | Median | Over 2 s | Served from the GPU cache |
|---|---|---|---|
| 40 GiB | 725 ms | 9.5% | 82% |
| 180 GiB | 606 ms | 2.5% | 86% |
One B200, our vLLM fork before the longer drafts (three draft tokens), one run each (the 40 GiB run had a 5-minute window, the 180 GiB run a 10-minute one). With the larger tier, the engine also recomputed 29% fewer prompt tokens per second.
Larger pages
vLLM stores the cache in fixed-size pages, and by default a cache hit drops its last page: an EAGLE drafter recomputes its own cache there, but Gemma’s drafter reads the main model’s cache and writes none. Keeping that page (disable_eagle_block_drop) cut the prompt tokens the GPU computes at 100 sessions by 10%.
Doubling the page size helped more: with 32-token pages (64 on the full-attention layers), a session that comes back after a pause more often finds its whole private prefix in the CPU tier. At 120 sessions, the median went from 610 to 442 ms, and calls over 2 s from 3% to 1%. Larger full-attention pages would need a FlashInfer prefill kernel that doesn’t exist yet for Gemma’s 512-dimension heads with an FP8 cache.
Streaming
Our agent waits for the whole reply before sending it to text-to-speech. A reply is about 65 tokens at the median, but the first sentence ends after about 20. In our September replay, streaming the model output and sending to TTS as soon as a complete sentence is received would have saved 100–200 ms, at the expense of a TTS seam. Decoding has since become about twice as fast: on November’s production replies, we estimate the saving at about 50 ms at the median and 180 ms for the slowest 10%. This change hasn’t reached production yet.
Inference engine
We started with SGLang [2] because vLLM was slow out of the box with an 8-bit cache and speculative decoding, and we didn’t investigate further at that point. When we took the time to configure it properly [3] (see below), vLLM beat SGLang at every load we tried. At the same number of sessions, its first token arrives about 80 ms sooner and its median is about 130 ms lower. At this point, we have no clear explanation for this: it isn’t decoding waiting behind prefills because SGLang mixed batching didn’t help.
On 150 production prompts, a blind judge found no quality difference between the two engines.
We now run our own fork of vLLM, built on v0.33.0, and publish each build with its patch list (latest release). It adds pull requests that v0.33.0 doesn’t include, some of them by other people, and a few changes that are only ours:
- #59383, ours: lazy CPU offload returns copied blocks to the eviction end of the free queue. vLLM merged it in November, after v0.33.0.
- #64229: the lazy offload counts bounded sliding-window allocations when it decides how many blocks to copy.
- #57325: joint GPU and CPU prefix lookup.
- #53273: one kernel launch fewer per layer, by fusing a residual add into the next norm.
- #60689: drafts that start from the last accepted token (see A cheaper drafter step).
- Ours, not proposed upstream: prompt lookup after the drafter’s tokens (see Prompt lookup), the drafter’s output layer in 4-bit, and prefills that ask for zero tokens, skip drafting and wait behind real calls.
Lab notesvLLM config
- vLLM
0.33.0, our fork - NVIDIA’s 4-bit weights with FP8 attention projections
- FlashInfer attention everywhere
- full CUDA graphs in decode (
--language-model-only) - GPU memory 0.95: about 1,010,000 tokens of FP8 cache
- 32-token pages, 64 on the full-attention layers;
disable_eagle_block_drop - 180 GiB CPU tier:
SimpleCPUOffloadConnectorin lazy mode - Gemma’s drafter with nine tokens and its output layer in NVFP4, prompt lookup up to 15
- 8,192 batched tokens, 64 sequences, async scheduling,
-O3 - fastokens tokenizer on 4 threads
- prefills send
max_completion_tokens: 0
Long tail of minor gains
- Tokenize on the client, send token ids: −50 ms on SGLang, no change on vLLM
- Compile cache on a persisted volume reduces cold start 9 min → 2–5 min (not a latency gain per se, but makes auto-scaling much easier)
- Basic networking helps, such as keep-alive connections (−80 ms on a subset of calls). One gotcha: cancelling a request over HTTP/1.1 closes its connection, so the next call pays a new handshake. In production, 12.6% of our calls paid a handshake, most of them right after a cancelled prefill.
- Not done yet: optimizing prompt format to reduce the number of tokens, primarily on the critical path (i.e. everything that happens after a prefill and before a reply)
Lab notesExperiment log
Many things didn’t help, or not enough to keep. We list them briefly: most are one run, on one host, so “no gain” means “no gain we could see”.
| Tried | Result |
|---|---|
| Two B200s with tensor parallelism | Fixed the tail (p95 5.8 → 1.2 s at 14 sessions) at 1.9× the price; one GPU with 4-bit weights got close (1.45 s) |
| FP8 weights alone | Same quality, small latency gain |
| SGLang’s Triton attention (its only option for an FP8 cache at first) | 1.7 to 5× slower |
| 4-bit KV cache (SGLang, vLLM), TurboQuant | Doesn’t start for Gemma 4 |
| Google’s quantization-aware 4-bit weights (W4A16) | vLLM runs them through a slower kernel: prefill 3.5× slower, and most sessions time out while joining |
| DFlash drafter | Faster decode, later first token, worse from 25 sessions |
| RedHat’s DSpark drafter | 17% acceptance; training our own is still preliminary |
| Longer drafts on SGLang | Crash or garbled output from four draft tokens |
| SGLang flags: prefill CUDA graphs, 2k chunks, more memory, HiCache, 4 tokenizer workers, mixed batching, v0.5.20 | No gain |
torch.compile on SGLang | Doesn’t start |
| vLLM: 4k batch limit, two API servers | Worse or no gain |
| LMCache as the CPU tier | Its Gemma 4 recipe needs Triton attention with the drafter |
| KV split at 0.2 | A 3-minute run suggested twice the sessions; 5- and 10-minute runs gave 38, less than 0.4 |
| Other GPUs | H100 with our fork: 787 ms at 20 sessions. RTX PRO 6000: no speculative decoding kernel for Gemma’s head size, 1.6 s. B300: none available in the EU |
| Prompt reordering for caching | Broke prefix sharing across sessions |
| Warm spare connection | Saves 93 ms when a prefill is interrupted, about 2 ms on average |
| Nightly restart | A fresh replica looked 50 ms faster; never confirmed with a matched comparison |
Hopper GPUs
At most providers, Hopper GPUs are easier to get than B200s, and an H200 rents for less. Out of the box, though, Gemma 4 on an H200 was far from our target: about 1.8 s at three sessions on SGLang, and 2.4 s on vLLM.
Two fixes made it work better:
- vLLM v0.30.0 sent Gemma 4’s 512-dimension attention layers with an 8-bit cache to a slow Triton kernel on Hopper. vLLM PR #53175 selects FlashAttention 4 for them instead.
- FlashAttention 4’s Hopper kernel ignored how many parts it should split a long cache into, so one part read the whole cache alone: an attention call took 538 µs instead of 56 µs at 10,800 tokens of context. flash-attention#198 fixes it.
Both are part of vLLM since v0.33.0. On our v0.33.0 fork, one H200 holds 35 sessions: 463 ms at the median, with 4.5% of calls over 2 s. At 40 sessions, 6% of calls take over 2 s. It also absorbs fewer new sessions at once: with 20 players joining a minute, their first prompts queued until they timed out, so our H200 runs join at 10 a minute.
The limit is memory bandwidth, not memory size. Each decoding step reads about the same amount of weights, at 4.8 TB/s on an H200 against 8 TB/s on a B200. An idle H200 makes a token every 3.9 ms, about what a B200 does at 90 sessions (3.2 to 3.4 ms): the H200 starts where the B200 ends. Its cache isn’t the problem: at 40 sessions, it still served 95% of prompt tokens from cache, as much as a B200 at 130. Shorter drafts don’t help either: with five draft tokens instead of nine, each token took 6% longer.
In the end, at their public list prices, when accounting for price per hour and capacity, a B200 stays about 2.9 times less expensive per session than a H200.
Tooling
We used Modal to run those experiments and loved the developer experience: every replica above was a short-lived app with a TTL, billed by the second. Paired with strong coding agents, Modal makes running experiments extremely easy and fast.
Investing in a good load-testing benchmark pays off quickly. Most numbers above are very sensitive to precise traffic patterns, exact timing, prompt content, and many other parameters that can’t be simulated easily. Getting confidence in a config requires confidence in the test bench itself.
References
- Google DeepMind, Gemma 4 Technical Report, 2026.
- SGLang, Gemma 4 cookbook.
- vLLM, Gemma 4 Usage Guide.
- LiveKit, Latency optimized inference: Gemma 4 on LiveKit, July 2026.
- InferenceBench, Gemma 4 31B on H100: The Complete Inference Benchmark, April 2026.
- NVIDIA, Dynamo recipe: Gemma 4 31B.
Footnotes
-
A small draft model proposes the next few tokens, and the large model checks all of them in one forward pass, keeping the ones it agrees with. The output follows the same distribution as without a drafter; decoding is faster when the guesses are right. ↩
-
Quantization stores numbers with fewer bits: 16 (BF16), 8 (FP8) or 4 (NVFP4). Here it applies to the model weights and to the KV cache, the attention state the server keeps for tokens it has already processed. Smaller weights leave more GPU memory for the cache, and are faster to read at each step. ↩