帮我解决以下错误Traceback (most recent call last): File "train.py", line 42, in <module> loss = model.loss_fn(true_y, pred_y, input_mask) File "/home/22wd/pretrained_bert_models/REL/model.py", line 94, in loss_fn calc_loss(pred_obj_head, true_obj_head, mask) + \ File "/home/22wd/pretrained_bert_models/REL/model.py", line 82, in calc_loss weight = torch.where(true > 0, torch.tensor(CLS_WEIGHT_COEF[1]), torch.tensor(CLS_WEIGHT_COEF[0])) RuntimeError: Expected condition, x and y to be on the same device, but condition is on cuda:0 and x and y are on cpu and cpu respectively
时间: 2024-03-09 20:46:29 浏览: 141
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误是因为你的条件参数在 GPU 上,而其它参数在 CPU 上。你需要将条件参数也移到 GPU 上,可以使用 `to()` 方法将其转移到 GPU 上,例如:
```
condition = condition.to(device)
```
其中,`device` 是你的模型所在的设备,可以是 `"cuda:0"` 或者 `"cpu"`。
阅读全文