oldman-dev commited on
Commit
4246a1c
·
verified ·
1 Parent(s): 0907e56

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. README.md +90 -142
  2. metadata.json +10 -0
  3. msmarco_results.json +46 -0
  4. niah_hard_results.json +70 -0
  5. tis_components.pt +2 -2
  6. training.jsonl +20 -0
README.md CHANGED
@@ -1,183 +1,131 @@
1
  ---
2
  license: mit
3
- base_model: mistralai/Mistral-7B-v0.3
4
- tags:
5
- - token-importance
6
- - kv-cache
7
- - compression
8
- - efficient-inference
9
- - retrieval
10
- library_name: transformers
11
  language:
12
- - en
13
- metrics:
14
- - accuracy
 
 
 
 
 
15
  ---
16
 
17
- # Token Importance Scoring (TIS) v8b - Stage 3 ERT
18
 
19
- This checkpoint contains the Token Importance Scoring (TIS) components trained with **Efficient Retrieval Training (ERT)** objective for learned KV cache compression in large language models.
20
 
21
- ## Model Description
 
22
 
23
- Token Importance Scoring (TIS) is a learned approach to KV cache compression that achieves **100% NIAH accuracy** while maintaining strong semantic retrieval performance. This is the **main checkpoint** from the v8b publication, trained using a two-forward-pass ERT objective with KL divergence.
24
 
25
- **Key Features:**
26
- - **100% NIAH accuracy** at 50% cache budget
27
- - **52.8% LITM accuracy** at 50% cache budget
28
- - Consumer GPU compatible (RTX 5070, 8GB VRAM)
29
- - ✅ RMSNorm + Hard-Anchor forcing for stability
30
- - ✅ Efficient two-forward-pass training
31
 
32
- ## Performance
 
33
 
34
- ### Benchmarks (50% Cache Budget)
35
 
36
- | Benchmark | TIS v8b (this) | Vanilla | H2O | StreamingLLM | SnapKV |
37
- |-----------|----------------|---------|-----|--------------|--------|
38
- | **NIAH** | **100.0%** | 0.0% | 0.0%| 0.0% | 12.0% |
39
- | **LITM** | **52.8%** | 48.2% | 38.5%| 42.1% | 45.3% |
40
- | **NarrativeQA** | **67.2%** | 64.8% | 58.3%| 60.7% | 62.1% |
41
 
42
- ### Performance Across Cache Budgets
 
 
 
 
 
 
43
 
44
- | Budget | NIAH Accuracy | LITM Accuracy |
45
- |--------|---------------|---------------|
46
- | 25% | 98.0% | 45.2% |
47
- | 50% | 100.0% | 52.8% |
48
- | 75% | 100.0% | 68.5% |
49
- | 100% | 100.0% | 72.3% |
50
 
51
- ## Training Details
52
-
53
- **Base Model:** `mistralai/Mistral-7B-v0.3`
54
- **Training Data:** NarrativeQA (narrative passages with QA)
55
- **Training Objective:** ERT (Efficient Retrieval Training)
56
 
57
- ```
58
- Loss = KL(logits_full || logits_evicted) + λ_align * alignment_loss
59
- ```
 
 
 
60
 
61
- **Hyperparameters:**
62
- - Epochs: 1
63
- - Batch size: 1 (gradient accumulation: 1)
64
- - Learning rate: 1e-4
65
- - Precision: 4-bit quantization (NF4)
66
- - ERT budgets: [0.25, 0.5, 0.75]
67
- - Max sequence length: 256 tokens
68
- - Max training samples: 128
69
 
70
- **Hardware:** Trained on consumer GPU (RTX 5070, 8GB VRAM)
71
- **Training Time:** ~45 minutes per 500 steps
 
72
 
73
- ## Model Architecture
74
 
75
- This checkpoint contains:
76
- - **ImportanceUpdateHead**: RMSNorm-based importance predictor with hard-anchor forcing
77
- - **Importance Embedding**: Token-level importance embeddings
78
- - **Lambda Parameter**: Attention hook scaling factor (0.1)
79
 
80
- **Components:**
81
  ```python
82
- {
83
- 'importance_embedding': dict, # Token importance embeddings
84
- 'importance_head': dict, # RMSNorm + projection layers
85
- 'attn_hook_lambda': float # Attention scaling (0.1)
86
- }
87
  ```
88
 
89
- ## Usage
90
-
91
- ### Installation
 
92
 
93
- ```bash
94
- git clone https://github.com/nitroxido/token-importance-scoring
95
- cd token-importance-scoring
96
- python -m venv .venv
97
- source .venv/bin/activate
98
- pip install -e .
99
- ```
100
 
101
- ### Load Checkpoint
 
 
 
 
 
102
 
103
- ```python
104
- from token_importance.model.importance_head import ImportanceUpdateHead
105
- import torch
106
 
107
- # Load TIS components
108
- checkpoint = torch.load('tis_components.pt', map_location='cuda')
 
 
109
 
110
- # Extract components
111
- importance_head_state = checkpoint['importance_head']
112
- importance_embedding_state = checkpoint['importance_embedding']
113
- lambda_value = checkpoint['attn_hook_lambda']
114
 
115
- print(f"Lambda: {lambda_value}")
116
- print(f"Importance head keys: {importance_head_state.keys()}")
 
 
 
 
 
 
 
 
 
117
  ```
118
 
119
- ### Evaluate on NIAH Benchmark
120
 
121
- ```bash
122
- python scripts/eval.py \
123
- --model oldman-dev/tis-stage3-ert \
124
- --baseline tis \
125
- --benchmark niah \
126
- --cache_budgets 0.5 \
127
- --n_samples 50 \
128
- --output results/niah_eval.csv
129
  ```
130
-
131
- ### Evaluate on LITM Benchmark
132
-
133
- ```bash
134
- python scripts/eval.py \
135
- --model oldman-dev/tis-stage3-ert \
136
- --baseline tis \
137
- --benchmark litm \
138
- --cache_budgets 0.5 \
139
- --n_samples 100 \
140
- --output results/litm_eval.csv
141
  ```
142
 
143
- ## Intended Use
 
 
144
 
145
- **Primary Use Cases:**
146
- - KV cache compression for long-context inference
147
- - Efficient retrieval-augmented generation
148
- - Memory-constrained LLM deployment
149
 
150
- **Limitations:**
151
- - Trained on English narrative text (NarrativeQA)
152
- - Requires base model Mistral-7B-v0.3
153
- - Performance may vary on non-retrieval tasks
154
-
155
- ## Citation
156
-
157
- If you use this checkpoint, please cite:
158
-
159
- ```bibtex
160
- @software{token_importance_scoring_2026,
161
- title={Token Importance Scoring: Learned KV Cache Compression for Long-Context LLMs},
162
- author={Token Importance Scoring Contributors},
163
- year={2026},
164
- url={https://github.com/nitroxido/token-importance-scoring}
165
- }
166
- ```
167
 
168
  ## License
169
 
170
- MIT License - See [LICENSE](https://github.com/nitroxido/token-importance-scoring/blob/main/LICENSE)
171
-
172
- ## Acknowledgments
173
-
174
- Training compute sponsored by [GPU-Action](https://gpu-action.com/) (A100-80GB for oracle training).
175
- Consumer GPU validation performed on RTX 5070 (8GB VRAM).
176
-
177
- ## More Information
178
-
179
- - **Repository:** https://github.com/nitroxido/token-importance-scoring
180
- - **Documentation:** See REPOSITORY-OVERVIEW.md and REPRODUCIBILITY-GUIDE.md in the repository
181
- - **Related Checkpoints:**
182
- - [tis-v8b-hard-anchor](https://huggingface.co/oldman-dev/tis-v8b-hard-anchor) - Publication results with hard-anchor tuning
183
- - [tis-stage1-oracle](https://huggingface.co/oldman-dev/tis-stage1-oracle) - Oracle-labeled baseline
 
1
  ---
2
  license: mit
 
 
 
 
 
 
 
 
3
  language:
4
+ - en
5
+ tags:
6
+ - kv-cache
7
+ - token-importance
8
+ - llm-compression
9
+ - mistral
10
+ - pytorch
11
+ base_model: mistralai/Mistral-7B-v0.3
12
  ---
13
 
14
+ # TIS Stage 3 Closed-Loop Retrieval Checkpoint
15
 
16
+ **v2 replaces earlier incorrect upload (June 2026 release used wrong artifact)**
17
 
18
+ This is the Token Importance Scoring (TIS) checkpoint for learned KV cache compression,
19
+ trained via the closed-loop retrieval objective on Mistral-7B-v0.3.
20
 
21
+ ## What Changed in v2
22
 
23
+ The original `tis-stage3-ert` upload contained a 128-step prototype training run
24
+ (`stage3_ert_local_fresh`) rather than the trained checkpoint. That artifact had near-zero
25
+ `out_proj` weights (max 0.0007) and produced non-discriminative scores (std ≈ 1.7, range 45–54
26
+ for all tokens), which explains the 0%/12.5% NIAH results reported by external testers.
 
 
27
 
28
+ This v2 replaces it with the correct `closed_loop_retrieval_v6` checkpoint (2000 steps,
29
+ out_proj max 0.028, score std ≈ 22, full 0–100 range).
30
 
31
+ SHA256 of `tis_components.pt`: `794cb761d8d840709afb0bea6f0f9b73...` *(run `sha256sum tis_components.pt` to verify)*
32
 
33
+ ## Architecture
 
 
 
 
34
 
35
+ - Base model: `mistralai/Mistral-7B-v0.3`
36
+ - TIS components: `ImportanceUpdateHead` with RMSNorm + cross-attention
37
+ - State dict keys: 7 (`cross_attn.in_proj_weight`, `cross_attn.in_proj_bias`,
38
+ `cross_attn.out_proj.weight`, `cross_attn.out_proj.bias`, `out_proj.weight`,
39
+ `out_proj.bias`, `score_norm.scale`)
40
+ - Attention hook lambda: 0.0 (hook inactive; scoring via `out_proj(hidden)` direct path)
41
+ - Importance embedding projection: initialized to zero
42
 
43
+ ## Benchmark Results
 
 
 
 
 
44
 
45
+ Measured with `scripts/eval_niah_hard.py` on 50 examples, context 2048 tokens, seed 42.
46
+ **These are hard-NIAH numbers** (answer token must appear in top-5 final-position logits).
 
 
 
47
 
48
+ | Budget | Learned | SnapKV proxy | Heuristic | No eviction |
49
+ |--------|---------|-------------|-----------|-------------|
50
+ | 10% | 4% | 2% | 4% | 52% |
51
+ | 25% | 22% | 22% | 14% | 52% |
52
+ | 50% | **74%** | 24% | 28% | 52% |
53
+ | 75% | **78%** | 32% | 40% | 52% |
54
 
55
+ Evidence survival at 50% budget: 99.9%
56
+ Evidence survival at 75% budget: 100%
 
 
 
 
 
 
57
 
58
+ **Note:** The `no_eviction` ceiling is 52% because this hard evaluator tests whether the answer
59
+ token appears in the top-5 logits of the final token position. Eviction can actually *improve*
60
+ accuracy by removing distractors, which is the mechanism being measured here.
61
 
62
+ ## Scorer Path
63
 
64
+ The `eval_niah_hard.py` evaluator uses the **direct token scorer**:
 
 
 
65
 
 
66
  ```python
67
+ # Direct scorer — what eval_niah_hard.py uses
68
+ scores = sigmoid(importance_head.out_proj(hidden)) * 100.0
 
 
 
69
  ```
70
 
71
+ This is different from the full `ImportanceUpdateHead.forward()` which uses cross-attention
72
+ and RMSNorm. The direct scorer applies `out_proj` token-by-token to final-layer hidden states.
73
+ See [Source Code README](https://github.com/nitroxido/token-importance-scoring/blob/main/SOURCE-CODE-README.md)
74
+ for details on all scorer paths.
75
 
76
+ ## Training Details
 
 
 
 
 
 
77
 
78
+ - Training type: closed-loop retrieval
79
+ - Steps: 2000
80
+ - Learning rate: 0.001
81
+ - Loss weights: α_rank=1.0, β_retrieve=2.0, γ_stability=0.05
82
+ - Final loss: ~0.79
83
+ - Final evidence survival (training metric): ~70%
84
 
85
+ ## Usage
 
 
86
 
87
+ ```bash
88
+ # Clone repository
89
+ git clone https://github.com/nitroxido/token-importance-scoring.git
90
+ cd token-importance-scoring
91
 
92
+ # Setup
93
+ python -m venv .venv && source .venv/bin/activate
94
+ pip install -e .
 
95
 
96
+ # Download this checkpoint
97
+ hf download oldman-dev/tis-stage3-ert --local-dir checkpoints/stage3_ert_learned
98
+
99
+ # Run hard NIAH evaluation
100
+ python scripts/eval_niah_hard.py \
101
+ --learned-checkpoint checkpoints/stage3_ert_learned \
102
+ --budgets 0.25 0.5 0.75 \
103
+ --num-tests 50 \
104
+ --context-tokens 2048 \
105
+ --device cuda \
106
+ --seed 42
107
  ```
108
 
109
+ ## Reference Environment
110
 
 
 
 
 
 
 
 
 
111
  ```
112
+ transformers==4.36.0 # reference; Transformers 5 has SDPA compat issues with PatchedCausalLM
113
+ torch==2.1.2
114
+ bitsandbytes==0.41.3
115
+ python==3.11
 
 
 
 
 
 
 
116
  ```
117
 
118
+ Transformers 5 breaks the `PatchedCausalLM` forward path (attention mask injection conflicts
119
+ with the SDPA backend). The direct scorer (`out_proj(hidden)`) works under any version because
120
+ it does not go through the patched attention path.
121
 
122
+ ## Related Checkpoints
 
 
 
123
 
124
+ - [tis-v8b-hard-anchor](https://huggingface.co/oldman-dev/tis-v8b-hard-anchor): Hard-anchor
125
+ training on top of this checkpoint. Better at low budgets (25%).
126
+ - [tis-stage1-oracle](https://huggingface.co/oldman-dev/tis-stage1-oracle): Oracle baseline
127
+ using ground-truth labels.
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  ## License
130
 
131
+ MIT see [repository](https://github.com/nitroxido/token-importance-scoring)
 
 
 
 
 
 
 
 
 
 
 
 
 
metadata.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": "mistralai/Mistral-7B-v0.3",
3
+ "training_type": "closed_loop_retrieval",
4
+ "steps": 2000,
5
+ "lr": 0.001,
6
+ "alpha_rank": 1.0,
7
+ "beta_retrieve": 2.0,
8
+ "gamma_stability": 0.05,
9
+ "heuristic_init": false
10
+ }
msmarco_results.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "heuristic": {
3
+ "0.25": {
4
+ "accuracy": 64.0
5
+ },
6
+ "0.5": {
7
+ "accuracy": 62.0
8
+ },
9
+ "0.75": {
10
+ "accuracy": 56.0
11
+ }
12
+ },
13
+ "learned": {
14
+ "0.25": {
15
+ "accuracy": 52.0
16
+ },
17
+ "0.5": {
18
+ "accuracy": 64.0
19
+ },
20
+ "0.75": {
21
+ "accuracy": 54.0
22
+ }
23
+ },
24
+ "snapkv": {
25
+ "0.25": {
26
+ "accuracy": 60.0
27
+ },
28
+ "0.5": {
29
+ "accuracy": 62.0
30
+ },
31
+ "0.75": {
32
+ "accuracy": 58.0
33
+ }
34
+ },
35
+ "no_eviction": {
36
+ "0.25": {
37
+ "accuracy": 66.0
38
+ },
39
+ "0.5": {
40
+ "accuracy": 66.0
41
+ },
42
+ "0.75": {
43
+ "accuracy": 66.0
44
+ }
45
+ }
46
+ }
niah_hard_results.json ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "heuristic": {
3
+ "0.1": {
4
+ "accuracy": 4.0,
5
+ "evidence_survival": 32.382331266558204
6
+ },
7
+ "0.25": {
8
+ "accuracy": 14.0,
9
+ "evidence_survival": 41.18354874783684
10
+ },
11
+ "0.5": {
12
+ "accuracy": 28.0,
13
+ "evidence_survival": 62.74025152616919
14
+ },
15
+ "0.75": {
16
+ "accuracy": 40.0,
17
+ "evidence_survival": 78.32031858390032
18
+ }
19
+ },
20
+ "learned": {
21
+ "0.1": {
22
+ "accuracy": 4.0,
23
+ "evidence_survival": 32.382331266558204
24
+ },
25
+ "0.25": {
26
+ "accuracy": 22.0,
27
+ "evidence_survival": 62.152517806525026
28
+ },
29
+ "0.5": {
30
+ "accuracy": 74.0,
31
+ "evidence_survival": 99.92857142857143
32
+ },
33
+ "0.75": {
34
+ "accuracy": 78.0,
35
+ "evidence_survival": 100.0
36
+ }
37
+ },
38
+ "snapkv": {
39
+ "0.1": {
40
+ "accuracy": 2.0,
41
+ "evidence_survival": 33.83962051049928
42
+ },
43
+ "0.25": {
44
+ "accuracy": 22.0,
45
+ "evidence_survival": 46.329358988558106
46
+ },
47
+ "0.5": {
48
+ "accuracy": 24.0,
49
+ "evidence_survival": 64.30015919080714
50
+ },
51
+ "0.75": {
52
+ "accuracy": 32.0,
53
+ "evidence_survival": 80.55688092816011
54
+ }
55
+ },
56
+ "no_eviction": {
57
+ "0.1": {
58
+ "accuracy": 52.0
59
+ },
60
+ "0.25": {
61
+ "accuracy": 52.0
62
+ },
63
+ "0.5": {
64
+ "accuracy": 52.0
65
+ },
66
+ "0.75": {
67
+ "accuracy": 52.0
68
+ }
69
+ }
70
+ }
tis_components.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:878fac63e61ffc213b937165c2ebfe006bd1271f69e638dfddae0a66490cd86c
3
- size 268789935
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9852f6faaec72a9a128e64254946f532e94136b993ba0e5ba4907838bd82ea9
3
+ size 268790517
training.jsonl ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"step": 100, "loss": 0.8371540001212412, "rank": 0.04117626398801803, "retrieve": 0.39774603174025086, "stability": 0.00971332285553217, "ev_survival": 0.9022409955784678}
2
+ {"step": 200, "loss": 0.876377010345459, "rank": 0.0, "retrieve": 0.4381885051727295, "stability": 0.0, "ev_survival": 0.9335048758983612}
3
+ {"step": 300, "loss": 0.8517811459302902, "rank": 0.0, "retrieve": 0.4258905729651451, "stability": 0.0, "ev_survival": 0.8962065118551255}
4
+ {"step": 400, "loss": 0.8115472553297878, "rank": 0.0, "retrieve": 0.4057736276648939, "stability": 0.0, "ev_survival": 0.9021403068304061}
5
+ {"step": 500, "loss": 0.8626068061590195, "rank": 0.0, "retrieve": 0.43130340307950976, "stability": 0.0, "ev_survival": 0.8962856262922287}
6
+ {"step": 600, "loss": 0.822729275226593, "rank": 0.0, "retrieve": 0.4113646376132965, "stability": 0.0, "ev_survival": 0.881362396478653}
7
+ {"step": 700, "loss": 0.7913289571180939, "rank": 0.0, "retrieve": 0.39566447855904696, "stability": 0.0, "ev_survival": 0.9090958398580551}
8
+ {"step": 800, "loss": 0.8434155594930053, "rank": 0.0, "retrieve": 0.42170777974650264, "stability": 0.0, "ev_survival": 0.8881930476427078}
9
+ {"step": 900, "loss": 0.815227750390768, "rank": 0.0, "retrieve": 0.407613875195384, "stability": 0.0, "ev_survival": 0.8813758277893067}
10
+ {"step": 1000, "loss": 0.8738891038671136, "rank": 0.0, "retrieve": 0.4369445519335568, "stability": 0.0, "ev_survival": 0.8871889197826386}
11
+ {"step": 1100, "loss": 0.8441328368335962, "rank": 0.0, "retrieve": 0.4220664184167981, "stability": 0.0, "ev_survival": 0.8981528156995773}
12
+ {"step": 1200, "loss": 0.7647985039278865, "rank": 0.0, "retrieve": 0.38239925196394325, "stability": 0.0, "ev_survival": 0.895164275765419}
13
+ {"step": 1300, "loss": 0.8333014476671815, "rank": 0.0, "retrieve": 0.41665072383359075, "stability": 0.0, "ev_survival": 0.8938847494125366}
14
+ {"step": 1400, "loss": 0.8641506410762667, "rank": 0.0, "retrieve": 0.43207532053813336, "stability": 0.0, "ev_survival": 0.8726461982727051}
15
+ {"step": 1500, "loss": 0.8646381660550833, "rank": 0.0, "retrieve": 0.43231908302754163, "stability": 0.0, "ev_survival": 0.8765499836206436}
16
+ {"step": 1600, "loss": 0.7545320219546556, "rank": 0.0, "retrieve": 0.3772660109773278, "stability": 0.0, "ev_survival": 0.8902260011434555}
17
+ {"step": 1700, "loss": 0.7057499371096492, "rank": 0.0, "retrieve": 0.3528749685548246, "stability": 0.0, "ev_survival": 0.9063171845674515}
18
+ {"step": 1800, "loss": 0.8636072788387537, "rank": 0.0, "retrieve": 0.43180363941937683, "stability": 0.0, "ev_survival": 0.8686562418937683}
19
+ {"step": 1900, "loss": 0.7022718409823028, "rank": 0.0, "retrieve": 0.3511359204911514, "stability": 0.0, "ev_survival": 0.8638247573375701}
20
+ {"step": 2000, "loss": 0.790168259740874, "rank": 0.0, "retrieve": 0.395084129870437, "stability": 0.0, "ev_survival": 0.7021836014091969}