alvarobartt HF staff commited on
Commit
06eb103
·
verified ·
1 Parent(s): c58f49f

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +10 -11
handler.py CHANGED
@@ -89,18 +89,17 @@ class EndpointHandler:
89
  prompt = self.processor.apply_chat_template(
90
  messages, add_generation_prompt=True
91
  )
 
 
 
92
 
93
- with torch.no_grad(), torch.autocast("cuda"):
94
- processed_inputs = self.processor(
95
- text=prompt, images=images, return_tensors="pt"
96
- )
97
- generated_ids = self.model.generate(
98
- **processed_inputs, generation_config=generation_config
99
- )
100
- generated_texts = self.processor.batch_decode(
101
- generated_ids,
102
- skip_special_tokens=True,
103
- )
104
  predictions.append(generated_texts[0])
105
 
106
  return {"predictions": predictions}
 
89
  prompt = self.processor.apply_chat_template(
90
  messages, add_generation_prompt=True
91
  )
92
+ processed_inputs = self.processor(
93
+ text=prompt, images=images, return_tensors="pt"
94
+ ).to(self.model.device)
95
 
96
+ generated_ids = self.model.generate(
97
+ **processed_inputs, generation_config=generation_config
98
+ )
99
+ generated_texts = self.processor.batch_decode(
100
+ generated_ids,
101
+ skip_special_tokens=True,
102
+ )
 
 
 
 
103
  predictions.append(generated_texts[0])
104
 
105
  return {"predictions": predictions}