VLM_评判打分
更新时间:2026-07-29
简介
VLMJudgeScorer 以 VLM-as-Judge 方式(默认 Qwen2.5-VL-7B-Instruct 顶替 Gemma),对「媒体 + 候选描述」在 Faithfulness / Completeness / Correctness 三个维度各打 1-5 分。
功能描述
• 接收两个输入列:媒体(视频或图像)与 caption(StructuredCaptionPipeline 输出的 JSON 字符串或任意文本描述)。
• 通过评审 prompt 引导模型只输出一行 JSON(字段 faith / complete / correct),并用正则解析裁剪到 0-5 整数。
• 双后端推理:vLLM(默认)与 transformers 兜底,backend="auto" 时在 sm_120 新卡自动回退 transformers。
• 必须运行在 CUDA GPU 上,权重需预置于 {model_path}/{model_name};解析失败或出错时三项分数全为 0。
算子参数
输入
| 输入 | 含义 |
|---|---|
| contents | 媒体输入列,视频或图像(URL / base64 / 二进制),形式由 content_src_type 决定 |
| captions | 候选描述列,StructuredCaptionPipeline 输出的 JSON 字符串或任意文本 caption |
输出
| 输出 | 含义 |
|---|---|
| result | 评分结果,类型 struct{faith: int8, complete: int8, correct: int8},各维度取值 1-5;解析失败或出错时全为 0 |
参数
| 参数名称 | 类型 | 默认值 | 描述 | |
|---|---|---|---|---|
| content_src_type | str | "video_url" | 媒体输入类型,视频/图像各三种:video_url / video_base64 / video_binary / image_url / image_base64 / image_binary |
|
| model_path | str | "/opt/aihc/models" | 权重根目录,实际模型目录为 {model_path}/{model_name} |
|
| model_name | str | "Qwen/Qwen2.5-VL-7B-Instruct" | 评审模型名称/子目录 | |
| batch_size | int | 2 | 单批推理量 | |
| dtype | str | "auto" | 计算精度,可选 "auto" / "bfloat16" / "float16" / "float32" |
|
| max_model_len | int | 16000 | 最大上下文长度 | |
| max_pixels | int |None | 1280000 | 视觉输入像素上限 | |
| fps | float |None | 1.0 | 视频抽帧帧率 | |
| tensor_parallel_size | int | 1 | 张量并行度,仅 vLLM 后端生效 | |
| gpu_memory_utilization | float | 0.85 | GPU 显存利用率,仅 vLLM 后端生效 | |
| enforce_eager | bool | False | 是否强制 eager 模式,仅 vLLM 后端生效 | |
| temperature | float | 0.0 | 采样温度(评审默认贪心) | |
| top_p | float | 0.95 | nucleus 采样 top-p | |
| max_tokens | int | 128 | 单次生成最大 token 数 | |
| seed | int | 42 | 采样随机种子 | |
| backend | str | "auto" | 推理后端,可选 "auto" / "vllm" / "transformers";sm_120 自动走 transformers |
|
| fail_on_error | bool | False | 出错时是否抛异常;False 时对应行返回全 0 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.multimodal.vlm_judge_scorer import VLMJudgeScorer
10
11os.environ.setdefault("BOS_ENDPOINT", "http://bj.bcebos.com")
12os.environ.setdefault("BOS_REGION", "bj")
13
14MODEL_PATH = "/opt/aihc/models" # MOCK
15
16if __name__ == "__main__":
17 if os.getenv("DAFT_RUNNER", "native") == "ray":
18 import ray
19
20 ray.init(ignore_reinit_error=True)
21 daft.set_runner_ray()
22 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
23
24 samples = {
25 "video": ["bos://your-bucket/sample.mp4"], # MOCK
26 "caption": ["A person is demonstrating an action in the video."],
27 }
28 ds = daft.from_pydict(samples)
29 ds = ds.with_column(
30 "judge",
31 aihc_udf(
32 VLMJudgeScorer,
33 construct_args={
34 "content_src_type": "video_url",
35 "model_path": MODEL_PATH,
36 "model_name": "Qwen/Qwen2.5-VL-7B-Instruct",
37 "fps": 1.0,
38 "backend": "auto",
39 },
40 num_cpus=1,
41 num_gpus=1,
42 concurrency=1,
43 batch_size=1,
44 )(col("video"), col("caption")),
45 )
46 ds.show()
评价此篇文章
