Skip to content

Fix FFT many axes - #4968

Merged
zcbenz merged 4 commits into
ml-explore:mainfrom
michalk8:fix-fftn-many-axes
Nov 26, 2026
Merged

zcbenz merged 4 commits into
ml-explore:mainfrom
michalk8:fix-fftn-many-axes

Conversation

@michalk8

Copy link
Copy Markdown
Collaborator
  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: search, tests

A niche one, but FFT with >=4 axes is buggy on Metal:

  • >= 4 axes: use-after-free
  • >= 5 axes: a reused buffer keeps an earlier step's strides (wrong results)

Fix is to use the temps from the 3rd step, give the current step the correct strides and give fresh array for some FFT paths that need it.

Afaik this was introduced in #1102 and never really tested. I tested it below, it is correct and there is no regression w.r.t. the memory:

main this PR
4 ops × 7 shapes (3–6 axes) vs numpy 12/28 fail (all 5–6 axes) 0/28
5–6 axes, long axis at every position (220 cases) 212/220 fail 0/220
Metal validation, mx.set_cache_limit(0) abort (references deallocated object) pass
Peak memory, 6-axis fftn, 0.25 GiB input 2.00 GiB 2.00 GiB

@michalk8
michalk8 requested a review from nastya236 November 24, 2026 18:46
@zcbenz
zcbenz merged commit 8feb9fe into ml-explore:main Nov 26, 2026
24 checks passed
rcfa pushed a commit to cubiculum-ai/mlx that referenced this pull request Nov 26, 2026
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.

3 participants