Update model card: license, usage, numbers
Browse files
README.md
CHANGED
|
@@ -7,7 +7,7 @@ tags:
|
|
| 7 |
- llm
|
| 8 |
- inference
|
| 9 |
- compression
|
| 10 |
-
license:
|
| 11 |
---
|
| 12 |
|
| 13 |
# NexusQuant: E8 Lattice KV Cache Compression
|
|
@@ -16,29 +16,44 @@ Training-free KV cache compression for LLM inference. Uses E8 lattice vector qua
|
|
| 16 |
|
| 17 |
## Headline
|
| 18 |
|
| 19 |
-
+0.276% wikitext PPL
|
| 20 |
|
| 21 |
-
## Head-to-head (Llama-3.1-8B-Instruct, 4K, n=30)
|
| 22 |
|
| 23 |
| Method | bpe | NIAH |
|
| 24 |
|---|---|---|
|
| 25 |
| FP16 | 16.0 | 29/30 |
|
| 26 |
| TurboQuant 2-bit | 2.125 | 0/30 |
|
| 27 |
-
| NexusQuant K2V2 | 2.
|
|
|
|
|
|
|
| 28 |
|
| 29 |
## Install
|
| 30 |
|
| 31 |
```
|
| 32 |
-
pip install nexusquant-kv
|
| 33 |
```
|
| 34 |
|
| 35 |
## Usage
|
| 36 |
|
| 37 |
```python
|
|
|
|
|
|
|
| 38 |
from nexusquant import compress_kv_cache
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |
## Links
|
|
|
|
| 7 |
- llm
|
| 8 |
- inference
|
| 9 |
- compression
|
| 10 |
+
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
# NexusQuant: E8 Lattice KV Cache Compression
|
|
|
|
| 16 |
|
| 17 |
## Headline
|
| 18 |
|
| 19 |
+
+0.276% wikitext PPL on Mistral-7B-v0.1 (K3V2 pb=0, n=60, KIVI-iso). 5.83x compression measured on Mistral-Inst-v0.3 (same K3V2 config). NIAH retrieval preserved through 32K context. Validated on 10 architecture families.
|
| 20 |
|
| 21 |
+
## Head-to-head (Llama-3.1-8B-Instruct, 4K, n=30, iso-bpe)
|
| 22 |
|
| 23 |
| Method | bpe | NIAH |
|
| 24 |
|---|---|---|
|
| 25 |
| FP16 | 16.0 | 29/30 |
|
| 26 |
| TurboQuant 2-bit | 2.125 | 0/30 |
|
| 27 |
+
| NexusQuant K2V2 pb=0 | 2.125 | **30/30** |
|
| 28 |
+
|
| 29 |
+
NQ-vs-TQ McNemar b=30, c=0 (30 discordant pairs, all favor NexusQuant); FP16-vs-TQ floor b=29, c=0.
|
| 30 |
|
| 31 |
## Install
|
| 32 |
|
| 33 |
```
|
| 34 |
+
pip install "nexusquant-kv[hf]"
|
| 35 |
```
|
| 36 |
|
| 37 |
## Usage
|
| 38 |
|
| 39 |
```python
|
| 40 |
+
import torch
|
| 41 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, DynamicCache
|
| 42 |
from nexusquant import compress_kv_cache
|
| 43 |
|
| 44 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1", torch_dtype=torch.float16, device_map="auto")
|
| 45 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1")
|
| 46 |
+
inputs = tokenizer("The KV cache stores key and value tensors for each attention layer.", return_tensors="pt").to(model.device)
|
| 47 |
+
|
| 48 |
+
cache = DynamicCache()
|
| 49 |
+
with torch.no_grad():
|
| 50 |
+
out = model(inputs["input_ids"][:, :-1], use_cache=True, past_key_values=cache)
|
| 51 |
+
|
| 52 |
+
compressed = compress_kv_cache(out.past_key_values, mode="quant_only", key_bits=3, value_bits=2)
|
| 53 |
+
with torch.no_grad():
|
| 54 |
+
gen = model.generate(inputs["input_ids"], past_key_values=compressed, max_new_tokens=200, do_sample=False)
|
| 55 |
+
|
| 56 |
+
print(tokenizer.decode(gen[0], skip_special_tokens=True))
|
| 57 |
```
|
| 58 |
|
| 59 |
## Links
|