2024-09-20 Fri: Ollama を WSL2 で動かす
動機
LM Studio を Windows で動かしていたが、WSL2 と通信する方法がわからず、もういいやとなったため
やったこと
GPU を WSL2 側で認識しているかの確認
code:sh
nvidia-smi
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.30.04 Driver Version: 531.29 CUDA Version: 12.1 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 2070 S... On | 00000000:0B:00.0 On | N/A |
| 0% 49C P5 34W / 235W| 4739MiB / 8192MiB | 35% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 25 G /Xwayland N/A |
+---------------------------------------------------------------------------------------+
ちゃんと認識されていそう
ollama のインストール
code:sh
>>> Installing ollama to /usr/local
sudo password for hokupod: >>> Downloading Linux amd64 bundle
######################################################################## 100.0%
>>> Creating ollama user...
>>> Adding ollama user to render group...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> Nvidia GPU detected.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.
systemctl を利用出来るようにする
systemctl を使って常駐させる
code:sh
sudo systemctl status ollama
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
、、、systemctl が使えないことを知る。。。
systemctl を有効化する
code:sh
sudo vim /etc/wsl.conf
下記を追記
code:conf
systemd=true
PowerShell で WSL2 を再起動
code:ps1
wsl --shutdown
WSL2 に戻り、再度 systemctl を設定
code:sh
# 状況確認
sudo systemctl status ollama
# 常時起動設定
sudo systemctl enable ollama
# 今すぐ立ち上げ
sudo systemctl start ollama
ollama を楽しむ
あとは、好きなモデルをダウンロードし実行する
code:sh
ollama pull codestral
ollama run codestral