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

Haoyuan Sun, Ali Jadbabaie, Navid Azizan · DOI

Abstract

Transformer-based models demonstrate a remarkable ability for in-context learning (ICL), where they can adapt to unseen tasks from a few prompt examples without parameter updates. Recent research has illuminated how Transformers perform ICL, showing that the optimal linear self-attention (LSA) mechanism can implement one step of gradient descent for linear least-squares objectives when trained on random linear regression tasks. Building on this, we investigate ICL for nonlinear function classes. We first prove that LSA is inherently incapable of outperforming linear predictors on nonlinear tasks, underscoring why prior solutions cannot readily extend to these problems. To overcome this limitation, we analyze a Transformer block consisting of LSA and feed-forward layers inspired by the gated linear units (GLU), which is a standard component of modern Transformers. We show that this block achieves nonlinear ICL by implementing one step of gradient descent on a polynomial kernel regression loss. Furthermore, our analysis reveals that the expressivity of a single block is inherently limited by its dimensions. We then show that a deep Transformer can overcome this bottleneck by distributing the computation of richer kernel functions across multiple blocks, performing block-coordinate descent in a high-dimensional feature space that a single block cannot represent. Our findings highlight that the feed-forward layers provide a crucial and scalable mechanism by which Transformers can express nonlinear representations for ICL.

Introduction

In the quest to understand the mechanisms behind the success of Transformers, researchers have identified a fascinating emergent behavior: In-Context Learning (ICL). When presented with a prompt containing a sequence of examples, Transformers appear to execute a "hidden" optimization algorithm—effectively running a forward-pass version of gradient descent to adapt to the task at hand.

However, existing theoretical frameworks have largely focused on how Transformers solve linear problems using self-attention. This focus leaves a significant portion of the architecture—the Feed-Forward Networks (FFNs), which constitute roughly two-thirds of a model's parameters—largely unexplained in the context of ICL. If self-attention acts as the optimizer, what is the functional role of the FFN? This research investigates how FFNs unlock the ability to learn nonlinear functions in context, transforming Transformers from simple linear adaptors into powerful kernel regressors.

The Theoretical Gap: The Attention-Only Ceiling

Previous studies demonstrated that a single Linear Self-Attention (LSA) layer could perfectly mimic one step of gradient descent for linear regression. However, the real world is rarely linear. This study establishes a fundamental "Attention-Only Ceiling": the authors prove mathematically that no matter the depth of the network, a purely linear attention mechanism is incapable of outperforming a basic linear least-squares predictor when faced with nonlinear data.

For example, if a model is tasked with learning a quadratic function (e.g., $y = x^2$) from examples, a linear attention network will fail to capture the underlying curvature, remaining trapped in a linear approximation. This necessitates a mechanism for generating nonlinear features, which is where the FFN layers become essential.

FFNs as Engines of Nonlinearity

To bridge the gap between linear and nonlinear ICL, the researchers analyzed a Transformer architecture mirroring modern models like Llama and PaLM. This architecture utilizes:

  1. Linear Self-Attention (LSA): A simplified attention mechanism without softmax activation.
  2. Bilinear FFNs: A variant of the Gated Linear Unit (GLU) that computes the element-wise product of two linear projections.

The study demonstrates that the bilinear FFN acts as a "feature map." By taking an input $x$ and producing higher-order terms (such as quadratic features $x_i x_j$), the FFN transforms the input space into a high-dimensional feature space. When this transformation is coupled with an attention layer, the resulting Transformer block effectively implements Kernel Gradient Descent. In this framework, the FFN provides the "kernel" (the feature representation), and the attention layer performs the optimization over those features.

Scaling with Depth: Block-Coordinate Descent

A significant challenge in nonlinear learning is the dimensionality bottleneck. A single Transformer block is constrained by its embedding dimension ($d$). If a complex nonlinear task requires more features than the embedding dimension can hold, a single block cannot achieve optimal performance.

The authors propose that deep Transformers solve this through a process analogous to Block-Coordinate Descent. Rather than trying to represent all features in a single layer, the model distributes the workload across multiple blocks. Each layer focuses on a specific subset of the nonlinear features. For instance, in a task requiring quadratic representations, Layer 1 might process one set of interactions while Layer 2 processes another, with the network progressively refining its prediction. This allows the model to handle high-dimensional nonlinear problems that exceed the capacity of any individual layer.

Experimental Results and Feature Composition

The researchers validated their theoretical findings using synthetic datasets involving quadratic and cubic functions. Key findings include:

  • Necessity of FFNs: Experiments confirmed that without FFN layers, the error rate remains high regardless of model depth, as the model cannot generate the required nonlinear features.
  • Quadratic Performance: The "Bilinear Transformer" achieved an error rate of $O(d^2/n)$ (where $d$ is the input dimension and $n$ is the prompt length), matching the theoretical performance of specialized nonlinear solvers.
  • Feature Composition: When testing cubic functions, the authors found that "dense" FFNs—which allow layers to communicate and build upon previous outputs—significantly outperformed "sparse" ones. This suggests that deep Transformers do not just distribute features; they compose them, using the quadratic outputs of early layers to construct more complex cubic features in subsequent layers.

Limitations and Future Directions

While this work provides a robust framework for understanding FFNs, it relies on simplified components, such as linear attention (omitting softmax) and bilinear FFNs (omitting ReLU or GELU activations). While these are closely related to the components used in state-of-the-art models, the specific nuances of standard nonlinear activations remain an area for future study. Additionally, while the focus on polynomial kernels is mathematically tractable, exploring how Transformers implement more complex kernels (such as Radial Basis Functions) could further clarify their general-purpose learning capabilities.

Conclusion

This research shifts the perspective on Transformer architecture by demonstrating that Feed-Forward Layers are not merely auxiliary components but are the primary drivers of nonlinear representation in In-Context Learning. By acting as feature generators that enable kernel regression and utilizing depth to perform block-coordinate descent, FFNs allow Transformers to navigate and learn from complex, high-dimensional data environments.

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