GLM 5.4 Loop Transformer: How 28 Layers Run Twice
Updated
Official Z.ai · architecture report
The GLM 5.4 Loop Transformer repeats a 28-layer shared block to execute 106 effective passes from 78 stored layers without doubling weight memory.
- Stored layers
- 78
- Shared block
- 28 layers × 2
- Effective passes
- 106
The GLM 5.4 Loop Transformer in one forward pass
The GLM 5.4 Loop Transformer runs middle layers 27 through 54 twice while executing the entry and exit blocks once. The GLM 5.4 Loop Transformer stores 78 layers. Since 28 of them run one extra time, total computation visits 106 layers per token. The repeated block consumes the state produced on its first pass, so a second iteration can refine it with the same learned weights.

Z.ai adapted its pretrained GLM-5 base with continued training at the 750B scale. That route preserves a trained starting point while making the repeated block learn to operate on states from both passes. Sharing avoids a second set of weight tensors. The work still includes extra matrix operations, attention and activation traffic. Any physical bandwidth savings depend on serving infrastructure and reuse. See the official architecture report.
Gated progressive updates in GLM 5.4
Per-token, iteration-specific gates let the GLM 5.4 Loop Transformer control how strongly each pass modifies the hidden state. On the first pass, Z.ai observed smaller values as the block builds global context. The second pass typically opens the gates further for refinement. On harder tokens, Z.ai reports stronger first-pass updates. This limits uncontrolled growth in activation norms from running the same block again.
A gate controls the size of a residual update. If a pass proposes a change, a small gate scales it down before it is added to the state. Each iteration can make a different choice for each token. This is a way to allocate refinement within two passes. Z.ai lists variable loop counts for harder tokens as future work.
GLM 5.4 hybrid KV cache design
In the GLM 5.4 Loop Transformer, the hybrid KV cache gives the second pass access to first-pass sparse entries and retains separate second-pass entries only in a local sliding window. Both streams can contribute at the same position. The shared view carries selected distant information, while the local view carries newly computed representations from the current pass.
Under naive two-pass caching, a second set of entries could grow with the full sequence for every loop layer. The hybrid design caps the newly retained second-pass positions by the window size. The gap matters at long contexts because the entire sequence grows while a fixed window does not. The GLM 5.4 VRAM calculator models that trade-off and lists its proxy dimensions and window assumption.
Sparse attention index reuse across GLM 5.4 passes
During pass two of the GLM 5.4 Loop Transformer, attention reuses the first pass’s sparse attention index, which identifies positions to consult in the shared cache. Z.ai reports that the second pass requires no second indexing run and that reuse behaved nearly the same as recomputing the index in its experiments. Value reads and attention still happen on the second pass. Fused serving kernels also reduce intermediate traffic, according to Z.ai.
In a practical deployment, measure cache residency and speed separately. The cost of retaining fewer cache entries and the cost of processing a long prompt can move differently. Hosted throughput figures come from Z.ai’s own stack. A different runtime can encounter different bottlenecks.
What the GLM 5.4 Loop Transformer changes in practice
The GLM 5.4 Loop Transformer explains how more compute fits within a fixed approximate parameter count. Z.ai’s 30B ablation, listed in GLM 5.4 benchmarks, reports improved long-chain reasoning and shorter average output in controlled tests. The GLM 5.4 datasheet summarizes which findings have flagship evidence and which belong to the smaller experiment.
Reasoning depth, output length and wall-clock time answer different questions. For a long repository job, log accepted changes, elapsed time, output tokens and context compaction. Use the GLM 5.4 token counter to estimate the budget impact independently of the performance result.
Read depth and cache as separate budgets
In the GLM 5.4 Loop Transformer, 106 describes layer executions across the network for one token. It says nothing by itself about how many cached values one execution reads. At long context, a sparse index limits the selected global positions. A sliding window limits the additional local state. Both choices affect attention, while weight sharing governs stored model parameters.
The GLM 5.4 base configuration lists 78 stored layers. Z.ai’s loop description identifies the repeated middle block, which works on a state already transformed by the earlier layers. Extra compute is concentrated in the middle of the network.
This distinction matters when reading a memory estimate. A quantized copy can reduce weight storage without using the same format for the KV cache. The public weight format and the runtime still determine which parameters and cache entries can share memory across devices.
Related pages
Frequently asked questions
Does the GLM 5.4 Loop Transformer have 106 weight layers?
It stores 78 layers and executes 106 layer passes. Twenty-eight middle layers are executed a second time with shared weights.
What happens to pass-two cache at 1M context?
The second pass reuses sparse positions from the first pass and maintains a local window of its own KV. Its additional cache scales with that window.
Does a harder token get more loop iterations?
Z.ai describes two iterations with different gated update sizes. Adaptive iteration count is a direction for future work.
Does index reuse remove the second attention operation?
The second pass still computes attention. It reuses the sparse indices already selected by the first pass.