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

Error using Integrated Gradients on MPS #1240

Open
achouliaras opened this issue Feb 16, 2024 · 1 comment
Open

Error using Integrated Gradients on MPS #1240

achouliaras opened this issue Feb 16, 2024 · 1 comment

Comments

@achouliaras
Copy link

achouliaras commented Feb 16, 2024

Hi, I'm trying to use Integrated Gradients on a simple DQN model in my MacBook using the MPS backend.

model = IntegratedGradients(model)
attribution = xai.attribute(torch.tensor(ob, dtype = torch.float32).unsqueeze(0).to(self.agent.device), target = int(act[0])).squeeze(0).cpu().detach().numpy()

I get the following error:

File "/Users/andreas/miniconda3/envs/xdrl/lib/python3.9/site-packages/captum/log/init.py", line 42, in wrapper
return func(*args, **kwargs)
File "/Users/andreas/miniconda3/envs/xdrl/lib/python3.9/site-packages/captum/attr/_core/integrated_gradients.py", line 286, in attribute
attributions = self._attribute(
File "/Users/andreas/miniconda3/envs/xdrl/lib/python3.9/site-packages/captum/attr/_core/integrated_gradients.py", line 360, in _attribute
scaled_grads = [
File "/Users/andreas/miniconda3/envs/xdrl/lib/python3.9/site-packages/captum/attr/_core/integrated_gradients.py", line 362, in
* torch.tensor(step_sizes).view(n_steps, 1).to(grad.device)
TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

Is there a support issue with MPS it fails when I try to use TracInCP as well with the same error?

@NarineK
Copy link
Contributor

NarineK commented Feb 21, 2024

@achouliaras, I don't think that we have tested captum on MPS backend. It seems that this is a common error for MPS backend.
Do you see a similar error if you run a command: torch.tensor(50).view(50, 1).to(self.agent.device) ?

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