Recurrent Transformers Demystified: Hidden State Iteration and Gradient Truncation

    This article explores the core mechanisms of recurrent Transformers, moving beyond the superficial notion of simple weight sharing. It explains how hidden states iterate with input injection to prevent representation collapse or numerical divergence, and analyzes the architecture from a dynamical system and fixed-point perspective. Furthermore, it details the gradient truncation strategies required to stabilize training over long unrolled computation graphs, alongside the engineering trade-offs and applicable boundaries of this architecture.

    In a model architecture discussion, someone saw a diagram of recurrently reused weights and concluded, “Isn’t this just repeatedly calling a single layer’s weights, trading time for space to simulate a deep network?” This judgment is only half correct. While weight sharing is indeed the surface appearance, what truly determines whether this architecture works is the iterative trajectory of the hidden state in the feature space, the boundary conditions formed by input injection, and the gradient truncation strategy applied during the training of long unrolled computation graphs. If it is merely a simple weight loop, the hidden state will often suffer information collapse within a few steps or diverge due to numerical instability. Let’s break down this chain to understand how it works.

    1. Standard Transformers vs. Recurrent Architectures

    A standard Decoder-only Transformer is typically composed of a stack of multi-layer blocks with independent parameters. The $l$-th layer has its own attention, feed-forward network, and normalization parameters, and its output can be abstracted as:

    h^(l) = Block_l(h^(l-1))

    Here, each layer performs a representation transformation under a set of independent weights. The layers act more like cascading projections between different parameter subspaces: shallow layers extract local patterns, middle layers combine semantic relationships, and deep layers complete reasoning and output preparation. This structure has a very direct constraint: model capacity is highly coupled with computation. To increase “reasoning steps” or “effective depth,” one usually has to increase the number of layers, which means increasing both the parameter count and the forward computation. Parameter capacity and runtime FLOPs are bound to the same line, making it difficult to temporarily increase the computational budget during inference without altering the parameter scale.

    The recurrent weight architecture breaks this binding. It retains a single set of core Transformer Block parameters—usually including multi-head self-attention, a feed-forward network, normalization, and residual branches—and repeatedly calls this same set of operators to update the hidden state over multiple time steps:

    h_(t+1) = F(h_t, x)

    Here, $x$ is the static input representation after the embedding layer, and $F$ is the shared residual transformation branch. The parameter count does not grow with the number of iteration steps, but the computation does. Consequently, “parameter capacity” and “runtime computation” are partially decoupled. The model can use a fixed parameter set and trade more iteration steps for stronger representation refinement during inference. However, this is only the starting point; a bare loop is not sufficient to guarantee effectiveness.

    2. Why Bare Loops Collapse or Diverge

    If the recurrence is written simply as $h_{t+1}=F(h_t)$, the network is prone to two types of problems after multiple iterations.

    The first is representation collapse. When a shared operator repeatedly acts on the same hidden state, attention distributions may gradually converge, and residual branches repeatedly smooth the representation. This reduces the discriminability between different tokens and lowers the effective rank of the feature matrix. The information from the initial input is diluted over multiple transformations, eventually leaving only an approximately stable “average” representation, which naturally degrades reasoning capability.

    The second is numerical divergence. Once the loop is unrolled, the hidden state passes through multiple multiplications of identical or similar Jacobian matrices. If the local spectral norm of the shared operator is too large, residual accumulation, attention logit amplification, or normalization statistical drift can cause the state norm to gradually increase. Conversely, if the operator compresses too strongly, information decays rapidly. Without boundary constraints, the iterative trajectory can either shoot out of the stable region or converge to a meaningless constant.

    Therefore, an input injection mechanism must be introduced in engineering implementations. Each iteration re-fuses the initial word embedding feature $x$ into the current state, commonly abstracted as:

    h_(t+1) = F(h_t) + α ⊙ x

    Or more generally:

    h_(t+1) = F(h_t, x)

    Here, α can be a fixed coefficient or a gating weight, and $F$ internally contains residual transformations like Pre-Norm, attention, and feed-forward networks. In this context, $x$ acts as a “boundary condition” or “anchor” for the iterative process. As the operator repeatedly corrects $h_t$, it consistently performs residual corrections around the original token semantics, preventing the hidden state from deviating from the input manifold during the dynamical system’s evolution. Input injection is not simply adding a constant; it preserves an accessible path back to the original semantics in each iteration, preventing the loss of conditional information during the evolution of the hidden state.

    3. Dynamical Systems and Fixed-Point Perspective

    By writing the hidden state update of the recurrent Transformer as $h_{t+1}=F(h_t,x)$, we can understand it from a dynamical systems perspective. Given an input $x$, the iteration forms a trajectory in the feature space: $h_0, h_1, h_2, …$. Ideally, this trajectory will gradually approach a fixed point $h^*$ that satisfies:

    h = F(h, x)

    This is the fixed-point solving perspective. Instead of making independent projections between layers, the model iteratively refines the feature representation under a single operator. The more iteration steps, the closer the trajectory gets to the fixed point, and the closer the representation gets to the stable solution under those conditions. For complex reasoning tasks, this iterative refinement allows the model to dynamically allocate computational budget: simple samples require fewer iterations, while complex samples can increase steps to approach higher-order logical solutions.

    However, whether a fixed point exists and whether it is stable depends on the local properties of $F$. If $F$ approximates a contraction mapping in the relevant region, the trajectory will easily converge. If the Jacobian spectral radius is greater than 1, the trajectory may diverge or enter oscillation. In engineering, natural convergence is not assumed; instead, normalization, residual scaling, gated injection, spectral norm constraints, and early stopping strategies are used to restrict iterations within a controllable range. During inference, one can also decide whether to stop based on the state change, such as terminating early when $||h_{t+1}-h_t||$ falls below a threshold to avoid meaningless computation.

    4. Gradient Truncation: Stabilizing Training for Long Unrolled Graphs

    During training, a recurrent structure is unrolled into a $T$-step directed computation graph. The gradient of the loss with respect to the shared parameters passes through multiple Jacobian matrix multiplications, making it highly susceptible to gradient explosion or vanishing. “Gradient truncation” here must be understood at two levels.

    The first level is backpropagation window truncation. Backpropagating through all iteration steps causes both the computation graph and memory overhead to grow with $T$, and long-range Jacobian multiplications are unstable. A common practice is to backpropagate only the last $K$ steps, applying stop-gradient to prior states—retaining their values for the forward pass but excluding them from backpropagation. This allows the shared parameters to receive correction signals from local iterations while controlling training costs. The position of the stop-gradient must be designed carefully: truncating too short prevents the model from learning long-range refinement, while truncating too long brings back instability and memory pressure.

    The second level is gradient norm clipping. Even if backpropagation only covers $K$ steps, certain samples may still produce large gradients. Clipping the global gradient norm during training prevents a single aggressive update from destroying the shared operator. Its purpose differs from backpropagation window truncation: the former controls the magnitude of a single update, while the latter controls the length of the backpropagation path. They are often used in conjunction in engineering.

    Additionally, a curriculum approach to iteration steps can be adopted: using fewer steps in the early stages of training and gradually increasing them once stabilized; or applying random sampling to the step count to let the shared operator adapt to different iteration depths. Normalization positions, residual scaling, and injection gating also affect stability. Below is abstract pseudocode expressing the structure, not representing specific interfaces:

    1. # Forward: shared operator + input injection
    2. def loop_forward(e, steps, inject_weight):
    3. h = e
    4. for t in range(steps):
    5. f = shared_block(h) # The same set of parameters is called repeatedly
    6. h = h + f + inject_weight * e
    7. h = normalize(h)
    8. return h
    9. # Training: backprop window truncation + gradient norm clipping
    10. for e, y in batches:
    11. h = e
    12. for t in range(T):
    13. if t % K == 0:
    14. h = stop_gradient(h) # Truncate the backprop window every K steps
    15. h = loop_step(h, e)
    16. loss = task_head(h, y)
    17. loss.backward()
    18. clip_global_gradient(max_norm)
    19. update_shared_parameters()

    The key to this pseudocode is not the specific function names, but the two constraints: input injection ensures that each iteration has an original semantic anchor, while backprop window truncation and gradient clipping ensure that the shared parameters can be stably updated over long unrolls.

    5. Engineering Trade-offs and Applicable Boundaries

    Recurrent weight reuse is not “free deepening.” It trades a fixed parameter set for variable iterative computation, but inference latency, memory usage, and training difficulty remain correlated with the number of unrolled steps. Too few steps lead to insufficient refinement; too many steps yield diminishing returns and increased risk of instability. Therefore, practical systems usually require a combination of maximum steps, early stopping thresholds, and step scheduling during the training phase.

    This architecture is more suitable for scenarios that require multi-step reasoning, iterative representation refinement, and allow runtime adjustment of the computational budget. For tasks that only require shallow pattern matching, a fixed number of efficient feed-forward layers might be more direct. When evaluating such architectures, one should not merely look at “whether weights are shared,” but at whether input injection preserves conditional information, whether the iterative operator is stable, whether gradient truncation is reasonable, and whether the inference steps are adaptive. Once these mechanisms are unpacked, it becomes clear that the core of recurrent Transformers is not simple weight reuse, but controlled iteration and fixed-point approximation in the feature space.