If you are using S3 as backend store for artifacts and have a EC2 server for tracking, this is my workaround to delete full experiments 'folders'.
You have to delete the experiment both on the artifact store (S3) and on the backend store (database hosted on EC2)
Permanently delete experiments via list of experiment ids:
def permanently_delete_experiments_on_mlflow(list_of_experiments_id: list):
mlflow_client = MlflowClient(tracking_uri=YOUR_EC2_TRACKING_URI)
commands = []
for experiment_id in list_of_experiments_id:
print(f'deleting experiment {experiment_id}')
os.system(f"aws s3 rm {YOUR_S3_ARTIFACTS_STORE} "
f"--recursive --exclude '*' --include '{experiment_id}/*'")
try:
mlflow_client.delete_experiment(experiment_id)
except Exception as e:
print_red(f'failed to execute mlflow_client.delete_experiment({experiment_id}) \n {str(e)}')
commands.append(f"YOUR_PATH_TO_DATABASE_ON_EC2{os.sep}database.db{os.sep}{experiment_id} ")
commands.append(f"YOUR_PATH_TO_DATABASE_ON_EC2{os.sep}database.db{os.sep}.trash{os.sep}{experiment_id} ")
# format commands to send via ssh to EC2
commands = f"ssh -i {YOUR_EC2_SSH_KEY_PATH} ubuntu@{YOUR_EC2_IP} rm -r " \
+ ' '.join(commands)
print('executing on EC2 the following command: \n ', commands)
result = subprocess.Popen(commands, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
response, err = result.communicate()
print('response:', response)
Note that for this to work you need to have AWS CLI installed.
It basically runs a shell command from Python that does the trick.
As a side note, the mlflow tracking with EC2 creates 'folders' both on the EC2 database and on S3 named according to the experiment id which contains a 'subfolder' for each run id corresponding to that experiment. The code above relies on this structure.