AI State of the Art
SOTA/Advanced Attention Mechanisms/14 min
Section 79

GLM-5.2: Learned Sparse Attention, the Other Road to Long Context

Listen as a podcast →

Two schools for breaking the cost of long context

Facing the exploding cost of attention over long contexts, two strategies compete in 2025-2026. The first compresses the past into a fixed-size memory: that is linear attention (Kimi K3 lesson). The second keeps everything but consults only a selection: that is trainable sparse attention, embodied by DeepSeek and then by GLM-5.2.

Back to the case-file analogy: full attention re-reads the entire file before every sentence; linear attention works from a summary card; sparse attention keeps the whole file at hand but uses an index to open only the right pages.

GLM-5.2 in brief

Zhipu AI / Z.ai (Beijing) released GLM-5.2 on June 13, 2026, under the MIT license (open weights on Hugging Face). The spec sheet:

  • Mixture-of-Experts of roughly 750 billion parameters, with ~40 billion active per token;
  • one-million-token context, output up to 131,072 tokens;
  • tuned for coding, tool use and long-horizon agentic tasks;
  • two reasoning modes: "High" (capped thinking budget, fast, default) and "Max" (larger budget for hard problems).

On several coding and agent benchmarks, GLM-5.2 lands within a point or two of the best US models, at a fraction of the price, one of the symbols of the Chinese labs' 2026 catch-up.

Annotated architecture sheet for GLM-5.2 744B: a transformer block repeated 78 times with RMSNorm, multi-head latent attention combined with DeepSeek Sparse Attention using IndexShare, and a MoE layer of 256 experts of which 8 plus one shared expert are active; insets show the sparse attention mask and the SwiGLU module; at the bottom, an Artificial Analysis coding index ranking where GLM-5.2 scores 51.
The annotated architecture sheet. It carries the numbers from this lesson: 744 billion parameters in total but only 40 active per token, 78 blocks, a one-million-token context, and above all a block whose attention combines MLA with sparse attention plus IndexShare. At the bottom, GLM-5.2's place in the Artificial Analysis coding index, just behind the best closed models.Source : Sebastian Raschka, LLM Architecture Gallery

Learned sparse attention: the indexer

Unlike a fixed sparse pattern (sliding window, blocks, sparse attention lesson), learned sparse attention lets the model decide for itself where to look. The principle, brought to scale by DeepSeek in late 2025 with its DSA mechanism (DeepSeek Sparse Attention):

  1. A lightweight component (the indexer (lightning indexer)) quickly scans the whole context and assigns a relevance score to every past token.
  2. Only the few thousand best-scored tokens (the top-k) are kept.
  3. The expensive full attention is applied only to that selection.

The cost of the ranking is small (the indexer is tiny compared to the attention layers), and the model keeps exact access to the selected tokens, no compression, no summary.

Four-step flow of DeepSeek Sparse Attention: token embeddings enter a lightning indexer that computes similarity scores against the query, a top-k selector keeps the k largest scores, those scores form a sparse attention mask, and attention is then computed only over the surviving tokens.
The four steps of the mechanism, in order. The indexer scores every past token, the selector keeps only the top k, the result becomes a mask that switches off everything else, and full attention then works only on what survived. GLM-5.2 reuses exactly this chain.Source : Sebastian Raschka, LLM Architecture Gallery
IndexShare: GLM-5.2's refinement

Computing one index per attention layer is still redundant: neighboring layers often look at the same places. GLM-5.2 introduces IndexShare: a single indexer is shared across several sparse layers. The index is built once and reused several times, amortizing the cost of the selection.

Chart of the share of compute time spent in the indexer as a function of context length: during prefill it rises from 27 percent at 10,000 tokens to 81 percent at 200,000 tokens, and during decoding from 27 percent to 41 percent over the same range.
Why sharing the index pays off. The longer the context, the more the indexer (supposedly a detail) eats the compute budget: up to 81% of prefill at 200,000 tokens. Computing it once for several layers attacks exactly that line item.Source : IndexCache paper, Z.ai (figure 1)

On top of this comes improved multi-token prediction (MTP): the model predicts several tokens ahead to feed speculative decoding, a small predictor proposes, the big model verifies in one pass (~20% higher acceptance rates, hence noticeably faster generation).

Linear vs sparse: the match-up

Linear attention (Kimi K3)Sparse attention (DeepSeek, GLM-5.2)
Principlecompress the past into a fixed-size statekeep everything, consult only a selection
Memoryconstant, whatever the context lengththe full KV cache stays stored
Exact recallapproximate, hence the 3:1 hybridsexact, on the selected tokens
Risklosing a detail crushed by compressionthe indexer missing the right token
The bet"you can summarize without losing (much)""you can predict where to look"

Neither school has won: Moonshot (Kimi) bets on the first, DeepSeek and Zhipu on the second, and recent work explores combinations of the two.

August 2026 update: GLM-5.3, and GLM lands at Mistral

Two developments since this page was written. GLM-5.3 (August 14, 2026) is a post-training pass over the same base, aimed at coding and cybersecurity: Zhipu reports 66.9% on DeepSWE (some twenty points above GLM-5.2) and open weights published about two weeks after launch; a GLM-5.2 Turbo variant followed on August 17. And on August 11, Mistral opened its platform to third-party open models starting with GLM-5.2, served from its European regions with the same guarantees as its own models (see sovereignty at Mistral): a Chinese open-weights model, hosted in Europe, sold by a French lab. The open-weights market is decoupling from the hosting market.

Key takeaways

  1. GLM-5.2 = ~750 B MoE (40 B active), 1 M context, MIT license, aimed at coding and agents.
  2. Its answer to long context is learned sparse attention: a light indexer selects which tokens to look at; the expensive attention applies only to them.
  3. IndexShare shares the indexer across several layers to amortize its cost.
  4. It is the competing route to linear attention: no compression of the past, but selective consultation, two different bets on the same question.
Check your understanding0 / 4

1. In GLM-5.2's learned sparse attention, what is the indexer's job?

2. Compared with Kimi K3's linear attention, what does GLM-5.2's sparse attention change on the memory side?

3. Why does GLM-5.2 share a single indexer across several layers (IndexShare)?

4. What is the specific risk of each of the two long-context schools?