How to download mlflow model artifacts from Azure Databricks workspace to local directory?

Sriram Reddy Gade 51 Reputation points
2022-10-05T12:20:15.76+00:00

I have trained a machine learning model in Databricks workspace using mlflow. Model is getting registered in databricks model registry and saved in databricks file share. Now I want to download model artifacts from workspace. Currently I am transferring model to azure machine learning workspace. There I am able to download all the artifacts. How to do it from databricks workspace?

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,336 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,517 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ramr-msft 17,826 Reputation points
    2022-10-06T10:12:30.293+00:00

    @Sriram Reddy Gade Thanks for the question. To download a model from Databricks workspace you need to do two things:

    Set MLFlow tracking URI to databricks using python API

    Setup databricks authentication. I prefer authenticating by setting the following environment variables, you can also use databricks CLI to authenticate:

    DATABRICKS_HOST

    DATABRICKS_TOKEN
    Here's a basic code snippet to download a model from Databricks workspace model registry:

    import os  
    import mlflow  
    from mlflow.store.artifact.models_artifact_repo import ModelsArtifactRepository  
      
    model_name = "example-model-name"  
    model_stage = "Staging"  # Should be either 'Staging' or 'Production'  
      
    mlflow.set_tracking_uri("databricks")  
      
    os.makedirs("model", exist_ok=True)  
    local_path = ModelsArtifactRepository(  
        f'models:/{model_name}/{model_stage}').download_artifacts("", dst_path="model")  
      
    print(f'{model_stage} Model {model_name} is downloaded at {local_path}')  
    

    Running above python script will download an ML model in the model directory.

    Containerizing MLFlow model serving with Docker

    For more information you can follow this article from Akshay Milmile

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.