From a79c511b05989bc63a0be2ffdba1977d887dda2d Mon Sep 17 00:00:00 2001 From: lexgenius Date: Sun, 12 Apr 2026 05:24:29 +0000 Subject: [PATCH] feat: add macOS Metal GPU detection for local embeddings --- execute.py | 8 ++++++++ helpers/qmd_client.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/execute.py b/execute.py index 2a097b8..ff3ebb3 100644 --- a/execute.py +++ b/execute.py @@ -74,6 +74,14 @@ def _detect_gpu_backend() -> str: if lib_ok and icd_ok: return "vulkan" + # ── Apple Metal (macOS) ─────────────────────────────────────────────────── + # Metal is available on all Apple Silicon (M1+) and most modern Intel Macs. + # node-llama-cpp supports Metal natively — just needs NODE_LLAMA_CPP_GPU=metal. + if sys.platform == "darwin": + metal_framework = Path("/System/Library/Frameworks/Metal.framework") + if metal_framework.exists(): + return "metal" + # ── CPU fallback ────────────────────────────────────────────────────────── # "false" tells node-llama-cpp: use CPU only, do NOT attempt to build any # GPU backend from source. This avoids the CMake Vulkan errors entirely. diff --git a/helpers/qmd_client.py b/helpers/qmd_client.py index 1a970c2..932ba6f 100644 --- a/helpers/qmd_client.py +++ b/helpers/qmd_client.py @@ -18,6 +18,7 @@ import json import math import os +import sys import subprocess import threading from pathlib import Path @@ -180,6 +181,14 @@ def _detect_gpu_backend() -> str: if lib_ok and icd_ok: return "vulkan" + # ── Apple Metal (macOS) ─────────────────────────────────────────────────── + # Metal is available on all Apple Silicon (M1+) and most modern Intel Macs. + # node-llama-cpp supports Metal natively — just needs NODE_LLAMA_CPP_GPU=metal. + if sys.platform == "darwin": + metal_framework = Path("/System/Library/Frameworks/Metal.framework") + if metal_framework.exists(): + return "metal" + # ── CPU fallback ────────────────────────────────────────────────────────── return "false"