1
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分でローカルPCでVLLMを使ってRakuten/RakutenAI-2.0-mini-instructを高速起動する方法

Posted at

はじめに

VLLM は、効率的で軽量な大規模言語モデル(LLM)サーバーです。この記事では、ローカルPCでVLLMを使用して Rakuten/RakutenAI-2.0-mini-instruct という高性能な言語モデルを高速に起動する方法を紹介します。この記事の手順に従えば、5分以内にモデルを起動できます。

環境準備

必要なツール

以下のツールがインストールされていることを確認してください:

  • conda:Python仮想環境を管理するために使用します。
  • pip:Pythonパッケージをインストールするために使用します。
  • VLLM:LLMを効率的に実行するためのサーバーです。
  • flash-attn:モデルの推論を高速化するためのライブラリです。

仮想環境の作成

まず、Python 3.11の仮想環境を作成し、有効化します。

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

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]"

RakutenAI-2.0-mini-instructのダウンロード

以下のコマンドを使用して、RakutenAI-2.0-mini-instruct モデルをダウンロードします。

HF_HUB_ENABLE_HF_TRANSFER=1 \
huggingface-cli download Rakuten/RakutenAI-2.0-mini-instruct

モデルの起動

起動コマンド

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

CUDA_VISIBLE_DEVICES=0 \
VLLM_USE_V1=1 \
VLLM_WORKER_MULTIPROC_METHOD=spawn \
vllm serve Rakuten/RakutenAI-2.0-mini-instruct \
--trust-remote-code --served-model-name gpt-4 \
--gpu-memory-utilization 0.98 --tensor-parallel-size 1 \
--port 8000 --max-model-len 2048 \
--disable-sliding-window

起動確認

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

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": 2048,
  "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"

注意事項

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

参考リンク


以上の手順に従えば、ローカルPCで Rakuten/RakutenAI-2.0-mini-instruct モデルを高速に起動できます。ぜひ試してみてください!

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