Paper commentary
Residual Matrix Transformers: Scaling the Size of the Residual Stream
Residual Matrix Transformers replace the residual stream with outer product memories
- Problem Widening a transformer's residual stream also enlarges every weight matrix that touches it, so the stream cannot scale cheaply on its own.
- Method Residual Matrix Transformer (RMT) replaces each residual vector with a per-token matrix of outer products, read back with key vectors.
- Results RMT matches the transformer's loss with 58% fewer FLOPS and 25% fewer parameters on the largest pair.
Why a wider residual stream costs parameters and FLOPs
The residual stream is the channel through which transformer layers pass features to one another, and its width sets how many features it can hold. Because every matrix that touches the stream must match its width, widening the stream resizes all of them. Figure 1 plots model size and per-example FLOPS against residual stream size for both architectures.
The transformer curves rise with the stream, because its parameter and FLOP counts scale proportionally to the residual stream size.
The authors fix all model dimensions to those of GPT2-medium and vary D for the transformer. Raising the transformer's residual stream size by 100% brings a 100% increase in parameters and about 94% more FLOPS. The width knob is therefore tied to the cost of the whole network, not just the stream itself. As in a regular transformer, widening the stream also raises training memory, because residual activations are saved for gradient checkpointing.
The authors note that scaling is moving toward the limits of available data and energy. Under those limits, a width knob that drags parameters and FLOPs along becomes expensive to use. They address the coupling by replacing the residual stream with an outer product memory matrix. With that change, the relationship between stream size and parameter and FLOP count becomes nearly constant for typical transformer dimensions.
Replacing the stream with a per-token matrix memory
The RMT keeps a matrix for each token instead of a single residual vector. That matrix is built by summing outer products of key-value vector pairs, a construction the authors take from Kohonen (1972) and Anderson (1972). Each term in the sum pairs a key vector with a data vector, so one memory holds many such pairs. Each token's residual matrix is sized Dk × Dv, where a standard residual stream vector would be sized D.
A stored data vector is read back by contracting the matrix with its key vector over the first dimension. The paper writes this read as an approximation of the stored vector, not an exact lookup. The raw sum is unnormalized, so the pre-LayerNorm operations supply the normalization that Eq. 12 lacks.
The embedding layer forms each initial residual matrix by summing R outer products of learned keys and embeddings. In attention, key vectors replace the W_Q, W_K and W_V matrices, and tensor contractions replace matrix multiplies. Each attention head output is a data vector tied to its own key vector w_O before it is added to the residual matrix.
The authors vary Dk while holding Dv fixed at 64 for the GPT2-medium shapes. Scaling Dk by 100% raises the RMT's model size and FLOP count by less than 1%. A transformer whose residual stream grows by 100% gains 100% in parameters and about 94% in FLOPS. The design trades cheap key vectors for a residual matrix that can be enlarged without resizing the other layers.
One RMT layer step by step
The transformer baseline stacks an embedding with alternating attention and feed-forward layers, each adding its output back to the stream. The RMT keeps this recurrence but changes what a residual instance is: a tensor of shape Dk × Dv × N with one matrix per token. The embedding builds these matrices from R outer products, where R is a hyperparameter.
Each term pairs a learned key vector with a token or position input, so the initial residual matrix already stores outer product memories.
In attention, the query, key and value for each head come from contracting the residual matrix with three learned key vectors. Those key vectors replace the W matrices of the transformer, and the contraction runs over the first tensor dimension. The resulting queries, keys and values keep the dimensions they had in the transformer, so the softmax attention step is unchanged.
Each head output then becomes a data vector paired with its own key vector w(h)O, and the sum is added back to the residual matrix.
The feed-forward weights W1 and W2 are kept, and the RMT adds key vector adapters around them. The adapter retrieves R data vectors with key vectors and concatenates them into one input for the standard feed-forward operation. The output is split back into R vectors with unvec1, and each one is written into the residual matrix with its own key vector.
The authors keep the weights because they cite evidence that feed-forward weights store factual information, so these weights do more than read in and write out features.
For the output, the unembedding layer retrieves R data vectors from the final residual matrix with key vectors. Each retrieved vector is multiplied by its own unembedding weight, and the products are summed into the logits.
Keeping variance stable at initialization
Glorot and Bengio treated mean and variance passing through linear layers at initialization as a central test for deep networks. The RMT replaces its storage and retrieval steps with outer product memory operations, so the authors test those operations against the linear maps they replace. The authors draw the transformer rows of Table 1 from Kedia et al.
and derive the RMT rows themselves.
If weights are initialized independently with zero mean, the propagated mean is zero for RMT storage and retrieval. The backward mean is zero too, because each gradient term multiplies a zero-mean weight. On mean propagation, the RMT behaves the same as the transformer's linear transformations.
They plug GPT2-medium shapes and Xavier initialization into the variance expressions to get the ratios in Table 2. For attention storage, the RMT gives a forward ratio of 0.4 and a backward ratio of 1.6, versus 1 and 1 for the transformer. For feed-forward storage, the RMT gives 1 and 1, while the transformer gives 1.6 and 0.4. Feed-forward retrieval gives the RMT 1 and 1, against 0.4 and 1.6 for the transformer.
The authors judge the RMT favorable in every case except the attention storage operation. Their check uses one initialization and the forward and backward ratios, so it doesn't measure training dynamics.
How parameters and FLOPs change with width
The authors start from Hoffmann et al.'s formulas for transformer parameters and per-example compute, then derive matching RMT formulas in the appendix. They fix every model dimension to GPT2-medium and vary D for the transformer and Dk for the RMT. Dv stays at 64 while the residual stream width changes.
In the RMT, key vectors replace the attention weight matrices for queries, keys, values and outputs. The total RMT parameter count comes to R(2Dk(3L + 1) + Dv(2LDFF + V + N)). The RMT FLOP count adds up the embedding, attention and feed-forward terms over the L layers. The backward pass is approximated as twice the forward pass count.
For the transformer, a 100% larger residual stream means a 100% larger parameter count and about 94% more FLOPS. For the RMT, the same 100% increase changes model size and FLOP count by less than 1%. Figure 1 plots model size and per-example FLOPS against residual stream size for both models. The authors describe the RMT's parameter and compute cost from width as practically zero.

Figure 1 . Model size and per-example FLOPS versus residual stream size for the transformer and RMT. See §3.1 for details.
Original paper · CC BY 4.0 · Mak, Brian, Flanigan, Jeffrey · Residual Matrix Transformers: Scaling the Size of the Residual Stream · Original paper figure · Extracted the figure area from page 1 of the original PDF.Width still costs memory during training, because residual stream activations must be saved for gradient checkpointing. The RMT doesn't escape this cost, since its residual stream is scaled in the same way.
Pretraining the RMT against the transformer at matched scale
The authors pretrained both architectures on OpenWebText, tuning hyperparameters for each with µParam Transfer. The RMT residual stream was set to 2.5 to 4 times larger than its transformer counterpart, and each run stopped at its Chinchilla optimal token count. The authors used the standard transformer hyperparameters for the variant comparison in §4.3, because tuning every variant was too expensive.
Across these sizes, the RMT loss curve sits below the transformer's when plotted against FLOPS and model parameters. The authors read this as more efficient scaling in both FLOPS and parameters.
On the largest pair, the RMT reached the transformer's minimum train loss of 3.03 with 58% fewer FLOPS, 41% fewer tokens and 25% fewer parameters. The parameter counts are 405M for the transformer and 305M for the RMT.
After 6B training tokens, the RMT used 28% fewer FLOPS than the transformer, and it reached a dev loss of 2.91 against 3.02. The same run took 43% more training time for the RMT. The authors attribute the parameter saving to replacing the attention weight matrices with key vectors, which leaves the RMT with 33% fewer non-embedding parameters.
The authors argue the FLOP gap matters for energy use. The paper reports FLOPS and not energy, so the energy claim stays unmeasured.
Runtime and memory at training and inference
The RMT's FLOP advantage does not carry over to wall-clock time, because each train step is slower for the RMT. The RMT took 7.17s per train step, while the transformer only took 4.06s. Over the largest runs, the RMT's time came out 4% higher at the Table 3 point, and 43% higher when training on 6B tokens. The authors name runtime as the biggest limitation of their model.
They expect a hardware-aware implementation to significantly improve runtime, but they treat it as out of scope.
Training memory is about equal for both models, according to a batch size search on the largest models. Scaling the RMT's residual stream still raises training memory, because residual stream activations must be saved for gradient checkpointing. The authors infer that the extra checkpoint storage for the expanded residual stream is offset by the reduced model size.
At inference time, the RMT is more memory efficient, because it doesn't need to keep residual stream instances for gradient checkpointing. The savings from the smaller model outweigh the expanded residual stream at inference.
The authors hypothesize that the slowdown comes from replacing highly optimized GEMM operations with unoptimized tensor contractions. The contraction dimension of the RMT's tensor contraction is small compared to the transformer's embedding dimension.
Against prior residual-stream variants
The authors compare the RMT with three transformer variants that each modify how the residual stream is carried. Those variants are Highway Transformer, Depthwise LSTM and Hierarchical Aggregation. Every model used standard transformer hyperparameters, because tuning each variant was too computationally demanding.
The RMT used a residual stream of 2048, while the transformer and the three variants used 768. Figure 5 plots these runs as loss against FLOPS and against model parameters.

Figure 5 . RMT versus other transformer variants that modify the residual stream (Vaswani et al., 2017, Dou et al., 2018, Chai et al., 2020, Xu et al., 2024).
Original paper · CC BY 4.0The authors call the RMT the most compute and parameter efficient variant in this collection. They conclude that the prior variants' improvements are outweighed by their cost in these replications. Because all models share the transformer's hyperparameters, the ranking holds only for that shared setting.
They didn't test combining the RMT with these variants. The authors note that residual stream modifications can be combined with the RMT.
Does widening the residual stream help at fixed compute?
The authors trained GPT2-small-sized RMT models with residual stream sizes 384, 768, 1536, 2048, 3072, and 4096. Only the residual key dimension Dk changes across these models, so the core computation stays the same. The authors chose Dk because varying it leaves the model's core computations alone, which isolates the effect of the residual stream.
Dev loss fell monotonically as the residual stream grew, which the authors read as expanding the stream improving performance. Model size, dataset size, and computational budget were held constant for every run in this sweep. At residual size 4096, the RMT trained to the same final loss as the 768 model with 23% fewer FLOPS and 25% fewer tokens.
The 768 size matches GPT2-small, so that is the usual width the comparison starts from.

Figure 6 . Dev loss vs residual stream size. Model size, dataset size, and computational budget are held constant for all runs. Residual stream size is calculated as Dk × Dv.
Original paper · CC BY 4.0At residual size 768, the RMT reached a final train loss of 3.42, while the GPT2 model reached 3.43. So the gain comes from the wider stream, and without widening the RMT performs about as well as the transformer. The comparison used the same experimental settings as the earlier RMT versus transformer experiments.
Zero-shot downstream results
The authors ran zero-shot evaluations on their largest pretrained models, both trained on all 6B tokens. On the four perplexity datasets, a lower score means a better fit, and the RMT scores lower on every one. On LAMBADA OpenAI, the RMT reaches 25.21 where the transformer reaches 61.34. On OpenWebText the RMT scores 18.36 against 20.64 for the transformer.
On The Pile 10K the RMT scores 23.54, compared to 30.23 for the transformer. On WikiText the RMT scores 55.94, while the transformer scores 76.35. The LAMBADA perplexities came from the EleutherAI evaluation harness, and the other perplexity numbers were computed by hand.
The five accuracy tasks use the opposite reading, where a higher score is better. The RMT is ahead of the transformer on every one of these five tasks. The smallest gap is on ARC C, where the RMT scores 20.6 against 19.7 for the transformer. On ARC E the RMT reaches 46.1, compared to 44.3 for the transformer. On HellaSwag the RMT scores 30.5, while the transformer scores 28.7.
On PIQA the RMT scores 63.7 and the transformer scores 61.9, and on WinoGrande the RMT reaches 52.5 against 49.5.
These gains came with the RMT using 25% fewer parameters and 28% fewer FLOPS during training. These are zero-shot results for one pair of largest models only, so they don't show how the gap behaves at other sizes.
Limitations of the residual matrix transformer
The authors name runtime as the biggest limitation of the RMT, and they only suggest a fix. They expect a hardware-aware implementation would significantly improve runtime, but they didn't build one. They hypothesize that much of the slowdown comes from replacing highly optimized GEMM operations with unoptimized tensor contractions.
Memory is another limit, because scaling the residual stream of the RMT still raises training memory use. Residual stream activations must be saved for gradient checkpointing, just as in a regular transformer. The RMT's memory advantage therefore appears at inference time, not during training.
The residual stream scaling study varies only the residual key dimension Dk, which leaves the core computation unchanged. That study covers only GPT2-small sized RMT models, with residual stream sizes from 384 to 4096. The variant comparison uses the transformer's hyperparameters, since tuning every variant was too computationally demanding.
Paper info
- Authors
- Mak, Brian, Flanigan, Jeffrey
- Venue
- arXiv · Preprint
- First published
- 2025-6-28
- Added
- 2026-10-29
- Updated
- 2025-6-28
- Version
- v1
- arXiv
- 2506.22696
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Abstract
The residual stream acts as a memory bus where transformer layers both store and access features (Elhage et al., 2021). We consider changing the mechanism for retrieving and storing information in the residual stream, and replace the residual stream of the transformer with an outer product memory matrix (Kohonen, 1972, Anderson, 1972). We call this model the Residual Matrix Transformer (RMT). We find that the RMT enjoys a number of attractive properties: 1) the size of the residual stream can be scaled independently of compute and model size, improving performance, 2) the RMT can achieve the same loss as the transformer with 58% fewer FLOPS, 25% fewer parameters, and 41% fewer training tokens tokens, and 3) the RMT outperforms the transformer on downstream evaluations. We theoretically analyze the transformer and the RMT, and show that the RMT allows for more efficient scaling of the residual stream, as well as improved variance propagation properties. Code for this project can be found at https://github.com/bmac3/residual-matrix-transformer.
Quote from the paper
Mak, Brian, Flanigan, Jeffrey (2025). Residual Matrix Transformers: Scaling the Size of the Residual Stream. arXiv:2506.22696v1. https://arxiv.org/abs/2506.22696v1
BibTeX
@misc{brian2025residual,
title = {{Residual Matrix Transformers: Scaling the Size of the Residual Stream}},
author = {Mak, Brian and Flanigan, Jeffrey},
year = {2025},
eprint = {2506.22696},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2506.22696v1}
}