machanic / TangentAttack

The official implementation of NeurIPS 2021 paper: Finding Optimal Tangent Points for Reducing Distortions of Hard-label Attacks
https://arxiv.org/abs/2111.07492
Apache License 2.0
16 stars 0 forks source link

ImportError: cannot import name 'zero_gradients' #2

Open aknirala opened 2 years ago

aknirala commented 2 years ago

On running command like: !python tangent_attack_hemisphere/attack.py --gpu 0 --norm l2 --dataset CIFAR-10 --arch resnet-50

I get:

Traceback (most recent call last):
  File "tangent_attack_hemisphere/attack.py", line 19, in <module>
    from models.defensive_model import DefensiveModel
  File "/content/models/defensive_model.py", line 14, in <module>
    from adversarial_defense.feature_scatter.attack_methods import Attack_FeaScatter
  File "/content/adversarial_defense/feature_scatter/attack_methods.py", line 6, in <module>
    from torch.autograd.gradcheck import zero_gradients
ImportError: cannot import name 'zero_gradients' from 'torch.autograd.gradcheck' (/usr/local/lib/python3.7/dist-packages/torch/autograd/gradcheck.py)

On colab I am not able to successfully install requirements.txt, but was hoping it would work.

machanic commented 2 years ago

@aknirala the zero_gradients is used in the old version of PyTorch. The new version of PyTorch delete the function zero_gradients from torch.autograd.gradcheck. You can delete the code line of zero_gradients(x) or just delete from adversarial_defense.feature_scatter.attack_methods import Attack_FeaScatter and the corresponding code.