diff --git a/apps/host/server/native-control.mjs b/apps/host/server/native-control.mjs index 0b9ce901..50dcac5d 100644 --- a/apps/host/server/native-control.mjs +++ b/apps/host/server/native-control.mjs @@ -151,7 +151,7 @@ export function createNativeControl({directory,requests=()=>[],changed=()=>{},sp async function openSettingsFile(model,options={}){const info=settingsFile(model);await openTextFile(info.path,options);return info;} /* A mistake in the file holds the start back with the line, instead of an engine that dies on it. Warnings (an unknown key) never do. */ function assertSettingsFile(path){const check=checkRunConfig(readFileSync(path,'utf8'));if(!check.ok)throw new Error(`The settings file for this model has a mistake, so the model was not started. ${describeIssues(check.issues,'error').join(' ')}`);} - function settings(model){const {entry,config}=record(model);const values=Object.fromEntries(NATIVE_FIELDS.map(f=>[f.id,config[f.id]??null]));if(typeof values.aliases==='string')values.aliases=values.aliases.split(',').map(v=>v.trim()).filter(Boolean);values.sampling=config.sampling??{};values.args=config.args??[];values.env=publicNativeEnv(config.env??{});return {model,values,mcp:publicMcpServers(config.mcp_servers??config.mcpServers??{}),restartNeeded:true,capabilities:{dsExperts:ownEngine(config)&&dsExpertsSupported(config)},speedSwitches:speedSwitchRows(config.env??{},{deepseek:ownEngine(config),backend:config.backend??entry?.backend??snapshot.installed?.engine?.backend??null,gpus:snapshot.hardware?.gpus??[]})};} + function settings(model){const {entry,config}=record(model);const values=Object.fromEntries(NATIVE_FIELDS.map(f=>[f.id,config[f.id]??null]));if(typeof values.aliases==='string')values.aliases=values.aliases.split(',').map(v=>v.trim()).filter(Boolean);values.sampling=config.sampling??{};values.args=config.args??[];values.env=publicNativeEnv(config.env??{});return {model,values,mcp:publicMcpServers(config.mcp_servers??config.mcpServers??{}),restartNeeded:true,capabilities:{dsExperts:ownEngine(config)&&dsExpertsSupported(config)},speedSwitches:speedSwitchRows(config.env??{},{deepseek:ownEngine(config),arch:config.arch??null,backend:config.backend??entry?.backend??snapshot.installed?.engine?.backend??null,gpus:snapshot.hardware?.gpus??[]})};} function save(model,{values,mcp}){if([...jobs.values()].some(j=>j.state==='running'))throw new Error('Finish the current operation before saving native settings.');const {path,config}=record(model);if(busy(requests().filter(r=>instances.get(r.instanceId)?.model===model)))throw new Error('Finish this model’s requests before saving its settings.');const patch=validateNativeSettings(values??{}),next={...config};if(patch.ds_experts!=null&&!dsExpertsSupported(config))throw new Error('The Speed choice needs the newer DeepSeek engine. Update the engine in Settings, then choose it.');for(const field of nativeFields())if(field.supported===false&&patch[field.id]!=null&&JSON.stringify(patch[field.id])!==JSON.stringify(config[field.id]))throw new Error(`${field.label} needs a newer native Strata installation. Update it in Settings → About.`);for(const [key,value] of Object.entries(patch)){if(key==='env')next.env=restoreNativeEnv(value,config.env??{});else if(value===null)delete next[key];else next[key]=value;}if('vram_reserve_mib' in patch){const base=captureUserArgs(next);const mine=setUserFlag(base,'--vram-reserve-mib',patch.vram_reserve_mib);if(mine.length)next[USER_KEY]=mine;else delete next[USER_KEY];next.args=mine.length&&patch.vram_reserve_mib!==null?mergeUserArgs(next.args??[],mine):setUserFlag(next.args??[],'--vram-reserve-mib',null);delete next.ui_reserve_applied;if(Array.isArray(next.args_written))next.args_written=[...next.args];}if(mcp!==undefined){next.mcp_servers=validateMcpServers(mcp,config.mcp_servers??config.mcpServers??{});delete next.mcpServers;}copyFileSync(path,path+'.bak');chmodSync(path+'.bak',0o600);const temp=path+'.ui-tmp';writeFileSync(temp,JSON.stringify(next,null,2)+'\n',{mode:0o600});renameSync(temp,path);return settings(model);} function previousEngine(){if(packaged)return !!snapshot.engine?.previous;try{const data=snapshot.installed?.data_dir??snapshot.installed?.data_folder;return [join(preferences.repo,'engine/.previous'),data&&join(data,'engine/.previous')].filter(Boolean).some(existsSync)&&readFileSync(join(preferences.repo,'setup.py'),'utf8').includes('--rollback-engine');}catch{return false;}} async function plan(args){await refresh();if(!snapshot.available)throw new Error(snapshot.error);const result=await tool('strata_install',installArgs(args,false)); diff --git a/apps/host/server/native-settings.mjs b/apps/host/server/native-settings.mjs index 37730c78..82f93ed8 100644 --- a/apps/host/server/native-settings.mjs +++ b/apps/host/server/native-settings.mjs @@ -29,40 +29,48 @@ export const NATIVE_FIELDS=[ /** Engine environment names the app shows and edits: STRATA_* and the DeepSeek engine's DS4_*. Any other name in a model's file is kept untouched and not shown. */ export const ENV_FLAG=/^(?:STRATA|DS4)_[A-Z0-9_]+$/; /** - * The three speed features that are on by default in 0.2.7 and have an off switch in Expert settings. Each switch, when off, writes exactly the - * environment entries below into the model's settings file ("env"); turning it on again removes them, so a default launch carries none of them. - * The names are the engine switch contract (phaseA-tests/notes-027-plan.md); strata_control/speed_switches.py says the same for the Terminal - * (tests/terminal/test_speed_switches.py compares the two). + * The speed features of 0.2.7 that have a switch in Expert settings. A switch has a default ('on' or 'off'); outside it, it writes exactly the + * environment entries `env` into the model's settings file ("env"); back in its default it removes them, so a default launch carries none of them. + * "Faster long prompts" (Qwen KVA) is OFF by default (owner decision, 26 October): STRATA_KVA=1 turns it on, and an earlier test build's STRATA_KVA=0 reads as off. + * The other two are on by default. The names are the engine switch contract (phaseA-tests/notes-027-plan.md); strata_control/speed_switches.py says the + * same for the Terminal (tests/terminal/test_speed_switches.py compares the two). */ export const SPEED_SWITCHES=[ {id:'faster_long_prompts',label:'Faster long prompts',group:'Speed', - hint:'Reads long prompts faster by approximating part of the work. Turn off if answers about long documents look wrong.', - off:{STRATA_KVA:'0'}}, + hint:'Reads very long prompts faster by approximating part of the work. Off by default: answers about long documents can miss or mix up details.', + default:'off',env:{STRATA_KVA:'1'}}, {id:'faster_radeon_9000',label:'Faster answers on Radeon RX 9000 / AI PRO R9700',group:'Speed', hint:'Shares the work between the graphics card and the processor in a way that makes answers faster on these cards. Turn off to go back to the previous setting, which is slower.', - off:{STRATA_PCIE_FRAC_DEFAULT:'old'}}, + default:'on',env:{STRATA_PCIE_FRAC_DEFAULT:'old'}}, {id:'deepseek_speedups',label:'DeepSeek speed-ups',group:'Speed', hint:'Reads long prompts faster and loads the parts of the model it needs faster. Turn off if DeepSeek stops working or its answers look wrong; it then runs as in version 0.2.6.', - off:{DS4_FAST_ATTN:'0',DS4_ATTN_SLAB:'0',DS4_COPY_PIN:'0',DS4_COPY_HUGETLB:'0',DS4_STORE_SPARE:'0',DS4_STORE_PUT:'0'}}, + default:'on',env:{DS4_FAST_ATTN:'0',DS4_ATTN_SLAB:'0',DS4_COPY_PIN:'0',DS4_COPY_HUGETLB:'0',DS4_STORE_SPARE:'0',DS4_STORE_PUT:'0'}}, ]; const GFX12=/^gfx120[01]$/i, RADEON_9000=/\b(?:RX\s*9\d{3}|AI\s*PRO\s*R97\d{2}|R97\d{2})\b/i; -/** Which switches make sense for this model on this PC: only those are shown. `backend` is the engine's (cuda, hip, sycl, metal, cpu). */ -export function speedSwitchApplies(id,{deepseek=false,backend=null,gpus=[]}={}){ +/** + * Which switches make sense for this model on this PC: only those are shown. `backend` is the engine's (cuda, hip, sycl, metal, cpu). `arch` is the "arch" + * of the model's run config: setup writes it only for the families with an engine path of their own (Qwen3.6-35B-A3B "qwen35moe", DeepSeek "deepseek41"); + * the Qwen3.8-Flash-Next files (the original, Swift, Coder, Unsloth, Gyro, NVFP4) have none. KVA was measured on the Flash-Next shape (48 layers, 512 + * experts) and the engine declines it on any other, so "Faster long prompts" is shown for a model without an "arch" only. + */ +export function speedSwitchApplies(id,{deepseek=false,backend=null,gpus=[],arch=null}={}){ if(id==='deepseek_speedups')return !!deepseek; if(deepseek)return false; // the Qwen engine's switches - if(id==='faster_long_prompts')return backend==='cuda'||backend==='hip'; + if(id==='faster_long_prompts')return !arch&&(backend==='cuda'||backend==='hip'); if(id==='faster_radeon_9000')return backend==='hip'&&(gpus??[]).some(g=>(!g.vendor||g.vendor==='amd')&&(GFX12.test(String(g.arch??''))||(!g.arch&&RADEON_9000.test(String(g.name??''))))); return false; } -/** A switch is off when every entry it writes is in the environment with its value; anything less (a hand-edited file) reads as on and is left alone. */ -export function speedSwitchIsOff(env,id){const sw=SPEED_SWITCHES.find(s=>s.id===id);return !!sw&&Object.entries(sw.off).every(([name,value])=>env?.[name]===value);} -/** The environment with the switch turned off (its entries written) or on (its entries removed). Nothing else in it changes. */ +/** The switch is outside its default when every entry it writes is in the environment with its value; anything less or other (a hand-edited file, STRATA_KVA=0) is the default state and is left alone. */ +export function speedSwitchIsSet(env,id){const sw=SPEED_SWITCHES.find(s=>s.id===id);return !!sw&&Object.entries(sw.env).every(([name,value])=>env?.[name]===value);} +/** Is the feature on for a launch with this environment? */ +export function speedSwitchIsOn(env,id){const sw=SPEED_SWITCHES.find(s=>s.id===id);return !!sw&&speedSwitchIsSet(env,id)!==(sw.default==='on');} +/** The environment with the feature on or off: its default removes the switch's entries, the other state writes them. Nothing else in it changes. */ export function setSpeedSwitch(env,id,on){ const sw=SPEED_SWITCHES.find(s=>s.id===id);if(!sw)throw new Error(`Unknown speed switch: ${id}`); - const next={...(env??{})};for(const [name,value] of Object.entries(sw.off)){if(on)delete next[name];else next[name]=value;}return next; + const write=on!==(sw.default==='on'),next={...(env??{})};for(const [name,value] of Object.entries(sw.env)){if(write)next[name]=value;else delete next[name];}return next; } -/** What the settings answer carries: each switch that applies, with its words, the entries it writes when off, and whether it is on. */ -export function speedSwitchRows(env,context){return SPEED_SWITCHES.filter(s=>speedSwitchApplies(s.id,context)).map(s=>({...s,on:!speedSwitchIsOff(env,s.id)}));} +/** What the settings answer carries: each switch that applies, with its words, its default, the entries it writes outside the default, and whether the feature is on. */ +export function speedSwitchRows(env,context){return SPEED_SWITCHES.filter(s=>speedSwitchApplies(s.id,context)).map(s=>({...s,on:speedSwitchIsOn(env,s.id)}));} /** Settings the app itself applies when it starts a model (they are not read from the engine's source, so the engine's text never says it supports them). */ export const APP_OWNED_FIELDS=['mtp','batchMtp','drafting','ds_experts']; /** The engine arguments without the draft layer: --mtp , --spec-min-p

(its confidence threshold) and --batch-mtp. --spec stays: prompt lookup still uses its windows. Same rule as strata_control/draft_layer.py. */ diff --git a/apps/host/src/components/NativeSettings.tsx b/apps/host/src/components/NativeSettings.tsx index 561c8f66..062874f1 100644 --- a/apps/host/src/components/NativeSettings.tsx +++ b/apps/host/src/components/NativeSettings.tsx @@ -9,14 +9,16 @@ import { Btn, ErrorNotice, Select } from './ui'; import { speedOptions } from '../lib/deepseek-speed'; import type { RunCard } from '../lib/native-fit'; import { NativeMcpEditor } from './NativeMcpEditor'; -/** One of the three speed features that are on by default: what it is called, what turning it off does, and the engine environment it writes when off (server/native-settings.mjs). */ +/** One of the speed features: what it is called, what it does, whether it is on by default, and the engine environment it writes outside its default (server/native-settings.mjs). */ interface SpeedSwitch { id: string; label: string; hint: string; - off: Record; + default: 'on' | 'off'; + env: Record; } -const switchIsOff = (sw: SpeedSwitch, env: Record | undefined) => Object.entries(sw.off).every(([name, value]) => env?.[name] === value); +const switchIsSet = (sw: SpeedSwitch, env: Record | undefined) => Object.entries(sw.env).every(([name, value]) => env?.[name] === value); +const switchIsOn = (sw: SpeedSwitch, env: Record | undefined) => switchIsSet(sw, env) !== (sw.default === 'on'); export function NativeSettings({ model }: { model: string; }) { @@ -58,8 +60,8 @@ export function NativeSettings({ model }: { return () => { active = false; }; }, [model,revision]); const change = (id: string, value: any) => { const next = { ...values, [id]: value }; setValues(next); setText(JSON.stringify(next, null, 2)); setNotice(''); }; - /** On removes the switch's environment entries, off writes them: the model's file then carries nothing for a default launch. */ - const changeSwitch = (sw: SpeedSwitch, on: boolean) => { const env = { ...(values.env ?? {}) }; for (const [name, value] of Object.entries(sw.off)) { if (on) delete env[name]; else env[name] = value; } change('env', env); }; + /** The default removes the switch's environment entries, the other state writes them: the model's file then carries nothing for a default launch. */ + const changeSwitch = (sw: SpeedSwitch, on: boolean) => { const env = { ...(values.env ?? {}) }; const write = on !== (sw.default === 'on'); for (const [name, value] of Object.entries(sw.env)) { if (write) env[name] = value; else delete env[name]; } change('env', env); }; async function save() { setPending(true); setError(''); @@ -112,7 +114,7 @@ export function NativeSettings({ model }: { const rows = (native?.fields ?? []).filter(f => (!f.forModel || (model.toLowerCase().includes(f.forModel) && (f.id !== 'ds_experts' || dsExperts))) && `${tr(f.label)} ${f.id} ${tr(f.group)}`.toLowerCase().includes(query.toLowerCase())); const switchRows = switches.filter(sw => `${tr(sw.label)} ${sw.id} ${tr('Speed')}`.toLowerCase().includes(query.toLowerCase())); return

{tr("Native engine settings")}{tr(tuned?.changed?.length ?

{tr("Your tuning '{0}' sets", [tuned.preset?.name ?? ''])}

    {tuned.changed.map(c => { const d = describeChange(c); return
  • {d.name}{d.now || tr('off')}{d.was !== null ? {tr("was {0}", [d.was])} : null}
  • ; })}
: null)}

{tr(!original ? 'Reading saved settings… ' : '')}{tr("Settings for this model. Blank values use Strata\u2019s defaults.")}

{tr(['fields', 'json', 'tools'].map(t => ))}
- {tr(tab === 'fields' ? <> setQuery(e.target.value)}/>{tr(['Responses', 'GPU & memory', 'Serving', 'Image reading', 'Tools', 'Recovery'].map(group => rows.some(f => f.group === group) ?

{tr(group)}

{tr(rows.filter(f => f.group === group).map(f => ))}
: null))}{tr(switchRows.length ?

{tr("Speed")}

{tr(switchRows.map(sw =>