Skip to main content

How to Delete a Logged Model in MLflow

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Experiments pile up models you'll never use: test runs, failed ideas, the model you logged twice. MLflow 3 lets you delete a logged model on its own, from its page in the UI or from Python, and its files are removed for good the next time mlflow gc runs. This guide does both, with real screens and output from MLflow 3.18.0.

Syntax​

Syntax
MlflowClient().delete_logged_model(model_id)
PartWhat it means
MlflowClient()MLflow's client, from mlflow import MlflowClient
model_idThe m-… ID of the model to delete

Deleting marks the model as deleted: it disappears from the UI and from searches. Its files stay on the server until mlflow gc removes them.

Prerequisites​

Step 1: Delete a Model in the UI​

The example model is a linear regression on scikit-learn's diabetes data, logged in an experiment named delete-demo. Open the experiment's Models tab, click the model, then the ⋮ button next to Register model:

The model page of diabetes-model in delete-demo, with the More actions menu open under the three-dot button, showing one item, Delete.

Click Delete. MLflow asks first:

The Delete logged model dialog: Are you sure you want to delete this logged model? with the buttons Cancel and Delete.

Click Delete in the dialog. MLflow goes back to the experiment's Models tab, now without the model:

The delete-demo Models tab after the deletion: the table has its column headers but no rows, and below them the message Track and compare versions of your models.

Step 2: Delete a Model from Python​

For many models, or in a cleanup script, delete by ID. delete_model.py deletes the model whose ID you pass, then counts the models left in delete-demo:

The delete_model.py script in a macOS-style code window: it deletes the model whose ID is on the command line with MlflowClient().delete_logged_model, prints it, then searches delete-demo's logged models and prints how many are left.

delete_model.py
import sys

import mlflow
from mlflow import MlflowClient

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

model_id = sys.argv[1]
MlflowClient().delete_logged_model(model_id)
print("Deleted", model_id)

experiment = mlflow.get_experiment_by_name("delete-demo")
models = mlflow.search_logged_models(experiment_ids=[experiment.experiment_id], output_format="list")
print("Models left in delete-demo:", len(models))
Terminal
uv run python delete_model.py m-e8c0a59a92ef46ed8fcebb2733645342
Output
Deleted m-e8c0a59a92ef46ed8fcebb2733645342
Models left in delete-demo: 0

The output of delete_model.py in a terminal: Deleted m-e8c0a59a92ef46ed8fcebb2733645342, then Models left in delete-demo: 0.

The deleted model no longer counts. Looking it up by ID now fails too: mlflow.get_logged_model on it raised RESOURCE_DOES_NOT_EXIST: Logged model with ID 'm-e8c0a59a92ef46ed8fcebb2733645342' not found.

Step 3: Remove the Files with mlflow gc​

A deleted model's files stay on the tracking server: right after deleting another model the same way, its folder still held all seven files. mlflow gc, run in the server's folder, removes them for good, for every logged model in the deleted state:

Terminal (in the server's folder)
uv run mlflow gc --tracking-uri http://127.0.0.1:8080
Output
Logged model with ID m-f195725e7cf942a69ac037cfff78d6ee has been permanently deleted.

One line per deleted model, and that model's folder now holds no files. Run without options, mlflow gc also removes every deleted run and experiment for good; its help lists --logged-model-ids, --run-ids and --experiment-ids to narrow it down. Delete the models before you delete their experiment: Fixed: mlflow gc Leaves Logged Model Files Behind shows what happens otherwise.

Common Mistakes​

MistakeWhat happensDo this instead
Deleting an experiment with models in it, then running mlflow gcThe models' files stay on disk, with nothing left to point at themDelete the models first
Expecting deletion to free disk space at onceThe files stay until mlflow gcRun mlflow gc

Troubleshooting​

SymptomLikely causeFix
RESOURCE_DOES_NOT_EXIST: Logged model with ID '...' not found. after deletingDeleted models aren't returned by get_logged_modelExpected; there's nothing to fetch

FAQ​

Can I get a deleted model back?​

Not from the UI or the client calls used here: once deleted, the model is gone from both. After mlflow gc, its files are gone too.

Does deleting the model delete its run?​

No. The run, with its parameters and metrics, stays.

Conclusion​

The model page's ⋮ menu and MlflowClient().delete_logged_model(model_id) both deleted a logged model, and it vanished from the Models tab and from searches. Its files stay on the server until mlflow gc removes them.

Additional Resources​