MLflow supports custom models of mlflow.pyfunc flavor. You can create a custom class inherited from the mlflow.pyfunc.PythonModel
, that needs to provide function predict
for performing predictions, and optional load_context
to load the necessary artifacts, like this (adopted from the docs):
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)
You can log to MLflow whatever artifacts you need for your models, define Conda environment if necessary, etc.
Then you can use save_model
with your class to save your implementation, that could be loaded with load_model
and do the predict
using your model:
mlflow.pyfunc.save_model(
path=mlflow_pyfunc_model_path, python_model=MyModel(), artifacts=artifacts)
# Load the model in `python_function` format
loaded_model = mlflow.pyfunc.load_model(mlflow_pyfunc_model_path)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…