Incubator-mxnet: Dropout produces wrong mask with MKL-DNN

Created on 25 Jul 2019  ยท  5Comments  ยท  Source: apache/incubator-mxnet

Description

Dropout mask (second output) is always full of zeros when mxnet is built with MKL-DNN. Weirdly, setting MXNET_MKLDNN_ENABLED=0 doesn't fix it, but using a build without MKL-DNN does.

Environment info (Required)

----------Python Info----------
Version      : 3.7.2
Compiler     : GCC 7.3.0
Build        : ('default', 'Dec 29 2018 06:19:36')
Arch         : ('64bit', '')
------------Pip Info-----------
Version      : 19.0.1
Directory    : /opt/Anaconda/lib/python3.7/site-packages/pip
----------MXNet Info-----------
Version      : 1.5.0
Directory    : /home/matteo/Git/mxnet/python/mxnet
Commit hash file "/home/matteo/Git/mxnet/python/mxnet/COMMIT_HASH" not found. Not installed from pre-built package or built from source.
Library      : ['/home/matteo/Git/mxnet/python/mxnet/../../lib/libmxnet.so']
Build features:
โœ– CUDA
โœ– CUDNN
โœ– NCCL
โœ– CUDA_RTC
โœ– TENSORRT
โœ” CPU_SSE
โœ” CPU_SSE2
โœ” CPU_SSE3
โœ” CPU_SSE4_1
โœ” CPU_SSE4_2
โœ– CPU_SSE4A
โœ” CPU_AVX
โœ– CPU_AVX2
โœ– OPENMP
โœ– SSE
โœ” F16C
โœ” JEMALLOC
โœ– BLAS_OPEN
โœ” BLAS_ATLAS
โœ– BLAS_MKL
โœ– BLAS_APPLE
โœ– LAPACK
โœ” MKLDNN
โœ– OPENCV
โœ– CAFFE
โœ– PROFILER
โœ– DIST_KVSTORE
โœ– CXX14
โœ– INT64_TENSOR_SIZE
โœ– SIGNAL_HANDLER
โœ– DEBUG
----------System Info----------
Platform     : Linux-4.15.0-55-generic-x86_64-with-debian-buster-sid
system       : Linux
node         : mongolius
release      : 4.15.0-55-generic
version      : #60-Ubuntu SMP Tue Jul 2 18:22:20 UTC 2019
----------Hardware Info----------
machine      : x86_64
processor    : x86_64
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  2
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               94
Model name:          Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Stepping:            3
CPU MHz:             2700.253
CPU max MHz:         3500,0000
CPU min MHz:         800,0000
BogoMIPS:            5184.00
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            6144K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0117 sec, LOAD: 0.8935 sec.
Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.0599 sec, LOAD: 2.1901 sec.
Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.1028 sec, LOAD: 0.9832 sec.
Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0657 sec, LOAD: 1.2597 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0380 sec, LOAD: 0.8543 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0395 sec, LOAD: 0.4625 sec.

Using python package.

Build info (Required if built from source)

Compiler: gcc

MXNet commit hash: 076b2f330c60f05cb939beea28dd04cd571a34c0

Build config: plain config.mk, except for USE_OPENCV=0

Minimum reproducible example

import mxnet as mx

json = '{\"nodes\":[{\"op\":\"null\",\"name\":\"in\",\"inputs\":[]},{\"op\":\
\"Dropout\",\"name\":\"dropout\",\"attrs\":{\"axes\":\"()\",\"mode\":\
\"always\",\"p\":\"0.2\"},\"inputs\":[[0,0,0]]}],\"arg_nodes\":[0],\"\
heads\":[[1,0,0],[1,1,0]]}'

sym = mx.sym.load_json(json)
ex = sym.bind(mx.cpu(), {'in': mx.nd.array(range(10))})
ex.forward()
print(ex.outputs)

When running the above script using a build with MKL-DNN, the second output is full of 1.e-45. When using a build without MKL-DNN, it is as expected.

A side question: if I were to build that symbol using the symbol API, how would I grab the second Drouput output?

Bug MKL MKLDNN

Most helpful comment

@matteosal Thanks for reporting this issue. Seems this is not a computational error. I have looked into the dropout code, and found that the output mask is forced to be calculated and stored with int* type instead of original DType* or float* type. So, when you tried to access the value of mask, the wrong answer 1.e-45 will be printed. Refer to forward pass and backward pass.
You can build from source by commenting out the USE_MKL option in Makefile to work around it temporarily. We'll submit a PR for this after completing the verification locally.

All 5 comments

Hey, this is the MXNet Label Bot.
Thank you for submitting the issue! I will try and suggest some labels so that the appropriate MXNet community members can help resolve it.
Here are my recommended labels: Build

@wuxun-zhang please take a look for this issue.

Some background: MKL-DNN itself doesn't support dropout primitive. When MXNet is built with MKL-DNN, it will use functions from VSL to implement dropout. It's kind of legacy code from MKL2017 integration. That's why it cannot be disabled by MXNET_MKLDNN_ENABLED=0.

OK. I'll look into this issue.

@matteosal Thanks for reporting this issue. Seems this is not a computational error. I have looked into the dropout code, and found that the output mask is forced to be calculated and stored with int* type instead of original DType* or float* type. So, when you tried to access the value of mask, the wrong answer 1.e-45 will be printed. Refer to forward pass and backward pass.
You can build from source by commenting out the USE_MKL option in Makefile to work around it temporarily. We'll submit a PR for this after completing the verification locally.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuconglin picture yuconglin  ยท  3Comments

Fzz123 picture Fzz123  ยท  3Comments

dmadeka picture dmadeka  ยท  3Comments

JonBoyleCoding picture JonBoyleCoding  ยท  3Comments

xzqjack picture xzqjack  ยท  3Comments