一、问题现象:
使用bert-base-chinese进行微调(微调时固定了max_len=512)得到.pt,使用pt转onnx可以转成功,且可以通过np.testing.assert_allclose(torch_out, ort_outs[0], rtol=1e-01, atol=1e-5)精度测试。
但后续使用onnx转换后的om进行离线推理发现精度相差很大。
① 原始.pt文件的推理结果

② onnx文件的推理结果

③ om文件的推理结果

二、软件版本:
-- CANN 版本 (CANN 7.0.RC1):
--Python 版本 (Python 3.9.2):
--操作系统版本 (Ubuntu 22.04.3 LTS)
--Atlas产品型号 (Atlas 200I A2)
--npu芯片型号 (Ascend310B4)
三、测试步骤:
1.将pt模型转onnx
-- 转换时, input_data使用的是固定shape, 其中max_len=512 batch_size=1。
-- token_type_id在本次微调中不用手动传,所以input_names只包含“input_ids、attention_mask”。
2.将onnx转成om 指令:
-- 微调时的shape(input_ids)=(max_len,batch_size),shape(attention_mask)=(batch_size, max_len)
-- 指令:
atc --model=/root/first_app/invoice/model/invoice_ner.onnx --framework=5 --precision_mode=allow_fp32_to_fp16 --output=/root/first_app/invoice/model --input_shape="input_ids:512,1;attention_mask:1,512" --input_format=ND --log=debug --soc_version=Ascend310B4 --optypelist_for_implmode="Gelu" --op_select_implmode=high_performance
3.使用msquickcmp对比onnx和om,指令如下:
python3 main.py -m /root/first_app/invoice/model/invoice_ner.onnx -om /root/first_app/invoice/model/invoice_ner.om -o /root/first_app/invoice/result/test -s "input_ids:512,1;attention_mask:1,512"
4.onnx模型 和 msquickcmp比较结果 的链接
链接:https://pan.baidu.com/s/1Gj0laHU8g7bYhMqq3Z4s5A
提取码:jx2t
一、问题现象:



使用bert-base-chinese进行微调(微调时固定了max_len=512)得到.pt,使用pt转onnx可以转成功,且可以通过np.testing.assert_allclose(torch_out, ort_outs[0], rtol=1e-01, atol=1e-5)精度测试。
但后续使用onnx转换后的om进行离线推理发现精度相差很大。
① 原始.pt文件的推理结果
② onnx文件的推理结果
③ om文件的推理结果
二、软件版本:
-- CANN 版本 (CANN 7.0.RC1):
--Python 版本 (Python 3.9.2):
--操作系统版本 (Ubuntu 22.04.3 LTS)
--Atlas产品型号 (Atlas 200I A2)
--npu芯片型号 (Ascend310B4)
三、测试步骤:
1.将pt模型转onnx
-- 转换时, input_data使用的是固定shape, 其中max_len=512 batch_size=1。
-- token_type_id在本次微调中不用手动传,所以input_names只包含“input_ids、attention_mask”。
2.将onnx转成om 指令:
-- 微调时的shape(input_ids)=(max_len,batch_size),shape(attention_mask)=(batch_size, max_len)
-- 指令:
atc --model=/root/first_app/invoice/model/invoice_ner.onnx --framework=5 --precision_mode=allow_fp32_to_fp16 --output=/root/first_app/invoice/model --input_shape="input_ids:512,1;attention_mask:1,512" --input_format=ND --log=debug --soc_version=Ascend310B4 --optypelist_for_implmode="Gelu" --op_select_implmode=high_performance
3.使用msquickcmp对比onnx和om,指令如下:
python3 main.py -m /root/first_app/invoice/model/invoice_ner.onnx -om /root/first_app/invoice/model/invoice_ner.om -o /root/first_app/invoice/result/test -s "input_ids:512,1;attention_mask:1,512"
4.onnx模型 和 msquickcmp比较结果 的链接
链接:https://pan.baidu.com/s/1Gj0laHU8g7bYhMqq3Z4s5A
提取码:jx2t