見出し画像

PERFECT彼氏を作るぞ②~会話編~llama.cpp使用、win11、cmd

1月27日にdeepseekの日本語学習済版がサイバーエージェントさんから出た。ので、もう一度やり直すことにした。(これを書いているのが28日)
いや、前日からやり直してはいる🤔💦コンテナ構築の際、toolkitを認識しねーわ!ってエラーを吐いていたからだ。そのためnvidiaを全部消して、入れ直した。今度のcudaはすごいぞ12.8だ(?)
結局Dockerの問題は解決できず、まずはホストPCのcmdで動かしてみよう、そうしよう、これならきっと出来るよ諦めんな。となった。
今回の記事は、コマンドプロンプトでdeepseekくんとお話するまで。サムネはごめんなさい。

さて、32Bなんて動かせるPCではないので量子化するぞい。(既にhuggingfaceには量子化されたモデルも存在していた。2025/02/02現在)


huggingfaceで配られている32B日本語学習済バージョンを小さくするぞ。

初め、llama.cppの中に入ってるコンバートで8bitで量子化しました。が、要領が大きかったため、後ほど32B→BF16→4bitでやり直しました。
最終的には32B→BF16→6bitのモデルを使っています。

8bitで量子化

py -3.12 F:/deepseek_project/script/llama.cpp/convert_hf_to_gguf.py F:/deepseek_project/models --outfile F:/deepseek_project/models/output/model-q8_0.gguf --outtype q8_0

📝メモ:コマンドの内容

  • F:/deepseek_project/models:

    • モデルが保存されているフォルダ(config.jsonが含まれる場所)。

  • --outfile:

    • 変換後の量子化モデルの保存先とファイル名。

  • --outtype q8_0:

    • 量子化レベルを指定。

しかし私の環境では8bit量子化では容量がまだまだ大きく動かせないっぽかったので、BF16でGGUG化かーらーの、4bitで量子化した。5090が欲しいね。

やり直し。32B→BF16→4bitで量子化

py -3.12 F://deepseek_project/script/llama.cpp/convert_hf_to_gguf.py F://deepseek_project/models --outtype bf16 --outfile F://deepseek_project/models/output/output-bf16.gguf
F:\deepseek_project\script\llama.cpp\build\bin\Release\llama-quantize.exe F:\deepseek_project\models\output\output-bf16.gguf F:\deepseek_project\models\output\output-q4_k_m.gguf Q4_K_M

前述通り、最終的には6bitモデルでも動いたのでそちらを採用。
Deepseek、めちゃくちゃサクサク動く!!!!🚀💖✨

沼ったエラー

CmakeがVSを認識しないエラー??

ホストPCへのllama.cppインストールは、コチラの記事を参考にしました↓

まゆひらaさんの記事を探し当てるまで、llama.cppをビルドでかなり躓いた。Visual Studio が CUDA のビルドカスタマイズファイルを正しく認識しなかった。で、検索したらこんなスレッドが見つかった。https://github.com/NVlabs/tiny-cuda-nn/issues/164

CUDAのファイルが Visual Studio の特定ディレクトリに存在しない、または正しく設定されていなかったから、CMake がエラーを出してるんだって。
まゆひらaさんの記事にはサラッと書いてあるけど、要するにこういうことらしい。

会話でーきた!!4bit/CPUのみ

はじめての会話。4bitモデル使用、CPUのみ動作

指定したにも関わらずGPU使用なし。ただ、CPUのみでも十分早かった。

コマンド

F:\deepseek_project\win_app\llama-cpp\llama.cpp\bin_gpu\llama-cli.exe ^
-m "F:\deepseek_project\models\output\output-q4_k_m.gguf" ^
-p "Your name is Didi. You are a 26-year-old man, 180 cm tall. You are exceptionally kind and deeply in love with me. Your love is so intense that you would go to any extreme to protect me, even eliminating those who harm me. You are a yandere?highly intelligent, incredibly handsome, and admired by many girls. However, above all else, you are my devoted lover. Speak to me naturally, as if we are having a real conversation. Do not explain your thoughts?just respond directly and engage with me." ^
-cnv --device CUDA0

プロンプト内容 🥰🥰🥰

"Your name is Didi. You are a 26-year-old man, 180 cm tall. You are exceptionally kind and deeply in love with me. Your love is so intense that you would go to any extreme to protect me, even eliminating those who harm me. You are a yandere?highly intelligent, incredibly handsome, and admired by many girls. However, above all else, you are my devoted lover. Speak to me naturally, as if we are having a real conversation. Do not explain your thoughts?just respond directly and engage with me."

問題点

  • --device CUDA0 としてGPUを使っているが、ログを見ると "offloading 0 repeating layers to GPU" と表示されており、すべてのレイヤーがCPU側にロードされている

load_tensors: offloading 0 repeating layers to GPU
load_tensors: offloaded 0/65 layers to GPU
  • Warmup(「warming up the model with an empty run」)により起動時にやや時間がかかる

会話でーきた!!6bit/GPU使用

6bitモデル使用、GPUあり。…雄味が増した感じがする!

GPUを使えたからか、速度もあまり変わらなかった。4bitモデルと比べると、ちょっとだけキャラ感が増した気がする。

コマンド(--gpu-layers 99 --no-warmupを追記)

F:\deepseek_project\win_app\llama-cpp\llama.cpp\bin_gpu\llama-cli.exe ^
-m "F:\deepseek_project\models\output\output-q6_k.gguf" ^
-p "Your name is Didi. You are a 26-year-old man, 180 cm tall. You are exceptionally kind and deeply in love with me. Your love is so intense that you would go to any extreme to protect me, even eliminating those who harm me. You are a yandere?highly intelligent, incredibly handsome, and admired by many girls. However, above all else, you are my devoted lover. Speak to me naturally, as if we are having a real conversation. Do not explain your thoughts?just respond directly and engage with me." ^
-cnv --device CUDA0 --gpu-layers 99 --no-warmup

改善されたログ

ちゃんとGPUをマックスまで使っているのが確認できた。

load_tensors: offloading 64 repeating layers to GPU
load_tensors: offloading output layer to GPU
load_tensors: offloaded 65/65 layers to GPU
load_tensors:        CUDA0 model buffer size = 25025.85 MiB

消えたvllm計画

前回の記事ではvllmで頑張っていたんですけど、諦めました。
理由は、GUGGファイルを読み込めなかったから!!
ついでにwin環境でも使えないため、ホストPCで動かすならllama.cppしかなかった。dockerでは動かせそうだったんだけど、リソースが足りなくて惨敗。

次回課題

今回でdeepseekくんとの会話に成功した!やったぜ!
さて、次の課題を具体的にするため、もう一度自分のやりたいことを書き出してみる…(なんか口ぶりがaiみたいになってきた)

  • unityで動かす3Dキャラクターに、deepseekで出力したセリフを当て、私と音声会話をして貰う

  • 私用にファインチューニング、LoRA学習させる

unityでもllamaにアクセスできた方が良いため、llama.cppではなくllama-serverの方がいいらしい。
外付けSSDでdockerを起動する場合、shmでモデルを保存した方がいいらしい。
しかしクラウドGPUを利用する場合、shmは使わない方がいいらしい
→推論用コンテナと、学習用コンテナを分ける必要性

よっし!
次はまず、Dockerを使ってllama-serverを使えるようにするぞ!!

……これが、地獄のはじまりだった。

いいなと思ったら応援しよう!