Skip to content

Commit 0d68ddf

Browse files
authored
Move away from cached_download (huggingface#8419)
* Move away from * unused constant * Add custom error
1 parent 7d88711 commit 0d68ddf

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/diffusers/utils/dynamic_modules_utils.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,19 @@
2525
from typing import Dict, Optional, Union
2626
from urllib import request
2727

28-
from huggingface_hub import cached_download, hf_hub_download, model_info
29-
from huggingface_hub.utils import validate_hf_hub_args
28+
from huggingface_hub import hf_hub_download, model_info
29+
from huggingface_hub.utils import RevisionNotFoundError, validate_hf_hub_args
3030
from packaging import version
3131

3232
from .. import __version__
3333
from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging
3434

3535

36-
COMMUNITY_PIPELINES_URL = (
37-
"https://raw.githubusercontent.com/huggingface/diffusers/{revision}/examples/community/{pipeline}.py"
38-
)
39-
40-
4136
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
4237

38+
# See https://huggingface.co/datasets/diffusers/community-pipelines-mirror
39+
COMMUNITY_PIPELINES_MIRROR_ID = "diffusers/community-pipelines-mirror"
40+
4341

4442
def get_diffusers_versions():
4543
url = "https://pypi.org/pypi/diffusers/json"
@@ -281,20 +279,24 @@ def get_cached_module_file(
281279
f" {', '.join(available_versions + ['main'])}."
282280
)
283281

284-
# community pipeline on GitHub
285-
github_url = COMMUNITY_PIPELINES_URL.format(revision=revision, pipeline=pretrained_model_name_or_path)
286282
try:
287-
resolved_module_file = cached_download(
288-
github_url,
283+
resolved_module_file = hf_hub_download(
284+
repo_id=COMMUNITY_PIPELINES_MIRROR_ID,
285+
repo_type="dataset",
286+
filename=f"{revision}/{pretrained_model_name_or_path}.py",
289287
cache_dir=cache_dir,
290288
force_download=force_download,
291289
proxies=proxies,
292-
resume_download=resume_download,
293290
local_files_only=local_files_only,
294-
token=False,
295291
)
296292
submodule = "git"
297293
module_file = pretrained_model_name_or_path + ".py"
294+
except RevisionNotFoundError as e:
295+
raise EnvironmentError(
296+
f"Revision '{revision}' not found in the community pipelines mirror. Check available revisions on"
297+
" https://huggingface.co/datasets/diffusers/community-pipelines-mirror/tree/main."
298+
" If you don't find the revision you are looking for, please open an issue on https://github.com/huggingface/diffusers/issues."
299+
) from e
298300
except EnvironmentError:
299301
logger.error(f"Could not locate the {module_file} inside {pretrained_model_name_or_path}.")
300302
raise

0 commit comments

Comments
 (0)