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/04/14 11:07:58 UTC

[GitHub] [incubator-tvm] maheshambule opened a new pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

maheshambule opened a new pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330
 
 
   @siju-samuel, @shoubhik, @kevinthesun Please help in review.
   

----------------------------------------------------------------
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] maheshambule commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
maheshambule commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r408117481
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -1488,6 +1511,42 @@ def convert_split(self, op):
 
         return out
 
+    def convert_split_v(self, op):
+        """SPLIT_V implementation."""
+        try:
+            from tflite.Operator import Operator
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+
+        assert isinstance(op, Operator)
+        input_tensors = self.get_input_tensors(op)
+
+        assert len(input_tensors) == 3, "input tensors length should be == 3"
+
+        axis_tensor = input_tensors[2]
+        split_axis = self.get_tensor_value(axis_tensor)
+        input_tensor = input_tensors[0]
+        input_tensor_idx = input_tensor.tensor_idx
+
+        in_expr = self.get_expr(input_tensor_idx)
+        if self.has_expr(input_tensors[1].tensor_idx):
+            raise tvm.error.OpNotImplemented("For size_splits parameter of SPLIT_V operator, "
+                                             "only constant values are supported.")
+
+        size_splits = list(self.get_tensor_value(input_tensors[1]))
+        size_splits = tuple(np.cumsum(size_splits)[:-1])
+
+        out = _op.split(in_expr, size_splits, axis=int(split_axis))
+        # Relay does not like a TupleWrapper of 1 element, further this
+        # only shows up with tf1.13 if we use a split with num_splits==1.
+        # In tf 1.14 this doesn't appear as it is automatically a reshape
+        # operation.
+        if isinstance(out, _expr.TupleWrapper):
+            if out.size == 1:
 
 Review comment:
   done

----------------------------------------------------------------
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] siju-samuel commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r408070514
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -1488,6 +1511,42 @@ def convert_split(self, op):
 
         return out
 
+    def convert_split_v(self, op):
+        """SPLIT_V implementation."""
+        try:
+            from tflite.Operator import Operator
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+
+        assert isinstance(op, Operator)
+        input_tensors = self.get_input_tensors(op)
+
+        assert len(input_tensors) == 3, "input tensors length should be == 3"
+
+        axis_tensor = input_tensors[2]
+        split_axis = self.get_tensor_value(axis_tensor)
+        input_tensor = input_tensors[0]
+        input_tensor_idx = input_tensor.tensor_idx
+
+        in_expr = self.get_expr(input_tensor_idx)
+        if self.has_expr(input_tensors[1].tensor_idx):
+            raise tvm.error.OpNotImplemented("For size_splits parameter of SPLIT_V operator, "
+                                             "only constant values are supported.")
+
+        size_splits = list(self.get_tensor_value(input_tensors[1]))
+        size_splits = tuple(np.cumsum(size_splits)[:-1])
+
+        out = _op.split(in_expr, size_splits, axis=int(split_axis))
+        # Relay does not like a TupleWrapper of 1 element, further this
+        # only shows up with tf1.13 if we use a split with num_splits==1.
+        # In tf 1.14 this doesn't appear as it is automatically a reshape
+        # operation.
+        if isinstance(out, _expr.TupleWrapper):
+            if out.size == 1:
 
 Review comment:
   This 2 if's can be combined

----------------------------------------------------------------
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] maheshambule commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
maheshambule commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r408117717
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1105,6 +1112,37 @@ def test_forward_zeros_like():
     """ ZEROS LIKE """
     _test_zeros_like(np.arange(6.0, dtype=np.float32).reshape((1, 6)))
 
+
+#######################################################################
+# Fill
+# ----
+
+def _test_fill(dims, value_data, value_dtype):
+    """ Use the fill op to create a tensor of value_data with constant dims."""
+
+    value_data = np.array(value_data, dtype=value_dtype)
+    with tf.Graph().as_default():
+        value = array_ops.placeholder(dtype=value_dtype, name="value", shape=[])
+        out = tf.fill(dims,  value)
+        compare_tflite_with_tvm([value_data], ["value"], [value], [out])
+
+    with tf.Graph().as_default():
+        input1 = array_ops.placeholder(dtype=value_dtype, name="input1", shape=dims)
+        # Fill op gets converted to static tensor during conversion
+        out = tf.fill(dims,  value_data)
+        out1 = tf.add(out, input1)
+        input1_data = np.random.uniform(0, 5, size=dims).astype(value_dtype)
+        compare_tflite_with_tvm([input1_data], ["input1"], [input1], [out1])
+
+
+def test_forward_fill():
 
 Review comment:
   oh missed it! Thanks. Done.

----------------------------------------------------------------
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] siju-samuel commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r408072896
 
 

 ##########
 File path: tests/python/frontend/tflite/test_forward.py
 ##########
 @@ -1105,6 +1112,37 @@ def test_forward_zeros_like():
     """ ZEROS LIKE """
     _test_zeros_like(np.arange(6.0, dtype=np.float32).reshape((1, 6)))
 
+
+#######################################################################
+# Fill
+# ----
+
+def _test_fill(dims, value_data, value_dtype):
+    """ Use the fill op to create a tensor of value_data with constant dims."""
+
+    value_data = np.array(value_data, dtype=value_dtype)
+    with tf.Graph().as_default():
+        value = array_ops.placeholder(dtype=value_dtype, name="value", shape=[])
+        out = tf.fill(dims,  value)
+        compare_tflite_with_tvm([value_data], ["value"], [value], [out])
+
+    with tf.Graph().as_default():
+        input1 = array_ops.placeholder(dtype=value_dtype, name="input1", shape=dims)
+        # Fill op gets converted to static tensor during conversion
+        out = tf.fill(dims,  value_data)
+        out1 = tf.add(out, input1)
+        input1_data = np.random.uniform(0, 5, size=dims).astype(value_dtype)
+        compare_tflite_with_tvm([input1_data], ["input1"], [input1], [out1])
+
+
+def test_forward_fill():
 
 Review comment:
   test_forward_fill is not invoked from __main__

----------------------------------------------------------------
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] maheshambule commented on issue #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
maheshambule commented on issue #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330#issuecomment-613433087
 
 
   @siju-samuel Thanks. Made the changes.

----------------------------------------------------------------
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] siju-samuel commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
siju-samuel commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r408069942
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -1488,6 +1511,42 @@ def convert_split(self, op):
 
         return out
 
+    def convert_split_v(self, op):
+        """SPLIT_V implementation."""
+        try:
+            from tflite.Operator import Operator
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+
+        assert isinstance(op, Operator)
+        input_tensors = self.get_input_tensors(op)
+
+        assert len(input_tensors) == 3, "input tensors length should be == 3"
 
 Review comment:
   rephrase to -> input tensors length should be 3

----------------------------------------------------------------
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] maheshambule commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
maheshambule commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r408117340
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -1488,6 +1511,42 @@ def convert_split(self, op):
 
         return out
 
+    def convert_split_v(self, op):
+        """SPLIT_V implementation."""
+        try:
+            from tflite.Operator import Operator
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+
+        assert isinstance(op, Operator)
+        input_tensors = self.get_input_tensors(op)
+
+        assert len(input_tensors) == 3, "input tensors length should be == 3"
 
 Review comment:
   Done

----------------------------------------------------------------
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] maheshambule commented on pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
maheshambule commented on pull request #5330:
URL: https://github.com/apache/incubator-tvm/pull/5330#issuecomment-619145838


   @u99127 I have merged the master and removed the duplicate code.


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



[GitHub] [incubator-tvm] maheshambule commented on issue #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
maheshambule commented on issue #5330:
URL: https://github.com/apache/incubator-tvm/pull/5330#issuecomment-616454075


   @siju-samuel, Thanks. 
   @kevinthesun, Please help in review and merge.


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



[GitHub] [incubator-tvm] maheshambule commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
maheshambule commented on a change in pull request #5330:
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r414740666



##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -1067,6 +1069,27 @@ def convert_zeros_like(self, op):
 
         return out
 
+    def convert_fill(self, op):
+        """Convert TFLite FILL"""
+        try:
+            from tflite.Operator import Operator
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+

Review comment:
       Merged master and removed.




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



[GitHub] [incubator-tvm] u99127 commented on a change in pull request #5330: [Frontend][TFLite] support for FILL and SPLIT_V operators

Posted by GitBox <gi...@apache.org>.
u99127 commented on a change in pull request #5330:
URL: https://github.com/apache/incubator-tvm/pull/5330#discussion_r413943986



##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -1067,6 +1069,27 @@ def convert_zeros_like(self, op):
 
         return out
 
+    def convert_fill(self, op):
+        """Convert TFLite FILL"""
+        try:
+            from tflite.Operator import Operator
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+

Review comment:
       Please drop this , it's no longer needed as the assert has now been commonised.

##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -1488,6 +1511,41 @@ def convert_split(self, op):
 
         return out
 
+    def convert_split_v(self, op):
+        """SPLIT_V implementation."""
+        try:
+            from tflite.Operator import Operator
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+
+        assert isinstance(op, Operator)

Review comment:
       Likewise.




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