メインコンテンツへスキップ
見出し画像

llama.cpp v0.7.0 に MoE キャッシュが追加された - Strata 旋風の中では地味かもしれないがうれしい機能

    まとめ

    llama.cpp に MoE キャッシュ(--moe-cache-mib)が追加された。

    gemma-4-26B-A4B-it-qat に関しては、テキスト生成が 263 t/s 。MoE キャッシュ無しだと、130 t/s 。

    Gemma は約 2 倍、Qwen は約 1.4 倍程度の速度アップ。

    --moe-cache-mib とは?

    CPU に置いた MoE の expert のうち、直近に使われた expert を GPU にキャッシュし、キャッシュがいっぱいになったら一番長く使われていないものから入れ替える機能。値はキャッシュに使う VRAM の量(MiB)。

    Gemma と Qwen でやってみる

    Gn: gemma-4-26B-A4B-it-qat:UD-Q4_K_XL
    Qn: Qwen3.6-35B-A3B-MTP:UD-Q4_K_XL

    MoE Cache: --moe-cache-mib
    GPU: 1 - RTX5070Ti
    GPU: 2 - RTX5070Ti + RTX5070

    MGPUOffloadContextMoE CacheTG (t/s)G11-ncmoe 99262,1446,656181.29G21-ncmoe 99131,0729,216263.40G31-ncmoe 14262,144-90.78G41-ncmoe 8131,072-130.92G52-ts 10,7262,144-163.86G62-sm tensor262,144-258.03Q11-ncmoe 99262,1447,168116.64Q21-ncmoe 99131,0729,216143.43Q31-ncmoe 26262,144-83.27Q41-ncmoe 22131,072-105.37Q52-ts 16,12114,688-246.86Q62-sm tensor16,384-280.46\newcommand{\arraystretch}{1.5} % \begin{array}{|l|c|l|r|r|r|} \hline \textbf{M} & \textbf{GPU} & \textbf{Offload} & \textbf{Context} & \textbf{MoE Cache} & \textbf{TG (t/s)} \cr \hline \hline \text{G1} & \text{1} & \text{-ncmoe 99} & \text{262,144} & \text{6,656} & \text{181.29} \cr \text{G2} & \text{1} & \text{-ncmoe 99} & \text{131,072} & \text{9,216} & \text{263.40} \cr \text{G3} & \text{1} & \text{-ncmoe 14} & \text{262,144} & \text{-} & \text{90.78} \cr \text{G4} & \text{1} & \text{-ncmoe 8} & \text{131,072} & \text{-} & \text{130.92} \cr \text{G5} & \text{2} & \text{-ts 10,7} & \text{262,144} & \text{-} & \text{163.86} \cr \text{G6} & \text{2} & \text{-sm tensor} & \text{262,144} & \text{-} & \text{258.03} \cr \hline \text{Q1} & \text{1} & \text{-ncmoe 99} & \text{262,144} & \text{7,168} & \text{116.64} \cr \text{Q2} & \text{1} & \text{-ncmoe 99} & \text{131,072} & \text{9,216} & \text{143.43} \cr \text{Q3} & \text{1} & \text{-ncmoe 26} & \text{262,144} & \text{-} & \text{83.27} \cr \text{Q4} & \text{1} & \text{-ncmoe 22} & \text{131,072} & \text{-} & \text{105.37} \cr \text{Q5} & \text{2} & \text{-ts 16,12} & \text{114,688} & \text{-} & \text{246.86} \cr \text{Q6} & \text{2} & \text{-sm tensor} & \text{16,384} & \text{-} & \text{280.46} \cr \hline \end{array}

    検証コマンド

    G1

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 262144 --n-cpu-moe 99 --threads 6 --threads-batch 12 \
      --moe-cache-mib 6656

    G2

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 131072 --n-cpu-moe 99 --threads 6 --threads-batch 12 \
      --moe-cache-mib 9216

    G3

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 262144 --n-cpu-moe 14 --threads 6 --threads-batch 12

    G4

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 131072 --n-cpu-moe 8 --threads 6 --threads-batch 12

    G5

    llama serve -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 262144 -ngl 99 --threads 6 --threads-batch 12 \
      -ts 10,7

    G6

    llama serve -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 262144 -ngl 99 \
      -sm tensor -ts 5,3 --no-spec-draft-backend-sampling

    Q1

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/Qwen3.6-35B-A3B-MTP-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 262144 --n-cpu-moe 99 --threads 6 --threads-batch 12 \
      --moe-cache-mib 7168

    Q2

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/Qwen3.6-35B-A3B-MTP-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 131072 --n-cpu-moe 99 --threads 6 --threads-batch 12 \
      --moe-cache-mib 9216

    Q3

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/Qwen3.6-35B-A3B-MTP-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 262144 --n-cpu-moe 26 --threads 6 --threads-batch 12

    Q4

    CUDA_VISIBLE_DEVICES=0 \
    llama serve -hf unsloth/Qwen3.6-35B-A3B-MTP-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 131072 --n-cpu-moe 22 --threads 6 --threads-batch 12

    Q5

    llama serve -hf unsloth/Qwen3.6-35B-A3B-MTP-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 114688 -ngl 99 --threads 6 --threads-batch 12 \
      -ts 16,12

    Q6

    llama serve -hf unsloth/Qwen3.6-35B-A3B-MTP-GGUF:UD-Q4_K_XL \
      --spec-type draft-mtp --spec-draft-n-max 3 -np 1 -fa on -ctv q8_0 -ctk q8_0 \
      -c 16384 -ngl 99 \
      -sm tensor --no-spec-draft-backend-sampling

    リクエスト(10 構成で共通)

    curl -s http://127.0.0.1:9931/v1/chat/completions \
      -H 'Content-Type: application/json' \
      -d '{"messages":[{"role":"user","content":"Flappy Bird のクローンを index.html のみで作成して。localstorage は使用しない。"}],"stream":false}'

    あなたへのおすすめ