.FluxTrainingCallback

abstract type defined in module FluxTraining


			abstract type Callback

Supertype of all callbacks. Callbacks add custom functionality to the training loop by hooking into different Events.Events

Any Callback can be used by passing it to Learner. See subtypes(FluxTraining.Callback) for implementations.

Extending

See Custom callbacks for a less succinct tutorial format.

  1. Create a struct MyCallback that subtypes FluxTraining.Callback.

  2. Add event handlers by implementing methods for on (event, phase, callback, learner). Methods should always dispatch on your callback, and may dispatch on specific Phases.Phases and Events.Events.

    For example, to implement an event handler that runs at the end of every step during training: on(::StepEnd, ::AbstractTrainingPhase, ::MyCallback, learner).

  3. Define what state the callback accesses and/or modifies by implementing stateaccess (::MyCallback). While learner is always passed as an argument to on event handlers, by default a callback can not read or write to its fields. See stateaccess for more detail.

    If a callback needs to write some state that other callbacks should be able to access, it can store it in learner.cbstate if you add a permission in stateaccess.

  4. If the callback needs some one-time initialization, you can implement init! which will be run at least once before any step is run.