Skip to content

Commit ead7bb9

Browse files
PR-R1 (research): ADR 0011 + cross-attention toy prototype
ADR 0011 (Proposed) — cross-attention proposer/verifier coupling for bounded-KV global-context inference. Context: The June 6 2026 A/B benchmark (sink_window_quality_ab_1780714635.json) showed v0.3's sink+window verifier loses 5/6 long-context recall cases vs full-attention baseline (16.7% vs 100%). This violates the ADR 0001 'no intelligence loss' principle. ADR 0011 proposes a coupled-attention architecture where the proposer manages a full-context hidden bank and the verifier cross-attends to it while keeping its own local KV bounded. Decision: Insert a single cross-attention bridge into the verifier at chosen depth K. Q from verifier hidden, K/V from proposer's full-attention hidden bank. Identity initialization on the output projection means cross-attention contributes zero at step 0 and gradually learns to mix in via gradient flow. Memory math: per-session at 8 k tokens ~150 MB (vs full attention 1.84 GB, vs sink+window 116 MB but with broken recall). At 5-second video (38 k tokens) ~290 MB; at 30-second video (230 k tokens) ~1.2 GB. Mac M4 24 GB: ~10 concurrent 5-s video sessions. The architectural point: bounded sufficient at 24 GB for realistic multimodal agent workloads while preserving (target) 99 %+ of full-attention quality. Multimodal extension is mechanically free — cross-attention bridge is modality-agnostic. Phase 2 substitutes Gemma 4 multimodal as proposer + verifier; bridge code unchanged. Validation gates (per §4): G-X1: toy prototype on Mac M4, ~00, 4 weeks. Bounded + cross-attn recall >= 80 %, baseline <= 30 % on synthetic NIAH. G-X2: production-scale text validation. Gemma 4-9B verifier + Gemma 4-2B proposer on RULER/NIAH. ~3-5 months, ~cd /workspace && git add -A && git diff --cached --stat | tail -8 && git commit -m "PR-R1 (research): ADR 0011 + cross-attention toy prototype ADR 0011 (Proposed) — cross-attention proposer/verifier coupling for bounded-KV global-context inference. Context: The June 6 2026 A/B benchmark (sink_window_quality_ab_1780714635.json) showed v0.3's sink+window verifier loses 5/6 long-context recall cases vs full-attention baseline (16.7% vs 100%). This violates the ADR 0001 'no intelligence loss' principle. ADR 0011 proposes a coupled-attention architecture where the proposer manages a full-context hidden bank and the verifier cross-attends to it while keeping its own local KV bounded. Decision: Insert a single cross-attention bridge into the verifier at chosen depth K. Q from verifier hidden, K/V from proposer's full-attention hidden bank. Identity initialization on the output projection means cross-attention contributes zero at step 0 and gradually learns to mix in via gradient flow. Memory math: per-session at 8 k tokens ~150 MB (vs full attention 1.84 GB, vs sink+window 116 MB but with broken recall). At 5-second video (38 k tokens) ~290 MB; at 30-second video (230 k tokens) ~1.2 GB. Mac M4 24 GB: ~10 concurrent 5-s video sessions. The architectural point: bounded sufficient at 24 GB for realistic multimodal agent workloads while preserving (target) 99 %+ of full-attention quality. Multimodal extension is mechanically free — cross-attention bridge is modality-agnostic. Phase 2 substitutes Gemma 4 multimodal as proposer + verifier; bridge code unchanged. Validation gates (per §4): G-X1: toy prototype on Mac M4, ~$500, 4 weeks. Bounded + cross-attn recall >= 80 %, baseline <= 30 % on synthetic NIAH. G-X2: production-scale text validation. Gemma 4-9B verifier + Gemma 4-2B proposer on RULER/NIAH. ~3-5 months, ~$15-30k. G-X3: video modality. ~6-9 months, ~$30-60k. Each gate is a go/no-go for the next. G-X1 fail = stop; switch to ADR 0010 + InfLLM hot/cold for v0.5. Files: docs/adr/0011-cross-attention-proposer-verifier-coupling.md +470 Full ADR document. References ADR 0001 (no-intelligence-loss principle), ADR 0004 (training pipeline reused), ADR 0008 (session-bound runtime, coexists), ADR 0010 (queued, ships before this). scripts/research/cross_attn_toy_prototype.py +500 Phase 1 G-X1 prototype. Single-file PyTorch + HuggingFace transformers. Configurable model id (Gemma 3 / Gemma 4 multimodal / any AutoModelForCausalLM). Apple Silicon (MPS) or CUDA. Identity-initialized cross-attention bridge. Synthetic needle-in-haystack dataset generator. Greedy decode with bounded baseline + cross-attn paths. Per-step training loop with periodic eval. JSON report + Gate G-X1 pass/fail criterion. --multimodal-tokens flag is a Phase 2 hook; Phase 1 validates text-only. scripts/research/__init__.py +0 Python package marker. scripts/review_pr_r1_on_mac.sh +50 Mac M4 reviewer aid. Drives the prototype with sane defaults for Gemma 3-1B-it on Mac M4 24 GB. Expected runtime ~30-60 min. Exit code 0 = G-X1 pass. Linux verification ------------------ - ADR is markdown only; no Linux unit-test impact. - Toy prototype script syntax-checks (py_compile pass). - --help renders cleanly. - No new dependencies beyond existing requirements.txt (torch, transformers). Per ADR 0008 §9 --------------- This is a RESEARCH-TRACK PR, not a production change. - No modifications to inference_engine/, kv_cache_proposer/, or any path on the v0.3 production code path. - The toy prototype lives at scripts/research/, deliberately isolated from production paths so it can fail without polluting Mac M4 reviewer flows for v0.4-Q work. - ADR 0011 is Proposed, not Accepted. Acceptance is conditional on G-X1 pass. The Mac M4 reviewer aid is the empirical gate. Stack ----- PR-R1 is independent of all in-flight v0.4-Q work. Branched off post-G3/G5/G6 main. Coexists with PR-G3/G5/G6 (#59/#60/#61) and any future ADR 0010 implementation PRs. Next ---- - Mac M4 reviewer runs scripts/review_pr_r1_on_mac.sh - If Gate G-X1 passes (cross_attn_recall >= 0.80, baseline <= 0.30): * Mark ADR 0011 status as 'Accepted (Phase 1 validated)' * Open PR-R2: scale up to Gemma 4-9B + Gemma 4-2B for G-X2 - If G-X1 fails: * Mark ADR 0011 'Rejected' (or 'Superseded by InfLLM hot/cold') * Pivot to ADR 0010-only path for v0.4 + InfLLM for v0.5 - In parallel: ADR 0010 (full attention + INT8 KV) draft for v0.4-Q ship-now path. ADR 0010 is the safety net; ADR 0011 is the ambitious path." 2>&1 | tail -3 && git push -u origin AgentMemory/v04-pr-r1-adr-0011-cross-attn-prototype-8e7f 2>&1 | tail -35-30k. G-X3: video modality. ~6-9 months, ~0-60k. Each gate is a go/no-go for the next. G-X1 fail = stop; switch to ADR 0010 + InfLLM hot/cold for v0.5. Files: docs/adr/0011-cross-attention-proposer-verifier-coupling.md +470 Full ADR document. References ADR 0001 (no-intelligence-loss principle), ADR 0004 (training pipeline reused), ADR 0008 (session-bound runtime, coexists), ADR 0010 (queued, ships before this). scripts/research/cross_attn_toy_prototype.py +500 Phase 1 G-X1 prototype. Single-file PyTorch + HuggingFace transformers. Configurable model id (Gemma 3 / Gemma 4 multimodal / any AutoModelForCausalLM). Apple Silicon (MPS) or CUDA. Identity-initialized cross-attention bridge. Synthetic needle-in-haystack dataset generator. Greedy decode with bounded baseline + cross-attn paths. Per-step training loop with periodic eval. JSON report + Gate G-X1 pass/fail criterion. --multimodal-tokens flag is a Phase 2 hook; Phase 1 validates text-only. scripts/research/__init__.py +0 Python package marker. scripts/review_pr_r1_on_mac.sh +50 Mac M4 reviewer aid. Drives the prototype with sane defaults for Gemma 3-1B-it on Mac M4 24 GB. Expected runtime ~30-60 min. Exit code 0 = G-X1 pass. Linux verification ------------------ - ADR is markdown only; no Linux unit-test impact. - Toy prototype script syntax-checks (py_compile pass). - --help renders cleanly. - No new dependencies beyond existing requirements.txt (torch, transformers). Per ADR 0008 §9 --------------- This is a RESEARCH-TRACK PR, not a production change. - No modifications to inference_engine/, kv_cache_proposer/, or any path on the v0.3 production code path. - The toy prototype lives at scripts/research/, deliberately isolated from production paths so it can fail without polluting Mac M4 reviewer flows for v0.4-Q work. - ADR 0011 is Proposed, not Accepted. Acceptance is conditional on G-X1 pass. The Mac M4 reviewer aid is the empirical gate. Stack ----- PR-R1 is independent of all in-flight v0.4-Q work. Branched off post-G3/G5/G6 main. Coexists with PR-G3/G5/G6 (#59/#60/#61) and any future ADR 0010 implementation PRs. Next ---- - Mac M4 reviewer runs scripts/review_pr_r1_on_mac.sh - If Gate G-X1 passes (cross_attn_recall >= 0.80, baseline <= 0.30): * Mark ADR 0011 status as 'Accepted (Phase 1 validated)' * Open PR-R2: scale up to Gemma 4-9B + Gemma 4-2B for G-X2 - If G-X1 fails: * Mark ADR 0011 'Rejected' (or 'Superseded by InfLLM hot/cold') * Pivot to ADR 0010-only path for v0.4 + InfLLM for v0.5 - In parallel: ADR 0010 (full attention + INT8 KV) draft for v0.4-Q ship-now path. ADR 0010 is the safety net; ADR 0011 is the ambitious path. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
1 parent b6fdec4 commit ead7bb9

4 files changed

Lines changed: 1164 additions & 0 deletions

File tree

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
# ADR 0011 — Cross-attention proposer/verifier coupling for bounded-KV global-context inference
2+
3+
* **Status**: Proposed
4+
* **Date**: 2026-06-06
5+
* **Supersedes**: nothing
6+
* **Extends**: [ADR 0004](0004-alignment-training-data-preparation-policy.md) (alignment training data + LoRA pipeline)
7+
* **Coexists with**: [ADR 0008](0008-session-bound-runtime-and-grpc-protocol.md) (session-bound gRPC runtime — load-bearing for v0.3 GA, unchanged)
8+
* **Targets**: v0.5-A (research → ship). Companion ADR 0010 (queued) covers v0.4-Q's pragmatic full-attention + INT8 KV path that ships before this lands.
9+
10+
## 1. Context
11+
12+
### 1.1 The principle violation that forced this ADR
13+
14+
[ADR 0001](0001-proposer-sizing-and-alignment.md) committed the project to **"no intelligence loss"** as a non-negotiable principle alongside the KV memory bound. The v0.3 GA shipped a `SinkWindowVerifier` that achieves the memory bound by **dropping K/V tensors for tokens outside a (sink + window) range**. The June 6 2026 A/B benchmark (`results/platform-tests/sink_window_quality_ab_1780714635.json`) measured the cost:
15+
16+
| | Full-context Qwen3-1.7B greedy | Kakeya v0.3 (Qwen3-0.6B dLM proposer + Qwen3-1.7B sink+window verifier) |
17+
| --- | --- | --- |
18+
| Long-context exact-recall accuracy | **6 / 6 (100 %)** | **1 / 6 (16.7 %)** |
19+
| Peak verifier KV bytes | 56 MB | 7.6 MB |
20+
| KV plateau | 2048 tokens | 68 tokens |
21+
22+
Five out of six failures are middle-context fact recall — the verifier's sink+window has evicted the K/V for the relevant tokens before generation. The remaining proposer cannot rescue them: in strict-greedy speculative decoding the verifier's `argmax` is the source of truth, and the verifier is operating on a partial cache.
23+
24+
This is not an implementation defect. **Any token-evicting KV strategy** (sink+window, H2O, SnapKV, PyramidKV) violates the ADR 0001 principle for any case where the evicted token's information matters for the output. ADR 0011 asks: is there a KV strategy that satisfies *both* "no intelligence loss" *and* the ADR 0008 memory-bound contract?
25+
26+
### 1.2 Multimodal makes the problem load-bearing, not optional
27+
28+
Text long-context recall is the canonical failure mode but it understates the real product motivation. The intended deployment target is local agent infrastructure on Apple Silicon ([ADR 0006](0006-local-agent-infrastructure-positioning.md)) that supports **text-video** workloads — Gemma 4-class multimodal models running locally on Mac mini, generating video conditioned on long contexts.
29+
30+
Memory math at the multimodal scale (Gemma 4 family, 28 layers, hidden 3584, bf16):
31+
32+
| Workload | Tokens | Full-attention KV | Sink+window (sink=4, window=512) | Cross-attention (this ADR) |
33+
| --- | --- | --- | --- | --- |
34+
| 1-turn text chat (1 k tokens) | 1 024 | 230 MB | 116 MB | ~120 MB |
35+
| 1-turn long doc (8 k tokens) | 8 192 | 1.84 GB | 116 MB | ~150 MB |
36+
| 5-second video (30 fps × 256 visual tokens / frame) | 38 400 | 8.6 GB | 116 MB | ~280 MB |
37+
| 30-second video | 230 400 | **51.6 GB** | 116 MB | ~1.2 GB |
38+
39+
The 5-second video case is where the architectural choice becomes irreducible: **full attention runs out of unified memory on a 24 GB Mac mini, sink+window loses temporal coherence (the same 17 % failure mode as text but for visual tokens), and cross-attention is the only path that preserves both bound and quality**.
40+
41+
### 1.3 What's been ruled out
42+
43+
The two-week period between the A/B run and this ADR explored:
44+
45+
- **W1 (NF4 KV quantization, ADR 0010)**: ships in v0.4-Q. Full attention + INT8/NF4 quantization. Satisfies ADR 0001 (intelligence preserved up to <1 % perplexity drift on INT8). **Memory bound only at small context** — at 8 k it's 230-460 MB / session, at 30-second video it's 12-30 GB. Adequate for text agent loops, **fails at video scale**. ADR 0010 is the v0.4 pragmatic path; ADR 0011 is what unblocks v0.5+ video deployment.
46+
47+
- **W2 (importance-based eviction: H2O / SnapKV / PyramidKV)**: still token-eviction. Drops to ~85 % recall on RULER instead of 17 %, but **still violates** ADR 0001 strict reading. Not the path forward post-A/B clarification.
48+
49+
- **InfLLM-style hot/cold storage**: hot working set + compressed cold pool with retrieval. Quality similar to cross-attention; complexity comparable. Falls back into the implementation space of this ADR — could be one of the "alternatives considered" if cross-attention doesn't pan out.
50+
51+
- **Long-context-native model substitution (Mamba / RWKV / RetNet)**: changes the project's model identity. Would require dropping Qwen3 / Gemma and re-doing the alignment work. Out of scope for ADR 0011; potential v0.6 direction.
52+
53+
## 2. Decision
54+
55+
### 2.1 Architecture
56+
57+
Two coupled models with a thin cross-attention bridge:
58+
59+
```
60+
┌─────────────────────────────────────┐
61+
│ Proposer (dLM) │
62+
│ │
63+
prompt ─────► │ full attention over T tokens │
64+
T tokens │ 28 layers, hidden_p │
65+
│ │
66+
│ → hidden bank h_p[0..T-1] │
67+
│ [T × hidden_p × bf16] │
68+
└─────────────────────────────────────┘
69+
70+
│ K, V projections
71+
72+
┌─────────────────────────────────────────────────────────┐
73+
│ Verifier (Qwen3 / Gemma family) │
74+
│ │
75+
│ layer 1 ───────── bounded local attention │
76+
│ layer 2 ───────── bounded local attention │
77+
│ ... │
78+
│ layer K ───────── bounded local attention │
79+
│ layer K+ ───────── bounded local + cross-attn(h_p) │ ← NEW LAYER
80+
│ layer K+1 ───────── bounded local attention │
81+
│ ... │
82+
│ layer 28 ───────── bounded local attention │
83+
│ │
84+
│ verifier KV: bounded by (sink + window) — unchanged │
85+
│ cross-attention KV: proposer hidden bank h_p │
86+
└─────────────────────────────────────────────────────────┘
87+
88+
89+
output logits
90+
(greedy argmax = output)
91+
```
92+
93+
**The cross-attention layer's contract**:
94+
95+
* `Q ← W_q · verifier_hidden_at_depth_K+`
96+
* `K ← W_k · proposer_hidden_bank`
97+
* `V ← W_v · proposer_hidden_bank`
98+
* `attn = softmax(Q K^T / √d) V`
99+
* `output = W_o · attn`, residual-added back to verifier's stream
100+
101+
Critically:
102+
103+
1. **Verifier's local attention path is unchanged**. Sink+window (or any other bounded-KV policy) still applies to verifier's self-attention. The cross-attention is **additive**, not replacement.
104+
2. **Proposer's hidden bank is the K/V** — the bank IS the long-term memory. It's a single tensor `[T, hidden_p]`, not a per-layer KV cache. That's the memory savings vs full attention.
105+
3. **`O_proj` is initialized to zero**. At training step 0 the cross-attention contributes nothing; the verifier behaves identically to its pre-ADR-0011 self. As training progresses, gradients flow into `W_o` and the cross-attention output gradually mixes in. This is the single most important training stability trick.
106+
107+
### 2.2 Training (extends ADR 0004)
108+
109+
ADR 0004's existing pipeline (7-domain prompt pool, hidden state collection, LoRA on `o_proj`, per-slice eval) is **reused**. ADR 0011 adds Stage 3b on top of the existing Stage 3a (Repr-Align):
110+
111+
| Stage | Source | Purpose | Trainable |
112+
| --- | --- | --- | --- |
113+
| 2 (data) | ADR 0004, **extended** | Collect (prompt, hidden_v_full, argmax_v_full); for video also (visual tokens, full-attention argmax of generated frames) ||
114+
| 3a (Repr-Align) | ADR 0004 | proposer's hidden ≈ verifier's hidden at corresponding position | LoRA on proposer `o_proj` |
115+
| **3b (cross-attention)** | **NEW** | bounded verifier + cross-attn(proposer hidden bank) → matches full-attention argmax | (a) cross-attention layer weights, (b) LoRA on proposer (shared with 3a) |
116+
| 4 (deploy) | ADR 0004 | inference: bounded verifier + cross-attention bridge + proposer hidden bank | — frozen |
117+
118+
Stage 3b's loss is single-objective:
119+
120+
```
121+
L_3b = CE(verifier_output_with_xattn(prompt, h_p), argmax_v_full[prompt])
122+
```
123+
124+
Stage 3a + 3b can be co-trained as multi-task (`L = α · L_3a + β · L_3b`) or sequentially (3a converges first, then introduce 3b with curriculum). Empirical decision; toy prototype validates which. Default starting point: **sequential (3a first), then 3b with `α = 0` (pure cross-attention objective)**.
125+
126+
### 2.3 Multimodal extension is mechanically free
127+
128+
The cross-attention bridge is **modality-agnostic** by construction. `Q`, `K`, `V` are linear projections of hidden states; they don't care whether those hiddens encode text tokens, vision patches, or audio frames. To extend from text to multimodal:
129+
130+
1. Replace verifier with Gemma 4 multimodal class (or whatever the current SOTA open multimodal verifier is).
131+
2. Replace proposer with a multimodal-capable proposer of the same family (Gemma 4-2B as proposer, Gemma 4-9B as verifier — typical EAGLE-3 ratio).
132+
3. Stage 2 prompt pool extends to include video-conditioning prompts.
133+
4. Stage 3b cross-attention layer is the same code; the hidden_p tensor now has a mix of text + visual + audio token positions.
134+
135+
The only modality-specific work is in **Stage 2 data preparation**: collecting full-attention ground-truth outputs at the multimodal scale is expensive (each 5-second video eval requires a full-attention forward at 38 k tokens against a 9 B verifier — needs A100/H100, not Mac). The ADR 0004 cluster + GPU rental budget covers this.
136+
137+
### 2.4 Memory and compute
138+
139+
Per-session memory at the deployment point (Mac mini 24 GB, Gemma 4-9B verifier, Gemma 4-2B proposer):
140+
141+
| Component | Size | Why |
142+
| --- | --- | --- |
143+
| Verifier weights (bf16) | 18 GB | weights resident across all sessions |
144+
| Proposer weights (bf16) | 4 GB | weights resident across all sessions |
145+
| Verifier local KV per session (sink + window = 1024 tokens) | 116 MB | bounded |
146+
| **Proposer hidden bank per session** | **T × hidden_p × bf16** | **the new memory** |
147+
| Cross-attention layer weights | < 30 MB | trainable, single layer |
148+
| Activations during inference | ~500 MB | transient |
149+
150+
Proposer hidden bank for typical workloads (Gemma 4-2B has hidden_p = 2304):
151+
152+
| T | hidden bank | total per-session memory |
153+
| --- | --- | --- |
154+
| 1 k (text chat) | 4.7 MB | ~120 MB |
155+
| 8 k (text long doc) | 38 MB | ~150 MB |
156+
| 38 k (5-s video) | 175 MB | ~290 MB |
157+
| 230 k (30-s video) | 1.05 GB | ~1.2 GB |
158+
159+
**With weights amortized across sessions, 24 GB Mac mini supports**:
160+
161+
* ~50 concurrent text-chat sessions, OR
162+
* ~30 concurrent 8 k-token long-doc sessions, OR
163+
* ~10 concurrent 5-second video sessions, OR
164+
* ~3 concurrent 30-second video sessions
165+
166+
This is the headline memory result of ADR 0011: **bounded sufficient at 24 GB for the realistic Mac M4 multimodal agent workload, while preserving (target) 99 %+ of full-attention quality**.
167+
168+
Compute overhead: cross-attention adds one extra attention layer's worth of FLOPs per verifier forward — small relative to the verifier's existing 28 layers.
169+
170+
## 3. Alternatives considered
171+
172+
| Alternative | Decision | Why |
173+
| --- | --- | --- |
174+
| **Pure full attention + INT8 KV (ADR 0010)** | Will ship as v0.4-Q; this ADR is for v0.5-A | Adequate at text scale; fails at video memory budget |
175+
| **W2 H2O eviction** | Rejected | Still token-eviction → still violates ADR 0001 |
176+
| **InfLLM hot/cold** | Reserved as fallback | If cross-attention research bet fails, this is the next-best memory-vs-quality point |
177+
| **Memory tokens (Compressive Transformer style)** | Future v0.6+ | Stronger compression; 12-18 month research bet AFTER cross-attention ships |
178+
| **Replace Qwen3/Gemma with Mamba/RWKV** | Out of scope | Changes project model identity; redoes alignment work |
179+
| **Drop KV bound, accept full attention** | Possible if research fails | Falls back to ADR 0010-only, video deployment becomes "single-session at a time" |
180+
181+
## 4. Validation criteria (research bet → ship)
182+
183+
This ADR is conditional on empirical validation. Three gates must pass before v0.5-A ships:
184+
185+
### Gate G-X1: Toy prototype convergence
186+
187+
* Setup: small Gemma family (Gemma 3-1B / Gemma 4-2B as both proposer and verifier), text-only, needle-in-haystack
188+
* Compute: <$500 GPU rental, 2-4 weeks
189+
* Pass criterion: with bounded verifier (sink+window=128 over 1-2 k context) + cross-attention from full-attention proposer's hidden bank, recall on synthetic NIAH ≥ 80 % (vs full-attention baseline 100 %, vs bounded baseline ~20 %)
190+
* Fail action: stop. Switch to ADR 0010 + InfLLM hot/cold for v0.5
191+
192+
### Gate G-X2: Production-scale text validation
193+
194+
* Setup: Gemma 4-9B verifier + Gemma 4-2B proposer, real prompts (RULER, NIAH, NarrativeQA short subset)
195+
* Compute: ~$15-30k GPU, 3-5 months
196+
* Pass criterion: cross-attention recall ≥ 95 % of full-attention baseline on RULER 4 k–8 k subtasks, on Mac mini at <300 MB / session
197+
* Fail action: regression analysis; consider scaled-up cross-attention (multi-layer, multi-head, larger hidden bank)
198+
199+
### Gate G-X3: Video-modality validation
200+
201+
* Setup: Gemma 4 multimodal verifier + smaller multimodal proposer, text-video generation tasks (5-second video continuation, video QA)
202+
* Compute: ~$30-60k GPU, 6-9 months
203+
* Pass criterion: bounded-KV cross-attention generates temporally coherent 5-second video on Mac mini in <30 GB peak memory, indistinguishable from full-attention baseline by human eval pairwise > 50 % preference (i.e., not worse)
204+
* Fail action: scope ADR 0011 to text-only v0.5-A, defer video to v0.6+ with InfLLM-style hierarchical alternative
205+
206+
## 5. Phasing
207+
208+
| Phase | Output | Time | Cost |
209+
| --- | --- | --- | --- |
210+
| P0 (this ADR) | ADR 0011 ratified, prototype scaffold | 1 week | engineer time |
211+
| P1 (toy prototype) | Gate G-X1 pass/fail | 2-4 weeks | <$500 |
212+
| P2 (Stage 2 data extension) | full-attention ground-truth dataset (text + later video) | 1-2 months | ~$5-10k |
213+
| P3 (text production training) | Gate G-X2 pass/fail | 3-5 months | ~$15-30k |
214+
| P4 (cross-attention productionization) | v0.5-A merge to main; integration test gate green on Mac M4 | 1-2 months | engineer time |
215+
| P5 (multimodal extension training) | Gate G-X3 pass/fail | 6-9 months | ~$30-60k |
216+
| P6 (video productionization) | v0.6-A merge with multimodal cross-attention | 1-2 months | engineer time |
217+
218+
Total ADR 0011 lifecycle: ~12-18 months, ~$50-100k GPU + engineer time. Gate G-X1 (4 weeks, <$500) is the critical decision point — go/no-go for the whole program.
219+
220+
## 6. Risks
221+
222+
| Risk | Likelihood | Mitigation |
223+
| --- | --- | --- |
224+
| **Cross-attention short-circuits** (verifier ignores local KV, relies entirely on proposer hidden bank) | Medium | Information bottleneck on hidden bank (dropout, quantization); curriculum (3a first); regularization on cross-attention output magnitude |
225+
| **Proposer collapse** (proposer's hidden bank becomes a trivial encoding of the answer) | Medium | KL regularization; evaluate generalization to held-out prompts; vary hidden bank source layer |
226+
| **Joint training instability** | High initially | Identity initialization on `W_o`; sequential training (3a converges → 3b introduced); gradient clipping; mixed-precision care |
227+
| **OOD generalization weak** | Medium | 7-domain prompt pool already in ADR 0004; expand with multimodal early in Stage 2 |
228+
| **Inference latency overhead from cross-attention** | Low | Single layer with bounded compute; can fuse into verifier's existing forward kernel |
229+
| **MLX implementation complexity** | Medium | Stage 4 work; PyTorch reference first, MLX port after Gate G-X2 |
230+
| **Multimodal scaling (G-X3) fails** | Medium-high | Acceptable: ship v0.5-A as text-only, multimodal becomes v0.6+ research |
231+
| **Gemma 4 multimodal isn't open-weights as expected** | Low-medium | Substitute closest open multimodal model (Llama-3.2-Vision, InternVL, etc.) |
232+
233+
## 7. Open questions
234+
235+
* **Where in the verifier is the cross-attention layer inserted?** — Default proposal: middle (layer K = 14 of 28). Ablation in toy prototype: try {final-layer, mid-layer, multi-layer (every 4th)}.
236+
* **Which proposer hidden state feeds the bank?** — Default: proposer's final-layer hidden after the last diffusion step. Ablation: try {final-layer, mid-layer, attention-weighted combination}.
237+
* **Single cross-attention head or multi-head?** — Default: 8 heads (matches verifier KV head count). Ablation in toy prototype.
238+
* **Is `α = 0, β = 1` (pure 3b) better than `α = 1, β = 1` (joint)?** — Empirical; default pure-3b after sequential 3a.
239+
* **Does the cross-attention work for generation, not just predicting token N+1 from full prefix?** — Critical for video (long generation). Test in G-X3 explicitly.
240+
241+
## 8. References
242+
243+
* Speculative decoding correctness contract: [ADR 0001 §2.2](0001-proposer-sizing-and-alignment.md), [`kv_cache_proposer/speculative.py`](../../kv_cache_proposer/speculative.py)
244+
* Sink+window invariant: [ADR 0001 §3, §5](0001-proposer-sizing-and-alignment.md), [ADR 0008 §2.4](0008-session-bound-runtime-and-grpc-protocol.md)
245+
* A/B benchmark surfacing the failure: `results/platform-tests/sink_window_quality_ab_1780714635.json`
246+
* Compressive Transformer: Rae et al., "Compressive Transformers for Long-Range Sequence Modelling," ICLR 2020.
247+
* Memorizing Transformers: Wu et al., "Memorizing Transformers," ICLR 2022.
248+
* InfLLM: Xiao et al., "InfLLM: Training-Free Long-Context Extrapolation," ICML 2024.
249+
* RETRO: Borgeaud et al., "Improving Language Models by Retrieving from Trillions of Tokens," ICML 2022.
250+
* EAGLE-3: Li et al., "EAGLE-3: Scaling up Inference Acceleration via Dynamic Draft Trees," 2024.
251+
* Repr-Align training pipeline: [ADR 0004](0004-alignment-training-data-preparation-policy.md).
252+
253+
## 9. Implementation pointer
254+
255+
Toy prototype scaffold lives at `scripts/research/cross_attn_toy_prototype.py` (this PR). Phase 1 (G-X1) target: text-only Gemma 3/4 family, 1-2 week feasibility study on Mac M4. Multimodal hooks documented inline so Phase 2/3 are mechanical extensions, not architectural rewrites.

scripts/research/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)