Recurrent Transformer Explained: How Repeating 28 Layers Twice Works

    This article breaks down recurrent Transformers, using the example of a model that runs 28 base layers twice. It explains what recurrence actually repeats (computation, not input text), the engineering meaning of 28 × 2 = 56 layer executions, and three supporting designs that keep multi-pass execution stable and deployable: gated progressive updates, cross-pass sharing of global KV with independent local sliding windows, and reuse of sparse attention indices. It also separates three easily confused concepts—model parameters, internal computation, and chain-of-thought tokens—and outlines how to evaluate whether the extra depth is worthwhile in terms of task fit, latency budget, cache and memory usage, training stability, and deployment monitoring.

    1. Introduction: Why Recurrence Is Back in the Architecture Conversation

    As model parameter counts keep climbing, the industry is revisiting a simple idea: instead of making networks deeper and stacking more independent layers, execute the same set of layers repeatedly and trade time for depth. The recurrent Transformer is a representative example of this approach. Its goal is not simply to write a larger layer count into the model, but to extend the effective processing depth within a single forward pass without significantly increasing the parameter count, giving the model more opportunities for “internal thinking” before it emits the next token.

    It is worth stressing that parameter reuse does not mean computation is free, nor does it guarantee that every task runs faster. To understand this class of architecture, you have to separate three things that are often conflated: model parameters (the stored weights), internal computation (the operations that actually happen during the forward pass), and chain-of-thought tokens (the intermediate text the model explicitly generates for the outside world). Using the example of a large model that runs the 28 layers in its base twice, this article systematically unpacks the mechanism, the engineering cost, and the evaluation methods for recurrent Transformers.

    2. What a Recurrent Transformer Actually Repeats

    2.1 It Repeats Computation Layers, Not Input Text

    What a recurrent Transformer executes repeatedly is a group of internal computation layers. The hidden state produced in the previous pass becomes the input for the next pass and is processed further; the weights are shared across passes, but the hidden state changes from pass to pass. This contrasts with the familiar stacked Transformer: there, each layer typically holds independent parameters and executes in sequence within one forward pass, whereas here the same set of parameters participates in multiple passes of processing.

    A fitting analogy is a group of analysts revising the same working draft over and over—the people are not duplicated, but the draft keeps getting updated. Note, however, that what is actually passed along is a high-dimensional numerical representation (the hidden state), not a piece of already-written text. This distinction is what makes the recurrent architecture fundamentally different from “resubmitting the answer to the chat interface.”

    2.2 A Conceptual Flow

    The pseudocode below only illustrates the data flow; it is not a runnable implementation:

    1. Input
    2. ↓
    3. Pre-processing (embedding, etc.)
    4. ↓
    5. Initial hidden state h0
    6. ↓
    7. Shared recurrent block — Pass 1: h1 = Block(h0)
    8. ↓
    9. Same block — Pass 2: h2 = Block(h1)
    10. ↓
    11. Post-processing (normalization, output head)
    12. ↓
    13. Predict the next token

    The key point: weights can be shared across passes, but the hidden state still changes. So this is neither computing the same input verbatim several times, nor feeding the first pass’s result back into an interface.

    3. What “28 Layers Run Twice” Means in Engineering Terms

    According to public technical descriptions, this class of model builds on an already pre-trained base and introduces the recurrent structure through further training, executing 28 of its layers for two passes without duplicating an equally sized set of layer weights for the second pass.

    For this recurrent segment alone, the number of executions can be understood as 28 × 2 = 56 layer computations. Three clarifications are needed: 56 describes the unrolled computation of that segment, not the model’s total layer count; it does not mean the parameters double; and the network still contains other layers, gating, and caching designs. In other words, “run twice” describes computation unrolling, not a simple sum of parameter count or total depth.

    4. Three Supporting Designs: Managing Stability and Deployment Overhead

    Recurrence does not pay off just by wrapping a for loop around a model. To make multi-pass execution stable and deployable, three kinds of supporting mechanisms are typically required.

    4.1 Gated Progressive Updates

    This mechanism controls the proportion of each pass’s candidate change that is written back into the hidden state, preventing the representation scale from over-inflating after repeated execution and allowing the two passes to take on different roles. Intuitively, it works like a valve: the first pass allows larger changes to establish an initial representation, while the second pass absorbs only filtered increments, suppressing numerical drift. A sketch:

    1. # Conceptual illustration, not a real implementation
    2. g = sigmoid(gate_proj(h_prev)) # write-back ratio
    3. cand = block(h_prev) # candidate update for this pass
    4. h_next = g * cand + (1 - g) * h_prev

    4.2 Cross-Pass Shared Global KV with Independent Local Sliding Windows

    The second pass reuses the first pass’s global sparse KV while retaining local information within the new window. This lets the second pass “see” the global context the first pass already retrieved, while also supplementing new information inside the local window, keeping the extra cache footprint under control. For long-context scenarios, this is the key to keeping memory and bandwidth overhead within an acceptable range.

    4.3 Reuse of Sparse Attention Indices

    The second pass reuses the sparse attention indices selected in the first pass, reducing repeated retrieval overhead. Sparse attention itself requires scoring and selection; recomputing it every pass would raise the cost significantly. Reusing the indices amortizes that overhead and makes multi-pass execution more affordable at inference time.

    Together, these three points explain why you cannot simply wrap an ordinary model in a loop and get the same effect—stability, caching, and retrieval overhead all require dedicated design.

    5. Parameters, Computation, and Chain-of-Thought Tokens: Three Things to Keep Separate

    • Model parameters: under the recurrent architecture, these basically do not grow with the number of passes—the core benefit of parameter reuse.
    • Internal computation: grows roughly linearly with the number of passes; 56 layer computations mean that segment’s forward pass is heavier, with higher latency and compute consumption.
    • Chain-of-thought tokens: the intermediate text the model explicitly generates for the outside world—a different thing from the internal hidden-state loop. The former is visible, billable, and truncatable; the latter is invisible and happens inside a single forward pass.

    Confusing the three leads to misjudgment: seeing that “parameters didn’t double” and assuming “computation is free,” or equating internal multi-pass processing with an explicit chain of thought. The correct understanding is that the recurrent architecture trades computation for depth and parameter reuse for capacity efficiency, but the bill for latency and energy still has to be paid.

    6. How to Evaluate Whether a Recurrent Architecture Is Worth It

    1. Task fit: tasks that need multi-step internal reasoning, long-range dependencies, or high-precision extraction are more likely to benefit from extra internal depth; simple classification or short-text tasks see limited gains.
    2. Latency budget: multi-pass execution increases that segment’s time roughly linearly, so evaluate it against first-token latency and throughput targets.
    3. Cache and memory: pay attention to cross-pass KV sharing and local sliding-window strategies to avoid memory blow-up under long context.
    4. Training stability: whether mechanisms like gated progressive updates are in place directly determines whether the representation drifts after multiple passes.
    5. Deployment shape: under container platforms, model serving, and monitoring and alerting systems, the resource curves of multi-pass execution need to be observed separately rather than reusing the empirical values from a single-layer model.

    7. A Deployment Perspective on Baidu AI Cloud

    To host inference for this kind of recurrent architecture in the cloud, you can combine general-purpose capabilities: use a container platform to run elastic inference instances, object storage to manage model weights and intermediate artifacts, a message queue to smooth out request spikes, and logging and monitoring/alerting services to track the latency and memory curves of multi-pass execution. Baidu AI Cloud offers these general product categories, making it easier to evaluate the architectural payoff of “trading computation for depth” and the operational cost on the same dashboard.

    8. Common Misconceptions

    • Misconception 1: recurrence doubles the parameters. In fact, weights are shared and the parameter count stays basically unchanged.
    • Misconception 2: 56 is the total layer count. In fact, 56 is only the computation unrolling of that recurrent segment.
    • Misconception 3: the internal loop is chain of thought. In fact, the hidden-state loop is invisible; chain-of-thought tokens are the outward-facing text.
    • Misconception 4: wrapping a for loop around a model reproduces the effect. In fact, gating, KV sharing, and index reuse are all indispensable.

    9. Conclusion

    The value of the recurrent Transformer lies in trading parameter reuse for effective computation depth, letting the model do more internal processing before it outputs. Running 28 layers twice is just one instance of computation unrolling; what really determines success or failure is the supporting design—gated progressive updates, cross-pass KV sharing, and sparse index reuse. Understanding the boundaries between parameters, computation, and chain-of-thought tokens is what lets you make rational trade-offs among latency, memory, and accuracy, and what lets you get the engineering math right for this class of architecture in the cloud.