Commit 107eb92
Add MLX op handler for aten.isnan (#18952)
Good day
## Summary
This PR adds an MLX op handler for `aten.isnan` to the PyTorch
ExecuTorch MLX delegate, as requested in issue #18920.
## Changes
### Handler (`backends/mlx/ops.py`)
Added `_isnan_handler` registered for `torch.ops.aten.isnan.default`.
The implementation uses the mathematical property that `NaN != NaN` —
NaN is the only floating-point value that is not equal to itself — to
decompose the operation as:
```
isnan(x) = x != x
```
This uses the existing `NotEqualNode` by comparing the input with
itself, avoiding the need for a dedicated MLX isnan primitive.
### Test (`backends/mlx/test/test_ops.py`)
- Added `_nan_input_fn(nan_frac)` helper that generates tensors with a
configurable fraction of NaN values.
- Added `isnan` entry to `_UNARY_OP_TESTS` covering `_SHAPES_3` and
three float dtypes (`float32`, `float16`, `bfloat16`).
## Testing
The test can be run with:
```bash
python -m executorch.backends.mlx.test.run_all_tests -k isnan
```
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
Co-authored-by: RoomWithOutRoof <roomwithoutroof@users.noreply.github.com>
Co-authored-by: Scott Roy <161522778+metascroy@users.noreply.github.com>1 parent 9576316 commit 107eb92
2 files changed
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
421 | 447 | | |
422 | 448 | | |
423 | 449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4004 | 4004 | | |
4005 | 4005 | | |
4006 | 4006 | | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
4007 | 4023 | | |
4008 | 4024 | | |
4009 | 4025 | | |
| |||
4095 | 4111 | | |
4096 | 4112 | | |
4097 | 4113 | | |
| 4114 | + | |
4098 | 4115 | | |
4099 | 4116 | | |
4100 | 4117 | | |
| |||
0 commit comments