Skip to main content

How to Download an MLflow Model's Files

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Sometimes you want a logged model's files on disk: to look inside MLmodel, to use its serving_input_example.json as a request, or to hand the whole folder to a tool. MLflow downloads a model by its models:/ URI, from the terminal or from Python. This guide does both, with real output from MLflow 3.18.0.

Syntax​

Syntax (terminal)
mlflow artifacts download -u models:/MODEL_ID -d FOLDER
Syntax (Python)
folder = mlflow.artifacts.download_artifacts(artifact_uri=model_uri, dst_path=folder)
PartWhat it means
-u / artifact_uriThe model's URI, models:/<model ID>
-d / dst_pathThe folder to download into. MLflow's reference: "If the directory does not exist, it is created."
folderThe local path of the downloaded files, which both print or return

The terminal command finds the tracking server through the MLFLOW_TRACKING_URI environment variable.

Prerequisites​

Step 1: Download from the Terminal​

The example model is a linear regression trained on scikit-learn's diabetes data and logged with an input example, models:/m-27f5ad2cfe8b40659f4e226c0508db8d. In your project:

Terminal
export MLFLOW_TRACKING_URI=http://127.0.0.1:8080
uv run mlflow artifacts download -u models:/m-27f5ad2cfe8b40659f4e226c0508db8d -d diabetes-model
Output
/Users/you/source/mlflow-demo/diabetes-model

The terminal command mlflow artifacts download with the model's models:/ URI and -d diabetes-model, which prints the full path of the new diabetes-model folder.

The command prints where the files went. The folder holds the model's seven files:

diabetes-model/
diabetes-model/
├── MLmodel
├── conda.yaml
├── input_example.json
├── model.skops
├── python_env.yaml
├── requirements.txt
└── serving_input_example.json

Step 2: Download from Python​

The same, from a script that takes the URI on the command line:

The download_model.py script in a macOS-style code window: it calls mlflow.artifacts.download_artifacts with the model URI from the command line and dst_path diabetes-model, and prints the returned folder.

download_model.py
import sys

import mlflow

mlflow.set_tracking_uri("http://127.0.0.1:8080")

folder = mlflow.artifacts.download_artifacts(artifact_uri=sys.argv[1], dst_path="diabetes-model")
print(folder)
Terminal
uv run python download_model.py models:/m-27f5ad2cfe8b40659f4e226c0508db8d
Output
/Users/you/source/mlflow-demo/diabetes-model

The output of download_model.py in a terminal: the full path of the diabetes-model folder.

download_artifacts returns the folder, ready to use in the rest of the script.

Common Mistakes​

MistakeWhat happensDo this instead
Adding a file name to the model URI, models:/<ID>/MLmodelMLflow reads it as a registered model's name and version: RESOURCE_DOES_NOT_EXIST: Registered Model with name=m-... not foundFixed: Registered Model with name=m-... not found
mlflow artifacts list to see a model's filesIt takes a run ID, and MLflow 3 keeps models outside the run's filesDownload the model, or open its Artifacts tab
Leaving the downloaded folder in a Git projectIt shows up as new, untracked filesDelete it when you're done, or download outside the project

Troubleshooting​

SymptomLikely causeFix
MlflowException: Logged model with ID '...' not found.MLFLOW_TRACKING_URI isn't set, so the command looks in a local database, mlflow.db, which it creates in the folderSet it as above, and delete the stray mlflow.db

FAQ​

Do I need to download a model to load it?​

No: mlflow.pyfunc.load_model and mlflow.sklearn.load_model download what they need themselves.

Where do the files go without -d?​

MLflow's reference: "If unspecified the artifacts are downloaded to a new uniquely-named directory".

Conclusion​

mlflow artifacts download -u models:/m-… -d diabetes-model and mlflow.artifacts.download_artifacts both put the model's seven files in a folder and gave its path. To fetch only one of them, see the fix for single files.

Additional Resources​