Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JinBridger committed Jun 21, 2024
1 parent 962d784 commit 0373589
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
args = parser.parse_args()
model_path = args.repo_id_or_model_path
image_path = args.image_url_or_path
device = "cpu"

# Load model in 4 bit,
# which convert the relevant layers in the model into INT4 format
Expand All @@ -57,12 +56,14 @@
image = Image.open(image_path)
else:
image = Image.open(requests.get(image_path, stream=True).raw)

# here the prompt tuning refers to https://huggingface.co/THUDM/glm-4v-9b/blob/main/README.md
inputs = tokenizer.apply_chat_template([{"role": "user", "image": image, "content": query}],
add_generation_prompt=True,
tokenize=True,
return_tensors="pt",
return_dict=True) # chat mode
inputs = inputs.to(device)
inputs = inputs.to('cpu')

# Generate predicted tokens
with torch.inference_mode():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
args = parser.parse_args()
model_path = args.repo_id_or_model_path
image_path = args.image_url_or_path
device = "xpu"

# Load model in 4 bit,
# which convert the relevant layers in the model into INT4 format
Expand All @@ -59,12 +58,14 @@
image = Image.open(image_path)
else:
image = Image.open(requests.get(image_path, stream=True).raw)

# here the prompt tuning refers to https://huggingface.co/THUDM/glm-4v-9b/blob/main/README.md
inputs = tokenizer.apply_chat_template([{"role": "user", "image": image, "content": query}],
add_generation_prompt=True,
tokenize=True,
return_tensors="pt",
return_dict=True) # chat mode
inputs = inputs.to(device)
inputs = inputs.to('xpu')


# Generate predicted tokens
Expand Down

0 comments on commit 0373589

Please sign in to comment.