How can we train on a complex tensor?

I perform a Fourier transform with my data and then feed it into the network, but I get type mismatches. I believe that this is why complexPyTorch still exists, but I was wondering if there is a way to pass a complex tensor into a model without getting a type error. Any example (related to a GRU if possible) that could be provided would be very much appreciated.

Thank you

@ptrblck if you’re able to, would you please offer some advice related to this? Thank you

Complex modules are not fully supported yet and you could thus try if the modules you want to use would already work. E.g. GRU seems to work on the CPU already:

rnn = nn.GRU(10, 20, 2).to(torch.complex64)
input = torch.randn(5, 3, 10).to(torch.complex64)
h0 = torch.randn(2, 3, 20).to(torch.complex64)
output, hn = rnn(input, h0)

and yields a warning:

UserWarning: Complex modules are a new feature under active development whose design may change, and some modules might not work as expected when using complex tensors as parameters or buffers. Please file an issue at https://github.com/pytorch/pytorch/issues/new?template=bug-report.md if a complex module does not work as expected.

so feel free to create a feature request for non-working modules.

1 Like