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/12/08 16:05:50 UTC

[GitHub] [tvm] ashutosh-arm opened a new pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

ashutosh-arm opened a new pull request #9682:
URL: https://github.com/apache/tvm/pull/9682


   This PR fixes following issue: MergeComposite callback function from pattern table returns non boolean data type.


-- 
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] manupa-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-991564446


   Thanks @ashutosh-arm @u99127 @mshawcroft @ekalda . This is merged now!


-- 
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] ashutosh-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-989807244


   @manupa-arm  If you look at the latest changes that I've pushed, it contains both: Fix for the exact issue and the corresponding test.
   
   The issue was that MergeComposite() failed because Conv2D's check function failed on cifar_10. By check function here, I mean the callback function registered with MergeComposite(). As you can see in the code snippet posted above in the comments, IntImm comparison was causing the equality to return non bool value: _conv2d.attrs.padding[2] == 0_ . As you pointed out, we are trying to access C++ fields from python here.
   
   Regarding the test, @u99127 suggested to add corresponding test which I've pushed with my last commit. This test is a negative test to introduce the negative padding that would trigger a failure in the check function.
   
   So, now we do have both the fix and the test as per reviewers' comments.


-- 
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] ashutosh-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r765043641



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       The problem originated because of checks for Conv2D function: check_qnn_conv2d()
   
   Here is how it looks :
   ```
       conv2d.attrs.out_dtype == "int32"
               and conv2d.attrs.padding[2] == 0
               and conv2d.attrs.padding[3] == 0
               and conv2d_input.checked_type.dtype == "int8"
               and conv2d_weight.checked_type.dtype == "int8"
               and pattern.checked_type.dtype == "int8"
               and bias_dtype == "int32"
               and all([zp == 0 for zp in kernel_zp])
               and (not is_depthwise or bias_add is not None)
   ```
   This check _conv2d.attrs.padding[2] == 0_ returns _IntImm_ type instead of _bool_. So, the fix could be casting just the _conv2d.attrs.padding[2]_ instead of casting around the whole complex boolean expression. Just to be safe always, I chose to go with the latter choice for all the operators which involve accessing attributes.
   
   




-- 
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] manupa-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r766588850



##########
File path: tests/python/contrib/test_cmsisnn/test_pooling.py
##########
@@ -45,10 +45,9 @@
 def make_model(pool_op, shape, pool_size, strides, padding, dtype, scale, zero_point, relu_type):
     """Return a model and any parameters it may have"""
     op = relay.var("input", shape=shape, dtype=dtype)
-    pad_ = (0, 0, 0, 0)
-    if padding == "SAME":
-        dilation = (1, 1)
-        pad_ = get_same_padding((shape[1], shape[2]), pool_size, dilation, strides)
+    dilation = (1, 1)
+    pad_, result = get_padding((shape[1], shape[2]), pool_size, dilation, strides, padding)
+    if result:

Review comment:
       I have added a comment below, it is a bit difficult to follow what "result" means here. I think a named tuple might help.
   
   However, looking at this feel, it is better to keep the get_padding(..) just to return the pad top, bottom, left, right values while here we could use padding check create the nn.pad rather than passing it inside the get_padding to return another boolean as 'result'




-- 
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] ashutosh-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r765043641



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       The problem originated because of checks for Conv2D function: check_qnn_conv2d()
   
   Here is how it looks :
   ```
       conv2d.attrs.out_dtype == "int32"
               and conv2d.attrs.padding[2] == 0
               and conv2d.attrs.padding[3] == 0
               and conv2d_input.checked_type.dtype == "int8"
               and conv2d_weight.checked_type.dtype == "int8"
               and pattern.checked_type.dtype == "int8"
               and bias_dtype == "int32"
               and all([zp == 0 for zp in kernel_zp])
               and (not is_depthwise or bias_add is not None)
   ```
   This check _conv2d.attrs.padding[2] == 0_ returns _IntImm_ type instead of _bool_. So, the fix could just be casting just _conv2d.attrs.padding[2]_ instead of casting around the whole complex boolean expression. Just to be safe always, I chose to go with the latter choice for all the operators which involves accessing attributes.
   
   




-- 
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] mshawcroft commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       Ah ok, that's curious, and presumably once one of those subclauses has an integer type, the subsequent application of and just propagates the numerical type rather than giving a bool.
   
   Thanks for the explanation.
   
   This explanation makes sense for the conv2d case where that padding comparison return intimm, but presumably it does not apply to several of the other cases where bool() has been inserted. For instance this qnn_binary_op case that I commented on... in which case it would probably be some what less confusing to the future read of this code if we didn't insert the unnecessary bool() cast.
   
   For the case(s) where == return intimm instead of bool, I wonder whether this is the actual bug, or whether the actual bug is that the underlying == machinery is broken and returning an inappropriate type, it is certainly not illegal to have == return an arbitrary object in python, but there is a strong convention that __eq__ returns a bool, Im thinking specifically from the perspective of [the principle of least astonishment ](https://en.wikipedia.org/wiki/Principle_of_least_astonishment).
   
   If this really is the bug (and == really should be returning a non bool object), then I'd suggest that from the readers perspective, inserting bool cast just around the subexpression that need to be cast rather than around entire subexpression is less confusing.  A comment as to why the spurious bool() cast is required might also be helpful.....




-- 
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] u99127 commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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


   > LGTM (modulo others' comments) now!. Thanks for working with me on this.
   
   
   LGTM .
   
   Thanks,
   Ramana


-- 
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] mshawcroft commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       Ah ok, that's curious, and presumably once one of those subclauses has an integer type, the subsequent application of and just propagates the numerical type rather than giving a bool.
   
   Thanks for the explanation.
   
   This explanation makes sense for the conv2d case where that padding comparison return intimm, but presumably it does not apply to several of the other cases where bool() has been inserted. For instance this qnn_binary_op case that I commented on... in which case it would probably be some what less confusing to the future reader of this code if we didn't insert the unnecessary bool() cast.
   
   For the case(s) where == return intimm instead of bool, I wonder whether this is the actual bug, or whether the actual bug is that the underlying == machinery is broken and returning an inappropriate type, it is certainly not illegal to have == return an arbitrary object in python, but there is a strong convention that __eq__ returns a bool, Im thinking specifically from the perspective of [the principle of least astonishment ](https://en.wikipedia.org/wiki/Principle_of_least_astonishment).
   
   If this really is the bug (and == really should be returning a non bool object), then I'd suggest that from the readers perspective, inserting bool cast just around the subexpression that need to be cast rather than around entire subexpression is less confusing.  A comment as to why the spurious bool() cast is required might also be helpful.....




-- 
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] manupa-arm merged pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm merged pull request #9682:
URL: https://github.com/apache/tvm/pull/9682


   


-- 
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] ashutosh-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-988964852


   true that, I clubbed it with another bug fix which I'm still working on. If its okay with you, can I add that test later?


-- 
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] mshawcroft commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       Im puzzled by this change.  Specifically I don't understand how the insertion of the bool() cast here changes the return type of the function, superficially it looks like the two subclauses are comparisons of str == str, both resulting in a class 'bool', applying 'and' to two bools will result in a bool.   So what does the cast achieve?
   
   Ditto the same logic applies to each of the previous bool casts inserted above...
   
   What am I missing?




-- 
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] ashutosh-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-990803686


   @u99127 @manupa-arm any other thoughts on this?


-- 
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] ashutosh-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r766755054



##########
File path: tests/python/contrib/test_cmsisnn/test_pooling.py
##########
@@ -45,10 +45,9 @@
 def make_model(pool_op, shape, pool_size, strides, padding, dtype, scale, zero_point, relu_type):
     """Return a model and any parameters it may have"""
     op = relay.var("input", shape=shape, dtype=dtype)
-    pad_ = (0, 0, 0, 0)
-    if padding == "SAME":
-        dilation = (1, 1)
-        pad_ = get_same_padding((shape[1], shape[2]), pool_size, dilation, strides)
+    dilation = (1, 1)
+    pad_, result = get_padding((shape[1], shape[2]), pool_size, dilation, strides, padding)
+    if result:
         op = relay.nn.pad(
             op,
             pad_width=[(0, 0), (pad_[0], pad_[2]), (pad_[1], pad_[3]), (0, 0)],

Review comment:
       That has troubled me as well at the time of implementing it :)
   In CMSIS-NN, its only used for calculating the appropriate start, end for the Pooling kernel. I think this should work either way. I will try it out without the preceding padding op.




-- 
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] manupa-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-991564446


   Thanks @ashutosh-arm @u99127 @mshawcroft @ekalda . This is merged now!


-- 
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] ashutosh-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-988973411


   I agree with you on all the points there. Just wanted to avoid the long CI cycle. I will add the test.


-- 
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] ashutosh-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r766744080



##########
File path: tests/python/contrib/test_cmsisnn/utils.py
##########
@@ -86,18 +86,20 @@ def make_module(func):
     return mod
 
 
-def get_same_padding(data, kernel, dilation, stride, cmsisnn_padding=True):
+def get_padding(data, kernel, dilation, stride, padding):
     """Provides CMSIS-NN padding when output dim == input dim"""

Review comment:
       CMSIS-NN padding is same as TFLU padding. This function was for providing "SAME" kind of padding defined by TFL / TF specs. When we expect output to be of the same dim as input, input to Conv2D / other ops needs to be padded first.  




-- 
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] manupa-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-991079613


   Agreed! that part is out of scope for this PR but meant to be a general comment :) .
   
   As we discussed offline, if we can simply use get_<type>_padding() helpers as well as an invalid case to exercise non-offloading scenario, that should be good enough to get the PR in.


-- 
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] ekalda commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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



##########
File path: tests/python/contrib/test_cmsisnn/utils.py
##########
@@ -86,18 +86,20 @@ def make_module(func):
     return mod
 
 
-def get_same_padding(data, kernel, dilation, stride, cmsisnn_padding=True):
+def get_padding(data, kernel, dilation, stride, padding):
     """Provides CMSIS-NN padding when output dim == input dim"""

Review comment:
       For the enlightenment, what is CMSIS-NN padding and why is it provided only when `output dim == input dim`?

##########
File path: tests/python/contrib/test_cmsisnn/utils.py
##########
@@ -86,18 +86,20 @@ def make_module(func):
     return mod
 
 
-def get_same_padding(data, kernel, dilation, stride, cmsisnn_padding=True):
+def get_padding(data, kernel, dilation, stride, padding):

Review comment:
       What does `data` represent here? If it is a shape of a tensor, then I think the parameter name should represent that (or some documentation could help) 

##########
File path: tests/python/contrib/test_cmsisnn/test_pooling.py
##########
@@ -45,10 +45,9 @@
 def make_model(pool_op, shape, pool_size, strides, padding, dtype, scale, zero_point, relu_type):
     """Return a model and any parameters it may have"""
     op = relay.var("input", shape=shape, dtype=dtype)
-    pad_ = (0, 0, 0, 0)
-    if padding == "SAME":
-        dilation = (1, 1)
-        pad_ = get_same_padding((shape[1], shape[2]), pool_size, dilation, strides)
+    dilation = (1, 1)
+    pad_, result = get_padding((shape[1], shape[2]), pool_size, dilation, strides, padding)
+    if result:
         op = relay.nn.pad(
             op,
             pad_width=[(0, 0), (pad_[0], pad_[2]), (pad_[1], pad_[3]), (0, 0)],

Review comment:
       For enlightenment, why do we add a pad operator to the graph instead of using the padding attribute of pool2d?




-- 
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] mshawcroft commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       Ah ok, that's curious, and presumably once one of those subclauses has an integer type, the subsequent application of and just propagates the numerical type rather than giving a bool.
   
   Thanks for the explanation.
   
   This explanation makes sense for the conv2d case where that padding comparison return intimm, but presumably it does not apply to several of the other cases where bool() has been inserted. For instance this qnn_binary_op case that I commented on... in which case it would probably be some what less confusing to the future reader of this code if we didn't insert the unnecessary bool() casts.
   
   For the case(s) where == return intimm instead of bool, I wonder whether this is the actual bug, or whether the actual bug is that the underlying == machinery is broken and returning an inappropriate type, it is certainly not illegal to have == return an arbitrary object in python, but there is a strong convention that __eq__ returns a bool, Im thinking specifically from the perspective of [the principle of least astonishment ](https://en.wikipedia.org/wiki/Principle_of_least_astonishment).
   
   If this really is the bug (and == really should be returning a non bool object), then I'd suggest that from the readers perspective, inserting bool cast just around the subexpression that need to be cast rather than around entire subexpression is less confusing.  A comment as to why the spurious bool() cast is required might also be helpful.....




-- 
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] ashutosh-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r766744856



##########
File path: tests/python/contrib/test_cmsisnn/utils.py
##########
@@ -86,18 +86,20 @@ def make_module(func):
     return mod
 
 
-def get_same_padding(data, kernel, dilation, stride, cmsisnn_padding=True):
+def get_padding(data, kernel, dilation, stride, padding):

Review comment:
       Good point. I will take care of it.




-- 
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] ashutosh-arm commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-991052147


   We should definitely discuss about having TFLU E2E test with wider audience. 


-- 
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] manupa-arm edited a comment on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm edited a comment on pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#issuecomment-991079613


   Agreed! that part is out of scope for this PR but meant to be a general comment :) .
   
   As we discussed offline, if we can simply use get_\<type\>_padding() helpers as well as an invalid case to exercise non-offloading scenario, that should be good enough to get the PR in.


-- 
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] manupa-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r765509593



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       Where do you see the IntImm?
   
   I have seen python side bools become IntImm s when acessed from C++ via TVM's FFIs. Is it the case here?
   




-- 
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] manupa-arm merged pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm merged pull request #9682:
URL: https://github.com/apache/tvm/pull/9682


   


-- 
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] manupa-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
manupa-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r766579957



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -135,8 +135,8 @@ def check_qnn_conv2d(pattern):
 
         return (
             conv2d.attrs.out_dtype == "int32"
-            and conv2d.attrs.padding[2] == 0
-            and conv2d.attrs.padding[3] == 0
+            and int(conv2d.attrs.padding[2]) == 0

Review comment:
       I believe this is the actual fix. Am I right ? (because others are changes to test code).
   What test would fail in this PR without this change ?
   
   I think we could have a simpler test to check whether graph partitioning works with conv2d with padding values for top, left, bottom and right.

##########
File path: tests/python/contrib/test_cmsisnn/utils.py
##########
@@ -86,18 +86,20 @@ def make_module(func):
     return mod
 
 
-def get_same_padding(data, kernel, dilation, stride, cmsisnn_padding=True):
+def get_padding(data, kernel, dilation, stride, padding):

Review comment:
       Is this change necessary to fix the bug here ?

##########
File path: tests/python/contrib/test_cmsisnn/test_generate_constants.py
##########
@@ -94,16 +94,14 @@ def make_model(
     kernel_h = kernel_shape[h_index]
     kernel_w = kernel_shape[w_index]
     a = relay.var("input", shape=shape, dtype=dtype)
-    p = (0, 0, 0, 0)
-    if padding == "SAME":

Review comment:
       This seems orthogonal to the fix here

##########
File path: tests/python/contrib/test_cmsisnn/test_pooling.py
##########
@@ -45,10 +45,9 @@
 def make_model(pool_op, shape, pool_size, strides, padding, dtype, scale, zero_point, relu_type):
     """Return a model and any parameters it may have"""
     op = relay.var("input", shape=shape, dtype=dtype)
-    pad_ = (0, 0, 0, 0)
-    if padding == "SAME":
-        dilation = (1, 1)
-        pad_ = get_same_padding((shape[1], shape[2]), pool_size, dilation, strides)
+    dilation = (1, 1)
+    pad_, result = get_padding((shape[1], shape[2]), pool_size, dilation, strides, padding)
+    if result:

Review comment:
       I have added a comment below, it is a bit difficult to follow what "result" means here. I think a named tuple might help.
   
   However, looking at this feel, it is better to keep the get_padding(..) just to return the pad top, bottom, left, right values while here we could use padding check create the nn.pad rather than passing it inside the get_padding just and returning that check as the 'result'

##########
File path: tests/python/contrib/test_cmsisnn/utils.py
##########
@@ -86,18 +86,20 @@ def make_module(func):
     return mod
 
 
-def get_same_padding(data, kernel, dilation, stride, cmsisnn_padding=True):
+def get_padding(data, kernel, dilation, stride, padding):
     """Provides CMSIS-NN padding when output dim == input dim"""
+    if padding == "VALID":
+        return (0, 0, 0, 0), False
     dilated_kernel_h = dilation[0] * (kernel[0] - 1) + 1
     dilated_kernel_w = dilation[1] * (kernel[1] - 1) + 1
     out = int(math.ceil(float(data[0]) / float(stride[0])))
     pad = max(0, (out - 1) * stride[0] + dilated_kernel_h - data[0])
-    pad_top, pad_bottom = (pad, 0) if cmsisnn_padding else (0, pad)
+    pad_top, pad_bottom = (pad, 0) if padding == "SAME" else (0, pad)

Review comment:
       What pad mode does the else correspond to here ?

##########
File path: tests/python/contrib/test_cmsisnn/utils.py
##########
@@ -86,18 +86,20 @@ def make_module(func):
     return mod
 
 
-def get_same_padding(data, kernel, dilation, stride, cmsisnn_padding=True):
+def get_padding(data, kernel, dilation, stride, padding):
     """Provides CMSIS-NN padding when output dim == input dim"""
+    if padding == "VALID":
+        return (0, 0, 0, 0), False
     dilated_kernel_h = dilation[0] * (kernel[0] - 1) + 1
     dilated_kernel_w = dilation[1] * (kernel[1] - 1) + 1
     out = int(math.ceil(float(data[0]) / float(stride[0])))
     pad = max(0, (out - 1) * stride[0] + dilated_kernel_h - data[0])
-    pad_top, pad_bottom = (pad, 0) if cmsisnn_padding else (0, pad)
+    pad_top, pad_bottom = (pad, 0) if padding == "SAME" else (0, pad)
 
     out = int(math.ceil(float(data[1]) / float(stride[1])))
     pad = max(0, (out - 1) * stride[1] + dilated_kernel_w - data[1])
-    pad_left, pad_right = (pad, 0) if cmsisnn_padding else (0, pad)
-    return [pad_top, pad_left, pad_bottom, pad_right]
+    pad_left, pad_right = (pad, 0) if padding == "SAME" else (0, pad)
+    return [pad_top, pad_left, pad_bottom, pad_right], True

Review comment:
       Please add documentation as to what are returned with this function.
   It used to return the pad top,left,bottom and right values which are bit simpler, However augmenting that with a boolean is confusing.
   
   I would recommend using a named tuple as the return here to indicate what the boolean correspond to




-- 
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] u99127 edited a comment on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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


   We should be looking to add tests when they are fixing bugs at the time the commits go in to show what problem they are solving. Sometimes it is obvious but in this case we don't have any test coverage in the test suite for this failure. 
   
   A PR should also be ideally fixing one bug not multiple bugs and that too in an unclear fashion. 
   
   I'm not a committer or a reviewer in the TVM community , so others might have a different view.


-- 
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] u99127 commented on pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

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


   We should be looking to add tests when they are fixing bugs at the time the commits go in to show what problem they are solving. Sometimes it is obvious but in this case we don't have any test coverage in the test suite for this failure. 
   
   A commit should also be fixing one bug not multiple bugs and that too in an unclear fashion. 


-- 
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] ashutosh-arm commented on a change in pull request #9682: [CMSIS-NN] Fixed return data type from pattern callback function

Posted by GitBox <gi...@apache.org>.
ashutosh-arm commented on a change in pull request #9682:
URL: https://github.com/apache/tvm/pull/9682#discussion_r765076744



##########
File path: python/tvm/relay/op/contrib/cmsisnn.py
##########
@@ -227,7 +227,7 @@ def binary_op_pattern(op):
 
     def check_qnn_binary_op(extract):
         """Check if multiply is supported by CMSIS-NN."""
-        return (
+        return bool(

Review comment:
       Tagging @leandron  if he knows something about the conv2d.attrs.padding[2] == 0 returning IntImm instead of bool. Its definitely surprising. 
   
   I'd update the code to just cast the subexpression as that makes code more readable, as you've suggested. Thanks @mshawcroft 




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