Fully Nested Transformers

Avi Trost, Alexander Yun, John Cooper, Gabriel Orlanski, Frederic SalaAdaptFM @ ICML 2026

TL;DR

StairFormer is a novel Transformer architecture that mathematically nests smaller submodels within a larger "parent" model. Unlike previous methods, it ensures that a smaller model's output is an exact prefix of the larger model's output, enabling "cascading inference" where computations like the KV cache can be reused across different model scales in a single forward pass.

What Problem Does This Paper Address?

In the world of Large Language Models (LLMs), there is a constant tension between representation flexibility and computational efficiency.

Currently, we have two main approaches to adaptivity:

  1. Matryoshka Representation Learning (MRL): This produces embeddings where the first few dimensions (the "prefix") are useful on their own. However, to get that prefix, you still have to run the entire, expensive model.
  2. Elastic Architectures (e.g., MatFormer): These allow you to run smaller "sub-parts" of a model to save compute. The problem? The output of a small sub-part doesn't necessarily match the prefix of the full model's output.

The authors identify a fundamental architectural hurdle: standard Transformer components (dense linear layers, Softmax attention, and LayerNorm) are "nonlinear mixers." They allow information from the end of a vector to leak into the beginning, preventing true nesting. The paper asks: Can we design a Transformer where the small model is literally a subset of the big model, sharing the exact same mathematical path?

Methods

The authors introduce StairFormer, which achieves "full nestedness" through three key architectural modifications designed to be filtration-preserving (ensuring later coordinates never influence earlier ones):

  • Block Lower Triangular Weights: Instead of standard dense matrices, StairFormer uses a "staircase" structure. For a linear layer $W$, the first $k$ output blocks depend only on the first $k$ input blocks. This ensures that a smaller submodel's calculation is perfectly contained within the larger one.
  • PrefixRMSNorm: Standard RMSNorm calculates a scaling factor based on the entire vector. StairFormer introduces a variant where the normalization statistic for a specific block only depends on that block and its preceding blocks. This prevents "information leakage" from the high-capacity dimensions back into the low-capacity ones.
  • Head-Aligned Attention: The authors align attention head boundaries with the block boundaries of the submodels. Since attention heads are independent, a small model can simply activate a subset of heads. Crucially, because the projections ($Q, K, V$) are block-triangular, these heads only "see" the relevant prefix of the input.

Datasets

The researchers evaluated StairFormer using a 1.13B parameter model trained on:

  • Pretraining: The ClimbMix dataset (3.8B tokens), a high-quality mixture designed for base model training.
  • Supervised Fine-Tuning (SFT): A mixture of SmolTalk, MMLU auxiliary data, GSM8K (math), SimpleSpelling, and SpellingBee.
  • Evaluation: They used the CORE metric (from DataComp-LM) to measure base capabilities and GSM8K to measure reasoning performance after fine-tuning.

Key Insights and Ideas

  • The "Forward Pass" is Shared: The most significant "aha moment" is that running the largest version of StairFormer simultaneously computes the outputs for all smaller versions. You get the "small," "medium," and "large" answers for the price of one.
  • KV Cache Reuse: In standard cascading (where you might try a small model and then a big one), you usually have to restart the computation. In StairFormer, because the submodels are nested, the Key-Value (KV) cache generated by the small model is identical to the prefix of the big model's cache. You can "escalate" to a larger model mid-inference without recomputing the prompt.
  • Closing the Gap: While imposing strict block-triangular constraints usually hurts performance, the authors show that with proper scaling and modern optimizers (like Muon), the performance gap is surprisingly small.

Key Results

  • Competitive Performance: At the 1.13B parameter scale, StairFormer achieved a CORE score within 11.1% of a standard, unconstrained Transformer baseline.
  • Wider Dynamic Range: StairFormer maintains reasonable performance across a wider range of "budgets" (from Small to XL) compared to MatFormer, which tends to degrade more significantly when pushed to very small sub-architectures.
  • Efficient Cascading: In math-solving tasks (GSM8K), StairFormer demonstrated a superior accuracy-to-FLOPs tradeoff when using a "router" to decide when to escalate from a small submodel to a larger one, thanks to its ability to reuse prefill computations.

Limitations and Future Work

  • Hardware Optimization: Current AI hardware (GPUs) and software kernels are hyper-optimized for dense matrix multiplication. While block-triangular matrices are "GPU-friendly" in theory, they currently lack the specialized low-level kernels that make standard Transformers so fast.
  • Training Heuristics: The authors used a relatively simple weighted loss function to train all submodels simultaneously. They suggest that more sophisticated "curriculum" training or specialized optimizers could further close the performance gap with standard models.
  • Beyond Language: The authors note that this "fully nested" property could be highly valuable for embedding models used in vector databases, where users might want to dynamically trade off search speed (shorter vectors) for accuracy (longer vectors).

Summary updated

BibTeX
@inproceedings{trost2026fully,
  author = {Avi Trost and Alexander Yun and John Cooper and Gabriel Orlanski and Frederic Sala},
  title = {{Fully Nested Transformers}},
  booktitle = {AdaptFM @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=yv7Ie3UzlA},
}
Figure