Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable system metrics logging for resuming an existing run #10312

Merged

Conversation

chenmoneygithub
Copy link
Collaborator

@chenmoneygithub chenmoneygithub commented Nov 7, 2023

馃洜 DevTools 馃洜

Open in GitHub Codespaces

Install mlflow from this PR

pip install git+https://github.com/mlflow/mlflow.git@refs/pull/10312/merge

Checkout with GitHub CLI

gh pr checkout 10312

Related Issues/PRs

Resolve #10253

What changes are proposed in this pull request?

Enable system metrics logging for resuming an existing run.

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/gateway: AI Gateway service, Gateway client APIs, third-party Gateway integrations
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/recipes: Recipes, Recipe APIs, Recipe configs, Recipe Templates
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

Interface

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

Language

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

Integrations

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations

How should the PR be classified in the release notes? Choose one:

  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Copy link

github-actions bot commented Nov 7, 2023

Documentation preview for a77b849 will be available here when this CircleCI job completes successfully.

More info

@github-actions github-actions bot added rn/bug-fix Mention under Bug Fixes in Changelogs. rn/feature Mention under Features in Changelogs. and removed rn/bug-fix Mention under Bug Fixes in Changelogs. rn/feature Mention under Features in Changelogs. labels Nov 7, 2023
@chenmoneygithub chenmoneygithub requested review from danielyxyang and removed request for danielyxyang November 9, 2023 21:05
Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
mlflow/tracking/fluent.py Outdated Show resolved Hide resolved
chenmoneygithub and others added 2 commits November 9, 2023 15:50
Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
Co-authored-by: Harutaka Kawamura <hkawamura0130@gmail.com>
Signed-off-by: Chen Qian <chenmoney@google.com>
Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
@chenmoneygithub
Copy link
Collaborator Author

chenmoneygithub commented Nov 13, 2023

@danielyxyang Thanks for your help! But please don't start contributing by doing code review. Usually we assign code review tasks to OSS contributors after they have nailed several solid PRs, otherwise the review could be distracting and increasing our overhead.

chenmoneygithub and others added 2 commits November 13, 2023 11:41
Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
@github-actions github-actions bot removed the rn/feature Mention under Features in Changelogs. label Nov 13, 2023
@danielyxyang
Copy link

Oops sorry for that! I'll let you do your work then:)

Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
Comment on lines 139 to 142
# Unset the environment variables to avoid affecting other test cases.
mlflow.disable_system_metrics_logging()
mlflow.set_system_metrics_sampling_interval(None)
mlflow.set_system_metrics_samples_before_logging(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to add this as an autouse fixture in case an error occurs before we reach these lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice call.

Comment on lines +129 to +132
expected_metrics_name = [f"system/{name}" for name in expected_metrics_name]
for name in expected_metrics_name:
assert name in metrics

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_metrics_name = [f"system/{name}" for name in expected_metrics_name]
for name in expected_metrics_name:
assert name in metrics
expected_metric_names = [f"system/{name}" for name in expected_metrics_name]
assert sorted(metrics) == expected_metrics_name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not guaranteed to be equivalent. The expected set does not contain GPU metrics, which is logged when GPU is available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert metrics.keys() >= set(expected_metrics_name)

might work.


# Pause for a bit to allow the system metrics monitoring to exit.
time.sleep(1)
thread_names = [thread.name for thread in threading.enumerate()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call join on thread collected by threading.enumerate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda prefer to align the testing code with users' code, for which they won't explicitly join threads returned by threading.enumerate

mlflow/tracking/fluent.py Outdated Show resolved Hide resolved
metrics_history = mlflow.tracking.MlflowClient().get_metric_history(
run.info.run_id, "system/cpu_utilization_percentage"
)
assert metrics_history[-1].step > last_step
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this assertion more strict. For example,

assert [m.step for m in metrics_history] == expected_steps

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the behavior here is not deterministic because of python thread management.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's not deterministic? The number of steps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the number of steps is not guaranteed.

Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
import mlflow
from mlflow.system_metrics.system_metrics_monitor import SystemMetricsMonitor


@pytest.fixture(scope="module", autouse=True)
def clean_mlruns_dir():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename this fixture?

Copy link
Member

@harupy harupy Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the scope be module or function? should we run this after each test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry my bad.

Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
@chenmoneygithub chenmoneygithub merged commit 373c654 into mlflow:master Nov 14, 2023
34 checks passed
KonakanchiSwathi pushed a commit to KonakanchiSwathi/mlflow that referenced this pull request Nov 29, 2023
)

Signed-off-by: chenmoneygithub <chen.qian@databricks.com>
Signed-off-by: Chen Qian <chenmoney@google.com>
Co-authored-by: Harutaka Kawamura <hkawamura0130@gmail.com>
Signed-off-by: swathi <konakanchi.swathi@gmail.com>
@chenmoneygithub chenmoneygithub deleted the system-metrics-existing-run branch January 2, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn/bug-fix Mention under Bug Fixes in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] "log_system_metrics" not working when "existing_run_id" is set
3 participants