Closed Deep1994 closed 5 years ago
i encountered sample exception, how you solved it?
same here, changed to item() but the loss not updated anymore.
I was receiving this issue when using the built-in round() function rather than the torch.round() function. The built-in function will not work with tensors.
Hi, I found an error when run your code, the error log is:
TRAINING : Epoch 1 Learning rate : 0.1 train_nli.py:245: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number all_costs.append(loss.data[0]) Traceback (most recent call last): File "train_nli.py", line 351, in
train_acc = trainepoch(epoch)
File "train_nli.py", line 276, in trainepoch
round(100.*correct/(stidx+k), 2)))
TypeError: type Tensor doesn't define round method
I change round(100.correct/(stidx+k), 2))) to round(100.correct.item()/(stidx+k), 2))), it can run, but the loss cannot update, and always be a constant, do you know why this happen? Thanks!