Same weights, two stacks, one scoreboard. Take google/gemma-3-4b-it, serve it with Keras Hub's generate(), then serve it with vllm serve — and the result is almost a trick question. At one request at a time the two stacks tie. At 64 concurrent requests, vLLM serves 26.5x more tokens. The gap is not the model, the GPU, or the weights. It is batching — and it starts paying at just 3 concurrent requests.

This is GDE post #17, the head-to-head the Keras/JAX lane has been building toward. GDE #12 ran Gemma 3 locally with Keras, #14 showed one model on three backends, #15 priced TPU inference, #16 fine-tuned it with LoRA. This one answers the question those posts left open: once the model works, which stack do you serve it on? Every number below is recomputed in the companion notebook.

The ELI5 version

Think of a restaurant. Keras is a talented home cook: one order at a time, cooked start to finish, excellent food, no waiting list. vLLM is a restaurant kitchen: same chef, same recipe, but orders are batched — the oven runs once for ten dishes, prep is shared, and the table layout (paged KV cache) means a big party doesn't block the room.

The model is the recipe. The GPU is the kitchen. The serving stack is everything about how orders flow through the kitchen — and for an LLM, the flow matters more than the recipe once more than one person is hungry.

The model: Gemma 3 4B, by the numbers

Gemma 3 comes in 1B, 4B, 12B, and 27B sizes, all open weights, with 128K context on everything except the 1B (32K). The 4B is the sweet spot for this comparison: multimodal, 128K context, and small enough to fit on one 24 GB consumer card in bf16 — 4,301M parameters total (417M vision encoder + 675M embeddings + 3,209M transformer), about 8.0 GiB of weights.

The architectural detail that decides this whole post is the attention pattern. Gemma 3 interleaves 5 local layers per 1 global layer, with the local layers' sliding window capped at 1,024 tokens. A full-attention model stores KV for every token at every layer. Gemma 3 stores every token at only 5 of its 34 layers; the other 29 store at most the last 1,024 tokens, forever.

The arithmetic is exact, from the published config (34 layers, 8 query heads, 4 KV heads, head dim 256, bf16):

Context Full-attention KV Gemma 3 KV Saving
1K 0.13 GiB 0.13 GiB 1.0x
8K 1.06 GiB 0.27 GiB 3.9x
32K 4.25 GiB 0.74 GiB 5.8x
128K 17.00 GiB 2.61 GiB 6.5x

At 128K context, a full-attention 4B model needs 17.0 GiB of KV cache — more than a 24 GB card has left after the 8.0 GiB of weights. Gemma 3 needs 2.61 GiB. That is not a marginal optimisation. It is the difference between serving 128K context on one card and not serving it at all.

KV cache per sequence vs context length: a full-attention 4B model needs 17.0 GiB at 128K context, Gemma 3's 5:1 local/global pattern needs 2.61 GiB — 6.5x less. The dashed line is the 16.0 GiB left on a 24 GB card after weights.

What fits on one 24 GB card, after weights:

Context per sequence Max concurrent sequences (Gemma 3) Full-attention equivalent
2K 104 60
8K 59 15
32K 21 3
128K 6 0 — doesn't fit

The two stacks

Keras serves Gemma through keras_hub:

import os os.environ["KERAS_BACKEND"] = "jax" # or "torch" / "tensorflow" import keras_hub gemma = keras_hub.models.Gemma3CausalLM.from_preset("gemma3_4b_en") print(gemma.generate("Explain attention in one sentence.", max_length=64)) 

That is the whole serving path: load the preset, call generate(). It runs anywhere Keras 3 runs — GPU, TPU via JAX, even CPU for the 1B — and the same code that fine-tuned the model (GDE #16) now serves it. What it does not give you: an HTTP server (you write the FastAPI wrapper), continuous batching (one prompt at a time, or a static list), paged KV management, prefix caching, or structured output. Every request reads the full 8 GiB of weights, generates its tokens, and exits.

vLLM serves the same weights as a production server:

vllm serve google/gemma-3-4b-it --max-model-len 131072 curl http://localhost:8000/v1/chat/completions -d '{ "model": "google/gemma-3-4b-it", "messages": [{"role": "user", "content": "Explain attention in one sentence."}]}' 

One command buys an OpenAI-compatible API, continuous batching, PagedAttention, prefix caching, chunked prefill, and speculative decoding (EAGLE/MTP — GDE #5). The cost is operational: a server process to run, monitor, and scale, and GPU-first kernels (TPU support exists but trails — GDE #8).

Two architectures: Keras generates one prompt at a time through a single generate() call, with requests waiting in line; vLLM runs an OpenAI-compatible server with continuous batching and PagedAttention, serving the whole batch in one forward pass.

The benchmark: where the gap actually lives

Here is the measurement that decides the post, from an independent head-to-head published in November 2026 (xbill, Gemma 4 E2B on one NVIDIA L4, same prompts, same weights, greedy decoding):

  • One request: five engines — vLLM, SGLang, llama.cpp, mistral.rs, and a plain PyTorch loop — land within 8% of each other, 135–145 tok/s. At batch size 1, decode is memory-bandwidth bound: every token reads all the weights once, and no engine can dodge that. Keras' generate() lives in this regime too.
  • 64 concurrent requests: vLLM reaches 3,716 tok/s. The single-request engines don't move — they serve one request at a time, so their ceiling is the single-request rate. vLLM's continuous batching amortises one weight read across 64 sequences.

The same author measured the same shape on a Cloud TPU v5e: vLLM at 143.9 tok/s for one request, 1,689 tok/s at 64 — an 11.7x rise on a much smaller chip. The pattern is hardware-independent; only the ceiling moves.

Fitting a saturating curve T(N) = Tmax · N / (N + K) to the two L4 anchors (140 at N=1, 3,716 at N=64) gives the full picture — recomputed in the notebook:

Concurrent requests vLLM (tok/s) Keras (tok/s) Ratio
1 140 140 1.0x
2 274 140 2.0x (1.96x — just under the 2x line)
3 402 140 2.9x
8 968 140 6.9x
16 1,677 140 12.0x
32 2,644 140 18.9x
64 3,716 140 26.5x

The crossover is the headline: vLLM is 2x Keras at just 3 concurrent requests. You do not need a viral launch to justify a serving engine. Three users at once is enough. Sustained over a day, that's 12.1M tokens for the single-request stack vs 321M for the batched one — same GPU, same weights, same electricity.

Total throughput vs concurrent requests: Keras stays flat at 140 tok/s; vLLM rises from the same 140 to 3,716 tok/s at 64 requests. Red dots are the published measurement anchors; the crossover to 2x is at 3 concurrent requests.

The scoreboard

Keras generate() vLLM 0.33
Single-request decode ~140 tok/s ~140 tok/s — a tie
Max concurrent 8K sequences, one 24 GB card 1 (serialized) 59 (KV-bound)
Output tokens/day, sustained 12.1M 321M
HTTP API Write your own OpenAI-compatible, built in
Continuous batching No Yes
Prefix caching No Yes
Structured output Manual Guided decoding, built in
TPU serving Yes, via JAX backend Yes, but kernels trail GPU
Ops burden A script A server to run and monitor
Best for Local/dev, single-user, fine-tune-then-serve Multi-user APIs, 3+ concurrent

Scoreboard: max concurrent 8K sequences on one 24 GB card (1 vs 59), sustained tokens per day (12.1M vs 321M), single-request decode rate (a tie at ~140 tok/s).

Why it breaks: three ways to pick wrong

Serving a multi-user API with a library. The failure mode is silent: everything works in testing (one user, one request), then latency explodes at launch because requests serialise. If your p99 budget assumes parallelism, you need a stack that actually parallelises. The tell is the queue: if requests ever wait for each other, you are running a library, not a server.

Running a server for one user. The opposite mistake. A vLLM server for a single-user local app buys you an ops burden — process supervision, health checks, GPU memory pre-allocation — for a 1.0x speedup. If concurrency never exceeds 2, Keras is simpler, cheaper to operate, and exactly as fast.

Forgetting the KV budget. Both stacks share the same KV arithmetic, and 128K context is where it bites. Six concurrent 128K sequences fit on a 24 GB card with Gemma 3; a full-attention model fits zero. The fix is architectural (sliding windows, GQA, quantization — GDE #6 covered FP8 KV) before it is operational.

Takeaways

  • At 1 request, vLLM and Keras tie at ~140 tok/s — decode is memory-bandwidth bound and no engine dodges the weight read. Pick on workflow, not speed, at this scale.
  • At 3 concurrent requests vLLM is already 2x; at 64 it is 26.5x (3,716 vs 140 tok/s, measured on one L4). Batching is the whole gap.
  • Gemma 3's 5:1 local/global attention cuts 128K KV cache 6.5x (17.0 → 2.61 GiB) — the reason 128K context and 59 concurrent 8K sequences fit on one 24 GB card.
  • Keras wins when the user count is 1, the stack is already Keras, or the hardware is a TPU — and when you would rather write ten lines than operate a server.
  • vLLM wins the moment a second and third user arrive — the crossover is that low, and the OpenAI-compatible API is free with it.

Honesty note: the KV arithmetic is exact, from Gemma 3's published config (tech report arXiv:2503.19786). The throughput anchors are published measurements by xbill (Nov 2026) on Gemma 4 E2B — one NVIDIA L4 and one Cloud TPU v5e — not Gemma 3 4B; the notebook fits a saturating model to those anchors and labels the curves as a calibrated model, not a live run on this machine (no GPU was available here). Gemma 4 E2B shipped in November 2026 (2B active of 26B, MoE); the serving story is unchanged and vLLM 0.33 serves it. Single-request rates of 135–145 tok/s across engines are the same author's measurements. No excluded-vendor content, per the standing exclusion.

Companion notebook: the runnable tutorial for this post — download it here (open in Colab/Jupyter).