kvq
Norm-Aware KV Cache Quantization
Quantize What Counts: Bit Allocation Insights Informed by Spectral Gaps in Keys and Values.
Norm-Aware KVQuant: Precision Where It Counts
Installation
To install the package from PyPI, run the following command:
pip install kvq
Usage
Initialization
1.1. Creating a KVQ object using a configuration object:
import torch from kvq import KVQConfig, KVQ config = KVQConfig( budget = 4, model="meta-llama/Llama-3.1-8B-Instruct" residual_length=32, group_size={"k": 64, "v": 64}, # Group size for keys and values axis={"k": 0, "v": 0}, # Axis along which to quantize ) kv_cache = KVQ(config) text = "What is the meaning of life?" inputs = tokenizer(text, return_tensors="pt").to(model.device) outputs = model.generate( **inputs, max_new_tokens=256, past_key_values=kv_cache, use_cache=True, pad_token_id=tokenizer.eos_token_id, )
GitHub Repository
The source code is hosted on GitHub:
https://github.com/mohsenhariri/spectral-kv
Feel free to open issues, suggest improvements, or submit pull requests!
Citation
If you find our work useful or interesting, please consider citing our paper:
@article{hariri2025quantize,
title = {Quantize What Counts: Bit Allocation Insights Informed by Spectral Gaps in Keys and Values},
author = {Hariri, Mohsen and Luo, Alan and Nemati, Mohammadreza and Nguyen, Lam and Zhong, Shaochen and Wang, Qifan and Hu, Xia and Han, Xiaotian and Chaudhary, Vipin},
journal = {arXiv preprint arXiv:2502.15075},
year = {2025},
url = {https://arxiv.org/abs/2502.15075v2},
}
Metadata
Release files for kvq 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kvq-0.1.0.tar.gz | 28.0 kB | Without provenance | Details for kvq-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kvq-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for kvq-0.1.0-py3-none-any.whl |
Total release size: 48.5 kB
Release files / kvq-0.1.0.tar.gz
| Download URL | kvq-0.1.0.tar.gz |
|---|---|
| Size | 28.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cc5891ba4945b550e9d1cf84f68dc48a50ba41da1d7c557add323d4830d1c0f
|
|
BLAKE2b-256 checksum How to use checksums |
f293beab503a0abfceb4b3923284caa5deb0c338d9e42d99af27d5cd6bfac889
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / kvq-0.1.0-py3-none-any.whl
| Download URL | kvq-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e0eb38b0e7c176d247e4a982e10972d148a5f16c228128e8c53e13b60a0e105
|
|
BLAKE2b-256 checksum How to use checksums |
e6e1e9fd0cdc2deacb5caaea1e80549d24efb33542be83d840c39e8c51b84109
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Security for kvq 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.