Skip to content

Add MLX hardtanh op handler#19776

Open
atharvjairath wants to merge 6 commits into
pytorch:mainfrom
atharvjairath:mlx-hardtanh-op-handler
Open

Add MLX hardtanh op handler#19776
atharvjairath wants to merge 6 commits into
pytorch:mainfrom
atharvjairath:mlx-hardtanh-op-handler

Conversation

@atharvjairath
Copy link
Copy Markdown

Fixes #18921

Adds MLX delegate support for aten.hardtanh.default by lowering it to the existing ClipNode path with the operator's min_val and max_val bounds. This enables bounded activation models, including ReLU6-style hardtanh usage, to stay delegated to MLX instead of failing as an unsupported op.

This also adds focused MLX op tests for:

  • default hardtanh bounds [-1.0, 1.0]
  • ReLU6 bounds [0.0, 6.0]
  • symmetric custom bounds [-2.0, 2.0]
  • asymmetric custom bounds [-0.25, 0.75]

Test plan:

lintrunner backends/mlx/ops.py backends/mlx/test/test_ops.py
ok No lint issues.
CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 python -m executorch.backends.mlx.test.run_all_tests --rebuild hardtanh
Rebuilding op_test_runner in /Users/atharvjairath/Desktop/timepass/executorch/cmake-out...
Build succeeded.

Running test: hardtanh_min-1.0_max1.0_2x3x4
✓ MLX delegation verified
C++ binary output: OK
✓ PASSED: All outputs match

Running test: hardtanh_min0.0_max6.0_4x8
✓ MLX delegation verified
C++ binary output: OK
✓ PASSED: All outputs match

Running test: hardtanh_min-2.0_max2.0_10
✓ MLX delegation verified
C++ binary output: OK
✓ PASSED: All outputs match

Running test: hardtanh_min-0.25_max0.75_2x8x16
✓ MLX delegation verified
C++ binary output: OK
✓ PASSED: All outputs match

TEST SUMMARY
Passed: 4
Failed: 0

This follows up on #18986 by adding custom min/max bound coverage and including the requested local test output.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 26, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19776

Note: Links to docs will display an error until the docs builds have been completed.

❗ 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 26, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: atharvjairath / name: atharvjairath (19fa148)

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 26, 2026
@atharvjairath
Copy link
Copy Markdown
Author

@pytorchbot label "release notes: apple"

@pytorch-bot pytorch-bot Bot added the release notes: apple Changes to the Apple backend delegate label May 26, 2026
@atharvjairath
Copy link
Copy Markdown
Author

cc: @nil-is-all

@digantdesai digantdesai requested a review from metascroy May 27, 2026 20:28
@atharvjairath
Copy link
Copy Markdown
Author

Friendly bump, PR is ready for review. Added MLX support for aten.hardtanh.default via the existing ClipNode path, with tests for default/custom bounds and ReLU6 usage.

Would appreciate a review when possible. cc @metascroy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: apple Changes to the Apple backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Good First Issue: Add MLX Op Handler for aten.hardtanh

2 participants