-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[JIT] Build mechanism for custom operators #10226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9b8ab0f to
e43ebb2
Compare
e43ebb2 to
8cb6d71
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goldsborough has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
test/custom_operator/test.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/custom_operator/op.cpp
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/custom_operator/op.cpp
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/custom_operator.h
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/custom_operator.h
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
8cb6d71 to
9d5f8a0
Compare
|
Thanks for the review! I added code to dynamically load a shared library in the way that caffe2 does it. This avoid having to make the user |
|
One last TODO is to try the end-to-end flow of defining a script module in C++ that uses a custom operator registered inside Python, then exporting that to something that is loaded from C++, and then executing the module from C++. Ok, actually, I will do this in a separate PR. There is more work to be done here. Let's keep this PR as the build integration. |
dzhulgakov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but please double check the CMake part
cmake/Modules/FindTorch.cmake
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/custom_operator/test.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/test_jit.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
zdevito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JIT changes look good. I don't know enough about CMake best practices to comment there.
test/custom_operator/CMakeLists.txt
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/custom_operator.h
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/csrc/jit/custom_operator.h
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Create CMake setup for custom ops Fixes to enable custom op build Figure out Python integration Fix Windows Fix python test for custom op and give bound operators better docstrings
2d30ac6 to
b017f0a
Compare
|
I think if tests pass I will land this diff. I know the CMake stuff can be improved, but this diff has code changes unrelated to the cmake. I will then create a new PR that integrates the custom operator tests with CI, in which we can discuss the proper way of doing the TorchConfig.cmake. I spent a little time looking at how Caffe2Config.cmake works, but there may be some open questions |
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goldsborough has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
56d5f13 to
8e20a7e
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goldsborough is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
8e20a7e to
f02b340
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goldsborough is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary:
This is the last step in the custom operator implementation: providing a way to build from C++ and Python. For this I:
1. Created a `FindTorch.cmake` taken largely from ebetica with a CMake function to easily create simple custom op libraries
2. Created a ` torch/op.h` header for easy inclusion of necessary headers,
3. Created a test directory `pytorch/test/custom_operator` which includes the basic setup for a custom op.
1. It defines an op in `op.{h,cpp}`
2. Registers it with the JIT using `RegisterOperators`
3. Builds it into a shared library via a `CMakeLists.txt`
4. Binds it into Python using a `setup.py`. This step makes use of our C++ extension setup that we already have. No work, yey!
The pure C++ and the Python builds are separate and not coupled in any way.
zdevito soumith dzhulgakov
Pull Request resolved: pytorch/pytorch#10226
Differential Revision: D9296839
Pulled By: goldsborough
fbshipit-source-id: 32f74cafb6e3d86cada8dfca8136d0dfb1f197a0

This is the last step in the custom operator implementation: providing a way to build from C++ and Python. For this I:
FindTorch.cmaketaken largely from @ebetica with a CMake function to easily create simple custom op librariestorch/op.hheader for easy inclusion of necessary headers,pytorch/test/custom_operatorwhich includes the basic setup for a custom op.op.{h,cpp}RegisterOperatorsCMakeLists.txtsetup.py. This step makes use of our C++ extension setup that we already have. No work, yey!The pure C++ and the Python builds are separate and not coupled in any way.
@zdevito @soumith @dzhulgakov