Skip to main content

FAQs

Can MLflow 3.x load runs/models/traces logged with MLflow 2.x?​

Yes, MLflow 3.x can load runs/models/traces logged with MLflow 2.x. However, the reverse is not true.

load_model throws a ResourceNotFound error when loading a model logged with MLflow 2.x. What's wrong?​

For example, the following code fails to load the model in MLflow 3.x since the model artifacts are NOT stored as run artifacts:

import mlflow

with mlflow.start_run() as run:
mlflow.sklearn.log_model(my_model, "model")
mlflow.sklearn.load_model(mlflow.get_artifact_uri("model"))
# Throws a `ResourceNotFound` error.

To avoid this error, call mlflow.<flavor>.load_model with the model URI returned by mlflow.<flavor>.log_model:

import mlflow

with mlflow.start_run() as run:
info = mlflow.sklearn.log_model(my_model, name="model")
# if the result of `log_model` is available (recommended)
mlflow.sklearn.load_model(info.model_uri)
# if only `model_id` is available
mlflow.sklearn.load_model(f"models:/{info.model_id}")
# if neither `model_id` nor `model_uri` is available (deprecated and will be removed in future versions)
mlflow.sklearn.load_model(f"runs:/{run.info.run_id}/model")

Why does this happen? In MLflow 3.x, the model artifacts are stored in a different location than in MLflow 2.x. The following is a comparison of the two versions using the tree format:

# MLflow 2.x
experiments/
└── <experiment_id>/
└── <run_id>/
└── artifacts/
└── ... # model artifacts are stored here

# MLflow 3.x
experiments/
└── <experiment_id>/
└── models/
└── <model_id>/
└── artifacts/
└── ... # model artifacts are stored here

I want to modify requirements.txt of my model. How can I do that?​

You can modify the requirements.txt of your model using mlflow.models.update_requirements() to add or remove requirements. The update_requirements function allows you to specify a new requirements file or a list of new requirements to be added.

import mlflow

mlflow.models.update_model_requirements(
model_uri="models:/<model_id>", operation="add", requirement_list=["..."]
)

I'm still not ready to upgrade to MLflow 3.x. How can I pin my MLflow version to 2.x?​

You can pin MLflow to the latest 2.x version by using the following command:

pip install 'mlflow<3'