Registry /
gcp / google-cloud-mldiagnostics
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
muslpy 3.10–3.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 74.5MB
glibcpy 3.10–3.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.fixMigrate 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.fixVerify 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.fixInstall `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.fixEnsure 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.