Skip to content

Conversation

@CC-Yeh
Copy link
Contributor

@CC-Yeh CC-Yeh commented Dec 17, 2025

Proposed changes

View-only layout ops (e.g. expand_dims, squeeze) can sit between elementwise ops and reduce compile’s fusion opportunities.

This PR adds a small “layout mover” step in compile_simplify that (conservatively) rewrites view(op(x)) -> op(view(x)), and runs it to a bounded fixpoint so the view can move up multiple elementwise layers.

This is an early draft to get feedback on whether MLX wants this optimization before I refine/extend it (e.g. consider reshape, flatten ...).

Before:
fused_old

After:
fused_new

Checklist

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@CC-Yeh CC-Yeh changed the title View-only layout mover View-only layout ops mover Dec 18, 2025
@CC-Yeh
Copy link
Contributor Author

CC-Yeh commented Dec 18, 2025

@awni @angeloskath

What do you think about adding this to compile?
It's a bit similar to XLA ReshapeMover.

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.

1 participant