Skip to content

feat(mlx): add handler for aten.roll#19038

Open
IshanG97 wants to merge 2 commits intopytorch:mainfrom
IshanG97:ishan/mlx-roll-18919
Open

feat(mlx): add handler for aten.roll#19038
IshanG97 wants to merge 2 commits intopytorch:mainfrom
IshanG97:ishan/mlx-roll-18919

Conversation

@IshanG97
Copy link
Copy Markdown

@IshanG97 IshanG97 commented Apr 22, 2026

Summary

Adds an MLX delegate handler for aten.roll, mapping torch.roll onto mlx::core::roll via a new RollNode in the schema. Replaces the default decomposition (index_select + arange + cat) with a single native kernel — needed by Swin Transformer's shift-window attention.

Flat roll (dims=[]) raises NotImplementedError for now; no known consumer needs it yet.

Generated files (MLXLoader.*, schema_generated.h, mlx_graph_schema.py, _generated_serializers.py, _generated_inspector.py, _generated/) are regenerated from schema.fbs by backends/mlx/CMakeLists.txt at build time and are deliberately not committed.

Fixes #18919.

Test plan

  • python backends/mlx/serialization/generate.py — regenerates cleanly with RollNode in all expected outputs.
  • lintrunner --skip MYPY --paths-cmd 'git diff --name-only upstream/main' — no issues.
  • End-to-end run_all_tests -k roll not run locally (no executorch build on this machine); relying on CI. Happy to push fixes if it finds anything.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 22, 2026

🔗 Helpful Links

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

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

As of commit b2f3bf0 with merge base 48ec3fc (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 Apr 22, 2026
@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.

Maps torch.roll to mlx::core::roll via a new RollNode. Adds the schema
table, the custom handler for the (shifts, dims) args, the exec_roll
runtime, and test cases covering 1D, 2D, multi-axis, negative shifts,
and negative dims.

Flat roll (dims=[]) is explicitly NotImplementedError for now; all
known use cases (Swin Transformer shift-window attention) pass dims.

Fixes pytorch#18919
@IshanG97 IshanG97 force-pushed the ishan/mlx-roll-18919 branch from 53b77ef to 726c721 Compare April 22, 2026 09:43
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants