Skip to content

feat(gpu): Engram byte-n-gram conditional memory + validated framing protocol - #215

Merged
ronaldtse merged 2 commits into
mainfrom
feat/engram-module
Sep 12, 2026
Merged

ronaldtse merged 2 commits into
mainfrom
feat/engram-module

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Implements TODO.impl/10's free portion — the lexical-memory lever whose gate opened when 02 (teacher mixture) and 04 (trained-init lite) both closed negative.

The module (src/gpu/engram.py): one embedding table addressed by hashes of the byte n-grams ending at each position (orders 2/3/4), summed into the encoder stream at one layer — the proportionate dose of DeepSeek's Engram for a 300M byte-level backbone. Zero-init projection leaves the backbone untouched at step 0 (the PKM rule). Artifact form: int8 table + fp16 projection — 64 MiB at 2M x 32, a defensible tier between lite (95 MB) and 2.1-int8 (264 MB).

Export contract, settled by the probe: python-side hashing is not graph-exportable, and ONNX rejects int64 bitwise-AND — so from_addresses is the pure-graph path (Gather + mean + Linear with remainder addressing, which also re-enables the report's prime table sizes), and the hash becomes a 20-line portable function per runtime with addresses as an IMF input. Probe passes: export → ORT → torch within 1e-4.

Also: the validated framing protocol (greedy v3) that today's matrix was measured with — two protocol bugs invalidated the first runs (a cache-rebuild corruption and a PAD-dropping window); main still carried the buggy script.

6 Engram specs green. The training run remains owner-gated (one distill run with the table attached).

Ronald Tse added 2 commits September 12, 2026 21:34
…opened)

The lexical-memory lever: one embedding table addressed by hashes of
the byte n-grams ending at each position (orders 2/3/4), summed into
the encoder stream at one layer. Zero-init projection leaves the
backbone untouched at step 0 (the PKM rule). int8 table + fp16
projection as the artifact form (64 MiB at 2M x 32).

Export contract settled by the probe: hashing is NOT graph-exportable
(python data-dependence) and int64 bitwise-and is rejected by ONNX -
from_addresses is the pure-graph path (Gather + mean + Linear with
remainder addressing, which also allows the report's prime table
sizes), and the hash becomes a 20-line portable function per runtime,
with addresses as an IMF input. Probe: export -> ORT -> torch match
within 1e-4.

6 specs: determinism and order separation, byte-not-token addressing,
zero-init identity, context sensitivity, int8 roundtrip, ONNX
gather survival. Training run remains owner-gated.
Two protocol bugs invalidated the first framing runs: a cache-rebuild
loop that re-fed window tokens onto a cache already containing them,
and a window that dropped the PAD prefix (batch=1 degenerated to an
order-1 Markov decode - fp32 'diverging' with itself was the tell).
v3 windows over the full consumed sequence [PAD]+tokens and uses the
judge call's own presents as the advanced cache. Sanity: fp32 framing
480/480 under Python ORT (the physics baseline).
@ronaldtse
ronaldtse merged commit 66e6343 into main Sep 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant