From 6a2da9a95cf807d529ea97b2ce1c46103a88e158 Mon Sep 17 00:00:00 2001 From: Guillaume Klein Date: Thu, 11 May 2023 15:07:15 +0200 Subject: [PATCH] Also catch client-side network exceptions when synchronizing models (#228) --- faster_whisper/utils.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/faster_whisper/utils.py b/faster_whisper/utils.py index 94a203f..4b5e290 100644 --- a/faster_whisper/utils.py +++ b/faster_whisper/utils.py @@ -4,6 +4,7 @@ import os from typing import Optional import huggingface_hub +import requests from tqdm.auto import tqdm @@ -84,16 +85,23 @@ def download_model( kwargs["cache_dir"] = cache_dir try: - return huggingface_hub.snapshot_download( + return huggingface_hub.snapshot_download(repo_id, **kwargs) + except ( + huggingface_hub.utils.HfHubHTTPError, + requests.exceptions.ConnectionError, + ) as exception: + logger = get_logger() + logger.warning( + "An error occured while synchronizing the model %s from the Hugging Face Hub:\n%s", repo_id, - **kwargs, + exception, ) - except huggingface_hub.utils.HfHubHTTPError: + logger.warning( + "Trying to load the model directly from the local cache, if it exists." + ) + kwargs["local_files_only"] = True - return huggingface_hub.snapshot_download( - repo_id, - **kwargs, - ) + return huggingface_hub.snapshot_download(repo_id, **kwargs) def format_timestamp(