Registering operator for MatrixInverse
Closed this issue · 3 comments
Please provide guidance on registering a matrix inversion op such as com.microsoft.Inverse op for the node 'MatrixInverse' in a model.
System information
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Centos 7
tf2onnx version: 1.9.1
ONNX Runtime version: 1.8.1
Python version: 3.7
To Reproduce
I have a proprietary tensorflow model which I cannot share. However, the original model uses tf.linalg.inv() operation and I used tf2onnx Python API to convert the model to ONNX.
During the conversion using tf2onnx, I got the message from tf2onnx:
Tensorflow op [model_5/lambda_5/MatrixInverse: MatrixInverse] is not supported
Unsupported ops: Counter({'MatrixInverse': 1})
The onnx file was still produced by tf2onnx and I understand that the suspect node needs to be registered with a relevant operation before it can be executed in onnxruntime. Without this, I get the following error from onnxruntime:
onnxruntime.capi.onnxruntime_pybind11_state.InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : Load model from model.onnx failed:This is an invalid model. Error in Node:model_5/lambda_5/MatrixInverse : No Op registered for MatrixInverse with domain_version of 9
I opened issue #8397 at onnxruntime and they pointed me here.
I notice that there is an implementation for inverse in onnxruntime's contrib_ops. I was wondering if there is a way for me to register the same for the MatrixInverse node.
Can you please guide me as to how I can accomplish it?
Yes, you can register a new op in tf2onnx. Check out this example: https://github.com/microsoft/onnxruntime-extensions/blob/main/tutorials/tf2onnx_custom_ops_tutorial.ipynb (Just the part under "Adding a custom op conversion rule using python" is related)
But it turns out we already have a conversion in tf2onnx! Just add the --extra_opset com.microsoft:1
and it should convert it.
Yes, Inverse is already here:
https://github.com/onnx/tensorflow-onnx/blob/master/tf2onnx/custom_opsets/ms.py
and as Tom said --extra_opset com.microsoft:1
should enable it.
No response from user yet, close it.