Skip to content

I follow the Documentation and I still can't fully export an ASR model to ONNX :( #2434

@i-just-wanna-do-things

Description

@i-just-wanna-do-things

System Info

Python 3.13.13
optimum 2.1.0
Miniconda3 version 26.1.1
Windows 10 Pro x64
Intel Core i5-13600K

Who can help?

@echarlaix, @IlyasMoutawwakil

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction (minimal, reproducible, runnable)

  1. I create a blank Conda environment with Python 3.13
  2. Per https://huggingface.co/docs/optimum-onnx/installation I install optimum
  3. Per https://huggingface.co/docs/optimum-onnx/onnx/usage_guides/export_a_model I run this command: optimum-cli export onnx --model openai/whisper-large-v3 ./whisperv3/

The following ensures after running this exact command:

<Env_Path_Here>\Lib\site-packages\transformers\models\whisper\modeling_whisper.py:669: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
    if input_features.shape[-1] != expected_seq_length:
<Env_Path_Here>\Lib\site-packages\transformers\integrations\sdpa_attention.py:81: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
    is_causal = query.shape[2] > 1 and attention_mask is None and getattr(module, "is_causal", True)

...and finally...

Traceback (most recent call last):
  File "<Env_Path_Here>\Lib\site-packages\optimum\exporters\onnx\convert.py", line 1119, in onnx_export_from_model
    models_and_onnx_configs, onnx_files_subpaths = onnx_config.post_process_exported_models(
                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        output, models_and_onnx_configs, onnx_files_subpaths
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "<Env_Path_Here>\Lib\site-packages\optimum\exporters\onnx\base.py", line 768, in post_process_exported_models
    models_and_onnx_configs, onnx_files_subpaths = super().post_process_exported_models(
                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        path, models_and_onnx_configs, onnx_files_subpaths
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "<Env_Path_Here>\Lib\site-packages\optimum\exporters\onnx\base.py", line 410, in post_process_exported_models
    remove_duplicate_weights_from_tied_info(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        onnx_model, torch_model, tied_params, save_path=os.path.join(path, subpath)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "<Env_Path_Here>\Lib\site-packages\optimum\onnx\graph_transformations.py", line 98, in remove_duplicate_weights_from_tied_info
    check_and_save_model(onnx_model, save_path=save_path)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<Env_Path_Here>\Lib\site-packages\optimum\onnx\graph_transformations.py", line 137, in check_and_save_model
    if model.ByteSize() < onnx.checker.MAXIMUM_PROTOBUF:
       ~~~~~~~~~~~~~~^^
google.protobuf.message.EncodeError: Failed to serialize proto

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "<Env_Path_Here>\Scripts\optimum-cli.exe\__main__.py", line 5, in <module>
    sys.exit(main())
             ~~~~^^
  File "<Env_Path_Here>\Lib\site-packages\optimum\commands\optimum_cli.py", line 219, in main
    service.run()
    ~~~~~~~~~~~^^
  File "<Env_Path_Here>\Lib\site-packages\optimum\commands\export\onnx.py", line 264, in run
    main_export(
    ~~~~~~~~~~~^
        model_name_or_path=self.args.model,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<20 lines>...
        **input_shapes,
        ^^^^^^^^^^^^^^^
    )
    ^
  File "<Env_Path_Here>\Lib\site-packages\optimum\exporters\onnx\__main__.py", line 399, in main_export
    onnx_export_from_model(
    ~~~~~~~~~~~~~~~~~~~~~~^
        model=model,
        ^^^^^^^^^^^^
    ...<18 lines>...
        **kwargs_shapes,
        ^^^^^^^^^^^^^^^^
    )
    ^
  File "<Env_Path_Here>\Lib\site-packages\optimum\exporters\onnx\convert.py", line 1123, in onnx_export_from_model
    raise RuntimeError(
        "The post-processing of the ONNX export failed. The export can still be performed by passing the option --no-post-process"
    ) from e
RuntimeError: The post-processing of the ONNX export failed. The export can still be performed by passing the option --no-post-process

I have had this happen on a different Conda environment running Python 3.14, tackling a different model (the distilled version of Whisper) albeit it was on the same PC. That export had also failed.
I just wanted to pack a model into ONNX so I can use it locally :(

Expected behavior

Some occasional warnings appear here and there, but ultimately the model should be successfully exported to ONNX format, without post-processing failing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions