oneDNN icon indicating copy to clipboard operation
oneDNN copied to clipboard

Batch normalization data type

Open RadjaHachilif opened this issue 8 years ago • 3 comments

Hello, I'm using mkldnn batch normalization function to test correctness of my code for bn. I get results that are different from mkldnn though when i check manually my results are correct so i think the problem is in result precision or data types im using. I wanted to ask what type of data you're using in operations to calculate mean and variance and also for the output

( i tested my code using float, double and unsigned int 32 )

Thank you

RadjaHachilif avatar Nov 26 '18 11:11 RadjaHachilif

Hi @RadjaHachilif,

Intel MKL-DNN uses float (single precision) to compute mean and variance. However the order of summation might be different due to parallelization:

  • nthr = 1, mean = ( x[0] + ... + x[n-1] ) / n
  • nthr = 2, mean = ( (x[0] + .. x[(n-1)/2 - 1]) + (x[(n-1)/2] + ... + x[n-1]) ) / n

Also depending on your compiler and the way you built Intel MKL-DNN you might get different answers as well (not for the mean most likely, but definitely for variance). For instance, see here.

emfomenk avatar Nov 26 '18 11:11 emfomenk

@RadjaHachilif is this sufficient? Can you rewrite your code with float to match @emfomenk recommendation? If you suspect MKLDNN has error in BN computation, please provide a reproducer and we will investigate.

nathan-greeneltch-intel avatar Nov 28 '18 18:11 nathan-greeneltch-intel

Yes, this was sufficient Thank you

RadjaHachilif avatar Dec 02 '18 22:12 RadjaHachilif