Skip to content

[FIX][Relax][ONNX] Handle DFT inverse with onesided as IRFFT - #21079

Open
AshrafAhmed9 wants to merge 1 commit into
apache:mainfrom
AshrafAhmed9:fix-onnx-dft-irfft
Open

AshrafAhmed9 wants to merge 1 commit into
apache:mainfrom
AshrafAhmed9:fix-onnx-dft-irfft

Conversation

@AshrafAhmed9

Copy link
Copy Markdown

Fixes #21076

DFT with inverse=1 and onesided=1 is an inverse real DFT, which the ONNX reference implements as np.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:

  • returns a real output with a trailing dim of 1
  • defaults N to 2 * (len - 1) when dft_length isn't given
  • cuts or zero-pads the input to N // 2 + 1 bins, as numpy does
  • builds the cos/sin tables with Hermitian weights (bins 0 and N/2 count once, the rest twice) and drops the imaginary parts of those two bins, matching numpy

The dft_length <= 0 check 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_irfft compares against np.fft.irfft for odd and even N, with and without dft_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 dft passes (13 tests).

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

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][Relax][ONNX] DFT with inverse=1 and onesided=1 returns incorrect shape and values

1 participant