Skip to main content

How to Delete a Model Version in MLflow

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Versions pile up: every experiment you register leaves one behind. MlflowClient.delete_model_version removes one version from a registered model for good, and it takes the version's aliases with it. This guide deletes a version that still had an alias, with real output from MLflow 3.18.0.

Syntax​

Syntax
MlflowClient().delete_model_version(name, version)
PartWhat it means
nameThe registered model
versionThe number of the version to delete, such as "1"

MLflow's Model Registry workflows page warns: "Deleting registered models or model versions is irrevocable, so use it judiciously."

Prerequisites​

  • An MLflow tracking server with a database backend at http://127.0.0.1:8080, such as mlflow server --port 8080 with its default SQLite database. The registry needs one.
  • mlflow and scikit-learn in your project, for example with uv add mlflow scikit-learn pandas.

Step 1: Delete a Version​

The example registers two versions of a diabetes regression as diabetes-linear, a linear regression and a ridge regression, and points production at version 1. It prints the versions and aliases, deletes version 1, and prints them again:

The delete_version.py script in a macOS-style code window: two versions of diabetes-linear registered in a loop, production set to version 1, a print of the versions and aliases, delete_model_version of version 1, and the same print again.

delete_version.py
import mlflow
from mlflow import MlflowClient
from sklearn.datasets import load_diabetes
from sklearn.linear_model import LinearRegression, Ridge

mlflow.set_tracking_uri("http://127.0.0.1:8080")
mlflow.set_experiment("delete-version-example")
client = MlflowClient()
name = "diabetes-linear"

X, y = load_diabetes(return_X_y=True, as_frame=True)
for model in (LinearRegression(), Ridge(alpha=1.0)): # versions 1 and 2
with mlflow.start_run():
mlflow.sklearn.log_model(
model.fit(X, y), name="model", registered_model_name=name, input_example=X.head(3)
)
client.set_registered_model_alias(name, "production", "1")
print("Before: versions", [v.version for v in client.search_model_versions(f"name = '{name}'")],
"aliases", client.get_registered_model(name).aliases)

client.delete_model_version(name, "1")
print("After: versions", [v.version for v in client.search_model_versions(f"name = '{name}'")],
"aliases", client.get_registered_model(name).aliases)
Terminal
uv run python delete_version.py
Output (last lines)
Before: versions ['2', '1'] aliases {'production': '1'}
After: versions ['2'] aliases {}

The end of the output in a terminal: before, versions 2 and 1 with production on version 1; after, only version 2 and no aliases.

Version 1 is gone, and so is production, the alias that pointed to it. Version 2 is untouched. The logged model that version 1 was registered from is still in its experiment: deleting a version removes it from the registry, not the model's files.

Common Mistakes​

MistakeWhat happensDo this instead
Deleting the version an alias points toThe alias goes too, and every load of models:/<name>@<alias> failsMove the alias to another version first
Expecting the next version to reuse the deleted numberNumbers only go up, so a deleted version's number is never handed out again, even when it was the newestRefer to versions by alias, not by an expected number

Troubleshooting​

SymptomLikely causeFix
RESOURCE_DOES_NOT_EXIST: Model Version (name=diabetes-linear, version=1) not foundThe version was deleted, or never existedLoad another version, or an alias
The logged model still shows on the experiment's Models tabDeleting a version doesn't delete the logged modelDelete the logged model separately if you no longer need it

FAQ​

Can I get a deleted version back?​

No. MLflow calls the delete "irrevocable". You can register the same logged model again, but it becomes a new version with a new number.

How do I delete the whole registered model?​

With delete_registered_model: How to Delete a Registered Model in MLflow.

Conclusion​

client.delete_model_version("diabetes-linear", "1") removed version 1 and its production alias, and left version 2 and the logged models in place.

Additional Resources​