What this thread does
Enable cache_implementation="quantized" with cache_config={"backend": "fp8"} and remove integer-backend cache options before testing generation.
What changed
The 5.21.0 release adds FP8 to QuantizedCache. PyPI confirms the 5.21.0 upload on October 26, 2026; checked 2026-10-28.
Do first: python -m pip show transformers
1. Check python -m pip show transformers. Use 5.21.0 for this recipe, with an already working causal-language-model generation path. This cache supports models containing only full-attention layers; a working generation path alone does not establish compatibility. 2. Keep your existing model, tokenized inputs, prompt and generation length fixed. Change only the cache arguments:
outputs = model.generate(
**inputs,
max_new_tokens=64,
cache_implementation="quantized",
cache_config={"backend": "fp8"},
)
3. Remove nbits, axis_key, axis_value, q_group_size and residual_length from this configuration. The official cache guide says FP8 rejects them; it uses per-tensor scaling and needs no extra quantizer dependency. 4. Compare with your existing cache on representative short and long prompts. Record end-to-end latency, peak device memory and task quality separately. Keep FP8 only if the result meets your application's memory and quality targets.
Choose what to keep
| Option | What it is for; when it wins | When it loses; limit checked 2026-10-28 | Pick this if |
|---|---|---|---|
| FP8 cache | Lower-precision KV storage without an additional quantizer | Integer-backend options are invalid; quantization can increase latency | You want to evaluate the new backend |
| Your existing cache | A baseline with established behavior | May miss a useful memory tradeoff | It already fits and latency matters most |
This changes KV storage, not model weights. The official cache guide warns that quantization can hurt latency for short contexts when memory is sufficient. PR #48677 explains that FP8 states are dequantized before attention; enabling this backend does not itself enable low-precision attention kernels.
Recommendation by constraint
For a solo user, keep the existing cache unless memory pressure justifies measurement. For a small team serving long prompts, evaluate FP8 on the actual prompt distribution. For enterprise inference, retain the current cache as a rollback setting and require latency, memory and quality acceptance results. These recommendations do not promise a cost reduction or a particular memory saving.
Evidence
In issue #48608, jiqing-feng asked “FP8 KV cache + flash-attention: is this in scope?” on September 8, 2026. That request concerns a broader attention path than this recipe provides.
In PR #48677, jiqing-feng reported “Latency is 16% higher” in the September 10, 2026 opening post, using one model, prompt and A100 setup. This is the contributor's benchmark, not a rerun or a general result. Both sources share an author.
Prompt for your agent
Preserve the model weights and prompt, add the FP8 cache settings, remove incompatible integer tuning, and compare representative prompts with our existing cache. Report installed versions, latency, peak memory and quality regressions before recommending a default.
Mistakes
Do not carry an integer quantizer's options into FP8. Do not interpret smaller cache storage as an equal drop in peak application memory. Do not infer attention-kernel acceleration from the backend name.
Limits
No model was loaded and no hardware benchmark was run. This is a cache setup recipe, not the complete 5.21 upgrade: it does not cover custom TP/EP plans or earlier breaking changes. Model-specific compatibility and end-to-end savings must be measured for the intended deployment.
Started from a post by @Cyrilvallez, packaged by the editor. Original post