@@ -0,0 +1,1262 @@
+import torch%0Aimport onnxruntime as _ort%0Aimport io%0Aimport numpy%0A%0Afrom torch.onnx import register_custom_op_symbolic%0Afrom ortcustomops import (%0A    onnx_op,%0A    get_library_path as _get_library_path)%0A%0A%0A@onnx_op(op_type=%22Inverse%22)%0Adef inverse(x):%0A    # the user custom op implementation here:%0A    return numpy.linalg.inv(x)%0A%0A%0Adef my_inverse(g, self):%0A    return g.op(%22ai.onnx.contrib::Inverse%22, self)%0A%0A%0A# register_custom_op_symbolic('%3Cnamespace%3E::inverse', my_inverse, %3Copset_version%3E)%0Aregister_custom_op_symbolic('::inverse', my_inverse, 1)%0A%0A%0Aclass CustomInverse(torch.nn.Module):%0A    def forward(self, x):%0A        return torch.inverse(x) + x%0A%0A%0Ax = torch.randn(3, 3)%0A%0A# Export model to ONNX%0Af = io.BytesIO()%0Atorch.onnx.export(CustomInverse(), (x,), f)%0A%0Amodel = CustomInverse()%0Apt_outputs = model(x)%0A%0Aso = _ort.SessionOptions()%0Aso.register_custom_ops_library(_get_library_path())%0A%0A# Run the exported model with ONNX Runtime%0Aort_sess = _ort.InferenceSession(f.getvalue(), so)%0Aort_inputs = dict((ort_sess.get_inputs()%5Bi%5D.name, input.cpu().numpy()) for i, input in enumerate((x,)))%0Aort_outputs = ort_sess.run(None, ort_inputs)%0A%0A# Validate PyTorch and ONNX Runtime results%0Anumpy.testing.assert_allclose(pt_outputs.cpu().numpy(), ort_outputs%5B0%5D, rtol=1e-03, atol=1e-05)%0A

add a pytorch custom op example. (#5)