QwenLM/Qwen-VL

[BUG] <多样本推理,只有第一次的结果合理>

xinghedyc opened this issue · 1 comments

是否已有关于该错误的issue或讨论? | Is there an existing issue / discussion for this?

  • 我已经搜索过已有的issues和讨论 | I have searched the existing issues / discussions

该问题是否在FAQ中有解答? | Is there an existing answer for this in FAQ?

  • 我已经搜索过FAQ | I have searched FAQ

当前行为 | Current Behavior

使用modelscope进行for循环多样本推理(debug时用的同一张图片),但是只有第一次的预测结果是合理的,后续的结果均不合理。

model_dir = snapshot_download('qwen/Qwen-VL-Chat', cache_dir="/data/model_cache")

tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="cuda", trust_remote_code=True, fp16=True).eval()
model.generation_config = GenerationConfig.from_pretrained(model_dir, trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参
for idx in range(10):
    image_path = "40.jpg" 
    inp = f'<img>{image_path}</img>描述图片'
    response, history = model.chat(tokenizer, query=inp, history=None)

期望行为 | Expected Behavior

通过history=None来实现多样本推理,每个样本之间是独立的。

复现方法 | Steps To Reproduce

No response

运行环境 | Environment

- OS: Ubuntu 20.04
- Python: 3.9
- Transformers: 4.37.2
- PyTorch:2.2
- CUDA (`python -c 'import torch; print(torch.version.cuda)'`): 12.1

备注 | Anything else?

想要推理一批图片,应该怎么做?

response, history = model.chat(tokenizer, query=inp, history=None)中的inp应该不能只是单纯的图片路径吧,我看给的示例中是这样的:

query = tokenizer.from_list_format([
    {'image': 'https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg'},
    {'text': '这是什么'},
])