Repository navigation
fix(loader): honour HF_HUB_OFFLINE/TRANSFORMERS_OFFLINE env vars - #5598
Conversation
…trained When HF_HUB_OFFLINE or TRANSFORMERS_OFFLINE is set, propagate local_files_only=True through kwargs in FastLanguageModel.from_pretrained so every downstream HF call (AutoConfig, AutoModel, tokenizer) skips the network. Also guard get_statistics() and the unconditional HF_HUB_ENABLE_HF_TRANSFER assignment in dataprep/synthetic.py. Fixes #5316
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e17c3b557d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| local_files_only = True | ||
| kwargs["local_files_only"] = True |
There was a problem hiding this comment.
Set offline kwargs before FastModel delegation
When FastLanguageModel.from_pretrained(..., load_in_8bit=True), full_finetuning=True, or qat_scheme is used under HF_HUB_OFFLINE=1/TRANSFORMERS_OFFLINE=1, the method returns through the earlier FastModel.from_pretrained branch before this new block runs, so kwargs["local_files_only"] is never populated. FastModel.from_pretrained still defaults local_files_only to False at its own config probes, so these supported loading modes continue to make network-backed AutoConfig/PeftConfig calls despite the offline env vars.
Useful? React with 👍 / 👎.
The existing block landed after the early FastModel.from_pretrained delegation at loader.py:311, so load_in_8bit / full_finetuning / qat_scheme loading modes never received local_files_only when only HF_HUB_OFFLINE or TRANSFORMERS_OFFLINE was set. Hoist the check above that delegation and mirror it inside FastModel.from_pretrained so direct callers (FastVisionModel / FastTextModel) honour offline mode too.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6a07e7b60
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Mirror env-var fallback for direct callers (FastVisionModel / FastTextModel). | ||
| if not local_files_only: | ||
| _offline = {"1", "true", "yes", "on"} |
There was a problem hiding this comment.
Move offline detection before model-name resolution
When a direct FastModel.from_pretrained/vision/text caller uses HF_HUB_OFFLINE=1 with an arbitrary repo id that is not in the static mapper, this fallback runs only after get_model_name(...) has already executed at line 1013. get_model_name can call _get_new_mapper() in unsloth/models/loader_utils.py, which performs a requests.get to GitHub for unknown owner/model names, so offline mode still makes a network request before local_files_only is set. The env fallback needs to happen before model-name resolution or the mapper refresh needs to be skipped when offline.
Useful? React with 👍 / 👎.
|
Thanks this works! |
danielhanchen
left a comment
There was a problem hiding this comment.
Verified the additional FastModel delegation paths and unsloth-zoo sibling fix. Squash merging.
Detects offline state once at unsloth_zoo/__init__.py import using {"1","true","yes","on"} on HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE / HF_DATASETS_OFFLINE and skips HF_HUB_ENABLE_HF_TRANSFER=1 when set. The existing offline cross-sync block shares the same detection so the wider truthy parsing applies there too. Pairs with unslothai/unsloth#5598.
…trained (unslothai#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 unslothai#5316.
Summary
Fixes #5316 — offline environment variables (
HF_HUB_OFFLINE,TRANSFORMERS_OFFLINE) were silently ignored byFastLanguageModel.from_pretrained, causing unexpected network attempts (and failures in air-gapped environments) even when users had explicitly opted into offline mode.Root causes fixed (3 sites):
unsloth/models/loader.py—FastLanguageModel.from_pretrainedlocal_files_onlydefaulted toFalsewithout consulting the standard HF offline env vars. The fix reads those vars and setslocal_files_only = True+ propagates it throughkwargsso every downstream HF call (AutoConfig, AutoModel, tokenizer) skips the network.unsloth/models/_utils.py—get_statistics()Already guarded on the
local_files_onlyparameter but didn't check the env vars directly. A call that never passed the param would still attempt a network request. Added the same env-var guard.unsloth/dataprep/synthetic.pyModule-level
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"was unconditional.hf_transferis a Rust-based downloader that bypasses the Python-side offline flag. The assignment is now gated so it only runs when offline mode is not active.What is NOT changed: behaviour when offline env vars are absent is identical to before.
Test plan
HF_HUB_OFFLINE=1,TRANSFORMERS_OFFLINE=1, and normal (online) mode.ruff checkpasses on all three changed files with no warnings.Checklist
fix(loader): …)rufflint passes