From cf4749276dabc39a415df46895e4af0623e04dd9 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 19 Oct 2026 20:59:29 +0200 Subject: [PATCH 1/2] Mac pictures: strata-vision with Metal built in, Mac setup and launch turn pictures on tools/vision builds one program for the Mac: ggml's Metal backend inside, --gpu reads on the GPU, without it on the CPU. The reader choice (strata_control/vision_reader.py) gives a Mac the GPU reader whatever its memory (the CPU reader needs ~50 s per picture: ggml has no BF16 vector kernel on ARM). setup.py's Mac path downloads the mmproj and writes the vision section; strata launch, the MCP server and metal/setup_mac.py default pictures on. packaging/build_vision_mac.sh builds the program for the engine package. --- metal/setup_mac.py | 16 ++++++--- packaging/build_vision_mac.sh | 38 +++++++++++++++++++++ setup.py | 59 +++++++++++++++++++++++++++++++-- strata_cli/launch/catalog.py | 10 ++++-- strata_control/vision_reader.py | 43 ++++++++++++++++++------ tests/terminal/test_launch.py | 17 ++++++++++ tools/strata_mcp.py | 9 ++--- tools/test_picture_defaults.py | 24 ++++++++++++++ tools/test_strata_mcp.py | 5 ++- tools/test_vision_reader.py | 42 +++++++++++++++++++++++ tools/vision/CMakeLists.txt | 13 ++++++++ tools/vision/strata_vision.cpp | 19 +++++++++++ 12 files changed, 271 insertions(+), 24 deletions(-) create mode 100644 packaging/build_vision_mac.sh diff --git a/metal/setup_mac.py b/metal/setup_mac.py index 1d4717ad..4d255446 100644 --- a/metal/setup_mac.py +++ b/metal/setup_mac.py @@ -176,7 +176,7 @@ def build_vision(llama: Path) -> Path: with open(log, "w", encoding="utf-8") as f: for cmd in ([tool("cmake"), "-S", str(ROOT / "tools" / "vision"), "-B", str(ROOT / "build-vision"), "-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release", f"-DCMAKE_MAKE_PROGRAM={tool('ninja')}", f"-DLLAMA_DIR={llama}", - "-DSTRATA_VISION_CUDA=OFF", "-DSTRATA_PORTABLE=OFF"], + "-DSTRATA_VISION_CUDA=OFF", "-DSTRATA_VISION_METAL=ON", "-DSTRATA_PORTABLE=OFF"], [tool("ninja"), "-C", str(ROOT / "build-vision"), "strata-vision"]): if subprocess.call(cmd, stdout=f, stderr=subprocess.STDOUT, env=env) != 0: S.fail(f"the image encoder did not build (see {log})") @@ -343,8 +343,9 @@ def main(argv=None) -> int: ap.add_argument("--check", action="store_true") ap.add_argument("--update", action="store_true") ap.add_argument("--build", action="store_true", help="build the engine again even when it is current") - ap.add_argument("--vision", choices=["yes", "no"], - help="let the model read images (the image encoder on the GPU, built here; default: asked, no)") + ap.add_argument("--vision", choices=["yes", "no", "gpu", "cpu"], + help="let the model read images (the image encoder, built here; yes = gpu: it reads on the Mac's GPU, cpu is ~100x " + "slower; default: asked, yes)") a, rest = ap.parse_known_args(argv) if rest: S.warn("not used on a Mac: " + " ".join(rest)) @@ -394,7 +395,12 @@ def main(argv=None) -> int: for n in model_note(model, info["ram_gb"]): S.warn(n) vision = a.vision or ("yes" if S.ask("Should the model also read images? (the image encoder, ~1 GB more)", - ["y", "n"], "n", a.yes) == "y" else "no") + ["y", "n"], "y", a.yes) == "y" else "no") # on by default (strata_control/vision_reader.py) + if vision == "cpu": + from strata_control import vision_reader as VR + S.warn(VR.MAC_CPU_NOTE) + vision_gpu = vision != "cpu" + vision = "no" if vision == "no" else "yes" ctx = a.context or recommend_context(info["ram_gb"]) if ctx > TESTED_CONTEXT: S.say(f" context {ctx}: measured on the Mac up to {TESTED_CONTEXT} (needles found at 8K-32K); longer is kept") @@ -519,7 +525,7 @@ def main(argv=None) -> int: cfg["env"] = {"STRATA_METAL_STREAM": "1" if stream else "0"} # the engine follows setup's measured choice if vision == "yes": cfg["args"] += ["--vision"] - cfg["vision"] = {"exe": str(vexe), "mmproj": str(mmproj), "model": str(files[0]), "gpu": True, + cfg["vision"] = {"exe": str(vexe), "mmproj": str(mmproj), "model": str(files[0]), "gpu": vision_gpu, "max_tokens": 1024} if a.host: cfg["host"] = a.host diff --git a/packaging/build_vision_mac.sh b/packaging/build_vision_mac.sh new file mode 100644 index 00000000..f3544df1 --- /dev/null +++ b/packaging/build_vision_mac.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# packaging/build_vision_mac.sh - the picture reader for the Mac engine package: strata-vision for macOS arm64, with ggml's Metal +# backend built in (`--gpu` reads pictures on the Mac's GPU, without it on the CPU). One program for both: Apple Silicon always has +# the Metal framework, the Metal engine needs it too. It is built against the llama.cpp commit the engine is pinned to. +# +# packaging/build_vision_mac.sh --llama --out [--build ] [--jobs N] +# +# /strata-vision is the program; copy it beside `strata` in the engine package's --src before packaging/package_engine.py +# (`strata-vision` is one of the files it takes) and sign it with the rest (packaging/mac/sign-and-notarize.sh signs every Mach-O). +# Needs cmake and ninja on PATH and the Command Line Tools. The build is portable (no -march: it runs on an M1 as on an M5). +set -euo pipefail +here="$(cd "$(dirname "$0")" && pwd)" +llama="" out="" build="" jobs="" +while [ $# -gt 0 ]; do + case "$1" in + --llama) llama="$2"; shift 2 ;; + --out) out="$2"; shift 2 ;; + --build) build="$2"; shift 2 ;; + --jobs) jobs="$2"; shift 2 ;; + *) echo "unknown argument $1" >&2; exit 2 ;; + esac +done +[ -n "$llama" ] && [ -n "$out" ] || { echo "usage: $0 --llama --out [--build ] [--jobs N]" >&2; exit 2; } +[ "$(uname -s)" = Darwin ] && [ "$(uname -m)" = arm64 ] || { echo "this builds on an Apple Silicon Mac" >&2; exit 1; } +build="${build:-$out/build-vision}" +mkdir -p "$out" +cmake -S "$here/../tools/vision" -B "$build" -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLAMA_DIR="$llama" \ + -DSTRATA_PORTABLE=ON -DSTRATA_VISION_METAL=ON -DSTRATA_VISION_CUDA=OFF +ninja -C "$build" ${jobs:+-j "$jobs"} strata-vision +cp "$build/bin/strata-vision" "$out/strata-vision" +echo "built: $out/strata-vision" +# what it links: only Apple's own libraries (binary_deps.py in the package step checks the same) +otool -L "$out/strata-vision" | tail -n +2 | awk '{print " " $1}' +if otool -L "$out/strata-vision" | tail -n +2 | awk '{print $1}' | grep -vE '^(/usr/lib/|/System/Library/)' ; then + echo "refusing: the reader links a library that is not part of macOS" >&2 + exit 1 +fi +"$out/strata-vision" --version diff --git a/setup.py b/setup.py index c7a2d32a..d501ba30 100644 --- a/setup.py +++ b/setup.py @@ -6945,6 +6945,35 @@ def preview_family(a) -> int: return 0 +def mac_vision(asked, model: str, ram: float) -> str: + """The picture setting of a Mac's setup: "gpu", "cpu" or "none". Pictures are on wherever the model can read them (owner rule + 2026-10-18) and the reader follows strata_control/vision_reader.py: on a Mac, the GPU (Metal) reader, because the memory is shared + (no card to keep free) and the CPU reader is ~100x slower. --vision cpu is kept, with a note (recommend, never force).""" + from strata_control import vision_reader as VR + if asked in ("no", "none", "off"): + return "none" + if asked is None and not images_default(model, "qwen", ram): + return "none" + if MODELS.get(model, {}).get("vision") is False: + if asked is not None: + warn(f"images are not available with {model} yet: off") + return "none" + mode = VR.wanted(asked, None, unified=True) + if mode == "cpu": + warn(VR.MAC_CPU_NOTE) + return mode + + +def mac_reader(eng: Path, vision: str): + """The picture reader the Mac engine folder carries (strata-vision: Metal built in), for `vision` "gpu" or "cpu". A folder + without it gets pictures off, said once.""" + from strata_control import vision_reader as VR + r = VR.choose(eng, vision, windows=False, mac=True) + if r.mode == "none": + warn(r.note or "this engine has no picture reader: pictures off") + return r + + def mac_control_setup(a) -> int: """The app (and the Terminal's `strata launch`) on a Mac, STRATA_CONTROL_INSTALL=1: the same job as on Windows and Linux. It downloads and prepares the model files and writes a run config whose engine is "component:strata-engine"; it builds nothing @@ -6983,8 +7012,7 @@ def mac_control_setup(a) -> int: fail(f"{model} is not offered on a Mac in the app", "choose one of: " + ", ".join(app_sizes)) for n in MF.model_note(model, ram): warn(n) - if a.vision in ("yes", "gpu", "cpu"): - warn("the Mac engine has no picture reader yet: images off for this model (text works as usual)") + vision = mac_vision(a.vision, model, ram) ctx = a.context or MF.recommend_context(ram) if ctx > MF.TESTED_CONTEXT: say(f" context {ctx}: measured on the Mac up to {MF.TESTED_CONTEXT} (needles found at 8K-32K); longer is kept") @@ -6997,13 +7025,21 @@ def mac_control_setup(a) -> int: from strata_control import engine_component as EC llama = get_llama_cpp() # gguf-py for the preparation tools only: no git, no compiler ok(f"llama.cpp {LLAMA_CPP_COMMIT[:7]} (gguf-py for the preparation tools)") + reader = None try: found = EC.resolve(full=False) ok(f"engine component: {found.version} ({found.platform}-{found.backend})") + if vision != "none": + reader = mac_reader(Path(found.root), vision) + vision = reader.mode except EC.EngineMissing as e: warn(f"no Metal engine is installed for this Mac yet ({e}). The model is downloaded and prepared now; the engine comes " "with the app or its update feed, and is looked up when the model loads") + if vision != "none": + warn("pictures are off for now: the picture reader comes with the engine (run setup again once it is installed)") + vision = "none" ok("engine: the engine component (looked up when the model loads)") + ok("images: " + {"none": "off", "gpu": "on (read on the Mac's GPU)", "cpu": "on (read on the CPU)"}[vision]) step(5, f"downloading {fam['title']} {model}") models_dir = Path(a.gguf_dir) if a.gguf_dir else models_root / tag @@ -7033,6 +7069,18 @@ def mac_control_setup(a) -> int: download(fam["hf"].format(q=model) + s.name, s) check_shards(files) ok("model files present") + mmproj = None + if vision != "none": + mmproj = Path(models_root) / fam["mmproj"] + if not mmproj.exists(): # an earlier install's copy (the same file for every family) + mmproj = find_in(roots, f"models/{fam['mmproj']}") or mmproj + if not mmproj.exists() and a.gguf_dir and (Path(a.gguf_dir) / fam["mmproj"]).exists(): + mmproj = Path(a.gguf_dir) / fam["mmproj"] + elif not (mmproj.exists() and done(mmproj)): + download(fam["mmproj_hf"] + fam["mmproj"], mmproj, "vision encoder") + if fam["mmproj"] in ISTA_FILES: + verify_sha256(mmproj, *ISTA_FILES[fam["mmproj"]]) + ok(f"vision encoder: {mmproj}") step(6, "preparing the model for Strata") pack = find_in(roots, f"packs/{tag.lower()}") or data / "packs" / tag.lower() @@ -7072,6 +7120,13 @@ def mac_control_setup(a) -> int: cfg["draft_vocab"] = a.draft_vocab if a.browser is not None: cfg["open_browser"] = a.browser + if vision != "none": # the Mac's one program reads on the GPU (--gpu) or the CPU (strata_control/vision_reader.py) + from strata_control import vision_reader as VR + cfg["args"].append("--vision") + cfg["vision"] = VR.vision_section(reader, {"exe": str(reader.exe), "mmproj": str(mmproj), "model": str(files[0]), + "gpu": vision == "gpu", "max_tokens": vision_tokens(a.vision_tokens, vision, None)}) + if vision == "cpu": + cfg["vision"]["threads"] = vision_threads() cfg_path = home() / f"strata-{tag.lower()}.json" write_setup_config(cfg_path, cfg) script = write_run_script(tag, cfg_path, port, cfg.get("open_browser") is not False) diff --git a/strata_cli/launch/catalog.py b/strata_cli/launch/catalog.py index 33041493..efd52685 100644 --- a/strata_cli/launch/catalog.py +++ b/strata_cli/launch/catalog.py @@ -420,12 +420,18 @@ class Catalog: def picture_default(self, images: bool) -> str: """The picture setting nobody chose: off for a model that cannot read pictures or an engine without the reader; else on, with the reader the one rule of strata_control/vision_reader.py gives: the CPU reader under 24 GB of graphics memory, the GPU reader from 24 GB, - on every make of card (owner decision 2026-10-18). Without a usable graphics card there is nothing to read on: the CPU reader.""" + on every make of card (owner decision 2026-10-18); on a Mac the Metal reader (unified memory). Without a usable graphics card there is nothing to read on: the CPU reader.""" from strata_control import vision_reader as VR if not images or self.reader_state() == "missing": return "off" + if self.is_mac(): + return VR.default_mode(None, unified=True) # a Mac (unified memory): the Metal reader, nothing to keep free for a card vram = self.computer().main_vram_gb - return VR.default_mode(vram) if vram > 0 else "cpu" # a Mac (unified memory) or no card: nothing to keep free, the CPU reader + return VR.default_mode(vram) if vram > 0 else "cpu" # no usable card: nothing to read on, the CPU reader + + def is_mac(self) -> bool: + """An Apple Silicon Mac: the chip's memory is the system's (the Metal engine; strata_control/vision_reader.py).""" + return self.engine_backend() == "metal" # ---- installed models def installed_configs(self) -> list[dict]: diff --git a/strata_control/vision_reader.py b/strata_control/vision_reader.py index 143445fe..8678d5e3 100644 --- a/strata_control/vision_reader.py +++ b/strata_control/vision_reader.py @@ -1,4 +1,4 @@ -"""Which picture reader an engine folder gets: the GPU one (`strata-vision-hip`, AMD) or the CPU one (`strata-vision`). +"""Which picture reader an engine folder gets: the GPU one (`strata-vision-hip`, AMD; `strata-vision --gpu` on a Mac) or the CPU one (`strata-vision`). An AMD engine package carries two programs for pictures. `strata-vision` is the CPU reader: it needs nothing from the GPU runtime, so it starts on every PC. `strata-vision-hip` is the same reader on the card (llama.cpp's HIP backend), a @@ -7,6 +7,12 @@ reader as its fallback (`vision.cpu_exe`); the server (serve/server.py, Vision) log line, when the GPU reader does not start: the HIP runtime does not load, the card is not one the build has code for (the reader says so before it runs a kernel), or the card is busy. Nothing is asked of the user. +A Mac has one program for both: `strata-vision` is built with Metal, `--gpu` reads on the Mac's GPU and without it on the CPU, so the +CPU reader is the same file and the fallback needs no second program. Unified memory changes the 24 GB rule: nothing is taken from a +separate card, the reader's ~1.1 GB is the mmproj file itself on either side (measured on an M4, footprint 1,050 MB on the CPU, 1,179 MB +on the GPU), and the CPU reader takes ~50 s for a 260-token picture where the GPU one takes 0.45 s (ggml has no BF16 vector kernel on +ARM). So a Mac reads on the GPU unless the person asks for the CPU. + `choose` is the whole decision; setup.py calls it, and tools/test_vision_reader.py checks every branch. """ from __future__ import annotations @@ -24,13 +30,16 @@ GPU_READER = "strata-vision-hip" GPU_MIN_VRAM_GB = 23.5 -def default_mode(vram_gb: float | None) -> str: - """"cpu" or "gpu": the reader an unspecific "pictures on" gets on a card with this much memory (unknown memory: "gpu").""" +def default_mode(vram_gb: float | None, *, unified: bool = False) -> str: + """"cpu" or "gpu": the reader an unspecific "pictures on" gets on a card with this much memory (unknown memory: "gpu"). + unified: a Mac, where the chip's memory is the system's - always "gpu" (see the module doc).""" + if unified: + return "gpu" vram = float(vram_gb or 0.0) return "cpu" if 0 < vram < GPU_MIN_VRAM_GB else "gpu" -def wanted(asked: str | None, vram_gb: float | None) -> str: +def wanted(asked: str | None, vram_gb: float | None, *, unified: bool = False) -> str: """What is wanted for `asked` (None, "yes", "on", "gpu", "cpu", "no"/"none"/"off"): "gpu", "cpu" or "none". Nothing asked and "yes" mean the default for this card; "gpu" and "cpu" are kept as asked.""" a = (asked or "").lower() @@ -38,7 +47,7 @@ def wanted(asked: str | None, vram_gb: float | None) -> str: return "none" if a in ("gpu", "cpu"): return a - return default_mode(vram_gb) + return default_mode(vram_gb, unified=unified) GFX = re.compile(r"gfx[0-9a-f]+", re.IGNORECASE) @@ -47,13 +56,16 @@ def reader_name(base: str, windows: bool) -> str: return base + (".exe" if windows else "") -def find(folder: Path | str, windows: bool) -> dict: - """The readers in an engine folder: {"cpu": Path | None, "gpu": Path | None}.""" +def find(folder: Path | str, windows: bool, *, mac: bool = False) -> dict: + """The readers in an engine folder: {"cpu": Path | None, "gpu": Path | None}. On a Mac (mac=True) `strata-vision` is both: it has + Metal built in and `--gpu` picks the GPU.""" folder = Path(folder) found = {} for key, base in (("cpu", CPU_READER), ("gpu", GPU_READER)): path = folder / reader_name(base, windows) found[key] = path if path.is_file() else None + if mac: + found["gpu"] = found["cpu"] return found @@ -71,16 +83,27 @@ class Reader: note: str = "" # one plain sentence for the setup output when it is not what was asked for -def choose(folder: Path | str, asked: str, *, windows: bool, gpu_arch: str = "", archs: list | None = None) -> Reader: +MAC_CPU_NOTE = ("the picture reader on the CPU takes about 50 seconds for one picture on a Mac (the GPU reader: under a second): kept as " + "you chose; --vision gpu reads on the Mac's GPU") + + +def choose(folder: Path | str, asked: str, *, windows: bool, gpu_arch: str = "", archs: list | None = None, mac: bool = False) -> Reader: """The reader for `asked` ("yes"/"on"/"gpu" = the best the folder has, "cpu", "no"/"none"/"off"). gpu_arch: the card's architecture when setup knows it ("gfx1201"); archs: what the GPU reader was built for (BUILD.json `vision_archs`, else the package's `archs`). A card the build does not list gets the CPU reader here; - when the card is unknown the GPU reader is tried and falls back by itself (see the module doc).""" + when the card is unknown the GPU reader is tried and falls back by itself (see the module doc). + mac: the Mac's one program, `strata-vision`: "gpu" runs it with --gpu and keeps the same file as the CPU reader to fall back on.""" asked = (asked or "").lower() if asked in ("no", "none", "off", ""): return Reader("none") - have = find(folder, windows) + have = find(folder, windows, mac=mac) + if mac: + if have["cpu"] is None: + return Reader("none", note="this engine has no picture reader: pictures off") + if asked == "cpu": + return Reader("cpu", have["cpu"], note=MAC_CPU_NOTE) + return Reader("gpu", have["gpu"], have["cpu"]) if asked == "cpu": if have["cpu"]: return Reader("cpu", have["cpu"]) diff --git a/tests/terminal/test_launch.py b/tests/terminal/test_launch.py index 39e54529..b07b4b7e 100644 --- a/tests/terminal/test_launch.py +++ b/tests/terminal/test_launch.py @@ -333,6 +333,23 @@ class SetupArgs(unittest.TestCase): off = Runner(S.LaunchSettings(family="qwen", model="IQ3_XXS", context=32768, vision="off"), catalog=catalog(NV)) self.assertEqual(off.setup_args()[off.setup_args().index("--vision") + 1], "no") + def test_a_mac_defaults_pictures_to_the_metal_reader_whatever_its_memory(self): + for gb in (16.0, 32.0, 128.0): + hw = {"ram_gb": gb, "os": "Darwin", "cpu": {"avx2": None, "name": "Apple M4"}, + "mac": {"chip": "Apple M4", "macos": "27.2", "unified_gb": gb}, + "gpus": [{"index": 0, "name": "Apple M4", "vendor": "apple", "vram_gb": 0.0, "unified_gb": gb, "usable": True}]} + with Home(): + cat = catalog(hw) + with mock.patch.object(type(cat), "reader_state", lambda self: "present"): + self.assertTrue(cat.is_mac()) + self.assertEqual(cat.picture_default(True), "gpu", gb) + r = Runner(S.LaunchSettings(family="qwen", model="Q2_0", context=32768), catalog=cat) + with mock.patch.object(sys, "platform", "darwin"): + args = r.setup_args() + self.assertEqual(args[args.index("--vision") + 1], "gpu", gb) + with mock.patch.object(type(cat), "reader_state", lambda self: "missing"): + self.assertEqual(cat.picture_default(True), "off") + def test_a_model_that_cannot_read_pictures_stays_off_without_a_question(self): import dataclasses with Home(): diff --git a/tools/strata_mcp.py b/tools/strata_mcp.py index 8780210a..f9ddcc04 100644 --- a/tools/strata_mcp.py +++ b/tools/strata_mcp.py @@ -985,11 +985,12 @@ class Strata: d = models[m] tag = (fd.get("tag", "") + m).lower() sizes.append({"model": m, "about": d["about"], "download_gb": d["download_gb"], "experimental": False, - "images": False, # the app's first release reads no pictures (setup.py's Control mode says so) + "images": d.get("vision", fd.get("vision", True)) is not False, # the Mac engine carries the picture reader (Metal) "ram_needed_gb": d["ram_gb"], "experts_gb": d.get("arena_gb"), "mem_total": False, "memory_gb": round(float(d.get("arena_gb") or d["ram_gb"]) + 1.0, 1), "on_this_pc": self._mac_verdict(m, ram) if ram else None, "installed": tag in have, "id": tag}) - return [{"family": "qwen", "title": fd["title"], "about": fd.get("about"), "experimental": False, "images": False, "sizes": sizes}] + return [{"family": "qwen", "title": fd["title"], "about": fd.get("about"), "experimental": False, + "images": any(x["images"] for x in sizes), "sizes": sizes}] def recommend(self, hw: dict) -> dict: """setup.py's own rules: the size it preselects (IQ3_XXS from 60 GB of RAM, else the first, Q2_0), the @@ -1848,9 +1849,9 @@ class Tools: raise ToolError(f"images are not available with {families[family]['title']} {model} yet: use vision=no") if vision is None: # owner rule (2026-10-18): pictures are on by default wherever the model can read them and the engine has a reader; setup picks - # the reader (strata_control/vision_reader.py: the CPU under 24 GB, the GPU from 24 GB, every make of card). A Mac has none yet. + # the reader (strata_control/vision_reader.py: the CPU under 24 GB, the GPU from 24 GB, every make of card; a Mac reads on its GPU). can_read = md.get("vision", families[family].get("vision")) is not False - vision = "yes" if can_read and not mac else "no" + vision = "yes" if can_read else "no" target = self.check_data_dir(data_dir) if data_dir else s.data_dir() tag = (families[family].get("tag", "") + model) have_dir = target / "models" / tag diff --git a/tools/test_picture_defaults.py b/tools/test_picture_defaults.py index 0e51f272..8f141de5 100644 --- a/tools/test_picture_defaults.py +++ b/tools/test_picture_defaults.py @@ -71,6 +71,30 @@ class PictureDefaults(unittest.TestCase): self.assertEqual(setup.hip_vision(None, 16.0), "cpu") self.assertEqual(setup.hip_vision("gpu", 16.0), "gpu") +class MacPictureDefaults(unittest.TestCase): + """setup.py on a Mac: pictures on by default, on the Metal reader (strata_control/vision_reader.py).""" + + def test_nothing_asked_means_the_gpu_reader_for_every_mac_size(self): + from strata_control import mac_fit as MF + for model in MF.MAC_MODELS: + for ram in (32.0, 64.0, 128.0): + self.assertEqual(setup.mac_vision(None, model, ram), "gpu", (model, ram)) + self.assertEqual(setup.mac_vision("yes", model, ram), "gpu", (model, ram)) + + def test_off_and_cpu_are_kept_as_asked(self): + for off in ("no", "none", "off"): + self.assertEqual(setup.mac_vision(off, "Q2_0", 32.0), "none") + self.assertEqual(setup.mac_vision("cpu", "Q2_0", 32.0), "cpu") + + def test_a_folder_without_the_reader_turns_pictures_off(self): + import tempfile + d = Path(tempfile.mkdtemp(prefix="macvis-")) + (d / "strata").write_bytes(b"x") + self.assertEqual(setup.mac_reader(d, "gpu").mode, "none") + (d / "strata-vision").write_bytes(b"x") + r = setup.mac_reader(d, "gpu") + self.assertEqual((r.mode, r.exe.name), ("gpu", "strata-vision")) + if __name__ == "__main__": unittest.main() diff --git a/tools/test_strata_mcp.py b/tools/test_strata_mcp.py index 089a286a..1bcb31d1 100644 --- a/tools/test_strata_mcp.py +++ b/tools/test_strata_mcp.py @@ -706,7 +706,7 @@ class MacCatalog(unittest.TestCase): self.assertIn("slower", by["Q2_0"]["on_this_pc"]) self.assertIn("~14 tok/s", by["Q2_0"]["on_this_pc"]) self.assertTrue(by["IQ3_S"]["on_this_pc"].startswith("slow here")) - self.assertFalse(any(x["images"] for x in by.values())) + self.assertTrue(all(x["images"] for x in by.values()), "the Mac engine carries the Metal picture reader: pictures are on") s, hw = self.hw(128) self.assertEqual({x["on_this_pc"] for x in s.model_table(hw)[0]["sizes"]}, {"fits"}) s, hw = self.hw(8) @@ -723,6 +723,9 @@ class MacCatalog(unittest.TestCase): for flag in ("--kv", "--gpu", "--gpus", "--low-ram", "--backend"): self.assertNotIn(flag, args) self.assertIn("--gguf-dir", args) + with tempfile.TemporaryDirectory() as own: # nothing said about pictures: on, as everywhere (the Mac's reader is the Metal one) + _plan, args = M.Tools(s).install_plan("qwen", "Q2_0", None, None, "int8", 0, None, None, "auto", None, None, own) + self.assertEqual(args[args.index("--vision") + 1], "yes") with self.assertRaises(M.ToolError): s2, hw2 = self.hw(8) s2.hardware = lambda fresh=False: hw2 diff --git a/tools/test_vision_reader.py b/tools/test_vision_reader.py index e840aafa..d05739fe 100644 --- a/tools/test_vision_reader.py +++ b/tools/test_vision_reader.py @@ -104,6 +104,48 @@ class Choose(unittest.TestCase): self.assertIsNone(VR.cpu_fallback({"exe": "strata-vision", "gpu": True})) # an NVIDIA config has no fallback +class MacReader(unittest.TestCase): + """A Mac has one picture program, strata-vision with Metal built in: --gpu reads on the GPU, without it on the CPU.""" + + def test_a_mac_reads_on_the_gpu_by_default_whatever_its_memory(self): + for ram in (16, 32, 64, 128, None): + self.assertEqual(VR.default_mode(ram, unified=True), "gpu", ram) + self.assertEqual(VR.wanted(None, ram, unified=True), "gpu", ram) + self.assertEqual(VR.wanted("yes", ram, unified=True), "gpu", ram) + self.assertEqual(VR.wanted("cpu", 32, unified=True), "cpu") # asked for: kept + self.assertEqual(VR.wanted("off", 32, unified=True), "none") + self.assertEqual(VR.default_mode(16), "cpu") # a 16 GB card of a PC still follows the 24 GB rule + + def test_the_one_program_is_both_readers_and_its_own_fallback(self): + d = folder("strata", "strata-vision") + for ask in ("yes", "on", "gpu"): + r = VR.choose(d, ask, windows=False, mac=True) + self.assertEqual((r.mode, r.exe.name, r.cpu_exe.name, r.note), ("gpu", "strata-vision", "strata-vision", ""), ask) + sec = VR.vision_section(VR.choose(d, "yes", windows=False, mac=True), {"mmproj": "m.gguf", "model": "t.gguf", "max_tokens": 1024}) + self.assertTrue(sec["gpu"]) + self.assertEqual(sec["exe"], sec["cpu_exe"]) + fallback = VR.cpu_fallback(sec) + self.assertFalse(fallback["gpu"]) + self.assertEqual(fallback["exe"], sec["exe"]) + + def test_cpu_asked_is_kept_with_the_time_it_takes(self): + r = VR.choose(folder("strata-vision"), "cpu", windows=False, mac=True) + self.assertEqual((r.mode, r.exe.name, r.cpu_exe), ("cpu", "strata-vision", None)) + self.assertIn("50 seconds", r.note) + self.assertFalse(VR.vision_section(r, {})["gpu"]) + + def test_an_engine_without_the_reader_gets_pictures_off(self): + for ask in ("yes", "gpu", "cpu"): + r = VR.choose(folder("strata"), ask, windows=False, mac=True) + self.assertEqual(r.mode, "none", ask) + self.assertIn("no picture reader", r.note) + self.assertEqual(VR.choose(folder("strata-vision"), "off", windows=False, mac=True).mode, "none") + + def test_a_hip_program_is_not_a_mac_reader(self): + r = VR.choose(folder("strata-vision-hip"), "yes", windows=False, mac=True) + self.assertEqual(r.mode, "none") + + class FakeProc: def __init__(self, first_line: str): self.stdin, self.stdout = io.StringIO(), io.StringIO(first_line) diff --git a/tools/vision/CMakeLists.txt b/tools/vision/CMakeLists.txt index 5f031b9c..e2f958d4 100644 --- a/tools/vision/CMakeLists.txt +++ b/tools/vision/CMakeLists.txt @@ -23,6 +23,7 @@ endif() if(STRATA_VISION_HIP AND NOT STRATA_VISION_HIP_ARCHS) message(FATAL_ERROR "strata-vision: STRATA_VISION_HIP needs STRATA_VISION_HIP_ARCHS, for example \"gfx1200;gfx1201\"") endif() +option(STRATA_VISION_METAL "a Mac: ggml's Metal backend in the program, so --gpu reads pictures on the Mac's GPU (OFF: CPU only)" ON) option(STRATA_PORTABLE "build for other PCs: AVX2 baseline, static MSVC runtime" ON) if(STRATA_PORTABLE AND MSVC) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded") @@ -62,6 +63,15 @@ endif() set(GGML_BACKEND_DL OFF CACHE BOOL "" FORCE) set(GGML_CUDA ${STRATA_VISION_CUDA} CACHE BOOL "" FORCE) set(GGML_HIP ${STRATA_VISION_HIP} CACHE BOOL "" FORCE) +if(APPLE) + # One program for both readers: strata-vision --gpu runs the encoder on the Metal GPU, without --gpu on the CPU (Apple Silicon always + # has the Metal framework, the engine needs it too). The Metal shaders are embedded in the binary and compiled by macOS when the + # reader starts, so nothing but the program has to be shipped. No -march flag: the default target (an M1) runs on every Apple + # Silicon Mac, and ggml's CPU path has no BF16 vector kernel on ARM (measured on an M4: the same ~50 s for a 260-token picture with + # -march=armv8.6-a+bf16+i8mm as without), so a faster target would only risk the M1. + set(GGML_METAL ${STRATA_VISION_METAL} CACHE BOOL "" FORCE) + set(GGML_METAL_EMBED_LIBRARY ${STRATA_VISION_METAL} CACHE BOOL "" FORCE) +endif() if(STRATA_VISION_HIP) # the engine's HIP build says the same (cmake/hip_backend.cmake); ggml-hip reads AMDGPU_TARGETS / CMAKE_HIP_ARCHITECTURES set(AMDGPU_TARGETS "${STRATA_VISION_HIP_ARCHS}" CACHE STRING "" FORCE) @@ -82,6 +92,9 @@ if(STRATA_VISION_HIP) string(REPLACE ";" "," _hip_archs "${STRATA_VISION_HIP_ARCHS}") target_compile_definitions(strata-vision PRIVATE STRATA_VISION_HIP STRATA_VISION_HIP_ARCHS="${_hip_archs}") endif() +if(APPLE AND STRATA_VISION_METAL) + target_compile_definitions(strata-vision PRIVATE STRATA_VISION_METAL) +endif() if(WIN32 AND STRATA_VISION_HIP) # hipblas.dll (and rocblas.dll behind it) live in rocm\bin of the engine package: loaded on first use, after main() has put that folder on # the DLL search path, so the reader starts from any PATH and says "no GPU" itself where there is none diff --git a/tools/vision/strata_vision.cpp b/tools/vision/strata_vision.cpp index eef3e81c..fb892630 100644 --- a/tools/vision/strata_vision.cpp +++ b/tools/vision/strata_vision.cpp @@ -102,6 +102,8 @@ int main(int argc, char** argv) { else if (a == "--version") { #ifdef STRATA_VISION_HIP std::printf("strata-vision hip (GPU architectures: %s)\n", STRATA_VISION_HIP_ARCHS); +#elif defined(STRATA_VISION_METAL) + std::printf("strata-vision metal\n"); #else std::printf("strata-vision\n"); #endif @@ -162,6 +164,23 @@ int main(int argc, char** argv) { } } #endif +#ifdef STRATA_VISION_METAL + if (gpu) { + // The Mac: the same program reads on the GPU (--gpu, ggml's Metal backend) or on the CPU. With --gpu and no Metal device (a + // virtual machine without a GPU, say), mtmd would quietly use the CPU, which reads a picture in ~50 s: say so instead, and + // the server starts the program again without --gpu (serve/server.py, Vision._start) with one log line. + bool have_gpu = false; + for (size_t i = 0; i < ggml_backend_dev_count(); ++i) { + const auto type = ggml_backend_dev_type(ggml_backend_dev_get(i)); + have_gpu = have_gpu || type == GGML_BACKEND_DEVICE_TYPE_GPU || type == GGML_BACKEND_DEVICE_TYPE_IGPU; + } + if (!have_gpu) { + std::printf("ERR this Mac has no Metal GPU for the picture reader\n"); + std::fflush(stdout); + return 3; + } + } +#endif const auto load_t0 = std::chrono::steady_clock::now(); #if !defined(_WIN32) && !defined(__APPLE__) // macOS has no posix_fadvise From 509466a66802017222a8622ff5250a7d93061cd8 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 19 Oct 2026 21:26:49 +0200 Subject: [PATCH 2/2] Mac pictures: signing smoke checks strata-vision, docs and the 7 READMEs say the Mac reads pictures sign-and-notarize.sh starts strata-vision --version in the signed engine folders (it already signs every Mach-O). MAC.md carries the M4 numbers (0.45 s on the GPU, 50.7 s on the CPU for a 260-token picture) and the rule. --- README.de.md | 3 ++- README.es.md | 3 ++- README.fr.md | 4 ++-- README.ja.md | 2 +- README.md | 3 ++- README.pt-BR.md | 3 ++- README.zh-CN.md | 2 +- apps/desktop/tester/README-mac.txt.in | 3 +-- docs/AI_SETUP.md | 2 +- docs/DETAILS.md | 5 ++--- docs/INSTALL.md | 4 ++-- docs/MAC.md | 24 ++++++++++++++++++------ docs/MCP_SERVER.md | 2 +- docs/MODELS.md | 4 ++-- docs/TEST_REQUESTS.md | 2 +- docs/TROUBLESHOOTING.md | 2 +- packaging/README.md | 2 +- packaging/build_vision_mac.sh | 0 packaging/mac/README.md | 4 ++-- packaging/mac/sign-and-notarize.sh | 4 ++-- 20 files changed, 46 insertions(+), 32 deletions(-) mode change 100644 => 100755 packaging/build_vision_mac.sh diff --git a/README.de.md b/README.de.md index 22727337..67c3c0f3 100644 --- a/README.de.md +++ b/README.de.md @@ -282,7 +282,8 @@ Du kannst Bilder pro Modell ausschalten oder den Leser mit `--vision off`, `--vi Die Zahlen hinter der Regel: Auf einer Radeon AI PRO R9700 brauchte der Bildleser der Karte 57 ms für ein Bild mit 260 Tokens, der des Prozessors 3,1 s. Auf Karten mit 16 GB (Tesla P100 und RTX A4000, Linux) kostete der Bildleser der Karte 3-5 % des -Texttempos, weil er etwa 1,4 GB belegt, die sonst das Modell nutzen würde. Der Mac hat noch keinen Bildleser. +Texttempos, weil er etwa 1,4 GB belegt, die sonst das Modell nutzen würde. Auf dem Mac liest die GPU, egal wie viel Speicher er hat (0,45 s für ein Bild mit 260 Tokens auf einem M4 mit 32 GB, etwa 1,2 GB des gemeinsamen +Speichers); der Prozessor braucht dort etwa 50 s pro Bild und liest deshalb nur mit `--vision cpu`. ### Gut zu wissen diff --git a/README.es.md b/README.es.md index 952f8d90..bdf93860 100644 --- a/README.es.md +++ b/README.es.md @@ -281,7 +281,8 @@ NVIDIA y AMD. Puedes desactivar las imágenes por modelo, o elegir el lector con Las cifras detrás de la regla: en una Radeon AI PRO R9700, el lector de la tarjeta tardó 57 ms en una imagen de 260 tokens y el del procesador 3,1 s. En tarjetas de 16 GB (Tesla P100 y RTX A4000, Linux), el lector de la tarjeta costó un 3-5 % de -velocidad en texto, porque ocupa unos 1,4 GB que de otro modo usaría el modelo. El Mac todavía no tiene lector de imágenes. +velocidad en texto, porque ocupa unos 1,4 GB que de otro modo usaría el modelo. En un Mac lee la GPU, tenga la memoria que tenga (0,45 s para una imagen de 260 tokens en un M4 de 32 GB, unos 1,2 GB de la memoria compartida); +el procesador tarda unos 50 s por imagen, así que solo lee con `--vision cpu`. ### Conviene saber diff --git a/README.fr.md b/README.fr.md index c5fd2373..9a2e1e54 100644 --- a/README.fr.md +++ b/README.fr.md @@ -283,8 +283,8 @@ règle est la même pour NVIDIA et AMD. Vous pouvez désactiver les images par m Les chiffres derrière la règle : sur une Radeon AI PRO R9700, le lecteur de la carte a pris 57 ms pour une image de 260 tokens et celui du processeur 3,1 s. Sur des cartes de 16 Go (Tesla P100 et RTX A4000, Linux), le lecteur de la carte -a coûté 3 à 5 % de vitesse sur le texte, parce qu'il occupe environ 1,4 Go que le modèle utiliserait sinon. Le Mac n'a pas -encore de lecteur d'images. +a coûté 3 à 5 % de vitesse sur le texte, parce qu'il occupe environ 1,4 Go que le modèle utiliserait sinon. Sur un Mac, le lecteur tourne sur le GPU quelle que soit la mémoire (0,45 s pour une image de 260 tokens sur un M4 de 32 Go, environ 1,2 Go de la +mémoire partagée) ; le processeur met environ 50 s par image, il ne lit donc qu'avec `--vision cpu`. ### Bon à savoir diff --git a/README.ja.md b/README.ja.md index b18fd302..93e6d942 100644 --- a/README.ja.md +++ b/README.ja.md @@ -270,7 +270,7 @@ strata doctor # インストール済みのエ このルールの根拠となる数値です。Radeon AI PRO R9700 では、カードのリーダーは260トークンの画像に57 ms、プロセッサのリーダーは3.1秒かかりました。 16 GBのカード(Tesla P100 と RTX A4000、Linux)では、カードのリーダーを使うとテキストの速度が3〜5%下がりました。 -本来モデルが使う約1.4 GBをリーダーが占めるためです。Mac にはまだ画像リーダーがありません。 +本来モデルが使う約1.4 GBをリーダーが占めるためです。Mac ではメモリ量にかかわらず GPU が読み取ります(32 GB の M4 で260トークンの画像に0.45秒、共有メモリを約1.2 GB使います)。プロセッサでは1枚あたり約50秒かかるため、`--vision cpu` を指定したときだけ使います。 ### 知っておくと便利なこと diff --git a/README.md b/README.md index 2ebeef7d..72dc71d8 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,8 @@ off per model, or choose the reader with `--vision off`, `--vision gpu` or `--vi The numbers behind the rule: on a Radeon AI PRO R9700 the card's reader took 57 ms for a 260-token picture and the processor's took 3.1 s. On 16 GB cards (Tesla P100 and RTX A4000, Linux) the card's reader cost 3-5% of text speed, -because it holds about 1.4 GB that the model would use otherwise. The Mac has no picture reader yet. +because it holds about 1.4 GB that the model would use otherwise. On a Mac the reader runs on the Mac's GPU whatever its memory (0.45 s for a 260-token picture on an M4 with 32 GB, about 1.2 GB of the shared +memory); the processor reader needs about 50 s per picture there, so it runs only when you ask for it with `--vision cpu`. ### Good to know diff --git a/README.pt-BR.md b/README.pt-BR.md index f43682ee..146656ae 100644 --- a/README.pt-BR.md +++ b/README.pt-BR.md @@ -273,7 +273,8 @@ por modelo, ou escolha o leitor com `--vision off`, `--vision gpu` ou `--vision Os números por trás da regra: numa Radeon AI PRO R9700, o leitor da placa levou 57 ms para uma imagem de 260 tokens e o do processador levou 3,1 s. Em placas de 16 GB (Tesla P100 e RTX A4000, Linux), o leitor da placa custou de 3 a 5% da velocidade do texto, -porque ocupa cerca de 1,4 GB que o modelo usaria de outra forma. O Mac ainda não tem leitor de imagens. +porque ocupa cerca de 1,4 GB que o modelo usaria de outra forma. No Mac, a GPU faz a leitura, seja qual for a memória (0,45 s para uma imagem de 260 tokens em um M4 de 32 GB, cerca de 1,2 GB da memória compartilhada); +o processador leva cerca de 50 s por imagem, então só lê com `--vision cpu`. ### Bom saber diff --git a/README.zh-CN.md b/README.zh-CN.md index 793177c1..20e7d241 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -268,7 +268,7 @@ strata doctor # 检查已安装的引擎文件 这条规则背后的数据:在 Radeon AI PRO R9700 上,显卡读一张 260 token 的图片用了 57 ms,处理器用了 3.1 秒。在 16 GB 的显卡 (Tesla P100 和 RTX A4000,Linux)上,用显卡读图会让文字速度下降 3-5%,因为它占用约 1.4 GB 显存,否则这部分会被模型使用。 -Mac 目前还没有读图功能。 +在 Mac 上,无论内存多大,都由 GPU 读图(32 GB 的 M4 上读一张 260 token 的图片用 0.45 秒,占用约 1.2 GB 共享内存);处理器读一张约需 50 秒,所以只有指定 `--vision cpu` 时才用。 ### 使用须知 diff --git a/apps/desktop/tester/README-mac.txt.in b/apps/desktop/tester/README-mac.txt.in index eb604a66..1557c16a 100644 --- a/apps/desktop/tester/README-mac.txt.in +++ b/apps/desktop/tester/README-mac.txt.in @@ -27,8 +27,7 @@ START IT Closing the window stops Strata and its engine. -Pictures: this Mac build has no picture reader yet, so models read text only here. Picture input works on the Windows and -Linux builds. +Pictures: on by default. This Mac build reads them on the Mac's GPU (under a second for a small picture on an M4). @INCLUDE:common-gatekeeper-mac.txt@ diff --git a/docs/AI_SETUP.md b/docs/AI_SETUP.md index 3f8e9c98..ad829882 100644 --- a/docs/AI_SETUP.md +++ b/docs/AI_SETUP.md @@ -130,7 +130,7 @@ Notes: whether to allow Strata on the network if you used `--access lan`. - **AMD on Windows:** only the AMD driver is needed. The AMD engine is a ready-made download. It has not been run with a model on a real AMD card on Windows by us: ask the user to report how it runs ([AMD_HIP.md](AMD_HIP.md)). -- **Mac:** the Metal engine is fetched like any other. There is no picture reader on the Mac yet. +- **Mac:** the Metal engine is fetched like any other. Pictures are on by default and read on the Mac's GPU ([MAC.md](MAC.md)). ## 5. While it downloads, tell the user diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 07c9b3e6..cd997377 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1631,11 +1631,10 @@ The model has a vision encoder: [`mmproj-Qwen3.8-Flash-Next-BF16.gguf`](https:// (0.9 GB, a 27-layer ViT plus the projector into the language model). Pictures are **on by default** wherever a model can read them. The app, `strata launch` and setup use one rule for the reader: the **CPU reader under 24 GB** of graphics memory (nothing is taken from the card's memory, so the experts keep their room) and the **graphics card's reader from 24 GB**, on NVIDIA and AMD -cards. You can switch pictures off (`--vision no`, or "No" in the app and in `strata launch`) or pick the reader per model +cards; a Mac reads on its GPU (Metal) whatever its memory. You can switch pictures off (`--vision no`, or "No" in the app and in `strata launch`) or pick the reader per model (`--vision gpu` or `--vision cpu`). The setup downloads the encoder and puts a small helper (`strata-vision`, from llama.cpp's `mtmd` library) beside the engine; it adds it to your start script. Nothing else changes. Where a reader is missing, pictures -stay off and the screen says so: the Mac app and the Mac Terminal have no picture reader yet, and neither has the Intel Arc -engine. On AMD the card's reader is `strata-vision-hip`, a second program in the engine package; if it cannot start, the server +stay off and the screen says so: the Intel Arc engine has none yet. On AMD the card's reader is `strata-vision-hip`, a second program in the engine package; if it cannot start, the server starts the CPU reader by itself and prints one line ([AMD_HIP.md](AMD_HIP.md)). | Encoder on | Time per picture | Cost | diff --git a/docs/INSTALL.md b/docs/INSTALL.md index d917488c..6b3426ed 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -73,7 +73,7 @@ in `%LOCALAPPDATA%\Strata\components` (Linux and Mac: `~/.local/share/strata/com `Strata` folder in your Documents (you can change the model folder in the app). Removing the app does not remove them. **For a bug report:** Settings, Engine, Diagnostics, View logs, **Save logs**. -The app has no picture reader on the Mac yet. Everything else about pictures is in [Setup's questions](#setups-questions). +On a Mac pictures are on by default and read on the GPU ([MAC.md](MAC.md)). Everything else about pictures is in [Setup's questions](#setups-questions). ## The Terminal @@ -282,7 +282,7 @@ These are the questions of the installer from source (`START-HERE.bat`, `./setup from the GPU) and on the GPU from 24 GB (0.1-0.5 s per picture, ~1.4 GB of VRAM kept free for it). The rule is the same for NVIDIA and AMD cards; `--vision gpu` and `--vision cpu` choose the reader yourself, `--vision no` turns pictures off. On a Radeon AI PRO R9700 the GPU reader took 57 ms for a 260-token picture and the CPU reader 3.1 s. - The Mac has no picture reader yet. [Details](DETAILS.md#images-vision). + A Mac reads on its GPU (0.45 s for a 260-token picture on an M4). [Details](DETAILS.md#images-vision). - **Experimental speed projection?** Off unless you say yes - [read what it does](DETAILS.md#experimental-speed-projection-experimental-off-by-default) first. It changes how the model answers, and only the original model offers it. diff --git a/docs/MAC.md b/docs/MAC.md index ce9c8111..19483ab6 100644 --- a/docs/MAC.md +++ b/docs/MAC.md @@ -11,8 +11,8 @@ kernels are replaced by Metal ones (`metal/`), and the host code and the server - **From source: `./setup.sh`.** It sets things up the way `START-HERE.bat` does on Windows and builds the engine on your Mac (about 1-15 minutes). -**Pictures:** the app and the Terminal have no picture reader on the Mac yet. Only the source build can read pictures -([Limits](#limits-this-version)). The NVIDIA, AMD and Intel engines are unchanged. +**Pictures:** on by default in the app, the Terminal and the source build. The reader (`strata-vision`) comes in the engine package +and runs on the Mac's GPU through Metal ([Limits](#limits-this-version)). The NVIDIA, AMD and Intel engines are unchanged. **Status:** new. It is measured on three Macs: an M5 Max with 128 GB, where the model stays in memory; and an M4 Mac mini with 32 GB and an M1 Max with 34 GB, where the experts stream from the SSD (the M1 Max: 7.9 tok/s decode, 186 tok/s on a @@ -188,10 +188,22 @@ The arena was 11.5-14.7 GB. Tokens per second, one token per step (no MTP), medi ## Limits (this version) -- **Images (vision): the source build only.** `./setup.sh` asks "Should the model also read images?" (`--vision yes|no`) and - builds the picture reader (`strata-vision`) itself. Checked on one test picture with Q2_0 and UD-Q4_K_XL: the answers equal - the HIP engine's, and text output is unchanged with vision on. No other tests yet. The app and the Terminal have no - picture reader on the Mac yet. They show models as text only and do not turn pictures on. +- **Images (vision):** on by default. The app and the Terminal use the `strata-vision` that sits beside `strata` in the engine package; + `./setup.sh` builds it itself and asks "Should the model also read images?" (default yes). One program does both jobs: with `--gpu` it + reads on the Mac's GPU (ggml's Metal backend, the shaders are built into the program), without it on the CPU. A Mac always gets the GPU + reader, whatever its memory. The 24 GB rule of the PC cards does not apply: the Mac has no separate card memory to keep free, and the + reader's footprint is about the same on either side (1.18 GB on the GPU, 1.05 GB on the CPU, mostly the 0.9 GB projector file). + Measured on a Mac mini M4 (32 GB), Qwen3.8-Flash-Next's BF16 projector: + + | Picture | GPU reader | CPU reader | + |---|---|---| + | 260 tokens (640x400) | 0.45 s | 50.7 s | + | 972 tokens (1600x1200) | 2.4 s | 194 s | + + `--vision cpu` is still allowed and prints that note. The CPU reader is slow because ggml has no vector kernel for BF16 on ARM (a build + for newer chips, with the BF16 and int8 instructions, took the same 50.7 s). If the GPU reader cannot start, the server prints one line + and starts the same program on the CPU. With Q2_0 streaming from the SSD on that M4, the STRATA 42 test picture (red circle, blue square, + green triangle, the text "STRATA 42") was described correctly with both readers. Checked on one Mac only; the M5 Max is untested for pictures. - **Context:** measured up to 32K (needles, KL). Setup recommends 32K below 96 GB and 64K from 96 GB. Up to the model's 262K can be set, but it is not measured. - **One request at a time.** `--parallel` (batch slots) is not ported. Several clients queue. - **Not ported:** the control vector (`--control-vector-scaled`) and the PC tuning (`--calibrate`). diff --git a/docs/MCP_SERVER.md b/docs/MCP_SERVER.md index a86b433a..772919d3 100644 --- a/docs/MCP_SERVER.md +++ b/docs/MCP_SERVER.md @@ -128,7 +128,7 @@ Every result is JSON with a one-line `summary`. It is sent both as text and as M - the size setup itself would pick: IQ3_XXS from 60 GB of RAM, Q2_0 from about 44 GB, the Coder from about 28 GB, and the Coder in the low-RAM mode below that when the GPU makes up for the RAM; - the context setup recommends for the GPU's VRAM; -- pictures on where the model can read them (the reader runs on the CPU under 24 GB of VRAM and on the GPU from 24 GB, on NVIDIA and AMD cards; a Mac has none yet). +- pictures on where the model can read them (the reader runs on the CPU under 24 GB of VRAM and on the GPU from 24 GB, on NVIDIA and AMD cards; a Mac reads on its GPU). The first call returns the plan: the download size (58-111 GB), the free disk space, the RAM check, and the exact setup command. The assistant should show you the plan and call again with `confirm: true` once you agree. diff --git a/docs/MODELS.md b/docs/MODELS.md index fe4c0b7c..31a8ed6c 100644 --- a/docs/MODELS.md +++ b/docs/MODELS.md @@ -107,8 +107,8 @@ read them. The picture reader runs on the CPU when the graphics card has less th picture, nothing taken from the card) and on the graphics card from 24 GB (about 1-1.4 GB of VRAM; 0.1-0.5 s per picture). The rule is the same on NVIDIA and AMD cards. `--vision off` (or "No" in the app and in `strata launch`) turns pictures off; `--vision cpu` or `--vision gpu` picks the reader. On AMD, `strata-vision-hip` is the card's reader; if it -cannot start, Strata uses the CPU reader by itself ([AMD_HIP.md](AMD_HIP.md)). The Mac app and the Mac Terminal have no -picture reader yet ([MAC.md](MAC.md)), and neither does the Intel Arc engine ([INTEL.md](INTEL.md#not-done)). More: [Images](DETAILS.md#images-vision). +cannot start, Strata uses the CPU reader by itself ([AMD_HIP.md](AMD_HIP.md)). The Mac reads pictures on its GPU +([MAC.md](MAC.md)); the Intel Arc engine has no picture reader yet ([INTEL.md](INTEL.md#not-done)). More: [Images](DETAILS.md#images-vision). ### Qwen3.8-Flash-Next diff --git a/docs/TEST_REQUESTS.md b/docs/TEST_REQUESTS.md index 67197f6d..806c5c00 100644 --- a/docs/TEST_REQUESTS.md +++ b/docs/TEST_REQUESTS.md @@ -17,6 +17,6 @@ This list is edited by the maintainers. An item stays until a report answers it. | A long soak (an hour or more of back-to-back requests) on a split or resident setup | Shows crashes, drift and heat that a short run does not | #848 | | AMD RX 7000 series (RX 7900 XTX, 7900 XT, 7800 XT and similar, RDNA 3) on Linux or Windows | The RX 7000 builds have not been run on a real RX 7000 card by us; the Docker image for them is also untested on a card | none yet | | Windows with an AMD card: the app or the Terminal, one model, one picture sent | The Windows AMD build has not been run on a real card, and neither has its picture reader (CPU under 24 GB, GPU from 24 GB) | none yet | -| A Mac with Apple silicon (macOS 15 or newer): the app or the Terminal with a real model | Mac builds have run on very few Macs. Tell us the Mac's memory, the model, the speed, and anything that failed. The Mac app has no picture reader yet. The signing script has not been run against Apple's real notary service yet, so a first-launch warning is expected and useful to hear about | none yet | +| A Mac with Apple silicon (macOS 15 or newer): the app or the Terminal with a real model | Mac builds have run on very few Macs. Tell us the Mac's memory, the model, the speed, and anything that failed. Pictures on the Mac (GPU reader) were run on one Mac mini M4 only: tell us if they work on yours. The signing script has not been run against Apple's real notary service yet, so a first-launch warning is expected and useful to hear about | none yet | To add a request, open a pull request that adds a row, or tell the maintainers in an issue. diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md index fbe45ca5..ac541308 100644 --- a/docs/TROUBLESHOOTING.md +++ b/docs/TROUBLESHOOTING.md @@ -200,7 +200,7 @@ reader runs on the CPU under 24 GB of graphics memory and on the card from 24 GB several seconds (about 3 s at 300 image tokens on 8 cores, more with more tokens) are read by the encoder on the CPU; `--vision gpu` (NVIDIA and AMD, ~1.4 GB of VRAM) makes it 0.1-0.5 s. On AMD the card's reader is `strata-vision-hip`; if it cannot start, the server prints "the GPU picture reader did not start (...); pictures are read on the CPU" and goes on with -the CPU reader. The Mac app and the Mac Terminal have no picture reader yet. On Intel Arc, pictures are off by default for now (`--vision yes` turns them on). +the CPU reader. On a Mac the reader runs on the GPU; `--vision cpu` takes about 50 s per picture there. On Intel Arc, pictures are off by default for now (`--vision yes` turns them on). ## AMD cards diff --git a/packaging/README.md b/packaging/README.md index e70a3c4f..e8583989 100644 --- a/packaging/README.md +++ b/packaging/README.md @@ -16,7 +16,7 @@ A backend name alone is not a target. Each row is an OS x CPU ABI x backend tupl | Target tuple | App artifact | Engine package | Status | | --- | --- | --- | --- | -| `macos-arm64-metal` | `.app` + `.dmg` (Tauri) | Metal `strata`, bundled | **built.** The app's self-test passed from inside the mounted DMG and the engine's 17 kernel-parity suites pass on an Apple M4 GPU. A large model does not fit the 16 GiB test Mac. No picture reader on Mac yet. Signing and notarising: `packaging/mac/sign-and-notarize.sh` (see [mac/README.md](mac/README.md)); it has been run with stand-ins for Apple's service, not yet against the real one. | +| `macos-arm64-metal` | `.app` + `.dmg` (Tauri) | Metal `strata`, bundled | **built.** The app's self-test passed from inside the mounted DMG and the engine's 17 kernel-parity suites pass on an Apple M4 GPU. A large model does not fit the 16 GiB test Mac. Carries `strata-vision` (Metal), built by `packaging/build_vision_mac.sh`. Signing and notarising: `packaging/mac/sign-and-notarize.sh` (see [mac/README.md](mac/README.md)); it has been run with stand-ins for Apple's service, not yet against the real one. | | Terminal `darwin-arm64` | self-contained `.tar.gz` | any | **built and verified.** Runs from a moved directory in a clean environment with no usable system Python. | | `windows-x86_64-cuda` | NSIS `.exe` (Tauri) | `cuda13` and `cuda12` packages | **built and tested** on a Windows PC with an NVIDIA card: silent install with a PATH of System32 only, a real model, an agent chat. | | `windows-x86_64-hip` | NSIS `.exe` (Tauri) | `tools/hip/build_windows.bat` | **built; never run on a real AMD card.** | diff --git a/packaging/build_vision_mac.sh b/packaging/build_vision_mac.sh old mode 100644 new mode 100755 diff --git a/packaging/mac/README.md b/packaging/mac/README.md index cedaa741..da833c88 100644 --- a/packaging/mac/README.md +++ b/packaging/mac/README.md @@ -50,13 +50,13 @@ updater key** here: that key never goes near the Mac, and the Mac needs no node. ## What it does 1. Copies the `.app` out of the dmg into a temporary folder (the original is never changed). -2. Signs every Mach-O inside it, deepest first (node, python, every `.dylib`, `.so` and `.node`, the engine, `rg`, `spawn-helper`, +2. Signs every Mach-O inside it, deepest first (node, python, every `.dylib`, `.so` and `.node`, the engine and its picture reader `strata-vision`, `rg`, `spawn-helper`, the app's own program): hardened runtime and a secure timestamp. Then signs the `.app`. 3. Rewrites `engine-component.json` for the engine it just signed. Control checks every engine file against the SHA-256 in that file, and signing changes the engine binary, so without this step the signed app would refuse its own engine. 4. `codesign --verify --deep --strict`, `spctl -a -vvv`. 5. Runs the signed copy before Apple sees it: the app's own `--self-test` (private node, host, UI, Control), every native addon loaded in - the signed node, the bundled python (numpy, PIL, ctypes callbacks), the engine's `--version` (no model is loaded), and Control's own + the signed node, the bundled python (numpy, PIL, ctypes callbacks), the engine's and the picture reader's `--version` (no model is loaded), and Control's own check of the engine manifest. A signing mistake shows up here, not on a tester's Mac. 6. Notarises the `.app`, staples it, rebuilds the dmg (the app, an Applications link, the volume icon, as in `apps/desktop/scripts/make-dmg.sh`), signs the dmg, notarises and staples it, then `spctl -a -t open --context context:primary-signature -vv`. diff --git a/packaging/mac/sign-and-notarize.sh b/packaging/mac/sign-and-notarize.sh index f350c8c0..138c23b0 100755 --- a/packaging/mac/sign-and-notarize.sh +++ b/packaging/mac/sign-and-notarize.sh @@ -433,7 +433,7 @@ print("python ok", sys.version.split()[0])' >>"$LOG" 2>&1); then rec OK "smoke: if run_timeout 30 "$f" --version >"$WORK/engine-version.txt" 2>&1; then say " $(head -n 1 "$WORK/engine-version.txt")"; else cat "$WORK/engine-version.txt" >>"$LOG"; fails=$((fails + 1)); say " engine did not start: $f" fi - done < <(find "$res/engine-bundle" -mindepth 2 -maxdepth 2 -type f \( -name strata -o -name strata-device \) 2>/dev/null) + done < <(find "$res/engine-bundle" -mindepth 2 -maxdepth 2 -type f \( -name strata -o -name strata-device -o -name strata-vision \) 2>/dev/null) [ "$fails" -eq 0 ] || fail "smoke: bundled engine starts" "$fails engine(s) did not start under the hardened runtime" if [ -x "$py" ] && [ -d "$res/engine-bundle" ]; then out="$(cd "$ctl" && env HOME="$home" "$py" -c ' @@ -473,7 +473,7 @@ smoke_terminal() { # extracted terminal folder while IFS= read -r f; do [ -n "$f" ] || continue run_timeout 30 "$f" --version >>"$LOG" 2>&1 || fail "smoke: engine in the Terminal archive" "$f does not start" - done < <(find "$root" -type f \( -name strata -o -name strata-device \) -perm -u+x 2>/dev/null | while IFS= read -r c; do file "$c" | grep -q 'Mach-O' && printf '%s\n' "$c"; done) + done < <(find "$root" -type f \( -name strata -o -name strata-device -o -name strata-vision \) -perm -u+x 2>/dev/null | while IFS= read -r c; do file "$c" | grep -q 'Mach-O' && printf '%s\n' "$c"; done) } # ----------------------------------------------------------------------------------------------------------------- the app