Half the Nonlinearity Is Wasted: Measuring and Reallocating the Transformer's MLP Budget
Organizations: Peter Balogh
Abstract
We investigate when transformer MLP nonlinearity is actually necessary. A gate with parameters decides when to replace the full MLP with a linear surrogate. Through systematic investigation across six models (162M-2.8B parameters), two architectures, and three corpora, we establish that nonlinearity need cannot be predicted from token identity: cross-corpus correlation is zero (). The routing decision is fully contextual. Despite weak per-instance predictability, the gate exploits a heavily skewed distribution where most MLP computations are near-linear, achieving 25-56% linear routing at <1% perplexity cost in GPT-2. In GPT-2 Large, 11 of 36 layers beat baseline with gating and no layer exceeds 3.7% all-linear cost. This success is architecture-dependent: Pythia models show higher costs, though Pythia-2.8B's full 32-layer sweep reveals one layer that narrowly beats baseline. As a proof of concept, we progressively replace middle-layer MLPs with frozen linear matrices: 5 of 24 layers linearize at zero cost. With a full training budget, 4 linearized layers yield a 10.2% perplexity improvement -- and a two-phase gated approach pushes this to 17.3%, beating a vanilla fine-tuning control and confirming that the nonlinear MLPs at these layers were actively harmful.
Figures & tables
| Name | Architecture | Parameters |
|---|---|---|
| linear | ||
| b=1 | ||
| b=3 | PCA to 6 dims + logistic | |
| b=6 | PCA to 12 dims + logistic |
| Model | Family | Params | Layers | Layers tested | |
|---|---|---|---|---|---|
| GPT-2 Medium | GPT-2 | 345M | 24 | 1024 | 1–23 (all non-embedding) |
| GPT-2 Large | GPT-2 | 774M | 36 | 1280 | 0–35 (all) |
| Pythia-160M | GPT-NeoX | 162M | 12 | 768 | 0,2,5,8,11 |
| Pythia-410M | GPT-NeoX | 405M | 24 | 1024 | 0,2,6,12,18,23 |
| Pythia-1B | GPT-NeoX | 1,012M | 16 | 2048 | 0,2,6,8,10,15 |
| Pythia-2.8B | GPT-NeoX | 2,775M | 32 | 2560 | 0–31 (all) |
| Model | Params | Cheapest | Most Expensive | ||
|---|---|---|---|---|---|
| GPT-2 Medium | 345M | L8 | L23 | ||
| GPT-2 Large | 774M | L5 | L31 | ||
| Pythia-160M | 162M | L5 | L2 | ||
| Pythia-410M | 405M | L12 | L6 | ||
| Pythia-1B | 1,012M | L6 | L2 | ||
| Pythia-2.8B | 2,775M | L10 | L0 |
| Layer | Full | Token Only | Context Only | Token Type | Random |
|---|---|---|---|---|---|
| L1 | 0.536 | 0.533 | 0.538 | 0.545 | 0.500 |
| L12 | 0.579 | 0.568 | 0.575 | 0.579 | 0.500 |
| L23 | 0.609 | 0.567 | 0.605 | 0.607 | 0.500 |
| Test Corpus | Found | Still No-Fly | Flipped ( ) | Correlation |
|---|---|---|---|---|
| WikiText-103 train | 149 / 221 | 47 (31.5%) | 40 (26.8%) | |
| LAMBADA | 100 / 221 | 22 (22.0%) | — |
| Layer | PCA Var | Cluster AUC | Clean Clusters | Ambiguous |
|---|---|---|---|---|
| L1 | 61% | 0.519 | 0 / 20 | 100% |
| L12 | 37% | 0.570 | 0 / 20 | 100% |
| L23 | 56% | 0.611 | 0 / 20 | 100% |
| Metric | Value |
|---|---|
| Total gate parameters | 104,659 (0.03% of model) |
| Average linear routing | 39.9% of positions |
| Layers beating baseline | 4 / 23 |
| MLP FLOPs saved | |
| Total forward-pass FLOPs saved | |
| Best single layer | L9: at 35% linear |
| Model | Params | Base PPL | Layers | Best ( ) | Gate | Avg % Lin |
|---|---|---|---|---|---|---|
| GPT-2 Med | 345M | 34.8 | 23 | L9 ( ) | linear | 39.9% |
| GPT-2 Large | 774M | 30.6 | 36 | L5 ( ) | b=1 | 40.9% |
| Pythia-160M | 162M | 45.1 | 5 | L0 ( ) | b=1 | 42.4% |
| Pythia-410M | 405M | 29.5 | 6 | L12 ( ) | linear | 43.5% |
| Pythia-1B | 1,012M | 23.2 | 6 | L0 ( ) | b=1 | 26.9% |
| Pythia-2.8B | 2,775M | 17.7 | 32 | L3 ( ) | b=1 | 37.1% |
| Model | Params | All-Linear | Best Gate | % Linear |
|---|---|---|---|---|
| GPT-2 Large | 774M | (b=1) | 53.5% | |
| Pythia-160M | 162M | (b=1) | 18.0% | |
| Pythia-410M | 405M | (b=3) | 34.9% | |
| Pythia-1B | 1,012M | (b=1) | 8.2% | |
| Pythia-2.8B | 2,775M | — | — |
| # Linearized | Layer Added | PPL (after FT) | Note | |
|---|---|---|---|---|
| 0 | (baseline) | 27.17 | — | |
| 1 | L12 | 24.79 | beats baseline | |
| 2 | +L11 | 24.65 | beats baseline | |
| 3 | +L13 | 25.13 | beats baseline | |
| 4 | +L10 | 25.97 | beats baseline | |
| 5 | +L14 | 27.17 | matches baseline |
| Step | WikiText PPL | LAMBADA | |
|---|---|---|---|
| 0 (baseline) | 22.98 | — | — |
| 0 (post-lin) | 27.09 | ||
| 200 | 22.76 | ||
| 400 | 22.27 | ||
| 800 | 21.89 | ||
| 1000 | 21.32 |