MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / ExponentialLR

Class ExponentialLR

optimizers/lr_scheduler.py:481–507  ·  view source on GitHub ↗

Decays the learning rate of each parameter group by gamma every epoch. When last_epoch=-1, sets initial lr as lr. Args: optimizer (Optimizer): Wrapped optimizer. gamma (float): Multiplicative factor of learning rate decay. last_epoch (int): The index of last epoch. D

Source from the content-addressed store, hash-verified

479
480
481class ExponentialLR(_LRScheduler):
482 """Decays the learning rate of each parameter group by gamma every epoch.
483 When last_epoch=-1, sets initial lr as lr.
484
485 Args:
486 optimizer (Optimizer): Wrapped optimizer.
487 gamma (float): Multiplicative factor of learning rate decay.
488 last_epoch (int): The index of last epoch. Default: -1.
489 """
490
491 def __init__(self, optimizer, gamma, last_epoch=-1):
492 self.gamma = gamma
493 super(ExponentialLR, self).__init__(optimizer, last_epoch)
494
495 def get_lr(self):
496 if not self._get_lr_called_within_step:
497 warnings.warn("To get the last learning rate computed by the scheduler, "
498 "please use `get_last_lr()`.", UserWarning)
499
500 if self.last_epoch == 0:
501 return self.base_lrs
502 return [group['lr'] * self.gamma
503 for group in self.optimizer.param_groups]
504
505 def _get_closed_form_lr(self):
506 return [base_lr * self.gamma ** self.last_epoch
507 for base_lr in self.base_lrs]
508
509
510class CosineAnnealingLR(_LRScheduler):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected