Katib UI hyperparameter tuning
Scenario 8. Real Hyperparameter Tuning in Katib via UI
Objective
Verify that Katib:
creates an Experiment from the UI,
generates different hyperparameter values,
runs a real model training workload,
collects the
lossmetric,compares Trial results,
selects the best Trial,
finishes the Experiment with the
Succeededstatus.
This is not only an infrastructure smoke test. Each Trial runs one real MNIST training epoch with different lr and momentum values.
Preconditions
The user has the Editor role in the target namespace.
The namespace has the following label:
katib.kubeflow.org/metrics-collector-injection=enabled
The test is executed in the following namespace:
test
The Experiment name is not already in use.
1. Metadata
Set:
Name: katib-form-real-tuning
2. Trial Thresholds
Set:
Parallel Trial Count: 1
Max Trial Count: 3
Max Failed Trial Count: 1
Resume Policy: Never
Meaning:
Katib runs 3 Trials in total.
Trials run one after another.
One failed Trial is allowed.
3. Objective
Set:
Type: Minimize
Goal: 0.0001
Objective Metric Name: loss
Additional Metrics: leave empty
The low Goal value ensures that Katib should execute all 3 Trials instead of stopping after the first successful result.
4. Search Algorithm
Set:
Hyper Parameter Tuning
Name: Random
random_state: 10
5. Early Stopping
Set:
None
6. Hyperparameters
Parameter 1
Name: lr
Type: double
Min: 0.01
Max: 0.05
Step: leave empty
Parameter 2
Name: momentum
Type: double
Min: 0.5
Max: 0.9
Step: leave empty
7. Metrics Collector
Set:
Collector Type: StdOut
The training script prints the metric in the following format:
loss=<value>
8. Trial Template
Set:
Primary Container Name: training-container
Pod Labels: none
Retain: True
Source Type: YAML
Keep the default conditions:
Success Condition:
status.conditions.#(type=="Complete")#|#(status=="True")#
Failure Condition:
status.conditions.#(type=="Failed")#|#(status=="True")#
Paste the following YAML into the Trial Template editor:
apiVersion: batch/v1
kind: Job
spec:
backoffLimit: 0
template:
metadata:
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
- name: training-container
image: ghcr.io/kubeflow/katib/pytorch-mnist-cpu:v0.18.0
command:
- python3
- /opt/pytorch-mnist/mnist.py
- --epochs=1
- --batch-size=512
- --test-batch-size=1000
- --log-interval=10
- --no-cuda
- --lr=${trialParameters.learningRate}
- --momentum=${trialParameters.momentum}
resources:
requests:
cpu: "200m"
memory: "256Mi"
limits:
cpu: "1"
memory: "1Gi"
restartPolicy: Never
Set the Trial parameter mapping:
Name |
Reference |
|---|---|
|
|
|
|
9. Edit and Submit YAML
After opening the full YAML editor, verify that the manifest looks like this:
apiVersion: kubeflow.org/v1beta1
kind: Experiment
metadata:
name: katib-form-real-tuning
namespace: test
spec:
maxTrialCount: 3
parallelTrialCount: 1
maxFailedTrialCount: 1
resumePolicy: Never
objective:
type: minimize
goal: 0.0001
objectiveMetricName: loss
additionalMetricNames: []
algorithm:
algorithmName: random
algorithmSettings:
- name: random_state
value: "10"
parameters:
- name: lr
parameterType: double
feasibleSpace:
min: "0.01"
max: "0.05"
- name: momentum
parameterType: double
feasibleSpace:
min: "0.5"
max: "0.9"
metricsCollectorSpec:
collector:
kind: StdOut
trialTemplate:
primaryContainerName: training-container
successCondition: status.conditions.#(type=="Complete")#|#(status=="True")#
failureCondition: status.conditions.#(type=="Failed")#|#(status=="True")#
retain: true
trialParameters:
- name: learningRate
reference: lr
description: ""
- name: momentum
reference: momentum
description: ""
trialSpec:
apiVersion: batch/v1
kind: Job
spec:
backoffLimit: 0
template:
metadata:
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
- name: training-container
image: ghcr.io/kubeflow/katib/pytorch-mnist-cpu:v0.18.0
command:
- python3
- /opt/pytorch-mnist/mnist.py
- --epochs=1
- --batch-size=512
- --test-batch-size=1000
- --log-interval=10
- --no-cuda
- --lr=${trialParameters.learningRate}
- --momentum=${trialParameters.momentum}
resources:
requests:
cpu: "200m"
memory: "256Mi"
limits:
cpu: "1"
memory: "1Gi"
restartPolicy: Never
Click Create / Submit.
Expected Execution Flow
The Experiment changes from
CreatedtoRunning.Katib creates the first Trial.
Training progress and
lossvalues appear in the Trial logs.After the first Trial finishes, Katib starts the next Trial.
A total of 3 Trials are executed.
Each Trial receives different
lrandmomentumvalues.Katib stores numeric
lossvalues.After all Trials finish, the Experiment changes to
Succeeded.The UI displays the best Trial and its hyperparameters.
Expected Final Result
The test passes when:
the Experiment status is
Succeeded,3 Trials finish successfully,
every Trial has a numeric
lossmetric,the UI displays the best Trial,
the UI displays the
lrandmomentumvalues of the best Trial,MetricsUnavailabledoes not occur,the metrics collector does not report
unable to find main pid.
Terminal Verification
kubectl get experiments,trials -n test
kubectl get pods -n test -l katib.kubeflow.org/experiment=katib-form-real-tuning
kubectl describe experiment katib-form-real-tuning -n test
Execution Time Notes
This test runs real CPU-based model training.
A single Trial may take several minutes, depending on available cluster resources.
Because the configuration uses:
parallelTrialCount: 1
maxTrialCount: 3
the Trials run sequentially. The total Experiment duration may therefore be approximately three times longer than one Trial.