Forums - ConvTranspose2d PyTorch -> DLC Conversion Bug

4 posts / 0 new
Last post
ConvTranspose2d PyTorch -> DLC Conversion Bug
thelytch
Join Date: 26 Oct 22
Posts: 5
Posted: Mon, 2022-10-31 06:36

Hi,

It seems that `snpe-pytorch-to-dlc` is unable to handle `ConvTranspose2d` conversions from PyTorch. Is this expected? Any suggestions?

Dependencies:
- snpe-1.66.0.3729
torch==1.11

Complete Example Code:

    import torch
    class ConvTransposeModule(torch.nn.Module):
        
        def __init__(self, in_channels):
            super().__init__()
            self.in_channels = in_channels
            self.out_channels = in_channels // 4
            self.conv = torch.nn.ConvTranspose2d(self.in_channels, 
                                                 self.out_channels, 
                                                 kernel_size=2, 
                                                 stride=2, 
                                                 groups=self.out_channels,  # if you remove this, it still fails!
                                                 bias=False)
        
        def forward(self, x):
            return self.conv(x)

    channels = 128
    input_shape = [1,channels,64,64]
    convTranspose = ConvTransposeModule(channels)

    input = torch.randn(input_shape)
 
    def trace_and_save(module, inputs, filename):
        torchscript_model = torch.jit.trace(module, inputs)
        torchscript_model.save(filename)
 
    trace_and_save(convTranspose, [input], 'conv_transpose_module.pt') 


Conversion using `snpe-pytorch-to-dlc`:

> snpe-pytorch-to-dlc -i conv_transpose_module.pt --input_dim 'input_0' 1,128,64,64 --debug

In particular dimension 1 conflicts: 0 does not match 1.

Full trace:

2022-10-31 13:28:03,636 - 2972 - WARNING - Untyped Tensor found, assume it is float32
2022-10-31 13:28:03,844 - 209 - ERROR - Encountered Error: Traceback (most recent call last):
  9: TVMFuncCall
  8: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::transform::Pass, tvm::IRModule)>::AssignTypedLambda<tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#7}>(tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#7}, std::string)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
  7: tvm::transform::Pass::operator()(tvm::IRModule) const
  6: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  5: tvm::transform::ModulePassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  4: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::InferType()::{lambda(tvm::IRModule, tvm::transform::PassContext const&)#1}>(tvm::relay::transform::InferType()::{lambda(tvm::IRModule, tvm::transform::PassContext const&)#1})::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
  3: tvm::DiagnosticContext::Render()
  2: tvm::DiagnosticRenderer::Render(tvm::DiagnosticContext const&)
  1: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<void (tvm::DiagnosticContext)>::AssignTypedLambda<tvm::TerminalRenderer(std::ostream&)::{lambda(tvm::DiagnosticContext const&)#1}>(tvm::TerminalRenderer(std::ostream&)::{lambda(tvm::DiagnosticContext const&)#1})::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
  0: tvm::ReportAt(tvm::DiagnosticContext const&, std::ostream&, tvm::Span const&, tvm::Diagnostic const&)
  File "/prj/qct/webtech_hyd/pcgbait/projects/zsnpe_waipio/SNPE/ThirdParty/tvm/src/tvm_fork/src/ir/diagnostic.cc", line 238
TVMError: The source maps are not populated for this module. Please use `tvm.relay.transform.AnnotateSpans` to attach source maps for error reporting. Error: The Relay type checker is unable to show the following types match.
In particular dimension 1 conflicts: 0 does not match 1.
Traceback (most recent call last):
  File "/snpe-1.66.0.3729/bin/x86_64-linux-clang/snpe-pytorch-to-dlc", line 47, in main
    converter = PyTorchConverterFrontend(args)
  File "/snpe-1.66.0.3729/lib/python/qti/aisw/converters/pytorch/pytorch_to_ir.py", line 23, in __init__
    **kwargs)
  File "/snpe-1.66.0.3729/lib/python/qti/aisw/converters/relay/relay_to_ir.py", line 269, in __init__
    self.importer.convert_to_relay(self.input_model_path)
  File "/snpe-1.66.0.3729/lib/python/qti/aisw/converters/relay/importers/pytorch_importer.py", line 238, in convert_to_relay
    self.mod, self.params = from_pytorch(pytorch_model, shape_list, self.dtype_dict)
  File "/snpe-1.66.0.3729/lib/python/qti/tvm/relay/frontend/pytorch.py", line 3335, in from_pytorch
    ret = converter.convert_operators(_get_operator_nodes(graph.nodes()), outputs, ret_name)[0]
  File "/snpe-1.66.0.3729/lib/python/qti/tvm/relay/frontend/pytorch.py", line 2746, in convert_operators
    self.record_output_type(relay_out)
  File "/snpe-1.66.0.3729/lib/python/qti/tvm/relay/frontend/pytorch.py", line 220, in record_output_type
    self.infer_type_with_prelude(output)
  File "/snpe-1.66.0.3729/lib/python/qti/tvm/relay/frontend/pytorch.py", line 168, in infer_type_with_prelude
    body = self.infer_type(val, self.prelude.mod)
  File "/snpe-1.66.0.3729/lib/python/qti/tvm/relay/frontend/pytorch.py", line 161, in infer_type
    new_mod = transform.InferType()(new_mod)
  File "/snpe-1.66.0.3729/lib/python/qti/tvm/ir/transform.py", line 161, in __call__
    return _ffi_transform_api.RunPass(self, mod)
  File "/snpe-1.66.0.3729/lib/python/qti/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
qti.tvm._ffi.base.TVMError: Traceback (most recent call last):
  9: TVMFuncCall
  8: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::transform::Pass, tvm::IRModule)>::AssignTypedLambda<tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#7}>(tvm::transform::{lambda(tvm::transform::Pass, tvm::IRModule)#7}, std::string)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
  7: tvm::transform::Pass::operator()(tvm::IRModule) const
  6: tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  5: tvm::transform::ModulePassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const
  4: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::transform::InferType()::{lambda(tvm::IRModule, tvm::transform::PassContext const&)#1}>(tvm::relay::transform::InferType()::{lambda(tvm::IRModule, tvm::transform::PassContext const&)#1})::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
  3: tvm::DiagnosticContext::Render()
  2: tvm::DiagnosticRenderer::Render(tvm::DiagnosticContext const&)
  1: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<void (tvm::DiagnosticContext)>::AssignTypedLambda<tvm::TerminalRenderer(std::ostream&)::{lambda(tvm::DiagnosticContext const&)#1}>(tvm::TerminalRenderer(std::ostream&)::{lambda(tvm::DiagnosticContext const&)#1})::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
  0: tvm::ReportAt(tvm::DiagnosticContext const&, std::ostream&, tvm::Span const&, tvm::Diagnostic const&)
  File "/prj/qct/webtech_hyd/pcgbait/projects/zsnpe_waipio/SNPE/ThirdParty/tvm/src/tvm_fork/src/ir/diagnostic.cc", line 238
TVMError: The source maps are not populated for this module. Please use `tvm.relay.transform.AnnotateSpans` to attach source maps for error reporting. Error: The Relay type checker is unable to show the following types match.
In particular dimension 1 conflicts: 0 does not match 1.

 

  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Sat, 2022-11-05 23:18

Dear developer,

Could you help to convert your pth model to onnx and try again if this issue still have?

BR.

Wei

  • Up0
  • Down0
thelytch
Join Date: 26 Oct 22
Posts: 5
Posted: Sun, 2022-11-06 22:23

Hi, thanks for the response.

Filed provided:
conv_transpose.onnxhttps://drive.google.com/file/d/1PRPsOu5_bC2rvquuYEyMLDSBRd8Spzbx/view?u...
conv_transpose.dlc: https://drive.google.com/file/d/1z11rYo_MMNJFKsIPUUs6VZfB0Mo_n1B6/view?u...

That is, the conversion from ONNX -> DLC works. However I ave not yet confirmed that the execution actually works.

  • Up0
  • Down0
ss.pandiri
Join Date: 29 May 18
Posts: 58
Posted: Mon, 2022-11-28 22:47

---

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.