TL;DR
By controlling for total parameter count, researchers found that increasing transformer depth improves compositional generalization and language modeling performance, but these benefits saturate rapidly after just a few layers. Because model latency scales linearly with depth, the study suggests that many modern transformers could be made significantly shallower and faster without a meaningful loss in performance.
What Problem Does This Paper Address?
Language models (LMs) are remarkably good at mimicking human text, but they often stumble when required to perform compositional generalization—the ability to combine familiar words and syntactic structures in entirely new ways (e.g., understanding "the hedgehog ate the cake" even if it has only seen "hedgehog" as a subject and "cake" as an object separately).
While theoretical work suggests that deeper models should be more expressive and better at this kind of reasoning, empirical studies often suffer from a major confound: size. Usually, adding layers also adds parameters. This paper asks: if we keep the total parameter budget constant, does depth itself actually help a model generalize better?
Methods
To isolate the effect of depth, the authors constructed three families of models with fixed parameter counts: 41M, 134M, and 374M.
To make a model deeper without increasing its size, they had to make it "narrower." They achieved this by varying the feed-forward dimension ($d_{ff}$) while keeping the embedding size ($d_{model}$) and attention mechanism constant. This ensures that any performance changes are due to the number of sequential processing steps (depth) rather than the capacity of the attention mechanism or the total number of weights.
The models were pretrained as causal, decoder-only LMs on the C4 corpus and then fine-tuned on specific compositional generalization tasks.
Datasets
The researchers evaluated the models on four key benchmarks:
- COGS & COGS-vf: Semantic parsing tasks that require mapping natural language to logical forms, specifically testing lexical and structural generalization.
- GeoQuery: A classic dataset of natural language questions about US geography paired with SQL-style queries.
- English Passivization: A task testing whether models can correctly transform active sentences into passive ones using syntactically principled rules rather than shallow heuristics.
Key Insights and Ideas
- The Law of Diminishing Returns: While moving from 1 layer to 4-6 layers provides a massive boost in both language modeling and generalization, the benefits of adding even more layers (up to 32) are marginal.
- The $d_{ff}$ Bottleneck: Performance begins to degrade sharply when the feed-forward dimension ($d_{ff}$) becomes smaller than the model dimension ($d_{model}$). At this point, the projection into the feed-forward block becomes "lossy" (non-injective), effectively strangling the model's representational capacity.
- Lexical vs. Structural Generalization: Depth is a boon for lexical generalization (using a known word in a new position). However, even the deepest models struggled with structural generalization (handling deeper syntactic nesting than seen in training). This suggests that depth alone isn't the "silver bullet" for complex logical reasoning.
- Depth is an Independent Factor: The authors proved that the generalization benefit of depth isn't just a side effect of deeper models being better at basic language modeling. Even when comparing models with the same pretraining perplexity, the deeper ones still generalized better.
Key Results
The study yielded a clear "sweet spot" for transformer architecture:
-
Perplexity: Deeper models achieve lower perplexity, but the gap between a 12-layer and 32-layer model is tiny compared to the gap between 1 and 4 layers. Validation perplexity drops sharply with the first few layers but levels off quickly.
-
Generalization Accuracy: On tasks like COGS, accuracy jumps from ~15% (1 layer) to ~75% (6 layers) but then stays relatively flat even as depth triples. Generalization accuracy across different tasks shows that most of the benefit of depth is captured early on.
-
Efficiency: Since training and inference latency grow linearly with the number of layers, the authors recommend that for a fixed parameter budget, it is often more efficient to build a wider, shallower model. A 32-layer model might be 2x slower than a 4-layer model of the same size while offering negligible performance gains.
Limitations and Future Work
The authors acknowledge several areas for further exploration:
- Attention Heads: The study kept the number of attention heads constant; future work could investigate how head count interacts with depth.
- Universal Transformers: Weight-sharing (using the same parameters for every layer) could allow for extreme depth without the "narrowness" penalty of shrinking $d_{ff}$.
- In-Context Learning: The study focused on fine-tuning. As models scale, it remains to be seen if depth plays a different role in few-shot, in-context learning scenarios.
- Data Distribution: The impact of pretraining on different data types (like source code) might change how depth influences compositional logic.
Summary updated