Deepakvictor
commited on
Commit
•
d3f59c0
1
Parent(s):
efc6f35
Update handler.py
Browse files- handler.py +4 -7
handler.py
CHANGED
@@ -3,16 +3,13 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
3 |
import torch
|
4 |
from handler import EndpointHandler
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
self.
|
10 |
-
self.model = AutoModelForSeq2SeqLM.from_pretrained(path).to(device))
|
11 |
|
12 |
def __call__(self, data: str) -> str:
|
13 |
inp = self.tokenizer(data, return_tensors="pt")
|
14 |
-
for q in inp:
|
15 |
-
inp[q] = inp[q].to(device)
|
16 |
with torch.inference_mode():
|
17 |
out= self.model.generate(**inp)
|
18 |
final_output = self.tokenizer.batch_decode(out,skip_special_tokens=True)
|
|
|
3 |
import torch
|
4 |
from handler import EndpointHandler
|
5 |
|
6 |
+
class EndpointHandler():
|
7 |
+
def __init__(self, path=""):
|
8 |
+
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
9 |
+
self.model = AutoModelForSeq2SeqLM.from_pretrained(path)
|
|
|
10 |
|
11 |
def __call__(self, data: str) -> str:
|
12 |
inp = self.tokenizer(data, return_tensors="pt")
|
|
|
|
|
13 |
with torch.inference_mode():
|
14 |
out= self.model.generate(**inp)
|
15 |
final_output = self.tokenizer.batch_decode(out,skip_special_tokens=True)
|