AISpot

llama.cpp 的 MoE 快取支援把部分未命中專家交給 CPU,並新增調參指令碼

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

llama.cpp 新建置讓 MoE 快取把一部分未命中的專家改由 CPU 上的 host 專家計算,比例由新引數 --moe-cache-cpu-share F 控制,計算圖上分別從快取槽建置一份、從 host 專家建置一份,兩者相加後再加 down bias。

給本地跑 MoE 模型的人一個可調的效能開關:官方實現 CPU 分擔未命中專家,並附帶能實測本機速度、直接給出快取大小與 CPU 份額建議的調參指令碼。

原標題:b12191: llama_moe_cache: run missed experts on CPU, add tuning script (#30966)
閱讀原文

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

全文翻譯

moe-cache:在 CPU 上計算部分未命中 --moe-cache-cpu-share F 在 CPU 上從主機專家計算 MoE 快取未命中的份額 F,而不是上傳它們。圖會建置專家 FFN 兩次:在裝置上從快取槽建置,其中留給 CPU 的未命中讀取零槽;在 CPU 上從主機專家建置,其中在裝置上計算的專家 id 為 -1。兩個結果在下偏置之前相加。 ggml-cpu:MUL_MAT_ID 跳過負數 id 並寫入零行 sched:複製回撥會為拆分的所有輸入呼叫,並且在沒有事件時在主機同步之前呼叫 槽查詢回撥會與選定的專家一起讀取 CPU 部分的輸入,因此 CPU 部分不會等待裝置,並且其結果會非同步複製回來 每個 token 使用不同的零槽,mul_mat_id 不支援一個 token 兩次選擇同一個專家 LLAMA_MOE_CACHE_TRACE 會寫入每次查詢所選的專家,用於快取模擬器 scripts:新增 moe-cache-tune.py 以選擇 MoE 快取引數 該指令碼封裝了 llama-server 命令:它會以兩種快取大小和三種 CPU 份額啟動伺服器,擬合機器的上傳和 CPU 速度,並通過快取邏輯的副本重放執行的路由,以預測其他大小和份額。它會列印推薦的 --moe-cache-mib 和 --moe-cache-cpu-share。 docs/moe-cache.md 描述了 MoE 快取引數和該指令碼。 新增 am17an 作為 MoE 快取的程式碼所有者 moe-cache:在快取滿之前上傳所有未命中 在較高的 --moe-cache-cpu-share 下,上傳的未命中很少,因此空快取填充緩慢,並且比所需更多的未命中會轉到 CPU。現在,一旦快取組的所有槽都持有一個專家,CPU 份額就會開始。moe-cache-tune.py 會重放相同的規則。 為非同步傳輸佇列新增後端同步 moe-cache:讓排程器複製 CPU 部分的結果 修復 MSVC 編譯 移除同步更改 llama-graph:將 CPU 份額條件提取到 can_cpu_share llama-graph:使 llm_graph_params::moe_cache 為 const 圖建置不再直接更新 MoE 快取:層的 CPU 部分會在圖結果中累積,並在 llama_context::process_ubatch 中應用到快取,此時圖輸入已設定且圖尚未計算。 協助者:dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF(Mac Studio,M5 Ultra,256GB) scripts:在 moe-cache-tune.py 中重放 ClassLRU 策略 moe-cache:按 CRF 而非隨機選擇 CPU 未命中 ( #31853 ) moe-cache:從圖中移除 CPU 部分的後端邏輯 CPU 部分讀取主機專家,因此排程器將其放置在 CPU 上,而不使用 set_tensor_backend。對於裝置會解除安裝的批次,快取不提供 CPU 對映。帶有 CPU 部分的圖會查詢自己的槽位對映,因此圖不會向快取註冊該部分。 ggml-backend:下一個分割中已計算好的輸入會在當前分割執行之前複製到主機記憶體,因此 CPU 分割不必等待裝置分割。這取代了快取的暫存機制,並且複製回撥再次僅對主機權重呼叫。 llama-graph:在結構體中返回 MoE 快取槽位和 CPU id 排程器預取不再檢查下一個分割是否在另一個後端上執行:一個分割的輸入永遠不會在其自己的後端上,因此輸入迴圈已經跳過了這種情況。 Co-authored-by: Gaurav Garg [email protected] Co-authored-by: Georgi Gerganov [email protected] Co-authored-by: Alexey Kopytko [email protected]

由 AI 翻譯,以原文為準。

原文
moe-cache : compute part of the misses on the CPU --moe-cache-cpu-share F computes a share F of the MoE cache misses on the CPU from the host experts instead of uploading them. The graph builds the expert FFN twice: on the device from the cache slots, where the misses left to the CPU read zero slots, and on the CPU from the host experts, where the experts computed on the device have id -1. The two results are added before the down bias. ggml-cpu: MUL_MAT_ID skips negative ids and writes zero rows sched: the copy callback is called for all the inputs of a split, and before the host sync when there are no events the slot lookup callback reads the inputs of the CPU part together with the selected experts, so the CPU part does not wait for the device, and its result is copied back asynchronously each token uses distinct zero slots, mul_mat_id does not support an expert selected twice by a token LLAMA_MOE_CACHE_TRACE writes the selected experts of each lookup, for a simulator of the cache scripts : add moe-cache-tune.py to pick the MoE cache arguments The script wraps a llama-server command: it starts the server at two cache sizes and three CPU shares, fits the upload and CPU speeds of the machine, and replays the routing of the runs through a copy of the cache logic to predict other sizes and shares. It prints the recommended --moe-cache-mib and --moe-cache-cpu-share. docs/moe-cache.md describes the MoE cache arguments and the script. add am17an as codeowner for MoE cache moe-cache : upload all the misses until the cache is full With a high --moe-cache-cpu-share, few misses are uploaded, so an empty cache fills slowly and more misses than needed go to the CPU. The CPU share now starts once all the slots of a cache group hold an expert. moe-cache-tune.py replays the same rule. add backend sync for async transfer queue moe-cache : let the scheduler copy the results of the CPU part Fix MSVC compilation remove sync change llama-graph : extract the CPU share condition into can_cpu_share llama-graph : make llm_graph_params::moe_cache const The graph construction no longer updates the MoE cache directly: the CPU parts of the layers are accumulated in the graph result and applied to the cache in llama_context::process_ubatch, after the graph inputs are set and before the graph is computed. Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB) scripts : replay the ClassLRU policy in moe-cache-tune.py moe-cache : pick CPU misses by CRF instead of random ( #31853 ) moe-cache : remove the backend logic of the CPU part from the graph The CPU part reads the host experts, so the scheduler places it on the CPU without set_tensor_backend. The cache gives no CPU map for batches that a device would offload. Graphs with a CPU part look up their own slot map, so the graph does not register the part with the cache. ggml-backend : the inputs of the next split that are already computed are copied to host memory before the current split runs, so a CPU split does not wait for the device split before it. This replaces the stash of the cache, and the copy callback is again called for host weights only. llama-graph : return the MoE cache slots and CPU ids in a struct The scheduler prefetch no longer checks that the next split runs on another backend: the inputs of a split are never on its own backend, so the input loop already skips that case. Co-authored-by: Gaurav Garg [email protected] Co-authored-by: Georgi Gerganov [email protected] Co-authored-by: Alexey Kopytko [email protected]

相關報導

llama.cpp releases● 精選AI 評分69

llama.cpp b11507 支援 MoE 快取跨多 GPU

llama.cpp 發布 b11507 版本,新增 MoE 快取跨多張 GPU 的支援(PR #30112),可讓混合專家模型在多 GPU 環境下更充分地利用視訊記憶體。該版本同時更新了各平台預編譯產物,覆蓋 macOS Apple Silicon、iOS、Linux(CUDA 12/13、Vulkan、ROCm 10.0、SYCL、OpenVINO)、Windows、Android 以及 openEuler 等平台。

llama.cpp releases● 精選AI 評分85

llama.cpp v0.7.0 發布:MoE 專家快取最高帶來 2.2 倍解碼提速

llama.cpp 發布 v0.7.0,最核心的變化是新增主機記憶體 MoE 專家的 GPU 快取(--moe-cache-mib),專家改由裝置端 LRU 快取執行,專家解除安裝時解碼最高提速約 2.2 倍,且該快取可跨多張 GPU 共享。版本同時加入 LiliCorr 投機解碼與 GLM5-Next 的 MTP 投機解碼,並支援 K2 Horizon、Prism Bonsai 2 27B、EmbeddingGemma-2、MiniCPM-V 4.7 等一批新模型。

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 等後端。