Calculation Error in BenchDNN SoftMax Threshold (trh) for bf16, f16, and Other Datatypes Except f32
Description:
Summary
Hi @jondea ,in PR https://github.com/oneapi-src/oneDNN/issues/1819, there is an issue with the calculation of the "trh" variable for datatypes except f32. When using the bf16 datatype, the expected value of "trh" should be 0.0078125.
Version
Main Branch onednn_verbose,info,oneDNN v3.5.0 (commit e65a34ff8d48a5c010b036733015ad47acd9c4b6)
Environment
- CPU: Intel IceLake AVX-512
- OS: Linux 22.04.1-Ubuntu SMP Wed Mar 13 18:54:49 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
- Compiler version: 11.4.0
- CMake version: 3.22.1
- Git hash: bf7d0b95193c91e86d13d867b55d078467d22ffd
Steps to Reproduce
- Add print statement for "trh" variables in
tests/benchdnn/softmax/softmax.cppfile. - Build OneDNN.
Observed Behavior
- trh_dt: bf16
- is_flt_or_dbl: 0
- trh_coeff_log: 1
- trh_coeff_f32: 1
- trh_coeff_bwd: 1
- trh_f32: 0.0078125
- trh: 0
Expected Behavior
- trh_dt: bf16
- is_flt_or_dbl: 0
- trh_coeff_log: 1
- trh_coeff_f32: 1
- trh_coeff_bwd: 1
- trh_f32: 0.0078125
- trh: 0.0078125
That's odd, I can't see how the patch should affect x86 unless you build with DNNL_AARCH64_USE_ACL which doesn't support x86. What CMake flags are you building with?
Hi @jondea , indeed, the issue isn't related to your patch. It seems to stem from @dzarukin's commit (commit ID: 6727bbe8fe4217c8ec8982a9c1e975a6b75f81fb) titled 'benchdnn: softmax: make threshold 0 for low precision dst dt'. @dzarukin , could you please provide insight into why we're setting the threshold to 0 for lower precision? This change might lead to benchdnn failures on other CPU architectures or implementations.
0 threshold is justified by the following logic:
- Benchdnn prepares f16 input, passes it as is for the library and upconverts it to f32 for the benchdnn reference.
- The library takes f16 input ->
"does magic"-> returns f16 output. - The benchdnn reference takes f32 input -> makes all computations in f32 (accumulation and intermediate storage in dst) -> returns f32 output -> down converts to fp16 to secure proper rounding.
- Threshold
0secures that"does magic"is a pure equivalent of doing intermediate computations and storage in f32. If this is the case, there would be no failures as benchdnn rounded output and they should coincide.
That was not the case for x64 backend before, and that trend spread out. Now the way it's done is consistent with the rest of the library (at least all the places I'm aware of). If any computations inside softmax are expected to be done not in f32 purposely, we have a new attribute, acc_mode, that can help trigger the right expectations and set a more relevant threshold for benchdnn.
I can cover benchdnn infrastructure to do things properly, but putting right expectations for the implementation and new input files with acc_mode enabled should be done by correspondent responsible teams. Does it sound good?
Hi @dzarukin, thank you for the clarification. Your suggestion regarding the 'acc_mode' attribute sounds promising. However, I encountered an error when attempting to use 'acc_mode' with benchdnn. Here's the command I tried:
./benchdnn --softmax --attr-acc-mode=relaxed 64x64
The error message states: 'driver: ERROR: unknown option: softmax '--attr-acc-mode=relaxed'. Could you please provide guidance on how to resolve this issue? Your assistance would be greatly appreciated.
Hi @deepeshfujitsu, I've opened an internal PR that should resolve this issue. Thank you for waiting.
Hi @deepeshfujitsu, could you, please, double check the issue is resolved on your side?
Hi @dzarukin, it is resolved, Thank you