From fa14ec90f4ec302a86c605a8466bd64702ec567f Mon Sep 17 00:00:00 2001 From: firat Date: Mon, 3 Aug 2026 17:53:20 +0200 Subject: [PATCH] Select native macOS model builds --- ggml.py | 15 ++++++++++++++- tests/test_ggml.py | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ggml.py b/ggml.py index d8778b5..5ba85a7 100644 --- a/ggml.py +++ b/ggml.py @@ -37,6 +37,7 @@ import shutil import signal import socket import subprocess +import sys import tarfile import threading import time @@ -220,8 +221,15 @@ def _has_vulkan(): def _wanted_assets(program): - """Asset name endings to accept, best first.""" + """Asset name endings to accept, best first. + + llama.cpp publishes native Metal-enabled macOS archives. whisper.cpp does + not publish a runnable macOS server archive, so an arm64 Mac must not + mistake Ubuntu's arm64 archive for a native build. + """ arch = _arch() + if sys.platform == "darwin": + return () if program is WHISPER else (f"bin-macos-{arch}.tar.gz",) if program is LLAMA and _has_vulkan(): return (f"bin-ubuntu-vulkan-{arch}.tar.gz", f"bin-ubuntu-{arch}.tar.gz") return (f"bin-ubuntu-{arch}.tar.gz",) @@ -311,6 +319,11 @@ def install_program(program, tag="", on_progress=None, should_stop=None, if item: break if item is None: + if sys.platform == "darwin" and program is WHISPER: + raise LocalError(t( + "whisper.cpp publishes no macOS build. Install it with: " + "brew install whisper-cpp" + )) raise LocalError(t("{repo} {tag} has no build for this machine.", repo=program.repo, tag=tag)) diff --git a/tests/test_ggml.py b/tests/test_ggml.py index 548d4c3..161e688 100644 --- a/tests/test_ggml.py +++ b/tests/test_ggml.py @@ -176,6 +176,9 @@ class Download(Local): class InstallProgram(Local): def setUp(self): super().setUp() + # These fixtures are Ubuntu release archives. Keep checking that path + # on every host, including the Mac that checks the macOS backend. + self.patch_attr(sys, "platform", "linux") # Built once, because the release listing has to publish its checksum # and a tarball is not the same bytes twice. self.archive = tarball({ @@ -216,6 +219,23 @@ class InstallProgram(Local): ggml.install_program(ggml.WHISPER) self.assertIn("this machine", str(caught.exception)) + def test_a_mac_does_not_install_an_ubuntu_archive_for_the_same_architecture(self): + self.patch_attr(sys, "platform", "darwin") + self.patch_attr(ggml, "_arch", lambda: "arm64") + listing = self.release("whisper-bin-ubuntu-arm64.tar.gz") + with fake_urlopen(listing): + with self.assertRaises(ggml.LocalError) as caught: + ggml.install_program(ggml.WHISPER) + self.assertIn("brew install whisper-cpp", str(caught.exception)) + + def test_a_mac_uses_the_native_llama_archive_instead_of_ubuntu(self): + self.patch_attr(sys, "platform", "darwin") + self.patch_attr(ggml, "_arch", lambda: "arm64") + self.assertEqual( + ggml._wanted_assets(ggml.LLAMA), + ("bin-macos-arm64.tar.gz",), + ) + def test_what_was_installed_is_remembered(self): path, _ = self.install("whisper-bin-ubuntu-x64.tar.gz") self.assertEqual(ggml.installed_program(ggml.WHISPER), path) @@ -661,4 +681,3 @@ class Sizes(DikteTest): self.assertEqual(ggml.human_size(512), "512 B") self.assertEqual(ggml.human_size(574041195), "547.4 MB") self.assertEqual(ggml.human_size(3_095_033_483), "2.9 GB") -