Add MLX op handler for aten.isinf#18988
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18988
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
Implement isinf op handler for the MLX delegate backend. isinf(x) is decomposed as abs(x) == inf, using existing AbsNode and EqualNode which are already supported in the MLX graph schema. The handler also includes a corresponding test case with _inf_input_fn that generates inputs containing both positive and negative infinity. Fixes: pytorch#18922
|
@claude review |
|
Claude finished @nil-is-all's task in 1m 31s —— View job Reviewing PR #18988: Add MLX op handler for aten.isinf
Review SummaryThe decomposition approach ( Issues1. Formatting: The # Before (line 4129-4131 in original):
{"op_name": "isnan", ...},
# activations
{"op_name": "relu", ...},
# After (current):
{"op_name": "isnan", ...},
{"op_name": "isinf", ...}, # activations
{"op_name": "relu", ...},The {"op_name": "isnan", ...},
{"op_name": "isinf", ...},
# activations
{"op_name": "relu", ...},2. Hardcoded inf_slot = emit_lifted_constant(P, float('inf'), torch.float32)The inf constant is always created as 3. Minor: mask_pos = torch.rand(shape) > 0.8 # ~20% set to +inf
mask_neg = torch.rand(shape) > 0.9 # ~10% set to -inf (may overwrite +inf)
x[mask_pos] = float('inf')
x[mask_neg] = float('-inf')Since Looks Good
Issue (1) is the only one I'd consider a must-fix before merge. The |
Good day
Summary
This PR adds a decomposed MLX op handler for
aten.isinfto the pytorch/executorch project.Motivation
The MLX delegate converts PyTorch aten ops into MLX graph nodes during export. When an aten op has no handler, it falls back to CPU execution, breaking the GPU acceleration pipeline. Adding a handler for
aten.isinfenables it to run on Metal GPU via MLX.Implementation
The handler uses a decomposed approach:
This uses existing
AbsNodeandEqualNodewhich are already supported, avoiding the need for a dedicated MLX isinf op.Changes
_isinf_handlerfunction registered fortorch.ops.aten.isinf.defaultisinfto_UNARY_OP_TESTSwith standard test configurationTesting
The handler can be tested with:
Thank you for your attention. If there are any issues or suggestions, please leave a comment and I will address them promptly.
Warmly,
RoomWithOutRoof