2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

5分でできる!VLLMを使ったDeepSeek-R1-Distill-Qwen-32Bのローカル環境構築

Posted at

はじめに

VLLMは、大規模言語モデル(LLM)を高速かつ効率的に動作させるための軽量なサーバーです。本記事では、DeepSeek-R1-Distill-Qwen-32Bという高性能な言語モデルを、ローカルPCでVLLMを使って簡単に起動する方法を解説します。手順に従えば、わずか5分でモデルを動作させることが可能です。


目次

  1. 環境準備
  2. モデルのダウンロード
  3. モデルの起動
  4. モデルの検証
  5. 注意事項
  6. 参考リンク

環境準備

必要なツール

以下のツールを準備してください:

  • conda:Python仮想環境の管理に使用します。
  • pip:Pythonパッケージのインストールに使用します。
  • VLLM:LLMを高速に動作させるためのサーバーです。
  • flash-attn:モデルの推論速度を向上させるためのライブラリです。

仮想環境の作成

まず、Python 3.11の仮想環境を作成し、アクティベートします。

conda create -n vllm_v0.7.1 python=3.11 -y
conda activate vllm_v0.7.1

VLLMと依存ライブラリのインストール

以下のコマンドで、VLLMとflash-attnをインストールします。

pip install vllm
pip install flash-attn --no-build-isolation

モデルのダウンロード

Hugging Face CLIのインストール

モデルをダウンロードするために、Hugging Face CLIをインストールします。

pip install "huggingface_hub[hf_transfer]"

DeepSeek-R1-Distill-Qwen-32Bのダウンロード

以下のコマンドで、DeepSeek-R1-Distill-Qwen-32Bをダウンロードします。

HF_HUB_ENABLE_HF_TRANSFER=1 \
huggingface-cli download deepseek-ai/DeepSeek-R1-Distill-Qwen-32B

モデルの起動

起動コマンド

以下のコマンドでモデルを起動します。
CUDA_VISIBLE_DEVICESで使用するGPUを指定し、--tensor-parallel-sizeでGPUの数を指定します。)

CUDA_VISIBLE_DEVICES=3,1,0,2 \
VLLM_USE_V1=1 \
VLLM_WORKER_MULTIPROC_METHOD=spawn \
vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-32B \
--trust-remote-code --served-model-name gpt-4 \
--gpu-memory-utilization 0.98 --tensor-parallel-size 4 \
--port 8000 --max-model-len 65536

起動確認

起動に成功すると、以下のメッセージが表示されます。

INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

モデルの検証

APIリクエストの送信

以下のコマンドで、起動したモデルにAPIリクエストを送信し、動作を確認します。

invoke_url='http://localhost:8000/v1/chat/completions'

authorization_header='Authorization: Bearer sk-dummy'
accept_header='Accept: application/json'
content_type_header='Content-Type: application/json'

data=$'{
  "messages": [
    {
      "role": "user",
      "content": "Which number is larger, 9.11 or 9.8?"
    }
  ],
  "stream": false,
  "model": "gpt-4",
  "max_tokens": 4096,
  "presence_penalty": 0,
  "frequency_penalty": 0,
  "top_p": 0.7,
  "temperature": 0.6
}'

response=$(curl --silent -i -w "\n%{http_code}" --request POST \
  --url "$invoke_url" \
  --header "$authorization_header" \
  --header "$accept_header" \
  --header "$content_type_header" \
  --data "$data"
)

echo "$response"

サンプル出力

以下のようなレスポンスが返ってきます。
image.png


注意事項

  • GPUメモリの設定--gpu-memory-utilization 0.98はGPUメモリの利用率を設定します。環境に応じて調整してください。
  • テンソル並列処理--tensor-parallel-size 4は使用するGPUの数に応じて変更します。
  • ポート番号--port 8000はAPIのポート番号です。他のアプリケーションと競合する場合は変更してください。

参考リンク


この手順に従えば、ローカルPCでDeepSeek-R1-Distill-Qwen-32Bを簡単に動作させることができます。ぜひお試しください!

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?