单算子转换之如何书写规范的算子描述文件
收藏回复举报
单算子转换之如何书写规范的算子描述文件
t('forum.solved') 已解决
发表于2024-09-06 12:44:13
0 查看
 

一、问题描述

单算子模型转换样例太少,遇到未提供样例的算子该如何书写规范的描述文件呢?

https://www.hiascend.com/document/detail/zh/canncommercial/80RC2/devaids/auxiliarydevtool/atlasatc_16_0034.html?sub_id=%2Fzh%2Fcanncommercial%2F80RC2%2Fdevaids%2Fauxiliarydevtool%2Fatlasatc_16_0055.html 

(1)Concat算子描述文件该如何规范化书写? 

cke_2853.png

由该图所示,Concat的有两个输入,一个是list of tensor,另一个是记录拼接维度的常数 

而在书写算子描述文件中input_desc这一键值对时,如何构造list of tensor类型的TensorDesc数组?给的样例似乎都是tensor,TensorDesc数组type值的规范未看到符合条件的 

image.png

(2)Reshape算子描述文件该如何规范化书写? 

image.png 

(3)疑问: 

a. 遍历onnx模型中的所有算子,每个单算子对应生成Ascend算子描述文件,并且都能够成功转换和推理,那么该onnx模型是否就能适配到Ascend设备? 

b. 如果遇到未公开书写规范的算子,应该如何准确地书写Ascend算子描述文件呢?只参照Ascend算子描述文档吗?有没有一些自动化的方法? 

二、测试步骤 

(1)将Concat算子“x”输入写成两个TensorDesc数组,则会报输入个数未对齐的错误 

[ 

    { 

        "op": "Concat",  

        "name": "exp_concat",  

        "input_desc": [ 

            { 

                "name": "x", 

                "format": "NCHW",  

                "shape": [1, 32, 160, 160],  

                "type": "float32" 

            },  

            { 

                "name": "x", 

                "format": "NCHW",  

                "shape": [1, 32, 160, 160],  

                "type": "float32" 

            },  

            { 

                "name": "concat_dim", 

                "format": "ND", 

                "is_const": true, 

                "const_value": 1, 

                "shape" : [], 

                "type": "int32" 

            } 

        ],  

        "output_desc": [ 

            { 

                "format": "NCHW",  

                "shape": [1, 64, 160, 160],  

                "type": "float32" 

            } 

        ],  

        "attr": [ 

            { 

                "name": "N",  

                "type": "int",  

                "value": 1 

            } 

        ] 

    } 

]

(2)将一个[1,255,80,80]reshape成[1,3,85,80,80] 

reshape算子描述文件书写如下: 

[ 

    { 

        "op": "Reshape",  

        "input_desc": [ 

        { 

            "format": "NCHW",  

            "shape": [1, 255, 80, 80],  

            "type": "float32" 

        },  

        { 

            "format": "ND",  

            "shape": [5],  

            "type": "int32", 

            "const_value": [1, 3, 85, 80, 80], 

            "is_const": true 

        } 

        ],  

        "output_desc": [ 

        { 

            "format": "NC1HWC0",  

            "shape": [1, 3, 85, 80, 80],  

            "type": "float32" 

        } 

        ], 

        "attr": [ 

        { 

            "name": "axis", 

            "type": "int", 

            "value": 1 

        }, 

        { 

            "name": "num_axes", 

            "type": "int", 

            "value": 1 

        } 

        ] 

    } 

]

三、日志信息 

(1)concat单算子转换报错如下: 

ATC start working now, please wait for a moment. 

... 

ATC run failed, Please check the detail log, Try 'atc --help' for more information 

E14001: 2024-09-06-10:11:42.192.405 Argument [inputs size[2]] for Op [exp_concat, optype [Concat]], is invalid. Reason: tensor size is [3]. 

(2)reshape单算子转换报错如下: 

ATC start working now, please wait for a moment. 

... 

ATC run failed, Please check the detail log, Try 'atc --help' for more information 

EZ9999: Inner Error! 

EZ9999: 2024-09-06-10:26:44.852.873  Call InferShapeAndType for node:Reshape(Reshape) failed[FUNC:Infer][FILE:infershape_pass.cc][LINE:113] 

        TraceBack (most recent call last): 

        process pass InferShapePass on node:Reshape failed, ret:4294967295[FUNC:RunPassesOnNode][FILE:base_pass.cc][LINE:563] 

        build graph failed, graph id:0, ret:1343242270[FUNC:BuildModelWithGraphId][FILE:ge_generator.cc][LINE:1608] 

我要发帖子