-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Loading adapter honors offline mode #1976
FIX Loading adapter honors offline mode #1976
Conversation
HF_HUB_OFFLINE=1 was not honored when trying to load an adapter. This is now fixed.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
I wanted to add a test for this but for some reason, it does not work. Inside the test, I set Running this test manually works: def test_load_from_hub_then_offline_model():
peft_model_id = "peft-internal-testing/gpt2-lora-random"
base_model = AutoModelForCausalLM.from_pretrained("gpt2")
PeftModel.from_pretrained(base_model, peft_model_id) Without the fix, this test fails with |
Hi @BenjaminBossan, for offline_mode in OfflineSimulationMode:
with offline(mode=offline_mode):
with SoftTemporaryDirectory() as tmpdir:
with self.assertRaises(LocalEntryNotFoundError):
snapshot_download(self.repo_id, cache_dir=tmpdir) |
src/peft/utils/save_and_load.py
Outdated
if os.path.exists(os.path.join(path, SAFETENSORS_WEIGHTS_NAME)): | ||
filename = os.path.join(path, SAFETENSORS_WEIGHTS_NAME) | ||
use_safetensors = True | ||
elif os.path.exists(os.path.join(path, WEIGHTS_NAME)): | ||
filename = os.path.join(path, WEIGHTS_NAME) | ||
use_safetensors = False | ||
elif os.environ.get("HF_HUB_OFFLINE", 0) in {"1", "ON", "YES", "TRUE"}: # same check as in hfh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif os.environ.get("HF_HUB_OFFLINE", 0) in {"1", "ON", "YES", "TRUE"}: # same check as in hfh | |
elif huggingface_hub.constants.HF_HUB_OFFLINE: |
Better to let huggingface_hub
handle the env variable parsing. Suggestion needs an additional import.
Thanks for this. It looks like I cannot import this, as it's not part of the |
There is unfortunately no easy way to import this no 😕 Best way is to duplicate it, though I'd recommend to copy a simplified version of it with only with patch("huggingface_hub.constants.HF_HUB_OFFLINE", True):
reset_sessions()
yield
reset_sessions() You don't need to test the cases with ConnectionError or TimeoutError for this PR. |
Thanks, this works perfectly! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks for adding the small test :)
HF_HUB_OFFLINE=1
was not honored when trying to load an adapter. This is now fixed.Resolves huggingface/transformers#31700.