Bug in CosineAnnealingWarmRestarts #49630
Labels
module: optimizer
Related to torch.optim
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
馃悰 Bug
CosineAnnealingWarmRestarts gives AttributeError if we initialize it with last_epoch not equal to -1, which usually happens when one wants to resume training a network.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
No attribute error.
Environment
Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).
You can get the script and run it with:
conda
,pip
, source): condaAdditional context
After some investigation, I believe I found the code that causes this bug. When we initialize
CosineAnnealingWarmRestarts
, it will call its parent (_LRScheduler
) constructor (line 965 intorch/optim/lr_scheduler.py
). The constructor of_LRScheduler
will call the step function (line 79 intorch/optim/lr_scheduler.py
) ofCosineAnnealingWarmRestarts
before finishing the initialization. In the step function, because epoch is none and last_epoch is greater than 0, line 1008 will be executed which involvesself.T_cur
. But at this pointself.T_cur
has not been set yet as it is only set after the initialization is done (line 967).cc @vincentqb
The text was updated successfully, but these errors were encountered: