Installation

Install as Agent Plugin Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install gke-ai-troubleshooting-tpu-performance-degradation@skills-hub

Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled). Plugin gke-ai-troubleshooting-tpu-performance-degradation v1.0.0 follows the Agent Plugins spec.

Install with the gh extension
gh skills-hub install gke-ai-troubleshooting-tpu-performance-degradation

Don't have the extension? Run gh extension install samueltauil/skills-hub first.

Download and extract to your repository:

.github/skills/gke-ai-troubleshooting-tpu-performance-degradation/

Extract the ZIP to .github/skills/ in your repo. The folder name must match gke-ai-troubleshooting-tpu-performance-degradation for Copilot to auto-discover it.

Skill Files (6)

SKILL.md 14.1 KB
---
name: gke-ai-troubleshooting-tpu-performance-degradation
description: >-
  Diagnose GKE Cloud TPU training throughput drops and step-time regressions
  (15%+ TPU duty-cycle drop) using ML Diagnostics Workload Monitoring (`gcloud
  alpha mldiagnostics monitored-events` /
  `hypercomputecluster.googleapis.com/v1alpha`) and 1-minute Cloud Monitoring
  system metrics (`kubernetes.io/node/accelerator/*`). Distinguishes hardware
  and network fabric throttling from workload resource bottlenecks (HBM
  capacity, host memory, or host CPU saturation). Use when TPU training
  throughput or duty cycle drops without crashing pods, when
  `PERFORMANCE_DEGRADATION` monitored events fire, or when triaging slow
  multi-slice training steps. Don't use for complete multi-slice XLA execution
  stalls with `HANG_DETECTED` logs (use gke-ai-troubleshooting-tpu-mxla-hang) or
  pod eviction/interruption restarts (use
  gke-ai-troubleshooting-jobset-interruption).
metadata:
  version: "1.0.1"
  category: AiAndMachineLearning
---

# Troubleshoot GKE TPU performance degradation with ML Diagnostics Workload Monitoring

Diagnose and mitigate Cloud TPU training throughput drops and step-time
regressions (`15%+` drop in TPU duty cycle) on Google Kubernetes Engine (GKE) by
correlating **ML Diagnostics Workload Monitoring** `MonitoredEvent` analyzer
reports with **1-minute Cloud Monitoring system metrics** and GKE node topology
labels.

---

## Attribution

**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
MUST read [Usage Attribution](references/attribution.md). For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix `gcloud` with
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-ai-troubleshooting-tpu-performance-degradation)"`
and append `agent-skills/1.0 (skill:gke-ai-troubleshooting-tpu-performance-degradation)` to `User-Agent` headers.

## Prerequisites

- **Tools**: Install the
  [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) (`gcloud` with
  `alpha` component for `gcloud alpha mldiagnostics`) and `kubectl`.
- **Cloud Billing & Project Configuration**: Verify an active billing account is
  linked (`gcloud billing projects describe {project_id}`), authenticate
  (`gcloud auth login`), set the target project (`gcloud config set project
  {project_id}`), and ensure `container.googleapis.com`,
  `monitoring.googleapis.com`, and `hypercomputecluster.googleapis.com` are
  enabled.
- **Supported workloads and GKE versions**: Google Cloud ML Diagnostics only
  supports JAX on TPUs (see
  [ML Diagnostics platform](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/overview.md.txt)).
  Workload Monitoring is enabled by default, supports the `jobset` and `job` GKE
  job types, and is compatible with GKE versions `1.36.0-gke.4681000` and later,
  as stated in
  [Configure GKE for ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/gke.md.txt).
  If a workload uses another framework (such as PyTorch) or another custom
  resource type, `gcloud alpha mldiagnostics` won't list ML runs or monitored
  events for it. On-demand profiling (Step 4 Path A) additionally requires the
  cluster setup described in that document.
- **Required IAM Roles**:
  - Cluster Director Editor (`roles/hypercomputecluster.editor`), the role
    listed in the "IAM permissions" section of
    [ML Diagnostics platform](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/overview.md.txt),
    for the ML Diagnostics CLI and API calls in this skill (ML runs, monitored
    events, and on-demand profiler sessions)
  - Monitoring Viewer (`roles/monitoring.viewer`) for the PromQL queries in Step
    2
  - Kubernetes Engine Viewer (`roles/container.viewer`) for the `kubectl get
    nodes` query in Step 3
  - For remediation (`[High Risk]` steps): Kubernetes Engine Cluster Admin
    (`roles/container.clusterAdmin`)
- **Reference Documentation**:
  - [ML Diagnostics platform](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/overview.md.txt)
    (Sections: "IAM permissions")
  - [Configure GKE for ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/gke.md.txt)
    (Sections: "Set up with gcloud CLI, Google Cloud console, or Terraform",
    "Manual installation", "Connection-operator")
  - [Workload monitoring with ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)
    (Sections: "Workload Monitoring and analyzers", "HBM Capacity Analyzer",
    "Host Memory Utilization Analyzer", "CPU Utilization Analyzer", "Access
    Workload Monitoring information through the API", "List all monitored
    events", "System Metrics")
  - [Get started with the ML Diagnostics CLI](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt)
    (Sections: "List machine learning runs", "Monitored-events commands", "List
    profiler targets", "Capture on-demand profiler sessions")
  - [Scale container resource requests and limits](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/vertical-pod-autoscaling.md.txt)
    (Sections: "Identify workloads without resource requests or limits")
  - [Auto-repair nodes](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/node-auto-repair.md.txt)
    (Sections: "Repair criteria", "Verify node auto-repair is enabled for a
    Standard node pool", "Enable auto-repair for an existing Standard node
    pool", "Node auto repair in TPU slice nodes")
  - [Deploy TPU workloads in GKE Standard](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/tpus.md.txt)
    (Sections: "Configure auto repair for TPU slice nodes")
  - [Get support](https://docs.cloud.google.com/kubernetes-engine/docs/getting-support.md.txt)
    (Sections: "Before you contact support")

> **Read-only rule**: Run read-only diagnostic commands only. Never drain,
> delete, or re-create nodes, or run any other command that changes the cluster.
> Give the user any fix to apply themselves.

When you recommend a fix, link the doc section that describes it.

---

## Analyzer routing overview

By default, Workload Monitoring treats a 15% drop in TPU duty cycle as a
performance degradation, raises a `MonitoredEvent` (`type:
PERFORMANCE_DEGRADATION`), and runs its analyzers. Consult the
[Workload Monitoring and analyzers](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)
section in the official Cloud TPU documentation for the complete analyzer
definitions, detection criteria, and subsections, and route remediation by
category:

- **Category A: workload resource bottlenecks (never cordon or replace nodes)**:
  - When the firing analyzer (`detectionState: "DETECTED"`) indicates a workload
    memory or host CPU capacity bottleneck (see the "HBM Capacity Analyzer",
    "Host Memory Utilization Analyzer", and "CPU Utilization Analyzer" sections
    of
    [Workload monitoring with ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)),
    route to
    [Path A: Workload resource bottlenecks](references/path-a-workload-bottlenecks.md)
    (workload optimization and profiling).
- **Category B: infrastructure and network fabric throttling (culprit nodes)**:
  - When the firing analyzer (`detectionState: "DETECTED"`) indicates an
    interconnect, thermal/power throttling, memory bandwidth, or Top-of-Rack
    (ToR) network fault on specific instances (see
    [Workload Monitoring and analyzers](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)),
    route to
    [Path B: Infrastructure or network fabric throttling](references/path-b-infrastructure-throttling.md)
    (map the culprit Compute Engine instance IDs to GKE nodes, handle node
    repair through GKE, and escalate to Google Cloud Support).
- **Category C: `PERFORMANCE_DEGRADATION` event fired, but no analyzer reports
  `detectionState: "DETECTED"`**:
  - When a `PERFORMANCE_DEGRADATION` event exists (as in the sample output in
    [List all monitored events](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt),
    where `analyzerReports` entries have `detectionState: "NOT_DETECTED"`),
    route to
    [Path C: Event fired with no DETECTED analyzer](references/path-c-no-detected-analyzer.md).

---

## Diagnostic workflow

### Step 0: Collect context and set the investigation window `[Low Risk]`

Collect the target parameters. By default, query a 60-minute window `[T - 30m, T
+ 30m]` around `{issue_time}`:

- `{project_id}`: Google Cloud project ID
- `{location}`: Google Cloud region where the ML run and GKE cluster reside (for
  example, `us-central1`)
- `{cluster_name}`: GKE cluster name
- `{workload_name}` / `{ml_run_id}`: JobSet / workload name or ML Diagnostics
  run ID
- `{issue_time}`: Timestamp when throughput degradation was observed (`T`,
  ISO-8601 UTC)
- `{start_time}`: `T - 30m`
- `{end_time}`: `T + 30m`

---

### Step 1: Query ML runs and `monitoredEvents` `[Low Risk]`

1. **List active or recent ML runs**: Give the user `gcloud alpha mldiagnostics
   machine-learning-run list` with a link to
   [List machine learning runs](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt)
   in the ML Diagnostics CLI reference, and locate `{ml_run_id}` matching
   `{workload_name}`.
2. **List performance degradation events**: Give the user `gcloud alpha
   mldiagnostics monitored-events list` with a link to
   [Monitored-events commands](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt),
   or the `hypercomputecluster.googleapis.com/v1alpha` API with a link to
   [Access Workload Monitoring information through the API](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt),
   to check for `PERFORMANCE_DEGRADATION` events during `[{start_time},
   {end_time}]`.
3. **Describe the `MonitoredEvent`**: Give the user `gcloud alpha mldiagnostics
   monitored-events describe` with a link to the same
   [Monitored-events commands](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt)
   section, and inspect the `analyzerReports` array (`analyzer`,
   `detectionState`, `details`, and `recommendedActions`).
   - If a `PERFORMANCE_DEGRADATION` event fired, run Step 2 to corroborate with
     the 1-minute system metrics; if none of its `analyzerReports` entries has
     `detectionState: "DETECTED"`, follow
     [Path C: Event fired with no DETECTED analyzer](references/path-c-no-detected-analyzer.md).
   - If no `PERFORMANCE_DEGRADATION` event exists and duty cycle is steady in
     Step 2, **rule out** TPU performance degradation by following
     [Path D: Healthy telemetry](references/path-d-healthy-telemetry.md).

---

### Step 2: Correlate with 1-minute Cloud Monitoring system metrics `[Low Risk]`

Consult the
[System Metrics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt)
section in the Workload Monitoring documentation for the 1-minute Cloud
Monitoring metrics exported for TPU and host devices, and run read-only PromQL
queries over `[{start_time}, {end_time}]` to corroborate the analyzer report:

```promql
# 1. Node TPU duty cycle (look for the drop on the affected nodes)
kubernetes_io:node_accelerator_duty_cycle{
  monitored_resource="k8s_node",
  project_id="{project_id}",
  cluster_name="{cluster_name}"
}

# 2. HBM utilization ratio by node (around 0.90 is approaching the limit)
sum by (node_name) (
  kubernetes_io:node_accelerator_memory_used{
    monitored_resource="k8s_node",
    project_id="{project_id}",
    cluster_name="{cluster_name}"
  }
)
/
sum by (node_name) (
  kubernetes_io:node_accelerator_memory_total{
    monitored_resource="k8s_node",
    project_id="{project_id}",
    cluster_name="{cluster_name}"
  }
)

# 3. Host memory and CPU allocatable utilization
kubernetes_io:node_memory_allocatable_utilization{
  monitored_resource="k8s_node",
  project_id="{project_id}",
  cluster_name="{cluster_name}"
}

kubernetes_io:node_cpu_allocatable_utilization{
  monitored_resource="k8s_node",
  project_id="{project_id}",
  cluster_name="{cluster_name}"
}
```

---

### Step 3: Map culprit instance IDs to GKE nodes and topology `[Low Risk]`

When an infrastructure analyzer reports culprit numeric Compute Engine instance
IDs in `details` or `recommendedActions`, map those numeric instance IDs to GKE
`Node` names and physical topology blocks using this read-only `kubectl` query
inspecting `container.googleapis.com/instance_id`:

```bash
kubectl get nodes -l cloud.google.com/gke-tpu-accelerator \
  -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}'
```

---

### Step 4: Remediation by analyzer category

Load and follow only the reference file that matches the analyzer category from
Step 1:

- **Path A (workload resource bottlenecks — HBM, host memory, or host CPU
  utilization)**: Read
  [Path A: Workload resource bottlenecks](references/path-a-workload-bottlenecks.md).
- **Path B (infrastructure, thermal, ICI, memory bandwidth, or network fabric
  throttling)**: Read
  [Path B: Infrastructure or network fabric throttling](references/path-b-infrastructure-throttling.md).
- **Path C (`PERFORMANCE_DEGRADATION` event fired with all analyzers
  `NOT_DETECTED`)**: Read
  [Path C: Event fired with no DETECTED analyzer](references/path-c-no-detected-analyzer.md).
- **Path D (no `PERFORMANCE_DEGRADATION` events and steady telemetry)**: Read
  [Path D: Healthy telemetry](references/path-d-healthy-telemetry.md).

---

## Guardrails

1. **Never change GKE-managed instance groups or VMs through Compute Engine**:
   Don't run `gcloud compute instance-groups managed` commands, such as
   `delete`, on a node pool's managed instance group. Handle nodes through GKE,
   as described in
   [Path B: Infrastructure or network fabric throttling](references/path-b-infrastructure-throttling.md).
2. **Never cordon nodes for workload resource saturation**: If only the HBM
   capacity, host memory, or host CPU utilization analyzers detected an issue,
   don't cordon or replace nodes.
references/
attribution.md 1.9 KB
# Usage Attribution

**MUST READ**: Before executing any `gcloud`, REST API, or MCP command with
this skill, follow these usage attribution instructions. Tag every command you
execute directly in the terminal so usage can be attributed. The tag identifies
only the skill and its version; it carries no user data.

-   **`gcloud` CLI Commands**: Prefix every `gcloud` invocation, whatever the
    subcommand, with the metrics environment variable. Set it inline on each
    command because shell state may not persist between commands:

    ```bash
    CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-ai-troubleshooting-tpu-performance-degradation)" \
    gcloud <command> [flags]
    ```

    Do not use `gcloud config set` for this: it would persist beyond the current
    task and mislabel unrelated usage.

-   **Direct HTTP, REST, and MCP Requests**: On direct HTTP calls to Google
    Cloud APIs (for example with `curl`) or HTTP requests to a remote MCP
    server, include `agent-skills/1.0 (skill:gke-ai-troubleshooting-tpu-performance-degradation)` in the `User-Agent`
    header. If a `User-Agent` header is already specified, append this string to
    the end of it rather than overwriting existing `User-Agent` data — the
    collection pipeline parses the `agent-skills/<version>` and `skill:<name>`
    tokens, so any rewording breaks attribution:

    ```
    User-Agent: <existing_user_agent> agent-skills/1.0 (skill:gke-ai-troubleshooting-tpu-performance-degradation)
    ```

-   **Constraint for Generated Code**: The tracking prefix is strictly for
    commands you execute directly in the terminal. Do NOT include this tracking
    prefix in generated scripts, Terraform templates, or code provided to the
    user for their own repositories.

-   **User Opt-Out**: If the user asks to disable or remove tracking or
    attribution tags, omit the `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION` variable
    and custom `User-Agent` suffix from all commands.
path-a-workload-bottlenecks.md 2.3 KB
# Path A: Workload resource bottlenecks `[Low Risk]`

> **Guardrail**: Don't cordon, drain, or replace GKE TPU nodes when performance
> degradation is caused by the HBM capacity, host memory, or host CPU
> utilization analyzers. The documented actions for these analyzers are workload
> changes.

1. **Capture an on-demand profile (when on-demand profiling is set up)**:
   - Follow the "List profiler targets" and "Capture on-demand profiler
     sessions" sections of
     [Get started with the ML Diagnostics CLI](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt)
     (`gcloud alpha mldiagnostics profiler-target list` and `gcloud alpha
     mldiagnostics profiler-session capture`) to capture a profile on the
     affected workload.
   - As documented in those sections, both commands require that on-demand XProf
     is enabled in the workload (which deploys the XProf server on the workload
     nodes) and that the GKE cluster is set up for ML Diagnostics
     (`connection-operator` deployed). If `profiler-target list` returns no
     targets because these prerequisites are not configured, point the user to
     [Configure GKE for ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/gke.md.txt)
     (Sections: "Set up with gcloud CLI, Google Cloud console, or Terraform",
     "Manual installation") so they can set up on-demand profiling, and continue
     with item 2 below in the meantime.
2. **Suggest workload mitigations for the user to apply, and link the doc
   section for each**:
   - For HBM saturation, follow the guidance in
     [HBM Capacity Analyzer](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt):
     collect XProf profiles to analyze HBM usage, and consider reducing the
     batch size or adjusting model parameters.
   - For host memory or CPU saturation, follow the "Host Memory Utilization
     Analyzer" and "CPU Utilization Analyzer" sections of
     [Workload monitoring with ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/workload-monitoring.md.txt),
     and
     [Identify workloads without resource requests or limits](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/vertical-pod-autoscaling.md.txt),
     to right-size pod resource requests or reduce host data-loader overhead.
path-b-infrastructure-throttling.md 2.2 KB
# Path B: Infrastructure or network fabric throttling `[High Risk]`

When an infrastructure analyzer reports `detectionState: "DETECTED"` on specific
instances:

1. **Identify the culprit node**: Provide the `kubectl get nodes` command from
   Step 3 of `SKILL.md` to map the reported instance IDs to GKE node names, and
   review the analyzer report's `recommendedActions`.
2. **Handle node repair through GKE, not Compute Engine**:
   - Don't change the node's VM or the node pool's managed instance group
     through Compute Engine.
   - GKE node auto-repair repairs nodes that meet the
     [Repair criteria](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/node-auto-repair.md.txt),
     which states that a node reporting a `Ready` status is considered healthy.
     None of the listed repair conditions, including the TPU slice conditions in
     [Configure auto repair for TPU slice nodes](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/tpus.md.txt),
     mention thermal/power throttling or ICI link issues. Because a throttled or
     ICI-degraded node can stay `Ready`, auto-repair might not catch this
     condition, so opening the support case in item 3 below is the main action.
   - If the node does transition to an unhealthy condition, Autopilot clusters
     always auto-repair nodes, and Standard cluster users can check or turn on
     auto-repair by following the "Verify node auto-repair is enabled for a
     Standard node pool" and "Enable auto-repair for an existing Standard node
     pool" sections of
     [Auto-repair nodes](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/node-auto-repair.md.txt)
     (note per "Node auto repair in TPU slice nodes" in that document that GKE
     re-creates the entire multi-host TPU slice node pool when a node in it
     needs repair).
3. **Escalate to Google Cloud Support (main action)**:
   - Follow
     [Get support](https://docs.cloud.google.com/kubernetes-engine/docs/getting-support.md.txt)
     and open a support case with the `MonitoredEvent` resource name
     (`projects/{project_id}/locations/{location}/machineLearningRuns/{ml_run_id}/monitoredEvents/{event_id}`),
     the firing analyzer report, and the mapped Compute Engine instance ID and
     GKE `{node_name}`.
path-c-no-detected-analyzer.md 1.5 KB
# Path C: Event fired with no `DETECTED` analyzer `[Low Risk]`

When a `PERFORMANCE_DEGRADATION` event exists in `[{start_time}, {end_time}]`
(Step 1 of `SKILL.md`), meaning Workload Monitoring observed a 15% or greater
drop in TPU duty cycle, but every entry in `analyzerReports` has
`detectionState: "NOT_DETECTED"`:

1. **Do not cordon, drain, or replace nodes**: No analyzer identified a culprit
   instance or hardware fault.
2. **Share what the Step 2 metrics show**: Report which nodes show the TPU
   duty-cycle drop in `kubernetes_io:node_accelerator_duty_cycle` and whether
   HBM, host memory, or host CPU utilization shifted during the event window.
3. **Suggest an on-demand profile if set up**: Suggest capturing a profile as in
   item 1 of
   [Path A: Workload resource bottlenecks](path-a-workload-bottlenecks.md)
   (`gcloud alpha mldiagnostics profiler-target list` and `profiler-session
   capture` in
   [Get started with the ML Diagnostics CLI](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/cli.md.txt))
   if on-demand XProf and the cluster's ML Diagnostics `connection-operator` are
   configured (or link
   [Configure GKE for ML Diagnostics](https://docs.cloud.google.com/tpu/docs/ml-diagnostics/gke.md.txt)
   if not yet set up). If the drop persists without a clear workload cause, the
   user can open a support case
   ([Get support](https://docs.cloud.google.com/kubernetes-engine/docs/getting-support.md.txt))
   with the `MonitoredEvent` resource name and the Step 2 metric findings.
path-d-healthy-telemetry.md 0.3 KB
# Path D: Healthy telemetry (rule out performance degradation) `[Low Risk]`

If there are no `PERFORMANCE_DEGRADATION` events in the window, TPU duty cycle
shows no drop of 15% or more, and HBM and host memory aren't close to their
limits, rule out TPU performance degradation. Tell the user that no remediation
is needed.

License (Apache-2.0)

View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/google/skills/blob/main/LICENSE