モデル概要
モデル特徴
モデル能力
使用事例
🚀 Qwen2.5-VL-72B-Instruct
Qwen2.5-VL-72B-Instructは、Qwenファミリーの最新のビジョン言語モデルです。画像や動画に含まれるテキスト、チャート、アイコンなどを分析する能力に優れ、またビジュアルエージェントとしての機能も備えています。金融や商取引などの分野での利用にも役立つ構造化出力機能を持っています。
🚀 クイックスタート
Qwen2.5-VLのコードは最新のHugging face transformersに含まれています。ソースからビルドすることをおすすめします。以下のコマンドを実行してください。
pip install git+https://github.com/huggingface/transformers accelerate
これを行わないと、以下のエラーが発生する可能性があります。
KeyError: 'qwen2_5_vl'
様々なタイプのビジュアル入力をより便利に扱うためのツールキットが用意されています。以下のコマンドでインストールできます。
# 高速な動画読み込みのために `[decord]` 機能の使用を強くおすすめします。
pip install qwen-vl-utils[decord]==0.0.8
Linuxを使用していない場合は、PyPIから decord
をインストールできない可能性があります。その場合は pip install qwen-vl-utils
を使用すると、動画処理にtorchvisionが使用されます。ただし、ソースからdecordをインストール することで、動画読み込み時にdecordを使用できます。
🤗 Transformersを使用したチャット
以下は、transformers
と qwen_vl_utils
を使用してチャットモデルを利用するコード例です。
from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
# デフォルト: 利用可能なデバイス上でモデルをロード
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen2.5-VL-72B-Instruct", torch_dtype="auto", device_map="auto"
)
# より高速な処理とメモリ節約のために flash_attention_2 を有効にすることをおすすめします。特に複数画像や動画のシナリオで有効です。
# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
# "Qwen/Qwen2.5-VL-72B-Instruct",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
# device_map="auto",
# )
# デフォルトのプロセッサー
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-72B-Instruct")
# モデルでの画像ごとのビジュアルトークン数のデフォルト範囲は4 - 16384です。
# パフォーマンスとコストをバランスさせるために、min_pixelsとmax_pixelsを必要に応じて設定できます。例えば、トークン範囲を256 - 1280に設定できます。
# min_pixels = 256*28*28
# max_pixels = 1280*28*28
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-72B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
},
{"type": "text", "text": "Describe this image."},
],
}
]
# 推論の準備
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# 推論: 出力の生成
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
複数画像の推論
# 複数の画像とテキストクエリを含むメッセージ
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/image1.jpg"},
{"type": "image", "image": "file:///path/to/image2.jpg"},
{"type": "text", "text": "Identify the similarities between these images."},
],
}
]
# 推論の準備
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# 推論
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
動画の推論
# 動画としての画像リストとテキストクエリを含むメッセージ
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": [
"file:///path/to/frame1.jpg",
"file:///path/to/frame2.jpg",
"file:///path/to/frame3.jpg",
"file:///path/to/frame4.jpg",
],
},
{"type": "text", "text": "Describe this video."},
],
}
]
# ローカル動画パスとテキストクエリを含むメッセージ
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": "file:///path/to/video1.mp4",
"max_pixels": 360 * 420,
"fps": 1.0,
},
{"type": "text", "text": "Describe this video."},
],
}
]
# 動画URLとテキストクエリを含むメッセージ
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4",
},
{"type": "text", "text": "Describe this video."},
],
}
]
# Qwen 2.5 VLでは、フレームレート情報もモデルに入力され、絶対時間とのアライメントが行われます。
# 推論の準備
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
fps=fps,
padding=True,
return_tensors="pt",
**video_kwargs,
)
inputs = inputs.to("cuda")
# 推論
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
動画URLの互換性は主にサードパーティライブラリのバージョンに依存します。詳細は以下の表を参照してください。デフォルトのバックエンドを使用しない場合は、FORCE_QWENVL_VIDEO_READER=torchvision
または FORCE_QWENVL_VIDEO_READER=decord
でバックエンドを変更できます。
バックエンド | HTTP | HTTPS |
---|---|---|
torchvision >= 0.19.0 | ✅ | ✅ |
torchvision < 0.19.0 | ❌ | ❌ |
decord | ✅ | ❌ |
バッチ推論
# バッチ推論のサンプルメッセージ
messages1 = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/image1.jpg"},
{"type": "image", "image": "file:///path/to/image2.jpg"},
{"type": "text", "text": "What are the common elements in these pictures?"},
],
}
]
messages2 = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who are you?"},
]
# バッチ処理のためにメッセージを結合
messages = [messages1, messages2]
# バッチ推論の準備
texts = [
processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
for msg in messages
]
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=texts,
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# バッチ推論
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_texts = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_texts)
🤖 ModelScope
特に中国本土のユーザーには、ModelScopeの使用を強くおすすめします。snapshot_download
を使用すると、チェックポイントのダウンロードに関する問題を解決できます。
その他の使用方法
入力画像には、ローカルファイル、base64エンコード、URLをサポートしています。動画については、現在ローカルファイルのみをサポートしています。
# テキスト内の任意の位置に、ローカルファイルパス、URL、またはbase64エンコードされた画像を直接挿入できます。
## ローカルファイルパス
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/your/image.jpg"},
{"type": "text", "text": "Describe this image."},
],
}
]
## 画像URL
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "http://path/to/your/image.jpg"},
{"type": "text", "text": "Describe this image."},
],
}
]
## Base64エンコードされた画像
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "data:image;base64,/9j/..."},
{"type": "text", "text": "Describe this image."},
],
}
]
パフォーマンス向上のための画像解像度
モデルは広範囲の解像度入力をサポートしています。デフォルトでは、ネイティブ解像度を使用しますが、より高い解像度を使用すると、計算量は増えますがパフォーマンスが向上します。ユーザーは最小および最大ピクセル数を設定して、速度とメモリ使用量のバランスを取ることができます。例えば、トークン数の範囲を256 - 1280に設定できます。
min_pixels = 256 * 28 * 28
max_pixels = 1280 * 28 * 28
processor = AutoProcessor.from_pretrained(
"Qwen/Qwen2.5-VL-72B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels
)
さらに、モデルに入力する画像サイズを細かく制御する方法が2つあります。
-
min_pixelsとmax_pixelsを定義する: 画像は、min_pixelsとmax_pixelsの範囲内でアスペクト比を維持したままリサイズされます。
-
正確な寸法を指定する:
resized_height
とresized_width
を直接設定します。これらの値は、最も近い28の倍数に丸められます。
# min_pixelsとmax_pixels
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "file:///path/to/your/image.jpg",
"resized_height": 280,
"resized_width": 420,
},
{"type": "text", "text": "Describe this image."},
],
}
]
# resized_heightとresized_width
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "file:///path/to/your/image.jpg",
"min_pixels": 50176,
"max_pixels": 50176,
},
{"type": "text", "text": "Describe this image."},
],
}
]
長文の処理
現在の config.json
は、最大32,768トークンのコンテキスト長に設定されています。32,768トークンを超える大量の入力を処理するために、YaRN というモデルの長文拡張技術を利用しています。これにより、長文でも最適なパフォーマンスを維持できます。
サポートされているフレームワークでは、config.json
に以下を追加してYaRNを有効にできます。
{
...,
"type": "yarn",
"mrope_section": [
16,
24,
24
],
"factor": 4,
"original_max_position_embeddings": 32768
}
ただし、この方法は時間的および空間的なローカライゼーションタスクのパフォーマンスに大きな影響を与えるため、使用はおすすめできません。
同時に、長い動画入力の場合は、MRoPE自体がidsをより節約的に使用するため、max_position_embeddingsを直接64kなどのより大きな値に変更することができます。
✨ 主な機能
主な強化点
-
視覚的な理解能力: Qwen2.5-VLは、花、鳥、魚、昆虫などの一般的な物体の認識に精通しているだけでなく、画像内のテキスト、チャート、アイコン、グラフィック、レイアウトを分析する能力も高いです。
-
エージェント機能: Qwen2.5-VLは、視覚エージェントとして直接機能し、推論してツールを動的に指示することができます。コンピューターや携帯電話の使用も可能です。
-
長い動画の理解とイベントの捕捉: Qwen2.5-VLは、1時間以上の動画を理解することができ、今回は関連する動画セグメントを特定することでイベントを捕捉する新しい機能を備えています。
-
様々な形式でのビジュアルローカライゼーション: Qwen2.5-VLは、バウンディングボックスまたはポイントを生成することで画像内の物体を正確にローカライズすることができ、座標と属性の安定したJSON出力を提供することができます。
-
構造化出力の生成: 請求書、フォーム、テーブルなどのスキャンデータについて、Qwen2.5-VLはその内容の構造化出力をサポートしており、金融、商取引などの分野での利用に役立ちます。
モデルアーキテクチャの更新
- 動画理解のための動的解像度とフレームレートのトレーニング: 動的解像度を時間次元に拡張し、動的FPSサンプリングを採用することで、モデルが様々なサンプリングレートで動画を理解できるようにしました。それに応じて、時間次元のmRoPEをIDと絶対時間のアライメントで更新し、モデルが時間的なシーケンスと速度を学習し、特定の瞬間を特定する能力を獲得できるようにしました。
- 効率的なビジョンエンコーダー: ViTにウィンドウアテンションを戦略的に実装することで、トレーニングと推論の速度を向上させました。ViTアーキテクチャは、SwiGLUとRMSNormでさらに最適化され、Qwen2.5 LLMの構造に合わせられています。
パラメータ数が30億、70億、720億の3つのモデルがあります。このリポジトリには、命令微調整された72BのQwen2.5-VLモデルが含まれています。詳細については、ブログ と GitHub を参照してください。
📚 ドキュメント
画像ベンチマーク
ベンチマーク | GPT4o | Claude3.5 Sonnet | Gemini-2-flash | InternVL2.5-78B | Qwen2-VL-72B | Qwen2.5-VL-72B |
---|---|---|---|---|---|---|
MMMUval | 70.3 | 70.4 | 70.7 | 70.1 | 64.5 | 70.2 |
MMMU_Pro | 54.5 | 54.7 | 57.0 | 48.6 | 46.2 | 51.1 |
MathVista_MINI | 63.8 | 65.4 | 73.1 | 76.6 | 70.5 | 74.8 |
MathVision_FULL | 30.4 | 38.3 | 41.3 | 32.2 | 25.9 | 38.1 |
Hallusion Bench | 55.0 | 55.16 | 57.4 | 58.1 | 55.16 | |
MMBench_DEV_EN_V11 | 82.1 | 83.4 | 83.0 | 88.5 | 86.6 | 88 |
AI2D_TEST | 84.6 | 81.2 | 89.1 | 88.1 | 88.4 | |
ChartQA_TEST | 86.7 | 90.8 | 85.2 | 88.3 | 88.3 | 89.5 |
DocVQA_VAL | 91.1 | 95.2 | 92.1 | 96.5 | 96.1 | 96.4 |
MMStar | 64.7 | 65.1 | 69.4 | 69.5 | 68.3 | 70.8 |
MMVet_turbo | 69.1 | 70.1 | 72.3 | 74.0 | 76.19 | |
OCRBench | 736 | 788 | 854 | 877 | 885 | |
OCRBench-V2(en/zh) | 46.5/32.3 | 45.2/39.6 | 51.9/43.1 | 45/46.2 | 47.8/46.1 | 61.5/63.7 |
CC-OCR | 66.6 | 62.7 | 73.0 | 64.7 | 68.7 | 79.8 |
動画ベンチマーク
ベンチマーク | GPT4o | Gemini-1.5-Pro | InternVL2.5-78B | Qwen2VL-72B | Qwen2.5VL-72B |
---|---|---|---|---|---|
VideoMME w/o sub. | 71.9 | 75.0 | 72.1 | 71.2 | 73.3 |
VideoMME w sub. | 77.2 | 81.3 | 74.0 | 77.8 | 79.1 |
MVBench | 64.6 | 60.5 | 76.4 | 73.6 | 70.4 |
MMBench-Video | 1.63 | 1.30 | 1.97 | 1.70 | 2.02 |
LVBench | 30.8 | 33.1 | - | 41.3 | 47.3 |
EgoSchema | 72.2 | 71.2 | - | 77.9 | 76.2 |
PerceptionTest_test | - | - | - | 68.0 | 73.2 |
MLVU_M-Avg_dev | 64.6 | - | 75.7 | 74.6 | |
TempCompass_overall | 73.8 | - | - | 74.8 |
エージェントベンチマーク
ベンチマーク | GPT4o | Gemini 2.0 | Claude | Aguvis-72B | Qwen2VL-72B | Qwen2.5VL-72B |
---|---|---|---|---|---|---|
ScreenSpot | 18.1 | 84.0 | 83.0 | 87.1 | ||
ScreenSpot Pro | 17.1 | 1.6 | 43.6 | |||
AITZ_EM | 35.3 | 72.8 | 83.2 | |||
Android Control High_EM | 66.4 | 59.1 | 67.36 | |||
Android Control Low_EM | 84.4 | 59.2 | 93.7 | |||
AndroidWorld_SR | 34.5% (SoM) | 27.9% | 26.1% | 35% | ||
MobileMiniWob++_SR | 66% | 68% | ||||
OSWorld | 14.90 | 10.26 | 8.83 |
📄 ライセンス
このモデルは、qwen ライセンスの下で提供されています。









