💡 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 env variable to disable macOS MPS devices, closes #592
davidmezzettie7552a62cce9
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 43bef525..57283548 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -40,6 +40,7 @@ jobs:- name: Install dependencies - macOSrun: |echo "OMP_NUM_THREADS=1" >> $GITHUB_ENV+ echo "PYTORCH_MPS_DISABLE=1" >> $GITHUB_ENVif: matrix.os == 'macos-latest'- name: Install dependencies - Windowsdiff --git a/src/python/txtai/models/models.py b/src/python/txtai/models/models.pyindex 267884b3..c3f50c59 100644--- a/src/python/txtai/models/models.py+++ b/src/python/txtai/models/models.py@@ -132,7 +132,7 @@ class Models:else f"cuda:{deviceid}"if torch.cuda.is_available()else "mps"- if torch.backends.mps.is_available()+ if Models.hasmpsdevice()else Models.finddevice())@@ -145,7 +145,18 @@ class Models:True if an accelerator device is available, False otherwise"""- return torch.cuda.is_available() or torch.backends.mps.is_available() or bool(Models.finddevice())+ return torch.cuda.is_available() or Models.hasmpsdevice() or bool(Models.finddevice())++ @staticmethod+ def hasmpsdevice():+ """+ Checks if there is a MPS device available.++ Returns:+ True if a MPS device is available, False otherwise+ """++ return os.environ.get("PYTORCH_MPS_DISABLE") != "1" and torch.backends.mps.is_available()@staticmethoddef finddevice():