You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/01/15 00:07:26 UTC

[GitHub] [incubator-tvm] hcho3 opened a new pull request #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant

hcho3 opened a new pull request #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant
URL: https://github.com/apache/incubator-tvm/pull/4707
 
 
   Consider the following snippet of a TensorFlow model:
   ```
   node {
     name: "flatten_1/stack/0"
     op: "Const"
     attr {
       key: "dtype"
       value {
         type: DT_INT32
       }
     }
     attr {
       key: "value"
       value {
         tensor {
           dtype: DT_INT32
           tensor_shape {
           }
           int_val: -1
         }
       }
     }
   }
   node {
     name: "flatten_1/stack"
     op: "Pack"
     input: "flatten_1/stack/0"
     input: "flatten_1/Prod"
     attr {
       key: "N"
       value {
         i: 2
       }
     }
     attr {
       key: "T"
       value {
         type: DT_INT32
       }
     }
     attr {
       key: "axis"
       value {
         i: 0
       }
     }
   }
   ```
   
   The Pack operator accepts two inputs: the 0D constant `flatten_1/stack/0` and a 0D tensor  `flatten_1/Prod`. Currently, the TF frontend cannot handle this model because it turns the 0D constant `flatten_1/stack/0` into a 1D constant of dimension `(1,)`:
   https://github.com/apache/incubator-tvm/blob/f4c4fde4a07d2346c159f1d5c6ccd00fb8fb7c7d/python/tvm/relay/frontend/tensorflow.py#L2402-L2405
   
   This PR modifies the frontend to handle 0D constants properly.

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

[GitHub] [incubator-tvm] hcho3 edited a comment on issue #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant

Posted by GitBox <gi...@apache.org>.
hcho3 edited a comment on issue #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant
URL: https://github.com/apache/incubator-tvm/pull/4707#issuecomment-574931580
 
 
   Looks like this change breaks the following snippet:
   https://github.com/apache/incubator-tvm/blob/49d31443c4b65c814a3da6decc363a881c05b372/tests/python/frontend/tensorflow/test_forward.py#L2352-L2354
   
   The `size_value` variable is set to `2` (0D tensor) so `size_tensor` should have been `(2,)` (1D tensor). But currently, the TF frontend seems to silently ignore `tf.expand_dims`; `size_tensor` is simply set to `2`.  So the current "auto-boxing" behavior of the TF frontend is actually necessary for many op implementations to work.
   
   Ideal fix would be to make strict distinction between 1D `(1,)` tensors and 0D tensors. Unfortunately, I do not currently have bandwidth to perform the necessary audit of the TF frontend.

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

[GitHub] [incubator-tvm] hcho3 closed pull request #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant

Posted by GitBox <gi...@apache.org>.
hcho3 closed pull request #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant
URL: https://github.com/apache/incubator-tvm/pull/4707
 
 
   

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

[GitHub] [incubator-tvm] kevinthesun commented on a change in pull request #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant

Posted by GitBox <gi...@apache.org>.
kevinthesun commented on a change in pull request #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant
URL: https://github.com/apache/incubator-tvm/pull/4707#discussion_r366892830
 
 

 ##########
 File path: python/tvm/relay/frontend/tensorflow.py
 ##########
 @@ -2400,9 +2400,7 @@ def _parse_param(self, key, value, name, shape):
 
             array_ndim = len(np_array.shape)
             if array_ndim == 0:
-                new_array = np.empty([1], dtype=np_array.dtype)
-                new_array[0] = np_array
-                self._nodes[name] = [tvm.relay.const(new_array)]
+                self._nodes[name] = [tvm.relay.const(np_array)]
 
 Review comment:
   Add a test case?

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

[GitHub] [incubator-tvm] hcho3 commented on issue #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant

Posted by GitBox <gi...@apache.org>.
hcho3 commented on issue #4707: [Relay][Frontend][TF] Fix handling of 0D scalar Constant
URL: https://github.com/apache/incubator-tvm/pull/4707#issuecomment-574931580
 
 
   Looks like this change breaks the following snippet:
   https://github.com/apache/incubator-tvm/blob/49d31443c4b65c814a3da6decc363a881c05b372/tests/python/frontend/tensorflow/test_forward.py#L2352-L2354
   
   The `size_value` variable is set to `2` (0D tensor) so `size_tensor` should have been `(2,)` (1D tensor). But currently, the TF frontend seems to silently ignore `tf.expand_dims`; `size_tensor` is simply set to `2`. 
   
   Ideal fix would be to make strict distinction between 1D `(1,)` tensors and 0D tensors. Unfortunately, I do not currently have bandwidth to perform the necessary audit of the TF frontend.

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