GLM-5.4's Loop Transformer: How 78 Layers Achieve 106 Layers of Depth

GLM-5.4 reuses intermediate layers in a loop to reach 106 layers of depth from 78 without adding parameters, using gating and cache optimization to solve three dead ends.
GLM-5.4 proposes a third scaling path: without adding parameters, it loops the middle 28 layers of a 78-layer base once, reaching a total depth of 106 layers. Direct looping would hit three dead ends: numerical distribution collapse, 36% more KV cache, and repeated indexer scanning. GLM-5.4 uses per-token gating to dynamically scale loop updates by word difficulty, sparse index reuse to skip the second-pass indexer, and hybrid cross-layer cache to store only a 128-token local window, pushing long-context costs close to zero. What's saved is parameters and memory capacity, but generation time and HBM bandwidth are not saved, and speed under heavy load may drop to seventy or eighty tokens per second. The 30B comparison shows 10% training compute buys over 11 points on AIME25, but commercial pricing and real quality still need verification after weights are open-sourced.
Why Has Loop Transformer Suddenly Become a Flagship Architecture?
Over the past two years, large models have basically gotten stronger through two paths: piling on parameters to fatten the model, or lengthening the chain of thought to make the draft longer. GLM-5.4 offers a third path—without adding parameters, it deepens computation by looping and reusing intermediate layers. According to the breakdown by Bilibili creator "过你和青年", GLM-5.4 keeps the 78-layer GLM-5 foundation, doesn't add a single parameter, and simply runs the middle 28 layers one extra time in place, pushing total depth directly to 106 layers.
This idea isn't new. As early as seven or eight years ago, Google's Universal Transformer proposed the concept of looping layers, but no one ever used it for a flagship. There are two reasons: first, Zhipu itself verified that under equal compute, a loop model trained from scratch can't beat a standard large model, so the only option is to first train a good 78-layer base, then fold the middle 28 layers into a loop via continued training; second, once you wire the trained 28 layers straight back in, the model immediately hits three dead ends.

Three Dead Ends: Numerical Distribution, Cache Overhead, and Index Redundancy
Numerical Distribution Collapse
What flows inside the model isn't text but a row of hidden states that are constantly being rewritten. Normally each layer is only accustomed to the data distribution passed down from the previous layer—layer 27 has been trained its whole life to recognize only the magnitude of the numbers right as they exit layer 26. But the data passes through the middle 28 layers, each stacking updates and transformations on top, and by the time it exits layer 54 it has completely changed. The UP host gave a concrete set of numbers: right after exiting layer 26, this row of numbers is around 0.8; after normally running through the middle 28 layers, the network stacks an update of +1.2, and the numbers land at 2.0—which is exactly the range layer 55 is used to receiving. If you stuff 2.0 unchanged back into layer 27, which only recognizes 0.8, those 28 layers will keep adding on according to old habits, the numbers instantly shoot to 5, 6, 7, the feature distribution flies off entirely, and the output collapses into gibberish.
Cache and Index Overhead
Once the numbers are stabilized, memory and compute are the second hurdle. Every time a large model spits out a new character, every layer must store the key and value of historical words into GPU memory (KV Cache). Running the middle 28 layers twice means the second pass's states differ from the first, and the dumbest approach requires storing a separate cache, adding 36% to the whole network's cache. To handle 1 million tokens, GLM-5 uses sparse attention (DSA), where before each attention computation an indexer scores historical code to pick out the important parts. When the middle 28 layers run a second time, the indexer also dumbly rescans the 1 million tokens, doubling the compute those 28 layers spend finding the important parts.

Hidden state refers to the high-dimensional vector output by each layer of the model, the numerical representation of the input text after being encoded at a specific layer, typically with thousands of dimensions. Each layer has its own weight matrix and expects input with a specific statistical distribution. If the input distribution shifts too much (e.g., mean jumps from 0.8 to 2.0), the activations computed by that layer's weights enter the saturation or explosion region of the nonlinear function, causing vanishing gradients or numerical overflow, and the output degrades into gibberish. Therefore, loop layers must ensure each pass's input falls within the distribution range the downstream layers saw during training.
KV Cache is the GPU memory structure that caches each layer's Key/Value tensors for historical tokens during autoregressive generation. When generating a new token, the model only needs to compute the current token's query and perform attention against the cached Key/Value, avoiding recomputation of all history. Its memory usage grows linearly with the number of layers, context length, and hidden dimension; a model with tens of billions of parameters can reach tens of GB at a million-token context. If the loop layer's second pass caches separately, that doubles this portion. Sparse attention (such as DSA) uses a lightweight indexer to select the Top-K most relevant historical blocks for each query and only attends to those blocks, reducing O(n²) complexity to O(n·K), but the indexer itself still needs to scan all historical tokens, and repeated scanning offsets some of the benefit.
How GLM-5.4 Solves It: Per-Token Gating, Index Reuse, and Hybrid Cache
Per-Token Gating: Pulling the Loop Exit's Values Back into the Safe Zone
GLM-5.4 adds a 0-to-1 ratio switch at the exit of each of the two loop passes, called per-token gating—each token manages its own switch. After the first pass through the 28 layers, the network computes the +1.2 update row, but instead of adding it directly, it first multiplies by the first switch. Turn the switch to 0 and it adds 0, leaving the numbers unchanged; turn it to 1 and the numbers jump straight to 2.0, and stuffing them back into layer 27 still collapses. After continued training, the model learns to adapt to each word: for simple words that can be written at a glance—like Python colons, indentation, and return—the model keeps the first switch very low, say 0.2, taking in only +0.24, gently moving the numbers from 0.8 to 1.0; for the truly critical hard words that decide which variable to fill in or whether to check for null, the model opens the switch a bit more, say 0.5, moving the numbers from 0.8 to 1.4—both remain safely within the range layer 27 recognizes.
Per-token gating mathematically performs element-wise scaling on the loop layer's output increment: h_out = h_in + α_t ⊙ Δh, where α_t ∈ [0,1] is computed from the current token's hidden state via a linear layer and Sigmoid, and Δh is the update produced by the 28-layer loop. Unlike the fixed coefficient in residual connections, α_t lets the model adaptively adjust the loop's contribution based on token difficulty. During training, the gating parameters are fine-tuned together with the loop layers, teaching the model to push α toward 0 for simple tokens and moderately raise α for complex tokens, thereby preserving the benefits of deep computation while keeping the distribution stable.
Rereading with Suspicion: The Second Pass's Query Has Changed
After this small step, what did the first pass actually do? In the 28 layers just passed, this word has already used unidirectional causal attention to look back over the error stack traces and function definitions in the previous ten thousand lines of Python, compressing the initial suspicion from that first glance into that +0.6 adjustment. Carrying the new number 1.4, it enters layer 27 a second time; its own number has changed, so the query vector computed by the weight matrix is no longer the first pass's initial version—just like scanning an error first to form a rough suspicion, then rereading the code with that suspicion, the questions asked are far more precise. After the second pass, it exits layer 54; this time it's no longer stuffed back into layer 27 but pushed directly to layer 55. Layer 55 is already waiting to receive fully updated numbers like 2.x, so the second switch can safely be turned up close to 1, solidly writing in the refined result of both passes.

Index Reuse and Hybrid KV Cache
For compute and memory, GLM-5.4 directly uses two tricks. The first is sparse attention index reuse: during the first pass through the 28 layers, the indexer has already picked out from 100,000 lines of code the small batch of functions and definitions most relevant to the current error, equivalent to listing the important line numbers; on the second pass through these 28 layers, the indexer is skipped entirely and blocks are fetched according to the list. Zhipu's evaluation found that the savings come with almost no difference in effectiveness compared to rescoring, and the indexing overhead in the second loop pass drops directly to zero. The second trick is Hybrid KV Cache: on the second pass, when the loop layers look far back across hundreds of thousands of historical tokens, they're still eyeing the same batch of important line numbers selected in the first pass, and the sparse KV at these distant important positions directly borrows the cache stored in the first pass, without re-storing a single byte in memory. The distant Key/Value haven't changed, but the current token's query has, and using the updated query to compute dot-product scores against the same batch of old code can still extract associations not noticed in the first pass. For the hot code just written right in front, the second pass allocates only a fixed-length local sliding window for a short segment immediately adjacent to the current position to store new KV—in the public test configuration this window is as small as 128 tokens. Whether the codebase is 100,000 tokens or a full 1 million tokens, the second pass's newly added cache is fixed at these 128 tokens.
The core of hybrid cross-layer cache is: in the second loop pass, the current token's query vector has been updated, but distant historical tokens' Key/Value are unchanged, so the sparse KV blocks cached in the first pass can be reused. Attention scores = softmax(Q_new · K_old^T / √d) · V_old, still able to capture new associations between the new query and old context. For the local window immediately adjacent to the current position, because the first pass didn't cache it or the distribution changed greatly, the second pass recomputes it and stores it in a fixed-length (e.g., 128-token) sliding window cache, ensuring local details aren't lost. This design keeps the loop layer's second-pass extra memory usage at a constant level, decoupled from total context length.
What It Saves, What It Doesn't

What GLM-5.4 truly saves is parameter count and full memory capacity—no need to build a two-to-three-trillion-parameter giant and stuff it into the data center; guarding the old 78-layer foundation is enough to pull out 106 layers of computational depth. But it doesn't save a single bit of generation time or memory bandwidth. When a large model spits out characters one by one, the GPU's most common bottleneck isn't compute but the HBM bandwidth of moving weights out of memory each round; the middle 28 layers' weights don't fit in on-chip cache, so running the second pass still requires re-fetching and recomputing from memory, and the forward layer count per character genuinely increases by 36%. Add to that the "marathon thinking" that Zhipu itself candidly admits—after deep self-correction, when hitting hard code problems, it easily falls into this mode: it computes meticulously, but doesn't budget, so wait times noticeably lengthen, and under heavy load speed can drop to seventy or eighty tokens per second.
Skipping the second-pass indexer also has boundaries: on the second pass, these 28 layers can only dig deep into the batch of historical blocks picked in the first pass, and cannot temporarily rescore 1 million tokens within the loop layers to swap in a different batch of distant files; fishing for new clues across the whole codebase must be left to layers 55 through 78, which run the indexer as usual, or wait until the next chain-of-thought token is emitted and search again.
30B Comparison and Status Caveats
Zhipu first ran a comparison with a 30B model: spending only about 10% more training compute, the math competition problem AIME25 gained over 11 points. But one must also see the commercial framing clearly—the per-token deduction coefficient is one-third lower than the previous generation, and available quota has risen to 1.5x; these are mainly subscription-tier commercial pricing and overall service optimization, not the loop making per-character compute cheaper. GLM-5.4 currently only has a coding plan online; the standard API and open-source weights will be released gradually after security hardening. The 750B reaching 2T to 3T inference depth and the 30B data are currently all official claims, and the real quality will only be determined after the weights are open-sourced and latency and accuracy are tested on real large projects.
But stepping back, GLM-5.4 has truly brought the path of "trading compute time for parameter memory" onto the main flagship table. In the future, if you see a new model whose parameter table hasn't grown much but which has suddenly gotten much sharper at catching bugs in complex code, take a look at its architecture diagram—there may well be a loop like this hidden inside.
Related articles

MIT PhD Takes You from Scratch to Build DeepSeek: A 25-Hour Hardcore Course
MIT PhD Raj Dandekar launches a 25+ hour Bilibili course building DeepSeek from scratch—MoE, MLA, GRPO, hand-written code plus math derivations, aiming to reproduce mini R1.

DeepSeek Harness in Practice: From Installation to Plugin Ecosystem, Building a Fully Automated AI Workflow
Based on a hardcore Bilibili tutorial, this guide systematically covers DeepSeek Harness installation, three plugin installation methods, and real-world use cases to help developers quickly build customizable AI Agent workflows.

DeepSeek Harness in Practice: From Installation to Automated Workflows
Hands-on DeepSeek Harness tutorial covering Mac/Windows installation, login, workspace binding, model & permission setup, and minimal closed-loop verification for AI automation workflows.