Recurloop, Hyper-Connections, and Parallel KV Caching

draft
reasoning
architecture
looped-transformers
Mental models for looping across both depth and tokens, two-stream Hyper-Connections and DeepSeek mHC, and how they connect to our cognitive core.
Published

December 4, 2026

Introduction

Our target in Core Cognition and Looped Transformers is a small, dense cognitive core [1] that gets maximum reasoning accuracy out of a fixed parameter count and FLOP budget. Rather than spending billions of unique weights memorizing static facts, a looped core reuses a compact set of shared weights across many passes so extra compute goes straight into latent deduction.

While mapping out where looped language models are heading next, we dug into Recurloop [2]—and stumbled into ARLoop [3], Hyper-Connections [4], and DeepSeek’s mHC [5] along the way. Working through them from scratch came down to four mental models:

  1. Why depth-only loops (ARLoop) stay trapped inside a single pass—and inside their training loop count.
  2. How Recurloop resolves the parallel paradox to pass a token’s final thought forward to the next token without giving up parallel training.
  3. Why two-stream Hyper-Connections (and mHC) are needed once clean token embeddings and carried thoughts share the same weights.
  4. How Parallel KV caching handles multi-pass state during autoregressive decoding.

Vertical Loops First: ARLoop and the Step-Index Trap

Most looped Transformers—including ARLoop [3]—loop strictly vertically at each token position. In its simplest form (ARLoop-Full), every layer inside every loop pass appends its output into one accumulating list (history = [b0, b1, b2, ...]), and Attention Residuals [6] uses a learned step query q_depth[step] ([D]) to collapse that list back into one [B, T, D] input vector before the next block runs. Because an unbounded list grows linearly with loop count (O(N) memory and attention dilution at deep passes), ARLoop-SW caps the list to a pinned b0 anchor plus a FIFO sliding window of the last W block outputs ([b0] + window[-W:]):

What This Block Reads
Takeaway

    

Stepping through the list and q_depth[step] above exposes two limits:

  • Locked to training depth. Because q_depth learns a separate parameter vector for every loop index step, the router only knows the step indices seen during training—the exact same extrapolation trap we hit with MeSH [7] when rolling out deeper at test time.
  • No top-to-bottom handoff across tokens. When token t - 1 finishes all R vertical loops at the top of the stack, its final representation h_final[t - 1] goes straight to the LM head to predict token t. Token t still starts at the bottom from its raw embedding e_t alone, never seeing h_final[t - 1].

Looping Across Depth and Tokens: The Parallel Paradox

Recurloop [2] asks a simple question: what if token t could start at the bottom with both its own token embedding e_t and the finished deep thought h_final[t - 1] from the previous token—like one step of continuous latent Chain-of-Thought without printing scratchpad words?

At first glance, that hits a parallel paradox. During training and prefill, a Transformer processes all T tokens in parallel ([B, T, D]). By the time h_final[t - 1] exists at the top of column t - 1, token t has already finished running alongside it. If token t had to wait on t - 1, which waited on t - 2, training would turn into a slow token-by-token RNN.

Recurloop resolves this by calling the parallel R-loop model twice (Sweep 0 and Sweep 1), shifting the finished thoughts right by one token slot in between:

  • Sweep 0 (KV_0) runs all T tokens in parallel through R loops of the shared block with no neighbor feedback yet, producing a draft thought h0 ([B, T, D]) at the top of every column.
  • shift_right_1 slides h0 one position to the right along the token axis (padding zero at t = 0), so column t receives h0[t - 1].
  • Sweep 1 (KV_1) runs all T tokens in parallel a second time through the exact same weights and R loops, seeded with h0[t - 1] at the bottom, and sends h1 to the LM head.

Both sweeps stay parallel [B, T, D] tensor calls on the GPU. Each extra sweep buys one hop of top-to-bottom latent handoff (Sweep 0 gives t - 1 → t), trading 2× parallel compute for zero new layer weights.

Inside One Shared Layer: Hyper-Connections and mHC

Once token t receives both its own identity e_t and the previous token’s deep vector h0[t - 1], adding them into one [B, T, D] vector (e_t + h0[t - 1]) causes the two signals to collide across repeated passes.

To keep them separate without doubling Self-Attention or MLP weights, Recurloop borrows two-stream Hyper-Connections [4]. In a standard Transformer, a residual wrapper around Self-Attention holds one vector x ([D]) per token:

x_next = 1.0 * x + 1.0 * self_attn(1.0 * x)

Original Hyper-Connections (designed for standard non-looped networks, initialized symmetrically as [e_t, e_t]) widen that residual highway from one vector to two parallel lanes H = [s0, s1] of shape [2, D], while keeping Self-Attention and MLP single-stream ([D]):

Inside one purple Shared Layer box from the diagram above: the top branch collapses [2, D] → [D] for Self-Attention and scales it back to [2, D]; the bottom branch runs the 2×2 residual matrix M.
  1. Read ([2, D] → [D]). Two dynamic scalars a = [a0, a1] mix s0 and s1 into x_in = a0 * s0 + a1 * s1 ([B, T, D]) so standard Self-Attention or MLP runs unchanged.
  2. Write ([D] → [2, D]). Two scalars b = [b0, b1] write the sublayer output y back onto both lanes as [b0 * y, b1 * y].
  3. Residual (2×2 matrix M). Instead of fixed 1.0 skip weights, a dynamic 2×2 matrix M mixes [s0, s1] across the skip branch (M @ H).

Recurloop adapts this to two sweeps by initializing Sweep 1 asymmetrically: s0 = e_t stays a clean anchor for the current token, while s1 = e_t + alpha_fb * gate(h0[t - 1]) carries the gated thought from t - 1. At the end of R loops, the two lanes sum back to [B, T, D] via H.sum(dim=-2) (s0 + s1).

def two_stream_sublayer(H, sublayer, hc):
    # H: [B, T, 2, D]   two residual lanes [s0, s1] per token
    Hn   = rms_norm(H)                                                  # [B, T, 2, D]
    a, b = hc.read_weights(Hn), hc.write_weights(Hn)                    # [B, T, 2], [B, T, 2]
    M    = torch.eye(2) + hc.res_scale * torch.tanh(hc.mix_logits(Hn))  # [B, T, 2, 2]

    x_in = torch.einsum('bts,btsd->btd', a, Hn)                         # [2, D] -> [D]
    y    = sublayer(x_in)                                               # [B, T, D]
    return torch.einsum('btij,btjd->btid', M, H) + b.unsqueeze(-1) * y.unsqueeze(-2)

def recurloop_forward(tokens, core_layers, R):
    e = embed(tokens)                                                   # [B, T, D]
    a = torch.zeros_like(e)                                             # Sweep 0: no neighbor state
    for sweep in range(2):
        H = torch.stack([e, e + alpha_fb * a], dim=-2)                  # [B, T, 2, D]
        for r in range(R):
            for layer in core_layers:
                H = two_stream_sublayer(H, layer.self_attn, layer.hc_attn)
                H = two_stream_sublayer(H, layer.mlp,       layer.hc_mlp)
        h = rms_norm(H.sum(dim=-2))                                     # collapse s0 + s1 -> [B, T, D]
        if sweep == 0:
            h_shift = F.pad(h[:, :-1, :], (0, 0, 1, 0))                 # shift_right_1 along T
            a = torch.sigmoid(W_g(e)) * rms_norm(h_shift)               # gated feedback for Sweep 1
    return lm_head(h)

Where DeepSeek’s mHC Fits In

In unconstrained Hyper-Connections, M = I_2 + scale * tanh(...) has unconstrained row and column sums. Multiplying unconstrained 2×2 matrices across dozens of layers or loop steps can quietly compound norms until gradients explode.

DeepSeek’s Manifold-Constrained Hyper-Connections (mHC) [5] fixes this by projecting M onto doubly stochastic matrices (via Sinkhorn normalization), where every entry is non-negative and every row and column sums to 1.0. Because every output lane becomes a convex average of the input lanes, signal norms cannot blow up no matter how deep you stack or loop the core.

How Attention Residuals, Hyper-Connections, and Gated Delta Overlap

Stepping back, Attention Residuals [6] and Hyper-Connections / mHC [4], [5] solve the exact same bottleneck: preventing fixed x = x + f(x) residual addition from muddying early embeddings and later deductions into one flat vector.

Their difference is how they store depth history—the exact same trade-off as Softmax KV Cache vs. Fixed Recurrent State along the token axis, turned sideways onto the depth axis:

# 1. Attention Residuals (Softmax KV cache along depth)
S    = torch.stack(history, dim=-2)                   # [B, T, 1+step, D] grows with depth
x_in = (rms_norm(S) @ q_depth[step]).softmax(-1) @ S  # step-indexed q_depth[step]

# 2. Hyper-Connections / mHC (Fixed 2-lane state along depth)
x_in   = torch.einsum('bts,btsd->btd', a, H)          # H: [B, T, 2, D] fixed size
y      = sublayer(x_in)                               # [B, T, D]
H_next = M @ H + b.unsqueeze(-1) * y.unsqueeze(-2)    # step-free when weights are shared

# 3. Our Gated-Delta Core (Content-addressed dk-slot memory along depth)
S = alpha * S + beta * outer(k, v - (alpha * k) @ S)  # S: [B, T, dk, D] fixed size, step-free
Table 1. Comparing depth-routing mechanisms along the loop axis.
Mechanism Depth State Step Weights Loop Extrapolation
Attention Residuals [1 + step, D] q_depth[step] Locked to training steps
Hyper-Connections / mHC [2, D] None Extrapolates cleanly
Gated-Delta (S_attn, S_mlp) 2 × [dk, D] None Extrapolates + ΔS halt

Using Attention Residuals across loops collides with test-time depth extrapolation because q_depth[step] is tied to training step indices, whereas both mHC and our content-addressed (S_attn, S_mlp) memory stay step-free.

Parallel KV Caching at Decode Time

During autoregressive decoding, each sweep builds its own KV cache: KV_0 comes from Sweep 0, and KV_1 comes from Sweep 1 (stored per inner loop step, just like any looped causal LM).

Tracing a concrete prompt like ["2", "+", "3"] followed by decoding "=" shows why both sweeps still run in a single batched pass per generated token:

  1. Prefill on ["2", "+", "3"]. Sweep 0 computes [h0_"2", h0_"+", h0_"3"] and populates KV_0. Sweep 1 shifts those right ([0, h0_"2", h0_"+"]), populates KV_1, and predicts "=". Notice that h0_"3" was never used yet—we keep h0_"3" in our pocket for the next token.
  2. Decoding "=" (1 new token; past tokens stay frozen in KV_0 and KV_1). We need two jobs on "=":
    • Sweep 1 of "=" reads h0_"3" from our pocket and attends to KV_1 to predict "5" right now.
    • Sweep 0 of "=" starts with zero neighbor feedback and attends to KV_0 to compute h0_"=" for tomorrow’s pocket (when "5" arrives).

Because Sweep 0 of "=" and Sweep 1 of "=" do not depend on each other, they stack along the batch dimension (batch = 2) and run simultaneously through one weight read from GPU memory:

def decode_one_token_parallel_kv(tok_t, pocket_h0_prev, KV_0, KV_1):
    # tok_t: [1, 1]              newly sampled token (e.g. "=")
    # pocket_h0_prev: [1, 1, D]  Sweep 0 output saved from token t-1 (e.g. h0_"3")
    e = embed(tok_t)                                                    # [1, 1, D]
    a_1 = torch.sigmoid(W_g(e)) * rms_norm(pocket_h0_prev)              # [1, 1, D]

    H_0 = torch.stack([e, e], dim=-2)                                   # Sweep 0 input: [1, 1, 2, D]
    H_1 = torch.stack([e, e + alpha_fb * a_1], dim=-2)                  # Sweep 1 input: [1, 1, 2, D]
    H_pair = torch.cat([H_0, H_1], dim=0)                               # [2, 1, 2, D] -> 1 weight load!

    H_pair, KV_0, KV_1 = run_looped_core_batched(H_pair, [KV_0, KV_1])
    h0_curr, h1_curr = rms_norm(H_pair.sum(dim=-2)).chunk(2, dim=0)     # [1, 1, D] each
    return lm_head(h1_curr), h0_curr, KV_0, KV_1                        # h0_curr goes into pocket

At batch = 1 autoregressive generation, runtime is bottlenecked by loading model weights from HBM rather than arithmetic, so folding both sweeps into one weight load avoids paying a 2× wall-clock latency penalty while keeping KV_0 and KV_1 aligned with training.

Results and Connection to Our Cognitive Core

Table 2. Key pretraining and decode results reported in Recurloop [2].
Comparison Setting Gain
Pretraining efficiency Matched validation CE loss 2.0×–2.4× fewer FLOPs
Recurloop-1.3B vs. Qwen3.5-2B-Base Math, code, and CRUXEval Beats 2B dense baseline
Parallel KV vs. naive 1-pass decode MATH-500 and GSM8K +7.6 points at 1 weight load

Needing less than half the pretraining FLOPs to reach the same cross-entropy loss—and beating a larger dense baseline on multi-step state tracking—points directly at the same target as our cognitive core: turning shared parameters and structured loop state into higher accuracy per parameter and per FLOP. Where Recurloop separates clean token embeddings from cross-token feedback in two lanes, our gated-delta core [8] separates Attention and MLP loop memory (S_attn, S_mlp) so wrong intermediate deductions are erased rather than averaged, and halts early once ΔS settles.

References

[1]
A. Karpathy, “Andrej Karpathy on the cognitive core (Dwarkesh podcast).” Dwarkesh Podcast, Oct. 2025. Available: https://www.dwarkesh.com/p/andrej-karpathy
[2]
W. Feng et al., “Recurloop Transformer: Superposition across depth and tokens,” arXiv preprint arXiv:2612.03907, 2026, Available: https://arxiv.org/abs/2612.03907
[3]
Y. Yao, Y. Du, D. Zhu, and H. Sun, “ARLoop: Fully-open pre-trained looped Transformers with attention residuals,” arXiv preprint arXiv:2611.05234, 2026, Available: https://arxiv.org/abs/2611.05234
[4]
D. Zhu et al., “Hyper-connections,” in International conference on learning representations (ICLR), 2025. Available: https://arxiv.org/abs/2409.19606
[5]
DeepSeek-AI, “mHC: Manifold-constrained hyper-connections,” arXiv preprint arXiv:2512.24880, 2025, Available: https://arxiv.org/abs/2512.24880
[6]
Kimi Team, G. Chen, Y. Zhang, J. Su, et al., “Attention residuals,” arXiv preprint arXiv:2603.15031, 2026, Available: https://arxiv.org/abs/2603.15031
[7]
C. Yu et al., “MeSH: Memory-as-state-highways for recursive transformers,” in International conference on learning representations (ICLR), 2026. Available: https://arxiv.org/abs/2510.07739
[8]
S. Yang, J. Kautz, and A. Hatamizadeh, “Gated delta networks: Improving Mamba2 with delta rule,” in International conference on learning representations (ICLR), 2025. Available: https://arxiv.org/abs/2412.06464