mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 19:06:11 +00:00
Select native macOS model builds
This commit is contained in:
@@ -37,6 +37,7 @@ import shutil
|
|||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@@ -220,8 +221,15 @@ def _has_vulkan():
|
|||||||
|
|
||||||
|
|
||||||
def _wanted_assets(program):
|
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()
|
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():
|
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-vulkan-{arch}.tar.gz", f"bin-ubuntu-{arch}.tar.gz")
|
||||||
return (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:
|
if item:
|
||||||
break
|
break
|
||||||
if item is None:
|
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.",
|
raise LocalError(t("{repo} {tag} has no build for this machine.",
|
||||||
repo=program.repo, tag=tag))
|
repo=program.repo, tag=tag))
|
||||||
|
|
||||||
|
|||||||
+20
-1
@@ -176,6 +176,9 @@ class Download(Local):
|
|||||||
class InstallProgram(Local):
|
class InstallProgram(Local):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
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
|
# Built once, because the release listing has to publish its checksum
|
||||||
# and a tarball is not the same bytes twice.
|
# and a tarball is not the same bytes twice.
|
||||||
self.archive = tarball({
|
self.archive = tarball({
|
||||||
@@ -216,6 +219,23 @@ class InstallProgram(Local):
|
|||||||
ggml.install_program(ggml.WHISPER)
|
ggml.install_program(ggml.WHISPER)
|
||||||
self.assertIn("this machine", str(caught.exception))
|
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):
|
def test_what_was_installed_is_remembered(self):
|
||||||
path, _ = self.install("whisper-bin-ubuntu-x64.tar.gz")
|
path, _ = self.install("whisper-bin-ubuntu-x64.tar.gz")
|
||||||
self.assertEqual(ggml.installed_program(ggml.WHISPER), path)
|
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(512), "512 B")
|
||||||
self.assertEqual(ggml.human_size(574041195), "547.4 MB")
|
self.assertEqual(ggml.human_size(574041195), "547.4 MB")
|
||||||
self.assertEqual(ggml.human_size(3_095_033_483), "2.9 GB")
|
self.assertEqual(ggml.human_size(3_095_033_483), "2.9 GB")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user