Function AddmmBackward returned an invalid gradient at index 1报错解决

最近在写程序的时候,在损失进行反向传播的时候,出现了这样的一个错误

Function MmBackward returned an invalid gradient at index 0 - got [2400, 150] but expected shape compatible with [2400, 768]

为了排查错误,我们首先使用注释法注释掉网络结构的一些内容,然后再接着跑
(排查是哪一个网络结构出现了问题)

output = self.dense(output)
output = self.activation(output)

注释完之后就很快发现了问题,是dense网络层出现了错误
dense网络层的定义错误

self.dense = nn.Linear(out_channels,1)

这里的out_channels = 150,实际上out_channels的值应该为768

Guess you like

Origin blog.csdn.net/znevegiveup1/article/details/121216900