Fix ordering bug in CosineAnnealingWarmRestarts in optim/lr_scheduler.py#64758
Fix ordering bug in CosineAnnealingWarmRestarts in optim/lr_scheduler.py#64758BalajiAI wants to merge 1 commit intopytorch:masterfrom BalajiAI:patch-2
Conversation
'CosineAnnealingWarmRestarts' object has no attribute 'T_cur'. In the Constructor of the CosineAnnealingWarmRestarts, we're calling the constructor of the Parent class (_LRScheduler) which inturn calls the step method of the CosineAnnealingWarmRestarts. The called method tries to update the object's attribute 'T_cur' which is not defined yet. So it raises the error. This only holds, when we give the value for last_epoch argument as 0 or greater than 0 to the 'CosineAnnealingWarmRestarts', while initializing the object.
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit cf38722 (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
Codecov Report
@@ Coverage Diff @@
## master #64758 +/- ##
=======================================
Coverage 66.65% 66.66%
=======================================
Files 710 710
Lines 92418 92418
=======================================
+ Hits 61601 61609 +8
+ Misses 30817 30809 -8 |
|
Doing this would break #23480 again no? |
I feel the assignment changes to after the initialization of superclass. However, here we're doing the update before initialzation. What do you think about this @albanD ? |
No sir. It won't break. |
|
@jbschlosser |
jbschlosser
left a comment
There was a problem hiding this comment.
Looks good AFAICT! From my (limited) testing, it seems to fix the problem
|
@jbschlosser has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
|
@jbschlosser merged this pull request in 32f0387. |
🐛 Bug
'CosineAnnealingWarmRestarts' object has no attribute 'T_cur'.
In the Constructor of the CosineAnnealingWarmRestarts, we're calling the constructor of the Parent class (_LRScheduler) which inturn calls the step method of the CosineAnnealingWarmRestarts.
The called method tries to update the object's attribute 'T_cur' which is not defined yet. So it raises the error.
This only holds, when we give the value for last_epoch argument as 0 or greater than 0 to the 'CosineAnnealingWarmRestarts', while initializing the object.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I only expected the 'CosineAnnealingWarmRestarts' object to be initialized.
Environment
PyTorch version: 1.9.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.2 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.21.2
Libc version: glibc-2.31
Python version: 3.8.10 [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.8.0-59-generic-x86_64-with-glibc2.29
Is CUDA available: False
CUDA runtime version: No CUDA
Additional context
We can able to solve this bug by moving the line 'self.T_cur = self.last_epoch' above the 'super(CosineAnnealingWarmRestarts,self).init()' line. Since we've initialized the "self.T_cur" to the object.
Possibly related: #65342