Skip to content

Commit 5b9e072

Browse files
committed
fix: respect HF_HUB_OFFLINE in download_model to avoid network calls
When HF_HUB_OFFLINE is set to a truthy value (1, true, yes, on), download_model() should treat local_files_only=True to avoid any network calls. Currently, even with the local-cache-first pass (which may fail due to missing metadata), the retry loop still calls download_files_from_huggingface() without local_files_only, which triggers model_info() — a network API call that immediately fails in offline mode. This causes an unnecessary fallback to GCS download from storage.googleapis.com. By setting local_files_only=True when HF_HUB_OFFLINE is enabled: 1. The HF local cache pass works if the model is cached 2. The retry loop skips the network-dependent HF path entirely 3. retrieve_model_gcs() only checks for local fast-* directories 4. No network calls are attempted at all The truthy value check aligns with huggingface_hub's own parsing of HF_HUB_OFFLINE, which accepts "1", "true", "yes", "on" (case-insensitive). This is critical for air-gapped / restricted environments where both HuggingFace and Google Cloud Storage are unreachable. Made-with: Cursor
1 parent ea55268 commit 5b9e072

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

fastembed/common/model_management.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ def download_model(cls, model: T, cache_dir: str, retries: int = 3, **kwargs: An
395395
Path: The path to the downloaded model directory.
396396
"""
397397
local_files_only = kwargs.get("local_files_only", False)
398+
hf_offline = os.environ.get("HF_HUB_OFFLINE", "").strip().upper()
399+
if not local_files_only and hf_offline in {"1", "TRUE", "YES", "ON"}:
400+
local_files_only = True
401+
kwargs["local_files_only"] = True
398402
specific_model_path: str | None = kwargs.pop("specific_model_path", None)
399403
if specific_model_path:
400404
return Path(specific_model_path)

0 commit comments

Comments
 (0)