How to retrieve the model signature from the MLflow Model Registry

Viewed 904

I have registered a scikit learn model on my MLflow Tracking server, and I am loading it with sklearn.load_model(model_uri).

Now, I would like to access the signature of the model so I can get a list of the model's required inputs/features so I can retrieve them from my feature store by name. I can't seem to find any utility or method in the mlflow API or the MLFlowClient API that will let me access a signature or inputs/outputs attribute, even though I can see a list of inputs and outputs under each version of the model in the UI.

I know that I can find the input sample and the model configuration in the model's artifacts, but that would require me actually downloading the artifacts and loading them manually in my script. I don't need to avoid that, but I am surprised that I can't just return the signature as a dictionary the same way I can return a run's parameters or metrics.

1 Answers

The way to access the model's signature without downloading the MLModel file is under the loaded model. And then you'll access the model's attributes, such as its signature or even other Pyfunc-defined methods.

import mlflow

model = mlflow.pyfunc.load_model("runs:/<run_id>/model")
print(model._model_meta._signature)
Related