Engrams for GLM-5.3: Why You Can't Transcode Experts into Lookup Tables
- The idea, and why it is seductive
- What Engram actually is
- Why an expert cannot be transcoded
- DeepSeek's win does not cut the bytes we stream
- The arithmetic on our box
- What people have actually retrofitted
- The serving side, for completeness
- The cousin idea: memoize MoE outputs by n-gram
- What we would measure before believing any of it
- The honest comparators
- Verdict and reopen triggers
The idea, and why it is seductive
Two models live on the same DGX Station GB300, and they pay for host memory in completely different currencies.
The big GLM-5.3 (744B, NVFP4) does not fit in 250.7 GiB of HBM, so all 75 MoE layers of routed experts are pinned in Grace RAM and read over NVLink-C2C through a per-layer slot cache. Every decode step the GPU streams whole experts that missed the cache: 18 MiB of 4-bit weights plus 2.25 MiB of scales, each. Nsight puts that at 18 ms of a 40.1 ms K=1 step, 46.6% of the budget. It is the reason the lane sits at 54.7 tok/s C1 and the reason every lever we have tried since September has been about which experts live where.
DeepSeek-V4.1-Flash, on the :30006 lane, also keeps ~190 GiB of parameters in Grace: its two Engram modules, 196B parameters of hashed n-gram embeddings. Those cost 0.04 ms of a 14.6 ms step. Same RAM, same link, four hundred times cheaper per step. The difference is shape: an Engram lookup is 48 rows of 264 bytes at addresses known before the forward pass starts; an expert miss is 20 MiB of contiguous weights the GPU has to pull before it can multiply.
So the question writes itself. Parameters in table form are nearly free in Grace. Parameters in expert form are bandwidth-bound. GLM-5.3 has 725B parameters in expert form. Could some of them be moved into table form, and would that let the lane stream less?
I spent a research round on it: four background workers against primary sources (the Engram paper, the V4.1-Flash tech report, the Qwen3.8-Flash-Next report, the GLM-5.3 config and card, vLLM source on both our pinned build and upstream main, and every retrofit or lookup-table paper we could find through October 2026). This post is the teaching version of the answer. The physics intuition is right. The premise about where the parameters come from is wrong, and the arithmetic does not rescue it.
What Engram actually is
Engram is DeepSeek's "conditional memory" module (Cheng et al., arXiv:2601.07372, January 2026, revised July). MoE is conditional computation: route the token to a few experts and run them. Engram is the complementary axis, conditional memory: look up a static vector for a fixed local pattern and add it to the residual stream, O(1), no matmul.
- Address. For position t and n-gram order n, the key is the suffix of compressed token ids ending at t. Compression folds case and Unicode variants (23.4% vocabulary reduction on their 128k tokenizer). Each order has several hash heads; each head hashes the n-gram into its own prime-sized table. The rows from all heads and orders are concatenated.
- Gate. The retrieved vector is a context-free prior. The hidden state is the query: a key projection of the row is compared with the normalized hidden state, and a sigmoid gate scales the value projection before it is added. If the memory contradicts the context, the gate closes. The paper's ablation lists removing this gate as one of the three largest regressions.
- Placement. Early. In a 12-layer sweep the best single injection is layer 2; the loss degrades as the module moves deeper. V4.1-Flash puts its two modules at zero-indexed layers 1 and 14 "to balance memory usage across training pipeline stages."
- Training. From scratch, jointly with the backbone. Engram tables get a 5× learning rate; V4.1 swaps Adam for a momentum update with Sinkhorn balancing to avoid optimizer state on 196B rows. There is no post-hoc stage anywhere in either paper.
- Inference. Because the address depends only on token ids, every row can be prefetched from host memory before the layer that needs it. That is the whole reason the 0.04 ms exists.
V4.1-Flash's modules: n-gram orders {2, 3, 4}, 8 heads, 256 dims per head (2048 per order), ~16M rows per head at distinct primes, FP8 rows plus ue8m0 block scales. That is 384M rows × 264 B = 94.4 GiB per module computed, 94.6 GiB per module as we measured it pinned. Qwen3.8-Flash-Next adopted the same primitive (they call it "N-gram Embedding": 51B parameters, one module at layer 2, 20M bigram/trigram rows) — also trained in from step zero.
Why an expert cannot be transcoded
This is the part that kills the idea before any arithmetic.
| routed expert | Engram row | |
|---|---|---|
| input | h ∈ R^6144, the post-attention hidden state — a function of the entire prefix | a hashed suffix n-gram of token ids — a function of the last 2–4 tokens |
| computes | W2 · silu(W1 h) ⊙ (W3 h), 37.7M parameters | a stored vector, gated by h but not computed from it |
| domain | continuous, unbounded | finite, enumerable before the forward pass |
| can be precomputed into a table? | no — there is no finite set of inputs to precompute over | it is the table |
There is exactly one paper that turns trained experts into exact lookup tables: Mixture of Lookup Experts (arXiv:2503.15798, ICML 2025). It works because MoLE changes the architecture before training so that experts take the embedding-layer output as input instead of the hidden state. The input domain is then the vocabulary, a finite set, and FFN_j(Embedding(i)) can be precomputed for every i. A GLM-5.3 expert was trained on h. Two prefixes that share a 4-token suffix can need different expert outputs, and the expert gives them different outputs. A token-keyed table cannot, by construction. The best a table can do is store the per-n-gram mean of the expert's output and hope the residual is small. Nobody has published that residual for any frontier MoE, and the Engram paper's own gate ablation is a warning that an ungated prior hurts.
DeepSeek's win does not cut the bytes we stream
Even granting a magic conversion, the Engram result does not do what the physics argument needs.
The paper's "sparsity allocation" law holds total parameters and activated parameters fixed and varies ρ, the fraction of the inactive sparse budget kept as experts. Validation loss is U-shaped; the optimum moves ~20–25% of the sparse budget into Engram. The 27B demonstration cuts routed experts from 72 to 55 and spends the freed parameters on 5.7B of tables. Top-6 is unchanged. Activated parameters are unchanged. The expert GEMM volume per token is unchanged. What shrinks is how many experts exist in storage, not how many are read when a token routes.
Our 18 ms is not a tax on unused inventory. It is the bytes of the experts that were routed to and missed the 7,360-slot HBM cache. Inventory shrink only helps that number indirectly, by letting the same slots cover a larger fraction of a smaller set (7,360 / 19,200 = 0.38 coverage today; a 72→55-style cut would make it 0.50 — and coverage is not hit rate, and the full-trace LRU ceiling at this budget is already 0.802). That is a cache-footprint experiment wearing an Engram costume, and it requires deleting experts, which is a quality decision James has not made.
Qwen's version of the same sweep (Qwen3.8-Flash-Next report, Table 8) is worth knowing: a fixed-budget swap of 10 / 25 / 50% of parameters from experts into n-gram tables lowered loss but showed no clear downstream win. They stopped treating n-gram as a substitute for experts, kept all 512, and scaled the table on top. Two labs, same primitive, and neither one shipped a model with fewer active expert bytes because of it.
The arithmetic on our box
The routed-expert payload is an identity, not an estimate: 75 MoE layers × 256 experts × (3 × 6144 × 2048) parameters / 2 bytes-per-pair = 337.5 GiB, which is exactly what the lane measured. FP8 scales at one per 16 weights add 42.2 GiB (the ledger's "45 GB"). Per MoE layer: 5.06 GiB. Per expert on the wire: 18 MiB + 2.25 MiB.
| first N MoE layers → tables | backbone layers | expert bytes freed | C2C saved (modeled) | share of 40.1 ms step |
|---|---|---|---|---|
| 4 | 3–6 | 20.25 GiB | 0.96 ms | 2.4% |
| 8 | 3–10 | 40.5 GiB | 1.92 ms | 4.8% |
| 12 | 3–14 | 60.75 GiB | 2.88 ms | 7.2% |
| 16 | 3–18 | 81.0 GiB | 3.84 ms | 9.6% |
| 19 | 3–21 | 96.2 GiB | 4.56 ms | 11.4% — pays for one module |
| 38 | 3–40 | 192.4 GiB | 9.12 ms | 22.7% — pays for two; half the MoE stack |
Modeled: the 18 ms is split uniformly by N/75. No layer-resolved miss profile exists for this lane; if early layers are hotter than average (plausible, unmeasured), the real saving is smaller. Do not convert these to tok/s — the 40.1 ms budget is K=1 and the 54.7 tok/s is MTP K=2. A second modeled read that also credits the freed slots to the remaining layers’ hit rate reaches 6.9–9.9 ms for N=16 (at hit 0.44 / 0.61, capped at the 0.802 LRU ceiling); that is an upper sketch resting on a residency→hit-rate curve nobody has measured, and it still requires deleting 16 layers and training a table that does not exist.
Now the other side of the ledger. A V4.1-sized module is 94.6 GiB pinned. Grace is 494 GiB with no swap. After the expert pin the arithmetic headroom is 114.3 GiB, before the OS, the vLLM process, page tables and shared memory — and the lane has already host-OOMed once at a sloppy pin.
Grace budget on the big GLM-5.3 lane. The bar is to scale (494 GiB → 820 px). Two V4.1-sized Engram modules overflow by 75 GiB even with zero process overhead; one module fits only on paper.
Put the two tables together: to make room for one module you delete 19 MoE layers (a quarter of the stack) for a modeled 11% step-time saving, and you have not yet trained the table that is supposed to replace what those layers did. The Engram paper's own ρ→0 arm says an Engram-dominated allocation "loses conditional computation capacity." Thirty-eight deleted layers is that regime.
And the published placement lands in the wrong place anyway. The paper's best single injection is layer 2; V4.1 uses 1 and 14. GLM-5.3's layers 0–2 are dense. The first streamed expert layer is index 3. Copying either placement onto GLM does not touch a streamed parameter.
What people have actually retrofitted
The question I most wanted answered: has anyone added an Engram-style memory to an already-trained model, or removed experts and compensated with one? Ranked by closeness to "convert this checkpoint's experts":
| work | what it did | scale | deletes experts? |
|---|---|---|---|
| STAPLE (Oct 2026) | Continued-trains OLMo-2 with token-indexed tables added as a residual beside the kept FFN up-projection. Their Engram-style upcycle arm (layers 2 and 7, hashed 2/3-grams) lost to the simpler token residual. Replacing the up-projection (STEM) stays below the dense baseline even after 100B tokens. | 1B, 7B | no |
| TF-Engram (Jul 2026) | Train-free: mines phrases from an external corpus, encodes them, injects into a frozen model. Ten-benchmark average 57.6 → 59.4. | Qwen3-0.6B | no (dense) |
| Cross-model memory transfer (Aug 2026) | Freezes an Engram table trained with model A, attaches to frozen model B, trains only a reader. | ≤9B | no |
| BadEngram (Sep 2026) | Grafts an 8,191-row Engram onto a frozen 7B as a backdoor. Proves a frozen backbone accepts a residual from a trained graft; reports attack success, not MMLU. | 7B | no |
| Memory Decoder (2025) | Separate 0.5B transformer imitating a kNN retriever, interpolated at the logits. +28% inference cost. | Qwen2.5, Llama | no |
| DSV4.1-Flash, Qwen3.8-Flash-Next | Trained the tables in from step zero (45T tokens; a new pretrain respectively). | 552B+196B; 125B+51B | n/a |
Nothing on that list deletes an expert. Nothing is within an order of magnitude of 744B. The only retrofit with a real downstream win (STAPLE) keeps every FFN weight and found the Engram shape worse than a plainer one. If GLM-5.3 ever carries n-gram memory, it will be because Z.ai trained it in; the public config has no engram, ngram or ple field, and the card says 5.3 shares its base with 5.2 — every gain is post-training.
On training cost, for the record: the one experiment that fits one GB300 is a probe — freeze the backbone, stage the first K MoE layers in HBM (8 layers = 36 GiB), train a table to mimic their outputs, measure the residual. It does not produce a checkpoint that can drop those experts. Anything that unfreezes a 744B backbone needs BF16 master weights (1.49 TB) plus optimizer state; our eight DGX Sparks total 1.02 TB. GLM-5 was pretrained on 28.5T tokens; V4.1-Flash on 45T. That is not a one-person lab's afternoon.
The serving side, for completeness
Assume the checkpoint existed. vLLM's Engram is pure Python + Triton (no csrc): FP8 rows gathered from pinned host memory over UVA on a side stream, prefetched before the consuming layer, gated into DeepSeek V4.1's hyper-connection residual of shape [T, hc_mult, H], with token history read from the DSA sliding-window metadata. The allowlist in vllm/config/engram.py is three architecture strings: DeepseekV41ForCausalLM and the two Qwen4Exp* classes. Qwen did not reuse the DeepSeek module; PR #54371 was a parallel PLE stack (+1712/−495 lines) sharing only the config object. GlmMoeDsaForCausalLM is an alias of DeepseekV32ForCausalLM with a plain residual. Our pinned v0.28.0 image contains zero Engram files; it lands with the V4.1 support in the 0.30 line.
A graft is on the order of 1–2k lines and 2–4 weeks after the MRV2 rebase the lane already treats as its expensive open lever — a new token-history source, a gate for a non-mHC residual, the weight mapper (the engram.embed.scale regex is the silent one), and a re-validation of the slot-cache hook under piecewise CUDA graphs. It is the cheapest part of the whole proposal, and it is moot without the checkpoint.
The cousin idea: memoize MoE outputs by n-gram
If you cannot retrain, the next thought is an inference-time cache: key the MoE layer's output (or a cold expert's output) on the hashed token n-gram, serve the cached vector on a hit, run the real experts on a miss. "Engram-like," but learned from the model's own outputs instead of trained.
Three things are wrong with it as a bytes lever, and only one of them is the function-class problem again.
- It is a partial function. Unseen n-grams — most of a Zipf tail — still need the real experts, so the experts stay pinned. Not one byte leaves the streaming set.
- A hit only saves a miss the slot cache would have paid. Frequent n-grams are the tokens whose experts are most likely already resident in HBM. The intersection between "n-gram frequent enough to cache" and "expert that would have missed" is exactly the quantity that decides whether this does anything, and it is unmeasured.
- Ungated. Engram's gate exists so the memory can be suppressed when context disagrees with the prior. An ungated cache of observed outputs is the paper's own worst ablation, minus the training. Polysemy is the test case: the same 3-gram in two contexts that should not share a layer output, averaged into one centroid.
Geva et al.'s "FFN layers are key-value memories" is often cited here. Read it carefully: the key is an inner product with the hidden state x, not a token hash, and "lower layers capture shallow patterns" is not "lower layers are token-determined." After one attention layer, nothing is.
What we would measure before believing any of it
None of this changes serving. The first one is minutes of CPU.
| # | measurement | cost | what it decides |
|---|---|---|---|
| M3 | n-gram coverage, CPU only. On 200k–1M tokens of real agent traffic, the fraction of tokens whose suffix 2/3/4-gram has count ≥2, ≥8, ≥32. | minutes, no GPU | If coverage at ≥8 is small next to the measured agent-traffic miss rate (1 − 0.41 = 0.59), the memoization variant is dead before any GPU work. |
| M4 | Within-bucket stability. Hook the MoE residual addend (routed + shared) at layers 3–18 with controls at 20/40/77; per n-gram bucket with support ≥8, mean cosine to centroid and variance explained — and the same on the pre-MoE hidden state: if h is not stable in a bucket, y cannot be. | 1–5 min of prefill at 3.4k tok/s; statistics only (naive vector dumps would be 183 GiB) | A high cosine is a screen, not a logprob. It only earns a quality gate. |
| M1 | Layer-resolved C2C miss bytes, layers 3–18 vs 19–77, on agent and probe mixes. | one lane-down profiling boot | The only number that can make the N-layer table above real or kill it. Sharpens every residency lever, not just this one. |
| M2 | Host residual after exact-pin: pinned bytes, RSS, MemAvailable, lane idle. | read-only snapshot | Whether "114 GiB headroom" is memory or arithmetic. |
If anything is ever built, the gate is the lane's standing one: teacher-forced logprobs against the incumbent including a long prefix (the slot-cache hook's bar is max |Δlogp| = 0.0 on 3,071 tokens; any nonzero delta is "measured, not promoted"), needle 18/18 to 211K, the task ladder, MTP acceptance per class, plus two cache-specific slices — a forced-miss slice that must equal the incumbent, and a polysemy slice. Deleting experts to make room for a table is pruning-plus-compensation and needs James's explicit yes.
The honest comparators
The physics goal — fewer streamed bytes per step — has levers that do not require a training run. The retrofit has to beat these, and it cannot, because it does not touch the 18 ms unless experts are deleted.
| lever | attacks the 18 ms? | status |
|---|---|---|
| Sub-4-bit cold-expert tier | yes, proportionally on misses | legal under the September 30 quality policy; gate runs on the box; QMoE precedent is a top-1 Switch Transformer, transfer unverified |
| KV → expert slots (HiSparse capacity trade) | yes, via hit rate | the one ≥10% modeled lever from the October 16 round; behind the MRV2 rebase |
| Explicit expert prune (REAP class) | yes, ≈ f of misses for fraction f | needs James's yes; near-lossless on coder models at 50% in the paper, never run on GLM-5.3 |
| Cross-layer expert bank (vLLM #56177 idea) | only via fewer unique bytes | offline sim first, bar ≥ +0.02 hit |
| Engram retrofit | no — adds bytes unless experts are deleted | research probe at most |
Verdict and reopen triggers
- No boot, no checkpoint work. The Engram-for-GLM idea is closed as a serving lever on this box.
- M3 runs if James wants the memoization variant closed with data rather than literature. It is a CPU script over traffic we already have.
- M1 and M2 fold into the next lane-down window regardless — they are the measurements every residency lever has been missing.
- Reopen only if Z.ai ships a GLM with n-gram memory trained in, or someone publishes a frozen-backbone expert→table distillation at ≥100B with a real quality gate.
What I keep from the round is the teaching point: DeepSeek did not make their tables cheap by putting them in host memory. They made them cheap by training parameters that are addressable before the forward pass. Host placement is the consequence, not the trick. You cannot get the consequence by moving someone else's parameters.
Credits
- DeepSeek — the Engram paper and the V4.1-Flash tech report, which say plainly how the tables are trained and placed.
- Qwen — for publishing the fixed-budget sweep (Table 8) that did not win, which is rarer than publishing the one that did.
- Sadhukhan et al. (STAPLE) — the only retrofit on the list with a real downstream number, and an honest loss for the Engram-shaped arm.
- Jie et al. (MoLE) — the existence proof of what an exact expert→table conversion requires.
Sources
- Cheng et al., Conditional Memory via Scalable Lookup — arXiv:2601.07372
- DeepSeek-AI, DeepSeek-V4.1-Flash tech report (§2.4.2 Engram, §3.1.3) — arXiv:2609.19969; checkpoint deepseek-ai/DeepSeek-V4.1-Flash
- Qwen Team, On the Design of Qwen3.8-Next Architecture — tech report; model card
- zai-org/GLM-5.3 config.json and model card; GLM-5 report arXiv:2602.15763
- Jie et al., Mixture of Lookup Experts — arXiv:2503.15798
- Sadhukhan et al., STAPLE — arXiv:2610.12599 · Ma et al., TF-Engram — arXiv:2607.07388 · Li et al., cross-model memory transfer — arXiv:2608.17050 · Fogel et al., BadEngram — arXiv:2609.13478 · Cao et al., Memory Decoder — arXiv:2508.09874
- Geva et al., Transformer Feed-Forward Layers Are Key-Value Memories — arXiv:2012.14913 · Lasby et al., REAP — arXiv:2510.13999 · Frantar & Alistarh, QMoE — arXiv:2310.16795
- vLLM: docs/features/engram.md · vllm/config/engram.py · #54371 (Qwen4Exp PLE offload) · #56512 (async Engram prefetch) · #56815
- Lane measurements: GB300 GLM-5.3 Testing (18 ms / 40.1 ms step, slot cache, 54.7 tok/s) and GB300 DeepSeek Flash 4.1 Testing (Engram 2 × 94.6 GiB, 0.04 ms)