Skip to content

[MLX] Add leaky_relu op handler#20305

Merged
metascroy merged 4 commits into
pytorch:mainfrom
devin-lai:mlx-leaky-relu-handler
Jun 23, 2026
Merged

[MLX] Add leaky_relu op handler#20305
metascroy merged 4 commits into
pytorch:mainfrom
devin-lai:mlx-leaky-relu-handler

Conversation

@devin-lai

@devin-lai devin-lai commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary:

  • Add MLX lowering for aten.leaky_relu.default using existing GreaterEqual, Multiply, and Where nodes.
  • Add focused MLX op tests for custom negative_slope values, including a slope above 1.

Test Plan:

  • python -m py_compile backends/mlx/ops.py backends/mlx/test/test_ops.py
  • git diff --check HEAD^..HEAD
  • PATH="$PWD/.venv-mlx/bin:$PATH" .venv-mlx/bin/lintrunner backends/mlx/ops.py backends/mlx/test/test_ops.py
  • .venv-mlx/bin/python -m executorch.backends.mlx.test.run_all_tests leaky_relu --timeout 180

cc @metascroy

Lower aten.leaky_relu.default with existing MLX graph nodes and add focused op tests for custom slopes, including slopes above 1.
@pytorch-bot

pytorch-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 1556a0e with merge base 2b1ccd4 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@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 Jun 16, 2026
@devin-lai

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: apple"

@pytorch-bot pytorch-bot Bot added the release notes: apple Changes to the Apple backend delegate label Jun 16, 2026
@nil-is-all nil-is-all added the module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon label Jun 22, 2026
@nil-is-all nil-is-all requested a review from metascroy June 22, 2026 17:01
Comment thread backends/mlx/ops.py Outdated
require_kwargs(P.kwargs(n), set(), "aten.leaky_relu")

x = args[0]
negative_slope = float(args[1]) if len(args) > 1 else 0.01

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0.01 the default value in pytorch?


@classmethod
def get_test_configs(cls) -> List["LeakyReLUTest"]:
return [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a negative slot None case to test the default you set?

@metascroy

Copy link
Copy Markdown
Contributor

Thanks @devin-lai! Overall it looks great, just have some comments on the default value of negative slot.

@pytorch-bot

pytorch-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@devin-lai

Copy link
Copy Markdown
Contributor Author

Thanks @devin-lai! Overall it looks great, just have some comments on the default value of negative slot.

Thanks! 0.01 is the PyTorch default. I’ve handled the None case and added a test for the default path .

@metascroy

Copy link
Copy Markdown
Contributor

Looks great! Thanks for the contribution @devin-lai!

@metascroy metascroy merged commit 4433d1f into pytorch:main Jun 23, 2026
236 of 239 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/mlx CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: mlx Issues related to MLX Backend: Metal-accelerated inference on Apple Silicon release notes: apple Changes to the Apple backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants