mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-26 08:34:52 +08:00
Pull Request resolved: https://github.com/pytorch/pytorch/pull/158531 Approved by: https://github.com/AlannaBurke, https://github.com/mlazos, https://github.com/anijain2305 ghstack dependencies: #157985, #158055 Co-authored-by: Svetlana Karslioglu <svekars@meta.com>
1013 B
1013 B
Custom Operators
Summary:
- Use custom operators to have
torch.compiletreat a function as opaque.torch.compilewill never trace into the function and Inductor (the backend) will run the function as-is.
You may wish to use a custom operator in any of the following situations:
- Your code calls some C/C++/CUDA code. Dynamo is a Python bytecode interpreter and generally does not know how to handle calls to C/C++/CUDA functions that are bound to Python.
- Dynamo and non-strict tracing have trouble tracing through a function and you want it to be ignored by
torch.compile.
Please see the Python custom ops tutorialfor more details on how to wrap a Python function into a torch.compile-understood custom operator.
For more advanced use cases, you may wish to use our C++ Custom Operator API; please see here for more information.