-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Almost finished the third hw3 (perf analysis is light)
- Loading branch information
1 parent
faf0f1d
commit 6bbaccd
Showing
11 changed files
with
721 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[core] | ||
analytics = false | ||
remote = storage | ||
autostage = true | ||
['remote "storage"'] | ||
url = gdrive://1fCTKCtocuLIhDQ5OaL8lQKtI8fPcBVFZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM nvcr.io/nvidia/tritonserver:23.12-py3 | ||
|
||
COPY requirements.txt . | ||
RUN pip3 install -r requirements.txt --ignore-installed | ||
RUN git clone https://github.com/TopCoder2K/mlops-course.git | ||
|
||
# ENTRYPOINT ["cd", "mlops-course", "&&", "tritonserver", "--model-repository", "/models", "--log-info", "1"] | ||
ENTRYPOINT ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/catboost.p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
outs: | ||
- md5: 02c2243ee7ebf7a4c7f03203a2a76102 | ||
size: 2903484 | ||
hash: md5 | ||
path: catboost.p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import numpy as np | ||
from tritonclient.http import InferenceServerClient, InferInput, InferRequestedOutput | ||
from tritonclient.utils import np_to_triton_dtype | ||
|
||
|
||
def test_catboost_with_triton(): | ||
example = { | ||
"season": "spring".encode("utf-8"), | ||
"month": 1, | ||
"hour": 0, | ||
"holiday": 0, | ||
"weekday": 6, | ||
"workingday": 0, | ||
"weather": "clear".encode("utf-8"), | ||
"temp": 9.84, | ||
"feel_temp": 14.395, | ||
"humidity": 0.81, | ||
"windspeed": 0.0, | ||
} # This is the first row of the training split | ||
input_example = list() | ||
for k, v in example.items(): | ||
if k in ["temp", "feel_temp", "humidity", "windspeed"]: | ||
v = np.array( | ||
[ | ||
v, | ||
], | ||
dtype=np.float32, | ||
).reshape(-1, 1) | ||
elif k in ["month", "hour", "holiday", "weekday", "workingday"]: | ||
v = np.array( | ||
[ | ||
v, | ||
], | ||
dtype=np.int32, | ||
).reshape(-1, 1) | ||
else: | ||
v = np.array( | ||
[ | ||
v, | ||
] | ||
).reshape(-1, 1) | ||
input_example.append( | ||
InferInput( | ||
name=k, shape=[1, 1], datatype=np_to_triton_dtype(v.dtype) | ||
).set_data_from_numpy(v) | ||
) | ||
|
||
client = InferenceServerClient(url="localhost:8000") | ||
result = client.infer( | ||
"catboost", | ||
input_example, | ||
outputs=[ | ||
InferRequestedOutput("prediction"), | ||
], | ||
) | ||
expected_pred = 31.22848957148021 # Is taken from the mlflow inference result | ||
assert ( | ||
expected_pred == result.as_numpy("prediction")[0] | ||
), "Something is wrong with the inference :((" | ||
print("Predicted:", result.as_numpy("prediction")[0]) | ||
print("The test is passed!") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_catboost_with_triton() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import pickle | ||
from typing import Any, List | ||
|
||
import c_python_backend_utils as c_utils | ||
import numpy as np | ||
import pandas as pd | ||
import triton_python_backend_utils as pb_utils | ||
|
||
|
||
class TritonPythonModel: | ||
def initialize(self, args): | ||
with open(f"/assets/{args['model_name']}.p", "rb") as f: | ||
self.model = pickle.load(f) | ||
|
||
@staticmethod | ||
def get_from_request_by_name(request: c_utils.InferenceRequest, name: str) -> Any: | ||
return pb_utils.get_input_tensor_by_name(request, name).as_numpy().tolist()[0] | ||
|
||
def execute( | ||
self, requests: List[c_utils.InferenceRequest] | ||
) -> List[c_utils.InferenceResponse]: | ||
reqs = list() | ||
for request in requests: | ||
reqs.append( | ||
{ | ||
"season": TritonPythonModel.get_from_request_by_name( | ||
request, "season" | ||
)[0].decode(), | ||
"weather": TritonPythonModel.get_from_request_by_name( | ||
request, "weather" | ||
)[0].decode(), | ||
"month": TritonPythonModel.get_from_request_by_name(request, "month")[ | ||
0 | ||
], | ||
"hour": TritonPythonModel.get_from_request_by_name(request, "hour")[ | ||
0 | ||
], | ||
"holiday": TritonPythonModel.get_from_request_by_name( | ||
request, "holiday" | ||
)[0], | ||
"weekday": TritonPythonModel.get_from_request_by_name( | ||
request, "weekday" | ||
)[0], | ||
"workingday": TritonPythonModel.get_from_request_by_name( | ||
request, "workingday" | ||
)[0], | ||
"temp": TritonPythonModel.get_from_request_by_name(request, "temp")[ | ||
0 | ||
], | ||
"feel_temp": TritonPythonModel.get_from_request_by_name( | ||
request, "feel_temp" | ||
)[0], | ||
"humidity": TritonPythonModel.get_from_request_by_name( | ||
request, "humidity" | ||
)[0], | ||
"windspeed": TritonPythonModel.get_from_request_by_name( | ||
request, "windspeed" | ||
)[0], | ||
} | ||
) | ||
preds = self.model(pd.DataFrame(reqs)) | ||
|
||
responses = list() | ||
for pred in preds: | ||
responses.append( | ||
c_utils.InferenceResponse( | ||
output_tensors=[ | ||
c_utils.Tensor("prediction", np.array(pred).reshape(1)) | ||
] | ||
) | ||
) | ||
return responses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: "catboost" | ||
backend: "python" | ||
max_batch_size: 1024 | ||
|
||
input [ | ||
{ | ||
name: "season" | ||
data_type: TYPE_STRING | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "weather" | ||
data_type: TYPE_STRING | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "month" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "hour" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "holiday" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "weekday" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "workingday" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "temp" | ||
data_type: TYPE_FP32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "feel_temp" | ||
data_type: TYPE_FP32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "humidity" | ||
data_type: TYPE_FP32 | ||
dims: [ 1 ] | ||
}, | ||
{ | ||
name: "windspeed" | ||
data_type: TYPE_FP32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
output [ | ||
{ | ||
name: "prediction" | ||
data_type: TYPE_FP32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
instance_group [ | ||
{ | ||
count: 1 | ||
kind: KIND_CPU | ||
} | ||
] | ||
|
||
dynamic_batching: { max_queue_delay_microseconds: 500 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
catboost==1.2.2 | ||
mlflow==2.8.1 | ||
omegaconf==2.3.0 |
Oops, something went wrong.