Configure Compute Engine for ML Diagnostics

You can configure the ML Diagnostics platform for machine learning (ML) workloads on Compute Engine virtual machine (VM) instances. Using ML Diagnostics with Compute Engine lets you collect workload metrics, track configurations, and capture profiles to diagnose and optimize the performance of your workloads.

On Compute Engine VMs, ML Diagnostics supports the following features:

To enable on-demand and continuous profiling, use an instance startup script to deploy the Diagon daemon on your Compute Engine VMs. The startup script starts the daemon automatically as a Docker container whenever a VM boots.

Deploy the Diagon daemon

To deploy the Diagon daemon on Compute Engine, prepare the startup script, create a VM with the script, and verify that the daemon connects to the ML Diagnostics control plane.

Prepare the startup script

For VM environments that include a preinstalled container runtime, such as Container-Optimized OS, create a file named startup-script.sh with the following content. This script authenticates Docker with Artifact Registry and starts the diagon-daemon container when the VM boots:

#!/bin/bash
set -xe

gcloud auth configure-docker us-central1-docker.pkg.dev --quiet || true

docker rm -f diagon-daemon 2>/dev/null || true
docker run -d \
  --name diagon-daemon \
  --restart=always \
  --net=host \
  us-central1-docker.pkg.dev/hypercomputediagon-release/daemon-docker/mldiagnostics-daemon:latest \
  /mldiagnostics_extension_files/bin/mldiagnostics_extension \
    -standalone=true \
    -channel=hypercomputecluster.googleapis.com/diagnostics \
    -alsologtostderr=true

You can pass startup-script.sh to the startup-script metadata key when you create an individual VM or an instance template.

Create a VM instance with the startup script

In Cloud Shell or a terminal authenticated to Google Cloud, create a Compute Engine VM instance with the startup script and the --scopes=cloud-platform flag. The --scopes=cloud-platform flag grants the OAuth access scope required to pull the container image from Artifact Registry and upload captured .xplane.pb traces to Cloud Storage:

gcloud compute instances create VM_NAME \
  --zone=ZONE \
  --project=PROJECT_ID \
  --scopes=cloud-platform \
  --metadata-from-file=startup-script=startup-script.sh

Replace the following:

  • VM_NAME: a name for your Compute Engine VM instance
  • ZONE: the zone for the VM instance, such as us-central1-a
  • PROJECT_ID: your Google Cloud project ID

Verify the deployment

To verify that the startup script ran and that the Diagon daemon is connected to the ML Diagnostics control plane, check the container status and logs:

  1. Connect to the VM instance by using SSH:

    gcloud compute ssh VM_NAME --zone=ZONE
    
  2. On the VM, check that the diagon-daemon container is running and view its recent logs:

    docker ps --filter "name=diagon-daemon"
    docker logs --tail=50 diagon-daemon
    

    When the daemon is active and connected to the ML Diagnostics control plane, the output includes the following log entries:

    Stream established.
    Received successful DaemonRegistrationResponse from backend
    Sending DaemonHeartbeatRequest