YoungHun Jo
05/19/2024, 9:10 AMbentoml.mlflow.import_model (docs) and I checked the trained model in bento-ml model store file system(/users/zedd/bentoml/models path)
But, I tried to serve the trained model using bento-ml with Service object following tutorial code. my code is below.
# main.py
import numpy as np
import bentoml
from bentoml.io import NumpyNdarray
#
path = "/Users/zedd/home-mlops/mlruns/283184337928820717/0d83b6bdeea44e34b74f70f821aa239a/artifacts/iris_model"
# `bentoml._internal.models.model.Model` object
iris_clf_runner = bentoml.mlflow.import_model(
name="zedd-iris-clf-in-mlflow",
model_uri=path
)
svc = bentoml.Service(
name="zedd_iris_classifier",
runners=[iris_clf_runner]
)
def preprocessing(x: np.ndarray) -> np.ndarray:
return x
def postprocessing(y: np.ndarray) -> np.ndarray:
return y
@svc.api(input=NumpyNdarray(), output=NumpyNdarray())
def predict(input_arr: np.ndarray) -> np.ndarray:
# preprocess
x = preprocessing(input_arr)
# inference
y = iris_clf_runner.predict(x)
# postprocessing
result = postprocessing(y)
return result
Next, I enter the command on terminal; bentoml serve main:svc and I got this error.
AssertionError: Service runners list can only contain bentoml.Runner instances, type "<class 'bentoml._internal.models.model.Model'>" found.
How to fix this problem? What the best practice making bento-ml serving api with mlflow-trained model? I looking forward to replying anyone's reply. Thanks.YoungHun Jo
05/19/2024, 9:19 AMrunner class using to_runner() function of bentoml._internal.models.model.Model object