FP8 KV Cache: Fit More Requests on a GPU

Quantizing the KV cache to FP8 halves its memory, so one GPU holds longer contexts and more concurrent requests. How FP8 KV cache works in vLLM, and its limits.

You quantized the weights and the card still runs out of room. This is a common second surprise. You dropped a model to INT8 or AWQ, the weights shrank, and for a while throughput went up. Then traffic grew, or someone started sending longer prompts, and the server went back to turning requests away. The weights were never the part that scaled with load. The KV cache is, and on most setups it is still sitting in 16-bit while everything around it has been cut down.

This post is for engineers serving an open model behind vLLM or a similar engine, who have already picked a quantized checkpoint and are now bumping into a concurrency or context-length ceiling. FP8 KV cache is a separate, independent lever from weight quantization, and it is often the one actually standing between you and more simultaneous requests. It is also not free, so it is worth knowing where it helps and where it quietly costs you.

The cache is the part that scales with load

I wrote the full version of this in why GPU memory runs out, so here is the short one. A transformer keeps the keys and values of every past token so it does not recompute them at each decode step. That store is the KV cache, and its size is one formula times two numbers you do not fully control:

bytes/token = 2 x num_layers x num_kv_heads x head_dim x dtype_bytes

The two numbers that move are context length and batch size. Both are linear. A Llama-2-7B token in fp16 costs about 512 KB of cache, so a single 4,000-token conversation is 2 GB, and a batch of eight of them is 16 GB, more than the weights themselves on that model. The weights are a fixed cost you pay once at load. The cache is the variable cost you pay again for every token of every concurrent request, and it is what decides how many users fit on the card at once.

Weight quantization does nothing for that variable cost. It shrinks the fixed block and frees headroom, but the thing eating the headroom back is still stored at full width. If you want the cache itself to take less room, you have to quantize the cache, and the most common way to do that today is FP8.

FP8 is one byte instead of two

The last term in that formula, dtype_bytes, is the one FP8 attacks. Store each key and value in an 8-bit float instead of a 16-bit one and every value drops from two bytes to one. The whole cache halves. Nothing about the model architecture changes; this is a serving-time decision about how the cache is stored in memory.

There are two 8-bit float formats in circulation, and the names tell you the layout. Both spend one bit on sign and split the other seven between exponent (range) and mantissa (precision), as laid out in NVIDIA’s FP8 Formats for Deep Learning (Micikevicius et al., 2022).

One cache value stored three ways: fp16 as a sign bit, 5 exponent bits and 10 mantissa bits reaching about 65504; fp8 E4M3 as a sign bit, 4 exponent and 3 mantissa bits with a maximum value of 448; fp8 E5M2 as a sign bit, 5 exponent and 2 mantissa bits with a maximum value of 57344. More exponent bits buy range, more mantissa bits buy precision, and at eight bits total you cannot have both.

E4M3 keeps four exponent bits and three mantissa bits. It reaches a maximum magnitude of 448 and spends the rest of its bits on precision. E5M2 keeps five exponent bits and two mantissa bits, reaching 57,344 but with coarser steps between representable numbers. For KV cache, E4M3 is the usual pick, because the keys and values you are storing sit in a fairly narrow range and you would rather spend bits resolving nearby values than reaching numbers that never occur.

The catch with E4M3 is the one that trips people up: its range is small. To represent the actual spread of a tensor, FP8 quantization pairs each tensor with a higher-precision scaling factor, usually kept in FP32, that stretches the 8-bit values onto the real distribution. Get that scale wrong and you either clip the large values or waste resolution on a range nothing uses. More on that below, because it is where the quality cost lives.

This is a different operation from the weight quantization you may already have on. That compresses the static weights once, offline. FP8 KV cache compresses a buffer that is written fresh on every decode step, at serving time. They are orthogonal: you can run an AWQ-weighted model with an fp16 cache, or a full-precision model with an fp8 cache. Because they hit different parts of the memory budget, you usually want both.

What the extra byte buys you

Half the cache per token means twice the tokens in the same space. On a 24 GB card running Llama-2-7B, the fp16 weights take roughly 14 GB, leaving about 10 GB for cache. At 512 KB per token that is around 20,000 tokens of cache; at 256 KB it is around 40,000.

A bar chart comparing cache capacity on a 24 GB GPU running Llama-2-7B. An fp16 cache at 512 KB per token fits about 20,000 tokens; an fp8 cache at 256 KB per token fits about 40,000, roughly twice the room. The headroom can go to longer contexts or more concurrent requests.

That doubled headroom is a budget you get to spend, and the two things you can spend it on pull against each other. You can serve longer contexts, holding one big conversation that would not have fit before. Or you can keep the context the same and batch twice as many requests, which is the win that matters for a busy endpoint because continuous batching turns free cache directly into higher concurrency. The vLLM docs frame the benefit exactly this way: a smaller cache footprint means more tokens held, which means more throughput.

Worth being precise about one thing. FP8 KV cache saves memory; it is not primarily a compute speedup. The decode step is memory-bound, so a smaller cache can mean less data moved per step and some latency benefit, but the headline reason to turn it on is capacity. If your card has spare memory and you are not concurrency-limited, FP8 cache buys you less than you would hope.

Turning it on in vLLM

The flag is kv_cache_dtype. Left at auto the cache matches the model’s dtype, which is the fp16 default. Set it to fp8 (an alias for fp8_e4m3) or fp8_e5m2 and the cache is stored in that format:

from vllm import LLM

llm = LLM(
    model="meta-llama/Llama-2-7b-chat-hf",
    kv_cache_dtype="fp8_e4m3",   # or "fp8", or "fp8_e5m2"
)

The same flag exists on the server:

vllm serve meta-llama/Llama-2-7b-chat-hf \
  --kv-cache-dtype fp8_e4m3

That works out of the box, but it uses a default scaling factor of 1.0 for every tensor, which is the setting most likely to cost you accuracy. The scale is what maps the real distribution of your keys and values onto the narrow FP8 range; a flat 1.0 is a guess that happens to be wrong for most models. To do it properly you calibrate the scales on a sample of representative data, which is a short offline pass. vLLM points at LLM Compressor for this: you run the model over a calibration set, it measures the activation ranges, and it writes out per-tensor FP8 scales baked into the checkpoint. Serve that checkpoint and the cache quantizes against measured scales instead of a placeholder. If you only remember one operational detail from this post, make it this one. Uncalibrated FP8 cache is the version people benchmark, see a quality drop on, and wrongly conclude FP8 is not worth it.

The flags and the exact connector support move between vLLM releases, so check the quantized KV cache docs for your version before copying anything into production.

Where it bites

FP8 cache is well-behaved, but it has edges worth knowing before you ship it.

Accuracy is “usually fine,” not “always fine.” The vLLM docs report that E4M3 typically degrades inference accuracy only minimally, and that matches most people’s experience. But “typically” is doing work in that sentence. The right move is to measure it, the same way you would any other change to the model’s outputs. Run your eval set with the cache on and off and compare. Treat it as a quality change to verify, not a config toggle to assume.

Long contexts feel it first. Quantization error on the cache is per-token, and it accumulates over a long sequence. A short chat may show no measurable difference while a 30,000-token document-grounded answer does. If your product leans on very long contexts (exactly the case where you most want the memory back), that is the case you most need to evaluate, not skip.

Per-tensor scales are the current limit. vLLM supports per-tensor (one scale per tensor) scaling for FP8 cache. Research like KIVI (Liu et al., ICML 2024) shows finer-grained schemes do better, with keys quantized per channel and values per token, which is roughly why 2-bit cache is a research topic while 8-bit is a production default. If plain FP8 costs you more quality than you can accept, finer granularity is the direction, but it is not a flag you flip today.

FP8 is not two levers. Quantizing the cache and quantizing the weights are independent, but they are also both “lossy compression of the model’s numbers.” Stacking an aggressive weight quantization with an uncalibrated FP8 cache compounds the error. If you run both, which is normal, evaluate the combination, not each piece alone.

What I would check first

The order I reach for cache levers has not changed much, and FP8 slots into the middle of it rather than the top.

  1. Serve on an engine that pages the cache. PagedAttention (Kwon et al., SOSP 2023) recovers the 60 to 80% of cache memory that older servers wasted to fragmentation. That is the biggest single win and it costs nothing in quality.
  2. Prefer a grouped-query-attention model, which shrinks the cache by cutting KV heads and is free at serving time.
  3. Then turn on FP8 cache, but calibrate the scales and run your evals before and after.
  4. Only after that, spend real engineering effort trimming context in the application: retrieving fewer, tighter chunks, or summarizing old turns instead of replaying them.

The first two are close to free. FP8 is nearly free but asks for one calibration pass and one evaluation. The last one is actual work, and it is where an application engineer has the most control, so I save it for when the cheaper levers have run out.

This is the kind of arithmetic I spend my days on now, building dedicated inference for open models, and it was the same shape of problem behind Archi, the retrieval copilot I worked on for CMS operations at CERN. Archi’s answers pulled in logs and documents, so a single request could run to many thousands of tokens of context. That is precisely the workload where the cache, not the weights, sets your ceiling, and precisely where halving it earns its keep. The honest first question was always whether a free lever closed the gap. When it did not and the contexts were long, FP8 cache was the next thing I tried, with the evals to back it up.

This post is part of my guide to inference engineering, which covers what an inference engineer does and where techniques like this one fit.


Diagrams by M. Hassan Ahmed, released under CC0. No external image was used in this post.