Saved in:
Bibliographic Details
Main Authors: Wu, Haixu, Guo, Minghao, Ma, Yuezhou, Sun, Yuanxu, Wang, Jianmin, Matusik, Wojciech, Long, Mingsheng
Format: Preprint
Published: 2025
Subjects:
Online Access:https://arxiv.org/abs/2505.12044
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866911228766453760
author Wu, Haixu
Guo, Minghao
Ma, Yuezhou
Sun, Yuanxu
Wang, Jianmin
Matusik, Wojciech
Long, Mingsheng
author_facet Wu, Haixu
Guo, Minghao
Ma, Yuezhou
Sun, Yuanxu
Wang, Jianmin
Matusik, Wojciech
Long, Mingsheng
contents Attention with bias, which extends standard attention by introducing prior knowledge as an additive bias matrix to the query-key scores, has been widely deployed in vision, language, protein-folding and other advanced scientific models, underscoring its status as a key evolution of this foundational module. However, introducing bias terms creates a severe efficiency bottleneck in attention computation. It disrupts the tightly fused memory-compute pipeline that underlies the speed of accelerators like FlashAttention, thereby stripping away most of their performance gains and leaving biased attention computationally expensive. Surprisingly, despite its common usage, targeted efficiency optimization for attention with bias remains absent, which seriously hinders its application in complex tasks. Diving into the computation of FlashAttention, we prove that its optimal efficiency is determined by the rank of the attention weight matrix. Inspired by this theoretical result, this paper presents FlashBias based on the low-rank compressed sensing theory, which can provide fast-exact computation for many widely used attention biases and a fast-accurate approximation for biases in general formalizations. FlashBias can fully take advantage of the extremely optimized matrix multiplication operation in modern GPUs, achieving 1.5$\times$ speedup for Pairformer in AlphaFold 3, and over 2$\times$ speedup for attention with bias in vision and language models without loss of accuracy. Code is available at this repository: https://github.com/thuml/FlashBias.
format Preprint
id arxiv_https___arxiv_org_abs_2505_12044
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle FlashBias: Fast Computation of Attention with Bias
Wu, Haixu
Guo, Minghao
Ma, Yuezhou
Sun, Yuanxu
Wang, Jianmin
Matusik, Wojciech
Long, Mingsheng
Machine Learning
Attention with bias, which extends standard attention by introducing prior knowledge as an additive bias matrix to the query-key scores, has been widely deployed in vision, language, protein-folding and other advanced scientific models, underscoring its status as a key evolution of this foundational module. However, introducing bias terms creates a severe efficiency bottleneck in attention computation. It disrupts the tightly fused memory-compute pipeline that underlies the speed of accelerators like FlashAttention, thereby stripping away most of their performance gains and leaving biased attention computationally expensive. Surprisingly, despite its common usage, targeted efficiency optimization for attention with bias remains absent, which seriously hinders its application in complex tasks. Diving into the computation of FlashAttention, we prove that its optimal efficiency is determined by the rank of the attention weight matrix. Inspired by this theoretical result, this paper presents FlashBias based on the low-rank compressed sensing theory, which can provide fast-exact computation for many widely used attention biases and a fast-accurate approximation for biases in general formalizations. FlashBias can fully take advantage of the extremely optimized matrix multiplication operation in modern GPUs, achieving 1.5$\times$ speedup for Pairformer in AlphaFold 3, and over 2$\times$ speedup for attention with bias in vision and language models without loss of accuracy. Code is available at this repository: https://github.com/thuml/FlashBias.
title FlashBias: Fast Computation of Attention with Bias
topic Machine Learning
url https://arxiv.org/abs/2505.12044