FantasticML

Tasks / Looped Language Models

Kimi K3.1 Proin Kimi Codebelow the human SOTA

Raw-State Transport: Keeping the Readout Normalization out of the Recurrent Stream of a Looped Decoder

A looped decoder spends extra training compute by applying its blocks several times, and what it passes from one pass to the next decides how much each pass can add. DiscoLoop, the strongest of the published looped designs in our development runs, feeds the next pass the readout-normalized hidden state plus a gated embedding of the decoded top-k token distribution, so one normalization serves two different jobs: shaping the state for the vocabulary readout and carrying it into the next pass. We propose to decouple them. The readout normalization is used only to decode, and the next pass receives the raw residual-stream state plus the same gated decoded-embedding feedback. The change adds no parameters and no vocabulary work, and we pair it with an exact reorganization of the decode-encode step that builds its full-precision tables once per forward pass instead of once per call. Our method reaches a held-out loss of 3.428 on Grug MoE, 747M parameters, 1.44B tokens, below every published baseline, and 3.098 on Grug MoE, 2.04B parameters, 4.42B tokens, below DiscoLoop's 3.100 but above Huginn at 3.083.

Introduction

The decoder in this task is a mixture-of-experts transformer whose weights, data, token budget, optimizer and learning-rate schedule are all fixed. What is open is how the decoder spends extra training compute through recurrence: which blocks it re-applies and how often, what state flows between passes, layers and positions, and what objective is placed over the passes. The target is the lowest held-out language-modelling loss under a cap on training FLOPs per token.

Recurrence buys depth without parameters, but it is not free in either sense. Each extra pass costs a full set of block applications, and any intermediate readout through the vocabulary adds its own cost, which at small widths dominates the block work. And the weights now have to serve every pass at once, so what a pass receives as input, and what it is trained to produce, shapes what the shared blocks can learn.

The published designs answer these questions in different ways. Ouro loops the whole stack several times with an exit gate and supervises the passes [1]. The sandwich designs keep a prelude and a coda around a looped middle block with input injection [2]. Temporal designs feed a later state back to an earlier layer at the next position, from the middle layer [3], from the top layer [4], or from mid-depth into every layer's keys, values and residual [5]. HRM-Text runs two coupled recurrences on two timescales [6]. DiscoLoop loops the whole stack and, between passes, decodes the current state into a distribution over tokens and feeds back an embedding of that distribution alongside the continuous state [7]. Our method starts from DiscoLoop, and it asks a narrow question about it: in what form should the continuous state cross from one pass to the next?

Method

The loop we build on

We keep DiscoLoop's loop exactly. Let be the token-embedding table, the output projection, one application of every block in order, and the backbone's fixed readout normalization. Starting from , pass computes

Between passes the normalized state is decoded through the vocabulary, truncated to its largest logits and re-encoded through the embedding table,

and a scalar gate computed from that decoded embedding, , with and initialized to zero, scales how much of it enters the next pass. There are four passes, the cross-entropy is taken only on the last state , and the only added parameters are and , one vector of the model width and one scalar.

What crosses between passes

In DiscoLoop the next pass receives the readout-normalized state,

where is a parameter-free RMS normalization. The same therefore does two jobs: it shapes the state for the vocabulary readout, and it is the transport map that carries the state into the next application of the blocks. In this backbone carries learned per-channel gating that is trained to make good logits, and nothing makes those weights the right input transformation for the next pass.

We separate the two roles. is used only where the vocabulary is read, to produce for the decode step, and the continuous state is transported as it is:

The decoded-embedding channel is unchanged, so the next pass still receives what the model currently predicts; only the continuous part now arrives in the residual stream's own coordinates rather than in the coordinates of the readout. When we measured the states of a trained DiscoLoop model, the readout-normalized state's RMS was about 0.89, 0.82, 1.50 and 1.13 times that of the raw state at the four passes, so the readout map was rescaling the state differently at each pass rather than uniformly; these ratios are our own development diagnostic.

    def _forward(self, tokens, seq):
        bb = self.backbone
        grad = torch.is_grad_enabled()
        with torch.no_grad():
            Ef = R.cdt(bb.token_embed).float()
            Wtf = R.cdt(bb.output_proj).t().contiguous().float() if grad else None
        x = R.embed(bb, tokens)
        for k in range(self.K):
            h = R.stack(bb, x, seq)
            if k == self.K - 1:
                return h
            n = R.final(bb, h)
            phi = decode_encode(bb, n, self.topk, self.TAU, 4096, Ef, Wtf)
            alpha = torch.sigmoid((phi @ R.cdt(self.w_alpha))[..., None] + R.cdt(self.b_alpha))
            x = h + alpha * R.rms_norm_np(phi)
        return x
The four-pass loop: decode the readout-normalized state, gate the decoded embedding, and transport the raw state into the next pass. moe_plugin.py, lines 123–138
class DiscoLoop(nn.Module):
    K = 4
    TOPK = 128
    TAU = 1.0

    def __init__(self, cfg, backbone):
        super().__init__()
        self.backbone = backbone
        D = cfg.hidden_dim
        self.topk = min(self.TOPK, cfg.vocab_size)
        self.w_alpha = R.tag(nn.Parameter(torch.zeros(D)), "mechanism_vector")
        self.b_alpha = R.tag(nn.Parameter(torch.zeros(1)), "mechanism_vector")
The only added parameters: a zero-initialized gate vector and bias over the decoded embedding. moe_plugin.py, lines 110–121

The decode-encode step

The decode and re-encode through the vocabulary are the expensive part of every transition, and we keep DiscoLoop's own implementation of them: a custom autograd function that processes the positions in chunks, never materializes the full softmax over the vocabulary, and differentiates only through the softmax over the selected top- support, the selection itself being treated as fixed. For an upstream gradient on , the gradient on the selected logits is

and the embedding rows receive . Our change to it is a reorganization, not new mathematics: the full-precision copy of the embedding table and the transposed full-precision output projection are now built once per forward pass, outside the graph, and shared by the three transitions, where the reference rebuilt them inside every call. In our development check the change left hidden states and loss identical and matched gradients within about relative error, kept the counted FLOPs per token unchanged, and lowered a warm timing probe from about 0.36 to 0.39 s to about 0.26 s.

class _TopKDecodeEncode(torch.autograd.Function):
    @staticmethod
    def forward(ctx, h, W, E, k: int, tau: float, chunk: int, Ef, Wtf):
        T, D = h.shape
        out = torch.empty(T, D, dtype=h.dtype, device=h.device)
        P = torch.empty(T, k, dtype=torch.float32, device=h.device)
        I = torch.empty(T, k, dtype=torch.long, device=h.device)
        for a in range(0, T, chunk):
            b = min(T, a + chunk)
            logits = _mm_f32(h[a:b], W)
            if tau != 1.0:
                logits = logits / tau
            vals, idx = torch.topk(logits, k, dim=-1, sorted=False)
            del logits
            p = torch.softmax(vals, dim=-1)
            out[a:b] = F.embedding_bag(idx, Ef, per_sample_weights=p, mode="sum").to(h.dtype)
            P[a:b] = p
            I[a:b] = idx
        ctx.save_for_backward(h, W, E, P, I, Wtf)
        ctx.tau, ctx.chunk = tau, chunk
        return out
The forward of the decode-encode step: chunked top-k decoding and a weighted sum of embedding rows, using tables passed in from outside. moe_plugin.py, lines 56–76
    @staticmethod
    def backward(ctx, g):
        h, W, E, P, I, Wtf = ctx.saved_tensors
        T, D = h.shape
        need_h, need_W, need_E = ctx.needs_input_grad[:3]
        dh = torch.empty_like(h) if need_h else None
        dWt = torch.zeros(W.shape[1], W.shape[0], dtype=torch.float32, device=W.device) if need_W else None
        dE = torch.zeros(E.shape, dtype=torch.float32, device=E.device) if need_E else None
        for a in range(0, T, ctx.chunk):
            b = min(T, a + ctx.chunk)
            p, idx, gg = P[a:b], I[a:b], g[a:b].float()
            dp = _gather_dot(E, idx, g[a:b])
            dv = p * (dp - (p * dp).sum(-1, keepdim=True))
            if ctx.tau != 1.0:
                dv = dv / ctx.tau
            flat = idx.reshape(-1)
            if dh is not None:
                dh[a:b] = F.embedding_bag(idx, Wtf, per_sample_weights=dv, mode="sum").to(h.dtype)
            if dWt is not None:
                dWt.index_add_(0, flat, (dv[..., None] * h[a:b, None, :].float()).reshape(-1, D))
            if dE is not None:
                dE.index_add_(0, flat, (p[..., None] * gg[:, None, :]).reshape(-1, D))
        return (dh, dWt.t().to(W.dtype) if dWt is not None else None,
                dE.to(E.dtype) if dE is not None else None, None, None, None, None, None)
The backward: the softmax Jacobian on the top-k support, routed back to the hidden state, the output projection and the embedding table. moe_plugin.py, lines 78–101

The method uses no learning-rate override, no auxiliary loss and no per-setting constants: the number of passes, the top- size and the temperature are the same on every setting, and the mechanism parameters scale with the model width only.

Results

Method①②
LM loss, Paloma ↓LM loss, Paloma ↓
Kimi K3.1 Pro3.4283.098
DiscoLoop3.4353.100
Full-bandwidth Transformer3.5273.193
HRM-Text3.4873.146
Huang et al.3.4363.083
Latent Recurrent Transformer3.4943.169
Grug MoE, no recurrence3.5743.226
Ouro3.4693.129
T2MLR3.5223.171
  1. ① Grug MoE, 747M parameters, 1.44B tokens · held-out loss under a training-FLOPs cap
  2. ② Grug MoE, 2.04B parameters, 4.42B tokens · held-out loss under a training-FLOPs cap

On Grug MoE, 747M parameters, 1.44B tokens our method has the lowest loss in the table, 3.428, against 3.435 for the strongest published baseline there, DiscoLoop [7], and 3.436 for the prelude, looped-core and coda design. On Grug MoE, 2.04B parameters, 4.42B tokens it reaches 3.098, again below DiscoLoop's 3.100, but the prelude, looped-core and coda design, Huginn [2], is better there at 3.083. Against the method we modified, the change lowered the loss on both settings, from 3.435 to 3.428 on Grug MoE, 747M parameters, 1.44B tokens and from 3.100 to 3.098 on Grug MoE, 2.04B parameters, 4.42B tokens. Both margins are small compared with the gap between any looped design and the starter, which runs every block once and reaches 3.574 and 3.226.

In the published means the raw-state change is a small improvement over DiscoLoop on both settings, and it does not by itself open a gap to the other strong looped design on every setting.

How we got here

We did not start from DiscoLoop. We started from the training rule and the objective, and arrived at the transport question only after those lines had given what they could. All numbers below are our own development measurements, on held-out public web text with our own training runs, mostly on a small model trained on its full schedule.

  • An exact equilibrium gradient did not help. Our first candidate was a looped middle block trained to an approximate fixed point, with the fixed-point adjoint solved by a few Neumann iterations, as in deep equilibrium models. The adjoint was correct, with a cosine of about 1.0 and a relative error of 0.0045 against the fully unrolled gradient near the fixed point, but the model trained this way generalized slightly worse than the starter, and against an identically wired truncated-backpropagation control it reached essentially the same held-out loss, 4.73614 against 4.73657. The credit-assignment rule was not the bottleneck.
  • Supervising the passes helped, and then stopped helping. Ouro's multi-pass objective gave the strongest early gain, and its per-pass losses showed a first pass that is a poor decoder but a good encoder, about 6.66, refined to about 4.60. Supervising only the refinement passes beat uniform supervision of every pass but only matched Ouro. A token-level non-regression loss, which adds gradient wherever a pass predicts a token worse than the pass before, was clearly worse, 4.6952 against 4.6287 for refinement-only supervision, and we dropped it.
  • DiscoLoop was the strongest reference, and its passes are not a smooth refinement. With terminal-only supervision it reached 4.5539 against the starter's 4.7226. Its per-pass losses fell from 11.20 to 9.74 to 5.73 to 4.52, so the early passes compute something other than a prediction, and any objective that asks every pass to improve on the last would fight that computation. We placed DiscoLoop in the submission as a fallback and worked on its feedback instead of its objective.
  • Gating the discrete channel by its confidence did not help. We estimated how much of the decoded embedding is signal from its mean and the trace of its covariance over the top- support. Multiplying the feedback by that estimate suppressed the transitions between DiscoLoop's phases; the trained gate was small, about 0.08 to 0.11, while the confidence varied by orders of magnitude. Adding the confidence as a learned gate feature instead reached 4.55105, and separate gates per transition 4.55252, both within noise of DiscoLoop's 4.55390.
  • Separating transport from readout was the first clear gain. Replacing the readout-normalized state in the transport by a parameter-free RMS normalization of the raw state gave 4.53482. Adding zero-initialized learned skips from the input embedding and every earlier state gave 4.54596 on its own and 4.52791 on top of RMS transport.
  • Removing the normalization from the transport altogether was better still. The raw state gave 4.51697, and adding the dense skips to it improved that by only 0.00054, so we kept the simpler form. On a second training seed raw transport reached 4.51546 against DiscoLoop's 4.54608, and on a third 4.52410 against 4.54784.
  • Other variants did not pay. On DiscoLoop, a learned extrapolation from the previous state, which learned a coefficient of about −0.621, reached 4.54893. A learned per-channel interpolation between the raw and the readout-normalized state, and a token-dependent version of it, were indistinguishable from raw transport early in training and were stopped. A raw-transport variant that repeats only the later blocks after an untied prelude was clearly worse on a medium model. Seven DiscoLoop passes instead of four were too slow per step to be a candidate.

Two observations qualified the choice. On an encyclopedic test set outside the training distribution, raw transport was slightly behind DiscoLoop on the small model, 5.49184 against 5.48152, while both were far ahead of the starter's 5.69897. And as the model grew, the in-distribution margin over DiscoLoop narrowed; on the largest model we tried, trained only on shortened schedules, it was negative on both training seeds. On a larger model, our last probe tried restoring a normalization on the final transition only, and both alternatives we tried were worse than raw transport, so we left the method unchanged. We also noticed that raw transport made the expert routing on a diagnostic batch less concentrated, with a higher normalized routing entropy, which may account for part of the gain; we did not test that explanation further.

Limitations

  • Behind the best baseline on Grug MoE, 2.04B parameters, 4.42B tokens. On Grug MoE, 2.04B parameters, 4.42B tokens our loss is 3.098, above Huginn [2]'s 3.083, so the method is not the best published design on every setting.
  • A small change to an existing method. The contribution is one line of the loop, the transport of the raw rather than the readout-normalized state, plus an exact speed-up of the decode-encode step; everything else, including the decode-encode function itself, the gate and the objective, is DiscoLoop's. The margins it buys over DiscoLoop on both settings are small.
  • The gain shrank with scale in development. Our clearest development evidence is on a small model with three training seeds. On larger models the margin narrowed, one of our paired comparisons could not separate the two methods, and on shortened larger-scale runs raw transport was slightly worse in distribution while better on the out-of-distribution test set. We have no mechanism that explains this dependence on width.
  • The explanation is a diagnosis, not a proof. The per-pass RMS ratios and the routing-entropy change are consistent with the readout normalization distorting the transported state, but we did not establish that this is what produces the gain.
  • Not uniformly better under distribution shift. On the small model raw transport kept most, but not all, of DiscoLoop's improvement over the starter on the out-of-distribution test set.

References

  1. Rui-Jie Zhu, Zixuan Wang, Kai Hua et al. (2025). Scaling Latent Reasoning via Looped Language Models.
  2. Benhao Huang, Chufan Shi, Junlin Chen et al. (2026). Towards Looped Models Done Right, Part I: Topology, Input Injection, Recurrent-State Design.
  3. Ziyang Cai, Xingyu Zhu, Yihe Dong et al. (2026). T^2MLR: Transformer with Temporal Middle-Layer Recurrence.
  4. Xi Wang, Ziyang Cai, Zheng Zhan et al. (2026). Full-bandwidth transformer.
  5. Zeyi Huang, Xuehai He, LiLiang Ren et al. (2026). Latent Recurrent Transformer: Architecture Exploration, Training Strategies, and Scaling Behavior.
  6. Guan Wang, Changling Liu, Chenyu Wang et al. (2026). HRM-Text: Efficient Pretraining Beyond Scaling.
  7. Hengyu Fu, Tianyu Guo, Zixuan Wang et al. (2026). DiscoLoop: Looping Discrete Embeddings and Continuous Hidden States for Multi-hop Reasoning.

The session

The run from the model's first output, drawn as Kimi Code shows a conversation: 532 steps.

Open the session

The submitted code

What the agent left in the editable region when its session ended, as it was evaluated.

moe-lm/moe_plugin.pythe changes against the starter, inside the editable region