FP8 KV Cache: Memory Savings and Quality Checks

Vladimir Lomtev•
FP8 KV Cache: Memory Savings and Quality Checks

Storing the KV cache in FP8 instead of FP16 or BF16 cuts its size by about half, because each value takes 1 byte instead of 2. On the same GPU, you can fit roughly twice as many context tokens or simultaneous conversations. The model weights do not change. Quality may shift slightly, so before enabling this in production, you need a side-by-side test on your own workloads.

Prepared by Vladimir Lomtev’s AI Studio on November 16, 2026, for engineers running LLMs on vLLM, SGLang, or llama.cpp and hitting GPU memory limits. Parameters were verified against engine documentation and the llama.cpp v1.0.0 release notes. We did not perform our own quality or speed measurements. All calculations in this article are approximate and show order-of-magnitude estimates.

Contents

What exactly is being compressed

An LLM running on a server has three main GPU memory consumers: model weights, KV cache, and auxiliary buffers. Weight quantization, for example GGUF Q4 or AWQ, reduces the first part. Compressing the KV cache reduces the second — the memory that grows with context length and the number of concurrent requests. These are independent settings: you can keep the weights in BF16 and the cache in FP8, or the other way around. How weight quantization works is covered in the article “LLM Quantization in Practice”.

Compressing the cache makes sense when the model already fits, but there is not enough room for long contexts or parallel users. If the weights themselves do not fit, an FP8 cache will not solve that problem. The diagnostic order is described in the article “When an LLM Does Not Fit in GPU Memory”.

How much memory FP8 saves: the math

KV cache size per token for a model with GQA:

2 × number of layers × number of KV heads × head size × bytes per value

Let’s use a hypothetical configuration typical for 8B models: 32 layers, 8 KV heads, head size 128.

Cache format Bytes per value Size per token Tokens in a 20 GiB pool 8192-token sessions
FP16 / BF16 2 128 KiB 163,840 20
FP8 1 64 KiB 327,680 40

Calculation: 2 × 32 × 8 × 128 × 2 = 131,072 bytes = 128 KiB; 20 GiB / 128 KiB = 163,840 tokens; 163,840 / 8192 = 20 sessions. For FP8, all values are twice as good. Real capacity will be slightly lower because of scale factors, block alignment, and the fact that the engine reserves part of the memory for activations.

The doubling applies only to the KV cache pool. If 16 GB of a 24 GB GPU are occupied by weights, transitioning to FP8 will not create more free memory for the cache — it will simply double the number of tokens that fit into the same gigabytes.

E4M3 and E5M2: which FP8 format to choose

FP8 comes in two main variants. E4M3 uses four bits for the exponent and three for the mantissa: higher precision, narrower range. E5M2 uses five bits for the exponent and two for the mantissa: wider range, lower precision. For storing attention values, precision is usually more important, so E4M3 with scale factors appears more often in the documentation.

A scale factor maps values into a range that FP8 can represent without overflow loss. Without it, values are stored as-is. The vLLM documentation on quantized KV cache says that with fp8 without calibration, all scale factors are 1.0, and the SGLang arguments reference explicitly warns that default 1.0 scale factors can cause accuracy issues and recommends passing a file with them.

How to enable an FP8 cache in different engines

Engine Parameter FP8 values Scale factors
vLLM --kv-cache-dtype fp8, fp8_e4m3, fp8_e5m2 and others Calibration via llm-compressor, default 1.0
SGLang --kv-cache-dtype fp8_e4m3, fp8_e5m2 File --quantization-param-path
llama.cpp -ctk, -ctv f8_e4m3 starting with version 1.0.0 Optional static per-tensor scale factors

vLLM

By default --kv-cache-dtype auto, which means the cache is stored in the model’s data type. The documentation says that fp8_e4m3 is supported on CUDA 11.8+ and ROCm, fp8_e5m2 is supported on CUDA 11.8+. The engine’s argument reference lists more options, including 4-bit ones; support depends on the GPU and version.

vllm serve Qwen/Qwen3-8B \
  --host 127.0.0.1 --port 8000 \
  --api-key "$VLLM_API_KEY" \
  --kv-cache-dtype fp8 \
  --kv-cache-dtype-skip-layers sliding_window

The parameter --kv-cache-dtype-skip-layers keeps sensitive layers, such as sliding-window attention layers, in the original data type. The vLLM documentation marks calibration of scaling factors on a dataset through llm-compressor as the recommended approach, using a tensor-wise or attention-head-wise strategy. Per-head scaling requires the Flash Attention backend.

SGLang

python3 -m sglang.launch_server \
  --model-path Qwen/Qwen3-8B --host 127.0.0.1 --port 30000 \
  --kv-cache-dtype fp8_e4m3 \
  --quantization-param-path ./kv_scales.json

The path ./kv_scales.json is just an example. The file with scaling factors is obtained through calibration or taken from the model repository if the author published it.

llama.cpp

In the llama-server description for -ctk and -ctv the following values are listed: f32, f16, bf16, f8_e4m3, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1; the default is f16. FP8 was added in release v1.0.0 on November 13, 2026, along with optional static tensor-wise scales. Keys and values can be quantized differently:

llama-server -m ./models/model-Q4_K_M.gguf \
  --host 127.0.0.1 --port 8080 \
  -c 32768 -np 4 \
  -fa on \
  -ctk f8_e4m3 -ctv f8_e4m3

llama.cpp has long supported integer cache variants as well q8_0 and q4_0. They also save memory, but this is a different quantization scheme. Compare them to FP8 on the same test set, not by name alone.

How to check that quality did not drop

The engine documentation does not provide a universal estimate of quality loss: it depends on the model, context length, and task. So you need to test on your own data.

  1. Build a test set. 100–300 real queries from your use cases with reference answers or evaluation criteria. Add long documents close to your maximum working context.
  2. Lock the conditions. The same model and engine version, temperature 0, identical generation parameters. Only the cache type changes.
  3. Compare the answers. The share of answers that match the reference or pass validation; for structured output, the share of valid JSON; for document search, whether the needed fact is found at different context depths.
  4. Compare token distributions. In llama.cpp, there is a utility for this llama-perplexity: according to its README the logits from the reference run are saved with --kl-divergence-base and the --kl-divergence flag calculates the divergence from them. The smaller the divergence, the closer the behavior is to the original cache.
  5. Check speed and capacity. How many simultaneous requests the server can handle before the queue grows, using the method from the article on load testing a local LLM.
  6. Decide based on a threshold. Write down in advance what drop in the metric is acceptable, for example no more than one percentage point in correct-answer rate, and compare it with the result.

Example of calculating KL divergence in llama.cpp:

# reference run with an f16 cache, logits are saved to a file
llama-perplexity -m ./models/model-Q4_K_M.gguf -f ./eval.txt -c 4096 \
  -ctk f16 -ctv f16 --kl-divergence-base ./base.kld
# run with an FP8 cache and comparison to the reference
llama-perplexity -m ./models/model-Q4_K_M.gguf -f ./eval.txt -c 4096 \
  -fa on -ctk f8_e4m3 -ctv f8_e4m3 \
  --kl-divergence-base ./base.kld --kl-divergence

Perplexity and KL divergence show distribution shift, but they do not replace testing on your own tasks. A model may slightly change the probabilities and still answer just as correctly, and vice versa. How to build your own evaluation set is described in the article on your own benchmark for choosing an LLM.

Where an FP8 cache is riskier

  • Very long context. Rounding errors accumulate in the attention mechanism, and factual retrieval near the end of a long document suffers sooner than a short dialogue.
  • Tasks with exact answers. Code, calculations, and extraction of details from documents where a single wrong digit makes the answer incorrect.
  • Models with special layers. Sliding window, hybrid architectures, models where the author has already defined a special cache format. For these, check the recommendations in the model card.
  • No scaling factors. Default values of 1.0 are the simplest and riskiest option.

Speed: what to expect

An FP8 cache reduces the amount of data that has to be read at each generation step and allows more requests to be packed into a batch. That can increase throughput. But the end result depends on whether your GPU and attention backend support FP8 calculations directly or spend time converting formats. The vLLM documentation, for example, notes that with the Flash Attention 3 backend, the requests are quantized in FP8 as well. Without measuring on your own hardware, do not promise speedup; promise only capacity.

Frequently asked questions

Are FP8 cache and FP8 weights the same thing? No. FP8 weights shrink the model, while an FP8 cache reduces memory for context. They are enabled with different parameters and tested separately.

Can you enable an FP8 cache on any GPU? vLLM and SGLang note a CUDA 11.8+ requirement for FP8, and some formats and backends require newer GPUs and CUDA versions. In llama.cpp, support depends on the build backend. Check with a test run and engine logs.

Which should you choose: FP8 or q8_0 in llama.cpp? Both formats take about one byte per value. Choose based on the result of the same quality and speed test on your model.

Do you need to change the application? No, the API stays the same. Only the server launch parameters change and, if you’re lucky, the maximum number of parallel requests.

How Vladimir Lomtev’s AI studio helps with FP8 cache setup

Vladimir Lomtev’s AI studio deploys and configures LLMs on company servers. For KV cache compression, that means:

  • calculating how much context and how many concurrent users the business scenario needs, and how much memory that requires;
  • building a test set from real requests and comparing quality with the original cache and with FP8;
  • selecting the format, scaling factors, and engine parameters for the specific model and GPU;
  • running load testing and giving the team criteria for rolling back the configuration.

The first step is to choose one scenario where there is currently not enough context or concurrency, and record the quality metric that must not get worse. Discuss the project.

Bottom line: FP8 doubles cache capacity, and quality must be proven

FP8 cuts KV cache size in half and lets you keep more context on the same GPU. It is one of the cheapest memory optimizations, but it is not free. Enable it with scaling factors, leave sensitive layers in the original type, and make the decision based on testing on your own workloads, not on the format name.

Request an audit

Share your contact details and we will follow up.

← All articles

Comments (0)

Loading comments…

Leave a comment
No registration required

Book a strategy call
for agentic operations

Tell us which workflow you want to improve. We will map feasibility, risks, and the fastest MVP path.

By submitting, you agree to our privacy policy

Contacts

Global Operations

Serving U.S. clients remotely
with private cloud and on-prem options

Strategy calls by request

We respond after reviewing your workflow context.

info@agentsunrise.pro

For partnership inquiries

Have a proposal?

Write to us in messengers

© 2026 AgentSunrise