Skip to content
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

Non contiguous arrays? #93

Closed
giuliolovisotto opened this issue Mar 5, 2021 · 2 comments
Closed

Non contiguous arrays? #93

giuliolovisotto opened this issue Mar 5, 2021 · 2 comments

Comments

@giuliolovisotto
Copy link
Contributor

Hi, I found a problem reproducing the basic example in https://github.com/microsoft/robust-models-transfer (I downloaded resnet18_l2_eps3.ckpt).

Problem is that I get NaN values for accuracy. If I print the exception caught at Line 470 of robustness/train.py it says the following UserWarning: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

Screenshot 2021-03-05 at 10 58 07

I investigated a bit and I can fix this by adding .contiguous() in the accuracy computation in robustness/tools/helpers.py:
correct_k = correct[:k].contiguous().view(-1).float(), I found a similar issue here cezannec/capsule_net_pytorch#4. The problem was when computing top-5 accuracy specifically (I assume it would happen with everything higher than top-1). Changing that line made everything work again.

I haven't opened a pull request because I'm not sure why this happens in my setup, I am running everything inside this docker container and on an Nvidia Titan RTX.

@andrewilyas
Copy link
Collaborator

Thanks for making an issue! Does this still happen with the latest version of the library? We became aware of this issue (it actually only happens with PyTorch 1.7) a few months ago and so we changed that line to use .reshape() instead:

correct_k = correct[:k].reshape(-1).float()

The updated version should be available on PyPI; let us know if the problem persists after a pip install --upgrade robustness!

@giuliolovisotto
Copy link
Contributor Author

Great thanks, updating to the newest version fixed it! Don't know if you want to change the robustness version in the requirements.txt file for the other project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants