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

Model not automatically loaded from cache #1461

Closed
DavidHuebner opened this issue Mar 11, 2022 · 2 comments
Closed

Model not automatically loaded from cache #1461

DavidHuebner opened this issue Mar 11, 2022 · 2 comments

Comments

@DavidHuebner
Copy link

First, let me thank you for maintaining this great package!

I think that the model-caching logic in SentenceTransformer.py could be improved. When I specify a model and a cache_dir like so SentenceTransformer("distiluse-base-multilingual-cased-v1", cache_folder="~/.models/") , my hope (and expectation) was the following behaviour:

  1. When executed for the first time, it should download the model into the cache_folder (this is ok!).
  2. When executed for a second time, it should re-load the existing model from that cache folder (does not work!). Even worse, it will download the model every time.

To actually make the model reload from cache, one would need to specify the model_name_or_path like so: SentenceTransformer(model_name_or_path="~/.models/sentence-transformers_distiluse-base-multilingual-cased-v1"). This leaves me with two different calls (first call, later re-loads) to SentenceTransformer with some checking in between.

The fix to this is rather simple. The loading code should check if the model was already downloaded to the cache_dir. The call to snapshot_download in https://github.com/UKPLab/sentence-transformers/blob/master/sentence_transformers/SentenceTransformer.py#L86 should only be executed if there is no existing model at model_path yet.

@sadnoodles
Copy link
Contributor

Sorry for incomplete PR.

#1923 is also not a fix. If download is not complete, this will go wrong.

I’m think check it's integrality.

@tomaarsen
Copy link
Collaborator

Hello!

The caching functionality has been overhauled in the new v2.3.0. It shouldn't re-download the model every time! I'll close this for now. Feel free to let me know if other model loading issues pop up with the new release.

  • Tom Aarsen

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