Skip to content

Add GLM MoE Metal active expert patches - #1063

Merged
i386 merged 1 commit into
mainfrom
jd/glm-moe-metal-active
Jul 23, 2026
Merged

Add GLM MoE Metal active expert patches#1063
i386 merged 1 commit into
mainfrom
jd/glm-moe-metal-active

Conversation

@i386

@i386 i386 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a GLM MoE Metal patch queue on top of the merged GLM-DSA llama foundation
  • add active-expert Q3 down kernels and Q2 gate/up dispatch controls for GLM-5.2 style expert tensors
  • add selector diagnostics and focused backend/perf tests for selected expert paths

Why

This keeps the GLM MoE performance work separate from the core GLM-DSA architecture and IndexShare support. The GLM-DSA foundation has landed in #1034; this PR is the next layer.

Validation

  • LLAMA_WORKDIR=$(mktemp -d /tmp/mesh-llm-llama.XXXXXX) scripts/prepare-llama.sh pinned

Summary by CodeRabbit

  • Performance

    • Improved Metal acceleration for GLM Mixture-of-Experts models by processing only active experts and skipping zero-weight or inactive slots.
    • Added specialized execution paths for different active-expert counts, potentially reducing dispatch overhead and improving inference efficiency.
    • Updated routing and workload calculations to better reflect active-expert usage.
  • Diagnostics

    • Added optional terminal diagnostics for troubleshooting GLM MoE Metal execution.
    • Expanded configuration options for enabling or disabling experimental execution modes.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f6215f0-a5d1-49de-8292-6cc6c386b24e

📥 Commits

Reviewing files that changed from the base of the PR and between e92422f and 09ee9ca.

📒 Files selected for processing (12)
  • third_party/llama.cpp/patches/0030-ggml-default-GLM-MoE-two-phase-Metal-path.patch
  • third_party/llama.cpp/patches/0031-ggml-add-GLM-MoE-Metal-selector-diagnostics.patch
  • third_party/llama.cpp/patches/0032-ggml-skip-zero-weight-GLM-MoE-gate-up-slots.patch
  • third_party/llama.cpp/patches/0033-tests-cover-full-GLM-MoE-selected-chain.patch
  • third_party/llama.cpp/patches/0034-tests-add-GLM-Q2Q3-selected-weight-roofline.patch
  • third_party/llama.cpp/patches/0035-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch
  • third_party/llama.cpp/patches/0036-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch
  • third_party/llama.cpp/patches/0037-ggml-honor-explicit-Q2-gate-up-Metal-variant-flags.patch
  • third_party/llama.cpp/patches/0038-ggml-make-GLM-MoE-roofline-honor-active-experts.patch
  • third_party/llama.cpp/patches/0039-ggml-avoid-GLM-Q3-fused-tail-under-active-policy.patch
  • third_party/llama.cpp/patches/0040-ggml-shrink-GLM-Q2-gate-up-active-dispatch.patch
  • third_party/llama.cpp/patches/0041-ggml-skip-inactive-GLM-Q3-down-slots.patch

📝 Walkthrough

Walkthrough

GLM MoE Metal execution now defaults to two-phase mode, supports terminal diagnostics and explicit selector flags, skips inactive or zero-weight slots, adds active-count Q3 kernels, applies maximum-active policies to dispatch and roofline paths, and expands backend evaluation and performance coverage.

Changes

GLM MoE Metal execution

Layer / File(s) Summary
Two-phase diagnostics and selector controls
third_party/llama.cpp/patches/0030-...patch, third_party/llama.cpp/patches/0031-...patch
Two-phase execution defaults and override variables are updated; terminal diagnostics, selector precedence, and diagnostic test wiring are added.
Gate-up active-slot dispatch
third_party/llama.cpp/patches/0032-...patch, third_party/llama.cpp/patches/0037-...patch, third_party/llama.cpp/patches/0040-...patch
Zero-weight slots are skipped, explicit Q2 variants take precedence, and Q2 dispatch uses active-slot metadata.
Q3 active-slot kernels and dispatch
third_party/llama.cpp/patches/0035-...patch, third_party/llama.cpp/patches/0036-...patch, third_party/llama.cpp/patches/0041-...patch
Q3 active2/4/6 pipelines and kernel entrypoints are added, selected through the maximum-active policy, with inactive-slot guards and matching tests.
Active-expert roofline and fusion paths
third_party/llama.cpp/patches/0038-...patch, third_party/llama.cpp/patches/0039-...patch
Roofline dispatch and accounting use active experts, while Q3 fused-tail fusion is disabled under the active-expert policy.
Selected-chain and roofline coverage
third_party/llama.cpp/patches/0033-...patch, third_party/llama.cpp/patches/0034-...patch
Selected-chain tolerance and variants are expanded, alongside Q2Q3 roofline evaluation and performance cases.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GLMActivePolicy
  participant MetalOps
  participant PipelineSelector
  participant MetalKernel
  GLMActivePolicy->>MetalOps: set maximum active experts
  MetalOps->>PipelineSelector: select active-count Q3 pipeline
  PipelineSelector->>MetalKernel: dispatch active2, active4, or active6 kernel
  MetalKernel->>MetalKernel: process only active slots
Loading

Suggested labels: experimental

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jd/glm-moe-metal-active

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@i386
i386 merged commit 121ff55 into main Jul 23, 2026
2 of 3 checks passed
@i386
i386 deleted the jd/glm-moe-metal-active branch July 23, 2026 21:33
@github-actions
github-actions Bot requested a review from ndizazzo July 23, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant