【ATC转换模型onnx->om】torch.onnx.export 错误码E19010 No parser is registered for Op
收藏回复举报
【ATC转换模型onnx->om】torch.onnx.export 错误码E19010 No parser is registered for Op
t('forum.solved') 已解决
发表于2024-11-21 21:38:09
0 查看

我看到别人在model.py导出自定义的TddBatchMatMulV2Add算子模型tdd_batchmatmulv2_add.onnx后,再用命令

atc --model=tdd_batchmatmulv2_add.onnx --framework=5 --output=tdd_batchmatmulv2_add --soc_version=Ascend310P3将模型转为om模型能正确处理

但是我看到算子实现的源码tdd_batchmatmulv2_add.py中,@register_operator("TddBatchMatmulV2Add")的算子名称中mul明明是小写字母,为什么这里要使用大写字母呢?

import torch 

import numpy as np 

 

class TddBatchMatMulV2Add(torch.autograd.Function): 

    @staticmethod 

    def forward(ctx, x, weight, bias, y): 

        z = torch.zeros_like(x) 

        return z 

 

    @staticmethod 

    def symbolic(g, x, weight, bias, y): 

        return g.op('TddBatchMatMulV2Add', x, weight, bias, y, outputs=1) 

 

class Model(torch.nn.Module): 

    def __init__(self): 

        super().__init__() 

 

    def forward(self, x, weight, bias, y): 

        z = TddBatchMatMulV2Add.apply(x, weight, bias, y) 

        return z 

 

def export(): 

    models = Model() 

    x = torch.from_numpy(np.load("./x_nd.npy")) 

    bias = torch.from_numpy(np.load("./bias_nd.npy")) 

    weight = torch.from_numpy(np.load("./weight_nd.npy")) 

    y = torch.from_numpy(np.load("./y_nd.npy")) 

 

    models.eval() 

    torch.onnx.export( 

        models, 

        (x, weight, bias, y), 

        "tdd_batchmatmulv2_add.onnx", 

        opset_version=11, 

        export_params=False, 

        verbose=False, 

        input_names=["x", "weight", "bias", "y"], 

        output_names=["z"], 

    ) 

 

if __name__ == "__main__": 

    export() 

对应的算子实现的代码片段 tdd_batchmatmulv2_add.py ,其中mul是小写字母:

...

@register_operator("TddBatchMatmulV2Add") 

@para_check.check_op_params(para_check.REQUIRED_INPUT, para_check.REQUIRED_INPUT, para_check.REQUIRED_INPUT, 

                            para_check.REQUIRED_INPUT, 

                            para_check.REQUIRED_OUTPUT, 

                            para_check.KERNEL_NAME) 

def tdd_batchmatmulv2_add(input_x, input_weight, input_bias, input_y, output_z, 

                          kernel_name="tdd_batchmatmulv2_add"): 

    m_0, k_0, n_0 = 16, 16, 16 

    batch_num, k_1, m_1 = input_x.get("shape")[:3] 

    n_1 = input_weight.get("shape")[0] 

    dtype = input_x.get("dtype") 

    obj = BatchMatmulV2Add(batch_num, m_0, m_1, k_0, k_1, n_0, n_1, dtype, kernel_name) 

    obj.start_compute()

我要发帖子