• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _jit_unsupported:
2
3TorchScript Unsupported PyTorch Constructs
4============================================
5
6Torch and Tensor Unsupported Attributes
7------------------------------------------
8
9
10TorchScript supports most methods defined on ``torch`` and ``torch.Tensor``, but we do not have full coverage.
11Here are specific known ops and categories of ops which have diverging behavior between
12Python and TorchScript. If you encounter something else that is not supported please
13file a GitHub issue. Deprecated ops are not listed below.
14
15
16
17.. automodule:: torch.jit.unsupported_tensor_ops
18
19
20Functions Not Correctly Bound on Torch
21~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
23The following functions will fail if used in TorchScript, either because they
24are not bound on `torch` or because Python expects a different schema than
25TorchScript.
26
27  * :func:`torch.tensordot`
28  * :func:`torch.nn.init.calculate_gain`
29  * :func:`torch.nn.init.eye_`
30  * :func:`torch.nn.init.dirac_`
31  * :func:`torch.nn.init.kaiming_normal_`
32  * :func:`torch.nn.init.orthogonal_`
33  * :func:`torch.nn.init.sparse`
34
35
36Ops With Divergent Schemas Between Torch & Python
37~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38
39The following categories of ops have divergent schemas:
40
41Functions which construct tensors from non-tensor inputs do not support the `requires_grad`
42argument, except for `torch.tensor`. This covers the following ops:
43
44  * :func:`torch.norm`
45  * :func:`torch.bartlett_window`
46  * :func:`torch.blackman_window`
47  * :func:`torch.empty`
48  * :func:`torch.empty_like`
49  * :func:`torch.empty_strided`
50  * :func:`torch.eye`
51  * :func:`torch.full`
52  * :func:`torch.full_like`
53  * :func:`torch.hamming_window`
54  * :func:`torch.hann_window`
55  * :func:`torch.linspace`
56  * :func:`torch.logspace`
57  * :func:`torch.normal`
58  * :func:`torch.ones`
59  * :func:`torch.rand`
60  * :func:`torch.rand_like`
61  * :func:`torch.randint_like`
62  * :func:`torch.randn`
63  * :func:`torch.randn_like`
64  * :func:`torch.randperm`
65  * :func:`torch.tril_indices`
66  * :func:`torch.triu_indices`
67  * :func:`torch.vander`
68  * :func:`torch.zeros`
69  * :func:`torch.zeros_like`
70
71The following functions require `dtype`, `layout`, `device` as parameters in TorchScript,
72but these parameters are optional in Python.
73
74  * :func:`torch.randint`
75  * :func:`torch.sparse_coo_tensor`
76  * :meth:`~torch.Tensor.to`
77
78
79PyTorch Unsupported Modules and Classes
80------------------------------------------
81
82TorchScript cannot currently compile a number of other commonly used PyTorch
83constructs. Below are listed the modules that TorchScript does not support, and
84an incomplete list of PyTorch classes that are not supported. For unsupported modules
85we suggest using :meth:`torch.jit.trace`.
86
87  * :class:`torch.nn.RNN`
88  * :class:`torch.nn.AdaptiveLogSoftmaxWithLoss`
89  * :class:`torch.autograd.Function`
90  * :class:`torch.autograd.enable_grad`
91