Open carcloudfly opened 1 month ago
可以分享下出现这个问题的代码以及运行的环境吗
CUDA_AVIBLE_DEVICES=0,1,2,3 python web_demo_mm.py -c ../Qwen2-VL-2B-Instruct/ --server-port 8350 --server-name 0.0.0.0 谢谢,环境是这样的。如果只指定 gpu 0 是可以正常运行的。但是容易爆显存。 requirements_web_demo_locl.txt
不用web demo,用本地脚本,也会出现同样的问题。
你好 请问这个问题解决了嘛? 遇到了相同的问题
你好 请问这个问题解决了嘛? 遇到了相同的问题
我遇到了相同的问题,运行硬件环境为Tesla V100*4,运行指令CUDA_VISIBLE_DEVICES=0,1,2,3 python start.py
。start.py来自readme中的faststart。
具体代码如下:
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
import torch
# default: Load the model on the available device(s)
model = Qwen2VLForConditionalGeneration.from_pretrained(
"/Qwen2-VL-7B-Instruct", torch_dtype=torch.float16, device_map="auto"
)
# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
# model = Qwen2VLForConditionalGeneration.from_pretrained(
# "Qwen/Qwen2-VL-7B-Instruct",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
# device_map="auto",
# )
# default processer
processor = AutoProcessor.from_pretrained("/Qwen2-VL-7B-Instruct")
# The default range for the number of visual tokens per image in the model is 4-16384.
# You can set min_pixels and max_pixels according to your needs, such as a token range of 256-1280, to balance performance and cost.
# min_pixels = 256*28*28
# max_pixels = 1280*28*28
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "/demo.jpeg",
},
{"type": "text", "text": "Describe this image."},
],
}
]
# Preparation for inference
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")
# Inference: Generation of the output
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
解决了吗
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:3 and cuda:0! (when checking argument for argument mask in method wrapper_CUDA__maskedscatter)
请问是什么原因,如何修正?