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/02/14 01:17:47 UTC

[GitHub] ptrendx opened a new pull request #14153: Fix shape inference pass

ptrendx opened a new pull request #14153: Fix shape inference pass
URL: https://github.com/apache/incubator-mxnet/pull/14153
 
 
   ## Description ##
   
   This PR fixes shape inference, which currently results in wrong result for some cases.
   
   An example problematic case (as it works in current version of MXNet, before applying this change):
   If I do
   ```
   import mxnet as mx
   
   data = mx.sym.Variable('data', shape=(1,0,512,512))
   weight = mx.sym.Variable('weight')
   cdata = mx.sym.cast(data, dtype='float16')
   cweight = mx.sym.cast(weight, dtype='float16')
   test = mx.sym.Convolution(data=cdata, weight=cweight,layout='NCHW', pad=(3, 3), num_filter=64, stride=(2, 2), no_bias=True, dilate=(1, 1), kernel=(7, 7), num_group=1)
   
   print(test.infer_shape_partial())
   ```
   I get expected result:
   ```
   ([(1, 0, 512, 512), (64, 0, 7, 7)], [(1, 64, 256, 256)], [])
   ```
   but when I change H and W dimensions in the shape to 0s,
   ```
   import mxnet as mx
   
   data = mx.sym.Variable('data', shape=(1,0,0,0))
   weight = mx.sym.Variable('weight')
   cdata = mx.sym.cast(data, dtype='float16')
   cweight = mx.sym.cast(weight, dtype='float16')
   test = mx.sym.Convolution(data=cdata, weight=cweight,layout='NCHW', pad=(3, 3), num_filter=64, stride=(2, 2), no_bias=True, dilate=(1, 1), kernel=(7, 7), num_group=1)
   
   print(test.infer_shape_partial())
   ```
   I get
   ```
   ([(1, 0, 0, 0), ()], [(1, 64, 0, 0)], [])
   ```
   so the shape of the weight changed to `()`.
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
   - [ ] Code is well-documented: 
   - For new C++ functions in header files, their functionalities and arguments are documented. 
   - [x] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [x] Change to the way passes are done so that both forward and backward inference is performed every time - I'm not sure if this is necessary - @eric-haibin-lin, thoughts? 
   - [x] Change to the way shape inference works. Currently a shape contributes 1 to the `num_unknown` if it has at least 1 zero. After the change number of 0 elements is added to the `num_unknown` - that way shape inference pass does not end prematurely if only some of the elements of shape were deduced.
   
   ## Comments ##
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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