Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(engine): A40, models load again on macOS 14 and 15 (GH #259)

purple922239e8ea45
diff --git a/.github/workflows/metal-shaders.yml b/.github/workflows/metal-shaders.yml
new file mode 100644
index 00000000..b3827691
--- /dev/null
+++ b/.github/workflows/metal-shaders.yml
@@ -0,0 +1,61 @@
+name: Mac sidecar Metal shaders compile on older macOS
+
+# A40 (GH #259, 3.1.2). The Mac sidecar embeds llama.cpp's Metal shaders as
+# source, and the user's macOS compiles them at the first model load with the
+# Metal compiler that ships in that macOS. b11960 (LU 3.0.9 to 3.1.1) carried
+# two bfloat casts that macOS 26 accepts and macOS 14 and 15 refuse, so no
+# model loaded on those Macs. The release lane builds on macos-15 and checks
+# that version itself; this workflow compiles the same embedded sources on
+# every hosted macOS image LU still promises, whenever the llama.cpp pin or
+# LU's patches change, weekly against image drift, and on demand.
+#
+# Only ggml-metal is built (scripts/check-metal-shaders.sh --from-source), not
+# the whole sidecar: the shader sources are cmake outputs of that one target.
+on:
+ push:
+ branches: [master]
+ paths:
+ - 'scripts/build-llama.sh'
+ - 'scripts/llama-patches/**'
+ - 'scripts/check-metal-shaders.sh'
+ - 'scripts/metal-shader-check.m'
+ - '.github/workflows/metal-shaders.yml'
+ pull_request:
+ paths:
+ - 'scripts/build-llama.sh'
+ - 'scripts/llama-patches/**'
+ - 'scripts/check-metal-shaders.sh'
+ - 'scripts/metal-shader-check.m'
+ - '.github/workflows/metal-shaders.yml'
+ schedule:
+ - cron: '41 4 * * 1' # Mondays 04:41 UTC
+ workflow_dispatch:
+
+# Only reads the repository (OpenSSF Scorecard, Token-Permissions).
+permissions:
+ contents: read
+
+jobs:
+ metal-shaders:
+ strategy:
+ fail-fast: false
+ matrix:
+ # macos-14 is the oldest macOS LU promises (tauri.macos.conf.json
+ # minimumSystemVersion). When GitHub retires that image this job
+ # fails to start, which is the moment to decide how 14 is checked,
+ # not a reason to drop the entry quietly.
+ runner: [macos-14, macos-15]
+ runs-on: ${{ matrix.runner }}
+ timeout-minutes: 30
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
+ with:
+ persist-credentials: false
+
+ - name: Compile the embedded Metal sources with this macOS
+ shell: bash
+ env:
+ BUILD_JOBS: 3
+ MACOSX_DEPLOYMENT_TARGET: '14.0'
+ run: bash scripts/check-metal-shaders.sh --from-source
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index a57534c4..0f2b9c82 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1496,6 +1496,19 @@ jobs:
exit 1
fi
+ # A40 (GH #259, 3.1.2): minos above says the binary STARTS on macOS 14.
+ # It does not say the shaders compile there: the sidecar embeds its
+ # Metal code as source, and the user's own macOS compiles it at the
+ # first model load. b11960 shipped in 3.0.9 to 3.1.1 with two bfloat
+ # casts the compiler of macOS 14 and 15 refuses, so no model loaded on
+ # those Macs while every check here was green. This step asks the
+ # compiler of THIS runner (macos-15) through the same call llama.cpp
+ # makes. macOS 14 is covered by metal-shaders.yml on a macos-14 runner,
+ # which runs on every change to the build script or the patches.
+ - name: "Metal shaders compile on this runner's macOS"
+ shell: bash
+ run: bash scripts/check-metal-shaders.sh ".llama-build/build-$SIDECAR_TRIPLE/ggml/src/ggml-metal/autogenerated"
+
# Same proof shape as the Windows and Linux lanes: a real model load and
# /health, not `--version`. `-ngl 0` keeps the layers on the processor:
# hosted runners are virtual machines, and whether their paravirtual GPU
diff --git a/scripts/build-llama.sh b/scripts/build-llama.sh
index 9a8ee4d3..5bc5b303 100755
--- a/scripts/build-llama.sh
+++ b/scripts/build-llama.sh
@@ -320,8 +320,12 @@ ensure_src() {
}
# LU's own changes to the pinned source, reviewed in this repo
-# (scripts/llama-patches/*.patch). They only touch tools/cvector-generator,
-# so the server binary is the pinned source unchanged.
+# (scripts/llama-patches/*.patch). 0001-0004 only touch
+# tools/cvector-generator. 0005 (A40, 3.1.2) is upstream llama.cpp PR 31360
+# backported: two `constexpr` words out of ggml-metal/kernels/unary.metal, so
+# the embedded Metal library compiles on macOS 14 and 15 again. Drop it once
+# LLAMA_COMMIT is at or past c9daee1. Everything else in the server binary is
+# the pinned source unchanged.
#
# P11 FEHLER 10 (David's test build, 31.10.2026): the vector tool aborted
# on Qwen3.5 (GGML_ASSERT diff_filtered.size() == n_layers - 1): b9949 keeps
diff --git a/scripts/check-metal-shaders.sh b/scripts/check-metal-shaders.sh
new file mode 100755
index 00000000..2aaa92c3
--- /dev/null
+++ b/scripts/check-metal-shaders.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+#
+# check-metal-shaders.sh — compile the Mac sidecar's embedded Metal sources
+# with the Metal compiler of the macOS this runs on (A40, GH #259, 3.1.2).
+#
+# The sources are the files cmake writes for GGML_METAL_EMBED_LIBRARY
+# (<build>/ggml/src/ggml-metal/autogenerated/ggml-metal-embed-<kind>.metal),
+# which are byte for byte what the binary carries and what a user's Mac
+# compiles at the first model load. Each one is compiled twice, with and
+# without GGML_METAL_HAS_BF16, through scripts/metal-shader-check.m.
+#
+# Usage:
+# scripts/check-metal-shaders.sh <autogenerated dir>
+# scripts/check-metal-shaders.sh --from-source
+# configures the pinned, patched llama.cpp (scripts/build-llama.sh) and
+# builds only the ggml-metal target, then checks its sources. For a
+# runner that does not build the whole sidecar (metal-shaders.yml).
+#
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+die() { printf '[check-metal] ERROR: %s\n' "$*" >&2; exit 1; }
+
+[ "$(uname -s)" = "Darwin" ] || die "this check needs macOS: it asks the system's own Metal compiler"
+
+if [ "${1:-}" = "--from-source" ]; then
+ # shellcheck source=build-llama.sh
+ source "$SCRIPT_DIR/build-llama.sh"
+ require_cmake
+ ensure_src
+ build_dir="$CACHE_DIR/metal-check-aarch64-apple-darwin"
+ flags="$(cmake_flags_for aarch64-apple-darwin)"
+ # shellcheck disable=SC2086
+ cmake -S "$SRC_DIR" -B "$build_dir" $flags >/dev/null
+ cmake --build "$build_dir" --config Release --target ggml-metal -j "${BUILD_JOBS:-3}" >/dev/null
+ dir="$build_dir/ggml/src/ggml-metal/autogenerated"
+else
+ dir="${1:-}"
+fi
+
+[ -n "$dir" ] && [ -d "$dir" ] || die "no autogenerated directory given or found: '${dir:-}'"
+
+sources=()
+while IFS= read -r f; do sources+=("$f"); done < <(find "$dir" -maxdepth 1 -type f -name 'ggml-metal-embed-*.metal' | LC_ALL=C sort)
+# b11960 writes 36. Fewer than a handful means the path is wrong, not that
+# there is little to check, and an empty list must never pass.
+[ "${#sources[@]}" -ge 10 ] || die "found ${#sources[@]} embedded Metal sources under $dir, expected the full set"
+
+work="$(mktemp -d)"
+trap 'rm -rf "$work"' EXIT
+xcrun clang -fobjc-arc -framework Foundation -framework Metal \
+ -o "$work/metal-shader-check" "$SCRIPT_DIR/metal-shader-check.m"
+
+echo "macOS $(sw_vers -productVersion) ($(sw_vers -buildVersion)), ${#sources[@]} embedded Metal sources"
+status=0
+for bf16 in 1 0; do
+ "$work/metal-shader-check" "$bf16" "${sources[@]}" || status=$?
+ # 2 = no Metal device: nothing was checked, stop here and say so.
+ [ "$status" -ne 2 ] || die "no Metal device on this machine, the shaders were not checked"
+done
+if [ "$status" -ne 0 ]; then
+ die "the Metal compiler of macOS $(sw_vers -productVersion) refuses the sidecar's shaders. Every Mac on this version would fail to load any model (see GH #259)."
+fi
+echo "OK: every embedded Metal source compiles on macOS $(sw_vers -productVersion)"
diff --git a/scripts/llama-patches/0005-metal-unary-bf16-no-constexpr.patch b/scripts/llama-patches/0005-metal-unary-bf16-no-constexpr.patch
new file mode 100644
index 00000000..c039f887
--- /dev/null
+++ b/scripts/llama-patches/0005-metal-unary-bf16-no-constexpr.patch
@@ -0,0 +1,25 @@
+A40 (GH #259, 3.1.2): upstream llama.cpp PR 31360, merge commit
+c9daee149d606adc30b4c5b7a3254697c9771e2b (29.10.2026), backported onto b11960.
+The Metal compiler of macOS 14 and 15 rejects these two constexpr bfloat
+specializations (-Winvalid-constexpr), so the embedded unary library does not
+build there and every model load dies in ggml_metal_init. macOS 26 accepts
+them, which is why it only shows on older systems. Drop this patch once
+LLAMA_COMMIT is at or past c9daee1.
+
+--- a/ggml/src/ggml-metal/kernels/unary.metal
++++ b/ggml/src/ggml-metal/kernels/unary.metal
+@@ -11,12 +11,12 @@ inline constexpr T ggml_metal_unary_cast(U x) {
+ #if defined(GGML_METAL_HAS_BF16)
+ // MSL has no C-style cast from float vectors to bfloat vectors
+ template <>
+-inline constexpr bfloat4 ggml_metal_unary_cast<bfloat4, float4>(float4 x) {
++inline bfloat4 ggml_metal_unary_cast<bfloat4, float4>(float4 x) {
+ return bfloat4(bfloat(x[0]), bfloat(x[1]), bfloat(x[2]), bfloat(x[3]));
+ }
+
+ template <>
+-inline constexpr bfloat4 ggml_metal_unary_cast<bfloat4, float>(float x) {
++inline bfloat4 ggml_metal_unary_cast<bfloat4, float>(float x) {
+ return bfloat4(bfloat(x), bfloat(x), bfloat(x), bfloat(x));
+ }
+ #endif
diff --git a/scripts/metal-shader-check.m b/scripts/metal-shader-check.m
new file mode 100644
index 00000000..3ec19a0b
--- /dev/null
+++ b/scripts/metal-shader-check.m
@@ -0,0 +1,67 @@
+// metal-shader-check.m — compile llama.cpp's embedded Metal sources with the
+// Metal compiler of the macOS this runs on (A40, GH #259, 3.1.2).
+//
+// The Mac sidecar embeds its shaders as SOURCE (GGML_METAL_EMBED_LIBRARY).
+// They are compiled on the user's Mac, by the compiler that ships inside that
+// macOS, through the same call llama.cpp makes (newLibraryWithSource). b11960
+// carried two constexpr bfloat casts that the compiler of macOS 26 accepts and
+// the one of macOS 14 and 15 refuses, so no model loaded there and nothing in
+// the release lane noticed. This program makes that same call on a runner of
+// the oldest macOS LU supports, before a build ships.
+//
+// usage: metal-shader-check <bf16 0|1> <file.metal>...
+// bf16 1 sets GGML_METAL_HAS_BF16, as llama.cpp does on every Apple Silicon
+// GPU (has_bfloat), which is the branch that broke. The tensor API stays
+// off: it needs Metal 4, so a Mac below macOS 26 never compiles it.
+// Exit 0 when every file compiles, 1 when one does not, 2 when this machine
+// has no Metal device (then nothing was checked, which must not read as a
+// pass).
+
+#import <Foundation/Foundation.h>
+#import <Metal/Metal.h>
+
+int main(int argc, char ** argv) {
+ @autoreleasepool {
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s <bf16 0|1> <file.metal>...\n", argv[0]);
+ return 2;
+ }
+ id<MTLDevice> device = MTLCreateSystemDefaultDevice();
+ if (device == nil) {
+ fprintf(stderr, "FAIL: no Metal device on this machine, nothing was compiled\n");
+ return 2;
+ }
+ const bool bf16 = atoi(argv[1]) != 0;
+ printf("device: %s, GGML_METAL_HAS_BF16=%s\n", [[device name] UTF8String], bf16 ? "1" : "unset");
+
+ int failures = 0;
+ for (int i = 2; i < argc; i++) {
+ NSError * error = nil;
+ NSString * src = [NSString stringWithContentsOfFile:@(argv[i]) encoding:NSUTF8StringEncoding error:&error];
+ if (src == nil) {
+ fprintf(stderr, "FAIL %s: cannot read it\n", argv[i]);
+ failures++;
+ continue;
+ }
+ NSMutableDictionary * prep = [NSMutableDictionary dictionary];
+ prep[@"GGML_METAL_EMBED_LIBRARY"] = @"1";
+ if (bf16) {
+ prep[@"GGML_METAL_HAS_BF16"] = @"1";
+ }
+ MTLCompileOptions * options = [MTLCompileOptions new];
+ options.preprocessorMacros = prep;
+ // No languageVersion: llama.cpp leaves it at the system default
+ // unless the tensor API is on, and so does this check.
+ error = nil;
+ id<MTLLibrary> lib = [device newLibraryWithSource:src options:options error:&error];
+ if (lib == nil) {
+ fprintf(stderr, "FAIL %s\n%s\n", argv[i], [[error localizedDescription] UTF8String]);
+ failures++;
+ } else {
+ printf("ok %s\n", argv[i]);
+ }
+ }
+ printf("%d of %d compiled\n", argc - 2 - failures, argc - 2);
+ return failures == 0 ? 0 : 1;
+ }
+}
diff --git a/src-tauri/src/commands/engine.rs b/src-tauri/src/commands/engine.rs
index 0434e43e..5b9bffc6 100644
--- a/src-tauri/src/commands/engine.rs
+++ b/src-tauri/src/commands/engine.rs
@@ -2912,6 +2912,24 @@ pub(crate) fn stderr_blames_the_port(stderr: &str) -> bool {
/// install path as the cause (review-longpath.md Runde 2, Blocker 9): this
/// function stays the right answer for every OTHER "the child died and said
/// something model-shaped" case, short-path included.
+/// A40 (GH #259, 3.1.2): the Metal compiler of this Mac refused the engine's
+/// shader code. llama.cpp builds its Metal library from source on the user's
+/// machine, with the compiler that ships in macOS, so a shader a newer macOS
+/// accepts can fail on an older one (b11960 on macOS 14 and 15). The log then
+/// carries `ggml_metal_init: error: failed to initialize the Metal library`
+/// after a page of compiler output nobody outside llama.cpp can act on.
+fn stderr_blames_the_metal_library(stderr: &str) -> bool {
+ const MARKERS: &[&str] = &[
+ "failed to initialize the metal library",
+ "ggml_metal_library_compile_all: failed to build",
+ ];
+ let lower = stderr.to_ascii_lowercase();
+ MARKERS.iter().any(|m| lower.contains(m))
+}
+
+/// The sentence a user reads instead of the Metal compiler output.
+const METAL_LIBRARY_HINT: &str = "This Mac could not prepare the graphics code of the LU Engine, so no model could load. Update the app and macOS to the newest version. Until then Ollama works as a backend, pick it in Settings, AI Backends.";
+
fn stderr_blames_the_model(stderr: &str) -> bool {
const MARKERS: &[&str] = &[
"unknown model architecture",
@@ -3161,6 +3179,9 @@ fn illegal_instruction_repair_sentence(module_count: Option<usize>, is_macos: bo
/// Order, most specific (something the CHILD process itself proved) first:
/// 1. A named missing system library (`stderr_names_a_missing_system_library`),
/// read straight off the loader's own error line.
+/// 1b. A40 (3.1.2): a Metal library the Mac's own shader compiler refused
+/// (`stderr_blames_the_metal_library`). Neither a file nor an install
+/// problem, so neither "download it again" nor "reinstall" fits.
/// 2. `backend_dir_too_long`: a too-long install path is checked BEFORE the
/// general model-blame step, not after. Blocker 9: `stderr_blames_the_model`
/// (step 3) matches `failed to load model`, which llama.cpp prints on load
@@ -3182,6 +3203,8 @@ fn illegal_instruction_repair_sentence(module_count: Option<usize>, is_macos: bo
fn died_failure_hint(stderr: &str, backend_dir_too_long: bool, on_linux: bool) -> String {
if let Some(lib) = stderr_names_a_missing_system_library(stderr) {
missing_library_hint(&lib, on_linux)
+ } else if stderr_blames_the_metal_library(stderr) {
+ format!(" {METAL_LIBRARY_HINT}")
} else if let Some(arch) = stderr_names_an_unknown_architecture(stderr) {
format!(" The model file is a {arch} model, and this LU Engine does not know that architecture yet. Downloading it again will not help. Run it through Ollama, or pick another model.")
} else if backend_dir_too_long {
@@ -3323,7 +3346,9 @@ pub(crate) fn start_failure_message(
budget.as_secs()
)
};
- if failure.stderr.is_empty() {
+ // A40: the Metal compiler output is a page of shader source and helps no
+ // reader of this message. The log file under Troubleshoot keeps all of it.
+ if failure.stderr.is_empty() || stderr_blames_the_metal_library(&failure.stderr) {
head
} else {
format!("{head}\n\n{}", failure.stderr)
@@ -3341,6 +3366,11 @@ pub(crate) fn start_failure_message(
/// already refused a stranger on the port above and does not retry, so the
/// port and retry wording would not be true.
pub(crate) fn embed_start_failure_message(timeout_error: &str, stderr_tail: &str) -> String {
+ if stderr_blames_the_metal_library(stderr_tail) {
+ // A40: the embeddings server is the same binary, so the same Metal
+ // failure kills Document Chat. Same sentence, no shader dump.
+ return format!("The embeddings server of the LU Engine could not start. {METAL_LIBRARY_HINT}");
+ }
let hint = stderr_names_a_missing_system_library(stderr_tail)
.map(|lib| missing_library_hint(&lib, cfg!(target_os = "linux")))
.unwrap_or_default();
@@ -4444,7 +4474,19 @@ fn spawn_engine_attempt(
// Without it a two-card box spreads the model over both, and the video on
// the other card runs out of memory. Added here, not in build_server_args,
// so every attempt and every restart gets it from one place.
- if let Some(device) = chat_engine_device(state, binary, backend_dir) {
+ //
+ // A40 (GH #259, 3.1.2): on a Mac the processor-only attempt also says
+ // `--device none`. `-ngl 0` alone keeps no layers on the GPU, but
+ // llama.cpp still opens the Metal backend for the context and compiles
+ // its shader library there, so a Metal library the system compiler
+ // refuses killed the "CPU" retry with the same error as the first try.
+ // With no device the Metal context is never created. Mac only for now:
+ // on Windows and Linux the Vulkan behaviour of this flag is not measured
+ // on the box yet, and the chat-card pin below is never set on a Mac.
+ if flags.cpu_fallback && cfg!(target_os = "macos") {
+ tracing::info!(target: "engine", "the processor-only attempt runs with --device none, so Metal is not opened at all");
+ cmd.args(["--device", "none"]);
+ } else if let Some(device) = chat_engine_device(state, binary, backend_dir) {
tracing::info!(target: "engine", device = %device, "the LU Engine is pinned to the chat card");
cmd.args(["--device", device.as_str()]);
}
@@ -7663,6 +7705,63 @@ mod tests {
);
}
+ /// A40 (GH #259): the stderr tail of 3.1.1 on macOS 15.7.4, M1 Max, as
+ /// the reporter pasted it (shortened, the shader lines kept).
+ const METAL_LIBRARY_STDERR: &str = "program_source:1570:26: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
+inline constexpr bfloat4 ggml_metal_unary_cast<bfloat4, float4>(float4 x) {
+ ^
+program_source:1571:27: note: subexpression not valid in a constant expression
+ return bfloat4(bfloat(x[0]), bfloat(x[1]), bfloat(x[2]), bfloat(x[3]));
+ ^
+0.00.190.668 E ggml_metal_init: error: failed to initialize the Metal library
+0.00.190.675 E ggml_backend_metal_device_init_backend: error: failed to allocate context
+0.00.190.709 E llama_init_from_model: failed to initialize the context: failed to initialize MTL0 backend
+0.00.190.712 E cmn common_init_: failed to create context with model '/m.gguf'
+0.00.190.715 I srv operator(): operator(): cleaning up before exit...
+0.00.190.946 E srv server_run_i: exiting due to model loading error";
+
+ #[test]
+ fn a_metal_library_the_mac_refuses_gets_a_sentence_and_no_shader_dump() {
+ let failure = StartFailure {
+ died: true,
+ port_taken: false,
+ stderr: METAL_LIBRARY_STDERR.into(),
+ exit_code: Some(1),
+ signal: None,
+ };
+ for second in [SecondAttempt::CpuOnly, SecondAttempt::SameOffload] {
+ let msg = start_failure_message(&failure, 8127, Duration::from_secs(60), second, None);
+ assert!(msg.contains(METAL_LIBRARY_HINT), "{msg}");
+ assert!(!msg.contains("program_source"), "{msg}");
+ assert!(!msg.contains("bfloat4"), "{msg}");
+ // Not the reinstall advice: a reinstall brings back the same binary.
+ assert!(!msg.contains("Reinstall"), "{msg}");
+ // Not the GPU-Layers advice either, the retry already ran without
+ // the card and Metal is no name in GPU_BACKENDS.
+ assert!(!msg.contains("set GPU Layers to 0"), "{msg}");
+ }
+ let embed = embed_start_failure_message("LU Engine did not become healthy on port 8128 within 30s", METAL_LIBRARY_STDERR);
+ assert!(embed.contains(METAL_LIBRARY_HINT), "{embed}");
+ assert!(!embed.contains("program_source"), "{embed}");
+ // Any other death still carries llama-server's own words.
+ let other = embed_start_failure_message("x", "some other line");
+ assert!(other.contains("some other line"), "{other}");
+ }
+
+ #[test]
+ fn the_processor_only_attempt_on_a_mac_opens_no_metal_device() {
+ // `-ngl 0` alone still creates the Metal context, which is where the
+ // shader library is compiled. Only `--device none` keeps it shut, so
+ // the retry has to send it, and only when it is the processor retry.
+ let src = include_str!("engine.rs");
+ let body = &src[src.find("\nfn spawn_engine_attempt(\n").expect("spawn_engine_attempt")..];
+ let body = &body[..body.find("\n}\n").expect("end of spawn_engine_attempt")];
+ let gate = body.find("if flags.cpu_fallback && cfg!(target_os = \"macos\") {").expect("the processor retry gate");
+ let none = body.find("cmd.args([\"--device\", \"none\"]);").expect("--device none");
+ let pin = body.find("chat_engine_device(state, binary, backend_dir)").expect("chat card pin");
+ assert!(gate < none && none < pin, "--device none is sent before, and instead of, the chat card pin");
+ }
+
#[test]
fn the_second_attempt_says_that_it_ran_on_the_processor() {
// The old message said "It was tried twice" about two identical
diff --git a/src/api/__tests__/build-llama-script.test.ts b/src/api/__tests__/build-llama-script.test.ts
index 47366990..2312d60a 100644
--- a/src/api/__tests__/build-llama-script.test.ts
+++ b/src/api/__tests__/build-llama-script.test.ts
@@ -491,6 +491,22 @@ describe('build-llama.sh — the llama.cpp revision is pinned to a commit', { ti
expect(patch).toContain('+ printf("LU norm %d %.6f\\n", (int) il, v[v.size() / 2]);')
})
+ // A40 (GH #259, 3.1.2): b11960's unary shader did not compile on the Metal
+ // compiler of macOS 14 and 15, so no model loaded there. The patch is
+ // upstream PR 31360 and nothing more: the two constexpr words, one file.
+ it('the repo\'s Metal patch is the upstream unary fix and touches nothing else', () => {
+ const patch = readFileSync(join(REPO_ROOT, 'scripts', 'llama-patches', '0005-metal-unary-bf16-no-constexpr.patch'), 'utf8')
+ expect([...patch.matchAll(/^\+\+\+ b\/(.+)$/gm)].map((m) => m[1])).toEqual(['ggml/src/ggml-metal/kernels/unary.metal'])
+ const removed = patch.split('\n').filter((l) => l.startsWith('-') && !l.startsWith('---'))
+ const added = patch.split('\n').filter((l) => l.startsWith('+') && !l.startsWith('+++'))
+ expect(removed).toEqual([
+ '-inline constexpr bfloat4 ggml_metal_unary_cast<bfloat4, float4>(float4 x) {',
+ '-inline constexpr bfloat4 ggml_metal_unary_cast<bfloat4, float>(float x) {',
+ ])
+ expect(added).toEqual(removed.map((l) => '+' + l.slice(1).replace('constexpr ', '')))
+ expect(patch).toContain('c9daee149d606adc30b4c5b7a3254697c9771e2b')
+ })
+
it('hashes a digest of the binary it installed', () => {
const probe = join(tmp('llama-digest-'), 'artifact')
writeFileSync(probe, 'llama-server')