option: reduce connecting to huggingface #16298
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
add option: reduce connecting to huggingface
for assets if local cache is available
note: enabling this with prevent the assets from being updated
option is disabled by default because it can prevent updates to those assets if updates are necessary
some user are not too happy with webui connecting to hugging face to fetch metadata for assets
like when loading SD3Tokenizer
stable-diffusion-webui/modules/models/sd3/other_impls.py
Lines 216 to 221 in 4823909
the
.from_pretrained
internally callshf_hub_download()
whitch connects to hugging face (basically checking if there's any revisions to the files) and downloading the files if not locally availableone way for those sensitive users who really don't want it to connect to hugging face se to set the environment variable
TRANSFORMERS_OFFLINE
to1
this would disabled connecting to hugging facewhen
local_files_only=True
it basically it doesn't cause to hugging face checking for updates and just newest revision in the localif the cache isn't found then it raise
LocalEntryNotFoundError
the problem with using
TRANSFORMERS_OFFLINE
is that if those files haven't been downloaded, it won't be able to download them at all, which makes this rather not user friendlyeven sensitive users should understand that it will have to at least make the connection once in order to download the necessary files
for these users ideally hugging face hub should have an
only downloads once and don't check for updates
optionbut since there isn't the easiest way to add this functionality is to patch
file_download
and let it first try withlocal_files_only=True
and if it raise
LocalEntryNotFoundError
error try again withlocal_files_only=False
to prevent crushing if there's updates to huggingface_hub
local_files_only
is a parameter of file_download.hf_hub_downloadthis should mean so as long as huggingface_hub did not completely modify how file_download.hf_hub_download the
local_files_only
arg works it should not break the patch should be disabled and shouldn't cause issuesif all safety checks failed and it raise an unexpected exception it would just try the function without patch again
not too happy with my description of this option
stable-diffusion-webui/modules/shared_options.py
Line 131 in 8574528
normally I would prefer to introduce this type of thing as an extension
but this happens way too early during the even before preload
unless something to pre-initialize callback is added I don't think this is possible as an extension
Checklist: