Skip to content

Support in-place PyTorch bitwise and logical ops (__ior__, __iand__, __ixor__) - #2816

Open
jaseem-kurikkal wants to merge 1 commit into
apple:mainfrom
jaseem-kurikkal:feat/support-inplace-bitwise-logical-ops
Open

Support in-place PyTorch bitwise and logical ops (__ior__, __iand__, __ixor__)#2816
jaseem-kurikkal wants to merge 1 commit into
apple:mainfrom
jaseem-kurikkal:feat/support-inplace-bitwise-logical-ops

Conversation

@jaseem-kurikkal

Copy link
Copy Markdown

Summary

Adds support for in-place PyTorch logical and bitwise operators (__ior__, __iand__, __ixor__, i.e., |=, &=, ^=) in the PyTorch frontend.

Context / Motivation

Modern transformer and LLM architectures (such as attention mask construction in Gemma and LLaMA) make frequent use of in-place boolean masking (mask1 |= mask2). When converted, PyTorch emits aten::__ior__, aten::__iand__, and aten::__ixor__ nodes (sanitized to ior, iand, ixor), which previously raised:

NotImplementedError: PyTorch convert function for op 'ior' not implemented.

Changes

  • Registered iand, ior, and ixor aliases for bitwise_and, bitwise_or, and bitwise_xor in coremltools/converters/mil/frontend/torch/ops.py.
  • Added unit test cases (test_and_operator, test_iand_operator, test_ior_operator, test_xor_operator, test_ixor_operator) in coremltools/converters/mil/frontend/torch/test/test_torch_ops.py covering TorchScript and TorchExport across all backend and compute unit permutations.

Testing

Ran:

pytest coremltools/converters/mil/frontend/torch/test/test_torch_ops.py -k "TestBitwise"

@TobyRoseman

Copy link
Copy Markdown
Collaborator

This change looks good.

CI: https://gitlab.com/coremltools1/coremltools/-/pipelines/2767223028

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants