You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A RuntimeError occurs due to a device mismatch when using torch.ones(1) (created on the CPU by default) with values_tmp (on the GPU).
To Reproduce
Steps to reproduce the behavior:
Create an instance of PyTorchClassifier on GPU.
Create an instance of ProjectedGradientDescent to attack the PyTorchClassifier model.
Try to generate adversarial data with the attack.generate method.
Raise the error: "RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!"
Expected behavior
The adversarial data generation process should complete without errors.
Error Messages
Traceback (most recent call last):
[...]
File "adversarial-robustness-toolbox/art/attacks/evasion/projected_gradient_descent/projected_gradient_descent.py", line 202, in generate
return self._attack.generate(x=x, y=y, **kwargs)
File "adversarial-robustness-toolbox/art/attacks/evasion/projected_gradient_descent/projected_gradient_descent_pytorch.py", line 223, in generate
adv_x[batch_index_1:batch_index_2] = self._generate_batch(
File "adversarial-robustness-toolbox/art/attacks/evasion/projected_gradient_descent/projected_gradient_descent_pytorch.py", line 284, in _generate_batch
adv_x = self._compute_pytorch(
File "adversarial-robustness-toolbox/art/attacks/evasion/projected_gradient_descent/projected_gradient_descent_pytorch.py", line 451, in _compute_pytorch
perturbation = self._projection(x_adv - x_init, eps, self.norm)
File "adversarial-robustness-toolbox/art/attacks/evasion/projected_gradient_descent/projected_gradient_descent_pytorch.py", line 500, in _projection
values_norm == 0, torch.minimum(torch.ones(1), torch.tensor(eps).to(values_tmp.device) / values_norm)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
Suggested solution
Just replace line 500, in _projection function in "adversarial-robustness-toolbox/art/attacks/evasion/projected_gradient_descent/projected_gradient_descent_pytorch.py":
Describe the bug
A RuntimeError occurs due to a device mismatch when using
torch.ones(1)
(created on the CPU by default) withvalues_tmp
(on the GPU).To Reproduce
Steps to reproduce the behavior:
PyTorchClassifier
on GPU.ProjectedGradientDescent
to attack thePyTorchClassifier
model.attack.generate
method.Expected behavior
The adversarial data generation process should complete without errors.
Error Messages
Suggested solution
Just replace line 500, in
_projection
function in "adversarial-robustness-toolbox/art/attacks/evasion/projected_gradient_descent/projected_gradient_descent_pytorch.py":From
To
System information (please complete the following information):
The text was updated successfully, but these errors were encountered: