Fix estimate-memory for timm>=1.0.29 by adding the hf-hub: prefix - #4213
Open
iamsharduld wants to merge 2 commits into
Open
Fix estimate-memory for timm>=1.0.29 by adding the hf-hub: prefix#4213iamsharduld wants to merge 2 commits into
estimate-memory for timm>=1.0.29 by adding the hf-hub: prefix#4213iamsharduld wants to merge 2 commits into
Conversation
timm 1.0.29 no longer accepts a Hub repo id without a source prefix, so `accelerate estimate-memory timm/resnet50.a1_in1k --library_name timm` fails with "Model name ... has no source prefix". Older timm versions dropped the repo owner and looked the rest up in the registry, which is why this used to work. I now add the hf-hub: prefix before calling timm.create_model when the name looks like a repo id. Bare architecture names like resnet50 are left alone. With the prefix, timm reads config.json from the Hub and raises its own errors when the file is missing or belongs to another library. I map those to the existing "Tried to load ... with timm but ..." message so the user sees the same error as before. Tested with timm 1.0.28 and 1.0.29. Added unit tests for the prefix rule and the error mapping, plus one end-to-end test for a non-timm repo.
SunMarc
reviewed
Sep 4, 2026
SunMarc
left a comment
Member
There was a problem hiding this comment.
Thanks, just a couple of nits. Also, does this still works with older version of timm ?
Comment on lines
+578
to
+585
| @require_timm | ||
| def test_check_has_model_timm(self): | ||
| # Unknown architecture in the `timm` registry | ||
| assert check_has_model(RuntimeError("Unknown model (dummy)")) == "timm" | ||
| # Hub repo without a `timm` `config.json`, raised by `timm.create_model("hf-hub:...")` | ||
| assert check_has_model(EntryNotFoundError("Entry Not Found for url: .../config.json.")) == "timm" | ||
| # Hub repo whose `config.json` belongs to another library, raised by `timm.create_model("hf-hub:...")` | ||
| assert check_has_model(KeyError("architecture")) == "timm" |
Member
There was a problem hiding this comment.
Suggested change
| @require_timm | |
| def test_check_has_model_timm(self): | |
| # Unknown architecture in the `timm` registry | |
| assert check_has_model(RuntimeError("Unknown model (dummy)")) == "timm" | |
| # Hub repo without a `timm` `config.json`, raised by `timm.create_model("hf-hub:...")` | |
| assert check_has_model(EntryNotFoundError("Entry Not Found for url: .../config.json.")) == "timm" | |
| # Hub repo whose `config.json` belongs to another library, raised by `timm.create_model("hf-hub:...")` | |
| assert check_has_model(KeyError("architecture")) == "timm" |
Comment on lines
+55
to
+56
| # `timm.create_model("hf-hub:...")` reads `config.json` from the Hub without wrapping the errors: a missing file | ||
| # raises `EntryNotFoundError` and a `config.json` from another library has no `architecture` key (`KeyError`) |
Member
There was a problem hiding this comment.
Suggested change
| # `timm.create_model("hf-hub:...")` reads `config.json` from the Hub without wrapping the errors: a missing file | |
| # raises `EntryNotFoundError` and a `config.json` from another library has no `architecture` key (`KeyError`) |
Comment on lines
+75
to
+81
| Adds the `hf-hub:` source prefix that `timm.create_model` needs to load `model_name` from the Hub. Bare | ||
| architecture names from the `timm` registry (such as `resnet50`) are returned unchanged. So are names that already | ||
| carry a source prefix (such as `hf-hub:timm/resnet50.a1_in1k`), which only direct callers can pass: `verify_on_hub` | ||
| in `create_empty_model` rejects them before this function runs. | ||
|
|
||
| `timm>=1.0.29` refuses a Hub repo id without the prefix. Earlier versions dropped the repo owner and resolved the | ||
| rest of the name through the registry. |
Drop the check_has_model unit test, remove the comment above the timm branch in check_has_model, and shorten the add_timm_hub_prefix docstring, as suggested in review.
Author
|
Applied all three suggestions: dropped the unit test and the comment, and shortened the docstring. On older timm versions: yes, it still works. The hf-hub: prefix has been accepted since timm 0.6 (the hf_hub: spelling even earlier), and I ran the estimator tests with timm 1.0.28 as well as 1.0.29 after this change. |
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.
What does this PR do?
accelerate estimate-memory timm/resnet50.a1_in1k --library_name timmfails with timm 1.0.29:Since huggingface/pytorch-image-models#2727 (shipped in timm 1.0.29), timm needs a source prefix for anything that looks like a repo id. Older versions dropped the repo owner and looked the rest up in the registry, which only worked because timm names its Hub repos after the architecture. The two timm tests in tests/test_cli.py fail on main because of this, see https://github.com/huggingface/accelerate/actions/runs/33763859075/job/100676635381.
I now add the hf-hub: prefix before calling timm.create_model when the name looks like a repo id, and leave bare architecture names like resnet50 alone. With the prefix, timm reads config.json from the Hub and raises its own errors when the file is missing or belongs to another library. I map those to the existing "Tried to load ... with timm but ..." message, so the user sees the same error as with timm 1.0.28.
Note that timm names now resolve through the Hub config.json rather than the registry entry with the same name. That means user-owned timm repos work as well.
I tested with timm 1.0.28 and 1.0.29. I added unit tests for the prefix rule and the error mapping, and one end-to-end test for a repo whose config.json belongs to another library. No version pin is needed, timm has supported the hf-hub: prefix for a long time.
Fixes #4212
Before submitting
Pull Request section?
to it if that's the case.
timm/resnet50.a1_in1kexample works as before.Who can review?
@SunMarc (Command Line Interface)