Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add KMP_DUPLICATE_OK workaround for Faiss OMP Error #1009

davidmezzetticeb7a4a8f865
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a720eae8..080981e1 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -35,12 +35,10 @@ jobs:
- name: Install dependencies - macOS
run: |
- echo "OMP_NUM_THREADS=1" >> $GITHUB_ENV
echo "PYTORCH_MPS_DISABLE=1" >> $GITHUB_ENV
echo "LLAMA_NO_METAL=1" >> $GITHUB_ENV
echo "TIKA_STARTUP_SLEEP=30" >> $GITHUB_ENV
echo "TIKA_STARTUP_MAX_RETRY=10" >> $GITHUB_ENV
- echo "KMP_DUPLICATE_LIB_OK=TRUE" >> $GITHUB_ENV
brew install portaudio
sudo xcode-select -s "/Applications/Xcode_16.app"
if: matrix.os == 'macos-latest'
diff --git a/docs/faq.md b/docs/faq.md
index 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.py
index 9ac427f6..565caad2 100644
--- a/src/python/txtai/ann/dense/faiss.py
+++ b/src/python/txtai/ann/dense/faiss.py
@@ -4,17 +4,23 @@ Faiss module
import math
import platform
+import os
import 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_threads
from faiss import index_factory, IO_FLAG_MMAP, METRIC_INNER_PRODUCT, read_index, write_index
from faiss import index_binary_factory, read_index_binary, write_index_binary, IndexBinaryIDMap
from ..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)