0
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?

FreeBSD 15-RELEASEでQwen3.5 4B/9Bを動かす

0
Posted at

粗筋

FreeBSD 14.3でQwen3.5を動作させるべくllama.cppの設定を詰めてみたが、DRMと相性が良くないのかDeviceLostが起きる度にOS毎の再起動を強いられた。最新のドライバを使用する方がトラブルも少いと思案し、最新の15-RELEASEにして環境構築をし直すことにした。

OSのアップグレード

最初にOSのバージョンをアップグレードする。バックアップしたら以下のコマンドを入力する。トラブルで履歴が飛んだので記憶で書いてあるが、概ね正しいしハンドブックの内容とも同じだから問題はない筈。

freebsd-update fetch
freebsd-update install
freebsd-update upgrade -R 15.0-RELEASE
freebsd-update install
pkg update
pkg upgrade
reboot

DRMのトラブル

再起動したものの、sshログインすら受け付けない。モニタを繋げて確認したら、DRMドライバがエラーを出してカーネルパニックが起きてた。

KLD admgpu_yellow_carp_vcn_bin.ko: depend on kernel - not available or version mismatch

...

drmn0: could not load firmware image 'admgpu_yellow_carp_vcn_bin'

キーボードを繋いでシングルユーザーモードに入り、一時的にDRMを外す。

mount -u /
pkg delte drm-66-kmod

無事にマルチユーザーモードで起動したが、使用したいのはDRMドライバなのでこのままでは困る。drm-latest-kmodも試したが解消しないため、GoogleやGeminiに頼る。ドライバのアンマッチだから強制再インストールが良いと出たのでその通りにする。

pkg delete -f drm-latest-kmod drm_info gpu-firmware-*
pkg install drm-latest-kmod drm_info gpu-firmware-kmod

これで問題は解決した。

LLM環境の再構築

llama-swapを起動して既存のLLMが動作するか確認する。gemma-3n-E4Bがpkgでインストールしたllama.cppで動作するのを確認。

llama.cppの再コンパイル

いよいよQwen3.5だが、pkgのllama.cppでは動作しないので野良ビルドする。14.3で使用したディレクトリを流用するとビルドしても起動に失敗するので、新規にディレクトリを作る必要がある。手順はQwen3.5 - ローカル実行ガイド|Unsloth Documentationに詳しい。

cd llama.cpp
rm -rf build
git pull # 念のため
cd ..
cmake llama.cpp -B llama.cpp/build -DBUILD_SHARED_LIBS=OFF -DGGML_VULKAN=ON
cmake --build llama.cpp/build --config Release -j 16 --clean-first --target llama-cli llama-mtmd-cli llama-server llama-gguf-split

Vulkanシェーダーのキャッシュ削除

14.3で動作させた設定があるのでそのまま動くと期待してたが、エラーが出た。

radv/amdgpu: The CS has been cancelled because the context is lost. This context is innocent.

Terminating due to uncaught exception 0x3e33d4a2da80 of type vk::DeviceLostError

Geminiと遣り取りしてVulkanシェーダーにあるキャッシュが合致しないのではと提案された。その通りにキャッシュを削除する。

rm -r .cache/mesa_shader_cache

これで無事に動作した。

llama.cppのチューニング

起動後はllama.cppのWebインタフェースを使用してパラメータのチューニングする。DeviceLostが起きてもOSのリブートが不要なのでサクサク進む。野良ビルドしたバイナリだからなのか「gemma-3n-E4Bをロードした後にQwen3.5をロードしないとフラッシュアテンションがONにならない」みたいな動作になるが、大した手間が増えるでもないのでこのまま設定を詰める。最終的に以下で安定した。

config.yaml
models:
  "gemma-3n-E4B":
    cmd: |
      /usr/local/bin/llama-server
      --model /home/llama/models/gemma-3n-E4B-it-Q4_K_S.gguf
      -ngl 99
      --ctx-size 32768
      --temp 1.0
      --top-p 0.95
      --min-p 0.0
      --port ${PORT}

  "Qwen3.5-4B-nothink":
    env:
      - "GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1"
    cmd: |
      env GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1 \
      /home/llama/bin/llama-server
      --model /home/llama/models/qwen3.5-4b/Qwen3.5-4B-Q4_K_M.gguf
      --mmproj /home/llama/models/qwen3.5-4b/mmproj-F16.gguf
      --mmproj-offload
      --draft 0
      --spec-type none
      --flash-attn on
      --no-context-shift
      -ngl 99
      -np 1
      --no-warmup
      -ctk f16 -ctv f16
      --temp 0.1
      --top-p 0.95
      --min-p 0.00
      --repeat_penalty 1.1
      --ctx-size 16384
      --reasoning off
      --port ${PORT}

  "Qwen3.5-4B-think":
    env:
      - "GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1"
    cmd: |
      env GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1 \
      /home/llama/bin/llama-server
      --model /home/llama/models/qwen3.5-4b/Qwen3.5-4B-Q4_K_M.gguf
      --mmproj /home/llama/models/qwen3.5-4b/mmproj-F16.gguf
      --mmproj-offload
      --draft 0
      --spec-type none
      --flash-attn on
      -ngl 99
      -np 1
      --no-warmup
      -ctk f16 -ctv f16
      --temp 0.1
      --top-p 0.95
      --min-p 0.00
      --repeat_penalty 1.1
      --ctx-size 16384
      --reasoning on
      --port ${PORT}

  "Qwen3.5-9B-think":
    env:
      - "GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1"
    cmd: |
      env GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1 \
      /home/llama/bin/llama-server
      --model /home/llama/models/qwen3.5-9b/Qwen3.5-9B-Q4_K_M.gguf
      --spec-type none
      --flash-attn on
      -ngl 33
      -np 1
      --no-warmup
      -ctk q8_0 -ctv q8_0
      --temp 0.7
      --top-p 0.95
      --min-p 0.00
      --repeat_penalty 1.1
      --ctx-size 10240
      -b 256
      -ub 128
      --reasoning on
      --port ${PORT}

  "Qwen3.5-9B-nothink":
    env:
      - "GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1"
    cmd: |
      env GGML_VULKAN_DISABLE_FUSED_GATED_DELTA_NET=1 \
      /home/llama/bin/llama-server
      --model /home/llama/models/qwen3.5-9b/Qwen3.5-9B-Q4_K_M.gguf
      --draft 0
      --spec-type none
      --flash-attn on
      -ngl 33
      -np 1
      --no-warmup
      -ctk q8_0 -ctv q8_0
      --temp 0.1
      --top-p 0.95
      --min-p 0.00
      --repeat_penalty 1.1
      --ctx-size 16384
      --reasoning off
      --port ${PORT}

動作結果

以下に動作結果を示す。推論速度は平均を算出してないので目安として欲しい。

モデル マルチモーダル 推論速度
gemma-3n-E4B 20.18 t/s
Qwen3.5-4B-nothink 18.76 t/s
Qwen3.5-4B-think 18.74 t/s
Qwen3.5-9B-nothink 11.72 t/s
Qwen3.5-9B-think 11.69 t/s

マルチモーダルの利用は可能だが、エンコードに80秒以上のコストが掛かるのでこの環境では微妙ではある。しかし、CPUのRadeon 680Mを利用したローカルLLMの性能として十分な性能は出せた。Qwen3.5は素の性能が高いので期待したい。

補則

ローカルLLM基盤としてはollamaもあるが、まだバージョンが0.13.5で採用に至らない。ただし0.18.0はFRESH ports | misc/ollamaにあるので、待てばその内にQwen3.5で遊べる筈だ。

御精讀、ありがたうございました。

0
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
0
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?