Commit ead7bb9
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
- docs/adr
- scripts
- research
Lines changed: 255 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
Whitespace-only changes.
0 commit comments