Skip to main content
QUICK REVIEW

[论文解读] Transformers to SSMs: Distilling Quadratic Knowledge to Subquadratic Models

Aviv Bick, Kevin Y. Li|arXiv (Cornell University)|Aug 19, 2024
Topic ModelingComputer Science被引用 3
一句话总结

该论文提出 MOHAWK,一种三阶段蒸馏框架,通过逐步对齐混合矩阵、隐藏状态和最终预测,将大型二次时间 Transformer(Phi-1.5)的知识迁移至次二次状态空间模型(SSM),如 Mamba-2。尽管仅使用了 30 亿 tokens——少于训练教师模型所用数据的 1%——Phi-Mamba 在开源非 Transformer 模型中实现了最先进性能,在多个基准测试中超越了先前的 SSM 模型。

ABSTRACT

Transformer architectures have become a dominant paradigm for domains like language modeling but suffer in many inference settings due to their quadratic-time self-attention. Recently proposed subquadratic architectures, such as Mamba, have shown promise, but have been pretrained with substantially less computational resources than the strongest Transformer models. In this work, we present a method that is able to distill a pretrained Transformer architecture into alternative architectures such as state space models (SSMs). The key idea to our approach is that we can view both Transformers and SSMs as applying different forms of mixing matrices over the token sequences. We can thus progressively distill the Transformer architecture by matching different degrees of granularity in the SSM: first matching the mixing matrices themselves, then the hidden units at each block, and finally the end-to-end predictions. Our method, called MOHAWK, is able to distill a Mamba-2 variant based on the Phi-1.5 architecture (Phi-Mamba) using only 3B tokens and a hybrid version (Hybrid Phi-Mamba) using 5B tokens. Despite using less than 1% of the training data typically used to train models from scratch, Phi-Mamba boasts substantially stronger performance compared to all past open-source non-Transformer models. MOHAWK allows models like SSMs to leverage computational resources invested in training Transformer-based architectures, highlighting a new avenue for building such models.

研究动机与目标

  • 使 Mamba-2 等次二次模型能够利用大型预训练二次 Transformer 的知识。
  • 通过从高资源、高质量的预训练中迁移知识,弥合 SSM 与 Transformer 之间的性能差距。
  • 开发一种分阶段在多个粒度层级上迁移知识的方法:矩阵级、隐藏状态级和端到端级。
  • 证明当从强教师模型蒸馏时,SSM 可以匹配甚至超越更大、更依赖数据的 SSM 模型的性能。
  • 验证矩阵近似质量(通过 Frobenius 距离衡量)与下游性能的相关性,为模型设计提供指导。

提出的方法

  • 该方法称为 MOHAWK,采用三阶段蒸馏流程:(1) 矩阵对齐,用于对齐教师与学生模型之间的序列混合矩阵;(2) 隐藏状态对齐,逐层匹配中间表示;(3) 使用知识蒸馏进行端到端微调。
  • 该框架将 Transformer 和 SSM 视为在标记序列上应用结构化矩阵的序列混合器,从而实现其混合机制的直接比较与对齐。
  • 矩阵级蒸馏通过最小化教师模型(Transformer)的注意力矩阵与 SSM 的状态转移矩阵之间的 Frobenius 距离来实现。
  • 隐藏状态蒸馏使用对比损失或蒸馏损失,对齐教师与学生网络中对应层的隐藏表示。
  • 端到端蒸馏通过结合知识蒸馏与标准语言建模范式,对学生模型进行微调。
  • 该方法应用于改进的 Mamba-2 架构(Phi-Mamba),其设计旨在与 Phi-1.5 Transformer 的模块结构保持一致,以实现直接比较。
Figure 1 : Plot of trained token budget to averaged accuracy on Winogrande, Arc-E, Arc-C, PIQA, and Hellaswag on various open-source models (mainly non-Transformer-based models). Our model (Phi-Mamba) uses more than $33\times$ less token budget to achieve 5% higher average accuracy than the next bes
Figure 1 : Plot of trained token budget to averaged accuracy on Winogrande, Arc-E, Arc-C, PIQA, and Hellaswag on various open-source models (mainly non-Transformer-based models). Our model (Phi-Mamba) uses more than $33\times$ less token budget to achieve 5% higher average accuracy than the next bes

实验结果

研究问题

  • RQ1能否通过从大型预训练 Transformer 模型蒸馏知识,有效训练次二次状态空间模型(如 Mamba-2)?
  • RQ2与直接端到端蒸馏相比,针对矩阵、隐藏状态和最终输出的渐进式多层级蒸馏是否能带来更好的性能?
  • RQ3矩阵近似质量(以 Frobenius 距离衡量)在多大程度上与下游模型性能相关?
  • RQ4一个仅包含四层注意力机制、其余部分替换为 SSM 的混合模型,能否匹配或超越完整 Transformer 模型的性能?
  • RQ5在显著更少的数据上训练(例如 30 亿 tokens)的模型,是否能超越从头开始在更大数据集上训练的模型?

主要发现

  • Phi-Mamba 仅使用 30 亿 tokens 蒸馏,Winogrande 基准测试准确率达到 71.7%,优于原始 Mamba-2 模型(60.9%)和所有先前的开源非 Transformer 模型。
  • 在 ARC-C 基准测试中,Phi-Mamba 达到 44.1% 的准确率,而原始 Mamba-2 仅为 33.3%,表明蒸馏带来了显著的性能提升。
  • 混合型 Phi-Mamba 模型(四层注意力机制与 20 层 Mamba 结构)在各基准测试上的平均准确率达到 66.0%,与 Phi-1.5 的 67.2% 非常接近,尽管其训练数据更少且注意力层更少。
  • 消融实验表明,MOHAWK 的每一阶段均具有显著贡献:跳过矩阵或隐藏状态蒸馏均导致性能大幅下降,证实了多阶段方法的必要性。
  • 观察到近似混合矩阵的 Frobenius 距离与下游性能之间存在强相关性,验证了更优的矩阵近似可带来更优的模型行为。
  • 即使在低质量的 C4 数据集上训练,Phi-Mamba 的表现仍优于在更高质 Phi-2 数据集上训练的更大模型 Samba,表明强教师模型蒸馏的有效性。
Figure 2 : The Phi-Mamba architecture consists of a stack of blocks, each of which contains a Mamba block and an MLP block. The Mamba block is a simplified version of the Mamba-2 block [ 8 ] that omits the non-linear activation function after the convolutional operation, as well as the layer normali
Figure 2 : The Phi-Mamba architecture consists of a stack of blocks, each of which contains a Mamba block and an MLP block. The Mamba block is a simplified version of the Mamba-2 block [ 8 ] that omits the non-linear activation function after the convolutional operation, as well as the layer normali

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。