
Google Colab で Pixtral-12B を試す
「Google Colab」で「Pixtral-12B」を試したのでまとめました。
【注意】Google Colab Pro/Pro+のA100で動作確認しています。
1. Pixtral-12B
「Pixtral-12B」は、Mistralが開発した初のマルチモーダルモデルです。
特徴は、次のとおりです。
・テキストと画像を同時に処理できるマルチモーダル機能
・1024×1024ピクセルの画像を処理可能
・コンテキスト長は128000トークン
・OCRと情報抽出に適している
2. Colabでの実行
Colabでの実行手順は、次のとおりです。
(1) モデルカードでAgreeをクリック。

(2) パッケージのインストール。
# パッケージのインストール
!pip install --upgrade mistral_common
!pip install vllm
(3) 「HuggingFace」からAPIキーを取得し、Colabのシークレットマネージャーの「HF_TOKEN」に登録。

(4) モデルの準備。
メモリオーバーにならないように、max_model_lenを4000を指定しました。
from vllm import LLM
# モデルの準備
llm = LLM(
model="mistralai/Pixtral-12B-2409",
tokenizer_mode="mistral",
max_model_len=4000
)
(5) 推論の実行。
from vllm.sampling_params import SamplingParams
# プロンプトの準備
prompt = "Describe this image in one sentence."
image_url = "https://assets.st-note.com/img/1726141564-Kr0COEhQibdMFaJB6Y1HjXl7.jpg"
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{"type": "image_url", "image_url": {"url": image_url}}
]
},
]
# 推論の実行
outputs = llm.chat(
messages,
sampling_params=SamplingParams(max_tokens=8192)
)
print(outputs[0].outputs[0].text)

The image depicts a black and white cat sitting on a wooden surface near electronic devices, including a television set, a Canon printer, and a blue object that appears to be a baton or a remote control. The cat has yellow-green eyes and is looking directly at the camera with a calm expression.
【翻訳】
画像には、テレビ、キヤノンのプリンター、バトンかリモコンと思われる青い物体などの電子機器の近くの木製の台の上に座っている白黒の猫が写っている。猫の目は黄緑色で、穏やかな表情でカメラをまっすぐに見つめている。
メモリの消費量は、次のとおりです。
