pytorch/torch
anjali411 415ed434aa Add whitelist for complex backward (#45461)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/45461

This PR disables autograd for all C -> C, R -> C functions which are not included in the whitelist `GRADIENT_IMPLEMENTED_FOR_COMPLEX`. In practice, there will be a RuntimeError during forward computation when the outputs are differentiable:
```
>>> x=torch.randn(4, 4, requires_grad=True, dtype=torch.cdouble)
>>> x.pow(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: pow does not support automatic differentiation for outputs with complex dtype.
```

The implicit assumption here is that all the C -> R functions have correct backward definitions. So before merging this PR, the following functions must be tested and verified to have correct backward definitions:
`torch.abs` (updated in #39955 ), `torch.angle`, `torch.norm`, `torch.irfft`, `torch.istft`.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D23998156

Pulled By: anjali411

fbshipit-source-id: 370eb07fe56ac84dd8e2233ef7bf3a3eb8aeb179
2020-09-30 08:45:55 -07:00
..
_C Add callgrind collection to Timer (#44717) 2020-09-30 05:52:54 -07:00
autograd Source code level attribution in profiler (#43898) 2020-09-30 00:57:35 -07:00
backends Enable typechecking for torch.testing._internal.common_quantized.* (#44805) 2020-09-17 14:24:32 -07:00
contrib Fix exception chaining in torch/ (#43836) 2020-08-31 20:26:23 -07:00
csrc Add whitelist for complex backward (#45461) 2020-09-30 08:45:55 -07:00
cuda Enable torch.cuda.amp typechecking (#45480) 2020-09-29 09:31:55 -07:00
distributed Source code level attribution in profiler (#43898) 2020-09-30 00:57:35 -07:00
distributions Remove py2 compatible future imports (#44735) 2020-09-16 12:55:57 -07:00
fft torch.fft: Multi-dimensional transforms (#44550) 2020-09-23 22:09:58 -07:00
for_onnx
futures
fx Create experimental FX graph manipulation library (#44775) 2020-09-29 15:32:41 -07:00
jit [JIT] Enable @unused syntax for ignoring properties (#45261) 2020-09-29 10:24:25 -07:00
legacy
lib [PyTorch/NCCL] Fix async error handling (#45456) 2020-09-29 15:44:34 -07:00
linalg Add torch.linalg.norm (#42749) 2020-08-28 18:28:33 -07:00
multiprocessing Remove py2 compatible future imports (#44735) 2020-09-16 12:55:57 -07:00
nn Some fixes to smooth_l1_loss (#45532) 2020-09-30 07:28:44 -07:00
onnx [ONNX] Fix view for dynamic input shape (#43558) 2020-09-28 14:46:51 -07:00
optim Add more tests for mt optimizers (#45475) 2020-09-28 23:59:58 -07:00
package [package] Add dependency viz (#45214) 2020-09-28 15:38:41 -07:00
quantization [quant] Add quant APIs to save/load observer state_dict (#44846) 2020-09-29 01:52:42 -07:00
sparse
testing Update backward formula for torch.dot and add backward definition for torch.vdot (#45074) 2020-09-29 12:52:03 -07:00
utils Add ShuffleDataset with buffer (#45290) 2020-09-30 07:58:15 -07:00
__config__.py
__future__.py
__init__.py Updates deterministic flag to throw a warning, makes docs consistent (#45410) 2020-09-29 11:17:33 -07:00
_appdirs.py
_classes.py [BE] Use f-string in various Python functions (#44161) 2020-09-04 07:38:25 -07:00
_jit_internal.py [JIT] Enable @unused syntax for ignoring properties (#45261) 2020-09-29 10:24:25 -07:00
_linalg_utils.py
_lobpcg.py Backward support for generalized eigenvalue solver with LOBPCG in forward [only k-rank SYMEIG case] (#43002) 2020-09-28 07:22:35 -07:00
_lowrank.py
_namedtensor_internals.py
_ops.py
_six.py Delete raise_from from torch._six (#43981) 2020-09-01 15:46:18 -07:00
_storage_docs.py
_tensor_docs.py torch.sgn for complex tensors (#39955) 2020-09-22 08:24:53 -07:00
_tensor_str.py
_torch_docs.py Fix docs for kwargs, q-z (#43589) 2020-09-29 22:57:02 -07:00
_utils_internal.py Remove py2 compatible future imports (#44735) 2020-09-16 12:55:57 -07:00
_utils.py [caffe2][torch] correctly re-raise Manifold StorageException 2020-08-28 11:41:10 -07:00
_VF.py Address JIT/Mypy issue with torch._VF (#43454) 2020-08-25 09:23:54 -07:00
_vmap_internals.py Beef up vmap docs and expose to master documentation (#44825) 2020-09-18 13:26:25 -07:00
abi-check.cpp
CMakeLists.txt Add callgrind collection to Timer (#44717) 2020-09-30 05:52:54 -07:00
custom_class_detail.h
custom_class.h Adding a version serialization type to ConvPackedParam (#43086) 2020-08-28 15:41:30 -07:00
extension.h
functional.py Improves fft doc consistency and makes deprecation warnings more prominent (#45409) 2020-09-29 09:07:49 -07:00
hub.py Add a torch.hub.load_local() function that can load models from any local directory with a hubconf.py (#44204) 2020-09-21 14:17:21 -07:00
library.h Add TORCH_SELECTIVE_NAME to AMP definitions (#44711) 2020-09-16 14:25:17 -07:00
overrides.py Add callgrind collection to Timer (#44717) 2020-09-30 05:52:54 -07:00
py.typed
quasirandom.py Type check quasirandom (#45434) 2020-09-28 16:49:38 -07:00
random.py
README.txt
script.h
serialization.py torch.package - a way to package models and code (#45015) 2020-09-22 21:21:21 -07:00
storage.py [BE] Use f-string in various Python functions (#44161) 2020-09-04 07:38:25 -07:00
tensor.py Makes rdiv consistent with div (#45407) 2020-09-29 08:34:01 -07:00
types.py Enable torch.tensor typechecks (#45077) 2020-09-24 08:22:06 -07:00

Note [TH abstraction violation]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TH/THC provide some hpp headers, which are proper C++ headers rather than
C headers.  These headers serve double duty as *internal implementation
detail* headers, whose contents should largely not be used by external
clients.

Ideally, we would not install these headers at all; instead, you should
use public functions (in headers like `THTensor.h`, NOT `THTensor.hpp`)
to manipulate these structs.  However, there are a few places
in torch/csrc where we violate this abstraction.  They are marked with
a pointer to this note.  Each of those sites will have to be refactored
when we refactor the guts of THTensor and related structures.