-
Notifications
You must be signed in to change notification settings - Fork 105
Description
test_outputs = test_outputs.to(device=device, dtype=torch.int64)
with torch.no_grad():
y_val = model(categorical_test_data)
loss = loss_function(y_val, test_outputs)
print(f'Loss: {loss:8f}')
여기서 y_val = model(categorical_test_data) 부분에 device 지정을 해줘야 하지 않나요( y_val = model(categorical_test_data).to(device))
앞서 train 단계에서 지정된 device가 test에서 사용된 device와 달라 오류가 발생합니다
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument target in method wrapper_CUDA_nll_loss_forward)
또한 train 과정에서는 model에 device 지정한 부분이 존재합니다.
epochs = 500
aggregated_losses = []
train_outputs = train_outputs.to(device=device, dtype=torch.int64)
for i in range(epochs):
i += 1
y_pred = model(categorical_train_data).to(device) ## 해당 부분
single_loss = loss_function(y_pred, train_outputs)
aggregated_losses.append(single_loss)
책 정말 잘 공부하고 있습니다.
좋은 책 집필 감사합니다.