TinyEngram: An Engram Memory Module Bolted Onto Qwen and Stable Diffusion
Research of DeepSeek Engram Architecture based on Qwen-3 and Stable Diffusion series.
At a glance
- What is it?
- TinyEngram is a research codebase that reproduces DeepSeek's Engram memory injection on top of Qwen, and extends the same idea to Stable Diffusion's text encoder. It is a notebook-style repository for people who want to run the Engram-versus-LoRA comparison themselves, not a library you can pip install into a product.
- Who is it for?
- Adopt TinyEngram if you are a researcher who wants to reproduce the Engram-versus-LoRA parameter ablation and forgetting comparison on Qwen, or to test whether N-gram memory injection into a Stable Diffusion text encoder is enough for your concept. Do not adopt it if you need a supported inference library, a documented public API, or a licence file you can point a legal reviewer at.
- Can I use it commercially?
- Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
- Is it still maintained?
- Yes. The repository last received commits 118 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
The phrase-level memory problem TinyEngram targets
Transformer language models handle rare multi-token phrases poorly. A name, a product code, or a fixed idiom gets shredded into subword pieces, and the model has no dedicated place to store what that whole phrase means. Fine-tuning on the phrase works but touches every weight. LoRA reduces the number of trained parameters but still writes into the same attention and MLP matrices the base model uses for everything else, which is where interference between unrelated concepts comes from.
TinyEngram is aimed at the narrower question of whether a separate, small memory module can hold phrase-level knowledge and be read out only when that phrase appears. The README describes Engram as an LLM enhancement that boosts phrase-level understanding by integrating a compact N-gram memory module and a gated retrieval mechanism into key transformer layers. The intended audience is people who want to reproduce that claim on a small base model rather than take it on faith. The repository is framed as both a toolkit and a living research notebook, with training logs and findings published in the same place as the code.
What the N-gram memory module actually does
The mechanism has three parts. A hash table keyed by N-grams, a learned embedding per entry, and a gate that decides how much of the retrieved embedding to add back into the hidden state at specific transformer layers. Because the key is a hash of the exact token sequence, lookup is a direct match rather than a similarity search. The README makes a strong claim about what follows from that: since Engram relies on exact N-gram matching, memories strictly do not interfere with each other, and you can stack thousands of different character or style engrams together because each only triggers on its exact name.
That is the design's main selling point and its main risk, and the README does not resolve the tension. Exact matching means no cross-talk, but it also means no generalization. A phrase that is reworded, pluralized, or split across a different token boundary will not hit the same key. The README's own phrase is hard hash collisions, which is the failure mode on the other side: two different N-grams mapping to the same bucket. How the code handles that case is not described in the material available here, and it is the first thing I would read in the source before trusting the composability claim.
The vision extension reuses the same idea. Visual concepts are treated as memories injected into the Stable Diffusion text encoder, triggered by recognizing specific N-grams in the prompt. The U-Net or DiT backbone stays frozen, and only the text-encoder-side memory is trained. The README states the goal is teaching the model new subjects such as specific characters without touching the large generative backbone.
Getting the environment up
The README gives one installation path, and it is deliberately pinned. The commands are a conda environment on Python 3.10, an upgrade of pip, then a single requirements file:
conda create -n tinyengram python=3.10 -y conda activate tinyengram pip install --upgrade pip pip install -r requirements.txt
The README calls requirements.txt a clean, pinned direct-dependency file covering both training and vision reproduction, and defers CUDA notes and optional evaluation dependencies to doc/reproduction/environment.md. That deferral matters: the README does not state a required CUDA or PyTorch version, so the environment doc is the only place to check before you provision a machine. There is no setup.py, no pyproject.toml, and no published package mentioned, so the install story is clone the repo and use the pinned file.
The README does not list the training entry points, the config keys for the memory module (hash size, N-gram order, gate initialization, which layers receive the module), or the commands for the Engram-versus-LoRA reproduction. The announcements say reproduction scripts for that experiment were released, and that parameter ablation studies and a catastrophic forgetting comparison were added, so the scripts exist in the tree. The README just does not enumerate them. Budget time for reading the repository layout rather than the README.
The Engram-versus-LoRA comparison and what it does not settle
The headline claim is that Engram-based memory injection beats LoRA on both parameter efficiency and resistance to catastrophic forgetting, with the vision extension as a second demonstration that the approach is modality-agnostic. The repository timeline backs this up as a research program rather than a single result: an initial commit in January 2026, parameter ablation studies and the forgetting comparison added the same day later that month, the Engram-versus-LoRA reproduction scripts released in early February, the vision experiment in mid-February, and a vision technical report in May 2026 with an arXiv identifier.
What the README does not give is any number. No parameter counts, no forgetting metric, no benchmark table, no base-model size. The claim is stated as a conclusion and the evidence lives in the linked report and the logs in the repository. That is a normal shape for a research README, but it means you cannot evaluate the result from the front page. If the parameter efficiency argument is the reason you are here, read the ablation section of the report before you read the code.
There is also a scope question the README leaves open. The forgetting comparison is described only as being between TinyEngram and LoRA. It does not say which base model, which task, or how forgetting was measured. Those three details decide whether the result transfers to your setting.
Where the design breaks down
The exact-match requirement is the sharpest limitation. A memory module keyed on N-grams is a lookup table with learned values, and lookup tables do not generalize. If your users refer to the same entity three different ways, you need three engrams, and you need to know in advance that all three are coming. For a fixed set of character names in a prompt-driven image generator, that is a reasonable trade. For open-ended text where the target phrase varies in surface form, it is the wrong tool, and the failure is silent: the gate simply does not fire and the model falls back to its base behaviour with no error.
The second constraint is that this is a research repository with no releases. The material shows no tagged versions, no changelog, and no package on an index. Upgrading means pulling main and re-reading the diff. The announcements section, which is where the project records its own history, is the closest thing to a changelog and it is written as dated bullet points rather than release notes.
The third is licensing. The README's badge links to a LICENSE file at the repository root and the badge text says MIT, but the repository metadata supplied here lists the licence as unknown. Those two things disagree. Until you open the file, you do not know what you are agreeing to, and the badge image is not the licence.
How this differs from LoRA and from retrieval augmentation
The obvious alternative is LoRA, and the project positions itself directly against it. The difference is where the new knowledge is written. LoRA adds low-rank update matrices to existing weight matrices, so the stored knowledge is entangled with the base model's computation and every adapter shares the same parameter space. Engram adds a separate table read through a gate, so the stored knowledge sits beside the model rather than inside it. That separation is what the no-interference claim rests on, and it is also why stacking many engrams is claimed to be safe while stacking many LoRA adapters is a known source of interference.
Retrieval augmentation is the other comparison worth drawing, and the README does not make it. A retrieval system fetches passages at inference time and puts them in the context window. Engram fetches a learned embedding and adds it into the hidden state at a chosen layer. The practical difference is that retrieval needs no training and can handle paraphrases through embedding similarity, while Engram needs a training run per memory and only fires on exact matches. Engram's advantage is that nothing is added to the context window, so there is no prompt-length cost per memory and no risk of the model ignoring retrieved text. If your problem is many small, stable, exactly-named concepts, that trade favours Engram. If your problem is open-domain knowledge, retrieval is the better fit and Engram is not a substitute.
Maintenance cost and what to check before you commit
The repository is not archived and the last push is recent, so it is active. Activity in a research project means the scripts move. The pinned requirements.txt protects you against dependency drift but not against the training scripts themselves changing under you, and there are no releases to pin against. If you build on this, record the commit hash you used, because the only way to reproduce your own run later is to check out the same tree.
The licence question is unresolved in the material available. The badge says MIT and the metadata says unknown. If you plan to ship anything derived from this, open the LICENSE file first and confirm it is present and matches the badge. Nothing here is legal advice, and a badge image is not a licence grant.
Three concrete things to verify before spending GPU time. First, read doc/reproduction/environment.md, since the README gives no CUDA or PyTorch version and that file is the only stated source for it. Second, check the hash collision handling in the N-gram memory implementation, because the composability claim depends on it and the README does not describe the resolution strategy. Third, confirm that the Qwen and Stable Diffusion checkpoints you intend to use are reachable and compatible with the pinned dependencies, since the README names Qwen as the base LLM and SD 1.5 and 3.5 as the vision bases but does not pin specific checkpoint revisions.
Editorial conclusion
Adopt TinyEngram if you are a researcher who wants to reproduce the Engram-versus-LoRA parameter ablation and forgetting comparison on Qwen, or to test whether N-gram memory injection into a Stable Diffusion text encoder is enough for your concept. Do not adopt it if you need a supported inference library, a documented public API, or a licence file you can point a legal reviewer at. Before committing GPU time, verify the LICENSE file actually exists at the path the README badge links to, check doc/reproduction/environment.md for the CUDA version your driver supports, and confirm the Qwen and Stable Diffusion checkpoints you intend to use are compatible with the pinned requirements.txt.
Community notes