2026年8月13日木曜日

WSL2 上で llama.cpp をビルドする

前回 は、 DGX Spark 向けにビルドしましたが、今回は WSL2 上でビルドする手順。

今回は初めからデーモン化する前提で進めていく。

前提

  • Windows: Windows 11 Pro 25H2 ビルド 26200.8524
  • グラフィックボード: NVIDIA GeForce RTX 4070 Ti SUPER (16 GB)
  • WSL2: Ubuntu 24.04 LTS

前提パッケージのインストール

llama.cpp 版をビルドするために必要なパッケージをインストールする。

sudo apt update
sudo apt install -y git build-essential cmake libssl-dev nvidia-cuda-toolkit

llama.cpp 実行ユーザーの追加

llama というシステムユーザーを追加する。

sudo useradd \
  --system \
  --home-dir /opt/llama \
  --shell /usr/sbin/nologin \
  llama

llama.cpp 用のディレクトリ作成

sudo mkdir /opt/llama
sudo chown llama:llama /opt/llama

llama.cpp ソースコードのクローン

いつものように git clone する。

cd /opt/llama
sudo -u llama git clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp

llama.cpp ビルド

NVIDIA のグラボなので、それ用の make コマンドを叩く。

sudo -u llama cmake -B build-cuda \
      -DGGML_CUDA=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DLLAMA_CURL=ON \
      -DLLAMA_OPENSSL=ON
sudo -u llama cmake --build build-cuda -j"$(nproc)" --target llama-server

動作確認

とりあえず普通に動くかを確認。

sudo -u llama /opt/llama/llama.cpp/build-cuda/bin/llama-server -hf unsloth/DeepSeek-V4-Flash-0731-GGUF:Q8_0

OK.

systemd 用のファイル作成

cat << 'EOF' | sudo tee /etc/systemd/system/llama-server.service
[Unit]
Description=llama.cpp OpenAI-compatible inference server
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=llama
Group=llama
WorkingDirectory=/opt/llama/llama.cpp/build-cuda/bin

ExecStart=/opt/llama/llama.cpp/build-cuda/bin/llama-server \
  -hf unsloth/Qwen3.6-35B-A3B-GGUF:UD-IQ3_XXS \
  --gpu-layers all \
  --no-mmap \
  --host 0.0.0.0 \
  --port 11434

Restart=on-failure
RestartSec=5

TimeoutStartSec=0
TimeoutStopSec=120
KillSignal=SIGINT

StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF

設定反映

sudo systemctl daemon-reload
sudo systemctl enable llama-server
sudo systemctl start llama-server

以上。

0 件のコメント:

コメントを投稿