chopratejas commited on
Commit
eacbdc5
·
verified ·
1 Parent(s): da20349

Add model card: 70M distilled model, 7.4/10 quality, 13ms ONNX

Browse files
Files changed (1) hide show
  1. README.md +146 -0
README.md ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - token-compression
7
+ - context-optimization
8
+ - llm
9
+ - agentic
10
+ - modernbert
11
+ - distilled
12
+ metrics:
13
+ - f1
14
+ - accuracy
15
+ pipeline_tag: token-classification
16
+ model-index:
17
+ - name: kompress-small
18
+ results:
19
+ - task:
20
+ type: token-classification
21
+ name: Token Compression
22
+ metrics:
23
+ - name: Quality Score (Claude-judged)
24
+ type: custom
25
+ value: 7.4
26
+ - name: Latency ONNX (median)
27
+ type: latency
28
+ value: 13ms
29
+ ---
30
+
31
+ # Kompress-Small: Distilled Token Compressor (70M params, 13ms ONNX)
32
+
33
+ **6-layer distilled version of [kompress-base](https://huggingface.co/chopratejas/kompress-base).** Same quality, 4x faster, half the size.
34
+
35
+ Compresses text in LLM context windows so agents can do more with less. Distilled from the 22-layer teacher using knowledge distillation — the student learns the teacher's probability distributions, not just hard labels.
36
+
37
+ ## Results
38
+
39
+ | Model | Quality | Latency | Size | Params |
40
+ |-------|---------|---------|------|--------|
41
+ | **kompress-small (ONNX)** | **7.4/10** | **13-29ms** | **279MB** | **70M** |
42
+ | kompress-base | 7.9/10 | 49-84ms | 600MB | 150M |
43
+ | LLMLingua-2 | 5.9-6.2/10 | 113-117ms | 710MB | 179M |
44
+
45
+ ### Detailed Benchmarks
46
+
47
+ **Unstructured text** (assistant explanations, plans, error analysis, status summaries):
48
+
49
+ | Metric | kompress-small | kompress-base | LLMLingua-2 |
50
+ |--------|---------------|--------------|-------------|
51
+ | Quality (Claude-judged) | **7.4/10** | 7.9/10 | 5.9/10 |
52
+ | Latency (median) | **29ms** | 84ms | 117ms |
53
+ | Compression | 58% kept | 58% kept | 53% kept |
54
+
55
+ **Real Claude Code sessions** (text segments):
56
+
57
+ | Metric | kompress-small | kompress-base | LLMLingua-2 |
58
+ |--------|---------------|--------------|-------------|
59
+ | Quality (Claude-judged) | **7.4/10** | 7.3/10 | 6.2/10 |
60
+ | Latency (median) | **13ms** | 83ms | 114ms |
61
+
62
+ ## Architecture
63
+
64
+ Distilled from kompress-base by keeping 6 evenly-spaced layers from the original 22:
65
+
66
+ ```
67
+ Teacher (kompress-base): layers [0,1,2,...,21] → 150M params, 600MB
68
+ Student (kompress-small): layers [0,4,8,12,17,21] → 70M params, 279MB
69
+ ```
70
+
71
+ Both token classification head and span importance CNN are copied from the teacher, then the full model is fine-tuned with knowledge distillation:
72
+
73
+ ```
74
+ loss = 0.5 * CrossEntropy(student, labels) + 0.5 * KL_div(student, teacher) * T²
75
+ ```
76
+
77
+ The soft KL divergence loss transfers richer information than hard labels alone — teaching the student *how confident* the teacher is about each token, not just the binary decision.
78
+
79
+ ### Available Formats
80
+
81
+ | Format | Size | Latency | Use case |
82
+ |--------|------|---------|----------|
83
+ | `model.safetensors` | 279MB | ~77ms (MPS) | PyTorch inference |
84
+ | `model_int8.pt` | 189MB | ~50ms (CPU) | PyTorch INT8 |
85
+ | `model.onnx` + `.data` | 275MB | **13-29ms** (CPU) | Production deployment |
86
+
87
+ ## Usage
88
+
89
+ ### ONNX (Fastest)
90
+
91
+ ```python
92
+ import onnxruntime as ort
93
+ from transformers import AutoTokenizer
94
+
95
+ sess = ort.InferenceSession("model.onnx")
96
+ tokenizer = AutoTokenizer.from_pretrained("answerdotai/ModernBERT-base")
97
+
98
+ text = "Your text here..."
99
+ words = text.split()
100
+ enc = tokenizer(words, is_split_into_words=True, truncation=True,
101
+ max_length=8192, padding=True, return_tensors="np")
102
+
103
+ logits = sess.run(None, {
104
+ "input_ids": enc["input_ids"],
105
+ "attention_mask": enc["attention_mask"]
106
+ })[0][0]
107
+
108
+ # Argmax: keep tokens where class 1 > class 0
109
+ keep = logits[:, 1] > logits[:, 0]
110
+ word_ids = enc.word_ids(batch_index=0)
111
+
112
+ kept_words = []
113
+ seen = set()
114
+ for idx, wid in enumerate(word_ids):
115
+ if wid is not None and wid not in seen and keep[idx]:
116
+ kept_words.append(words[wid])
117
+ seen.add(wid)
118
+
119
+ compressed = " ".join(kept_words)
120
+ ```
121
+
122
+ ### With Headroom
123
+
124
+ ```bash
125
+ pip install headroom-ai
126
+ ```
127
+
128
+ kompress-small is available as a lightweight alternative in [Headroom](https://github.com/headroom-ai/headroom).
129
+
130
+ ## Training Details
131
+
132
+ - **Teacher**: kompress-base (22 layers, 150M params)
133
+ - **Distillation**: 5 epochs, batch 32, lr 3e-5, temperature 4.0, α=0.5
134
+ - **Data**: 263K examples (same extractive labels from 8 diverse datasets)
135
+ - **Hardware**: NVIDIA H100
136
+ - **Training time**: ~4 hours
137
+
138
+ ## Limitations
139
+
140
+ - English only
141
+ - Best on natural language text; use specialized compressors for JSON/code/logs
142
+ - Sequences >512 tokens may degrade (inherited from ModernBERT layer pruning)
143
+
144
+ ## License
145
+
146
+ Apache 2.0