1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Linux 環境で llama.cpp でローカルモデルを使ってみた

1
Last updated at Posted at 2026-02-10

はじめに

今までローカルモデルはLM Studio で立ち上げて使っていましたが、llama.cppでもっと細かく設定できそうで、試してみようと思ったんです。

最初の壁

llama.cpp の Github ページから最初は homebrew でインストールしましたが、homebrew 版でグラフィクスボードは使えなさそうです。Nvidia なら使えるかもしれないが、僕は AMD なので、ROCm もしくは Vulkan のサポートは必要でした。そのため、手動でビルドしてインストールしました。

ビルド手段

ライブラリインストール:

まずはビルドライブラリをインストールする。

sudo apt install pciutils build-essential cmake curl libcurl4-openssl-dev

AMD GPU で ROCm 使うつもりですので、関係ライブラリをインストールする。

P.S.: 最近ハマっているゲーム向け Linux ディストロは使っている場合、rocm-meta パッケージは既に用意されているかもしれません。その場合ディストロのサイトから確認すれば良い。僕は Debian ベースの PikaOS 利用していますから、簡単に rocm-meta パッケージをインストールができる。)

Debian でインストール方法

wget https://repo.radeon.com/amdgpu-install/7.2/ubuntu/noble/amdgpu-install_7.2.70200-1_all.deb
sudo apt install ./amdgpu-install_7.2.70200-1_all.deb
sudo apt update
sudo apt install python3-setuptools python3-wheel
sudo usermod -a -G render,video $LOGNAME # Add the current user to the render and video groups
sudo apt install rocm

RDNA3 以上のグラフィクスボードなら、もっとパフォーマンスをもらうためrocWMMA ライブラリをインストールする。

sudo apt install rocwmma-dev hipblas

グラフィクスボードのコードネームを取る:

rocminfo | grep gfx | head -1 | awk '{print $2}'

出た文字列を覚えといてください。ビルドステップに必要となる。

クローンしてビルド:

git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp/
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
    cmake -S . -B build -DGGML_HIP=ON -DGPU_TARGETS=<前回のステップから得たコードネーム> -DCMAKE_BUILD_TYPE=Release -DGGML_HIP_ROCWMMA_FATTN=ON \
    && cmake --build build --config Release -- -j 16

Ryzen 9950X でビルドに1分ぐらいかかります。

適当な場所に移動

ビルドしたバイナリファイルは適当なところに移動します。

mkdir ~/llama.cpp
cp build/bin/* ~/llama.cpp/

モデルダウンロード

今回のデモで、最近リリースされた Qwen3-Coder-Next の Q4-K-XL UD モデルをダウンロードして試してみます。HuggingFace から直接ダウンロードは可能です。

pip install -U huggingface_hub
hf download unsloth/Qwen3-Coder-Next-GGUF \
    --local-dir unsloth/Qwen3-Coder-Next-GGUF \
    --include "*UD-Q4_K_XL*"

ダウンロード終わったら、サーバーを立ち上がります。

./llama.cpp/llama-server \
    --model unsloth/Qwen3-Coder-Next-GGUF/Qwen3-Coder-Next-UD-Q4_K_XL.gguf \
    --alias "unsloth/Qwen3-Coder-Next" \
    --fit on \
    --seed 3407 \
    --temp 1.0 \
    --top-p 0.95 \
    --min-p 0.01 \
    --top-k 40 \
    --port 8001 \
    --jinja \
    --ctx-size 65536

立ち上がったら、http://127.0.0.1:8001/ の URL から直接チャットができます。

image.png

同じモデルは LM Studio でロードしたら、同じプロンプトで生成速度比べたら、llama.cpp のほうが倍以上でした。これほどのパフォーマンスの差は、おそらく LM Studio ででかいモデルは ROCm でロードできないからかもしれないです。モデルは完全に VRAM に入れない場合 LM Studio で Vulkan バックエンドを使われます。

最後に

インストールで参考にしたリソースは共有しましたので、みなさんも是非、llama.cpp を使ってみてください。

参考:

https://unsloth.ai/docs/models/qwen3-coder-next
https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md#hip
https://rocm.docs.amd.com/projects/install-on-linux/en/latest/install/quick-start.html
https://rocm.docs.amd.com/projects/rocWMMA/en/latest/install/installation.html
https://rocm.docs.amd.com/projects/hipBLAS/en/latest/install/Linux_Install_Guide.html

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?