Open gordonhart opened 6 days ago
Hey @gordonhart! 👋 I'm here to help you with any bugs, questions, or contributions you have in mind. If you need assistance, feel free to reach out to me.
To resolve the segmentation fault on MacOS when using HuggingFaceEmbedding
with FAISS, you can try setting the device
to cpu
explicitly. This can help avoid issues related to GPU usage which might be causing the segmentation fault. Here is a minimal script to demonstrate this:
import faiss
from llama_index.legacy.embeddings.huggingface import HuggingFaceEmbedding
# Initialize the HuggingFaceEmbedding with device set to 'cpu'
embedding_model = HuggingFaceEmbedding(
model_name="BAAI/bge-small-en-v1.5",
device="cpu"
)
print("success")
In this script, the device
parameter is explicitly set to "cpu"
when initializing the HuggingFaceEmbedding
class. This should help in avoiding segmentation faults related to GPU issues on MacOS [1].
To continue talking to Dosu, mention @dosu.
@dosu adding device="cpu"
to the HuggingFaceEmbedding
initialization did not fix the issue.
If setting the device
to "cpu"
did not resolve the issue, you can try the following steps to address the segmentation fault:
Check Library Versions: Ensure you are using compatible versions of the faiss-cpu
, torch
, and transformers
libraries. The recommended versions are:
faiss-cpu
: 1.7.3torch
: 1.13.1transformers
: 4.25.1You can install these specific versions using the following commands:
pip install faiss-cpu==1.7.3
pip install torch==1.13.1
pip install transformers==4.25.1
Update Dependencies: Ensure all your dependencies are up to date and compatible with each other. You can update your dependencies using:
pip install --upgrade faiss-cpu torch transformers
Environment Testing: Try running your script in a different environment, such as a Linux-based system, to rule out any specific incompatibilities with your current MacOS setup.
Enable Debugging: Enable DEBUG
logging level in your application to get more detailed error messages and tracebacks. This can provide more clues as to what might be causing the segmentation fault.
If the issue persists, you might want to check for any known compatibility issues between FAISS and the transformers
library on MacOS. There is a documented issue related to FAISS on MacOS where a user encountered a TypeError
when running the FAISS example notebook [1].
By following these steps, you should be able to identify and resolve the segmentation fault issue.
To continue talking to Dosu, mention @dosu.
Bug Description
Seeing segmentation fault when running a minimal script with HuggingFaceEmbedding and FAISS. A simple
import faiss
is enough to trigger the failure in a new environment with nothing butllama-index-embeddings-huggingface
andfaiss-cpu
installed.Contents of
example.py
:As far as I can tell, the specific model passed to
HuggingFaceEmbedding
does not have an impact.Potentially related to #9949, though that issue does not appear to relate to FAISS.
Version
0.10.51
Steps to Reproduce
From a fresh directory:
poetry init
with Python 3.12 and click through init menupoetry add llama-index-embeddings-huggingface faiss-cpu
poetry run python3 example.py
(see contents of this file above)Output:
If you remove the
import faiss
line fromexample.py
, the output is as expected:Relevant Logs/Tracebacks
With
DEBUG
logging enabled: