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.
Hi,
Try to convert your model from pytorch to onnx, and than try to do the DLC conversion.
Thanks