From b0d360dc46facd62b0473f62eb32de2d14b3ecad Mon Sep 17 00:00:00 2001 From: Salah Eddine Bekhouche Date: Tue, 24 Nov 2026 07:31:26 +0200 Subject: [PATCH] Detect the Apple GPU as an integrated GPU Lemonade reports an Apple GPU under devices.metal, which LemonMatrix did not read. A Mac therefore looked like a CPU-only machine, so every llamacpp-metal run was refused, and a forced run was always marked invalid. 1) available_compute_engines counts an available metal device as igpu, since Apple silicon shares memory with the CPU; 2) profile discovery records the metal device as the profile's igpu and takes its driver version; 3) both changes sit in the shared checks, so every modality that validates its engine and backend (model, speech, image, audio, embeddings, rerank, classify, 3D, omni) accepts a -metal backend; 4) the README describes the Apple silicon case, and CI runs the tests on macOS as well as Linux. Tested with the real devices block of an Apple M5 running Lemonade 2026.47.1, and with live runs on that machine (model, embeddings, speech and text-to-speech), whose results pass validate-submission. Fixes #4. --- .github/workflows/tests.yml | 7 ++++++- README.md | 13 ++++++++++++ src/lemonmatrix/capabilities.py | 5 ++++- src/lemonmatrix/profile.py | 14 +++++++++++++ tests/test_capabilities.py | 27 ++++++++++++++++++++++++ tests/test_profile_real_shape.py | 36 ++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ec96130..f8cb5cb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,10 +7,15 @@ on: jobs: test: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: + os: [ubuntu-latest] python-version: ["3.10", "3.11", "3.12"] + include: + # Apple silicon: the Metal device detection and macOS paths. + - os: macos-latest + python-version: "3.12" steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index 6e8f2da..f2bbf29 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,19 @@ omni model's components count as the run's own models; anything else loaded makes the run invalid, as for every other run. Results go to `results//omni/`. +## Apple silicon + +Lemonade reports an Apple GPU as a `metal` device. It shares memory with the +CPU, so LemonMatrix treats it as an integrated GPU: use `--engine igpu` with a +`-metal` backend (`llamacpp-metal`, `whispercpp-metal`, `sd-cpp-metal`): + +```bash +lemonmatrix run --profile my-mac \ + --model Qwen3-1.7B-GGUF --model-class dense --quant Q4_0 \ + --context-length 4096 --engine igpu --backend llamacpp-metal \ + --power-state plugged +``` + ## Ryzen AI NPU and hybrid runs Lemonade's `ryzenai-llm` recipe has one backend, `ryzenai-llm-npu`, and the diff --git a/src/lemonmatrix/capabilities.py b/src/lemonmatrix/capabilities.py index 21b4cad..4a03677 100644 --- a/src/lemonmatrix/capabilities.py +++ b/src/lemonmatrix/capabilities.py @@ -289,8 +289,11 @@ def available_compute_engines(system_info: dict) -> list[str]: has_igpu = any(g.get("available") and is_integrated_gpu(g) for g in amd_gpus) has_amd_dgpu = any(g.get("available") and not is_integrated_gpu(g) for g in amd_gpus) has_nvidia_dgpu = any(g.get("available") for g in _as_list(devices.get("nvidia_gpu"))) + # Apple silicon: Lemonade reports the GPU under "metal". It shares memory + # with the CPU, so it counts as an integrated GPU. + has_metal_igpu = any(g.get("available") for g in _as_list(devices.get("metal"))) - if has_igpu: + if has_igpu or has_metal_igpu: engines.append("igpu") if has_amd_dgpu or has_nvidia_dgpu: engines.append("dgpu") diff --git a/src/lemonmatrix/profile.py b/src/lemonmatrix/profile.py index cce8acf..f87379c 100644 --- a/src/lemonmatrix/profile.py +++ b/src/lemonmatrix/profile.py @@ -16,6 +16,8 @@ rather than crashing. Callers can override anything discovery got wrong via CLI flags. Each amd_gpu entry carries an "integrated" flag (seen on 11.6 and on 2026.47); see is_integrated_gpu below for the fallback when it is absent. +On Apple silicon (Lemonade 2026.47.1, macOS 26) the GPU is a "metal" entry +under "devices"; it is treated as an integrated GPU. """ from __future__ import annotations @@ -121,6 +123,18 @@ def _classify_gpus(devices: dict) -> tuple[str | None, str | None, str | None, s igpu_families.append(family) driver_version = driver_version or gpu.get("driver_version") + # Apple silicon reports its GPU under "metal". It shares memory with the + # CPU, so it is an integrated GPU. + metal_gpus = devices.get("metal") or [] + if isinstance(metal_gpus, dict): + metal_gpus = [metal_gpus] + for gpu in metal_gpus: + name = gpu.get("name") + if not gpu.get("available", True) or not name: + continue + igpu_names.append(name) + driver_version = driver_version or gpu.get("driver_version") + nvidia_gpus = devices.get("nvidia_gpu") or [] if isinstance(nvidia_gpus, dict): nvidia_gpus = [nvidia_gpus] diff --git a/tests/test_capabilities.py b/tests/test_capabilities.py index 2e735b9..35db97f 100644 --- a/tests/test_capabilities.py +++ b/tests/test_capabilities.py @@ -187,3 +187,30 @@ def test_parse_quantization_keeps_plain_and_custom_variants(): def test_parse_quantization_returns_nothing_for_onnx_npu_checkpoints(): assert parse_quantization("AMD-OLMo-1B-SFT-DPO-Hybrid", "amd/AMD-OLMo-1B-SFT-DPO-onnx-ryzenai-1.7-hybrid") == "" + + +# Real devices block from Lemonade 2026.47.1 on a MacBook with an Apple M5. +APPLE_SYSTEM_INFO = { + "devices": { + "amd_gpu": [], + "amd_npu": {"available": False, "name": "Apple M5"}, + "cpu": {"available": True, "name": "Apple M5", "family": "arm64"}, + "metal": { + "available": True, + "driver_version": "Metal", + "family": "metal", + "name": "Apple M5", + "vram_gb": 24.96, + }, + "nvidia_gpu": [{"available": False, "name": ""}], + }, +} + + +def test_available_compute_engines_treats_apple_metal_as_igpu(): + assert available_compute_engines(APPLE_SYSTEM_INFO) == ["cpu", "igpu"] + + +def test_available_compute_engines_ignores_unavailable_metal(): + info = {"devices": {"cpu": {"available": True}, "metal": {"available": False, "name": ""}}} + assert available_compute_engines(info) == ["cpu"] diff --git a/tests/test_profile_real_shape.py b/tests/test_profile_real_shape.py index d9bbcbf..72c5cbd 100644 --- a/tests/test_profile_real_shape.py +++ b/tests/test_profile_real_shape.py @@ -99,3 +99,39 @@ def test_discover_environment_ignores_unavailable_npu_with_bogus_name(): # field with the CPU name -- must not be mistaken for a real NPU. environment, _ = discover_environment(_StubClient(REAL_SYSTEM_INFO, REAL_HEALTH)) assert "npu" not in environment + + +APPLE_SYSTEM_INFO = { + "OS Version": "macOS 26.7.3 Darwin Kernel Version 25.6.0", + "Physical Memory": "32 GB", + "Processor": "Apple M5", + "devices": { + "amd_gpu": [], + "amd_npu": { + "available": False, + "error": "NPU not supported on macOS (Ryzen AI NPUs are Windows/Linux only)", + "family": "", + "name": "Apple M5", + "utilization": 0.0, + }, + "cpu": {"available": True, "cores": 10, "family": "arm64", "name": "Apple M5", "threads": 10}, + "metal": { + "available": True, + "driver_version": "Metal", + "family": "metal", + "name": "Apple M5", + "vram_gb": 24.96, + }, + "nvidia_gpu": [{"available": False, "error": "NVIDIA GPUs not detected on macOS", "name": ""}], + }, +} + +APPLE_HEALTH = {"status": "ok", "version": "2026.47.1", "model_loaded": None, "all_models_loaded": []} + + +def test_discover_environment_reports_apple_metal_gpu_as_igpu(): + environment, _ = discover_environment(_StubClient(APPLE_SYSTEM_INFO, APPLE_HEALTH)) + assert environment["igpu"] == "Apple M5" + assert "dgpu" not in environment + assert environment["driver_version"] == "Metal" + assert environment["lemonade_version"] == "2026.47.1"