Edited by humans. Written by AI. How our editing works
All articles

GLM-5's Self-Distillation Trick Solves AI's Memory Problem

GLM-5 uses self-distillation to prevent catastrophic forgetting during training. A deep dive into the engineering that makes 700B-parameter models actually work.

Rachel "Rach" Kovacs

Written by AI. Rachel "Rach" Kovacs

February 21, 20267 min read
Share:
Man with glasses presenting a research paper on GLM-5 training pipeline with diagrams showing pre-training, mid-training,…

Photo: Hugging Face / YouTube

Training a 700-billion-parameter AI model is expensive. Training it multiple times because it forgot how to do basic math while you were teaching it to use tools? That's the kind of expensive that gets people fired.

The team behind GLM-5 ran into this exact problem—and their solution involves teaching the model using itself as the teacher. It's weird. It works. And it reveals something important about how we're going to train [the next generation of AI systems.

The Forgetting Problem

Here's the setup: You've trained a massive language model. Now you want to make it better at reasoning. So you do reinforcement learning focused on math and logic. Great—it gets smarter. Then you want to teach it to use tools and APIs, so you do another round of RL focused on agentic behavior. Also great.

Except now your model has partially forgotten how to do the reasoning tasks you just spent weeks training it on. This is called catastrophic forgetting, and it's been a thorn in the side of AI researchers since before anyone was throwing billions of dollars at these problems.

The Hugging Face team discussing GLM-5's technical paper kept circling back to this issue. As one researcher put it: "If you start from the SFT model and you just do like sequential stages of RL training then the general problem you run into is like catastrophic forgetting. So essentially if I do like agentic training on top of a reasoning model perhaps I start to lose some of my base reasoning capabilities in a trade-off with like the agentic ones."

The standard approach is to just... accept it. You train different specialized models, or you carefully balance your training data, or you throw more compute at the problem until it mostly works. GLM-5's approach is different.

Teaching Yourself Using Yourself

GLM-5 uses what they call "on-policy cross-stage distillation." Strip away the jargon and here's what's happening: at each training stage, the previous version of the model becomes the teacher for the current one.

You train the base model, then do supervised fine-tuning. That SFT model becomes the teacher when you do reasoning-focused RL—you're not just optimizing for good reasoning, you're also trying to stay close to what the SFT model knew. Then that reasoning-RL model becomes the teacher for the agentic-RL stage. And so on.

The team discusses a twist: rather than doing this sequentially, they might be using all the expert models as teachers simultaneously in the final training stage. "You train essentially all these expert models right like you have a math expert... and then I suppose you then take all those models as your teachers and then you do the final stage," one researcher suggests.

Why would you do it this way instead of sequentially? The answer reveals the constraints of working at this scale: "This is the 700 billion parameter model. I guess... the other advantage is also if you do it their way, you can kind of parallelize the effort, right? You don't have to wait for one checkpoint to be trained before you can do the next page."

When your training runs cost millions of dollars and take weeks, being able to parallelize matters. A lot.

The Infrastructure Nobody Talks About

The self-distillation trick is clever, but the researchers spent more time discussing the infrastructure required to make any of this work. This is where the real engineering lives.

GLM-5 uses Deep Seek Sparse Attention, which sounds like a buzzword until you realize what it actually does: instead of every token attending to every previous token (which scales quadratically and becomes computationally absurd), an indexer selects which past tokens actually matter. This isn't new, but it's finicky to train and requires "very careful training strategy" according to the discussion.

Then there's the rollout problem. When you're training an AI agent that might spend hours on a single task—calling APIs, waiting for responses, making decisions—you can't freeze your entire training pipeline waiting for it to finish. GLM-5's solution is to decouple the rollout logic (generating responses, using tools) from the training logic (computing gradients, updating weights).

As one researcher explained: "On the one hand like in the generators you can basically define like kind of arbitrarily complex rollout logic and then you have some like API like HTTP thing... and so the nice thing with that right is that you can develop your own rollout logic without having to have the training stuff coupled."

This seems obvious in retrospect—of course you'd want to develop and test these pieces independently—but it's not how most RL frameworks work. The fact that GLM-5 needed to build this suggests we're at a transition point where the old tooling doesn't quite fit the new problems.

When Theory Meets Practice

The conversation kept hitting moments where the paper's claims didn't quite match the researchers' understanding of the underlying systems. GLM-5 claims to do "entirely on-policy" training for the reasoning stage, but also uses asynchronous RL, "which I think it's inherently off policy," one researcher notes.

Another points out: "I've never really seen a paper using these huge models doing like on policy training but I guess they don't mean like synchronous on policy cuz that would be like super inefficient."

This isn't just academic nitpicking. It matters because on-policy versus off-policy training represents different trade-offs between sample efficiency and computational cost. At 700 billion parameters, those trade-offs become existential.

The team also discusses GLM-5's solution to very long rollouts: they just throw them away if they become too off-policy. "They seem to basically keep like a kind of history of like trajectories and then if you imagine that there's like one like roll out that is like taking let's say 3 hours and by then you've done so many updates to the model that it's like super off policy they uh they discard it."

This is the kind of decision you make when theory meets practice at scale. Is it elegant? No. Does it work? Apparently.

Three Ways to Think

One detail that got overlooked in the infrastructure discussion: GLM-5 can operate in three different reasoning modes. It can preserve all its reasoning traces across conversation turns, discard them to save context, or use "preserved thinking" where it keeps reasoning before each tool call.

This matters for a practical reason the researchers identified: "With this kind of thinking mode you need obviously like a way bigger token budget but they train their agents specifically for long context reasoning."

You're not just training one model anymore. You're training a model that can choose how much thinking to show, how much context to maintain, and when to prioritize efficiency over explainability. The model adapts to the task—coding scenarios need preserved thinking, simple queries don't.

The complexity here isn't in any single technique. It's in the orchestration of dozens of techniques, each addressing a specific failure mode that only emerges when you scale up.

What Actually Shipped

GLM-5 ranks among the best closed-source models on standard benchmarks. The researchers confirmed it uses token-in-token-out interfaces rather than text-in-text-out, which prevents tokenization boundary issues during training. They verified the use of FP8 precision and prefill-decode disaggregation for managing long rollouts.

These aren't the sexy ML breakthroughs that make headlines. They're the engineering decisions that determine whether your training run completes or burns millions of dollars producing garbage.

The self-distillation approach—using previous checkpoints as teachers—might be the most interesting contribution. Not because it's revolutionary, but because it's practical at a scale where most "obvious" solutions break down.

We're past the point where training better AI models is primarily a research problem. It's increasingly an infrastructure problem, a systems engineering problem, a "how do we not forget what we learned" problem. GLM-5's solutions might not be elegant, but they're designed for constraints that most researchers never have to think about: what happens when your training run costs millions and you can't afford to fail twice?

Rachel 'Rach' Kovacs

From the BuzzRAG Team

AI Moves Fast. We Keep You Current.

Framework breakdowns, tool comparisons, and AI coding insights — distilled from the best tech YouTube creators. Free, weekly.

Weekly digestNo spamUnsubscribe anytime

More Like This

A URL comparison showing "http://localhost:3000/myapp" with a red X on the left and green checkmark on the right against a…

Vercel's Portless Tool: Weekend Project or Real Solution?

Vercel Labs released Portless to eliminate localhost port conflicts. Does this weekend project solve a real problem, or create new ones?

Rachel "Rach" Kovacs·5 months ago·5 min read
A bearded man in a gray shirt holds a phone next to large "V4" text with Transformers.js logo and celebratory graphics on a…

AI Models Now Run in Your Browser. That Shouldn't Work.

Transformers.js v4 brings 20-billion parameter AI models to web browsers. The technical achievement is remarkable. The implications are just beginning.

Bob Reynolds·4 months ago·5 min read
Developer with headphones at dual monitors displaying code and analytics in neon-lit workspace, showcasing trending open…

GitHub's Latest Trending Repos Reveal Where AI Is Actually Going

33 trending GitHub repos show how developers are solving real problems with AI agents, local models, and better tooling—no hype, just working code.

Yuki Okonkwo·4 months ago·7 min read
Man in glasses gesturing toward a compact PC tower and anime character figurine against a green pixelated background with…

Nvidia's New AI Model Runs Locally—But There's a Catch

Nvidia just released Nemotron 3 Super for local use, but the Level1Techs team found something weird when they tested it. Context engineering is the new game.

Zara Chen·4 months ago·6 min read
Eight illustrated icons representing dynamic programming concepts including algorithms, data structures, and optimization…

Dynamic Programming: From Theory to Practical Empowerment

Explore dynamic programming's practical power, transforming complex challenges into manageable solutions.

Rachel "Rach" Kovacs·6 months ago·4 min read
Gemini AI interface with code editor showing Next.js portfolio project, overlaid with "3.1 PRO KING MODE" text and Frontend…

System Prompts Are the New Jailbreaks, Apparently

A YouTuber claims a custom prompt turns Google's Gemini 3.1 Pro from waste to winner. It's either clever optimization or a band-aid on broken AI.

Mike Sullivan·5 months ago·7 min read
Developer at desk with dual monitors displaying analytics dashboards and data visualizations in a neon-lit tech environment

34 Self-Hosted Projects That Could Replace Your Cloud Stack

From AI email agents to thermal printer dashboards, these trending GitHub projects show what happens when developers get tired of subscription fees.

Rachel "Rach" Kovacs·3 months ago·6 min read
Bearded man wearing glasses and a beanie gestures toward camera with confused expression, text reads "NOW WHAT?

Why Your AI Agent Sits Idle After Installation

Installing an AI agent takes 10 minutes. Making it actually useful takes 40 hours. Here's why the industry keeps solving the wrong problem.

Rachel "Rach" Kovacs·3 months ago·6 min read

RAG·vector embedding

2026-04-15
1,729 tokens1536-dimmodel text-embedding-3-small

This article is indexed as a 1536-dimensional vector for semantic retrieval. Crawlers that parse structured data can use the embedded payload below.