-
Notifications
You must be signed in to change notification settings - Fork 940
Add MLX op handler for aten.isinf #18936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4004,6 +4004,22 @@ def fn(shape, dtype): | |
| return fn | ||
|
|
||
|
|
||
| def _inf_input_fn(): | ||
| """Return a callable(shape, dtype) that generates inputs with some inf/nan values.""" | ||
|
|
||
| def fn(shape, dtype): | ||
| x = torch.randn(shape, dtype=dtype) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add some nans to this generated test input as well?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — added NaN values to |
||
| mask_pos = torch.rand(shape) > 0.8 | ||
| mask_neg = torch.rand(shape) > 0.9 | ||
| mask_nan = torch.rand(shape) > 0.85 | ||
| x[mask_pos] = float("inf") | ||
| x[mask_neg] = float("-inf") | ||
| x[mask_nan] = float("nan") | ||
| return (x,) | ||
|
|
||
| return fn | ||
|
|
||
|
|
||
| # Standard shape and dtype configs used by unary tests. | ||
| _SHAPES_3 = [(16,), (4, 4), (2, 3, 4)] | ||
| _SHAPES_2 = [(16,), (4, 4)] | ||
|
|
@@ -4103,6 +4119,7 @@ def create_model(self) -> nn.Module: | |
| # math | ||
| {"op_name": "rsqrt", "op_fn": torch.rsqrt, "shapes": [(2, 3, 4), (10,), (4, 8), (2, 8, 16), (1, 64)], "dtypes": [torch.float32], "input_fn": _input_fn(uniform=True, offset=0.1)}, | ||
| {"op_name": "clone", "op_fn": torch.clone, "shapes": [(2, 3, 4), (8, 8), (16,)], "dtypes": [torch.float32]}, | ||
| {"op_name": "isinf", "op_fn": torch.isinf, "shapes": _SHAPES_3, "input_fn": _inf_input_fn()}, | ||
| ] | ||
| # fmt: on | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other variants of this torch op? E.g., isinf.Tensor, etc.
There may not be, just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the PyTorch ATen operator registry and the executorch codebase — the only variant is
aten.isinf.default. There is noisinf.Tensororisinf.outoverload defined. The other backends (MPS, Qualcomm) also only registeraten.isinf.default, so this handler covers the complete surface.