Skip to content

feat(models): port GLM-4V MoE (ViT + GLM-4 MoE text with half-split MRoPE)#598

Merged
inureyes merged 1 commit into
mainfrom
feature/issue-530-glm4v-moe
Jul 1, 2026
Merged

feat(models): port GLM-4V MoE (ViT + GLM-4 MoE text with half-split MRoPE)#598
inureyes merged 1 commit into
mainfrom
feature/issue-530-glm4v-moe

Conversation

@inureyes

@inureyes inureyes commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary

Adds GLM-4V MoE (model_type: "glm4v_moe", GLM-4.5V-class) as a vision-language model, reusing the GLM-4V ViT vision encoder from #529 and the GLM-4 MoE text machinery, wired end-to-end through the shared Qwen-VL runtime. Ported faithfully from references/mlx-vlm/mlx_vlm/models/glm4v_moe/.

What changed

  • src/models/glm4v_moe.rs (new): GLM-4 MoE text backbone with sectioned half-split MRoPE (GPT-NeoX rotation), no q/k norm, two RMSNorm layers per decoder block. The MoE/dense MLP machinery (grouped noaux_tc routing, shared experts, first_k_dense_replace dense layers) is reused from src/models/glm4_moe.rs.
  • src/vision/glm4v_moe.rs (new): VLM wrapper reusing the GLM-4V ViT (src/vision/encoders/glm4v.rs) and its config, the shared Qwen-VL processor/prompt plumbing, LLaVA merge, and compute_rope_index. Implements LanguageModel + shared QwenVlRuntime. The GLM-4V and GLM-4V MoE vision towers differ only in a mathematically equivalent windowed-attention formulation, so the encoder is shared.
  • src/models/glm4v.rs: generalized Glm4vMRoPE with a pairing parameter (even/odd vs half-split), promoted to pub(crate) so both GLM-4V and GLM-4V MoE share one sectioned-MRoPE implementation.
  • Wiring: ModelType::Glm4vMoe + detection.rs arm for "glm4v_moe", model_metadata registration, VLM load route (load_glm4v_moe reusing the GLM-4V weight remap + GLM-4 MoE args), LoadedModel variant + delegation, vlm_runtime dispatch, tensor-parallel arch fallback (glm4_moe), and a docs/supported-models.md row.
  • Tests: a half-split MRoPE-selector unit test and tests/glm4v_moe_parity.rs (config parse + detection in CI; real-model forward gated on checkpoint presence).

Test plan

  • cargo fmt
  • cargo check --lib (clean)
  • cargo test --lib models::glm4v (4 passed, incl. half-split selector)
  • cargo test --test glm4v_moe_parity (4 passed; real-model arms skip without a checkpoint)
  • cargo test --test glm4v_parity (5 passed; feat(models): port GLM-4V (ViT + GLM-4 text) #529 regression check)
  • cargo clippy --lib --tests -- -D warnings (clean)

Real-checkpoint forward-pass validation is deferred to the orchestrator.

Closes #530

…RoPE)

Add GLM-4V MoE (model_type "glm4v_moe", GLM-4.5V-class) as a vision-language model, reusing the GLM-4V ViT vision encoder and the GLM-4 MoE text machinery, wired end-to-end through the shared Qwen-VL runtime.

Text backbone (src/models/glm4v_moe.rs): a GLM-4 MoE backbone driven by sectioned half-split MRoPE. Unlike GLM-4V (sectioned even/odd), GLM-4V MoE uses the sectioned half-split style (GPT-NeoX rotation), applies no q/k norm, and uses two RMSNorm layers per decoder block. The MoE and dense MLP machinery (grouped noaux_tc routing, shared experts, first_k_dense_replace dense layers) is reused from src/models/glm4_moe.rs.

Vision (src/vision/glm4v_moe.rs): reuses the GLM-4V ViT (src/vision/encoders/glm4v.rs) and its config, plus the shared Qwen-VL image processor, prompt-token plumbing, and LLaVA merge, with 3D MRoPE positions from compute_rope_index. The GLM-4V and GLM-4V MoE vision towers differ only in a mathematically equivalent windowed-attention formulation (per-segment vs block-diagonal mask), so the encoder is shared.

Generalized src/models/glm4v.rs: Glm4vMRoPE gains a pairing parameter (even/odd vs half-split) and is promoted to pub(crate) so both GLM-4V and GLM-4V MoE share one sectioned-MRoPE implementation.

Wiring: ModelType::Glm4vMoe variant and detection arm for "glm4v_moe", model_metadata registration, the VLM load route (load_glm4v_moe reusing the GLM-4V weight remap and the GLM-4 MoE args), LoadedModel variant and delegation, vlm_runtime dispatch, a QwenVlRuntime impl, tensor-parallel arch fallback (glm4_moe), and a docs/supported-models.md row.

Tests: a half-split MRoPE-selector unit test plus a glm4v_moe_parity integration test (config parse and detection run in CI; real-model forward passes are gated on checkpoint presence).

Closes #530
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata status:review Under review labels Jul 1, 2026
@inureyes
inureyes merged commit e6463ce into main Jul 1, 2026
5 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Jul 1, 2026
@inureyes
inureyes deleted the feature/issue-530-glm4v-moe branch July 2, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): port GLM-4V MoE (ViT + GLM-4 MoE text)

1 participant