Slackbot
01/03/2022, 4:10 PMAlexandre Divet
01/03/2022, 4:12 PMrun_id (as shown in this notebook) but as I’m working with NLP models a lot, I tend to pack everything up into a pyfunc (model + tokenizer) and can simply load the model using mlflow.pyfunc.load_model and its .predict() method.
It would be ideal to be able to wrap these pyfunc models around a BentoML service and use it for deployment.
Technically I can create a custom MLflow artifact and service extracting the .predict() from the pyfunc but this is not ideal cause pyfunc forces you to define your predict that way
class MyModel(mlflow.pyfunc.PythonModel):
def load_context(self, context):
# load your artifacts
def predict(self, context, model_input):
return my_predict(model_input.values)
and that context parameter is messing up with the predict() method I need for BentoMLChaoyu
01/03/2022, 4:17 PMChaoyu
01/06/2022, 3:28 PMAlexandre Divet
01/06/2022, 3:42 PMAlexandre Divet
01/06/2022, 3:51 PMclass ModelPyfunc(mlflow.pyfunc.PythonModel):
def load_context(self, context):
self.model = clf
def predict(self, context, model_input):
return self.model.predict(model_input)
how can I create a bento service around it? the model itself already contains the predict method, so not sure what would be a working equivalent to this in your quickstartChaoyu
01/06/2022, 4:15 PMbentoml.mlflow.import_from_uri(...)
And then load the PyFunc model back as a Runner and use it in your Service definition:
runner = bentoml.mlflow.load_runner("name:version")
my_svc = bentoml.Service('my_service', runners=[runner])
@my_svc.api(...)
def predict(...):
runner.run( .. )Chaoyu
01/06/2022, 4:15 PMrunner.run will be sending input data to the predict function in your PyFunc model definitionChaoyu
01/06/2022, 4:16 PM