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

Unable to load local trained cross encoder model #2372

Closed
SamuelHudec opened this issue Dec 7, 2023 · 3 comments
Closed

Unable to load local trained cross encoder model #2372

SamuelHudec opened this issue Dec 7, 2023 · 3 comments

Comments

@SamuelHudec
Copy link

hi, I tried to load a cross encoder model I trained, but I got an Error message:
OSError: Error no file named pytorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory

Yes, model is saved as model.safetensors not as pytorch_model.bin. I found that my virtual environment is missing the library safetensors. So fix was easy and fast:

pip install safetensors

If my problem is not local, please add lib to dependencies.

Thanks

@tomaarsen
Copy link
Collaborator

Hello!

This is indeed a bit of an inconsistency or bug, although it might be fairly niche. After all, to train a model that ends up saving as model.safetensors, you have to have safetensors installed. Additionally, newer versions of transformers have safetensors as a dependency. So I think this only happens if you train a model in virtualenvironment 1 with safetensors, and then use SentenceTransformers in virtualenvironment 2 without safetensors.

Now, I don't blame you for doing so, SentenceTransformers has a few issues with the latest versions of transformers, huggingface_hub, etc., so I think the best solution is likely indeed to add safetensors as a dependency.

Although perhaps there is some other scenario where this might happen as well? Regardless, I'll add the dependency.

  • Tom Aarsen

tomaarsen added a commit to tomaarsen/sentence-transformers that referenced this issue Dec 7, 2023
@SamuelHudec
Copy link
Author

hello thanks for fast answer,

yes you right, there are two venv but both built with same dependences. Only difference is that one is docker on linux and my local is Mac OS. I double checked libraries, and both have transformers==4.25.1 and sentence-transformers==2.2.2 :/

Its weird. Thats why I wrote, "If my problem is not local,...".

Also 100% agree with you and it bothered me too, Ones model is dumped with safetensors with same venv, reverse processing should be possible.

If anyone has an idea of something I should check, I'd be happy to do it.

Lets wait for a while, one of the reasons for this issue was to check if it happened to anyone else.

thanks again Samuel

@tomaarsen
Copy link
Collaborator

In the next version, transformers will need to be at least 4.32.0 due to #2345, and 4.32.0 onwards has safetensors as a dependency, so we don't need to explicitly specify it. With other words, this should stop happening when the next release is out (hopefully within the next 2 weeks or so).

So I'll close this for now :)

  • 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

Successfully merging a pull request may close this issue.

2 participants