Llama中的Mamba:蒸馏与加速混合模型
The Mamba in the Llama: Distilling and Accelerating Hybrid Models
AI总结:
提出将大型Transformer蒸馏为线性RNN混合模型的方法,复用注意力层权重并引入硬件感知投机解码算法加速推理,在有限资源下实现高性能并具备长度外推能力。
摘要:
线性RNN架构(如Mamba)在语言建模中可以与Transformer模型相媲美,同时具备有利的部署特性。鉴于当前对训练大规模Transformer模型的关注,我们考虑将这些预训练模型转换为可部署模型的挑战。我们证明,通过复用注意力层中的线性投影权重并利用学术级GPU资源,将大型Transformer蒸馏为线性RNN是可行的。由此产生的混合模型保留了四分之一的注意力层,在聊天基准测试中实现了与原始Transformer相当的性能,并且在聊天基准和通用基准上均优于使用数万亿token从头训练的开源混合Mamba模型。此外,我们引入了一种硬件感知的投机解码算法,加速了Mamba和混合模型的推理速度。总体而言,我们展示了如何在计算资源有限的情况下,移除原始模型中的许多注意力层,并从结果模型中更高效地生成内容。我们表现最佳的模型由Llama3-8B-Instruct蒸馏而来,在AlpacaEval 2上对GPT-4达到了29.61的长度控制胜率,在MT-Bench上达到7.35,超越了同等8B规模下最佳的指令微调线性RNN模型。我们还发现,蒸馏模型具有自然长度外推能力,在20倍蒸馏长度的“大海捞针”测试中表现出近乎完美的准确率。代码和预训练检查点已在 https://github.com/jxiw/MambaInLlama 和 https://github.com/itsdaniele/speculative_mamba 开源。
英文摘要:
Linear RNN architectures, like Mamba, can be competitive with Transformer models in language modeling while having advantageous deployment characteristics. Given the focus on training large-scale Transformer models, we consider the challenge of converting these pretrained models for deployment. We demonstrate that it is feasible to distill large Transformers into linear RNNs by reusing the linear projection weights from attention layers with academic GPU resources. The resulting hybrid model, which incorporates a quarter of the attention layers, achieves performance comparable to the original Transformer in chat benchmarks and outperforms open-source hybrid Mamba models trained from scratch with trillions of tokens in both chat benchmarks and general benchmarks. Moreover, we introduce a hardware-aware speculative decoding algorithm that accelerates the inference speed of Mamba and hybrid models. Overall we show how, with limited computation resources, we can remove many of the original attention layers and generate from the resulting model more efficiently. Our top-performing model, distilled from Llama3-8B-Instruct, achieves a 29.61 length-controlled win rate on AlpacaEval 2 against GPT-4 and 7.35 on MT-Bench, surpassing the best 8B scale instruction-tuned linear RNN model. We also find that the distilled model has natural length extrapolation, showing almost perfect accuracy in the needle-in-a-haystack test at 20x the distillation length. Code and pre-trained checkpoints are open-sourced at https://github.com/jxiw/MambaInLlama and https://github.com/itsdaniele/speculative_mamba.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。