Open
Conversation
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 Authored-with: Claude <noreply@anthropic.com>
🔗 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. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
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
Adds an MLX delegate handler for
aten.roll, mappingtorch.rollontomlx::core::rollvia a newRollNodein the schema. Replaces the default decomposition (index_select + arange + cat) with a single native kernel — needed by Swin Transformer's shift-window attention.Fixes #18919.
Changes
backends/mlx/serialization/schema.fbs: newRollNode { x, out, shift: [IntOrVid], axes: [int32] }, appended to theOpNodeunion (APPEND ONLY rule preserved).backends/mlx/ops.py: custom_roll_handlerfortorch.ops.aten.roll.default. Normalises scalar-vs-listshifts/dims, validates length parity, and raisesNotImplementedErrorfor flat roll (dims=[]) since no known consumer needs it yet.backends/mlx/runtime/MLXInterpreter.h:exec_rollusingto_shape(n.shift, st)for theShapeconversion, plus the dispatch case.backends/mlx/test/test_ops.py:RollTestcovering 1D, 2D, 3D, multi-axis, negative shifts, and a negative dim.Generated files (
MLXLoader.*,schema_generated.h,mlx_graph_schema.py,_generated_serializers.py,_generated_inspector.py,_generated/) are regenerated fromschema.fbsbybackends/mlx/CMakeLists.txtat build time and are deliberately not committed.Test plan
python backends/mlx/serialization/generate.pyregenerates cleanly withRollNodeappearing in all expected outputs.lintrunner --skip MYPY --paths-cmd 'git diff --name-only upstream/main'— no issues.python -m executorch.backends.mlx.test.run_all_tests -k rollis pending a fullinstall_executorch.shbuild on this machine; relying on CI for the end-to-end validation. Happy to push fixes if CI finds anything.PR authored with Claude Code.