Registry / gcp / google-cloud-mldiagnostics

google-cloud-mldiagnostics

JSON →
library1.0.3pypypiunverified

The `google-cloud-mldiagnostics` library is the Python SDK for Google Cloud's ML Diagnostics platform. It integrates with machine learning workloads to collect and manage workload metrics, configurations, and profiles, and enables programmatic and on-demand profile capture. It helps users create and monitor machine learning runs, deploy managed XProf resources for performance profiling, and visualize various workload aspects on Google Cloud. The library is actively maintained, with frequent updates aligning with new features and improvements in Google Cloud services.

pip install google-cloud-mldiagnostics
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-MLDIA
G
google-cloud-mldiagnostics
gcppythonv1.0.3
Install
6.0s avg
Import
Disk
73MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 74.5MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 6.0s · import 0.000s · 72MB
73MB installed
● package 73MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

google_cloud_mldiagnostics
import google_cloud_mldiagnostics
import google_cloud_mldiagnostics

This quickstart demonstrates how to integrate `google-cloud-mldiagnostics` into your Python ML workload. It sets up Cloud Logging, creates a machine learning run, records sample metrics, and writes configuration data. Ensure `GCP_PROJECT_ID` environment variable is set or replace `'your-gcp-project-id'` with your actual Google Cloud project ID. Authentication typically relies on Application Default Credentials (e.g., via `gcloud auth application-default login`).

import os import logging import google.cloud.logging from google_cloud_mldiagnostics import machinelearning_run from google_cloud_mldiagnostics import metrics from google_cloud_mldiagnostics import xprof from google_cloud_mldiagnostics.proto.diagnostics import MetricType # Set up Cloud Logging (recommended) logging_client = google.cloud.logging.Client() logging_client.setup_logging() logging.info("Cloud Logging is set up.") PROJECT_ID = os.environ.get('GCP_PROJECT_ID', 'your-gcp-project-id') # Ensure GOOGLE_APPLICATION_CREDENTIALS is set or authenticated via gcloud CLI def run_ml_diagnostics_example(): print(f"Using GCP Project ID: {PROJECT_ID}") # 1. Create a machine learning run # The SDK automatically generates a unique run_id if not provided. run_name = machinelearning_run.create_run( project_id=PROJECT_ID, experiment_name="my-first-experiment", display_name="my-training-run" ) print(f"Created ML Run: {run_name}") # 2. Record metrics metrics.record(MetricType.LOSS, 0.5, step=1, run_name=run_name) metrics.record(MetricType.ACCURACY, 0.8, step=1, run_name=run_name) print("Recorded initial metrics.") metrics.record(MetricType.LOSS, 0.2, step=10, run_name=run_name) metrics.record(MetricType.ACCURACY, 0.95, step=10, run_name=run_name) print("Recorded updated metrics.") # 3. Write configurations (example) machinelearning_run.write_config(run_name, {"learning_rate": 0.01, "batch_size": 32}) print("Wrote run configurations.") # Example of capturing a profile (requires XProf server running in your workload) # For on-demand capture, ensure xprof.start_server() is called in your ML workload. # xprof.capture_profile(run_name, 'gs://your-bucket/profiles', duration_ms=10000) # print("Attempted to capture profile.") print("ML Diagnostics example completed. Check Google Cloud Console for 'my-training-run'.") if __name__ == '__main__': run_ml_diagnostics_example()
Debug
Known issues
breakingThe generic `google-cloud` package is deprecated. Users should install product-specific packages like `google-cloud-mldiagnostics` instead of the umbrella package to avoid issues and ensure up-to-date functionality.
fix
Migrate from `google-cloud` to `pip install google-cloud-mldiagnostics` and other specific `google-cloud-*` libraries. Remove `google-cloud` from your project's dependencies.
affects: <=0.34.0 of google-cloud
gotchaThe ML Diagnostics SDK for Python currently only officially supports JAX on TPUs. Using it with other frameworks (e.g., TensorFlow, PyTorch) or hardware (e.g., GPUs, CPUs) might not be fully supported or may have limitations.
fix
Verify compatibility with your specific ML framework and hardware setup. Refer to the official documentation for the latest support matrix.
affects: All versions
gotchaTo route SDK logs, metrics, and configuration information to Google Cloud Logging, you must explicitly install and configure the `google-cloud-logging` library in your application. Without this, SDK output will only go to standard Python logging, not Cloud Logging.
fix
Install `google-cloud-logging` and add `import google.cloud.logging; logging_client = google.cloud.logging.Client(); logging_client.setup_logging()` to your script as shown in the quickstart.
affects: All versions
gotchaAuthentication to Google Cloud services is required. Incorrect or missing authentication credentials (e.g., `GOOGLE_APPLICATION_CREDENTIALS` not set, or `gcloud auth application-default login` not run) will lead to permission errors when the SDK attempts to interact with Google Cloud APIs.
fix
Ensure your environment is properly authenticated. The recommended approach is to use Application Default Credentials (ADC) by running `gcloud auth application-default login` or setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of a service account key file.
affects: All versions
Upgrade
Version history
1.0.3latest on PyPI · released Jun 10, 2026
Audit
Dependencies
google-cloud-loggingrequiredRecommended for routing SDK logs, metrics, and configs to Cloud Logging for visualization and analysis.
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
google-cloud-mldiagnostics — pip install google-cloud-mldiagnostics · libregistry