SandHouse
Pages and contents

Fast Multipole Attention (FMA)

0\. Metadata

Field
Value
⋮⋮
Authors
Tran, Kang, Sterck
⋮⋮
Year
2025
⋮⋮
Link / arXiv
https://arxiv.org/pdf/2310.11960
⋮⋮
Code
https://github.com/epoch98/FMA
⋮⋮
My relevance (1-5)
5
⋮⋮
Tags
#transformer #attention

1\. Main Idea

Fast Multipole Attention provides an attention mechanism that beats Swin and is O(Nlog⁡(N))in compute time. Local objects receive full attention while more distant objects receive coarse learned attention.

2\. Problem

While Transformer networks benefit from a global receptive field, their quadratic cost relative to sequence length restricts their application to long sequences and high-resolution inputs. We introduce Fast Multipole Attention (FMA), a divide-and-conquer mechanism for self-attention inspired by the Fast Multipole Method from n-body physics. FMA reduces the time and memory complexity of self-attention fromO(N²)toO(Nlog⁡(N))and O(N) while preserving full-context interactions.

3\. Method

In the neighborhood of the query, attention is calculated with keys and values in full resolution. Moving away from the query, keys and values are grouped and downsampled (or summarized) in increasingly larger groups using learned downsampling weights, and attention is calculated in lower resolution. The resulting attention matrix has a hierarchical structure.

Standard attention

Given input tokens X∈ℝn×d , queries, keys, and values are produced by
learned projections:

Q=XWQ,K=XWK,V=XWV.

Standard self-attention computes

Attention⁡(Q,K,V)=softmax⁡(QK⊤dh)V.

Because every query interacts with every key, this requires O(n2) attention scores.

Near-field attention

FMA divides the input into spatial cells of size r×r . Each query attends exactly to tokens in its own cell and the eight adjacent cells. For a query at position i , its near field is

𝒩(i)={j:|Bx(j)−Bx(i)|≤1;|By(j)−By(i)|≤1},

where Bx(i) and By(i) identify the spatial cell containing token i . Attention within this near field uses the original full-resolution keys and values:

yinear=∑j∈𝒩(i)αijvj,

with

αij=exp⁡(qi⊤kj/dh)∑t∈𝒩(i)exp⁡(qi⊤kt/dh)

This preserves detailed interactions between nearby image regions.

Hierarchical far-field summaries

Distant regions are represented by progressively coarser summaries arranged in a quadtree. At
hierarchy level ℓ , a cell covers an area proportional to

r2ℓ×r2ℓ.

Each cell S is represented by learned aggregated keys and values:

k‾S=∑j∈Sπℓ,jkkj,v‾S=∑j∈Sπℓ,jvvj,

where πℓk and πℓv are learned aggregation weights. Instead of attending to every distant token, a query attends to these cell summaries:

yi(ℓ)=∑S∈ℱℓ(i)βi,S(ℓ)v‾S,

where

βi,S(ℓ)=exp⁡(qi⊤k‾ S/dh)∑S′∈ℱℓ(i)exp⁡(qi⊤k‾ S′/dh).

The set ℱℓ(i) contains distant cells represented at level ℓ . Regions farther from the query are represented at increasingly coarse resolutions.

Combined output

The final FMA output combines exact near-field attention with contributions from every coarse level:

yi=yinear+∑ℓ=1L−1yi(ℓ).

Thus, each layer provides both:

• High-resolution modeling of nearby tokens.
• Coarse but global interaction with distant regions.

Computational complexity

For 2D inputs, each query attends exactly to at most 9r2 nearby tokens and to a constant-size set of summaries at each hierarchy level. With L=O(log⁡n) hierarchy levels, the total attention complexity is

O(n(9r2+log⁡n))=O(nlog⁡n).

The paper also describes a query-downsampled variant that reduces the complexity to O(n) .

Coarse rank

A coarse cell can be represented using more than one learned summary. With coarse rank p , each cell stores

{k‾S(s),v‾S(s)}s=1p.

Increasing p gives the far-field representation more capacity, but increases its compute and memory cost approximately in proportion to p . The simplest form of FMA uses p=1 .