Skip to content

Commit 05c5c3a

Browse files
Add memory computability guide
Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
1 parent 9d2c8d6 commit 05c5c3a

2 files changed

Lines changed: 264 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ algorithmic core in this repo with continuous batching, async
286286
proposer/verifier pipelining, NF4 KV quantization, and a fixed-slab
287287
KV pool sized for sink+window. Architecture and phased build plan are
288288
in [`docs/local-inference-engine.md`](docs/local-inference-engine.md).
289+
The memory-computability design baseline is captured in
290+
[`docs/memory-computable-guide.md`](docs/memory-computable-guide.md).
289291

290292
Short version of why the engine **does not use PagedAttention**: the
291293
sink+window invariant turns each session's KV cache into a constant-size

docs/memory-computable-guide.md

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
# Memory Computable Guide
2+
3+
This guide captures the current design baseline for memory computability in
4+
the Kakeya inference engine. It deliberately starts from the three laws of
5+
attention and memory computation, then translates them into a trainable memory
6+
operator. It does not assume proposer cross-training.
7+
8+
## Three laws
9+
10+
### 1. Alignment object law
11+
12+
Attention aligns to the output token distribution; memory aligns to stored
13+
records.
14+
15+
- Attention computation is constrained by generation targets such as
16+
`P(y_t | x, y_<t)`.
17+
- Memory computation is constrained by already stored records such as user
18+
history, interaction traces, documents, logs, or persistent system state.
19+
20+
In short:
21+
22+
```text
23+
attention alignment = distribution alignment
24+
memory alignment = record alignment
25+
```
26+
27+
### 2. Sparsification law
28+
29+
Both attention and memory need sparse classification, but under different
30+
constraints.
31+
32+
- Attention sparsifies under a generation-distribution constraint and is a
33+
natural fit for autoregressive token generation.
34+
- Memory sparsifies by topic under an existing-record constraint and is a
35+
natural fit for diffusion-style reconstruction.
36+
37+
The important distinction is not "short term vs long term". It is whether the
38+
sparse choice is judged against a token distribution or against stored records.
39+
40+
### 3. Mutual embedding law
41+
42+
Attention contains memory storage; memory contains attention forward. They are
43+
not opposing modules, but mutually embedded computation processes.
44+
45+
For this guide, "memory contains attention forward" means that the current
46+
Transformer computation predicts a memory support distribution. It is not a
47+
claim that attention forward has already read a verified memory fact.
48+
49+
## Memory computation definition
50+
51+
Memory computation is the extension of attention computation from output
52+
distribution alignment to stored-record alignment:
53+
54+
```text
55+
current Transformer state
56+
-> memory attention forward
57+
-> memory support prediction
58+
-> record-aligned support objective
59+
-> sparse topic support
60+
-> diffusion-style denoising convergence
61+
-> record-aligned memory state
62+
```
63+
64+
The core operator is:
65+
66+
```text
67+
M(q, R) -> z_M
68+
```
69+
70+
where:
71+
72+
- `q` is the current Transformer computation state.
73+
- `R = {r_i}` is the set of stored records.
74+
- `M` is the memory computation operator.
75+
- `z_M` is the resulting memory state.
76+
77+
The required constraint is:
78+
79+
```text
80+
z_M ~= E(R_relevant)
81+
```
82+
83+
where `R_relevant` is the stored-record support that should be relevant for
84+
the current computation.
85+
86+
## Operator boundaries
87+
88+
### Memory attention forward predicts support
89+
90+
Memory attention forward produces a support prediction:
91+
92+
```text
93+
pi = P(record/topic | q, R)
94+
```
95+
96+
This is a prediction over records or topic clusters. It is not a verified read.
97+
The support prediction must be aligned to stored records during training.
98+
99+
### Record alignment is the memory requirement
100+
101+
Record alignment is not an optional external check. It is the core training
102+
requirement that makes the support prediction a memory computation rather than
103+
a generic retrieval or generation bias.
104+
105+
The model must learn:
106+
107+
```text
108+
predicted support ~= relevant stored records
109+
```
110+
111+
If this alignment fails, later denoising can stabilize or amplify the wrong
112+
topic.
113+
114+
### Diffusion denoising converges within support
115+
116+
Diffusion-style reconstruction does not change the predicted topic support.
117+
It only denoises and converges inside the support produced by memory attention
118+
forward.
119+
120+
```text
121+
z_T -> z_0 ~= E(R_relevant)
122+
```
123+
124+
Therefore diffusion is useful only after the support prediction is record
125+
aligned. If the support is noisy or wrong, diffusion can make that wrong memory
126+
state more stable rather than correcting it.
127+
128+
## Minimal neural operators
129+
130+
### 1. Transformer state adapter
131+
132+
Maps the current Transformer computation state into a memory query:
133+
134+
```text
135+
q_M = Phi(q)
136+
```
137+
138+
The adapter can consume hidden states, residual states, attention summaries,
139+
or other current-forward state summaries.
140+
141+
### 2. Record encoder
142+
143+
Maps stored records into the memory space:
144+
145+
```text
146+
r_i -> e_i
147+
```
148+
149+
The output can be grouped into record embeddings, topic embeddings, or
150+
record-topic blocks.
151+
152+
### 3. Memory attention forward
153+
154+
Predicts a sparse support distribution over records or topics:
155+
156+
```text
157+
score_i = sim(q_M, e_i)
158+
pi = sparsemax(score) # or entmax / top-k routing
159+
```
160+
161+
### 4. Support alignment head
162+
163+
Trains `pi` against the known relevant support:
164+
165+
```text
166+
L_support = CE(pi, support_label)
167+
```
168+
169+
or a contrastive support objective:
170+
171+
```text
172+
L_support = -log exp(sim(q_M, e_pos) / tau)
173+
/ sum_j exp(sim(q_M, e_j) / tau)
174+
```
175+
176+
### 5. Diffusion memory denoiser
177+
178+
Denoises a memory latent inside the predicted support:
179+
180+
```text
181+
L_denoise = || eps - eps_theta(z_t, q_M, pi, R, t) ||^2
182+
```
183+
184+
The denoiser should be evaluated only with support-quality metrics attached,
185+
because denoising quality is meaningless if the support is wrong.
186+
187+
## Training objective
188+
189+
The memory operator can be trained with:
190+
191+
```text
192+
L_memory =
193+
L_support_alignment
194+
+ lambda_record * L_record_alignment
195+
+ lambda_sparse * L_sparse_topic
196+
+ lambda_denoise * L_diffusion_reconstruction
197+
+ lambda_cf * L_counterfactual_record
198+
```
199+
200+
Where:
201+
202+
- `L_support_alignment` trains memory attention forward to predict the correct
203+
record or topic support.
204+
- `L_record_alignment` trains the final memory state to align with the stored
205+
records.
206+
- `L_sparse_topic` encourages a small active topic set.
207+
- `L_diffusion_reconstruction` trains denoising convergence inside the support.
208+
- `L_counterfactual_record` verifies that changing stored records changes the
209+
predicted support and memory state.
210+
211+
## H200 training target
212+
213+
The first H200 training milestone should validate the memory operator itself,
214+
not proposer integration.
215+
216+
Recommended sample shape:
217+
218+
```text
219+
(q, R_positive, R_negative, R_counterfactual, support_label)
220+
```
221+
222+
The run should report both model-quality and system-efficiency metrics.
223+
224+
### Quality metrics
225+
226+
- Support precision: predicted support records are relevant.
227+
- Support recall: relevant records are covered by the predicted support.
228+
- Record alignment accuracy: `z_M` matches the correct stored record state.
229+
- Sparse topic entropy: routing remains sparse rather than diffuse.
230+
- Denoising gain on clean support: diffusion improves a correct support state.
231+
- Noise amplification rate: diffusion does not stabilize wrong support.
232+
- Counterfactual flip rate: replacing records changes support and `z_M`.
233+
- Update/delete consistency: changed or deleted records stop influencing
234+
memory output.
235+
236+
### H200 system metrics
237+
238+
- Samples per second.
239+
- Records per second.
240+
- HBM usage.
241+
- Routing latency.
242+
- Denoising latency.
243+
- End-to-end memory-operator latency.
244+
245+
## Acceptance criteria
246+
247+
The memory operator should be considered valid only if:
248+
249+
1. Support prediction aligns to stored records with high precision and recall.
250+
2. Diffusion denoising improves record-aligned states on clean support.
251+
3. Diffusion does not amplify noisy or wrong support beyond an allowed budget.
252+
4. Counterfactual record changes cause corresponding memory state changes.
253+
5. Record update/delete tests stop stale records from influencing output.
254+
6. The H200 latency and memory overhead are small enough to justify later
255+
inference-engine integration.
256+
257+
## Design summary
258+
259+
Memory computability is not proven by training on historical data. It is proven
260+
when the current computation predicts a sparse memory support, that support is
261+
aligned to stored records, and diffusion-style denoising converges only inside
262+
the aligned support.

0 commit comments

Comments
 (0)