Repository navigation
[FIX][Relax][ONNX] Handle DFT inverse with onesided as IRFFT - #21079
Open
AshrafAhmed9 wants to merge 1 commit into
Open
AshrafAhmed9 wants to merge 1 commit into
AshrafAhmed9 wants to merge 1 commit into
Conversation
DFT with inverse=1 and onesided=1 is an inverse real DFT. The converter treated it like a plain onesided transform, so it returned a complex output with the wrong length. Now the output is real with a last dim of 1, N defaults to 2 * (len - 1) when dft_length is absent, and the input is cut or zero-padded to N // 2 + 1 bins, matching np.fft.irfft. Fixes apache#21076
This branch has not been deployed
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.
Fixes #21076
DFT with
inverse=1andonesided=1is an inverse real DFT, which the ONNX reference implements asnp.fft.irfft(x, n=N). The Relax converter treated it as an ordinary onesided transform, so it returned a complex output of the wrong length.With this change, that combination:
2 * (len - 1)whendft_lengthisn't givenN // 2 + 1bins, as numpy doesThe
dft_length <= 0check now also runs when the length is derived, since a single input bin gives N = 0 and used to divide by zero.The other DFT modes take the same path as before.
Tests:
test_dft_inverse_onesided_irfftcompares againstnp.fft.irfftfor odd and even N, with and withoutdft_length, for real and complex input, and on a non-last axis. It also checks the values from the issue. ONNX Runtime rejects this attribute combination, so the test runs TVM only and compares to numpy. I also added a validation case for the single-bin input. All 9 new IRFFT cases fail on main.pytest tests/python/relax/test_frontend_onnx.py -k dftpasses (13 tests).