fix(loader): honour HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE in from_pretrained (#5598)
Reads HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE in FastLanguageModel.from_pretrained and FastModel.from_pretrained, forcing local_files_only=True so all delegation paths (load_in_4bit, load_in_8bit, full_finetuning, qat_scheme) and direct FastModel callers (FastVisionModel, FastTextModel) honour offline mode. Also gates HF_HUB_ENABLE_HF_TRANSFER in unsloth/dataprep/synthetic.py and adds an early return in get_statistics. Pairs with unslothai/unsloth-zoo#675. Fixes #5316.
This commit is contained in:
parent
c4908b7929
commit
94026fc8dc
3 changed files with 32 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue