Repository navigation
feat(gguf): serve GLM-5.3-Flash GGUF checkpoints on glm5-next - #721
void-mckenzie wants to merge 2 commits into
Conversation
Adds the llama.cpp glm5-next GGUF reader (unsloth GLM-5.3-Flash-GGUF, both the glm5-next and the older glm5next arch spellings) on the GGUF quant kind from FlashML-org#690: - parse_gguf_config derives the text config from the GGUF KV metadata, with per-block attention.head_count_kv laying out the KDA/DSA hybrid (tensor-name census fallback for the pre-list writer), the trailing MTP block dropped like the HF loader drops it, and the MLA head widths from the *_length_mla keys (q_b/v_b rows fallback). - iter_gguf_weights maps every tensor to the glm5_next state dict and undoes the converter transforms: A_log stored as -exp(A_log) is inverted, the per-head attn_k_b/attn_v_b pair (k transposed) fuses into the dense kv_b_proj layout the MLA absorption reads, and the q|k|v conv kernels concatenate on the channel axis. The mixed-type fused KDA in_proj (Q8_0 q|k|v + BF16 b|f_a|g_a) rides FlashML-org#702 segments; the routed experts load as GGUF expert banks at their shipped types (unsloth dynamic quants: IQ3_S gate/up + IQ4_XS down, Q8_0 outlier layers pass through natively). - passes quant_config to embed_tokens so the Q8_0 token_embd serves packed; registers Glm5NextGGUFForCausalLM and claims it in the AOT table (also claims the two qwen3.5 GGUF archs FlashML-org#701 left unclaimed, which broke the claim test on main). - expert banks: load_gguf_expert_banks gains the dense-MLP prefix offset (first_k_dense_replace) glm5-next needs -- banks for MoE layers mid-stack read blk.<first + moe_layer> now. Verified end to end against unsloth GLM-5.3-Flash-IQ4_XS (5 split shards): full 45-layer engine on a 32GB GPU serves coherent output with 43 layers of IQ3_S/IQ4_XS experts off host banks; unit tests cover the config parse, the state-dict mapping and each converter transform on a synthetic miniature glm5-next GGUF. Text-only, TP=1. Part of FlashML-org#671.
492e79f to
b463832
Compare
Test stats & setupWorkload results (bs=1, single RTX 5090):
Model: unsloth Launch: Host: Ryzen 9 7950X3D (32 threads), 187 GiB RAM (~130 GiB pinned expert banks), RTX 5090 32 GB (sm_120), driver 580.95.05, CUDA 13.0, Linux 6.8.0-136-generic, shards on a Crucial T500 2 TB NVMe. Stack: Python 3.10.19, torch 2.14.1, triton 3.8, transformers 5.18.0. @jason-fxz Upstreaming my private branch that I was using for GLM 5.3 Flash GGUF. Rebased to current main to align this branch with the gguf direction chosen by the Repo. I also have a branch up for deepseek v4 privately, if you'd like me to help you finish these gguf ports, let me know :) |
…g#707 landed the claim itself)
Part of #671 (Model Support:
glm5-next).Follows the per-family GGUF adapter pattern established for qwen4exp in #690 (config from KV metadata through the family's own
parse_config, checkpoint-leafto_ggufmap,fused()state-dict emission, GGUF expert banks, text-only TP=1).What
Serves llama.cpp
glm5-nextGGUFs — unsloth GLM-5.3-Flash-GGUF — on the GGUF quant kind from #690, reusing the existingglm5_nextmodel classes:parse_gguf_configbuilds the text config from the GGUF KV metadata. The new llama.cpp writer carriesattention.head_count_kvas a per-block list (0 = KDA, 1 = MLA), which encodes the 34/11 hybrid layout directly; unsloth's earlierglm5nextspelling predates it and falls back to a tensor-name census. The trailing MTP block (nextn_predict_layers) is dropped exactly like the HF loader drops the MTP layer. MLA head widths come from the new*_length_mlakeys with aq_b/v_b-rows fallback. The served-model facts the KV cannot express (NoPE, interleaved indexer rope) are pinned to the HF release values.iter_gguf_weightsmaps every tensor into theglm5_nextstate dict and undoes the converter transforms:A_logis stored pre-transformed as-exp(A_log)and inverted at load; the MLAkv_b_projis split per-head asattn_k_b/attn_v_b(k transposed) and re-fused into the dense[H*(nope+v), lora]layout the module's absorption reads; the q|k|v conv kernels concatenate on the channel axis. The mixed-type fused KDAin_proj(Q8_0 q|k|v + BF16 b|f_a|g_a, as shipped) rides the feat(gguf): run experts whose gate_up and down mix float and quantized types #702 segments; kv_b, the indexer projections and the router stay dense where the file stores floats.load_gguf_expert_banksgains the dense-MLP prefix offset (first_k_dense_replace): glm5-next's first MoE layer sits mid-stack, and the banks walkedblk.0before.Glm5NextGGUFForCausalLMregistered and claimed in the AOT table; also claims the two qwen3.5 GGUF archs feat(gguf): serve Qwen3.5 dense and MoE GGUF checkpoints #701 left unclaimed (that omission breakstest_every_registry_architecture_is_claimed_by_an_aot_entryon current main).embed_tokenstakesquant_configso the Q8_0token_embdserves packed.Verified
GLM-5.3-Flash-IQ4_XS(5 split shards, 159 GB): the full 45-layer engine (RTX 5090 32GB, 40k context, 6 GiB expert slot cache) loads 43 layers of IQ3_S/IQ4_XS experts as host banks and serves coherent, correct output over/v1/chat/completions; the tokenizer, eos set and chat template come from the GGUF via the shared loader.zai-org/GLM-5.3-Flashconfig.json throughglm5_next.config.parse_config; the state dict matches the constructed model 1042/1042 tensors (names + shapes).head_count_kvpresent and stripped, trailing MTP block) and cover the config parse, the full state-dict mapping and each converter transform.Text-only, TP=1 — same status as the other GGUF families. Vision (
mmprojsidecar) is a natural follow-up.