INT4/INT8 KV Cache

April 16, 2026 ยท View on GitHub

Since v0.4.0, LMDeploy has supported online key-value (kv) cache quantization with int4 and int8 numerical precision, utilizing an asymmetric quantization method that is applied on a per-head, per-token basis. The original kv offline quantization method has been removed.

Intuitively, quantization is beneficial for increasing the number of kv block. Compared to fp16, the number of kv block for int4/int8 kv can be increased by 4 times and 2 times respectively. This means that under the same memory conditions, the system can support a significantly increased number of concurrent operations after kv quantization, thereby ultimately enhancing throughput.

However, quantization typically brings in some loss of model accuracy. We have used OpenCompass to evaluate the accuracy of several models after applying int4/int8 quantization. int8 kv keeps the accuracy while int4 kv has slight loss. The detailed results are presented in the Evaluation section. You can refer to the information and choose wisely based on your requirements.

LMDeploy inference with quantized kv supports the following NVIDIA GPU models:

  • Volta architecture (sm70): V100
  • Turing architecture (sm75): 20 series, T4
  • Ampere architecture (sm80, sm86): 30 series, A10, A16, A30, A100
  • Ada Lovelace architecture (sm89): 40 series
  • Hopper architecture (sm90): H100, H200

In summary, LMDeploy kv quantization has the following advantages:

  1. data-free online quantization
  2. Supports all nvidia GPU models with Volta architecture (sm70) and above
  3. KV int8 quantization has almost lossless accuracy, and KV int4 quantization accuracy is within an acceptable range
  4. Efficient inference, with int8/int4 kv quantization applied to llama2-7b, RPS is improved by round 30% and 40% respectively compared to fp16

TurboQuant

LMDeploy supports KV quantization based on Google Research's TurboQuant technology (to be presented at ICLR 2026), achieving higher compression ratio with near-zero accuracy loss through K=4bit QJL4 + V=2bit MSE combination.

Principles

TurboQuant achieves efficient compression through two key steps:

  1. High-quality compression (PolarQuant method): First randomly rotates the data vectors (using orthogonal transforms like Hadamard transform). This clever step simplifies the data's geometry, making it easy to apply a standard, high-quality quantizer to each part of the vector individually. This stage uses most of the compression power (the majority of the bits) to capture the main concept and strength of the original vector.

  2. Eliminating hidden errors (QJL method): Uses a small, residual amount of compression power (just 1 bit) to apply the QJL (Quantized Johnson-Lindenstrauss) algorithm to the tiny amount of error left over from the first stage. The QJL stage acts as a mathematical error-checker that eliminates bias, leading to more accurate attention scores.

K/V Quantization Scheme

  • K Path - QJL4 Quantization:

    • Uses 3-bit Lloyd-Max codebook for MSE quantization (captures main information)
    • Uses 1-bit QJL to store residual sign (eliminates error bias)
    • Each token's K is compressed to 4-bit
  • V Path - MSE int2 Quantization:

    • Uses 2-bit Lloyd-Max codebook for MSE quantization
    • Each token's V is compressed to 2-bit
    • Stores normalization coefficients for dequantization

Advantages

  • Zero accuracy loss: Through PolarQuant + QJL combination, achieves high compression rate while maintaining model accuracy
  • Higher compression ratio: K 4bit + V 2bit = average 3bit, further compression compared to int4's 4bit
  • Eliminates quantization bias: QJL algorithm acts as error-checker, effectively eliminating quantization-induced bias

Performance Benchmark

Tested on H200 with Qwen3-30B-A3B-Base model and ShareGPT dataset:

MetricBaseline (quant_policy=0)TurboQuant (quant_policy=42)Change
Input throughput2368.8 tok/s2195.8 tok/s-7.3%
Output throughput2186.7 tok/s2027.0 tok/s-7.3%
Request throughput10.74 req/s9.96 req/s-7.3%
Mean E2E latency5.888s6.348s+7.8%
Mean TTFT1.139s1.235s+8.4%
Mean TPOT0.024s0.026s+8.3%
Mean ITL0.059s0.059s~unchanged

Test configuration: GPU: H200, Model: Qwen3-30B-A3B-Base, Dataset: ShareGPT, Concurrency: 64, Requests: 5000

Takeaway: TurboQuant K4V2 achieves ~5x KV cache memory reduction with about 7%-8% end-to-end performance overhead, which looks like a reasonable trade-off for memory-bound serving scenarios.

Limitations

  • PytorchEngine only: TurboQuant currently only supports PyTorch engine, not Turbomind engine
  • MLA not supported: Does not support Multi-head Latent Attention architecture
  • Speculative decoding not supported: Does not support speculative decoding
  • Requires head_dim to be a power of 2
  • Requires fast_hadamard_transform package for best performance (optional)

Optional Dependency

TurboQuant uses Hadamard transform to accelerate the quantization process. Installing fast_hadamard_transform provides better performance:

pip install fast_hadamard_transform

Without this dependency, TurboQuant still works correctly, but performance may be slightly reduced.

In the next section, we will take internlm2-chat-7b model as an example, introducing the usage of kv quantization and inference of lmdeploy. But before that, please ensure that lmdeploy is installed.

pip install lmdeploy

Usage

Applying kv quantization and inference via LMDeploy is quite straightforward. Simply set the quant_policy parameter.

LMDeploy specifies that quant_policy=4 stands for 4-bit kv, quant_policy=8 indicates 8-bit kv, and quant_policy=42 indicates TurboQuant.

Offline inference

from lmdeploy import pipeline, TurbomindEngineConfig
engine_config = TurbomindEngineConfig(quant_policy=8)
pipe = pipeline("internlm/internlm2_5-7b-chat", backend_config=engine_config)
response = pipe(["Hi, pls intro yourself", "Shanghai is"])
print(response)

Serving

lmdeploy serve api_server internlm/internlm2_5-7b-chat --quant-policy 8

TurboQuant

TurboQuant uses quant_policy=42, PytorchEngine only:

from lmdeploy import pipeline, PytorchEngineConfig
engine_config = PytorchEngineConfig(
    tp=1,
    cache_max_entry_count=0.8,
    quant_policy=42  # TurboQuant: K=4bit QJL4 + V=2bit MSE
)
pipe = pipeline("Qwen/Qwen3-8B", backend_config=engine_config)
response = pipe.infer("Hello, how are you?", max_new_tokens=30)
print(response.text)

Evaluation

We apply kv quantization of LMDeploy to several LLM models and utilize OpenCompass to evaluate the inference accuracy. The results are shown in the table below:

---llama2-7b-chat--internlm2-chat-7b--internlm2.5-chat-7b--qwen1.5-7b-chat--
datasetversionmetrickv fp16kv int8kv int4kv fp16kv int8kv int4kv fp16kv int8kv int4fp16kv int8kv int4
ceval-naive_average28.4227.9627.5860.4560.8860.2878.0677.8777.0570.5670.4968.62
mmlu-naive_average35.6435.5834.7963.916462.3672.3072.2771.1761.4861.5660.65
triviaqa2121cescore56.0956.1353.7158.7358.758.1865.0964.8763.2844.6244.7744.04
gsm8k1d7fe4accuracy28.228.0527.3770.1369.7566.8785.6785.4483.7854.9756.4154.74
race-middle9a54b6accuracy41.5741.7841.2388.9388.9388.9392.7692.8392.5587.3387.2686.28
race-high9a54b6accuracy39.6539.7740.7785.3385.3184.6290.5190.4290.4282.5382.5982.02

For detailed evaluation methods, please refer to this guide. Remember to pass quant_policy to the inference engine in the config file.

Performance

modelkv typetest settingsRPSv.s. kv fp16
llama2-chat-7bfp16tp1 / ratio 0.8 / bs 256 / prompts 1000014.981.0
-int8tp1 / ratio 0.8 / bs 256 / prompts 1000019.011.27
-int4tp1 / ratio 0.8 / bs 256 / prompts 1000020.811.39
llama2-chat-13bfp16tp1 / ratio 0.9 / bs 128 / prompts 100008.551.0
-int8tp1 / ratio 0.9 / bs 256 / prompts 1000010.961.28
-int4tp1 / ratio 0.9 / bs 256 / prompts 1000011.911.39
internlm2-chat-7bfp16tp1 / ratio 0.8 / bs 256 / prompts 1000024.131.0
-int8tp1 / ratio 0.8 / bs 256 / prompts 1000025.281.05
-int4tp1 / ratio 0.8 / bs 256 / prompts 1000025.801.07

The performance data is obtained by benchmark/profile_throughput.py