Add MLX op handler for aten.isnan#18952
Conversation
Add a handler for aten.isnan in the MLX delegate using the mathematical property that NaN != NaN (NaN is the only value not equal to itself). This uses the existing NotEqualNode by comparing x with itself. Also add corresponding test with a custom input function that injects NaN values at a configurable fraction.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18952
Note: Links to docs will display an error until the docs builds have been completed. ❌ 14 New Failures, 21 PendingAs of commit 49811c4 with merge base 9576316 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@claude review |
|
Claude finished @kirklandsign's task in 1m 21s —— View job Review of PR #18952: Add MLX op handler for aten.isnan
This is a clean, well-structured PR. The implementation is correct and follows existing patterns in the codebase. A few observations: Handler (
|
|
Looks good to me. Re-running tests to see if there are any failures |
Good day
Summary
This PR adds an MLX op handler for
aten.isnanto the PyTorch ExecuTorch MLX delegate, as requested in issue #18920.Changes
Handler (
backends/mlx/ops.py)Added
_isnan_handlerregistered fortorch.ops.aten.isnan.default. The implementation uses the mathematical property thatNaN != NaN— NaN is the only floating-point value that is not equal to itself — to decompose the operation as:This uses the existing
NotEqualNodeby comparing the input with itself, avoiding the need for a dedicated MLX isnan primitive.Test (
backends/mlx/test/test_ops.py)_nan_input_fn(nan_frac)helper that generates tensors with a configurable fraction of NaN values.isnanentry to_UNARY_OP_TESTScovering_SHAPES_3and three float dtypes (float32,float16,bfloat16).Testing
The test can be run with:
The implementation is consistent with the approach described in the linked issue and follows the existing code patterns in the MLX backend.
Thank you for your attention. If there are any issues or suggestions, please leave a comment and I will address them promptly.
Warmly,
RoomWithOutRoof