We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CUDA 12.2 transformers 4.44.0 python 3.10.2 torch 2.0.0+cu118
No response
在官方的——快速调用 GLM-4V-9B 多模态模型-使用 transformers 后端进行推理代码的基础上。将gen_kwargs修改为 gen_kwargs= {"do_sample": False, "top_p": None, "temperature": None}。 程序每次处理5张图片,得到5张图片的内容描述。代码如下: from transformers import AutoTokenizer, AutoModelForCausalLM os.environ['CUDA_VISIBLE_DEVICES']='1' device = "cuda" if torch.cuda.is_available() else "cpu" glm4vtokenizer = AutoTokenizer.from_pretrained("glm-4v-9b", trust_remote_code=True)
glm4vmodel = AutoModelForCausalLM.from_pretrained( "glm-4v-9b", torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, trust_remote_code=True, device_map="auto" ).eval()
for imagepath in imagepaths: image = Image.open(imagepath).convert("RGB") message1 = [{"role": "user", "image": image, "content": "请描述这张图片的内容"}] inputs = glm4vtokenizer.apply_chat_template(message1, add_generation_prompt=True, tokenize=True,return_tensors="pt", return_dict=True) # chat mode inputs = inputs.to(device) gen_kwargs = {"do_sample": False,"top_p":None,"temperature":None} with torch.no_grad(): outputs = glm4vmodel.generate(**inputs, **gen_kwargs) outputs = outputs[:, inputs['input_ids'].shape[1]:] response1 = glm4vtokenizer.decode(outputs[0], skip_special_tokens=True) print(response1)
程序每次总共会处理5张图片,希望每一次跑程序,得到的5张图片的内容描述都是相同的。
The text was updated successfully, but these errors were encountered:
我在根据你的代码复现时对于同一张图片每次输出都是一样的,另外没太懂程序每次总共会处理5张图片啥意思,每次只能处理一张图片
Sorry, something went wrong.
zhipuch
No branches or pull requests
System Info / 系統信息
CUDA 12.2
transformers 4.44.0
python 3.10.2
torch 2.0.0+cu118
Who can help? / 谁可以帮助到您?
No response
Information / 问题信息
Reproduction / 复现过程
在官方的——快速调用 GLM-4V-9B 多模态模型-使用 transformers 后端进行推理代码的基础上。将gen_kwargs修改为 gen_kwargs= {"do_sample": False, "top_p": None, "temperature": None}。
程序每次处理5张图片,得到5张图片的内容描述。代码如下:
from transformers import AutoTokenizer, AutoModelForCausalLM
os.environ['CUDA_VISIBLE_DEVICES']='1'
device = "cuda" if torch.cuda.is_available() else "cpu"
glm4vtokenizer = AutoTokenizer.from_pretrained("glm-4v-9b", trust_remote_code=True)
glm4vmodel = AutoModelForCausalLM.from_pretrained(
"glm-4v-9b",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True,
device_map="auto"
).eval()
for imagepath in imagepaths:
image = Image.open(imagepath).convert("RGB")
message1 = [{"role": "user", "image": image, "content": "请描述这张图片的内容"}]
inputs = glm4vtokenizer.apply_chat_template(message1, add_generation_prompt=True, tokenize=True,return_tensors="pt", return_dict=True) # chat mode
inputs = inputs.to(device)
gen_kwargs = {"do_sample": False,"top_p":None,"temperature":None}
with torch.no_grad():
outputs = glm4vmodel.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs['input_ids'].shape[1]:]
response1 = glm4vtokenizer.decode(outputs[0], skip_special_tokens=True)
print(response1)
Expected behavior / 期待表现
程序每次总共会处理5张图片,希望每一次跑程序,得到的5张图片的内容描述都是相同的。
The text was updated successfully, but these errors were encountered: