Skip to content

Commit 0ae7340

Browse files
authored
Merge pull request #397 from goldsborough/custom-op-faq
Change format of note about types in custom TorchScript ops
2 parents d1b279f + 46aaed6 commit 0ae7340

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

advanced_source/torch_script_custom_ops.rst

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ in Python). The return type of our ``warp_perspective`` function will also be a
8585
allocate and initialize new tensor objects in C++ (not required for this
8686
operator).
8787

88+
.. attention::
89+
90+
The TorchScript compiler understands a fixed number of types. Only these types
91+
can be used as arguments to your custom operator. Currently these types are:
92+
``torch::Tensor``, ``torch::Scalar``, ``double``, ``int64_t`` and
93+
``std::vector``s of these types. Note that __only__ ``double`` and __not__
94+
``float``, and __only__ ``int64_t`` and __not__ other integral types such as
95+
``int``, ``short`` or ``long`` are supported.
96+
8897
Inside of our function, the first thing we need to do is convert our PyTorch
8998
tensors to OpenCV matrices, as OpenCV's ``warpPerspective`` expects ``cv::Mat``
9099
objects as inputs. Fortunately, there is a way to do this **without copying
@@ -874,7 +883,9 @@ lines between Python, TorchScript and C++ to blend smoothly.
874883
875884
As always, if you run into any problems or have questions, you can use our
876885
`forum <https://discuss.pytorch.org/>`_ or `GitHub issues
877-
<https://github.com/pytorch/pytorch/issues>`_ to get in touch.
886+
<https://github.com/pytorch/pytorch/issues>`_ to get in touch. Also, our
887+
`frequently asked questions (FAQ) page
888+
<https://pytorch.org/cppdocs/notes/faq.html>`_ may have helpful information.
878889
879890
Appendix A: More Ways of Building Custom Operators
880891
--------------------------------------------------
@@ -1076,34 +1087,3 @@ visible to TorchScript:
10761087
>>> torch.ops.load_library("warp_perspective.so")
10771088
>>> print(torch.ops.custom.warp_perspective)
10781089
<built-in method custom::warp_perspective of PyCapsule object at 0x7ff51c5b7bd0>
1079-
1080-
1081-
FAQ
1082-
---------------------------------------
1083-
1084-
1085-
Custom Ops Types
1086-
*******************
1087-
1088-
TorchScript custom Ops supports a limited number of types. The types supported by JIT custom ops are declared `here<https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/core/jit_type.h>`_.
1089-
1090-
Currently, the types that are supported are:
1091-
1092-
- torch::Tensor
1093-
- at::Scalar
1094-
1095-
This represents the python number
1096-
1097-
- double
1098-
1099-
Note that float is not currently supported.
1100-
1101-
- int64_t
1102-
1103-
Note that int is not currently supported.
1104-
1105-
- bool
1106-
- string
1107-
- std::vector<torch::Tensor>
1108-
- std::vector<double>
1109-
- std::vector<int64_t>

0 commit comments

Comments
 (0)