llama.cpp
やはりC/C++製のLLM推論エンジンが本命かなぁ、あらま;
CPU/CUDA/Vulkanの比較
ベンチマークを試してみました
pp512 (Prompt Processing): 512トークンの入力速度
tg128 (Token Generation): 128トークンの生成速度
モデルは最初に定義して置きます
~/git/llama.cpp$ Model=/data/models/gemma-4-12b-it-qat-q4_0.gguf
■ CPUホスト
~/git/llama.cpp$ time build-cpu/bin/llama-bench -m "$Model"
| model | size | params | backend | threads | test | t/s |
| -------------- | -------: | ------: | ------- | ------: | ----: | ----------: |
| gemma4 ?B Q4_0 | 6.48 GiB | 11.91 B | CPU | 4 | pp512 | 6.94 ± 0.10 |
| gemma4 ?B Q4_0 | 6.48 GiB | 11.91 B | CPU | 4 | tg128 | 3.77 ± 0.03 |
real 10m16.274s
user 40m10.284s
sys 0m3.167s
________________________________________________________________________________
■ CUDAホスト
~/git/llama.cpp$ time build-cuda/bin/llama-bench -ngl 99 -m "$Model"
| model | size | params | backend | ngl | test | t/s |
| -------------- | -------: | ------: | ------- | --: | ----: | -------------: |
| gemma4 ?B Q4_0 | 6.48 GiB | 11.91 B | CUDA | 99 | pp512 | 2507.27 ± 100. |
| gemma4 ?B Q4_0 | 6.48 GiB | 11.91 B | CUDA | 99 | tg128 | 53.23 ± 0.07 |
real 0m16.226s
user 0m15.372s
sys 0m0.845s
________________________________________________________________________________
■ Vulkanホスト
~/git/llama.cpp$ time build-vulkan/bin/llama-bench -ngl 99 -m "$Model"
| model | size | params | backend | ngl | test | t/s |
| -------------- | -------: | ------: | ------- | --: | ----: | -------------: |
| gemma4 ?B Q4_0 | 6.48 GiB | 11.91 B | Vulkan | 99 | pp512 | 1707.19 ± 0.69 |
| gemma4 ?B Q4_0 | 6.48 GiB | 11.91 B | Vulkan | 99 | tg128 | 51.26 ± 0.06 |
real 0m18.138s
user 0m8.368s
sys 0m0.969s
Vulkanも試してみた
参考👉 AMDローカルLLMホスティングにおけるROCm vs Vulkan:2026年版ガイド
https://www.glukhov.org/ja/llm-hosting/comparisons/amd-rocm-vs-vulkan-llm-hosting/
■ Vulkanホスト対応でビルド(CPU版ビルド後の環境です)
~/git/llama.cpp$ sudo apt install libvulkan-dev glslc glslang-tools spirv-headers
~/git/llama.cpp$ cmake -B build-vulkan -DGGML_VULKAN=ON
~/git/llama.cpp$ cmake --build build-vulkan --config Release -j 4
■ コンソールから実行(モデルは同じ)
~/git/llama.cpp$ Model=/data/models/gemma-4-12b-it-qat-q4_0.gguf
~/git/llama.cpp$ build-vulkan/bin/llama-cli -m "$Model"
_______________________________________________________
> こんにちは↵
こんにちは!何かお手伝いできることはありますか?
質問や相談など、何でもお気軽にどうぞ。
> /exit↵
_______________________________________________________
これも速い! 約50トークン/秒くらい。
CUDAホスト対応ビルド
NVIDIAグラボならこれがベストか
■ 事前確認
~$ nvidia-smi
CUDA Version: 13.2 (対応する nvcc の最大バージョンらしい)
~$ nvcc -V
release 12.0, V12.0.140
■ CUDAホスト対応でビルド(CPU版ビルド後の環境です)
~/git/llama.cpp$ sudo apt install nvidia-cuda-toolkit
~/git/llama.cpp$ cmake -B build-cuda -DGGML_CUDA=ON -DGGML_CUDA_NCCL=OFF -DCMAKE_CUDA_ARCHITECTURES="86"
[注意1] nccl (マルチGPU) について警告が出ます
-DGGML_CUDA_NCCL=OFF を追加
[注意2] Linux Mint 22.3 の nvcc V12.0 は古いらしい、エラーになる
-DCMAKE_CUDA_ARCHITECTURES="86" を追加
失敗したらbuild-cudaを削除し、原因を修正し "cmake -B build-cuda ..." を繰り返します
~/git/llama.cpp$ rm -rf build-cuda
~/git/llama.cpp$ cmake -B build-cuda -DGGML_CUDA=ON ...
そしてビルド
~/git/llama.cpp$ cmake --build build-cuda --config Release -j 4
■ コンソールから実行(モデルは同じ)
~/git/llama.cpp$ Model=/data/models/gemma-4-12b-it-qat-q4_0.gguf
~/git/llama.cpp$ build-cuda/bin/llama-cli -m "$Model"
_______________________________________________________
> こんにちは↵
こんにちは!何かお手伝いできることはありますか?
ご質問や、相談したいこと、またはただの雑談など、何でもお気軽にお話しください。
> /exit↵
_______________________________________________________
さすがに速い! 約50トークン/秒くらい。
llama.cppインストール
CPUホスト版なら、大きなGPUが無くても動くらしい
■ まずは llama.cpp をダウンロード
~$ sudo apt install git git-lfs
~$ mkdir git
~$ cd ~/git
~/git$ git clone https://github.com/ggml-org/llama.cpp.git
~/git$ ls
llama.cpp/
~/git$ cd llama.cpp/
■ CPUホストに設定してビルド
~/git/llama.cpp$ sudo apt install cmake g++ libcurlpp-dev ccache libssl-dev
~/git/llama.cpp$ cmake -B build-cpu
~/git/llama.cpp$ cmake --build build-cpu --config Release -j 4
■ コンソールから実行
gemma-4-12bモデル(ggufファイル)をダウンロード
https://www.kaggle.com/models/google/gemma-4/gguf
そして起動
~/git/llama.cpp$ Model=/data/models/gemma-4-12b-it-qat-q4_0.gguf
~/git/llama.cpp$ build-cpu/bin/llama-cli -m "$Model"
_______________________________________________________
build : b11294-185103dcf
model : /data/models/gemma-4-12b-it-qat-q4_0.gguf
ftype : Q4_0
modalities : text
available commands:
/exit or Ctrl+C stop or exit
/regen regenerate the last response
/clear clear the chat history
/read <file> add a text file
/glob <pattern> add text files using globbing pattern
_______________________________________________________
> こんにちは↵
こんにちは!何かお手伝いできることはありますか?
> /exit↵
_______________________________________________________
毎秒数トークンでした。