Repository navigation
Add GLM-5.3, and fix GLM-5.2/5.3 output past 2048 tokens - #2512
Merged
Merged
Conversation
This was referenced Oct 30, 2026
Merged
Merged
Merged
Merged
AlexCheema
force-pushed
the
deps/mlx-lm-upstream
branch
from
November 1, 2026 16:02
d5eb3a5 to
66ea418
Compare
Landing commit: this PR's change on top of main, with conflicts with the PRs landed before it resolved as in the tested integration build. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
AlexCheema
force-pushed
the
models/glm-5.3
branch
from
November 1, 2026 16:20
7e19c94 to
8a4ef14
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2509 (upstream mlx-lm), which is stacked on #2508 (MLX 0.32.4) and #2507 (per-family model folders).
Summary
GLM-5.2 and GLM-5.3 have the same architecture (
glm_moe_dsa). It is DeepSeek sparse attention with the indexer shared across layers:exo's previous mlx-lm treated the model as DeepSeek V3.2, with an indexer in every layer. exo also loads checkpoints with
strict=False. So the 57 indexers the checkpoint doesn't contain kept their random initial weights, and nothing reported it.On the first 8 layers of the 4-bit model, next-token top-1 agreement with Hugging Face transformers falls from 0.95 to 0.50 at 3.9k tokens and to 0.36 at 20k tokens. That matches the needle failures above about 2.6k prompt tokens reported in #2270, on both tensor and pipeline sharding.
A header-only load of every mlx-community conversion of these models gives the same result. That covers GLM-5.2
4bit,mxfp4,DQ4plus-q8(the model in #2270) andfp8, and GLM-5.34bitandmixed-4_5bit:Upstream mlx-lm implements the shared indexer (ml-explore/mlx-lm#1410), so the move to upstream mlx-lm (#2509) fixes the model itself. This PR adds what exo still needs:
load_model_checkedrecords the tensor names mlx-lm loads. It raisesMissingWeightsErrorwhen a model parameter was not in the checkpoint.strict=Falsefor the other direction: checkpoint tensors the model doesn't use, such as MTP layers and vision towers.[B, 1, L, 2048]). This only happens for models with shared layers, and only once the context exceedsindex_topk.models/glm/. These are mlx-lm's model with two reference details restored:moe_router_dtype: "float32") and transformers specify. mlx-lm runs the matmul in bf16 and only the sigmoid in float32. On the 8-layer check this moves top-1 from 0.959 to 0.968 and mean KL from 1.0e-4 to 6.2e-5.reasoning_effort.lowandhigh, and GLM-5.2's onlyhigh. Both render every other value as "Reasoning Effort: Max".enable_thinking: trueintomedium, so a plain thinking request ran at Max.xhigh→ Max, the template default;mediumorhigh→ High;none,minimalorlow→ Low on GLM-5.3 (High on GLM-5.2, which has no Low).<think>.enable_thinking: falsenow closes the block (<think></think>), as GLM-5.2's template does.mlx-community/GLM-5.3-4bit.generation_config.json.Long context relies on MLX 0.32.4 (#2508) or mlx-lm's workaround.
Fixes #2270 in exo. The report also mentions corruption under a bare
mlx_lm.server, which was not reproduced here. On a single Mac Studio, origin/main recalls a needle at 1k tokens and fails from about 4.5k on (0/9 prompts), the same threshold #2270 reports for tensor and pipeline sharding. This branch recalls all 15 prompts up to 16k.Test plan
uv run basedpyright(0 errors),uv run ruff check,nix fmt(no changes) andpytest src(1945 passed).load_model_checkedon a model with a missing parameter;reasoning_effort/enable_thinkingcombination through the effort and generation-prompt lines of the GLM-5.2 and GLM-5.3 templates, copied verbatim. The full mlx-community GLM-5.3 template was also checked by hand: see "Chat template" below;Correctness report
Verdict: PASS.
Headline: next-token agreement with transformers past 2048 tokens
Setup:
mlx-community/GLM-5.3-4bit: three indexer layers (0, 1, 2), three shared layers (3, 4, 5), one indexer layer (6) and one shared layer (7).uv.lockbuilds the same tag (36969c09) from source on macOS.Columns:
Each cell is next-token top-1 agreement and mean KL.
(1) transformers' bf16 matmuls on CPU fall back to a scalar kernel, too slow for a 20k-token prompt.
This PR is as close to the float32 reference as transformers' own bf16 forward is:
upstream mlx-lm sits at about 1.5x the noise floor's KL;
origin/main sits at 100x to 300x.
origin/main by layer: the hidden-state error against the reference jumps at layer 3, the first shared layer: from 5e-3 to 0.11-0.18, reaching 0.29-0.46 at layer 7.
Key selection: the shared layers' selections overlap the reference's by 0.54-0.57 on origin/main, against 0.986 with upstream mlx-lm and this PR.
Sparse prefill: past 16,384 tokens, where upstream mlx-lm switches to its sparse prefill, this PR scores top-1 0.968 (KL 6.5e-5), upstream mlx-lm 0.961 (1.0e-4) and origin/main 0.27 (2.9e-2).
Noise floor: transformers' own bf16 run, against its float32 run, has a last-layer median hidden error of 7.0e-3 to 7.3e-3 past 2048 tokens. The other runs, past 2048 tokens:
Pipeline parallel (2 ranks, split at layer 4, a shared layer; 5,999 tokens, positions ≥ 2048)
Three of every four layers past layer 2 are shared layers, so most pipeline split points start a rank on one. On the two Mac Studios here, exo's placement split at layer 38, which is an indexer layer.
Full model, split at layer 39 (a shared layer). This is two Mac Studios, all 78 layers, teacher forcing on the 3.9k-token and 6k-token prompts with 512-token prefill chunks.
Tiny-random parity (
tiny-random/glm-5.3, float32, 4,993 tokens, index_topk 128)Full model: needle recall (single Mac Studio, 4-bit)
Setup:
mlx-community/GLM-5.3-4bit, all 78 layers, through exo's own loading, chat template andmlx_generate, decoding greedily.host=vault-07 service=secrets port=… rotation_code=KESTREL-…) and a question about it.<think></think>.</think>)origin/main's answers past 4k tokens are not wrong answers but token salad. For example, at 8k:
That is the #2270 symptom, here on a single device: correct below about 2.6k prompt tokens, garbage from about 4k.
This PR answers every prompt in the same form, e.g.
The secrets service on host vault-07 has rotation_code KESTREL-6880 and listens on port 22947.On the full model, origin/main's next-token distributions differ from this PR's as follows (teacher forcing, the same four prompts as the 8-layer check):
(1) Below 2048 tokens, only the float32 router, the epsilon and the MLX version differ.
Full model on two Mac Studios: needle recall through the API
Setup:
enable_thinking: false.enable_thinking: falseproduces the same<think></think>prompt.Chat template
On the real GLM-5.3 template:
enable_thinking: true(exo sendsmedium)reasoning_effort: "low"enable_thinking: false<think>opened<think></think>Deviations and caveats
seed * 1000 + length, so the 2,541-token seed-3 prompt and the 4,536-token seed-1 prompt share a code and port, though not a haystack. Each request is independent: there is no prefix cache.Reproduce
The commands use the exo correctness harness and its GLM helper scripts.
Performance (4-bit, one and two Mac Studios)
Setup
MlxJaccl).MlxRing) over the same cable, split by exo at layer 38 of 78.mlx-community/GLM-5.3-4bit(affine, group 64, 418 GB).uv.lockbuilds from source), mlx-lm 6b572ab.Method: the exo correctness harness perf runner, batch 1.
/bench/chat/completions. The prefix cache is off.generation_stats./state.Observations
The raw numbers are in
perf.json.Screenshots
Captured with headless Chromium from the dashboard of the two-Mac-Studio cluster, with the model running 2x tensor parallel over RDMA. Device names are generic.
🤖 Generated with Claude Code