fix(exporters/tasks): support local timm model paths in ONNX export#2424
Open
Anai-Guo wants to merge 1 commit intohuggingface:mainfrom
Open
fix(exporters/tasks): support local timm model paths in ONNX export#2424Anai-Guo wants to merge 1 commit intohuggingface:mainfrom
Anai-Guo wants to merge 1 commit intohuggingface:mainfrom
Conversation
Previously, `get_model_from_task` always prepended `hf_hub:` when loading timm models, forcing them to be fetched from HF Hub even when a local directory was provided. This caused a `Repository Not Found` error for locally fine-tuned timm models. Fix: check if `model_name_or_path` is an existing local directory. If so, pass it directly to `create_model`; otherwise use the `hf_hub:` prefix for Hub models. Fixes huggingface#2423
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When exporting locally fine-tuned timm models to ONNX, the export fails with:
Root cause:
get_model_from_taskunconditionally prependshf_hub:to the model path when loading timm models (line 1177 inoptimum/exporters/tasks.py):This forces timm's
create_modelto treat the path as an HF Hub model ID, breaking local directory paths.Fix
Check if
model_name_or_pathis a local directory. If so, pass it directly tocreate_model; otherwise use thehf_hub:prefix for Hub models.Testing
Fixes #2423