Flexformer: Flexible Linear Transformer with Learnable Attention Kernel
Haoran Zhang, Zisu Dong, Feng Zhou
NeurIPS 2026
TL;DR. We propose Flexformer, a linear Transformer that learns attention kernels in a fully data-driven way, achieving higher expressiveness and better performance than existing linear attention methods while remaining efficient for long sequences.
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. 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.
Are you an author? Claim this paper to see who's reading it, with views and other statistics, and to write about it here.
Claim this paperedit · history
NeurIPS 2026
Accept (poster) · 4 reviews · OpenReview
Updated 25 Nov 2026, 03:43 UTC.
- Decision
- Accept (poster)
Read decision
Meta-review
This paper extends the kernel view of self-attention to a wider family of kernels. The approach is based on representations of stationary and non-stationary kernels. The main technique used is random Fourier features. Experiments are done on tasks in long-range arena, language modeling on WikiText-103, and testing distillation of RoBERTa on GLUE.
The paper is well motivated and well explained. This would have been a great paper if it was written in 2022, so there is no question about the rigor of the experimental design. However, the field has moved on, and the main concern from reviewer K8yg and 379y is timeliness. Since then there are a lot of things built on top of regular Transformers, and to make a convincing argument, it would be better to have one experiment that is more timely, for example, replacing regular softmax attention with the proposed attention.
In terms of the revisions needed, I don't find the sentences in the intro dismissive as pointed out by reviewer 379y. I also don't see why FlashAttention is relevant (though it's still good to make it explicit), because specialized implementation will come later. I also don't see the issue with time complexity raised by reviewer K8yg. Really, the only issue left is timeliness.
The rebuttal includes additional experiments extending long-context experiments to 16K and to GPT-3 XL. The timeliness concern is properly addressed.
Final justification
See the updated meta-review.
- Final justification
- See the updated meta-review.
Read meta-review
Meta-review
This paper extends the kernel view of self-attention to a wider family of kernels. The approach is based on representations of stationary and non-stationary kernels. The main technique used is random Fourier features. Experiments are done on tasks in long-range arena, language modeling on WikiText-103, and testing distillation of RoBERTa on GLUE.
The paper is well motivated and well explained. This would have been a great paper if it was written in 2022, so there is no question about the rigor of the experimental design. However, the field has moved on, and the main concern from reviewer K8yg and 379y is timeliness. Since then there are a lot of things built on top of regular Transformers, and to make a convincing argument, it would be better to have one experiment that is more timely, for example, replacing regular softmax attention with the proposed attention.
In terms of the revisions needed, I don't find the sentences in the intro dismissive as pointed out by reviewer 379y. I also don't see why FlashAttention is relevant (though it's still good to make it explicit), because specialized implementation will come later. I also don't see the issue with time complexity raised by reviewer K8yg. Really, the only issue left is timeliness.
The rebuttal includes additional experiments extending long-context experiments to 16K and to GPT-3 XL. The timeliness concern is properly addressed.
7 comments
Response to Initial MetaReview by Reviewer K8yg
Dear Area Chair,
Thank you for the careful summary of the discussion. I would like to clarify the rationale behind two of my concerns, as they bear directly on the remaining timeliness issue.
1. Why FlashAttention is relevant — it should not be conflated with flash linear attention.
Causal-mask attention is arguably the most important deployment setting for self-attention today, as the core component of LLMs. Because linear attention must accumulate the KV state before applying Q, a causal mask cannot be incorporated in its linear-recurrent form (), masking requires materializing QK first. This is why practical linear models rely on chunk-wise flash linear attention (linear form across off-diagonal chunks, quadratic computation within diagonal chunks) with heavily optimized triton kernels.
Two reference points:
- (i) DeltaNet's plain torch implementation is slower than standard attention although it is linear complexity, and only becomes usable through its Triton flash-linear implementation;
- (ii) FlashAttention-optimized softmax matches the throughput of linear attention at 4K–8K sequence lengths, and is faster at shorter ones.
The paper does not describe how its attention is implemented, nor compare against optimized baselines in this setting, so its practical efficiency advantage remains unverified.
2. On timeliness — I agree to replace regular softmax attention with the proposed attention.
- Both dominant settings should be covered: causal-mask attention (LLMs) and bidirectional self-attention (ViTs), the two core components of modern architectures.
- LRA should not serve as the core evidence: it uses only two transformer layers with extreme seq_len:head_dim ratios (up to 4K:32). It was a reasonable proxy in 2022, but is no longer representative in sequence length, model size, or task setup.
- Scale matters: the quality gap between linear and softmax attention widens with model size and sequence length, which is a key reason modern LLMs (e.g., Qwen, Kimi) adopt hybrid architectures. The paper's largest model has 247M parameters with a 512-token context, below even GPT-2-medium (300M+ parameters, 1024-token context). Validation in the 0.6B regime suggested in my review would be substantially more convincing.
In summary, I respectfully see the remaining issues as going beyond timeliness alone. For a linear attention work, comparison against FlashAttention and hardware compatibility (e.g., flash linear attention) are in my view obligatory rather than optional, since they determine whether the claimed efficiency is practically realizable. Beyond efficiency, the most critical gap is large-scale validation, particularly GPT-style experiments at modern LLM scales, which I consider essential for establishing the framework's viability.
Best regards,
Reviewer K8yg
Thank you for your constructive suggestion. We fully agree that the requested long-sequence experiments are essential to demonstrate our method’s effectiveness in more challenging scenarios. We are currently running two complementary experiments: (1) long-sequence classification with length extended to 16K, and (2) autoregressive language modeling with 1024‑token context on a 1.3B model. Due to computational constraints, we expect to complete them shortly before the rebuttal deadline. We will update our response with detailed results and analysis as soon as they are available. We appreciate your attention and will keep you informed.
- Rating
- 3/6
- Confidence
- 4/5
- Quality
- 2/4
- Clarity
- 3/4
- Significance
- 2/4
- Originality
- 3/4
- Contribution type
- general
- Ethical concerns
- NO or VERY MINOR ethics concerns only
Read review
Summary
FlexFormer is a kernelized linear attention mechanism that generalizes Performer/RFA-style linear attention by learning the spectral representation of the attention kernel. Rather than sampling Fourier frequencies from a fixed distribution or computing a fixed linear attention kernel, FlexFormer treats the spectral frequencies as trainable parameters and learns them end-to-end from data. This enables the model to learn both stationary and non-stationary kernel families while retaining the linear-time and linear-memory complexity of kernelized linear attention.
Strengths and weaknesses
Strengths:
1.) The central idea of learning the attention kernel, rather than relying on a fixed hand-designed kernel, is interesting and well-motivated. While the scope of the work is primarily limited to improving kernelized linear attention, it represents a meaningful step toward more expressive and adaptive attention mechanisms and may inspire future research in this direction.
2.) The distillation experiments provide useful empirical evidence and help validate the proposed approach beyond standard training benchmark comparisons.
3.) The work is grounded in theoretical foundation, with a principled formulation based on spectral kernel learning. The exploration of both stationary and non-stationary kernel variants is valuable and helps clarify the trade-offs between expressiveness and computational efficiency.
Weaknesses:
1.) The discussion in Lines 34--37 appears somewhat dismissive of prior sparse attention approaches. Many of the cited sparse-attention methods have been rigorously evaluated across a broad range of benchmarks and settings, often with substantially more extensive experimental validation than the LRA and WikiText-103 evaluations presented in this work. The manuscript would benefit from a more balanced characterization of these prior efforts.
2.) The long-context evaluation is relatively limited given the manuscript's emphasis on scalable sequence modeling. The longest sequences considered are 4K tokens, making it difficult to assess the practical benefits of FlexFormer in contemporary long-context workloads. Evaluations at 16K, 32K, or longer context lengths would provide stronger evidence that the proposed approach maintains its effectiveness and efficiency in the settings for which linear-attention methods are typically motivated.
3.) The baseline selection could be expanded to better reflect recent developments in efficient sequence modeling. Although Hedgehog and PolaFormer are strong and relevant comparisons, additional evaluations against more recent linear-time architectures and attention alternatives, such as Gated DeltaNet [1], Mamba [2], and RACE Attention [3], would help more clearly establish the strengths and limitations of FlexFormer within the broader landscape of scalable sequence models.
4.) It is unclear whether the Softmax Attention results reported in Figure 2 use FlashAttention [4]. Since performance comparisons are a central part of the manuscript, it is important to compare against the strongest available implementation of Softmax Attention that is compatible with the target hardware.
5.) The presentation can be improved in several places. For example, the font sizes in Figure 2 are difficult to read. Additionally, some claims would benefit from more precise citations. For instance, the manuscript refers to optimized Softmax Attention implementations without clearly identifying the corresponding work. There are also several relevant linear attention works that are not discussed, including YOSO [5], PolySketchFormer [6], Nyströmformer [7], etc. A more comprehensive discussion of related work would strengthen the manuscript.
[1] Songlin Yang, Jan Kautz, Ali Hatamizadeh. Gated Delta Networks: Improving Mamba2 with Delta Rule. ICLR 2025.
[2] Albert Gu, Tri Dao. Mamba: Linear-Time Sequence Modeling with Selective State Spaces. COLM 2024.
[3] Sahil Joshi, Agniva Chowdhury, Amar Kanakamdala, et al. RACE Attention: A Strictly Linear-Time Attention Layer for Training on Outrageously Large Contexts. ICLR 2026.
[4] Tri Dao, Daniel Y Fu, Stefano Ermon, et al. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness. NeurIPS 2022.
[5] Zhanpeng Zeng, Yunyang Xiong, Sathya N. Ravi, et al. You Only Sample (Almost) Once: Linear Cost Self-Attention Via Bernoulli Sampling. ICML 2021.
[6] Praneeth Kacham, Vahab Mirrokni, Peilin Zhong. PolySketchFormer: Fast Transformers via Sketching Polynomial Kernels. ICML 2024.
[7] Yunyang Xiong, Zhanpeng Zeng, Rudrasis Chakraborty, et al. Nyströmformer: A Nystöm-based Algorithm for Approximating Self-Attention. AAAI 2021.
Questions
1.) To what extent do the reported improvements stem from kernel learning itself versus the additional trainable parameters introduced by the learnable spectral frequencies? Have the authors considered parameter-matched baselines, such as using learned projection layers or MLP-based feature maps with comparable parameter counts, to isolate the contribution of the spectral kernel parameterization?
2.) What context length was used for the WikiText-103 language modeling experiments (block size of 512)? Given that one of the motivations of the paper is improving long-context modeling, it would be helpful to evaluate training with longer contexts (e.g., 1024 or 2048 tokens, since LM is expensive) and report whether the observed gains persist in those settings.
3.) The proposed framework is built around learnable spectral kernel representations. Is the approach extendable to non-softmax kernel families?
The empirical evaluation and rigor appears relatively limited compared to the scope of the claims made in the manuscript. Addressing the concerns raised in the Weaknesses section would significantly strengthen the manuscript and could potentially affect my overall assessment.
Limitations
Yes.
Final justification
-
(Low weight - resolved) The authors acknowledged the relevant prior work and committed to discussing it more thoroughly in the final version. They also agreed not to downplay sparse attention, as the current evidence does not support such claims, and to improve the overall clarity and precision of the paper.
-
(High weight - partially resolved) During the rebuttal, the authors added long-context experiments up to 16K tokens. While these results are helpful and led me to increase my initial score, I had recommended evaluating contexts up to 64K, as such scales have become increasingly standard and expected.
-
(High weight - unresolved) The efficiency claims remain a significant concern. No optimized CUDA or Triton kernel has been provided, which substantially limits reproducibility and makes it difficult to assess the practical efficiency of the proposed method. Given that the NeurIPS review process permits authors to share code privately with the Area Chair, it is unclear why this opportunity was not utilized.
Final score: 3 (Borderline Reject).
Overall, I believe the paper has merit, but additional empirical validation is needed to make its claims fully convincing. In particular, stronger evidence demonstrating the accuracy and efficiency at larger scales and against the latest competitive baselines would significantly strengthen the work.
Formatting concerns
No formatting issues.
6 comments
Rebuttal
Thank you for your insightful comments. We would like to respond to the weaknesses and questions you raised as follows:
Q1: Lines 34--37 appears dismissive of prior sparse attention approaches.
A1: We do not consider the sentences in the intro dismissive. AC agrees with this point. Linear attention and sparse attention are two parallel directions within efficient attention, both having seen substantial progress in recent years. However, we argue that linear attention incurs less information loss theoretically, and since our idea is to provide a theoretically grounded method for linear attention, our primary discussion and comparisons focus on linear attention.
Q2: The long-context evaluation is limited. The longer context lengths would be better.
A2: We evaluate long-context performance using Long Range Arena (LRA), a standard benchmark for long-range sequence modeling. The experiments on it sufficiently demonstrate Flexformer's strong performance in long-sequence modeling. As for efficiency, it is shown in Figure 2 that our method already demonstrates a substantial efficiency advantage at a sequence length of 4K. At longer context lengths, this efficiency advantage will only become more pronounced.
Q3: More recent linear-time architectures and attention baselines, such as DeltaNet and Mamba.
A3: Below, we provide comparative results against Mamba and DeltaNet on the image classification and document retrieval task in LRA and the evaluation results and efficiency comparisons are as follows.
| Model | CIFAR | AAN | ||||
|---|---|---|---|---|---|---|
| Accuracy | Training Speed | Memory | Accuracy | Training Speed | Memory | |
| Transformer | 41.89 | 15 | 21.2 | 64.49 | 7 | 21.2 |
| 45.42 | 28 | 3.5 | 73.94 | 18 | 3.4 | |
| Mamba | 43.50 | 23 | 7.2 | 73.90 | 13 | 5 |
| DeltaNet | 44.69 | 26 | 3.8 | 75.74 | 12 | 4.2 |
As can be seen, Mamba and DeltaNet achieve comparable performance to Flexformer, but are slightly inferior in computational efficiency on long sequences.
Q4: It is unclear whether the Softmax Attention results reported in Figure 2 use FlashAttention.
A4: The results in Figure 2 were obtained without using FlashAttention. Our method focuses on reducing the complexity of attention, whereas the current implementation does not incorporate IO-aware memory optimizations such as FlashAttention. These two directions are complementary and could be combined in future work. AC agrees with this point.
Q5: The presentation can be improved in several places.
A5: Thanks for your suggestion. We will improve these in the camera ready.
Q6: Have the authors considered parameter-matched baselines to isolate the contribution of the spectral kernel parameterization?
A6: As shown in Table 7, the additional parameters introduced by Flexformer are minimal, with a relative increase of less than 1%. Therefore, we consider the comparisons in our main experiments to be fair.
Q7: What context length was used for the WikiText-103 language modeling experiments (block size of 512)? Given that one of the motivations of the paper is improving long-context modeling, it would be helpful to evaluate training with longer contexts (e.g., 1024 or 2048 tokens, since LM is expensive) and report whether the observed gains persist in those settings.
A7: In this experiment, we follow the unified settings of prior work and set the maximum sequence length to 512. We evaluate long-sequence modeling capability on LRA, whereas here we only additionally examine whether the proposed method can adapt to autoregressive language modeling. Moreover, most samples in the WikiText-103 dataset have lengths shorter than 512, so setting a longer sequence length would not lead to significant changes in evaluation results.
Q8: Is the approach extendable to non-softmax kernel families?
A8: Of course. In fact, only when the red term in Equation (4) remains within the Gaussian family does the resulting kernel belong to the softmax kernel family. By extending the red term in Equation (4) to arbitrary bounded, continuous, and positive definite kernels, we obtain a substantially broader family that includes many kernels beyond the softmax kernel. This is precisely the generalization introduced by Flexformer.
#1 Response to Rebuttal
Thank you for your responses.
C1. Clarification on "dismissive".
A1. By "dismissive," I was referring specifically to the statement that "attention patterns are not rigorously validated and are often based on empirically derived patterns, making it difficult to guarantee their consistently superior performance across diverse data." I disagree with this characterization. There is a substantial body of literature on sparse attention, well over 20+ papers (1-6 and more) that provide strong empirical evidence demonstrating its effectiveness across a range of tasks. Several of these works are also supported by theoretical analyses that explain why these methods perform well. Given this literature, I do not believe the statement accurately reflects the current state of research.
C2. Long-Context Evaluation.
A2. If the implication is that 4K tokens constitute a long-context evaluation in 2026, I do not agree. Recent work [7] routinely evaluates models on contexts of 16K tokens and beyond, with experiments extending to 64K. These longer settings are precisely where linear attention methods are expected to demonstrate their advantages. This is also why I believe the timeliness of the empirical evaluation is an important consideration, a point that AC also acknowledged.
C3. Related Baselines.
A3. Relatedly, many of the relevant baselines are designed to operate in genuinely long-context settings (4K+). In addition, I found the reported experimental metrics difficult to interpret because the units are not clearly specified. For example, it is unclear whether training speed is measured in seconds, milliseconds, or another unit, and whether memory usage is reported in MB or GB. Is the training speed measured per layer or full model? Without this information, it is difficult to draw meaningful conclusions or fairly compare methods. I would encourage the authors to clearly define all reported metrics and their corresponding units.
C4–C8. Other concerns.
A4-A8. I consider these concerns to have been adequately addressed.
Finally, while I appreciate the authors' efforts in responding to the reviews, I remain unconvinced that the paper is empirically mature enough for acceptance. Context lengths of 512–4096 tokens may have been considered representative of long-context evaluation in 2022, but this is no longer the case. Given the current state of the field, I believe evaluations on substantially longer contexts are necessary to convincingly demonstrate the practical advantages of the proposed method. I strongly believe that Reviewer K8yg will also agree to this.
[1] Desai, A. et al. vAttention: Verified Sparse Attention via Sampling. ICLR 2026.
[2] Desai, A. et al. HashAttention: Semantic Sparsity for Faster Inference. ICML 2025.
[3] Hooper, C. et al. Squeezed attention: Accelerating long context length llm inference. ACL 2025.
[4] Zhang, H. et al. Pqcache: Product quantization-based kvcache for long context llm inference. SIGMOD 2025.
[5] Tang, J. et al. QUEST: Query-Aware Sparsity for Efficient Long-Context LLM Inference. ICML 2024.
[6] Yang, S. et al. Post-Training Sparse Attention with Double Sparsity.
[7] Joshi, S. et al. RACE Attention: A Strictly Linear-Time Attention Layer for Training on Outrageously Large Contexts. ICLR 2026.
Thank you for your constructive suggestion. We fully agree that the requested long-sequence experiments are essential to demonstrate our method’s effectiveness in more challenging scenarios. We are currently running two complementary experiments: (1) long-sequence classification with length extended to 16K, and (2) autoregressive language modeling with 1024‑token context on a 1.3B model. Due to computational constraints, we expect to complete them shortly before the rebuttal deadline. We will update our response with detailed results and analysis as soon as they are available. We appreciate your attention and will keep you informed.
- Rating
- 3/6
- Confidence
- 5/5
- Quality
- 2/4
- Clarity
- 3/4
- Significance
- 2/4
- Originality
- 2/4
- Contribution type
- general
- Ethical concerns
- NO or VERY MINOR ethics concerns only
Read review
Summary
The paper proposes Flexformer, a new linear transformer, which extends kernel-based linear attention with random fourier features by making the feature map fully learnable. Based on two classical theorems, the authors introduce both stationary and nonstationary variants of the learnable kernel to expand the expressive capacity of the model beyond fixed probability measures. The proposed method is evaluated on the Long Range Arena (LRA) benchmark, WikiText-103 for causal language modeling, and GLUE for bidirectional language modeling, and achieving both high efficiency and competitive performance on long-sequence tasks.
Strengths and weaknesses
Strengths
-
Solid Theoretical Motivation: Extending the use of random Fourier features from fixed probability measures to parameter-learned spectral measures provides a mathematically sound framework for increasing kernel flexibility.
-
Extensive Empirical Baselines: Flexformer demonstrates competitive performance across LRA tasks and WikiText-103 compared to classical linear variants like Performer, Linear Transformer, and more recent learnable baselines like Hedgehog and Polaformer.
Weakness
-
The paper claims an asymptotic time complexity of . However, setting results in , effectively degrading the time complexity to . For models with wide hidden dimensions, this quadratic dependency on introduces significant projection overhead and memory footprint, which will likely offset the benefits of linearizing sequence length on memory-bound hardware. More wall-clock efficiency is needed.
-
Eq. 6 is similar to existing methods that utilize Ptolemy’s theorem to introduce absolute/relative positional penalties or reconstruct attention matrices (e.g., NaLaFormer[1]) Authors should adequately discuss the mechanistic similarities regarding how these trigonometric components preserve fidelity or enforce spatial inductive biases.
-
Potential in Linearizing Pretrained LLMs. Learnable feature maps are friendly for linearizing pretrained LLMs, such as STILL[2] and LoLCATs[3]. The paper currently neglects this crucial application. To strengthen the submission, the authors should supplement experiments applying Flexformer to linearize modern pretrained LLMs, or at minimum, discuss its feasibility and theoretical advantages within this paradigm.
-
The current evaluation lacks the scale necessary to prove the framework's broader applicability. To convincingly demonstrate the algorithmic viability of Flexformer, the authors are strongly encouraged to supplement the evaluation with standard computer vision benchmarks (e.g., ImageNet-1K classification). Furthermore, the language modeling experiments are significantly under-scaled; evaluating on models with only up to 247M parameters falls short of even baseline GPT-small configurations. The authors should include larger-scale, GPT-style autoregressive language modeling experiments (e.g., in the 0.6B parameter regime) to verify that the model maintains competitive performance at modern LLM scales.
[1] "Norm $\times $ Direction: Restoring the Missing Query Norm in Vision Linear Attention." arXiv preprint arXiv:2506.21137 (2025).
[2] "STILL: Selecting Tokens for Intra-Layer Hybrid Attention to Linearize LLMs." arXiv preprint arXiv:2602.02180 (2026).
[3] "Lolcats: On low-rank linearizing of large language models." ICLR, 2025.
Questions
In addition to the weaknesses mentioned above, I have the following questions for the authors:
-
Could you visualize or statistically analyze the learned frequency distribution ? How significantly does it deviate from the initialization or a standard fixed Gaussian distribution?
-
Compatibility with Flash Linear Attention (IO-Awareness)
-
Comparison with Flash attention, mamba and deltanet in efficiency and simple language modeling tasks.
This is an interesting work, and I will raise my score accordingly if the authors address all my concerns.
Limitations
yes
Final justification
I thank the authors for their rebuttal and the additional experiments, which partially address my concerns. I maintain that the proposed method is technically sound and the core idea is a valuable contribution to linear attention. However, my central concern remains only partially resolved, so I keep my score unchanged.
My main issue is the lack of validation in the regime where this work matters most. As the method is positioned as a potential replacement for standard self-attention, the community's bar is evidence at LLM-relevant scale and sequence length. This is why I requested causal LM experiments at the 1.3B-parameter scale with sequences beyond 4K, rather than the bidirectional AAN setting. Empirically, the relative performance of linear versus standard attention, in both task accuracy and time/memory efficiency, may shift substantially with model scale and context length, and much of this shift stems from hardware utilization of the underlying implementations rather than asymptotic complexity (hence my questions regarding FLA-based kernels). Without direct comparisons against strong, well-optimized baselines such as FlashAttention and DeltaNet in a large-scale causal LM setting, it is difficult to judge whether the claimed advantages hold in practice. The newly added experiments move in the right direction, but they remain limited in scale, sequence length, and evaluation setting, so this key evidence is still missing.
Overall, I will maintain my initial score 3.
Formatting concerns
NA
1 comment
Rebuttal
Thank you for your insightful comments. We would like to respond to the weaknesses and questions you raised as follows:
Q1: When approaches , linear complexity in no longer confers an advantage.
A1: Here, refers to the per-head dimension. Even for models with overall dimensions in the thousands, the per-head dimension typically remains around 64, while sequence lengths of hundreds or more are commonplace. Therefore, generally holds. AC agrees with this point.
Q2: Difference from methods that reconstruct attention matrices based on trigonometric functions.
A2: The difference is we do not reconstruct attention matrices using trigonometric functions with certain inductive biases, as done in cosformer or NaLaformer. Rather, we leverage the spectral representation theory of kernel functions to express a kernel in terms of its spectral density, and then approximate it via Monte Carlo, thereby obtaining a trigonometric-function-based representation of the kernel.
Q3: Lack of experiments on linearizing pretrained LLMs.
A3: In fact, this is exactly what we do in the attention-weight distillation experiments presented in Sections 4.3 and 4.4, where we linearize the attention of a pretrained RoBERTa model and evaluate its performance after replacing the original attention mechanism.
Q4: Lack of experiments on large-scale models.
A4: Due to limited computational resources, we are unable to conduct experiments on larger-scale models. However, as can be observed from the results in Table 2, as the model scale increases, Flexformer's advantage over other baselines becomes more pronounced.
Q5: The visualization of . How significantly does it deviate from a Gaussian distribution?
A5: Since is a high-dimensional distribution, its density is difficult to visualize. By computing the mean and variance of each component, we can verify that it does not follow an i.i.d. Gaussian distribution. Additionally, we compared Xavier and Gaussian initializations for these parameters and found no difference in either convergence speed or final performance.
Q6: Compatibility with Flash Attention.
A6: Our method is compatible with IO-aware optimization. While our work focuses on reducing the complexity of attention, the current implementation does not explicitly optimize memory access. These two directions are complementary and could be combined to achieve further efficiency gains. As illustrated in Figure 1, IO-aware techniques, such as tiling and kernel fusion, could be applied to the computation involving (K) and (V).
Q7: Comparison with Flash attention, mamba and deltanet.
A7: FlashAttention and our method address two complementary aspects of attention efficiency. Therefore, we do not include a direct comparison with FlashAttention in the rebuttal (AC agrees with this point). Below, we provide comparative results against Mamba and DeltaNet on the image classification and document retrieval task in LRA and the evaluation results and efficiency comparisons are as follows.
| Model | CIFAR | AAN | ||||
|---|---|---|---|---|---|---|
| Accuracy | Training Speed | Memory | Accuracy | Training Speed | Memory | |
| Transformer | 41.89 | 15 | 21.2 | 64.49 | 7 | 21.2 |
| 45.42 | 28 | 3.5 | 73.94 | 18 | 3.4 | |
| Mamba | 43.50 | 23 | 7.2 | 73.90 | 13 | 5 |
| DeltaNet | 44.69 | 26 | 3.8 | 75.74 | 12 | 4.2 |
As can be seen, Mamba and DeltaNet achieve comparable performance to Flexformer, but are slightly inferior in computational efficiency on long sequences.
- Rating
- 5/6
- Confidence
- 3/5
- Quality
- 3/4
- Clarity
- 3/4
- Significance
- 3/4
- Originality
- 3/4
- Contribution type
- general
- Ethical concerns
- NO or VERY MINOR ethics concerns only
Read review
Summary
The paper proposes a learnable kernel for linear attention. The paper starts from representing softmax kernel with random fourier features introduced by A. Rahimi and B. Recht. The paper then introduces two changes to make the kernel more flexible. First, instead of approximating softmax, they make the frequency learnable. Second, they extend the stationary kernel to a nonstationary kernel, by extending Bochner's theorem, known as Yaglom's theorem or the Yaglom-Genton theorem. A nonstationary kernel can therefore also be approximated via a Monte Carlo scheme. The nonstationary kernel is claimed to be more expressive than the stationary one. Empirical evidence shows than the proposed learnable kernel significantly reduces complexity of attention compared to the quadratic format, and obtained similar or better performance over downstream tasks.
Strengths and weaknesses
Strengths:
- The proposed learnable attention kernel addresses the quadratic complexity of softmax attention and improves the flexibility of previous work on linear attention kernels.
- The paper further extends the kernel from stationary to nonstationary to improve its flexibility.
- Empirically, the proposed linear kernel improves softmax attention in terms of efficiency and comparable or better downstream performance.
- The stationary kernel can generalize to softmax kernel.
Weaknesses:
- L112-113 needs more explanation on being infinite.
- Although it may be straightforward, showing how eq4 is derived would make the presentation more accessible.
- Around L177-178. It is unclear to me why p needs to be written as sum of four terms of some density g.
- How is sampled is not clear. It is also not clear how do authors define in the stationary kernel and in the nonstationary kernel).
- It is unclear haw many samples n are used to approximate the expectations via Monte-Carlo. What is the efficiency of Monte-Carlo sampling.
minor points:
- I wonder if there's a way to better quantify the expressiveness of a kernel without looking at the downstream performance. Especially, stationary kernel vs. nonstationary kernel.
- I suggested specifying the original theory used in Theorem 3.1 (Bochner's theorem) and 3.2 (Yaglom-Genton theorem) along with the citations.
- In Sec 4.3, for recovering softmax attention, it would be good to have some visualisations. For instance, present n sampled feature maps and the average of the averaged feature maps vs. the softmax attention.
Questions
- May all nonstandard and positive definite kernels be approximated by random fourier features?
- Are there any constraints imposed to the learnable frequency?
Limitations
see above
Formatting concerns
no
1 comment
Rebuttal
Thank you for your insightful comments. We would like to respond to the weaknesses and questions you raised as follows:
Q1: Lack explanation on being infinite.
A1: It is rigorously proved in the reference [35] "Understanding the differences in foundation models: Attention, state space models, and recurrent neural networks" NeurIPS 2024. In short, this is because the Taylor expansion of is infinite.
Q2: Around L177-178, why needs to be written as sum of four terms of some density .
A2: As stated in Theorem 3.2, is required to be a bounded positive-semidefinite spectral density. To ensure this property by construction, we reparameterize as the sum of four terms derived from a density . This representation guarantees that satisfies the required positive-semidefinite condition.
Q3: How is sampled is not clear. How do authors define in the stationary kernel and in the nonstationary kernel.
A3: In our method, is not sampled; instead, it is treated as a set of learnable parameters. Our theoretical analysis shows that, when the spectral density associated with a kernel function is known, sampling from this density provides an approximation to the kernel. In Flexformer, we aim to learn the kernel function itself. This is equivalent to learning its spectral density and, consequently, to learning the corresponding 's directly from data. Therefore, is not actually sampled from a predefined spectral density but is optimized as a set of learnable parameters during training.
Q4: How many samples are used to approximate the expectations?
A4: Theoretically, a larger yields more accurate approximations of various kernel functions. In our experiments, to ensure a fair comparison with existing linear attention methods in terms of dimension and parameter count, we set .
Q5: For recovering softmax attention, it would be good to have some visualisations.
A5: Thanks for your suggestion. We will add some visualizations in the camera ready.
Q6: May all nonstandard and positive definite kernels be approximated by random fourier features?
A6: According to the theorem, all bounded, continuous, and positive definite kernel functions can be represented.
Q7: Are there any constraints imposed to the learnable frequency?
A7: We impose no constraints on the learned frequencies, which ensures that Flexformer can learn within a sufficiently large kernel space.
Thank you again for your comments, which have provided valuable inspiration for our future research.
- Rating
- 5/6
- Confidence
- 4/5
- Quality
- 3/4
- Clarity
- 3/4
- Significance
- 3/4
- Originality
- 3/4
- Contribution type
- general
- Ethical concerns
- NO or VERY MINOR ethics concerns only
Read review
Summary
This paper proposes learnable kernel-based approximations to attention that reduce time and space complexity. The approximations proposed are more expressive than the fixed, non-learnable kernel approximations that appear in the literature, allowing the model to adapt to the data more accurately. The paper studies two approximations, one with a learnable stationary kernel, and one with a nonstationary learnable kernel. It shows that these two kernels outperform existing linear attention approximations, and have quality close to the vanilla transformer, especially in the distillation setting, while being significantly more efficient.
Strengths and weaknesses
Strengths:
- Proposes an interesting linear attention approximation to attention to speed up computation and save space.
- Many experiments at small scale to validate empirical strength of the approximation
- Well motivated theoretically, with comparison to existing non-learnable approximations; precisely points out the drawbacks of existing works, and why this new method could better fit the data.
- Distillation results in particular are quite interesting.
Weaknesses:
- Lacks large-scale experiments, unclear if findings scale well -- also lacks any kind of scaling study.
Questions
- Do you have any understanding of how well the (quality) results translate with scale?
- Do you have any proposals (not necessarily empirically validated) for extending the method to non-positive-definite kernels?
Limitations
Yes
Formatting concerns
No
1 comment
Rebuttal
Thank you for your insightful comments. We would like to respond to the weaknesses and questions you raised as follows:
Q1: Lacks large-scale experiments and scaling study. Any understanding of how well the (quality) results translate with scale?
A1: Due to limited computational resources, we are unable to conduct experiments on larger-scale models. However, as can be observed from the results in Table 2, as the model scale increases, Flexformer's advantage over other baselines becomes more pronounced.
Q2: Can it be extended to non-positive-definite kernels?
A2: This is an interesting direction, but we have yet to explore the spectral representation theory for non-positive-definite kernel functions.
Thank you again for your comments, which have provided valuable inspiration for our future research.
From OpenReview, CC BY 4.0. Authors as signed there; shown unedited.
Loading the discussion…
Dear AC,
Thank you for the thoughtful metareview. In our rebuttal, we clarified the main theoretical questions concerning the spectral representation, positive-semidefinite parameterization, learnable frequencies, and time complexity. We also clarified the experimental settings, parameter fairness, long-context evaluation, and the complementary relationship between Flexformer and FlashAttention.
Regarding timeliness, we would like to emphasize three points. First, Sections 4.3 and 4.4 already perform the experiment suggested in the metareview: we replace the standard Softmax Attention in pretrained RoBERTa with Flexformer through attention-weight distillation and evaluate the resulting model on GLUE. We will highlight this experiment more clearly in the revision.
Second, following the reviewers’ suggestions, we added comparisons with the more recent Mamba and DeltaNet architectures. Flexformer achieves competitive predictive performance while providing better training speed and memory efficiency on the evaluated long-sequence tasks.
Third, Flexformer is not a fixed-kernel random-feature approximation. It learns the spectral frequencies directly from data and therefore learns the attention kernel itself within a broad family of stationary and nonstationary kernels. Moreover, Flexformer can replace attention modules in existing Transformers and remain compatible with other advances built around the Transformer ecosystem.
We hope these clarifications and additional results address the timeliness concern and demonstrate the continued relevance of Flexformer.
Authors