Skip to content
New issue

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

使用GLM-4V-9B的时候,尽管设置了gen_kwargs = {"do_sample": False,"top_p":None,"temperature":None},但每次结果还是不一样 #654

Open
1 of 2 tasks
nwym126 opened this issue Nov 16, 2024 · 1 comment
Assignees

Comments

@nwym126
Copy link

nwym126 commented Nov 16, 2024

System Info / 系統信息

CUDA 12.2
transformers 4.44.0
python 3.10.2
torch 2.0.0+cu118

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

  • The official example scripts / 官方的示例脚本
  • My own modified scripts / 我自己修改的脚本和任务

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张图片的内容描述都是相同的。

@zhipuch zhipuch self-assigned this Nov 18, 2024
@zhipuch
Copy link
Collaborator

zhipuch commented Nov 18, 2024

我在根据你的代码复现时对于同一张图片每次输出都是一样的,另外没太懂程序每次总共会处理5张图片啥意思,每次只能处理一张图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants