cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results for 
Search instead for 
Did you mean: 

Can view Model Registry using a Service Principal, but cannot load the model for inference.

JC3
New Contributor II

I have a Service Principal (for M2M auth) with read access to a Databricks Model Registry. I can successfully search the registry (via the `WorkspaceClient`) and find the model that I want to load using (Python) APIs, but I cannot load the model for inference.

Loading for inference seems to require MLFlow, but each time I try to use `mlflow.MlflowClient` to load a model, it errors out with `InvalidConfigurationError: You haven't configured the CLI yet!`.

I need to be able to use M2M auth, and configuring the CLI is not possible in my workflow.

How can I use the M2M auth approach to load models with MLFlow, or is there a different model-loading workflow that needs to be followed?

 

2 REPLIES 2

Kumaran
Databricks Employee
Databricks Employee

Hello @JC3,

Thank you for posting your question in the Databricks community.

Is it possible to share with us the minimum reproducible code?

JC3
New Contributor II

Thank you, @Kumaran.

The short version of this is below. Note that I have the following env vars loaded at runtime:

  • DATABRICKS_HOST
  • DATABRICKS_CLIENT_ID
  • DATABRICKS_CLIENT_SECRET
  • MLFLOW_TRACKING_URI

 

import os
import
mlflow

if __name__ == "__main__":
# attempt to use mlflow to search model registry and load model
mlflow_client = mlflow.MlflowClient(
registry_uri=os.getenv('MLFLOW_TRACKING_URI')
)

model_name = 'test-model'
for model in mlflow_client.search_model_versions(filter_string=f"name='{model_name}'"):
pymodel = mlflow.pyfunc.load_model(model_uri=f"models:/{model.name}/{model.version}")

 

If DATABRICKS_CLIENT_ID and DATABRICKS_CLIENT_SECRET were replaced by a personal access token at  DATABRICKS_TOKEN, then this works as expected. But not when using the Service principal's client id and secret, which is what I hope to use, so that auth is M2M.

Can you help here?

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group