diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index cc97e043c139..c7530fbee9fc 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -40,6 +40,8 @@ jobs: apt install -y libpq-dev postgresql-client python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 python -m uv pip install -r benchmarks/requirements.txt - name: Environment run: | diff --git a/.github/workflows/mirror_community_pipeline.yml b/.github/workflows/mirror_community_pipeline.yml index 9cf573312b34..72440636acad 100644 --- a/.github/workflows/mirror_community_pipeline.yml +++ b/.github/workflows/mirror_community_pipeline.yml @@ -76,6 +76,7 @@ jobs: run: | python -m pip install --upgrade pip pip install --upgrade huggingface_hub + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) # Check secret is set - name: whoami diff --git a/.github/workflows/nightly_tests.yml b/.github/workflows/nightly_tests.yml index 479e5503eed2..63303404877b 100644 --- a/.github/workflows/nightly_tests.yml +++ b/.github/workflows/nightly_tests.yml @@ -75,6 +75,7 @@ jobs: python -m uv pip install -e [quality,test] pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git python -m uv pip install pytest-reportlog + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -129,6 +130,7 @@ jobs: python -m uv pip install peft@git+https://github.com/huggingface/peft.git pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git python -m uv pip install pytest-reportlog + python -m uv pip install compel==0.1.8 - name: Environment run: python utils/print_env.py @@ -237,6 +239,7 @@ jobs: python -m uv pip install peft@git+https://github.com/huggingface/peft.git pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git python -m uv pip install pytest-reportlog + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -286,6 +289,7 @@ jobs: python -m uv pip install -e [quality,test] python -m uv pip install peft@git+https://github.com/huggingface/peft.git pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git + python -m uv pip install compel==0.1.8 - name: Environment run: | diff --git a/.github/workflows/pr_dependency_test.yml b/.github/workflows/pr_dependency_test.yml index d9350c09ac42..9758fbff4479 100644 --- a/.github/workflows/pr_dependency_test.yml +++ b/.github/workflows/pr_dependency_test.yml @@ -22,13 +22,15 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" python -m pip install --upgrade pip uv - python -m uv pip install -e . + python -m uv pip install --prerelease=allow -e . + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) python -m uv pip install pytest + python -m uv pip install compel==0.1.8 - name: Check for soft dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" diff --git a/.github/workflows/pr_modular_tests.yml b/.github/workflows/pr_modular_tests.yml index e01345e32524..6ad88630636d 100644 --- a/.github/workflows/pr_modular_tests.yml +++ b/.github/workflows/pr_modular_tests.yml @@ -44,6 +44,7 @@ jobs: run: | python -m pip install --upgrade pip pip install .[quality] + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) - name: Check quality run: make quality - name: Check if failure @@ -64,6 +65,7 @@ jobs: run: | python -m pip install --upgrade pip pip install .[quality] + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) - name: Check repo consistency run: | python utils/check_copies.py @@ -109,9 +111,10 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] pip uninstall transformers -y && python -m uv pip install -U transformers@git+https://github.com/huggingface/transformers.git --no-deps pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git --no-deps + python -m uv pip install compel==0.1.8 - name: Environment run: | diff --git a/.github/workflows/pr_test_fetcher.yml b/.github/workflows/pr_test_fetcher.yml index b032bb842786..f14a96f49ffc 100644 --- a/.github/workflows/pr_test_fetcher.yml +++ b/.github/workflows/pr_test_fetcher.yml @@ -34,7 +34,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -92,7 +94,9 @@ jobs: run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" python -m pip install -e [quality,test] + python -m pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) python -m pip install accelerate + python -m uv pip install compel==0.1.8 - name: Environment run: | @@ -149,7 +153,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" + python -m pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) python -m pip install -e [quality,test] + python -m uv pip install compel==0.1.8 - name: Environment run: | diff --git a/.github/workflows/pr_tests.yml b/.github/workflows/pr_tests.yml index 34a344528e3e..34f63dcfbdfc 100644 --- a/.github/workflows/pr_tests.yml +++ b/.github/workflows/pr_tests.yml @@ -35,11 +35,12 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | python -m pip install --upgrade pip pip install .[quality] + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) - name: Check quality run: make quality - name: Check if failure @@ -55,11 +56,12 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | python -m pip install --upgrade pip pip install .[quality] + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) - name: Check repo consistency run: | python utils/check_copies.py @@ -115,9 +117,10 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] pip uninstall transformers -y && python -m uv pip install -U transformers@git+https://github.com/huggingface/transformers.git --no-deps pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git --no-deps + python -m uv pip install compel==0.1.8 - name: Environment run: | @@ -196,7 +199,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Environment run: | @@ -250,12 +255,13 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] # TODO (sayakpaul, DN6): revisit `--no-deps` python -m pip install -U peft@git+https://github.com/huggingface/peft.git --no-deps python -m uv pip install -U transformers@git+https://github.com/huggingface/transformers.git --no-deps python -m uv pip install -U tokenizers pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git --no-deps + python -m uv pip install compel==0.1.8 - name: Environment run: | diff --git a/.github/workflows/pr_tests_gpu.yml b/.github/workflows/pr_tests_gpu.yml index 45294c89fe35..214b994b4e49 100644 --- a/.github/workflows/pr_tests_gpu.yml +++ b/.github/workflows/pr_tests_gpu.yml @@ -36,11 +36,12 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | python -m pip install --upgrade pip pip install .[quality] + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) - name: Check quality run: make quality - name: Check if failure @@ -56,11 +57,12 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | python -m pip install --upgrade pip pip install .[quality] + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) - name: Check repo consistency run: | python utils/check_copies.py @@ -89,7 +91,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -131,9 +135,10 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git pip uninstall transformers -y && python -m uv pip install -U transformers@git+https://github.com/huggingface/transformers.git --no-deps + python -m uv pip install compel==0.1.8 - name: Environment run: | @@ -201,10 +206,11 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] python -m uv pip install peft@git+https://github.com/huggingface/peft.git pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git pip uninstall transformers -y && python -m uv pip install -U transformers@git+https://github.com/huggingface/transformers.git --no-deps + python -m uv pip install compel==0.1.8 - name: Environment run: | @@ -267,7 +273,8 @@ jobs: run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" pip uninstall transformers -y && python -m uv pip install -U transformers@git+https://github.com/huggingface/transformers.git --no-deps - python -m uv pip install -e [quality,test,training] + python -m uv pip install --prerelease=allow -e [quality,test,training] + python -m uv pip install compel==0.1.8 - name: Environment run: | diff --git a/.github/workflows/pr_torch_dependency_test.yml b/.github/workflows/pr_torch_dependency_test.yml index c39d5eca2d9a..8a95797a3ac0 100644 --- a/.github/workflows/pr_torch_dependency_test.yml +++ b/.github/workflows/pr_torch_dependency_test.yml @@ -22,14 +22,16 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" python -m pip install --upgrade pip uv - python -m uv pip install -e . + python -m uv pip install --prerelease=allow -e . python -m uv pip install torch torchvision torchaudio python -m uv pip install pytest + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Check for soft dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" diff --git a/.github/workflows/push_tests.yml b/.github/workflows/push_tests.yml index 6896e0145cbb..85812070df91 100644 --- a/.github/workflows/push_tests.yml +++ b/.github/workflows/push_tests.yml @@ -35,7 +35,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -76,8 +78,10 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -127,9 +131,10 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] python -m uv pip install peft@git+https://github.com/huggingface/peft.git pip uninstall accelerate -y && python -m uv pip install -U accelerate@git+https://github.com/huggingface/accelerate.git + python -m uv pip install compel==0.1.8 - name: Environment run: | @@ -181,7 +186,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test,training] + python -m uv pip install --prerelease=allow -e [quality,test,training] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -224,7 +231,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test,training] + python -m uv pip install --prerelease=allow -e [quality,test,training] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Environment run: | python utils/print_env.py @@ -265,7 +274,9 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test,training] + python -m uv pip install --prerelease=allow -e [quality,test,training] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) + python -m uv pip install compel==0.1.8 - name: Environment run: | diff --git a/.github/workflows/push_tests_fast.yml b/.github/workflows/push_tests_fast.yml index e274cb021892..d159ddb4b734 100644 --- a/.github/workflows/push_tests_fast.yml +++ b/.github/workflows/push_tests_fast.yml @@ -61,7 +61,7 @@ jobs: - name: Install dependencies run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" - python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow -e [quality,test] - name: Environment run: | diff --git a/.github/workflows/push_tests_mps.yml b/.github/workflows/push_tests_mps.yml index eb6c0da22541..04dbad0324e1 100644 --- a/.github/workflows/push_tests_mps.yml +++ b/.github/workflows/push_tests_mps.yml @@ -41,10 +41,11 @@ jobs: shell: arch -arch arm64 bash {0} run: | ${CONDA_RUN} python -m pip install --upgrade pip uv - ${CONDA_RUN} python -m uv pip install -e ".[quality,test]" + ${CONDA_RUN} python -m uv pip install --prerelease=allow -e ".[quality,test]" ${CONDA_RUN} python -m uv pip install torch torchvision torchaudio ${CONDA_RUN} python -m uv pip install accelerate@git+https://github.com/huggingface/accelerate.git ${CONDA_RUN} python -m uv pip install transformers --upgrade + ${CONDA_RUN} python -m uv pip install compel==0.1.8 - name: Environment shell: arch -arch arm64 bash {0} diff --git a/.github/workflows/pypi_publish.yaml b/.github/workflows/pypi_publish.yaml index dc36b6b024c5..8e8a97b5540e 100644 --- a/.github/workflows/pypi_publish.yaml +++ b/.github/workflows/pypi_publish.yaml @@ -20,7 +20,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.8' + python-version: "3.9" - name: Fetch latest branch id: fetch_latest_branch @@ -47,14 +47,14 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.9" - name: Install dependencies run: | python -m pip install --upgrade pip pip install -U setuptools wheel twine pip install -U torch --index-url https://download.pytorch.org/whl/cpu - pip install -U transformers + pip install git+https://github.com/huggingface/transformers.git # temporary (only for tests) - name: Build the dist files run: python setup.py bdist_wheel && python setup.py sdist diff --git a/.github/workflows/run_tests_from_a_pr.yml b/.github/workflows/run_tests_from_a_pr.yml index c8eee8dbbc33..8f5093e19920 100644 --- a/.github/workflows/run_tests_from_a_pr.yml +++ b/.github/workflows/run_tests_from_a_pr.yml @@ -65,10 +65,12 @@ jobs: run: | python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" python -m uv pip install -e [quality,test] + python -m uv pip install --prerelease=allow "transformers @ git+https://github.com/huggingface/transformers.git" # temporary (only for tests) python -m uv pip install peft + python -m uv pip install compel==0.1.8 - name: Run tests env: - PY_TEST: ${{ github.event.inputs.test }} + PY_TEST: ${{ github.event.inputs.test }} run: | pytest "$PY_TEST" diff --git a/setup.py b/setup.py index ba3ad8e2b307..d26cef936eb7 100644 --- a/setup.py +++ b/setup.py @@ -97,12 +97,12 @@ _deps = [ "Pillow", # keep the PIL.Image.Resampling deprecation away "accelerate>=0.31.0", - "compel==0.1.8", "datasets", "filelock", "flax>=0.4.1", "hf-doc-builder>=0.3.0", - "huggingface-hub>=0.34.0", + "httpx", + "huggingface-hub==1.0.0.rc1", "requests-mock==1.10.0", "importlib_metadata", "invisible-watermark>=0.2.0", @@ -139,7 +139,7 @@ "tiktoken>=0.7.0", "torch>=1.4", "torchvision", - "transformers>=4.41.2", + # "transformers>=4.41.2", # tmp for tests "urllib3<=2.0.0", "black", "phonemizer", @@ -219,7 +219,6 @@ def run(self): extras["docs"] = deps_list("hf-doc-builder") extras["training"] = deps_list("accelerate", "datasets", "protobuf", "tensorboard", "Jinja2", "peft") extras["test"] = deps_list( - "compel", "GitPython", "datasets", "Jinja2", @@ -236,7 +235,7 @@ def run(self): "scipy", "tiktoken", "torchvision", - "transformers", + # "transformers", "phonemizer", ) extras["torch"] = deps_list("torch", "accelerate") @@ -259,6 +258,7 @@ def run(self): install_requires = [ deps["importlib_metadata"], deps["filelock"], + deps["httpx"], deps["huggingface-hub"], deps["numpy"], deps["regex"], diff --git a/src/diffusers/configuration_utils.py b/src/diffusers/configuration_utils.py index 540aab03071d..1c4ee33acbfd 100644 --- a/src/diffusers/configuration_utils.py +++ b/src/diffusers/configuration_utils.py @@ -30,11 +30,11 @@ from huggingface_hub import DDUFEntry, create_repo, hf_hub_download from huggingface_hub.utils import ( EntryNotFoundError, + HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError, validate_hf_hub_args, ) -from requests import HTTPError from typing_extensions import Self from . import __version__ @@ -419,7 +419,7 @@ def load_config( raise EnvironmentError( f"{pretrained_model_name_or_path} does not appear to have a file named {cls.config_name}." ) - except HTTPError as err: + except HfHubHTTPError as err: raise EnvironmentError( "There was a specific connection error when trying to load" f" {pretrained_model_name_or_path}:\n{err}" diff --git a/src/diffusers/dependency_versions_table.py b/src/diffusers/dependency_versions_table.py index 79dc4c50a050..8c59406040e8 100644 --- a/src/diffusers/dependency_versions_table.py +++ b/src/diffusers/dependency_versions_table.py @@ -4,12 +4,12 @@ deps = { "Pillow": "Pillow", "accelerate": "accelerate>=0.31.0", - "compel": "compel==0.1.8", "datasets": "datasets", "filelock": "filelock", "flax": "flax>=0.4.1", "hf-doc-builder": "hf-doc-builder>=0.3.0", - "huggingface-hub": "huggingface-hub>=0.34.0", + "httpx": "httpx", + "huggingface-hub": "huggingface-hub==1.0.0.rc1", "requests-mock": "requests-mock==1.10.0", "importlib_metadata": "importlib_metadata", "invisible-watermark": "invisible-watermark>=0.2.0", @@ -46,7 +46,6 @@ "tiktoken": "tiktoken>=0.7.0", "torch": "torch>=1.4", "torchvision": "torchvision", - "transformers": "transformers>=4.41.2", "urllib3": "urllib3<=2.0.0", "black": "black", "phonemizer": "phonemizer", diff --git a/src/diffusers/models/modeling_flax_utils.py b/src/diffusers/models/modeling_flax_utils.py index 573828dc4b03..8050afff2767 100644 --- a/src/diffusers/models/modeling_flax_utils.py +++ b/src/diffusers/models/modeling_flax_utils.py @@ -26,11 +26,11 @@ from huggingface_hub import create_repo, hf_hub_download from huggingface_hub.utils import ( EntryNotFoundError, + HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError, validate_hf_hub_args, ) -from requests import HTTPError from .. import __version__, is_torch_available from ..utils import ( @@ -385,7 +385,7 @@ def from_pretrained( raise EnvironmentError( f"{pretrained_model_name_or_path} does not appear to have a file named {FLAX_WEIGHTS_NAME}." ) - except HTTPError as err: + except HfHubHTTPError as err: raise EnvironmentError( f"There was a specific connection error when trying to load {pretrained_model_name_or_path}:\n" f"{err}" diff --git a/src/diffusers/pipelines/pipeline_loading_utils.py b/src/diffusers/pipelines/pipeline_loading_utils.py index 388128df0ebd..b7a3e08105ff 100644 --- a/src/diffusers/pipelines/pipeline_loading_utils.py +++ b/src/diffusers/pipelines/pipeline_loading_utils.py @@ -19,12 +19,12 @@ from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Union +import httpx import requests import torch from huggingface_hub import DDUFEntry, ModelCard, model_info, snapshot_download -from huggingface_hub.utils import OfflineModeIsEnabled, validate_hf_hub_args +from huggingface_hub.utils import HfHubHTTPError, OfflineModeIsEnabled, validate_hf_hub_args from packaging import version -from requests.exceptions import HTTPError from .. import __version__ from ..utils import ( @@ -1110,7 +1110,7 @@ def _download_dduf_file( if not local_files_only: try: info = model_info(pretrained_model_name, token=token, revision=revision) - except (HTTPError, OfflineModeIsEnabled, requests.ConnectionError) as e: + except (HfHubHTTPError, OfflineModeIsEnabled, requests.ConnectionError, httpx.NetworkError) as e: logger.warning(f"Couldn't connect to the Hub: {e}.\nWill try to load from local cache.") local_files_only = True model_info_call_error = e # save error to reraise it if model is not cached locally diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index 01b3c56777c8..3f6e53099b38 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -23,6 +23,7 @@ from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Union, get_args, get_origin +import httpx import numpy as np import PIL.Image import requests @@ -36,9 +37,8 @@ read_dduf_file, snapshot_download, ) -from huggingface_hub.utils import OfflineModeIsEnabled, validate_hf_hub_args +from huggingface_hub.utils import HfHubHTTPError, OfflineModeIsEnabled, validate_hf_hub_args from packaging import version -from requests.exceptions import HTTPError from tqdm.auto import tqdm from typing_extensions import Self @@ -1616,7 +1616,7 @@ def download(cls, pretrained_model_name, **kwargs) -> Union[str, os.PathLike]: if not local_files_only: try: info = model_info(pretrained_model_name, token=token, revision=revision) - except (HTTPError, OfflineModeIsEnabled, requests.ConnectionError) as e: + except (HfHubHTTPError, OfflineModeIsEnabled, requests.ConnectionError, httpx.NetworkError) as e: logger.warning(f"Couldn't connect to the Hub: {e}.\nWill try to load from local cache.") local_files_only = True model_info_call_error = e # save error to reraise it if model is not cached locally diff --git a/src/diffusers/utils/hub_utils.py b/src/diffusers/utils/hub_utils.py index fcdf49156a8f..b6e99452aa88 100644 --- a/src/diffusers/utils/hub_utils.py +++ b/src/diffusers/utils/hub_utils.py @@ -38,13 +38,13 @@ from huggingface_hub.file_download import REGEX_COMMIT_HASH from huggingface_hub.utils import ( EntryNotFoundError, + HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError, is_jinja_available, validate_hf_hub_args, ) from packaging import version -from requests import HTTPError from .. import __version__ from .constants import ( @@ -316,7 +316,7 @@ def _get_model_file( raise EnvironmentError( f"{pretrained_model_name_or_path} does not appear to have a file named {weights_name}." ) from e - except HTTPError as e: + except HfHubHTTPError as e: raise EnvironmentError( f"There was a specific connection error when trying to load {pretrained_model_name_or_path}:\n{e}" ) from e @@ -432,7 +432,7 @@ def _get_checkpoint_shard_files( # We have already dealt with RepositoryNotFoundError and RevisionNotFoundError when getting the index, so # we don't have to catch them here. We have also dealt with EntryNotFoundError. - except HTTPError as e: + except HfHubHTTPError as e: raise EnvironmentError( f"We couldn't connect to '{HUGGINGFACE_CO_RESOLVE_ENDPOINT}' to load {pretrained_model_name_or_path}. You should try" " again after checking your internet connection." diff --git a/tests/models/test_modeling_common.py b/tests/models/test_modeling_common.py index 5e7be62342c3..3a008edfe1c2 100644 --- a/tests/models/test_modeling_common.py +++ b/tests/models/test_modeling_common.py @@ -37,9 +37,8 @@ import torch.nn as nn from accelerate.utils.modeling import _get_proper_dtype, compute_module_sizes, dtype_byte_size from huggingface_hub import ModelCard, delete_repo, snapshot_download, try_to_load_from_cache -from huggingface_hub.utils import is_jinja_available +from huggingface_hub.utils import HfHubHTTPError, is_jinja_available from parameterized import parameterized -from requests.exceptions import HTTPError from diffusers.models import FluxTransformer2DModel, SD3Transformer2DModel, UNet2DConditionModel from diffusers.models.attention_processor import ( @@ -272,7 +271,7 @@ def test_cached_files_are_used_when_no_internet(self): response_mock = mock.Mock() response_mock.status_code = 500 response_mock.headers = {} - response_mock.raise_for_status.side_effect = HTTPError + response_mock.raise_for_status.side_effect = HfHubHTTPError("Server down", response=mock.Mock()) response_mock.json.return_value = {} # Download this model to make sure it's in the cache. @@ -296,7 +295,7 @@ def test_local_files_only_with_sharded_checkpoint(self): error_response = mock.Mock( status_code=500, headers={}, - raise_for_status=mock.Mock(side_effect=HTTPError), + raise_for_status=mock.Mock(side_effect=HfHubHTTPError("Server down", response=mock.Mock())), json=mock.Mock(return_value={}), ) diff --git a/tests/pipelines/test_pipelines.py b/tests/pipelines/test_pipelines.py index 09df140f1af8..3a6981361268 100644 --- a/tests/pipelines/test_pipelines.py +++ b/tests/pipelines/test_pipelines.py @@ -33,9 +33,9 @@ import torch import torch.nn as nn from huggingface_hub import snapshot_download +from huggingface_hub.utils import HfHubHTTPError from parameterized import parameterized from PIL import Image -from requests.exceptions import HTTPError from transformers import CLIPImageProcessor, CLIPModel, CLIPTextConfig, CLIPTextModel, CLIPTokenizer from diffusers import ( @@ -430,7 +430,7 @@ def test_cached_files_are_used_when_no_internet(self): response_mock = mock.Mock() response_mock.status_code = 500 response_mock.headers = {} - response_mock.raise_for_status.side_effect = HTTPError + response_mock.raise_for_status.side_effect = HfHubHTTPError("Server down", response=mock.Mock()) response_mock.json.return_value = {} # Download this model to make sure it's in the cache. @@ -457,7 +457,7 @@ def test_local_files_only_are_used_when_no_internet(self): response_mock = mock.Mock() response_mock.status_code = 500 response_mock.headers = {} - response_mock.raise_for_status.side_effect = HTTPError + response_mock.raise_for_status.side_effect = HfHubHTTPError("Server down", response=mock.Mock()) response_mock.json.return_value = {} # first check that with local files only the pipeline can only be used if cached