Skip to content

[MLX] Add elu, max.dim and min.dim handlers - #25747

Open
vineetha00 wants to merge 1 commit into
pytorch:mainfrom
vineetha00:mlx-elu-min-max-dim
Open

vineetha00 wants to merge 1 commit into
pytorch:mainfrom
vineetha00:mlx-elu-min-max-dim

Conversation

@vineetha00

Copy link
Copy Markdown

Summary

Part of #24669 (LeRobot policies on MLX). TD-MPC is listed there as MLX 20 + CPU 205 and slower than eager PyTorch. Counting the operators left on the CPU kernels in that export shows where the 205 come from:

181  aten::elu.out
 12  aten::gather.out
  6  aten::min.dim_min
  6  aten::max.dim_max

gather is already handled on main (#24598). This PR adds handlers for the other three, built from nodes the backend already has:

  • aten.elu: where(x <= 0, alpha * scale * expm1(input_scale * x), scale * x), as ATen computes it. All three coefficients are honored, which is what selu needs (it exports as aten.elu with its own alpha and scale). Multiplies by 1 are not emitted.
  • aten.max.dim / aten.min.dim: MaxNode / MinNode for the values and ArgmaxNode / ArgminNode for the indices. Each output is emitted only when the graph reads it. A 0-D input is rejected, so it stays on the CPU.

Effect on TD-MPC

Random TD-MPC checkpoint from make_random.py in #24669, exported with lerobot-export --backend.type=executorch_mlx on a MacBook Air (Apple Silicon, macOS 15.1), ExecuTorch 1.6.0 wheel, with and without these three handlers added to its ops.py:

1.6.0 1.6.0 + this PR
Operators on CPU kernels 205 12 (all gather)
MLX programs 20 7
Bundle check vs eager (tolerance 2e-05) 4.77e-07 5.36e-07
forward, median of 50 runs 129.1 ms 84.5 ms

The timing loads model.pte with the Python runtime and calls forward on the same random inputs, 10 warm-up runs then 50 timed, each bundle timed twice in alternation (129.1 / 129.5 ms and 84.5 / 84.5 ms). It is not the lerobot-rollout number from the table in #24669.

I did not measure TD-MPC on main. With #24598 the remaining 12 gather calls should also be delegated there.

Test plan

New tests in backends/mlx/test/test_ops.py:

  • ELUTest: default alpha, alpha 0.5, 1.0 and 2.0, and selu, on inputs covering both branches, zero, and a value large enough to overflow expm1 in the branch where does not select.
  • MinMaxDimTest: max and min over 1-D, 2-D and 3-D inputs, positive and negative dims, keepdim, returning values only, indices only, and both.

On macOS 15.1 (Apple Silicon), Python 3.12, source build:

python -m executorch.backends.mlx.test.run_all_tests elu min_max_dim leaky_relu topk amax amin argmax argmin
Passed: 53
Failed: 0

Investigated and written with assistance from Anthropic Claude.

cc @shoumikhin @metascroy

@pytorch-bot

pytorch-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 18 Awaiting Approval

As of commit 9326861 with merge base 8c3f75d (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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 Nov 26, 2026
@vineetha00

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: mlx"

@pytorch-bot pytorch-bot Bot added the release notes: mlx Changes to the MLX Backend: Metal-accelerated inference on Apple Silicon label Nov 26, 2026

This branch has not been deployed

No deployments
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: mlx Changes to the MLX Backend: Metal-accelerated inference on Apple Silicon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant