Complex functions : "exp does not support automatic differentiation for outputs with complex dtype."

Hi, it seems that my very elementary complex exponential does not support Autograd :

z = torch.tensor([1.1-2j], requires_grad=True)
f = torch.exp(z)

gives me a RunTimeError :

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-31-69abc9207ce8> in <module>
      1 z = torch.tensor([1.1-2j], requires_grad=True)
----> 2 f = torch.exp(z)

RuntimeError: exp does not support automatic differentiation for outputs with complex dtype.

How can I use Autograd with complex functions in general, and with the elementary complex exponential in particular ?

Thank you,
S

Hi,

In preparation for the 1.7 release and to avoid issues, we added error messages for all the functions that were not yet audited for complex autograd.
We are working on auditing the formulas and re-enabling them.

cc @anjali411 do we have an issue describing the process if people want to help here?

Thank you.
Is there a list of the complex functions that already support autograd ?

Yes you can find the list here: https://github.com/pytorch/pytorch/blob/master/tools/autograd/gen_variable_type.py#L151-L164

You can find the PRs adding new support by doing a search like that: https://github.com/pytorch/pytorch/pulls?q=is%3Aopen+is%3Apr+label%3A"module%3A+complex"

Also if you need another op that no one is implementing, feel free to send a PR and it will be available on the next nightly build after it is merged :slight_smile:

Maybe you can use torch.cos(z) + 1j * torch.sin(z) instead.

1 Like

Hey albanD, I am using the stable Pytorch 1.7.1 build and when I try testing functions that are listed under the GRADIENT_IMPLEMENTED_FOR_COMPLEX the ‘does not support automatic differentiaion’ error still occurs for many of them. Should I instead use the nightly build to access these complex autogradients? Thanks

It depends where you are checking that constant. If you check it on master, then yes it will correspond to the nightly build.
For the ones supported in 1.7.1, you can check the version that was used for the release here: pytorch/gen_variable_type.py at 57bffc3a8e4fee0cce31e1ff1f662ccf7b16db57 · pytorch/pytorch · GitHub

1 Like