# 多模态大模型 本框架支持两种自定义多模态评测方式: - **通用问答题格式(General-VQA)**:基于 OpenAI 消息格式,支持多图片/音频输入、系统提示和 base64 编码,适用于问答类多模态评测任务。 - **通用选择题格式(General-VMCQ)**:类似 MMMU 格式,问题文本中可包含图片占位符 ``,适用于选择题类多模态评测任务。 ## 通用问答题格式(General-VQA) ### 1. 数据准备 准备符合 OpenAI 消息格式的数据文件,支持 **JSONL** 或 **TSV** 格式: **JSONL 格式示例** (`example_openai.jsonl`): ```json {"messages": [{"role": "user", "content": [{"type": "text", "text": "What animal is this?"}, {"type": "image_url", "image_url": {"url": "custom_eval/multimodal/images/dog.jpg"}}]}], "answer": "Dog"} {"messages": [{"role": "user", "content": [{"type": "text", "text": "What building is this?"}, {"type": "image_url", "image_url": {"url": "custom_eval/multimodal/images/AMNH.jpg"}}]}], "answer": "Museum"} ``` **TSV 格式示例** (`example_openai.tsv`): ```text messages answer [{"role": "user", "content": [{"type": "text", "text": "What animal is this?"}, {"type": "image_url", "image_url": {"url": "custom_eval/multimodal/images/dog.jpg"}}]}] Dog [{"role": "user", "content": [{"type": "text", "text": "What building is this?"}, {"type": "image_url", "image_url": {"url": "custom_eval/multimodal/images/AMNH.jpg"}}]}] Museum ``` **字段说明**: - `messages`: OpenAI 格式的消息数组,支持: - 文本内容:`{"type": "text", "text": "问题文本"}` - 图片 URL:`{"type": "image_url", "image_url": {"url": "路径或base64"}}` - 音频输入:`{"type": "input_audio", "input_audio": {"data": "路径或base64", "format": "wav"}}` - 视频 URL:`{"type": "video_url", "video_url": {"url": "路径或base64"}}` - 系统消息:`{"role": "system", "content": "系统提示"}` - `answer`: 参考答案(可选,用于计算 BLEU 和 Rouge 分数) **支持的图片格式**: - 本地路径:`"url": "custom_eval/multimodal/images/dog.jpg"` - HTTP URL:`"url": "https://example.com/image.jpg"`(需模型服务侧支持) - Base64 编码:`"url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."` **支持的音频格式**: - 本地路径:`"data": "custom_eval/multimodal/audio/sample.wav"` - Base64 编码:`"data": "data:audio/wav;base64,UklGRiQ..."` - 音频格式(`format` 字段):支持 `"wav"` 和 `"mp3"` **支持的视频格式**: - 本地路径:`"url": "custom_eval/multimodal/videos/sample.mp4"` - HTTP URL:`"url": "https://example.com/video.mp4"`(需模型服务侧支持) - Base64 编码:`"url": "data:video/mp4;base64,AAAAIGZ0eX..."` - 视频格式会从路径、URL 或 data URI 中推断;支持 `"mp4"`、`"mpeg"` 和 `"mov"`。 **多图片输入** 支持在一个问题中使用多张图片: ```json { "messages": [ { "role": "user", "content": [ {"type": "text", "text": "Compare these two images:"}, {"type": "image_url", "image_url": {"url": "image1.jpg"}}, {"type": "text", "text": "and"}, {"type": "image_url", "image_url": {"url": "image2.jpg"}}, {"type": "text", "text": "What are the differences?"} ] } ], "answer": "The main differences are..." } ``` **系统提示** 可以添加系统消息来设置评测上下文: ```json { "messages": [ {"role": "system", "content": "You are a medical AI assistant."}, { "role": "user", "content": [ {"type": "text", "text": "Analyze this X-ray:"}, {"type": "image_url", "image_url": {"url": "xray.jpg", "detail": "high"}} ] } ], "answer": "The X-ray shows..." } ``` **Base64 图片** 支持直接使用 base64 编码的图片: ```json { "messages": [ { "role": "user", "content": [ {"type": "text", "text": "What's in this image?"}, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD..." } } ] } ], "answer": "A beautiful landscape" } ``` **音频输入** 支持音频内容输入,使用 OpenAI `input_audio` 格式,`data` 字段支持本地路径或 base64 编码,`format` 支持 `wav` 和 `mp3`: ```json { "messages": [ { "role": "user", "content": [ {"type": "text", "text": "请描述这段音频的内容。"}, { "type": "input_audio", "input_audio": { "data": "custom_eval/multimodal/audio/sample.wav", "format": "wav" } } ] } ], "answer": "这是一段钢琴演奏的音乐。" } ``` 也可以使用 base64 编码的音频数据: ```json { "messages": [ { "role": "user", "content": [ {"type": "text", "text": "这段音频里说了什么?"}, { "type": "input_audio", "input_audio": { "data": "UklGRiQAAABXQVZFZm10IBAAAA...", "format": "wav" } } ] } ], "answer": "你好,世界。" } ``` **视频输入** 支持视频内容输入,使用 OpenAI-compatible `video_url` 格式,`url` 字段支持本地路径、HTTP URL 或 base64 编码: ```json { "messages": [ { "role": "user", "content": [ {"type": "text", "text": "请描述这段视频的内容。"}, { "type": "video_url", "video_url": { "url": "custom_eval/multimodal/videos/sample.mp4" } } ] } ], "answer": "这是一段短视频。" } ``` ### 2. 配置评测任务 使用 Python API 或 CLI 进行评测: **Python API**: ```python from evalscope.run import run_task from evalscope.config import TaskConfig from os import environ as env task_cfg = TaskConfig( model='qwen-vl-plus', api_url='https://dashscope.aliyuncs.com/compatible-mode/v1', api_key=env.get('DASHSCOPE_API_KEY'), eval_type='openai_api', datasets=['general_vqa'], dataset_args={ 'general_vqa': { 'local_path': 'custom_eval/multimodal/vqa', # 数据集目录 'subset_list': ['example_openai'], # 文件名(不含扩展名) } }, limit=5, # 可选:限制评测样本数 ) result = run_task(task_cfg=task_cfg) ``` **CLI**: ```bash evalscope eval \ --model qwen-vl-plus \ --api-url https://dashscope.aliyuncs.com/compatible-mode/v1 \ --api-key "$DASHSCOPE_API_KEY" \ --eval-type openai_api \ --datasets general_vqa \ --dataset-args '{"general_vqa": {"local_path": "custom_eval/multimodal/vqa", "subset_list": ["example_openai"]}}' \ --limit 5 ``` 评测将输出 BLEU 和 Rouge 指标: ```text +--------------+-------------+----------------+----------------+-------+---------+---------+ | Model | Dataset | Metric | Subset | Num | Score | Cat.0 | +==============+=============+================+================+=======+=========+=========+ | qwen-vl-plus | general_vqa | mean_bleu-1 | example_openai | 5 | 0.0067 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_bleu-2 | example_openai | 5 | 0 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_bleu-3 | example_openai | 5 | 0 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_bleu-4 | example_openai | 5 | 0 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-1-R | example_openai | 5 | 0.4 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-1-P | example_openai | 5 | 0.0062 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-1-F | example_openai | 5 | 0.0121 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-2-R | example_openai | 5 | 0 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-2-P | example_openai | 5 | 0 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-2-F | example_openai | 5 | 0 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-L-R | example_openai | 5 | 0.4 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-L-P | example_openai | 5 | 0.0047 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ | qwen-vl-plus | general_vqa | mean_Rouge-L-F | example_openai | 5 | 0.0093 | default | +--------------+-------------+----------------+----------------+-------+---------+---------+ ``` ### 3. 配置裁判模型 可以通过 `judge_model` 参数指定裁判模型,用于生成参考答案进行评测,将获取准确率指标: ```python from evalscope.run import run_task from evalscope.constants import EvalType, JudgeStrategy from os import environ as env task_cfg = TaskConfig( model='qwen-vl-plus', api_url='https://dashscope.aliyuncs.com/compatible-mode/v1', api_key=env.get('DASHSCOPE_API_KEY'), eval_type='openai_api', datasets=['general_vqa'], dataset_args={ 'general_vqa': { 'local_path': 'custom_eval/multimodal/vqa', 'subset_list': ['example_openai'], } }, limit=5, judge_model_args={ 'model_id': 'qwen-plus', # 无需是多模态模型 'api_url': 'https://dashscope.aliyuncs.com/compatible-mode/v1', 'api_key': env.get('DASHSCOPE_API_KEY'), 'generation_config': { 'temperature': 0.0, 'max_tokens': 4096 }, }, eval_batch_size=5, judge_strategy=JudgeStrategy.LLM, ) result = run_task(task_cfg=task_cfg) ``` **CLI**(等效配置): ```bash evalscope eval \ --model qwen-vl-plus \ --api-url https://dashscope.aliyuncs.com/compatible-mode/v1 \ --api-key "$DASHSCOPE_API_KEY" \ --eval-type openai_api \ --datasets general_vqa \ --dataset-args '{"general_vqa": {"local_path": "custom_eval/multimodal/vqa", "subset_list": ["example_openai"]}}' \ --limit 5 \ --judge-model-args '{"model_id": "qwen-plus", "api_url": "https://dashscope.aliyuncs.com/compatible-mode/v1", "api_key": "$DASHSCOPE_API_KEY", "generation_config": {"temperature": 0.0, "max_tokens": 4096}}' \ --judge-worker-num 5 \ --judge-strategy llm ``` 评测将输出准确率指标(输出指标较ROUGE和BLEU更直观): ```text +--------------+-------------+----------+----------------+-------+---------+---------+ | Model | Dataset | Metric | Subset | Num | Score | Cat.0 | +==============+=============+==========+================+=======+=========+=========+ | qwen-vl-plus | general_vqa | mean_acc | example_openai | 5 | 1 | default | +--------------+-------------+----------+----------------+-------+---------+---------+ ``` ## 通用选择题格式(General-VMCQ) ### 1. 数据准备 General-VMCQ 采用与 MMMU 相似的结构:问题文本中可包含图片占位符 `` 和视频占位符 `