Skip to content

Add MLX handler for aten.flip#19609

Open
mzl2233 wants to merge 1 commit into
pytorch:mainfrom
mzl2233:add-mlx-flip-handler
Open

Add MLX handler for aten.flip#19609
mzl2233 wants to merge 1 commit into
pytorch:mainfrom
mzl2233:add-mlx-flip-handler

Conversation

@mzl2233
Copy link
Copy Markdown

@mzl2233 mzl2233 commented May 15, 2026

Summary:

  • Add an MLX op handler for aten.flip by lowering flips to reverse slices along each requested dimension.
  • Cover one-dimensional, multi-dimensional, and negative-dimension flip cases in the MLX op tests.

Validation:

  • python3 -m py_compile backends/mlx/ops.py backends/mlx/test/test_ops.py

Fixes #18918

Copilot AI review requested due to automatic review settings May 15, 2026 01:34
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 15, 2026

🔗 Helpful Links

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

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:

❌ 12 Awaiting Approval, 1 New Failure

As of commit 5496e64 with merge base d8e4ffd (image):

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

NEW FAILURE - The following job has failed:

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

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 15, 2026

Hi @mzl2233!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds MLX delegate support for aten.flip by lowering flips into reverse SliceNode operations and adds op tests covering several flip dimension patterns.

Changes:

  • Registers an MLX handler for torch.ops.aten.flip.default.
  • Implements flip as chained reverse slices across requested dimensions.
  • Adds MLX op-test coverage for 1-D, multi-dimensional, all-dimension, and negative-dimension flips.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
backends/mlx/ops.py Adds the aten.flip MLX op handler using reverse slicing.
backends/mlx/test/test_ops.py Adds FlipModel and FlipTest configurations for MLX op validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +884 to +885
dim_str = ",".join(str(d) for d in dims)
self.name = f"flip_dim({dim_str})"
Comment thread backends/mlx/ops.py
if len(set(d % ndim for d in dims)) != len(dims):
raise ValueError(f"aten.flip: dims must be unique, got {dims}")

out = P.make_or_get_slot(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants