From b0dc0de8325ee9686900d904c62bb5f36626f3ed Mon Sep 17 00:00:00 2001 From: yuwenzho Date: Sun, 10 Mar 2024 01:37:54 -0800 Subject: [PATCH] Fix onnxrt example bug: bart export failure (#1658) Signed-off-by: yuwenzho --- .../quantization/ptq_dynamic/prepare_model.py | 9 ++++++--- .../quantization/ptq_dynamic/requirements.txt | 3 ++- .../quantization/ptq_static/prepare_model.py | 9 ++++++--- .../quantization/ptq_static/requirements.txt | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/prepare_model.py b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/prepare_model.py index d020e8aecb6..be05479d9e3 100644 --- a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/prepare_model.py +++ b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/prepare_model.py @@ -88,7 +88,10 @@ def export_onnx_model(args, model): config=AutoConfig.from_pretrained(args.input_model)) if args.input_model == 'Intel/bart-large-mrpc': - import os - os.system('python -m transformers.onnx --model=Intel/bart-large-mrpc --feature=sequence-classification --export_with_transformers bart-large-mrpc/') + import shutil + from optimum.exporters.onnx import main_export + + main_export(args.input_model, output="bart-large-mrpc", task="text-classification") + shutil.move("bart-large-mrpc/model.onnx", args.output_model) else: - export_onnx_model(args, model) \ No newline at end of file + export_onnx_model(args, model) diff --git a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/requirements.txt b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/requirements.txt index 416ff1b96e0..9988cdf0329 100644 --- a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/requirements.txt +++ b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_dynamic/requirements.txt @@ -8,4 +8,5 @@ sympy onnxruntime-extensions; python_version < '3.11' numpy==1.23.5 sentencepiece -protobuf<=3.20.3 \ No newline at end of file +protobuf<=3.20.3 +optimum diff --git a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/prepare_model.py b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/prepare_model.py index 6d8d774887b..a8272021d5a 100644 --- a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/prepare_model.py +++ b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/prepare_model.py @@ -87,7 +87,10 @@ def export_onnx_model(args, model): config=AutoConfig.from_pretrained(args.input_model)) if args.input_model == 'Intel/bart-large-mrpc': - import os - os.system('python -m transformers.onnx --model=Intel/bart-large-mrpc --feature=sequence-classification --export_with_transformers bart-large-mrpc/') + import shutil + from optimum.exporters.onnx import main_export + + main_export(args.input_model, output="bart-large-mrpc", task="text-classification") + shutil.move("bart-large-mrpc/model.onnx", args.output_model) else: - export_onnx_model(args, model) \ No newline at end of file + export_onnx_model(args, model) diff --git a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/requirements.txt b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/requirements.txt index bc078ee513b..9988cdf0329 100644 --- a/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/requirements.txt +++ b/examples/onnxrt/nlp/huggingface_model/text_classification/quantization/ptq_static/requirements.txt @@ -9,4 +9,4 @@ onnxruntime-extensions; python_version < '3.11' numpy==1.23.5 sentencepiece protobuf<=3.20.3 -optimum[exporters] \ No newline at end of file +optimum