jkillay commited on
Commit
0fc4adb
·
verified ·
1 Parent(s): 346cc4f

Stage 2b memory extractor: negative-result research artifact

Browse files

566M C2KV-style sidecar for a frozen Qwen3-4B. Published so a FAILED experiment is reproducible: Stage 2b gate INCONCLUSIVE, Stage 3 cross-page composition FAIL. safetensors is the primary artifact (exact round-trip verified); the original .pt is included only because its SHA-256 is pinned in the repo's Stage 3 freeze manifest. Not a useful general model.

Files changed (4) hide show
  1. README.md +133 -0
  2. config.json +26 -0
  3. stage2b_extractor.pt +3 -0
  4. stage2b_extractor.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen3-4B
4
+ tags:
5
+ - kv-cache
6
+ - context-compression
7
+ - long-context
8
+ - research
9
+ - negative-results
10
+ - reproducibility
11
+ library_name: safetensors
12
+ ---
13
+
14
+ # context-cache-lab — Stage 2b memory extractor (research artifact)
15
+
16
+ > ## ⚠️ This is a negative-result research artifact, not a useful model.
17
+ >
18
+ > It is published so that a **failed** experiment is reproducible. Its own
19
+ > preregistered gates returned **INCONCLUSIVE** (Stage 2b) and **FAIL** (Stage 3).
20
+ > Do not use it for anything in production. Do not read a capability claim into it.
21
+
22
+ A 566M-parameter C²KV-style sidecar that compiles chunks of text into compressed,
23
+ pre-RoPE KV "pages" for a **frozen** `Qwen/Qwen3-4B`. It does not generate text and
24
+ cannot be used standalone — it only produces key/value state that the frozen target
25
+ consumes.
26
+
27
+ **Code, protocol, preregistration and all results:**
28
+ https://github.com/johnathonkillaly/context-cache-lab
29
+
30
+ ## What was measured
31
+
32
+ | Stage | Verdict | Result |
33
+ |---|---|---|
34
+ | 2b — does learned compressed state beat equal-budget raw text? | 🟡 **INCONCLUSIVE** | Beat `BUDGET` at every ratio, but missed 2 of 4 frozen criteria by ~1% |
35
+ | 3 — do independently compiled pages support two-page reasoning? | ❌ **FAIL** | **0/13** valid items vs NATIVE **13/13**; all 5 gates missed |
36
+
37
+ **Stage 2b (single-document QA, 4096 tokens, `clean_hit`):**
38
+
39
+ | ratio | this extractor | equal-budget raw text | NATIVE |
40
+ |---|---|---|---|
41
+ | 2× | 0.569 | 0.472 | 0.958 |
42
+ | 4× | 0.389 | 0.222 | 0.958 |
43
+ | 8× | 0.347 | 0.125 | 0.958 |
44
+ | 16× | 0.278 | 0.069 | 0.958 |
45
+
46
+ Semantic facts survived compression (0.625 at 4×) while exact strings did not —
47
+ hashes collapsed to **0.000** and identifiers to 0.250, where raw text at the same
48
+ budget scored 0.750. Warm reuse was 23–32× faster than native prefill with breakeven
49
+ at 2 queries, but compilation costs more than a single prefill, so the first query is
50
+ slower.
51
+
52
+ **Stage 3** then evaluated this exact frozen checkpoint on a preregistered cross-page
53
+ compositional task. It scored **zero** clean accuracy on every native-valid item, with a
54
+ mean rank margin (−2.47) *worse* than no context at all (−1.10). Compiling the document
55
+ jointly instead of per-page also scored zero, so this is not an independence tax.
56
+
57
+ **What that failure does not establish:** Stage 3 used a different corpus (~94–100 token
58
+ pages against ~256-token training chunks), so it measures insufficient transfer of *this*
59
+ carrier to *that* task — not the impossibility of independently compiled memory in
60
+ general. It also cannot fully separate loss of within-page fidelity from failure to
61
+ combine intact relations. See the repository's Stage 3 report for the full limitations.
62
+
63
+ ## Files
64
+
65
+ | File | Purpose |
66
+ |---|---|
67
+ | `stage2b_extractor.safetensors` | **Use this.** 109 fp32 tensors, safe to load. Verified to round-trip exactly against the original. |
68
+ | `stage2b_extractor.pt` | Provenance artifact only. Its SHA-256 is pinned in the repo's `results/stage3/freeze.json`, so the Stage 3 integrity audit reproduces exactly. **It is a pickle** — the repo's scripts load it with `weights_only=False`. Only use it if you need the hash to verify. |
69
+ | `config.json` | `layer_share`, `n_sink`, training step, target model revision, and the original `.pt` SHA-256. |
70
+
71
+ ```
72
+ original .pt sha256: b8384dd2eeaa87890a6b65e22f791183399764b93dd9a7f4e8a6e4ce13fca425
73
+ target model revision: 1cfa9a7208912126459214e8b04321603b3df60c
74
+ training step: 2200
75
+ ```
76
+
77
+ ## Usage
78
+
79
+ The extractor is only meaningful alongside the repository's code:
80
+
81
+ ```bash
82
+ git clone https://github.com/johnathonkillaly/context-cache-lab
83
+ cd context-cache-lab
84
+ uv venv --python 3.12 .venv && uv pip install --python .venv/bin/python -e ".[dev]"
85
+ ```
86
+
87
+ ```python
88
+ from huggingface_hub import hf_hub_download
89
+ from safetensors.torch import load_file
90
+ from ccl.compressor import MemoryExtractor
91
+ from ccl.target import TargetModel
92
+
93
+ target = TargetModel("Qwen/Qwen3-4B") # frozen
94
+ extractor = MemoryExtractor(target, layer_share=1, n_sink=8)
95
+ extractor.load_state_dict(load_file(hf_hub_download(
96
+ "jkillay/context-cache-lab-stage2b-extractor",
97
+ "stage2b_extractor.safetensors")))
98
+ extractor.eval()
99
+
100
+ pages = extractor.compile_chunks([target.encode(c) for c in chunks], ratio=4.0)
101
+ ```
102
+
103
+ Requires `transformers>=5.0` (the legacy tuple KV-cache format is gone) and roughly
104
+ 10 GB of memory for the frozen target plus the sidecar. Developed on Apple Silicon
105
+ (MPS); no CUDA is assumed.
106
+
107
+ ## Training
108
+
109
+ 2,200 steps, ~108 minutes on an Apple M4 Max, compression ratio sampled per example
110
+ (C²KV's `-Dyn` variant). The target model was frozen throughout — only the shared
111
+ memory-token embedding and per-layer Q/K/V projection heads received gradients.
112
+ Supervision was on answer tokens only, applied **after** page concatenation, so the
113
+ extractor is pushed toward states that compose rather than states that are merely
114
+ individually informative.
115
+
116
+ Training data was a **synthetic** corpus generated deterministically from integer
117
+ seeds, with value pools provably disjoint from the held-out evaluation draw. No
118
+ scraped text and no personal data.
119
+
120
+ ## License and attribution
121
+
122
+ Apache-2.0. This is a derivative of [`Qwen/Qwen3-4B`](https://huggingface.co/Qwen/Qwen3-4B)
123
+ (Apache-2.0) in the sense that its projections were initialized from that model's
124
+ weights; **no Qwen weights are redistributed here** — only the trained sidecar.
125
+
126
+ The mechanism is a reimplementation of the published design of
127
+ [C²KV (Du et al., KDD 2026)](https://arxiv.org/abs/2607.17715). No C²KV source code was
128
+ copied. Please cite that paper alongside this artifact.
129
+
130
+ ## Citation
131
+
132
+ See `CITATION.cff` in the
133
+ [GitHub repository](https://github.com/johnathonkillaly/context-cache-lab).
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "layer_share": 1,
3
+ "n_sink": 8,
4
+ "step": 2200,
5
+ "training_config": {
6
+ "model": "Qwen/Qwen3-4B",
7
+ "corpus": "results/raw/corpus/train_A.json",
8
+ "steps": 2200,
9
+ "lr": 5e-05,
10
+ "warmup": 50,
11
+ "layer_share": 1,
12
+ "n_sink": 8,
13
+ "max_chunks": 4,
14
+ "val_docs": 12,
15
+ "val_every": 275,
16
+ "val_examples": 16,
17
+ "clip": 1.0,
18
+ "seed": 0,
19
+ "ckpt": "results/raw/stage2b_extractor.pt",
20
+ "out": "results/raw/stage2b_train.json"
21
+ },
22
+ "target_model": "Qwen/Qwen3-4B",
23
+ "target_model_revision": "1cfa9a7208912126459214e8b04321603b3df60c",
24
+ "n_trainable_params": 566233600,
25
+ "original_pt_sha256": "b8384dd2eeaa87890a6b65e22f791183399764b93dd9a7f4e8a6e4ce13fca425"
26
+ }
stage2b_extractor.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b8384dd2eeaa87890a6b65e22f791183399764b93dd9a7f4e8a6e4ce13fca425
3
+ size 2264972579
stage2b_extractor.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df76629581d832ba1df544fcf06dfbe4dfa2a68d2aad16c2c6b74813378b0b2e
3
+ size 2264944568