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

如何处理RuntimeError: _cdist_backward requires X1(X2) to be contiguous

东郭存
2023-12-01

错误通常报在loss.backward这一句。反向传播的时候,函数torch.cdist(x1,x2)需要为连续,如果有这个错说明X1(X2)的参数不连续,只要在这个参数后面加上.contiguous()就可以了。也就是如果报的是requires X1 to be contiguous那么只要找出torch.cdist,并改成
torch.cdist(x1.contiguous(),x2)就可以了

 类似资料: