skip to content

How do Katib's Experiment, Suggestion and Trial objects split the tuning of a Kubeflow TrainJob, and how many trials run at once by default?

level: middleimportance: should knowfreq 8%

answer

  1. one spec, one proposer, many runs
  2. trialParameters reference the search space
  3. the Trial renders and creates the TrainJob
  4. parallelTrialCount when left unset
  5. maxFailedTrialCount ends it as Failed

basics

~20 s

The Experiment declares objective, search space, algorithm, limits and a trialTemplate; its Suggestion obtains parameter assignments from the algorithm; each assignment becomes a Trial that renders and runs one TrainJob and records its metric. parallelTrialCount defaults to 3.

solid answer

~40 s

In Katib 0.19 all three kinds live in `kubeflow.org/v1beta1`. The **Experiment** holds the `objective` (`type`, `objectiveMetricName`, optional `goal`), the `algorithm`, the `parameters` (search space), a `trialTemplate` whose `trialSpec` is the TrainJob with `${trialParameters.<name>}` placeholders, and the limits `parallelTrialCount` (default 3), `maxTrialCount` and `maxFailedTrialCount`. The controller keeps one **Suggestion** for the Experiment; its `spec.requests` asks the algorithm service for assignments, which appear in `status.suggestions`. Each assignment becomes a **Trial**, which substitutes the values into the template, creates the TrainJob, waits for its success or failure condition and stores the collected metric as its observation. The Experiment succeeds when `maxTrialCount` trials have succeeded or the goal is reached, and fails when failed trials reach `maxFailedTrialCount`. Left at the default, a dozen four-node trials run three TrainJobs at a time.

code

yaml · 28 lines
yaml
apiVersion: kubeflow.org/v1beta1
kind: Experiment
metadata:
  name: layout-lr-warmup
  namespace: doc-ai
spec:
  objective: {type: minimize, objectiveMetricName: val_loss}
  algorithm: {algorithmName: random}
  parallelTrialCount: 2
  maxTrialCount: 12
  maxFailedTrialCount: 3
  parameters:
    - {name: lr, parameterType: double, feasibleSpace: {min: "0.00001", max: "0.0003", distribution: logUniform}}
    - {name: warmup_steps, parameterType: int, feasibleSpace: {min: "200", max: "2000"}}
  trialTemplate:
    primaryContainerName: node
    trialParameters:
      - {name: learningRate, reference: lr}
      - {name: warmupSteps, reference: warmup_steps}
    trialSpec:
      apiVersion: trainer.kubeflow.org/v1alpha1
      kind: TrainJob
      spec:
        runtimeRef: {name: torch-distributed}
        trainer:
          numNodes: 4
          image: registry.internal.example/doc-ai/layout-train:1.4
          command: ["torchrun", "/workspace/train.py", "--lr=${trialParameters.learningRate}", "--warmup-steps=${trialParameters.warmupSteps}"]

go deeper

for a junior

Recall the three Katib objects: an Experiment defines the search, a Suggestion proposes values, and each Trial runs one job with one set of values.

for a middle

Explain the loop: Suggestion requests and assignments, Trials rendering trialSpec through trialParameters, and the parallelTrialCount default of 3 with maxTrialCount and maxFailedTrialCount as stop rules.

for a senior

Size an Experiment against GPU capacity: set parallelTrialCount from what tuning may hold, cap failures, and know the TrainJob-specific defaults for success condition and primary pod.

for a principal

Judge how much cluster capacity tuning may take next to production training, and whether experiments run in a shared queue or a dedicated budget per team.

## Three kinds, one tuning run **Katib** is Kubeflow's hyperparameter tuning system, and release 0.19 (October 2025) defines its objects under `kubeflow.org/v1beta1`: - An **Experiment** is one tuning run: what to optimise, over which values, with which algorithm, and how to run each attempt. - A **Suggestion** is the Experiment's channel to the search algorithm. Its `spec.requests` says how many parameter assignments are wanted so far, and `status.suggestions` lists the assignments returned. - A **Trial** is one attempt with one assignment. It owns one worker object, here a Kubeflow Trainer `TrainJob`. The `katib-controller` reconciles all three, and the metrics trials report reach the Katib database through `katib-db-manager`. ## The Experiment spec | Field | Role | Default when omitted | |---|---|---| | `objective` | `type` (`minimize` or `maximize`), `objectiveMetricName`, optional `goal`, `additionalMetricNames` | none | | `algorithm` | `algorithmName`, such as `random`, `grid`, `bayesianoptimization`, `tpe`, `hyperband` | none | | `parameters` | `name`, `parameterType` (`int`, `double`, `discrete`, `categorical`), `feasibleSpace` | distribution `uniform` | | `trialTemplate` | `trialSpec`, `trialParameters`, `primaryContainerName`, success and failure conditions | conditions defaulted per kind | | `parallelTrialCount` | Most trials running at once | `3` | | `maxTrialCount` | Succeeded trials needed to finish | none: runs until the goal or the failure limit | | `maxFailedTrialCount` | Failed trials that end the Experiment | none | | `metricsCollectorSpec` | How metrics are read | `StdOut` collector | | `earlyStopping` | Optional rule, for example `medianstop` | none | | `resumePolicy` | What may happen after the Experiment ends | `Never` | How an algorithm chooses its next assignment is search theory, covered with model selection; Katib's part is the objects that carry the request and the answer. ## The loop 1. The controller creates the Experiment's Suggestion with the algorithm settings, and its `spec.requests` records how many assignments have been asked for so far. 2. The algorithm service fills `status.suggestions` with parameter assignments. 3. For each new assignment the controller creates a Trial. The Trial's `runSpec` is the `trialSpec` with every `${trialParameters.learningRate}`-style placeholder replaced. Each entry in `trialParameters` maps a placeholder `name` to a search-space parameter through `reference`. 4. The Trial creates the TrainJob and watches it. For a TrainJob, Katib 0.19 defaults the `successCondition` to a `Complete` condition and the `failureCondition` to `Failed`. 5. The metrics collector records the objective, and the Trial stores it as its `observation`. A Trial with no metric ends `MetricsUnavailable`; early stopping can end one `EarlyStopped`. 6. The Experiment updates its counts and `currentOptimalTrial`, then asks for more until it succeeds (goal reached, or `maxTrialCount` trials succeeded) or fails (failed trials, including `MetricsUnavailable` ones, reach `maxFailedTrialCount`). ## A dozen trials of a 32-GPU job Suppose a document-AI team tunes learning rate and warm-up steps for a layout-detection transformer, with each trial a TrainJob of four nodes and eight GPUs. With `maxTrialCount: 12` and `parallelTrialCount` left out: - **Three TrainJobs run at once**, because the default is 3. That is 96 GPUs held by tuning. - **Twelve trials take about four rounds** if each trial runs for a similar time. - **Nothing caps failures** unless `maxFailedTrialCount` is set, so a systematic error, such as a bad image tag, can burn through many trials before anyone notices. Set `parallelTrialCount` deliberately from the GPUs the team may hold, and set `maxFailedTrialCount` so a systematic error ends the Experiment early. The Kubeflow SDK's `OptimizerClient` writes `parallelTrialCount` explicitly, from `TrialConfig.parallel_trials`, which defaults to 1. ## Watching an Experiment `kubectl get experiment layout-lr-warmup -n doc-ai -o yaml` shows the running totals in `status`: `trials`, `trialsSucceeded`, `trialsFailed`, `trialsRunning`, `trialsPending`, `trialsEarlyStopped` and `trialMetricsUnavailable`, plus lists of trial names for each state. `status.currentOptimalTrial` names the best trial so far in `bestTrialName` and repeats its `parameterAssignments` and `observation`. `kubectl get trials -n doc-ai` lists every Trial with its condition, and `kubectl get suggestions -n doc-ai` shows, for the Experiment's Suggestion, how many assignments have been requested and returned. The Experiment's own conditions move through `Created` and `Running` to `Succeeded` or `Failed`. ## Where the TrainJob specifics enter - **Primary pod.** Katib 0.19 defaults `primaryPodLabels` for a TrainJob to `jobset.sigs.k8s.io/replicatedjob-name: node` and `batch.kubernetes.io/job-completion-index: "0"`, so its metrics sidecar wraps the first node pod only. - **Primary container.** `primaryContainerName` must name the training container, `node` in the shipped runtimes. - **Retention.** `trialTemplate.retain: true` keeps each trial's TrainJob after it finishes, which helps when reading logs.

  • What makes a Katib Experiment end before maxTrialCount trials have succeeded?
    Two things. If the objective metric of a trial reaches `objective.goal`, the Experiment succeeds early. If failed trials, counting both `Failed` and `MetricsUnavailable`, reach `maxFailedTrialCount`, it ends with a `Failed` condition. Without a `goal` and without `maxTrialCount`, it runs until the failure limit is hit.
  • How would you stop clearly bad trials early instead of letting each TrainJob finish?
    Add an `earlyStopping` section with `algorithmName: medianstop`. Its settings, such as `min_trials_required` and `start_step`, decide when a running trial is compared with completed ones; a trial judged worse is stopped and marked `EarlyStopped`, and Katib asks the Suggestion for another assignment.

  • Katib runs every trial at once unless you set parallelTrialCount
  • Each Trial asks the search algorithm directly for its parameters
  • trialParameters hold the search ranges themselves
  • maxTrialCount is required, or the Experiment never starts
  • MetricsUnavailable trials do not count toward maxFailedTrialCount

Assumes Katib 0.19.0 (kubeflow.org/v1beta1), which recognises a Kubeflow Trainer v2.3.0 TrainJob as a trial worker kind.