fra31 / auto-attack

Code relative to "Reliable evaluation of adversarial robustness with an ensemble of diverse parameter-free attacks"
https://arxiv.org/abs/2003.01690
MIT License
656 stars 112 forks source link

pytoch API `view` may not work if tensors are non-contiguous #9

Closed CNOCycle closed 4 years ago

CNOCycle commented 4 years ago

Hi authors,

I'm not familiar with pytorch, I got some errors occasionally.

It complaint that tensor is not non-contiguous and suggest that reshape is better than view.

https://github.com/fra31/auto-attack/blob/0185c7930e5c535ff3380197c54c74ba916f449b/fab_tf.py#L394-L407

I also found that the code is not unified. As you seen, L397,L401 is view but L404 is reshape.

An alternative solution is calling .contiguous() before .view(...). Or view should be replace by reshape

I'm not sure which solution is suitable in this project.

Any suggestion?

fra31 commented 4 years ago

Hey,

I think this depends on the PyTorch version, probably newer ones don't agree with how view is used in the code. I guess both solutions are fine, but I'll investigate the details to fix it at best. Yeah, the code is not always homogeneous, this will be object of future updates, thanks for pointing it out!

CNOCycle commented 4 years ago

I'm not pytorch expert. Any update about this issues? Or which solution would you prefer? I can make a PR fix this issue quickly.

fra31 commented 4 years ago

I fixed this with reshape(...). I've to test it with different pytorch versions (as this seems to be one of the causes). I plan to integrate it into the repo soon (a few days) together with other updates.

fra31 commented 4 years ago

This should be fixed now in fab_tf.py. Please let me know if you come across it again.

CNOCycle commented 4 years ago

Thanks, this issues has been fixed. But fab attack's runtime performance is still poor. I guess that it would cause by computing gradient in TF side.