UKPLab / sentence-transformers

Multilingual Sentence & Image Embeddings with BERT
https://www.SBERT.net
Apache License 2.0
14.45k stars 2.4k forks source link

Compatibility issue with faiss-cpu #2473

Open JackMurphy97 opened 5 months ago

JackMurphy97 commented 5 months ago

Getting segmentation fault errors zsh: segmentation fault poetry run python3 jack_debug/test.py when I try to instantiate a SentenceTransformer model. Only happens when the imports are this way round:

import faiss
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")

whereas everything works fine when the imports are this way round:

from sentence_transformers import SentenceTransformer
import faiss
model = SentenceTransformer("all-MiniLM-L6-v2")

Here is my poetry toml:

[tool.poetry]
name = "jack-debug"
version = "0.1.0"
description = ""
authors = ["jackmurphy <my_email>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.10,<3.11"
sentence-transformers = "2.2.2"
faiss-cpu = "^1.7.4"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

I've tried changing the versions of faiss and sentence_transformers but wasn't able to resolve this.

Anyone able to help? Please let me know if I can provide any further information that would be helpful. Thanks :)

tomaarsen commented 5 months ago

Hello!

This is related to #2291. Others have experienced similar issues re. segmentation faults, but I've been unable to reproduce it locally myself, making it very challenging to resolve. I also cannot reproduce it on Google Colab. There are a lot of issues online about faiss causing segmentation faults, standalone or in combination with sentence-transformers or transformers.

JackMurphy97 commented 5 months ago

Hey @tomaarsen,

Thanks for the response and the link to the related issue, indeed seems like exactly the same problem as others are facing.

Will keep an eye on this thread in case anything comes up

jma7889 commented 5 months ago

@tomaarsen I had similar issue after did a poetry update. I have to stay with the 2.2.2 and older versions of transformers and torch. After upgrading sentence-transformer, it gave me segmentation crash. Only downgrading the sentence-transformers and transformers would not solved the issue though. Might relates to torch or even more packages. If you need a working project.toml and poetry.lock, I can share them with you.

bdeck8317 commented 1 month ago

Any further updates on this front? I am also having faiss and sentence transformers issues.

tomaarsen commented 1 month ago

Following https://github.com/facebookresearch/faiss/issues/2099, it might be worth a shot to install faiss-cpu 1.6.5 or 1.7.0?

It's likely a compatibility issue between faiss-cpu and torch, as those are the only related packages that interact on the C-level, i.e. where Segmentation Faults can occur.