Skip to content
MAMasterAI Now
Fundamentals14 min read

KV Cache Quantization Explained: FP8, INT8 and Memory Trade-Offs

Learn how KV cache quantization works, compare FP8 and INT8, and understand how reduced precision saves GPU memory during LLM inference.

By MasterAI Now Team

KV Cache Quantization Explained: FP8, INT8 and Memory Trade-Offs

Running a large language model locally can be surprisingly difficult, even when the model itself appears to fit inside your GPU memory.

You load a model, send a short prompt, and everything works. Then you start a longer conversation. The GPU memory usage increases, generation becomes slower, and eventually the application runs out of memory.

The problem may not be the model weights. It may be the KV cache.

The Key-Value cache is an important part of Transformer inference. It stores intermediate attention information so that a model does not need to recalculate everything when generating each new token.

However, this cache consumes GPU memory. As conversations become longer and more requests run simultaneously, its memory requirements can become substantial.

One way to reduce this overhead is KV cache quantization.

Instead of storing cached values using higher-precision numerical formats, the inference system stores them using lower-precision representations such as FP8 or INT8.

This can reduce memory consumption and increase the number of requests that fit on a GPU. But there is a trade-off: lower precision can introduce numerical errors that affect model behavior.

Understanding this trade-off is essential for developers working with local LLMs, inference servers, and GPU-constrained environments.

What Is the KV Cache in a Transformer?

To understand KV cache quantization, it helps to understand how attention works.

Transformer models use an attention mechanism to determine which parts of the input are relevant when processing a token.

During attention calculations, the model produces three important representations:

  • Query (Q)
  • Key (K)
  • Value (V)

Queries are compared with keys to determine attention scores. Those scores are then used to combine value representations.

A simplified attention equation is:

[ Attention(Q,K,V)=softmax\left(\frac{QK^T}{\sqrt{d_k}}\right)V ]

Here, (d_k) represents the dimensionality of the key vectors.

During autoregressive generation, a language model produces one token at a time.

Without caching, the model would repeatedly calculate key and value representations for previously processed tokens.

This creates unnecessary computation.

The KV cache solves this problem by storing previously calculated key and value tensors.

When a new token arrives, the model calculates its new representations and reuses the cached information from earlier tokens.

Instead of recalculating the entire history, the model only needs to process the new token and attend to the stored keys and values.

This makes generation more efficient.

Why Does KV Cache Consume So Much GPU Memory?

The KV cache grows as the sequence becomes longer.

It also depends on the model architecture, number of layers, attention heads, head dimensions, batch size, and numerical precision.

A simplified estimate for standard multi-head attention is:

[ M=2 \times L \times B \times S \times H_{kv} \times D \times P ]

Where:

  • (L) = number of Transformer layers
  • (B) = batch size
  • (S) = sequence length
  • (H_{kv}) = number of key-value heads
  • (D) = head dimension
  • (P) = bytes per stored element
  • The factor 2 represents keys and values.

Let's use an example.

Imagine a model with:

  • 32 Transformer layers
  • 8 KV heads
  • 128 dimensions per head
  • 8,192 tokens
  • Batch size of 1
  • FP16 storage (2 bytes per element)

The estimated cache size is:

[ 2 \times 32 \times 1 \times 8192 \times 8 \times 128 \times 2 ]

The result is:

[ 1,073,741,824 \text{ bytes} ]

That is approximately 1 GiB of KV cache.

This is only an illustrative calculation. Actual memory requirements depend on the model implementation, attention architecture, cache layout, and additional runtime overhead.

Now imagine increasing the sequence length from 8,192 to 32,768 tokens.

The cache requirement becomes approximately four times larger.

This explains why long-context inference can become memory-intensive even when the model weights remain unchanged.

What Is KV Cache Quantization?

Quantization is the process of representing numerical values using a lower-precision format.

In deep learning, model weights and intermediate activations are often stored using formats such as FP32, FP16, BF16, INT8, and FP8.

KV cache quantization applies this idea specifically to the cached key and value tensors.

For example, a cache originally stored in FP16 uses two bytes per element.

If the same values are stored using an 8-bit representation, the storage requirement for the underlying values can be reduced to one byte per element.

In an idealized comparison:

FormatStorage per elementRelative storage
FP324 bytes100% baseline
FP162 bytes50%
BF162 bytes50%
FP81 byte25%
INT81 byte25%

These percentages compare raw element storage against FP32. They do not include scales, zero points, alignment, metadata, or implementation overhead.

The important point is that quantization can reduce the memory required to retain attention information.

This does not necessarily mean the model's weights are being quantized. KV cache quantization is a separate optimization.

A model can use FP16 weights while maintaining its KV cache in FP8 or INT8, depending on the inference engine and hardware support.

FP8 vs INT8: What Is the Difference?

FP8 and INT8 are both 8-bit representations, but they describe numbers differently.

FP8: Floating-point representation

FP8 uses a limited floating-point representation.

Depending on the implementation, common FP8 formats include:

  • E4M3
  • E5M2

E4M3 uses four exponent bits and three mantissa bits, while E5M2 uses five exponent bits and two mantissa bits.

The exponent determines the approximate magnitude range, while the mantissa controls precision.

This creates a trade-off between numerical range and precision.

E4M3 provides greater precision within a smaller range. E5M2 provides a wider numerical range with less precision.

FP8 can be useful for KV cache storage because it retains floating-point behavior while reducing the number of bits used per element.

However, FP8 is not automatically supported by every GPU or inference framework.

Hardware capabilities and kernel implementations matter.

INT8: Integer representation

INT8 stores values using signed 8-bit integers.

A floating-point value is mapped into a discrete integer range using a scaling factor.

A simplified symmetric quantization formula is:

[ q=round\left(\frac{x}{s}\right) ]

And the reconstructed value is:

[ \hat{x}=q \times s ]

Where:

  • (x) is the original value.
  • (q) is the quantized integer.
  • (s) is the scaling factor.
  • (\hat{x}) is the reconstructed approximation.

For asymmetric quantization, a zero-point may also be used.

INT8 can provide efficient storage and computation, but the quality of quantization depends on the distribution of the original values and the scaling strategy.

Which one is better?

There is no universally better choice.

FP8 may be attractive when the hardware and inference engine provide efficient native support.

INT8 may be useful in systems with mature integer quantization implementations.

The right choice depends on hardware, software compatibility, numerical accuracy, and actual workload performance.

It is important not to assume that two 8-bit formats will produce identical results.

How Much GPU Memory Can KV Cache Quantization Save?

Let's return to the earlier example.

We calculated approximately 1 GiB of KV cache using FP16.

If the underlying cached values are represented using an 8-bit format instead, the idealized storage requirement becomes approximately 512 MiB.

Illustrative comparison, excluding quantization metadata and runtime overhead.

<|-- comparison table --|>

Cache formatApproximate memory
FP322 GiB
FP161 GiB
BF161 GiB
FP8512 MiB
INT8512 MiB

This represents a 50% reduction when moving from FP16 to an 8-bit representation.

For a single short request, this may not seem particularly important.

But consider a server handling 16 concurrent conversations, each with an 8,192-token context.

The difference can become substantial.

Reducing cache memory can make it possible to:

  • Support longer conversations.
  • Increase concurrent request capacity.
  • Reserve more GPU memory for model execution.
  • Reduce the risk of out-of-memory errors.
  • Improve the utilization of available hardware.

Actual throughput improvements are workload-dependent. Quantization does not guarantee that every request will become faster.

Does KV Cache Quantization Reduce Model Quality?

This is where the trade-off becomes interesting.

Quantization introduces approximation error.

When a model stores a key or value using fewer bits, the original floating-point number cannot always be reconstructed exactly.

These differences affect attention calculations.

A small numerical error in one operation may be insignificant. But Transformer models perform many operations across multiple layers and tokens.

Depending on the model and workload, approximation errors may affect generated output.

Potential consequences include:

  • Slightly different generated text.
  • Reduced accuracy on long-context tasks.
  • Changes in retrieval from earlier parts of a conversation.
  • Different behavior on numerically sensitive tasks.

However, it would be incorrect to assume that every quantized cache causes a noticeable quality reduction.

Many quantization techniques are designed to preserve useful numerical information while reducing storage requirements.

The actual impact depends on the quantization format, scaling strategy, model architecture, and task.

A system used for ordinary chat may tolerate a configuration that performs poorly on long-context reasoning or code generation.

For production workloads, the only reliable approach is to benchmark the actual model and tasks.

What Are Per-Tensor, Per-Channel and Per-Head Quantization?

Not all quantization methods apply the same scaling strategy.

The scaling granularity determines how numerical values are grouped when calculating quantization parameters.

Per-tensor quantization

A single scale is used for an entire tensor.

This is relatively simple and can have low metadata overhead.

However, if the tensor contains values with significantly different numerical ranges, a single scale may not represent every region efficiently.

Per-channel quantization

Separate scales are calculated for individual channels.

This allows the quantization process to adapt to differences between channels.

It may preserve more useful information when different channels have different value distributions.

Per-head quantization

In attention-based models, separate scaling parameters can be maintained for individual attention heads.

This can be useful when different heads produce values with different numerical characteristics.

The trade-off is additional metadata and implementation complexity.

The best strategy depends on the tensor layout and the inference engine.

How KV Cache Quantization Works in Real Inference Engines

The implementation details vary between inference frameworks.

Some systems expose cache data types directly through configuration options. Others provide quantization settings or specialized cache implementations.

For example, vLLM provides KV cache configuration options that depend on its version and supported hardware.

Developers should check the documentation for the exact release they are using rather than assuming that every FP8 or INT8 option is available everywhere.

A simplified conceptual configuration might look like this:

# Illustrative configuration only.
# Exact options depend on the vLLM version and hardware.

from vllm import LLM

llm = LLM(
    model="your-model-name",
    kv_cache_dtype="fp8"
)

This is an example of selecting an FP8 cache type, not a complete universal deployment recipe.

Before using it, verify:

  • Whether the selected GPU supports the required operations.
  • Whether the model and attention backend support the cache format.
  • Whether the framework version exposes the option.
  • Whether additional scaling configuration is required.

Also remember that the model's weight precision and KV cache precision are independent configuration choices.

How to Benchmark KV Cache Quantization

A successful quantization experiment should measure more than GPU memory consumption.

Imagine comparing an FP16 cache against an FP8 cache.

You should run the same prompts, model, batch sizes, and generation settings under both configurations.

Useful measurements include:

1. Peak GPU memory

Measure the maximum allocated GPU memory during inference.

This shows how much memory the cache optimization actually saves.

2. Time to first token

Measure how long it takes before the model generates its first output token.

Prefill computation and cache preparation can affect this metric.

3. Time per output token

Measure how long the model takes to generate each additional token.

This is useful for evaluating generation performance.

4. Maximum context length

Check how long a request can become before memory limits are reached.

5. Concurrent request capacity

Measure how many simultaneous requests the system can handle.

6. Output quality

Run a representative evaluation set and compare task accuracy, long-context retrieval, and output consistency.

A simple experiment could use three configurations:

ExperimentModel precisionKV cache
BaselineFP16FP16
Experiment AFP16FP8
Experiment BFP16INT8

Keep the remaining variables as consistent as possible.

If you change the model, GPU, batch size, and cache format simultaneously, it becomes difficult to identify which change caused the observed difference.

Common Mistakes When Using KV Cache Quantization

Assuming 8-bit always means half the total GPU memory

KV cache quantization only reduces the memory occupied by the cached tensors.

Model weights, temporary activations, CUDA workspaces, and other allocations still consume memory.

The total GPU memory reduction will therefore depend on how much of the original memory usage came from the KV cache.

Confusing weight quantization with cache quantization

Quantizing model weights and quantizing KV cache are different operations.

A model can use 4-bit weights with an FP16 cache, or higher-precision weights with an FP8 cache.

They solve different memory problems.

Ignoring metadata overhead

Quantization scales, zero-points, and alignment requirements may consume additional memory.

Idealized calculations do not always match measured memory usage.

Benchmarking only short prompts

Short prompts may not expose the main benefits of KV cache optimization.

Longer sequences and concurrent requests provide a more useful evaluation.

Assuming every GPU supports every FP8 format

Hardware support varies across GPU generations and architectures.

Software support also depends on the inference engine and attention backend.

Always verify compatibility before deploying a configuration.

Frequently Asked Questions

What is KV cache quantization?

KV cache quantization reduces the numerical precision used to store the key and value tensors generated by Transformer attention layers. It can reduce GPU memory consumption during language model inference.

Does FP8 KV cache use less memory than FP16?

Yes. An FP8 representation generally uses one byte per element, compared with two bytes for FP16. This can reduce the raw storage requirement of the cached values by approximately 50%, excluding metadata and overhead.

Is INT8 better than FP8 for LLM inference?

Not universally. Both formats use eight bits, but their numerical representations differ. Performance and quality depend on hardware support, quantization strategy, and inference implementation.

Does KV cache quantization affect model weights?

No. KV cache quantization targets cached attention tensors rather than the model's stored parameters. Weight quantization is a separate optimization.

Can KV cache quantization improve inference speed?

It can improve performance in some environments by reducing memory bandwidth requirements and allowing more requests to fit in GPU memory. However, quantization overhead and hardware support can influence the result.

Does KV cache quantization help with long-context models?

Yes. Long sequences require more cached key and value information. Reducing the storage size can help accommodate longer contexts or additional concurrent requests within the available memory.

What is the difference between KV cache quantization and weight quantization?

Weight quantization reduces the precision of the model's learned parameters. KV cache quantization reduces the precision of intermediate attention information stored during inference.

Should I use FP8 KV cache in production?

Only after checking hardware compatibility and evaluating the model on representative workloads. Measure memory usage, generation performance, concurrency, and output quality before choosing a production configuration.

Final Thoughts

KV cache quantization addresses one of the practical limitations of running large language models: the amount of GPU memory required to retain attention information during generation.

FP8 and INT8 representations can significantly reduce the storage required by cached keys and values compared with FP16.

However, the best configuration depends on more than the number of bits. Numerical accuracy, quantization granularity, hardware support, and inference software all influence the outcome.

For developers working with local LLMs, understanding KV cache behavior is an important step toward building more efficient inference systems.

The most useful optimization is not necessarily the one that produces the smallest cache. It is the one that provides a good balance between memory consumption, generation performance, and output quality.