我有一个如下所示的代码段。它完美地在CPU中工作。但是,我想在GPU中运行代码,但出现以下错误。有什么想法吗?
def take_action(状态):
global steps_done
sample = random.random()
eps_threshold = EPS_END + (EPS_START - EPS_END) * \
math.exp(-1. * steps_done / EPS_DECAY)
steps_done += 1
if sample > eps_threshold:
with torch.no_grad():
action=torch.as_tensor(torch.argmax(policy_net(state)))
else:
action=torch.tensor(random.randrange(0,7,1))
RuntimeError:后端CPU的预期对象,但参数#2'mat2'获得了后端CUDA。