From b5812fe6464d9787bc6daaeb07e238456b444634 Mon Sep 17 00:00:00 2001 From: Wauplin Date: Thu, 4 Jan 2024 11:07:56 +0100 Subject: [PATCH 1/2] Respect offline mode when loading model --- src/diffusers/pipelines/pipeline_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index e7a795365ad3..2a255c2ff8e9 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -35,7 +35,7 @@ model_info, snapshot_download, ) -from huggingface_hub.utils import validate_hf_hub_args +from huggingface_hub.utils import OfflineModeIsEnabled, validate_hf_hub_args from packaging import version from requests.exceptions import HTTPError from tqdm.auto import tqdm @@ -1654,7 +1654,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 as e: + except (HTTPError, OfflineModeIsEnabled) as e: logger.warn(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 From 1c462ab897fb887413aacc402f10eae6407917f8 Mon Sep 17 00:00:00 2001 From: Wauplin Date: Thu, 4 Jan 2024 11:09:35 +0100 Subject: [PATCH 2/2] default to local entry if connectionerror --- src/diffusers/pipelines/pipeline_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index 2a255c2ff8e9..3054c491fd1f 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -13,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - import fnmatch import importlib import inspect @@ -27,6 +26,7 @@ import numpy as np import PIL.Image +import requests import torch from huggingface_hub import ( ModelCard, @@ -1654,7 +1654,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) as e: + except (HTTPError, OfflineModeIsEnabled, requests.ConnectionError) as e: logger.warn(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