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?

10分でできる!VLLMを使ったmistralai/Mistral-Small-3.1-24B-Instruct-2503のローカル環境構築

Last updated at Posted at 2025-03-18

はじめに

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


目次

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

環境準備

必要なツール

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

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

仮想環境の作成

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

conda create -n vllm_main python=3.12 -y
conda activate vllm_main

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

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

pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly --upgrade
pip install flash-attn --no-build-isolation
pip install flashinfer-python -i https://flashinfer.ai/whl/cu124/torch2.6
pip install git+https://github.com/huggingface/transformers@v4.49.0-Gemma-3

2025/3/18時点では、mistralai/Mistral-Small-3.1-24B-Instruct-2503をサポートするVLLMはまだリリースされていないため、nightlyからインストールする必要です。


モデルのダウンロード

Hugging Face CLIのインストール

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

pip install "huggingface_hub[hf_transfer]"

mistralai/Mistral-Small-3.1-24B-Instruct-2503のダウンロード

以下のコマンドで、mistralai/Mistral-Small-3.1-24B-Instruct-2503をダウンロードします。

HF_HUB_ENABLE_HF_TRANSFER=1 \
huggingface-cli download mistralai/Mistral-Small-3.1-24B-Instruct-2503

モデルの起動

起動コマンド

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

CUDA_VISIBLE_DEVICES=3,1,0,2 \
VLLM_WORKER_MULTIPROC_METHOD=spawn \
TRANSFORMERS_OFFLINE=1 \
HF_DATASETS_OFFLINE=1 \
VLLM_WORKER_MULTIPROC_METHOD=spawn \
vllm serve mistralai/Mistral-Small-3.1-24B-Instruct-2503 \
--tokenizer_mode mistral \
--config_format mistral \
--load_format mistral \
--tool-call-parser mistral \
--trust-remote-code \
--served-model-name gpt-4o \
--gpu-memory-utilization 0.98 \
--tensor-parallel-size 4 \
--port 8000 \
--api-key sk-dummy \
--max-model-len 32768 \
--enable-auto-tool-choice --tool-call-parser mistral \
--limit_mm_per_prompt 'image=10' \
--enable-chunked-prefill \
--max-num-batched-tokens 2048

起動確認

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

INFO 03-13 08:17:14 [api_server.py:958] Starting vLLM API server on http://0.0.0.0:8000
INFO 03-13 08:17:14 [launcher.py:26] Available routes are:
INFO 03-13 08:17:14 [launcher.py:34] Route: /openapi.json, Methods: HEAD, GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /docs, Methods: HEAD, GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /docs/oauth2-redirect, Methods: HEAD, GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /redoc, Methods: HEAD, GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /health, Methods: GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /ping, Methods: POST, GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /tokenize, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /detokenize, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /v1/models, Methods: GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /version, Methods: GET
INFO 03-13 08:17:14 [launcher.py:34] Route: /v1/chat/completions, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /v1/completions, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /v1/embeddings, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /pooling, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /score, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /v1/score, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /v1/audio/transcriptions, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /rerank, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /v1/rerank, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /v2/rerank, Methods: POST
INFO 03-13 08:17:14 [launcher.py:34] Route: /invocations, Methods: POST
INFO:     Started server process [102854]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

モデルの検証

Chatbox AIというツールを使用して、検証してみてみました。

検証1

鯉のぼりを識別してくれませんでした。

image.png

検証2

Markdownのフォーマットが崩れました。

image.png

検証3

テーブル形式で識別してもらったら、またMarkdownのフォーマットが崩れました。

image.png

検証4

テキストを抽出してもらいました。

image.png


注意事項

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

参考リンク


この手順に従えば、ローカルPCでmistralai/Mistral-Small-3.1-24B-Instruct-2503を簡単に動作させることができます。ぜひお試しください!

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?