fix: import GLM5 fused experts under transformers>=5.13 - #385
Merged
yghstill merged 1 commit intoSep 25, 2026
Merged
Conversation
transformers 5.13 renamed GlmMoeDsaNaiveMoe to GlmMoeDsaExperts (same class body). angelslim/models/llm/glm5_1.py imported the old name unconditionally and angelslim/models/llm/__init__.py imports GLM5_1 eagerly, so with any transformers release from 5.13 up to the declared <6.0 ceiling every CLI and `from angelslim import Engine` failed at import time, even for non-GLM models. Fall back to the new name when the old one is missing, and add a test that the adapter imports and that GlmExpertsWithLinear reproduces the fused experts module's forward on the installed transformers. Fixes Tencent#382
yghstill
approved these changes
Sep 25, 2026
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.
Fixes #382
Problem
angelslim/models/llm/glm5_1.pydoesand
angelslim/models/llm/__init__.pyimportsGLM5_1eagerly. transformers renamed that class toGlmMoeDsaExpertsin 5.13.0 (5.12.x still hasGlmMoeDsaNaiveMoe; 5.13.0 onwards onlyGlmMoeDsaExperts), whilerequirements/requirements.txtallowstransformers>=5.6.0,<6.0. So with transformers 5.13–5.17 (current release 5.17.0) every entry point fails at import time, for any model:Fix
Try the old name first and fall back to the new one:
The alias is exact, not just name-compatible: diffing
GlmMoeDsaNaiveMoe(v5.12.0) againstGlmMoeDsaExperts(v5.17.0) in transformers shows the only change is the class name — samenum_experts/hidden_dim/intermediate_dim/act_fnattributes, same 3-Dgate_up_proj/down_projparameters, sameforward(hidden_states, top_k_index, top_k_weights). Those are exactly what_is_glm_naive_moe()andGlmExpertsWithLinearrely on, so the GLM5 quantization path keeps working rather than silently skipping the expert replacement.Test
tests/test_glm5_experts_compat.py:angelslim.models.llmimports, andglm5_1.GlmMoeDsaNaiveMoeis whichever fused-experts class the installed transformers provides;GlmMoeDsaConfig(hidden 8, intermediate 6, 4 experts) fused experts module wrapped inGlmExpertsWithLineargives the same forward output as the original module (torch.testing.assert_close), i.e. the linearization still matches the renamed class.Checked with transformers 5.17.0 / torch 2.14: on
mainbothimport angelslim.modelsandtools/run.py --helpraise the ImportError above and the new test errors at collection; with this change they succeed, the two new tests pass, andtests/test_config_parser.py+tests/test_install_extras.pystill pass (8 passed). black (99) / isort (black profile) / flake8 (99) clean on the changed lines (the E231 flake8 reports inglm5_1.pyare pre-existing, on lines this PR does not touch).Related: #330 is a different, runtime-level transformers-5.x incompatibility (rope / tied-weights); this PR only restores importability.
Written with Claude Code (AI-assisted) and submitted under the account owner's authorization.