oneDNN icon indicating copy to clipboard operation
oneDNN copied to clipboard

CNN model running on pytorch built with libmkldnn generates poor prediction on Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz

Open ghost opened this issue 7 years ago • 11 comments

Environment

  • CPU make and model
# cat /proc/cpuinfo | grep flags | sort -u
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke
  • OS version (uname -a)
Linux d309edc59c46 4.14.94-73.73.amzn1.x86_64 #1 SMP Tue Jan 22 20:25:24 UTC 2019 x86_64 GNU/Linux
  • Compiler version (gcc --version) I didn't built mkl-dnn from scratch, I installed latest mkl-dnn from conda

Steps to reproduce:

0. Compile and install latest pytorch from scratch

1. Download latest https://github.com/Cadene/pretrained-models.pytorch

2. Run python examples/imagenet_logits.py -a senet154 --path_img data/cat.jpg

Results:

  • When evaluating model senet154 on Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz with mkl-dnn enabled, the model prediction is fig.
  • While in all other cases (either different model like pnasnet5large, or other CPU like i5, i7, or with mkl-dnn disabled), the model prediction is tabby, tabby cat

In general, the model output is significantly biased to a few categories with the above (senet154, Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz, mkl-dnn enabled) configuration, here are some examples:

'senet154': '../imagen/imagen/n00007846_147031_person.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n00007846_149204_person.jpg' is a 'fig'
'senet154': '../imagen/imagen/n00007846_152343_person.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n00007846_160891_person.jpg' is a 'Granny Smith'
'senet154': '../imagen/imagen/n00007846_98724_person.jpg' is a 'scorpion'
'senet154': '../imagen/imagen/n01443537_11099_goldfish.jpg' is a 'television, television system'
'senet154': '../imagen/imagen/n01443537_2625_goldfish.jpg' is a 'Granny Smith'
'senet154': '../imagen/imagen/n01443537_2675_goldfish.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n01443537_4691_goldfish.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n01443537_5048_goldfish.jpg' is a 'rain barrel'
'senet154': '../imagen/imagen/n01495701_1216_ray.jpg' is a 'rain barrel'
'senet154': '../imagen/imagen/n01495701_1287_ray.jpg' is a 'golf ball'
'senet154': '../imagen/imagen/n01495701_2358_ray.jpg' is a 'chain saw, chainsaw'
'senet154': '../imagen/imagen/n01495701_3614_ray.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n01495701_4155_ray.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n01503061_10156_bird.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n01503061_11000_bird.jpg' is a 'letter opener, paper knife, paperknife'
'senet154': '../imagen/imagen/n01503061_17069_bird.jpg' is a 'letter opener, paper knife, paperknife'

See also https://github.com/Cadene/pretrained-models.pytorch/issues/140 and https://github.com/pytorch/pytorch/issues/18218 for related informations.

I'm glad to compile latest mkl-dnn and retest if that helps.

If anyone could guide me how to reduce my issue to a piece of simple C code I would be very happy to try.

Any hints are greatly appreciated.

Thank you!

ghost avatar Mar 21 '19 07:03 ghost

@fracting This is an issue for the pytorch integration team. Can you submit this question to the pytorch github? If you do that and post the link here, I will bring it to the attention of the team responsible for integrating MKL-DNN into pytorch.

nathan-greeneltch-intel avatar Mar 21 '19 19:03 nathan-greeneltch-intel

@fracting @nathan-greeneltch-intel We (Intel Pytorch team) are following up on this. This is a link to Pytorch issue https://github.com/pytorch/pytorch/issues/18218

Jianhui-Li avatar Mar 21 '19 23:03 Jianhui-Li

@fracting @nathan-greeneltch-intel We (Intel Pytorch team) are following up on this. This is a link to Pytorch issue pytorch/pytorch#18218

Thanks Jianhui! I have reproduced the issue on Intel(R) Xeon(R) Platinum 8180M CPU. I will also follow up the issue.

ZhuoweiSi avatar Mar 22 '19 08:03 ZhuoweiSi

It may related to a mkl-dnn issue on group support for input-channel< vector-size. And it was fixed later in below commit: https://github.com/intel/mkl-dnn/commit/c502e5f45410d9b2bb2155cb99364eaf2360c6db

Latest mkl-dnn should work.

uyongw avatar Mar 22 '19 14:03 uyongw

Thanks @uyongw !

Has anyone tried to compile lastest pytorch with mkl 2019.3 (https://anaconda.org/anaconda/mkl ) from Conda? Last time I tried pytorch didn't compile. I can create an issue to pytorch this weekend if nobody else did it.

ghost avatar Mar 22 '19 14:03 ghost

@fracting Oh, it may not work with the mkl-dnn master. We will update it. If you want of validate the fix of this issue, please try the steps below:

$ (in pytorch folder) $ cd third_party/ideep/mkl-dnn/ $ git checkout c502e5f $ cd - $ (conda build)

uyongw avatar Mar 22 '19 15:03 uyongw

@uyongw Thanks very much for the hints. I can confirm your solution works.

For more details, the following configurations work for me:

# uname -a
Linux 7e8e456b0ea8 4.14.94-73.73.amzn1.x86_64 #1 SMP Tue Jan 22 20:25:24 UTC 2019 x86_64 GNU/Linux

CPU:
Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz

Python:
python-3.7.1-h0371630_7

PyTorch:
0d78126a6fd72b0954dae93bde3e6542d316d866
torch-1.1.0a0+0d78126

mkl-dnn:
c502e5f45410d9b2bb2155cb99364eaf2360c6db

# conda list | grep mkl
blas                      1.0                         mkl
mkl                       2019.3                      199
mkl-include               2019.3                      199
mkl_fft                   1.0.10           py37ha843d7b_0
mkl_random                1.0.2            py37hd81dba3_0


pretrained-models.pytorch:
82d6cc9dfbbb424c1f961027aa3320a39029b2a6

senet154 prebuilt version:
http://data.lip6.fr/cadene/pretrainedmodels/senet154-c7b49a05.pth

imagen mini dataset:
2e8718956e3bb046db9a8e488c2254fd9846b6c5

cat.jpg is recognized as tabby, tabby cat again :)

I also tested the imagen dataset, and the output looks fine:

'senet154': 'imagen/imagen/n00007846_147031_person.jpg' is a 'ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin'
'senet154': 'imagen/imagen/n00007846_149204_person.jpg' is a 'mask'
'senet154': 'imagen/imagen/n00007846_152343_person.jpg' is a 'suit, suit of clothes'
'senet154': 'imagen/imagen/n00007846_160891_person.jpg' is a 'prayer rug, prayer mat'
'senet154': 'imagen/imagen/n00007846_98724_person.jpg' is a 'dumbbell'
'senet154': 'imagen/imagen/n01443537_11099_goldfish.jpg' is a 'goldfish, Carassius auratus'
'senet154': 'imagen/imagen/n01443537_2625_goldfish.jpg' is a 'goldfish, Carassius auratus'
'senet154': 'imagen/imagen/n01443537_2675_goldfish.jpg' is a 'goldfish, Carassius auratus'
'senet154': 'imagen/imagen/n01443537_4691_goldfish.jpg' is a 'goldfish, Carassius auratus'
'senet154': 'imagen/imagen/n01443537_5048_goldfish.jpg' is a 'goldfish, Carassius auratus'
'senet154': 'imagen/imagen/n01495701_1216_ray.jpg' is a 'stingray'
'senet154': 'imagen/imagen/n01495701_1287_ray.jpg' is a 'stingray'
'senet154': 'imagen/imagen/n01495701_2358_ray.jpg' is a 'stingray'
'senet154': 'imagen/imagen/n01495701_3614_ray.jpg' is a 'electric ray, crampfish, numbfish, torpedo'
'senet154': 'imagen/imagen/n01495701_4155_ray.jpg' is a 'electric ray, crampfish, numbfish, torpedo'
'senet154': 'imagen/imagen/n01503061_10156_bird.jpg' is a 'kite'
'senet154': 'imagen/imagen/n01503061_11000_bird.jpg' is a 'magpie'
'senet154': 'imagen/imagen/n01503061_17069_bird.jpg' is a 'white stork, Ciconia ciconia'
'senet154': 'imagen/imagen/n01503061_3560_bird.jpg' is a 'coucal'
'senet154': 'imagen/imagen/n01503061_4034_bird.jpg' is a 'seashore, coast, seacoast, sea-coast'
'senet154': 'imagen/imagen/n01639765_11023_frog.jpg' is a 'tree frog, tree-frog'
'senet154': 'imagen/imagen/n01639765_19901_frog.jpg' is a 'bullfrog, Rana catesbeiana'
'senet154': 'imagen/imagen/n01639765_25915_frog.jpg' is a 'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui'

I also retested my demo.py code in https://github.com/pytorch/pytorch/issues/18218#issuecomment-475453948 and I can confirm the xeon output is consistent with i7 now.

Just double check, I reverted mkl-dnn c502e5f45410d9b2bb2155cb99364eaf2360c6db and rebuilt with exactly the same environment and I can reproduce this issue again.

Thanks many people in this thread and in the PyTorch thread! The PyTorch community and the mkl-dnn team are really efficient and professional, I appreciate a lot.

If you update a new binary build with the avx512 fix, I would be glad to download and test again.

ghost avatar Mar 23 '19 02:03 ghost

@fracting Thanks for reporting the issue and the verification. We will fix it from PyTorch side soon. For the PyTorch conda build issue we are seeking a decent solution too.

uyongw avatar Mar 23 '19 03:03 uyongw

@fracting @uyongw Thank you all so much for fixing this for pytorch!

ssnl avatar Mar 26 '19 15:03 ssnl

Closing this since PyTorch issues were fixed by upgrading MKL-DNN to the v0.18.

tprimak avatar Mar 26 '19 21:03 tprimak

Closing this since PyTorch issues were fixed by upgrading MKL-DNN to the v0.18.

Thanks. However, on avx2 there seems still a minor issue. The jit version of group convolution for first-conv can not be enabled with only checking IC (it should be ic/group?). This is only a performance issue. https://github.com/intel/mkl-dnn/blob/master/src/cpu/jit_avx2_convolution.hpp#L73 @tprimak @sotoflom

uyongw avatar Mar 27 '19 03:03 uyongw