Forums - Depthwise Convolution Bug

3 posts / 0 new
Last post
Depthwise Convolution Bug
thelytch
Join Date: 26 Oct 22
Posts: 5
Posted: Wed, 2022-11-02 05:09

Hi,

I have a simple PyTorch module that executes a depthwise convolution.

Complete Code

    import torch
    class Depthwise(torch.nn.Module):
        
        def __init__(self):
            super().__init__()
            self.conv = torch.nn.Conv2d(12, 
                                        48, 
                                        kernel_size=2, 
                                        stride=2, 
                                        groups=12, 
                                        bias=False)
 
        
        def forward(self, x):
            return self.conv(x)
 
    channels = 12
    input_shape = [1,channels,288,480]
    
    bugModule = Depthwise()

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


snpe-pytorch-to-dlc will convert the model without terminating with an error, but provides the runtime warning:

$ snpe-pytorch-to-dlc -i depthwise.pt --input_dim 'input_0' 1,12,288,480 --debug

snpe-1.66.0.3729/lib/python/qti/aisw/converters/backend/ir_to_dlc.py:336: RuntimeWarning: info_code=1002; message=Layer parameter value is invalid. Layer depthwise_convolution_0: input depth should be evenly divisible by group parameter; component=Model Validation; line_no=992; thread_id=139737817130816
  node.op.group)
 
If you attempt to execute it, it will fail with:

ERROR - snpebm.snpebm_device: ['error_code=1002; error_message=Layer parameter value is invalid. error_code=1002; error_message=Layer parameter value is invalid. Layer depthwise_convolution_0: input depth should be evenly divisible by group parameter; error_component=Model Validation; line_no=992; thread_id=-225721888; error_component=Model Validation; line_no=342; thread_id=-183237516']
 

Clearly the input depth (12) and the groups (12) are equal, and so input depth is evenly divisible by group parameter

Dependencies:
- snpe: 1.66.0.3729
- torch: 1.11 (also same issue with 1.8)

DLC file: depthwise.dlchttps://drive.google.com/file/d/1n13g07X6mExJp1hWa0tYojA4sE2QfIcV/view?u...
PT file: depthwise.pthttps://drive.google.com/file/d/1anTHbFizVczXMrz9JpKpBz8YEWAu2lER/view?u...

  • Up0
  • Down0
sanjjey.a.sanjjey
Join Date: 17 May 22
Posts: 51
Posted: Thu, 2022-11-03 01:33

Hi,

Please check the command you have used snpe-pytorch-to-dlc, you need to provide -o output_path followed by output file(.dlc) where you want to save your dlc model.

If not specified, the converter model will be written to a file with same name as the input model.

Please check the link given:  https://developer.qualcomm.com/sites/default/files/docs/snpe/tools.html#...

Thanks.

  • Up0
  • Down0
thelytch
Join Date: 26 Oct 22
Posts: 5
Posted: Thu, 2022-11-03 07:49

That is incorrect, the output path is not required. As you can observe in my first post, I have depthwise.pt and depthwise.dlc attached and generated using my code, which you could have easily verified. Your response has nothing to do with the problem of my question.

The argument -o is not required (look at the link you sent and you will see it's optional), furthermore, if you don't specify -o to snpe-pytorch-to-dlc, it will generate a new file like this <input-file-name>.dlc, eg:

$ snpe-pytorch-to-dlc -i input_file.pt ...

Results in the output file input_file.dlc

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