题库 人工智能大模型 题目列表 Qwen2.5-VL 是多模态⼤语⾔模型(Vision-Language Mod...
组合题

Qwen2.5-VL 是多模态⼤语⾔模型(Vision-Language Model, VLM),能够同时处理图像与⽂本输 ⼊,实现图⽂问答与视觉描述等任务。以下代码演⽰了使⽤ Qwen2.5-VL-7B-Instruct 模型,对输⼊图 像进⾏分析并⽣成⽂本回答。请阅读以下代码,并根据描述完成空缺部分。

import torch
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
from PIL import Image
model_name = "Qwen/Qwen2.5-VL-7B-Instruct"
# 1) 加载处理器与模型
processor = ____[1]____
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
    model_name,
    device_map="auto",
    torch_dtype=torch.bfloat16,
    trust_remote_code=True
)
    # 2) 读取输⼊图像
    image = ____[2]____
    # 3) 构建多模态输⼊提⽰
    messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": image},
            {"type": "text", "text": "请描述图⽚中的主要内容。"}
        ]
    }
]
text = ____[3]____
inputs = processor(text=[text], images=[image],
return_tensors="pt").to(model.device)
# 4) 模型推理⽣成回答
model = model.eval()
with ____[4]____:
    output_ids = model.generate(
        **inputs,
        max_new_tokens=128,
        temperature=0.7,
    )
    generated_ids = ____[5]____
    answer = processor.tokenizer.batch_decode(generated_ids,
skip_special_tokens=True)[0]
    print("模型回答:", answer)
第1题 单选
Qwen2.5-VL 模型依赖⾃定义多模态处理逻辑,需启⽤ remote code。请选择⼀种能正确加载该 模型处理器的⽅式:
A.
AutoProcessor.from_pretrained(model_name)
B.
AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
C.
AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
D.
Qwen2_5_VLProcessor.from_pretrained(model_name)
第2题 单选
输⼊图像应以 PIL.Image 对象的 RGB 格式提供给 processor。请选择正确的实现⽅式:
A.
Image.open("image.jpg").convert("RGB")
B.
cv2.cvtColor(cv2.imread("image.jpg"), cv2.COLOR_BGR2RGB)
C.
np.array(Image.open("image.jpg").convert("RGB"))
D.
transforms.ToTensor()(Image.open("image.jpg").convert("RGB"))
第3题 单选
对于对话式多模态模型,需要使⽤ chat template 格式化输⼊。请选择正确的实现⽅式:
A.
processor.format_messages(messages)
B.
processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
C.
processor.tokenize(messages, add_special_tokens=True)
D.
json.dumps(messages)
第4题 单选
推理时应使⽤专⽤上下⽂管理器以禁⽤梯度计算并优化性能。请选择最适合推理的⽅式:
A.
torch.enable_grad(False)
B.
torch.set_grad_enabled(False)
C.
torch.autograd.set_detect_anomaly(False)
D.
torch.inference_mode()
第5题 单选
模型输出包含输⼊和⽣成部分,需要提取仅新⽣成的 token。请选择正确的实现⽅式:
A.
output_ids[inputs['input_ids'].shape[0]:]
B.
output_ids.squeeze()
C.
output_ids[:, inputs['input_ids'].shape[1]:]
D.
output_ids[:, -128:]
题目信息
青少年组 第一轮 2025年 编程题
-
正确率
0
评论
24
点击