Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
tuner measures the engine a load starts: the app's request-slot choice (and fit_max_tokens) moves into buildConfig, which both the load and the tune use; test that a tune's saved config equals a load's for the same model and profile, on a 12 GB and a 48 GB card
Niko122115937b7e8075
diff --git a/apps/host/server/native-control.mjs b/apps/host/server/native-control.mjsindex cfec2dadf..fee0da997 100644--- a/apps/host/server/native-control.mjs+++ b/apps/host/server/native-control.mjs@@ -178,19 +178,20 @@ export function createNativeControl({directory,requests=()=>[],changed=()=>{},spif(args.gpus!==undefined){const detected=new Set((snapshot.hardware?.gpus??[]).map(g=>g.index));if(!Array.isArray(args.gpus)||!args.gpus.length||new Set(args.gpus).size!==args.gpus.length||args.gpus.some(g=>!Number.isInteger(g)||!detected.has(g)))throw new Error('Choose distinct detected GPUs. CPU-only text inference is not supported by this native adapter.');cfg.gpu=args.gpus.length===1?args.gpus[0]:args.gpus;cfg.layer_split=args.gpus.length>1?validateNativeSettings({layer_split:args.layerSplit??'auto'}).layer_split:'auto';if(cfg.layer_split!=='auto'&&cfg.layer_split.split(',').length!==args.gpus.length-1)throw new Error('Choose one layer split point between each pair of GPUs.');}if(cfg.vram_reserve_mib!==undefined&&cfg.vram_reserve_mib!==null){cfg.args=[...(cfg.args??[])];const at=cfg.args.indexOf('--vram-reserve-mib');if(at>=0)cfg.args.splice(at,2);cfg.args.push('--vram-reserve-mib',String(cfg.vram_reserve_mib));}if(cfg.vision){if(cfg.vision_tokens!=null)cfg.vision={...cfg.vision,max_tokens:cfg.vision_tokens};if(cfg.vision_min_tokens!=null)cfg.vision={...cfg.vision,min_tokens:cfg.vision_min_tokens};}cfg.mcp={...(cfg.mcp??{}),...(cfg.mcp_timeout_s!=null?{timeout_s:cfg.mcp_timeout_s}:{}),...(cfg.mcp_max_rounds!=null?{max_rounds:cfg.mcp_max_rounds}:{}),...(cfg.mcp_max_result_chars!=null?{max_result_chars:cfg.mcp_max_result_chars}:{})};for(const arg of cfg.args??[])if(arg.endsWith('.gguf')&&!existsSync(resolve(repo(),arg)))throw new Error('An engine argument names a missing GGUF. Restore the saved arguments or repair the files.');- return {cfg,resources,visionPreferences};- }- async function loadEngine(job,args){- await refresh(true);if(job.state!=='running')return;const {config,entry}=record(args.model);if(packaged){const engine=await control.engine();if(!engine.usable)throw new Error(engine.notice??'No engine for this PC was found.');}if(!entry.ready)throw new Error('Some model files are missing. Use Download / repair to restore them.');- if(externalRunning().length)throw new Error('A Strata server is already running outside this UI. Stop it before loading here, or connect its API in Settings → Models.');- if(args.multiple&&instances.size>=8)throw new Error('Unload an instance before adding another. Up to eight native instances can run here.');- const {cfg,resources,visionPreferences}=buildConfig(args,config);- /* Installed app: several requests at once by default (4, fewer where the card has no room), unless a number was chosen. */+ /* The app's own choice of request slots (4, fewer where the card has no room) is part of the configuration, so a tune measures the engine a load will start: slots take VRAM from the expert cache. */const parallelChoice=packaged?chooseParallel({config:cfg,values:args.values??{},hardware:snapshot.hardware?.gpus?.length?snapshot.hardware:{gpus:hardwareProbe()??[]}}):null;let parallelNote=null;/* The agent asks for long answers (a thinking model can use most of the window): let the engine clamp the output to what is left of the context instead of refusing the request. */if(packaged&&cfg.fit_max_tokens===undefined)cfg.fit_max_tokens=true;if(parallelChoice){const applied=applyParallel(cfg,parallelChoice);for(const k of Object.keys(cfg))if(!(k in applied.cfg))delete cfg[k];Object.assign(cfg,applied.cfg);parallelNote=applied.note;}+ return {cfg,resources,visionPreferences,parallelChoice,parallelNote};+ }+ async function loadEngine(job,args){+ await refresh(true);if(job.state!=='running')return;const {config,entry}=record(args.model);if(packaged){const engine=await control.engine();if(!engine.usable)throw new Error(engine.notice??'No engine for this PC was found.');}if(!entry.ready)throw new Error('Some model files are missing. Use Download / repair to restore them.');+ if(externalRunning().length)throw new Error('A Strata server is already running outside this UI. Stop it before loading here, or connect its API in Settings → Models.');+ if(args.multiple&&instances.size>=8)throw new Error('Unload an instance before adding another. Up to eight native instances can run here.');+ const {cfg,resources,visionPreferences,parallelChoice,parallelNote:chosenNote}=buildConfig(args,config);+ let parallelNote=chosenNote;const fingerprint=createHash('sha256').update(JSON.stringify({...cfg,api_key:undefined,port:undefined})).digest('hex');const placement=Array.isArray(cfg.gpu)?cfg.gpu:cfg.gpu===undefined?[]:[cfg.gpu];const matching=[...instances.values()].find(i=>i.model===args.model&&JSON.stringify(i.gpus)===JSON.stringify(placement));if(matching?.status==='ready'&&matching.fingerprint===fingerprint&&(args.multiple||instances.size===1))return {summary:`${matching.label} is already ready.`,instanceId:matching.id};@@ -311,7 +312,7 @@ export function createNativeControl({directory,requests=()=>[],changed=()=>{},spreturn {...loaded,...measured,summary:'Your model is tuned and ready.',profile:args.profile};}/* What the tuner measures is what a load would start: the saved model config with the user's choices and the resource profile. */- function tuneConfig(args){const {config,entry}=record(args.model);if(!entry.ready)throw new Error('Prepare the model before tuning it.');const {cfg}=buildConfig({model:args.model,vision:args.vision,resourceProfile:args.resourceProfile,gpus:args.gpus},config);return {path:writeTuneConfig(directory,args.model,cfg),entry};}+ function tuneConfig(args){const {config,entry}=record(args.model);if(!entry.ready)throw new Error('Prepare the model before tuning it.');const {cfg}=buildConfig({model:args.model,vision:args.vision,resourceProfile:args.resourceProfile,gpus:args.gpus,values:args.values},config);return {path:writeTuneConfig(directory,args.model,cfg),entry};}async function tuneStatus(args){await refresh();const {path}=tuneConfig(args);return autotuner.status(path);}async function autotune(job,args){await refresh(true);if(job.state!=='running')return;diff --git a/apps/host/tests/packaged-control.test.mjs b/apps/host/tests/packaged-control.test.mjsindex 0b7827ea6..fdcc800a8 100644--- a/apps/host/tests/packaged-control.test.mjs+++ b/apps/host/tests/packaged-control.test.mjs@@ -95,6 +95,7 @@ function packagedFixture({ engineUsable = true, updater = null } = {}) {return { id, path };});const calls = [];+ const saved = [];const spawned = [];const rpc = [];let startFailure = null, startFailureLeft = Infinity;@@ -108,7 +109,7 @@ function packagedFixture({ engineUsable = true, updater = null } = {}) {: { usable: false, notice: 'No engine for this PC was found in E:\\c: the component folder holds no engine package. The app never downloads an engine while it starts or serves.', backend: 'cuda', engine: null, components_dir: 'E:\\c' };},async importPlan(path) { calls.push(['importPlan', path]); return { file_set_status: 'plausible', candidate_selection: { family: 'qwen', model: 'IQ3_S' }, file_count: 2, total_bytes: 1e9, issues: [] }; },- async saveProfile(name, path) { calls.push(['saveProfile', name, basename(path)]); return {}; },+ async saveProfile(name, path) { calls.push(['saveProfile', name, basename(path)]); saved.push(JSON.parse(readFileSync(path, 'utf8'))); return {}; },async start(name, options) { calls.push(['start', name, options?.waitSeconds]); if (startFailure && startFailureLeft-- > 0) { const e = new Error(startFailure.message); e.output = startFailure.output; throw e; } return { ok: true, state: 'ready' }; },async stop(name) { calls.push(['stop', name]); return { ok: true, state: 'stopped' }; },...(updater ? { async updateCheck() { calls.push(['updateCheck']); return updater.report; }, async update(options) { calls.push(['update', options.engine, options.control]); return updater.update(options); } } : {}),@@ -146,7 +147,7 @@ function packagedFixture({ engineUsable = true, updater = null } = {}) {};const native = createNativeControl({ control, directory: data, spawnProcess, fetcher, requests: () => requests });const others = () => spawned.filter(s => !String(s.args[0]).endsWith('strata_mcp.py'));- return { native, calls, spawned, others, rpc, failStart: (v, times = Infinity) => { startFailure = v; startFailureLeft = times; }, catalog, hardware, install, root, cleanup: () => { rmSync(root, { recursive: true, force: true }); } };+ return { native, calls, saved, spawned, others, rpc, failStart: (v, times = Infinity) => { startFailure = v; startFailureLeft = times; }, catalog, hardware, install, root, cleanup: () => { rmSync(root, { recursive: true, force: true }); } };}const finish = async (native, id) => { for (let i = 0; i < 400; i++) { const job = native.state().jobs.find(j => j.id === id); if (job.state !== 'running') return job; await new Promise(r => setTimeout(r, 10)); } throw new Error('job did not finish'); };@@ -453,3 +454,21 @@ test('packaged: the app default of several requests at once and the memory retryassert.equal(g.calls.filter(c => c[0] === 'start').length, 2, 'memory change and parallel drop ride on the same single try');} finally { await g.native.close(); g.cleanup(); }});++test('packaged: a tune measures the engine a load starts: same start args, slots included, for the same model and profile', async () => {+ for (const vram of [11.9, 48]) {+ const f = packagedFixture(); f.hardware.gpus[0].vram_gb = vram;+ try {+ await f.native.refresh(true);+ const args = { model: 'iq2_xs', resourceProfile: 'work', vision: 'no' };+ await f.native.tuneStatus(args).catch(() => {}); // the fake host cannot run Control's tuner; the config it would measure is written first+ const tuned = JSON.parse(readFileSync(join(f.root, 'data', 'native-tune', 'iq2_xs.json'), 'utf8'));+ const job = await finish(f.native, f.native.operation('load', args).id);+ assert.equal(job.state, 'done', job.error);+ const loaded = { ...f.saved.at(-1) }; delete loaded.port; delete loaded.api_key;+ assert.deepEqual(tuned.args, loaded.args, 'the engine arguments are identical');+ for (const [key, value] of Object.entries(tuned)) assert.deepEqual(loaded[key], value, `${key} is the same in the tune and the load`); // a load adds only its own identity (aliases, model name, key, port)+ if (vram > 40) assert.ok(tuned.parallel > 1, 'a big card gets the app default of several slots in the tune too');+ } finally { await f.native.close(); f.cleanup(); }+ }+});