1
---
2
name: gke-ai-troubleshooting-tpu-mxla-hang
3
description: >-
4
Diagnose GKE Cloud TPU multi-slice training hangs (Megascale `HANG_DETECTED`
5
logs and hang monitored events) using the ML Diagnostics `Megascale XLA (MXLA)
6
Hang Analyzer` (`gcloud alpha mldiagnostics monitored-events`) and 1-minute
7
Cloud Monitoring multi-slice latency metrics
8
(`kubernetes.io/container/multislice/*`). Distinguishes XLA compiler/HLO
9
launch divergence and host data-input stalls from TPU chip, SparseCore, ICI,
10
or network fabric faults. Use when multi-slice TPU training jobs freeze
11
without progressing steps, emit `HANG_DETECTED`, or stall in collective
12
operations. Don't use for gradual step-time throughput drops without hangs
13
(use gke-ai-troubleshooting-tpu-performance-degradation) or pod
14
preemption/eviction restarts (use gke-ai-troubleshooting-jobset-interruption).
15
metadata:
16
version: "1.0.1"
17
category: AiAndMachineLearning
18
---
19
20
# Troubleshoot GKE TPU multi-slice hangs with the MXLA Hang Analyzer
21
22
Diagnose Cloud TPU multi-slice training hangs on Google Kubernetes Engine (GKE)
23
by correlating Megascale `HANG_DETECTED` logs and **ML Diagnostics Workload
24
Monitoring** `Megascale XLA (MXLA) Hang Analyzer` reports with **1-minute
25
multi-slice latency metrics** (`kubernetes.io/container/multislice/*`) and GKE
26
node topology labels.
27
28
---
29
30
## Attribution
31
32
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
33
MUST read [Usage Attribution](references/attribution.md). For commands executed
34
directly in the terminal (never in generated scripts, Terraform, or user code),
35
prefix `gcloud` with
36
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-ai-troubleshooting-tpu-mxla-hang)"`
37
and append `agent-skills/1.0 (skill:gke-ai-troubleshooting-tpu-mxla-hang)` to `User-Agent` headers.
38
39
## Prerequisites
40
41
- **Tools**: Install the
42
[Google Cloud SDK](https://cloud.google.com/sdk/docs/install) (`gcloud` with
43
`alpha` component for `gcloud alpha mldiagnostics`) and `kubectl`.
44
- **Cloud Billing & Project Configuration**: Verify an active billing account is
45
linked (`gcloud billing projects describe {project_id}`), authenticate
46
(`gcloud auth login`), set the target project (`gcloud config set project
47
{project_id}`), and ensure `container.googleapis.com`,
48
`logging.googleapis.com`, `monitoring.googleapis.com`, and
49
`hypercomputecluster.googleapis.com` are enabled.
50
- **Supported workloads and versions**: Google Cloud ML Diagnostics only
51
supports JAX on TPUs (see
52
[ML Diagnostics platform](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/overview.md.txt)).
53
Workload Monitoring is enabled by default, supports the `jobset` and `job` GKE
54
job types, and is compatible with GKE versions `1.36.0-gke.4681000` and later
55
([Configure GKE for ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/gke.md.txt),
56
which also covers the cluster setup needed for on-demand profiling in Step 4
57
Path B). If a workload uses another framework (such as PyTorch) or another
58
custom resource type, `gcloud alpha mldiagnostics` won't list ML runs or
59
monitored events for it. The Megascale XLA hang analyzer and Megascale XLA
60
metrics require LibTPU `0.40.0` or later (see "Get started" in
61
[Workload monitoring with ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)).
62
- **Required IAM Roles**:
63
- Cluster Director Editor (`roles/hypercomputecluster.editor`), the role
64
listed in the "IAM permissions" section of
65
[ML Diagnostics platform](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/overview.md.txt),
66
for the ML Diagnostics CLI and API calls in this skill (ML runs, monitored
67
events, and on-demand profiler sessions)
68
- Monitoring Viewer (`roles/monitoring.viewer`) for the PromQL queries in Step
69
2
70
- Logs Viewer (`roles/logging.viewer`) for the Cloud Logging query in Step 1
71
- Kubernetes Engine Viewer (`roles/container.viewer`) for the `kubectl get
72
nodes` query in Step 3
73
- For remediation (`[High Risk]` steps): Kubernetes Engine Cluster Admin
74
(`roles/container.clusterAdmin`)
75
- **Reference Documentation**:
76
- [ML Diagnostics platform](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/overview.md.txt)
77
(Sections: "IAM permissions")
78
- [Configure GKE for ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/gke.md.txt)
79
(Sections: "Set up with gcloud CLI, Google Cloud console, or Terraform",
80
"Manual installation", "Connection-operator")
81
- [Workload monitoring with ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)
82
(Sections: "Get started", "Megascale XLA (MXLA) Hang Analyzer", "Access
83
Workload Monitoring information through the API", "System Metrics")
84
- [Get started with the ML Diagnostics CLI](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt)
85
(Sections: "List machine learning runs", "Monitored-events commands", "List
86
profiler targets", "Capture on-demand profiler sessions")
87
- [Get support](https://docs.cloud.google.com/kubernetes-engine/docs/getting-support.md.txt)
88
(Sections: "Before you contact support")
89
- [Auto-repair nodes](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/node-auto-repair.md.txt)
90
(Sections: "Repair criteria", "Verify node auto-repair is enabled for a
91
Standard node pool", "Enable auto-repair for an existing Standard node
92
pool", "Node auto repair in TPU slice nodes")
93
- [Deploy TPU workloads in GKE Standard](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/tpus.md.txt)
94
(Sections: "Configure auto repair for TPU slice nodes")
95
- [Dump HLO Computations (OpenXLA)](https://openxla.org/xla/hlo_dumps)
96
97
> **Read-only rule**: Run read-only diagnostic commands only. Never drain,
98
> delete, or re-create nodes, or run any other command that changes the cluster.
99
> Give the user any fix to apply themselves.
100
101
When you recommend a fix, link the doc section that describes it.
102
103
---
104
105
## MXLA Hang Analyzer routing overview
106
107
A Megascale hang occurs when a multi-slice worker has waited on a Megascale
108
communication operation for a set timeout period. The TPU logs then show a
109
Megascale `HANG_DETECTED` message. `HANG_DETECTED` is a catch-all signal that
110
the workload isn't progressing, and the cause can be in software or in hardware.
111
When a hang occurs, ML Diagnostics runs the `Megascale XLA (MXLA) Hang
112
Analyzer`, which reports the likely cause as a code. Consult the
113
[Megascale XLA (MXLA) Hang Analyzer](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)
114
section for the definition and recommended action of each code, and route by
115
category:
116
117
- **Category A: compiler or HLO divergence (never cordon or replace nodes)**:
118
- When the analyzer reports different HLO modules, inconsistent HLO
119
compilation, or an inconsistent launch order across VMs (such as
120
`FINGERPRINT_MISMATCH`), route to
121
[Path A: Compiler or HLO divergence](references/path-a-compiler-hlo-divergence.md).
122
- **Category B: host program queueing or data input stall (never cordon or
123
replace nodes)**:
124
- When the analyzer reports that VMs aren't queuing programs to the TPU or
125
that data input stalled (such as `DATA_INPUT_STALL`), route to
126
[Path B: Host program queueing or data input stall](references/path-b-program-queueing-input-stall.md).
127
- **Category C: hardware or network faults on specific instances**:
128
- When the analyzer attributes the hang to a TPU chip, SparseCore, ICI, or DCN
129
networking issue, or to an unrecoverable error on specific instances, route
130
to
131
[Path C: Hardware or network faults](references/path-c-hardware-network-faults.md).
132
- **Category D: hang signal or event exists, but the analyzer is `NOT_DETECTED`
133
or reports `UNKNOWN`**:
134
- When `HANG_DETECTED` logs or a hang monitored event fired, but the analyzer
135
report has `detectionState: "NOT_DETECTED"` or reports `UNKNOWN` ("The MXLA
136
hang was detected but a potential cause is not determined"), route to
137
[Path D: No DETECTED analyzer or UNKNOWN cause](references/path-d-no-detected-or-unknown.md).
138
139
---
140
141
## Diagnostic workflow
142
143
### Step 0: Collect context and set the investigation window `[Low Risk]`
144
145
Collect the target parameters. By default, query a 60-minute window `[T - 30m, T
146
+ 30m]` around `{issue_time}`:
147
148
- `{project_id}`: Google Cloud project ID
149
- `{location}`: Google Cloud region where the ML run and GKE cluster reside (for
150
example, `us-central1`)
151
- `{cluster_name}`: GKE cluster name
152
- `{namespace}` / `{workload_name}`: Kubernetes namespace and JobSet/Pod prefix
153
- `{ml_run_id}`: ML Diagnostics run ID
154
- `{issue_time}`: Timestamp when the hang occurred (`T`, ISO-8601 UTC)
155
- `{start_time}`: `T - 30m`
156
- `{end_time}`: `T + 30m`
157
158
---
159
160
### Step 1: Query `HANG_DETECTED` logs and hang events `[Low Risk]`
161
162
1. **Check GKE container logs for `HANG_DETECTED` (read-only Cloud Logging
163
LQL)**: Query `k8s_container` logs over `[{start_time}, {end_time}]` to
164
confirm `HANG_DETECTED` and identify the first stalled pods:
165
166
```sql
167
resource.type="k8s_container"
168
resource.labels.project_id="{project_id}"
169
resource.labels.cluster_name="{cluster_name}"
170
"HANG_DETECTED"
171
timestamp >= "{start_time}" AND timestamp <= "{end_time}"
172
```
173
174
2. **List active or recent ML runs**: Follow the
175
[List machine learning runs](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt)
176
section of the ML Diagnostics CLI reference (`gcloud alpha mldiagnostics
177
machine-learning-run list`) to identify `{ml_run_id}`.
178
3. **List and describe hang monitored events**: Follow the
179
[Monitored-events commands](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt)
180
section (`gcloud alpha mldiagnostics monitored-events list` and `gcloud alpha
181
mldiagnostics monitored-events describe`) or
182
[Access Workload Monitoring information through the API](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)
183
to inspect the `Megascale XLA (MXLA) Hang Analyzer` report (`detectionState`,
184
`details`, and `recommendedActions`).
185
- If `HANG_DETECTED` logs or a hang monitored event fired, run Step 2 to
186
correlate with the 1-minute metrics; if no analyzer reports
187
`detectionState: "DETECTED"` or the analyzer reports `UNKNOWN`, follow
188
[Path D: No DETECTED analyzer or UNKNOWN cause](references/path-d-no-detected-or-unknown.md).
189
- If no `HANG_DETECTED` log or hang monitored event exists and multi-slice
190
latencies are normal in Step 2, **rule out** an MXLA hang by following
191
[Path E: Healthy telemetry](references/path-e-healthy-telemetry.md).
192
193
---
194
195
### Step 2: Correlate with 1-minute multi-slice and TPU metrics `[Low Risk]`
196
197
Consult the
198
[System Metrics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)
199
section of the Workload Monitoring guide for the 1-minute multi-slice network
200
(`kubernetes.io/container/multislice/network/*`), multi-slice accelerator
201
(`kubernetes.io/container/multislice/accelerator/*`), and node duty-cycle
202
(`kubernetes.io/node/accelerator/duty_cycle`) metrics, and run read-only PromQL
203
queries over `[{start_time}, {end_time}]`:
204
205
```promql
206
# 1. P95 multi-slice collective end-to-end latency by pod
207
histogram_quantile(
208
0.95,
209
sum by (pod_name, le) (
210
rate(kubernetes_io:container_multislice_network_collective_end_to_end_latencies_bucket{
211
monitored_resource="k8s_container",
212
project_id="{project_id}",
213
cluster_name="{cluster_name}"
214
}[5m])
215
)
216
)
217
218
# 2. P95 multi-slice DCN transfer latency by pod
219
histogram_quantile(
220
0.95,
221
sum by (pod_name, le) (
222
rate(kubernetes_io:container_multislice_network_dcn_transfer_latencies_bucket{
223
monitored_resource="k8s_container",
224
project_id="{project_id}",
225
cluster_name="{cluster_name}"
226
}[5m])
227
)
228
)
229
230
# 3. P95 host-to-device transfer latency by pod
231
histogram_quantile(
232
0.95,
233
sum by (pod_name, le) (
234
rate(kubernetes_io:container_multislice_accelerator_host_to_device_transfer_latencies_bucket{
235
monitored_resource="k8s_container",
236
project_id="{project_id}",
237
cluster_name="{cluster_name}"
238
}[5m])
239
)
240
)
241
242
# 4. Node TPU duty cycle (Workload Monitoring detects a hang as a prolonged
243
# period of minimal to no TPU activity)
244
kubernetes_io:node_accelerator_duty_cycle{
245
monitored_resource="k8s_node",
246
project_id="{project_id}",
247
cluster_name="{cluster_name}"
248
}
249
```
250
251
---
252
253
### Step 3: Map culprit Compute Engine instance IDs to GKE nodes `[Low Risk]`
254
255
When the `Megascale XLA (MXLA) Hang Analyzer` reports culprit numeric Compute
256
Engine instance IDs in `details` or `recommendedActions`, map those numeric IDs
257
to GKE `Node` names and physical topology blocks using this read-only `kubectl`
258
query inspecting `container.googleapis.com/instance_id`:
259
260
```bash
261
kubectl get nodes -l cloud.google.com/gke-tpu-accelerator \
262
-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}'
263
```
264
265
---
266
267
### Step 4: Remediation by root-cause category
268
269
Load and follow only the reference file that matches the root-cause category
270
from Step 1:
271
272
- **Path A (compiler or HLO divergence — different HLO modules, inconsistent HLO
273
compilation, or inconsistent launch order across VMs, such as
274
`FINGERPRINT_MISMATCH`)**: Read
275
[Path A: Compiler or HLO divergence](references/path-a-compiler-hlo-divergence.md).
276
- **Path B (host program queueing or data input stall — `PROGRAM_NOT_QUEUED` or
277
`DATA_INPUT_STALL`)**: Read
278
[Path B: Host program queueing or data input stall](references/path-b-program-queueing-input-stall.md).
279
- **Path C (hardware, SparseCore, ICI, DCN networking faults, or
280
`UNRECOVERABLE_ERROR` on specific instances)**: Read
281
[Path C: Hardware or network faults](references/path-c-hardware-network-faults.md).
282
- **Path D (`HANG_DETECTED` logs or hang event fired, but the analyzer is
283
`NOT_DETECTED` or reports `UNKNOWN`)**: Read
284
[Path D: No DETECTED analyzer or UNKNOWN cause](references/path-d-no-detected-or-unknown.md).
285
- **Path E (no `HANG_DETECTED` logs or hang events, and steady telemetry)**:
286
Read [Path E: Healthy telemetry](references/path-e-healthy-telemetry.md).
287
288
---
289
290
## Guardrails
291
292
1. **Never change GKE-managed instance groups or VMs through Compute Engine**:
293
Don't run `gcloud compute instance-groups managed` commands, such as
294
`delete`, on a node pool's managed instance group. Handle nodes through GKE,
295
as described in
296
[Path C: Hardware or network faults](references/path-c-hardware-network-faults.md).
297
2. **Never cordon or replace nodes for compiler divergence or input stalls**: If
298
the analyzer reports a compiler or HLO divergence, a program queueing issue,
299
or a data input stall, don't cordon or replace TPU nodes. Follow
300
[Path A: Compiler or HLO divergence](references/path-a-compiler-hlo-divergence.md)
301
or
302
[Path B: Host program queueing or data input stall](references/path-b-program-queueing-input-stall.md)
303
instead.
304