Forums - snpe-onnx-to-dlc: Wrong allowed_data_types

1 post / 0 new
snpe-onnx-to-dlc: Wrong allowed_data_types
anhtu.nguyen
Join Date: 22 Jun 22
Posts: 11
Posted: Tue, 2022-08-02 02:07

Hello,

1. Problem

I'm using snpe-onnx-to-dlc from snpe-1.61.0.3358 to convert my onnx model to dlc using some UDOs.

I find out that if I specify the data-type for of input tensors for each core for my UDOs, the data type verification is not correct.

This is the Traceback that I receive

Traceback (most recent call last):
  File "/workspace/qualcomm-base/snpe-1.61.0.3358/lib/python/qti/aisw/converters/onnx/onnx_to_ir.py", line 223, in convert
    self.graph)
  File "/workspace/qualcomm-base/snpe-1.61.0.3358/lib/python/qti/aisw/converters/common/converter_ir/translation.py", line 51, in apply_method_to_op
    return translation.apply_method(method_name, *args, **kwargs)
  File "/workspace/qualcomm-base/snpe-1.61.0.3358/lib/python/qti/aisw/converters/common/converter_ir/translation.py", line 17, in apply_method
    return self.indexed_methods[method_name](*args, **kwargs)
  File "/workspace/qualcomm-base/snpe-1.61.0.3358/lib/python/qti/aisw/converters/common/converter_ir/translation.py", line 120, in add_op
    op = self.extract_parameters(src_op, graph)
  File "/workspace/qualcomm-base/snpe-1.61.0.3358/lib/python/qti/aisw/converters/onnx/custom_op_translations.py", line 44, in extract_parameters
    param.data_type = get_internal_dtype(param.data, param)
  File "/workspace/qualcomm-base/snpe-1.61.0.3358/lib/python/qti/aisw/converters/backend/custom_ops/helpers/udo_module_helpers.py", line 185, in get_internal_dtype
    .format(src_type, op_attr.name, op_attr.allowed_data_types))
TypeError: The provided datatype: uint16 is not a valid datatype defined for: 672. Expected one of ['SNPE_UDO_CORETYPE_CPU', 'SNPE_UDO_CORETYPE_DSP']

2. Finding the cause

Below is parameters of the operation and the UDO in my UDO configuration. 

Parameters: (i can get these values by printing variable param in method extract_parameters in snpe-1.61.0.3358/lib/python/qti/aisw/converters/onnx/custom_op_translations.py

{'name': '672', 'allowed_data_types': ['SNPE_UDO_CORETYPE_CPU', 'SNPE_UDO_CORETYPE_DSP'], 'shape': '', 'default_value': None, 'layout': 'SNPE_UDO_LAYOUT_LAST', 'dimensions': [], 'repeated': False, 'static': True, 'rank': 1, 'data_type': 'SNPE_UDO_DATATYPE_UINT_16', 'data': None, 'param_type': 'SNPE_UDO_PARAMTYPE_TENSOR', 'per_core_data_types': None}

UDO:

"type": "expand",
"inputs":[
{
"name":"Input",
"per_core_data_types":{"CPU":"FLOAT_32", "DSP":"UINT_8"},
"static": false, "tensor_layout": "NCHW"
},
{
"name":"shape",
"per_core_data_types":{"CPU":"UINT_16", "DSP":"UINT_8"},
"static": true
}
],
"outputs":[
{
"name":"Output",
"per_core_data_types":{"CPU":"FLOAT_32", "DSP":"UINT_8"}
}
],
"core_types": ["CPU", "DSP"]

 

If we look at the parameters at allowed_data_types': ['SNPE_UDO_CORETYPE_CPU', 'SNPE_UDO_CORETYPE_DSP'], the value of allowed_data_types does not seem correct. 

I traced back to the staticmethod create_per_core_tensor_infos in snpe-1.61.0.3358/lib/python/qti/aisw/converters/backend/custom_ops/core.py I found that the way snpe gets the allowed dtype of tensor is not correct:

- At line 77 of that file, the value of per_core_dict is {'SNPE_UDO_CORETYPE_CPU': 'SNPE_UDO_DATATYPE_FLOAT_32', 'SNPE_UDO_CORETYPE_DSP': 'SNPE_UDO_DATATYPE_UINT_8'}. And just after that, snpe gets tensor_info.allowed_data_types by getting it keys instead of its values. That's why we get ['SNPE_UDO_CORETYPE_CPU', 'SNPE_UDO_CORETYPE_DSP'] as the dtype. That causes the whole problem of dtype verification after.

3. Fix Suggestion

Change line 77 of snpe-1.61.0.3358/lib/python/qti/aisw/converters/backend/custom_ops/core.py from: 

tensor_info.allowed_data_types = list(per_core_dict.keys())

to 

tensor_info.allowed_data_types = [per_core_dict[k] for k in per_core_dict]

 

 

  • Up0
  • Down0

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.