RuntimeError: “nll_loss_forward_reduce_cuda_kernel_2d_index“ not implemented for ‘Int‘

本文探讨了一次在使用PyTorch进行模型训练时遇到的RuntimeError,焦点在于labels参数类型不匹配导致的'nll_loss_forward_reduce_cuda_kernel_2d_index'未实现。通过分析源代码和官方文档,发现问题在于labels应为long类型而非Int。解决方法是将labels转换为long并配合GPU使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Int'


今天有空,把之前遇到的问题总结一下。
问题Traceback详情

Traceback (most recent call last):
  File "E:/MyWorkspace/EEG/Pytorch/Train.py", line 79, in <module>
    opti='Adam')
  File "E:\MyWorkspace\EEG\Pytorch\Utils.py", line 133, in TrainTest_Model
    validation_loss, validation_acc = Test_Model(net, testloader, criterion,True)
  File "E:\MyWorkspace\EEG\EEGLearn-Pytorch\Utils.py", line 82, in Test_Model
    loss = criterion(outputs, labels.cuda()) # GPU
  File "D:\coson\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值