Manuscript Offprint
arXiv:2610.31818Nested Sparsity for Scalable Pretraining and Continual Learning
Abstract
Mixture-of-experts (MoE) transformers, the standard backbone for modern large-scale deep learning, employ conditional computation: only a sparse subset of model weights is used in each forward pass. In MoE transformers, this sparsity arises in the MoE operator, which generalizes the multi-layer perceptron in the classical transformer. In this work, we explore an alternative mechanism for conditional computation that analogously generalizes the attention operator. The sparsity induced by this mechanism naturally nests (i.e., hierarchically composes) with the sparsity induced by the MoE operator. We show that a transformer employing this nested sparsity mechanism, which we call NESTOR, performs better than a conventional MoE transformer at equal compute and equal sparsity in language model pretraining. We also show that NESTOR is well-suited for continual pretraining: it can be adapted to longer contexts more effectively than conventional MoEs, as well as adapt more efficiently to new domains while forgetting less on old domains. Furthermore, we demonstrate that these benefits persist as model size, dataset size, and context length grow. Our results demonstrate the potential of alternative conditional computation mechanisms for deep neural network architectures. Code and checkpoints are available on GitHub.
1 Introduction
Conditional computation in LLMs. Large language models (LLMs) based on variants of the transformer architecture (Vaswani et al., 2017) improve predictably as their parameters, training data, and training compute grow (Kaplan et al., 2020; Brown et al., 2020; Hoffmann et al., 2022). A central goal of architecture design is to reach a lower loss with the same training compute. A particularly successful approach is conditional computation (Bengio et al., 2013; Shazeer et al., 2017), in which each input uses only a small (input-dependent) “active” subset of the model weights and correspondingly less compute for training or inference. In this setting, the number of total parameters grows much faster than the active parameters and compute used on each token.
Mixtures of experts (MoEs). In modern LLMs, this form of conditional computation is implemented almost exclusively via the MoE operator (Jacobs et al., 1991; Shazeer et al., 2017; Lepikhin et al., 2021; Fedus et al., 2022), which replaces the multi-layer perceptron (MLP) in each transformer layer by many expert MLPs and routes each token to a few of them. MoE transformers need substantially less compute than
Equal contribution; ordered alphabetically.

(a) The nested sparsity mechanism in NESTOR.
(b) The effective attention map computed by each column.
Figure 1: Nested sparsity in NESTOR. (a) The NESTOR architecture. In each block, the column router sends the token to of the columns. Each column has layers, each with its own attention and its own experts, of which a per-layer expert router selects . The token uses only the colored parameters. (b) The causal attention map computed by each column for tokens, shown in terms of the whole sequence: column computes attention only among the tokens routed to it.
dense transformers to reach the same loss (Fedus et al., 2022; Clark et al., 2022), and this advantage is retained at scale when the experts are configured appropriately (Ludziejewski et al., 2024; Abnar et al., 2025). As a result, many modern LLMs are MoE transformers (Jiang et al., 2024; DeepSeek-AI, 2024; Yang et al., 2025; Kimi Team, 2025a; OpenAI, 2025). In all of these models, however, this conditional computation is confined to the MLP weights: every token is processed by the same attention parameters in every layer. The attention operator accounts for a considerable fraction of the (active) parameters used by each token, and at long context lengths it accounts for most of the computation. One may then ask whether conditional computation can be applied to the attention operator as well, and how it should interact with the MoE.
Sparsity in the attention operator. Attention operators traditionally implement two forms of conditional computation. The more popular by far is the so-called “sparse attention” methods, which reduce the cost of attention by restricting the set of tokens to which each token attends, via fixed local patterns (Child et al., 2019; Beltagy et al., 2020), hashing or clustering (Kitaev et al., 2020; Roy et al., 2021), or a top-K selection for each query (Yuan et al., 2025; Lu et al., 2025; DeepSeek-AI, 2025). Relatedly, many LLMs interleave a few global attention layers with cheaper local or linear attention layers (Brown et al., 2020; Gemma Team, 2025; Kimi Team, 2025b). These methods sparsify the attention map, with the purpose of approximating full attention at a lower cost, while all tokens still share the same attention parameters. Other methods restrict the set of parameters used by each token, such as mixtures of attention heads (Zhang et al., 2022; Csordás et al., 2024), which route each token to a subset of the attention parameters, while every token still attends to the whole context. Other methods make both the map and the parameters sparse (Piekos et al., 2025), or pair mixtures of attention heads with an MoE (Shen et al., 2023; Csordás et al., 2024). In each of them, the attention is routed separately from the MLP and anew in every layer.
Continual pretraining. One of the circumstances in which such attention sparsity is most effective at reducing both training and inference costs is with long context documents. Pretrained models are routinely continually (pre-)trained in a long-context extension stage (Xiong et al., 2024; Fu et al., 2024; Grattafiori et al., 2024), and simultaneously further on new domains, such as code and mathematics (Gururangan et al., 2020; Rozière et al., 2023; Azerbaijan et al., 2024; Shao et al., 2024). Since neural networks trained on a new distribution tend to perform worse on the old one (McCloskey et al., 1989; French, 1999; Kirkpatrick et al., 2017), and LLMs are no exception (Luo et al., 2025), a central challenge is to maintain the performance on old data while capably handling the new data.
Our contributions. We propose NESTOR (Figure 1), a transformer architecture with nested sparsity: we generalize the attention operator in the same way that the MoE operator generalizes the MLP, and hierarchically composes the two resultant operators' sparsity. This yields a natural architecture that generalizes MoE transformers and has three coupled but distinct forms of sparsity: attention weight sparsity, attention map sparsity, and expert sparsity. We study it empirically and theoretically in language model pretraining and continual pretraining, showing that NESTOR architectures utilizing all sparsity axes in tandem outperform strong MoE and dense Transformer baselines at scales from 100M to 1B active parameters, at the limit of our compute resources. Namely, our contributions are:
• Compute-efficient pretraining (Section 3). We perform a scaling law study, finding that NESTOR is as compute-efficient as the MoE transformer, and as compute-efficient as a dense transformer; neither factor shrinks as the scale grows.
• Effective continual pretraining (Section 4). When adapted to various specialized domains, we show that NESTOR gains about as much as the MoE transformer on every new domain while forgetting less of the pretraining distribution, with fewer training FLOPs per token in the continual pretraining data. When extended from a context length of 4k to lengths up to 64k, NESTOR preserves its advantage over the MoE transformer when each model receives an equal number of continual pretraining tokens, and its advantage over the MoE transformer grows at longer context lengths when each model uses equal continual pretraining FLOPs.
• Theoretical analysis (Section 5). We give a theoretical account of these observations. Namely, we give a statistical model of data with hierarchical latent structure, in which a stylized version of NESTOR outperforms a stylized version of an MoE transformer. We show that this analytically tractable model reproduces the pretraining compute efficiency, its growth with the context length, and the reduced forgetting that we observe empirically.
Overall, our results suggest that conditional computation need not be confined to the MLP, and that adding and composing new sparsity mechanisms is a promising direction for architecture design. We postpone a detailed discussion of related work to Appendix A.
Conditional computation in MoE transformers. Each layer of a transformer (Vaswani et al., 2017) updates the token features using an attention operator, which mixes information across tokens, followed by an MLP, which acts on each token separately. The MoE transformer (Shazeer et al., 2017; Fedus et al., 2022; Dai et al., 2024) replaces the MLP by expert MLPs, of which each token uses only . A learned router assigns the token a vector of scores , and the MoE operator computes (omitting normalization for simplicity, here and after):
and the gating weights are the softmax of the routing scores for the selected experts (see Figure 1a). The number of parameters in the MoE operator grows with , while the computation spent on each token grows only with . This conditional computation is confined to the MLP.
Column-routed attention. We now apply the same principle to the attention operator. We replace the attention operator by C attention operators with separate parameters, which we call columns. A column router with scores selects for each token a set of columns, with gating weights , as in (1). Namely, letting be the set of tokens that were routed to the same column, the routed attention computes:
where denotes multi-head attention with the query computed from and the keys and values computed from the given context. Each column is a sequence-to-sequence operator applied to a subsequence chosen by the router. Routing therefore sparsifies both the parameters used by a token, i.e., of the attention operators, and the attention pattern (Figure 1b).
Nested sparsity. The two routing mechanisms compose hierarchically, as in a hierarchical mixture of experts (Jordan et al., 1994; Shazeer et al., 2017), except that the first level of routing also selects the attention operator and its context. We give each column its own experts and its own expert router . In each active column , this router selects the set of experts, with gating weights :
An expert is indexed by the pair (see Figure 1a). One layer stores C attention operators and CE experts, while a token uses and of them respectively. Each layer also has a small number of experts whose weights are tied across columns (cf. the shared experts of Dai et al. (2024)).
NESTOR as a meta-architecture. We group the layers of the network into blocks of M layers each, and compute the column routing once per block, from the input of the block, so that a token stays in the same columns for all M layers within the block (see Figure 1a left). Within a block, each column is a small MoE transformer of depth M whose attention operates on its own subsequence; the columns of a token share the input to each layer (Appendix B). Apart from the shared experts, the routers, and the residual connections, a token uses only the parameters of its columns. Setting in (2) and (3) recovers the regular MoE transformer exactly, and further setting recovers the dense transformer, so conventional transformers are special cases of NESTOR. Actually, at the expense of a slightly more inefficient implementation, we can use any sequence-to-sequence deep architecture for each column. Thus, one can view NESTOR as a meta-architecture for sparsely and hierarchically composing parallel deep networks, such that the presented version is a special case.
Relation to sparse attention. Sparse attention methods restrict the set of tokens to which each token attends (the attention pattern) to reduce the cost of long contexts. The pattern may be fixed in advance, as in sliding window attention and its variants (Child et al., 2019; Beltagy et al., 2020); computed by clustering the tokens (Roy et al., 2021); or selected for each query by a top-K rule over blocks or tokens (Yuan et al., 2025; Lu et al., 2025; DeepSeek-AI, 2025). In all of these methods every token is processed by the same attention parameters, so only the pattern is conditional, and the purpose is to approximate full attention at a lower cost. Mixtures of attention heads (Zhang et al., 2022; Csordás et al., 2024) route each token to a subset of the attention parameters, and each token still attends to the full context. Column-routed attention (2) is sparse in both senses: one routing decision determines both the parameters that the token uses and the tokens to which it attends. The closest mechanism is that of Piekos et al. (2025), in which each attention head selects a fixed number of tokens and attends only among them. There, the selection is made by the heads, separately in every layer, and is independent of the MLP; in NESTOR, the selection is made by the tokens, once per block, and the selected module contains the attention operators and the experts of all M layers. This makes the sparsity nested. The two approaches can be combined, because any sparse attention pattern (or, again, any backbone network) can be applied within a column. In this work each column uses full causal attention over its tokens; the baselines in Sections 3 and 4 also use full causal attention. We discuss the relation of NESTOR to such related work further and in detail in Appendix A.
Further design choices. We summarize the remaining empirical design choices here, with more details in Appendix C. Sparsity schedule. The number of active columns can differ between blocks. In all experiments we use C = 8 and increase with depth, from in the first block to in the last block, which computes full attention over the whole sequence. Hence, this architecture relates to the interleaved globalized and local (or linear) attention layers popular in modern LLMs (Brown et al., 2020; Gemma Team, 2025; Kimi Team, 2025b); here, one can interpret NESTOR as using progressively more globalized attention layers. Our experimental baselines use global attention at each layer, therefore using more attention compute than NESTOR. Residual connections. Equations (2) and (3) show plain residual connections. In NESTOR, each active column accumulates its outputs in its own residual stream. The streams are combined, within and across blocks, by an attention residual (Kimi Team, 2026): the input of each layer is a learned softmax-weighted mixture of the token embedding, the outputs of the earlier blocks, and the mean of the streams of the current block. The input of the output head also includes the deviation of each stream from the mean. We ablate this choice in Appendix C.3; note that our baselines also use and benefit from attention residuals. Routing. Both routers use top-K selection by each token, and are balanced without an auxiliary loss by a bias that is updated in a backpropagation-free manner (Wang et al., 2024; DeepSeek-AI, 2024). We ablate our routing and sparsity setup in Appendix C.3. We fully describe the final architecture in Appendix B.
Aspirational connection to the cerebral cortex. To some extent, one may view NESTOR as an architecture that tries to emulate the neural architecture of the cerebral cortex of a brain (Hawkins, 2021): the blocks correspond to different lobes or functional regions in the cortex, from low-level to high-level, and the many columns in each block emulate the cortical columns within each region.
3 Compute-Efficient Pretraining with NESTOR
In this section we show that NESTOR is more compute-efficient than strong iso-sparsity MoE transformer and dense transformer baselines in language model pretraining, and that the advantage does not shrink as the scale grows to the limits of our compute. Following prior scaling law studies of MoE transformers (see Appendix A), we compare architectures at the same sparsity, fit a scaling law to each, and report the projected compute that each baseline needs to reach the held-out loss of NESTOR.
Setup. We compare three architectures at four scales, which we call 100M, 200M, 500M, and 1B after the active parameter count. The dense transformer has width , depth , 16 heads, and MLP width 4D. The MoE transformer has the same shape, with each MLP replaced by experts of which are active, so that its active MLP width is also 4D. NESTOR uses columns, increasing with depth from in the first block to (all columns active) in the final block. Both baselines use full causal attention with the attention residual (Kimi Team, 2026). At each scale, NESTOR uses no more training FLOPs than either baseline, and stores approximately the same number of parameters as the MoE transformer. We consider further baselines in Appendix C.3. All models are trained on DCLM-baseline (Li et al., 2024) at context length for 50 tokens per active parameter (beyond the roughly 20 that are compute optimal for dense transformers; Hoffmann et al., 2022). The parameterization and optimizer settings used in these experiments are specified in Appendix D. We report the cross-entropy on held-out DCLM-baseline tokens at the end of training.
NESTOR is more compute-efficient at every scale. NESTOR achieves lower held-out loss than both baselines at all four model scales, as shown in Figure 2; the losses, parameter counts, and training compute at each scale are in Table 3 of Appendix C.2. To quantify the compute savings at equal loss, we fit each architecture's loss-compute curve with (Kaplan et al., 2020; Hoffmann et al., 2022). For each measured NESTOR result, we trace a horizontal line to each baseline's fitted curve. The intersection gives an estimate of the baseline compute needed to reach the same loss. We report this estimate, normalized by the training compute of NESTOR, as the horizontal ticks in Figure 2 and the last column of Table 3. At
Our FLOP count includes attention FLOPs (Appendix C.1). Under the common approximation that counts only linear layers' FLOPs, NESTOR uses 4–8% more FLOPs than the baselines at each scale, at length S = 4096.

Training compute (PFLOP/s-days)
Figure 2: Held-out loss scaling laws for NESTOR, MoE, and dense models. Each law is fitted as , where F is the training FLOPs. NESTOR reaches the lowest hold-out loss at every scale. The horizontal ticks mark the projected compute that the MoE and dense baselines need to match NESTOR.
the largest scale, matching the loss of NESTOR is estimated to need as much compute for the MoE transformer and for the dense transformer. The fitted exponents of NESTOR and the MoE transformer agree to three digits, and NESTOR has a smaller estimated coefficient and irreducible loss.
4 NESTOR Enables Efficient Continual Learning
A pretrained model is often customized via continual training to learn new capabilities while retaining old ones. Concretely, pretrained models are often continually pre-trained on new domains (Gururangan et al., 2020; Rozière et al., 2023; Azerbaijan et al., 2024; Shao et al., 2024) and longer contexts (Xiong et al., 2024; Fu et al., 2024; Grattafiori et al., 2024); in this setting, it is important to retain its original capabilities on old domains and shorter contexts, which continual training tends to erode (French, 1999; Luo et al., 2025). In this section we show that NESTOR is well suited to both settings: it adapts to new domains as well as the MoE transformer while forgetting less (Section 4.1), and it extends to long contexts more efficiently and effectively (Section 4.2).
4.1 Domain Adaptation
Setup. We compare the 500M NESTOR, 500M MoE transformer, and 1B dense transformer, selected for their similar pretraining losses. All models first undergo context extension to 32k using equal token budgets on DCLM. Details of the starting checkpoints and their initial performance are in Appendix C.4. Each model is then trained separately on 0.5B tokens from each of four target domains, without replay of pretraining data (a common way to reduce forgetting; Ibrahim et al., 2024): books (PG-19; Rae et al., 2020), mathematics (OpenWebMath; Paster et al., 2024), code (AlgebraicStack; Azerbaijan et al., 2024), and German (FineWeb2; Penedo et al., 2025). We freeze the router parameters of both sparse models (cf. Li et al., 2025) and update all remaining trainable parameters; the dense model is fully fine-tuned. We measure adaptation by the reduction in held-out loss on the target corpus and forgetting by the increase in held-out loss on the pretraining corpus, both relative to the model before adaptation. We also repeat the experiment with 25% of the training tokens drawn from the pretraining corpus, keeping the total budget fixed at 0.5B tokens; details and results are in Appendix C.4. Table 6 reports the held-out losses before and after adaptation.
NESTOR adapts as well as the baselines with less forgetting. All three models achieve similar adaptation gains: averaged across the four target domains, the gains of NESTOR and the 1B dense transformer are both within 1% of the 500M MoE transformer's (Figure 3). The models differ more in how much they forget. NESTOR forgets 3% less than the MoE on average, whereas the dense model forgets 21%. Thus, NESTOR

Figure 3: Domain adaptation and forgetting relative to the MoE transformer. Top: reduction in held-out loss on the target corpus. Bottom: increase in held-out loss on the pretraining corpus. Both are measured relative to each model before adaptation and shown as a percentage of the MoE transformer's value.
has a modest retention advantage over the MoE, and both sparse models forget substantially less than the dense model. Replaying 25% pretraining data reduces forgetting by about 70% across all three models at a cost of about 6% of the adaptation gain and preserves this ordering: NESTOR forgets 5% less than the MoE on average and the dense model 13% more, while the two sparse models' gains remain within 2% of each other (Figure 3, faded marks).
4.2 Long Context Extension
Setup. Starting from the pretrained models of Section 3, which have context length 4k, we extend each model to a target context length by continued pretraining on long documents (Xiong et al., 2024; Fu et al., 2024; Gao et al., 2025) of at least S tokens from DCLM-baseline. Each target length is a separate run from the 4k checkpoint. The baselines are trained on 0.5B tokens. Since the FLOPs per token of NESTOR decrease relative to the baselines as S grows (Figure 10), we train NESTOR in two settings: at equal tokens (0.5B), and at equal FLOPs, where the saved compute is spent on more tokens of either repeated or new documents. We report the held-out loss at length S, relative to the MoE transformer of the same scale. Details of the data, the schedules, and the losses behind Figure 4 are provided in Appendix C.5.
The advantage of NESTOR grows with context length at equal compute. At equal tokens, NESTOR achieves gains from context extension comparable to those of the MoE transformer, broadly preserving its advantage before extension (Figure 4). As the context length increases, its lower FLOPs per token allow more training within the same compute budget (Figure 10). Spending these savings on repeated data produces a downward trend in held-out loss relative to MoE, even without additional training data. Spending them on fresh data, as one might expect, yields the largest improvements. In Appendix E we quantify the saving: for equal shapes and balanced routing, at equal FLOPs NESTOR trains on times as many tokens as the MoE, where is the mean fraction of active columns and the context length at which the MoE transformer's attention FLOPs equal its other FLOPs, and increases with towards .
5 Theoretical Analysis
In this section we compare stylized versions of NESTOR and of the MoE transformer on a statistical model with hierarchical latent structure. In this analytically tractable model, we reproduce the empirical pre-training compute efficiency and continual training properties of the two architectures. We state the results informally here, and give the formal statements and the proofs in Appendix F.

Nestor equal FLOPs, fresh equal FLOPs, repeated equal tokens
baselines dense transformer MoE (reference, ) open: pretrained, at 4k
Figure 4: Long context extension by continued pretraining. We show the held-out loss at each context length from 4k to 64k at all scales, relative to the MoE transformer of the same scale. Top: the dense transformer. Bottom: NESTOR at equal FLOPs with new documents, at equal FLOPs with the documents of the equal-token run repeated over the run, and at equal tokens. The open markers at 4k are the pretrained checkpoints.
Nested structure in the data. We assume that the next token is predicted in two stages. A coarse latent variable determines which tokens of the context are relevant, how they are weighted, and which statistic of them is computed. A fine latent variable determines how this statistic is used. For example, in a corpus of code and mathematics, c may be the kind of text, the relevant tokens may be the declarations in scope or the hypotheses in effect, and e may determine whether the next token of code is a variable or an operator. In NESTOR, c corresponds to the output of the column router, the statistic to the output of the attention operator of column c, with its own pattern and value map, and e to the output of the expert router of the column. In the MoE transformer, one shared pattern weights the tokens and one shared value map computes the statistic. We study the simplest case: one layer with one head, linear attention and maps, and the squared loss (Figure 5a).
Model 1: Let and . For each and , fix an invertible pattern and matrices and of rank . Each sample is generated in four steps.
-
The labels are drawn with for all .
-
The context consists of tokens for and the query . The labels are uniform on , and the contents are drawn from a distribution with a density and finite moments, all independently of each other.
-
The summary is over the relevant tokens .
-
The target is , with independent noise of mean zero and covariance .
We observe T independent samples .
The summary is the output of one head of linear attention at the query, over the tokens with the label on average. The target stands in for the next token, for example the update that the layer adds to the residual stream. The regression function is , where
The last property is the nested structure: for a fixed coarse label , the maps share the pattern and the row space of , while both of these may differ from one coarse label to another.
The two predictors and their training. Both predictors take the labels as input along with the context, so no router is learned. The nested predictor is one layer of NESTOR with : the attention of column sums
(a) One sample
context; tokens with the label c shaded

coarse label c:
fine label e:
which r directions
what to compute
of the context to read
from them
(b) Flat predictor

patterns:
CE row spaces:
CE maps:
C patterns:
(c) Nested predictor

C row spaces:
CE maps:
Figure 5: The linear model and the two predictors, for coarse labels (blue, green) and fine labels. (a) One sample: the coarse label determines the relevant tokens, the pattern , and the row space of ; the fine label determines the map . (b) The flat predictor (MoE transformer): the shared attention scores every token, and each expert has its own row space, fit from its own samples. (c) The nested predictor (NESTOR): the attention of a column scores only the tokens with its label, and its row space is fit once from the samples of all of its experts. The free parameters are counted below each panel.
over the tokens with the label , with its own pattern and a value map of width , and expert applies a linear map . The flat predictor is one layer of an MoE transformer: a shared attention operator sums over all tokens, with a value map of full width , as in our baseline, and each expert is a linear MLP with hidden units. Since a score bilinear in the raw tokens cannot depend on both labels (Theorem 1a), the shared score is bilinear in the product features as in Remark 8, with one block per pair of labels. The two predictors are
We fit each predictor by least squares over its function class M, and measure its excess risk:
Theorem 1 (Informal version of Theorem 4): Let .
(a) Both predictors can represent , unlike a flat predictor with a bilinear score on raw tokens.
(b) As , the excess risk of either predictor is asymptotically , where is the number of directions in weight space that change the prediction. For and ,
(c) If a sample costs FLOPs plus FLOPs per scored token, the flat predictor requires
times as many FLOPs for the same expected excess risk (in the large-data limit ), a factor that grows in S from to .
The count has three parts: the patterns, the row spaces, i.e., the -dimensional subspaces of on which the maps depend, and the maps from the row spaces to the output (Figure 5b,c). Both predictors have CE maps to fit. The flat predictor also has one row space per expert, fit from the samples of that expert, and
pattern blocks, of which the blocks with are zero at the target and have to be fit as zero from data. The nested predictor has one row space and one pattern per column, fit from the samples of all experts of the column, and its routing fixes the other blocks to zero. The ratio is near when the patterns dominate the parameter count and near 2 when the experts do. With the routing, the nested predictor scores only of the context, so part (c) is the multiplier of Section 4.2 with , which grows with as in Figure 4. As in Table 4, both parts of nesting are needed: with the predictors coincide, and with column-routed attention and experts shared across columns, the column space of lies in that of for every , so this predictor cannot represent a target where the column space of changes with .
Continual training and forgetting. Each predictor starts from weights that represent and is trained by gradient flow on the population squared loss of a new domain . Every sample of has the coarse label , e.g., a new corpus of code, and new maps , and otherwise follows Model 1. The forgetting on the old labels at time is the increase of their risk since time 0.
Proposition 2 (Informal version of Proposition 5): In the nested predictor, the columns never change, so there is no forgetting on any other coarse label. In the flat predictor, for , and the forgetting on is
where and whenever . For orthonormal rows, the coefficient lies between multiples of and , where are principal angles between the row spaces of and .
In the flat predictor, the shared value map is the only source of forgetting on other labels, and the forgetting grows with the overlap between the row spaces of and . This is consistent with Figure 3. Both results depend on how the relevant tokens, patterns, and row spaces vary across coarse labels. Nesting improves sample and compute efficiency when these differ between labels, and, with all weights trained, it removes forgetting through the shared value map when the row spaces overlap, which is the generic case.
6 Conclusion
In this work, we introduced nested sparsity, a conditional computation mechanism in which a router sends each token to several columns, and each column contains its own attention operators and its own experts. The resulting architecture, NESTOR, generalizes both the MoE transformer and the dense transformer. In language model pretraining at scales from 100M to 1B active parameters, the MoE transformer needs 1.13–1.29× the compute of NESTOR to reach the same loss at an equal number of stored parameters, and this factor shows no downward trend as the scale grows (Section 3). In continual pretraining, NESTOR adapts to new domains as well as the MoE transformer while forgetting less (Section 4.1), and its advantage in long context extension grows with the context length at equal FLOPs (Section 4.2). Our theoretical analysis (Section 5) provides conceptual reasoning for why NESTOR can obtain such empirical results in the context of highly structured data.
Our study has several limitations, which suggest directions for future work. First, our largest model has 1B active parameters, and we evaluate models by their held-out loss; an important next step is to test whether the compute multiplier persists at larger scales and carries over to downstream tasks, such as standard benchmarks after post-training. Second, NESTOR is in some sense a meta-architecture, and we studied only the case in which each column uses full causal attention. Columns with sparse or linear attention would compound the savings at long contexts. More broadly, columns comprised of subnetworks with interesting properties could preserve them through the meta-architecture.
Here, the map V is in some sense redundant: freezing it would remove this forgetting without changing the function class. Proposition 2 compares the predictors with attention and expert weights trained, as in Section 4.1.
References
Abnar, Samira, Harshay Shah, Dan Busbridge, et al. (2025). "Parameters vs FLOPs: Scaling Laws for Optimal Sparsity for Mixture-of-Experts Language Models". In: International Conference on Machine Learning.
Ainslie, Joshua, Tao Lei, Michiel de Jong, et al. (2023). "CoLT5: Faster Long-Range Transformers with Conditional Computation". In: Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing.
Aljundi, Rahaf, Punarjay Chakravarty, and Tinne Tuytelaars (2017). "Expert Gate: Lifelong Learning with a Network of Experts". In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition.
Azerbaiyev, Zhangir, Hailey Schoelkopf, Keiran Paster, et al. (2024). "Llemma: An Open Language Model for Mathematics". In: International Conference on Learning Representations.
Beltagy, Iz, Matthew E. Peters, and Arman Cohan (2020). "Longformer: The Long-Document Transformer". In: arXiv preprint arXiv:2004.05150.
Bengio, Yoshua, Nicholas Léonard, and Aaron Courville (2013). "Estimating or Propagating Gradients Through Stochastic Neurons for Conditional Computation". In: arXiv preprint arXiv:1308.3432.
Brown, Tom B., Benjamin Mann, Nick Ryder, et al. (2020). "Language Models are Few-Shot Learners". In: Advances in Neural Information Processing Systems.
Chen, Wuyang, Yanqi Zhou, Nan Du, et al. (2023). "Lifelong Language Pretraining with Distribution-Specialized Experts". In: International Conference on Machine Learning.
Child, Rewon, Scott Gray, Alec Radford, et al. (2019). "Generating Long Sequences with Sparse Transformers". In: arXiv preprint arXiv:1904.10509.
Clark, Aidan, Diego de Las Casas, Aurelia Guy, et al. (2022). "Unified Scaling Laws for Routed Language Models". In: International Conference on Machine Learning.
Cohere (2025). "Command A: An Enterprise-Ready Large Language Model". In: arXiv preprint arXiv:2504.00698.
Csordás, Róbert, Piotr Piekos, Kazuki Irie, et al. (2024). "SwitchHead: Accelerating Transformers with Mixture-of-Experts Attention". In: Advances in Neural Information Processing Systems.
Dai, Damai, Chengqi Deng, Chenggang Zhao, et al. (2024). "DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models". In: Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics.
DeepSeek-AI (2024). "DeepSeek-V3 Technical Report". In: arXiv preprint arXiv:2412.19437.
— (2025). “DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models”. In: arXiv preprint arXiv:2512.02556.
Doan, Thang, Mehdi Abbana Bennani, Bogdan Mazoure, et al. (2021). "A theoretical analysis of catastrophic forgetting through the NTK overlap matrix". In: International Conference on Artificial Intelligence and Statistics, pp. 1072–1080.
Drton, Mathias (2009). "Likelihood ratio tests and singularities". In: The Annals of Statistics 37.2, pp. 979–1012.
Fedus, William, Barret Zoph, and Noam Shazeer (2022). "Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity". In: Journal of Machine Learning Research 23.120, pp. 1–39.
Fernando, Chrisantha, Dylan Banarse, Charles Blundell, et al. (2017). "PathNet: Evolution Channels Gradient Descent in Super Neural Networks". In: arXiv preprint arXiv:1701.08734.
French, Robert M. (1991). "Using Semi-Distributed Representations to Overcome Catastrophic Forgetting in Connectionist Networks". In: Proceedings of the 13th Annual Conference of the Cognitive Science Society, pp. 173–178.
— (1999). "Catastrophic Forgetting in Connectionist Networks". In: Trends in Cognitive Sciences 3.4, pp. 128–135.
Fu, Yao, Rameswar Panda, Xinyao Niu, et al. (2024). "Data Engineering for Scaling Language Models to 128K Context". In: International Conference on Machine Learning.
Gao, Tianyu, Alexander Wettig, Howard Yen, et al. (2025). "How to Train Long-Context Language Models (Effectively)". In: Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics.
Gemma Team (2024). "Gemma 2: Improving Open Language Models at a Practical Size". In: arXiv preprint arXiv:2408.00118.
— (2025). "Gemma 3 Technical Report". In: arXiv preprint arXiv:2503.19786.
Geyer, Charles J. (1994). "On the asymptotics of constrained M-estimation". In: The Annals of Statistics 22.4, pp. 1993–2010.
Grattafiori, Aaron, Abhimanyu Dubey, Abhinav Jauhri, et al. (2024). "The Llama 3 Herd of Models". In: arXiv preprint arXiv:2407.21783.
Gururangan, Suchin, Mike Lewis, Ari Holtzman, et al. (2022). "DEMix Layers: Disentangling Domains for Modular Language Modeling". In: Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies.
Gururangan, Suchin, Ana Marasović, Swabha Swayamdipta, et al. (2020). "Don't Stop Pretraining: Adapt Language Models to Domains and Tasks". In: Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics.
Hawkins, Jeff (2021). A Thousand Brains: A new theory of intelligence. Basic Books.
Hoffmann, Jordan, Sebastian Borgeaud, Arthur Mensch, et al. (2022). "An Empirical Analysis of Compute-Optimal Large Language Model Training". In: Advances in Neural Information Processing Systems.
Ibrahim, Adam, Benjamin Thérien, Kshitij Gupta, et al. (2024). "Simple and Scalable Strategies to Continually Pre-train Large Language Models". In: Transactions on Machine Learning Research.
Jacobs, Robert A., Michael I. Jordan, Steven J. Nowlan, et al. (1991). "Adaptive Mixtures of Local Experts". In: Neural Computation 3.1, pp. 79–87.
Jiang, Albert Q, Alexandre Sablayrolles, Antoine Roux, et al. (2024). "Mixtral of Experts". In: arXiv preprint arXiv:2401.04088.
Jin, Peng, Bo Zhu, Li Yuan, et al. (2025). "MoH: Multi-Head Attention as Mixture-of-Head Attention". In: International Conference on Machine Learning.
Jordan, Keller, Yuchen Jin, Vlado Boza, et al. (2024). Muon: An Optimizer for Hidden Layers in Neural Networks. https://kellerjordan.github.io/posts/muon/.
Jordan, Michael I. and Robert A. Jacobs (1994). "Hierarchical Mixtures of Experts and the EM Algorithm". In: Neural Computation 6.2, pp. 181–214.
Kaplan, Jared, Sam McCandlish, Tom Henighan, et al. (2020). "Scaling Laws for Neural Language Models". In: arXiv preprint arXiv:2001.08361.
Kimi Team (2025a). "Kimi K2: Open Agentic Intelligence". In: arXiv preprint arXiv:2507.20534.
— (2025b). "Kimi Linear: An Expressive, Efficient Attention Architecture". In: arXiv preprint arXiv:2510.26692.
— (2026). "Attention Residuals". In: arXiv preprint arXiv:2603.15031.
Kirkpatrick, James, Razvan Pascanu, Neil Rabinowitz, et al. (2017). "Overcoming Catastrophic Forgetting in Neural Networks". In: Proceedings of the National Academy of Sciences 114.13, pp. 3521–3526.
Kitaev, Nikita, Łukasz Kaiser, and Anselm Levskaya (2020). "Reformer: The Efficient Transformer". In: International Conference on Learning Representations.
Lepikhin, Dmitry, HyoukJoong Lee, Yuanzhong Xu, et al. (2021). "GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding". In: International Conference on Learning Representations.
Li, Hongbo, Sen Lin, Lingjie Duan, et al. (2025). "Theory on Mixture-of-Experts in Continual Learning". In: International Conference on Learning Representations.
Li, Jeffrey, Alex Fang, Georgios Smyrnis, et al. (2024). "DataComp-LM: In search of the next generation of training sets for language models". In: Advances in Neural Information Processing Systems (Datasets and Benchmarks Track).
Lieber, Opher, Barak Lenz, Hofit Bata, et al. (2024). "Jamba: A Hybrid Transformer-Mamba Language Model". In: arXiv preprint arXiv:2403.19887.
Lin, Jessy, Luke Zettlemoyer, Gargi Ghosh, et al. (2025). "Continual Learning via Sparse Memory Finetuning". In: arXiv preprint arXiv:2510.15103.
Loshchilov, Ilya and Frank Hutter (2019). "Decoupled Weight Decay Regularization". In: International Conference on Learning Representations.
Lu, Enzhe, Zhejun Jiang, Jingyuan Liu, et al. (2025). "MoBA: Mixture of Block Attention for Long-Context LLMs". In: arXiv preprint arXiv:2502.13189.
Ludziejewski, Jan, Jakub Krajewski, Kamil Adamczewski, et al. (2024). "Scaling Laws for Fine-Grained Mixture of Experts". In: International Conference on Machine Learning.
Ludziejewski, Jan, Maciej Pióro, Jakub Krajewski, et al. (2025). "Joint MoE Scaling Laws: Mixture of Experts Can Be Memory Efficient". In: International Conference on Machine Learning.
Luo, Yun, Zhen Yang, Fandong Meng, et al. (2025). "An Empirical Study of Catastrophic Forgetting in Large Language Models During Continual Fine-tuning". In: IEEE Transactions on Audio, Speech and Language Processing 33. arXiv:2308.08747, pp. 3776–3786.
Mallya, Arun and Svetlana Lazebnik (2018). "PackNet: Adding Multiple Tasks to a Single Network by Iterative Pruning". In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition.
McCloskey, Michael and Neal J. Cohen (1989). "Catastrophic Interference in Connectionist Networks: The Sequential Learning Problem". In: Psychology of Learning and Motivation. Vol. 24. Academic Press, pp. 109–165.
MiniMax (2025). "MiniMax-01: Scaling Foundation Models with Lightning Attention". In: arXiv preprint arXiv:2501.08313.
OpenAI (2025). "gpt-oss-120b & gpt-oss-20b Model Card". In: arXiv preprint arXiv:2508.10925.
Paster, Keiran, Marco Dos Santos, Zhangir Azerbaijan, et al. (2024). "OpenWebMath: An Open Dataset of High-Quality Mathematical Web Text". In: International Conference on Learning Representations.
Penedo, Guilherme, Hynek Kydliček, Vinko Sabolčec, et al. (2025). "FineWeb2: One Pipeline to Scale Them All – Adapting Pre-Training Data Processing to Every Language". In: Conference on Language Modeling.
Piekos, Piotr, Róbert Csordás, and Jürgen Schmidhuber (2025). "Mixture of Sparse Attention: Content-Based Learnable Sparse Attention via Expert-Choice Routing". In: arXiv preprint arXiv:2505.00315.
Rae, Jack W., Anna Potapenko, Siddhant M. Jayakumar, et al. (2020). "Compressive Transformers for Long-Range Sequence Modelling". In: International Conference on Learning Representations.
Raposo, David, Sam Ritter, Blake Richards, et al. (2024). "Mixture-of-Depths: Dynamically Allocating Compute in Transformer-Based Language Models". In: arXiv preprint arXiv:2404.02258.
Roy, Aurko, Mohammad Saffar, Ashish Vaswani, et al. (2021). "Efficient Content-Based Sparse Attention with Routing Transformers". In: Transactions of the Association for Computational Linguistics 9, pp. 53–68.
Rozière, Baptiste, Jonas Gehring, Fabian Gloeckle, et al. (2023). "Code Llama: Open Foundation Models for Code". In: arXiv preprint arXiv:2308.12950.
Rusu, Andrei A., Neil C. Rabinowitz, Guillaume Desjardins, et al. (2016). "Progressive Neural Networks". In: arXiv preprint arXiv:1606.04671.
Shao, Zhihong, Peiyi Wang, Qihao Zhu, et al. (2024). "DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models". In: arXiv preprint arXiv:2402.03300.
Shazeer, Noam (2020). "GLU variants improve transformer". In: arXiv preprint arXiv:2002.05202.
Shazeer, Noam, Azalia Mirhoseini, Krzysztof Maziarz, et al. (2017). "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer". In: International Conference on Learning Representations.
Shen, Yikang, Zheyu Zhang, Tianyou Cao, et al. (2023). "ModuleFormer: Modularity Emerges from Mixture-of-Experts". In: arXiv preprint arXiv:2306.04640.
Su, Jianlin, Murtadha Ahmed, Yu Lu, et al. (2024). "RoFormer: Enhanced Transformer with Rotary Position Embedding". In: Neurocomputing 568, p. 127063.
Sukhbaatar, Sainbayar, Olga Golovneva, Vasu Sharma, et al. (2024). "Branch-Train-MiX: Mixing Expert LLMs into a Mixture-of-Experts LLM". In: Conference on Language Modeling.
Thérien, Benjamin, Charles-Étienne Joseph, Zain Sarwar, et al. (2025). "Continual Pre-training of MoEs: How Robust is Your Router?" In: Transactions on Machine Learning Research.
Vaart, Aad W. van der (1998). Asymptotic Statistics. Cambridge Series in Statistical and Probabilistic Mathematics. Cambridge, UK: Cambridge University Press.
Vaswani, Ashish, Noam Shazeer, Niki Parmar, et al. (2017). "Attention is All You Need". In: Advances in Neural Information Processing Systems.
Wang, Lean, Huazuo Gao, Chenggang Zhao, et al. (2024). "Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts". In: arXiv preprint arXiv:2408.15664.
Wortsman, Mitchell, Vivek Ramanujan, Rosanne Liu, et al. (2020). "Supermasks in Superposition". In: Advances in Neural Information Processing Systems.
Xiong, Wenhan, Jingyu Liu, Igor Molybog, et al. (2024). "Effective Long-Context Scaling of Foundation Models". In: Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies.
Yang, An, Anfeng Li, Baosong Yang, et al. (2025). "Qwen3 Technical Report". In: arXiv preprint arXiv:2505.09388.
Yang, Greg, Edward J. Hu, Igor Babuschkin, et al. (2021). "Tensor Programs V: Tuning Large Neural Networks via Zero-Shot Hyperparameter Transfer". In: Advances in Neural Information Processing Systems. arXiv:2203.03466.
Yang, Greg, James B Simon, and Jeremy Bernstein (2023). "A Spectral Condition for Feature Learning". In: arXiv preprint arXiv:2310.17813.
Yuan, Jingyang, Huazuo Gao, Damai Dai, et al. (2025). "Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention". In: Annual Meeting of the Association for Computational Linguistics.
Zhang, Xiaofeng, Yikang Shen, Zeyu Huang, et al. (2022). "Mixture of Attention Heads: Selecting Attention Heads Per Token". In: Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pp. 4150–4162.
Zhou, Yanqi, Tao Lei, Hanxiao Liu, et al. (2022). "Mixture-of-Experts with Expert Choice Routing". In: Advances in Neural Information Processing Systems.
Appendix
A Related Work
Scaling laws and sparsity. The loss of a language model is well described by a power law in the number of parameters, the number of training tokens, and the training compute (Kaplan et al., 2020), which determines the compute-optimal allocation between model size and data (Hoffmann et al., 2022). Several works extend these laws to MoE transformers. Clark et al. (2022) fit a law that is jointly a function of the model size and the number of experts. Ludziejewski et al. (2024) add the granularity of the experts as a variable, and find that MoE transformers with appropriately sized experts outperform dense transformers at every compute budget. Abnar et al. (2025) study the sparsity level, i.e., the fraction of inactive parameters, and find that the optimal sparsity increases with the model size, and Ludziejewski et al. (2025) fit a joint law for dense and MoE models under memory constraints. In all of these works only the MLP is sparse. Since our architectures are sparse in more than one component, we compare them at the same sparsity to avoid ambiguity in the scaling laws: we fit a scaling law for each architecture and report the projected compute efficiency compared to a strong MoE transformer baseline to reach the same held-out loss.
Conditional computation and mixtures of experts. Mixtures of experts were introduced by Jacobs et al. (1991), and Jordan et al. (1994) extended them to a tree of gating networks. Shazeer et al. (2017) used them as a sparsely gated layer in deep networks, following the proposal of conditional computation (Bengio et al., 2013), and later work used them in the transformer and changed the routing (Lepikhin et al., 2021; Fedus et al., 2022; Zhou et al., 2022). Recent MoE transformers use many small experts, some of which are shared by all tokens (Dai et al., 2024), and balance the load of the experts with a bias in the router (Wang et al., 2024; DeepSeek-AI, 2024); we do the same. Nested sparsity is closest to the hierarchical mixture of experts, since in NESTOR the experts of a token are selected from the experts of its columns, which are in turn selected by the column router. The difference is that in a hierarchical mixture of experts both levels of routing select MLPs, whereas in NESTOR the first level selects an attention operator together with its context, and this selection is held fixed over several layers. Other works route tokens around whole layers: in Raposo et al. (2024) only the top-K tokens of each layer go through its attention operator and MLP, and Ainslie et al. (2023) apply a heavy attention operator and MLP only to the routed tokens and a light one to all tokens. In these methods there is a single routed module per layer, and a token that is not selected does not go through it; in NESTOR, every layer applies to every token, with modules that depend on the token.
Sparse attention and mixtures of attention heads. A large body of work reduces the quadratic cost of attention by making the attention map sparse. The pattern can be fixed in advance, such as local or strided windows (Child et al., 2019; Beltagy et al., 2020); it can depend on the content through hashing or clustering of the queries and keys (Kitaev et al., 2020; Roy et al., 2021); or it can be selected for each query by a top-K rule over blocks or tokens (Yuan et al., 2025; Lu et al., 2025; DeepSeek-AI, 2025). A complementary line of work makes the attention parameters sparse, by routing each token to a subset of the attention heads or of their projections (Zhang et al., 2022; Csordás et al., 2024; Jin et al., 2025), possibly together with an MoE operator for the MLP (Shen et al., 2023). The method of Piekos et al. (2025), in which a fixed number of tokens is selected for each head and attention is computed only among them, is the closest to column-routed attention. We compare NESTOR with these methods in detail in Section 2. In column-routed attention, both the pattern and the parameters are sparse, and both are given by one routing decision, which is computed for each token, held fixed over a block of layers, and shared with the experts. Also, in our experiments NESTOR has lower loss than baselines with full attention, which sparse attention methods approximate.
Interleaved attention. In many LLMs, the cost of attention is reduced by using full attention in only some of the layers. GPT-3 has dense and locally banded sparse attention layers in alternation (Brown et al., 2020), and more recent models interleave sliding window and global attention layers at ratios from one to one up to five to one (Gemma Team, 2024; Gemma Team, 2025; Cohere, 2025; OpenAI, 2025). In hybrid models, the local layers are state space or linear attention layers (Lieber et al., 2024; MiniMax, 2025; Kimi Team, 2025b). NESTOR uses the same principle with a different local operator: the number of active columns increases with depth, so attention in the early blocks is computed within routed subsequences, and attention in the last block is full attention over the whole sequence (Section 2). Unlike a sliding window, the context of a column depends on the input and can contain tokens from anywhere in the sequence.
Continual pretraining and forgetting. Continued pretraining on text from a target domain improves performance in that domain (Gururangan et al., 2020), and it is the standard way to obtain specialized models for code and mathematics (Rozière et al., 2023; Azerbaijan et al., 2024; Shao et al., 2024). Its main difficulty is catastrophic forgetting (McCloskey et al., 1989; French, 1999; Kirkpatrick et al., 2017; Luo et al., 2025), which is usually reduced by replaying pretraining data (Ibrahim et al., 2024). French (1991) observed that forgetting comes from the overlap of distributed representations, and that sparser representations reduce it. For this reason, many continual learning methods use separate parameters for each task, obtained by adding, freezing, or masking parts of the network (Rusu et al., 2016; Fernando et al., 2017; Aljundi et al., 2017; Mallya et al., 2018; Wortsman et al., 2020). For language models, modularity is typically obtained with experts: Gururangan et al. (2022) condition the experts on the domain and adapt to a new domain by training a new expert with the rest of the model frozen, Chen et al. (2023) add and freeze experts as the distribution changes, Sukhbaatar et al. (2024) train domain models separately and merge their MLPs into the experts of an MoE transformer, and Lin et al. (2025) update a sparse set of memory slots. Shen et al. (2023) route tokens among both attention and MLP modules, and find that their model has less forgetting than a dense model and that new modules can be added to it. Thérien et al. (2025) find that the routing of standard MoE transformers changes little under the distribution shifts of continual pretraining, and Li et al. (2025) analyze MoE models in continual learning theoretically. When an MoE transformer is continually pretrained with trainable attention parameters, these parameters are shared by all tokens, so the gradient of every new token changes them. In NESTOR, each layer applies to a token only the attention operators and experts of its columns, in addition to the shared experts, with no task labels and no changes to training. In the one-layer model of Section 5, where each token uses one column, there is then no forgetting on the other coarse labels. Our analysis of forgetting in Section 5 uses the overlap between the row spaces of the value maps of the old and the new data, as in Doan et al. (2021).
B Mathematical Description of the Architecture
This section specifies the forward pass of NESTOR as trained in all experiments. It expands (2) and (3) with the normalization, the residual connections, and the routing details that Section 2 omits. The initialization and the learning rate of each parameter are in Appendix D, and the sizes of each model are in Appendix C.1.
Notation and overall structure. The input is a sequence of tokens, and all features have width . Let , and let be the RMS normalization with a learned gain ; each use of Norm below has its own gain. No linear map has a bias. The embedding of the token is , with no learned position embedding, and the network then applies blocks. Block has layers, columns, and active columns per token. Below we describe one block and omit the index from its parameters and its routing variables. Each block has one output for each token, which we define in (17). The input of block is , with .
Column router. The router is computed once per block from the block input. Its scores are with , with a hidden layer of width 128. During training we add input-dependent noise (Shazeer et al., 2017), i.e., we replace by with ; there is no noise at evaluation. The selected columns and their gating weights are
and is the set of tokens routed to column . The bias is used only for the selection: the gating weights do not contain it, and it has no gradient. After each optimizer step we update the bias by (Wang et al., 2024)
where is the number of tokens in the batch which selected the column , and . By this update, the bias increases for the columns with less than the average load. We use no auxiliary balancing loss. The sets and the weights are used by all layers of the block. In the last block , so that , , and the router gives only the weights .
Attention residual. We replace all residual connections by the following operator, which is applied to each token separately. For a list of sources , its output is the mixture
with a learned query and learned gains . Each use of AttnRes below has its own query and gains. This is the attention residual of Kimi Team (2026) with two changes, which make the scales of the mixture and of its logits independent of the width: in the mixture, the sources are normalized to unit RMS, as in the logits, and multiplied by the gains ; and the logits are divided by . The query does not depend on the token, so the mixture weights depend on the input only through the sources. We initialize , so that the mixture is initially uniform.
One layer. Within a block, each token has one residual stream for each active column , where counts the attention and MLP operators applied so far, and . Let be the mean of the streams. For each , layer is
In (13) and (15), the sources are the embedding, the outputs of the earlier blocks (here the superscripts are block indices), and the current mean of the streams of this block. We omit the last source in (13) when , since it is zero. The outputs of the attention operator of column and of the experts of column are added only to the stream of column , and the outputs of the shared experts are added to every stream. All columns have the same inputs and , which depend on the streams only through their mean. The output of the block is the final mean,
By (14) and (16), this mean is the sum of the updates in (2) and (3) over the layers of the block, with a factor on the terms of the columns and a factor or on the experts.
Attention in a column. Each column has its own projections and in each layer, where is the number of heads of one column and is the width of a head. In the head , the token has the query, key, and value , which are the corresponding slices of , , and ; we apply rotary position embeddings (Su et al., 2024) to the queries and the keys, using the position of the token in the whole sequence and not its position within . The output of the head is
and . The division by instead of follows (Yang et al., 2021). In the implementation, we gather the tokens routed to column , apply a standard causal attention kernel to this shorter sequence, and scatter the result back to the positions of these tokens. To compute the saving, give each column heads, so that all projections cost the same FLOPs as in a transformer with heads. If the routing is balanced, i.e., , then the quadratic term in the attention FLOPs decreases from to
The saving grows with the context length .
Experts. Every expert is an MLP with gated linear units, (Shazeer, 2020). Each expert router is a linear map of with its own balancing bias, updated by (11). Each layer has shared experts with one router , and each column has experts with its own router :
The weights of the shared experts are normalized over the selected experts, as in (10). The weights are normalized over all E experts of the column (Fedus et al., 2022), so that they depend on the router also when . The load in the update (11) of counts only the tokens in . The two families of experts are weighted by a gate with the same input,
In all experiments and . The hidden widths of the experts are for a shared expert and for an expert of a column, rounded to a multiple of 8, so that each token uses hidden units of total width in every block. We use in the blocks where the resulting width is at least 160, and in the other blocks.
Output. The input of the output head is an attention residual with sources the embedding, the output of every block, and the deviation of every stream from the mean of its block:
where and are the final stream and the selected columns of block . The logits of the next token are a linear map of , whose weights are not tied to the embedding, and the training loss is the cross-entropy of the next token, with no auxiliary term. This is the only place where the individual streams are used, since the layers in (13) and (15) use only the means. We use the deviations because after the normalization in (12) the streams of a block are close to their mean, so using the streams themselves would add nearly the same source several times. The deviations sum to zero over , so they contain only the part of each stream that is specific to its column. Their gains in (12) are initialized at 0, and all other gains at 1, so that at initialization the output does not depend on the deviations.
Special cases. Let . Then and , each block has one stream, the deviations in (23) are zero, and (13)–(16) are layers of an MoE transformer with full causal attention and the block attention residual of Kimi Team (2026), with the two changes stated after (12). Our MoE baseline is this case with a single family of experts, , the gating weights of (20), and no gate (22). The dense baseline further sets , with a single SwiGLU of hidden width per layer and gating weight 1. Both baselines have the same block attention residual as above.
C Further Experiments and Ablations
C.1 Architecture Configurations and Hyperparameters
This subsection gives the configuration of NESTOR and of the two baselines at the four scales of Section 3, the rules that set every quantity other than the number of active columns, the experiment by which we selected the schedule of active columns over depth, and the FLOP accounting used throughout the paper.
Sizes. The four scales are listed in Table 1. The dense transformer and the MoE transformer share the width , the depth, 16 heads of width , and the training budget; in the MoE transformer, each MLP is replaced by experts of which are active. NESTOR has columns in every block and the same schedule of active columns at every scale, in the first six blocks and in the last. The number of layers per block grows with the scale, and the number of experts per column is raised at 500M and 1B so that the stored parameters match those of the MoE transformer. The batch grows with the scale so that every model is trained for about the same number of steps.
| Scale | Depth | Tokens per step | Steps | NESTOR: layers per block | FLOPs | Stored | |||
|---|---|---|---|---|---|---|---|---|---|
| 100M | 480 | 12 | 30 | 262,144 | 19,080 | 1, 1, 2, 2, 2, 3, 2 (13) | 8 | 0.38B | |
| 200M | 640 | 16 | 40 | 524,288 | 19,080 | 2, 2, 2, 3, 3, 3, 2 (17) | 8 | 0.76B | |
| 500M | 960 | 24 | 60 | 1,048,576 | 23,844 | 3, 3, 3, 4, 4, 5, 3 (25) | 12 | 2.44B | |
| 1B | 1280 | 32 | 80 | 2,097,152 | 23,842 | 3, 4, 4, 6, 6, 6, 4 (33) | 15 | 5.53B |
Table 1: The four scales. Width, depth, head width, and training budget are those of the dense transformer and of the MoE transformer; the sequence length is 4096. For NESTOR, the layers of the seven blocks (total in parentheses) at the schedule , the number of experts per column , its forward FLOPs per token at relative to the dense transformer, and its stored parameters (the MoE transformer has 0.37B, 0.79B, 2.41B, and 5.49B).
Derived quantities. Only and the schedule of are design choices; every other quantity that affects the FLOPs is set by a rule, so two configurations with different schedules differ in nothing else. Each column has heads of the baselines' head width, i.e., 5, 4, 3, 3, 3, 2, 2 heads in the seven blocks. The FLOPs of the attention projections of a token are then within 10% of those of the baselines, and a sparse block uses fewer FLOPs only in the products of queries with keys and of attention weights with values (19). The expert widths follow Appendix B: the shared experts and the experts of the columns of a token have total hidden width 4D in every block, the active MLP width of the baselines, and determines the number of stored parameters without changing the active width. With heads and widths fixed, the FLOPs of a layer depend only on the of its block, and we choose the number of layers in each block to meet the budget: for a given schedule we enumerate the splits of layers over blocks and keep those whose forward FLOPs at , with the accounting below, do not exceed the dense transformer's. Among the splits within budget at 200M, we selected the one in Table 1, which has most of its layers in the later blocks where is large. The other configurations of the search with the same budget (a sparser or denser first block, a lower endpoint of the schedule, more layers in the sparse blocks, wider attention or wider experts instead of more layers) have losses higher by 0.004 to 0.033 nats. At the other scales we used splits of the same form without further search. The resulting models use 1–2% fewer FLOPs than the budget.
The schedule of active columns. We compare ten schedules of over depth on the 200M model (Table 2 and Figure 6). Everything else is set as above, by the same rules, so that the FLOPs of every schedule are within 0.97 to those of NESTOR. The schedules are: a constant with the depth set by the budget; the schedule of NESTOR reversed, which has the same layers, FLOPs, and stored parameters; two symmetric schedules, dense at the ends and sparse in the middle, and the reverse; and three two-level schedules on one multiset of layers, sparse then dense, dense then sparse, and the same layers interleaved. Because an expert of a column has width , the stored parameters vary with the schedule, from those of NESTOR at constant to at . The number of stored parameters does not explain the ordering below, since the model with the most stored parameters has the highest loss.
Varying the number of active columns with depth generally improves held-out loss (Table 2; Figure 6, left). Among constant schedules, loss decreases as increases, but even full attention has a higher loss than NESTOR and the MoE transformer. Every varying schedule except the sparse-to-dense step has a lower loss than all constant schedules. The sparsest constant schedule has a much higher loss than the others, although its training loss curve is smooth.
The order of layers also affects the loss (Figure 6, right). Gradual schedules have lower losses than two-level schedules at similar mean . With the layer composition, FLOPs, and stored parameters fixed, the dense-to-sparse step has a lower loss than its reverse, and the symmetric schedule with a dense middle has a lower loss than the one with dense ends. Alternating sparse and dense layers gives the same loss as the better step schedule, while a long run of sparse layers at the start gives the highest loss of the varying schedules. Reversing the ramp of NESTOR has a smaller effect, close to the variation across seeds.
At 200M, the ramp of NESTOR and the symmetric schedule with a dense middle have the lowest losses, with no clear difference across the two seeds. Both start with sparse layers and have their largest at or after the middle. At 500M, with the stored parameters of both schedules matched to approximately those of the MoE transformer, the ramp has the lower loss in a single-seed comparison, so we use it in NESTOR. The symmetric schedule uses fewer attention FLOPs at long contexts, and is an alternative there.
| Schedule | Shape | per block | Layers per block | Mean | FLOPs | Stored | Loss |
|---|---|---|---|---|---|---|---|
| NESTOR (ramp up) | 3, 4, 5, 6, 6, 7, 8 | 2, 2, 2, 3, 3, 3, 2 | 5.71 | 1.00× | 762M | 3.092 / 3.088 | |
| ramp down | 8, 7, 6, 6, 5, 4, 3 | 2, 3, 3, 3, 2, 2, 2 | 5.71 | 1.00× | 762M | 3.101 | |
| constant | 2 | 20 | 2.00 | 1.00× | 1244M | 3.582 | |
| constant | 4 | 18 | 4.00 | 0.98× | 719M | 3.192 | |
| constant | 6 | 16 | 6.00 | 1.00× | 751M | 3.157 | |
| constant | 8 | 16 | 8.00 | 1.02× | 627M | 3.148 | |
| dense ends | 8, 5, 3, 3, 5, 8 | 3 each | 5.33 | 1.02× | 822M | 3.118 | |
| dense middle | 3, 5, 8, 8, 5, 3 | 3 each | 5.33 | 1.02× | 822M | 3.088 / 3.087 | |
| step up | 3, 8 | 9, 8 | 5.35 | 0.97× | 743M | 3.169 | |
| step down | 8, 3 | 8, 9 | 5.35 | 0.97× | 743M | 3.136 | |
| alternating | 3, 8, 3, 8, ..., 3 | 17 of 1 | 5.35 | 0.97× | 745M | 3.134 |
Table 2: Ten schedules of active columns on the 200M model, , everything else as in NESTOR; constant is full attention. In the column "Shape", , from 2 to 8, is plotted against depth. Mean is weighted by the layers per block; FLOPs are forward FLOPs per token at relative to NESTOR; stored parameters are totals. Held-out loss at the matched final step, seeds 42 / 43 if two seeds were run.
FLOP accounting. In the forward pass of one layer of width , the four attention projections cost FLOPs per token, and the three matrices of a gated MLP of width cost FLOPs per token. With a causal mask, the attention of a token is over tokens on average, and the products of queries with keys and of attention weights with values cost FLOPs per token. The ratio

Same layers, different order
★ Nestor: ramp up ★ ramp down (reversed) ● constant
▲ two-level ■ symmetric ○ other gradual ramps
Figure 6: The schedule of active columns. Left: held-out loss of the ten schedules of Table 2 against the layer-weighted mean of . The constant schedules are joined by a line; the run at is above the plotted range. The grey circles are the gradual ramps of the configuration search, the dashed line is the dense transformer, and the band is the range of the two seeds of the MoE transformer. Right: groups of schedules that differ only in the order of their layers. Within a group, the schedules have the same multiset of layers and hence the same FLOPs and stored parameters, so the differences within a group are due to the order alone. The shaded band is the mean of the two seeds of NESTOR plus or minus 0.010 nats, the difference between seeds at this scale. Where two seeds were run, they are joined by a whisker.
of the two is , which is between 0.20 and 0.53 for our models at . In a layer of NESTOR with C columns of width , each token is routed to columns, and each column contains tokens, so the quadratic term is FLOPs per token, which is the fraction of the 2SD FLOPs of full attention, as in (19). The routers, the attention residual, and the output head are not counted.
C.2 Pretraining Results
The pretraining runs of Section 3, plotted in Figure 2, are listed in Table 3: the number of training tokens and the training compute at each scale, and the stored parameters and the held-out loss of each model.
In Figure 7, we compare these runs with three sliding window baselines. Each baseline is the MoE transformer with sliding window attention in place of the column attention of NESTOR, pretrained from scratch at every scale with the same recipe, token budget, and attention residuals as the other models, with a single seed. The three baselines differ in how the attention FLOPs are distributed over depth. The first has the depth and the blocks of NESTOR. In each block, we choose the window so that a layer has as many attention scores as the corresponding layer of NESTOR, which gives windows of 798, 1,200, 1,460, 2,477, 2,477, and 2,113 tokens in the six windowed blocks and full attention in the last block. We choose its number of experts so that its stored parameters are within 1.6% of those of NESTOR, and its FLOPs per token are then within 0.5% of those of NESTOR. The second has the depth, the blocks, and the experts of the MoE transformer. Its layers have the same windows at the same relative depth, and its top two to four layers have full attention. The attention FLOPs saved by the windows are not used elsewhere, so this baseline has the stored parameters of the MoE transformer and 5–9% fewer FLOPs per token. The third has the shape and the FLOPs per token of the second, but the same attention FLOPs are distributed uniformly over depth: every windowed layer has a window of about 1,800 tokens, and a full attention layer follows every five windowed layers at 100M and every seven at the other scales. We choose the window so that the model has as many attention scores as the second baseline.
| Size | Tokens | Compute (PFLOP/s-days) | Model | Total params | Loss | Estimated compute at equal loss |
|---|---|---|---|---|---|---|
| 100M | 5B | 0.02 | Dense transformer | 0.14B | 3.578 | |
| MoE | 0.37B | 3.386 | ||||
| NESTOR | 0.38B | 3.356 | ||||
| 200M | 10B | 0.10 | Dense transformer | 0.23B | 3.293 | |
| MoE | 0.79B | 3.108 | ||||
| NESTOR | 0.76B | 3.092 | ||||
| 500M | 25B | 0.78 | Dense transformer | 0.55B | 2.953 | |
| MoE | 2.41B | 2.793 | ||||
| NESTOR | 2.44B | 2.758 | ||||
| 1B | 50B | 3.49 | Dense transformer | 1.10B | 2.743 | |
| MoE | 5.49B | 2.592 | ||||
| NESTOR | 5.53B | 2.571 |
Table 3: Pretraining results at four model scales. These are the numbers plotted in Figure 2 of Section 3. The last column is the estimated compute at which each baseline reaches the held-out loss of NESTOR at the same scale, from the fitted law , normalized by the training compute of NESTOR.
Sliding window attention and NESTOR. The sliding window baselines are more compute-efficient than the MoE, and at some scales they are comparable to NESTOR at similar compute. However, the compute efficiency of each baseline relative to NESTOR decreases with scale. The fitted scaling laws agree with this: the sliding window baselines have a higher irreducible loss (the loss at infinite compute) than NESTOR. One possible reason is that a sliding window restricts the context of a token to the most recent tokens, whereas in NESTOR the context of a token in a column depends on the input and can contain tokens from anywhere in the sequence. This class of attention patterns is strictly more expressive, and could scale better.
C.3 Architecture Ablations
Attribution of the improvement over the MoE transformer. The MLP of NESTOR differs from that of the MoE transformer baseline in three ways. First, it has two groups of experts with separate routers: the experts whose weights are tied across columns, and the experts of each column. Second, the two groups are weighted by the gate (22). Third, each token uses more experts of smaller width: at the 200M active parameter scale, a token uses 7 to 10 experts per layer in NESTOR, and 3 in the baseline. We test whether these differences, or column-routed attention alone, explain the improvement in Figure 2. The held-out losses of eight models at the 200M active parameter scale and of three models at the 500M scale are in Table 4. All models have the setup of Section 3, the attention residual, and an active MLP width of 4D.
An MoE transformer with twice as many experts of half the width (row 2) has the same loss as the baseline (row 1), so the smaller experts of NESTOR do not explain the improvement. NESTOR with has the same loss as an MoE transformer with the same number of stored parameters, both at 470M stored parameters (rows 3 and 4) and at the storage of the baseline (rows 5 and 1; at the 500M scale, rows 10 and 9). With one column, every token can use the experts of the column, so the models in rows 4, 5, and 10 have all three differences listed above and no column routing. Column-routed attention with the MLP of the baseline (rows 6 and 7) gives losses between 3.097 and 3.124 over three runs, which is the loss of the baseline within the variation between seeds. The full model (row 8), in which the experts are nested within the columns, has a loss lower than the baseline by 0.016 and 0.025 nats on the two seeds, and by 0.035 nats at the 500M scale (row 11).
C.4 Domain Adaptation Settings
Starting checkpoints. We use the 500M NESTOR, 500M MoE transformer, and 1B dense transformer from Section 3. Before domain adaptation, the context length of each model is extended from 4k to 32k on 0.5B

Figure 7: Pretraining with sliding window baselines. Figure 2 without the dense transformer and with three sliding window baselines, described in Appendix C.2: the MoE transformer with sliding window attention in place of the column attention of NESTOR: at the depth of NESTOR, with windows that give the same number of attention scores as NESTOR in each layer (triangles); at the depth of the MoE, with the same windows (inverted triangles); and at the depth of the MoE, with one uniform window and periodic full attention layers (pentagons). Top: held-out loss against training compute, with the fitted laws and the compute multiples of Figure 2. Bottom: the same losses minus the fitted law of the MoE at the same training compute (the zero line), on a scale where differences of a few hundredths of a nat are visible; at 200M, a second seed is drawn as a whisker. The two windowed models at the depth of the MoE use fewer FLOPs per token than the MoE, so the MoE law is evaluated at their smaller compute, and their values in the bottom panel are lower than the differences between their losses and the losses of the MoE.
DCLM-baseline tokens, using the equal-token protocol of Section 4.2. The extension documents have at least 32,768 tokens, and the rotary embedding base is . The held-out losses of the resulting checkpoints are in Table 5. Each model has one starting checkpoint for every target domain and both replay settings. The adaptation runs are independent and do not start from a model adapted to another domain.
Data. We use the published training and test splits of PG-19, OpenWebMath, AlgebraicStack, and the German subset of FineWeb-2, as cited in Section 4.1. OpenWebMath and AlgebraicStack are taken from Proof-Pile-2. The available training data consist of the PG-19 training split, the first 12 OpenWebMath training files, all 79 AlgebraicStack training files, and the first two German training files of FineWeb-2. All corpora are tokenized with the c1100k_base tokenizer. We separate documents with an end-of-text token, concatenate them, and train on shuffled 32,768-token sequences. Sequences may cross document
| Attention | Experts | Stored | FLOPs | Held-out loss | |
|---|---|---|---|---|---|
| 200M active parameters, 10B tokens | |||||
| 1 | full | 787M | |||
| 2 | full | 781M | |||
| 3 | full | 471M | |||
| 4 | full () | experts of NESTOR: , width | 470M | ||
| 5 | full () | experts of NESTOR at the width of the baseline: | 787M | ||
| 6 | column-routed | , tied across columns, with an earlier schedule of active columns | 935M | ||
| 7 | column-routed | , tied across columns, with the schedule of NESTOR | 843M | ||
| 8 | column-routed | experts of NESTOR (full model) | 762M | ||
| 500M active parameters, 25B tokens | |||||
| 9 | full | 2.41B | |||
| 10 | full () | experts of NESTOR at the width of the baseline, as in row 5 | 2.41B | ||
| 11 | column-routed | experts of NESTOR (full model) | 2.44B | ||
Table 4: Held-out loss of eight models at the 200M scale and three models at the 500M scale. FLOPs are forward FLOPs per token relative to the dense transformer at . Where a second seed was run, both losses are given (seed 42 / seed 43).
Table 5: Held-out loss before domain adaptation, after context extension to 32k. All losses are from the 32k evaluation described below. These are the starting losses for adaptation and forgetting in Figure 3.
| Model | DCLM | PG-19 | OpenWebMath | AlgebraicStack | German |
|---|---|---|---|---|---|
| 500M NESTOR | 2.779 | 2.732 | 2.417 | 1.789 | 4.171 |
| 500M MoE | 2.810 | 2.765 | 2.449 | 1.813 | 4.224 |
| 1B dense | 2.779 | 2.719 | 2.412 | 1.720 | 4.164 |
boundaries; causal attention is not reset at those boundaries. The same data and sampling order are used for all three models within each setting.
Adaptation protocol. Each run has 477 optimizer steps with 32 sequences per step, or 1,048,576 tokens per step. This gives 500,170,752 tokens, rounded to 0.5B in the text. For both sparse models, we freeze the router parameters and load-balancing biases and disable routing noise. All other trainable parameters, including attention projections, experts, normalization parameters, embeddings, the output head, and attention residuals, are updated. Routing decisions are recomputed from the current hidden states, so freezing the routers does not fix the token assignments. The dense model is fully fine-tuned. Each model, domain, and replay setting has one run, with seed 42. The data sampler uses seed 0 to shuffle the training sequences.
Optimization. The optimizer settings are the same for all three models in both replay conditions. We initialize fresh optimizer states and restart the learning-rate schedule for each run. Attention and expert matrices are trained by Muon with base learning rate 0.0025 and the matrix-shape scaling of Appendix D. The remaining trainable parameters are trained by AdamW with base learning rate , including token embeddings, the output head, normalization parameters, attention residual queries and gains, and the path gates of NESTOR. Muon uses momentum 0.95, Nesterov updates, and five Newton–Schulz iterations; AdamW uses and . The decoupled weight decay is 0.1 for attention and expert matrices, token embeddings, the output head, and path gates. Normalization parameters, biases, and attention residual queries and gains have no weight decay. We clip the global gradient norm to 1.0. The schedule

Figure 8: Ablation of the placement of the experts of NESTOR, at the 200M scale. We vary the stored parameters of three designs, with the columns, the schedule of active columns, the attention residual, the training recipe and the 10B-token budget of Section 3 held fixed, so that every model has the same active FLOPs: the design of NESTOR, shared experts with and experts per column with ; a shared bank only, with and no experts in the columns, which is the MLP of the MoE baseline with column-routed attention; and experts in the columns only, with and no shared experts. The dashed line is the capacity law of the MoE baseline, fitted to its runs with 16, 24 and 48 experts (diamonds), and each design is fitted with the same exponent, solid over its measured span and dashed beyond it. Where two seeds were run, they are joined by a whisker. NESTOR is 0.018–0.031 nats below the law at every size. With experts in the columns only, the loss is below the law at small sizes and closer to the law at larger sizes. With a shared bank only, the loss is on the law from 24 to 48 experts. The shared bank with 96 experts is omitted: its routing collapsed, and 54 of its 96 experts per layer were selected by under 1% of the tokens.
starts with 47 steps of linear warmup, followed by cosine annealing for the remaining 430 steps. The cosine scheduler uses and , so the run ends before the scheduled minimum.
Compute reference. At the 32k context length used for adaptation, the estimated forward FLOPs per token for NESTOR are approximately those of the 500M MoE transformer and those of the 1B dense transformer. In these estimates we count attention projections, causal attention, and MLPs, assume balanced token assignments across columns, and exclude routers, attention residuals, normalization, and the output head. Since all models are trained on the same number of tokens, the same ratios apply to these forward FLOP totals over each adaptation run. We report them as a reference for computational cost; the adaptation and forgetting results compare models trained on equal token budgets.
Evaluation. We evaluate the starting checkpoint and the final checkpoint at step 477 on identical held-out sequences. For PG-19, we use the first 32,768 tokens of each of the 77 test books with at least this length. For OpenWebMath, AlgebraicStack, and German, we use the first 200 non-overlapping 32,768-token sequences of each test stream, allowing sequences to contain multiple documents. To measure forgetting, we use the first 32,768 tokens of each of 200 DCLM-baseline validation documents with at least this length. This DCLM evaluation set is separate from the extension and replay data. We average next-token cross-entropy over all prediction targets, excluding the first token of each sequence. The evaluation sequences are the same for all models, and there are no parameter updates during evaluation. Adaptation is the initial loss minus the

Figure 9: Ablation of the attention residual of NESTOR at 100M, 200M, 500M, and 1B, on the axes of Figure 2. We compare the column attention residual (Col. AttnRes), the merged attention residual (AttnRes), which is that of Kimi Team (2026) with the changes of Appendix B, and no attention residual. The rest of the model is unchanged. Each series is fitted by , and a horizontal tick marks the projected compute at which each variant reaches the loss of Col. AttnRes. Removing the attention residual increases the loss by 0.073–0.086 nats at every scale, which corresponds to 1.5–2× the compute. The two attention residuals have the same loss up to 500M and differ at 1B.
final loss on the target corpus; forgetting is the final loss minus the initial loss on DCLM. In the averages in Figure 3 and Table 6, each of the four target domains has equal weight.
Adaptation with replay of the pretraining corpus. In the runs without replay, all training tokens come from the target corpus. We repeat these runs with a mixture containing approximately 75% target-domain tokens and 25% DCLM-baseline tokens, keeping the total budget and all other training settings unchanged. The DCLM sequences are taken from those already used during context extension. The target sequences are a subset of those used in the corresponding run without replay. We shuffle the combined sequences before training; the 25% share is approximate because the data are sampled in whole sequences. The results are in Figure 3 (faded marks) and Table 6. Averaged over the four domains, replay reduces forgetting by about 70% for each model, while reducing the adaptation gain by about 6%. With replay, NESTOR and the MoE transformer have mean gains of 0.687 and 0.687, respectively, and mean forgetting of 0.073 and 0.076. NESTOR has less forgetting on each of the four corpora. The 1B dense transformer has a mean gain of 0.696 and mean forgetting of 0.087. The per-domain results and averages for both replay settings, including the values in Section 4.1, are listed in Table 6.
C.5 Long Context Extension Settings
This subsection gives the details of the long context extension experiments in Section 4.2. We report results through 64k at the 100M, 200M, 500M, and 1B scales.
Starting checkpoints. We extend the pretrained dense transformer, MoE transformer, and NESTOR of Section 3 at all four scales. These models were pretrained at context length 4k with rotary base ; their 4k held-out losses are the first column of Table 8. Each target length is a separate run from the 4k checkpoint, and no run continues from a model extended to a shorter length. At 200M, NESTOR was pretrained with
Table 6: Loss before and after domain adaptation. Target-corpus and DCLM held-out losses at 32k, before adaptation and after 0.5B training tokens. Gain is target loss before minus after; forgetting is DCLM loss after minus before, corresponding to Figure 3. In the average, the four domains have equal weight. Differences and averages are computed before rounding to three decimal places.
| Domain | Model | Target-corpus loss | DCLM loss | ||||
|---|---|---|---|---|---|---|---|
| Before | After | Gain | Before | After | Forgetting | ||
| No replay | |||||||
| Books | 500M NESTOR | 2.732 | 2.548 | 0.184 | 2.779 | 2.996 | 0.217 |
| 500M MoE | 2.765 | 2.582 | 0.182 | 2.810 | 3.039 | 0.229 | |
| 1B dense | 2.719 | 2.538 | 0.181 | 2.779 | 3.032 | 0.252 | |
| Math | 500M NESTOR | 2.417 | 2.084 | 0.332 | 2.779 | 2.885 | 0.106 |
| 500M MoE | 2.449 | 2.111 | 0.338 | 2.810 | 2.920 | 0.110 | |
| 1B dense | 2.412 | 2.075 | 0.338 | 2.779 | 2.914 | 0.134 | |
| Code | 500M NESTOR | 1.789 | 1.084 | 0.705 | 2.779 | 3.073 | 0.294 |
| 500M MoE | 1.813 | 1.102 | 0.712 | 2.810 | 3.106 | 0.296 | |
| 1B dense | 1.720 | 1.031 | 0.688 | 2.779 | 3.164 | 0.385 | |
| German | 500M NESTOR | 4.171 | 2.465 | 1.706 | 2.779 | 3.176 | 0.398 |
| 500M MoE | 4.224 | 2.521 | 1.704 | 2.810 | 3.221 | 0.410 | |
| 1B dense | 4.164 | 2.431 | 1.733 | 2.779 | 3.273 | 0.494 | |
| Average | 500M NESTOR | 2.777 | 2.045 | 0.732 | 2.779 | 3.033 | 0.254 |
| 500M MoE | 2.813 | 2.079 | 0.734 | 2.810 | 3.072 | 0.261 | |
| 1B dense | 2.754 | 2.019 | 0.735 | 2.779 | 3.096 | 0.316 | |
| 25% replay | |||||||
| Books | 500M NESTOR | 2.732 | 2.573 | 0.158 | 2.779 | 2.828 | 0.049 |
| 500M MoE | 2.765 | 2.607 | 0.158 | 2.810 | 2.863 | 0.053 | |
| 1B dense | 2.719 | 2.560 | 0.159 | 2.779 | 2.837 | 0.058 | |
| Math | 500M NESTOR | 2.417 | 2.113 | 0.304 | 2.779 | 2.832 | 0.053 |
| 500M MoE | 2.449 | 2.140 | 0.309 | 2.810 | 2.867 | 0.057 | |
| 1B dense | 2.412 | 2.101 | 0.311 | 2.779 | 2.842 | 0.063 | |
| Code | 500M NESTOR | 1.789 | 1.131 | 0.658 | 2.779 | 2.867 | 0.088 |
| 500M MoE | 1.813 | 1.146 | 0.668 | 2.810 | 2.901 | 0.091 | |
| 1B dense | 1.720 | 1.074 | 0.646 | 2.779 | 2.885 | 0.106 | |
| German | 500M NESTOR | 4.171 | 2.546 | 1.626 | 2.779 | 2.879 | 0.101 |
| 500M MoE | 4.224 | 2.611 | 1.614 | 2.810 | 2.913 | 0.102 | |
| 1B dense | 4.164 | 2.497 | 1.667 | 2.779 | 2.899 | 0.120 | |
| Average | 500M NESTOR | 2.777 | 2.091 | 0.687 | 2.779 | 2.851 | 0.073 |
| 500M MoE | 2.813 | 2.126 | 0.687 | 2.810 | 2.886 | 0.076 | |
| 1B dense | 2.754 | 2.058 | 0.696 | 2.779 | 2.866 | 0.087 | |

Nestor MoE transformer (dense within 0.2%) dashed: beyond the trained lengths
Figure 10: Forward FLOPs per token against the context length. Top: the forward FLOPs per token of NESTOR and of the baselines at all scales, with the accounting of Appendix C.1. The baseline curve is that of the MoE transformer. The dense transformer has the same FLOPs at 100M and 500M; at 200M and 1B, because of the rounding of the MoE expert widths, the two differ by less than 0.2% over the plotted lengths. Bottom: the FLOPs per token of NESTOR relative to the MoE transformer. The markers are the context lengths of Figure 4, and the same formula is plotted up to 1M tokens as dashed curves. The projections and MLPs of NESTOR cost 4–8% more than those of the baselines, and its attention costs 0.75–0.81× as much. The share of attention in the total grows with S, so the relative cost of NESTOR decreases from 0.98–0.99× at 4k to 0.80–0.84× at 64k, and tends to the attention ratio as (dotted).
two seeds, and every setting is run from both checkpoints, with a data order for the extension run that depends on the seed; the baselines, and all models at the other scales, have one run per length.
Data. For a target length S, the extension corpus consists of DCLM-baseline documents of at least S tokens, taken from a part of the corpus that was not used in pretraining. Documents are separated by an end-of-text token and concatenated, and the training sequences are consecutive S-token windows of this stream, so a sequence may cross a document boundary; causal attention is not reset at those boundaries. At a given length, all models are trained on the same sequences in the same order (data sampler seed 0). The held-out set at length S consists of the first S tokens of each of 200 documents of at least S tokens (100 at 64k), taken from a third part of the corpus that is disjoint from both the pretraining and the extension data. The losses at 4k are those of Section 3, on its held-out set.
Extension at equal tokens. Each run has 477 optimizer steps with 1,048,576 tokens per step (128, 64, 32, and 16 sequences per step at 8k, 16k, 32k, and 64k), which gives 500,170,752 tokens, rounded to 0.5B in the text. The rotary base is raised from to , , , and at the four lengths, in training and in evaluation. All parameters are trained, including the routers. The optimizer, the weight decay, and the gradient clipping are those of Appendix C.4: Muon with peak learning rate 0.0025 and AdamW with peak learning rate , a quarter of the pretraining peaks, with fresh optimizer states, 47 steps of linear warmup (10%), and cosine annealing over the remaining steps.
Extension at equal FLOPs. Let be the forward FLOPs per token of NESTOR relative to the MoE transformer at length S, with the accounting of Appendix C.1; its values are given under the panels of
Figure 4 and listed in Table 7, and is the measured counterpart of the multiplier of Section 4.2. The equal-FLOP runs of NESTOR are trained on tokens at the same tokens per step, that is for steps, with a warmup of of and the cosine schedule spread over the steps, and with both peak learning rates multiplied by , so that the product of the number of steps and the peak learning rate is that of the equal-token run. At the unscaled peak learning rate, the losses of the same runs were higher by 0.002 to 0.014 nats at 500M and 1B, with a difference that increases with . In the setting with new documents, the sequences are drawn from the full extension corpus, so the additional steps use documents that are not in the equal-token run. In the setting with repeated documents, the corpus is restricted to the sequences used in the equal-token run, extended by steps' worth of sequences drawn from that set without replacement, so that no sequence appears more than twice, and the run is one shuffled pass over this multiset; the two copies of a repeated sequence are therefore at random positions of the run, at a mean distance of steps. The two settings have the same number of steps, tokens, and FLOPs, and differ only in the data.
Table 7: FLOP ratio of NESTOR to the MoE transformer at each context length, and, in parentheses, the number of optimizer steps of the equal-FLOP runs, . The equal-token runs have 477 steps.
| Scale | 8k | 16k | 32k | 64k |
|---|---|---|---|---|
| 100M | 0.940 (508) | 0.895 (533) | 0.860 (555) | 0.837 (570) |
| 200M | 0.933 (512) | 0.881 (542) | 0.837 (570) | 0.806 (592) |
| 500M | 0.938 (509) | 0.888 (537) | 0.840 (568) | 0.802 (595) |
| 1B | 0.956 (499) | 0.911 (524) | 0.863 (553) | 0.821 (581) |
Evaluation. Each run is evaluated at its final step on the held-out sequences of its length, with the rotary base of the run and in full precision. We average the next-token cross-entropy over all prediction targets of all sequences, excluding the first token of each sequence. The same sequences are used for every model and setting at a length. In Figure 4, we plot these losses minus the loss of the MoE transformer of the same scale at the same length; at 200M, the two seeds are joined by a whisker. The losses are listed in Table 8.
Results. The loss of the dense transformer is higher than that of the MoE transformer by 0.13 to 0.19 nats at every length and scale. At equal tokens, the margin of NESTOR over the MoE transformer is about the same as in pretraining at every length: -0.028 to -0.030 nats at 100M, -0.012 to -0.015 at 200M, -0.031 to -0.035 at 500M, and -0.017 to -0.025 at 1B. At equal FLOPs the margin increases with the context length. With new documents it is -0.047, -0.037, -0.061, and -0.058 nats at 64k at the four scales; with repeated documents, -0.037, -0.023, -0.047, and -0.033. With repeated documents, the losses are within 0.006 nats of those with new documents at 8k and 16k at every scale; at 32k and 64k, the losses with new documents are lower by 0.004 to 0.025 nats.
C.6 Routing Statistics and Routing Counterfactuals
This section describes how balanced the trained routers of NESTOR and of the MoE transformer are, what information each level of the routing contains, and how much the held-out loss depends on each level. For the first two questions we record the routing decisions of the 500M models of Section 4.1; for the third we evaluate the pretrained models of Section 3 with modified routing.
Routing statistics. For the 500M NESTOR and the 500M MoE transformer after context extension to 32k (the starting checkpoints of Appendix C.4), we record the selections of every router on the first 64 held-out sequences of 32,768 tokens of each of the five corpora of Section 4.1 (DCLM-baseline, books, mathematics, code, and German; 2.1M tokens per corpus), in evaluation mode. We repeat this for the models adapted to each corpus, with and without frozen routers, on the same sequences, to count the assignments that change during adaptation. In Figure 14 we plot, per router family and layer, the effective number of choices
Table 8: Held-out loss at each context length, before extension (4k) and after extension to 8k, 16k, 32k, and 64k, for the runs of Figure 4. The three settings of NESTOR start from the same 4k checkpoint; repeated and new refer to the documents of the equal-FLOP runs. At 200M, NESTOR is given for both seeds (seed 42 / seed 43); the baselines and the other scales have one seed.
| Model | 4k | 8k | 16k | 32k | 64k |
|---|---|---|---|---|---|
| 100M | |||||
| Dense transformer | 3.578 | 3.511 | 3.495 | 3.501 | 3.490 |
| MoE transformer | 3.386 | 3.338 | 3.330 | 3.330 | 3.325 |
| NESTOR, equal tokens | 3.356 | 3.311 | 3.302 | 3.302 | 3.296 |
| NESTOR, equal FLOPs, repeated | - | 3.309 | 3.298 | 3.297 | 3.287 |
| NESTOR, equal FLOPs, new | - | 3.307 | 3.295 | 3.293 | 3.277 |
| 200M | |||||
| Dense transformer | 3.293 | 3.256 | 3.248 | 3.244 | 3.237 |
| MoE transformer | 3.108 | 3.096 | 3.095 | 3.084 | 3.080 |
| NESTOR, equal tokens | 3.092/3.088 | 3.081/3.078 | 3.084/3.083 | 3.070/3.068 | 3.066/3.063 |
| NESTOR, equal FLOPs, repeated | - | 3.079/3.076 | 3.075/3.073 | 3.061/3.058 | 3.056/3.051 |
| NESTOR, equal FLOPs, new | - | 3.077/3.073 | 3.074/3.071 | 3.056/3.054 | 3.043/3.042 |
| 500M | |||||
| Dense transformer | 2.953 | 2.971 | 2.970 | 2.952 | 2.948 |
| MoE transformer | 2.793 | 2.827 | 2.842 | 2.810 | 2.805 |
| NESTOR, equal tokens | 2.758 | 2.792 | 2.811 | 2.779 | 2.773 |
| NESTOR, equal FLOPs, repeated | - | 2.789 | 2.802 | 2.766 | 2.757 |
| NESTOR, equal FLOPs, new | - | 2.787 | 2.800 | 2.758 | 2.744 |
| 1B | |||||
| Dense transformer | 2.743 | 2.797 | 2.810 | 2.779 | 2.780 |
| MoE transformer | 2.592 | 2.633 | 2.683 | 2.634 | 2.632 |
| NESTOR, equal tokens | 2.571 | 2.616 | 2.661 | 2.612 | 2.607 |
| NESTOR, equal FLOPs, repeated | - | 2.616 | 2.655 | 2.603 | 2.599 |
| NESTOR, equal FLOPs, new | - | 2.610 | 2.650 | 2.591 | 2.574 |

Nestor
baselines
MoE + sliding window
equal FLOPs, fresh
-
★ - equal FLOPs, repeated
-
◆ - MoE (reference, 1.00×)
equal tokens
☆ open: pretrained, at 4k
equal FLOPs, fresh
Figure 11: Long context extension with a sliding window baseline. The panels of Figure 4 with one more baseline in the bottom row (triangles): the MoE transformer with sliding window attention in as many layers as needed to match the FLOPs per token of NESTOR, extended at equal FLOPs with new documents. It starts from the 4k checkpoint of the MoE transformer, so both have the same open marker at 4k.
of the distribution of the assignments over the choices, the share of choices that are rarely or never selected, and the mean per-token entropy of the router's softmax as a fraction of .

Nestor
baselines
MoE + sliding window
equal FLOPs, fresh
dense transformer
equal FLOPs, fresh
equal FLOPs, repeated
MoE (reference, 1.00×)
equal tokens
open: pretrained, at 4k
Figure 12: Long context extension with a sliding window baseline, one global layer in two. As Figure 11, with a different baseline (triangles): the MoE transformer with sliding window attention of window 4096 in every other layer, starting from the first, and global attention elsewhere. Its FLOPs per token are 0.94–0.96× those of the MoE transformer at 8k and 0.61–0.67× at 64k, lower than those of NESTOR from 16k on. At equal FLOPs it is therefore trained on more tokens than NESTOR: 0.75–0.82B against 0.60–0.62B at 64k.
Balance and entropy. On the pretraining corpus the load of both models is almost uniform over the choices (effective choices of at least 0.97E in every router family and layer), with one exception: the routing in the first layer of the MoE transformer has collapsed: two experts are each selected by about 70% of the tokens and one expert is never selected (0.41E). On the other corpora the load is more concentrated in both models, most of all on code and German, where a third to a half of the experts of some layers have less than half of the uniform load; for the columns this share is smaller (15–21%). For each token, the softmax of the column router is close to uniform: in the six routed blocks its entropy is 0.95–0.997 of log C, so the gating weights of the selected columns are within a few percent of uniform, and its scores have an RMS of 0.15–0.41, below the mean magnitude 0.44 of the balancing bias. However, the selection depends on the input and is stable under noise: routing with the training-time noise agrees with noise-free routing on 85–98% of tokens per block, and for only 1–16% of tokens is the selection the same as that by the bias alone. The softmax of the expert routers is more concentrated, with per-token entropies of 0.4–0.9 of log E.
| Routing decision | Corpus information (bits; range over layers) | Assignments changed by adaptation routers frozen | all parameters trained |
|---|---|---|---|
| NESTOR: which column | 0.05 (0.01–0.08) | 4.7% | 13.7% |
| NESTOR: which shared expert | 0.13 (0.01–0.36) | 15.6% | 24.4% |
| NESTOR: which expert of the column | 0.28 (0.04–0.54) | 25.8% | 32.6% |
| MoE transformer: which expert | 0.25 (0.02–0.48) | 21.7% | 30.7% |
Table 9: Information in each routing level, for the 500M models of Figure 14. Corpus information: mutual information, in bits, between the corpus (five corpora with equal token counts, entropy 2.32 bits) and the selection, counting each selection as one draw; mean over the routed layers, range in parentheses. For the experts of a column, the information is conditional on the column, so the column and expert rows add up to the information of the pair. Assignments changed: share of tokens of the adaptation corpus whose selected set differs from that before adaptation, after 0.5B tokens of adaptation without replay, averaged over the four corpora of Section 4.1; with frozen routers, every change is due to a change of the routers' inputs. Training on the pretraining corpus alone changes 2 / 8 / 15 / 11% of the assignments in the four rows.

Figure 13: Long context extension with a sliding window baseline, one global layer in six. As Figure 11, with a different baseline (triangles): the MoE transformer with sliding window attention of window 4096 in five of every six layers and global attention in the sixth. Its FLOPs per token are 0.89–0.94× those of the MoE transformer at 8k and 0.34–0.43× at 64k, so at equal FLOPs it is trained on 1.15–1.49B tokens at 64k, against 0.60–0.62B for NESTOR. The 64k extension corpus has 1.2B tokens; at 100M, 200M, and 500M, 17%, 20%, and 2% of the tokens of the 64k run are therefore seen a second time. The vertical range of the bottom row is larger than in Figure 11.
Information in each level. The column assignment contains almost no information about the corpus (Table 9; 0.05 bits of a possible 2.32), while the choice of expert within a column contains as much as the choice of expert in the MoE transformer (0.28 and 0.25 bits). The enrichment of a corpus at an expert of a column is the sum of its enrichment at the column and its enrichment within the column, and the mean absolute value of the second term is three times that of the first (0.84 against 0.29). The column assignment is also the most stable decision under domain adaptation: with frozen routers, 4.7% of the column assignments on the target corpus change, against 26% of the assignments to the experts of the columns and 22% of the assignments in the MoE transformer. Thus the column routing is largely the same across corpora, and the selections that depend on the corpus are those of the expert routers within each column.
Routing counterfactuals. To measure how much the held-out loss depends on each routing level, we re-evaluate the pretrained models of Section 3 on the held-out set of Figure 2, at context length 4k, with the decisions of one router family replaced at evaluation time and without any training. In the shuffled condition, each token is given the routing output (selected set and gating weights) of another token of the same sequence, chosen uniformly at random. The number of tokens in every column and expert, and hence the attention FLOPs, are then unchanged, and only the assignment of decisions to tokens changes. In the random condition, each token is assigned a uniformly random subset of K choices, weighted by the router's scores at those choices. When the column routing is replaced, different tokens are routed to each column, and the expert routers of the column route these tokens with their learned parameters, so this condition changes only the column decision. With the learned routing, we obtain the losses of Table 3 to four decimals. The increase in held-out loss for NESTOR and the MoE transformer at 200M, 500M, and 1B, and for the column-routed model with the MoE's shared expert bank (row 7 of Table 4), is in Table 10.

layer
layer
layer
DCLM
Books
Math
Code
German
equal-token mixture
bars (mixture), share of the layer's choices: ■ never selected ■ below 1/10 of the uniform load ■ 1/10 to 1/2 of it
pentagons: the three together on DCLM alone
private experts: line = mean over the 8 columns, band = min to max, dashed = joint over all 96 experts
Figure 14: Routing statistics of the trained 500M models across depth, one column of panels per router family. Top: effective number of choices of the aggregate assignment distribution on each held-out corpus (thin lines) and on their equal-token mixture (heavy line). Middle: share of the layer's choices that are never selected or selected well below the uniform load. Bottom: mean per-token entropy of the router's softmax as a fraction of , which measures how concentrated the router's distribution is for each token, as opposed to how balanced the load is. In the last block of NESTOR, every column is selected (shaded).
| Replaced routing | NESTOR | MoE transformer | Column-routed, shared bank | |||
|---|---|---|---|---|---|---|
| 200M | 500M | 1B | 200M | 500M / 1B | ||
| columns, shuffled | 0.40 / 0.48 | 0.74 | 0.62 | - | - | 0.50 |
| columns, random | 0.39 / 0.46 | 0.69 | 0.79 | - | - | 0.53 |
| shared experts, shuffled | 2.59 / 2.53 | 2.11 | 2.13 | - | - | - |
| experts of the columns, shuffled | 0.99 / 1.08 | 1.36 | 1.31 | - | - | - |
| both expert levels, shuffled | 3.96 / 3.77 | 3.82 | 3.61 | - | - | - |
| experts, shuffled | - | - | - | 4.01 / 4.23 | 4.47 / 4.51 | 4.08 |
| experts, random | - | - | - | 3.88 / 3.99 | 4.16 / 4.57 | 4.16 |
| all routing, shuffled | 4.14 / 3.94 | 4.09 | 4.23 | - | - | 4.39 |
Table 10: Increase in held-out loss (nats) of the pretrained models when one routing level is replaced at evaluation time. The columns of the table are the models of Table 3 and the column-routed model with the shared bank of the MoE transformer (row 7 of Table 4, at 200M); the 200M models are given for both seeds, as seed 42 / seed 43. For reference, the loss of the MoE transformer exceeds the loss of NESTOR by 0.016 / 0.025 at 200M, 0.035 at 500M, and 0.022 at 1B.
Results. First, the loss depends strongly on the column assignment at every scale: replacing it increases the loss by 0.40–0.48 nats at 200M, 0.74 at 500M, and 0.62 at 1B, which is 18–28 times the difference between the losses of the MoE transformer and of NESTOR at the same scale, and the shuffled and random conditions agree. The loss depends on which columns a token is routed to, although the gating weights of the columns are nearly uniform, so the learned columns are not equivalent to a random partition of the tokens. Second,
| Model | Block (active columns of 8) | Sum | All blocks | ||||||
|---|---|---|---|---|---|---|---|---|---|
| 1 (3) | 2 (4) | 3 (5) | 4 (6) | 5 (6) | 6 (7) | 7 (8) | |||
| NESTOR, seed 42 | 0.003 | 0.124 | 0.049 | 0.045 | 0.064 | 0.027 | 0.001 | 0.312 | 0.398 |
| NESTOR, seed 43 | 0.002 | 0.124 | 0.057 | 0.060 | 0.070 | 0.027 | 0.002 | 0.341 | 0.479 |
| Column-routed, shared bank | 0.054 | 0.046 | 0.058 | 0.078 | 0.039 | 0.030 | 0.009 | 0.314 | 0.500 |
Table 11: Increase in held-out loss (nats) of the 200M column-routed models when the column routing of one block is shuffled and the other blocks have their learned routing, next to the sum over blocks and the cost of shuffling all blocks at once (the first row of Table 10). In the last block every column is selected, so shuffling changes only its gating weights.
replacing the column assignment increases the loss by a similar amount (0.50 nats) in the column-routed model whose experts are shared by all columns. The importance of the column decision is therefore due to column-routed attention and not to the nesting, and the evidence that the improvement of NESTOR is due to the nesting comes from the trained ablations of Appendix C.3, not from these counterfactuals. Third, at 200M, replacing both expert levels of NESTOR increases the loss about as much as replacing the single expert level of the MoE transformer (3.8–4.0 against 4.0–4.2 nats). At larger scales the two increases differ more (3.6 against 4.5 at 1B), while the increase for the column level is larger than at 200M, so at larger scales a larger share of the effect of the routing is due to the columns. Within the expert levels of NESTOR, the loss depends most on the shared experts. The effect of the column assignment of each block is given in Table 11. In NESTOR, shuffling the assignment of the first block, which is computed before any attention layer, has almost no effect, shuffling the second block has the largest effect, and the effect decreases towards the last block. The sum over blocks is below the increase from replacing all blocks at once, so the routers of later blocks depend on features computed under the learned routing of the earlier blocks. In the column-routed model with the shared bank, shuffling the assignment of the first block has an effect (0.054 nats).
D Optimization and Initialization
Optimization. The matrices of the attention operators and of the experts are trained by Muon (Jordan et al., 2024) with the base learning rate . The update of a matrix in is multiplied by , so that its spectral norm scales as in the spectral condition of Yang et al. (2023). All other parameters are trained by AdamW (Loshchilov et al., 2019) with the base learning rate . These are the token embeddings, the output head, the expert routers of the MoE baseline and of NESTOR (including the routers of the shared experts and of the experts of each column, and the gate (22)), the queries and gains of the attention residual, and the normalization gains. The only exception is the last layer of the column router, which has the learning rate , where is the hidden width of the router and is the number of layers in its block: this router is evaluated once and used by all layers, so its gradient is a sum of terms. The Muon base learning rate was selected at 200M and reused at the other scales. The AdamW base learning rate was fixed, without a separate sweep.
Initialization. The three architectures have the same initialization. The query, key, and value projections, the input and gate matrices of the experts, the expert routers, and the gate (22) are initialized with standard deviation . The output projections of the attention operators and the output matrices of the experts are initialized with this standard deviation divided by , where is the number of layers of the model. The token embeddings and the output head have standard deviation 0.1; the output of the embedding is multiplied by 12, and the output logits are divided by 8. The last layer of the column router is initialized with standard deviation , so that the column routing is close to uniform at initialization, and the queries of the attention residual are initialized at zero.
| Setting | Value |
|---|---|
| Learning rate, Muon | |
| Learning rate, AdamW | |
| Muon momentum | , Nesterov |
| Newton–Schulz iterations | |
| AdamW (), | |
| Warmup | linear, of the steps |
| Decay | cosine, minimum |
| Weight decay | on matrices, on vectors |
| Gradient clipping | |
| Dropout | |
| Sequence length | |
| Precision | bfloat16 autocast |
| Seed |
Table 12: Pretraining hyperparameters, shared by all architectures and scales.
E Compute Multipliers under Scaling Laws
In addition to Sections 3 and 4.2, this section gives a compute accounting for the full architectures, analogous to the one in Theorem 4(c) for Model 1 at a fixed model size. We take as a hypothesis that the losses of the full architectures follow a scaling law with common exponents and coefficients that depend on the architecture. We show that the compute multiplier between the two architectures is then the same at every loss, and that it grows with the context length because NESTOR has fewer attention FLOPs.
E.1 The Compute Multiplier
The multiplier at every scale. Theorem 4 holds for fixed , and . There, the excess risks of the two architectures have the same exponent in , the different coefficients , and the different costs per sample, and (34) is the compute multiplier. We take as a hypothesis that the losses of the full architectures have the same form when the model size also grows, which Model 1 does not capture: a scaling law of the form of Hoffmann et al. (2022), with common exponents and coefficients that depend on the architecture. Under this hypothesis, the compute multiplier is the same at every scale. Let be the number of active parameters, the number of training tokens, and the training FLOPs. Our compute accounting includes the attention FLOPs (Appendix C.1). At a fixed context length,
where is the FLOPs of the projections and the experts, and is the ratio of the attention FLOPs of architecture to these FLOPs. For equal shapes and balanced routing, (19) gives for NESTOR (N) and the MoE transformer (F), where is the average of over the layers of NESTOR.
Proposition 3: For each architecture , let and , where and are constants. Let and . Then
For every loss , the compute at which the MoE transformer reaches , divided by the compute at which NESTOR reaches , is
The multiplier (26) has two factors. The first is the saving in attention FLOPs, and the second is the ratio of the coefficients of the law. The ratio of Theorem 4 is an example of the latter at a fixed size, and the second factor of (34) is the former. Neither factor depends on L, so under the hypotheses of the proposition the multiplier stays constant while the difference of the losses goes to zero. In Figure 2, the fitted exponents of NESTOR and of the MoE are equal to three digits, and the measured multiplier has no trend over our four scales. The fits have separate offsets, which the proposition does not allow; we discuss their effect at the end of Appendix E.3. Appendix E.3 also extends the proposition to a ratio that changes with the model size, and to the training path of our experiments, which has a fixed ratio T/N.
E.2 Long Contexts
The attention FLOPs of one token are proportional to the context length S, and the other FLOPs do not depend on S. Let be the context length at which the two are equal for the MoE transformer, so that and . The first factor of (26) is then
In the context extension experiments the models are fixed and S grows. For equal shapes and balanced routing, at equal FLOPs NESTOR is trained on times as many tokens as the MoE transformer. For our models the measured counterpart is (Table 7), which also accounts for the slightly different shapes of the two architectures (Figure 10). The multiplier increases with S and converges to , as we show below. This explains why the margin at equal FLOPs grows with the context length in Figure 4. At equal tokens the margin is unchanged, which agrees with the assumption of Section 5 that the restricted context is sufficient for the prediction. In pretraining, S is fixed and the width D grows. The length is proportional to D, because the attention FLOPs grow as SD and the other FLOPs as . Then , and the pretraining advantage at large width must come from the second factor of (26).
We now derive and the properties of . In one layer, let a token cost FLOPs in the projections and the experts of either architecture and FLOPs in the attention of the MoE transformer. By (19), it costs FLOPs in the attention of NESTOR. We sum over the layers and obtain and with . In the backward pass, all costs are multiplied by the same factor. For a layer of width , is proportional to and to , so is proportional to . The accounting of Appendix C.1 gives for our models. The ratio of (27) has the derivative and the limit as .
To express the saving in terms of the loss, we assume a learning curve for the continued training of NESTOR at the context length S,
where accounts for the pretrained initialization. Let be the loss of the MoE transformer minus the loss of NESTOR when both are trained on T tokens. When NESTOR is trained on tokens at equal FLOPs, the difference is
The second term is positive and increasing in . Therefore grows with when and change little with , which agrees with Figure 4.
E.3 Proof of Proposition 3 and Extensions
The law has the form of Hoffmann et al. (2022). Clark et al. (2022) study routed models, where the exponents can depend on the number of experts. At the fixed sparsity of our experiments, the relation between the stored and the active parameters is absorbed in .
Proof of Proposition 3. Let , and substitute . As a function of , the excess loss is the sum of decreasing and increasing exponentials. It is strictly convex and diverges at both ends, so it has a unique minimizer, where . With , , and
Since and , we obtain
Their sum is (25), and solving it for F at a loss gives , giving (26).
Attention ratio that depends on the model size. At a fixed context length, the ratio decreases as the width grows (Appendix E.2), so it is a function . The frontier then has no closed form, but the comparison of the architectures remains valid. Suppose that , , and for all . Let be any allocation of the MoE transformer with compute . With the same compute, a model of NESTOR of size can be trained on tokens, and . Therefore NESTOR has the lower frontier at every .
Fixed ratio of tokens to parameters. Our models are trained with for a constant , which is not the optimal allocation. On this path, and . Let and . Architecture reaches the loss at the size , and the ratio of the compute of the two architectures at this loss is
This has the same two factors as (26). The second factor is constant. The first factor is constant when is constant, and then is one power law in , which is the form fitted in Figure 2. When the width grows at a fixed context length, the first factor converges to 1, and the multiplier converges to . If , the two terms of change their relative size with , and the multiplier depends on . In this case , , and are still sufficient for NESTOR to have the lower loss at every when the compute increases with : with the same compute, a model of NESTOR that is at least as large can then be trained on at least as many tokens. The fits in Figure 2 have a separate offset for each architecture, and the offset of NESTOR is lower. A lower limit for NESTOR makes the multiplier grow with the scale.
F Theoretical Analysis
In this section we give the formal versions of the results stated informally in Section 5, together with further discussion. The setup is that of Section 5: the data are generated by Model 1, the nested and flat predictors (5) are fit by least squares, and a fit is measured by its excess risk, both as in (6). We state the results on sample and compute efficiency in Appendix F.1 and on forgetting in Appendix F.2, prove them in Appendices F.3 and F.4, and compare the nested predictor with other flat predictors in Appendix F.5.
F.1 Sample and Compute Efficiency
We write for the -th standard basis vector. The narrow flat predictor is the flat predictor in (5) whose attention score is computed from the raw tokens rather than from the product features, so that its score is for a matrix that is shared by all pairs of labels, and its values are as in (5).
Theorem 4: In Model 1, let , and let and be least squares fits of the nested and flat predictors (5) on T samples.
(a) Both predictors can represent the regression function : the nested predictor with , , and , and the flat predictor with , for , , , and . The narrow flat predictor cannot represent for any value of its weights.
(b) As , we have and in distribution, where
The limits have the means and , and .
(c) Let , and let a sample cost FLOPs when scores are computed for context tokens, so that the expected FLOPs per sample are and . If predictor is trained on samples, then F \mathcal{E}(\hat{\mathbf{f}}^s) \leadsto \sigma^2 F_s \chi_d_s^2, whose mean is . The two means are equal when the flat predictor uses
times the FLOPs of the nested predictor, and increases from at to as .
Interpretation of part (a). The two predictors can represent the same target, because the experts of the flat predictor can include the value maps of the columns, and the blocks of its pattern can implement the routing. The second requires that the score of the shared attention depend on the labels of both tokens, which is impossible for a bilinear score of the raw tokens: in the narrow flat predictor, the term of the score that is bilinear in does not depend on the labels, so it cannot vanish on the tokens of the other labels and equal on the relevant tokens. With the product features, the input of the shared attention is C times wider, and Remark 8 gives the same construction for the full architectures. Part (b) quantifies the statistical cost of this width.
Interpretation of part (b). The predictors differ in the quantities estimated from data. The number is the dimension of the set of functions that a predictor can represent near the target, which is the number of directions in weight space that change the prediction. It is smaller than the number of stored weights, because is redundant, an invertible change of the hidden units does not change the prediction, and multiplying the pattern of a label by a constant and its maps by the inverse does not change the prediction, which accounts for the term in both counts. Each dimension adds to the mean of the limit of , as in the classical asymptotic theory of least squares over a smooth model (Vaart, 1998; Geyer, 1994).
The three terms of (33) are the patterns, the row spaces, and the maps; the last two are shown in Figure 5b,c. In the nested predictor, one pattern per column is estimated from the tokens routed to the column. In the flat predictor, one block per pair of labels is estimated, i.e., blocks, of which the blocks with are zero at the target: in the flat predictor these zero blocks must be estimated from data, whereas in NESTOR the tokens of the other labels are removed by the routing before the pattern is applied. A matrix of rank is determined by its row space and by a linear map from the row space to . The row space is an -dimensional subspace of and has free parameters, and the map has . In both predictors, a separate map is estimated for each of the CE experts. In the flat predictor each expert has its own , so the row space of each expert is estimated from the samples of that expert only. In the nested predictor all experts of a column have the row space of , which is estimated from the samples of all experts of the column. Altogether,
where the first term is due to the routed attention and the second to the nesting of the experts in the columns. If the flat predictor is fitted on kT samples, then . This limit has the same mean as the limit of the nested predictor on T samples when . We use this ratio of the limiting means to compare the sample sizes needed by the two predictors. It equals at , where a row space has no free parameters, and it tends to as for fixed and . Dropping the terms of lower order in and in gives the forms (7): , , and the ratio with , which decreases in from to when .
The dimensions in (33) do not depend on the label probabilities or the context length S. An expert with probability is used on about samples, so its weight error is larger by a factor . It is also used with probability , and the two factors cancel in the excess risk (6). Every module therefore adds to the mean of the limit for each of its dimensions, however few samples it is used on. The count includes all C patterns, C value maps, and CE experts, so it accounts for the cost of specialization.
Nesting requires both column-routed attention and experts within the columns, which agrees with Table 4, where neither part alone improves the loss. With , the nested predictor is a flat predictor, and the narrow flat predictor represents the target. With column-routed attention and experts shared by all columns, the predictor is . The column space of is contained in that of , which has dimension at most , so this predictor represents the target only if, for each , the maps have the same column space for all . Nesting also helps only when the coarse variable changes the computation. If every token were relevant to every query and neither the patterns nor the row spaces of the depended on , then a shared attention with a label-free pattern and a value map of width , followed by the experts, would represent the target with one pattern and one row space, whereas the nested predictor would estimate a separate copy of both for each column.
Interpretation of part (c). The excess risks of the two predictors decay at the same rate in the number of samples, and they differ in the coefficient and in the cost of a sample. The multiplier (34) is the product of the two ratios. The first factor, , is the cost of the estimation of the pattern blocks and CE row spaces of the flat predictor. The second factor, , is the cost of scoring all context tokens when only of them are relevant; it is the multiplier of (27) with the fraction of active columns, and is the crossover length of Section 4.2, at which the cost of scoring the context equals the other cost of a sample. Appendix E derives the same multiplier for the full architectures from a scaling law hypothesis. This explains Figure 4: at equal tokens the two predictors differ by the first factor alone, and at equal FLOPs the second factor grows with the context length. At a fixed context length, grows with the cost of the maps, so the second factor tends to one as the width grows, and the advantage at large widths in Figure 2 is the first factor.
F.2 Forgetting
We formalize the continual training of Section 5. The new domain Q is a distribution over : the fine label is drawn with probability , the context is drawn as in Model 1 with the query label , the summary is computed with the pattern of the label , and for fixed matrices and noise as in Model 1. Let , and let under Model 1; both are positive definite. The initial weights of both predictors are those of Theorem 4(a). The weights of each predictor follow the gradient flow of the population loss
where is either predictor in (5). The forgetting at time on the old data with the labels is
which is the increase of the risk of Model 1 on these labels.
Proposition 5: In the setting above, let and .
(a) For the nested predictor, , , and stay at their initial values, so and for all .
(b) For the flat predictor, the blocks and the experts stay at their initial values, so
for all , and as ,
Moreover, , so if and only if . The leading coefficient in (38) is zero if A_c^\star A_{c_Q}^\star^\top = \mathbf{0}, and it is positive if A_c^\star A_{c_Q}^\star^\top is invertible and .
When the rows of and of are orthonormal, the singular values of A_c^\star A_{c_Q}^\star^\top are the cosines of the principal angles between the two row spaces, so this matrix is the overlap matrix by which Doan et al. (2021) characterize forgetting in the linearized regime. In this case, since is injective and is invertible, the leading coefficient of (38) lies between and , where are the principal angles. In the proposition, the two predictors are compared at equal time under gradient flow. In training on , the pattern blocks and the experts of the label of the flat predictor change, as do the weights of the column of the nested predictor, and in addition changes. The change of is the only source of forgetting on the other coarse labels. The nested predictor has no such shared weight, and only its column changes. Since is redundant, the flat predictor with held fixed has the same function class, and it has no forgetting on the other coarse labels either. The forgetting in part (b) is therefore due to training a value map shared by all labels, as in the MoE transformer in Section 4.1.
F.3 Proof of Theorem 4
Both predictors are linear in a fixed set of polynomial features of the context, so least squares over a predictor is least squares over a class of functions inside one finite-dimensional linear space. Least squares over a class is a projection of the unconstrained least squares estimator onto the class. The error of the unconstrained estimator is asymptotically an isotropic Gaussian vector in the norm that defines the excess risk, and after the projection only its component in the tangent space of the class remains. The limit of is therefore times a variable whose number of degrees of freedom is the dimension of the class at the target. The dimension is the number of weights of the predictor minus the dimension of the set of reparametrizations that leave the prediction fixed, which we compute with the following lemma.
Lemma 6: For , let be the map z from to , an element of the finite-dimensional space of polynomial maps that are linear in and homogeneous quadratic in , and fix a norm on .
(i) if and only if or , and there is with for all .
(ii) Let W be invertible and . Then if and only if for some , and the differential of P at vanishes on if and only if for some .
Proof. Since , the map sends to , so if and only if for all .
Part (i). If , then every lies in ker or in ker , and a vector space is not the union of two proper subspaces, so or . is bilinear and continuous and does not vanish on the compact set , so its minimum there is positive, and the bound follows by homogeneity.
Part (ii). Let , which is open and dense. For , the matrix is nonzero of rank one, so and for a scalar . Hence every is an eigenvector of . A linear map for which every vector of a nonempty open set is an eigenvector is a multiple of the identity: for linearly independent eigenvectors and small , the vector is an eigenvector only if and have the same eigenvalue, so the eigenvalue is constant on , which spans . Therefore for some , and then on , hence everywhere. The converse is clear. The differential of at sends to . If this vanishes, then for the two rank-one terms cancel, so and for a scalar , and the argument above gives and . The converse is again clear.
Proof of Theorem 4. Part (a). The two constructions represent by substitution: in the flat predictor, the terms with have the score zero, and the remaining sum is . For the narrow flat predictor, write and suppose that it represents . Then, for every and every configuration of the labels of the context, the two predictions agree for almost every , hence as polynomials. Setting for gives the identity
where and . Write , where , , and depend on and does not. The right side of (39) with is nonzero, so . Since , there is , for which the right side is zero; then the score vanishes for all and all , hence identically, so . For , the left side then has no term of degree one in and two in , whereas the right side is in the notation of Lemma 6, which is of exactly these degrees and nonzero by Lemma 6(i). This contradiction proves the claim.
Part (b), the function space. Let H be the space of functions of of the form
with as in Lemma 6. Both classes lie in : the nested predictor has and for , and the flat predictor has . Define , so that . This is a norm on : if , then for every and every configuration of the labels, which has positive probability, the sum in (40) vanishes for almost every , hence as a polynomial, and setting all but one of to zero shows that every . In particular a function in determines its components , and is finite since the contents have finite moments. Let be the empirical norm. By the law of large numbers applied to a basis of , uniformly on the unit sphere of , almost surely, so is eventually a norm and the unconstrained least squares estimator is eventually unique. By the normal equations, for every ,
So a least squares estimator over a closed class is a projection of onto in the norm .
Since and is independent of with mean zero and covariance , the unconstrained problem is a linear regression with the feature map given by a basis of , and the central limit theorem gives , where is a centered Gaussian vector with covariance and is the Gram matrix of . That is, is an isotropic Gaussian vector with variance in the norm .
Part (b), the limit. Let be a closed class that contains and is, near , a smooth manifold of dimension with tangent space at . Its least squares estimator satisfies , so . The objective in (41) is quadratic, its Hessian converges to that of , and a smooth manifold is Chernoff regular with tangent cone . The theorem on constrained estimators of Geyer (1994, Section 4) then gives , where is the projection onto that is orthogonal in . By the continuous mapping theorem, , which has the distribution .
Part (b), the classes are manifolds. It remains to show that the two classes are smooth manifolds near and to compute their dimensions. We parametrize each class by the matrices that enter Lemma 6. The matrices of rank in form a smooth manifold of dimension , and since the rank is lower semicontinuous, the closed set of matrices of rank at most coincides with this manifold near each of its points. For the nested predictor, let stack . A rank factorization shows that for some and if and only if rank . The nested class is therefore the image of the polynomial map on the domain , with . For the flat predictor, with attains every matrix of rank at most , so the flat class is with on , with . The targets are and with and for . Since is injective and is surjective, rank , so each domain is a smooth manifold near its target, of dimension
Both classes are closed, so the least squares estimators exist. Let with , and call , respectively , the pattern blocks of the label . If they are all zero, then so are the components of with the query label , and we may replace by and the pattern blocks by any blocks of unit norm without changing or leaving . Otherwise, the action of defined below rescales the pattern blocks of the label to unit total Frobenius norm without changing . After this normalization, for each some pattern block of the label has , and Lemma 6(i) gives , which is bounded because the components of converge. Hence is bounded, a subsequence converges to some in the closed set , and by continuity.
Let . The group acts on by and , respectively for all , and is invariant under this action. We claim that near the differential of on the tangent space of has the kernel of dimension exactly that is tangent to the orbits, and that the fiber is the orbit of . For the fiber, Lemma 6(ii) applied to the components , where is invertible and , gives and , where does not depend on because the pattern is shared by the experts of the label ; and for the flat predictor, Lemma 6(i) applied to the components with , where vanishes and , gives . For the kernel, the tangent space of the orbit through a point of consists of the directions , , and it has dimension wherever the blocks of each label are not all zero, which is an open condition that holds at the target; the kernel contains it by invariance. At the target, the kernel is no larger: Lemma 6(ii) applied to the components gives and with common to the experts of the label, and, for the flat predictor, the components with reduce to , so by Lemma 6(i). Since the rank of the differential is lower semicontinuous, it is at least near the target, and it is at most this wherever the orbit has dimension . Hence has the constant rank near , and by the constant rank theorem there is a neighborhood of in such that is an embedded submanifold of of dimension .
We show that coincides with near . Otherwise there are with and . The components of converge to the nonzero components of , so by Lemma 6(i) the diagonal blocks of are eventually nonzero, and by the invariance of we may rescale so that they have the Frobenius norms of the . The bound in Lemma 6(i) then shows that the of are bounded and, since the components are bounded away from zero, also bounded away from zero, so that all blocks of are bounded. A subsequence converges to some in the closed set with , which lies in the orbit of . Applying the inverse group element to the subsequence gives points of with the same images, a contradiction. Therefore is a smooth manifold of dimension near , the limit above applies, and (42) gives (33). The difference (35) is positive for , and
since gives .
Part (c). With samples, F\mathcal{E}(\hat{f}^s) = F_s \cdot T\mathcal{E}(\hat{f}^s) \leadsto \sigma^2 F_s \chi_d_s^2 by part (b). The means at the budgets are equal when , and is increasing in with the stated limits because is.
F.4 Proof of Proposition 5
Proof of Proposition 5. The summary of Model 1 has : for , on the event the scalar is a nonzero polynomial, because is invertible, so it is nonzero almost surely. The same argument gives .
The loss (36) depends on the weights only through the predictions . For the nested predictor these depend only on , and , so the gradient with respect to , and is zero for , these weights stay at their initial values, and . This is part (a).
For the flat predictor, depends only on the blocks , the experts of the label , and . Hence the blocks and the experts of a label stay at their initial values , and , so that , and
On the new domain the pattern is that of the label , so at the predictor's summary equals the summary of . Since has mean zero and is independent of , for any matrix we have , and therefore
using at . Since is injective, this gradient is zero if and only if . The vector field of the gradient flow is polynomial in , so is smooth and . Substituting into (44) gives (38). As is injective and invertible, the leading coefficient is zero if and only if ; this holds when , and when is invertible it holds if and only if .
F.5 Further Comparisons
We give two remarks on the scope of Theorem 4: the first is on other shapes of the flat predictor, and the second relates the product features of the flat predictor to the full architectures.
Remark 7: The comparison in Theorem 4 does not depend on the shape of the experts of the flat model. If its experts have rank , its class contains , so its tangent cone at contains the tangent space of . The class is the image of a polynomial map and therefore Chernoff regular (Drton, 2009, Lemma 3.3), the limit of is the squared norm of a projection of onto , and for a closed cone this is . Wider experts therefore do not reduce the limit. If and the row spaces of the matrices are linearly independent, the flat model can also represent the target with a shared value map that stacks the matrices and experts of rank , i.e., linear MLPs with hidden units. The map is invariant to , for invertible , and the kernel of its differential at the target consists of these directions only, because there. The map terms of the dimension of this class at the target are therefore , which exceed the map terms of by , while the pattern terms are those of . The extra terms count the expert parameters needed to pick out the coordinates of a column from the Cr outputs of .
Remark 8: An MoE transformer can simulate a column of NESTOR with a residual stream that is wider by a constant factor. Consider one head of column c, with logits and values for . In an MoE transformer, let the experts of the preceding layer be routed by the column labels, and let the expert for the label c output , , and in separate coordinates of the residual stream. A shared head whose queries, keys, and values are these coordinates has the same logits and values for all pairs of tokens in the same column, and the following experts can apply the output map of the column. The pairs in different columns are removed by adding to the logits, which needs C more coordinates and is exact as . This simulation has the same number of stored parameters as the columns. It needs a residual stream that is wider by the total width of the queries, keys, and values of the active columns. This width is a constant multiple of D, and it increases the size of every other matrix. We therefore expect the two architectures to differ by constants at equal resources. The product features of the flat predictor in (5) are this construction for one layer, and Theorem 4 gives the resulting constant; Proposition 3 in Appendix E shows that a constant in the coefficients is a constant compute multiplier.