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

Remove all .cuda() calls #61

Merged
merged 5 commits into from
Jan 19, 2022
Merged

Remove all .cuda() calls #61

merged 5 commits into from
Jan 19, 2022

Conversation

dedeswim
Copy link
Member

As correctly pointed out in #58, there are some parts in the codebase where .cuda() is called. This causes errors when users want to run the benchmark on machines with multiple GPUs, and the device passed as an argument to benchmark is not used as expected.

This PR solves this issue by using some PyTorch APIs. In particular,

  • For the DMWideResNet and DMPreActResNet models I save mean and std with register_buffer, so that the tensors are automatically moved to the same device as the overall model.
  • For the ensembles (Chen2020AdversarialNet, Diffenderfer2021CARD_Deck, Diffenderfer2021CARD_Deck_Binary), it is enough to save the sub-models using nn.ModuleList, so that the sub-models are moved to the same device as the overall model.

The overall API remains unchanged, and users can continue specifying the device to use for the benchmark by passing the device argument to benchmark.

I have run the exact clean accuracy tests on all the models, and they pass.

@dedeswim dedeswim self-assigned this Jan 19, 2022
Copy link
Member

@fra31 fra31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

@dedeswim dedeswim merged commit 1650af1 into master Jan 19, 2022
@dedeswim dedeswim mentioned this pull request Jan 19, 2022
2 tasks
@dedeswim dedeswim removed the request for review from max-andr January 20, 2022 09:47
@dedeswim dedeswim deleted the remove-cuda-calls branch October 11, 2022 08:56
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

Successfully merging this pull request may close these issues.

2 participants