okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
1import type { Experience } from './experience' ; 2import type { Hardware } from './types' ; 3import type { ComputerUse } from './run-profiles' ; 4 5export interface RunMemory { 6total :number ; 7weights :number ; 8context :number ; 9runtime :number ; 10ram :number ; 11gpu :number ; 12ssd :number ; 13budget :number ; 14reserve :number ; 15unified :boolean ; 16cacheFits :boolean ; 17devices :{ name :string ; budget :number }[]; 18} 19 20/** A capacity planning preview. Actual placement must be verified by the engine. */ 21export function planMemory ( experience :Experience , hardware :Hardware | null , use :ComputerUse , parallel = 1 , allowSpill = true ) :RunMemory | null { 22if ( ! experience . memory || ! hardware ) return null ; 23const m = experience . memory ; 24const unified = hardware . accelerator . unified ; 25const cpuOnly = hardware . accelerator . backend === 'cpu' || experience . config . placement === 'CPU only' ; 26const reserve = Math . min ( hardware . memory . totalGb , use === 'shared' ?Math . max ( 4 , hardware . memory . totalGb * .25 ) :Math . max ( 2 , hardware . memory . totalGb * .125 )); 27const ramBudget = Math . max ( 0 , hardware . memory . totalGb - reserve ); 28const devices = unified || cpuOnly ?[] :hardware . gpus . filter ( g => ! g . unified && g . backend !== 'cpu' ). map ( g => ({ 29name :g . name , 30budget :Math . max ( 0 , g . vramGb - ( use === 'shared' ?Math . max ( 1 , g . vramGb * .1 ) :Math . max ( .5 , g . vramGb * .05 ))), 31})); 32const gpuBudget = devices . reduce (( sum , g ) => sum + g . budget , 0 ); 33// Explicit partial offload needs layer sizes, which this catalog does not expose. 34if ( ! unified && ! cpuOnly && ! [ 'Automatic' , 'All layers' ]. includes ( experience . config . placement )) return null ; 35const budget = ramBudget + gpuBudget ; 36const context = m . cache * Math . max ( 1 , parallel ); 37const total = m . weights + context + m . runtime ; 38const fixed = context + m . runtime ; 39const cacheFits = fixed <= ( unified || cpuOnly ?ramBudget :gpuBudget || ramBudget ); 40const ssd = cacheFits && allowSpill ?Math . min ( m . weights , Math . max ( 0 , total - budget )) :0 ; 41const gpu = Math . min ( gpuBudget , total - ssd ); 42const ram = Math . min ( ramBudget , Math . max ( 0 , total - ssd - gpu )); 43return { total, weights :m . weights , context, runtime :m . runtime , ram, gpu, ssd, budget, reserve, unified, cacheFits, devices}; 44} 45 46/** Illustrative preview curves stay separate from measured/estimated evidence. */ 47export function demoRunExperience ( experience :Experience , memory :RunMemory | null , use :ComputerUse ) :Experience { 48if ( experience . source !== 'demo' || ! memory || ! experience . reading || ! experience . answer ) return experience ; 49const spillFraction = memory . ssd / Math . max ( 1 , memory . weights ); 50const factor = ( use === 'full' ?1.08 :1 ) / ( 1 + spillFraction * 3 ); 51const scale = ( range :NonNullable < Experience [ 'reading' ]>) => ({ low :Math . max ( 1 , Math . round ( range . low * factor )), high :Math . max ( 2 , Math . round ( range . high * factor )) }); 52return { ...experience , reading :scale ( experience . reading ), answer :scale ( experience . answer ), provenance :'Illustrative design preview including context, computer use and SSD spill. Not a benchmark.' }; 53}