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

pipeline does not load from local folder, instead, it always downloads models from the internet. #21613

Closed
2 of 4 tasks
z7ye opened this issue Feb 14, 2023 · 7 comments
Closed
2 of 4 tasks

Comments

@z7ye
Copy link

z7ye commented Feb 14, 2023

System Info

I create pipeline and called save_pretrained(...) to save to some local directory. However, when I load it back using pipeline(model="local_folder"), it either load from cache or try to start downloading from the internet.

However, if I do the following, it works. I am using the latest transformers. am I misused it or misunderstood something?

mypipeline.save_pretrained(save_directory=model_path)
mypipeline.model.config.use_pretrained_backbone = False
mypipeline.model.config.save_pretrained(save_directory=model_path)

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

  1. run the code below
from transformers import pipeline

vision_classifier = pipeline(task="image-classification", model="google/vit-base-patch16-224")
vision_classifier.save_pretrained("./huggingface")
  1. now delete the cache
  2. load the model now
vision_classifier = pipeline("./huggingface")

and it will start download the pretrained model again.

Expected behavior

I expect it loads the model from the local folder

@sgugger
Copy link
Collaborator

sgugger commented Feb 14, 2023

cc @Narsil

@Narsil
Copy link
Contributor

Narsil commented Feb 20, 2023

Seems to be working fine on my end, but there needs to be a few modifications (I'm super suprises it can download anything, your included code just crashes normally).

from transformers import pipeline

pipe = pipeline(task="image-classification", model="google/vit-base-patch16-224")
pipe.save_pretrained("./local_vit")

pipe = pipeline(task="image-classification", model="./local_vit")

You need to specify the task for local, since that information is contained in the HUB, not in the config directly. So if you specify it, it works with everything locally.

On what version of transformers are you on ?

@z7ye
Copy link
Author

z7ye commented Feb 20, 2023

Hi, sorry I specified the task for local, and it still does not work. I will check the version.

@z7ye
Copy link
Author

z7ye commented Feb 21, 2023

the version is 4.24.0

@Narsil
Copy link
Contributor

Narsil commented Feb 21, 2023

I cannot reproduce even on 4.24.0 Can you include the full script + error ?

@z7ye
Copy link
Author

z7ye commented Mar 2, 2023

sure. I am still seeing the error. I will post the code later.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot closed this as completed Apr 5, 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

No branches or pull requests

3 participants