当前位置: 首页 > 工具软件 > Forward DL > 使用案例 >

RuntimeError: “nll_loss_forward_reduce_cuda_kernel_2d_index“ not implemented for ‘Int‘

澹台镜
2023-12-01

报错代码:

File "train_synpg.py", line 285, in <module>
    train(epoch, model, train_data, valid_data, train_loader, valid_loader, optimizer, criterion, dictionary, bpe, args)
  File "train_synpg.py", line 124, in train
    valid_loss = evaluate(model, valid_data, valid_loader, criterion, dictionary, bpe, args)
  File "train_synpg.py", line 185, in evaluate
    loss = criterion(outputs_, targs_)
  File "C:\Users\DELL\.conda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\DELL\.conda\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 1166, in forward
    label_smoothing=self.label_smoothing)
  File "C:\Users\DELL\.conda\envs\pytorch\lib\site-packages\torch\nn\functional.py", line 3014, 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 'Int'

loss计算时,数据类型出错,将:

loss = criterion(outputs_, targs_)

改成:

loss = criterion(outputs_, targs_.long())

 类似资料: