Learning Rate Scheduling Callback
Source:R/CallbackSetLRScheduler.R
mlr_callback_set.lr_scheduler.RdChanges the learning rate based on the schedule specified by a torch::lr_scheduler.
As of this writing, the following are available:
torch::lr_one_cycle()(where the default values forepochsandsteps_per_epochare the number of training epochs and the number of batches per epoch)Custom schedulers defined with
torch::lr_scheduler().
Resuming
The state of the wrapped torch scheduler is stored and restored, so a resumed run continues the
schedule instead of starting it over.
Creating a scheduler resets the optimizer's learning rate to the one the schedule started at, so
the rate the restored schedule had reached is put back afterwards.
That state contains the scheduler's configuration as well as its progress, and restoring it
overwrites what the resuming run was configured with.
Resuming with different scheduler arguments, or a different opt.lr, which the schedule's base
rates are derived from, therefore silently continues the schedule of the checkpointed run.
Super class
CallbackSet -> CallbackSetLRScheduler
Public fields
scheduler_fn(
lr_scheduler_generator)
Thetorchfunction that creates a learning rate schedulerscheduler(
LRScheduler)
The learning rate scheduler wrapped by this callback
Methods
Inherited methods
CallbackSetLRScheduler$new()
Creates a new instance of this R6 class.
Usage
CallbackSetLRScheduler$new(.scheduler, step_on_epoch, ...)Arguments
.scheduler(
lr_scheduler_generator)
Thetorchscheduler generator (e.g.torch::lr_step).step_on_epoch(
logical(1))
Whether the scheduler steps after every epoch (otherwise every batch)....(any)
The scheduler-specific initialization arguments.
CallbackSetLRScheduler$state_dict()
Returns the state of the wrapped torch scheduler, so that a later run can continue the
schedule instead of starting it over.
Returns NULL if the scheduler was not created yet, i.e. before the training loop began.
CallbackSetLRScheduler$load_state_dict()
Loads the state of the wrapped torch scheduler.
Arguments
state_dict(named
list())
The state dict as retrieved via$state_dict().