-
Notifications
You must be signed in to change notification settings - Fork 479
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
Bug in *.attribute -- New tensor in gathering ignoring used device #316
Comments
Hi @kai-tub , thanks for the detailed information, you are right, this is definitely a bug! Your proposed fix with maintaining the output device looks great, would you like to create a PR making that change? |
Yes I would like to create a PR. :) |
Closed
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 10, 2020
Summary: Hey, Here is my proposed fix for [#316. I've added a test case that uses the BaseGPUTest class and simply runs the saliency target tests again, with everything on the GPU. As I did not fully understand the `_target_batch_test_assert` function and what the requirements for the tests are, I simply copied the function for now. I assume there may be an obvious way to integrate these tests. :) Another question is: Do we want to enforce the move if we receive a target tensor, which is not on the right device? We could print a User Warning similar to automatically setting require gradients as in gradient.py:33. Or should the user be responsible to move the target tensor to the correct device? Best regards, Kai Pull Request resolved: #317 Reviewed By: NarineK Differential Revision: D20371529 Pulled By: vivekmig fbshipit-source-id: 92461d358f589bf47487d6170fac6a54e1d83123
Closing since the PR is merged! Thank you! |
NarineK
pushed a commit
to NarineK/captum-1
that referenced
this issue
Nov 19, 2020
Summary: Hey, Here is my proposed fix for [pytorch#316. I've added a test case that uses the BaseGPUTest class and simply runs the saliency target tests again, with everything on the GPU. As I did not fully understand the `_target_batch_test_assert` function and what the requirements for the tests are, I simply copied the function for now. I assume there may be an obvious way to integrate these tests. :) Another question is: Do we want to enforce the move if we receive a target tensor, which is not on the right device? We could print a User Warning similar to automatically setting require gradients as in gradient.py:33. Or should the user be responsible to move the target tensor to the correct device? Best regards, Kai Pull Request resolved: pytorch#317 Reviewed By: NarineK Differential Revision: D20371529 Pulled By: vivekmig fbshipit-source-id: 92461d358f589bf47487d6170fac6a54e1d83123
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, first of all, thanks for providing and working on such a neat library!
I think I found a "bug" in the
common.py
file, which is used for most attributions. The problem arises when a Cuda device is used and a non-tensor target is given, for example, a simple list.I don't know if you officially support CUDA or not, but as I couldn't find any hints indicating otherwise, I've used the Saliency function without any problems on a CUDA device, while I was using a tensor as a target. After some refactoring, I changed the target to a simple list and the error occurred. I traced it down to the following line:
return torch.gather(output, 1, torch.tensor(target).reshape(len(output), 1))
As it can be seen a tensor is created but no device information is used. A simple fix would be to look where the output tensor lives:
(I don't know if this could cause problems if the data lies on a different GPU, as I have no experience with multiple GPUs)
The tensor version works, as it can be moved before on the user side and only reshapes the used one:
return torch.gather(output, 1, target.reshape(len(output), 1))
I've included a minimal example highlighting the problem:
The text was updated successfully, but these errors were encountered: