Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion fastembed/common/model_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@
_DOWNLOAD_CHUNK_SIZE = 256 * 1024


def _hf_transport_errors() -> tuple[type[Exception], ...]:
"""Network errors of huggingface_hub's HTTP library that aren't OSError.

A refused connection, a DNS failure or a timeout raises an OSError in huggingface_hub 0.x,
which is built on requests, but a TransportError in 1.x (httpx) and 2.x (httpx2).
"""
try:
# huggingface_hub>=1.30 re-exports whichever of httpx and httpx2 it's built on.
from huggingface_hub.utils import httpx
except ImportError:
try:
import httpx # huggingface_hub 1.0 to 1.29
except ImportError: # huggingface_hub 0.x
return ()
return (httpx.TransportError,)


# Errors from an HF download that download_model handles by falling back to url and retrying.
_HF_DOWNLOAD_ERRORS = (OSError, RepositoryNotFoundError, ValueError) + _hf_transport_errors()


class ModelManagement(Generic[T]):
METADATA_FILE = "files_metadata.json"

Expand Down Expand Up @@ -502,7 +523,7 @@ def download_model(cls, model: T, cache_dir: str, retries: int = 3, **kwargs: An
**kwargs,
)
)
except (EnvironmentError, RepositoryNotFoundError, ValueError) as e:
except _HF_DOWNLOAD_ERRORS as e:
if not local_files_only:
logger.error(
f"Could not download model from HuggingFace: {e} "
Expand Down
Loading