You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for lowering mhlo.fft in codegen #5299
After prototyping on this, I found that there is a slight numerical issue. I verified in many ways, and ended up with the implementation of sin/cos is different between our backends and g++/clang++. Although it is only like 1e-6 accuracy, the cumulative sum of matmul will increase errors to around 1e-4.
I highly suspect that the numerical difference in fft between VMLA and my prototype is coming from this kind of "issue". I think I'm doing correct things in the prototype, and I'm going to adjust the golden result based on what I have, and ignore VMLA one.
Activity
hanhanW commentedon Apr 2, 2021
I will put more context later, because it should go through some patterns in HLOToHLOPreprocessPass, like
PopulateComplexLoweringPatternsfirst.Fix RFFT bugs in VMLA.
Fix RFFT bugs in VMLA. (#5308)
hanhanW commentedon Apr 13, 2021
After prototyping on this, I found that there is a slight numerical issue. I verified in many ways, and ended up with the implementation of sin/cos is different between our backends and
g++/clang++. Although it is only like1e-6accuracy, the cumulative sum of matmul will increase errors to around1e-4.I wrote a naive c++ code to compare results: https://gist.github.com/hanhanW/1a3d2bcf060eb96d3d698f95ec9aa115
func1: based on the DFT definitionfunc2: convert to matmul formfunc3: use constant coefficients (which are generated from our backends) to compute.Log: https://gist.githubusercontent.com/hanhanW/1a3d2bcf060eb96d3d698f95ec9aa115/raw/19f795c1dbc30b9f04103ce36b7ff02d8f0d06e1/log
You can see that the second number of real part is different. One is
-0.000000, and another is-0.000010.If you dig into more, take the computed numbers as input to sin, it will generate
But if it is computed through for-loops which have constant boundaries, it will generate 0 and 1:
The former one matches the result from all of out backends.
Tested with
Output from VMLA, and vulkan:
I highly suspect that the numerical difference in
fftbetweenVMLAand my prototype is coming from this kind of "issue". I think I'm doing correct things in the prototype, and I'm going to adjust the golden result based on what I have, and ignore VMLA one.CC @rsuderman @NatashaKnk who worked on FFT support in VMLA.
benvanik commentedon Apr 13, 2021
SGTM - the VMLA one is likely to be specific quirks of the pffffffffft library and may not match source tensorflow/etc.
benvanik commentedon Apr 13, 2021
(@rsuderman / @NatashaKnk may know how closely pfffffft matched tf, though)
hanhanW commentedon Apr 13, 2021
1e-4looks like a reasonable tolerance for fft to me. This test is small, we probably need to verify with larger tests.Add support for lowering mhlo.fft to Linalg. (#5450)