NeurIPS 2026QuestionsPapersAreasAboutMarkdown

Flexformer: Flexible Linear Transformer with Learnable Attention Kernel

Haoran Zhang, Zisu Dong, Feng Zhou

NeurIPS page · OpenReview · alphaXiv · Open on the map

Category: Efficient LLM Inference & Training › Linear Attention Memory Mechanisms · Type: new method · Keywords: linear attention, trainable spectral frequencies, long sequence modeling, efficient transformers, attention kernel learning, random Fourier features

Areas: Long Context › Long-context mechanisms › Efficient attention; Model Architectures & Sequence Modeling › Language Model Architectures › Efficient Attention

Summary

Flexformer introduces a flexible linear Transformer that learns attention kernels via trainable spectral frequencies, achieving efficient linear complexity and strong performance on long sequences.

Explained to a 5-year-old

Flexformer is a new kind of brain for computer programs that helps them read long stories without getting too slow. It learns how to focus on the most important parts by tweaking some special numbers. This makes the program faster and smarter, like a super-fast reader. It can be copied from existing smart programs, so it works in many different places. Overall, it makes long-range thinking easier and more efficient.

Explained to a 5-year-old, longer

Flexformer is a new kind of brain for computer programs that helps them understand long texts without becoming slow. Traditional transformers need a lot of work because they look at every word together, which is like counting all the stars in the sky at once. To make things faster, researchers created linear attention that works like a shortcut, but it often cannot learn much. Flexformer improves this shortcut by letting the program adjust some special numbers that decide how to focus. These special numbers are like tiny dials that can be turned to match the story being read. By turning these dials, the program can pay attention to far-away words while staying quick. The system comes in two flavors: one that works with simple dials and another that can use more complex ones. The more complex version can capture richer patterns, like understanding jokes that refer back to earlier parts of a story. Experiments show that Flexformer works better than the old shortcuts on tasks like predicting the next word and classifying text. It can also be copied from already smart programs, so it works well in many different subjects, like pictures or sounds. This copying ability means the learned attention can be reused, saving time and effort. In short, Flexformer makes long-range thinking fast, smart, and flexible for many kinds of data.

For a technical reader

Flexformer replaces the quadratic-time softmax attention in standard transformers with a linear-time attention mechanism based on random Fourier features. By making the spectral frequencies of these features trainable, the model can learn a wide variety of attention kernels, both stationary and non-stationary. This design yields a model that scales linearly with sequence length, enabling efficient processing of long documents while preserving expressive power. The authors show that Flexformer not only outperforms existing linear-attention baselines on language modeling and classification but also transfers well when distilled from pre-trained transformers. Overall, Flexformer provides a scalable, expressive alternative for long-range modeling.

Problem

Transformer attention mechanisms have quadratic computational cost, making them hard to scale to long sequences. Existing linear attention approximations reduce complexity but rely on fixed kernels, which limits their expressive power.

Method

The approach builds on random Fourier feature-based linear attention and makes the spectral frequencies trainable, allowing the model to learn a wide family of attention kernels. It provides both stationary and nonstationary variants, with the nonstationary version offering greater expressiveness. The resulting model operates with linear complexity while retaining expressive power.

Results

The approach consistently outperforms baseline linear attention methods on language modeling and sequence classification, and it transfers well across domains while maintaining high efficiency on long sequences.

Contributions

The work introduces trainable spectral frequencies for random Fourier feature-based linear attention, providing both stationary and nonstationary kernel variants with increased expressiveness, and demonstrates effective distillation and cross-domain transfer of attention kernels.

Practical relevance

It enables scalable, efficient transformers for long sequences, facilitating applications such as long-document processing and real-time sequence modeling.

Research questions this paper is counted under

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. Suggest a correction