无需重训练,可将大模型注意力架构高效转换为更省显存的新结构。
Attention Editing: A Versatile Framework for Cross-Architecture Attention Conversion
- 用可学习模块替换原注意力,通过渐进式蒸馏优化
- 在Qwen3-8B/30B上实现显著推理效率提升
- 适合需在国产硬件部署且想升级注意力架构的开发者
键值缓存内存和带宽在长上下文与长生成场景下日益成为大语言模型推理的主要成本。多头潜在注意力(MLA)和混合滑动窗口注意力(SWA)等架构虽能缓解此瓶颈,但将其集成到现有模型中仍具挑战。以往方法对源与目标注意力模块均提出细粒度结构要求,难以满足实际部署需求。本文提出Attention Editing,一种无需从头再训练即可将已训练大模型转换为新注意力架构的实用框架。该框架通过可学习的目标模块替代原始注意力,并采用渐进式蒸馏进行训练:(1) 层级教师强制优化结合中间激活监督,防止冷启动误差累积;(2) 基于下一个词分布的模型级蒸馏,可选地辅以弱特征匹配正则化。我们在MLA和GateSWA(一种门控混合滑动窗口设计)两种目标架构上进行了实例化,应用于Qwen3-8B和Qwen3-30B-A3B模型。结果表明,转换后模型性能保持竞争力,同时实现显著的效率提升,验证了大规模注意力转换的可行性与鲁棒性。实验基于Ascend 910B集群开展,提供了国产硬件上的实际训练案例。
原文摘要 · Abstract (English)
Key-Value (KV) cache memory and bandwidth increasingly dominate large language model inference cost in long-context and long-generation regimes. Architectures such as multi-head latent attention (MLA) and hybrid sliding-window attention (SWA) can alleviate this bound, but integrating them into existing models remains difficult. Prior methods impose fine-grained structural requirements on both source and target attention modules, which cannot meet the feasible requirement in practical deployment. We present Attention Editing, a practical framework for converting already-trained large language models (LLMs) with new attention architectures without re-pretraining from scratch. Attention editing replaces the original attention with a learnable target module and trains it using progressive distillation, consisting of (1) layer-wise teacher-forced optimization with intermediate activation supervision to prevent cold-start error accumulation, and (2) model-level distillation on next-token distributions, optionally regularized by weak feature matching. We instantiate the framework on two different target--MLA and GateSWA, a gated hybrid SWA design, and apply it to Qwen3-8B and Qwen3-30B-A3B. The resulting models maintain competitive performance while delivering substantial efficiency improvements, demonstrating that large-scale attention conversion is both feasible and robust. Notably, experiments are conducted on an Ascend 910B clusters, offering a practical training case study on domestic hardware.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。