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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(neuron): say how long a slider takes, show its progress live, fit the tool to the card
purple5b67ef9fe164
diff --git a/scripts/llama-patches/0003-cvector-generator-progress-flush.patch b/scripts/llama-patches/0003-cvector-generator-progress-flush.patchnew file mode 100644index 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/src-tauri/src/commands/neuron/estimate.rs b/src-tauri/src/commands/neuron/estimate.rsnew file mode 100644index 00000000..f98fcacc--- /dev/null+++ b/src-tauri/src/commands/neuron/estimate.rs@@ -0,0 +1,135 @@+//! How long one slider takes, said before it starts.+//!+//! The vector tool reads every example pair through the whole model, so its+//! time grows with the model file and the number of pairs. How fast it is+//! depends on the build that ships: the Mac's runs on Metal, the Windows and+//! Linux release tool is (for now) a static CPU build on the K1 baseline,+//! without AVX, and takes minutes where the Mac takes seconds (I1 on the+//! box, 31.10.2026). After the first run on a PC LU knows that PC's real+//! speed and uses it, keyed to the tool file, so a new tool is measured anew.++use serde::{Deserialize, Serialize};+use std::path::Path;++/// Seconds per GB of model file and example pair for the static CPU+/// baseline tool (Windows, Linux release). I1 on the box, CI artifact+/// 41211851481: LFM3 1.7B Q4_K_M (1.10 GB), 40 pairs, about 25 min in all,+/// of which roughly a minute is the strength check on the engine.+/// E1: change this with the fast build (Vulkan / CPU variants).+pub const SHIPPED_TOOL_CPU_BASELINE: f64 = 33.0;++/// The same for the Mac's Metal tool: Qwen3.5 9B Q4_K_M (6.8 GB), 40 pairs,+/// 30 s in all with the strength check (P11, FEHLER 10).+pub const SHIPPED_TOOL_METAL: f64 = 0.05;++/// The strength check after the tool runs on the chat engine: up to 11 short+/// answers, seconds on a GPU, longer on a processor alone.+const CHECK_SECS: (f64, f64) = (15.0, 120.0);++pub fn shipped_speed() -> f64 {+ if cfg!(target_os = "macos") { SHIPPED_TOOL_METAL } else { SHIPPED_TOOL_CPU_BASELINE }+}++#[derive(Debug, Clone, Copy, PartialEq, Serialize)]+#[serde(rename_all = "camelCase")]+pub struct Estimate {+ pub low_secs: u64,+ pub high_secs: u64,+ /// From a run on this PC with this tool, not from the shipped default.+ pub measured: bool,+}++/// The range for one slider. A measured speed is close; the shipped default+/// is a guess for a PC LU has never seen, so its range is wide.+pub fn estimate(model_bytes: u64, pairs: usize, measured: Option<f64>) -> Estimate {+ let gb = model_bytes as f64 / 1e9;+ let (speed, low, high) = match measured {+ Some(s) => (s, 0.8, 1.5),+ None => (shipped_speed(), 0.5, 2.0),+ };+ let tool = speed * gb * pairs as f64;+ Estimate {+ low_secs: (tool * low + CHECK_SECS.0).round() as u64,+ high_secs: (tool * high + CHECK_SECS.1).round() as u64,+ measured: measured.is_some(),+ }+}++/// What one finished tool run says about this PC.+pub fn speed_of_run(secs: f64, model_bytes: u64, pairs: usize) -> Option<f64> {+ let work = model_bytes as f64 / 1e9 * pairs as f64;+ (work > 0.0 && secs > 0.0).then(|| secs / work)+}++#[derive(Debug, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "camelCase")]+struct Remembered {+ tool: String,+ secs_per_gb_pair: f64,+}++/// The tool file as it is now: size and change time. Another build (an+/// update, E1's fast tool) gives another key, and its speed is not assumed.+pub fn tool_key(tool: &Path) -> Option<String> {+ let m = std::fs::metadata(tool).ok()?;+ let at = m.modified().ok()?.duration_since(std::time::UNIX_EPOCH).ok()?.as_secs();+ Some(format!("{:x}-{at:x}", m.len()))+}++pub fn remembered(file: &Path, tool: &str) -> Option<f64> {+ let r: Remembered = serde_json::from_slice(&std::fs::read(file).ok()?).ok()?;+ (r.tool == tool && r.secs_per_gb_pair.is_finite() && r.secs_per_gb_pair > 0.0).then_some(r.secs_per_gb_pair)+}++pub fn remember(file: &Path, tool: &str, secs_per_gb_pair: f64) {+ let r = Remembered { tool: tool.into(), secs_per_gb_pair };+ if let Ok(bytes) = serde_json::to_vec_pretty(&r) {+ if let Some(dir) = file.parent() {+ let _ = std::fs::create_dir_all(dir);+ }+ let _ = std::fs::write(file, bytes);+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn the_box_case_comes_out_as_the_box_measured_it() {+ // LFM3 1.7B on the CPU baseline tool: I1 measured about 25 min.+ let e = estimate(1_099_627_808, 40, Some(SHIPPED_TOOL_CPU_BASELINE));+ assert!(e.low_secs <= 25 * 60 && e.high_secs >= 25 * 60, "{e:?}");+ let mac = estimate(6_828_993_824, 40, Some(SHIPPED_TOOL_METAL));+ assert!(mac.low_secs <= 30 && mac.high_secs >= 30, "{mac:?}");+ }++ #[test]+ fn a_default_is_wider_than_a_measurement_and_says_which_it_is() {+ let d = estimate(1_100_000_000, 40, None);+ let m = estimate(1_100_000_000, 40, Some(shipped_speed()));+ assert!(!d.measured && m.measured);+ assert!(d.low_secs < m.low_secs && d.high_secs > m.high_secs);+ }++ #[test]+ fn a_run_is_turned_into_a_speed_and_back() {+ let s = speed_of_run(1440.0, 1_100_000_000, 40).unwrap();+ assert!((s - 32.727).abs() < 0.01);+ assert_eq!(speed_of_run(10.0, 0, 40), None);+ assert_eq!(speed_of_run(0.0, 1, 40), None);+ }++ #[test]+ fn a_remembered_speed_counts_only_for_the_same_tool() {+ let dir = std::env::temp_dir().join(format!("lu-neuron-speed-{}", std::process::id()));+ let file = dir.join("tool-speed.json");+ assert_eq!(remembered(&file, "a"), None);+ remember(&file, "a", 12.5);+ assert_eq!(remembered(&file, "a"), Some(12.5));+ assert_eq!(remembered(&file, "b"), None, "a new tool build is measured anew");+ std::fs::write(&file, b"{\"tool\":\"a\",\"secsPerGbPair\":-1}").unwrap();+ assert_eq!(remembered(&file, "a"), None);+ let _ = std::fs::remove_dir_all(&dir);+ }+}diff --git a/src-tauri/src/commands/neuron/mod.rs b/src-tauri/src/commands/neuron/mod.rsindex 51c7dcc0..c1f11f6c 100644--- a/src-tauri/src/commands/neuron/mod.rs+++ b/src-tauri/src/commands/neuron/mod.rs@@ -36,6 +36,7 @@pub mod calib;pub mod cvec;+pub mod estimate;pub mod model;pub mod presets;pub mod sae;@@ -54,6 +55,15 @@ use tauri::Manager;const GENERATOR: &str = "lu-llama-cvector-generator";const PROBE_QUESTION: &str = "Write one sentence about rain.";const LOG_LINES: usize = 40;+/// How the vector tool runs. `-ngl auto`: with a GPU backend (E1, 3.0.9:+/// the tool comes out of the server build with BACKEND_DL) llama.cpp puts+/// as many layers on the card as fit, as the engine does when the card was+/// not measured (GH #156); a fixed 99 would fail on a model the card cannot+/// hold. The chat engine is stopped first, so the tool has the card alone.+/// LU only uses `mean`; PCA never runs. 1024 tokens hold the longest pair.+const TOOL_ARGS: [&str; 6] = ["--method", "mean", "-ngl", "auto", "-c", "1024"];+/// The speed the vector tool showed on this PC (`estimate`).+const SPEED_FILE: &str = "tool-speed.json";// ── paths ─────────────────────────────────────────────────────────────────@@ -431,12 +441,13 @@ fn generate(app: &tauri::AppHandle, model_path: &str, plus: &[String], minus: &[.arg("--positive-file").arg(&pos).arg("--negative-file").arg(&neg).arg("-o").arg(&out)- .args(["--method", "mean", "-ngl", "99", "-c", "1024"])+ .args(TOOL_ARGS).stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped());crate::commands::engine::prepare_tool_command(app, &mut cmd);log(format!("$ {} …", binary.file_name().map(|s| s.to_string_lossy().into_owned()).unwrap_or_default()));+ let ran = Instant::now();let mut child = cmd.spawn().map_err(|e| format!("The vector tool did not start: {}", crate::os_error::english(&e)))?;let stderr = child.stderr.take().map(crate::commands::shell::drain);let stdout = child.stdout.take().ok_or("no output")?;@@ -472,6 +483,10 @@ fn generate(app: &tauri::AppHandle, model_path: &str, plus: &[String], minus: &[return Err(tool_failure(&why));}with_job(|j| j.step = j.total);+ let bytes = std::fs::metadata(model_path).map(|m| m.len()).unwrap_or(0);+ if let (Some(key), Some(speed)) = (estimate::tool_key(&binary), estimate::speed_of_run(ran.elapsed().as_secs_f64(), bytes, plus.len())) {+ estimate::remember(&root().join(SPEED_FILE), &key, speed);+ }let cv = cvec::read(&out)?;let _ = std::fs::remove_file(&pos);let _ = std::fs::remove_file(&neg);@@ -613,6 +628,14 @@ fn own_id(name: &str) -> String {if base.is_empty() { format!("own-{tag}") } else { format!("own-{base}-{tag}") }}+/// The time range for a ready-made slider (the largest set of pairs) and for+/// an own one, said before either starts.+pub fn build_estimates(model_bytes: u64, template: model::Template, measured: Option<f64>) -> (estimate::Estimate, estimate::Estimate) {+ let preset_pairs = presets::PRESETS.iter().map(|p| presets::pairs(p, template).0.len()).max().unwrap_or(0);+ let own_pairs = presets::custom_pairs(&["a".into()], &["b".into()], template).map(|(p, _)| p.len()).unwrap_or(0);+ (estimate::estimate(model_bytes, preset_pairs, measured), estimate::estimate(model_bytes, own_pairs, measured))+}+#[tauri::command]pub fn neuron_presets() -> Value {json!(presets::PRESETS.iter().map(|p| json!({ "id": p.id, "left": p.left, "right": p.right })).collect::<Vec<_>>())@@ -635,6 +658,9 @@ pub async fn neuron_info(app: tauri::AppHandle, model_path: String) -> Result<Va})});let active = control_vector_for(&model_path);+ let measured = generator_binary(&app).and_then(|b| estimate::tool_key(&b)).and_then(|k| estimate::remembered(&root.join(SPEED_FILE), &k));+ let bytes = std::fs::metadata(&model_path).map(|m| m.len()).unwrap_or(0);+ let (build_estimate, own_estimate) = build_estimates(bytes, facts.template, measured);Ok(json!({"facts": facts,"modelKey": model_key(&model_path),@@ -643,6 +669,8 @@ pub async fn neuron_info(app: tauri::AppHandle, model_path: String) -> Result<Va"vectors": list_vectors(&root, &model_path),"sae": sae,"activeMix": active,+ "buildEstimate": build_estimate,+ "ownEstimate": own_estimate,}))}).await@@ -1023,6 +1051,23 @@ mod tests {use super::*;+ #[test]+ fn the_time_before_computing_covers_a_ready_made_and_an_own_slider() {+ // I1 on the box: LFM3 1.7B, a ready-made slider, ~25 min with the+ // CPU baseline tool. An own slider has half the pairs.+ let (preset, own) = build_estimates(1_099_627_808, super::model::Template::ChatMl, Some(estimate::SHIPPED_TOOL_CPU_BASELINE));+ assert!(preset.low_secs <= 25 * 60 && preset.high_secs >= 25 * 60, "{preset:?}");+ assert!(own.high_secs < preset.high_secs && own.low_secs < preset.low_secs, "{own:?}");+ assert!(preset.measured);+ }++ #[test]+ fn the_tool_lets_llama_cpp_fit_the_layers_to_the_card() {+ let ngl = TOOL_ARGS.windows(2).find(|w| w[0] == "-ngl").map(|w| w[1]);+ assert_eq!(ngl, Some("auto"));+ assert!(TOOL_ARGS.windows(2).any(|w| w == ["--method", "mean"]));+ }+#[test]fn progress_lines_of_the_generator_parse() {assert_eq!(parse_progress("Evaluating prompt[12/40]: \"a\" - \"b\" (31 tokens)"), Some((12, 40)));diff --git a/src/api/__tests__/build-llama-script.test.ts b/src/api/__tests__/build-llama-script.test.tsindex 0c64ee1a..2ad634f2 100644--- a/src/api/__tests__/build-llama-script.test.ts+++ b/src/api/__tests__/build-llama-script.test.ts@@ -467,6 +467,17 @@ describe('build-llama.sh — the llama.cpp revision is pinned to a commit', { tiexpect(runScript('printf "%s" "$LU_PATCH_DIR"', { LLAMA_LU_PATCH_DIR: '' }).out).toBe(`${REPO_ROOT}/scripts/llama-patches`.replace(/\\/g, '/'))})+ // I1 on the box (31.10.2026): the Windows tool took ~25 min and the app+ // showed no progress. Over a pipe the generator's printf is fully+ // buffered, so its "Evaluating prompt[i/n]" lines, which the app reads for+ // progress and time left, came in batches or only at the end.+ it('the repo\'s generator patches hand every progress line to the app at once', () => {+ const dir = join(REPO_ROOT, 'scripts', 'llama-patches')+ const patch = readFileSync(join(dir, '0003-cvector-generator-progress-flush.patch'), 'utf8')+ expect([...patch.matchAll(/^\+\+\+ b\/(.+)$/gm)].map((m) => m[1])).toEqual(['tools/cvector-generator/cvector-generator.cpp'])+ expect(patch).toMatch(/^ {13}\(int\) t\.max_seq_len\);\n(\+ {8}\/\/.*\n)*\+ {8}fflush\(stdout\);$/m)+ })+it('hashes a digest of the binary it installed', () => {const probe = join(tmp('llama-digest-'), 'artifact')writeFileSync(probe, 'llama-server')diff --git a/src/api/neuron.ts b/src/api/neuron.tsindex 24921dbc..78717e0f 100644--- a/src/api/neuron.ts+++ b/src/api/neuron.ts@@ -46,6 +46,16 @@ export interface NeuronInfo {vectors: NeuronVector[]sae: NeuronSae | nullactiveMix: string | null+ /** How long one slider takes on this PC, said before it starts. */+ buildEstimate: NeuronEstimate+ ownEstimate: NeuronEstimate+}++export interface NeuronEstimate {+ lowSecs: number+ highSecs: number+ /** From a run on this PC with this vector tool, not the shipped default. */+ measured: boolean}export interface NeuronJob {diff --git a/src/lib/__tests__/neuron.test.ts b/src/lib/__tests__/neuron.test.tsindex 9f119dec..f4f1367f 100644--- a/src/lib/__tests__/neuron.test.ts+++ b/src/lib/__tests__/neuron.test.ts@@ -13,6 +13,7 @@ import {shortDuration,strengthWarning,tweakedModelNote,+ buildTimeNote,} from '../neuron'import type { NeuronJob } from '../../api/neuron'import type { Profiles } from '../neuron'@@ -121,3 +122,27 @@ describe('the note for a tweaked model', () => {expect(tweakedModelNote({ tweaked: [], original: 'Qwen2.5 0.5B' })).toBeNull()})})++// I1 on the box (31.10.2026): one slider took ~25 min on Windows with the+// CPU-only vector tool, and nothing said so before. The page now says how+// long it will take, before the start, whenever it is more than a moment.+describe('the time a slider takes, said before computing', () => {+ it('says nothing when it is quick', () => {+ expect(buildTimeNote({ lowSecs: 20, highSecs: 110, measured: false })).toBeNull()+ })+ it('gives the range, why, and that it can be stopped', () => {+ const note = buildTimeNote({ lowSecs: 741, highSecs: 3023, measured: false })!+ expect(note.title).toBe('This takes a while on this PC')+ expect(note.text).toContain('about 12–50 min for one slider')+ expect(note.text).toMatch(/slow on this PC/)+ expect(note.text).toMatch(/stop it any time/)+ })+ it('says when the range comes from a run on this PC', () => {+ const note = buildTimeNote({ lowSecs: 1176, highSecs: 2297, measured: true })!+ expect(note.text).toContain('about 20–38 min for one slider')+ expect(note.text).toMatch(/last run on this PC/)+ })+ it('reads across units', () => {+ expect(buildTimeNote({ lowSecs: 1800, highSecs: 7300, measured: false })!.text).toContain('about 30 min to 2 h 2 min')+ })+})diff --git a/src/lib/neuron.ts b/src/lib/neuron.tsindex 050fdbf9..cf0fa519 100644--- a/src/lib/neuron.ts+++ b/src/lib/neuron.ts@@ -1,7 +1,7 @@// The Neuron tweaker's rules that need no backend: which slider values apply// to which chat, how a job's progress reads, when to warn.-import type { NeuronEntry, NeuronJob } from '../api/neuron'+import type { NeuronEntry, NeuronEstimate, NeuronJob } from '../api/neuron'import type { Persona } from '../types/settings'import { plainChatSpeaker } from './chat-persona'import { isGroupChat } from './group-chat'@@ -169,3 +169,24 @@ export function tweakedModelNote(facts: TweakFacts): { title: string; text: strioriginal: facts.original ?? null,}}++/**+ * How long one slider will take, said before it starts (I1 on the box,+ * 31.10.2026: ~25 min on Windows with the CPU-only vector tool, and nothing+ * said so). Null when it is a moment, as on the Mac.+ */+export function buildTimeNote(est: NeuronEstimate): { title: string; text: string } | null {+ if (est.highSecs < 120) return null+ const lowMin = Math.round(est.lowSecs / 60)+ const highMin = Math.round(est.highSecs / 60)+ const range = est.lowSecs >= 60 && highMin < 60+ ? `${lowMin}–${highMin} min`+ : `${shortDuration(est.lowSecs)} to ${shortDuration(est.highSecs)}`+ const basis = est.measured+ ? 'That is what the last run on this PC took.'+ : 'LU reads every example pair through the whole model, and its vector tool is slow on this PC.'+ return {+ title: 'This takes a while on this PC',+ text: `Expect about ${range} for one slider. ${basis} The chat pauses while LU computes; you can stop it any time.`,+ }+}