Learning Rate Scheduling
Similar to the optimizers, the PyTorch Vanilla learning rate schedulers are incompatible with traced lazy execution. There are exact drop-in replacements for all commonly used learning rate schedulers available in cerebras.pytorch.optim.lr_scheduler.
For example:
Writing Custom Learning Rate Schedulers
To define a Cerebras-compliant learning rate scheduler, create a subclass of cerebras.pytorch.optim.lr_scheduler.LRScheduler
.
For example:
As can be seen in the above example, the base LRScheduler
class expects three arguments:
-
The optimizer whose learning rate is being scheduled
-
The total number of iterations that the scheduler is scheduled (optional)
-
The last epoch to start on
In addition, the _get_closed_form_lr
abstract method must be overridden. This method is where the full scheduler is defined in closed form.
Due to the nature of lazy tensor tracing and execution, there may not be any Python level conditions or loops used to dynamically define the control flow. This means that only torch ops (such as torch.where
) may be used.
Moreover, static structures are allowed. For example, a loop with a fixed number of iterations, or a Python conditional that doesn’t involve any torch tensors whose conditional involves only constant variables.
This method is expected to return a torch.Tensor
that represents the full learning rate schedule as a computed tensor.
See the existing LR scheduler implementations for examples of how to correctly define the schedule.
Once you’ve written your custom LR scheduler, as long as its available in the global scope, you can use it in ModelZoo in a similar way by setting the scheduler
to be the name of your custom LR schedule class in your params YAML file.