python-3.x 如何从MLflow中删除run_id

btxsgosb  于 12个月前  发布在  Python
关注(0)|答案(1)|浏览(96)

我想从MLflow中的实验中永久删除run_id
我使用以下代码:

import mlflow
from mlflow.entities import ViewType
_mlflow_tracking_uri = "the mlflow tracking url"
exp_id_delete = "2"
mlflow.set_tracking_uri(_mlflow_tracking_uri)
           

client = mlflow.tracking.MlflowClient()
run_infos = mlflow.list_run_infos(exp_id_delete, run_view_type=ViewType.DELETED_ONLY)
               
for r in run_infos:
                    
   client.delete_run(r.run_id)

字符串
但我得到一个错误INVALID_PARAMETER_VALUE: The run blabla must be in the 'active' state. Current state is deleted.
有什么想法吗?

  • 更新 *

我试着在@Alex Ott建议的链接的帮助下编写一些代码:

import mlflow
from mlflow.entities import ViewType
from mlflow.store.tracking import DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH
from mlflow.store.artifact.artifact_repository_registry import get_artifact_repository
from mlflow.tracking import _get_store
from mlflow.entities.lifecycle_stage import LifecycleStage
from mlflow.exceptions import MlflowException
_mlflow_tracking_uri = "the mlflow tracking url"
exp_id_delete = "2"
mlflow.set_tracking_uri(_mlflow_tracking_uri)

client = mlflow.tracking.MlflowClient()
run_infos = mlflow.list_run_infos(exp_id_delete, run_view_type=ViewType.DELETED_ONLY)

for r in run_infos:
      

 print("- run_id: {}, lifecycle_stage: {}".format(r.run_id, r.lifecycle_stage))

 run = backend_store.get_run(r.run_id)
 if run.info.lifecycle_stage != LifecycleStage.DELETED:
      raise MlflowException(
          "Run % is not in `deleted` lifecycle stage. Only runs in "
          "`deleted` lifecycle stage can be deleted." % r.run_id
                    )
 artifact_repo = get_artifact_repository(run.info.artifact_uri)
 artifact_repo.delete_artifacts()
 backend_store._hard_delete_run(r.run_id)
 print("Run with ID %s has been permanently deleted." % str(r.run_id))


但现在,即使我得到的第一条消息:

Deleted runs: run_id: 24ac591d1af840cfb703131dbe1f92a9, lifecycle_stage: deleted


则会得到以下错误

mlflow.exceptions.MlflowException: Run '24ac591d1af840cfb703131dbe1f92a9' not found


有什么想法吗?

qyswt5oh

qyswt5oh1#

有一个mlflow gc命令可以实现这一点--你可以从Python脚本中调用它,或者至少和源代码中一样。

相关问题