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

Check local files if (RepoNotFound, GatedRepo, HTTPError) while downloading files #1561

Merged
merged 7 commits into from
Jul 26, 2023

Conversation

jiamings
Copy link
Contributor

In certain cases, we might assume that the model files exist (like in a docker) but huggingface token is not set, and the user only needs to run the model locally. This works for diffusers with default arguments, but in transformers, a RepositoryNotFoundError is raised if not_local_files_only is true, but user is not logged into huggingface.

Example code:

from transformers import T5EncoderModel, T5Tokenizer

tokenizer = T5Tokenizer.from_pretrained("DeepFloyd/IF-I-XL-v1.0", subfolder="tokenizer")
# tokenizer = T5Tokenizer.from_pretrained("DeepFloyd/IF-I-XL-v1.0", subfolder="tokenizer", local_files_only=True)

prompt = "something"
text_inputs = tokenizer(prompt, padding="max_length", max_length=77, truncation=True, add_special_tokens=True, return_tensors="pt")

print(text_inputs)

The fix is to check if there is a token or not. If there is a token, then there might be authentication issues. If not, then it might be expected behavior from the user that a local file is being used (like in production).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 21, 2023

The documentation is not available anymore as the PR was closed or merged.

@Wauplin
Copy link
Contributor

Wauplin commented Jul 21, 2023

Hi @jiamings, thanks for asking about this and opening a PR for it! Actually your proposal is perfectly valid as it can also be useful for setups where a cache directory is shared among different users that might not have access to the repo on the Hub.

I hope it is fine with you, I completed your PR to add support for more use cases I had in mind:

  • private repos (i.e. repo not found), even if token is passed
  • gated repos
  • error 500 or 504 => unlikely case if the Hub is down but files are already cached
    I also added a test for it.

cc @julien-c @LysandreJik can you review the logic to confirm it's good for you?

NOTE: failing tests are unrelated

@Wauplin Wauplin requested review from LysandreJik and julien-c July 21, 2023 16:11
@Wauplin Wauplin changed the title Fix case where model exists locally but huggingface is not logged in. Check local files if RepoNotFound, GatedRepo or HTTPError Jul 21, 2023
@Wauplin Wauplin changed the title Check local files if RepoNotFound, GatedRepo or HTTPError Check local files if (RepoNotFound, GatedRepo, HTTPError) while downloading files Jul 21, 2023
@Wauplin Wauplin merged commit 6bc3318 into huggingface:main Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants