Skip to content

Commit d304f3d

Browse files
Wauplinpatrickvonplaten
authored andcommitted
Respect offline mode when loading pipeline (#6456)
* Respect offline mode when loading model * default to local entry if connectionerror
1 parent 7f551e2 commit d304f3d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/diffusers/pipelines/pipeline_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
1716
import fnmatch
1817
import importlib
1918
import inspect
@@ -27,6 +26,7 @@
2726

2827
import numpy as np
2928
import PIL.Image
29+
import requests
3030
import torch
3131
from huggingface_hub import (
3232
ModelCard,
@@ -35,7 +35,7 @@
3535
model_info,
3636
snapshot_download,
3737
)
38-
from huggingface_hub.utils import validate_hf_hub_args
38+
from huggingface_hub.utils import OfflineModeIsEnabled, validate_hf_hub_args
3939
from packaging import version
4040
from requests.exceptions import HTTPError
4141
from tqdm.auto import tqdm
@@ -1654,7 +1654,7 @@ def download(cls, pretrained_model_name, **kwargs) -> Union[str, os.PathLike]:
16541654
if not local_files_only:
16551655
try:
16561656
info = model_info(pretrained_model_name, token=token, revision=revision)
1657-
except HTTPError as e:
1657+
except (HTTPError, OfflineModeIsEnabled, requests.ConnectionError) as e:
16581658
logger.warn(f"Couldn't connect to the Hub: {e}.\nWill try to load from local cache.")
16591659
local_files_only = True
16601660
model_info_call_error = e # save error to reraise it if model is not cached locally

0 commit comments

Comments
 (0)