跳到主内容
@wquguru
精选88MarkTechPost(RSS)模型发布/更新

斯坦福开源Memorilla:16个记忆Token替代全文上下文

Stanford Research Open-Sources Memorilla, a Latent Memory Module for Frozen LLMs

原文
发到 X
推荐理由

给做Agent的同学看,用16个Token替代海量上下文,既省显存又提速度,实测效果还比全量上下文更好,赶紧试试你的链路。

Stanford researchers have released Memorilla, an open-source memory system for LLMs. The Memorilla memory system reads a whole document collection and hands a frozen LLM just 16 memory tokens. On FactKG, a frozen Qwen3-8B scored 84.33% with Memorilla, against 80.43% with every document in context. It did that with 108x fewer document tokens. Code, training recipes and checkpoints are public under Apache 2.0. You can check the deployment options and specs here through our GPULeaderboard.com chrome extension.

斯坦福研究人员发布了 Memorilla,这是一个面向大语言模型(LLM)的开源记忆系统。Memorilla 记忆系统读取整个文档集合,并向冻结的大语言模型仅提供 16 个记忆 token。在 FactKG 数据集上,使用 Memorilla 时,冻结的 Qwen3-8B 得分达到 84.33%,而将所有文档置于上下文中时得分为 80.43%。它使用的文档 token 数量减少了 108 倍。代码、训练配方和检查点均在 Apache 2.0 许可下公开。你可以通过我们的 GPULeaderboard.com Chrome 扩展程序在此查看部署选项和规格。

TL;DR

TL;DR(太长不看版)

  • Size: 194M-parameter trainable memory module. It always outputs 16 memory tokens, whatever the collection size. The encoder (Qwen3-Embedding-4B) and decoder (Qwen3-8B) stay frozen.
  • Runs on: Linux with CUDA GPUs and Python 3.11. The quickstart needs 1 GPU with 80 GB (recipes ran on H100 80GB). No quantized variants disclosed.
  • Performance: Highest reported average across 8 benchmarks (49.68), top score on 5 of 8.
  • Best: PersonaMem-v2 accuracy of 44.60%, versus 27.92% for full context.
  • Worst: PubMedQA accuracy of 59.00%, versus 69.00% for LLMLingua-2.
  • 规模:1.94 亿参数的可训练记忆模块。无论集合大小如何,它始终输出 16 个记忆 token。编码器(Qwen3-Embedding-4B)和解码器(Qwen3-8B)保持冻结状态。
  • 运行环境:Linux、CUDA GPU 和 Python 3.11。快速入门需要 1 块 80 GB 显存的 GPU(训练配方在 H100 80GB 上运行)。未披露量化变体。
  • 性能:在 8 个基准测试中报告的平均分最高(49.68),其中 5 个基准测试取得了最高分。
  • 最佳表现:PersonaMem-v2 准确率为 44.60%,而全上下文方法为 27.92%。
  • 最差表现:PubMedQA 准确率为 59.00%,而 LLMLingua-2 为 69.00%。

What is Memorilla?

什么是 Memorilla?

Memorilla is a memory module that turns a document collection into 16 vectors for a frozen LLM. The work comes from Jure Leskovec’s SNAP group, with co-authors from Toronto, Penn and MIT.

Memorilla 是一个记忆模块,它将文档集合转换为 16 个向量供冻结的大语言模型使用。该工作来自 Jure Leskovec 领导的 SNAP 小组,合作者来自多伦多大学、宾夕法尼亚大学和麻省理工学院。

A frozen LLM can only use what sits in its context window. Full-context prompting grows slower as history grows. Retrieval pastes the chunks most similar to the question, and can miss weaker clues. Memorilla takes a third route: it learns what each question needs from the whole store.

冻结的大语言模型只能使用其上下文窗口内的内容。随着历史记录的增长,全上下文提示的效果增长变慢。检索方法粘贴与问题最相似的片段,可能会遗漏较弱的线索。Memorilla 采取了第三条路径:它学习每个问题需要从整个存储中获取什么。

How does Memorilla work?

Memorilla 是如何工作的?

The pipeline has 3 steps:

流程包含 3 个步骤:

  • Encode once. A frozen Qwen3-Embedding-4B embeds each document a single time. New documents never force re-encoding of old ones.
  • Read per question. 16 learned slots attend to the question and the full store. The module uses 2 cross-attention layers with 8 heads.
  • Inject. The slots are projected into Qwen3-8B’s input embedding space and prepended to the question.
  • 一次性编码。冻结的 Qwen3-Embedding-4B 对每篇文档仅嵌入一次。新文档永远不会强制重新编码旧文档。
  • 按问题读取。16 个学习到的槽位关注问题和整个存储。该模块使用 2 层交叉注意力层,每层有 8 个头。
  • 注入。将槽位投影到 Qwen3-8B 的输入嵌入空间,并前置到问题之前。

Only the memory module trains: 194,123,776 parameters for the 8B decoder. Training runs in 3 stages. Stage 1 uses about 1.98M Wikipedia paraphrase-reconstruction examples. Stage 2 adds about 1.34M examples from 10 QA and summarization datasets. Stage 3 fine-tunes on all 8 benchmarks. The full recipe takes about 19 hours on 4 H100 GPUs.

仅训练记忆模块:解码器为 8B 参数,共 194,123,776 个参数。训练分 3 个阶段进行。第 1 阶段使用约 198 万个维基百科改写重建示例。第 2 阶段增加了来自 10 个问答和摘要数据集的约 134 万个示例。第 3 阶段在所有 8 个基准测试上进行微调。在 4 块 H100 GPU 上,完整训练配方耗时约 19 小时。

How does Memorilla perform on benchmarks?

Memorilla 在基准测试中的表现如何?

All baselines use the same frozen Qwen3-8B, per the paper’s main table. Scores are self-reported by the research team.

所有基线方法均使用相同的冻结 Qwen3-8B,如论文主表所示。分数由研究团队自行报告。

  • FactKG: 84.33% accuracy, versus 80.43% full context and 80.38% MemoRAG.
  • PersonaMem-v2: 44.60%, versus 30.90% for xRAG, the next best method.
  • TriviaQA: 57.00 exact match, just ahead of MemoRAG at 56.60.
  • LaMP-4 / LaMP-7: 18.15 and 48.37 ROUGE-L, both the best scores.
  • Average: 49.68, versus 41.92 for xRAG, 40.75 for LLMLingua-2 and 38.02 for Mem0.
  • FactKG:准确率达 84.33%,而完整上下文为 80.43%,MemoRAG 为 80.38%。
  • PersonaMem-v2:准确率为 44.60%,而次优方法 xRAG 仅为 30.90%。
  • TriviaQA:精确匹配率为 57.00,略高于 MemoRAG 的 56.60。
  • LaMP-4 / LaMP-7:ROUGE-L 分数分别为 18.15 和 48.37,均为最佳成绩。
  • 平均分:49.68,而 xRAG 为 41.92,LLMLingua-2 为 40.75,Mem0 为 38.02。

Memorilla loses on 3 benchmarks. On PubMedQA it scores 59.00%, while LLMLingua-2 reaches 69.00%. Those abstracts total only 324 tokens, so compression has little to gain. MemoRAG leads on PersonalizationV4 (67.88% vs 66.65%) and NarrativeQA ROUGE-L (20.51 vs 19.31). MemoRAG used about 690x and 50x more document tokens there.

Memorilla 在 3 个基准测试中表现不佳。在 PubMedQA 上得分为 59.00%,而 LLMLingua-2 达到 69.00%。这些摘要总共只有 324 个 token,因此压缩带来的收益微乎其微。MemoRAG 在 PersonalizationV4(67.88% vs 66.65%)和 NarrativeQA ROUGE-L(20.51 vs 19.31)上领先。在这些任务中,MemoRAG 使用的文档 token 分别多出约 690 倍和 50 倍。

Compression peaks on NarrativeQA: 16 tokens replace 67,385 document tokens, a 4,212x cut. As agent memory, 8 memory tokens lift a Qwen3-4B TextWorld agent from 18.6% to 24.2% average success.

在 NarrativeQA 上压缩效果达到峰值:16 个 token 替代了 67,385 个文档 token,实现了 4,212 倍的缩减。作为智能体记忆,8 个记忆 token 将 Qwen3-4B TextWorld 智能体的平均成功率从 18.6% 提升至 24.2%。

How fast is Memorilla compared to full context?

与完整上下文相比,Memorilla 的速度有多快?

On 1 H100, Memorilla answers in 0.74 s at 512 documents (about 128K tokens). Full context slows from 0.75 s to 19.9 s, which is 27x slower. The memory module itself takes about 2 ms.

在单张 H100 GPU 上,Memorilla 处理 512 个文档(约 128K token)时响应时间为 0.74 秒。完整上下文的推理时间从 0.75 秒降至 19.9 秒,慢了 27 倍。记忆模块本身的耗时约为 2 毫秒。

An optional memory cache precomputes cross-attention keys and values. On 1 B200, a question then takes 8.1 ms at 1M documents and 33 ms at 4M. With torch.compile, the 1M case drops to 5.0 ms. The cache costs 80 GiB at 4M documents.

可选的记忆缓存会预计算交叉注意力的键和值。在单张 B200 GPU 上,处理 100 万文档时每个问题耗时 8.1 毫秒,处理 400 万文档时耗时 33 毫秒。使用 torch.compile 后,100 万文档的情况降至 5.0 毫秒。在 400 万文档规模下,缓存占用 80 GiB 内存。

How do you run Memorilla?

如何运行 Memorilla?

Install with uv on Linux, then load MemoryVLLM.from_pretrained. The first run downloads about 25 GB of models. Checkpoints live at memorilla/Memorilla-Qwen3-8B as Stage 1, 2, 3, PV4 and PMv2 folders.

在 Linux 上使用 uv 安装,然后加载 MemoryVLLM.from_pretrained。首次运行会下载约 25 GB 的模型。检查点位于 memorilla/Memorilla-Qwen3-8B 下的 Stage 1、Stage 2、Stage 3、PV4 和 PMv2 文件夹中。

Each checkpoint must run with the decoder it was trained with (evaluation docs). Custom data needs parquet files with collection_id, question, answer and documents columns. The research team also released PersonalizationV4: 149 synthetic users, 200 conversations each, under CC BY 4.0.

每个检查点必须与其训练时使用的解码器配合运行(参见评估文档)。自定义数据需要包含 collection_id、question、answer 和 documents 列的 parquet 文件。研究团队还发布了 PersonalizationV4 数据集:包含 149 个合成用户,每人 200 次对话,采用 CC BY 4.0 许可协议。

Memorilla vs Mem0, MemoRAG and xRAG

Memorilla 与 Mem0、MemoRAG 和 xRAG 的对比

Benchmark scores come from Memorilla’s paper, which ran every baseline on the same Qwen3-8B. Licenses come from each project’s repository.

基准测试分数来自 Memorilla 的论文,该论文在同一 Qwen3-8B 模型上运行了所有基线方法。许可证信息来自各项目仓库。

Memorilla (paper)MemoRAG (repo)Mem0 (repo)xRAG (repo)
ApproachLearned latent memory tokensMemory model guides retrievalExtracted text memories1-token RAG compression (paper)
Doc tokens per query (geo. mean)167842121
What the LLM reads16 soft memory embeddingsRetrieved textRetrieved memory text1 projected embedding
LicenseApache 2.0Apache 2.0Apache 2.0Not disclosed
FactKG (Acc)84.3380.3872.7978.98
PersonaMem-v2 (Acc)44.6028.7627.4830.90
PubMedQA (Acc)59.0067.0024.0036.00
NarrativeQA (ROUGE-L)19.3120.5113.8016.92
Average, 8 benchmarks49.6847.52 (our calc.)38.0241.92
Memorilla(论文)MemoRAG(仓库)Mem0(仓库)xRAG(仓库)
方法学习的潜在记忆令牌记忆模型引导检索提取的文本记忆1-token RAG压缩(论文)
每个查询的文档令牌数(几何平均)167842121
LLM读取的内容16个软记忆嵌入向量检索到的文本检索到的记忆文本1个投影嵌入向量
许可证Apache 2.0Apache 2.0Apache 2.0未公开
FactKG(准确率)84.3380.3872.7978.98
PersonaMem-v2(准确率)44.6028.7627.4830.90
PubMedQA(准确率)59.0067.0024.0036.00
NarrativeQA(ROUGE-L)19.3120.5113.8016.92
8个基准测试的平均值49.6847.52(我们计算)38.0241.92

Key Takeaways

关键要点

  • 16 memory tokens replace whole document collections for a frozen Qwen3-8B.
  • FactKG: 84.33% vs 80.43% full context, with 108x fewer tokens.
  • Highest reported 8-benchmark average: 49.68.
  • Weak spot: PubMedQA at 59.00% and fine-grained facts.
  • Apache 2.0 code; 194M-parameter checkpoints on Hugging Face.
  • 16个记忆令牌取代了整个文档集合,用于冻结的Qwen3-8B模型。
  • FactKG:84.33% vs 80.43%完整上下文,令牌数量减少了108倍。
  • 报告的最高8个基准测试平均值:49.68。
  • 弱点:PubMedQA为59.00%,以及细粒度事实。
  • Apache 2.0代码;Hugging Face上的1.94亿参数检查点。

Check out the paper, browse the GitHub repo, and download the checkpoints. You can check the deployment options and specs here through our GPULeaderboard.com chrome extension.

查看论文,浏览GitHub仓库,并下载检查点。您可以通过我们的GPULeaderboard.com Chrome扩展程序在此处查看部署选项和规格。

Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

此外,欢迎在Twitter上关注我们,别忘了加入我们有15万+成员的ML SubReddit,并订阅我们的新闻通讯。等等!你在Telegram上吗?现在你也可以在Telegram上加入我们。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件