Skip to content

Tensors are not on the same device #265

@CaptainCuong

Description

@CaptainCuong

leave_1_probs_argmax = torch.argmax(leave_1_probs, dim=-1)

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/OpenAttack/attack_eval/utils.py", line 10, in attack_process
    adversarial_sample = attacker(victim, data)
  File "/usr/local/lib/python3.10/site-packages/OpenAttack/attackers/classification.py", line 28, in __call__
    adversarial_sample = self.attack(victim, input_["x"], goal)
  File "/usr/local/lib/python3.10/site-packages/OpenAttack/attackers/bert_attack/__init__.py", line 119, in attack
    important_scores = self.get_important_scores(words, victim, current_prob, goal.target, orig_probs)
  File "/usr/local/lib/python3.10/site-packages/OpenAttack/attackers/bert_attack/__init__.py", line 241, in get_important_scores
    (leave_1_probs_argmax != orig_label).float()
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

This bug can be fixed by moving orig_label to cpu

orig_label = orig_label.to(torch.device('cpu'))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions