Repository navigation
Any guide on implementing and building custom operator #26431
Replies: 2 comments
|
Hi Kwangyeon, Yes. ONNX Runtime has a supported custom-op API, and custom operators can be compiled into a shared library ( I’d recommend starting with the official guide and its shared-library example:
A practical workflow is:
For a quick proof of concept, implement a simple CPU operator first, such as element-wise addition, and run a tiny ONNX model that invokes it. Once that works, add your real operation and any required attributes or dynamic-shape handling. One important distinction: if you want the operator to become a built-in ONNX Runtime operator rather than a separately loaded custom op, that is a different contribution path involving the runtime’s operator schema, kernel implementation, and tests. For application-specific functionality, a custom-op shared library is usually the more direct approach. If you share whether you are targeting Windows or Linux, and whether your operator should run on CPU or GPU, the build and registration steps can be narrowed down for your setup. If this answer helped or pointed you in the right direction, I'd appreciate it if you could mark it as the accepted answer so it's easier for others with the same issue to find. Also, if you found my contribution useful, I'd appreciate it if you could check out my GitHub profile, follow me, and star any repositories you find interesting. GitHub: https://github.com/Advait251206 |
|
For a concrete DLL/SO example, look at ORT's own The CMake target builds a shared library. Use matching ORT releases for the headers/build and the Python runtime. After configuring an ORT source build with unit-test targets enabled, you can build that target directly: cmake --build <configured-ORT-build-dir> --config Release --target custom_op_libraryThen load the generated library before creating the session: import onnxruntime as ort
opts = ort.SessionOptions()
opts.register_custom_ops_library("/absolute/path/libcustom_op_library.so")
session = ort.InferenceSession(
"custom_op_test.onnx", opts, providers=["CPUExecutionProvider"]
)Use |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to implement and build custom operator for onnx to import .dll or .so in onnxruntime session, but the documentation is not that helpful. Is there any practical guide on it?
All reactions