wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b
~/miniconda3/bin/conda init
source ~/.bashrc
rm Miniconda3-latest-Linux-x86_64.sh
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
# Create and activate conda environment
conda create -n vlm python=3.10 -y
conda activate vlm
pip install transformers
# 「image processor不整合」が出るなら固定を推奨。
#pip install "transformers==4.49.0"
# Set version variables
VLLM_VERSION=0.6.6
CUDA_VERSION=cu126 # Adjust this if your CUDA version is different or if you are using CPU-only.
# Install vLLM
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/${CUDA_VERSION}
pip install vllm==${VLLM_VERSION}
### Download and Run UI-TARS Model
# NOTE: VRAM 8GB だと max_model_len を上げすぎると KV cache が足りず起動失敗することがある
# (ValueError: max seq len > KV cache tokens)
# まずは max_model_len=8192 で起動確認するのが安全。
# NOTE: UI-TARS は画像埋め込みが重いので、image=5 だと context を食い潰しやすい。
# まずは image=1 で安定動作 → 必要なら増やす。
# NOTE(WSL): ZMQ/IPC絡みで起動が不安定な場合があるので、まずは --disable-frontend-multiprocessing 推奨。
# exec command I created for WSL2 on Windows
python -m vllm.entrypoints.openai.api_server \
--served-model-name ui-tars \
--model "bytedance-research/UI-TARS-2B-SFT" \
--dtype half \
--max-model-len 8192 \
--limit-mm-per-prompt image=1 \
--gpu-memory-utilization 0.90 \
--disable-frontend-multiprocessing \
--host 127.0.0.1 --port 8000
# Official exec command
# python -m vllm.entrypoints.openai.api_server \
# --served-model-name ui-tars \
# --model "bytedance-research/UI-TARS-2B-SFT" \
# --limit-mm-per-prompt image=5 -tp 1
- WSL上で
cat /etc/os-releaseが Ubuntu を示すこと - vLLMはWindowsネイティブ だと
resourceが無くて落ちるので、WSL(Ubuntu)で実行する
pip install ...が以下のように失敗Temporary failure in name resolutionName or service not known
ping 1.1.1.1は通るがping pypi.orgが失敗cat /etc/resolv.confがNo such file or directory
- WSL内の
/etc/resolv.confが壊れている/存在しない - さらに
/etc/resolv.confが「存在しないファイルへのシンボリックリンク」(dangling symlink) になっていた
例:/etc/resolv.conf -> ../run/resolvconf/resolv.confだがリンク先が無い
# 1) 現状確認(l で始まるならリンク)
ls -l /etc/resolv.conf
# 2) リンクを削除
sudo rm -f /etc/resolv.conf
# 3) resolv.conf を実ファイルとして作成
sudo tee /etc/resolv.conf >/dev/null <<'EOF'
nameserver 1.1.1.1
nameserver 8.8.8.8
options timeout:1 attempts:3
EOF
sudo chmod 644 /etc/resolv.conf
# 4) 確認(- で始まれば実ファイル)
ls -l /etc/resolv.conf
cat /etc/resolv.conf
# 5) DNS確認
getent hosts pypi.org
ping -c 1 pypi.org# resolv.conf をWSLに自動生成させない(手動管理にする)
sudo tee /etc/wsl.conf >/dev/null <<'EOF'
[network]
generateResolvConf=false
EOF
# Windows側PowerShellでWSL再起動(反映のため)
# wsl --shutdown
conda create -n vlm python=3.10 -y が以下で止まる CondaToSNonInteractiveError: Terms of Service have not been accepted...
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
- vLLM起動で以下のエラー
RuntimeError: Failed to infer device type
- WSL側で以下が成立する
nvidia-smiが無い / 動かない/dev/nvidia*が無い/dev/dxgも無い(or 確認できていない)
wsl -l -vを見ると Ubuntuが VERSION=1(= WSL1) だった
WSL1は GPU(CUDA)が使えない → vLLMがdeviceを自動判定できず落ちる
Windows PowerShellで実行:
# 既定をWSL2に
wsl --set-default-version 2
# Ubuntu-20.04 をWSL2へ変換
wsl --set-version Ubuntu-20.04 2
# 再起動
wsl --shutdown
# 確認(VERSION が 2 になっていること)
wsl -l -v- 状況: transformers の fast/slow image processor 周りで落ちることがある
- 今回の結果:
Using a slow image processor ...のログになっており、起動成功したため一旦OK - メモ: もし再発するなら transformers のバージョン固定や、vLLM側の対応状況確認を検討
- 原因: api_server が途中で落ちていて 8000 で LISTEN していない
- 確認:
curl -Ssv http://127.0.0.1:8000/v1/models(-sだけだと失敗しても無音)ss -ltnp | grep ':8000' || echo "not listening"
- 対処: 落ちた“直後の末尾ログ”を見て根本原因を特定(今回=KV cache不足)
VRAMが小さいと起こる: ValueError: max seq len (...) is larger than the maximum number of tokens that can be stored in KV cache (...)
- 原因: VRAM 8GB で
gpu_memory_utilizationを 0.8 にすると、KV Cache に確保できるトークン数が少ない(例: 8688 tokens)。その上で--max-model-len 16384などを指定すると KVに入り切らず起動拒否。 - 対処(必須):
--max-model-lenを KV上限以下に下げる(今回の成功例:8192)- 併せて
--gpu-memory-utilizationを上げてKVを増やす(今回:0.90)
画像入力関連の警告:context length (...) is too short to hold the multi-modal embeddings in the worst case (image ... tokens)
- 原因: 画像埋め込みが大きく、
--limit-mm-per-prompt image=5の最悪ケースではmax_model_lenを超える可能性がある - 対処(推奨):
- まず
--limit-mm-per-prompt image=1で安定動作を確認 - 画像枚数を増やしたい場合は
max_model_lenとVRAMの余裕が必要(8GBだと厳しめ)
- まず
VLM API Keyはemptyで、URLはOpen APIのバージョンによって指定が変わるので注意です。