Foundation reference

Mixture-of-Depths

Mixture-of-depths (MoD) uses a learned router to send selected tokens through a transformer block while the other tokens skip it. MoD models matched baseline transformers trained with the same FLOPs and wall-clock time while needing only a fraction of the FLOPs per forward pass, and were upwards of 50% faster per step when sampling (Raposo et al., 2024).

Concept 95 of 100EfficiencyStudy phase 13
Key equation
htℓ+1={htℓ+rt [fℓ(HSℓℓ)]tt∈Sℓhtℓt∉Sℓh^{\ell+1}_t = \begin{cases} h^\ell_t + r_t\, [f_\ell(H^\ell_{S_\ell})]_t & t \in S_\ell \\ h^\ell_t & t \notin S_\ell \end{cases}
Reading map and next steps

Study guide

Where to start

Concept 95 of 100Mixture-of-DepthsEfficiency · Study phase 13: Recent research (2024–2025)
Question

Which tokens would you expect the router to send through a block, and which to let skip it?

How to study this pagePredict · Check · Generalize · Continue
PredictSay what you expect.

Pick a concrete input and say what the equation should give before you read the math.

CheckCheck against the math and the papers.

Work through the math, then read the cited papers for the original argument.

GeneralizeName what stays the same.

Identify the part of the idea that survives a change of notation or model, so you can recognize it in another paper or system.

ContinueFollow the connections.

Use the prerequisites and related concepts at the end of the page to fill the next gap.

Why It Matters for Modern Models

  • Mixture-of-depths (MoD) uses a learned router to send selected tokens through a transformer block while the other tokens skip it. MoD models matched baseline transformers trained with the same FLOPs and wall-clock time while needing only a fraction of the FLOPs per forward pass, and were upwards of 50% faster per step when sampling (Raposo et al., 2024).
  • It is related to mixture-of-experts: both use learned top-k routing, but MoE chooses which expert processes a token, while MoD chooses whether a block processes it at all.
  • Unlike earlier adaptive-computation schemes, in which the amount of computation varies with the input (Graves, 2016), MoD fixes the total compute per block in advance, which keeps the computation graph static and the cost predictable.

Questions to Think About

  • Why does multiplying the block output by the router weight matter for training, when the top-k choice itself is not differentiable?
  • Why is choosing the top k tokens over a whole sequence a problem for generating text one token at a time, and how does predicting the choice get around it?

Core Math

Key Equation
htℓ+1={htℓ+rt [fℓ(HSℓℓ)]tt∈Sℓhtℓt∉Sℓh^{\ell+1}_t = \begin{cases} h^\ell_t + r_t\, [f_\ell(H^\ell_{S_\ell})]_t & t \in S_\ell \\ h^\ell_t & t \notin S_\ell \end{cases}

Mixture-of-depths (MoD) lets each block of a transformer process only some of the tokens in a sequence; the others skip the block through the residual connection (Raposo et al., 2024).

At block ℓ\ell, a learned router gives each of the nn tokens a scalar weight rtr_t. Only the kk tokens with the largest weights, the set SℓS_\ell, go through the block's attention and MLP, written fℓf_\ell. Let HSℓℓH^\ell_{S_\ell} be the selected token sequence; [fℓ(HSℓℓ)]t[f_\ell(H^\ell_{S_\ell})]_t is its output at selected position tt:

htℓ+1={htℓ+rt [fℓ(HSℓℓ)]tt∈Sℓhtℓt∉Sℓh^{\ell+1}_t = \begin{cases} h^\ell_t + r_t\, [f_\ell(H^\ell_{S_\ell})]_t & t \in S_\ell \\ h^\ell_t & t \notin S_\ell \end{cases}

Multiplying the block output by rtr_t puts the router on the gradient path, so it can be trained by ordinary backpropagation.

Because kk is fixed in advance, the compute per block and the tensor shapes are known before the input is seen. With a capacity of k/n=12.5%k/n = 12.5\% on every other block, the setting Raposo et al. found best, 87.5% of tokens skip each routed block.

Choosing the top kk over a whole sequence looks at future tokens, which are not available when generating one token at a time. Raposo et al. therefore train either the router itself, with an auxiliary loss, or a small separate predictor to guess whether each token would have been in the top kk, and use that guess during sampling.

Key Papers

Mixture-of-Depths: Dynamically allocating compute in transformer-based language models

Raposo et al.2024arXiv
Read paper →

Adaptive Computation Time for Recurrent Neural Networks

Graves2016arXiv
Read paper →

Connections

Prerequisites