Update handler.py
Browse files- handler.py +0 -22
handler.py
CHANGED
@@ -30,19 +30,10 @@ def mean_pooling(model_output):
|
|
30 |
|
31 |
class EndpointHandler():
|
32 |
def __init__(self, path=""):
|
33 |
-
print("HELLO THIS IS THE CWD:", os.getcwd())
|
34 |
-
print("HELLO THIS IS THE PATH ARG:", path)
|
35 |
-
files = os.listdir(path)
|
36 |
-
for file in files:
|
37 |
-
print(file)
|
38 |
-
# self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
39 |
task = "feature-extraction"
|
40 |
self.tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/msmarco-MiniLM-L-6-v3')
|
41 |
model_regular = ORTModelForFeatureExtraction.from_pretrained("jpohhhh/msmarco-MiniLM-L-6-v3_onnx", from_transformers=False)
|
42 |
-
|
43 |
self.onnx_extractor = pipeline(task, model=model_regular, tokenizer=self.tokenizer)
|
44 |
-
# self.model.to(self.device)
|
45 |
-
# print("model will run on ", self.device)
|
46 |
|
47 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
48 |
"""
|
@@ -52,24 +43,11 @@ class EndpointHandler():
|
|
52 |
Return:
|
53 |
A :obj:`list` | `dict`: will be serialized and returned
|
54 |
"""
|
55 |
-
print("A")
|
56 |
sentences = data.pop("inputs",data)
|
57 |
-
print("B")
|
58 |
sentence_embeddings = []
|
59 |
-
print("C")
|
60 |
for sentence in sentences:
|
61 |
-
print("D")
|
62 |
-
|
63 |
-
|
64 |
# Compute token embeddings
|
65 |
with torch.no_grad():
|
66 |
model_output = self.onnx_extractor(sentence)
|
67 |
-
print("E")
|
68 |
-
|
69 |
-
# Perform pooling. In this case, max pooling.
|
70 |
-
# embedding = mean_pooling(model_output, encoded_input['attention_mask'])
|
71 |
-
print("F")
|
72 |
-
|
73 |
sentence_embeddings.append(mean_pooling(model_output))
|
74 |
-
print("G")
|
75 |
return sentence_embeddings
|
|
|
30 |
|
31 |
class EndpointHandler():
|
32 |
def __init__(self, path=""):
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
task = "feature-extraction"
|
34 |
self.tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/msmarco-MiniLM-L-6-v3')
|
35 |
model_regular = ORTModelForFeatureExtraction.from_pretrained("jpohhhh/msmarco-MiniLM-L-6-v3_onnx", from_transformers=False)
|
|
|
36 |
self.onnx_extractor = pipeline(task, model=model_regular, tokenizer=self.tokenizer)
|
|
|
|
|
37 |
|
38 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
39 |
"""
|
|
|
43 |
Return:
|
44 |
A :obj:`list` | `dict`: will be serialized and returned
|
45 |
"""
|
|
|
46 |
sentences = data.pop("inputs",data)
|
|
|
47 |
sentence_embeddings = []
|
|
|
48 |
for sentence in sentences:
|
|
|
|
|
|
|
49 |
# Compute token embeddings
|
50 |
with torch.no_grad():
|
51 |
model_output = self.onnx_extractor(sentence)
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
sentence_embeddings.append(mean_pooling(model_output))
|
|
|
53 |
return sentence_embeddings
|