PaddleNLP icon indicating copy to clipboard operation
PaddleNLP copied to clipboard

[Bug]: 文本分类离线部署使用fp16加速报错

Open FFinchR opened this issue 2 years ago • 4 comments

软件环境

- paddle-bfloat         0.1.7          
- paddle2onnx           1.0.1          
- paddlefsl             1.1.0          
- paddlenlp             2.4.1          
- paddleocr             2.6.0.1        
- paddlepaddle-gpu      2.4.0rc0

重复问题

  • [X] I have searched the existing issues

错误描述

文本分类离线部署使用fp16加速报错

稳定复现步骤 & 代码

尝试按照multi_class使用fp16加速进行文本分类预训练模型微调的离线部署时(不使用fp16加速时可正常部署,且我在使用uie时,fp16加速也可正常部署),遇到了这个报错: 指令: python infer.py --device "gpu" --model_path_prefix "../../export/float32" --model_name_or_path "ernie-3.0-medium-zh" --max_seq_length 128 --batch_size 32 --dataset_dir "../../data" --use_fp16 报错如下:

Traceback (most recent call last):
  File "infer.py", line 62, in <module>
    predictor = Predictor(args, label_list)
  File "/opt/paddleocr/applications/text_classification/multi_class/deploy/predictor/predictor.py", line 127, in __init__
    args.num_threads)
  File "/opt/paddleocr/applications/text_classification/multi_class/deploy/predictor/predictor.py", line 76, in __init__
    'device_id': device_id
  File "/usr/local/lib/python3.7/dist-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 347, in __init__
    self._create_inference_session(providers, provider_options, disabled_optimizers)
  File "/usr/local/lib/python3.7/dist-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 384, in _create_inference_session
    sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from ../../export/fp16_model.onnx failed:Node (p2o.Squeeze.0) Op (Squeeze) [ShapeInferenceError] Dimension of input 1 must be 1 instead of 0

FFinchR avatar Oct 19 '22 09:10 FFinchR

能提供一下onnxconverter-common的版本吗?

wawltor avatar Oct 19 '22 09:10 wawltor

能提供一下onnxconverter-common的版本吗?

onnxconverter-common 1.12.2

FFinchR avatar Oct 19 '22 09:10 FFinchR

这个问题应该是某个onnxconverter-common的infer bug,你可以把导出的onnx的模型进行转化一下,并进行替换

你可以根据下面的下面转化一下

import onnx
fp16_model = onnx.load('fp16_model.onnx')

fp16_model.graph.value_info[990].type.tensor_type.shape.dim[1].dim_value=1

onnx.save(fp16_model, "new_fp16_model.onnx")

同时我们排查一下具体哪个onnxconverter-common版本可用

wawltor avatar Oct 19 '22 10:10 wawltor

这个问题应该是某个onnxconverter-common的infer bug,你可以把导出的onnx的模型进行转化一下,并进行替换

你可以根据下面的下面转化一下

import onnx
fp16_model = onnx.load('fp16_model.onnx')

fp16_model.graph.value_info[990].type.tensor_type.shape.dim[1].dim_value=1

onnx.save(fp16_model, "new_fp16_model.onnx")

同时我们排查一下具体哪个onnxconverter-common版本可用

好的,感谢。

FFinchR avatar Oct 19 '22 10:10 FFinchR

推荐使用onnxconverter-common版本1.9.0

lugimzzz avatar Nov 15 '22 07:11 lugimzzz

已解决

lugimzzz avatar Nov 18 '22 02:11 lugimzzz