arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2604.07394cs.LGcs.CL
收藏

流注意机制:一种面向高效大语言模型推理的上下文感知混合注意机制

Flux Attention: Context-Aware Hybrid Attention for Efficient LLMs Inference

Baidu Inc(百度公司)

Quantong Qiu, Zhiyi Hong, Yi Yang, Haitian Wang, Kebin Liu, Qingqing Dang, Juntao Li, Min Zhang

AI总结:

本文提出流注意机制,通过动态层级路由优化注意力计算,提升大语言模型在长上下文场景下的推理效率,实验显示在预填和解码阶段速度提升达2.8倍和2.0倍。

摘要:

标准注意力机制的二次计算复杂度在长上下文场景中成为严重可扩展性瓶颈。尽管混合注意力机制结合全注意力(FA)和稀疏注意力(SA)提供了解决方案,但现有方法通常依赖静态分配比例,无法适应不同任务的变量检索需求。此外,层次级动态稀疏性常导致严重的计算负载不均衡和同步长尾,阻碍硬件加速在自回归解码中。为弥合这一差距,我们引入流注意力,一种上下文感知框架,通过在冻结的预训练LLM中集成轻量级层路由器,使方法能够根据输入上下文动态地将每一层路由到FA或SA。这种层级路由在保持高保真信息检索的同时确保连续内存访问,将理论计算减少转化为实际的墙钟加速。作为参数高效的方法,我们的框架仅需在8$\times$A800 GPU上训练12小时。在多个长上下文和数学推理基准上的广泛实验表明,流注意力在性能与推理速度之间实现了更优的权衡,相比基线模型,在预填和解码阶段的速度提升可达2.8倍和2.0倍。

英文摘要:

The quadratic computational complexity of standard attention mechanisms presents a severe scalability bottleneck for LLMs in long-context scenarios. While hybrid attention mechanisms combining Full Attention (FA) and Sparse Attention (SA) offer a potential solution, existing methods typically rely on static allocation ratios that fail to accommodate the variable retrieval demands of different tasks. Furthermore, head-level dynamic sparsity often introduces severe computational load imbalance and synchronization long-tails, which hinder hardware acceleration during autoregressive decoding. To bridge this gap, we introduce Flux Attention, a context-aware framework that dynamically optimizes attention computation at the layer level. By integrating a lightweight Layer Router into frozen pretrained LLMs, the proposed method adaptively routes each layer to FA or SA based on the input context. This layer-wise routing preserves high-fidelity information retrieval while ensuring contiguous memory access, translating theoretical computational reductions into practical wall-clock speedups. As a parameter-efficient approach, our framework requires only 12 hours of training on 8$\times$A800 GPUs. Extensive experiments across multiple long-context and mathematical reasoning benchmarks demonstrate that Flux Attention achieves a superior trade-off between performance and inference speed compared with baseline models, with speed improvements of up to $2.8\times$ and $2.0\times$ in the prefill and decode stages.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑