Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
76 lines
6.1 KiB
JavaScript
76 lines
6.1 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { transform } from 'esbuild';
|
|
async function loadTs(path) {
|
|
const {code}=await transform(await readFile(new URL(path,import.meta.url),'utf8'),{loader:'ts',format:'esm'});
|
|
return import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
|
|
}
|
|
const profiles=await loadTs('../src/lib/run-profiles.ts');
|
|
const memory=await loadTs('../src/lib/run-memory.ts');
|
|
const engine={expert:[{id:'ctx.length',recommended:'128K'},{id:'perf.threads',recommended:8},{id:'mem.mmap',recommended:true}]};
|
|
const hardware={host:{name:'Test PC',platform:'darwin',arch:'arm64'},cpu:{model:'Test CPU',cores:10},memory:{totalGb:16},gpus:[{id:'a',name:'Unified GPU',vramGb:16,backend:'metal',unified:true}],accelerator:{backend:'metal',unified:true}};
|
|
const experience={source:'demo',config:{placement:'Automatic'},reading:{low:100,high:120},answer:{low:20,high:30},memory:{weights:19,cache:2.7,runtime:2.5,total:24.2}};
|
|
|
|
test('saved settings retain the optional image choice and older profiles restore Off',()=>{
|
|
const config=profiles.recommendedConfig(engine,hardware);
|
|
const profile={id:'images',name:'With images',variantId:'q4',hardware:profiles.computerIdentity(hardware),engineVersion:'1',config,imageModel:'q6',updatedAt:'2026-10-12'};
|
|
const saved=profiles.saveProfile(profiles.emptyProfiles(),profile,true);
|
|
assert.equal(profiles.readProfiles(JSON.stringify(saved)).profiles[0].imageModel,'q6');
|
|
const older=structuredClone(saved);delete older.profiles[0].imageModel;
|
|
assert.equal(profiles.readProfiles(JSON.stringify(older)).profiles[0].imageModel,'off');
|
|
older.profiles[0].imageModel='unknown-version';
|
|
assert.equal(profiles.readProfiles(JSON.stringify(older)).profiles[0].imageModel,'off');
|
|
});
|
|
|
|
test('profiles retain custom expert values and defaults belong to an exact version on a specific computer',()=>{
|
|
const config=profiles.recommendedConfig(engine,hardware,'256k');config.expert['sample.temp']=.37;
|
|
const computer=profiles.computerIdentity(hardware);
|
|
const profile={id:'daily',name:'Everyday',variantId:'q4',hardware:computer,engineVersion:'1',config,updatedAt:'2026-10-10'};
|
|
const store=profiles.saveProfile(profiles.emptyProfiles(),profile,true);
|
|
config.expert['sample.temp']=1; // A later draft must not alter the saved profile.
|
|
const restored=profiles.readProfiles(JSON.stringify(store));
|
|
assert.equal(restored.profiles[0].config.expert['sample.temp'],.37);
|
|
assert.equal(restored.profiles[0].config.expert['ctx.length'],'256K');
|
|
assert.equal(restored.defaults[profiles.defaultProfileKey(computer,'q4')],'daily');
|
|
assert.equal(restored.defaults[profiles.defaultProfileKey(computer,'q2')],undefined);
|
|
const different=profiles.computerIdentity({...hardware,memory:{totalGb:32}});
|
|
assert.equal(restored.defaults[profiles.defaultProfileKey(different,'q4')],undefined);
|
|
assert.equal(profiles.saveProfile(restored,restored.profiles[0],false).defaults[profiles.defaultProfileKey(computer,'q4')],undefined);
|
|
});
|
|
test('resource choices preserve expert tuning and reset returns to 128K with hardware-aware CPU headroom',()=>{
|
|
const config=profiles.recommendedConfig(engine,hardware,'512k');config.expert['sample.temp']=.3;
|
|
const full=profiles.resourceConfig(config,'full',hardware);
|
|
assert.equal(full.expert['perf.threads'],10);assert.equal(full.expert['ctx.length'],'512K');assert.equal(full.expert['sample.temp'],.3);
|
|
const recommended=profiles.recommendedConfig(engine,hardware);
|
|
assert.equal(recommended.beginner.contextLength,'recommended');assert.equal(recommended.expert['ctx.length'],'128K');assert.equal(recommended.expert['perf.threads'],8);
|
|
const dual=profiles.resourceConfig(config,'shared',{...hardware,cpu:{...hardware.cpu,cores:48}});
|
|
assert.equal(dual.expert['perf.threads'],38);
|
|
});
|
|
test('unified memory is counted once; SSD plans change with context and computer use',()=>{
|
|
const shared=memory.planMemory(experience,hardware,'shared');const full=memory.planMemory(experience,hardware,'full');
|
|
assert.equal(shared.gpu,0);assert.equal(shared.budget,12);assert.equal(full.budget,14);
|
|
assert.ok(Math.abs(shared.ram+shared.ssd-shared.total)<.001);
|
|
assert.ok(full.ssd<shared.ssd);
|
|
const shorter=memory.planMemory({...experience,memory:{...experience.memory,cache:.7,total:22.2}},hardware,'shared');
|
|
assert.ok(shorter.ssd<shared.ssd);
|
|
const tooMuchCache=memory.planMemory({...experience,memory:{...experience.memory,cache:20}},hardware,'shared');
|
|
assert.equal(tooMuchCache.cacheFits,false);assert.equal(tooMuchCache.ssd,0,'KV cache overflow must not be represented as disk-backed weights');
|
|
const parallel=memory.planMemory(experience,hardware,'shared',4);assert.equal(parallel.cacheFits,false);
|
|
const locked=memory.planMemory(experience,hardware,'shared',1,false);assert.equal(locked.ssd,0);assert.ok(locked.total>locked.budget,'Locked model memory must not be presented as an SSD spill plan');
|
|
});
|
|
test('multi-GPU planning retains individual budgets and respects CPU-only and unknown partial placement',()=>{
|
|
const discrete={...hardware,memory:{totalGb:32},accelerator:{backend:'cuda',unified:false},gpus:[{id:'a',name:'GPU A',vramGb:24,backend:'cuda'},{id:'b',name:'GPU B',vramGb:12,backend:'cuda'}]};
|
|
const plan=memory.planMemory(experience,discrete,'shared');
|
|
assert.equal(plan.devices.length,2);assert.equal(plan.budget,24+21.6+10.8);assert.equal(plan.ssd,0);
|
|
const cpu=memory.planMemory({...experience,config:{placement:'CPU only'}},discrete,'shared');assert.equal(cpu.gpu,0);assert.equal(cpu.devices.length,0);assert.equal(cpu.budget,24);
|
|
assert.equal(memory.planMemory({...experience,config:{placement:'Half'}},discrete,'shared'),null);
|
|
});
|
|
test('illustrative spill penalties never modify or impersonate measured performance',()=>{
|
|
const plan=memory.planMemory(experience,hardware,'shared');
|
|
assert.ok(memory.demoRunExperience(experience,plan,'shared').answer.low<experience.answer.low);
|
|
const measured={...experience,source:'measured'};
|
|
assert.strictEqual(memory.demoRunExperience(measured,plan,'full'),measured);
|
|
assert.deepEqual(experience.answer,{low:20,high:30});
|
|
});
|