dwb2023 commited on
Commit
1365247
·
verified ·
1 Parent(s): 719c202

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +2 -1
inference.py CHANGED
@@ -19,10 +19,11 @@ class PaliGemmaModel:
19
  def infer(self, image: PIL.Image.Image, text: str, max_new_tokens: int) -> str:
20
  inputs = self.processor(text=text, images=image, return_tensors="pt").to(self.device)
21
  with torch.inference_mode():
 
22
  generated_ids = self.model.generate(
23
  **inputs,
24
  max_new_tokens=max_new_tokens,
25
  do_sample=False
26
  )
27
  result = self.processor.batch_decode(generated_ids, skip_special_tokens=True)
28
- return result[0][len(text):].lstrip("\n")
 
19
  def infer(self, image: PIL.Image.Image, text: str, max_new_tokens: int) -> str:
20
  inputs = self.processor(text=text, images=image, return_tensors="pt").to(self.device)
21
  with torch.inference_mode():
22
+ inputs = {k: v.to(self.device) for k, v in inputs.items()}
23
  generated_ids = self.model.generate(
24
  **inputs,
25
  max_new_tokens=max_new_tokens,
26
  do_sample=False
27
  )
28
  result = self.processor.batch_decode(generated_ids, skip_special_tokens=True)
29
+ return result[0][len(text):].lstrip("\n")