DEV Community

Cover image for Loop transformer: 99.9% vs 98.1% on mod-113 addition
frank chu
frank chu

Posted on

Loop transformer: 99.9% vs 98.1% on mod-113 addition

Loop transformer: 99.9% vs 98.1% on mod-113 addition

My loop transformer beat the baseline 99.9% to 98.1% on held-out mod-113 addition — same 214,530 parameters, no extra weights. The gated version's real win wasn't accuracy, it was stability: its hidden-state norms stayed in a flat 7.5–8.1 band while the ungated loop's hit 21.8.

Zhipu's GLM-5.4 landed on Hacker News yesterday (388 points): a 750-billion-parameter model built on what they call a Loop Transformer — 28 layers run for two iterations, so the network is deeper without adding parameters. The claim that caught me is the one they tested on a 30B model first: same parameter count, only ~10% more training compute, clear gains on math and reasoning, and 10–14% shorter chains of thought, because part of the reasoning moves from output tokens into the loop's implicit depth.

I cannot run GLM-5.4. The weights are not open — the blog says they "plan to open-source the model weights responsibly after completing necessary safety hardening" — and 750B parameters would not fit on this box anyway. What I can do is test the mechanism itself at toy scale: build the smallest loop transformer that can show the effect, and measure whether looping helps at identical parameter counts, or whether it is just a deeper network wearing a parameter-efficiency costume.

The experiment

Task: modular addition mod 113 — the classic grokking task. Input a + b =, output c. All 12,769 pairs split 70/30 into train and held-out test, so the test pairs are never trained on. A model that memorizes gets ~0% on test; a model that learns the algorithm gets ~100%. That split is what makes the comparison honest.

Three models, exactly 214,530 parameters each — the same 4 unique layers (d=64, 4 heads, feedforward 256), the same init, the same data order, the same optimizer (Adam, lr 3e-3, cosine decay), batch 512, 2,000 steps, CPU JAX on an AMD EPYC VM:

  • A, baseline: 4 unique layers, each run once. 4 layers of compute.
  • B, looped: the same 4 layers, but the middle two run twice. 6 layers of compute, same weights.
  • C, looped + gated: B plus a per-token scalar gate on the second pass — my small version of GLM-5.4's "gated progressive updates". The blog's rationale: naively overwriting hidden states makes activation norms blow up across iterations, so the gates write the second pass back proportionally. I wanted to see that blow-up, or not, in the numbers.

I also logged the hidden-state RMS norm after every pass, because the blog's gating story is a claim about norms and I could measure it directly.

The results

Held-out exact-match accuracy (3,831 test pairs):

Step A baseline B looped C looped + gated
250 20.80% 16.84% 18.82%
500 43.67% 42.23% 30.85%
750 62.12% 61.97% 64.27%
1000 76.79% 62.12% 79.87%
1250 91.28% 90.92% 94.78%
1500 98.90% 99.58% 99.03%
1750 99.37% 99.82% 99.48%
2000 98.09% 99.90% 99.77%

All three cross 95% at the same checkpoint, step 1500. Looping did not get there faster in steps. What it did is finish higher: B ends at 99.90%, C at 99.77%, A at 98.09% — though A's final checkpoint dipped from its own peak of 99.37% at step 1750, so the honest gap is somewhere between half a point and two, depending on which checkpoint you pick.

The middle of training is where the three separate. B stalls: 61.97% at step 750, then 62.12% at step 1000 — flat for 250 steps — then jumps to 90.92%. C is the steadiest climber: behind at step 500 (30.85%, the gates start at ~0.12 and throttle the second pass early), then ahead of both at steps 750, 1000 and 1250, leading B by 17.75 points at step 1000 (79.87% vs 62.12%).

And the norms — the part the blog actually theorizes about:

hidden-state RMS norm per pass, step 250 (input, then each layer/pass):
A: [0.09, 5.38, 6.57, 7.86, 12.08]
B: [0.09, 7.14, 8.57, 10.04, 12.55, 15.60, 21.80]
C: [0.09, 5.97, 7.35, 9.34,  9.67, 10.24, 16.35]

hidden-state RMS norm per pass, step 2000 (final):
A: [0.12, 6.23, 7.01, 8.64,  5.40]
B: [0.13, 8.66, 9.25, 9.65, 10.96, 12.74,  8.27]
C: [0.13, 7.47, 8.04, 8.14,  8.07,  7.95,  4.80]
Enter fullscreen mode Exit fullscreen mode

The blow-up is real: at step 250, B's second pass drives the norm to 21.80, nearly double A's final 12.08. The gates work as advertised: C's second-pass norms sit at 9.67 and 10.24 where B's sit at 12.55 and 15.60, and by step 2000 C's norms live in a flat 7.5–8.1 band while B's still span 8.7–12.7. Two caveats, both in the numbers: B's norms settle on their own by step 500 (12.52) — the network learns to manage the blow-up even without gates — and C's final norm after the last layer (4.80) is lower than A's (5.40), so "flat" is not the same as "same scale".

The cost side

B and C run 6 layers per step against A's 4 — 50% more forward compute per step, for a final-accuracy edge of ~1–2 points and no advantage in steps to 95%. Wall time: A 638s, B 1051s, C 1048s (each includes its own JIT compile). Per unit of compute, the baseline is more efficient here; per step, the looped models end higher. Zhipu's "~10% more training compute" does not apply at my scale: their 28 looped layers sit inside a much larger model, so the loop is a smaller fraction of the whole. At 4 layers, the loop is half the network.

The limits of this test

Three, stated plainly. First, this is a toy: 4 layers, one synthetic task, 214,530 parameters against GLM-5.4's 750 billion. A mechanism that works at 30B can fail here and a mechanism that works here can fail there — the direction of the evidence matters more than the size of the gap. Second, mod-113 addition is a memorization-then-generalization task; it rewards depth in a specific way that may not transfer to the long-chain reasoning GLM-5.4 is built for. Third, I trained from scratch, while Zhipu adapted an already pre-trained base model into a loop through continued training — their own blog says looped models trained from scratch lag unshared models under the same pre-training compute budget, and that the conversion is the trick. My test measures the architecture, not their conversion recipe.

Even with those limits, the question I started with has an answer at this scale: looping the same weights twice buys a small, late accuracy edge — 99.9% vs 98.1% at the final checkpoint — at 50% more compute per step, and the gated version's real contribution is stability, not accuracy: flat norms from step 500 on, and the steadiest climb in the middle of training. The mechanism is real. The size of the payoff is a question of scale, and this scale says "small".

Sources

  • Zhipu, "GLM-5.4: Toward Generalized Coding with Our First Loop Transformer", 2026-11-23: https://z.ai/blog/glm-5.4 (HN 388 points). All quoted claims — 750B scale, 28 layers looped twice, 30B iso-parameter ablation with ~10% more training compute, 10–14% shorter output, 200 tok/s off-peak / 70–80 tok/s peak, weights to be open-sourced after safety hardening — are from this post. I also checked HuggingFace for GLM-5.4 weights on 2026-11-23: none listed, consistent with the blog.
  • All training numbers are my own runs on 2026-11-23: AMD EPYC VM, CPU JAX 0.4.34, pure-JAX transformer (214,530 parameters), mod-113 addition, 70/30 train/test split over all 12,769 pairs, Adam lr 3e-3 cosine, batch 512, 2,000 steps. One bug found during the runs and fixed before the gated model trained: the per-token gate broadcast against the hidden state, which crashed the first C run.

Top comments (0)