vllm-ascend について
vLLM-Ascendは、Huawei AscendプロセッサでLLM推論を実行するvLLMプラグインです。Ascend NPU向けにモデルをデプロイするチームを対象に、最適化カーネル、量子化、分散推論を提供します。
主な機能
- 01Ascend最適化推論カーネル
- 02msModelSlim量子化対応
- 03テンソル並列とパイプライン並列
- 04オフラインバッチ推論
- 05OpenAI互換APIサーバー
活用シーン
- 01Huawei Ascend NPUでのLLM提供
- 02量子化モデルの推論実行
- 03大規模モデルの複数NPUへの分散
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ ascend-ai-coding/ awesome-ascend-skills --skill vllm-ascendインストール後、Claude Code で/vllm-ascendを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/deployment.mddistributed.mdinstallation.mdperformance.mdquantization.mdtroubleshooting.mdscripts/benchmark.pycheck_env.shdeploy_service.sh詳細
vLLM-Ascend - LLM 推論サービング
vLLM-Ascend は、Huawei Ascend AI プロセッサー上で効率的な LLM 推論を実現する vLLM 用プラグインです。Ascend に最適化されたカーネル、量子化のサポート、分散推論機能を提供します。
クイックスタート
オフラインバッチ推論
import os
# Required for vLLM-Ascend: set multiprocessing method before importing vLLM
os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
from vllm import LLM, SamplingParams
# Load model with Ascend NPU (device auto-detected when vllm-ascend is installed)
llm = LLM(
model="Qwen/Qwen2.5-7B-Instruct",
max_model_len=4096
)
# Prepare prompts and sampling params
prompts = [
"Hello, how are you?",
"Explain quantum computing in simple terms.",
]
sampling_params = SamplingParams(temperature=0.7, top_p=0.9, max_tokens=512)
# Generate outputs
outputs = llm.generate(prompts, sampling_params)
# Print results
for output in outputs:
print(f"Prompt: {output.prompt}")
print(f"Output: {output.outputs[0].text}\n")
OpenAI 互換 API サーバー
# Start the API server
vllm serve Qwen/Qwen2.5-7B-Instruct \
--max-model-len 4096 \
--max-num-seqs 256 \
--served-model-name "qwen2.5-7b"
# Or using Python
python -m vllm.entrypoints.openai.api_server \
--model Qwen/Qwen2.5-7B-Instruct \
--max-model-len 4096
API クライアントの例
import requests
# Completions API
response = requests.post(
"http://localhost:8000/v1/completions",
json={
"model": "qwen2.5-7b",
"prompt": "Once upon a time",
"max_tokens": 100,
"temperature": 0.7
}
)
print(response.json())
# Chat Completions API
response = requests.post(
"http://localhost:8000/v1/chat/completions",
json={
"model": "qwen2.5-7b",
"messages": [
{"role": "user", "content": "Hello!"}
],
"max_tokens": 100
}
)
print(response.json())
インストール
前提条件
- CANN:8.0.RC1 以降
- Python:3.9 以降
- PyTorch Ascend:使用する CANN バージョンとの互換性があること
方法 1:Docker(推奨)
# Pull pre-built image
docker pull ascendai/vllm-ascend:latest
# Run with NPU access
docker run -it --rm \
--device /dev/davinci0 \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
-v /usr/local/Ascend/add-ons:/usr/local/Ascend/add-ons \
-e ASCEND_RT_VISIBLE_DEVICES=0 \
ascendai/vllm-ascend:latest
方法 2:pip によるインストール
# Install vLLM with Ascend plugin
pip install vllm-ascend
# Or install from source
git clone https://github.com/vllm-project/vllm-ascend.git
cd vllm-ascend
pip install -e .
インストールの確認
# Check vLLM Ascend installation
python -c "import vllm_ascend; print(vllm_ascend.__version__)"
# Check NPU availability
python -c "import torch; import torch_npu; print(torch_npu.npu.device_count())"
デプロイ
サーバーモード
# Basic server deployment
vllm serve <model_path> \
\
--served-model-name <name> \
--host 0.0.0.0 \
--port 8000
# Production deployment with optimizations
vllm serve /path/to/model \
\
--served-model-name "qwen2.5-72b" \
--max-model-len 8192 \
--max-num-seqs 256 \
--tensor-parallel-size 4 \
--gpu-memory-utilization 0.9 \
--dtype bfloat16 \
--api-key <your-api-key>
Python API
import os
# Required: Set spawn method before importing vLLM
os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
from vllm import LLM, SamplingParams
# Single NPU
llm = LLM(
model="Qwen/Qwen2.5-7B-Instruct",
max_model_len=4096,
dtype="bfloat16"
)
# Distributed inference (multi-NPU)
llm = LLM(
model="Qwen/Qwen2.5-72B-Instruct",
tensor_parallel_size=4,
max_model_len=8192
)
# Generate
params = SamplingParams(temperature=0.7, max_tokens=512)
outputs = llm.generate(["Hello world"], params)
LLM エンジン(上級者向け)
from vllm import LLMEngine, EngineArgs, SamplingParams
engine_args = EngineArgs(
model="Qwen/Qwen2.5-7B-Instruct",
max_model_len=4096
)
engine = LLMEngine.from_engine_args(engine_args)
# Add requests and step through generation
request_id = "req-001"
prompt = "Hello, world!"
params = SamplingParams(max_tokens=50)
engine.add_request(request_id, prompt, params)
while engine.has_unfinished_requests():
outputs = engine.step()
for output in outputs:
if output.finished:
print(f"{output.request_id}: {output.outputs[0].text}")
量子化
vLLM-Ascend は msModelSlim で量子化されたモデルをサポートしています。量子化の詳細については、msmodelslim を参照してください。
量子化モデルの使用
# W8A8 quantized model
vllm serve /path/to/quantized-model-w8a8 \
\
--quantization ascend \
--max-model-len 4096
# W4A8 quantized model
vllm serve /path/to/quantized-model-w4a8 \
\
--quantization ascend \
--max-model-len 4096
量子化を使用する Python API
from vllm import LLM, SamplingParams
llm = LLM(
model="/path/to/quantized-model",
quantization="ascend",
max_model_len=4096
)
params = SamplingParams(temperature=0.7, max_tokens=512)
outputs = llm.generate(["Hello"], params)
分散推論
テンソル並列化
大規模モデル向けに、モデルのレイヤーを複数の NPU に分散します。
# 4-way tensor parallelism
vllm serve Qwen/Qwen2.5-72B-Instruct \
--tensor-parallel-size 4 \
--max-model-len 8192
import os
os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
from vllm import LLM
llm = LLM(
model="Qwen/Qwen2.5-72B-Instruct",
tensor_parallel_size=4,
max_model_len=8192
)
パイプライン並列化
from vllm import LLM
llm = LLM(
model="DeepSeek-V3",
pipeline_parallel_size=2,
tensor_parallel_size=4
)
マルチノードデプロイ
# Node 0 (Rank 0)
vllm serve <model> \
\
--tensor-parallel-size 8 \
--pipeline-parallel-size 2 \
--distributed-init-method "tcp://192.168.1.10:29500" \
--distributed-rank 0
# Node 1 (Rank 1)
vllm serve <model> \
\
--tensor-parallel-size 8 \
--pipeline-parallel-size 2 \
--distributed-init-method "tcp://192.168.1.10:29500" \
--distributed-rank 1
パフォーマンスの最適化
主なパラメーター
| パラメーター | デフォルト | 説明 | 調整のアドバイス |
|---|---|---|---|
--max-model-len | Model max | 最大シーケンス長 | OOM が発生する場合は値を小さくします |
--max-num-seqs | 256 | 最大同時シーケンス数 | スループットを高めるには値を大きくします |
--gpu-memory-utilization | 0.9 | GPU メモリーの使用率 | ウォームアップ中に OOM が発生する場合は値を小さくします |
--dtype | auto | データ型 | 速度を優先する場合は bfloat16、互換性を優先する場合は float16 |
--tensor-parallel-size | 1 | テンソル並列化の次数 | 大規模モデルで使用します |
--pipeline-parallel-size | 1 | パイプライン並列化の次数 | 超大規模モデルで使用します |
設定例
# Small model (7B), single NPU
vllm serve <model> --max-model-len 4096 --max-num-seqs 256
# Medium model (32B), single NPU
vllm serve <model> --max-model-len 8192 --max-num-seqs 128
# Large model (72B), multi-NPU
vllm serve <model> --tensor-parallel-size 4 --max-model-len 8192
# Maximum throughput
vllm serve <model> --max-num-seqs 512 --gpu-memory-utilization 0.95
トラブルシューティング
よくある問題
Q:AclNN_Parameter_Error または dtype エラーが発生しますか?
# Check CANN version compatibility
npu-smi info
# Ensure CANN >= 8.0.RC1
# Try different dtype
vllm serve <model> --dtype float16
Q:メモリー不足(OOM)が発生しますか?
# Reduce max model length
vllm serve <model> --max-model-len 2048
# Lower memory utilization
vllm serve <model> --gpu-memory-utilization 0.8
# Reduce concurrent sequences
vllm serve <model> --max-num-seqs 128
Q:モデルの読み込みに失敗しますか?
# Check model path
ls /path/to/model
# Verify tokenizer
python -c "from transformers import AutoTokenizer; tok = AutoTokenizer.from_pretrained('/path/to/model'); print('OK')"
# Use trust_remote_code for custom models
vllm serve <model> --trust-remote-code
Q:推論が遅いですか?
# Enable bfloat16 for faster compute
vllm serve <model> --dtype bfloat16
# Adjust block size
vllm serve <model> --block-size 256
# Enable prefix caching
vllm serve <model> --enable-prefix-caching
Q:API サーバーへの接続が拒否されますか?
# Check server is running
curl http://localhost:8000/health
# Verify port is not in use
lsof -i :8000
# Use explicit host/port
vllm serve <model> --host 0.0.0.0 --port 8000
環境変数
# Required: Set multiprocessing method for vLLM-Ascend
export VLLM_WORKER_MULTIPROC_METHOD=spawn
# Set Ascend device IDs
export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3
# Debug logging
export VLLM_LOGGING_LEVEL=DEBUG
# Disable lazy initialization (for debugging)
export VLLM_ASCEND_LAZY_INIT=0
スクリプト
scripts/benchmark_throughput.py- スループットのベンチマークscripts/benchmark_latency.py- レイテンシーのベンチマークscripts/start_server.sh- サーバー起動用テンプレート
参考資料
- references/deployment.md - デプロイパターンとベストプラクティス
- references/supported-models.md - モデルサポートの完全な一覧
- references/api-reference.md - API エンドポイントのドキュメント
関連スキル
- msmodelslim - vLLM-Ascend 用のモデル量子化
- ascend-docker - Ascend 用 Docker コンテナーのセットアップ
- npu-smi - NPU デバイス管理
- hccl-test - マルチ NPU 向け HCCL パフォーマンステスト
公式リファレンス
- vLLM-Ascend ドキュメント:https://docs.vllm.ai/projects/ascend/en/latest/
- vLLM ドキュメント:https://docs.vllm.ai/
- Huawei Ascend:https://www.hiascend.com/document
- GitHub リポジトリ:https://github.com/vllm-project/vllm-ascend
コメント
Markdown 対応