Problem importing CyclicLR

For some reason I can’t import CyclicLR. For example, “from torch.optim.lr_scheduler import CyclicLR” should work but it doesn’t. I have the latest version of PyTorch (version 1.1.0). Don’t know what the issue is. Help would be appreciated.

What kind of error message do you get?
I tried it in the latest stable version and it is working on my machine.

I get AttributeError: module ‘torch.optim’ has no attribute ‘CyclicLR’.

It’s as if it doesn’t exist. Everything else works fine except this. For example, nn.MultiheadedAttention, which is also part of the new release, works no problem. All the other new additions I’ve tested so far also work. CyclicLR seems to be the only issue that I’ve encountered. Very weird.

Did you forget to use “lr_scheduler” in your import?

from torch.optim.lr_scheduler import CyclicLR

At least, the error message points to torch.optim instead of torch.optim.lr_scheduler.

That’s exactly what I used, still not importing though. I even checked the installed torch package in torch/optim/lr_scheduler.py – CyclicLR is there so it should work. I wonder if anyone else is having this issue.

Could you print the PyTorch version using

print(torch.__version__)

Version 1.1.0, which is the latest.

I just installed this version and it’s working:

>>> import torch
>>> torch.__version__
'1.1.0'
>>> from torch.optim.lr_scheduler import CyclicLR
>>> CyclicLR
<class 'torch.optim.lr_scheduler.CyclicLR'>

That’s really weird, but could you post some more information, e.g. which OS are you using?

It’s a MacOS X 10.14.4. I reinstalled torch and even restarted and updated my machine. Still, the problem persists. Could be a problem specific to Macs.

Updated my PyCharm editor and it fixed the problem. Don’t know what exactly the issue was but I’m glad it’s working now. Thank you for all the help.

Good to hear it’s working, but could you explain what went wrong?
Is the PyCharm editor used to install packages?

1 Like

Yes, I do use it to install packages. So that could have been the issue. I didn’t update it in 6 months so I’m not surprised I started seeing problems. Whatever the bug was, it seems to be fixed.