matteosal opened a new issue #16037: LSTM with MKL-DNN produces wrong output 
after weights are changed
URL: https://github.com/apache/incubator-mxnet/issues/16037
 
 
   ## Description
   1) Create an RNN op with `mode='lstm'` and bind it
   2) Run a forward pass
   3) Change the NDArray holding the RNN parameters
   4) Run a forward pass again
   
   The output doesn't change, unless the second forward pass is performed in 
training mode (`is_train=True`). Setting `MXNET_MKLDNN_ENABLED=0` doesn't fix 
the issue, but using a build without MKL-DNN does.
   
   This severly impacts training with a validation set, because evaluating the 
performance on the validation set is typically performed with `is_train=False` 
after several updates of the weights. In this case, validation shows no 
improvement because the output of the layer is stuck at the very first training 
iteration.
   
   ## 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.
   ```
   
   Package used (Python/R/Scala/Julia): python
   
   ## Build info (Required if built from source)
   
   Compiler (gcc/clang/mingw/visual studio): gcc
   
   MXNet commit hash: 076b2f330c60f05cb939beea28dd04cd571a34c0
   
   Build config: plain config.mk, except for USE_OPENCV=0
   
   ## Minimum reproducible example
   ```
   import mxnet as mx
   
   sym = mx.sym.RNN(mode='lstm', num_layers=1, state_outputs=False, 
state_size=1, name='rnn')
   
   ex = sym.bind(mx.cpu(), 
        {
                'rnn_data': mx.ndarray.random.uniform(low=-1, high=1, 
shape=(10, 128, 5)),
                'rnn_parameters': mx.ndarray.random.uniform(low=-1, high=1, 
shape=(32)),
                'rnn_state': mx.ndarray.zeros(shape=(1, 128, 1)),
                'rnn_state_cell': mx.ndarray.zeros(shape=(1, 128, 1)),
        }
   )
   
   print('---- Output in training mode:')
   ex.forward(is_train=True)
   print(ex.output_dict['rnn_output'].sum().asnumpy())
   
   print('\n---- Output in test mode:')
   ex.forward(is_train=False)
   print(ex.output_dict['rnn_output'].sum().asnumpy())
   
   ex.copy_params_from( 
        {
                'rnn_data': ex.arg_dict['rnn_data'],
                'rnn_parameters': mx.ndarray.random.uniform(low=-1, high=1, 
shape=(32)),
                'rnn_state': ex.arg_dict['rnn_state'],
                'rnn_state_cell': ex.arg_dict['rnn_state_cell'],
        }
   )
   
   print('\n---- Output in training mode after changing weights:')
   ex.forward(is_train=True)
   print(ex.output_dict['rnn_output'].sum().asnumpy())
   
   print('\n---- Output in test mode after changing weights:')
   ex.forward(is_train=False)
   print(ex.output_dict['rnn_output'].sum().asnumpy())
   ```
   
   When using a build with MKL-DNN, this script print something like this:
   ```
   ---- Output in training mode:
   [-112.02175]
   
   ---- Output in test mode:
   [-112.02175]
   
   ---- Output in training mode after changing weights:
   [-362.91537]
   
   ---- Output in test mode after changing weights:
   [-112.02175]
   ```
   Which shows that the output doesn't change after changing the weights unless 
the forward pass is performed in training mode. Setting 
`MXNET_MKLDNN_ENABLED=0` doesn't fix the issue, but using a build without 
MKL-DNN does.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to