Skip to content

Commit

Permalink
Fix cuda issue (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahules786 authored Apr 12, 2023
1 parent 60353ed commit 4d7ddc3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions blade2blade/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ def preprocess(
# Generated responses should contain them already.
inputs.append("<|assistant|>" + text + self.tokenizer.eos_token)

input_ids, attn_mask = self.tokenizer(
"".join(inputs),
padding="max_length",
truncation=True,
).values()
input_ids, attn_mask = (
self.tokenizer(
"".join(inputs),
padding="max_length",
truncation=True,
return_tensors="pt",
)
.to(self.device)
.values()
)

input_ids = torch.tensor([input_ids])
attn_mask = torch.tensor([attn_mask])
return {
"input_ids": input_ids,
"attention_mask": attn_mask,
Expand Down Expand Up @@ -81,7 +84,7 @@ def predict(self, prompt: str, **kwargs):
padding="max_length",
truncation=True,
return_tensors="pt",
)
).to(self.device)

output = self.model.generate(**inputs, **kwargs).detach().cpu().numpy()[0]
output = self.tokenizer.convert_tokens_to_string(
Expand Down

0 comments on commit 4d7ddc3

Please sign in to comment.