Create a schedule with a constant learning rate preceded by a warmup period during which the learning rate increases linearly between 0 and the initial lr set in the optimizer. Args: optimizer ([`~torch.optim.Optimizer`]): The optimizer for which to schedule the lea
(optimizer: Optimizer, num_warmup_steps: int, last_epoch: int = -1)
| 16 | |
| 17 | |
| 18 | def get_constant_schedule_with_warmup(optimizer: Optimizer, num_warmup_steps: int, last_epoch: int = -1): |
| 19 | """ |
| 20 | Create a schedule with a constant learning rate preceded by a warmup period during which the learning rate |
| 21 | increases linearly between 0 and the initial lr set in the optimizer. |
| 22 | |
| 23 | Args: |
| 24 | optimizer ([`~torch.optim.Optimizer`]): |
| 25 | The optimizer for which to schedule the learning rate. |
| 26 | num_warmup_steps (`int`): |
| 27 | The number of steps for the warmup phase. |
| 28 | last_epoch (`int`, *optional*, defaults to -1): |
| 29 | The index of the last epoch when resuming training. |
| 30 | |
| 31 | Return: |
| 32 | `torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule. |
| 33 | """ |
| 34 | |
| 35 | lr_lambda = partial(_get_constant_schedule_with_warmup_lr_lambda, num_warmup_steps=num_warmup_steps) |
| 36 | return LambdaLR(optimizer, lr_lambda, last_epoch=last_epoch) |
| 37 | |
| 38 | |
| 39 |
nothing calls this directly
no outgoing calls
no test coverage detected