ByteDance's MoDA Lets Transformers Query Past Layers, Boosting Performance by 2.11%
MoDA lets each attention head reach back into earlier layers directly, delivering 2.11% average downstream gains on 1.5B models with 3.7% extra FLOPs.
ProTakeaways
- MoDA lets each attention head retrieve KV pairs from all preceding layers, addressing signal dilution in deep Transformers. Paper
- Improves 1.5B model downstream average by 2.11% and perplexity by 0.2 across 10 benchmarks with only 3.7% extra FLOPs.
- Hardware-aware Triton kernel hits 97.3% of FlashAttention-2 efficiency at 64K sequence length via chunk and group-aware indexing.
- Naive PyTorch depth attention is 1458x slower; kernel optimizations make training practical at scale.
- Post-norm outperforms pre-norm when combined with MoDA, and the classic attention-sink pattern noticeably weakens.
- Code, kernels, and training recipes for LLM and ImageNet available at hustvl/MoDA.
Every Transformer stack has a communication problem. Since the ResNet skip connection landed in 2015, the residual pathway has been the single highway that shuttles information between layers. Add depth, and shallow features get repeatedly overwritten by residual updates until they are essentially unreachable in the upper stack. A new paper from Huazhong University of Science & Technology and ByteDance Seed argues that the fix is not a better residual, but attention itself, applied along the depth axis.
The mechanism, called Mixture-of-Depths Attention (MoDA), lets every attention head simultaneously attend to the current layer's sequence keys and values and to depth keys and values pulled from all preceding layers. On 1.5B-parameter models trained with the OLMo2 recipe, it improves average perplexity by 0.2 across 10 validation benchmarks and lifts average downstream performance by 2.11% across 10 tasks, with only 3.7% extra FLOPs. The code and Triton kernels are already public.
The signal-dilution tax on depth
Depth is one of the four scaling knobs for LLMs, but it has been the hardest to convert into proportional gains. As Transformers become deeper, informative features formed in shallow layers are gradually diluted by repeated residual updates, making them harder to recover in deeper layers. Prior work tried to patch this by upgrading the aggregation rule itself: DenseNet-style concatenation, DenseFormer's weighted averaging, Hyper-Connections, MUDDFormer. Every one of them still accumulates layer outputs into a single evolving tensor.
The authors reframe the problem: inter-layer communication should be retrieval, not accumulation. Layer 152 should not have to strain to hear the signal from layer 3 buried under 149 additions. It should be able to query for it directly, the same way sequence attention queries earlier tokens.
A design space with four flavors of depth

The paper analyzes stacking through a "read, operate, write" lens and compares four options:
- Depth Residual: the classic
x + F(x)highway. Cheap, but compresses the entire history into one tensor. - Depth Dense: read all prior layer outputs and linearly project them back. Lossless but its computation grows as O(TL²D²) in dominant terms, which is prohibitive for large models.
- Depth Attention: use attention itself to retrieve historical depth KV pairs in a data-dependent way, at O(TL²D).
- Mixture-of-Depths Attention (MoDA): fuse sequence and depth retrieval into a single softmax, where each head jointly attends to the current layer's sequence KV and depth KV from all preceding layers.
MoDA is the interesting point on this frontier because it reuses the query projection from sequence attention, so no extra depth-query projection is introduced. In GQA settings, only grouped depth key/value projections are needed, and even those are inexpensive.
Making it fast enough to actually train
A naive PyTorch implementation is a non-starter. The originating tweet notes a naive depth-attention forward+backward at over 44,000 ms; the author's incremental ablation confirms it at 2128.900 ms in the naive PyTorch baseline versus 1.460 ms with all optimizations, roughly 1458x end-to-end speedup. Depth lookups produce non-contiguous gather-style memory access, which starves tensor cores.
The kernel, built on Triton and Flash Linear Attention, layers three tricks:
- Flash-compatible depth-KV layout: flatten the depth cache along a single axis of length T×L so each query maps to a contiguous slice.
- Chunk-aware depth-KV layout: group queries into chunks of size C, so each chunk only touches a C×L depth region instead of scanning the full T×L axis.
- Group-aware indexing: under GQA, G adjacent query rows share the same base-time index, so they can reuse the same depth-KV blocks, cutting the effective depth span to (C×L)/G.

The result is competitive with FlashAttention-2 in real training regimes. At 64K sequence length the MoDA kernel reaches 97.3% of FlashAttention-2 efficiency, and the relative overhead consistently decreases from 25.86% at T=4096 down to 2.73% at T=65536. The catch is depth scaling: at fixed T=16384 and G=8, MoDA runtime rises from 127.7 ms at L=64 to 168.0 ms at L=256, so very deep stacks are where the overhead concentrates.
Where the accuracy gains actually come from
The ablations reveal a clean design principle. At 700M, just injecting each token's depth KV (reusing the preceding layer's sequence KV, no new parameters) buys 1.17 points of downstream average and 0.11 C4 validation PPL at only 0.12% extra FLOPs. Adding a separate KV projection for the FFN layers, so FFN blocks also emit depth memories, gives another 0.77 downstream points. Adding a dedicated depth KV projection to the attention side barely moves the needle, so it is dropped.

Scaled to 1.5B and trained on 400B tokens from the OLMo2 dataset, the gains persist across categories. WinoGrande jumps from 63.22 to 65.59, ARC-Challenge from 42.47 to 46.82, BoolQ from 63.61 to 67.34, and MMLU from 27.73 to 29.59. Per-domain validation perplexity drops on every one of the ten domains tested, including C4, Pile, Wiki-text, Books, and peS2o.
Two surprises: post-norm returns, attention sinks fade
Two secondary findings are worth flagging. First, combining MoDA with post-norm yields better performance than using it with pre-norm. In the 48-layer study, adding depth KV under post-norm reduced FineWeb-Edu validation loss by 0.0409, versus just 0.0041 under pre-norm. Depth retrieval appears to be a stronger regularizer for post-norm stacks, which have been out of fashion since GPT-2.
Second, the attention heatmaps show something unusual. Rather than collapsing a large fraction of probability mass onto a few fixed sink positions, attention in MoDA heads is distributed more broadly across sequence and depth slots. The attention-sink phenomenon, where a few positions absorb disproportionate mass and can wreck streaming inference, appears to weaken when the model has a legitimate outlet for cross-layer retrieval.
What's actually shipped, and what to watch
The GitHub repository ships MoDA and Flash Depth Attention Triton kernels, a non-causal variant, LLM training recipes based on BlaGPT, and an ImageNet classification recipe using DeiT. Requirements are PyTorch 2.5+ and Triton 3.0+. Testing a kernel is a one-liner:
cd libs/moda_triton
pip install -e .
python3 libs/moda_triton/fla/ops/moda/moda_v14.py
The honest limitations: the depth-KV cache grows linearly with the number of layers, which becomes a memory bandwidth headache at very deep or long-context scales. The authors flag bounded depth-KV slot caching, either top-S selection or a sliding window, as the next step for industrial-scale training. And every result here is at 700M or 1.5B; whether the 2.11% average lift holds at 70B or 400B remains open.