TypeError: expected TensorOptions(dtype=__int64, device=cpu, layout=Strided, requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt)) (got TensorOptions(dtype=float, device=cpu, layout=Strided, requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt)))
loss = criterion(output,targets.view(batch_size*seq_length).type(torch.LongTensor))
loss.backward()
nn.utils.clip_grad_norm_(net.parameters(), clip)
opt.step()
changing the data type to torch.LongTensor does not help. (i am working via CPU only)
Using a LongTensor
for nn.CrossEntropyLoss
or nn.NLLLoss
should work and the error points to a dtype
mismatch as a FloatTensor
seems to be passed.
Could you post a minimal, executable code snippet which would reproduce the issue, please?