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 2022/02/13 05:19:15 UTC

[GitHub] [tvm] Hzfengsy opened a new pull request #10233: [PyTorch] add var_mean support

Hzfengsy opened a new pull request #10233:
URL: https://github.com/apache/tvm/pull/10233


   This PR adds Torch `var_mean` op support, which is used in the new ConvNeXt network.
   
   cc @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 merged pull request #10233: [PyTorch] add var_mean support

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


   


-- 
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 #10233: [PyTorch] add var_mean support

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



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       See https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L356-L357
   
   I think we can directly call `_make._variance` here to avoid computing `mean` twice. If `keep_dims == False` for `mean`, we can collapse unneeded axes by `squeeze`.




-- 
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] Hzfengsy commented on a change in pull request #10233: [PyTorch] add var_mean support

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



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       Thanks for your advice. Finally, I found an existing API `mean_variance`, and enhance it a bit.
   https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L395




-- 
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 #10233: [PyTorch] add var_mean support

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



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       See https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L356-L357
   
   I think we can directly call `_make._variance` here to avoid computing `mean` twice (or add a wrapper in `op/reduce.py` for `variance` given already computed mean). If `keep_dims == False` for `mean`, we can collapse unneeded axes by `squeeze`.




-- 
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 #10233: [PyTorch] add var_mean support

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


   


-- 
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 #10233: [PyTorch] add var_mean support

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



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       See https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L356-L357
   
   I think we can directly call `_make._variance` here to avoid computing `mean` twice.

##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       See https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L356-L357
   
   I think we can directly call `_make._variance` here to avoid computing `mean` twice. If `keep_dims == False` for `mean`, we can collapse unneeded axes by `squeeze`.

##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       See https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L356-L357
   
   I think we can directly call `_make._variance` here to avoid computing `mean` twice (or add a wrapper in `op/reduce.py` for `variance` given already computed mean). If `keep_dims == False` for `mean`, we can collapse unneeded axes by `squeeze`.




-- 
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 #10233: [PyTorch] add var_mean support

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



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       See https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L356-L357
   
   I think we can directly call `_make._variance` here to avoid computing `mean` twice.




-- 
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] Hzfengsy commented on a change in pull request #10233: [PyTorch] add var_mean support

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



##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -1597,6 +1597,21 @@ def func(x):
 
         return func(data)
 
+    def var_mean(self, inputs, input_types):
+        data = inputs[0]
+        if len(inputs) == 2:
+            axis = None
+            keepdims = False
+            unbiased = bool(inputs[1])
+        else:
+            axis = inputs[1]
+            keepdims = bool(inputs[3])
+            unbiased = bool(inputs[2])
+
+        return _op.reduce.variance(data, axis=axis, keepdims=keepdims, unbiased=unbiased), _op.mean(
+            data, axis, keepdims
+        )

Review comment:
       Thanks for your advice. Finally, I found an existing API `mean_variance`, and enhance it a bit.
   https://github.com/apache/tvm/blob/6df070aac6d0e26d1e127095a323c61c2287eb9d/python/tvm/relay/op/reduce.py#L395




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