Skip to content

Conversation

@mikeseven
Copy link
Contributor

Pytorch Conv Transpose Padding Fix

Background

  • we noticed a discrepancy between the output shapes produced by Pytorch and TVM for a Pytorch network containing a single torch.nn.ConvTranspose2d operator.
  • When comparing the attributes of the torch.nn.ConvTranspose2d operator and the tvm.relay.nn.conv2d_transpose
    operator, the output_padding parameter in tvm.relay.nn.conv2d_transpose would always default to
    0 regardless of what output padding was set in torch.nn.ConvTranspose2d.
  • Upon further inspection, it was found that in tvm/python/tvm/relay/frontend/pytorch.py, the import logic for convolution layers was missing the output_padding parameter.

The Fix

  • All fixes were implemented in tvm/relay/frontend/pytorch.py.
  • To resolve the missing padding parameter, convolution method of the
    PyTorchOpConverter class is updated so that when it constructed the relay convolution op it supplied the output_padding attribute in the cases where it was creating convolution transpose operations.
  • Over the course of the fix I also discovered that the convolution class automatically converted
    torch.nn.ConvTranspose1D operations into tvm.relay.nn.conv2d_transpose. This was fixed so now they were
    converted into tvm.relay.nn.conv1d_transpose operations.
  • Over the couse of the fix we also discovered that torch.nn.Conv1d operations were being converted into
    tvm.relay.nn.conv2d operations. This was fixed so that they are now converted into tvm.relay.nn.conv1d
    operations. There is a slight caveat where because tvm does not support grouped 1D convolution as stated in the
    description of tvm.relay.nn.conv1d, in that case we convert the operation to 2D convolution which does have
    support for grouped convolution. After the 2D convolution, we then squeeze the output to get the correct shape and
    values for a grouped 1D convolution.

Test Coverage

  • extended the test_forward_conv_transpose test in tvm/tests/python/frontend/pytorch/test_forward.py.

Mikael Sevenier added 30 commits March 18, 2020 19:30
# Conflicts:
#	python/tvm/relay/frontend/tensorflow.py
Mikael Sevenier and others added 23 commits February 26, 2021 12:28
…rameter for conv transpose operations

* updating pytorch converter to correctly convert conv1d to conv1d in tvm inestead of a flattened conv2d unless under circumstances of grouped convolution
* updating pytorch converter to correctly convert conv1d transpose to conv1d transpose in tvm instead of a flattened conv2d transpose
* added tests to cover these latest additions
…he#34)

SYSOL-584 Pytorch Conv Transpose Padding Fix

Approved-by: Alicja Kwasniewska
Approved-by: Mikael Sevenier
@mikeseven
Copy link
Contributor Author

updated with missing files

@masahi masahi self-assigned this Apr 27, 2021
@masahi masahi closed this May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants