Skip to content

Fix fftn size one axis aliasing a temporary - #4705

Open
StockerMC wants to merge 2 commits into
ml-explore:mainfrom
StockerMC:fix-fft-length-one-alias
Open

StockerMC wants to merge 2 commits into
ml-explore:mainfrom
StockerMC:fix-fft-length-one-alias

Conversation

@StockerMC

Copy link
Copy Markdown

fixes #4704

fft_op aliases the output onto the input for a size one axis. In nd_fft_op, this results in the primitive output sometimes sharing a buffer with an intermediate, and since the intermediates are then registered as temporaries, the output loses its fence the same way as #4702. With the inverse transform, the size one axis runs first so the input gets registered as a temporary instead.

Intermediates that share a buffer with the input or output are no longer registered as temporaries.

I added a regression test for both directions with an input large enough so that the command buffer splits after the FFT; the inverse case fails every time on 0.32.3 and 0.32.4, tested on an M3 Pro.

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this fixes the bug, we should fix the code that adds input/output to temp_arrs, rather than skipping them afterwards.

@StockerMC

Copy link
Copy Markdown
Author

Thanks, I updated nd_fft_op to skip identity transforms before creating temporary buffers to prevent the aliases from happening at all.

@StockerMC
StockerMC force-pushed the fix-fft-length-one-alias branch from 207c762 to a3c09e5 Compare October 19, 2026 04:53

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the update, just a note that I will need to land #4711 first which will add a deterministic check and can simplify the tests.

This branch has not been deployed

No deployments
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.

[BUG] fft2/fftn over a length 1 axis can return wrong results on large Metal inputs

2 participants