Repository navigation
[MLX] Add elu, max.dim and min.dim handlers - #25747
Open
vineetha00 wants to merge 1 commit into
Open
vineetha00 wants to merge 1 commit into
vineetha00 wants to merge 1 commit into
Conversation
🔗 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.
|
Author
|
@pytorchbot label "release notes: mlx" |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #24669 (LeRobot policies on MLX). TD-MPC is listed there as
MLX 20 + CPU 205and slower than eager PyTorch. Counting the operators left on the CPU kernels in that export shows where the 205 come from:gatheris 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 whatseluneeds (it exports asaten.eluwith its own alpha and scale). Multiplies by 1 are not emitted.aten.max.dim/aten.min.dim:MaxNode/MinNodefor the values andArgmaxNode/ArgminNodefor 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.pyin #24669, exported withlerobot-export --backend.type=executorch_mlxon a MacBook Air (Apple Silicon, macOS 15.1), ExecuTorch 1.6.0 wheel, with and without these three handlers added to itsops.py:gather)forward, median of 50 runsThe timing loads
model.ptewith the Python runtime and callsforwardon 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 thelerobot-rolloutnumber from the table in #24669.I did not measure TD-MPC on main. With #24598 the remaining 12
gathercalls 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 overflowexpm1in the branchwheredoes 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:
Investigated and written with assistance from Anthropic Claude.
cc @shoumikhin @metascroy