tensorflow-onnx icon indicating copy to clipboard operation
tensorflow-onnx copied to clipboard

Unsupported tensorflow ops: `BitwiseXor`, `BitwiseOr`, `Bitcast`, `BitwiseAnd`

Open josephrocca opened this issue 3 years ago • 5 comments

Describe the bug The BitwiseXor, BitwiseOr, Bitcast, and BitwiseAnd ops are not supported by the converter.

  1. https://www.tensorflow.org/api_docs/python/tf/raw_ops/Bitcast
  2. https://www.tensorflow.org/api_docs/python/tf/raw_ops/BitwiseAnd
  3. https://www.tensorflow.org/api_docs/python/tf/raw_ops/BitwiseOr
  4. https://www.tensorflow.org/api_docs/python/tf/raw_ops/BitwiseXor

For context, I'm trying to convert a BART model to ONNX.

I've tried up to opset 16 and installed from Github with pip install git+https://github.com/onnx/tensorflow-onnx to get latest changes.

Urgency No hard deadlines.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): 18.04 (Google Colab)
  • Tensorflow Version: 2.8.2
  • Python version: 3.7.13

To Reproduce I don't think a reproduction is needed, since this is simply about op support. But I can definitely provide a reproduction if requested.

josephrocca avatar Jun 29 '22 18:06 josephrocca

Hi @fatcat-z, I'm wondering if you could provide some guidance: In case you're currently too busy to add support for these, I'm wondering what a general plan/outline might be for me to try to add support - as someone who hasn't done this sort of thing before, but is eager to give it a shot (since it is a blocker for me)?

My plan was to find a pull request that's kind of analogous to these ops, and then see what they've done, and try to emulate that. But upon looking at this list of ONNX ops, it looks like ONNX doesn't actually have equivalent or related/superset ops to convert to? Am I correct in assuming that lack of equivalent ONNX ops blocks this issue, or is there perhaps some way to get around this?

Note that my target platform is web (using ONNX Runtime Web), and so IIUC this means that I can't use custom op stuff, but I could be wrong there.

Thanks!

josephrocca avatar Jul 02 '22 11:07 josephrocca

Hi @fatcat-z Jay Zhang FTE, I'm wondering if you could provide some guidance: In case you're currently too busy to add support for these, I'm wondering what a general plan/outline might be for me to try to add support - as someone who hasn't done this sort of thing before, but is eager to give it a shot (since it is a blocker for me)?

My plan was to find a pull request that's kind of analogous to these ops, and then see what they've done, and try to emulate that. But upon looking at this list of ONNX ops, it looks like ONNX doesn't actually have equivalent or related/superset ops to convert to? Am I correct in assuming that lack of equivalent ONNX ops blocks this issue, or is there perhaps some way to get around this?

Note that my target platform is web (using ONNX Runtime Web), and so IIUC this means that I can't use custom op stuff, but I could be wrong there.

Thanks!

You are right, ONNX doesn't support such op directly is blocking the conversion. A potential way is to combine existing ONNX ops to implement the same function in tf2onnx and then export them into final ONNX file. But after I took a quick check, there is no easy way to do it yet.

About using ONNX Runtime Web, per my understanding, its backend is still ONNX Runtime. Ideally, if you implement such a custom op in ONNXRuntime and then merge it into the code. You can then build and deploy ONNX Runtime Web with this new code, meaning the custom op is there. Then you can add corresponding code in tf2onnx to convert these tf ops to custom ops you implemented in ORT. It then will work well.

fatcat-z avatar Jul 04 '22 07:07 fatcat-z

@fatcat-z Thanks! I'll look into the custom op route that you recommended. I've also added an issue at @onnx/onnx to request support for these operators: https://github.com/onnx/onnx/issues/4343

josephrocca avatar Jul 04 '22 17:07 josephrocca

BitwiseXor, BitwiseOr, BitwiseNot, and BitwiseAnd are now implemented in ONNX:

  • https://github.com/onnx/onnx/pull/4496
  • https://github.com/onnx/onnx/pull/4497

I think Bitcast is still unimplemented.

josephrocca avatar Jan 04 '23 05:01 josephrocca