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(neuron): build the vector tool in the server build, on its backends

purple89c8cd03a2ba
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index fed8db26..b00e5af9 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -545,13 +545,14 @@ jobs:
esac
echo "OK: sidecar boots from $moved, loads a real model, /health answers, and has a libggml-cpu-*.so from $moved/llama mapped, nowhere near the build directory it was compiled in"
- # FEHLER-P11 #7/#8: the vector tool is a static baseline build of its
- # own (build-llama.sh cvector_cmake_flags_for); the app starts it the
- # way it starts the server (cwd and LD_LIBRARY_PATH on the companions
- # directory, engine.rs prepare_tool_command), which it does not need
- # but must not trip over. Same moved-directory proof as above, with a
- # real run: two example lines each way through the tiny model, and the
- # control vector it writes must be there.
+ # FEHLER-P11 #7, E1: the vector tool is an exe of the server build and
+ # loads the same ggml modules (build-llama.sh cvector_ships_for); the
+ # app starts it the way it starts the server (cwd and LD_LIBRARY_PATH
+ # on the companions directory, engine.rs prepare_tool_command). Same
+ # moved-directory proof as above, with a real run: two example lines
+ # each way through the tiny model, the control vector it writes must
+ # be there, and it must load the ggml-cpu variants from the moved
+ # directory (a baseline-only tool took hours on 9B models).
- name: "Vector tool computes from a moved directory (P11)"
if: matrix.sidecar_triple == 'x86_64-unknown-linux-gnu'
shell: bash
@@ -574,7 +575,9 @@ jobs:
|| { echo "FAIL: stories260K.gguf did not match the pinned sha256" >&2; exit 1; }
printf 'Once upon a time there was a happy dog.\nThe sun was bright and everyone smiled.\n' > "$moved/more.txt"
printf 'Once upon a time there was a sad dog.\nThe rain fell and everyone cried.\n' > "$moved/less.txt"
- ( cd "$moved/llama" && "$moved/lu-llama-cvector-generator-${{ matrix.sidecar_triple }}" -m "$model" \
+ # LD_DEBUG=files: glibc names every library it loads; the tool logs
+ # nothing about ggml's backend loading itself.
+ ( cd "$moved/llama" && LD_DEBUG=files "$moved/lu-llama-cvector-generator-${{ matrix.sidecar_triple }}" -m "$model" \
--positive-file "$moved/more.txt" --negative-file "$moved/less.txt" \
-o "$moved/direction.gguf" --method mean -c 256 ) >/tmp/cvector.log 2>&1 || {
cat /tmp/cvector.log
@@ -582,7 +585,9 @@ jobs:
exit 1
}
[ -s "$moved/direction.gguf" ] || { cat /tmp/cvector.log; echo "FAIL: no control vector written" >&2; exit 1; }
- echo "OK: the vector tool computes a control vector from $moved, nowhere near the build directory"
+ grep -E "file=$moved/llama/libggml-cpu-[a-z0-9_]+\.so .*dynamically loaded by" /tmp/cvector.log \
+ || { cat /tmp/cvector.log; echo "FAIL: the vector tool did not load a ggml-cpu variant from $moved/llama" >&2; exit 1; }
+ echo "OK: the vector tool computes a control vector from $moved on a ggml-cpu variant from there, nowhere near the build directory"
# Nachbesserung N5 (review-sidecar.md, Runde 2): before this step,
# release.yml had no real model-load proof for EITHER platform (the
diff --git a/scripts/build-llama-flags.test.mjs b/scripts/build-llama-flags.test.mjs
index e433b4fd..8bac4fee 100644
--- a/scripts/build-llama-flags.test.mjs
+++ b/scripts/build-llama-flags.test.mjs
@@ -15,6 +15,7 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
+import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
@@ -64,51 +65,43 @@ test('mac and Linux cmake flags are untouched by the Windows -MAP fix', () => {
assert.doesNotMatch(cmakeFlagsFor('x86_64-unknown-linux-gnu'), /MAP/);
});
-// FEHLER-P11 #8: the pinned llama.cpp defines the cvector-generator target
-// only with GGML_BACKEND_DL OFF (tools/CMakeLists.txt:35-39), which the
-// Windows/Linux server build needs ON (K1). The vector tool gets a cmake run
-// of its own there: static, CPU only, every ISA option off by name, since
-// GGML_NATIVE=OFF alone turns AVX/AVX2 on (INS_ENB). The server flags stay
-// as they were.
+// E1 (3.0.9): the vector tool comes out of the server build on every
+// platform. Upstream defines its target only without GGML_BACKEND_DL; LU's
+// patch 0002 lifts that, so on Windows/Linux it loads the same CPU variants
+// and Vulkan as the server. The static CPU-only baseline build it had there
+// before (FEHLER-P11 #8) made Neurons take hours on 9B models.
function sourced(call) {
return execFileSync('bash', ['-c', `source "${SCRIPT}"; ${call}`], { encoding: 'utf8' }).trim();
}
-const ISA_OPTIONS = ['SSE42', 'AVX', 'AVX_VNNI', 'AVX2', 'BMI2', 'FMA', 'F16C', 'AVX512', 'AVX512_VBMI', 'AVX512_VNNI', 'AVX512_BF16', 'AMX_TILE', 'AMX_INT8', 'AMX_BF16'];
-
-for (const triple of ['x86_64-pc-windows-msvc', 'x86_64-unknown-linux-gnu']) {
- test(`P11 #8: ${triple} builds the vector tool apart from the server`, () => {
- assert.equal(sourced(`cvector_separate_build_for ${triple} && echo yes || echo no`), 'yes');
- const flags = sourced(`cvector_cmake_flags_for ${triple}`);
- for (const f of ['BUILD_SHARED_LIBS=OFF', 'GGML_BACKEND_DL=OFF', 'GGML_CPU_ALL_VARIANTS=OFF', 'GGML_VULKAN=OFF', 'GGML_OPENMP=OFF', 'GGML_NATIVE=OFF']) {
- assert.match(flags, new RegExp(`-D${f}\\b`), f);
- }
- for (const isa of ISA_OPTIONS) assert.match(flags, new RegExp(`-DGGML_${isa}=OFF\\b`), `GGML_${isa} must be off by name`);
- assert.doesNotMatch(flags, /=ON\b/, 'nothing in the vector tool build is switched on');
- assert.notEqual(sourced(`cvector_build_dir_for ${triple}`), sourced(`echo "$CACHE_DIR/build-${triple}"`), 'its own build directory');
- // The server build is the K1 one, untouched.
- assert.match(cmakeFlagsFor(triple), /-DGGML_BACKEND_DL=ON\b/);
- assert.match(cmakeFlagsFor(triple), /-DGGML_CPU_ALL_VARIANTS=ON\b/);
+for (const triple of ['x86_64-pc-windows-msvc', 'x86_64-unknown-linux-gnu', 'aarch64-apple-darwin']) {
+ test(`E1: ${triple} builds the vector tool in the server build`, () => {
+ assert.equal(sourced(`cvector_ships_for ${triple} && echo yes || echo no`), 'yes');
+ assert.equal(sourced(`cvector_build_dir_for ${triple}`), sourced(`echo "$CACHE_DIR/build-${triple}"`), 'the server build directory');
+ assert.equal(sourced(`type cvector_cmake_flags_for >/dev/null 2>&1 && echo yes || echo no`), 'no', 'no separate baseline build');
});
}
-test('P11 #8: the Windows vector tool keeps its linker map for the ISA guard', () => {
- assert.match(sourced('cvector_cmake_flags_for x86_64-pc-windows-msvc'), /-DCMAKE_EXE_LINKER_FLAGS=-MAP\b/);
- assert.doesNotMatch(sourced('cvector_cmake_flags_for x86_64-unknown-linux-gnu'), /MAP/);
-});
-
-test('P11 #8: the Mac builds the vector tool in its server build (static there already)', () => {
- assert.equal(sourced('cvector_separate_build_for aarch64-apple-darwin && echo yes || echo no'), 'no');
- assert.equal(sourced('cvector_ships_for aarch64-apple-darwin && echo yes || echo no'), 'yes');
+test('E1: the Windows/Linux server build the tool comes from is the K1 one', () => {
+ for (const triple of ['x86_64-pc-windows-msvc', 'x86_64-unknown-linux-gnu']) {
+ assert.match(cmakeFlagsFor(triple), /-DGGML_BACKEND_DL=ON\b/);
+ assert.match(cmakeFlagsFor(triple), /-DGGML_CPU_ALL_VARIANTS=ON\b/);
+ assert.match(cmakeFlagsFor(triple), /-DGGML_VULKAN=ON\b/);
+ }
});
-test('P11 #9: the Windows vector tool puts jump tables in .rdata, without replacing the MSVC defaults', () => {
- const flags = sourced('cvector_cmake_flags_for x86_64-pc-windows-msvc');
- assert.match(flags, /-DCMAKE_C_FLAGS_INIT=-jumptablerdata\b/);
- assert.match(flags, /-DCMAKE_CXX_FLAGS_INIT=-jumptablerdata\b/);
- assert.doesNotMatch(flags, /-DCMAKE_(C|CXX)_FLAGS=/, 'CMAKE_<LANG>_FLAGS would drop /EHsc and the other MSVC defaults');
- assert.doesNotMatch(flags, /\/jumptablerdata/, 'MSYS rewrites a leading slash into a path, as with /MAP');
- assert.doesNotMatch(sourced('cvector_cmake_flags_for x86_64-unknown-linux-gnu'), /jumptablerdata/);
+test('E1: LU patch 0002 lets the vector tool build with GGML_BACKEND_DL', () => {
+ const patch = readFileSync(new URL('./llama-patches/0002-cvector-generator-backend-dl.patch', import.meta.url), 'utf8');
+ const touched = [...patch.matchAll(/^\+\+\+ b\/(.+)$/gm)].map((m) => m[1]).sort();
+ assert.deepEqual(touched, ['tools/CMakeLists.txt', 'tools/cvector-generator/cvector-generator.cpp', 'tools/cvector-generator/mean.hpp', 'tools/cvector-generator/pca.hpp']);
+ assert.match(patch, /^\+ if \(GGML_CPU\)$/m);
+ assert.match(patch, /^\+ add_subdirectory\(cvector-generator\)$/m);
+ // Every call into ggml-cpu goes; the registry replaces it.
+ for (const gone of ['ggml_backend_cpu_init', 'ggml_backend_cpu_set_n_threads', 'ggml_get_f32_nd', 'ggml_set_f32_nd', 'ggml_get_f32_1d', 'ggml_set_f32_1d']) {
+ assert.doesNotMatch(patch, new RegExp(`^\\+.*\\b${gone}\\(`, 'm'), `${gone} still called`);
+ }
+ assert.match(patch, /ggml_backend_init_by_type\(GGML_BACKEND_DEVICE_TYPE_CPU/);
+ assert.match(patch, /ggml_backend_reg_get_proc_address\(reg, "ggml_backend_set_n_threads"\)/);
});
test('E1 #1: the Windows server build puts jump tables in .rdata too, without replacing the MSVC defaults', () => {
diff --git a/scripts/build-llama.sh b/scripts/build-llama.sh
index 90a125c1..9a8ee4d3 100755
--- a/scripts/build-llama.sh
+++ b/scripts/build-llama.sh
@@ -165,12 +165,16 @@ cmake_flags_for() {
# since they are where an unconditional-AVX regression would actually
# ship. All three linker-flags variables now carry -MAP.
#
- # -jumptablerdata (FEHLER-E1 #1): same reason and spelling as the vector
- # tool's build (cvector_cmake_flags_for, FEHLER-P11 #9). With b11960 the
- # guard read a switch jump table that MSVC had put in llama.dll's .text
- # as "vsqrtph zmm28" at $LN954 of unicode.obj; nothing in that object
- # can emit EVEX (no /arch outside ggml-cpu). In .rdata the guard no
- # longer reads tables as code, so a hit that stays is real code.
+ # -jumptablerdata (FEHLER-E1 #1, FEHLER-P11 #9): MSVC puts switch jump
+ # tables in .text beside the code by default (learn.microsoft.com,
+ # /jumptablerdata), and their entries are image RVAs that the ISA guard
+ # decodes as instructions. With b11960 it read one in llama.dll as
+ # "vsqrtph zmm28" at $LN954 of unicode.obj; nothing in that object can
+ # emit EVEX (no /arch outside ggml-cpu). In .rdata the guard no longer
+ # reads tables as code, so a hit that stays is real code. Set through
+ # CMAKE_<LANG>_FLAGS_INIT, which CMake's Windows-MSVC module appends its
+ # defaults (/EHsc and the rest) to; CMAKE_<LANG>_FLAGS would replace
+ # them. Dash spelling for the same MSYS reason as -MAP. MSVC 17.7+, x64.
echo "$common -DBUILD_SHARED_LIBS=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DGGML_VULKAN=ON -DCMAKE_SHARED_LINKER_FLAGS=-MAP -DCMAKE_EXE_LINKER_FLAGS=-MAP -DCMAKE_MODULE_LINKER_FLAGS=-MAP -DCMAKE_C_FLAGS_INIT=-jumptablerdata -DCMAKE_CXX_FLAGS_INIT=-jumptablerdata" ;;
x86_64-unknown-linux-gnu)
# CMAKE_BUILD_RPATH_USE_ORIGIN=ON (BLOCKER B3): without it,
@@ -236,11 +240,21 @@ quantize_out_name_for() {
# llama-cvector-generator (3.0.9, P11 Neuron tweaker) ships on all three
# desktop platforms: it turns two short lists of example prompts into a
# control vector for the model the user has, which llama-server then applies
-# with --control-vector. Same pinned source tree. On the Mac it comes out of
-# the server's own static build; on Windows and Linux out of a static build
-# of its own (cvector_cmake_flags_for below, FEHLER-P11 #8), one file that
-# needs no library beside it. FEHLER-P11 #7: everything a feature needs must
-# come with the install.
+# with --control-vector. FEHLER-P11 #7: everything a feature needs must come
+# with the install.
+#
+# It comes out of the server's own build on every platform, linked against
+# the same libraries: on the Mac the static Metal build, on Windows and Linux
+# the GGML_BACKEND_DL build with the CPU variants and Vulkan as loadable
+# modules (K1). Upstream defines the target only without GGML_BACKEND_DL,
+# because the generator calls ggml-cpu directly; LU's patch
+# 0002-cvector-generator-backend-dl.patch reaches those through the backend
+# registry instead and lifts that condition. So the tool computes on the
+# GPU (LU passes -ngl 99) and otherwise on the best CPU variant, like the
+# server. Until E1 (3.0.9) Windows and Linux had a static CPU-only baseline
+# build of their own (FEHLER-P11 #8), without SSE4.2/AVX/AVX2: LFM3 1.7B
+# took ~25 min on the box against 30 s on the Mac, a 9B model hours. That
+# build is gone; its ISA rules hold for the tool as for the server exe.
cvector_ships_for() {
case "$1" in
*-apple-darwin | x86_64-pc-windows-msvc | x86_64-unknown-linux-gnu) return 0 ;;
@@ -248,59 +262,10 @@ cvector_ships_for() {
esac
}
-# FEHLER-P11 #8: the pinned llama.cpp only defines the cvector-generator
-# target when GGML_BACKEND_DL is OFF (tools/CMakeLists.txt:35-39, "these
-# tools use backends directly ... and depend on CPU backend symbols"). The
-# server build on Windows and Linux needs BACKEND_DL ON (K1, the dynamic
-# CPU variants), so there the generator gets a cmake run of its own, in its
-# own build directory, and the server build is left exactly as it was.
-#
-# What that run builds, and why:
-# - static (BUILD_SHARED_LIBS=OFF): one self-contained file, no companion
-# library to stage, find or keep in step with the server's;
-# - CPU only (no GGML_VULKAN): no hard link to vulkan-1.dll/libvulkan.so,
-# so the tool starts on a machine without a GPU driver as well. It reads
-# some 40 short example pairs once per slider; the strength check after
-# it runs on the engine (GPU), not here;
-# - the K1 baseline: GGML_NATIVE=OFF alone switches SSE4.2/AVX/AVX2/FMA/
-# F16C/BMI2 ON (ggml/CMakeLists.txt:141-166, INS_ENB), the exact K1
-# crash on older CPUs, and a static build has no CPU variants to fall
-# back on. So every ISA option is set OFF by name, and
-# verify-sidecar-isa.sh checks the built file like the server exe
-# (baseline: no AVX instruction);
-# - no OpenMP: ggml's own thread pool, so no vcomp140.dll/libgomp.so is
-# needed beside it;
-# - Windows keeps -MAP, the ISA guard reads the linker map;
-# - Windows puts switch jump tables in .rdata (-jumptablerdata, MSVC 17.7+,
-# x64 only). By default MSVC places them in .text beside the code
-# (learn.microsoft.com, /jumptablerdata), and their entries are image
-# RVAs, so in this exe they decode as instructions that are not there:
-# FEHLER-P11 #9, an "unprotected" EVEX vfmadd132ss xmm21 at a $LN label
-# of speculative.obj, while the same object in the server's
-# llama-common.dll (other RVAs) reads clean. Nothing in this build may
-# emit EVEX (no /arch, every ISA option off), so moving the tables out
-# of .text is the fix and the proof at once: if the guard still finds
-# the hit, it is real code. Set through CMAKE_<LANG>_FLAGS_INIT, which
-# CMake's Windows-MSVC module appends its defaults (/EHsc and the rest)
-# to; CMAKE_<LANG>_FLAGS itself would replace them. Dash spelling for
-# the same MSYS reason as -MAP.
-cvector_separate_build_for() {
- is_dynamic_isa_triple "$1"
-}
-
-cvector_cmake_flags_for() {
- local triple="$1"
- local common="-DLLAMA_OPENSSL=OFF -DLLAMA_BUILD_UI=OFF -DLLAMA_USE_PREBUILT_UI=OFF -DCMAKE_BUILD_TYPE=Release"
- local cpu="-DBUILD_SHARED_LIBS=OFF -DGGML_BACKEND_DL=OFF -DGGML_CPU_ALL_VARIANTS=OFF -DGGML_VULKAN=OFF -DGGML_OPENMP=OFF -DGGML_NATIVE=OFF -DGGML_SSE42=OFF -DGGML_AVX=OFF -DGGML_AVX_VNNI=OFF -DGGML_AVX2=OFF -DGGML_BMI2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_AVX512=OFF -DGGML_AVX512_VBMI=OFF -DGGML_AVX512_VNNI=OFF -DGGML_AVX512_BF16=OFF -DGGML_AMX_TILE=OFF -DGGML_AMX_INT8=OFF -DGGML_AMX_BF16=OFF"
- case "$triple" in
- x86_64-pc-windows-msvc) echo "$common $cpu -DCMAKE_EXE_LINKER_FLAGS=-MAP -DCMAKE_C_FLAGS_INIT=-jumptablerdata -DCMAKE_CXX_FLAGS_INIT=-jumptablerdata" ;;
- x86_64-unknown-linux-gnu) echo "$common $cpu" ;;
- *) die "no separate vector-tool build for $triple" ;;
- esac
-}
-
+# Where the tool is built, and where verify-sidecar-isa.sh finds its linker
+# map on Windows: the server's build directory.
cvector_build_dir_for() {
- echo "$CACHE_DIR/build-$1-cvector"
+ echo "$CACHE_DIR/build-$1"
}
cvector_out_name_for() {
@@ -585,16 +550,8 @@ build_triple() {
if quantize_ships_for "$triple"; then
cmake --build "$build_dir" --config Release --target llama-quantize -j "${BUILD_JOBS:-4}"
fi
- local cv_build_dir="$build_dir"
if cvector_ships_for "$triple"; then
- if cvector_separate_build_for "$triple"; then
- cv_build_dir="$(cvector_build_dir_for "$triple")"
- local cv_flags; cv_flags="$(cvector_cmake_flags_for "$triple")"
- log "configuring the vector tool for $triple apart from the server ($cv_flags)"
- # shellcheck disable=SC2086
- cmake -S "$SRC_DIR" -B "$cv_build_dir" $cv_flags
- fi
- cmake --build "$cv_build_dir" --config Release --target llama-cvector-generator -j "${BUILD_JOBS:-4}"
+ cmake --build "$build_dir" --config Release --target llama-cvector-generator -j "${BUILD_JOBS:-4}"
fi
# Locate the produced binary (path differs by generator/platform).
local built
@@ -613,8 +570,8 @@ build_triple() {
fi
if cvector_ships_for "$triple"; then
local built_cv
- built_cv="$(find "$cv_build_dir" -type f \( -name 'llama-cvector-generator' -o -name 'llama-cvector-generator.exe' \) -print -quit)"
- [ -n "$built_cv" ] || die "llama-cvector-generator binary not found under $cv_build_dir"
+ built_cv="$(find "$build_dir" -type f \( -name 'llama-cvector-generator' -o -name 'llama-cvector-generator.exe' \) -print -quit)"
+ [ -n "$built_cv" ] || die "llama-cvector-generator binary not found under $build_dir"
cp "$built_cv" "$BIN_DIR/$(cvector_out_name_for "$triple")"
chmod +x "$BIN_DIR/$(cvector_out_name_for "$triple")"
fi
diff --git a/scripts/llama-patches/0002-cvector-generator-backend-dl.patch b/scripts/llama-patches/0002-cvector-generator-backend-dl.patch
new file mode 100644
index 00000000..ef7981bd
--- /dev/null
+++ b/scripts/llama-patches/0002-cvector-generator-backend-dl.patch
@@ -0,0 +1,151 @@
+diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
+index 6a6592c..1e0f8ac 100644
+--- a/tools/CMakeLists.txt
++++ b/tools/CMakeLists.txt
+@@ -35,9 +35,13 @@ else()
+ if (LLAMA_CONNECT)
+ add_subdirectory(connect)
+ endif()
++ if (GGML_CPU)
++ # LU: cvector-generator reaches its backends through the registry, so
++ # it also builds with GGML_BACKEND_DL (LU's Windows/Linux sidecar)
++ add_subdirectory(cvector-generator)
++ endif()
+ if (NOT GGML_BACKEND_DL AND GGML_CPU)
+ # these tools use backends directly (no dynamic loading) and depend on CPU backend symbols
+- add_subdirectory(cvector-generator)
+ add_subdirectory(export-lora)
+ endif()
+ add_subdirectory(fit-params)
+diff --git a/tools/cvector-generator/cvector-generator.cpp b/tools/cvector-generator/cvector-generator.cpp
+index 829fb35..60af47e 100644
+--- a/tools/cvector-generator/cvector-generator.cpp
++++ b/tools/cvector-generator/cvector-generator.cpp
+@@ -121,7 +121,7 @@ struct callback_data {
+ // check if given row containing all zero elements
+ int n_cols = t->ne[0]; // hint: should be equal to n_embd
+ for (int col = 0; col < n_cols; ++col) {
+- if (ggml_get_f32_nd(t, col, row, 0, 0) > eps) {
++ if (lu_get_f32_nd(t, col, row, 0, 0) > eps) {
+ return false;
+ }
+ }
+@@ -150,8 +150,8 @@ struct callback_data {
+ for (int dest_row = 0; dest_row < n_nonzero_rows; dest_row++) {
+ int src_row = rows_to_copy[dest_row];
+ for (int i = 0; i < n_embd; i++) {
+- float src_elem = ggml_get_f32_nd(a, i, src_row, 0, 0);
+- ggml_set_f32_nd(diff_filtered, i, dest_row, 0, 0, src_elem);
++ float src_elem = lu_get_f32_nd(a, i, src_row, 0, 0);
++ lu_set_f32_nd(diff_filtered, i, dest_row, 0, 0, src_elem);
+ }
+ }
+
+@@ -248,7 +248,7 @@ struct train_context {
+ for (int ir = 0; ir < n_rows; ++ir) {
+ for (int ic = 0; ic < n_embd; ++ic) {
+ float f = arr[ir*n_embd + ic];
+- ggml_set_f32_nd(diff, ir, ic, 0, 0, f);
++ lu_set_f32_nd(diff, ir, ic, 0, 0, f);
+ }
+ }
+ } else {
+diff --git a/tools/cvector-generator/mean.hpp b/tools/cvector-generator/mean.hpp
+index 4eeac1e..bdbc556 100644
+--- a/tools/cvector-generator/mean.hpp
++++ b/tools/cvector-generator/mean.hpp
+@@ -23,22 +23,22 @@ static void run(
+ for (int ic = 0; ic < t_layer->ne[0]; ic++) {
+ float f = 0.0;
+ for (int ir = 0; ir < t_layer->ne[1]; ir++) {
+- f += ggml_get_f32_nd(t_layer, ic, ir, 0, 0);
++ f += lu_get_f32_nd(t_layer, ic, ir, 0, 0);
+ }
+ f /= t_layer->ne[1];
+- ggml_set_f32_1d(ctrl_out, ic, f);
++ lu_set_f32_1d(ctrl_out, ic, f);
+ }
+
+ // normalize output vector
+ float norm = 0.0;
+ for (int i = 0; i < ggml_nelements(ctrl_out); i++) {
+- float f = ggml_get_f32_1d(ctrl_out, i);
++ float f = lu_get_f32_1d(ctrl_out, i);
+ norm += f*f;
+ }
+ norm = sqrt(norm);
+ for (int i = 0; i < ggml_nelements(ctrl_out); i++) {
+- float f = ggml_get_f32_1d(ctrl_out, i);
+- ggml_set_f32_1d(ctrl_out, i, f / norm);
++ float f = lu_get_f32_1d(ctrl_out, i);
++ lu_set_f32_1d(ctrl_out, i, f / norm);
+ }
+
+ printf("%s: Done layer %d / %d\n", __func__, (int) il+1, (int) v_input.size());
+diff --git a/tools/cvector-generator/pca.hpp b/tools/cvector-generator/pca.hpp
+index afd3bf6..b629b04 100644
+--- a/tools/cvector-generator/pca.hpp
++++ b/tools/cvector-generator/pca.hpp
+@@ -16,6 +16,30 @@
+ #include <string>
+ #include <vector>
+
++// LU: the generator reads and writes its own host F32 tensors with these
++// instead of ggml-cpu's ggml_{get,set}_f32_{1d,nd}, and reaches the CPU
++// backend through the registry, so it builds with GGML_BACKEND_DL as well
++// and runs on the server's dynamically loaded backends (CPU variants, GPU).
++static float lu_get_f32_nd(const struct ggml_tensor * t, int i0, int i1, int i2, int i3) {
++ GGML_ASSERT(t->type == GGML_TYPE_F32);
++ return *(const float *) ((const char *) t->data + i0*t->nb[0] + i1*t->nb[1] + i2*t->nb[2] + i3*t->nb[3]);
++}
++
++static void lu_set_f32_nd(const struct ggml_tensor * t, int i0, int i1, int i2, int i3, float value) {
++ GGML_ASSERT(t->type == GGML_TYPE_F32);
++ *(float *) ((char *) t->data + i0*t->nb[0] + i1*t->nb[1] + i2*t->nb[2] + i3*t->nb[3]) = value;
++}
++
++static float lu_get_f32_1d(const struct ggml_tensor * t, int i) {
++ GGML_ASSERT(t->type == GGML_TYPE_F32 && ggml_is_contiguous(t));
++ return ((const float *) t->data)[i];
++}
++
++static void lu_set_f32_1d(const struct ggml_tensor * t, int i, float value) {
++ GGML_ASSERT(t->type == GGML_TYPE_F32 && ggml_is_contiguous(t));
++ ((float *) t->data)[i] = value;
++}
++
+ #define DEBUG_POS 5
+
+ static void print_debug_tensor(struct ggml_tensor * t, bool with_data = true) {
+@@ -23,7 +47,7 @@ static void print_debug_tensor(struct ggml_tensor * t, bool with_data = true) {
+ if (!with_data) return;
+ printf("%s: %s[0] = [", __func__, t->name);
+ for (size_t i = 0; i <= DEBUG_POS; i++) {
+- printf(" %f,", ggml_get_f32_nd(t, i, 0, 0, 0));
++ printf(" %f,", lu_get_f32_nd(t, i, 0, 0, 0));
+ }
+ printf(" ... ]\n");
+ }
+@@ -80,7 +104,7 @@ struct pca_model {
+
+ // if there aren't GPU Backends fallback to CPU backend
+ if (!backend) {
+- backend = ggml_backend_cpu_init();
++ backend = ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr);
+ }
+
+ const int num_tensors = 4;
+@@ -200,8 +224,11 @@ static ggml_status compute_piter(
+ // allocate tensors
+ ggml_gallocr_alloc_graph(allocr, gf);
+
+- if (ggml_backend_is_cpu(model.backend)) {
+- ggml_backend_cpu_set_n_threads(model.backend, params.n_threads);
++ ggml_backend_dev_t dev = ggml_backend_get_device(model.backend);
++ ggml_backend_reg_t reg = dev ? ggml_backend_dev_backend_reg(dev) : nullptr;
++ auto set_n_threads = reg ? (ggml_backend_set_n_threads_t) ggml_backend_reg_get_proc_address(reg, "ggml_backend_set_n_threads") : nullptr;
++ if (set_n_threads) {
++ set_n_threads(model.backend, params.n_threads);
+ }
+
+ ggml_status res = ggml_backend_graph_compute(model.backend, gf);
diff --git a/scripts/verify-sidecar-isa.sh b/scripts/verify-sidecar-isa.sh
index 7c46e55e..cefcbbcf 100755
--- a/scripts/verify-sidecar-isa.sh
+++ b/scripts/verify-sidecar-isa.sh
@@ -546,10 +546,10 @@ if [[ "$TRIPLE" == *-windows-* ]]; then
vlog "no exe found at $exe_path, skipping the exe-itself check (build first for the full check)"
fi
- # FEHLER-P11 #8: the Neuron tweaker's vector tool is a static exe of its
- # own (build-llama.sh cvector_cmake_flags_for), so every ggml-cpu line it
- # carries is the baseline one and must hold the same rule as the server
- # exe. Its map lies in its own build directory.
+ # The Neuron tweaker's vector tool (P11) is an exe of the server build
+ # (build-llama.sh, cvector_ships_for) that loads the same ggml modules, so
+ # it holds the same rule as the server exe. Its map lies beside the
+ # server's (cvector_build_dir_for).
cv_path="$BIN_DIR/$(cvector_out_name_for "$TRIPLE")"
if [ -f "$cv_path" ]; then
cv_map="$(find "${WIN_CVEC_MAP_DIR_OVERRIDE:-$(cvector_build_dir_for "$TRIPLE")}" -type f -iname 'llama-cvector-generator.map' -print -quit 2>/dev/null)"
@@ -926,8 +926,8 @@ else
vlog "no exe found at $exe_path, skipping the exe-itself check (build first for the full check)"
fi
-# FEHLER-P11 #8: the vector tool, a static baseline exe of its own (see the
-# Windows branch above), holds the server exe's rule.
+# The vector tool, an exe of the server build (see the Windows branch above),
+# holds the server exe's rule.
cv_path="$BIN_DIR/$(cvector_out_name_for "$TRIPLE")"
if [ -f "$cv_path" ]; then
asm="$(disassemble "$cv_path")"
diff --git a/src/api/__tests__/build-llama-script.test.ts b/src/api/__tests__/build-llama-script.test.ts
index 7361c37b..20b5e256 100644
--- a/src/api/__tests__/build-llama-script.test.ts
+++ b/src/api/__tests__/build-llama-script.test.ts
@@ -507,14 +507,15 @@ describe('build-llama.sh — the llama.cpp revision is pinned to a commit', { ti
})
/**
- * FEHLER-P11 #8: the pinned llama.cpp defines the cvector-generator target
- * only without GGML_BACKEND_DL, which the Windows/Linux server build needs.
- * build_triple therefore configures the vector tool apart from the server.
- * Run with a stand-in `cmake` that records its calls and writes the files a
- * real build would, in a throwaway checkout: the order and the directories
- * are the point, not the compile.
+ * E1: the vector tool comes out of the server build on every platform (LU
+ * patch 0002 lets it build with GGML_BACKEND_DL), so on Windows/Linux it
+ * runs on the server's CPU variants and Vulkan instead of a static baseline
+ * build of its own (FEHLER-P11 #8, hours on 9B models). Run with a stand-in
+ * `cmake` that records its calls and writes the files a real build would, in
+ * a throwaway checkout: the order and the directories are the point, not the
+ * compile.
*/
-describe('build-llama.sh: the vector tool gets a cmake run of its own on Windows and Linux', () => {
+describe('build-llama.sh: the vector tool comes out of the server build', () => {
const temps: string[] = []
const tmp = (prefix: string) => {
const dir = mkdtempSync(join(tmpdir(), prefix))
@@ -552,22 +553,18 @@ cmake() {
}
for (const triple of ['x86_64-unknown-linux-gnu', 'x86_64-pc-windows-msvc']) {
- it(`${triple}: server as before, the tool from its own static baseline build`, () => {
+ it(`${triple}: one K1 build makes the server and the tool`, () => {
const r = build(triple)
expect(r.code, r.out).toBe(0)
const server = `${r.cache}/build-${triple}`
- const tool = `${r.cache}/build-${triple}-cvector`
const configures = r.calls.filter((c) => c.startsWith('configure '))
- expect(configures).toHaveLength(2)
+ expect(configures).toHaveLength(1)
expect(configures[0]).toContain(`configure ${server} `)
expect(configures[0]).toContain('-DGGML_BACKEND_DL=ON')
- expect(configures[1]).toContain(`configure ${tool} `)
- expect(configures[1]).toContain('-DGGML_BACKEND_DL=OFF')
- expect(configures[1]).toContain('-DBUILD_SHARED_LIBS=OFF')
- expect(configures[1]).toContain('-DGGML_AVX2=OFF')
+ expect(configures[0]).toContain('-DGGML_CPU_ALL_VARIANTS=ON')
expect(r.calls).toContain(`build ${server} llama-server`)
- expect(r.calls).toContain(`build ${tool} llama-cvector-generator`)
- expect(r.calls).not.toContain(`build ${server} llama-cvector-generator`)
+ expect(r.calls).toContain(`build ${server} llama-cvector-generator`)
+ expect(r.calls.some((c) => c.includes(`build-${triple}-cvector`))).toBe(false)
const exe = triple.includes('windows') ? '.exe' : ''
expect(existsSync(join(r.repoRoot, 'src-tauri', 'bin', `lu-llama-cvector-generator-${triple}${exe}`))).toBe(true)
expect(existsSync(join(r.repoRoot, 'src-tauri', 'bin', `lu-llama-server-${triple}${exe}`))).toBe(true)