{"data":{"slug":"github-google-skills-skills-cloud-gke-ai-troubleshooting-tpu-mxla-hang-5d938cee213d","title":"Diagnose GKE Cloud TPU Multi-Slice Training Hangs","summary":"Identify and resolve hangs in GKE multi-slice TPU training jobs using ML Diagnostics MXLA Hang Analyzer and Cloud Monitoring metrics. The deliverable is a diagnostic report that distinguishes between software and hardware causes of hangs.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-ai-troubleshooting-tpu-mxla-hang-5d938cee213d","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-gke-ai-troubleshooting-tpu-mxla-hang-5d938cee213d","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-ai-troubleshooting-tpu-mxla-hang-5d938cee213d.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-ai-troubleshooting-tpu-mxla-hang-5d938cee213d\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud`, REST API, or MCP command, you must read [Usage Attribution](references\/attribution.md). For terminal commands, prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-ai-troubleshooting-tpu-mxla-hang)\"` and append `agent-skills\/1.0 (skill:gke-ai-troubleshooting-tpu-mxla-hang)` to `User-Agent` headers. Only run read-only diagnostic commands; do not modify the cluster.","instructions":"---\nname: gke-ai-troubleshooting-tpu-mxla-hang\ndescription: >-\n  Diagnose GKE Cloud TPU multi-slice training hangs (Megascale `HANG_DETECTED`\n  logs and hang monitored events) using the ML Diagnostics `Megascale XLA (MXLA)\n  Hang Analyzer` (`gcloud alpha mldiagnostics monitored-events`) and 1-minute\n  Cloud Monitoring multi-slice latency metrics\n  (`kubernetes.io\/container\/multislice\/*`). Distinguishes XLA compiler\/HLO\n  launch divergence and host data-input stalls from TPU chip, SparseCore, ICI,\n  or network fabric faults. Use when multi-slice TPU training jobs freeze\n  without progressing steps, emit `HANG_DETECTED`, or stall in collective\n  operations. Don't use for gradual step-time throughput drops without hangs\n  (use gke-ai-troubleshooting-tpu-performance-degradation) or pod\n  preemption\/eviction restarts (use gke-ai-troubleshooting-jobset-interruption).\nmetadata:\n  version: \"1.0.1\"\n  category: AiAndMachineLearning\n---\n\n# Troubleshoot GKE TPU multi-slice hangs with the MXLA Hang Analyzer\n\nDiagnose Cloud TPU multi-slice training hangs on Google Kubernetes Engine (GKE)\nby correlating Megascale `HANG_DETECTED` logs and **ML Diagnostics Workload\nMonitoring** `Megascale XLA (MXLA) Hang Analyzer` reports with **1-minute\nmulti-slice latency metrics** (`kubernetes.io\/container\/multislice\/*`) and GKE\nnode topology labels.\n\n---\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-ai-troubleshooting-tpu-mxla-hang)\"`\nand append `agent-skills\/1.0 (skill:gke-ai-troubleshooting-tpu-mxla-hang)` to `User-Agent` headers.\n\n## Prerequisites\n\n- **Tools**: Install the\n  [Google Cloud SDK](https:\/\/cloud.google.com\/sdk\/docs\/install) (`gcloud` with\n  `alpha` component for `gcloud alpha mldiagnostics`) and `kubectl`.\n- **Cloud Billing & Project Configuration**: Verify an active billing account is\n  linked (`gcloud billing projects describe {project_id}`), authenticate\n  (`gcloud auth login`), set the target project (`gcloud config set project\n  {project_id}`), and ensure `container.googleapis.com`,\n  `logging.googleapis.com`, `monitoring.googleapis.com`, and\n  `hypercomputecluster.googleapis.com` are enabled.\n- **Supported workloads and versions**: Google Cloud ML Diagnostics only\n  supports JAX on TPUs (see\n  [ML Diagnostics platform](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/overview.md.txt)).\n  Workload Monitoring is enabled by default, supports the `jobset` and `job` GKE\n  job types, and is compatible with GKE versions `1.36.0-gke.4681000` and later\n  ([Configure GKE for ML Diagnostics](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/gke.md.txt),\n  which also covers the cluster setup needed for on-demand profiling in Step 4\n  Path B). If a workload uses another framework (such as PyTorch) or another\n  custom resource type, `gcloud alpha mldiagnostics` won't list ML runs or\n  monitored events for it. The Megascale XLA hang analyzer and Megascale XLA\n  metrics require LibTPU `0.40.0` or later (see \"Get started\" in\n  [Workload monitoring with ML Diagnostics](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/workload-monitoring.md.txt)).\n- **Required IAM Roles**:\n  - Cluster Director Editor (`roles\/hypercomputecluster.editor`), the role\n    listed in the \"IAM permissions\" section of\n    [ML Diagnostics platform](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/overview.md.txt),\n    for the ML Diagnostics CLI and API calls in this skill (ML runs, monitored\n    events, and on-demand profiler sessions)\n  - Monitoring Viewer (`roles\/monitoring.viewer`) for the PromQL queries in Step\n    2\n  - Logs Viewer (`roles\/logging.viewer`) for the Cloud Logging query in Step 1\n  - Kubernetes Engine Viewer (`roles\/container.viewer`) for the `kubectl get\n    nodes` query in Step 3\n  - For remediation (`[High Risk]` steps): Kubernetes Engine Cluster Admin\n    (`roles\/container.clusterAdmin`)\n- **Reference Documentation**:\n  - [ML Diagnostics platform](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/overview.md.txt)\n    (Sections: \"IAM permissions\")\n  - [Configure GKE for ML Diagnostics](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/gke.md.txt)\n    (Sections: \"Set up with gcloud CLI, Google Cloud console, or Terraform\",\n    \"Manual installation\", \"Connection-operator\")\n  - [Workload monitoring with ML Diagnostics](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/workload-monitoring.md.txt)\n    (Sections: \"Get started\", \"Megascale XLA (MXLA) Hang Analyzer\", \"Access\n    Workload Monitoring information through the API\", \"System Metrics\")\n  - [Get started with the ML Diagnostics CLI](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/cli.md.txt)\n    (Sections: \"List machine learning runs\", \"Monitored-events commands\", \"List\n    profiler targets\", \"Capture on-demand profiler sessions\")\n  - [Get support](https:\/\/docs.cloud.google.com\/kubernetes-engine\/docs\/getting-support.md.txt)\n    (Sections: \"Before you contact support\")\n  - [Auto-repair nodes](https:\/\/docs.cloud.google.com\/kubernetes-engine\/docs\/how-to\/node-auto-repair.md.txt)\n    (Sections: \"Repair criteria\", \"Verify node auto-repair is enabled for a\n    Standard node pool\", \"Enable auto-repair for an existing Standard node\n    pool\", \"Node auto repair in TPU slice nodes\")\n  - [Deploy TPU workloads in GKE Standard](https:\/\/docs.cloud.google.com\/kubernetes-engine\/docs\/how-to\/tpus.md.txt)\n    (Sections: \"Configure auto repair for TPU slice nodes\")\n  - [Dump HLO Computations (OpenXLA)](https:\/\/openxla.org\/xla\/hlo_dumps)\n\n> **Read-only rule**: Run read-only diagnostic commands only. Never drain,\n> delete, or re-create nodes, or run any other command that changes the cluster.\n> Give the user any fix to apply themselves.\n\nWhen you recommend a fix, link the doc section that describes it.\n\n---\n\n## MXLA Hang Analyzer routing overview\n\nA Megascale hang occurs when a multi-slice worker has waited on a Megascale\ncommunication operation for a set timeout period. The TPU logs then show a\nMegascale `HANG_DETECTED` message. `HANG_DETECTED` is a catch-all signal that\nthe workload isn't progressing, and the cause can be in software or in hardware.\nWhen a hang occurs, ML Diagnostics runs the `Megascale XLA (MXLA) Hang\nAnalyzer`, which reports the likely cause as a code. Consult the\n[Megascale XLA (MXLA) Hang Analyzer](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/workload-monitoring.md.txt)\nsection for the definition and recommended action of each code, and route by\ncategory:\n\n- **Category A: compiler or HLO divergence (never cordon or replace nodes)**:\n  - When the analyzer reports different HLO modules, inconsistent HLO\n    compilation, or an inconsistent launch order across VMs (such as\n    `FINGERPRINT_MISMATCH`), route to\n    [Path A: Compiler or HLO divergence](references\/path-a-compiler-hlo-divergence.md).\n- **Category B: host program queueing or data input stall (never cordon or\n  replace nodes)**:\n  - When the analyzer reports that VMs aren't queuing programs to the TPU or\n    that data input stalled (such as `DATA_INPUT_STALL`), route to\n    [Path B: Host program queueing or data input stall](references\/path-b-program-queueing-input-stall.md).\n- **Category C: hardware or network faults on specific instances**:\n  - When the analyzer attributes the hang to a TPU chip, SparseCore, ICI, or DCN\n    networking issue, or to an unrecoverable error on specific instances, route\n    to\n    [Path C: Hardware or network faults](references\/path-c-hardware-network-faults.md).\n- **Category D: hang signal or event exists, but the analyzer is `NOT_DETECTED`\n  or reports `UNKNOWN`**:\n  - When `HANG_DETECTED` logs or a hang monitored event fired, but the analyzer\n    report has `detectionState: \"NOT_DETECTED\"` or reports `UNKNOWN` (\"The MXLA\n    hang was detected but a potential cause is not determined\"), route to\n    [Path D: No DETECTED analyzer or UNKNOWN cause](references\/path-d-no-detected-or-unknown.md).\n\n---\n\n## Diagnostic workflow\n\n### Step 0: Collect context and set the investigation window `[Low Risk]`\n\nCollect the target parameters. By default, query a 60-minute window `[T - 30m, T\n+ 30m]` around `{issue_time}`:\n\n- `{project_id}`: Google Cloud project ID\n- `{location}`: Google Cloud region where the ML run and GKE cluster reside (for\n  example, `us-central1`)\n- `{cluster_name}`: GKE cluster name\n- `{namespace}` \/ `{workload_name}`: Kubernetes namespace and JobSet\/Pod prefix\n- `{ml_run_id}`: ML Diagnostics run ID\n- `{issue_time}`: Timestamp when the hang occurred (`T`, ISO-8601 UTC)\n- `{start_time}`: `T - 30m`\n- `{end_time}`: `T + 30m`\n\n---\n\n### Step 1: Query `HANG_DETECTED` logs and hang events `[Low Risk]`\n\n1. **Check GKE container logs for `HANG_DETECTED` (read-only Cloud Logging\n   LQL)**: Query `k8s_container` logs over `[{start_time}, {end_time}]` to\n   confirm `HANG_DETECTED` and identify the first stalled pods:\n\n```sql\nresource.type=\"k8s_container\"\nresource.labels.project_id=\"{project_id}\"\nresource.labels.cluster_name=\"{cluster_name}\"\n\"HANG_DETECTED\"\ntimestamp >= \"{start_time}\" AND timestamp <= \"{end_time}\"\n```\n\n2. **List active or recent ML runs**: Follow the\n   [List machine learning runs](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/cli.md.txt)\n   section of the ML Diagnostics CLI reference (`gcloud alpha mldiagnostics\n   machine-learning-run list`) to identify `{ml_run_id}`.\n3. **List and describe hang monitored events**: Follow the\n   [Monitored-events commands](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/cli.md.txt)\n   section (`gcloud alpha mldiagnostics monitored-events list` and `gcloud alpha\n   mldiagnostics monitored-events describe`) or\n   [Access Workload Monitoring information through the API](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/workload-monitoring.md.txt)\n   to inspect the `Megascale XLA (MXLA) Hang Analyzer` report (`detectionState`,\n   `details`, and `recommendedActions`).\n   - If `HANG_DETECTED` logs or a hang monitored event fired, run Step 2 to\n     correlate with the 1-minute metrics; if no analyzer reports\n     `detectionState: \"DETECTED\"` or the analyzer reports `UNKNOWN`, follow\n     [Path D: No DETECTED analyzer or UNKNOWN cause](references\/path-d-no-detected-or-unknown.md).\n   - If no `HANG_DETECTED` log or hang monitored event exists and multi-slice\n     latencies are normal in Step 2, **rule out** an MXLA hang by following\n     [Path E: Healthy telemetry](references\/path-e-healthy-telemetry.md).\n\n---\n\n### Step 2: Correlate with 1-minute multi-slice and TPU metrics `[Low Risk]`\n\nConsult the\n[System Metrics](https:\/\/docs.cloud.google.com\/tpu\/docs\/ml-diagnostics\/workload-monitoring.md.txt)\nsection of the Workload Monitoring guide for the 1-minute multi-slice network\n(`kubernetes.io\/container\/multislice\/network\/*`), multi-slice accelerator\n(`kubernetes.io\/container\/multislice\/accelerator\/*`), and node duty-cycle\n(`kubernetes.io\/node\/accelerator\/duty_cycle`) metrics, and run read-only PromQL\nqueries over `[{start_time}, {end_time}]`:\n\n```promql\n# 1. P95 multi-slice collective end-to-end latency by pod\nhistogram_quantile(\n  0.95,\n  sum by (pod_name, le) (\n    rate(kubernetes_io:container_multislice_network_collective_end_to_end_latencies_bucket{\n      monitored_resource=\"k8s_container\",\n      project_id=\"{project_id}\",\n      cluster_name=\"{cluster_name}\"\n    }[5m])\n  )\n)\n\n# 2. P95 multi-slice DCN transfer latency by pod\nhistogram_quantile(\n  0.95,\n  sum by (pod_name, le) (\n    rate(kubernetes_io:container_multislice_network_dcn_transfer_latencies_bucket{\n      monitored_resource=\"k8s_container\",\n      project_id=\"{project_id}\",\n      cluster_name=\"{cluster_name}\"\n    }[5m])\n  )\n)\n\n# 3. P95 host-to-device transfer latency by pod\nhistogram_quantile(\n  0.95,\n  sum by (pod_name, le) (\n    rate(kubernetes_io:container_multislice_accelerator_host_to_device_transfer_latencies_bucket{\n      monitored_resource=\"k8s_container\",\n      project_id=\"{project_id}\",\n      cluster_name=\"{cluster_name}\"\n    }[5m])\n  )\n)\n\n# 4. Node TPU duty cycle (Workload Monitoring detects a hang as a prolonged\n#    period of minimal to no TPU activity)\nkubernetes_io:node_accelerator_duty_cycle{\n  monitored_resource=\"k8s_node\",\n  project_id=\"{project_id}\",\n  cluster_name=\"{cluster_name}\"\n}\n```\n\n---\n\n### Step 3: Map culprit Compute Engine instance IDs to GKE nodes `[Low Risk]`\n\nWhen the `Megascale XLA (MXLA) Hang Analyzer` reports culprit numeric Compute\nEngine instance IDs in `details` or `recommendedActions`, map those numeric IDs\nto GKE `Node` names and physical topology blocks using this read-only `kubectl`\nquery inspecting `container.googleapis.com\/instance_id`:\n\n```bash\nkubectl get nodes -l cloud.google.com\/gke-tpu-accelerator \\\n  -o jsonpath='{range .items[*]}{.metadata.name}{\"\\tinstance_id=\"}{.metadata.annotations.container\\.googleapis\\.com\/instance_id}{\"\\tblock=\"}{.metadata.labels.cloud\\.google\\.com\/gce-topology-block}{\"\\tsubblock=\"}{.metadata.labels.cloud\\.google\\.com\/gce-topology-subblock}{\"\\thost=\"}{.metadata.labels.cloud\\.google\\.com\/gce-topology-host}{\"\\n\"}{end}'\n```\n\n---\n\n### Step 4: Remediation by root-cause category\n\nLoad and follow only the reference file that matches the root-cause category\nfrom Step 1:\n\n- **Path A (compiler or HLO divergence \u2014 different HLO modules, inconsistent HLO\n  compilation, or inconsistent launch order across VMs, such as\n  `FINGERPRINT_MISMATCH`)**: Read\n  [Path A: Compiler or HLO divergence](references\/path-a-compiler-hlo-divergence.md).\n- **Path B (host program queueing or data input stall \u2014 `PROGRAM_NOT_QUEUED` or\n  `DATA_INPUT_STALL`)**: Read\n  [Path B: Host program queueing or data input stall](references\/path-b-program-queueing-input-stall.md).\n- **Path C (hardware, SparseCore, ICI, DCN networking faults, or\n  `UNRECOVERABLE_ERROR` on specific instances)**: Read\n  [Path C: Hardware or network faults](references\/path-c-hardware-network-faults.md).\n- **Path D (`HANG_DETECTED` logs or hang event fired, but the analyzer is\n  `NOT_DETECTED` or reports `UNKNOWN`)**: Read\n  [Path D: No DETECTED analyzer or UNKNOWN cause](references\/path-d-no-detected-or-unknown.md).\n- **Path E (no `HANG_DETECTED` logs or hang events, and steady telemetry)**:\n  Read [Path E: Healthy telemetry](references\/path-e-healthy-telemetry.md).\n\n---\n\n## Guardrails\n\n1. **Never change GKE-managed instance groups or VMs through Compute Engine**:\n   Don't run `gcloud compute instance-groups managed` commands, such as\n   `delete`, on a node pool's managed instance group. Handle nodes through GKE,\n   as described in\n   [Path C: Hardware or network faults](references\/path-c-hardware-network-faults.md).\n2. **Never cordon or replace nodes for compiler divergence or input stalls**: If\n   the analyzer reports a compiler or HLO divergence, a program queueing issue,\n   or a data input stall, don't cordon or replace TPU nodes. Follow\n   [Path A: Compiler or HLO divergence](references\/path-a-compiler-hlo-divergence.md)\n   or\n   [Path B: Host program queueing or data input stall](references\/path-b-program-queueing-input-stall.md)\n   instead.\n","use_cases":["When a multi-slice TPU training job freezes without progressing steps and emits HANG_DETECTED logs.","When a job stalls in collective operations without progressing.","When there is a sudden stop in training progress without gradual throughput drops."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/gke-ai-troubleshooting-tpu-mxla-hang\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T15:08:21.000000Z","updated_at":"2026-11-17T05:10:29.000000Z","seo_title":"Diagnose GKE TPU Multi-Slice Training Hangs","seo_description":"Use ML Diagnostics and Cloud Monitoring to diagnose and resolve hangs in GKE multi-slice TPU training jobs.","seo_keywords":["GKE TPU hang diagnosis","ML Diagnostics MXLA Hang Analyzer","Cloud Monitoring TPU latency metrics","TPU multi-slice training hang","HANG_DETECTED log analysis"]}}