使用modelscope推理Qwen/Qwen3-VL-8B-Instruct报错如下信息,官方例子会有这个报错:
ValueError: Image features and image tokens do not match: tokens: 2752, features 2752
调整后的代码:
from modelscope import Qwen3VLForConditionalGeneration, AutoProcessor
from PIL import Image
import torch
# Load the model on GPU for better performance
model = Qwen3VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen3-VL-8B-Instruct",
dtype=torch.bfloat16,
device_map="cuda",
)
processor = AutoProcessor.from_pretrained("Qwen/Qwen3-VL-8B-Instruct")
# 使用官方推荐的消息格式
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
},
{"type": "text", "text": "请介绍下这张图片"},
],
}
]
# 使用apply_chat_template处理输入
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt"
)
# 检查inputs的类型并正确处理
if isinstance(inputs, torch.Tensor):
# 如果inputs是张量,直接移到设备上
inputs = inputs.to(model.device)
# 创建正确的输入字典
inputs_dict = {"input_ids": inputs}
else:
# 如果inputs是字典,正常处理
inputs_dict = {k: v.to(model.device) for k, v in inputs.items()}
# Inference: Generation of the output
generated_ids = model.generate(**inputs_dict, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs_dict["input_ids"], generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)c#中string和StringBuilder直接看看执行速度。(2).String类型累计赋值Test  ...
【一】.钩子文件的设置和创建(1).打开hooks目录,可以看到有一个post-commit.tmpl文件,这是一个模板文件。复制一份,重命名为post-commit,将其用户组设为www,并设置为可执行。chown www:www post-commitchmod +x post-commit(2...
1.全局用户信息设置 git config --global user.name gaojiufeng git config --global user.email 392223903...
在安装之前我们先看看官方给出的依赖关系.首先是dll文件和mongodb软件的依赖关系然后是PHP文件和dll的依赖关系我的是phpstudy的集成环境PHP5.4.45 NTS+Apache+Mysql【一】.安装mongodb3.0软件对比依赖关系下载mongodb3.0.msi软件,完整名称:...
1.远程仓库的协作模式开发者把自己最新的版本推到线上仓库,同时把线上仓库的最新代码,拉到自己本地即可2.注册git帐号国外: http://www.github.com国内: http://git.oschina.net2.在码云创建项目,不要初始化readmegit push https://gi...
git pull https://git.oschina.net/392223903/learn.git master 换为您的git地址...