Using Early Stopping

How to use early stopping in Katib experiments

This guide shows how you can use early stopping to improve your Katib experiments. Early stopping allows you to avoid overfitting when you train your model during Katib experiments. It also helps by saving computing resources and reducing experiment execution time by stopping the experiment’s trials when the target metric(s) no longer improves before the training process is complete.

The major advantage of using early stopping in Katib is that you don’t need to modify your training container package. All you have to do is make necessary changes in your experiment’s YAML file.

Early stopping works in the same way as Katib’s metrics collector. It analyses required metrics from the stdout or from the arbitrary output file and an early stopping algorithm makes the decision if the trial needs to be stopped. Currently, early stopping works only with StdOut or File metrics collectors.

Note: Your training container must print training logs with the timestamp, because early stopping algorithms need to know the sequence of reported metrics. Check the MXNet example to learn how to add a date format to your logs.

Configure the experiment with early stopping

As a reference, you can use the YAML file of the early stopping example.

  1. Follow the guide to configure your Katib experiment.

  2. Next, to apply early stopping for your experiment, specify the .spec.earlyStopping parameter, similar to the .spec.algorithm. Refer to the EarlyStoppingSpec type for more information.

    • .earlyStopping.algorithmName - the name of the early stopping algorithm.

    • .earlyStopping.algorithmSettings- the settings for the early stopping algorithm.

What happens is your experiment’s suggestion produces new trials. After that, the early stopping algorithm generates early stopping rules for the created trials. Once the trial reaches all the rules, it is stopped and the trial status is changed to the EarlyStopped. Then, Katib calls the suggestion again to ask for the new trials.

Learn more about Katib concepts in the overview guide.

Follow the Katib configuration guide to specify your own image for the early stopping algorithm.

Early stopping algorithms in detail

Here’s a list of the early stopping algorithms available in Katib:

More algorithms are under development.

You can add an early stopping algorithm to Katib yourself. Check the developer guide to contribute.

Median Stopping Rule

The early stopping algorithm name in Katib is medianstop.

The median stopping rule stops a pending trial X at step S if the trial’s best objective value by step S is worse than the median value of the running averages of all completed trials’ objectives reported up to step S.

To learn more about it, check Google Vizier: A Service for Black-Box Optimization.

Katib supports the following early stopping settings:

Setting NameDescriptionDefault Value
min_trials_requiredMinimal number of successful trials to compute median value3
start_stepNumber of reported intermediate results before stopping the trial4

Submit an early stopping experiment from the UI

You can use Katib UI to submit an early stopping experiment. Follow these steps to create an experiment from the UI.

Once you reach the early stopping section, select the appropriate values:

UI form to deploy an early stopping Katib experiment

View the early stopping experiment results

First, make sure you have jq installed.

Check the early stopped trials in your experiment:

  1. kubectl get experiment <experiment-name> -n <experiment-namespace> -o json | jq -r ".status"

The last part of the above command output looks similar to this:

  1. . . .
  2. "earlyStoppedTrialList": [
  3. "median-stop-2ml8h96d",
  4. "median-stop-cgjkq8zn",
  5. "median-stop-pvn5p54p",
  6. "median-stop-sjc9tcgc"
  7. ],
  8. "startTime": "2020-11-05T03:03:43Z",
  9. "succeededTrialList": [
  10. "median-stop-2kmh57qf",
  11. "median-stop-7ccstz4z",
  12. "median-stop-7sqt7556",
  13. "median-stop-lgvhfch2",
  14. "median-stop-mkfjtwbj",
  15. "median-stop-nfmgqd7w",
  16. "median-stop-nsbxw5m9",
  17. "median-stop-nsmhg4p2",
  18. "median-stop-rp88xflk",
  19. "median-stop-xl7dlf5n",
  20. "median-stop-ztc58kwq"
  21. ],
  22. "trials": 15,
  23. "trialsEarlyStopped": 4,
  24. "trialsSucceeded": 11
  25. }

Check the status of the early stopped trial by running this command:

  1. kubectl get trial median-stop-2ml8h96d -n <experiment-namespace>

and you should be able to view EarlyStopped status for the trial:

  1. NAME TYPE STATUS AGE
  2. median-stop-2ml8h96d EarlyStopped True 15m

In addition, you can check your results on the Katib UI. The trial statuses on the experiment monitor page should look as follows:

UI form to view trials

You can click on the early stopped trial name to get reported metrics before this trial is early stopped:

UI form to view trial info

Next steps

Last modified 14.11.2020: Move images under Katib directory (#2354) (b2ad541e)