Spaces:
Sleeping
Sleeping
Lokesh Jirati commited on
Commit ·
814fe95
1
Parent(s): d252c5e
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ----------- Triton Model Code Starts Below -------------
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import triton_python_backend_utils as pb_utils
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
class TritonPythonModel:
|
| 8 |
+
def initialize(self, args):
|
| 9 |
+
self.model_config = model_config = json.loads(args["model_config"])
|
| 10 |
+
|
| 11 |
+
output0_config = pb_utils.get_output_config_by_name(model_config, "OUTPUT0")
|
| 12 |
+
output1_config = pb_utils.get_output_config_by_name(model_config, "OUTPUT1")
|
| 13 |
+
|
| 14 |
+
self.output0_dtype = pb_utils.triton_string_to_numpy(output0_config["data_type"])
|
| 15 |
+
self.output1_dtype = pb_utils.triton_string_to_numpy(output1_config["data_type"])
|
| 16 |
+
|
| 17 |
+
def execute(self, requests):
|
| 18 |
+
output0_dtype = self.output0_dtype
|
| 19 |
+
output1_dtype = self.output1_dtype
|
| 20 |
+
responses = []
|
| 21 |
+
|
| 22 |
+
for request in requests:
|
| 23 |
+
in_0 = pb_utils.get_input_tensor_by_name(request, "INPUT0")
|
| 24 |
+
in_1 = pb_utils.get_input_tensor_by_name(request, "INPUT1")
|
| 25 |
+
|
| 26 |
+
out_0 = in_0.as_numpy() + in_1.as_numpy()
|
| 27 |
+
out_1 = in_0.as_numpy() - in_1.as_numpy()
|
| 28 |
+
|
| 29 |
+
out_tensor_0 = pb_utils.Tensor("OUTPUT0", out_0.astype(output0_dtype))
|
| 30 |
+
out_tensor_1 = pb_utils.Tensor("OUTPUT1", out_1.astype(output1_dtype))
|
| 31 |
+
|
| 32 |
+
inference_response = pb_utils.InferenceResponse(
|
| 33 |
+
output_tensors=[out_tensor_0, out_tensor_1]
|
| 34 |
+
)
|
| 35 |
+
responses.append(inference_response)
|
| 36 |
+
|
| 37 |
+
return responses
|
| 38 |
+
|
| 39 |
+
def finalize(self):
|
| 40 |
+
print("Cleaning up...")
|