Skip to content

Commit

Permalink
Clarify Python custom operators do not work without Python (#3212)
Browse files Browse the repository at this point in the history
  • Loading branch information
zou3519 authored Jan 6, 2025
1 parent d8a9749 commit 7f76cfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions advanced_source/custom_ops_landing_page.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You may wish to author a custom operator from Python (as opposed to C++) if:
respect to ``torch.compile`` and ``torch.export``.
- you have some Python bindings to C++/CUDA kernels and want those to compose with PyTorch
subsystems (like ``torch.compile`` or ``torch.autograd``)
- you are using Python (and not a C++-only environment like AOTInductor).

Integrating custom C++ and/or CUDA code with PyTorch
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions advanced_source/python_custom_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
into the function).
- Adding training support to an arbitrary Python function
Use :func:`torch.library.custom_op` to create Python custom operators.
Use the C++ ``TORCH_LIBRARY`` APIs to create C++ custom operators (these
work in Python-less environments).
See the `Custom Operators Landing Page <https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html>`_
for more details.
Please note that if your operation can be expressed as a composition of
existing PyTorch operators, then there is usually no need to use the custom operator
API -- everything (for example ``torch.compile``, training support) should
Expand Down

0 comments on commit 7f76cfd

Please sign in to comment.