Skip to content
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

Loading LORA weights with load_lora_weights do not respect HF_HUB_OFFLINE / local_file_only #6089

Closed
Wauplin opened this issue Dec 7, 2023 · 5 comments · Fixed by #6184
Closed
Labels
bug Something isn't working

Comments

@Wauplin
Copy link
Contributor

Wauplin commented Dec 7, 2023

First reported by @rvorias in huggingface/huggingface_hub#1893 (comment).

TL;DR: Loading lora weights on a pipeline makes a call to the Hub even when HF_HUB_OFFLINE=1 is set as environment variable (or local_file_only=True is passed as parameter), which is not expected.

This seems to be due to the _best_guess_weight_name method that try to guess which file to load when the LoRA filename is not provided. It makes a call to model_info to check which files exist on the Hub repo.

pipeline.load_lora_weights(
  "latent-consistency/lcm-lora-sdxl",
  adapter_name="lcm",
  cache_dir=cache_dir,
  local_files_only=True,
)

Suggestions:

  • raise an error if offline mode => "hey you should pass a filename"
  • check local cache if offline mode => try to guess based on that locally saved files?
@sayakpaul
Copy link
Member

Maybe it's better to be explicit here so, I would prefer the first option.

@Wauplin
Copy link
Contributor Author

Wauplin commented Dec 9, 2023

Agree on raising an explicit error while the problem is not solved but it would be good to be able to load lora weights while being offline, no? I think it just requires to list the local files (os.listdir(snapshot_path)) instead of listing files from the Hub.

And I'll open an issue in huggingface_hub to raise explicit error in all method of HfApi if HF_HUB_OFFLINE=1 (currently only the case for download methods).

@sayakpaul
Copy link
Member

I think it just requires to list the local files (os.listdir(snapshot_path)) instead of listing files from the Hub.

Hmm, so when local_files_only=True we do os.listdir(...), yeah? Yeah, that makes sense too.

@Wauplin
Copy link
Contributor Author

Wauplin commented Dec 12, 2023

I created huggingface/huggingface_hub#1899 in huggingface_hub to raise an explicit error if someone tries to call the Hub with HF_HUB_OFFLINE=1. It will make it more obvious to the user what happens.
diffusers will have to deal with OfflineModeIsEnabled exception the same way it deals with local_files_only=True. Instead of catching the error, another possibility is to look at the huggingface_hub.constant.HF_HUB_OFFLINE constant directly (i.e. have a condition if local_files_only or constants.HF_HUB_OFFLINE: ....

@sayakpaul
Copy link
Member

@Wauplin thanks for your inputs. I will take a closer look soon and open a PR asking for your review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants