Skip to content
INDIE / MACHINE
CONCEPTLESSON 6 OF 67 MIN

Training and serving Engram

Where the layers go, how much of the parameter budget to give them, the training recipe, serving a 100B table from host memory, and what Engram ends up storing.

STEP 1 / 8QUIZ 0 / 3
01 /

Where it goes

Engram-27B has two Engram layers in a 30-block model, at layers 2 and 15 (the demo's config writes them 0-indexed as [1, 15]). The output is added to the residual before attention and the MoE of that block.

In the paper's ablation on a 12-layer model, a single Engram layer did best at layer 2 and got worse the deeper it went. Early placement is consistent with the paper's analysis: models with Engram reach a given internal representation earlier, as if they had more effective depth (their CKA study matches Engram-27B's layer 5 to the MoE baseline's layer 12).

02 /

How much memory?

Hold total and active parameters fixed and move a share of the sparse (inactive) budget from experts to Engram. The paper calls the expert share ρ:

P_MoE = ρ · P_sparse, P_Engram = (1 − ρ) · P_sparse
ρ = 100% is pure MoE.
FINDINGPAPER
Best splitρ ≈ 75-80%: 20-25% of the sparse budget in Engram
Loss at 10B total, pure MoE → best split1.7248 → 1.7109
Still matches pure MoE atρ ≈ 40%
Engram-27Bρ = 74.3%

Both extremes lose: all experts means no memory, all memory means too little computation. Plotted against ρ, validation loss traces the U-shaped scaling law in the paper.

03 / CHECK YOURSELF

Quick check

With ρ = 80%, what share of the sparse parameters is Engram?

04 /

The training recipe

  • The embedding tables train with Adam at 5× the base learning rate and no weight decay; the backbone uses Muon at 4e-4 with weight decay 0.1.
  • The conv weights start at zero, “to strictly preserve the identity mapping” of the conv branch.
  • Each row only gets gradient when an n-gram hashes to it, so updates are sparse: a scatter-add in the backward pass, not a dense matmul.

Set the conv scale to 0 and the conv branch adds nothing: the output is exactly the gated value. Raise it and |y − value| appears.

INTERACTIVE / LIVE ENGRAM (HYPERFIELD, IN THIS PAGE)
The function from the code step, running in your browser: width 8, orders 2 and 3, two heads each with 31-43 rows, fixed weights. Words are normalized before they get an id, so “The” and “the” are the same token. ↺ marks an n-gram the sentence already read: the same rows, the same memory. The gate still differs, because it also looks at the hidden state.
05 /

Serving a 100B table

Because rows depend only on token ids, the server knows which rows a step needs before the first block runs. The paper keeps the whole table in host memory and copies just those rows over PCIe while the first block computes:

ARCHITECTURE DIAGRAM
Rendering diagram...
BACKBONE (H800, NANO-VLLM)WITHOUT ENGRAMWITH A 100B-PARAM ENGRAM TABLE IN DRAM
4B dense9,031.62 tok/s8,858.28 tok/s
8B dense6,315.52 tok/s6,140.02 tok/s (−2.8%)

No caching in GPU memory was used for those runs, so every row crossed PCIe. MoE cannot do this: its routing depends on the hidden state, so it is only known once the previous layer has finished.

06 / CHECK YOURSELF

Quick check

Why can Engram's rows be prefetched from host memory when MoE experts can't?

07 /

What ends up in the table

The paper switches Engram off at inference in a trained model. Factual-knowledge benchmarks keep only 29-44% of their score (TriviaQA 29%); reading comprehension keeps 81-93% (C3 93%). The table holds the facts; the context-dependent work stays in the backbone - the split the design was aiming for.

For generation, a cached decode step only needs each Engram layer's last two token ids (for the next trigram) and the last nine conv inputs. Hyperfield's layer keeps both in the KV cache, and chunked decoding gives the same outputs as one full pass.

  • Compress the vocabulary, hash every 2- and 3-gram into several prime-sized tables.
  • Concatenate the rows; let the hidden state gate them through a signed-sqrt sigmoid.
  • Add a short dilated conv; add the result to the residual.
  • Train the tables sparsely with a higher learning rate; serve them from wherever memory is cheap.
08 / CHECK YOURSELF

Last check

With Engram disabled at inference, which kind of task suffers most?

LESSON 6 COMPLETE

That's the whole The Engram Course. Nice work.