From 9212f0227c7af5d6f1497e8db212e4afd0490879 Mon Sep 17 00:00:00 2001 From: Bryce Date: Mon, 23 Jan 2023 20:16:47 -0800 Subject: [PATCH] fix: bypass hf cache retrieval bug If one uses `hf_hub_download` only referencing specific commits the `refs` folder will not be created even though data will be cached via `snapshots` and `blobs`. Subsequent calls to `try_to_load_from_cache` will return None even though the desired data was in the cache. Example: ```python # download something hf_hub_download(repo_id=repo, revision=commit_hash, filename=filepath, token=token) # returns None try_to_load_from_cache(repo_id=repo, revision=commit_hash, filename=filepath) ``` https://github.com/huggingface/huggingface_hub/pull/1306 --- imaginairy/model_manager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/imaginairy/model_manager.py b/imaginairy/model_manager.py index e5ecee2..c71308c 100644 --- a/imaginairy/model_manager.py +++ b/imaginairy/model_manager.py @@ -346,6 +346,12 @@ def huggingface_cached_path(url): dest_path = hf_hub_download( repo_id=repo, revision=commit_hash, filename=filepath, token=token ) + # make a refs folder so caching works + # work-around for + # https://github.com/huggingface/huggingface_hub/pull/1306 + # https://github.com/brycedrennan/imaginAIry/issues/171 + refs_url = dest_path[: dest_path.index("/snapshots/")] + "/refs/" + os.makedirs(refs_url, exist_ok=True) return dest_path