已经支持autograd的复杂功能-Pytorch

问题描述

我正在使用此自定义函数自定义损失函数中重塑我的张量。

f(list(t))

但是,我收到此错误

def reshape_fortran(x,shape): if len(x.shape) > 0: x = x.permute(*reversed(range(len(x.shape)))) return x.reshape(*reversed(shape)).permute(*reversed(range(len(shape))))

用于RuntimeError: _unsafe_view does not support automatic differentiation for outputs with complex dtype. 输出

您知道可能是什么问题吗? Pytorch autograd中不支持复数的哪个功能

解决方法

我可以改用此函数来解决问题,但是我不知道为什么它不起作用以及为什么现在可以起作用:

def convert_output84_torch(input):
  shape84 = (8,4)
  T1 = torch.transpose(input,2).permute(0,1,2).contiguous()
  T2 = T1.view(shape84[::-1])
  output = torch.transpose(T2,1)
  return output

我将reshape替换为view,并且目前工作正常。但是由于我的代码以前运行良好,所以我不确定它是否是一个长期解决方案,因为我不知道主要的来源。

,

Complex Autograd 从 1.8 版开始就处于 Beta 版,但现在很稳定,应该完全支持 1.9 起的此类操作。