-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce get_parent_run fluent API #8493
Conversation
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
Documentation preview for 6a6ff89 will be available here when this CircleCI job completes successfully. More info
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great @annzhang-db . Can we also extend this to the mlflow client APIs (see mlflow/tracking/client.py
)? Similar to the way we call MlflowClient().get_run(run_id)
, it would be helpful to call MlflowClient().get_parent_run(run_id)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :) Awesome work
mlflow/tracking/fluent.py
Outdated
@@ -518,6 +518,43 @@ def get_run(run_id: str) -> Run: | |||
return MlflowClient().get_run(run_id) | |||
|
|||
|
|||
def get_parent_run(run_id: str) -> Optional[Run]: | |||
""" | |||
Gets the parent run for the given run id. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gets the parent run for the given run id if one exists
mlflow/tracking/fluent.py
Outdated
child_run = MlflowClient().get_run(run_id) | ||
parent_run_id = child_run.data.tags.get(MLFLOW_PARENT_RUN_ID) | ||
if parent_run_id is None: | ||
return None | ||
return MlflowClient().get_run(parent_run_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
child_run = MlflowClient().get_run(run_id) | |
parent_run_id = child_run.data.tags.get(MLFLOW_PARENT_RUN_ID) | |
if parent_run_id is None: | |
return None | |
return MlflowClient().get_run(parent_run_id) | |
client = MlflowClient() | |
child_run = client.get_run(run_id) | |
parent_run_id = child_run.data.tags.get(MLFLOW_PARENT_RUN_ID) | |
if parent_run_id is None: | |
return None | |
return client.get_run(parent_run_id) |
Can we reuse the client?
tests/tracking/fluent/test_fluent.py
Outdated
def test_get_parent_run(): | ||
parent_run_id = mlflow.start_run().info.run_id | ||
mlflow.log_param("a", 1) | ||
mlflow.log_metric("b", 2.0) | ||
child_run_id = mlflow.start_run(nested=True).info.run_id | ||
mlflow.end_run() | ||
mlflow.end_run() | ||
|
||
parent_run = mlflow.get_parent_run(child_run_id) | ||
assert parent_run.info.run_id == parent_run_id | ||
assert parent_run.data.metrics == {"b": 2.0} | ||
assert parent_run.data.params == {"a": "1"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add a test that ensures get_parent_run
returns None if the parent run doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left comments, otherwise LGTM!
tests/tracking/fluent/test_fluent.py
Outdated
parent_run_id = mlflow.start_run().info.run_id | ||
mlflow.log_param("a", 1) | ||
mlflow.log_metric("b", 2.0) | ||
child_run_id = mlflow.start_run(nested=True).info.run_id | ||
mlflow.end_run() | ||
mlflow.end_run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parent_run_id = mlflow.start_run().info.run_id | |
mlflow.log_param("a", 1) | |
mlflow.log_metric("b", 2.0) | |
child_run_id = mlflow.start_run(nested=True).info.run_id | |
mlflow.end_run() | |
mlflow.end_run() | |
with mlflow.start_run() as parent: | |
mlflow.log_param("a", 1) | |
mlflow.log_metric("b", 2.0) | |
with mlflow.start_run(nested=True) as child: |
Can we use with mlflow.start_run()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once @harupy 's comments are addressed
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @annzhang-db ! Just one small nit comment and a test
mlflow/tracking/client.py
Outdated
with mlflow.start_run(nested=True) as child_run: | ||
child_run_id = child_run.info.run_id | ||
|
||
parent_run = mlflow.get_parent_run(child_run_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we update this to demonstrate the MlflowClient approach? something like
parent_run = MlflowClient().get_parent_run
child_run_id: 7d175204675e40328e46d9a6a5a7ee6a | ||
parent_run_id: 8979459433a24a52ab3be87a229a9cdf | ||
""" | ||
return MlflowClient().get_parent_run(run_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat!
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
How is this patch tested?
Does this PR change the documentation?
Release Notes
Is this a user-facing change?
Introduce
mlflow.get_parent_run()
fluent APIWhat component(s), interfaces, languages, and integrations does this PR affect?
Components
area/artifacts
: Artifact stores and artifact loggingarea/build
: Build and test infrastructure for MLflowarea/docs
: MLflow documentation pagesarea/examples
: Example codearea/model-registry
: Model Registry service, APIs, and the fluent client calls for Model Registryarea/models
: MLmodel format, model serialization/deserialization, flavorsarea/recipes
: Recipes, Recipe APIs, Recipe configs, Recipe Templatesarea/projects
: MLproject format, project running backendsarea/scoring
: MLflow Model server, model deployment tools, Spark UDFsarea/server-infra
: MLflow Tracking server backendarea/tracking
: Tracking Service, tracking client APIs, autologgingInterface
area/uiux
: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/docker
: Docker use across MLflow's components, such as MLflow Projects and MLflow Modelsarea/sqlalchemy
: Use of SQLAlchemy in the Tracking Service or Model Registryarea/windows
: Windows supportLanguage
language/r
: R APIs and clientslanguage/java
: Java APIs and clientslanguage/new
: Proposals for new client languagesIntegrations
integrations/azure
: Azure and Azure ML integrationsintegrations/sagemaker
: SageMaker integrationsintegrations/databricks
: Databricks integrationsHow should the PR be classified in the release notes? Choose one:
rn/breaking-change
- The PR will be mentioned in the "Breaking Changes" sectionrn/none
- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/feature
- A new user-facing feature worth mentioning in the release notesrn/bug-fix
- A user-facing bug fix worth mentioning in the release notesrn/documentation
- A user-facing documentation change worth mentioning in the release notes