[KongchangAI]
· 4 min read· 2,045 words

GLM 5.4 Loop Transformer Explained: Coding Capabilities and a Real-World Comparison with Claude

GLM 5.4 Loop Transformer Explained: Coding Capabilities and a Real-World Comparison with Claude

GLM 5.4 uses a loop Transformer to run 106 passes with 78 layers of weights, trading inference compute for reasoning quality.

GLM 5.4 uses a Loop Transformer design: it stores only 78 layers of weights but performs 106 layer passes per token, with the middle 28 layers looped twice, trading inference-time compute for stronger single-pass reasoning. In controlled experiments with equal parameters, the loop version of the 30B design spent only about 10% more training compute, with AIME25 rising from 19.17 to 30.42 and GPQA Diamond from 47.58 to 56.26. Engineering-wise, it controls VRAM overhead through gated write-back, having the second loop pass borrow the first pass's KV cache (keeping only a 128-token window), and 2,048-position sparse attention. In the independent KingBench 4 test, GLM 5.4 scored 33.2 and ranked 7th, about 1.5 points behind Claude Opus 5.5, but took 431 minutes and 1,128 steps versus its predecessor's 109 minutes and 244 steps. Known weaknesses include marathon thinking loops that cause timeouts on short tasks, and estimated weights of about 375GB that make local deployment difficult.

What Is a Loop Transformer: Doing More with Fewer Layers

Most language models are like a tall tower: text enters at the bottom, each layer processes it a little, and it passes upward until the top layer decides the next word. For every token generated, every layer runs once. The usual way to make a model smarter is to add layers—but more layers mean more parameters, higher memory usage, and longer response times.

GLM 5.4 takes a different approach. It stores only 78 layers of weights, but each token generation runs 106 layer passes: the first 26 layers run once, the middle 28 layers (layers 27 through 54) run twice, and the final 24 layers run once. 26+28+28+24 equals exactly 106. The two middle passes reuse the same set of weights—like rereading a difficult problem with the same brain, giving yourself one more chance to reason it through.

This design is called a Loop Transformer. According to z.ai, if you train a loop model from scratch, a conventional model still performs better under the same training budget. So their approach was to first train GLM 5, then continue training it to learn how to use loops—layering a second pass of reasoning on top of existing knowledge. Experiments were first validated at 1B, 4B, and 30B parameter scales.

z.ai frames this design as follows: memory-intensive tasks benefit from more parameters, while reasoning-intensive tasks benefit from more effective compute. Fixing a bug in a large codebase depends at each step on the conclusion of the previous step—knowing more facts only gets you so far. This judgment explains why they chose to focus on the reasoning side rather than simply stacking parameters.

Loop Transformer layer diagram

Decoupling parameters from compute: In a traditional Transformer, the total parameter count is tied to the compute required per generated token (FLOPs)—more layers means more parameters and more compute. The Loop Transformer breaks this coupling: by reusing the same set of weights for multiple forward passes, it increases compute without increasing parameter storage. This idea falls under "inference-time compute scaling," philosophically similar to models like OpenAI's o-series that consume more inference compute by generating longer chains of thought—but the implementation path differs. The latter extends the output sequence length, while the former extends the number of deep processing passes over the same input.

Loops vs. recursion: A Loop Transformer differs from earlier Universal Transformers or recurrent neural networks. RNNs recurse over time steps, whereas a Loop Transformer repeatedly invokes a fixed block of layers along the depth dimension, and the input to each loop is the output of the previous loop plus the original input (via residual connections). As a result, it doesn't suffer from the vanishing gradient problem like RNNs do, and it's easier to parallelize during training.

Engineering Challenges: Overflow, VRAM, and Sparse Attention

Feeding the intermediate layer's output directly back in causes problems: values can become too large, causing upper layers to receive input distributions they never saw during training. z.ai's solution is to add a gate after each loop that controls the proportion of new results written back. After training, the first pass makes small modifications and builds the overall picture, while the second pass lets through more results to refine that picture.

VRAM is the second hurdle. When the model reads a long conversation, it maintains a KV cache (essentially reading notes). If every loop pass saved a complete copy, memory would explode at million-token context lengths. GLM 5.4 has the second loop pass borrow the first pass's notes, keeping its own independent cache only for a very small window (128 tokens).

Another trick for saving compute is sparse attention: the model selects only the 2,048 most critical positions in the text, and the second loop pass looks at the same positions. z.ai says this adds almost no extra overhead, with results close to re-selecting positions.

Second loop pass shares KV cache

What the gating mechanism actually does: The "gate" mentioned in the article is essentially a learnable scalar or vector coefficient, in a form like h_out = h_in + α · f(h_in), where α is determined by training. During the first loop pass, α is close to 0, meaning the intermediate layer's output barely changes the original representation—the model is mainly building a global semantic framework. During the second loop pass, α increases, allowing the intermediate layer to make larger corrections to the existing representation. This design avoids the numerical explosion caused by direct write-back and also lets the two passes take on different functional roles—the first pass "skims," the second "refines."

The economics of KV cache: The KV cache is the memory structure that stores the Key and Value matrices of historical tokens during autoregressive generation, and its size is proportional to context length. At million-token contexts, a single layer's KV cache can reach several GB. GLM 5.4 has the second loop pass reuse the first pass's KV cache, keeping an independent copy only for a 128-token sliding window—compressing the cache overhead of the extra loop from O(context length) to O(128). This is the key engineering decision that makes million-level context feasible.

How Much Does Looping Actually Help: Controlled Experiments with Equal Parameters

The most convincing evidence comes from a set of controlled experiments by z.ai: two versions trained on the same 30B parameter design, with identical total parameter counts. The loop version spent about 10% more training compute, and the gains were—

  • AIME25 (high-difficulty math competition): 19.17 → 30.42
  • GPQA Diamond (high-difficulty science QA): 47.58 → 56.26
  • Long-document reading: 40.33 → 47.67
  • Common sense and instruction following: each improved by about 3 points

According to the video author's estimate, looping adds about 36% more layer passes per token. Reusing layers saves parameters and memory, but the extra compute cost must be paid in full every time a token is generated. This is a clear trade-off: using inference-time compute to buy stronger single-pass reasoning quality.

What AIME and GPQA mean: AIME25 refers to the 2025 American Invitational Mathematics Examination problems, which require multi-step rigorous derivation and place extremely high demands on a model's deep reasoning ability. GPQA Diamond is a graduate-level science QA benchmark covering physics, chemistry, biology, and other disciplines, with problems designed by experts to resist search and shallow reasoning. Both are representative "reasoning-intensive" tasks, echoing z.ai's judgment in the article—that the loop design benefits reasoning-intensive tasks the most. Common sense and instruction-following tasks improved by only about 3 points, which also indirectly shows that the gains from looping are concentrated in scenarios requiring multi-step derivation, rather than knowledge recall or format compliance.

The mismatch between training and inference compute: It's worth noting that the loop version spends only about 10% more training compute, yet pays about 36% more layer passes per token at inference time. This means the "cost" of looping occurs mainly at deployment rather than training—the one-time extra training overhead is small, but it must be paid continuously with every generation. For high-concurrency, low-latency online services, this calculation needs careful weighing; for offline or batch-style complex tasks, it's easier to accept.

Product Capabilities: Multimodal Input, Long Context, and "Generalized Coding"

GLM 5.4 accepts text, image, video, and file inputs, supports contexts up to 1 million tokens, can write up to 128,000 words per response, and always outputs text. On speed, z.ai claims up to 200 tokens per second when idle and 70 to 80 tokens per second under peak load; fused operations reduce memory round-trips.

Multimodal input and long-context support

z.ai calls its goal "generalized coding": as long as the model writes code well enough, it can build all sorts of things with code. The three official examples—a model-dubbed music video, a six-axis robotic arm modeled in FreeCAD, and an interactive 3D birdwatching scene built from scratch with shaders—are quite detailed, including stage lighting, trees and birds, and every joint of the robotic arm. Of course, these are company-selected showcase cases.

Comparison with Claude: Divergence Between Official Head-to-Heads and Independent Tests

z.ai's own comparison covers three models, notably missing Claude. Against the previous generation GLM 5.3, GLM 5.4 has a 51% win rate and 23% loss rate; against Kimi K3.1 Pro it's 42 to 31; against DeepSeekAd V4.0 it's 37 to 33. z.ai also did not publish the flagship version's results on standard coding tests.

The only head-to-head comparison comes from an independent test, KingBench 4: a tester obtained the model early in their own environment and had each model build six complete applications with maximum effort, 10 points each for 60 total. Claude Fable 5.2 led with 42.0, Claude Opus 5.5 scored 34.7, GLM 5.4 scored 33.2, Claude Haiku 5.5 scored 32.5, and GLM 5.3 scored 27.5. GLM 5.4 ranked 7th among 19 models on that leaderboard and, according to the tester, is the best open-source model on the list—about 1.5 points behind Opus 5.5, slightly above Haiku 5.5, and 5.7 points better than its own predecessor.

But the cost dimension cannot be ignored: in the same test, GLM 5.4 took 431 minutes and 1,128 steps; GLM 5.3 took only 109 minutes and 244 steps. Claude Opus 5.5 is priced at $4 per million input tokens and $20 per million output tokens. GLM 5.4 doesn't yet have an API and no per-token pricing; for reference, GLM 5.3 is $1.40 input and $4.40 output, and 5.4 is available through the GLM coding plan starting at $18 per month. When evaluating cost-effectiveness, beyond the per-token price, the total workload consumed by a single run is also worth factoring in.

In another standard test, Terminal Bench 4.0, Anthropic reports Opus 5.5 at 66.4%, while z.ai did not publish GLM 5.4's result, making direct comparison impossible. As for the claim of "competing with 2 to 3 trillion parameter models," it's prudent to reserve judgment until independent tests come out.

GLM coding plan pricing

The significance and limitations of the KingBench 4 methodology: KingBench 4 uses a "maximum effort to build complete applications" evaluation approach, giving each model ample time to iterate, debug, and fix—closer to real development scenarios than single-turn Q&A. This design can expose a model's planning ability, error recovery, and persistence on long-horizon tasks, but it also amplifies runtime differences—GLM 5.4 took 431 minutes and 1,128 steps, nearly 4 times its predecessor, indicating that it trades extensive trial and error for quality. The independent test was conducted by only one tester with a sample of six applications, so statistical power is limited, and 1-2 point gaps between adjacent models on the leaderboard should not be over-interpreted.

The nature of Terminal Bench 4.0: This benchmark tests a model's ability to complete real command-line tasks in a terminal environment, involving file operations, script writing, system debugging, and more—one of the standard tests for evaluating "generalized coding" ability. z.ai did not publish GLM 5.4's result on this benchmark, making direct comparison with Claude Opus 5.5's 66.4% impossible—one of the reasons the article advises reserving judgment on the "competing with 2 to 3 trillion parameter models" claim.

Known Weaknesses and Selection Advice

z.ai itself admits that the model sometimes falls into marathon thinking loops—repeatedly checking after you'd expect it to wrap up. The company says this extra checking helps accuracy, but in one short-task test, both the high-effort and maximum-effort settings hit the 180-second time limit because the model kept changing its mind. This factor needs to be factored in when choosing an effort level.

Another practical constraint is availability: downloadable weights cannot be found. At 4-bit quantization, the weights alone are estimated at about 375GB, far beyond what a laptop can handle. z.ai says the next-generation model will be much larger, with the phrasing "coming soon."

Back to the core question: a bigger model, or a smarter loop? GLM 5.4's answer is the latter—trading fewer stored layers for more inference-time reasoning depth. It trails Claude's top models by a narrow margin in independent tests, but as a representative of the open-source camp, it has already approached the first tier. The cost is longer runtime and higher total consumption per task. If your scenario is reasoning-intensive—complex code fixes, multi-step scientific problems, long-document analysis—this trade-off may be worthwhile; if you're after throughput and low latency, the traditional route of densely stacking parameters remains the safer choice.

#GLM 5.4#Loop Transformer#Claude Opus 5.5#KingBench 4#inference-time compute scaling#open-source LLM
Share:

Related articles