AISpot

llama.cpp 修復 Metal 後端 mul_mat_id 重複 id 錯誤

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

llama.cpp 建置版本 b11569 修復了 Metal 後端 mul_mat_id 在 id 重複時輸出錯誤、丟行乃至溢位到下一個 expert 切片的問題。新實現先做一遍預掃描,為每個 expert 建立緊湊的 (token, slot) 條目列表,並借鑑 Vulkan 方案讓 map0 額外輸出 tile 描述符,kernel_mul_mm_id 按描述符處理單個 tile,重複 id 由此被隱式處理。

MoE 模型在 Metal 後端遇到重複 expert id 時會算錯或丟行,此次修復同時把 grid 縮小 8–16 倍、pp 提升約 2%,對在 Mac 上用 llama.cpp 跑 MoE 模型的人最有用。

原標題:b11569
閱讀原文

評分46 / 58(平均 52,門檻 60)
狀態未入選

原文

metal : fix mul_mat_id with duplicate ids ( #30373 ) metal : fix mul_mat_id limits and kernel name metal : fix mul_mat_id with duplicate ids kernel_mul_mm_id_map0 assumed at most one match per token and a fixed capacity of ne21 entries per expert, which produced wrong or dropped output rows and could overflow into the slice of the next expert when the ids contain duplicates. build a compact per-expert list of the (token, slot) entries instead: pass 1 counts the entries of every expert, thread 0 computes the offsets of the expert slices (tpe now holds [base, count]) pass 2 writes the entries with one unconditional store per token (conditional stores of divergent lanes are very slow), the dummy value of the tokens without a match lands on a padding slot of the slice that is never read - duplicates are handled by a rare branch kernel_mul_mm_id reads the base/count of its expert and loops over the entry tiles that do not fit into the grid The ids buffer is sized as ne20*ne21 + ne02 (entries + padding). 883/883 test-backend-ops MUL_MAT_ID tests pass, llama-bench is within run-to-run variance of the previous behavior. Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-MOPD metal : make mul_mat_id map0 ne02 a function constant use FOR_UNROLL for the id loops of kernel_mul_mm_id_map0 and turn ne02 into the function constant FC_mul_mm_id_map0_ne02 (FC_MUL_MM + 7), so that the threadgroup offsets of cnt/bas/sids and the prefix-sum bound fold at compile time. the pipeline name now encodes ne02 (same convention as the ssm_conv nc/silu constants) and the map0 pipeline is compiled with the constant value set. ne02 is no longer part of ggml_metal_kargs_mul_mm_id_map0 - the dispatch grid still comes from the tensor ne[2] on the host. no measurable perf change: 883/883 test-backend-ops MUL_MAT_ID tests pass, op-level and llama-bench results are within run variance. Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-MOPD cont : clean-up + TODO metal : dispatch mul_mat_id entry tiles from the prepass follow the approach of the vulkan implementation ( #29998 ): instead of launching a grid over experts x ne21 entry tiles and letting most of the threadgroups early exit, kernel_mul_mm_id_map0 now also emits a row map - the total tile count plus one (expert, first entry, valid rows) descriptor per 32-entry tile that has work. kernel_mul_mm_id is launched with a static upper bound on the number of tiles (full tiles over all entries plus at most one partial tile per expert), reads its descriptor and processes a single tile - the tail early exits. This removes the round loop that was needed to cover duplicate ids past the grid (register pressure: th_max 768 -> back to the plain mul_mm level) and duplicates are now handled implicitly, since they only produce more descriptors within the bound. The grid shrinks by ~8-16x on typical shapes (e.g. 128 experts, 8 used, 512 tokens: 128 tiles instead of 2048 entry tiles, of which 94% only launched to exit) and ne21 is no longer needed by the mm kernel kargs. 883/883 test-backend-ops MUL_MAT_ID tests pass. llama-bench (Qwen3.6-35B-A3B Q8_0) is now faster than master on all pp sizes (pp2048/4096/8192 +2%, pp512 +0.5%), tg32 unchanged. Assisted-by: pi:llama.cpp/MiMo-V2.6-Flash-MOPD cont : add smem assert Website: https://llama.app Attestations: https://github.com/ggml-org/llama.cpp/attestations/55057952 macOS/iOS: macOS Apple Silicon (arm64) macOS Apple Silicon (arm64, KleidiAI enabled) DISABLED macOS Intel (x64) iOS XCFramework Linux: Ubuntu x64 (CPU) Ubuntu arm64 (CPU) Ubuntu s390x (CPU) Ubuntu x64 (Vulkan) Ubuntu arm64 (Vulkan) Ubuntu x64 (CUDA 12) - CUDA 12.8 libraries Ubuntu x64 (CUDA 13) - CUDA 13.4 libraries Ubuntu arm64 (CUDA 13) - CUDA 13.4 libraries Ubuntu x64 (ROCm 10.0) Ubuntu x64 (OpenVINO) Ubuntu x64 (SYCL FP32) Ubuntu x64 (SYCL FP16) Linux arm64 (Snapdragon: CPU, Adreno GPU, Hexagon NPU) - setup guide Android: Android arm64 (CPU) Android arm64 (Snapdragon: CPU, Adreno GPU, Hexagon NPU) - setup guide Windows: Windows x64 (CPU) Windows arm64 (CPU) Windows arm64 (OpenCL Adreno) Windows x64 (CUDA 12) - CUDA 12.4 DLLs Windows x64 (CUDA 13) - CUDA 13.4 DLLs Windows arm64 (CUDA 13) - CUDA 13.4 DLLs Windows x64 (Vulkan) Windows arm64 (Vulkan) Windows x64 (OpenVINO) Windows x64 (SYCL) Windows x64 (ROCm 10.0) openEuler: DISABLED openEuler x86 (310p) openEuler x86 (910b, ACL Graph) openEuler aarch64 (310p) openEuler aarch64 (910b, ACL Graph) UI: UI

相關報導

llama.cpp releases● 精選AI 評分74

llama.cpp 修復 Metal 後端 MUL_MAT+ADD 融合錯誤

llama.cpp 合併 PR #30100,修復 Metal 後端 MUL_MAT+ADD 融合中殘差運算元的選擇錯誤:當 ADD 的兩個運算元都是矩陣乘法輸出(x = W1@u + W2@v)時,舊邏輯會選中自身從未寫入的輸出緩衝區,導致結果錯誤。Clef 決策模型因此在 Metal 上機率趨近均勻,billing 輸出 0.28,而 CPU 後端為 0.977,且同一檔案在 CPU 上結果正確,說明並非量化問題。

llama.cpp releasesAI 評分46

llama.cpp 新版最佳化 Vulkan 上 MoE 重複專家的矩陣乘

llama.cpp 發布 b11554,Vulkan 後端改進了 MoE 推理中 mul_mat_id 對重複專家 id 的處理:不再逐個迴圈,而是在預計算階段統一處理。原本受限的 hoist row ids 最佳化現在預設開啟,會生成緊湊的 tile 描述列表、按需發射多個 tile,從而收緊 workgroup 數量上界,尾部執行緒可直接提前退出。

llama.cpp releasesAI 評分36

llama.cpp 修復 Vulkan 後端 RDNA4 矩陣向量調優

llama.cpp 發布 b11389 版本,修復了 Vulkan 後端在 RDNA4 架構上的矩陣向量運算調優問題(PR #29934)。該版本繼續提供覆蓋 macOS、Linux、Windows、Android 等平台的預編譯二進位制,包括 Vulkan、CUDA、ROCm、SYCL 等後端,其中 macOS Apple Silicon 的 KleidiAI 啟用版和 openEuler 建置被停用。