NervanaSystems / neon

Intel® Nervana™ reference deep learning framework committed to best performance on all hardware
http://neon.nervanasys.com/docs/latest
Apache License 2.0
3.87k stars 811 forks source link

why bias cost so much ? #385

Closed guoxuesong closed 6 years ago

guoxuesong commented 7 years ago

I found some examples of neon not add bias to Affine, I tried to add it back, It becomes much slower. for example mnist_mlp.py use 3.76s/epoch without bias, but 5.30s/epoch with bias.

The difference is HUGE !

convnet-benchmarks/googlenet_v1.py, also huge difference.

I tried lasagne, with bias or without bias, nearly same.

wei-v-wang commented 7 years ago

Hi @guoxuesong Thanks for your report! This is a known issue to us and we have been trying to fix it. Can you test with this commit id to see if you still have the issue with adding bias?

https://github.com/NervanaSystems/neon/commit/199f215aeac1b699a63cb808ada88ece180c46f0

wei-v-wang commented 6 years ago

Hi @guoxuesong We have done fusion of convolution + bias to improve the performance for convolution with bias. Can you please verify if you observe big perf. improvement?

https://github.com/NervanaSystems/neon/tree/v2.3.0 (neon v2.3.0)

wei-v-wang commented 6 years ago

The reason adding bias was slower was because Bias layer was a non-MKL op and data conversion needed to happen. With neon v2.3.0. Convolution +Bias layers become Convolution_Bias layers.

wei-v-wang commented 6 years ago

Please re-open if issues still exist. Thanks for reporting!