-
Describe the bug I'm trying to load swin transformer in a kaggle's offline environment. While it ran without issue yesterday, it now fails to load with a To Reproduce
Expected behavior Error message
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
@eesoymilk latest timm versions (0.9.x) use the huggingface hub for weights by default now, that takes priority over the torch hub cache, many weights have been remapped for model changes so best download via HF hub. Kaggle really should support passing through HF hub or at least caching it properly but they seem to have no interest in making things simpler for people so the manual caching of weights in datasets madness continues... To override pretrained location, you download the weights file manually from the hub and try the following. timm.create_model(
'swinv2_large_window12to16_192to256',
pretrained=True,
pretrained_cfg_overlay=dict(file='path/to/checkpoint'),
) where checkpoint is a .safetensors/.bin/.pth/.pt etc file... |
Beta Was this translation helpful? Give feedback.
-
moving to discussions for future reference |
Beta Was this translation helpful? Give feedback.
-
@rwightman can you pls point me what is the default path where loaded models are stored in 0.9.x versions? |
Beta Was this translation helpful? Give feedback.
-
I had a related problem and would like to share the solution: I couldn't find a way to change the model download path (to speedup application deployments). I tried to change it by passing arguments to Here is an example (using timm 1.0.12, torch 2.5.1+cpu, huggingface_hub 0.26.3). First, let's test using standard HF cache dir: import timm
from huggingface_hub import scan_cache_dir
# Load a model to ensure it's downloaded in the standard cache dir
model = timm.create_model("timm/vit_small_patch14_dinov2.lvd142m", pretrained=True, num_classes=0)
# Now check where the downloaded repositories were stored
cache = scan_cache_dir()
cache.repos
for repo in cache.repos:
print(f"repo {repo.repo_id} stored in {repo.repo_path}") The code above will print something like this (
Now, let's force the !rm -rf /data/models # Make sure it does not exist, so force HF to download the model
import os
os.environ["HF_HUB_CACHE"] = "/data/models/"
# The rest of the code is exactly the same:
import timm
from huggingface_hub import scan_cache_dir
# Load a model to ensure it's downloaded in the custom cache dir
model = timm.create_model("timm/vit_small_patch14_dinov2.lvd142m", pretrained=True, num_classes=0)
# Now check where the downloaded repositories were stored
cache = scan_cache_dir()
cache.repos
for repo in cache.repos:
print(f"repo {repo.repo_id} stored in {repo.repo_path}") And the output will be:
|
Beta Was this translation helpful? Give feedback.
-
FYI @turicas & others, I have a feature issue up to address #2338 ... I welcome comments about the proposed idea there from a user interface aspect. The idea is you download model repo ahead of time from the HF hub Then create model with an identifier that specifies it's a local folder Even right now, you can avoid rooting through the HF hub cache and download the model using the cli, then using the pretrained_cfg_overlay to point to either the .safetensors or .bin file. You retain more control that way than you do letting the hub cache. Best use case for the cache is just let it be if you're on the same machine, switch between offline/online if you are unplugged sometimes. If you are on an isolated network, either share a cache folder that you can sync from another machien that fills it or download models ahead of time explicitly. To lookup the hf repoid without poking around |
Beta Was this translation helpful? Give feedback.
@eesoymilk latest timm versions (0.9.x) use the huggingface hub for weights by default now, that takes priority over the torch hub cache, many weights have been remapped for model changes so best download via HF hub. Kaggle really should support passing through HF hub or at least caching it properly but they seem to have no interest in making things simpler for people so the manual caching of weights in datasets madness continues...
To override pretrained location, you download the weights file manually from the hub and try the following.
where checkpoi…