Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move away from cached_download #8419

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/diffusers/utils/dynamic_modules_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@
from typing import Dict, Optional, Union
from urllib import request

from huggingface_hub import cached_download, hf_hub_download, model_info
from huggingface_hub.utils import validate_hf_hub_args
from huggingface_hub import hf_hub_download, model_info
from huggingface_hub.utils import RevisionNotFoundError, validate_hf_hub_args
from packaging import version

from .. import __version__
from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging


COMMUNITY_PIPELINES_URL = (
"https://raw.githubusercontent.com/huggingface/diffusers/{revision}/examples/community/{pipeline}.py"
)


logger = logging.get_logger(__name__) # pylint: disable=invalid-name

# See https://huggingface.co/datasets/diffusers/community-pipelines-mirror
COMMUNITY_PIPELINES_MIRROR_ID = "diffusers/community-pipelines-mirror"


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

# community pipeline on GitHub
github_url = COMMUNITY_PIPELINES_URL.format(revision=revision, pipeline=pretrained_model_name_or_path)
try:
resolved_module_file = cached_download(
github_url,
resolved_module_file = hf_hub_download(
repo_id=COMMUNITY_PIPELINES_MIRROR_ID,
repo_type="dataset",
filename=f"{revision}/{pretrained_model_name_or_path}.py",
cache_dir=cache_dir,
force_download=force_download,
proxies=proxies,
resume_download=resume_download,
local_files_only=local_files_only,
token=False,
)
submodule = "git"
module_file = pretrained_model_name_or_path + ".py"
except RevisionNotFoundError as e:
raise EnvironmentError(
f"Revision '{revision}' not found in the community pipelines mirror. Check available revisions on"
" https://huggingface.co/datasets/diffusers/community-pipelines-mirror/tree/main."
" If you don't find the revision you are looking for, please open an issue on https://github.com/huggingface/diffusers/issues."
) from e
except EnvironmentError:
logger.error(f"Could not locate the {module_file} inside {pretrained_model_name_or_path}.")
raise
Expand Down
Loading