💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Add KMP_DUPLICATE_OK workaround for Faiss OMP Error #1009
davidmezzetticeb7a4a8f865
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex a720eae8..080981e1 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -35,12 +35,10 @@ jobs:- name: Install dependencies - macOSrun: |- echo "OMP_NUM_THREADS=1" >> $GITHUB_ENVecho "PYTORCH_MPS_DISABLE=1" >> $GITHUB_ENVecho "LLAMA_NO_METAL=1" >> $GITHUB_ENVecho "TIKA_STARTUP_SLEEP=30" >> $GITHUB_ENVecho "TIKA_STARTUP_MAX_RETRY=10" >> $GITHUB_ENV- echo "KMP_DUPLICATE_LIB_OK=TRUE" >> $GITHUB_ENVbrew install portaudiosudo xcode-select -s "/Applications/Xcode_16.app"if: matrix.os == 'macos-latest'diff --git a/docs/faq.md b/docs/faq.mdindex ec560985..0ff2ab61 100644--- a/docs/faq.md+++ b/docs/faq.md@@ -105,9 +105,10 @@ __Solution__Set the following environment parameters.-- OpenMP threading is handled internally on macOS platforms but it can be disabled via `export OMP_NUM_THREADS=1`+- Disable OpenMP multithreading via `export OMP_NUM_THREADS=1`- Disable PyTorch MPS device via `export PYTORCH_MPS_DISABLE=1`- Disable llama.cpp metal via `export LLAMA_NO_METAL=1`+- Workaround `OMP: Error #15` errors via `export KMP_DUPLICATE_LIB_OK=TRUE`For more details, refer to [this issue on GitHub](https://github.com/kyamagu/faiss-wheels/issues/100).diff --git a/src/python/txtai/ann/dense/faiss.py b/src/python/txtai/ann/dense/faiss.pyindex 9ac427f6..565caad2 100644--- a/src/python/txtai/ann/dense/faiss.py+++ b/src/python/txtai/ann/dense/faiss.py@@ -4,17 +4,23 @@ Faiss moduleimport mathimport platform+import osimport numpy as np+# pylint: disable=C0413+if platform.system() == "Darwin" or os.name == "nt":+ # Workaround for a Faiss issue with OMP: Error #15+ os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"+from faiss import omp_set_num_threadsfrom faiss import index_factory, IO_FLAG_MMAP, METRIC_INNER_PRODUCT, read_index, write_indexfrom faiss import index_binary_factory, read_index_binary, write_index_binary, IndexBinaryIDMapfrom ..base import ANN-if platform.system() == "Darwin":- # Workaround for a Faiss issue causing segmentation faults on macOS. See txtai FAQ for more.+if platform.system() == "Darwin" or os.name == "nt":+ # Workaround for a Faiss issue causing segmentation faults. See txtai FAQ for more.omp_set_num_threads(1)