Skip to content

Map aten bitwise operators to existing ONNX ones #5497

Closed as not planned
Closed as not planned

Description

@leandro-gracia-gil

Currently the aten bitwise operators are not supported in ONNX as listed here. However, as far as I can tell these operators are pretty straightforward (see CPU and CUDA implementations) so it should be possible to map them to existing ONNX bitwise operators.

In particular:

  • aten::bitwise_and -> BitwiseAnd
  • aten::bitwise_or -> BitwiseOr
  • aten::bitwise_not -> BitwiseNot
  • aten::bitwise_xor -> BitwiseXor
  • aten::left_shift -> BitShift
  • aten::right_shift -> BitShift

As a workaround until these ops are available, it also seems to be possible to do the mapping at export time.

torch.onnx.register_custom_op_symbolic(
    symbolic_name='aten::bitwise_and',
    symbolic_fn=lambda g, *args: g.op('BitwiseAnd', *args),
    opset_version=18)

Activity

  1. justinchuby commented on Aug 11, 2023

    @justinchuby
    Member

    Thanks for reporting the issue. I would open the same issue on the PyTorch as this concerns the PyTorch API. Contributions would be appreciated!

  2. leandro-gracia-gil commented on Aug 11, 2023

    @leandro-gracia-gil
    Author

    Thanks for pointing out the implementation. I wonder why pyTorch was failing to export it then, even when using recent ONNX opset versions.

  3. justinchuby commented on Aug 11, 2023

    @justinchuby
    Member

    The implementation is for the new PyTorch exporter: torch.onnx.dynamo_export. You may experiment with it using the latest torch nightly build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: operatorIssues related to ONNX operators

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions