Changshi Li

Author directory

2026

The Key–Value (KV) cache has become a critical memory bottleneck that significantly hinders the deployment of large language models, especially under long-context inference. Existing approaches either introduce non-negligible errors through lossy compression, or are tightly coupled to specific tasks or model structures, limiting their general applicability. In this work, we first identify that the exponent values in BFloat16 KV caches are highly concentrated, and further prove theoretically that such concentration is inherent to LLMs, ensuring the broad generalizability of our method. Leveraging this insight, we propose AdaCode, a bit-exact lossless compression framework. The core idea is to encode frequent exponents with a short fixed-length code while storing rare outliers explicitly. AdaCode consists of two key components: (1) a minimal-cost optimization that selects the optimal code length and exponent range by balancing the storage overhead of short codes against that of outliers, complemented by a lightweight online adjuster to handle occasional distribution shifts without GPU overhead; and (2) a GPU-friendly byte-aligned packing format together with offline calibration for parameter precomputation. Experiments show that AdaCode achieves an average compression ratio of 71.78% on diverse LLMs and 70.26% on vision-language models, with bit-exact identical recovery and no accuracy loss, effectively alleviating the KV cache memory bottleneck. The codes are available at https://github.com/lichangshiwhu/Adacode.