Mamba- Linear-Time Sequence Modeling with Selective State Spaces
标题:Mamba: Linear-Time Sequence Modeling with Selective State Spaces
作者:Albert Gu(CMU)、Tri Dao(普林斯顿)(共同一作)
提交:2023-12-04,arXiv:2312.00752
正式出版:COLM 2024(Conference on Language Modeling)
论文下载地址:
链接:https://pan.quark.cn/s/e03ffb1a22e8
原文摘要
Many subquadratic-time architectures such as linear attention, gated convolution and recurrent models, and structured state space models (SSMs) have been developed to address Transformers’ computational inefficiency on long sequences, but they have not performed as well as attention on important modalities such as language. We identify that a key weakness of such models is their inability to perform content-based reasoning, and make several improvements. First, simply letting the SSM parameters be functions of the input addresses their weakness with discrete modalities, allowing the model to selectively propagate or forget information along the sequence length dimension depending on the current token. Second, even though this change prevents the use of efficient convolutions, we design a hardware-aware parallel algorithm in recurrent mode. We integrate these selective SSMs into a simplified end-to-end neural network architecture without attention or even MLP blocks (Mamba). Mamba enjoys fast inference (5× higher throughput than Transformers) and linear scaling in sequence length, and its performance improves on real data up to million-length sequences. As a general sequence model backbone, Mamba achieves state-of-the-art performance across several modalities such as language, audio, and genomics. On language modeling, our Mamba-3B model outperforms Transformers of the same size and matches Transformers twice its size, both in pretraining and downstream evaluation.
摘要中文翻译
为解决 Transformer 在长序列上计算低效的问题,学界已经提出很多次二次复杂度架构,包括线性注意力、门控卷积、循环模型以及结构化状态空间模型(SSM);但这类模型在语言这类关键模态上,效果一直不如注意力。
本文指出这类模型的核心短板:无法基于内容做选择性推理,并针对性改进。
第一,让 SSM 的参数成为输入的函数,以此适配离散模态,让模型可以根据当前 token,沿着序列选择性保留或者遗忘信息。
第二,虽然该改动无法再使用高效卷积,我们设计了面向硬件感知的并行扫描算法来实现递推计算。我们把选择性 SSM 封装成一套极简端到端架构,全程不含注意力,甚至没有独立 MLP 块,也就是 Mamba。
Mamba 推理速度快,吞吐是 Transformer 的 5 倍,计算量随序列长度线性增长;在百万长度序列上依然可以稳定提升效果。作为通用序列主干,它在语言、音频、基因组等多个模态上达到 SOTA。
在语言建模任务上,3B 规模的 Mamba 优于同参数量 Transformer,并且可以追上两倍参数量的 Transformer,预训练和下游任务均是如此。
一句话主旨:提出选择性 SSM(Selective SSM),让 SSM 可以根据输入内容动态选择记忆 / 遗忘,构造出无注意力、O (N) 线性复杂度的序列主干 Mamba,是 Mamba 系列开山之作。
核心贡献
选择性机制(Selectivity) 老版本 SSM(S4 等)是固定参数,不管输入是什么,记忆规则不变;Mamba 让 A,B,C 这些 SSM 状态矩阵由当前输入动态生成,token 不同,记忆策略不同,解决了老 SSM 语言能力弱的致命问题。
硬件感知并行扫描(Hardware-aware Parallel Scan) 选择性机制破坏了 S4 的卷积等价形式,不能用快速卷积;作者专门设计 GPU 上高效的并行递推算子,利用 SRAM 缓存状态,实现训练并行、推理常数步开销。
极简 Mamba Block 结构非常干净:短卷积 + 选择性 SSM + 门控,去掉了自注意力,也拆掉独立 MLP,是纯 SSM 架构。
长上下文能力 复杂度 \(O(N)\),不像 Transformer \(O(N^2)\);原生支持百万 token 长序列,推理不需要巨大 KV 缓存。实验:Mamba-3B 对标 6B Transformer。
Mamba- Linear-Time Sequence Modeling with Selective State Spaces
https://www.devpilot.cloud/archives/mamba-linear-time-sequence-modeling-with-selective-state-spaces
评论