登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
登录
注册
就在本周六,成都站 Gitee Talk | 模力方舟 AI 应用开发沙龙抢占最后席位!聚焦 AI 开发全链路,结识技术同频人~
代码拉取完成,页面将自动刷新
开源项目
>
人工智能
>
AI-人工智能
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
217
Star
1.2K
Fork
1.1K
Ascend
/
samples
代码
Issues
49
Pull Requests
95
Wiki
统计
流水线
服务
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
om模型在推理时出现报错和精度很差的问题
DONE
#I9O7QS
推理问题
Nolan0206
创建于
2024-05-10 16:28
一、问题现象(附报错日志上下文): ### 前景提要: 将段落分割的bert模型转换成onnx模型,并已经验证其推理正常。 ### 问题一: 使用atc工具从onnx转成om模型时,使用了两种方式,开始使用动态shape的方式进行转换。 转换命令为: `atc --input_format=ND --framework=5 --model=./onnx/model.onnx --input_shape='input_ids:1~10,512;attention_mask:1~10,512;token_type_ids:1~10,512' --output=bert_base_1 --log=info --soc_version=Ascend310P3 --precision_mode=allow_fp32_to_fp16 --op_select_implmode=high_precision` 在转换过程中出现警告:  进行推理时动态shape没有生效。 ### 问题二: 转换成om静态模型,转换成功,且可以进行推理,但结果准确性很差,实现不了任何分段效果。 转换命令: `atc --framework=5 --input_format=ND --model=./onnx/model.onnx --input_shape='input_ids:1,512;attention_mask:1,512;token_type_ids:1,512' --output=bert_base_static_nd --log=info --soc_version=Ascend310P3 --precision_mode=allow_fp32_to_fp16` **推理过程正常,但输出的结果完全不正确。**   ### 已尝试的调试工作: 参照https://gitee.com/ascend/samples/issues/I83OOL这个已解决的问题,使用命令将onnx模型的输入shape固定下来后转om,但效果没有变好,没有任何作用。 转换命令: `ONNXSIM_FIXED_POINT_ITERS=100 onnxsim model.onnx model_bert_sim.onnx --overwrite-input-shape 'input_ids:1,512' 'attention_mask:1,512' 'token_type_ids:1,512'` `atc --framework=5 --input_format=ND --model=./onnx/model_bert_sim.onnx --input_shape='input_ids:1,512;attention_mask:1,512;token_type_ids:1,512' --output=bert_base_static_hc --log=info --soc_version=Ascend310P3 --precision_mode=allow_fp32_to_fp16` 尝试使用ait命令进行分析,结果如下,详细结果在附件中。 ait命令: `ait debug compare -gm ./onnx/model.onnx -om ./bert_base_static_nd2.om -c /usr/local/Ascend/ascend-toolkit/latest -o /home/test -is 'input_ids:1,512;attention_mask:1,512;token_type_ids:1,512'`  ### 软件版本: -- CANN 版本 (CANN 8.0.RC2.alpha001): --Python 版本 (Python 3.8.10): --操作系统版本 (Ubuntu 20.04): ### 用于推理的部分代码: `# print(f"predict_dataset : {predict_dataset}") # # {'input_ids': [[n,n,...]],'token_type_ids': [[0,0,...]],'attention_mask': [[1,1,...,0,0]]}` ``` from ais_bench.infer.interface import InferSession class OmInferencer: def __init__(self, om_path, device_id=0): super(OmInferencer, self).__init__() self.session = InferSession(device_id=device_id, model_path=om_path) def model_inference(self, model_input): input_ids = model_input["input_ids"] token_type_ids = model_input["token_type_ids"] attention_mask = model_input["attention_mask"] input_ids = np.array(input_ids) token_type_ids = np.array(token_type_ids) attention_mask = np.array(attention_mask) model_output = self.session.infer(feeds=[input_ids, token_type_ids, attention_mask])[0] print(model_output) return model_output vpr_inferencer = OmInferencer('/home/bert_base_static_nd4.om') predictions = vpr_inferencer.model_inference(predict_dataset) ``` ### 附件: 推理代码、onnx模型、问题图片、分析结果均在网盘上:链接:https://pan.baidu.com/s/117dBN_z0Uwdgxv1G9WFYNw?pwd=luz9 提取码:luz9
一、问题现象(附报错日志上下文): ### 前景提要: 将段落分割的bert模型转换成onnx模型,并已经验证其推理正常。 ### 问题一: 使用atc工具从onnx转成om模型时,使用了两种方式,开始使用动态shape的方式进行转换。 转换命令为: `atc --input_format=ND --framework=5 --model=./onnx/model.onnx --input_shape='input_ids:1~10,512;attention_mask:1~10,512;token_type_ids:1~10,512' --output=bert_base_1 --log=info --soc_version=Ascend310P3 --precision_mode=allow_fp32_to_fp16 --op_select_implmode=high_precision` 在转换过程中出现警告:  进行推理时动态shape没有生效。 ### 问题二: 转换成om静态模型,转换成功,且可以进行推理,但结果准确性很差,实现不了任何分段效果。 转换命令: `atc --framework=5 --input_format=ND --model=./onnx/model.onnx --input_shape='input_ids:1,512;attention_mask:1,512;token_type_ids:1,512' --output=bert_base_static_nd --log=info --soc_version=Ascend310P3 --precision_mode=allow_fp32_to_fp16` **推理过程正常,但输出的结果完全不正确。**   ### 已尝试的调试工作: 参照https://gitee.com/ascend/samples/issues/I83OOL这个已解决的问题,使用命令将onnx模型的输入shape固定下来后转om,但效果没有变好,没有任何作用。 转换命令: `ONNXSIM_FIXED_POINT_ITERS=100 onnxsim model.onnx model_bert_sim.onnx --overwrite-input-shape 'input_ids:1,512' 'attention_mask:1,512' 'token_type_ids:1,512'` `atc --framework=5 --input_format=ND --model=./onnx/model_bert_sim.onnx --input_shape='input_ids:1,512;attention_mask:1,512;token_type_ids:1,512' --output=bert_base_static_hc --log=info --soc_version=Ascend310P3 --precision_mode=allow_fp32_to_fp16` 尝试使用ait命令进行分析,结果如下,详细结果在附件中。 ait命令: `ait debug compare -gm ./onnx/model.onnx -om ./bert_base_static_nd2.om -c /usr/local/Ascend/ascend-toolkit/latest -o /home/test -is 'input_ids:1,512;attention_mask:1,512;token_type_ids:1,512'`  ### 软件版本: -- CANN 版本 (CANN 8.0.RC2.alpha001): --Python 版本 (Python 3.8.10): --操作系统版本 (Ubuntu 20.04): ### 用于推理的部分代码: `# print(f"predict_dataset : {predict_dataset}") # # {'input_ids': [[n,n,...]],'token_type_ids': [[0,0,...]],'attention_mask': [[1,1,...,0,0]]}` ``` from ais_bench.infer.interface import InferSession class OmInferencer: def __init__(self, om_path, device_id=0): super(OmInferencer, self).__init__() self.session = InferSession(device_id=device_id, model_path=om_path) def model_inference(self, model_input): input_ids = model_input["input_ids"] token_type_ids = model_input["token_type_ids"] attention_mask = model_input["attention_mask"] input_ids = np.array(input_ids) token_type_ids = np.array(token_type_ids) attention_mask = np.array(attention_mask) model_output = self.session.infer(feeds=[input_ids, token_type_ids, attention_mask])[0] print(model_output) return model_output vpr_inferencer = OmInferencer('/home/bert_base_static_nd4.om') predictions = vpr_inferencer.model_inference(predict_dataset) ``` ### 附件: 推理代码、onnx模型、问题图片、分析结果均在网盘上:链接:https://pan.baidu.com/s/117dBN_z0Uwdgxv1G9WFYNw?pwd=luz9 提取码:luz9
评论 (
16
)
登录
后才可以发表评论
状态
DONE
TODO
WIP
Analysing
Feedback
ACCEPTED
DONE
CLOSED
Replied
REJECTED
负责人
未设置
Liuboyu
liuboyuHappy
负责人
协作者
+负责人
+协作者
标签
未设置
项目
未立项任务
未立项任务
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (18)
标签 (28)
master
r1.9
r1.8
r1.7
r1.5
r1.6
pr_2663
add_lut4_llama7b_quantization
r1.4
r1.3
r1.1
r1.2
r1.21.0
r0.2
r1.0
r0.3
8.0.RC3_bugfix
r.ss928.1
v1.8-8.3.RC1.alpha002
v1.7-8.3.RC1.alpha001
v1.5-8.2.RC1
v1.6-8.2.RC1.alpha003
v1.4-8.2.RC1.alpha002
v1.3-8.2.RC1.alpha001
v1.1-8.1.RC1.beta1
v1.2-8.1.RC1.alpha002
v1.0-8.1.RC1.alpha001
v0.2-8.0.0.beta1
v0.3-8.0.0.alpha003
8.0.RC3
v0.1-8.0.0.alpha002
8.0.RC2.2
8.0.RC2
8.0.RC1
7.0.0
7.0.RC1
6.3.RC2
v0.9.0
v0.8.0
v0.7.0
v0.6.0
v0.1.0
v0.2.0
v0.3.0
v0.4.0
v0.5.0
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(1)
1
https://gitee.com/ascend/samples.git
git@gitee.com:ascend/samples.git
ascend
samples
samples
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册