diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index e7a795365ad3..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, @@ -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, 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