arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2605.16893cs.AI
收藏

NGM: 一种无需训练的插拔式内存模块用于大语言模型

NGM: A Plug-and-Play Training-Free Memory Module for LLMs

Nanjing University(南京大学)

Yuwen Qu, Wenhui Dong, Camil Hamami, Ming Zhao, Chenyang Si, Caifeng Shan

AI总结:

本文提出NGM,一种无需训练的插拔式内存模块,通过因果n-gram编码器和余弦门控内存注入器,实现高效的知识检索,提升大语言模型在代码生成和知识密集型任务中的性能。

摘要:

近期的研究引入了条件内存模块,将知识存储与神经计算解耦,从而实现更直接的知识访问。与MoE相比,依赖动态计算路径的MoE,显式查找提供了一种更高效的检索机制。然而,这些方法仍然依赖于学习的内存嵌入,需要额外的训练,限制了灵活性。为此,我们提出了N-gram Memory (NGM),一种无需训练的插拔式模块,由因果N-gram编码器和余弦门控内存注入器组成。因果N-gram编码器直接平均预训练的骨干模型的token嵌入,以构建n-gram表示,从而消除了需要从头训练n-gram嵌入的需要。这种设计不需要额外的内存表或检索流水线。余弦门控内存注入器则使用非参数化的余弦门与ReLU,将检索到的嵌入调节为上下文表示。我们在Qwen3系列从0.6B到14B的八个基准测试中评估了NGM。NGM在平均性能上提高了0.5到1.2个点,尤其在代码生成和知识密集型任务(例如,Qwen3-14B在LiveCodeBench上+3.0,在GPQA上+3.03)中表现突出。此外,NGM还在多模态基准测试(例如,MMStar在Qwen3-VL-2B上+1.53)中提高了性能。

英文摘要:

Recent studies have introduced memory-augmented architectures that decouple knowledge storage from neural computation, enabling more direct access to stored representations. However, existing approaches often rely on learned memory embeddings or explicit memory and retrieval components, requiring additional training or increasing architectural complexity. To address these limitations, we propose N-gram Memory (NGM), a training-free, plug-and-play module that repurposes a backbone model's pretrained token embedding space as memory. NGM consists of a Causal N-Gram Encoder and a Cosine-Gated Memory Injector. The former constructs N-gram representations by directly aggregating pretrained token embeddings, while the latter uses cosine similarity with ReLU gating to adaptively control the amount of retrieved memory injected into contextual representations. Unlike conventional memory-augmented architectures, NGM requires neither additional embedding training nor a separately learned memory bank or external retrieval infrastructure. We evaluate NGM on ten benchmarks across six language-model backbones spanning two model families and multiple scales, including four Qwen3 models (0.6B, 1.7B, 4B, and 8B) and two Llama-3.2-Instruct models (1B and 3B). NGM consistently improves the ten-task average across all six backbones. Notably, it improves HumanEval by 4.26, HumanEval+ by 2.41, and GPQA-Diamond by 6.56 percentage points. Furthermore, NGM extends beyond text-only language models to vision-language models, with Qwen3-VL-2B achieving improvements across all five VLM benchmarks. Project page: https://pioneerqyw.github.io/ngm-project/

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑