DSE-MSU / DeepRobust

A pytorch adversarial library for attack and defense methods on images and graphs
MIT License
988 stars 192 forks source link

[Bug] x.zero_grad() will result in "AttributeError: 'Tensor' object has no attribute 'zero_grad'" #89

Closed zhjwy9343 closed 2 years ago

zhjwy9343 commented 3 years ago

In the # 105 of deeprobust/image/attack/deepfool.py. The code was change from zero_gradients(x) to x.zero_grad(), which will cause the "AttributeError: 'Tensor' object has no attribute 'zero_grad'" error in Pytorch 1.10, 1.9, 1.8, 1.7.

YaxinLi0-0 commented 3 years ago

Thank you for reporting this bug to us! Which pytorch version are you using currently?

YaxinLi0-0 commented 3 years ago

Originally zero_gradients(x) is included in torch.autograd.gradcheck. While it has been removed. So I add the original source code for zero_gradients(x) into deepfool.py. See if it works now.

jsrdcht commented 2 years ago

Do you still preserve the mistake? Try x.grad.zero_(), I think it may work.