ccjoechou opened a new issue #8848:
URL: https://github.com/apache/tvm/issues/8848


   We are prototyping a BYOC flow and have a need to convert the layout of each 
nn.max_pool2d call in IR graph to use the attrs["layout"] = "NHWC" format.
   Based on our analysis, we found 2 possible issues below:
   (1) It seems that there is a bug in the tvm/src/relay/op/nn/pooling.cc file 
for the IF condition (at line 52) of the InferCorrectLayoutOutput 
PoolInferCorrectLayout() function -- we have a resolution, which is provided at 
the end of this message. Without applying our resolution and by using the 
latest TVM codebase, we can "not" convert the layout of a nn.max_pool2d call 
from the default "NCHW" format to a "NHWC" format.
   (2) It seems also that there are 3 + 1 problems in the 
tvm/tests/python/relay/test_pass_convert_op_layout.py file where:
   (2.a) The expected IR outcomes can be incorrect for these 3 test cases: 
test_conv_bias_pool_convert_layout(), 
test_deformable_conv_bias_pool_convert_layout(), and 
test_resnet_convert_layout(). Can these cause the problem identified in item 
(1) not being auto detected?
   (2.b) Also found minor typos at the end of this test file where: we are 
calling test_image_resize_convert_layout() and 
test_conv_image_resize_convert_layout() but they should be calling 
test_image_resize2d_convert_layout() and 
test_conv_image_resize2d_convert_layout(), respectively.
   
   We are new to the community.
   We have attached our test_pass_convert_op_layout.py.rev2 file in the 
provided zip file for you to review and run - in order to reproduce the 
reported issue (BUT based on our expected IR graphs in the file).
   $ cd <your tvm folder>/tests/python/relay/
   $ cp test_pass_convert_op_layout.py.rev2 .
   $ python3 -u test_pass_convert_op_layout.py.rev2
   
   We have also attached our pooling_rev2.cc file in the provided zip file for 
you to review and to rebuild tvm/build area in order to re-run our 
test_pass_convert_op_layout_rev2.py again.
   
   We have been using the following 2 snippets (A, B) to convert layout for 
nn.max_pool2d calls in our BYOC flow.
   
[issue-08252021.zip](https://github.com/apache/tvm/files/7048694/issue-08252021.zip)
   
   + snippet A
       @tvm.ir.register_op_attr("nn.max_pool2d", "FTVMConvertOpLayout")
       def convert_maxpool2d(attrs, inputs, tinfos, desired_layouts):
           new_attrs = dict(attrs)
           new_attrs["layout"] = str(desired_layouts[0])
           return relay.nn.max_pool2d(*inputs, **new_attrs)
   
   + snippet B
       pass = [
           tvm.relay.transform.InferType(),
           tvm.transform.PrintIR("before ConvertLayout"),
           tvm.relay.transform.ConvertLayout( { "nn.max_pool2d": ["NHWC"] } ),
           tvm.transform.PrintIR("after ConvertLayout"),
       ]
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to