[Feat] GLM 5.2 support request
Introduction
@antirez We planned to support GLM 5.2 for agent coding. And what the most important is that GLM 5.2 is essentially deepseek v3.2 with shared indexer.
Do you have plan to support it ?
Yes, support is work in progress right now, both for q2 and q4, with SSD streaming and full residency. However currently I have working support only for Metal. CUDA / ROCm work still to start, I may release the Metal version as a preview before working at the rest.
Yes, support is work in progress right now, both for q2 and q4, with SSD streaming and full residency. However currently I have working support only for Metal. CUDA / ROCm work still to start, I may release the Metal version as a preview before working at the rest.
Well that is great news!
Yes, support is work in progress right now, both for q2 and q4, with SSD streaming and full residency. However currently I have working support only for Metal. CUDA / ROCm work still to start, I may release the Metal version as a preview before working at the rest.
I would like to know if the 256 GB of RAM on the Mac can be used with glm 5.2. Thank you very much for your work.
The current 2 bit file I generated is too large, since it uses all Q2_K routed experts tensors. I need to produce one with IQ2 up/gate in order to fit 256 GB of RAM, but yes, it will be supported.
P.S. with --ssd-streaming with 200GB of cache it already works quickly enough btw, for decent usage. But not to the 15 t/s it can go with full residency. With SSD streaming we are in the 10 t/s, however full Q2_K (almost 3 bit) is much better quality I bet.
@antirez , thanks for all the work implementing GLM 5.2. I'll be looking for the strix halo support and happy as usual to do all testing I can. I did run the IQ2_M quant with llama.cpp RPC server across two strix halo nodes, the pp perfromance is not great, I'm curious to compare SSD streaming on a single node with ds and also distrivuted inference.
@kyuz0 thank you Donato, please could you drop me an email? I can't find your email address. Mine is nick at google email. Maybe we can coordinate a bit the work on the Strix Halo about GLM. Thank you. P.S. I'll be traveling today/tomorrow so may not reply promptly.
@kyuz0 thank you Donato, please could you drop me an email? I can't find your email address. Mine is nick at google email. Maybe we can coordinate a bit the work on the Strix Halo about GLM. Thank you. P.S. I'll be traveling today/tomorrow so may not reply promptly.
Sent!
@kyuz0 did you quantize with imatrix ? It is very important in my personal experiences. IQ2_M quant should be independent from the machine you used. Previouly we did this by producing a single node checkpoint.
Any differences in producing two nodes checkpoint, maybe I can coodiante this with you.
GLM-5.2 MTP: measured spec-decode economics on local hardware (α, cost decomposition), plus notes on where the weights live
Different runtime (EXO/MLX, 2× M3 Ultra 512GB, tensor parallel), but most of
this is runtime-agnostic and relevant to the glm5.2 branch, since --mtp is
currently a TODO there.
1. The MTP head: GGUFs already carry it; MLX-land amputated it.
GGUF conversion pipelines preserved layer 78 (blk.78) — and this branch
already anticipates it: block_count is validated as 79 and the weight layout
defines blk.78 with the nextn glue tensors, with the engine skipping the
layer at execution. So wiring --mtp for GLM is purely runtime work, no
weights recovery needed. On the MLX side the situation is worse: mlx-lm's
sanitize silently drops every tensor with layer index ≥ num_hidden_layers,
so no MLX community quant carries the head. We recovered it from the bf16
shards (00270–00274: 791 tensors, ~9.95B params — a full decoder layer with
its own DSA indexer plus the eh_proj/enorm/hnorm/shared_head glue) and
re-quantized it as a sidecar. One config detail relevant either way:
index_share_for_mtp_iteration: true — multi-token draft iterations are
meant to share top-k indices; the MTP path is not indexer-less.
2. Measured acceptance and cost, batch-1 local MoE. With the head restored we built a lossless self-speculative loop (1 draft, verify at L=2, exact-match accept — z is always sampled from the true per-position distribution, so output is distribution-identical at any temperature). Live on the cluster: α = 0.66–0.82 (0.79 greedy technical, 0.70 temp-1 technical, 0.66 temp-1 fiction; exact-match is a lower bound on rejection-sampling acceptance). Zhipu claims they improved this head for GLM-5.2 specifically — as far as I know these are the first independent local numbers on it. Acceptance is not the problem. The problem is the toll, measured at +36 ms/step over stock (~64.5 ms/token baseline at 40k ctx):
- ~20 ms: pipeline serialization — the mid-step accept decision breaks async double-buffering. Implementation artifact, recoverable by deferring the accept read one step (stock already reads results one step lagged).
- ~15 ms: MoE expert double-read at L=2 — the two positions route to mostly different experts. This part is fundamental to spec decode on sparse MoE.
- ~12 ms: the L=2 indexer scan. O(S), so it grows with context depth.
Net v1: parity-minus (−5 to −10% vs stock). With the serialization removed, projection is 1.15–1.4× depending on α and depth. So: not free, not hopeless — an itemizable toll, of which only the ~15 ms is physics.
3. One kernel lesson that will transfer. Prefill-shaped sparse kernels are pathological at verify shapes: the native sparse-MLA Metal kernel in our stack (vendored from an omlx PR) was occupancy-starved at L=2 — ~7 ms/layer × 78 layers ≈ 600 ms/step. Not a defect in the kernel; it's excellent at the shapes it was built for. Guarding on q_len ≥ 64 and routing small L through a simple gather path fixed it. Any prefill-shaped top-k/gather kernel wired into an MTP verify path will likely need the same guard.
Full writeup — recovery/quantization recipe, needle ladder to 539k, per-phase timing methodology (second file in the gist): https://gist.github.com/aidiffuser/a3a5d107fbb08eb00d24c0ad0f2e8d62#file-glm52_mtp_speculative_decode_notes-md
Extraction/sidecar scripts are small and self-contained — happy to share details if useful when GLM MTP lands here.
GLM 5.2 IQ2_XXS QA — MLX Studio beta (Mac M5, 24 GB, SSD streaming)
Independent QA run from MLX Studio using the glm5.2 preview branch and the antirez monolithic GLM GGUF. Full residency was not attempted (197 GB model, 24 GB unified RAM).
Environment
| Field | Value |
|---|---|
| ds4 commit | bd89932 |
| ds4 branch | glm5.2 |
| MLX Studio commit | b6de167 |
| Machine | Mac (Mac17,2), Apple M5 |
| Unified RAM | 24 GB |
| macOS | 26.5.1 (25F80) |
| GGUF | GLM-5.2-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf |
| GGUF size | ~197 GB |
| Client | MLX Studio scripts/start-ssd-chat.sh → ds4-server on :8085 |
Preflight (./scripts/test-glm-ssd.sh): pass=8 fail=0 — branch marker, monolithic GGUF, disk/RAM checks OK.
Quality gate — SSD streaming (score_official)
Built scorer with make gguf-tools/quality-testing/score_official (plain make does not build it).
DS4_GLM_MEMORY_GUARD=0 \
gguf-tools/quality-testing/score_official \
~/mlx-ssd-models/GLM-5.2-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf \
gguf-tools/quality-testing/data/glm52-openrouter-100/manifest.tsv \
/tmp/glm-iq2-streaming.tsv \
4096 \
--ssd-streaming \
--ssd-streaming-cache-experts 8GB
Runtime ~6.5 h for 100 cases on this machine.
Reference band (from QA_BEFORE_RELEASES.md, IQ2/Q2 routed): first-token ~92/100, API top-1 ~0.890, pair-order ~0.800.
Measured (SSD streaming only):
summary cases=100 tokens=2299 avg_nll=0.479170755 first_match=83 avg_lcp=6.890
api_summary ref_tokens=2294 target_tokens=2223 target_mae=0.423860231 target_mean_delta=-0.384877069 top_items=44460 top_mapped=44357 top_coverage=0.997683311 top1_match=1914/2223 top1_rate=0.860998650 topn_hit=29935/44357 topn_recall=0.674865297 top_logprob_count=44357 top_mae=2.396785848 top_mean_delta=1.397802208 pair_agree=319516/414321 pair_rate=0.771179834
| Metric | Result | IQ2 reference | Delta |
|---|---|---|---|
| First-token match | 83/100 | ~92/100 | -9 |
| API top-1 rate | 0.861 | ~0.890 | -0.029 |
| API pair-order | 0.771 | ~0.800 | -0.029 |
| Top coverage | 0.998 | — | — |
3 manifest rows had API/local token-count mismatch (case_019, case_035, case_088); API agreement skipped for those continuation lengths.
Full residency: not run — model does not fit 24 GB RAM.
Note: ds4-server and score_official share /tmp/ds4.lock; stop the server before running the scorer.
Regression tests
DS4_GLM_MEMORY_GUARD=0 DS4_TEST_SSD_STREAMING=1 DS4_TEST_SSD_STREAMING_CACHE_GB=8 \
DS4_TEST_MODEL="$GGUF" \
DS4_TEST_VECTOR_FILE=tests/test-vectors/glm-openrouter/official.vec \
./ds4_test --logprob-vectors
| Test | Result | Notes |
|---|---|---|
--logprob-vectors (5 GLM OpenRouter vectors) |
FAIL | 548 assertion failures vs OpenRouter reference; expected gap for IQ2_XXS |
glm_long_context_smoke.sh |
skipped | default ctx=100k not feasible on 24 GB + 197 GB streaming model |
--tool-call-quality |
not run | — |
Without DS4_GLM_MEMORY_GUARD=0, GLM session creation fails on Macs with 32 GB RAM or less (same guard bypass MLX Studio applies for chat).
Runtime UX (MLX Studio chat probe)
./scripts/start-ssd-chat.sh ds4/glm-5.2-ud-iq2-xxs
./scripts/test-glm-ssd.sh --chat # pass=8 fail=0
| Metric | Observed |
|---|---|
| Server flags | --ssd-streaming --ctx 8192 --ssd-streaming-cache-experts 8GB |
| First chat prefill (19 prompt tokens) | ~107 s |
| Generation (16 tokens, greedy) | ~90 s (~0.18 t/s) |
/v1/chat/completions |
JSON OK; prompt asked for GLM_OK, reply was "GLM" plus reasoning_content |
| Expert cache warning | 370 experts cached vs 600 working set — heavy SSD thrashing on 24 GB |
Multi-turn chat works but is slow on this tier; usable for beta/QA, not production latency expectations.
Conclusion
- [ ] IQ2_XXS meets quality band full residency — N/A on 24 GB
- [ ] IQ2_XXS meets quality band SSD streaming — slightly below IQ2 reference (-9 first-token, -0.03 top-1, -0.03 pair-order); worth maintainer review for this tier
- [x] MLX Studio integration path usable for beta (preflight + OpenAI API chat on
:8085) - Blockers: no crashes/hangs in chat or scorer; strict logprob vectors fail as expected for IQ2_XXS
Happy to re-run full residency on a machine with 128 GB RAM or more, or compare against Q4 XL with compare_scores.py if useful.
GLM-5.2 IQ2_XXS on consumer CUDA (RTX 4060 Ti 16 GB, SSD streaming), glm5.2 branch
Building on the GlmMoeDsa groundwork in #470 / #473 and the IQ2_XXS SSD-streaming runs others have posted here, this is the CUDA counterpart on a single consumer 16 GB card.
Result. GLM-5.2 (743B, 39B active) runs end to end on an RTX 4060 Ti 16 GB with --cuda --ssd-streaming. Greedy decode is coherent and correct:
- "What is the capital of France? Answer in one word." produces "Paris"
- "Name a color." produces "Blue."
- exit 0, all 78 layers on GPU: indexed decode attention, compact LoRA-KV store, DSA indexer, router, streamed routed experts, shared expert.
Model: GLM-5.2-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf (211 GB), streamed from disk. Only the non-routed weights plus KV are resident (about 1.9 GB planned); the routed-expert cache sizes itself to free VRAM.
Speed. 0.06 t/s decode, 0.07 t/s prefill. This is entirely disk-bound: the routed IQ2_XXS experts stream from a slow SATA SSD (about 0.5 GB/s). A Gen5 NVMe (about 14 GB/s) arrives next week and I will re-time then; at this size the streaming bandwidth is the whole story.
What it took, against glm5.2 @ bd89932. The CUDA path on that branch is Metal-gated and was missing the GLM device kernels: compact KV store, DSA indexer, indexed attention, routed MoE plus shared expert, and q8_0 embeddings, plus a force_resident signature mismatch and a Metal-only runtime guard. I filled those in.
The one non-obvious blocker was the routed-MoE launch. It only accepted gate=IQ2_XXS with down=Q2_K (the DeepSeek quant), or all-Q4_K. The UD RoutedIQ2XXS quant keeps both gate and down in IQ2_XXS, which no path handled, so the layer returned 0 after a full attention pass. The fix is a scalar IQ2_XXS dequant functor wired into the GLM pair and down kernels, with the generic-vs-GLM MoE dispatch refined so only IQ2_XXS + Q2_K stays on the DeepSeek kernel. The DeepSeek Flash and Pro paths are untouched and regression-clean on the same build.
Branch (experimental, gated behind DS4_GLM_CUDA_UNSAFE since it rides on the WIP branch): https://github.com/giannisanni/ds4/tree/glm-local
Happy to turn this into a PR against glm5.2 if useful, or to hold until the CUDA GLM path settles upstream, whichever fits your plans @antirez.
For anyone waiting on this: we have GLM-5.2 (743B) running on ds4's CUDA backend in a fork, including SSD streaming of the routed experts, on a single RTX 4060 Ti 16GB with 32GB RAM at ~0.4 t/s. MLA attention, the DSA sparse indexer, and the blk.78 MTP head are all wired.
Fork: github.com/giannisanni/neutronstar (branch glm-local), weights: huggingface.co/giannisan/GLM-5.2-ds4-gguf (196GB uniform-slab IQ2_XXS merge, smaller than the stock UD quant and required for the streaming expert cache addressing). The README documents the port, the streaming fixes it needed, and the env knobs.
It is CUDA only right now, the Metal path for GLM's custom ops is not written. If #496 is what you're hitting (token_embd.weight missing), that's mainline not knowing the GLM tensor names, and this fork is a workaround until official support lands.
The Metal path should work (gglm5.2 branch, not main) if you use the GGUF that you can download with the download script. I also have working ROCm support. But I still miss the CUDA part. I'll merge your code if there is an open PR, @giannisanni
That's great to hear! I'll rebase the CUDA work onto the gglm5.2 branch and open a PR. My fork was built against main so I want to make sure the PR layers cleanly on your GLM plumbing rather than duplicating it, and that it works with your download-script GGUF first (my fork runs a custom uniform-slab merge for the streaming expert cache, that can be a follow-up). Will take a few days to do it properly.
Update: went much faster than expected, the PR is open at #517. Your engine and my fork had converged on nearly the same internal ds4_gpu API, so the CUDA backend linked against the glm5.2 branch almost immediately; it only needed two small engine changes (backend gate + gating the split value-projection on the f16 compact cache). Tested against your official GGUF on the 4060 Ti, decode and batch prefill both correct, numbers in the PR.
@giannisanni First of all, thanks. I’ve seen your PR, and it’s quite substantial (although I don’t have enough CUDA expertise to properly evaluate that part of the code)
Beyond the tests mentioned in the PR, how extensively have you tested it? I was thinking of running some benchmarks across different GPUs. I also have a few ideas about the limitations of speculative decoding on MoE models, and your PR comes at the perfect time since I don’t have a Mac :(
@Lorenzo-Sibi Testing so far is single-GPU, so benchmarks across different cards would be genuinely useful, glad you are up for it. What the PR has been through on my side:
- Hardware: one RTX 4060 Ti 16GB (sm_89), Ryzen 9900X, 30GB RAM, model streamed from a Gen4 NVMe with io_uring (QD64).
- Correctness: greedy decode and batch prefill against the official GGUF, checked for exact expected completions. Batch prefill verified at 200 and 600 token prompts (3.24 and 6.5 t/s prefill, 0.31 t/s decode with a 5GB host expert cache).
- Mileage: the backend in the PR is the same code my fork runs daily for GLM, and since opening it I have ported a second MoE architecture (Tencent Hy3, GQA attention instead of MLA) on top of the same streaming machinery in my fork, which exercised the expert cache and fetch paths well beyond the PR benchmarks.
- Known limits: only sm_89 tested, kernels are dimension-parameterized but tuned on that card, nothing multi-GPU, ROCm untouched.
One thing to watch if you benchmark on CUDA: the IQ2_XXS expert-tile kernels had a shared-memory LUT staging bug for any model with n_embd > 4096 (symptom is fluent garbage, not a crash). The fix is #513 and is included in #517.
On speculative decoding limits on MoE: measured data from the GLM accept loop is in #495. Short version: expert selections across drafted tokens overlap only ~10-30%, so verification cannot amortize disk reads and each verify eval costs nearly a full decode eval. On a streaming box it stays net-negative at any plausible acceptance rate until the disk stops being the bottleneck. Draft-1 telemetry is essentially free though (95-100% hit on GLM). Happy to compare notes if your ideas attack it from another angle.