"module 'torch' has no attribute 'count_nonzero' "

Greetings,

can anyone tell me why I am getting this error?
The sample code from the documentation does not even work for me:
https://pytorch.org/docs/stable/generated/torch.count_nonzero.html

Is the function outdated? I am using Spyder.

Regards!

What is your pytorch version?

Typing print(torch.__version__) in Spyder gives 1.6.0.

Ok that is the problem torch 1.6.0 does not have a torch.count_nonzero function. There is no alternative to it so you may want to upgrade your pytorch version.

1 Like

Thank you!

I tried “conda update pytorch”. Now it was downgraded to 1.3.1 :joy:

Have you tried just reinstalling it. Try going to the pytorch page and reinstalling the new version with whatever os you need.