Looped Transformer Architecture: Shared Depth for Improving LLM Reasoning

    This article examines the looped Transformer architecture, which repeatedly applies a shared group of layers to the same input state to increase effective computational depth without a proportional increase in parameters. It covers token-wise gated updates, cross-iteration KV cache sharing, sparse attention index reuse, continued training from a mature base model, task suitability, deployment tradeoffs, and evaluation methods.

    As large models continue to scale, improving capability usually depends on more parameters, longer training time, and more inference compute. Simply expanding model size is not the only option, however. Another approach is to let existing network layers perform multiple rounds of computation on the same input state, so the model can repeatedly correct and refine its intermediate representations.

    Recently, a flagship large model introduced a looped Transformer architecture in a coding-focused model service. The core of this approach is not simply adding more layers. Instead, a group of layers with shared parameters runs for multiple consecutive passes. This increases the model’s effective computational depth while keeping parameter size largely unchanged, making it especially suitable for math, code, complex instruction understanding, and long-context tasks that require multi-step reasoning.

    1. What Is a Looped Transformer?

    A standard Transformer usually executes in a fixed order:

    1. Input
    2. ↓
    3. Layer 1
    4. ↓
    5. Layer 2
    6. ↓
    7. Layer 3
    8. ↓
    9. ……
    10. ↓
    11. Layer N
    12. ↓
    13. Output

    Each layer uses independent parameters and transforms the hidden state once. More layers usually mean stronger representational capacity and greater computational depth, but they also increase parameter count, training cost, and memory usage.

    A looped Transformer uses a structure more like this:

    1. Input
    2. ↓
    3. Shared layer group, pass 1
    4. ↓
    5. Shared layer group, pass 2
    6. ↓
    7. Output

    Here, “pass 1” and “pass 2” are not two completely separate networks. They are the same set of parameters called repeatedly. The first pass mainly establishes contextual relationships and an initial semantic representation. The second pass continues reasoning, correcting, and refining the existing result.

    One way to understand this is that a traditional model lets more different experts each process the input once, while a looped structure lets the same group of experts discuss the same proposal repeatedly. Parameter count does not grow linearly with the number of passes, but the computational path becomes deeper.

    2. Why Looped Computation Can Improve Reasoning

    For factual recall or simple text continuation, a single forward computation is often enough. For complex reasoning tasks, however, the hidden state usually needs to go through multiple stages:

    1. Identify entities, constraints, and goals in the problem;
    2. Build global contextual relationships;
    3. Generate an intermediate reasoning structure;
    4. Detect potential conflicts or errors;
    5. Correct and compress the result;
    6. Produce the final answer.

    A standard Transformer mainly relies on different layers to perform this work. A looped structure can instead let the same high-quality layers repeatedly process an intermediate state that has already been formed. The second pass does not need to restart from the original input; it can directly use the contextual representation produced by the first pass.

    This brings two potential benefits.

    First, the model can obtain a deeper reasoning path without substantially increasing parameter count. Second, some reasoning that would otherwise require generating a large number of chain-of-thought tokens can be shifted into additional computation rounds inside the hidden state. As a result, the model may complete similar or even more complex tasks with shorter output.

    It is important to note that looped computation does not automatically produce stronger intelligence. Without a stable training mechanism, repeated computation can cause hidden states to diverge, information to be overwritten, or errors to accumulate. What really determines the result is not the concept of looping itself, but the state update, cache management, and training strategy designed around it.

    3. Key Design 1: Token-Wise Gated Updates

    If each loop pass directly overwrites the old state with a new state, activation values may keep growing and the representation scale may drift. As the number of passes increases, the state received by later layers may move away from the distribution familiar from training, which can affect optimization stability.

    To address this, a token-wise gating mechanism can be introduced. Its basic form can be abstracted as:

    1. New state = old state + gate coefficient × candidate update

    The candidate update is computed by the Transformer layer in the current pass, and the gate coefficient determines how much information from this pass is written back. The gate can produce different values for different tokens, channels, or positions.

    This design is valuable in three main ways:

    • Control state scale: avoid continuous expansion of activation norms across multiple passes;
    • Preserve existing information: reduce overwriting when the current pass does not produce useful new information;
    • Create division of labor: different loop passes can gradually learn different responsibilities.

    In actual training, the first pass often focuses more on building global context, so its update magnitude tends to be cautious. Later passes take on more reasoning and refinement work and can make fuller modifications based on the existing representation. This “establish first, then refine” computation pattern is more stable than overwriting the state indiscriminately on every pass.

    From an optimization perspective, gating also provides a smoother gradient path. Even if one pass performs poorly, the model can reduce its impact through a smaller gate value instead of letting erroneous information directly overwrite useful representations that have already been formed.

    4. Key Design 2: Cross-Iteration KV Cache Sharing

    The looped structure faces an obvious problem during inference: attention mechanisms need to store Keys and Values. If each pass independently generates and stores a complete KV cache, cache size will grow with the number of loop passes, and memory pressure will rise accordingly.

    This problem is especially prominent in long-context scenarios. If context length reaches the million-token level, even a single-pass cache may already consume a large amount of memory, and copying multiple additional caches can quickly increase deployment cost.

    A more efficient approach is to share the KV cache across passes and use a sliding window to store new information from the current pass. The logic can be summarized as:

    1. Historical context KV: reused across passes
    2. Current local window: updated independently each pass
    3. Final attention range: shared history information + current window information

    In this way, the second pass does not need to store another complete copy of historical KV. It directly reuses the contextual structure established in the first pass. At the same time, the sliding window supplements local changes produced in the current pass.

    The advantages of this approach include:

    1. Lower additional memory overhead
      As the number of loop passes increases, the full cache is no longer copied proportionally.

    2. Preserve long-context capability
      Historical information can continue to participate in attention computation and is not completely lost when the window is updated.

    3. Control computation scope
      New passes focus on recent or local changes and avoid repeatedly scanning the entire context.

    However, cache sharing also carries accuracy risks. If the historical information selected in the first pass is incomplete, later passes may not be able to recover content that was ignored. Therefore, engineering implementations usually need to balance shared cache and local updates, and verify information recall through long-context evaluations.

    5. Key Design 3: Reusing Sparse Attention Indices

    When context length is very large, full attention computation is expensive, so many long-context models use sparse attention. Sparse attention usually first uses an indexer to determine which historical positions are most worth attending to, and then lets the main attention module compute only over those positions.

    If every loop pass re-runs the indexing process, the computational overhead introduced by additional depth may be considerable. To address this, later passes can reuse the sparse attention indices generated in the first pass.

    The basic flow is as follows:

    1. Pass 1:
    2. Context → Indexer → Set of important positions → Sparse attention
    3. Pass 2:
    4. Reuse the set of important positions → Run sparse attention directly

    This assumes that, for the same token and a similar hidden state, the key context positions selected in the first pass still have reference value in the short term. This reduces the cost of repeated indexing and allows loop passes to focus more on state refinement rather than repeating the same selection work.

    Of course, index reuse is not suitable for every scenario. If the hidden state changes substantially in the second pass, the attention positions selected in the first pass may no longer be optimal. Therefore, a real system can decide whether to recompute indices based on task type, context change magnitude, or confidence.

    6. Training Approach: Why Continued Training from a Mature Base Model Is Usually Needed

    Although the looped structure is simple in concept, training it from scratch is not easy. Shared parameters create stronger coupling between different loop passes, and the model needs to learn simultaneously:

    • How to build effective representations in the first pass;
    • How to continue using those representations in later passes;
    • How to avoid redundant computation;
    • How to control the state scale across different passes;
    • How to turn loop depth into actual task capability.

    A more reliable route is therefore to first train a mature non-looped base model, then adapt it to looped execution through structural modification and continued training.

    This approach has three benefits:

    1. The base model already has solid language modeling capability;
    2. Continued training can focus on optimizing the new behaviors introduced by looping;
    3. It is easier to run controlled experiments under the same parameter scale and data conditions.

    Continued training is not simply copying the layer structure, however. After looping is introduced, the model’s computation distribution changes, and the original layers may need to adapt to a longer effective path. Gate initialization, learning rate scheduling, training stage division, and gradient stability all affect the final result.

    7. Which Tasks Benefit Most from Looped Structures?

    Results from validating this type of architecture suggest that the benefits of looping are usually related to the reasoning depth required by the task.

    7.1 Mathematical Reasoning

    Math problems often require multi-step transformations, conditional constraints, and checks of intermediate results. Looped computation allows the model to continue processing the previous pass’s derivation results inside the hidden state, reducing the chance of outputting an incorrect answer too early.

    7.2 Code Generation and Code Understanding

    Code tasks require not only understanding natural language but also maintaining variable relationships, control flow, and interface constraints. Additional loop passes can help the model perform structural checks on generated results and reduce issues such as mismatched brackets, missing variables, and broken logic.

    7.3 Long-Context Understanding

    Long-document tasks require selecting key content from large amounts of information and building cross-paragraph relationships. Shared cache and sparse indices can reduce the repeated cost of long-context computation, while the loop process further integrates the selected information.

    7.4 Complex Instruction Following

    When an instruction contains multiple steps, multiple constraints, and different output formats, the model needs to first parse the requirements, then plan the execution order, and finally check the format. A looped structure provides more internal computation space for these stages.

    Conversely, for simple question answering, short-text classification, or fixed-format conversion, the benefits of additional loops may be limited and may even increase latency. Therefore, production deployments should not assume by default that every request should use the maximum loop depth.

    8. Engineering Tradeoffs in Inference Deployment

    The advantages of a looped Transformer usually come with additional computation. Even if parameter count remains largely unchanged, multiple passes still increase the number of forward computations. Deployment therefore needs to consider the following factors:

    • Latency: more loop passes usually mean longer response time per request;
    • Throughput: on the same hardware, the number of requests that can be processed simultaneously may decrease;
    • Memory: shared KV can slow growth, but intermediate states still need to be stored;
    • Power consumption: additional computation increases energy use per request;
    • Benefit stability: different tasks have different sensitivity to loop depth.

    A more practical strategy is dynamic looping. For example, the model can first execute a basic pass, then decide whether to continue computing based on hidden-state changes, confidence, or task type:

    1. Run first pass
    2. ↓
    3. Is the current state sufficient?
    4. ├─ Yes: output directly
    5. └─ No: run a second pass or more

    This approach can keep latency lower for simple requests while providing deeper reasoning capability for complex tasks. However, dynamic early exit requires additional training objectives and a reliable stopping criterion; otherwise, it may end too early or run ineffective loops.

    9. How to Evaluate Whether a Looped Architecture Is Truly Effective

    Evaluating this type of architecture cannot rely only on parameter scale or a single benchmark score. A complete comparison framework should be established:

    1. Compare under the same parameter scale: confirm whether gains come from the architecture rather than a larger model;
    2. Compare under the same training compute: avoid mistaking additional training budget for a structural advantage;
    3. Break down results by task type: examine reasoning, code, long context, and ordinary generation separately;
    4. Measure output length: observe whether the model reduces redundant chain-of-thought;
    5. Measure real latency and memory: evaluate the cost of the architecture in production;
    6. Inspect error types: distinguish knowledge gaps, reasoning errors, and context omissions;
    7. Test different loop counts: determine whether gains saturate after a certain number of passes.

    It is especially important to distinguish “capability improvement” from “computation shifting.” A looped structure may reduce visible tokens, but that does not mean total computation definitely decreases. Some reasoning is shifted into hidden-state updates, so generation tokens, forward computation count, end-to-end latency, and energy consumption should be measured together.

    10. Conclusion

    The core value of a looped Transformer is that it increases effective network depth through multiple passes of shared layers while keeping parameter size largely unchanged. It is not simply running the same layer repeatedly. To balance capability, stability, and deployment cost, it needs to be combined with gated state updates, cross-iteration KV cache sharing, and sparse attention index reuse.

    From a technical trend perspective, this architecture represents a shift in the scaling path for large models: capability no longer depends only on “having more parameters” but can also come from “computing more thoroughly over existing representations.” For mathematical reasoning, code generation, long-context tasks, and complex instructions, additional internal loops may be more efficient than simply increasing output tokens.

    In production environments, however, loop depth, cache strategy, and early-exit mechanisms still need to be selected according to business goals. Only under the combined constraints of consistent evaluation, real latency, and total cost can we determine whether a looped architecture is truly suitable for a specific application.