Batch normalization data type
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
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.
@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.
Yes, this was sufficient Thank you