[MLX] Add aten.bitwise_or op handler
Summary:
- Add an MLX schema node and op handler for
aten.bitwise_orTensor and Scalar overloads. - Execute the node through MLX
bitwise_orin the runtime interpreter. - Add bool, integer, and scalar op test coverage.
Fixes #18926.
Testing:
cmake --build cmake-out-mlx --target op_test_runner -j2PATH="$PWD/.venv-mlx/bin:$PATH" .venv-mlx/bin/python -m executorch.backends.mlx.test.run_all_tests bitwise_or_bool bitwise_or_int bitwise_or_scalar --timeout 180cmake --build cmake-out-mlx --target strict_compile_test -j2git diff --checkpy_compileon changed Python fileslintrunner --take FLAKE8,CLANGFORMAT,NEWLINE,ETCAPITAL,LICENSELINTon touched files
:link: Helpful Links
:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19869
- :page_facing_up: Preview Python docs built from this PR
Note: Links to docs will display an error until the docs builds have been completed.
:x: 1 Cancelled Job, 2 Unrelated Failures
As of commit ab83bbb49e4bf485e142e9c74012030a8dab7e00 with merge base 37effad30f951cc0066b986f792fa22617415fa0 ():
CANCELLED JOB - The following job was cancelled. Please retry:
- pull / test-models-linux (phi_4_mini, portable, linux.4xlarge.memory) / linux-job (gh)
##[error]The operation was canceled.
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
- MLX / test-mlx-voxtral-realtime / test-mlx-voxtral-realtime (gh) (detected as infra flaky with no log or failing log classifier)
- pull / test-qnn-testsuite-linux / test-backend-linux (qnn, models) / linux-job (gh) (detected as infra flaky with no log or failing log classifier)
This comment was automatically generated by Dr. CI and updates every 15 minutes.
This PR needs a
release notes:labelIf your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with
release notes:. This helps us keep track and include your important work in the next release notes.To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"For more information, see https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.
@pytorchbot label "release notes: apple"
@claude review
Claude finished @nil-is-all's task in 2m 43s —— View job
Code Review: [MLX] Add aten.bitwise_or op handler
- [x] Read changed files and gather context
- [x] Review
backends/mlx/ops.pychanges - [x] Review
backends/mlx/runtime/MLXInterpreter.hchanges - [x] Review
backends/mlx/serialization/schema.fbschanges - [x] Review
backends/mlx/test/test_ops.pychanges - [x] Post review feedback
Verdict: Looks good. This is a clean, well-structured addition that follows the exact same pattern as the existing bitwise_and op. No issues found.
Details
Schema (schema.fbs):
BitwiseOrNodetable correctly mirrors theBitwiseAndNodestructure witha,b, andoutfields- Appended to the
OpNodeunion at the end (respecting backward compatibility rules)
Runtime (MLXInterpreter.h):
exec_bitwise_orfollows the identical pattern asexec_bitwise_and— delegates directly to MLX'sbitwise_or- Dispatch case
OpCode::BITWISE_ORcorrectly wired up in the switch statement
Python ops (ops.py):
- Registers both
TensorandScalaroverloads via the_BINARY_OPStable withhas_scalar=True - Correctly imports
BitwiseOrNodefrom the generated schema
Tests (test_ops.py):
bitwise_or_boolandbitwise_or_intcover Tensor-Tensor via the_BINARY_OP_TESTStableBitwiseOrScalarTestcovers the Scalar overload with bool, int32, and int64 dtypes- Test structure is identical to the existing
BitwiseAndScalarTest
No correctness, performance, or compatibility concerns. The implementation correctly leverages MLX's native bitwise_or which handles broadcasting, and the scalar variant is handled by the framework's existing _BINARY_OPS infrastructure that wraps scalars into tensors before calling the op.
LGTM...let's see what CI says
~~Workflows were awaiting approval.~~ CI has now been triggered for the ciflow labels on this PR.
@devin-lai it looks like [MLX / backend-tester (models) / test-mlx-backend-models (push)] is failing. Can you have a look at why?
@devin-lai it looks like [MLX / backend-tester (models) / test-mlx-backend-models (push)] is failing. Can you have a look at why?
ok. I checked the logs for the failing push run. The job failed because the MLX model suite allows up to 3 failures, but this run had 4
The 3 failures that also appear in the passing PR-triggered run are:
- test_conformer[mlx-static_shapes-float32]
- test_swin_v2_t[mlx-static_shapes-float32]
- test_swin_v2_t[mlx-dynamic_shapes-float32]
The extra failure in the push run is:
- test_inception_v3 [mlx-dynamic_shapes-float32]
That one failed with a numerical output mismatch, not with a missing op, serialization issue, or anything obviously related to the bitwise_or change. The same SHA passed the PR-triggered MLX backend-models job with exactly 3 failures, and the MLX operator job passed.
This looks like a flaky/threshold-sensitive MLX model-suite failure rather than a regression from this PR. I tried to rerun the failed push job directly, but GitHub requires admin rights on pytorch/executorch. Could someone with permission rerun the failed job/run? If it reproduces, I can help look into the Inception V3 dynamic-shape case separately
@devin-lai it looks like [MLX / backend-tester (models) / test-mlx-backend-models (push)] is failing. Can you have a look at why?
ok. I checked the logs for the failing push run. The job failed because the MLX model suite allows up to 3 failures, but this run had 4
The 3 failures that also appear in the passing PR-triggered run are:
- test_conformer[mlx-static_shapes-float32]
- test_swin_v2_t[mlx-static_shapes-float32]
- test_swin_v2_t[mlx-dynamic_shapes-float32]
The extra failure in the push run is:
- test_inception_v3 [mlx-dynamic_shapes-float32]
That one failed with a numerical output mismatch, not with a missing op, serialization issue, or anything obviously related to the bitwise_or change. The same SHA passed the PR-triggered MLX backend-models job with exactly 3 failures, and the MLX operator job passed.
This looks like a flaky/threshold-sensitive MLX model-suite failure rather than a regression from this PR. I tried to rerun the failed push job directly, but GitHub requires admin rights on pytorch/executorch. Could someone with permission rerun the failed job/run? If it reproduces, I can help look into the Inception V3 dynamic-shape case separately
Re-running CI. Let's see if it passes now.
Looks like it passes now. Thanks for the contribution @devin-lai!