二、ONNX Runtime增加新的operator/kernel

來源文檔
onnx增加新的operator/kernel

可以通過以下3種方式在ONNXRuntime中編寫和註冊新operator/kernel

1. 使用實驗性的c API,暫不推薦,因爲API還不穩定,可能會有大變動,該方法不需要編譯ORT項目源碼。 Using the experimental custom op API in the C API (onnxruntime_c_api.h)

Note: These APIs are experimental and will change in the next release. They’re released now for feedback and experimentation.

  • Create an OrtCustomOpDomain with the domain name used by the custom ops
  • Create an OrtCustomOp structure for each op and add them to the OrtCustomOpDomain with OrtCustomOpDomain_Add
  • Call OrtAddCustomOpDomain to add the custom domain of ops to the session options
    See this for an example called MyCustomOp that uses the C++ helper API (onnxruntime_cxx_api.h).
    參考例子:https://github.com/onnx/tutorials/tree/master/PyTorchCustomOperator

2. 使用RegisterCustomRegistry API,該方法不需要編譯ORT項目源碼

  • 通過在include的路徑下的OpKernel and OpSchema APIs實現自己的kernel and schema。

  • 新建CustomRegistry object 並使用 registry註冊你自己的 kernel and schema。

  • 通過使用RegisterCustomRegistry API在ONNXRuntime註冊定製的registry。

  • Implement your kernel and schema (if required) using the OpKernel and OpSchema APIs (headers are in the include folder).

  • Create a CustomRegistry object and register your kernel and schema with this registry.

  • Register the custom registry with ONNXRuntime using RegisterCustomRegistry API.

See
this for an example.

3. 給ONNXRuntime貢獻Op,及直接修改onnxruntime內部的源碼。該方法需要編譯ORT項目源碼

這主要是針對正在向ONNX提議的Op。這樣,您如果馬上需要部署該Op無需等待ONNX團隊的批准。
This is mostly meant for ops that are in the process of being proposed to ONNX. This way you don’t have to wait for an approval from the ONNX team
if the op is required in production today.
See this for an example.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章