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/31 22:59:43 UTC

[GitHub] [incubator-mxnet] karan6181 edited a comment on issue #12337: InferShape return false not caught in Symbolic mode

karan6181 edited a comment on issue #12337: InferShape return false not caught in Symbolic mode
URL: https://github.com/apache/incubator-mxnet/issues/12337#issuecomment-497883972
 
 
   There are two scenarios here in which `where` operator should pass.
   
   1. When the `condition` is of 1D array, the below code(snippet from [control_flow_op.h](https://github.com/apache/incubator-mxnet/blob/master/src/operator/tensor/control_flow_op.h)) checks for size equality which is correct given number of dimension is just 1.
   
      ```C++
       } else if ((*in_attrs)[0].ndim() == 1) {
          CHECK_EQ((*in_attrs)[0].Size(), static_cast<size_t>(tshape[0]));
          return true;
      ```
   
      #### Correct scenario where the test pass:
   
      ```python
      condition = mx.sym.Variable('condition')
      x = mx.sym.Variable('x')
      y = mx.sym.Variable('y')
      where_sym = mx.sym.where(condition, x, y)
      
      where_sym.eval(x=mx.nd.array([[2,3],[4,5],[6,7]]),
                     y=mx.nd.array([[8,9],[10,11],[12,13]]),
                     condition=mx.nd.array([1,0,1])) # 1D array
      ```
   
      #### Correct scenario where the test Fails:
   
      ```python
      condition = mx.sym.Variable('condition')
      x = mx.sym.Variable('x')
      y = mx.sym.Variable('y')
      where_sym = mx.sym.where(condition, x, y)
      
      where_sym.eval(x=mx.nd.array([[2,3],[4,5],[6,7]]),
                     y=mx.nd.array([[8,9],[10,11],[12,13]]),
                     condition=mx.nd.array([1,0,1,1])) # Incorrect 1D array
      ```
   
   The 1D array condition is working perfectly as expected in symbolic mode. It throws error if there is a dimension mismatch.
   
   2. `condition` should have the same shape as input `x`.  The below code checks for `shape_assign` between `condition` and `x` where it internally checks for dimension compatibility, and it's returning `False`(Which is expected behaviour if there is a dimension mismatch), but the test is not throwing any error(STRANGE). 
   
   ```c++
   if ((*in_attrs)[0].ndim() == tshape.ndim()) {
       if (!shape_assign(&tshape, (*in_attrs)[0])) return false; // This is returning false which is expected behavior when there is dimension mismatch between variable condition and variable x but the  script is not asserting. However, it passes which is strange.
       SHAPE_ASSIGN_CHECK(*in_attrs, 0, tshape);
       return true;
   ```
   
   In reality, it should throw error something like:
   
   ```bash
   mxnet.base.MXNetError: Error in operator where0: 
   Shape inconsistent, Provided = [1,2], inferred shape=[3,2]
   ```
   
   I will look into it further in detail. Please feel free to suggest if I am going in the wrong direction. Thanks!

----------------------------------------------------------------
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