Write a Custom Learning Rate Scheduler
To define a Cerebras-compliant learning rate scheduler, create a subclass ofcerebras.pytorch.optim.lr_scheduler.LRScheduler
.
For example:
LRScheduler
class expects three arguments:
- The optimizer whose learning rate is being scheduled
- The total number of iterations scheduled (optional)
- The last epoch to start on
_get_closed_form
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.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.