TinyEngram

AutoArk更新放缓

复现 DeepSeek Engram 记忆架构的研究项目,基于 Qwen-3 和 Stable Diffusion,用 LoRA/PEFT 给大模型注入外部记忆,免去全量微调。

Research of DeepSeek Engram Architecture based on Qwen-3 and Stable Diffusion series.

暂无版本1,343star89fork同步于 2026-11-07 07:29 UTC

怎么上手

由 README 提炼,执行前请确认
conda create -n tinyengram python=3.10 -y
conda activate tinyengram
pip install --upgrade pip
pip install -r requirements.txt
硬件要求按 README 说明

README 未说明具体显存要求,仅提到训练与视觉复现依赖 CUDA,细节见 doc/reproduction/environment.md

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

基于 Qwen 与 Stable Diffusion 复现 DeepSeek Engram 记忆注入的开源研究代码库

复现 DeepSeek Engram 记忆架构的研究项目,基于 Qwen-3 和 Stable Diffusion,用 LoRA/PEFT 给大模型注入外部记忆,免去全量微调。

核心能力

  • 在 Qwen 解码层插入 Engram 模块做参数高效微调
  • 用 N-gram 记忆模块加门控检索增强短语级理解
  • 对比 Engram 与 LoRA 的灾难性遗忘表现
  • 把视觉概念作为记忆注入 SD 文本编码器,冻结主干
  • 提供 SD1.5 与 SD3.5 训练脚本、数据集与推理 demo

容易踩的坑

需按 requirements.txt 固定依赖安装,CUDA 与可选评测依赖另见环境文档;视觉实验需自行准备 SD1.5/SD3.5 权重与预处理数据集;仓库以研究复现为主,README 未给出开箱即用的推理入口

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    TinyEngram: Exploring New Axis of Scaling and Memory Injection

    Report Issues

    [!NOTE] TL;DR: TinyEngram demonstrates that Engram-based memory injection outperforms LoRA in both parameter efficiency and catastrophic forgetting resistance—and extends seamlessly to vision (e.g., Stable Diffusion) for lightweight, composable concept injection. All code, logs, and experiments are open!

    If you find TinyEngram useful, a ⭐ helps support the project.

    • 2026.05.20 — 📝 TinyEngram-Vision technical report is ready. We organized the vision findings into a complete technical report to invite discussion and further exploration. Read the report, or check out the arXiv version if you prefer.
    • 2026.02.12 — 🖼️ TinyEngram meets Vision! We injected visual concepts into Stable Diffusion through Engram, check our new cross-modal experiment!
    • 2026.02.02 — 📌 Released reproduction scripts for Engram vs LoRA experiment.
    • 2026.01.30 — 📌 Added comparison of catastrophic forgetting between TinyEngram and LoRA.
    • 2026.01.30 — 📌 Added parameter ablation studies of TinyEngram with convergence observations.
    • 2026.01.23 — 🎉 Initial TinyEngram commit.

    ⚙️ Quick Environment Setup

    TinyEngram provides a clean, pinned direct-dependency file for training and vision reproduction:

    conda create -n tinyengram python=3.10 -y
    conda activate tinyengram
    pip install --upgrade pip
    pip install -r requirements.txt
    

    For CUDA notes and optional evaluation dependencies, see doc/reproduction/environment.md.

    📖 Introduction

    TinyEngram is an open research project exploring the Engram architecture—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.

    Built on Qwen, TinyEngram provides a lightweight, ready-to-train codebase for anyone to reproduce, experiment with, or extend Engram-style models. We actively share new experiments, training logs, and findings right here—making this repo both a toolkit and a living research notebook.

    Beyond LLMs, we propose a modality-agnostic memory architecture. Engram in Stable Diffusion serves as one instantiation, proving that non-textual concepts can be retrieved and integrated as efficiently as language.

    [!TIP] Join the Research You are welcome to propose any questions in the Issues. We will burn our own GPUs to research on any interesting questions. Join us in evolving how LLMs remember what matters! 🧠✨

    🖼️ TinyEngram-Vision: Engram Goes Multimodal

    Technical Report: We have organized the TinyEngram-Vision findings into a complete technical report. Read the report for the full methodology, experiments, and conclusions, or check out the arXiv version if you prefer.

    Can Engram's memory mechanism work beyond text?

    We extended TinyEngram to Stable Diffusion, treating visual concepts as "memories" capable of being injected into the Text Encoder. By simply recognizing specific N-grams in the prompt, we inject learned embeddings that guide the generation—all without fine-tuning the massive U-Net or DiT backbone.

    It's a lightweight, composable way to "teach" the model new subjects (like specific characters) while keeping the original weights frozen.

    Why is this cool?

    • Minimal & Surgical: We construct a minimal Engram vocabulary specifically for your target phrase.
    • Infinite Composability: Since Engram relies on exact N-gram matching (hard hash collisions), memories strictly do not interfere with each other. You can stack thousands of different character/style engrams together, and they will only trigger when their exact name is called—zero degradation to the base model's general capabilities.

    🔗 Click here to view the full report (SD1.5 & SD3.5 experiments)

    Reproduce our experiments

    Interested in injecting your own concepts (or even your cat 🐱) into Stable Diffusion? 👉 Check out the reproduction guide here

    We provide everything needed to get started:

    • Training scripts for SD1.5 & SD3.5
    • Pre-processed datasets
    • Inference demos

    Have Fun!

    🧪 Key Finding 1. Engram as Parameter Efficient Fine-Tuning Method

    1. Engram works as Parameter Efficient Fine-Tuning Method

    We insert several Engram modules into decoder layers of Qwen. We fine-tune the Engram module on a subset of the Biomed-Enriched dataset. Only added parameters are trainable during the fine-tuning.

    The train and eval loss demonstrate robust convergence. This confirms that the Engram module effectively learns specialized biomedical knowledge while preserving the stability of the underlying pre-trained knowledge base.

    Biomedical TaskQwen3-0.6BEngram SFT
    MMLU_Clinical Knowledge0.33580.4415
    MMLU_Medical Genetics0.37000.4400
    MMLU_Prof. Medicine0.31990.4559
    PubMedQA0.57000.6250

    2. Catastrophic Forgetting

    • Objective: Verify if integrating Engram memory harms the model's pre-trained general capabilities while adapting to new domains.
    • Methodology: We fine-tune the Biomed-Enriched on Qwen, and evaluate the checkpoint on general benchmarks (We evaluate on MMLU, excluding all biomedical-related subtasks).
    • Full Results: Click here to view detailed results
    Task GroupQwen 3-0.6BEngram SFT
    mmlu (overall)0.40340.4500 (⬆️ +0.0466)
    humanities0.44330.4691 (⬆️ +0.0258)
    other0.42710.4696 (⬆️ +0.0425)
    social sciences0.48260.5389 (⬆️ +0.0563)
    stem0.35080.4088 (⬆️ +0.0580)

    📌 Update (2026.01.30): We have added a new set of experiments comparing Engram and LoRA on catastrophic forgetting. Please refer to Engram vs LoRA Catastrophic Forgetting Experiment for details.

    3. Vocabulary Scalability Analysis

    • Objective: Investigate the relationship between Engram memory size (vocabulary size) and performance gains.
    • Methodology: Train multiple models with varying engram_vocab_size (e.g., 2k vs 10k vs 20k vs 100k) and observe the impact on biomedical validation loss.
    • Full Results: Larger representation capacities do not necessarily translate into better performance. In our experiments, we observe an apparent trade-off: smaller capacities may suffer from semantic collisions, while larger ones can become difficult to fully utilize given limited data. Click here to view detailed results
    TaskNano (2k/0.2k)Small (10k/1k)Medium (20k/2k)Large (100k/10k)Qwen3-0.6B (Baseline)Winner
    MMLU_Clinical Knowledge0.37360.44150.43020.42260.3358Small 🏆
    MMLU_Medical Genetics0.39000.44000.44000.41000.3700Small/Med 🤝
    MMLU_Prof. Medicine0.40810.45590.42280.44120.3199Small 🏆
    PubMedQA0.62400.62500.61700.61500.5700Small 🏆

    📌 Update (2026.01.30):
    We have expanded our study with a comprehensive ablation of TinyEngram’s configurable hyperparameters. Please refer to Engram Systematic Hyperparameter Tuning Experiment for details.

    Reproduce our experiments

    To reproduce the experiments conducted in Key Finging 1, please refer to this guide.

    🧪 Key Finding 2. Engram Outperforms LoRA in Catastrophic Forgetting

    LoRA is the de-facto PEFT method, So how does Engram compare? We also conduct systematic hyperparameter tuning to understand Engram better.

    1. Engram vs LoRA Catastrophic Forgetting Experiment

    Preliminary observation: In our experiments, Engram shows noticeably better resistance to catastrophic forgetting than LoRA.

    Model ArchitectureAdaptation Metric (Eval Loss) $\downarrow$General Capability (TruthfulQA MC1) $\uparrow$General Capability (TruthfulQA MC2) $\uparrow$$\Delta$ (MC2 vs Base)
    Qwen-0.6B (Base)N/A0.25830.4269-
    LoRA (Rank 16)0.18620.24850.4078-1.91%
    TinyEngram0.18500.26440.4340+0.71%

    It is worth noting that LoRA generally converges faster. In our experiments, LoRA could reach an even lower loss (0.1458) quickly, but the trade-off was severe: catastrophic forgetting worsened significantly ($MC1: 0.2472$, $MC2: 0.3993$). Engram provides a safer learning path.

    We fine-tune models on "poisoned" function-call-style data (see processing script) based on the glaive-function-calling-v2 dataset, which encourages a strong bias toward structured function-call outputs. We then evaluate both LoRA and Engram on TruthfulQA, a natural language QA benchmark, to examine how well they retain general-language capabilities under this distribution shift. Click here to view detailed results.

    2. Engram Systematic Hyperparameter Tuning Experiment

    During initial trials, we observed that LoRA converges faster than the default Engram configuration. To enable a scientifically sound comparison, we conducted a systematic hyperparameter study to calibrate Engram such that it reaches evaluation loss levels comparable to LoRA on the same training data.

    Using the small-scale, filtered glaive-function-calling-v2 dataset, we ablated key Engram parameters beyond vocabulary size, including:

    • N-gram order
    • Vocabulary size
    • Embedding dimension per n-gram
    • Number of hash heads per n-gram
    • Target layer(s) for Engram injection

    We hope this experiment can serve as a solid starting point for parameter selection in similar small-scale supervised fine-tuning (SFT) scenarios. 🔗 Click here to view detailed results.

    Reproduce our experiments

    Reproduction details of experiments conducted in Key Finging 2: please refer to this guide.

    🗺️ More Research is on the way!

    CategoryItemStatus
    MultimodalStable Diffusion Injection✅
    Engram as PEFTEngram works✅
    Catastrophic Forgetting✅
    Vocabulary Scalability✅
    vs LoRA✅
    Hyperparameter Tuning✅
    MoreMore⬜

    🙏 Acknowledgements

    We borrowed a lot of code from the following excellent projects:

    We thank the authors of training datasets that help our research:

    🔗 Citation

    If you find TinyEngram useful for your research or projects, please cite us:

    @misc{cai2026tinyengramtriggerindexedconcepttables,
      title         = {Tiny-Engram: Trigger-Indexed Concept Tables for Generative Vision},
      author        = {Runyuan Cai and Yiming Wang and Yu Lin and Xiaodong Zeng},
      year          = {2026},
      eprint        = {2605.20309},
      archivePrefix = {arXiv},
      primaryClass  = {cs.CV},
      url           = {https://arxiv.org/abs/2605.20309}
    }