You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/05/27 07:36:06 UTC

[GitHub] [incubator-mxnet] ZhennanQin opened a new issue #15078: Naive engine produce incorrect result on MKLDNN backend

ZhennanQin opened a new issue #15078: Naive engine produce incorrect result on MKLDNN backend
URL: https://github.com/apache/incubator-mxnet/issues/15078
 
 
   Reproducible test:
   
   ```
   import numpy as np
   import mxnet as mx
   
   from mxnet import gluon, nd, image
   from mxnet.gluon.data.vision import transforms
   
   from gluoncv.model_zoo import get_model
   
   
   ctx = [mx.cpu()]
   
   # Load Model
   model_name = "cifar_resnet20_v1"
   kwargs = {'classes': 10, 'pretrained': True}
   net = get_model(model_name, **kwargs)
   
   net.hybridize(static_alloc=True, static_shape=True)
   
   def test(ctx, val_data):
       metric = mx.metric.Accuracy()
       for i, batch in enumerate(val_data):
           data = gluon.utils.split_and_load(batch[0], ctx_list=ctx, batch_axis=0)
           label = gluon.utils.split_and_load(batch[1], ctx_list=ctx, batch_axis=0)
           outputs = [net(X) for X in data]
           metric.update(label, outputs)
           break
       return metric.get()
   
   
   transform_test = transforms.Compose([
           transforms.ToTensor(),
           transforms.Normalize([0.4914, 0.4822, 0.4465], [0.2023, 0.1994, 0.2010])
       ])
   
   val_data = gluon.data.DataLoader(
              gluon.data.vision.CIFAR10(train=False).transform_first(transform_test),
              batch_size=128, shuffle=False, num_workers=2)
   
   name, val_acc = test(ctx, val_data)
   
   print('val=%f' % val_acc)
   ```
   
   With threaded_engine, result is correct:
   ```
   $ unset MXNET_ENGINE_TYPE
   $ python small.py
   val=0.929688
   ```
   
   with naive_engine, result is incorrect:
   ```
   $ export MXNET_ENGINE_TYPE=NaiveEngine
   $ python small.py
   val=0.085938
   ```
   
   If remove below line, the issue can get fix:
   https://github.com/apache/incubator-mxnet/blob/master/src/operator/nn/mkldnn/mkldnn_convolution.cc#L418
   `weight.MKLDNNDataReorderAsync(fwd->fwd_pd.weights_primitive_desc());`
   
   The reason behind is, naive_engine won't do this as lazy as threaded_engine, causing different execution order, and finally make result incorrect.
   
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services