Forums - snpe-pytorch-to-dlc with aten::broadcast_to UDO

2 posts / 0 new
Last post
snpe-pytorch-to-dlc with aten::broadcast_to UDO
kunalpaode
Join Date: 16 Jul 23
Posts: 4
Posted: Fri, 2023-11-10 14:05

I am trying to convert a pytorch model to a dlc.
The model consists of a linear layer, then a torch.broadcast_to() operation.
If i remove the broadcast_to() the .pt file does convert to dlc.
I have read the documentation, looked at forums posts, and still cannot find an answer.

Here is the pytorch code:

*****************************

import torch
from torch import nn
import numpy as np
 
class MyLayer(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(3, 1, bias=False)
        weights = [3.0, 5.0, 7.0]
        with torch.no_grad():
            for i in range(len(weights)):
                self.linear1.weight[0][i] = weights[i]
    def forward(self, x):
        out = self.linear1(x)
        out = torch.broadcast_to(out, (2,2))
        return out
    
input = torch.Tensor([5, 12, 35])
model = MyLayer()
model.eval()
 
script_model = torch.jit.trace(model, input)
script_model.save("simple_linear.pt")

****************************************************

Here is an example of 1 of the many variation of the snpe-pytorch-to-dlc calls I have made.

snpe-pytorch-to-dlc --input_network simple_linear.pt --input_dim input "1,1,1,3" --output_path simple_linear_with_udo.dlc --udo ./aten::broadcast_to.json

Here is the error I get, whether or not I include the "--udo" flag in my call above.

2023-11-10 13:57:34,287 - 230 - ERROR - Encountered Error: The following operators are not implemented: ['aten::broadcast_to']
Traceback (most recent call last):
  File "/opt/qcom/aistack/snpe/2.12.0.230626/bin/x86_64-linux-clang/snpe-pytorch-to-dlc", line 47, in main
    converter = PyTorchConverterFrontend(args)
  File "/opt/qcom/aistack/snpe/2.12.0.230626/lib/python/qti/aisw/converters/pytorch/pytorch_to_ir.py", line 24, in __init__
    super(PyTorchConverterFrontend, self).__init__(args,
  File "/opt/qcom/aistack/snpe/2.12.0.230626/lib/python/qti/aisw/converters/relay/relay_to_ir.py", line 274, in __init__
    self.relay_mod, self.relay_params, self.expr_to_source_info_dict = self.importer.convert_to_relay(self.input_model_path)
  File "/opt/qcom/aistack/snpe/2.12.0.230626/lib/python/qti/aisw/converters/relay/importers/pytorch_importer.py", line 383, in convert_to_relay
    self.mod, self.params = from_pytorch(pytorch_model, input_model_path, shape_list, self.dtype_dict, use_parser_friendly_name=True)
  File "/opt/qcom/aistack/snpe/2.12.0.230626/lib/python/qti/tvm/relay/frontend/pytorch.py", line 3852, in from_pytorch
    converter.report_missing_conversion(op_names)
  File "/opt/qcom/aistack/snpe/2.12.0.230626/lib/python/qti/tvm/relay/frontend/pytorch.py", line 2714, in report_missing_conversion
    raise NotImplementedError(msg)
NotImplementedError: The following operators are not implemented: ['aten::broadcast_to']
 
I have tried changing the name of the json file and/or the names inside the json file to be "aten::broadcast_to" or just "broadcast_to", but it does not work either way. I have also tried changing the list of inputs inside the json.
Here is my latest version:
 
{
    "UdoPackage_0":
    {
        "Operators": [
            {
            "type": "aten::broadcast_to",
                "inputs":[
                    {"name":"a", "per_core_data_types": {"CPU":"FLOAT_32"}},
                    {"name": "size", "data_type":"INT_32"}
                ],
                "outputs":[
                    {"name":"Output", "per_core_data_types": {"CPU":"FLOAT_32"}}
                ],
                "core_types": ["CPU"]
            }
        ],
        "UDO_PACKAGE_NAME": "aten::Broadcast_To_Udo_Package"
    }
}
 

I suspect it may be an issue with the form of the config not matching that of the actual function aten::braocast_to, but I can't seem to come up with a solution.

  • Up0
  • Down0
sanjjey.a.sanjjey
Join Date: 17 May 22
Posts: 57
Posted: Tue, 2024-01-30 02:13

Hi,

Try to convert your model from pytorch to onnx, and than try to do the DLC conversion.

 

Thanks

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