Skip to content

Fix GLM 5.2 native MTP execution - #1049

Merged
i386 merged 1 commit into
mainfrom
agent/glm52-mtp-execution
Jul 23, 2026
Merged

Fix GLM 5.2 native MTP execution#1049
i386 merged 1 commit into
mainfrom
agent/glm52-mtp-execution

Conversation

@i386

@i386 i386 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Adds a dedicated GLM-DSA MTP graph in the llama.cpp patch queue instead of reusing the DeepSeek2 MTP graph.
  • Runs GLM-DSA MTP through the GLM sparse-attention/indexer path, including DSA KV cache setup, optional LID rotation input handling, and GLM-specific top-k attention.
  • Keeps embeddings available for final layer-package stages so GLM MTP can fall back to token embeddings when the package does not carry nextn.embed_tokens.
  • Adds an opt-in package-backed smoke test for GLM 5.2 native MTP execution via SKIPPY_GLM52_MTP_PACKAGE.

Why

GLM-5.2's final MTP block is GLM-DSA shaped. Reusing the DeepSeek2 MTP graph and loading the final package stage without embeddings caused native MTP execution to fail for the published GLM 5.2 layer package.

Validation

  • LLAMA_BUILD_DIR=.deps/llama-build/build-stage-abi-static-cpu SKIPPY_FORCE_LLAMA_BUILD=1 scripts/build-llama.sh
  • cargo fmt --all --check
  • cargo test -p skippy-server runtime_config_keeps_package_embeddings_for_final_non_first_stage -- --nocapture
  • LLAMA_STAGE_BUILD_DIR=.deps/llama-build/build-stage-abi-static-cpu SKIPPY_GLM52_MTP_PACKAGE=/Users/jdumay/.cache/huggingface/hub/models--meshllm--GLM-5.2-Q2_K-MTP-Q8-layers/snapshots/main GGML_METAL_DEVICES=0 cargo test -p skippy-server glm52_final_stage_package_executes_native_mtp_when_fixture_is_set -- --nocapture
  • Fresh patch queue apply: LLAMA_WORKDIR=$(mktemp -d /tmp/mesh-llm-llama.XXXXXX) scripts/prepare-llama.sh pinned

Summary by CodeRabbit

  • Bug Fixes

    • Fixed GLM-DSA model execution for multi-token prediction (MTP), improving compatibility and reliability.
    • Preserved embeddings when loading final-stage layer packages, including stages beyond the first.
  • Testing

    • Added validation for native MTP execution on supported GLM-DSA packages.
    • Expanded coverage for final-stage package loading and generated token outputs.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request is currently a draft. Reviews will not take place until the PR is marked as ready for review.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

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: a08d3088-2d97-4982-a62b-ff3e06486db8

📥 Commits

Reviewing files that changed from the base of the PR and between 4ec025e and 49f0ab0.

📒 Files selected for processing (2)
  • crates/skippy-server/src/runtime_state.rs
  • third_party/llama.cpp/patches/0042-Fix-GLM-DSA-native-MTP-execution.patch

📝 Walkthrough

Walkthrough

Final-stage layer-package runtimes now retain embeddings for native MTP. llama.cpp adds GLM-DSA-specific fused-op handling, guarded attention inputs, and a dedicated MTP computation graph that produces logits.

Changes

GLM-DSA native MTP

Layer / File(s) Summary
Final-stage embedding retention and validation
crates/skippy-server/src/runtime_state.rs
Final LoadMode::LayerPackage stages enable include_embeddings; tests validate configuration and optionally execute native MTP from a GLM52 package fixture.
GLM-DSA MTP execution controls
third_party/llama.cpp/patches/0042-Fix-GLM-DSA-native-MTP-execution.patch
GLM-DSA fused operations are disabled for MTP contexts, and optional attention inputs require both pointers and backing buffers.
Dedicated GLM-DSA MTP graph
third_party/llama.cpp/patches/0042-Fix-GLM-DSA-native-MTP-execution.patch
A dedicated graph_mtp implementation builds GLM-DSA attention, MoE/FFN processing, normalization, and logits output.

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

Possibly related PRs

Suggested labels: experimental

Suggested reviewers: ndizazzo, michaelneale

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing GLM 5.2 native MTP execution.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/glm52-mtp-execution

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 marked this pull request as ready for review July 21, 2026 23:04
@github-actions
github-actions Bot requested a review from ndizazzo July 21, 2026 23:04
@i386
i386 force-pushed the agent/glm52-mtp-execution branch from f295f68 to 4ec025e Compare July 22, 2026 05:22
@i386
i386 changed the base branch from main to jd/glm-moe-metal-active July 22, 2026 05:22

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch (2)

951-955: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Dangling TODO comment with no adjacent disabled code.

This TODO block describes "keep route packing disabled until..." but there is no visible disabled/guarded code immediately following it in this hunk — it reads as an orphaned note that could confuse future readers about what, exactly, is disabled and where.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`
around lines 951 - 955, Remove the orphaned GLM-DSA route-packing TODO
immediately before ggml_metal_graph_optimize_reorder, since it has no adjacent
disabled or guarded implementation to reference. Keep the optimization function
and surrounding code unchanged.

974-977: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Fusion-scratch buffers are unconditionally allocated on every Metal init, regardless of whether the GLM-DSA private-scratch/dual-lane paths are ever exercised.

GGML_METAL_MAX_COMMAND_BUFFERS + 1 (9) buffers of GGML_METAL_FUSION_SCRATCH_SIZE (1 MiB) each are allocated in ggml_metal_init, i.e. up to 9 MiB reserved for every Metal backend instance even when the consuming features (gated by SKIPPY_GLM_DSA_*/GGML_METAL_EXPERIMENTAL_GLM_MOE_* env vars) are disabled. The failure path is handled gracefully (falls back via nil buffer id), so this isn't a bug, but it's a permanent resource cost paid by all users of this backend.

Also applies to: 1101-1125

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`
around lines 974 - 977, Make fusion-scratch allocation in ggml_metal_init
conditional on whether the GLM-DSA/private-scratch or dual-lane paths are
enabled by their existing SKIPPY_GLM_DSA_* or GGML_METAL_EXPERIMENTAL_GLM_MOE_*
configuration. Avoid reserving the GGML_METAL_MAX_COMMAND_BUFFERS + 1 scratch
buffers when those features are disabled, while preserving the current
nil-buffer fallback and allocation behavior when they are enabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`:
- Around line 27-39: Update RPC_PROTO_PATCH_VERSION in ggml-rpc.h alongside the
GGML_OP_COUNT change from 101 to 107, incrementing the protocol patch version so
RPC peers with mismatched operation sets are detected as incompatible.

In
`@third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch`:
- Around line 2588-2598: Guard the graph reset in skippy_import_kv_page by
checking whether get_gf_res_prev() returns a non-null result before calling
reset(). Preserve the existing behavior of invalidating the previous graph when
it exists, while allowing KV page imports before any graph result has been
created.

In
`@third_party/llama.cpp/patches/0021-tests-cover-native-GLM-DSA-execution-paths.patch`:
- Around line 647-652: Update the routed-whole-graph sanity probe invoking
test_backend_ops with the backend_args array, forwarding the selected
GLM52_PHASE_E_BACKEND filter before the existing perf options. Keep the sanity
log and TOPK_MOE_GLM_CONSUMER_SANITY configuration unchanged so verdict()
evaluates rows from the requested backend.

In
`@third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch`:
- Around line 22-69: Update the Q3 down-kernel dispatch branches to call the
matching active-slot getters: use _active6, _active4, or _active2 for
q3_active_count values 6, 4, and 2. Apply this in
third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch
lines 161-215 and
third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch
lines 75-84, replacing calls to
ggml_metal_library_get_pipeline_mul_mv_id_q3_weighted_reduce_slots_sg_r8_nb8_w0
while leaving other dispatch behavior unchanged.

---

Nitpick comments:
In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`:
- Around line 951-955: Remove the orphaned GLM-DSA route-packing TODO
immediately before ggml_metal_graph_optimize_reorder, since it has no adjacent
disabled or guarded implementation to reference. Keep the optimization function
and surrounding code unchanged.
- Around line 974-977: Make fusion-scratch allocation in ggml_metal_init
conditional on whether the GLM-DSA/private-scratch or dual-lane paths are
enabled by their existing SKIPPY_GLM_DSA_* or GGML_METAL_EXPERIMENTAL_GLM_MOE_*
configuration. Avoid reserving the GGML_METAL_MAX_COMMAND_BUFFERS + 1 scratch
buffers when those features are disabled, while preserving the current
nil-buffer fallback and allocation behavior when they are enabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 384b91a1-9f57-4794-b1bc-0cdd2e666875

📥 Commits

Reviewing files that changed from the base of the PR and between f295f68 and 4ec025e.

📒 Files selected for processing (24)
  • crates/skippy-ffi/src/lib.rs
  • crates/skippy-runtime/src/config.rs
  • crates/skippy-server/src/runtime_state.rs
  • third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch
  • third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch
  • third_party/llama.cpp/patches/0021-tests-cover-native-GLM-DSA-execution-paths.patch
  • third_party/llama.cpp/patches/0022-Support-GLM-DSA-fused-KV_B-tensors.patch
  • third_party/llama.cpp/patches/0023-Run-GLM-DSA-through-IndexShare-graph.patch
  • third_party/llama.cpp/patches/0024-Use-DSA-KV-cache-for-GLM-DSA.patch
  • third_party/llama.cpp/patches/0025-Bump-Skippy-ABI-for-GLM-DSA-runtime-config.patch
  • third_party/llama.cpp/patches/0026-Fix-GLM-DSA-Metal-get_rows-placement.patch
  • third_party/llama.cpp/patches/0027-ggml-default-GLM-MoE-two-phase-Metal-path.patch
  • third_party/llama.cpp/patches/0028-ggml-add-GLM-MoE-Metal-selector-diagnostics.patch
  • third_party/llama.cpp/patches/0029-ggml-skip-zero-weight-GLM-MoE-gate-up-slots.patch
  • third_party/llama.cpp/patches/0030-tests-cover-full-GLM-MoE-selected-chain.patch
  • third_party/llama.cpp/patches/0031-tests-add-GLM-Q2Q3-selected-weight-roofline.patch
  • third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch
  • third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch
  • third_party/llama.cpp/patches/0034-ggml-honor-explicit-Q2-gate-up-Metal-variant-flags.patch
  • third_party/llama.cpp/patches/0035-ggml-make-GLM-MoE-roofline-honor-active-experts.patch
  • third_party/llama.cpp/patches/0036-ggml-avoid-GLM-Q3-fused-tail-under-active-policy.patch
  • third_party/llama.cpp/patches/0037-ggml-shrink-GLM-Q2-gate-up-active-dispatch.patch
  • third_party/llama.cpp/patches/0038-ggml-skip-inactive-GLM-Q3-down-slots.patch
  • third_party/llama.cpp/patches/0039-Fix-GLM-DSA-native-MTP-execution.patch
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/skippy-server/src/runtime_state.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 4

🧹 Nitpick comments (2)
third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch (2)

951-955: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Dangling TODO comment with no adjacent disabled code.

This TODO block describes "keep route packing disabled until..." but there is no visible disabled/guarded code immediately following it in this hunk — it reads as an orphaned note that could confuse future readers about what, exactly, is disabled and where.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`
around lines 951 - 955, Remove the orphaned GLM-DSA route-packing TODO
immediately before ggml_metal_graph_optimize_reorder, since it has no adjacent
disabled or guarded implementation to reference. Keep the optimization function
and surrounding code unchanged.

974-977: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Fusion-scratch buffers are unconditionally allocated on every Metal init, regardless of whether the GLM-DSA private-scratch/dual-lane paths are ever exercised.

GGML_METAL_MAX_COMMAND_BUFFERS + 1 (9) buffers of GGML_METAL_FUSION_SCRATCH_SIZE (1 MiB) each are allocated in ggml_metal_init, i.e. up to 9 MiB reserved for every Metal backend instance even when the consuming features (gated by SKIPPY_GLM_DSA_*/GGML_METAL_EXPERIMENTAL_GLM_MOE_* env vars) are disabled. The failure path is handled gracefully (falls back via nil buffer id), so this isn't a bug, but it's a permanent resource cost paid by all users of this backend.

Also applies to: 1101-1125

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`
around lines 974 - 977, Make fusion-scratch allocation in ggml_metal_init
conditional on whether the GLM-DSA/private-scratch or dual-lane paths are
enabled by their existing SKIPPY_GLM_DSA_* or GGML_METAL_EXPERIMENTAL_GLM_MOE_*
configuration. Avoid reserving the GGML_METAL_MAX_COMMAND_BUFFERS + 1 scratch
buffers when those features are disabled, while preserving the current
nil-buffer fallback and allocation behavior when they are enabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`:
- Around line 27-39: Update RPC_PROTO_PATCH_VERSION in ggml-rpc.h alongside the
GGML_OP_COUNT change from 101 to 107, incrementing the protocol patch version so
RPC peers with mismatched operation sets are detected as incompatible.

In
`@third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch`:
- Around line 2588-2598: Guard the graph reset in skippy_import_kv_page by
checking whether get_gf_res_prev() returns a non-null result before calling
reset(). Preserve the existing behavior of invalidating the previous graph when
it exists, while allowing KV page imports before any graph result has been
created.

In
`@third_party/llama.cpp/patches/0021-tests-cover-native-GLM-DSA-execution-paths.patch`:
- Around line 647-652: Update the routed-whole-graph sanity probe invoking
test_backend_ops with the backend_args array, forwarding the selected
GLM52_PHASE_E_BACKEND filter before the existing perf options. Keep the sanity
log and TOPK_MOE_GLM_CONSUMER_SANITY configuration unchanged so verdict()
evaluates rows from the requested backend.

In
`@third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch`:
- Around line 22-69: Update the Q3 down-kernel dispatch branches to call the
matching active-slot getters: use _active6, _active4, or _active2 for
q3_active_count values 6, 4, and 2. Apply this in
third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch
lines 161-215 and
third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch
lines 75-84, replacing calls to
ggml_metal_library_get_pipeline_mul_mv_id_q3_weighted_reduce_slots_sg_r8_nb8_w0
while leaving other dispatch behavior unchanged.

---

Nitpick comments:
In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`:
- Around line 951-955: Remove the orphaned GLM-DSA route-packing TODO
immediately before ggml_metal_graph_optimize_reorder, since it has no adjacent
disabled or guarded implementation to reference. Keep the optimization function
and surrounding code unchanged.
- Around line 974-977: Make fusion-scratch allocation in ggml_metal_init
conditional on whether the GLM-DSA/private-scratch or dual-lane paths are
enabled by their existing SKIPPY_GLM_DSA_* or GGML_METAL_EXPERIMENTAL_GLM_MOE_*
configuration. Avoid reserving the GGML_METAL_MAX_COMMAND_BUFFERS + 1 scratch
buffers when those features are disabled, while preserving the current
nil-buffer fallback and allocation behavior when they are enabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 384b91a1-9f57-4794-b1bc-0cdd2e666875

📥 Commits

Reviewing files that changed from the base of the PR and between f295f68 and 4ec025e.

📒 Files selected for processing (24)
  • crates/skippy-ffi/src/lib.rs
  • crates/skippy-runtime/src/config.rs
  • crates/skippy-server/src/runtime_state.rs
  • third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch
  • third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch
  • third_party/llama.cpp/patches/0021-tests-cover-native-GLM-DSA-execution-paths.patch
  • third_party/llama.cpp/patches/0022-Support-GLM-DSA-fused-KV_B-tensors.patch
  • third_party/llama.cpp/patches/0023-Run-GLM-DSA-through-IndexShare-graph.patch
  • third_party/llama.cpp/patches/0024-Use-DSA-KV-cache-for-GLM-DSA.patch
  • third_party/llama.cpp/patches/0025-Bump-Skippy-ABI-for-GLM-DSA-runtime-config.patch
  • third_party/llama.cpp/patches/0026-Fix-GLM-DSA-Metal-get_rows-placement.patch
  • third_party/llama.cpp/patches/0027-ggml-default-GLM-MoE-two-phase-Metal-path.patch
  • third_party/llama.cpp/patches/0028-ggml-add-GLM-MoE-Metal-selector-diagnostics.patch
  • third_party/llama.cpp/patches/0029-ggml-skip-zero-weight-GLM-MoE-gate-up-slots.patch
  • third_party/llama.cpp/patches/0030-tests-cover-full-GLM-MoE-selected-chain.patch
  • third_party/llama.cpp/patches/0031-tests-add-GLM-Q2Q3-selected-weight-roofline.patch
  • third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch
  • third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch
  • third_party/llama.cpp/patches/0034-ggml-honor-explicit-Q2-gate-up-Metal-variant-flags.patch
  • third_party/llama.cpp/patches/0035-ggml-make-GLM-MoE-roofline-honor-active-experts.patch
  • third_party/llama.cpp/patches/0036-ggml-avoid-GLM-Q3-fused-tail-under-active-policy.patch
  • third_party/llama.cpp/patches/0037-ggml-shrink-GLM-Q2-gate-up-active-dispatch.patch
  • third_party/llama.cpp/patches/0038-ggml-skip-inactive-GLM-Q3-down-slots.patch
  • third_party/llama.cpp/patches/0039-Fix-GLM-DSA-native-MTP-execution.patch
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/skippy-server/src/runtime_state.rs
🛑 Comments failed to post (4)
third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch (1)

27-39: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

RPC protocol version not bumped despite GGML_OP_COUNT change.

The patch bumps the static_assert to GGML_OP_COUNT == 107, but RPC_PROTO_PATCH_VERSION is left at 3. The assert's own message says to update this version whenever GGML_OP_COUNT changes, precisely because RPC clients/servers negotiate compatibility using this constant. Six new ops (GGML_OP_DSA_SPARSE_MASK/ATTN/TOP1_ATTN, GGML_OP_MOE_ROUTE_WEIGHTS/WEIGHTED_SUM/MUL_MAT_ID) were added but the RPC version string was not incremented, so RPC peers running mismatched op sets will not be detected as incompatible.
#define RPC_PROTO_PATCH_VERSION 3

🐛 Proposed fix
-#define RPC_PROTO_PATCH_VERSION    3
+#define RPC_PROTO_PATCH_VERSION    4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`#define` RPC_PROTO_PATCH_VERSION    4
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0019-ggml-add-GLM-DSA-sparse-execution-primitives.patch`
around lines 27 - 39, Update RPC_PROTO_PATCH_VERSION in ggml-rpc.h alongside the
GGML_OP_COUNT change from 101 to 107, incrementing the protocol patch version so
RPC peers with mismatched operation sets are detected as incompatible.
third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch (1)

2588-2598: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm get_gf_res_prev() can return nullptr and how callers treat it.
rg -nP 'get_gf_res_prev\s*\(' third_party/llama.cpp -C2
# Locate the definition/return contract.
ast-grep run --pattern 'llm_graph_result * $_::get_gf_res_prev() { $$$ }' --lang cpp third_party/llama.cpp 2>/dev/null || \
rg -nP '\bget_gf_res_prev\b' third_party/llama.cpp -g '*.cpp' -g '*.h' -C3

Repository: Mesh-LLM/mesh-llm

Length of output: 6444


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the accessor definition and the backing storage.
sed -n '80,120p' third_party/llama.cpp/patches/0007-Expand-staged-execution-across-VL-and-broad-model-fa.patch
printf '\n---\n'
sed -n '1,140p' third_party/llama.cpp/patches/0007-Expand-staged-execution-across-VL-and-broad-model-fa.patch | rg -n 'gf_res_prev|get_gf_res_prev|reset\(' -n -C2

printf '\n=== other uses in patch 0020 ===\n'
rg -n 'get_gf_res_prev\(\)->reset|get_gf_res_prev\(\)' third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch -C2

Repository: Mesh-LLM/mesh-llm

Length of output: 3811


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look for the import_kv_page control flow and any surrounding preconditions.
rg -n 'skippy_import_kv_page|import_kv_page|n_past = std::max|get_gf_res_prev\(\)' third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch -C4

Repository: Mesh-LLM/mesh-llm

Length of output: 3083


Guard get_gf_res_prev() before calling reset().

get_gf_res_prev() returns the raw previous graph result and can be null; the other new uses in this patch already check for that. Calling reset() unconditionally here can crash if a KV page is imported before any prior graph result exists.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0020-skippy-expose-GLM-DSA-staged-runtime-controls.patch`
around lines 2588 - 2598, Guard the graph reset in skippy_import_kv_page by
checking whether get_gf_res_prev() returns a non-null result before calling
reset(). Preserve the existing behavior of invalidating the previous graph when
it exists, while allowing KV page imports before any graph result has been
created.
third_party/llama.cpp/patches/0021-tests-cover-native-GLM-DSA-execution-paths.patch (1)

647-652: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Routed-whole-graph sanity probe ignores ${backend_args[@]}.

Every other test_backend_ops invocation in this script forwards "${backend_args[@]}" (from GLM52_PHASE_E_BACKEND), but this sanity probe does not. Its rows feed the require_gates plausibility check (verdict()), so when a backend is explicitly selected, the probe still runs against the default/all backends and can trip a spurious gate failure or produce mismatched rows.

🔧 Forward the backend filter to the sanity probe
     "${test_backend_ops}" perf \
+        "${backend_args[@]}" \
         -o TOPK_MOE_GLM_CONSUMER_SANITY \
         -p 'n_embd=6144,n_ff=2048,.*fused_glu=1' \
         --output console > "${sanity_log}" 2>&1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

if [[ "${GLM52_PHASE_E_ROUTED_WHOLE_GRAPH_SANITY:-1}" != "0" ]]; then
    sanity_log="${out_dir}/routed-whole-graph-sanity.console.log"
    "${test_backend_ops}" perf \
        "${backend_args[@]}" \
        -o TOPK_MOE_GLM_CONSUMER_SANITY \
        -p 'n_embd=6144,n_ff=2048,.*fused_glu=1' \
        --output console > "${sanity_log}" 2>&1
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0021-tests-cover-native-GLM-DSA-execution-paths.patch`
around lines 647 - 652, Update the routed-whole-graph sanity probe invoking
test_backend_ops with the backend_args array, forwarding the selected
GLM52_PHASE_E_BACKEND filter before the existing perf options. Keep the sanity
log and TOPK_MOE_GLM_CONSUMER_SANITY configuration unchanged so verdict()
evaluates rows from the requested backend.
third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch (1)

22-69: 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== file list ==\n'
git ls-files 'third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch' \
             'third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch'

printf '\n== relevant hunks in 0032 ==\n'
grep -nE 'active6|active4|active2|weighted_reduce_slots_sg_r8_nb8_w0_active|weighted_reduce_slots_sg_r8_nb8_w0\(' \
  third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch

printf '\n== relevant hunks in 0033 ==\n'
grep -nE 'q3_active_count == [642]|weighted_reduce_slots_sg_r8_nb8_w0_active|weighted_reduce_slots_sg_r8_nb8_w0\(' \
  third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch

printf '\n== show context around 0032 helper and call sites ==\n'
sed -n '1,260p' third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch | \
  nl -ba | sed -n '1,260p' | grep -nE 'weighted_reduce_slots_sg_r8_nb8_w0_active|active6|active4|active2|kernel_mul_mv_id_q3_K_wr_slots_r8_a[642]|nsg_slot_parallel|_pad0'

printf '\n== show context around 0033 call sites ==\n'
sed -n '1,180p' third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch | \
  nl -ba | grep -nE 'q3_active_count == [642]|weighted_reduce_slots_sg_r8_nb8_w0_active|weighted_reduce_slots_sg_r8_nb8_w0\('

Repository: Mesh-LLM/mesh-llm

Length of output: 4710


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the two patch files with line numbers in the relevant regions.
echo '--- 0032 lines 1-260 ---'
nl -ba third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch | sed -n '1,260p'

echo '--- 0033 lines 1-180 ---'
nl -ba third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch | sed -n '1,180p'

Repository: Mesh-LLM/mesh-llm

Length of output: 220


🏁 Script executed:

#!/bin/bash
set -euo pipefail
echo "probe"

Repository: Mesh-LLM/mesh-llm

Length of output: 161


Use the _active6/4/2 getters in the Q3 down-kernel branches

These branches still call ggml_metal_library_get_pipeline_mul_mv_id_q3_weighted_reduce_slots_sg_r8_nb8_w0(...), so the 6/4/2-slot path never gets selected.

  • third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch#L161-L215: call the matching _active6, _active4, or _active2 helper in each branch.
  • third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch#L75-L84: same fix for the q3_active_count == 6/4/2 branches.
📍 Affects 2 files
  • third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch#L22-L69 (this comment)
  • third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch#L75-L84
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch`
around lines 22 - 69, Update the Q3 down-kernel dispatch branches to call the
matching active-slot getters: use _active6, _active4, or _active2 for
q3_active_count values 6, 4, and 2. Apply this in
third_party/llama.cpp/patches/0032-ggml-add-active-count-Q3-GLM-MoE-down-kernels.patch
lines 161-215 and
third_party/llama.cpp/patches/0033-ggml-use-GLM-max-active-policy-for-Q3-down-kernels.patch
lines 75-84, replacing calls to
ggml_metal_library_get_pipeline_mul_mv_id_q3_weighted_reduce_slots_sg_r8_nb8_w0
while leaving other dispatch behavior unchanged.

@i386
i386 force-pushed the jd/glm-moe-metal-active branch from e40ac0d to f4c41ce Compare July 23, 2026 21:00
@i386
i386 force-pushed the agent/glm52-mtp-execution branch from 4ec025e to 00ea41a Compare July 23, 2026 21:01
@i386
i386 force-pushed the jd/glm-moe-metal-active branch from f4c41ce to 09ee9ca Compare July 23, 2026 21:32
Base automatically changed from jd/glm-moe-metal-active to main July 23, 2026 21:33
@i386
i386 force-pushed the agent/glm52-mtp-execution branch from 00ea41a to 49f0ab0 Compare July 23, 2026 21:39
@i386
i386 merged commit ca5b6ea into main Jul 23, 2026
1 check was pending
@i386
i386 deleted the agent/glm52-mtp-execution branch 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