PaddlePaddle / X2Paddle

Deep learning model converter for PaddlePaddle. (『飞桨』深度学习模型转换工具)
http://www.paddlepaddle.org/
Apache License 2.0
727 stars 164 forks source link

pytorch->onnx->paddle出错 #943

Open smallsung1999 opened 1 year ago

smallsung1999 commented 1 year ago

感谢您参与 X2Paddle 社区! 问题模版为了 X2Paddle 能更好的迭代,例如新功能发布、 RoadMaps 和错误跟踪. :smile_cat:

问题描述

具体信息

pytorch模型转换至onnx成功,但onnx转换为paddle时,生成x2paddle_code.py后转换失败。 image image image

下面是对错误信息的推测: 模型conv前对数据进行了cast操作,将float32数据转换为float16再输入conv,而conv中的w与b均为float16,如何在x2paddle_code.py定义模型结构时指定conv的dtype为float16? 如有更好的解决办法,欢迎大佬指正。 image image

smallsung1999 commented 1 year ago

model.zip 模型相关文件

smallsung1999 commented 1 year ago

torch.onnx.export导出模型时设置do_constant_folding=False,关闭amp,w和b保存为float32

smallsung1999 commented 1 year ago

In transformed code:

File "H:\ast\pd_model\x2paddle_code.py", line 690, in forward
    x2paddle__blocks_0_attn_Gather_1_output_0 = paddle.gather(x=x2paddle__blocks_0_attn_Transpose_output_0, index=x2paddle__blocks_0_attn_Constant_5_output_0, axis=0)
    x2paddle__blocks_0_attn_Gather_2_output_0 = paddle.gather(x=x2paddle__blocks_0_attn_Transpose_output_0, index=x2paddle__blocks_0_attn_Constant_6_output_0, axis=0)
    x2paddle__blocks_0_attn_Transpose_1_output_0 = paddle.transpose(x=x2paddle__blocks_0_attn_Gather_1_output_0, perm=[0, 1, 3, 2])   
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    x2paddle__blocks_0_attn_MatMul_output_0 = paddle.matmul(x=x2paddle__blocks_0_attn_Gather_output_0, y=x2paddle__blocks_0_attn_Transpose_1_output_0)
    x2paddle__blocks_0_attn_Mul_output_0 = paddle.multiply(x=x2paddle__blocks_0_attn_MatMul_output_0, y=x2paddle__blocks_0_attn_Constant_7_output_0)

File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\paddle\tensor\linalg.py", line 123, in transpose
    raise ValueError(

ValueError: Input(perm) is the permutation of dimensions of Input(x), its length should be equal to dimensions of Input(x), but received dimension of Input(x) is 5, the length of Input(perm) is 4.

model.zip x2paddle_code.zip