Traceback (most recent call last):
  File "D:\nlp\zhinengyunwei\wh_lstm_pytorch.py", line 213, in <module>
    loss = loss_func(torch.squeeze(output), target)
  File "D:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\loss.py", line 1150, in forward
    return F.cross_entropy(input, target, weight=self.weight,
  File "D:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py", line 2846, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Float'

发生在loss计算的时候,

loss_func(torch.squeeze(output), target)

改为:

loss_func(torch.squeeze(output), target.long())
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐