On the Role of Transformer Feed-Forward Layers in Nonlinear In-Context Learning

Haoyuan Sun, Ali Jadbabaie, Navid Azizan

TL;DR

While linear self-attention alone can explain how Transformers learn linear tasks in-context, it hit a hard theoretical wall when faced with nonlinear functions. This paper proves that pure attention cannot outperform standard linear regression on nonlinear problems, and demonstrates that feed-forward layers (specifically gated linear units) are the missing piece—acting as implicit kernel feature maps that enable deep Transformers to execute block-coordinate gradient descent in high-dimensional feature spaces.

What Problem Does This Paper Address?

In-context learning (ICL) allows Transformers to adapt to unseen tasks at test time simply by conditioning on a prompt of input-label demonstrations $(\mathbf{x}_i, f(\mathbf{x}_i))$. Recent theoretical breakthroughs revealed that attention layers can implicitly simulate gradient descent to solve linear regression tasks.

However, how Transformers manage nonlinear in-context learning has remained largely unexplained. Most foundational theory has focused solely on attention modules, leaving the feed-forward network (FFN)—which makes up roughly two-thirds of the model's parameters—theoretically sidelined. The authors investigate this gap: why are attention-only models insufficient for nonlinear ICL, and what exact computational role do feed-forward layers play?

Methods

The authors adopt a theoretical approach, studying the expressive power and optimal parameter configurations of Transformer layers:

  1. Expressivity Lower Bounds: Analyzing the functional limits of deep Linear Self-Attention (LSA)—self-attention without softmax activation—on nonlinear target functions.
  2. LSA-GLU Block Construction: Pairing an LSA layer with a feed-forward layer based on Gated Linear Units (GLU), a standard fixture in modern architectures (e.g., LLaMA).
  3. Implicit Kernel Formulation: Modeling the forward pass of this combined block as kernel regression:
  4. The GLU layer maps raw inputs into a nonlinear (e.g., quadratic) feature space.
  5. The LSA layer computes gradient updates on the prompt examples directly within that feature space.
  6. Deep Network Extension: Analyzing how stacking multiple blocks allows the model to distribute higher-order polynomial computations across layers via block-coordinate descent.

Datasets

Not discussed in the paper. (This is a theoretical extended abstract that develops mathematical constructions and proofs rather than empirical benchmarks).

Key Insights and Ideas

  • The Attention-Only Barrier: No matter how deep you make a linear self-attention network, it can never beat a simple linear least-squares estimator when the underlying task is nonlinear. Attention alone cannot extract nonlinear feature representations.
  • Feed-Forward Layers as Implicit Kernels: GLU-style feed-forward layers compute polynomial feature maps (such as outer products of inputs). In essence, the FFN transforms the problem into a reproducing kernel Hilbert space (RKHS).
  • Attention as the Feature-Space Optimizer: Once the FFN creates the nonlinear representation, the attention layer performs preconditioned gradient descent on the kernelized data. The optimal attention layer uses a preconditioner approximately equal to the negative inverse covariance matrix of the features.
  • Depth Powers Block-Coordinate Descent: A single Transformer block has a representation bottleneck tied to its layer dimensions. Deep Transformers circumvent this by distributing the computation of higher-order polynomial kernels across multiple layers, performing block-coordinate descent in an exponentially richer feature space that no single block could represent.

Key Results

  • Impossibility Theorem: Proved that deep linear self-attention networks cannot achieve lower ICL loss than a linear least-squares predictor on nonlinear target functions.
  • Exact Quadratic Equivalence: Proved that a single block composed of a GLU-style FFN and an LSA layer provably implements one step of gradient descent with a quadratic kernel.
  • Optimality Characterization: Derived the optimal weight configuration, proving that optimal FFN weights explicitly materialize all quadratic feature combinations, while optimal attention weights implement feature-space gradient descent.
  • Scaling via Depth: Showed that deeper models structurally scale to higher-order polynomials through distributed kernel computation and block-coordinate updates.

Limitations and Future Work

  • Linear Self-Attention vs. Softmax Attention: The analysis relies on Linear Self-Attention (omitting softmax normalization). While standard in theoretical ICL literature, extending these exact equivalence proofs to standard softmax attention remains an open challenge.
  • Focus on Polynomial Function Classes: The explicit constructions primarily target quadratic and higher-order polynomial kernels. Though the authors state the analysis extends to other FFN architectures capable of nonlinear feature extraction, non-polynomial function classes (e.g., decision trees, general neural nets) require further formal exploration.

Summary updated

BibTeX
@inproceedings{sun2026role,
  author = {Haoyuan Sun and Ali Jadbabaie and Navid Azizan},
  title = {{On the Role of Transformer Feed-Forward Layers in Nonlinear In-Context Learning}},
  booktitle = {ALT},
  year = {2026},
  url = {https://openreview.net/forum?id=7u3GLaafyF},
}
Figure