Kumaran
Databricks Employee
Databricks Employee

Hi @Yuki,

Thank you for contacting the Databricks community.

  • If you run register_model with the same run twice, you’ll create multiple versions pointing to the same source.

  • To avoid that, you can check if the run is already registered before creating a new version:

     
    from mlflow.tracking import MlflowClient
    
    client = MlflowClient()
    existing = [
        v.source for v in client.search_model_versions(f"name='{model_name}'")
    ]
    if f"runs:/{best_run.run_id}/model" not in existing:
        result = mlflow.register_model(f"runs:/{best_run.run_id}/model", model_name)