开发者社区 > 大数据与机器学习 > 正文

求助transformers库的大模型BLIP2的程序错误是怎么回事?

程序源码如下:
from transformers import Blip2ForConditionalGeneration, AutoTokenizer, AutoProcessor
model_name='model/Salesforce_blip2-opt-2.7b'
model = Blip2ForConditionalGeneration.from_pretrained(model_name)
processor = AutoProcessor.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
model.eval()

# 评估循环
for batch in dataloader:
    images, reports, _ = batch
    images = images.to(device)

    # 使用processor处理输入
    inputs = processor(images=images, text=reports, padding=True, truncation=True, return_tensors="pt").to(device)

    # 前向传播
    with torch.no_grad():
        outputs = model.generate(**inputs)

以上程序执行后错误如下:
outputs = model.generate(**inputs)
File "D:\anaconda3\envs\llava\lib\site-packages\peft\peft_model.py", line 647, in generate
return self.get_base_model().generate(args, **kwargs)
File "D:\anaconda3\envs\llava\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(
args, **kwargs)
File "D:\anaconda3\envs\llava\lib\site-packages\transformers\models\blip_2\modeling_blip_2.py", line 2316, in generate
inputs_embeds[special_image_mask] = language_model_inputs.flatten()
RuntimeError: shape mismatch: value tensor of shape [2621440] cannot be broadcast to indexing result of shape [0]

哪位大牛能给解释一下这是怎么回事呀?谢谢!

展开
收起
游客ijsp4ghgv6ufc 2024-12-12 21:00:59 18 0
0 条回答
写回答
取消 提交回答

大数据领域前沿技术分享与交流,这里不止有技术干货、学习心得、企业实践、社区活动,还有未来。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载