Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reshape copy bug #1253

Merged
merged 3 commits into from
Jul 8, 2024
Merged

Fix reshape copy bug #1253

merged 3 commits into from
Jul 8, 2024

Conversation

angeloskath
Copy link
Member

Fixes ml-explore/mlx-swift#104 and potentially ml-explore/mlx-examples#642 .

The two first commits in the PR have two different fixes. The later one is what I consider a better choice. The bug is because the code in Reshape assumed that copy copies arrays of same total size but different shapes. That is not true, it is not checked but copy assumes in.shape() == out.shape(). I did not add this as an assertion but we could... let me know.

The fix in the previous PR was just allowing to copy from any shape to any shape assuming that the total number of elements is the same.

The current fix just fixes reshape to allocate and copy in place passing the correct output strides. I also updated the cpu copy to use collapse_contiguous_dims so we should get signficantly faster many-dimensional copies on the cpu.

@angeloskath angeloskath requested review from jagrit06 and awni July 6, 2024 02:28
Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

🚀 thanks for the fix!!

@angeloskath angeloskath merged commit 03cf033 into main Jul 8, 2024
3 checks passed
@angeloskath angeloskath deleted the copy-bug branch July 8, 2024 04:37
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.

C++ exception when reshaping after transposing on GPU
2 participants