-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice_multi_model.py
48 lines (41 loc) · 1.23 KB
/
service_multi_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import bentoml
import numpy as np
import numpy.typing as npt
from bentoml.models import BentoModel
from common import MyInputParams, my_image
@bentoml.service(
image=my_image,
resources={"cpu": "2"},
traffic={"timeout": 10},
)
class IrisClassifier:
bento_model_1 = BentoModel("iris:v1")
bento_model_2 = BentoModel("iris:v2")
def __init__(self):
self.model_1 = bentoml.mlflow.load_model(self.bento_model_1)
self.model_2 = bentoml.mlflow.load_model(self.bento_model_2)
@bentoml.api(route="/v1/predict", input_spec=MyInputParams)
def predict_1(
self,
input_data,
client_id,
) -> np.ndarray:
rv = self.model_1.predict(input_data)
return np.asarray(rv)
@bentoml.api(route="/v2/predict", input_spec=MyInputParams)
def predict_2(
self,
input_data,
client_id,
) -> np.ndarray:
rv = self.model_2.predict(input_data)
return np.asarray(rv)
@bentoml.api(input_spec=MyInputParams)
def predict_combined(
self,
input_data,
client_id,
) -> np.ndarray:
rv_a = self.model_1.predict(input_data)
rv_b = self.model_2.predict(input_data)
return np.asarray([rv_a, rv_b])