Update base learning rate scheduler
@@ -34,13 +34,16 @@ for _name, _Optim in torch.optim.__dict__.items():
del _PyroOptim
# Load all schedulers from PyTorch
+# breaking change in torch >= 1.14: LRScheduler is new base class
+if hasattr(torch.optim.lr_scheduler, "LRScheduler"):
+ _torch_scheduler_base = torch.optim.lr_scheduler.LRScheduler
+else: # for torch < 1.13, _LRScheduler is base class
+ _torch_scheduler_base = torch.optim.lr_scheduler._LRScheduler
+
for _name, _Optim in torch.optim.lr_scheduler.__dict__.items():
if not isinstance(_Optim, type):
continue
- if (
- not issubclass(_Optim, torch.optim.lr_scheduler._LRScheduler)
- and _name != "ReduceLROnPlateau"
- ):
+ if not issubclass(_Optim, _torch_scheduler_base) and _name != "ReduceLROnPlateau":
continue
if _Optim is torch.optim.Optimizer:
continue
