class ray.tune.Callback[source]#

Bases: object

Tune base callback that can be extended and passed to a TrialRunner

Tune callbacks are called from within the TrialRunner class. There are several hooks that can be used, all of which are found in the submethod definitions of this base class.

The parameters passed to the **info dict vary between hooks. The parameters passed are described in the docstrings of the methods.

This example will print a metric each time a result is received:

from ray import air, tune
from ray.tune import Callback

class MyCallback(Callback):
    def on_trial_result(self, iteration, trials, trial, result,
        print(f"Got result: {result['metric']}")

def train(config):
    for i in range(10):

tuner = tune.Tuner(

PublicAPI (beta): This API is in beta and may change before becoming stable.




Get the state of the callback.

on_checkpoint(iteration, trials, trial, ...)

Called after a trial saved a checkpoint with Tune.

on_experiment_end(trials, **info)

Called after experiment is over and all trials have concluded.

on_step_begin(iteration, trials, **info)

Called at the start of each tuning loop step.

on_step_end(iteration, trials, **info)

Called at the end of each tuning loop step.

on_trial_complete(iteration, trials, trial, ...)

Called after a trial instance completed.

on_trial_error(iteration, trials, trial, **info)

Called after a trial instance failed (errored).

on_trial_restore(iteration, trials, trial, ...)

Called after restoring a trial instance.

on_trial_result(iteration, trials, trial, ...)

Called after receiving a result from a trial.

on_trial_save(iteration, trials, trial, **info)

Called after receiving a checkpoint from a trial.

on_trial_start(iteration, trials, trial, **info)

Called after starting a trial instance.


Get the state of the callback.

setup([stop, num_samples, total_num_samples])

Called once at the very beginning of training.