SeerAttention: Learning Intrinsic Sparse Attention in Your LLMs

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Gao, Yizhao, Zeng, Zhichen, Du, Dayou, Cao, Shijie, Zhou, Peiyuan, Qi, Jiaxing, Lai, Junjie, So, Hayden Kwok-Hay, Cao, Ting, Yang, Fan, Yang, Mao
Format: Preprint
Veröffentlicht: 2024
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866915153623121920
author Gao, Yizhao
Zeng, Zhichen
Du, Dayou
Cao, Shijie
Zhou, Peiyuan
Qi, Jiaxing
Lai, Junjie
So, Hayden Kwok-Hay
Cao, Ting
Yang, Fan
Yang, Mao
author_facet Gao, Yizhao
Zeng, Zhichen
Du, Dayou
Cao, Shijie
Zhou, Peiyuan
Qi, Jiaxing
Lai, Junjie
So, Hayden Kwok-Hay
Cao, Ting
Yang, Fan
Yang, Mao
contents Attention is the cornerstone of modern Large Language Models (LLMs). Yet its quadratic complexity hinders efficiency and scalability, especially for long-context processing. A promising approach is to leverage sparsity in attention. However, existing sparsity-based solutions predominantly rely on predefined patterns or heuristics at the attention head level, struggling to adapt dynamically to different contexts efficiently. We propose SeerAttention, a simple yet effective attention mechanism that directly learns the block-level attention sparsity from the LLM itself. Inspired by the gating mechanism in Mixture of Experts (MoE), SeerAttention augments the conventional attention with a learnable gate that selectively activates important blocks within the attention map. Specifically, the gate first pools the query (Q) and key (K) tensors along the sequence dimension and processes them through learnable linear layers. The resulting matrices are then multiplied together to produce the gating scores, which are used to predict block-level attention sparsity. Combined with our block-sparse FlashAttention kernel, SeerAttention can achieve significant speedup on GPUs. When applied to pre-trained LLMs, SeerAttention only requires training the gate parameters in a lightweight self-distillation manner, allowing rapid convergence. Our evaluation results demonstrate that SeerAttention achieves better model accuracy and lower latency for long-context pre-filling compared to prior methods. Code is available at: https://github.com/microsoft/SeerAttention
format Preprint
id arxiv_https___arxiv_org_abs_2410_13276
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle SeerAttention: Learning Intrinsic Sparse Attention in Your LLMs
Gao, Yizhao
Zeng, Zhichen
Du, Dayou
Cao, Shijie
Zhou, Peiyuan
Qi, Jiaxing
Lai, Junjie
So, Hayden Kwok-Hay
Cao, Ting
Yang, Fan
Yang, Mao
Computation and Language
Attention is the cornerstone of modern Large Language Models (LLMs). Yet its quadratic complexity hinders efficiency and scalability, especially for long-context processing. A promising approach is to leverage sparsity in attention. However, existing sparsity-based solutions predominantly rely on predefined patterns or heuristics at the attention head level, struggling to adapt dynamically to different contexts efficiently. We propose SeerAttention, a simple yet effective attention mechanism that directly learns the block-level attention sparsity from the LLM itself. Inspired by the gating mechanism in Mixture of Experts (MoE), SeerAttention augments the conventional attention with a learnable gate that selectively activates important blocks within the attention map. Specifically, the gate first pools the query (Q) and key (K) tensors along the sequence dimension and processes them through learnable linear layers. The resulting matrices are then multiplied together to produce the gating scores, which are used to predict block-level attention sparsity. Combined with our block-sparse FlashAttention kernel, SeerAttention can achieve significant speedup on GPUs. When applied to pre-trained LLMs, SeerAttention only requires training the gate parameters in a lightweight self-distillation manner, allowing rapid convergence. Our evaluation results demonstrate that SeerAttention achieves better model accuracy and lower latency for long-context pre-filling compared to prior methods. Code is available at: https://github.com/microsoft/SeerAttention
title SeerAttention: Learning Intrinsic Sparse Attention in Your LLMs
topic Computation and Language
url https://arxiv.org/abs/2410.13276