Unverified Commit 691d8d3e authored by Lucain's avatar Lucain Committed by GitHub
Browse files

Respect offline mode when loading pipeline (#6456)

* Respect offline mode when loading model

* default to local entry if connectionerror
parent e7c0af5e
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import fnmatch import fnmatch
import importlib import importlib
import inspect import inspect
...@@ -27,6 +26,7 @@ from typing import Any, Callable, Dict, List, Optional, Union ...@@ -27,6 +26,7 @@ from typing import Any, Callable, Dict, List, Optional, Union
import numpy as np import numpy as np
import PIL.Image import PIL.Image
import requests
import torch import torch
from huggingface_hub import ( from huggingface_hub import (
ModelCard, ModelCard,
...@@ -35,7 +35,7 @@ from huggingface_hub import ( ...@@ -35,7 +35,7 @@ from huggingface_hub import (
model_info, model_info,
snapshot_download, 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 packaging import version
from requests.exceptions import HTTPError from requests.exceptions import HTTPError
from tqdm.auto import tqdm from tqdm.auto import tqdm
...@@ -1654,7 +1654,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin): ...@@ -1654,7 +1654,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin):
if not local_files_only: if not local_files_only:
try: try:
info = model_info(pretrained_model_name, token=token, revision=revision) 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.") logger.warn(f"Couldn't connect to the Hub: {e}.\nWill try to load from local cache.")
local_files_only = True local_files_only = True
model_info_call_error = e # save error to reraise it if model is not cached locally model_info_call_error = e # save error to reraise it if model is not cached locally
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment