Skip to content

Can't convert local timm models #2423

@antonkharkhonov

Description

@antonkharkhonov

System Info

optimum==2.1.0
optimum-onnx==0.1.0
Python 3.12.7
MacOS 26.3.1

Who can help?

@echarlaix @IlyasMoutawwakil I'm tagging you because I ran into this issue while trying to convert to ONNX format

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)

Link to my dataset https://storage.googleapis.com/models-backend-artifacts/models/furnished-classifier.zip
But should reproduce with any other timm image classification fine tuned models.
To get an error enough to use script from official documentation:

!optimum-cli export onnx --model furnished-classifier --task image-classification onnx_furnished_classifier

Error:

Traceback (most recent call last):
  File "/Users/antonkharkhonov/projects/ss/ai/propvision/custom-models/runpod-app/.venv/bin/optimum-cli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/antonkharkhonov/projects/ss/ai/propvision/custom-models/runpod-app/.venv/lib/python3.12/site-packages/optimum/commands/optimum_cli.py", line 219, in main
    service.run()
  File "/Users/antonkharkhonov/projects/ss/ai/propvision/custom-models/runpod-app/.venv/lib/python3.12/site-packages/optimum/commands/export/onnx.py", line 264, in run
    main_export(
  File "/Users/antonkharkhonov/projects/ss/ai/propvision/custom-models/runpod-app/.venv/lib/python3.12/site-packages/optimum/exporters/onnx/__main__.py", line 325, in main_export
    model = TasksManager.get_model_from_task(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/antonkharkhonov/projects/ss/ai/propvision/custom-models/runpod-app/.venv/lib/python3.12/site-packages/optimum/exporters/tasks.py", line 1175, in get_model_from_task
    model = model_class(f"hf_hub:{model_name_or_path}", pretrained=True, exportable=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/antonkharkhonov/projects/ss/ai/propvision/custom-models/runpod-app/.venv/lib/python3.12/site-packages/timm/models/_factory.py", line 114, in create_model
    pretrained_cfg, model_name, model_args = load_model_config_from_hf(
...
Repository Not Found for url: https://huggingface.co/furnished-classifier/resolve/main/config.json.
Please make sure you specified the correct `repo_id` and `repo_type`.
If you are trying to access a private or gated repo, make sure you are authenticated. For more details, see https://huggingface.co/docs/huggingface_hub/authentication
Invalid username or password.

From what I found manually in optimum code, only remote model loading is allowed intentionally for timm models:
https://github.com/huggingface/optimum/blob/main/optimum/exporters/tasks.py#L1177

Expected behavior

Successful conversion of the model to ONNX format

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