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?

Windows11の環境でllama-cpp-pythonをGPU対応でビルドするまでにハマった話

Posted at

こんにちは。
今回は Windows環境で「llama-cpp-python」をGPU(CUDA)対応でビルドする までにハマったポイントをまとめます。
同じように苦しむ人が減るといいなと思って書きます!


背景

友人からYoutubeのURLを入力すれば文字起こしができるアプリを作ってほしいという依頼にこたえる形で開発を始めました。

1.YouTubeから音声(m4a)だけダウンロード
(yt_dlp使用)

2.ffmpegで音声をWAVに変換
(Whisper用に16kHz・PCM形式へ)

3.Whisperで文字起こし
(英語・日本語どちらでもOK)

4.Llama.cppモデルを使って句読点を自動挿入
(LLMに整形してもらう)

5.テキストファイルに保存

今回この4番の環境構築でめんどくさいことになってしまったので共有します。


まず普通にインストールしようとしたら失敗

pip install llama-cpp-python

→ CPU版でしか動かない!

GPU使うにはCMakeオプション付きビルドが必要と知る。


🛠 Visual Studio周りの地獄

cl.exe がないエラー

cl.exe : 用語 'cl.exe' は認識されません。

解決方法

  • Visual Studio 2022 Community版インストール
  • 「C++によるデスクトップ開発」ワークロードを選択
  • 以後、**「x64 Native Tools Command Prompt for VS 2022」**から作業する!

x64 Developerコンソールでやったこと

まずコンソールを「管理者権限」で開いて、以下を実施!

cd C:\Users\ユーザ名\Documents\tool\AudioToText
.\venv311\Scripts\activate
cd llama-cpp-python

:: TEMPパスを短縮
set TEMP=C:\temp
set TMP=C:\temp

:: CUDA有効ビルドオプション
set CMAKE_ARGS=-DGGML_CUDA=on

:: 再インストール&ビルド
pip install . --force-reinstall --no-binary :all:

ハマったエラーたち

tempが長すぎると発生するエラー

LINK : fatal error LNK1104: ファイル 'build\temp.win-amd64-cpython-311\Release\xxx.exp' を開くことができません。

これ、Tempのパスが長いのが原因でした。

TEMP=C:\temp に変えたら回避できた!


CUDAオプションを間違えると発生するエラー

CMake Error at vendor/llama.cpp/CMakeLists.txt:107 (message):
  LLAMA_CUBLAS is deprecated and will be removed in the future.
  Use GGML_CUDA instead

→ 正しくは GGML_CUDA=on を指定すること!


最終的なビルドログのイメージ

Building wheel for llama_cpp_python (pyproject.toml) ... done
Successfully built llama_cpp_python
Installing collected packages: llama_cpp_python
Successfully installed llama_cpp_python-0.3.8

ここまでいけば、GPU版ビルド成功!!


まとめ表

問題 対策
cl.exeがない Visual Studio 2022 C++開発環境導入
LNK1104 Tempエラー TEMP=C:\temp に変更する
CUDAオプションミス GGML_CUDA=on に正しく設定
CPUビルドになってしまう --no-binary :all: を使ってソースからビルド

感想

  • Linuxなら数分だった…
  • WSL2は重いから使いたくなかった
  • 苦労したけどGPUは爆速で動いて大満足!

最後に

Visual StudioはBuild Toolsも忘れずに入れる
TEMPを短縮するだけでLNK1104は回避できる
CUDAオプションはGGML_CUDA=on!!

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?