diff --git a/unsloth/dataprep/synthetic.py b/unsloth/dataprep/synthetic.py index 612c531f47..1be83c3bb9 100644 --- a/unsloth/dataprep/synthetic.py +++ b/unsloth/dataprep/synthetic.py @@ -21,7 +21,12 @@ from collections import deque import time import os -os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1" +_OFFLINE_VALS = {"1", "true", "yes", "on"} +if not ( + os.environ.get("HF_HUB_OFFLINE", "").strip().lower() in _OFFLINE_VALS + or os.environ.get("TRANSFORMERS_OFFLINE", "").strip().lower() in _OFFLINE_VALS +): + os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1" import requests import torch import gc diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index a46d1f0c0e..f4313c4518 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -1771,6 +1771,13 @@ def get_statistics(local_files_only = False): return if local_files_only: return + # Also skip when HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE are set. + _offline_vals = {"1", "true", "yes", "on"} + if ( + os.environ.get("TRANSFORMERS_OFFLINE", "").strip().lower() in _offline_vals + or os.environ.get("HF_HUB_OFFLINE", "").strip().lower() in _offline_vals + ): + return from huggingface_hub.utils import ( disable_progress_bars, enable_progress_bars, diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index fc91178d88..c10443e289 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -308,6 +308,16 @@ class FastLanguageModel(FastLlamaModel): if is_dist: device_map = distributed_device_map + # Honour offline env vars BEFORE FastModel delegation so 8bit / + # full-finetuning / qat paths also receive local_files_only. + if not kwargs.get("local_files_only", False): + _offline = {"1", "true", "yes", "on"} + if ( + os.environ.get("TRANSFORMERS_OFFLINE", "").strip().lower() in _offline + or os.environ.get("HF_HUB_OFFLINE", "").strip().lower() in _offline + ): + kwargs["local_files_only"] = True + if load_in_8bit or full_finetuning or qat_scheme is not None: return FastModel.from_pretrained( model_name = model_name, @@ -1055,6 +1065,15 @@ class FastModel(FastBaseModel): model_config = None peft_config = None local_files_only = kwargs.get("local_files_only", False) + # Mirror env-var fallback for direct callers (FastVisionModel / FastTextModel). + if not local_files_only: + _offline = {"1", "true", "yes", "on"} + if ( + os.environ.get("TRANSFORMERS_OFFLINE", "").strip().lower() in _offline + or os.environ.get("HF_HUB_OFFLINE", "").strip().lower() in _offline + ): + local_files_only = True + kwargs["local_files_only"] = True try: model_config = AutoConfig.from_pretrained(