arXiv:2604.07394cs.LGcs.CL2026-04

动态调整注意力机制,让大模型长文本推理更快更准。

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

  • 按上下文自动选择全连接或稀疏注意力,层间智能路由。
  • 预填充阶段提速2.8倍,解码阶段提速2.0倍,性能不降。
  • 轻量训练仅需12小时,适配现有大模型快速部署。

标准注意力机制的二次计算复杂度严重制约大模型在长上下文场景下的扩展性。尽管混合注意力(全连接注意力FA与稀疏注意力SA结合)提供了潜在解决方案,但现有方法多采用静态分配比例,无法适应不同任务的可变检索需求。此外,头级动态稀疏性常导致计算负载不均和同步延迟,阻碍自回归解码中的硬件加速。为此,我们提出Flux Attention,一种上下文感知的层级动态优化框架。通过在冻结的预训练大模型中引入轻量级层路由模块,该方法根据输入上下文自适应地将每一层路由至FA或SA。此设计既保留高保真信息检索能力,又保障连续内存访问,将理论计算量降低转化为实际运行时加速。作为参数高效方法,本框架仅需在8×A800 GPU上训练12小时。大量实验在多个长上下文与数学推理基准上验证,其在性能与推理速度间取得更优平衡,预填充阶段最高提速2.8倍,解码阶段最高提速2.0倍。

原文摘要 · Abstract (English)

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.

大模型推理注意力机制动态路由长文本生成

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。