[ Web Proxy ]
URL:
Viewing: https://cloud.google.com/tpu/docs/goodput [Back]  [Original]

Monitor goodput with the ML Goodput Measurement library  |  Cloud TPU  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback Stay organized with collections Save and categorize content based on your preferences.

Monitor goodput with the ML Goodput Measurement library

The ML Goodput Measurement library (ml-goodput-measurement) is a Python package that helps you measure the efficiency of your ML training workloads running on Cloud TPU VMs. The library provides metrics that measure workload goodput, which is the proportion of TPU usage time spent making productive, preserved training progress. Conversely, badput is the proportion of total time spent on non-productive activities like startup overhead, I/O stalls, and disruption recovery.

You can visualize goodput metrics in realtime with Cloud Monitoring dashboards and TensorBoard, enabling you to pinpoint bottlenecks, optimize resource utilization, and ultimately reduce training costs.

For more information, see the ML Goodput Measurement GitHub repository.

Goodput metrics

The ML Goodput Measurement library provides the following metrics, which are also available to view in Cloud Monitoring and TensorBoard. The metrics in this table must be prefixed with compute.googleapis.com/workload/. For example, the full metric name for goodput_time is compute.googleapis.com/workload/goodput_time.

Installation

Use the following steps to set up the ML Goodput Measurement library with your TPU workloads:

  1. Enable the Cloud Logging API and Cloud Monitoring API.
  2. If deploying on Google Kubernetes Engine (GKE), configure all node pools with the cloud-platform access scope.

Install the ml-goodput-measurement package on your training host and analysis machine:

pip install ml-goodput-measurement

Monitor with the Goodput library

To use the ML Goodput Measurement library, initialize a GoodputRecorder instance, instrument your training code by wrapping key sections with the record_event context manager, and monitor metrics in realtime with GoodputMonitor. The monitor runs a background process to periodically calculate goodput metrics from the recorded events, and uploads them to Cloud Monitoring and TensorBoard for real-time analysis and visualization.

Initialize the Goodput recorder

Initialize the GoodputRecorder, which is the core component of the ML Goodput Measurement library.

import datetime
import jax
from ml_goodput_measurement import measurement

# Define a unique logger name for this specific run
logger_name = f'goodput_{config.run_name}'

# Instantiate the recorder
goodput_recorder = measurement.GoodputRecorder(
    job_name=config.run_name,
    logger_name=logger_name,
    logging_enabled=(jax.process_index() == 0)
)

Record events

Use the record_event context manager to wrap your training code.

def train_loop(config):

  # 1. Wrap the entire Job (Start/End)
  with goodput_recorder.record_event(measurement.Event.JOB):

    # 2. Record Hardware Initialization
    with goodput_recorder.record_event(measurement.Event.ACCELERATOR_INIT):
      # ... perform device mesh setup ...
      initialize_tpu(config)

    # 3. Record Training Prep
    with goodput_recorder.record_event(measurement.Event.TRAINING_PREP):
      # ... create checkpoint managers, setup model ...
      model = training_prep(config)

    # 4. Main Training Loop
    for step in range(config.steps):

      # Record Data Loading
      with goodput_recorder.record_event(measurement.Event.DATA_LOADING):
        batch = get_next_batch()

      # Record Step Start (CRITICAL: Pass the step number!)
      with goodput_recorder.record_event(measurement.Event.STEP, step):
        output = train_step(model, batch)

      # 5. Record Custom Events (e.g., Evaluation)
      if step % eval_interval == 0:
        with goodput_recorder.record_event(measurement.Event.CUSTOM, "eval_step"):
          run_evaluation()

For an example of how training code can be integrated with the Goodput library using MaxText, see goodput.py.

Monitor events

Monitor metrics with GoodputMonitor, which starts a background process to calculate and upload metrics while the job runs. Wrap the logic in a context manager to ensure that the uploader process starts and stops as intended.

Define a helper context manager to handle configuration and lifecycle management.

import contextlib
from ml_goodput_measurement import monitoring

@contextlib.contextmanager
def maybe_monitor_goodput(config):
  """Monitor goodput if enabled and on the main process."""
  if not config.monitor_goodput or jax.process_index() != 0:
    yield
    return

  goodput_monitor = None
  try:
    # Configure GCPOptions for Cloud Monitoring
    gcp_options = monitoring.GCPOptions(
      enable_gcp_goodput_metrics=config.enable_gcp_goodput_metrics
    )

    # Instantiate the monitor
    goodput_monitor = monitoring.GoodputMonitor(
      job_name=config.run_name,
      logger_name=f"goodput_{config.run_name}",
      tensorboard_dir=config.tensorboard_dir,
      upload_interval=config.goodput_upload_interval_seconds,
      monitoring_enabled=True,
      pathway_enabled=config.enable_pathways_goodput,
      include_badput_breakdown=True,
      gcp_options=gcp_options,
    )

    # Start the background upload process
    goodput_monitor.start_goodput_uploader()
    print("Started Goodput upload to Tensorboard & GCM in the background!")
    yield

  finally:
    # Ensure clean shutdown of the background process
    if goodput_monitor:
      goodput_monitor.stop_goodput_uploader()
      print("Flushed final metrics and safe exited from Goodput monitoring.")

To measure rolling window performance, configure the monitor to use start_rolling_window_goodput_uploader and stop_rolling_window_goodput_uploader.

try:
    self._rolling_window_monitor.start_rolling_window_goodput_uploader(
        self.config.rolling_window_size
    )
finally:
    if self._rolling_window_monitor:
        self._rolling_window_monitor.stop_rolling_window_goodput_uploader()

Wrap your main training entry point with the context manager. This ensures that monitoring starts before training begins, and final metrics are cleared when training ends.

def main():
  # ... Load configuration ...

  # Wrap the entire execution
  with maybe_monitor_goodput(config):
    # Run the training loop (which contains the GoodputRecorder events)
    train_loop(config)

Post-processing and analysis

You can calculate goodput metrics for a completed job from any machine, like a standard CPU VM or your laptop. You don't need to use a TPU for post-processing and analysis.

The following code outputs the total job goodput:

from ml_goodput_measurement import goodput

calculator = goodput.GoodputCalculator(
    job_name="my-run-name",
    logger_name="goodput_my-run-name"
)

goodput, badput, last_step = calculator.get_job_goodput(
    include_badput_breakdown=True
)

print(f"Goodput: {goodput}%")
print(f"Badput (Infra Recovery): {badput[goodput.BadputType.INFRASTRUCTURE_RECOVERY_FROM_DISRUPTION]}%")

For information on badput types (BadputType), see Badput breakdown details.

To specify a specific time window, use get_job_goodput_interval:

goodput_pct, badput, _, _, _ = calculator.get_job_goodput_interval(
    start_time_utc,
    end_time_utc
)

The start time (start_time_utc) and end time (end_time_utc) are datetime objects. For more information, see goodput.py.

Monitor with Goodput dashboards

To help you monitor and visualize your Machine Learning training workloads, Google Cloud offers two sets of Goodput dashboards: the GKE JobSet Goodput dashboard and the Cloud ML Goodput dashboard. Use the GKE JobSet dashboard to diagnose infrastructure or scheduling issues, and the Cloud ML Goodput dashboards to pinpoint bottlenecks within the training code.

Google Cloud ML Goodput dashboard

The ML Goodput dashboard measures the application-level efficiency of your training script. It provides insights into time spent on productive training, and badput sources like data loading, initialization, or recovering from disruptions.

To view the ML Goodput dashboard dashboard in Cloud Monitoring:

  1. In the Google Cloud console, go to the Cloud Monitoring page.
    Go to the Monitoring console
  2. In the navigation pane, click Dashboards.
  3. In the Filter search field, enter "Cloud ML Goodput Dashboard".

The ML Goodput dashboard includes the following metrics (prefixed with workload/):

GKE JobSet dashboard

The GKE JobSet Goodput dashboard focuses on the efficiency of the orchestration layer, and helps you understand if GKE is scheduling pods quickly and keeping them running.

To view comprehensive information about the health and performance of JobSets, go to the JobSet monitoring dashboard in the Google Cloud console:

Go to JobSet monitoring dashboard

The JobSet monitoring dashboard includes the following metrics:

For more information on the GKE JobSet dashboard, see Monitor JobSet goodput.

Troubleshooting guide

This section provides troubleshooting information to help you identify and resolve common problems you might encounter while using the ML Goodput Measurement library.

Missing Cloud Monitoring metrics

If you are missing Cloud Monitoring metrics:

Missing general metrics

If you are missing general metrics:

Corrupted metrics

If your metrics are corrupted or displaying odd values:

Missing logs

If you are missing logs from Cloud Logging:

Missing badput checkpoints

If you are missing badput checkpoints:

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-11 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-11 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page