GwiHwan-Go opened a new issue, #14927:
URL: https://github.com/apache/tvm/issues/14927

   Description
   TVM's AvgPool2d function exhibits a bug when the stride is larger than the 
kernel size. The function produces incorrect values, which are not consistent 
with the expected output as verified by PyTorch. This bug surfaces when certain 
configurations of stride and kernel size are used.
   
   Notably, the following argument settings trigger the issue:
   
   {'kernel_size': 6, 'stride': 10, 'padding': 0, 'ceil_mode': True, 
'count_include_pad': False, 'divisor_override': None}
   
   {'kernel_size': 4, 'stride': 9, 'padding': 0, 'ceil_mode': True, 
'count_include_pad': False, 'divisor_override': None}
   
   {'kernel_size': 7, 'stride': 7, 'padding': 2, 'ceil_mode': True, 
'count_include_pad': False, 'divisor_override': None}
   
   Interestingly, when {'kernel_size': 7, 'stride': 7, 'padding': 1} is used, 
the function does not produce incorrect results.
   
   The input information for the AvgPool2d function across all scenarios is: 
input_size = [2, 3, 18, 18], input_channels_first = True, 
input_same_width_height = False, input_data_type = torch.float32.
   
   ### Expected behavior
   
   When using the AvgPool2d function in TVM, the output should match the output 
from PyTorch, regardless of the values of stride and kernel size. 
   
   ### Actual behavior
   
   When the stride is larger than the kernel size, the function should 
correctly handle it and produce results consistent with PyTorch. Additionally, 
the output tensor shapes also differ, pointing to an issue with the function's 
implementation. Furthermore, the divisor_override attribute is reportedly 
always causing incorrect results according to issue #14795. 
   
   ### Environment
   
   OS : Linux 5.4.0-148-generic
   Python : 3.9.16
   PyTorch : 2.0.0
   TVM : 0.11.1
   Any environment details, such as: Operating System, TVM version, etc
   
   ### Steps to reproduce
   ```python
   import torch
   from tvm import relay
   import tvm
   import numpy as np
   
   m = torch.nn.AvgPool2d(kernel_size=6, stride=10, padding=0, ceil_mode=True, 
count_include_pad=False)
   
   input_data=[torch.randn([2, 3, 18, 18], dtype=torch.float32)]
   torch_outputs = m(*[input.clone() for input in input_data])
   
   trace = torch.jit.trace(m, input_data)
   input_shapes = [('input0', torch.Size([2, 3, 18, 18]))]
   
   mod, params = relay.frontend.from_pytorch(trace, input_shapes)
   
   with tvm.transform.PassContext(opt_level=3):
       exe = relay.create_executor('graph', mod=mod, params=params, 
device=tvm.device('llvm', 0), target='llvm').evaluate()
   
   input_tvm = dict(zip(['input0'], [inp.clone().cpu().numpy() for inp in 
input_data]))
   tvm_outputs = exe(**input_tvm).asnumpy()
   
   np.testing.assert_allclose(torch_outputs, tvm_outputs, rtol=1e-3, atol=1e-3)
   ```
   
   ### Triage
   
   Please refer to the list of label tags 
[here](https://github.com/apache/tvm/wiki/Issue-Triage-Labels) to find the 
relevant tags and add them below in a bullet format (example below).
   
   * needs-triage
   frontend:pytorch


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