AISpot

llama.cpp Metal 後端融合 DeepSeek-V4 與 GLM 的 MoE 路由

llama.cpp releases版本更新地端推論開源開發工具

llama.cpp 的 Metal 後端把 MoE 路由計算融合進單個核心,覆蓋 DeepSeek-V4/V4.1 以及 GLM、DeepSeek-V2/V3.2、Kimi、MiniMax 等 sigmoid 門控模型。

此前 Metal 只能融合 softmax 與 sqrt(softplus) 路由,這次把 sigmoid 門控的 GLM、DeepSeek、Kimi 等 MoE 模型納入,對在 Apple Silicon 上跑本地推理的人直接有用。

原標題:b12146: metal : fuse DeepSeek-V4/V4.1 and GLM MoE routing (#31615)
閱讀原文

評分66 / 68(平均 67,門檻 60)
狀態精選

全文翻譯

metal:在 TOPK_MOE 融合中支援 scale-bias 路由歸一化 DeepSeek-V4.1 圖使用 scale+bias(sum + 1e-20)對路由權重進行歸一化,而不是使用其他模型所用的下限截斷。新增 norm_bias/norm_scale_bias 融合鏈,使其在截斷位置接受一個具有單位縮放因子的 SCALE 節點,在核心引數中傳入加性偏置,並將其應用為 max(wt_sum, clamp) + bias,從而讓兩種變體共用一個核心。在 test-backend-ops 中覆蓋這些新鏈。 Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB) metal:將 sqrt(softplus) MoE 路由與選擇偏置融合 新增錨定在 softplus 節點上的 TOPK_MOE 鏈(UNARY+SQRT+ADD+ARGSORT+GET_ROWS 以及可選的 norm/scale),使 DeepSeek-V4/V4.1 路由在 Metal 上融合。核心使用 sqrt(softplus) 計算分數,並對帶選擇偏置的鍵進行排序,而收集到的權重和歸一化保持無偏,與參考圖一致。在 softplus 節點設定排程鉤子,在 test-backend-ops 中覆蓋 norm-bias 組合,並記錄新的 deepseek4/deepseek41 融合計數器。 Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB) metal:將 sigmoid MoE 路由與選擇偏置融合 sigmoid 門控的 MoE 架構(GLM、DeepSeek-V2/V3.2 等)會使用可選的權重歸一化對 sigmoid(logits) + exp_probs_b 進行排序,但此前只有 softmax 和 sqrt(softplus) 路由鏈可融合。 新增 6 條以 sigmoid 為錨點的 TOPK_MOE 鏈:sigmoid + ADD + ARGSORT + GET_ROWS,以及可選的 SCALE 和 SUM_ROWS + CLAMP/SCALE + DIV 歸一化尾部;選擇偏置的 ADD 是必需的,與 sqrt(softplus) 鏈相同 將門控函式常量從 sqrt(softplus) 布林值泛化為整數(0 = softmax,1 = sqrt(softplus),2 = sigmoid);sigmoid 分數為 1 / (1 + exp(-logits)),與 CPU、Metal unary 和 CUDA 核心一致 同時將一元排程鉤子錨定在 sigmoid 節點上 test-backend-ops:4 個帶權重縮放和不帶權重縮放的 sigmoid 路由用例 重新記錄 tests/fusion/MTL.csv:sigmoid 架構(glm5-next、deepseek2/32、kimi、minimax 等)現在會融合其路由,並且 muse-spark prefill 減少了一次 MOE_REDUCE 觸發,因為重排後的圖將路由權重分配在 reduce 輸出範圍內,而 dst/input 重疊檢查正確地拒絕了該分配 Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB) cont:移除低訊號註釋 ocd:對 ggml_metal_fusions 進行垂直對齊

由 AI 翻譯,以原文為準。

原文
metal : support scale-bias routing norm in the TOPK_MOE fusion The DeepSeek-V4.1 graph normalizes the routing weights with a scale+bias (sum + 1e-20) instead of the lower clamp used by the other models. Add norm_bias/norm_scale_bias fusion chains that accept a SCALE node with a unit scale factor at the clamp position, pass an additive bias in the kernel args, and apply it as max(wt_sum, clamp) + bias so both variants share one kernel. Cover the new chains in test-backend-ops. Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB) metal : fuse sqrt(softplus) MoE routing with a selection bias Add TOPK_MOE chains anchored at the softplus node (UNARY+SQRT+ADD+ ARGSORT+GET_ROWS plus optional norm/scale) so the DeepSeek-V4/V4.1 routing fuses on Metal. The kernel scores with sqrt(softplus) and ranks selection-biased keys while the gathered weights and the norm stay unbiased, matching the reference graph. Dispatch hooks at the softplus node, cover the norm-bias combination in test-backend-ops and record the new deepseek4/deepseek41 fusion counters. Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB) metal : fuse sigmoid MoE routing with a selection bias The sigmoid-gated MoE archs (GLM, DeepSeek-V2/V3.2, ...) rank sigmoid(logits) + exp_probs_b with an optional weights-norm, but only the softmax and sqrt(softplus) routing chains were fusable. add 6 sigmoid-anchored TOPK_MOE chains: sigmoid + ADD + ARGSORT + GET_ROWS with optional SCALE and SUM_ROWS + CLAMP/SCALE + DIV norm tail; the selection-bias ADD is required, same as the sqrt(softplus) chains generalize the gating function constant from a sqrt(softplus) bool to an int (0 = softmax, 1 = sqrt(softplus), 2 = sigmoid); sigmoid scores are 1 / (1 + exp(-logits)), matching the CPU, Metal unary and CUDA kernels anchor the unary dispatch hook at sigmoid nodes too test-backend-ops: 4 sigmoid routing cases with and without a weights scale re-record tests/fusion/MTL.csv: the sigmoid archs (glm5-next, deepseek2/32, kimi, minimax, ...) now fuse their routing, and muse-spark prefill drops one MOE_REDUCE fire because the reordered graph allocates the routing weights inside the reduce output range, which the dst/input overlap check correctly declines Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB) cont : remove low-signal comments ocd : valign ggml_metal_fusions

相關報導

llama.cpp releasesAI 評分41

llama.cpp 修復 Metal 後端每 token 9 專家 MoE 核心缺失

llama.cpp 建置 b11755 修復了 Metal 後端缺少每 token 9 專家 MoE 核心變體的問題(#30610、#30699),涉及 Apple Silicon 上的 MoE 推理路徑。該版本照例發布全平台預編譯包,覆蓋 macOS/iOS、Linux(CUDA 12/13、ROCm 10.0、Vulkan、SYCL、OpenVINO)、Android、Windows 及 openEuler 昇騰等後端。

llama.cpp releasesAI 評分43

llama.cpp 為 CUDA 加入 384 專家的 Top-K MoE 融合

llama.cpp 發布 b11953 建置版本,CUDA 後端新增針對 384 個專家的 Top-K MoE 融合運算元(#31288),由 Codex 輔助完成,可加速此類稀疏 MoE 模型在 NVIDIA GPU 上的推理。該版本同步放出 macOS、Linux、Windows、Android 等多平台預編譯包,覆蓋 CUDA 12.8/13.4、ROCm 10.0、Vulkan、SYCL、OpenVINO 及驍龍 Adreno/Hexagon 等後端。

llama.cpp releases● 精選AI 評分70

llama.cpp 的 OpenVINO 後端更新至 2026.4.1 並大幅最佳化 MoE 效能

ggml-openvino 後端更新到 2026.4.1,重點最佳化 Qwen3.5 MoE 推理效能,並新增推理效能分析、預設使用遠端輸出張量、磁碟快取模型直載(cache_only)等能力。在 Arc B390 上以 q4_asym64_all 重量化執行 gemma-4-26B-A4B,pp512 從 66.16 t/s 提升到 1608.73 t/s,tg128 從 25.94 提升到 26.46 t/s,困惑度基本不變。