On the Role of Transformer Feed-Forward Layers in Nonlinear In-Context Learning
Haoyuan Sun, Ali Jadbabaie, Navid Azizan
TL;DR
The paper addresses the gap in understanding nonlinear in-context learning (ICL) in Transformer models. It demonstrates that linear self-attention (LSA) alone cannot capture nonlinear target functions, and shows that a bilinear feed-forward (GLU-like) layer enables nonlinear ICL by realizing one-step gradient descent in a quadratic kernel feature space; however, a single block is fundamentally limited by its embedding dimension. By stacking multiple bilinear blocks, deep Transformers perform block-coordinate descent across a richer feature space, enabling learning of higher-degree polynomials in-context (quadratic and cubic examples), with theoretical bounds and approximate optimality analyses. The key finding is that feed-forward layers provide a scalable, essential mechanism for nonlinear ICL in Transformers, and depth distributes nonlinear kernel computation to overcome single-block bottlenecks, offering insights for designing models with stronger in-context learning capabilities. These results have implications for understanding and engineering Transformers to perform task adaptations from prompts without weight updates, particularly for complex nonlinear tasks.
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.
