GLM-5.2: Anatomy of a Frontier Open Model
local graph
Chapter 44 — GLM-5.2: Anatomy of a Frontier Open Model
Section titled “Chapter 44 — GLM-5.2: Anatomy of a Frontier Open Model”Part XI — Case Studies
Everything in this book has been building toward the ability to read a real frontier model and recognize every part. This chapter does exactly that with GLM-5.2, the 744-billion-parameter open-weight model released by Z.ai (formerly Zhipu AI) in June 2026 under the MIT license. The remarkable thing — and the reason it makes such a fitting capstone — is how little of it is new to you. GLM-5.2 is, almost component for component, the architecture this book has already taught: Multi-head Latent Attention (Chapter 12), DeepSeek Sparse Attention (Chapter 14), a fine-grained Mixture-of-Experts with a shared expert and aux-loss-free routing (Chapter 11), and multi-token prediction (Chapter 13). What it adds on top — its one genuinely novel architectural idea, IndexShare — is a small, elegant refinement you are now fully equipped to understand. We will read GLM-5.2’s actual source, reproduced from its open implementation, and find the whole book inside it.
38.1 The Configuration
Section titled “38.1 The Configuration”GLM-5.2 inherits its shape from GLM-5: a 744B-parameter MoE activating about 40B parameters per token, trained on 28.5 trillion tokens, and — for the first time in the family — serving a stable one-million-token context. Its released configuration maps directly onto the cfg fields of the model we assembled in Chapter 16; only the numbers are larger.
| Parameter | Value | Parameter | Value |
|---|---|---|---|
| Total parameters | 744B | Routed experts | 256 |
| Active per token | ~40B | Shared experts | 1 |
| Layers | 78 | Active experts/token | 8 |
| Hidden size | 6,144 | Dense layers (first) | 3 |
| MLA KV latent | 512 | MoE intermediate | 2,048 |
| MLA query latent | 2,048 | DSA top-k | 2,048 |
| Vocabulary | 154,880 | Context length | 1,000,000 |
| Training tokens | 28.5T | Precision | BF16 / FP8 |
Table 44.1 — GLM-5.2 configuration (from the released glm_moe_dsa_config)
Read that table against Table 16.1. The first three layers are dense and the remaining seventy-five are MoE (first_k_dense_replace = 3), exactly the dense-then-sparse schedule of Chapter 16; the 512-dimensional KV latent and 2,048-dimensional query latent are the A compression of Chapter 12; and 256 routed experts with one shared expert and eight active per token is the fine-grained MoE of Chapter 11. GLM-5.2 is not a new kind of model. It is the model built, scaled up and carefully engineered.
38.2 Normalization and Routing, Unchanged
Section titled “38.2 Normalization and Routing, Unchanged”The smallest pieces are literally the code from earlier chapters. GLM-5.2’s normalization is the RMSNorm of Chapter 8, character for character:
class GlmMoeSARMSNorm(nn.Module): def __init__(self, hidden_size, eps=1e-6): super().__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.variance_epsilon = eps
def forward(self, hidden_states): input_dtype = hidden_states.dtype hidden_states = hidden_states.to(torch.float32) variance = hidden_states.pow(2).mean(-1, keepdim=True) hidden_states = hidden_states * torch.rsqrt( variance + self.variance_epsilon) return self.weight * hidden_states.to(input_dtype)Python — zai-org GLM · glm_moe_dsa: RMSNorm (reproduced, Apache 2.0)
The MoE router is the aux-loss-free design of Chapter 11: a plain linear scorer over experts, plus a per-expert e_score_correction_bias buffer that nudges the load balance without an auxiliary loss — the DeepSeek innovation, reproduced here in GLM’s code:
class GlmMoeDsaTopkRouter(nn.Module): def __init__(self, config): super().__init__() self.top_k = config.num_experts_per_tok # 8 active per token self.n_routed_experts = config.n_routed_experts # 256 experts self.weight = nn.Parameter( torch.empty((self.n_routed_experts, config.hidden_size))) # aux-loss-free load balancing (Chapter 11) self.register_buffer("e_score_correction_bias", torch.zeros(self.n_routed_experts))
def forward(self, hidden_states): hidden_states = hidden_states.view(-1, self.config.hidden_size) return F.linear(hidden_states.float(), self.weight.float())Python — zai-org GLM · glm_moe_dsa: MoE router (reproduced, Apache 2.0)
38.3 DeepSeek Sparse Attention: The Indexer
Section titled “38.3 DeepSeek Sparse Attention: The Indexer”GLM-5.2’s long context rests on DeepSeek Sparse Attention (Chapter 14): rather than attend to all past tokens, each query attends only to the index_topk = 2048 most relevant ones, chosen by a cheap indexer. The indexer is a lightweight attention with its own tiny projections, separate from the main MLA. It scores every past token, keeps the positive matches, and returns the indices of the top 2,048 — turning an O(T²) cost into roughly O(T·k). Here is its core, reproduced and lightly condensed from GLM’s implementation:
# a cheap query/key just for ranking tokens (separate from MLA)q = self.wq_b(q_resid).view(B, S, self.n_heads, self.head_dim)k = self.k_norm(self.wk(hidden_states)) # one key per tokenq_rot, k_rot = apply_rotary_pos_emb(q_rot, k_rot, cos, sin) # RoPE
scores = torch.matmul(q.float(), k.float().transpose(-1, -2)) * self.softmax_scalescores = F.relu(scores) # keep positive matches only
# learned weight per head, summed across heads -> one score per (q, key)weights = self.weights_proj(hidden_states).float() * (self.n_heads ** -0.5)index_scores = torch.matmul(weights.unsqueeze(-2), scores).squeeze(-2)index_scores = index_scores + attention_mask # respect causality
topk = min(self.index_topk, index_scores.shape[-1])return index_scores.topk(topk, dim=-1).indices # [B, S, 2048]Python — zai-org GLM · glm_moe_dsa: DSA indexer top-k selection (reproduced/adapted, Apache 2.0)
The selected indices become an additive mask (zero at the chosen tokens, –∞ elsewhere) that the main MLA attention then uses, so full attention is computed only over the 2,048 kept tokens. GLM notes that this bf16 version is equivalent to their reference kernel, which adds a Hadamard transform and FP8 scoring for speed — orthogonal optimizations that do not change the result.
38.4 IndexShare: The One New Idea
Section titled “38.4 IndexShare: The One New Idea”Here is GLM-5.2’s genuine architectural contribution, and it is small enough to state in a sentence: most layers do not compute their own indexer — they reuse a neighbour’s. The indexer of Section 44.3 is itself work, repeated at every layer; at a one-million-token context that cost adds up. IndexShare runs a full indexer only every few layers and marks the rest as shared, reusing the most recent full indexer’s token selection. The per-layer schedule is just a list:
# most layers REUSE a neighbour's indexer instead of computing their own;# only every "freq"-th layer runs a "full" indexer, the rest are "shared"self.indexer_types = [ "full" if (max(1 - offset + 1, 0) % freq) == 0 else "shared" for i in range(self.num_hidden_layers)]# freq = 4 -> F S S S F S S S ...Python — zai-org GLM · glm_moe_dsa: IndexShare layer schedule (reproduced, Apache 2.0)
with one full indexer per four layers, IndexShare cuts the indexer’s contribution to per-token compute by about 2.9× at a M-token context — the difference between a long context that is affordable to serve and one that is not. The idea is a clean generalization of a theme from Part IV: having paid (in MLA) to make the KV cache cheap and (in DSA) to make attention sparse, IndexShare observes that even the machinery that decides what is sparse can be amortized across layers. It is exactly the kind of refinement you are now equipped to invent.
38.5 Multi-Token Prediction, Context, and Effort
Section titled “38.5 Multi-Token Prediction, Context, and Effort”Three more features round out the model, each a direct application of earlier chapters. GLM-5.2 keeps the multi-token-prediction module of Chapter 13 and improves it for speculative decoding, reporting up to a 20% longer acceptance length — more drafted tokens confirmed per step, hence faster generation. Its one-million-token context is the long-context story of Chapter 9 and Chapter 14 made real: RoPE for position, DSA (now with IndexShare) to keep attention affordable that far out. And it exposes a flexible reasoning effort control — the test-time-compute axis of Chapter 25 — through a single parameter:
# "max" (default) thinks longest; "high" is lighter; off disables thinkingmessages = [{"role": "user", "content": "Refactor this module..."}]inputs = tokenizer.apply_chat_template( messages, reasoning_effort="max", enable_thinking=True)Python — zai-org GLM · controlling thinking budget (reproduced, MIT)
38.6 Running GLM-5.2
Section titled “38.6 Running GLM-5.2”Because GLM-5.2 is a standard (if large) MoE transformer, the serving stack of Part VII runs it directly. The FP8 weights serve on eight GPUs with vLLM, MTP speculative decoding enabled exactly as Chapter 28 described:
vllm serve zai-org/GLM-5.2-FP8 \--tensor-parallel-size 8 \--speculative-config.method mtp \--speculative-config.num_speculative_tokens 3 \--reasoning-parser glm45 \--served-model-name glm-5.2-fp8Shell — zai-org GLM · vLLM deployment (reproduced, MIT)
SGLang, KTransformers, and (quantized) llama.cpp, Ollama, and LM Studio run it too, down to consumer hardware — the full deployment arc of Chapter 33. For RL post-training at this scale, Z.ai built and open-sourced slime, an asynchronous RL infrastructure in the spirit of Chapter 19.
The whole book, in the wild GLM-5.2 is the strongest demonstration this book can offer that its contents are not a simplified model of the real thing — they are the real thing. Open its source and you find RMSNorm and SwiGLU, RoPE, MLA’s latent KV cache, a 256-expert aux-loss-free MoE, DeepSeek Sparse Attention, and multi-token prediction: every mechanism built from scratch in these pages, assembled into a frontier model that competes at the top of the open-source field. Its one new idea, IndexShare, is a two-line refinement to a technique you implemented yourself. You can now read a state-of-the-art model and understand all of it — which means you can build, modify, and improve one too.
44.7 Worked Example: What IndexShare Saves
Section titled “44.7 Worked Example: What IndexShare Saves”GLM-5.2’s most distinctive idea is IndexShare, and its value is best seen as arithmetic. DeepSeek Sparse Attention (Section 44.4) runs a lightweight indexer at each attention layer to decide which past tokens every query should attend to. That indexer is cheap per layer but not free, and at million-token context it is paid 78 times over. IndexShare observes that the indexer’s selections change slowly with depth, so it computes a fresh index only at every fourth sparse layer and reuses it at the three layers in between:
def indexer_types(n_layers, freq=4, offset=3): out = [] for i in range(n_layers): fresh = max(1 - offset + 1, 0) % freq == 0 out.append("full" if fresh else "shared") return out # F S S S F S S ...Python — glm/indexshare.py: per-layer indexer schedule (illustrative)
A sharing frequency of four, only one layer in four computes the indexer; the other three borrow it. Z.ai reports this cuts indexer FLOPs by roughly 2.9× at one-million-token context — not the attention itself, but the selection machinery in front of it, which at that length is a meaningful slice of the bill. The schedule’s pattern (a “full” layer followed by three “shared” ones) is exactly the kind of cheap structural insight that distinguishes a production system from a research prototype: no new mathematics, just the observation that a slowly varying quantity need not be recomputed every layer.
44.8 The Decoder Layer, Assembled
Section titled “44.8 The Decoder Layer, Assembled”Everything in this chapter composes into a single decoder layer, and seeing it whole shows how little of GLM-5.2 is genuinely new versus inherited from the architecture this book has built. Each layer normalizes, applies MLA attention with DSA selection (sharing the indexer when the schedule says so), normalizes again, and routes through the mixture of experts:
def decoder_layer(x, layer_idx): shared = indexer_types(n_layers)[layer_idx] == "shared" h = x + attention(rmsnorm(x), share_indexer=shared) # MLA + DSA if layer_idx < first_k_dense_replace: out = h + dense_mlp(rmsnorm(h)) # first 3 layers else: out = h + moe(rmsnorm(h)) # 256 experts, 8 active + 1 shared return outPython — glm/decoder_layer.py: one block, end to end (illustrative)
Two production details stand out. The first three layers use a dense MLP rather than the mixture (first_k_dense_replace = 3), a common stabilization choice — the earliest layers, which shape the most basic features, are kept dense to avoid routing instability where the model can least afford it. And the MoE activates 8 of 256 routed experts plus 1 always-on shared expert per token. Read against Chapters 11 through 16, there is almost nothing here you have not already implemented: GLM-5.2 is the book’s architecture, tuned and scaled, with IndexShare as its one genuinely novel flourish.
A frontier model is mostly familiar parts Strip GLM-5.2 to its decoder layer and it is MLA, DSA, and a top-8-of-256 MoE — every piece built earlier in this book. The frontier advances less by reinventing the block than by scaling it and shaving its constants, as IndexShare does.
44.9 Controllable Reasoning Effort
Section titled “44.9 Controllable Reasoning Effort”A defining feature of GLM-5.2, shared with the current generation of reasoning models, is that the amount of thinking is tunable at inference time. The same model can answer a simple question directly and cheaply, or spend a long chain of thought (Chapter 38) on a hard one — and which it does is controlled by a reasoning-effort setting the application chooses per request.
The mechanism turns the test-time-compute axis of Section 38.6 into a product feature. At low effort the model is prompted (and was trained) to respond directly, minimizing latency and cost for the many queries that do not need deliberation. At high effort it generates extended reasoning before committing to an answer, paying more compute for better results on genuinely hard problems. This “hybrid thinking” lets a single deployed model serve both regimes, rather than forcing a choice between a fast model and a smart one — the application dials the budget to match the task. It is a direct, commercial expression of the book’s recurring theme that reasoning is bought with inference compute (Chapter 38), and it is why the GLM-5.2 interface exposes a reasoning_effort control: the knob the user turns is, underneath, the length of the reasoning the model is permitted to generate.
One model, a dial for thinking Controllable reasoning effort exposes the test-time-compute trade as a per-request setting: answer directly when cheap suffices, reason at length when the problem demands it. One model spans both, with the application choosing the budget.
44.10 GLM-5.2 in the Lineage
Section titled “44.10 GLM-5.2 in the Lineage”Placing GLM-5.2 in context is itself one of the lessons of studying t. Architecturally, it is very nearly DeepSeek-V3’s blueprint — Multi-Head Latent Attention, sparse attention, a fine-grained mixture of experts, multi-token prediction (Chapter 45) — not because one copied the other but because the field has converged on these components as the effective way to build a large model. That convergence is the headline: two independently developed frontier models, from different organizations, share the same skeleton.
What distinguishes GLM-5.2 is therefore not radical architectural novelty but refinement along three axes. Its one genuinely new architectural idea, IndexShare (Section 44.7), is an efficiency optimization — reusing the sparse-attention indexer across layers — rather than a new kind of layer. Its controllable reasoning effort (Section 44.9) is a product feature, exposing the test-time-compute trade as a setting. And its scale and training data — 744 billion parameters, tens of trillions of tokens — are a matter of execution. Read together, GLM-5.2 is evidence for how the frontier now advances: the architecture is increasingly a shared, stable foundation, and differentiation comes from efficiency refinements, training data and scale, and product surface — not from reinventing the transformer block. That is a more mature phase of a field than the one that produced a new architecture every year, and recognizing it is part of reading the frontier correctly.
Convergence, then refinement GLM-5.2 shares DeepSeek-V3’s architecture not by imitation but by convergence — the field has settled on MLA, sparse MoE, and MTP. Its edge is refinement: IndexShare’s efficiency, reasoning control, and scale. The frontier now advances by tuning a shared foundation.