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.

ci(neuron): build P11's patches 0003/0004 into the vector tool and run it on every platform

purple4c5567eba088
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b00e5af9..b5925aa2 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -587,7 +587,21 @@ jobs:
[ -s "$moved/direction.gguf" ] || { cat /tmp/cvector.log; echo "FAIL: no control vector written" >&2; exit 1; }
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"
+ # LU patches 0003 and 0004 (P11): the progress line the app reads,
+ # and the measuring mode single-neuron doses are counted in.
+ grep -q 'Evaluating prompt\[2/2\]' /tmp/cvector.log \
+ || { cat /tmp/cvector.log; echo "FAIL: no progress line for the last prompt (patch 0003)" >&2; exit 1; }
+ ( cd "$moved/llama" && LU_LAYER_NORMS=1 "$moved/lu-llama-cvector-generator-${{ matrix.sidecar_triple }}" -m "$model" \
+ --positive-file "$moved/more.txt" --negative-file "$moved/less.txt" \
+ -o "$moved/norms.gguf" --method mean -c 256 ) >/tmp/cvector-norms.log 2>&1 || {
+ cat /tmp/cvector-norms.log
+ echo "FAIL: the vector tool's measuring mode (LU_LAYER_NORMS, patch 0004) exited non-zero" >&2
+ exit 1
+ }
+ norms="$(grep -cE '^LU norm [0-9]+ [0-9]+\.[0-9]{6}$' /tmp/cvector-norms.log || true)"
+ [ "$norms" -ge 1 ] && [ ! -e "$moved/norms.gguf" ] \
+ || { cat /tmp/cvector-norms.log; echo "FAIL: LU_LAYER_NORMS printed $norms 'LU norm' lines (want at least 1) or wrote a vector" >&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, and measures $norms layer lengths"
# Nachbesserung N5 (review-sidecar.md, Runde 2): before this step,
# release.yml had no real model-load proof for EITHER platform (the
@@ -669,6 +683,42 @@ jobs:
}
Write-Host "OK - sidecar boots from the resource layout, loads a model, answers /health, and has a ggml-cpu-*.dll from $runDir mapped"
+ # E1, P11: the vector tool is an exe of the server build (LU patch 0002)
+ # and the app starts it from the companions directory like the server
+ # (engine.rs prepare_tool_command). A real run on the tiny model: it
+ # writes a control vector, prints the progress line the app reads (patch
+ # 0003) and measures the layer lengths single-neuron doses are counted
+ # in (LU_LAYER_NORMS, patch 0004).
+ - name: "Vector tool computes from the resource layout (P11)"
+ if: matrix.sidecar_triple == 'x86_64-pc-windows-msvc'
+ shell: pwsh
+ timeout-minutes: 5
+ run: |
+ $tool = (Resolve-Path "src-tauri\bin\lu-llama-cvector-generator-${{ matrix.sidecar_triple }}.exe").Path
+ $runDir = (Resolve-Path "src-tauri\resources\llama\${{ matrix.sidecar_triple }}").Path
+ $model = "$env:RUNNER_TEMP\stories260K.gguf"
+ if (-not (Test-Path $model)) { throw "the boot smoke's model is missing: $model" }
+ $work = "$env:RUNNER_TEMP\cvector"
+ New-Item -ItemType Directory -Force -Path $work | Out-Null
+ Set-Content -Path "$work\more.txt" -Value 'Once upon a time there was a happy dog.', 'The sun was bright and everyone smiled.'
+ Set-Content -Path "$work\less.txt" -Value 'Once upon a time there was a sad dog.', 'The rain fell and everyone cried.'
+ Push-Location $runDir
+ & $tool -m $model --positive-file "$work\more.txt" --negative-file "$work\less.txt" -o "$work\direction.gguf" --method mean -c 256 *> "$work\cvector.log"
+ $vectorExit = $LASTEXITCODE
+ $env:LU_LAYER_NORMS = '1'
+ & $tool -m $model --positive-file "$work\more.txt" --negative-file "$work\less.txt" -o "$work\norms.gguf" --method mean -c 256 *> "$work\cvector-norms.log"
+ $normsExit = $LASTEXITCODE
+ Remove-Item Env:\LU_LAYER_NORMS
+ Pop-Location
+ Get-Content "$work\cvector.log", "$work\cvector-norms.log"
+ if ($vectorExit -ne 0) { throw "lu-llama-cvector-generator exited $vectorExit (run from $runDir)" }
+ if (-not (Test-Path "$work\direction.gguf")) { throw "no control vector written" }
+ if (-not (Select-String -Path "$work\cvector.log" -Pattern 'Evaluating prompt[2/2]' -SimpleMatch -Quiet)) { throw "no progress line for the last prompt (patch 0003)" }
+ if ($normsExit -ne 0) { throw "the measuring mode (LU_LAYER_NORMS, patch 0004) exited $normsExit" }
+ $norms = @(Select-String -Path "$work\cvector-norms.log" -Pattern '^LU norm [0-9]+ [0-9]+\.[0-9]{6}$').Count
+ if ($norms -lt 1 -or (Test-Path "$work\norms.gguf")) { throw "LU_LAYER_NORMS printed $norms 'LU norm' lines (want at least 1) or wrote a vector" }
+ Write-Host "OK - the vector tool computes a control vector from $runDir and measures $norms layer lengths"
+
# ── App build ────────────────────────────────────────────────────────
- name: Install npm dependencies
run: npm ci
@@ -1387,6 +1437,45 @@ jobs:
fi
echo "OK: the sidecar starts outside its build directory, loads a model and answers /health"
+ # P11: a real run of the vector tool on the tiny model, as on Linux and
+ # Windows: it writes a control vector, prints the progress line the app
+ # reads (LU patch 0003) and measures the layer lengths single-neuron
+ # doses are counted in (LU_LAYER_NORMS, patch 0004). `-ngl 0` for the
+ # reason the boot smoke above gives.
+ - name: "Vector tool computes outside its build directory (P11)"
+ shell: bash
+ timeout-minutes: 5
+ run: |
+ set -euo pipefail
+ tool="$PWD/src-tauri/bin/lu-llama-cvector-generator-$SIDECAR_TRIPLE"
+ model="$RUNNER_TEMP/stories260K.gguf"
+ echo "${STORIES260K_SHA256} $model" | shasum -a 256 -c - \
+ || { echo "FAIL: the boot smoke's stories260K.gguf is missing or does not match the pinned sha256" >&2; exit 1; }
+ work="$RUNNER_TEMP/cvector"
+ rm -rf "$work"
+ mkdir -p "$work"
+ printf 'Once upon a time there was a happy dog.\nThe sun was bright and everyone smiled.\n' > "$work/more.txt"
+ printf 'Once upon a time there was a sad dog.\nThe rain fell and everyone cried.\n' > "$work/less.txt"
+ ( cd "$work" && "$tool" -m "$model" --positive-file more.txt --negative-file less.txt \
+ -o direction.gguf --method mean -ngl 0 -c 256 ) >"$work/cvector.log" 2>&1 || {
+ cat "$work/cvector.log"
+ echo "FAIL: lu-llama-cvector-generator exited non-zero" >&2
+ exit 1
+ }
+ [ -s "$work/direction.gguf" ] || { cat "$work/cvector.log"; echo "FAIL: no control vector written" >&2; exit 1; }
+ grep -q 'Evaluating prompt\[2/2\]' "$work/cvector.log" \
+ || { cat "$work/cvector.log"; echo "FAIL: no progress line for the last prompt (patch 0003)" >&2; exit 1; }
+ ( cd "$work" && LU_LAYER_NORMS=1 "$tool" -m "$model" --positive-file more.txt --negative-file less.txt \
+ -o norms.gguf --method mean -ngl 0 -c 256 ) >"$work/cvector-norms.log" 2>&1 || {
+ cat "$work/cvector-norms.log"
+ echo "FAIL: the vector tool's measuring mode (LU_LAYER_NORMS, patch 0004) exited non-zero" >&2
+ exit 1
+ }
+ norms="$(grep -cE '^LU norm [0-9]+ [0-9]+\.[0-9]{6}$' "$work/cvector-norms.log" || true)"
+ [ "$norms" -ge 1 ] && [ ! -e "$work/norms.gguf" ] \
+ || { cat "$work/cvector-norms.log"; echo "FAIL: LU_LAYER_NORMS printed $norms 'LU norm' lines (want at least 1) or wrote a vector" >&2; exit 1; }
+ echo "OK: the vector tool computes a control vector outside its build directory and measures $norms layer lengths"
+
# ── App build, signing, notarization: nothing is uploaded yet ────────
- name: Install npm dependencies
run: npm ci
diff --git a/.github/workflows/sidecar-windows.yml b/.github/workflows/sidecar-windows.yml
index 974dddf7..8137b609 100644
--- a/.github/workflows/sidecar-windows.yml
+++ b/.github/workflows/sidecar-windows.yml
@@ -223,6 +223,41 @@ jobs:
}
Write-Host "OK - sidecar boots from the resource layout, loads a model, answers /health, and has a ggml-cpu-*.dll from $runDir mapped"
+ # E1, P11: the vector tool is an exe of the server build (LU patch 0002)
+ # and the app starts it from the companions directory like the server
+ # (engine.rs prepare_tool_command). A real run on the tiny model: it
+ # writes a control vector, prints the progress line the app reads (patch
+ # 0003) and measures the layer lengths single-neuron doses are counted
+ # in (LU_LAYER_NORMS, patch 0004).
+ - name: "Vector tool computes from the resource layout (P11)"
+ shell: pwsh
+ timeout-minutes: 5
+ run: |
+ $tool = (Resolve-Path "src-tauri\bin\lu-llama-cvector-generator-x86_64-pc-windows-msvc.exe").Path
+ $runDir = (Resolve-Path "src-tauri\resources\llama\x86_64-pc-windows-msvc").Path
+ $model = "D:\lb\stories260K.gguf"
+ if (-not (Test-Path $model)) { throw "the boot smoke's model is missing: $model" }
+ $work = "$env:RUNNER_TEMP\cvector"
+ New-Item -ItemType Directory -Force -Path $work | Out-Null
+ Set-Content -Path "$work\more.txt" -Value 'Once upon a time there was a happy dog.', 'The sun was bright and everyone smiled.'
+ Set-Content -Path "$work\less.txt" -Value 'Once upon a time there was a sad dog.', 'The rain fell and everyone cried.'
+ Push-Location $runDir
+ & $tool -m $model --positive-file "$work\more.txt" --negative-file "$work\less.txt" -o "$work\direction.gguf" --method mean -c 256 *> "$work\cvector.log"
+ $vectorExit = $LASTEXITCODE
+ $env:LU_LAYER_NORMS = '1'
+ & $tool -m $model --positive-file "$work\more.txt" --negative-file "$work\less.txt" -o "$work\norms.gguf" --method mean -c 256 *> "$work\cvector-norms.log"
+ $normsExit = $LASTEXITCODE
+ Remove-Item Env:\LU_LAYER_NORMS
+ Pop-Location
+ Get-Content "$work\cvector.log", "$work\cvector-norms.log"
+ if ($vectorExit -ne 0) { throw "lu-llama-cvector-generator exited $vectorExit (run from $runDir)" }
+ if (-not (Test-Path "$work\direction.gguf")) { throw "no control vector written" }
+ if (-not (Select-String -Path "$work\cvector.log" -Pattern 'Evaluating prompt[2/2]' -SimpleMatch -Quiet)) { throw "no progress line for the last prompt (patch 0003)" }
+ if ($normsExit -ne 0) { throw "the measuring mode (LU_LAYER_NORMS, patch 0004) exited $normsExit" }
+ $norms = @(Select-String -Path "$work\cvector-norms.log" -Pattern '^LU norm [0-9]+ [0-9]+\.[0-9]{6}$').Count
+ if ($norms -lt 1 -or (Test-Path "$work\norms.gguf")) { throw "LU_LAYER_NORMS printed $norms 'LU norm' lines (want at least 1) or wrote a vector" }
+ Write-Host "OK - the vector tool computes a control vector from $runDir and measures $norms layer lengths"
+
- name: Upload sidecar artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
@@ -231,8 +266,8 @@ jobs:
# ggml-cpu-*/ggml-vulkan DLLs staged next to it (see above):
# shipping only the exe from this artifact would be shipping
# something that cannot boot.
- # P11: the Neuron tweaker's vector tool is built in the same run
- # (static, nothing beside it) and ships with the app as well.
+ # P11, E1: the Neuron tweaker's vector tool is an exe of the same
+ # server build, needs the same companions and ships with the app.
path: |
src-tauri/bin/lu-llama-server-x86_64-pc-windows-msvc.exe
src-tauri/bin/lu-llama-cvector-generator-x86_64-pc-windows-msvc.exe
diff --git a/scripts/llama-patches/0003-cvector-generator-progress-flush.patch b/scripts/llama-patches/0003-cvector-generator-progress-flush.patch
new file mode 100644
index 00000000..fbc99a0a
--- /dev/null
+++ b/scripts/llama-patches/0003-cvector-generator-progress-flush.patch
@@ -0,0 +1,12 @@
+--- a/tools/cvector-generator/cvector-generator.cpp
++++ b/tools/cvector-generator/cvector-generator.cpp
+@@ -477,6 +477,9 @@ int main(int argc, char ** argv) {
+ tokens_to_str(ctx, t.tokens_pos.cbegin(), t.tokens_pos.cend()).c_str(),
+ tokens_to_str(ctx, t.tokens_neg.cbegin(), t.tokens_neg.cend()).c_str(),
+ (int) t.max_seq_len);
++ // LU: the app reads this line for progress and time left; over a
++ // pipe stdout is fully buffered and the lines came only in batches.
++ fflush(stdout);
+
+ cb_data.is_eval_pos = true;
+ success = get_hidden_layers(ctx, t.tokens_pos);
diff --git a/scripts/llama-patches/0004-cvector-generator-layer-norms.patch b/scripts/llama-patches/0004-cvector-generator-layer-norms.patch
new file mode 100644
index 00000000..15fd8106
--- /dev/null
+++ b/scripts/llama-patches/0004-cvector-generator-layer-norms.patch
@@ -0,0 +1,69 @@
+--- a/tools/cvector-generator/cvector-generator.cpp
++++ b/tools/cvector-generator/cvector-generator.cpp
+@@ -9,6 +9,9 @@
+ #include "mean.hpp"
+
+ #include <clocale>
++#include <algorithm>
++#include <cmath>
++#include <cstdlib>
+
+ #ifdef GGML_USE_CUDA
+ #include "ggml-cuda.h"
+@@ -466,6 +469,14 @@ int main(int argc, char ** argv) {
+
+ std::cout << "n_total_tokens: " << n_total_tokens << std::endl;
+
++ // LU: with LU_LAYER_NORMS set the tool measures instead of building a
++ // vector: the length of the residual stream after each block, over every
++ // token but the first, for the positive lines. The app takes the median
++ // per block as the unit of a single-neuron slider (the unit neuron
++ // recipes are shared in). The negative lines are not read.
++ const bool lu_norms = getenv("LU_LAYER_NORMS") != nullptr;
++ std::vector<std::vector<float>> lu_norms_by_layer;
++
+ for(size_t i = 0; i < ctx_train.positive_entries.size(); ++i) {
+ bool success = false;
+ tokenized_prompt t = tokenized_prompts[i];
+@@ -485,6 +496,23 @@ int main(int argc, char ** argv) {
+ success = get_hidden_layers(ctx, t.tokens_pos);
+ if (!success) break;
+
++ if (lu_norms) {
++ lu_norms_by_layer.resize(cb_data.v_pos.size());
++ for (size_t il = 0; il < cb_data.v_pos.size(); il++) {
++ const ggml_tensor * h = cb_data.v_pos[il];
++ for (int64_t r = 1; r < h->ne[1]; r++) {
++ const float * row = (const float *) ((const char *) h->data + r * h->nb[1]);
++ double sum = 0.0;
++ for (int64_t j = 0; j < h->ne[0]; j++) {
++ sum += (double) row[j] * row[j];
++ }
++ lu_norms_by_layer[il].push_back((float) std::sqrt(sum));
++ }
++ }
++ cb_data.reset();
++ continue;
++ }
++
+ cb_data.is_eval_pos = false;
+ success = get_hidden_layers(ctx, t.tokens_neg);
+ if (!success) break;
+@@ -506,6 +534,17 @@ int main(int argc, char ** argv) {
+ cb_data.reset();
+ }
+
++ if (lu_norms) {
++ for (size_t il = 0; il < lu_norms_by_layer.size(); il++) {
++ auto & v = lu_norms_by_layer[il];
++ if (v.empty()) continue;
++ std::nth_element(v.begin(), v.begin() + v.size() / 2, v.end());
++ printf("LU norm %d %.6f\n", (int) il, v[v.size() / 2]);
++ }
++ fflush(stdout);
++ return 0;
++ }
++
+ // done with the model, we can now free it to make gain some memory
+ printf("Done evaluate prompts, unload model...\n");
+
diff --git a/src/api/__tests__/build-llama-script.test.ts b/src/api/__tests__/build-llama-script.test.ts
index 20b5e256..48877a0e 100644
--- a/src/api/__tests__/build-llama-script.test.ts
+++ b/src/api/__tests__/build-llama-script.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect, afterAll } from 'vitest'
import { execFileSync } from 'node:child_process'
import { resolve, join } from 'node:path'
-import { existsSync, statSync, mkdtempSync, rmSync, readFileSync, writeFileSync } from 'node:fs'
+import { existsSync, statSync, mkdtempSync, rmSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { createServer } from 'node:net'
import { asNumber, prop } from '../../types/json-guards'
@@ -579,6 +579,34 @@ cmake() {
expect(r.calls).toContain(`build ${server} llama-cvector-generator`)
expect(existsSync(join(r.repoRoot, 'src-tauri', 'bin', 'lu-llama-cvector-generator-aarch64-apple-darwin'))).toBe(true)
})
+
+ // P11's patches 0003 (progress line) and 0004 (LU_LAYER_NORMS, the unit of
+ // a single-neuron dose) come into every build through the patch directory;
+ // CI runs the built tool on each platform and reads both.
+ it('CI runs the patched tool for real on Mac, Windows and Linux', () => {
+ const patches = readdirSync(join(REPO_ROOT, 'scripts', 'llama-patches'))
+ expect(patches).toContain('0003-cvector-generator-progress-flush.patch')
+ expect(patches).toContain('0004-cvector-generator-layer-norms.patch')
+ const steps = (workflow: string) =>
+ readFileSync(resolve(REPO_ROOT, workflow), 'utf8')
+ .split(/^ {6}- name: /m)
+ .filter((step) => step.startsWith('"Vector tool computes'))
+ const release = steps('.github/workflows/release.yml')
+ const windows = steps('.github/workflows/sidecar-windows.yml')
+ expect(release.map((s) => s.match(/^\s+if: (.*)$/m)?.[1] ?? 'mac')).toEqual([
+ "matrix.sidecar_triple == 'x86_64-unknown-linux-gnu'",
+ "matrix.sidecar_triple == 'x86_64-pc-windows-msvc'",
+ 'mac',
+ ])
+ expect(windows).toHaveLength(1)
+ for (const step of [...release, ...windows]) {
+ expect(step).toContain('stories260K.gguf')
+ expect(step).toContain('--method mean')
+ expect(step).toContain('Evaluating prompt')
+ expect(step).toMatch(/LU_LAYER_NORMS\s*=\s*'?1/)
+ expect(step).toContain('^LU norm [0-9]+ [0-9]+')
+ }
+ })
})
describe('build-llama.sh --check: a failed boot leaves no server behind (E1)', { timeout: 30_000 }, () => {