Add OpenVINO export support for glm4_moe_lite (GLM-4.7-Flash)#1699
Draft
openvino-agent wants to merge 1 commit intohuggingface:mainfrom
Draft
Add OpenVINO export support for glm4_moe_lite (GLM-4.7-Flash)#1699openvino-agent wants to merge 1 commit intohuggingface:mainfrom
openvino-agent wants to merge 1 commit intohuggingface:mainfrom
Conversation
- Add Glm4MoeLiteOpenVINOConfig in model_configs.py that inherits from MiniCPM3OpenVINOConfig to reuse the MLA-style PKV dummy generator (key head dim = qk_nope_head_dim + qk_rope_head_dim, value head dim = v_head_dim) - Add Glm4MoeLitePatcher in model_patcher.py with a vectorized replacement for Glm4MoeLiteNaiveMoe.forward to avoid dynamic control flow (nonzero + loop over experts) that breaks torch.jit.trace - Add glm4_moe_lite test entries to test_decoder.py, test_export.py, test_exporters_cli.py, test_quantization.py, and utils_tests.py - Update docs/source/openvino/models.mdx to list Glm4_moe_lite support
3 tasks
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.
What does this PR do?
Adds native OpenVINO IR export support for the
glm4_moe_litemodel type, which powers the GLM-4.7-Flash family of models (e.g.THUDM/GLM-4.7-Flash).Architecture overview
Glm4MoeLiteForCausalLMis a decoder-only transformer (available in Transformers ≥ 5.0) that combines:qk_nope_head_dim/qk_rope_head_dimkey dimensions and a smallerv_head_dimGlm4MoeLiteMLP) and sparse Mixture-of-Experts (Glm4MoeLiteMoE/Glm4MoeLiteNaiveMoe) layersChanges
optimum/exporters/openvino/model_configs.pyGlm4MoeLitePatcherGlm4MoeLiteOpenVINOConfigregistered underglm4_moe_litefortext-generationandtext-generation-with-pasttasks. Inherits fromMiniCPM3OpenVINOConfigto reuseOVMiniCPM3DummyPastKeyValuesGenerator(which correctly handles MLA-style KV cache shapes:k_head_dim = qk_nope_head_dim + qk_rope_head_dim,v_head_dim).optimum/exporters/openvino/model_patcher.pyglm4_moe_lite_naive_moe_forward— a fully vectorized replacement forGlm4MoeLiteNaiveMoe.forward. The original implementation uses anonzero()-driven Pythonforloop over active experts, which is incompatible withtorch.jit.trace(loop count varies per input). The patch replaces it with batched matrix multiplications (torch.bmm) over all experts simultaneously, producing a consistent graph regardless of routing decisions.Glm4MoeLitePatcher— patches theexpertssub-module inside every sparse MoE layer during export and restores the original on exit.Tests
tests/openvino/utils_tests.py— model ID entry forglm4_moe_liteand expected INT8 node count (42)tests/openvino/test_decoder.py— addglm4_moe_litetoSUPPORTED_ARCHITECTURES(Transformers ≥ 5.0) andEXPECTED_NUM_SDPAtests/openvino/test_export.py— addglm4_moe_liteexport test (Transformers ≥ 5.0)tests/openvino/test_exporters_cli.py— add CLI export test fortext-generation-with-pasttests/openvino/test_quantization.py— add toSUPPORTED_ARCHITECTURES_WITH_AUTO_COMPRESSIONDocs
docs/source/openvino/models.mdx— list Glm4MoeLite (GLM-4.7-Flash) as a supported modelBefore submitting