GLM-5.4: Z.ai's first looped transformer, explained

GLM-5.4: Z.ai's first looped transformer, explained
28 layers × 2the middle block of GLM-5 that runs twice, with the same weights
~10%more training compute for the looped version of their 30B test model
19.17 → 30.42on AIME25 with that test model, with the same parameters
200 tokens/soff-peak; 70-80 at peak load
GLM-5.4: Z.ai's first looped transformer, explained
I also walk through it in this video, on my channel Articulator EN. The figures in this post are frames from the video.

What Z.ai announceslink

Over the past three months, the Z.ai team scaled two things at once: the depth of the loop and the size of the model. They say the first surprise came from the architecture itself: if you run the same block of layers several times, the model reasons more deeply with the same weights and, according to them, matches much larger models.

That leads to their two main claims:

  • Intelligence comparable to models with 2 to 3 trillion parameters. That's Z.ai's claim. The article shows no evidence for that comparison, so I read it as a claim, not a result.
  • The start of "generalized coding": code as the foundation for far more tasks than software.

They also admit a flaw: the model tends to get stuck in overly long thinking loops, what they call "marathon thinking". The interesting part is that this long reflection, correcting itself along the way, consistently improves accuracy, beyond what you'd expect from its parameter count.

Reasoning needs compute, not storagelink

Z.ai starts from an idea from its GLM-5.3 technical blog:

  • memory-heavy tasks improve with more parameters, because there's more room to store facts;
  • reasoning-heavy tasks improve with more effective compute, meaning more computation steps for each answer.
Memory: more parameters. Reasoning: more effective compute.
Memory: more parameters. Reasoning: more effective compute.

And the tasks they care about are the second kind: large-scale software engineering, cybersecurity, 3D modeling or physical control. They're all extremely long chains of reasoning, where the model has to follow many steps of cause and effect while keeping the whole thing consistent. That, they say, can't be solved by stacking parameters or memorizing more data.

Standard vs looped transformerlink

In a standard transformer, each layer runs once per forward pass. In a looped transformer, a group of layers that share weights runs several times in a row, and each round refines the state left by the previous one. The result is a deeper network with exactly the same parameters.

Standard vs looped transformer: more layer steps with the same weights.
Standard vs looped transformer: more layer steps with the same weights.

The idea isn't new. The Universal Transformer proposed sharing weights across depth back in 2018, and recent work on recurrent depth and looped language models has shown gains at small scales. The catch is different: sharing weights saves parameters, but with the same pre-training budget a looped model trained from scratch still falls behind a standard one.

Not starting from scratchlink

So Z.ai didn't start from scratch. It took a base model that was already pre-trained and turned it into a looped transformer through continued training. It's like extending a house that's already built instead of putting up a new one. According to the team, this raises the intelligence ceiling with a relatively small compute overhead (they don't give the number for the big model; for the test model they do, see below).

The GLM-5.4 diagramlink

GLM-5.4 takes 28 layers of the GLM-5 base model and runs through them twice. Their architecture figure shows the whole thing:

  • prelude: 26 input layers (L1-26), run once;
  • loop: 28 layers (L27-54) that run twice with the same weights;
  • coda: 24 final layers (L55-78) before the output.

All in a model of about 750 billion parameters. At that scale, just repeating layers isn't enough: after extensive experimentation, they made three changes to balance the gains against the cost of serving it.

A 26-layer prelude, a 28-layer loop that runs twice and a 24-layer coda.
A 26-layer prelude, a 28-layer loop that runs twice and a 24-layer coda.

Change 1: gates that write step by steplink

When you turn the middle layers of a trained model into a loop and each round overwrites the hidden state, the size of the activations (their norms) blows up from one round to the next. The layers after it then receive values outside the scale and distribution they expect.

Z.ai's fix is independent gates per token and per round, which decide how much of each candidate update gets written into the residual stream. In their figure, round k computes xk = xk−1 + βk·(hk − xk−1): with a small β barely anything changes; with β = 1, the full update goes in.

After training, the gates split the work:

  • The first round builds the global context and writes carefully, with the gate almost closed, so the scale stays stable.
  • The second reuses that state to refine the output and opens the gate fully.

They also adjust the step size to each token's difficulty: on the hardest tokens, the first round writes more aggressively, so those complex predictions get more out of the second round's refinement.

The first round's gate almost closed and the second round's fully open.
The first round's gate almost closed and the second round's fully open.

Change 2: a hybrid KV cachelink

While generating, the model keeps a KV cache of what it has already read, so it doesn't recompute it. Done naively, each round of the loop needs its own full cache, and memory gets multiplied by the number of rounds.

Z.ai builds on sharing the cache across rounds and adds a sliding window:

  • the second round reuses the sparse cache selected by the first;
  • and keeps its own fresh cache, but only within a sliding window of the latest tokens (128 in their figure).

The two can overlap at the same positions, so the model attends both to the context from the first round and to the updated version from the second.

The second round reuses the first round's sparse cache and only stores its sliding window.
The second round reuses the first round's sparse cache and only stores its sliding window.

The result: an extra round doesn't cost a cache of the whole context, just one window. And with contexts of a million tokens, according to Z.ai, the increase in deployment cost over GLM-5.3 stays "well under control". They don't give a number.

Change 3: reusing the attention indiceslink

The base model uses sparse attention: an indexer picks which tokens to look at. The second round doesn't recompute those indices; it directly reuses the ones the indexer produced in the first, so indexing costs nothing extra. According to their experiments, it performs almost the same as recomputing them every round.

The second round copies the first round's indices: zero indexing cost.
The second round copies the first round's indices: zero indexing cost.

Does it work at scale?link

For Z.ai, looping is a test of what they call scaling correctness: any architecture change has to keep working as the model grows. So before using it in their flagship, they validated it step by step on base models with 1B, 4B, 30B and 750B parameters.

Validated step by step on 1B, 4B, 30B and 750B base models.
Validated step by step on 1B, 4B, 30B and 750B base models.

The clean comparison was done on the 30B model, which has the same architecture as the big one: two versions with exactly the same parameters, a standard one and a looped one. The looped one used only about 10% more total training compute. The results, after long-context fine-tuning at 200K and with thinking mode on:

BenchmarkBaseline+ LoopGainAvg. length
AIME25 (math)19.1730.42+11.3−635 tokens (−2%)
GPQA-Diamond (hard science)47.5856.26+8.7−2,473 tokens (−11.7%)
AA-LCR (long context)40.3347.67+7.3−539 tokens (−9.7%)
MMLU-Pro (general knowledge)71.6575.05+3.4−863 tokens (−14.9%)
IFBench (instruction following)50.2053.47+3.3−763 tokens (−13.0%)

Keep in mind: this is the 30B test model, not GLM-5.4. The article gives no such table for the big model.

Results of the 30B test model: standard vs looped.
Results of the 30B test model: standard vs looped.

The team's first conclusion: the longer the reasoning chain, the more the loop helps. The biggest gains are in math, scientific reasoning and long context, exactly what generalized coding needs.

Thinking with fewer tokenslink

The second conclusion is more surprising: the looped model writes less. The article's text talks about answers 10-14% shorter on most benchmarks; in its own table, average length drops between 9.7% and 14.9% on four of the five, mostly because the chain of thought gets shorter. On math (AIME25) it barely changes: 2%.

Z.ai's reading: part of the reasoning moves from the tokens the model writes into the implicit depth of the loop.

Speedlink

According to Z.ai, GLM-5.4 reaches 200 tokens per second off-peak and holds 70-80 at peak load. Getting there with a multi-round architecture meant designing the model and the inference infrastructure together: on top of the memory savings from the cache and the indices, they fused the core kernels to cut down intermediate memory reads and writes, the fragmented overhead that looping amplifies.

Generalized codinglink

The article's second big idea. For Z.ai, code has become the foundation for extending what a model can do. Since going all in on coding in early 2025, they have unlocked agentic engineering, long-horizon tasks and cybersecurity. Now they're going after generalized coding, which they say has a higher ceiling and broader impact; GLM-5.4 is just the starting point.

With improvements in both coding and vision, they show four demos that go beyond traditional software:

  • Video: "Hello World", a music video narrated in the model's own voice, produced by writing code to generate and edit it.
  • Engineering: a six-axis robotic arm, with engineering-grade CAD modeling in FreeCAD.
  • Games: a complete game built in one go, with character movement, physics, maps, a combat system and the art.
  • 3D: an interactive close-up bird-watching experience, generated from scratch using only mathematical geometry and hand-written GLSL shaders.
One of the article's demos: a complete game created by the model.
One of the article's demos: a complete game created by the model (video by Z.ai).

These demos were picked by the team itself, so they don't measure anything, but they show where they want to go.

Where to try it and what's nextlink

Z.ai offers it in its GLM Coding Plan, in its ZCode editor and in its chat. The API is "coming soon". As for open weights, they say they'll release them responsibly after completing the necessary safety hardening, with no date.

And they leave open questions:

  • Adaptive compute: giving harder tokens more rounds dynamically.
  • How the gains scale as both the number of rounds and the model size keep growing.

They're not choosing between scaling depth and scaling size: they're going for both. GLM-5.4 validates computational depth, and their next, "significantly larger" model will carry forward what they learned here. They say it will be ready soon.

In shortlink

GLM-5.4 runs 28 layers of GLM-5 twice to think deeper with the same weights. To make it work at 750 billion parameters without blowing up the cost, it adds per-token gates, a hybrid KV cache with a sliding window, and reuses the attention indices. In their 30B test model, the loop gains accuracy, especially on long reasoning chains, and writes fewer tokens. The rest (the comparison with 2-3 trillion parameter models, generalized coding) is Z.ai's bet, and the next model will show how far it goes.

Sourceslink

Continue reading

Last posts -->

Have you seen these projects?

Gymnasia

Gymnasia Gymnasia
Expo
React Native
TypeScript
OpenAI
Anthropic

Fitness app with two agents that run entirely on the device, with no backend, so the user's data never leaves the phone. A BYOK conversational coach with local tools and a remote system prompt with offline fallback, plus a food estimator that pulls macronutrients out of a photo of the plate, with barcode scanning against OpenFoodFacts.

LangGraph Deep Researcher

LangGraph Deep Researcher LangGraph Deep Researcher
Python
LangGraph
FastAPI
React
TypeScript
Docker

Multi-agent research system built with LangGraph. A supervisor breaks your question down into topics and launches search sub-agents in parallel; each one compresses its findings before handing them to a writer agent that produces the final sourced markdown report. Live streaming over WebSockets, a configurable model per role and bring-your-own API keys that are never persisted server-side.

Tau

Tau Tau
Python
LangChain

Multi-agent tutoring system for secondary school students, with one agent per subject and course material written and validated by a team of teachers. It was used with real students at a private school in Spain and at a secondary school in Colombia.

View all projects -->
>_ Available for projects

Do you have an AI project?

Let's talk.

maximofn@gmail.com

Machine Learning and AI specialist. I develop solutions with generative AI, intelligent agents and custom models.

Do you want to watch any talk?

Last talks -->

Do you want to improve with these tips?

Last tips -->

Use this locally

Hugging Face spaces allow us to run models with very simple demos, but what if the demo breaks? Or if the user deletes it? That's why I've created docker containers with some interesting spaces, to be able to use them locally, whatever happens. In fact, if you click on any project view button, it may take you to a space that doesn't work.

Flow edit

Flow edit Flow edit

FLUX.1-RealismLora

FLUX.1-RealismLora FLUX.1-RealismLora
View all containers -->
>_ Available for projects

Do you have an AI project?

Let's talk.

maximofn@gmail.com

Machine Learning and AI specialist. I develop solutions with generative AI, intelligent agents and custom models.

Do you want to train your model with these datasets?

short-jokes-dataset

HuggingFace

Dataset with jokes in English

Use: Fine-tuning text generation models for humor

231K rows 2 columns 45 MB
View on HuggingFace →

opus100

HuggingFace

Dataset with translations from English to Spanish

Use: Training English-Spanish translation models

1M rows 2 columns 210 MB
View on HuggingFace →

netflix_titles

HuggingFace

Dataset with Netflix movies and series

Use: Netflix catalog analysis and recommendation systems

8.8K rows 12 columns 3.5 MB
View on HuggingFace →
View more datasets -->