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 flag to disable macOS Metal for llama.cpp when running builds

davidmezzetti7f241b0f04b0
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index ae2ac5d8..bb3f574c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -41,6 +41,7 @@ jobs:
run: |
echo "OMP_NUM_THREADS=1" >> $GITHUB_ENV
echo "PYTORCH_MPS_DISABLE=1" >> $GITHUB_ENV
+ echo "LLAMA_NO_METAL=1" >> $GITHUB_ENV
echo "ACCELERATE_USE_CPU=1" >> $GITHUB_ENV
echo "TIKA_STARTUP_SLEEP=30" >> $GITHUB_ENV
echo "TIKA_STARTUP_MAX_RETRY=10" >> $GITHUB_ENV
diff --git a/src/python/txtai/pipeline/llm/llama.py b/src/python/txtai/pipeline/llm/llama.py
index e590e4ad..52566242 100644
--- a/src/python/txtai/pipeline/llm/llama.py
+++ b/src/python/txtai/pipeline/llm/llama.py
@@ -46,7 +46,7 @@ class LlamaCpp(Generation):
path = path if os.path.exists(path) else self.download(path)
# Default GPU layers if not already set
- kwargs["n_gpu_layers"] = kwargs.get("n_gpu_layers", -1 if kwargs.get("gpu", True) else 0)
+ kwargs["n_gpu_layers"] = kwargs.get("n_gpu_layers", -1 if kwargs.get("gpu", os.environ.get("LLAMA_NO_METAL") != "1") else 0)
# Create llama.cpp instance
self.llm = Llama(path, verbose=kwargs.pop("verbose", False), **kwargs)
diff --git a/src/python/txtai/vectors/llama.py b/src/python/txtai/vectors/llama.py
index 404ce795..11eaf4ee 100644
--- a/src/python/txtai/vectors/llama.py
+++ b/src/python/txtai/vectors/llama.py
@@ -53,7 +53,7 @@ class LlamaCpp(Vectors):
modelargs = self.config.get("vectors", {})
# Default GPU layers if not already set
- modelargs["n_gpu_layers"] = modelargs.get("n_gpu_layers", -1 if self.config.get("gpu", True) else 0)
+ modelargs["n_gpu_layers"] = modelargs.get("n_gpu_layers", -1 if modelargs.get("gpu", os.environ.get("LLAMA_NO_METAL") != "1") else 0)
# Create llama.cpp instance
return Llama(path, verbose=modelargs.pop("verbose", False), embedding=True, **modelargs)