-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImportError: cannot import name 'zero_gradients' from 'advertorch.attacks.utils' #115
Comments
Solution: |
Thank you for this solution. For more help, I converted this into a block code version.
def zero_gradients(x):
if isinstance(x, torch.Tensor):
if x.grad is not None:
x.grad.detach_()
x.grad.data.zero_()
elif isinstance(x, container_abcs.Iterable):
for elem in x:
zero_gradients(elem) |
I'm glad to be able to help you. I also encountered this problem yesterday, and then I found this solution, and then solved it through this solution. You can read the original text of the Website: https://blog.csdn.net/TaoLinna/article/details/137058509 |
Environment:
Installed advertorch using
pip install --upgrade git+https://github.com/BorealisAI/advertorch.git
While doing
from advertorch.attacks import LinfPGDAttack
, I got the following error:The text was updated successfully, but these errors were encountered: