Skip to content

Add GGUF loading support for GLM-4.5 MoE (glm4moe) - #46718

Closed
mironable wants to merge 2 commits into
huggingface:mainfrom
mironable:gguf-glm4moe
Closed

mironable wants to merge 2 commits into
huggingface:mainfrom
mironable:gguf-glm4moe

Conversation

@mironable

@mironable mironable commented Jun 17, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes #40042

What

Adds GGUF loading support for glm4_moe (GLM-4.5 / GLM-4.5-Air), closing #40042. Previously raised ValueError: GGUF model with architecture glm4moe is not supported yet.

Changes

  • adds glm4moe config mapping (attention + MoE + grouped routing; attention.key_length -> head_dim to preserve the partial-rotary default and a GPT2-style tokenizer converter
  • merges ffn_gate_exps + ffn_up_exps into stacked mlp.experts.gate_up_proj; maps exp_probs_b.bias -> mlp.gate.e_score_correction_bias, glm4_moe<->glm4moe arch aliasing, and a fixup dropping MTP layers from num_hidden_layers and inferring attention_bias/use_qk_norm from tensor presence
  • adds test_glm4moe_f16 logit-parity test

Routed-expert handling mirrors the existing MiniMax-M2 processor (same merged gate_up_proj layout).

Coordination

Issue #40042; maintainer greenlight from @SunMarc. No open PR addresses it (the earlier "base model missing" comment is outdated; glm4_moe modeling now exists)

Testing

Verified against a tiny GGUF, converted from trl-internal-testing/tiny-Glm4MoeForCausalLM, hosted at mironableee/tiny-glm4moe-gguf:

  • gguf vs original state_dict: 0 missing / 0 extra, max abs weight diff 2.98e-08
  • logit parity (committed test): max abs diff 0.0, assert_close passes

Test is @slow + @require_torch_accelerator (inherited), so it runs on GPU CI

AI assistance

Claude code was used in diagnosis. I reviewed every changed line, understood the implementation and ran the tests below myself

Fixture hosting

The fixture currently lives under my personal HF namespace mironableee/tiny-glm4moe-gguf. Please let me know if you 'd like it moved to hf-internal-testingor similar.

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.

PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.

This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read CONTRIBUTING.md.

  • I confirm that this is not a pure code agent PR.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: ggml

@mironable

Copy link
Copy Markdown
Author

fyi @SunMarc (you greenlit this on #40042) and @Cyrilvallez for the GGUF loading path; ready for review when you get a moment

@github-actions

Copy link
Copy Markdown
Contributor

CI Dashboard: View test results in Grafana

@github-actions

Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46718&sha=e88663

@mironable

Copy link
Copy Markdown
Author

tests/models/kosmos2_5/test_modeling_kosmos2_5.py::Kosmos2_5ModelTest::test_generate_with_cache_matches_no_cache (AssertionError: Lists differ on generated token IDs).
It's a Kosmos-2.5 generation/cache nondeterminism unrelated to this GGUF change since it auto-reran 5 times and still flaked. The fetcher pulled it in because the diff touches modeling_gguf_pytorch_utils.py. The actual test_glm4moe_f16 is @slow+@require_torch_accelerator and runs on the GPU CI. Could a maintainer rerun the job? cc @SunMarc

@minatoyukinaa

Copy link
Copy Markdown

#45977 gguf support in transformers will be changed in those pr. So i think we have to wait until those changes are done.

@mironable

Copy link
Copy Markdown
Author

Thanks @minatoyukinaa. @SunMarc @ArthurZucker this just adds the glm4moe arch mapping to the existing GGUF loading path. Should i hold until #45977 lands and rebase on top, or is it ok to merge this small additive mapping independently? Whatever is less churn for you; i'll mark this as draft in the meantime

@SunMarc

SunMarc commented Oct 27, 2026

Copy link
Copy Markdown
Member

We've refactored the GGUF integration to have better speed-up + design, please update the PR according to the new ones. Closing this for now !

@SunMarc SunMarc closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support loading glm4moe GGUF

3 participants