Recurrent Depth Networks: Adding Compute Depth to a Parameter-Fixed Transformer

    This article explains how recurrent depth networks decouple model depth from parameter count. It distinguishes storage depth from compute depth, outlines the three conditions that make recurrence effective, and shows how the approach fits sparse Mixture-of-Experts feed-forward layers. It also covers key training and inference considerations, including activation memory, sampled iteration counts, weight-sharing regularization, adaptive compute, and KV cache behavior, along with practical guidance for running ablation studies.

    1. The Starting Problem: Why Depth Is Locked by Parameter Count

    In a standard Transformer, the number of layers is effectively capped by how many distinct sets of weights you store. A 48-layer network means 48 independent parameter groups, each used only once per forward pass. Making the network deeper usually means adding parameters, which drives up memory usage, deployment cost, and inference latency at the same time.

    This raises a question worth answering carefully: can a model perform deeper computation without increasing its parameter count?

    2. Two Kinds of Depth: Storage Depth vs. Compute Depth

    In a standard structure with L layers, the hidden state passes through mutually distinct layers:

    1. h(l+1) = Block_l(h(l)), l = 0, 1, ..., L-1

    Each layer holds its own parameters θ_l, so depth is determined by the number of parameter sets. This can be called storage depth.

    A recurrent structure instead applies the same parameter set θ repeatedly for T steps:

    1. h(t+1) = Block_θ(h(t), t), t = 0, 1, ..., T-1

    Here storage depth is still 1, while compute depth becomes T. Depth shifts from a constant fixed at deployment time to a variable adjustable at runtime: extra computation buys effective depth, and effective depth buys inference capability.

    A useful analogy: if self-attention is viewed as building and querying an index, and the feed-forward layer as a knowledge base compressed into weights, then a recurrent structure repeatedly retrieves from that same knowledge base and refines the answer round by round. If a round does not get there, the intermediate result is carried into another pass.

    3. Why Repetition Is Not the Same as Standing Still

    If recurrence were merely a stack of identity mappings, repeating it would yield nothing. Effective recurrence needs three things:

    1. Step information injection. Introduce t as positional encoding, a gating scalar, or adaptive normalization parameters, so each round behaves distinguishably.
    2. Continued state evolution. Each round’s output must change the hidden state distribution rather than stall after converging to a fixed point.
    3. A stopping criterion. Use the relative change in the hidden state between adjacent rounds as a convergence signal, and exit once it falls below a threshold.

    A sketch implementation:

    1. def loop_forward(h, block, T_max, eps=1e-3):
    2. for t in range(T_max):
    3. h_next = block(h, step=t) # step information injected via step
    4. delta = (h_next - h).norm() / (h.norm() + 1e-6)
    5. h = h_next
    6. if delta < eps: # exit early once converged
    7. break
    8. return h, t + 1

    4. A Natural Fit with Mixture-of-Experts

    When the feed-forward layer uses a sparse expert structure, each expert can be seen as an independent knowledge point, while attention handles analysis and indexing of those points. Expanding parameters is like progressing from basic education all the way to higher education: more knowledge brings better problem-solving ability. But once a problem enters a stage that requires creative connections across knowledge points, simply piling on parameters stops working. What recurrence offers is precisely a mechanism for repeatedly integrating existing knowledge, and it can be seen as an early form of a reasoning chain inside the model.

    One engineering caveat: multiple rounds amplify routing load imbalance, so pair it with a load-balancing loss and capacity factor constraints to avoid a few experts being hit repeatedly while the rest sit idle.

    5. Key Points for Training and Inference

    • Memory and recomputation. Backpropagation needs activations from every round saved; gradient checkpointing can trade compute for memory. Keep checkpoint granularity aligned with the loop boundaries.
    • Sampled iteration count. Randomly sampling T during training keeps the model robust to depth changes and mitigates gradient degradation from too many rounds.
    • Regularization effect of weight sharing. Shared parameters substantially reduce trainable parameters, which usually calls for more training steps and a more careful learning rate schedule.
    • Inference adaptivity. Fewer loops for easy samples and more for hard ones can raise average quality within an overall latency budget. Set an upper bound on T and monitor the actual loop distribution.
    • Cache compatibility. Multiple iterations change the read/write timing of the key-value cache, so be explicit about whether the cache is reused each round or updated per round, to avoid hidden implementation bugs.

    6. Implementation Advice and Cloud Support

    To validate this idea in your own workload, start with ablation experiments on small and medium models, comparing two baselines: adding layers at fixed parameter count versus adding recurrence rounds at fixed parameter count. Then weigh perplexity, downstream task metrics, and measured latency against each other. On the engineering side, a container platform can handle elastic scaling and canary releases; monitoring, alerting, and logging services can track the loop distribution, tail latency, and resource utilization; and object storage can manage model and dataset versions. Baidu AI Cloud typically provides these general capability categories in such scenarios, making it easier to move an experiment quickly to an observable, rollback-ready state.

    7. Summary

    The core contribution of recurrent structures is freeing depth from parameter constraints and turning it into a compute budget adjustable at runtime. It adds no storage cost, but demands finer convergence control, routing balance, and cache strategy. Understanding the distinction between storage depth and compute depth is the prerequisite for assessing the benefits and costs of such approaches.