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 2021/09/28 23:40:35 UTC

[GitHub] [tvm] AndrewZhaoLuo opened a new pull request #9146: [ONNX] Fix unsqueeze constant expr

AndrewZhaoLuo opened a new pull request #9146:
URL: https://github.com/apache/tvm/pull/9146


   Unsqueeze converter was the wrong opset. _v12 --> _v13
   
   Also added constant evaluation


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi commented on pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#issuecomment-929720375


   @AndrewZhaoLuo Can we also replace `If` below with `op.where(...)`?
   
   https://github.com/apache/tvm/blob/479b96730d89ec0f0231e6e4954f8ec0dbc0e6e3/python/tvm/relay/frontend/onnx.py#L1499-L1501


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi edited a comment on pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#issuecomment-929720375


   @AndrewZhaoLuo Can we also replace `If` below with `op.where(...)`? To avoid making VM a requirement.
   
   https://github.com/apache/tvm/blob/479b96730d89ec0f0231e6e4954f8ec0dbc0e6e3/python/tvm/relay/frontend/onnx.py#L1499-L1501


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi edited a comment on pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#issuecomment-929720375


   @AndrewZhaoLuo Can we also replace `If` below with `op.where(...)`? To avoid making VM a requirement.
   
   https://github.com/apache/tvm/blob/479b96730d89ec0f0231e6e4954f8ec0dbc0e6e3/python/tvm/relay/frontend/onnx.py#L1499-L1501


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on a change in pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#discussion_r718055932



##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -1468,18 +1468,26 @@ class Unsqueeze(OnnxOpConverter):
     """Operator converter for Unsqueeze."""
 
     @classmethod
-    def _impl_v1(cls, inputs, attr, params):
-        axes = sorted(attr["axes"])
+    def run_calculation(cls, tensor, axes):
+        axes = sorted(axes)
         for axis in axes:
-            inputs[0] = _op.expand_dims(inputs[0], axis=axis, num_newaxis=1)
-        return inputs[0]
+            tensor = _op.expand_dims(tensor, axis=axis, num_newaxis=1)
+        return tensor
 
     @classmethod
-    def _impl_v12(cls, inputs, attr, params):
+    def _impl_v1(cls, inputs, attr, params):
+        return cls.run_calculation(inputs[0], attr["axes"])
+
+    @classmethod
+    def _impl_v13(cls, inputs, attr, params):
+        if isinstance(inputs[1], _expr.Constant):

Review comment:
       I thought axes could also be an Expr involving only constants, but I hope such weird usage wouldn't happen.




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi merged pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi merged pull request #9146:
URL: https://github.com/apache/tvm/pull/9146


   


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi merged pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi merged pull request #9146:
URL: https://github.com/apache/tvm/pull/9146


   


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] AndrewZhaoLuo commented on pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo commented on pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#issuecomment-929701367


   @masahi 
   


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi commented on pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#issuecomment-929720375


   @AndrewZhaoLuo Can we also replace `If` below with `op.where(...)`?
   
   https://github.com/apache/tvm/blob/479b96730d89ec0f0231e6e4954f8ec0dbc0e6e3/python/tvm/relay/frontend/onnx.py#L1499-L1501


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on a change in pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#discussion_r718055932



##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -1468,18 +1468,26 @@ class Unsqueeze(OnnxOpConverter):
     """Operator converter for Unsqueeze."""
 
     @classmethod
-    def _impl_v1(cls, inputs, attr, params):
-        axes = sorted(attr["axes"])
+    def run_calculation(cls, tensor, axes):
+        axes = sorted(axes)
         for axis in axes:
-            inputs[0] = _op.expand_dims(inputs[0], axis=axis, num_newaxis=1)
-        return inputs[0]
+            tensor = _op.expand_dims(tensor, axis=axis, num_newaxis=1)
+        return tensor
 
     @classmethod
-    def _impl_v12(cls, inputs, attr, params):
+    def _impl_v1(cls, inputs, attr, params):
+        return cls.run_calculation(inputs[0], attr["axes"])
+
+    @classmethod
+    def _impl_v13(cls, inputs, attr, params):
+        if isinstance(inputs[1], _expr.Constant):

Review comment:
       I thought axes could also be an Expr involving only constants, but I hope such weird usage wouldn't happen.




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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] AndrewZhaoLuo commented on pull request #9146: [ONNX] Fix unsqueeze constant expr

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo commented on pull request #9146:
URL: https://github.com/apache/tvm/pull/9146#issuecomment-929701367


   @masahi 
   


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

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org