QwenLM / Qwen2-VL

Qwen2-VL is the multimodal large language model series developed by Qwen team, Alibaba Cloud.
Apache License 2.0
2.99k stars 175 forks source link

进行视频理解时出现,RuntimeError: probability tensor contains either `inf`, `nan` or element < 0 #195

Open gavinzhang1995 opened 1 month ago

gavinzhang1995 commented 1 month ago

你好,我的推理代码如下


from PIL import Image
import torch
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
from modelscope import snapshot_download

model_dir = "/data/modelscope/hub/qwen/Qwen2-VL-2B-Instruct"
model = Qwen2VLForConditionalGeneration.from_pretrained(model_dir, device_map="cuda", torch_dtype = torch.float16)
min_pixels = 256*28*28
max_pixels = 1280*28*28
processor = AutoProcessor.from_pretrained(model_dir, min_pixels=min_pixels, max_pixels=max_pixels)

messages = [{"role": "user", "content": [{"type": "video", "video": "15633382782.mp4", 'max_pixels': 360*420, 'fps': 1.0}, {"type": "text", "text": "描述这个视频."}]}]

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 = model.generate(**inputs, max_new_tokens=128)就报错
RuntimeError: probability tensor contains either `inf`, `nan` or element < 0

这是什么原因
linchen111 commented 1 month ago

+1 , 我的偶尔会出错

gavinzhang1995 commented 1 month ago

这是来自QQ邮箱的自动回复邮件。   您好,您的邮件我已收到。我将尽快给您回复。张伟