Understanding Adjustable Compute Depth in Recurrent Transformers
Recurrent transformers reuse a shared block across multiple loop steps so effective depth can grow with compute rather than parameter count. This article explains parameter depth versus compute depth, architectural choices such as residuals, step encodings, and adaptive stopping, training for long unrolls, MoE routing across loops, and how to evaluate quality, latency, and stability.
Understanding Adjustable Compute Depth in Recurrent Transformers
1. What “deeper” actually means
Gains in large language models have long tracked a joint expansion of parameters, data, and compute. Scaling parameters, however, also scales memory, deployment cost, and inference latency. A natural question is whether a model can “think deeper” without a large increase in parameters.
In a standard Transformer with L layers, hidden states pass through L distinct blocks:
h^(l+1) = Block_l(h^(l)), l = 0,1,...,L-1
Each layer has its own parameters θ_l. Depth is therefore parameter depth: forty-eight layers means forty-eight weight sets, typically used once per forward pass. After training, that depth is a constant that is hard to change at runtime.
A recurrent Transformer instead applies one shared block repeatedly. Depth can then depend on how many times the block is executed, which is a structural basis for trading extra compute for a deeper effective network.
2. Shared weights and runtime loops
A basic recurrent form is:
h^(t+1) = Block_θ(h^(t), t), t = 0,1,...,T-1
Block_θ is shared; T is the number of loop steps. The main change is not attention or the feed-forward network itself, but reusing the same parameters across steps, each step continuing from the previous hidden state.
A typical layout uses prefix layers, a shared recurrent block, and suffix layers:
def loop_transformer(x, pre_blocks, shared_block, post_blocks, T):h = embed(x)for blk in pre_blocks:h = blk(h)for t in range(T):h = shared_block(h, step=t)for blk in post_blocks:h = blk(h)return head(h)
T can be fixed in training or adjusted at inference: fewer steps for easy inputs, more for hard ones. More loops do not automatically mean better quality. Poor shared-block design can cause representation drift, unstable gradients, or premature collapse. The engineering goal is to keep the same parameters stable across repeats while moving toward a better representation.
Intuitively, if self-attention indexes context and the feed-forward layers store compressed knowledge, the recurrent Transformer repeatedly queries that knowledge under the same indexing, refining an intermediate answer. If the shared block is a mixture of experts (MoE), routing may pick different experts each step and recombine the same parameter space.
3. Parameter depth versus compute depth
| Dimension | Standard Transformer | Recurrent Transformer |
|---|---|---|
| Parameter depth | Set by independent layers | Can be set by number of shared blocks |
| Compute depth | Roughly equal to layer count | Loop count times shared blocks, plus prefix/suffix |
| Parameter growth | Deeper usually means more parameters | Extra loops need not add parameters |
| Runtime control | Weak | Adjustable via T |
| Main costs | Parameters, memory, bandwidth | Compute, latency, stability |
In a standard stack, extra layers usually add parameters; in a recurrent stack, extra T mainly adds compute. That parameter efficiency is useful when memory is tight but FLOPs can vary. It is not free: longer unrolls raise forward/backward cost, latency, and gradient path length. Recurrent transformers are a new trade-off among parameter, compute, and latency budgets—not a drop-in replacement for deep stacks.
4. Architecture choices
4.1 Where to place the shared block, and how large it is
The shared block can sit in the middle or near the output. A middle placement lets prefix layers extract features and suffix layers adapt the output; a late placement looks more like multi-step reasoning. Capacity should match loop count: too small and extra steps add little; too large and the parameter-efficiency story weakens.
4.2 Residuals, normalization, and step encoding
Repeated application can drift hidden states. Common tools are residual connections, normalization, gated updates, and step encodings so the block knows which iteration it is in:
h^(t+1) = h^(t) + Gate_t · Block_θ(Norm(h^(t)), StepEmbed(t))
Gates limit update size; step encodings relax the assumption that every iteration is identical.
4.3 Adaptive stopping
Variable depth needs a stop rule: a light halt head on the hidden state, or random T during training so the model sees several depths. The goal is less compute on easy samples and more on hard ones, balancing average latency and quality.
5. Training: stability first
Long unrolls make gradients vanish, explode, or mismatch inference. Practical tactics include:
- Random T so the model is not locked to one loop count
- Curriculum: start with small T, then increase
- Intermediate supervision on some steps for shorter gradient paths
- Gradient clipping and checkpointing for memory and stability
- T consistency so inference T stays near the training distribution
These do not guarantee success, but they reduce instability. Evaluate performance across T, not only at a single best T.
6. Combining with MoE
If the shared block is MoE, each expert is a reusable knowledge fragment; attention indexes them. Ordinary MoE routes once per forward pass; looped MoE may route every step, combining experts differently. That can lengthen compute paths without a large parameter increase and fuse knowledge over rounds.
New issues follow: oscillating routes, load imbalance, overused experts, and extra communication. Watch routing stability, expert utilization, and how T changes the route distribution. Useful diagnostics include per-step routing entropy, expert usage, and route consistency across T.
7. Inference, deployment, and evaluation
The core trade-off is latency versus quality. In a batch, samples may need different T. Running everyone to max T wastes compute; per-sample early exit can hurt hardware utilization. Batching, caching, and halt thresholds must be designed together.
Suggested evaluation axes:
- Quality: language-modeling loss, downstream accuracy, reasoning tasks
- Compute: FLOPs, latency, and throughput versus T
- Stability: variance across T, gradient norms, routing consistency
- Ablations: block placement, T, gating, step encoding, adaptive stop
Watch for overthinking: too many loops can keep rewriting representations without gains, or even undo a correct answer. The best T depends on task difficulty and should be set with a validation set and a stop policy.
8. Conclusion
A recurrent Transformer turns depth from a constant set by how many parameter copies you store into a runtime variable set by loop count. Shared-block repetition can raise compute depth without necessarily raising parameter count, and with MoE it pairs multi-expert knowledge with multi-step refinement—at the cost of harder training, routing, and scheduling. Whether to use it depends on the trade among reasoning depth, latency, and parameter budget. Distinguishing parameter depth from compute depth is the first step in that engineering decision.
