LLMs之MemLong:《MemLong: Memory-Augmented Retrieval for Long Text Modeling》翻译与解读

LLMs之MemLong:《MemLong: Memory-Augmented Retrieval for Long Text Modeling》翻译与解读

导读:MemLong 是一种新颖高效的解决 LLM 长文本处理难题的方法,它通过外部检索器获取历史信息,并将其与模型的内部检索过程相结合,从而有效地扩展了上下文窗口,提升了模型的性能。MemLong 具有分布一致性、训练高效、扩展上下文窗口等优势,为 LLM 处理长文本提供了新的思路和解决方案。

>> 背景痛点

大语言模型 (LLM) 在处理长文本时面临巨大挑战,主要原因是:

● 注意力机制的二次时间和空间复杂度

● 生成过程中键值缓存的内存消耗不断增加

现有解决方案存在不足:

● 稀疏注意力机制会牺牲模型能力

● 基于 token 级别的记忆选择会导致语义信息的截断

● 检索增强语言模型存在分布偏移、需要重新训练、处理长文本会损害模型原始能力等问题

>> 解决方案

MemLong:一种高效轻量级的长文本建模方法,通过外部检索器获取历史信息来增强 LLM 的长文本处理能力。

MemLong 主要包含两个部分:

● Ret-Mem 模块:用于记忆和检索历史信息

● 部分可训练的解码器语言模型:用于整合检索信息

>> 核心思路步骤

(1)、构建记忆库: 将历史文本块存储在非可训练的记忆库中,并将其编码为键值对和表示嵌入。

(2)、检索相关信息: 使用检索器根据当前输入文本块的表示嵌入,从记忆库中检索出最相关的键值对。

(3)、融合检索信息: 在模型的上层,将检索到的键值对与当前输入上下文进行融合,并微调模型参数以校准检索偏好。

(4)、动态记忆更新: 当记忆库溢出时,根据检索频率对记忆库进行动态更新,保留更频繁使用的信息,删除不太相关的条目。

>> 优势

● 分布一致性: 记忆库中的信息分布保持一致,避免了模型训练过程中分布偏移问题。

● 训练高效: 只需微调模型的上层,大幅降低了计算成本。

● 扩展上下文窗口: 由于只存储一层模型的键值对,MemLong 可以轻松将上下文窗口扩展到 80k 个 token。

● 性能提升: MemLong 在多个长文本建模基准测试中表现优于其他最先进的 LLM,尤其是在检索增强上下文学习任务中,性能提升高达 10.2 个百分点。

目录

《MemLong: Memory-Augmented Retrieval for Long Text Modeling》翻译与解读

Abstract

1 Introduction

Figure 1: Illustration of Retrieval-Augment Genera-tion(RAG) and Memory-Retrieval flow of MemLong.(a) RAG can even degrade the generation performance (yellow) when the length of the retrieved information exceeds the model’s processing capacity. (b) Our ap-proach utilizes an external retriever to fetch historical information, which is then passed into the model as K-V pairs rather than in text form.图1:检索增强生成(RAG)与MemLong的记忆-检索流程的示意图。(a) 当检索到的信息长度超过模型处理能力时,RAG甚至可能会降低生成性能(黄色部分表示)。(b) 我们的方法利用外部检索器来获取历史信息,然后将这些信息以键值对(K-V pairs)的形式而非文本形式传递给模型。

7 Conclusion


《MemLong: Memory-Augmented Retrieval for Long Text Modeling》翻译与解读

地址

论文地址:https://arxiv.org/pdf/2408.16967

时间

2024 年8月30

作者

苏州大学、哈尔滨工业大学

Abstract

Recent advancements in Large Language Models (LLMs) have yielded remarkable success across diverse fields. However, handling long contexts remains a significant challenge for LLMs due to the quadratic time and space complexity of attention mechanisms and the growing memory consumption of the key-value cache during generation. This work introduces MemLong: Memory-Augmented Retrieval for Long Text Generation, a method designed to enhance the capabilities of long-context language modeling by utilizing an external retriever for historical information retrieval. MemLong combines a non-differentiable ``ret-mem'' module with a partially trainable decoder-only language model and introduces a fine-grained, controllable retrieval attention mechanism that leverages semantic-level relevant chunks. Comprehensive evaluations on multiple long-context language modeling benchmarks demonstrate that MemLong consistently outperforms other state-of-the-art LLMs. More importantly, MemLong can extend the context length on a single 3090 GPU from 4k up to 80k.

Our code is available at this https URL

近期,大型语言模型(LLMs)在各个领域取得了显著的成功。然而,由于注意力机制的二次时间和空间复杂性以及生成过程中键值缓存不断增长的内存消耗,处理长上下文对LLMs来说仍然是一个重大挑战。本文介绍了MemLong:一种用于长文本生成的记忆增强检索方法,该方法通过利用外部检索器来检索历史信息,旨在提高长上下文语言建模的能力。MemLong结合了一个不可微分的“ret-mem”模块与部分可训练的仅解码器语言模型,并引入了一种细粒度可控的检索注意力机制,利用语义级别的相关片段。通过对多个长上下文语言建模基准的全面评估表明,MemLong在性能上持续优于其他最先进的LLMs。更重要的是,MemLong可以在单个3090 GPU上将上下文长度从4k扩展到80k

我们的代码可在该链接获取。

1 Introduction

Large Language Models (LLMs) have achieved re-markable success in various fields. However, due to the quadratic time and space complexity of vanilla attention mechanisms (Vaswani et al., 2017), it is challenging to extend the context length consider-ably, which poses significant limitations for applica-tions involving long-sequence tasks, such as long-document summarization (Koh et al., 2022) and multiple rounds of dialogue (Wang et al., 2024a). As a result, LLMs are often expected to maintain a long working capability (a.k.a. long context LLMs) to effectively handle these demanding scenarios.

To tackle the computational bottleneck, numer-ous efforts have been made. The first line of work focuses on reducing the computation of vanilla at-tention mechanisms (Vaswani et al., 2017) by em-ploying sparse attention operations (Beltagy et al., 2020; Wang et al., 2020; Kitaev et al., 2020; Xiao et al., 2023a; Chen et al., 2023b; Lu et al., 2024). Although these types of works can reduce com-putational complexity to approximately O(n), it often comes with trade-offs in model capability. Therefore, Some works shift their focus to mem-ory selection (Dai et al., 2019; Bertsch et al., 2024; Yu et al., 2023). These approaches, as token-level memory selection, can result in the truncation of se-mantic information. Another recent line of work is Retrieval-Augment Language Modeling (Wu et al., 2022; Wang et al., 2024b; Rubin and Berant, 2023). These works usually introduce a retrieval mecha-nism to enhance the model’s ability to handle long texts. However, these methods have several draw-backs. Firstly, the information stored in memory may experience distribution shifts due to changes in model parameters during training. Secondly, these methods often require retraining, which is im-practical in the era of large models. Finally, these models are often prone to processing long text in-puts at the expense of the original capabilities of the pre-trained model. To address the limitations of previous research, we posed the following ques-tion: Can we utilize the explicit retrieval capa-bilities of a retriever to approximate the implicit retrieval processes within the model?

大型语言模型(LLMs)在各种领域取得了显著的成功。然而,由于基础注意力机制(Vaswani等人, 2017)的时间和空间复杂度为二次方,很难大幅延长上下文长度,这给涉及长序列任务的应用带来了重大限制,如长文档摘要(Koh等人, 2022)和多轮对话(Wang等人, 2024a)。因此,人们期望LLMs能够保持较长的工作能力(即所谓的长上下文LLMs),以有效应对这些需求场景。

为了克服计算瓶颈,已经做出了许多努力。第一类工作集中在通过使用稀疏注意力操作(Beltagy等人, 2020; Wang等人, 2020; Kitaev等人, 2020; Xiao等人, 2023a; Chen等人, 2023b; Lu等人, 2024)减少基础注意力机制(Vaswani等人, 2017)的计算量。尽管这类工作可以将计算复杂度降低至大约O(n),但它通常伴随着模型能力的折衷。因此,有些工作转向了记忆选择(Dai等人, 2019; Bertsch等人, 2024; Yu等人, 2023)。作为词元级记忆选择的方法可能会导致语义信息被截断。另一条近期的研究方向是检索增强的语言建模(Wu等人, 2022; Wang等人, 2024b; Rubin和Berant, 2023)。这些工作通常会引入一种检索机制来增强模型处理长文本的能力。但是,这些方法有几个缺点。首先,在训练过程中模型参数的变化可能导致存储在记忆中的信息经历分布偏移。其次,这些方法往往需要重新训练,在大模型时代这是不切实际的。最后,这些模型常常以牺牲预训练模型的原始能力为代价来处理长文本输入。为了解决先前研究的局限性,我们提出了以下问题:我们能否利用检索器的显式检索能力来近似模型内部的隐式检索过程?

In this work, we propose MemLong, an efficient and lightweight method to extending the context window of LLMs. The key idea is to store past contexts and knowledge in a non-trainable mem-ory bank and further leverages these stored em-beddings to retrieve chunk-level key-value (K-V) pairs for input into the model.. MemLong is ap-plicable to any decoder-only pretrained language models by incorporating (1) an additional ret-mem component for memory and retrieval, and (2) a retrieval causal attention module for integrating local and memory information. The memory and retrieval process of MemLong is illustrated in Fig-ure 1(b). During generation,one text that exceeds the model’s maximum processing length is stored as context information in a Memory Bank. Sub-sequently, given a recently generated text chunk in a long document, we use the retriever to explic-itly retrieve past information, obtaining additional context information through index alignment.

在这项工作中,我们提出了一种高效且轻量级的方法MemLong,用以扩展LLMs的上下文窗口。其核心思想是在非训练的记忆库中存储过去的上下文和知识,并进一步利用这些存储的嵌入来检索块级键值(K-V)对以供模型输入。通过添加(1)额外的ret-mem组件用于记忆和检索,以及(2)一个检索因果注意模块来整合局部和记忆信息,MemLong适用于任何仅解码器的预训练语言模型。图1(b)展示了MemLong的记忆和检索过程。在生成过程中,超过模型最大处理长度的文本被作为上下文信息存储在记忆库中。随后,对于长文档中最近生成的文本段落,我们使用检索器明确地检索过去的信息,通过索引对齐获得额外的上下文信息。

MemLong offers several benefits: (1) Distribu-tional Consistency: Unlike previous models that experienced a distribution shift when information was stored in memory, MemLong ensures the dis-tribution of cached information remains consistent.(2) Training Efficient: We freeze the lower layers of the model and only need to finetune the upper layers which greatly reduced computational cost. In our experiments, finetuning a 3B parameter ver-sion of MemLong on 0.5B tokens requires only eight 3090 GPUs for eight hours. (3) Extensive Context Window: Since only a single layer’s K-V pairs need to be memorized, MemLong is capable of extending the context window up to 80k tokens easily on a single 3090 GPU.

Extensive experiments have demonstrated that MemLong exhibits superior performance in several aspects when compared with other leading LLMs. MemLong outperforms OpenLLaMA (Touvron et al., 2023) and other retrieval-based models on several long-context language modeling datasets. In retrieval-augmented in-context learning tasks, MemLong achieves an improvement of up to 10.2 percentage points over OpenLLaMA.

MemLong提供了几个优点:(1) 分布一致性:与以前在信息存储于记忆时经历分布偏移的模型不同,MemLong确保了缓存信息的分布保持一致。(2) 训练效率:我们冻结了模型的下层并只需要微调上层,这大大降低了计算成本。在实验中,只需八个3090 GPU八小时即可完成对具有30亿参数版本的MemLong进行0.5亿个标记的微调。(3) 广泛的上下文窗口:因为只需要记住单一层的K-V对,MemLong能够在单个3090 GPU上轻松将上下文窗口扩展至80k个标记。

广泛的实验表明,与其他领先的LLMs相比,MemLong在多个方面表现出优越的性能。在几个长上下文语言建模数据集上,MemLong的表现超过了OpenLLaMA(Touvron等人, 2023)和其他基于检索的模型。在检索增强的上下文学习任务中,MemLong相对于OpenLLaMA实现了高达10.2个百分点的改进。

Figure 1: Illustration of Retrieval-Augment Genera-tion(RAG) and Memory-Retrieval flow of MemLong.(a) RAG can even degrade the generation performance (yellow) when the length of the retrieved information exceeds the model’s processing capacity. (b) Our ap-proach utilizes an external retriever to fetch historical information, which is then passed into the model as K-V pairs rather than in text form.图1:检索增强生成(RAG)与MemLong的记忆-检索流程的示意图。(a) 当检索到的信息长度超过模型处理能力时,RAG甚至可能会降低生成性能(黄色部分表示)。(b) 我们的方法利用外部检索器来获取历史信息,然后将这些信息以键值对(K-V pairs)的形式而非文本形式传递给模型。

7 Conclusion

We introduce MemLong, an innovative approach that significantly enhances the capability of lan-guage models to process long texts by leveraging an external retriever. MemLong utilizes a profi-cient retriever to swiftly and accurately access text relevant to the distant context with minimal mem-ory overhead. MemLong successfully expands the model’s context window from 2k to 80k tokens. We demonstrate that MemLong exhibits consider-able competitive advantages in long-distance text modeling and comprehension tasks. MemLong can achieve up to a 10.4 percentage point improvement in performance compared to the full-context model.

我们介绍了一种创新的方法MemLong,它通过利用外部检索器显著增强了语言模型处理长文本的能力。MemLong使用高效的检索器快速准确地访问与远距离上下文相关的文本,同时最小化内存开销。MemLong成功地将模型的上下文窗口从2k扩展到了80k个标记。我们证明了MemLong在长距离文本建模和理解任务中展现出相当大的竞争优势。与全上下文模型相比,MemLong的性能最多可以提高10.4个百分点。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1542030.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Wpf使用NLog将日志输出到LogViewer

1 LogViewer LogViewer是通过UDP传输的高性能实时log查看器。 具有一下特性: 通过UDP读取日志通过文件导入日志导出日志到一个文件中排序、过滤(日志树,日志等级)和查找突出显示搜索文本从UPD接收日志时忽略IP地址列表多接收器支…

HTML5中新增元素介绍

引入了许多新元素,以增强网页的语义和功能。这些新元素大致可以按以下几类进行分类和介绍。 下面是对各标签的详解,section、header、footer、nav、article、aside、figure、code、dialog、meter、time、progress、video、audio、details、atagrid、menu…

数据库提权【笔记总结】

文章目录 UDF提权以有webshell只有数据库权限条件复现msf工具sql语句提权 MOF提权前言条件复现msf工具php脚本提权 sqlserver提权前言条件xp_cmdshell提权复现 沙盒提权介绍复现 Oracle提权靶场搭建执行任意命令复现 通过注入存储过程提权(低权限提升至DBA&#xff…

深度学习之概率论预备知识点(3)

在深度学习中,概率论和数理统计是理解许多算法背后的理论基础。这些知识在处理不确定性、估计模型参数、理解数据分布等方面非常关键 1、概率 一种用来描述随机事件发生的可能性的数字度量,表示某一事件发生的可能性。 概率并不客观存在,是…

12. Inseq 特征归因:可视化解释 LLM 的输出

Feature Attribution(特征归因):你可以将其当做对模型输出的解释,就像在图像分类中可视化模型关注的区域一样。 本文将介绍 Inseq,这是一个用于解释和可视化序列生成模型输出的工具。我们将通过翻译任务(关…

【MySQL 01】数据库基础

目录 1.数据库是什么 2.基本操作 数据库服务器连接操作 数据库和数据库表的创建 服务器,数据库,表关系 数据逻辑存储 3.MySQL架构 4.SQL分类 5.存储引擎 1.数据库是什么 mysql&&mysqld: mysql:这通常指的是 MySQL …

C#描述-计算机视觉OpenCV(6):形态学

C#描述-计算机视觉OpenCV(6):形态学 前言阈值化二值图像腐蚀与膨胀算法形态学滤波器开启和闭合运算原理概括 前言 这是本系列第六节,主要是介绍基础的形态学运用。 形态学主要是分析图像中不同主题的形态,它定义了一系…

基于redis的HyperLogLog数据结构实现的布隆过滤器在信息流中历史数据的应用

一、基于redis的HyperLogLog数据结构实现的布隆过滤器在信息流中历史数据的应用 做信息流服务端的左发一定会遇到用户历史数据的集合,对于一些有限信息流(因DT数据中心的推荐数据变化较慢,推荐量不大),历史数据可以使用…

扎克伯格的未来愿景 用智能眼镜引领数字社交互动新时代

在即将召开的 Meta Connect 2024 大会之前,对公司创始人马克-扎克伯格(Mark Zuckerberg)进行了长达 90 分钟的播客采访,对 Meta 的未来发展方向和愿景进行了阐述。 这次访谈不仅为即将举行的会议预热,还深入探讨了 Met…

CAN通信技术入门篇

参考ISO 11898与BOSCH_CAN_V20 1.CAN通信技术概述 CAN ( Controller Area Network ) 即控制器局域网络。由于其高性能、高可靠性、及独特的设计,CAN越来越受到人们的重视。国外已有许多大公司的产品采用了这一技术。 CAN最初是由德国的BOSCH公司为汽车监测、控制系统而设计的…

ML 系列:机器学习和深度学习的深层次总结(04)多元线性回归 (MLR)

图 1.多元线性回归与简单线性回归 一、说明 线性回归从一维推广到多维,这与单变量线性回归有很多不同,情况更加复杂,而在梯度优化也需要改成向量梯度,同时,数据预处理也成了必要步骤。 二、综述 多元线性回归是简单线性…

利用JAVA写一张纸折叠珠穆拉玛峰高度

public class zhumulama {public static void main(String[] args) {double height 8848860;double zhi 0.1;int count 0;while(zhi < height){zhi*2;//每次折完厚度count;//计数}System.out.println("一共需要折"count"次");System.out.println(&qu…

PD协议过程详解:从物理连接到智能管理的全面剖析

随着科技的飞速发展&#xff0c;电力传输与数据交换的需求日益增加&#xff0c;Power Delivery&#xff08;简称PD&#xff09;协议应运而生&#xff0c;成为现代电子设备充电与数据传输的重要标准。PD协议由USB Implementers Forum&#xff08;USB-IF&#xff09;制定&#xf…

Lanterns (dp 紫 线段树 二分 维护dp)

Lanterns - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 让所有点被覆盖&#xff0c;那么状态可以设计成覆盖一段前缀&#xff0c;并且中间不允许出现断点 由于CF崩了&#xff0c;所以暂时没提交代码。 记f(i) 为前 i 个灯笼点亮的最长前缀。 由于答案具有保留性&#xff…

24年研赛-华为杯数模竞赛D题论文首发+代码分享

本届研赛助攻题目 C D F三题论文均已经全部完成。后更新计划 如图所示。 免费给大家分享 三个问题的论文部分代码 2024年华为杯-研赛分享资料&#xff08;论文部分代码&#xff09;&#xff08;已更新部分代码&#xff09;&#xff1a; 链接&#xff1a;https://pan.baidu.com…

【Vue系列五】—Vue学习历程的知识分享!

前言 本篇文章讲述前端工程化从模块化到如今的脚手架的发展&#xff0c;以及Webpack、Vue脚手架的详解&#xff01; 一、模块化 模块化就是把单独的功能封装到模块&#xff08;文件&#xff09;中&#xff0c;模块之间相互隔离&#xff0c;但可以通过特定的接口公开内部成员…

仓颉编程入门2,启动HTTP服务

上一篇配置了仓颉sdk编译和运行环境&#xff0c;读取一个配置文件&#xff0c;并把配置文件简单解析了一下。 前面读取配置文件&#xff0c;使用File.readFrom()&#xff0c;这个直接把文件全部读取出来&#xff0c;返回一个字节数组。然后又创建一个字节流&#xff0c;给文件…

动手学深度学习(李沐)PyTorch 第 1 章 引言

在线电子书 深度学习介绍 安装 使用conda环境 conda create -n d2l-zh python3.8 pip安装需要的包 pip install jupyter d2l torch torchvision下载代码并执行 wget https://zh-v2.d2l.ai/d2l-zh.zip unzip d2l-zh.zip jupyter notebookpip install rise如果不想使用jupyt…

数模打怪(九)之线性规划、非线性规划、多目标规划

一、线性规划 1、问题特征&#xff1a;有限的条件下&#xff0c;最大的收益 怎样分配&#xff0c;使……尽量多&#xff08;少&#xff09;&#xff0c;使利润最多&#xff0c;使最合理 变量都是一次项&#xff08;x&#xff09; 2、三个要素&#xff1a;决策变量、目标函数…

docker技术(上)

一、docker简介 Docker 是一个开源的应用容器引擎&#xff0c;于 2013 年由 Solomon Hykes 推出并开源。它基于 Go 语言开发&#xff0c;遵从 Apache2.0 协议。Docker 可以让开发者将应用及其依赖包打包到一个可移植的容器中&#xff0c;然后发布到任何流行的 Linux 或 Windows…