[KongchangAI]
· 3 min read· 1,910 words

GLM-5.4's Looped Transformer: Running Layers Twice for Double the Performance

GLM-5.4's Looped Transformer: Running Layers Twice for Double the Performance

Zhipu's GLM-5.4 uses a Looped Transformer to run some layers twice with shared weights, trading compute for performance.

Zhipu AI's GLM-5.4 uses a Looped Transformer architecture that runs layers 27-54 (28 layers) twice with shared weights, so each token goes through 106 layer passes instead of 78, while the model still stores only ~750B parameters yet performs like a 2-3 trillion parameter model. To address hidden-state inflation and KV cache doubling, z.ai adds a learnable damping gate and lets the second pass reuse the first pass's sparse attention selections and cache. In a 30B controlled experiment, the looped version used ~10% more training compute, improved markedly on math, science, and long-context reasoning, and produced shorter outputs. Costs include marathon thinking, lack of complete benchmarks, and limited open access.

Zhipu AI's (z.ai) new flagship model GLM-5.4 has a counterintuitive design: instead of adding parameters to boost performance, it runs some network layers twice. This architecture, called a "Looped Transformer," lets a model with roughly 750 billion parameters perform like a model with 2 to 3 trillion parameters. z.ai didn't release a full paper—only an architecture diagram, a technical blog post, and one experiment with real numbers.

Looped Transformer concept diagram

What Is a Looped Transformer?

To understand looping, you first need to grasp three key details of a standard Transformer. First, each token is a vector (hidden state), which in GLM-5 is 6144-dimensional. Second, each block doesn't replace the hidden state—it keeps adding the computed results of attention and MLP, forming a "residual stream." Third, each block has its own independent weights; GLM-5 has 78 such layers in total, and each token passes through every layer once, in order.

The Looped Transformer approach: take one group of layers and send the hidden state through that same group again—same weights, used twice. It's like reading a hard problem: you don't grow a second brain, you use the same brain to read it again, and the second pass catches what the first missed. The model therefore does more computation per token without growing in size or adding storage for new layers.

Why does a second pass help? Because problems like math, science, and large-scale code modification have long-chain characteristics, where each step depends on the previous one. Each layer pass is one computation step, and more passes mean the model can complete a longer reasoning chain inside the hidden state before emitting any single token. This differs from reasoning models that "write out their thinking": in those, every thinking token costs time, whereas looping lets part of the thinking happen silently inside the hidden state.

Residual Stream is key to understanding the looped architecture. In a standard Transformer, each sublayer (attention or MLP) doesn't directly overwrite the hidden state; it computes an "increment" that is added to the existing state via a residual connection: h = h + SubLayer(h). This makes the hidden state like a "bus" running through all layers—each layer reads information from the bus, computes, and writes results back. A Looped Transformer connects the same group of layers to this bus again, effectively adding a second read-write cycle; without controls, the second write would stack on top of the first increment, causing bus values to keep inflating—exactly the problem the "damping gate" described below solves.

KV Cache is the memory bottleneck during autoregressive generation. When generating each new token, the model needs to compute attention against all previous tokens, and each previous token's key and value vectors are fixed, so they can be cached to avoid recomputation. But cache size grows linearly with context length: with a million-token context, 28 layers each storing a full set of K/V can consume tens of GB of VRAM. If the loop structure built another cache on the second pass, that would double the cost, so z.ai had to design a cache reuse scheme.

Sparse Attention is a technical approach to reducing attention computation in long-context scenarios. Standard attention computes relevance between each token and all previous tokens, with O(n²) complexity; sparse attention only has each token attend to a small subset of selected tokens. DeepSeekAd Sparse Attention (DSA) works by first using a lightweight indexer to score each previous token, then performing full attention computation only on a fixed number of highest-scoring tokens. This caps the expensive computation per token at a constant level even with million-token contexts, and is the prerequisite for the Looped Transformer's second pass to reuse the cache.

Not a New Idea, But No One Had Done It at This Scale

Layer reuse isn't new. Google Brain and DeepMind's Universal Transformer in 2018 ran the same layer repeatedly; a 2025 Google paper showed that on synthetic reasoning tasks, a small block of layers run multiple times can nearly match a much deeper model; ByteDance's Hogan and Oro also matched larger models with 1.4B and 2.6B parameter recurrent models. But all of these stayed at small scale.

The known pitfall: training a looped model from scratch still lags behind a regular model under the same training budget. So z.ai didn't start from scratch—it took the already-pretrained GLM-5 base and continued training with the loop structure.

Architecture Breakdown: Prelude, Loop, Coda

z.ai's architecture diagram looks complex, but you only need to look at four parts. Layers 1 through 26 are the "prelude," running only once before the loop. Layers 27 through 54—28 layers total—are the loop body, run twice; the diagram explicitly labels them "shared weights," meaning there's only one copy in the model, and the second call uses the same copy with the first pass's output as input. Layers 55 through 78 are the "coda," running only once after the loop. Finally, the output head selects the next token. The model still stores 78 layers, but each token now goes through 106 layer passes.

Three Key Fixes

If you simply feed the hidden state back into the same group of layers, problems appear immediately. Each layer adds its update to the residual stream, and the second round's update stacks onto the same values. z.ai says that with this naive looping, the hidden state inflates with each pass, and the layers after the loop receive value ranges they never saw during training.

The author verified this on a laptop with a Qwen2.5 0.5B model: running the middle 8 layers repeatedly without training dropped the confidence in "the capital of France is Paris" from 32% to 13%; after 8 runs, Paris wasn't even in the top five, and the hidden state's magnitude grew from 0.77 to 1.84—more than doubling.

Repeated layers cause hidden state inflation

z.ai's fix is called a "damping gate": the new hidden state equals the old state plus β times the change proposed by that pass. β is a volume knob—0 means no change, 1 means take it all. Setting β manually to one quarter on a laptop, after 8 runs the magnitude only grew to 1.02 and Paris remained the top choice. Of course, a fixed, untrained β can only limit the damage; making the second pass truly useful depends on training. In GLM-5.4, β isn't fixed—a very small extra layer computes β for each token on each pass. After training, the gate learns to divide the work: on the first pass, β is smaller for cautious updates that build overall context; on the second pass, β opens up to write full updates that refine the output.

The second problem is memory. In attention, each token generates key and value, cached for all previous tokens during text generation—the KV cache. With long contexts the cache is huge, and building another full cache for the second trip through 28 layers would be an enormous memory cost. z.ai's solution: on the second pass, don't build a full cache—read the cache already written in the first pass, and not all of it. GLM-5 uses DeepSeek Sparse Attention (DSA), where a lightweight "lightning indexer" first scores each previous token, and only the top 2048 tokens enter real attention computation. Even with a million-token context, the expensive attention for each token reads only 2048. The second pass directly reuses the first pass's selection results without running the indexer again, and z.ai says the results are nearly identical. The second pass keeps only a sliding-window cache of the last 128 tokens for itself. The two sources of information are merged in a single softmax, and recent tokens may be seen twice. The cost: for older tokens, the second pass sees their keys and values from the first pass, not the refined versions. The model was trained this way and learned to adapt.

KV cache and sparse attention

Experimental Evidence: A 30B Parameter Controlled Comparison

The most trustworthy experiment in the t.z.ai blog: take a 30 billion parameter model designed the same way as the large model, train two versions—one regular, one looped—with the same parameter count, where the looped version uses only about 10% more training compute. On AIME 2025 math, the score rose from 19 to 30; GPQA Diamond graduate-level science from 48 to 56; the long-context reasoning test AALCR from 48 to 50; MMLU Pro from 70 to 75; instruction-following IFBench from 50 to 53. Math, science, long context—exactly the domains of long-chain problems—saw the biggest gains. The looped version also wrote shorter answers, with about 12% to 15% fewer tokens on GPQA, MMLU Pro, and IFBench. z.ai's interpretation: part of the thinking shifted from written text into the loop's extra depth.

Regular vs. looped controlled experiment

For the full GLM-5.4, there's currently only z.ai's own win-rate chart: 51% wins and 23% losses against GLM-5.3; against Kimi K3.1 Pro and DeepSeek V4.1 Flash the lead is narrower.

AIME, GPQA Diamond, MMLU Pro, IFBench are benchmarks measuring different dimensions of model capability. AIME (American Invitational Mathematics Examination) 2025 tests multi-step mathematical reasoning, with long problem chains and low tolerance for intermediate errors—a typical representative of "long-chain problems"; GPQA Diamond is graduate-level science Q&A requiring cross-domain knowledge integration and multi-step derivation; MMLU Pro is a multiple-choice benchmark covering a wide range of subjects, measuring breadth of general knowledge; IFBench specifically tests instruction following, examining whether the model can precisely satisfy fine-grained requirements like formats and constraints; AALCR is a long-context reasoning test checking the model's ability to locate and integrate information in very long inputs. The looped version's gains across these benchmarks are uneven—math and science improved most, matching the hypothesis that "more layer passes equal a longer implicit reasoning chain," while general-knowledge benchmarks improved less, suggesting the loop's benefits concentrate on tasks requiring deep computation rather than breadth.

Costs and Open Questions

The first problem z.ai admits is "marathon thinking": the model tends toward extremely long reasoning, and accuracy is still improving, but users have to wait. Second, GLM-5.4 has no complete benchmark scores yet—the 30B experiment is the main evidence, and the win-rate chart is self-reported. Third, it's currently only available through z.ai's coding solution Zcode and its chat interface; the API awaits safety evaluation, and open-source weights await "safety hardening."

z.ai's own open question: can difficult tokens loop more times and easy tokens fewer? Based on public information so far, GLM-5.4 is the largest known Looped Transformer model. z.ai says the next generation, significantly larger model will continue this design, and looping is likely to become the norm.

One-line Summary

Zhipu's GLM-5.4 uses a Looped Transformer to run some layers twice with shared weights, trading compute for performance.

Paragraph Summary

Zhipu AI's GLM-5.4 uses a Looped Transformer architecture that runs layers 27 through 54—28 layers total—twice with shared weights, so each token goes through 106 layer passes instead of 78, while the model still stores only about 750 billion parameters yet performs like a 2-3 trillion parameter model. To solve the hidden-state inflation and KV cache doubling caused by naive looping, z.ai introduces a learnable damping gate to control the magnitude of each round's update and lets the second pass reuse the first pass's sparse attention selections and cache. In a 30B parameter controlled experiment, the looped version used only about 10% more training compute, improved markedly on math, science, and long-context reasoning, and produced shorter outputs. Costs include marathon thinking, a lack of complete benchmarks, and limited open access channels.

#GLM-5.4#Looped Transformer#Zhipu AI#damping gate#KV cache reuse#sparse attention#LLM architecture
Share:

Related articles