Every Trial in a Katib Experiment tuning a Kubeflow TrainJob ends MetricsUnavailable although each TrainJob reaches Complete — what do you check, and in what order?
answer
- the job ran, the reading failed
- a sidecar has to be injected first
- which pod and which container it wraps
- name=value lines and a default regex
- counted as failures toward the limit
basics
~10 sTrace the default StdOut collector: the namespace needs the label katib.kubeflow.org/metrics-collector-injection: enabled, the sidecar wraps only the first node pod's primary container, and that process must print objectiveMetricName=value lines the default metricsFormat regex parses.
solid answer
~40 sIn Katib 0.19 an Experiment with no `metricsCollectorSpec` uses the pull-based `StdOut` collector: a sidecar reads the primary container's standard output and parses metric lines. `MetricsUnavailable` with a `Complete` TrainJob means the job ran but nothing was parsed. Check, in order: (1) the namespace carries `katib.kubeflow.org/metrics-collector-injection: enabled`, or no sidecar is ever injected; (2) the right pod and container are wrapped: for a TrainJob Katib defaults `primaryPodLabels` to the `node` replicated job at completion index 0, and `primaryContainerName` must be `node` in the shipped runtimes, so a metric printed only on another node is never seen; (3) the line format: the default `metricsFormat` regex needs `name=value`, so `val_loss=0.214` parses and `val_loss: 0.214` does not, and the name must equal `objectiveMetricName`. These trials count as failed, so reaching `maxFailedTrialCount` fails the Experiment.
code
yaml · 14 lines# Experiment excerpt: accept "val_loss: 0.214" lines instead of name=value
spec:
objective:
type: minimize
objectiveMetricName: val_loss
metricsCollectorSpec:
collector:
kind: StdOut
source:
filter:
metricsFormat:
- "([\\w|-]+)\\s*:\\s*([+-]?\\d*(\\.\\d+)?([Ee][+-]?\\d+)?)"
trialTemplate:
primaryContainerName: nodego deeper
Know that Katib needs the training code to print the objective metric as name=value lines it can read.
Explain the StdOut collector path: namespace label, sidecar on pods matching primaryPodLabels, primaryContainerName, and the default metricsFormat regex.
Diagnose in order, from injection to pod selection to line format, and recognise the TrainJob defaults: node replicated job, completion index 0, condition Complete.
Set a team convention for reporting metrics, print format or push, so that tuning runs on shared GPUs never burn a full budget on trials that cannot report.
## What MetricsUnavailable means A **Trial** in Katib 0.19 has two independent outcomes: whether its worker job succeeded, and whether Katib collected the objective metric. A Kubeflow Trainer `TrainJob` that reaches `Complete` satisfies the first. If the second is missing, the Trial ends with the condition **`MetricsUnavailable`**. Katib counts those trials as failed: once `Failed` plus `MetricsUnavailable` trials reach `maxFailedTrialCount`, the Experiment ends `Failed`. When every Trial ends this way, the cause is almost always in the collection path rather than in training. ## How the default collector reaches a TrainJob With no `metricsCollectorSpec`, Katib defaults the collector `kind` to **`StdOut`**, a pull-based collector. The path has five links, and any one of them can break: 1. **Injection is enabled** for the namespace by the label `katib.kubeflow.org/metrics-collector-injection: enabled`. 2. **A sidecar is added** to pods that match the trial template's `primaryPodLabels`. 3. **The sidecar follows the standard output** of the container named by `primaryContainerName`. 4. **Each line is matched** against the `metricsFormat` patterns, by default `([\w|-]+)\s*=\s*([+-]?\d*(\.\d+)?([Ee][+-]?\d+)?)`. The first group is the metric name, the second its value. 5. **Matches are stored** through `katib-db-manager`, and the Trial reads the objective from there as its `observation`. ## Check 1: the namespace label Without the label nothing is injected, and every Trial ends `MetricsUnavailable` regardless of what the script prints. Look at the namespace's labels first, and at a trial pod: if it has only the training container, injection never happened. The fix is one command, `kubectl label namespace doc-ai katib.kubeflow.org/metrics-collector-injection=enabled`, before the next Experiment. If the trial template sets `retain: true`, as the Kubeflow SDK always does, each trial's TrainJob is kept after it finishes for inspection. The Kubeflow SDK reads the sidecar's output from a container named `metrics-logger-and-collector`, and its absence from the pod is the clearest sign that injection never ran. ## Check 2: which pod, which container A four-node TrainJob has four node pods, and Katib does not wrap them all. For a TrainJob it defaults: | Setting | Default for a TrainJob trial | Default for a v1 Kubeflow job trial | |---|---|---| | `primaryPodLabels` | `jobset.sigs.k8s.io/replicatedjob-name: node` and `batch.kubernetes.io/job-completion-index: "0"` | `training.kubeflow.org/job-role: master` | | `successCondition` | condition type `Complete` | condition type `Succeeded` | - The metric must therefore be printed **by the process on the first node pod**. Code that prints from global rank 0 does that; code that prints from the last rank, or from every rank except the first node's, does not. - **`primaryContainerName`** must match the training container. The shipped runtimes name it `node`; a template that says `training-container`, copied from an older example, points the sidecar at a container that does not exist in the pod. ## Check 3: the line format - `val_loss=0.214` and `val_loss = 2.1e-01` match the default pattern. - `val_loss: 0.214` does not, because the pattern needs `=`. - A dictionary such as `{'val_loss': 0.214}` does not. - `val/loss=0.214` cannot be captured under its full name, since `/` is outside the name group; at most the tail `loss` matches, which is not the objective. - The captured name must equal `objectiveMetricName` exactly; `loss` printed for an objective called `val_loss` is never recorded. ## Fixes, least to most invasive 1. **Print what the default expects**, one `name=value` line per report, from the first node's primary process. 2. **Change the pattern** with `metricsCollectorSpec.source.filter.metricsFormat` when the script's format cannot change. 3. **Write to a file** with the `File` collector; its default path is `/var/log/katib/metrics.log` and its default format `TEXT`, and `JSON` lines are also accepted. 4. **Push instead of pull** with the `Push` collector: the script calls `report_metrics()` from the `kubeflow-katib` package, which must then be installed in the training image. 5. **Override the primary pod** by setting `primaryPodLabels` explicitly, when the process that knows the metric runs somewhere else. ## Before the next run The Experiment's status already tells you how widespread the problem is: `trialMetricsUnavailable` counts the affected trials and `metricsUnavailableTrialList` names them, next to `trialsSucceeded` and `trialsFailed`. If only some trials are affected, compare one good and one bad trial's logs; an intermittent miss usually points at a code path that sometimes skips the print, such as an evaluation step that only runs every few epochs. Run one trial by hand, with `parallelTrialCount: 1` and `maxTrialCount: 1`, and read the trial pod's sidecar logs before launching a dozen 32-GPU trials. A collection problem costs one trial that way instead of the whole search, and `maxFailedTrialCount` stops a repeat early.
- Why does Katib stop the whole Experiment instead of just skipping trials with no metric?Katib treats `MetricsUnavailable` like `Failed` when it counts against `maxFailedTrialCount`, because a trial with no observation gives the search nothing to learn from. When the count reaches the limit, the Experiment gets a `Failed` condition. Without `maxFailedTrialCount`, nothing stops a systematic collection error early.
- When would you choose the Push collector over StdOut?When the metric is hard to print in a parseable line, or when you want no sidecar in the pod. With `collector.kind: Push` the training code calls `report_metrics()` from the `kubeflow-katib` package, which sends the values to the Katib DB manager over gRPC with a timestamp. The cost is a Katib dependency inside the training image.
- MetricsUnavailable means the training job itself failed
- Katib reads metrics from every pod of the TrainJob
- Any line containing the metric name is parsed, whatever its format
- MetricsUnavailable trials do not count toward maxFailedTrialCount
- The metrics sidecar is injected in every namespace by default
Assumes Katib 0.19.0, whose Experiment defaults set the StdOut collector and TrainJob-specific primaryPodLabels and successCondition for Kubeflow Trainer v2.3.0 TrainJobs.