The Callback interface enables custom code to be triggered by various Hydra events.
To use the callback API, one should import Hydra's
Users can then create subclasses of this
Callback class, overriding one or more of
the methods defined by
Callback. For the methods of a subclass to be called at the
appropriate time, the subclass must be registered with Hydra in the
(see examples below).
The full API exposed by the
hydra.experimental.callback.Callback class is listed below:
Events supported (Click to expand)
Say we have
MyCallback so after every job ends we can upload a certain file to a S3 bucket.
For simplicity we include this Callback class within the application, in real life you should have the
Callback in a separate file.
Running the application, we can see our custom method
on_job_end was called.
Now let's take a look at the configurations.
on_multirun_start method will get called first,
on_job_start (called once for each job).
After each job
on_job_end is called, and finally either
on_multirun_end is called one time before the application exits.
hydra.callbacks section of your config, you can use a list to register multiple callbacks. They will be called in the final composed order for
start events and
in reversed order for
end events. So, for example, suppose we have the following composed config:
Before each job starts,
MyCallback1.on_job_start will get called first,
After each job ends,
MyCallback2.on_job_end will get called first,