Flexformer: Flexible Linear Transformer with Learnable Attention Kernel

Haoran Zhang, Feng Zhou
6/26/2026
cs.LGcs.AI
transformer-attention

No confident code implementation found for this paper.

Abstract

Transformer models rely on attention mechanism to capture long-range dependencies but suffer from quadratic complexity, limiting their scalability to long sequences. Kernel-based linear attention reduces this complexity but typically relies on fixed or weakly learnable kernels, restricting expressiveness and performance.

Show full abstract

In this work, we propose Flexformer, a flexible linear Transformer that learns attention kernels in a fully data-driven manner. Flexformer builds on random Fourier feature-based linear attention and treats spectral frequencies as trainable parameters, enabling the model to learn a broad family of attention kernels. We develop both stationary and nonstationary variants, with the latter offering strictly greater expressiveness. Extensive experiments on language modeling and sequence classification demonstrate that Flexformer consistently outperforms baselines. Moreover, Flexformer can be effectively distilled from pretrained Transformers to recover softmax attention and exhibits strong kernel transferability across domains, achieving both high efficiency and competitive performance on long-sequence tasks.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{zhang2026flexformer,
  title  = {Flexformer: Flexible Linear Transformer with Learnable Attention Kernel},
  author = {Haoran Zhang and Feng Zhou},
  year   = {2026},
  eprint = {2606.27748},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2606.27748v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2606.27748.svg)](https://codeofpaper.com/paper/2606.27748)

Discussion