okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
dbdd81a67
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { resourceSettings , saferStart , ramKeepGib , engineKnowsRamKeep , engineVersionOfExe , RAM_KEEP_MIN_ENGINE } from '../server/native-resources.mjs' ; 4 5const pc64 = { cpu :{ cores :12 }, ram_gb :63 , gpus :[{ index :0 , name :'NVIDIA GeForce RTX 5070' , vram_gb :11.9 }] }; 6const iq3s = { arenaGb :50.3 }; // engine version not known 7const iq3sNew = { arenaGb :50.3 , engineVersion :'0.1.56' }; // an engine that knows the setting 8const iq3sOld = { arenaGb :50.3 , engineVersion :'0.1.55' }; // the 0.2.9 release engine 9const config = { gpu :0 , args :[ '--native' , 'x.gguf' , '--max-context' , '32768' , '--pool-workers' , '12' ] }; 10const flag = ( args , name ) => args [ args . indexOf ( name ) + 1 ]; 11const old279 = ( ram , arena = 50.3 ) => Math . max ( 8 , Math . min ( Math . floor ( ram * .8 ) - 10 , Math . floor ( arena / 1.073741824 ))); // the 0.2.9 rule 12 13test ( 'which engines know the setting: RAM_KEEP_MIN_ENGINE and newer; unknown or unreadable versions are treated as older' , () => { 14assert . equal ( RAM_KEEP_MIN_ENGINE , '0.1.56' ); 15for ( const v of [ '0.1.56' , '0.1.56.1' , '0.1.57' , '0.2.0' , 'v0.1.56' , '1.0' ]) assert . equal ( engineKnowsRamKeep ( v ), true , v ); 16for ( const v of [ '0.1.52' , '0.1.54' , '0.1.55' , '0.1.55.1' , '0.1.55.2' , '0.1.5' , '0.1' , null , undefined , '' , 'local' , 'dev' ]) assert . equal ( engineKnowsRamKeep ( v ), false , String ( v )); 17assert . equal ( engineVersionOfExe ( 'C:\\Users\\x\\AppData\\Local\\Strata\\components\\engine\\0.1.54-windows-x86_64-cuda-cuda13\\strata.exe' ), '0.1.54' ); 18assert . equal ( engineVersionOfExe ( '/home/u/.strata/components/engine/0.1.56-linux-x86_64-cuda/strata' ), '0.1.56' ); 19assert . equal ( engineVersionOfExe ( 'component:strata-engine' ), null ); 20}); 21 22test ( 'an engine that knows the setting: "leave 20% for my work" asks it to keep W GiB of RAM free (env STRATA_RAM_KEEP_GIB), not a budget of 80% of the RAM' , () => { 23const work = resourceSettings ( config , pc64 , 'work' , iq3sNew ); 24assert . equal ( work . env . STRATA_RAM_KEEP_GIB , '8' , '63 GB: a fifth is 12.6, capped at 8' ); 25assert . equal ( work . args . includes ( '--ram-keep-gib' ), false , 'in the env, not as a flag' ); 26assert . equal ( work . args . includes ( '--resident-budget-gib' ), false , 'the engine decides from the RAM free at its start, not from the total: no budget from the app' ); 27assert . equal ( work . env . STRATA_RESIDENT_HEADROOM_GIB , undefined , 'and no STRATA_RESIDENT_HEADROOM_GIB of 20%' ); 28assert . deepEqual ([ work . ui_resource_baseline . ramKeep , work . ui_resource_baseline . ramBudget , work . ui_resource_baseline . ramHeadroom ], [ true , false , false ]); 29}); 30 31test ( 'an older engine (0.1.52, 0.1.54, 0.1.55 in the Engine tab) gets the 0.2.9 rule unchanged and never an argument it does not know' , () => { 32for ( const v of [ '0.1.52' , '0.1.54' , '0.1.55' , '0.1.55.1' ]) { 33const w = resourceSettings ( config , pc64 , 'work' , { arenaGb :50.3 , engineVersion :v }); 34assert . equal ( flag ( w . args , '--resident-budget-gib' ), String ( old279 ( 63 )), ` ${ v } : the 80% budget` ); 35assert . equal ( w . env . STRATA_RESIDENT_HEADROOM_GIB , '13' , ` ${ v } : 20% of 63 GB, rounded up` ); 36assert . equal ( w . env . STRATA_RAM_KEEP_GIB , undefined , ` ${ v } : the setting it does not know is not sent` ); 37assert . equal ( w . args . includes ( '--ram-keep-gib' ), false ); 38assert . deepEqual ([ w . ui_resource_baseline . ramKeep , w . ui_resource_baseline . ramBudget , w . ui_resource_baseline . ramHeadroom ], [ false , true , true ]); 39} 40// no engine version at all (not readable): the rule every engine understands 41const unknown = resourceSettings ( config , pc64 , 'work' , iq3s ); 42assert . equal ( flag ( unknown . args , '--resident-budget-gib' ), String ( old279 ( 63 ))); 43assert . equal ( unknown . env . STRATA_RAM_KEEP_GIB , undefined ); 44// an engine named by the run config's exe wins over the active engine's version 45const pinned = resourceSettings ({ ...config , exe :'C:\\x\\components\\engine\\0.1.54-windows-x86_64-cuda-cuda13\\strata.exe' }, pc64 , 'work' , iq3sNew ); 46assert . equal ( pinned . env . STRATA_RAM_KEEP_GIB , undefined ); 47assert . equal ( flag ( pinned . args , '--resident-budget-gib' ), String ( old279 ( 63 ))); 48const newer = resourceSettings ({ ...config , exe :'/x/components/engine/0.1.57-linux-x86_64-cuda/strata' }, pc64 , 'work' , iq3sOld ); 49assert . equal ( newer . env . STRATA_RAM_KEEP_GIB , '8' ); 50assert . equal ( newer . args . includes ( '--resident-budget-gib' ), false ); 51}); 52 53test ( '24, 32, 64 and 128 GB: a newer engine gets W in the env, an older one gets the 0.2.9 budget and 20% headroom; "Leave 20%" off gives neither' , () => { 54const cases = [[ 24 , '5' , 9 , '5' ], [ 32 , '7' , 15 , '7' ], [ 64 , '8' , 41 , '13' ], [ 128 , '8' , null , null ], [ 16 , '5' , 8 , '4' ], [ 26 , '6' , 10 , '6' ], [ 36 , '8' , 18 , '8' ], [ 63 , '8' , old279 ( 63 ), '13' ]]; 55for ( const [ ram , w , budget , headroom ] of cases ) { 56const pc = { ...pc64 , ram_gb :ram }; 57const on = resourceSettings ( config , pc , 'work' , iq3sNew ); 58assert . equal ( on . env . STRATA_RAM_KEEP_GIB , w , ` ${ ram } GB, new engine, Leave 20% on` ); 59assert . equal ( on . args . includes ( '--ram-keep-gib' ), false , ` ${ ram } GB: not a flag` ); 60assert . equal ( on . args . includes ( '--resident-budget-gib' ), false , ` ${ ram } GB: no budget from the app` ); 61assert . equal ( on . env . STRATA_RESIDENT_HEADROOM_GIB , undefined , ` ${ ram } GB: no env headroom` ); 62const older = resourceSettings ( config , pc , 'work' , iq3sOld ); 63assert . equal ( older . env ?. STRATA_RAM_KEEP_GIB , undefined , ` ${ ram } GB, old engine: no setting it does not know` ); 64assert . equal ( older . args . includes ( '--ram-keep-gib' ), false ); 65if ( budget === null ) { 66assert . equal ( older . args . includes ( '--resident-budget-gib' ), false , ` ${ ram } GB, old engine: the experts fit 80% of the RAM with 10 to spare: left alone` ); 67assert . equal ( older . env , undefined ); 68} else { 69assert . equal ( flag ( older . args , '--resident-budget-gib' ), String ( budget ), ` ${ ram } GB, old engine: the 0.2.9 budget` ); 70assert . equal ( older . env . STRATA_RESIDENT_HEADROOM_GIB , headroom , ` ${ ram } GB, old engine: 20% of the RAM rounded up` ); 71} 72for ( const v of [ iq3sNew , iq3sOld ]) { 73const off = resourceSettings ( config , pc , 'performance' , v ); 74assert . equal ( off . args . includes ( '--ram-keep-gib' ), false , ` ${ ram } GB, Leave 20% off` ); 75assert . equal ( off . args . includes ( '--resident-budget-gib' ), false , ` ${ ram } GB, off: no budget either` ); 76assert . equal ( off . env , undefined , ` ${ ram } GB, off: no env` ); 77} 78} 79assert . equal ( ramKeepGib ( 24 ), 5 ); assert . equal ( ramKeepGib ( 32 ), 7 ); assert . equal ( ramKeepGib ( 64 ), 8 ); assert . equal ( ramKeepGib ( 128 ), 8 ); 80assert . equal ( ramKeepGib ( 0 ), 5 , 'unknown RAM: the floor' ); assert . equal ( ramKeepGib ( undefined ), 5 ); 81}); 82 83test ( 'full performance takes the RAM settings of either engine out again and keeps what the installation had' , () => { 84for ( const model of [ iq3sNew , iq3sOld ]) { 85const work = resourceSettings ( config , pc64 , 'work' , model ); 86const back = resourceSettings ({ ...config , args :work . args , env :work . env , ui_resource_profile :'work' , ui_resource_baseline :work . ui_resource_baseline }, pc64 , 'performance' , model ); 87for ( const name of [ 'STRATA_RAM_KEEP_GIB' , 'STRATA_RESIDENT_HEADROOM_GIB' ]) assert . equal ( back . env ?.[ name ], undefined , ` ${ model . engineVersion } : ${ name } ` ); 88assert . equal ( back . args . includes ( '--ram-keep-gib' ), false ); 89assert . equal ( back . args . includes ( '--resident-budget-gib' ), false ); 90assert . deepEqual ([ back . ui_resource_baseline . ramKeep , back . ui_resource_baseline . ramBudget , back . ui_resource_baseline . ramHeadroom ], [ false , false , false ]); 91assert . equal ( flag ( back . args , '--pool-workers' ), '12' ); 92} 93assert . equal ( resourceSettings ( config , pc64 , 'performance' , iq3sNew ). env , undefined , 'performance from the start: nothing is passed, the whole system is used' ); 94}); 95 96test ( 'switching the engine in the Engine tab between loads swaps the rule: new -> old and old -> new' , () => { 97const asConfig = r => ({ ...config , args :r . args , env :r . env , ui_resource_profile :'work' , ui_resource_baseline :r . ui_resource_baseline }); 98const onNew = resourceSettings ( config , pc64 , 'work' , iq3sNew ); 99const toOld = resourceSettings ( asConfig ( onNew ), pc64 , 'work' , iq3sOld ); 100assert . equal ( toOld . env . STRATA_RAM_KEEP_GIB , undefined , 'the setting is not left behind for the engine that ignores it' ); 101assert . equal ( flag ( toOld . args , '--resident-budget-gib' ), String ( old279 ( 63 ))); 102assert . equal ( toOld . env . STRATA_RESIDENT_HEADROOM_GIB , '13' ); 103const backNew = resourceSettings ( asConfig ( toOld ), pc64 , 'work' , iq3sNew ); 104assert . equal ( backNew . args . includes ( '--resident-budget-gib' ), false , 'the old budget is gone again' ); 105assert . equal ( backNew . env . STRATA_RESIDENT_HEADROOM_GIB , undefined ); 106assert . equal ( backNew . env . STRATA_RAM_KEEP_GIB , '8' ); 107}); 108 109test ( 'a model whose size is unknown, or one with a RAM mode of the person, is left alone (either engine)' , () => { 110for ( const model of [ iq3sNew , iq3sOld ]) { 111assert . equal ( resourceSettings ( config , { ...pc64 , ram_gb :0 }, 'work' , model ). env , undefined , 'no RAM figure, no change' ); 112const ownEnv = resourceSettings ({ ...config , env :{ STRATA_RAM_KEEP_GIB :'3' } }, pc64 , 'work' , model ); 113if ( model === iq3sNew ) assert . equal ( ownEnv . env , undefined , 'a STRATA_RAM_KEEP_GIB of the person is left in the run config as it is' ); 114else { // an engine that ignores that variable: it keeps the person's value in the file and the 0.2.9 rule gives the room 115assert . equal ( ownEnv . env . STRATA_RAM_KEEP_GIB , '3' ); 116assert . equal ( flag ( ownEnv . args , '--resident-budget-gib' ), String ( old279 ( 63 ))); 117} 118for ( const mine of [[ '--mmap-experts' ], [ '--resident-experts' ], [ '--resident-budget-gib' , '30' ], [ '--ram-keep-gib' , '3' ]]) { 119const own = { ...config , args :[ ...config . args , ...mine ] }; 120const work = resourceSettings ( own , pc64 , 'work' , model ); 121assert . equal ( work . env , undefined , ` ${ mine [ 0 ]} : the app adds no RAM setting of its own` ); 122assert . ok ( work . args . includes ( mine [ 0 ]), ` ${ mine [ 0 ]} stays as it is` ); 123if ( mine [ 0 ] === '--resident-budget-gib' ) assert . equal ( flag ( work . args , '--resident-budget-gib' ), '30' ); 124assert . equal ( work . args . filter ( a => a === '--ram-keep-gib' ). length , mine [ 0 ] === '--ram-keep-gib' ?1 :0 , ` ${ mine [ 0 ]} : the app adds no flag` ); 125} 126} 127assert . equal ( resourceSettings ( config , pc64 , 'work' ). env , undefined , 'no model size, no change' ); 128}); 129 130test ( 'a config written by the earlier version (an 80% budget and a 20% env headroom) is replaced by the rule of the engine in use, and full performance takes the old settings out' , () => { 131const old = { ...config , args :[ ...config . args , '--resident-budget-gib' , '38' ], env :{ STRATA_RESIDENT_HEADROOM_GIB :'13' }, 132ui_resource_profile :'work' , ui_resource_baseline :{ workers :12 , reserve :0 , ramBudget :true , ramHeadroom :true } }; 133const work = resourceSettings ( old , pc64 , 'work' , iq3sNew ); 134assert . equal ( work . args . includes ( '--resident-budget-gib' ), false , 'the old budget is gone for an engine that knows the setting' ); 135assert . equal ( work . env . STRATA_RAM_KEEP_GIB , '8' ); 136assert . equal ( work . env . STRATA_RESIDENT_HEADROOM_GIB , undefined , 'and the old 20% env with it' ); 137const same = resourceSettings ( old , pc64 , 'work' , iq3sOld ); 138assert . equal ( flag ( same . args , '--resident-budget-gib' ), String ( old279 ( 63 )), 'an older engine keeps the 0.2.9 rule' ); 139assert . equal ( same . env . STRATA_RESIDENT_HEADROOM_GIB , '13' ); 140const perf = resourceSettings ( old , pc64 , 'performance' , iq3sNew ); 141assert . equal ( perf . args . includes ( '--resident-budget-gib' ), false ); 142assert . equal ( perf . args . includes ( '--ram-keep-gib' ), false ); 143assert . equal ( perf . env . STRATA_RESIDENT_HEADROOM_GIB , undefined ); 144assert . equal ( perf . env . STRATA_RAM_KEEP_GIB , undefined ); 145}); 146 147test ( 'neither profile reserves less VRAM than the engine\'s safe floor (the driver pages GPU memory below it and decoding collapses)' , () => { 148const card12 = { cpu :{ cores :12 }, ram_gb :63 , gpus :[{ index :0 , vram_gb :11.9 }] }; 149const card24 = { cpu :{ cores :12 }, ram_gb :63 , gpus :[{ index :0 , vram_gb :24 }] }; 150for ( const profile of [ 'work' , 'performance' ]) { 151const lowConfig = { gpu :0 , args :[ '--max-context' , '32768' , '--vram-reserve-mib' , '700' ] }; 152assert . ok ( resourceSettings ( lowConfig , card12 , profile ). vram_reserve_mib >= 1536 , ` ${ profile } on 12 GB` ); 153assert . ok ( resourceSettings ({ gpu :0 , args :[] }, card12 , profile ). vram_reserve_mib >= 1536 , ` ${ profile } , nothing configured` ); 154assert . ok ( resourceSettings ( lowConfig , card24 , profile ). vram_reserve_mib >= 1024 , ` ${ profile } on 24 GB` ); 155} 156assert . equal ( resourceSettings ({ gpu :0 , args :[] }, card12 , 'performance' ). vram_reserve_mib , 1536 ); 157assert . equal ( resourceSettings ({ gpu :0 , args :[] }, card24 , 'performance' ). vram_reserve_mib , 1024 ); 158assert . equal ( resourceSettings ({ gpu :0 , args :[], vram_reserve_mib :2437 }, card12 , 'performance' ). vram_reserve_mib , 2437 , 'a larger reserve of the installation is kept' ); 159}); 160 161test ( 'a STRATA_RESIDENT_HEADROOM_GIB of the person is left in the env (the engine reads it first); the app sets no env headroom of its own for an engine that knows the setting' , () => { 162const own = resourceSettings ({ ...config , env :{ STRATA_RESIDENT_HEADROOM_GIB :'6' , OTHER :'x' } }, pc64 , 'work' , iq3sNew ); 163assert . equal ( own . env . STRATA_RESIDENT_HEADROOM_GIB , '6' , 'a value the user set is not overwritten (the engine reads it before W)' ); 164assert . equal ( own . env . OTHER , 'x' ); 165assert . equal ( own . env . STRATA_RAM_KEEP_GIB , '8' ); 166for ( const ram of [ 24 , 32 , 64 , 128 ]) assert . equal ( resourceSettings ( config , { ...pc64 , ram_gb :ram }, 'work' , iq3sNew ). env . STRATA_RESIDENT_HEADROOM_GIB , undefined , ` ${ ram } GB: no env headroom` ); 167// an older engine: the 0.2.9 behaviour, a headroom of the person's is not overwritten either 168const oldOwn = resourceSettings ({ ...config , env :{ STRATA_RESIDENT_HEADROOM_GIB :'6' } }, pc64 , 'work' , iq3sOld ); 169assert . equal ( oldOwn . env , undefined ); 170assert . equal ( flag ( oldOwn . args , '--resident-budget-gib' ), String ( old279 ( 63 ))); 171}); 172 173test ( 'a start that died gets ONE safer second try: pin less when the locked memory ran out, else a RAM budget with the rest on the SSD' , () => { 174const pinned = saferStart ( config , pc64 , iq3s , 'server_exited: mapped staging allocation failed [pinned-memory-exhausted] start again with STRATA_ARENA_PIN_GIB=26 (pin less)' ); 175assert . equal ( pinned . config . env . STRATA_ARENA_PIN_GIB , '26' ); 176assert . match ( pinned . words , / would not lock as much memory / ); 177assert . equal ( flag ( saferStart ( pinned . config , pc64 , iq3s , 'server_exited: mapped staging allocation failed [pinned-memory-exhausted]' ). config . args , '--resident-budget-gib' ), String ( Math . floor ( 63 * .5 ) - 4 ), 'already pinned less: the next safer setting is the RAM budget' ); 178const noHint = saferStart ( config , pc64 , iq3s , 'mapped staging allocation failed' ); 179assert . equal ( noHint . config . env . STRATA_ARENA_PIN_GIB , String ( Math . floor ( 63 / 2 ) - 8 )); 180const low = saferStart ( config , pc64 , iq3s , 'server_exited: memory guard: 1.9 GiB free' ); 181assert . equal ( flag ( low . config . args , '--resident-budget-gib' ), String ( Math . floor ( 63 * .5 ) - 4 )); 182assert . match ( low . words , / low-memory mode / ); 183const already = saferStart ({ ...config , args :[ ...config . args , '--resident-budget-gib' , '40' ] }, pc64 , iq3s , 'server_exited' ); 184assert . equal ( flag ( already . config . args , '--resident-budget-gib' ), '28' , '70% of the budget it had' ); 185assert . equal ( saferStart ({ ...config , args :[ ...config . args , '--resident-budget-gib' , '10' ] }, pc64 , iq3s , 'server_exited' ), null , 'below 8 GB there is nothing left to give' ); 186assert . equal ( saferStart ({ ...config , args :[ ...config . args , '--resident-experts' ] }, pc64 , iq3s , 'server_exited' ), null , 'already the SSD mode' ); 187assert . equal ( saferStart ( config , pc64 , { arenaGb :20 }, 'server_exited' ), null , 'a model that fits RAM gains nothing from the SSD mode' ); 188assert . equal ( saferStart ( config , pc64 , undefined , 'server_exited' ), null , 'unknown model size: no guess' ); 189assert . equal ( saferStart ( config , pc64 , iq3s , 'Some model files are missing' ), null , 'not a memory failure: no second try' ); 190assert . equal ( config . args . includes ( '--resident-budget-gib' ), false , 'the input config is not changed' ); 191}); 192 193test ( 'an engine that stopped because the GPU expert cache got no room is started again with less VRAM kept free, then a shorter context (#3192)' , () => { 194const tenGb = { cpu :{ cores :16 }, ram_gb :64 , gpus :[{ index :0 , name :'NVIDIA GeForce RTX 3080' , vram_gb :10 }] }; 195const cfg = { gpu :0 , args :[ '--native' , 'x.gguf' , '--max-context' , '131072' , '--vision' , '--vram-reserve-mib' , '2048' ] }; 196const log = "server_exited (exit code 1): strata generate: no VRAM is left for the expert cache: it needs at least 288 slots (639 MiB), about 727 MiB more than this card has free. To make room: a smaller --max-context (the session, mostly its KV cache, takes 1931 MiB at 131072 tokens), --kv q4_0 | strata serve: verify: needs the profile-filled VRAM expert tier" ; 197const safer = saferStart ( cfg , tenGb , iq3s , log ); 198assert . equal ( flag ( safer . config . args , '--vram-reserve-mib' ), '1065' , '2048 - (727 + 256 margin)' ); 199assert . equal ( flag ( safer . config . args , '--max-context' ), '131072' , 'the reserve alone was enough: the context stays' ); 200assert . match ( safer . words , / no room left / ); 201const tight = saferStart ({ ...cfg , args :[ '--max-context' , '131072' , '--vram-reserve-mib' , '1100' ] }, tenGb , iq3s , log ); 202assert . equal ( flag ( tight . config . args , '--vram-reserve-mib' ), '1024' , 'never below 1024 MiB (#2065)' ); 203assert . ok ( Number ( flag ( tight . config . args , '--max-context' )) < 131072 , 'the rest comes from the context' ); 204assert . equal ( saferStart ({ ...cfg , args :[ '--max-context' , '16384' , '--vram-reserve-mib' , '1024' ] }, tenGb , iq3s , log ), null , 'nothing left to give' ); 205assert . equal ( flag ( saferStart ( cfg , tenGb , undefined , 'server_exited: strata serve: verify: needs the profile-filled VRAM expert tier' ). config . args , '--vram-reserve-mib' ), '1092' , 'without the numbers: a fixed step, no model size needed' ); 206assert . equal ( cfg . args [ cfg . args . indexOf ( '--vram-reserve-mib' ) + 1 ], '2048' , 'the input config is not changed' ); 207}); 208 209test ( '0.2.3 tuning: the Work profile takes 80% of the PHYSICAL cores rounded up, never more than the cores less the host thread' , () => { 210const w = cores => Number ( flag ( resourceSettings ({ gpu :0 , args :[] }, { cpu :{ cores}, ram_gb :64 , gpus :[{ index :0 , vram_gb :12 }] }, 'work' ). args , '--pool-workers' )); 211assert . equal ( w ( 6 ), 5 , 'Ryzen 5 7600: the engine\'s own 5 (floor gave 4, 8-10% slower; 12 logical threads gave 9 in 0.2.1)' ); 212assert . equal ( w ( 4 ), 3 ); 213assert . equal ( w ( 8 ), 7 ); 214assert . equal ( w ( 10 ), 8 ); 215assert . equal ( w ( 12 ), 10 ); 216assert . equal ( w ( 16 ), 13 ); 217assert . equal ( w ( 2 ), 1 ); 218const own = { gpu :0 , args :[ '--pool-workers' , '3' ] }; 219assert . equal ( flag ( resourceSettings ( own , { cpu :{ cores :6 }, ram_gb :64 , gpus :[] }, 'work' ). args , '--pool-workers' ), '3' , 'a count the person set stays when it is lower' ); 220}); 221 222test ( '0.2.3 tuning: Work keeps a fifth of the card but no more than 1536 MiB on a card of 16 GB or less; a CPU picture reader needs no 2048 floor' , () => { 223const card = gb => ({ cpu :{ cores :6 }, ram_gb :64 , gpus :[{ index :0 , vram_gb :gb , drives_display :true }] }); 224assert . equal ( resourceSettings ({ gpu :0 , args :[] }, card ( 11.9 ), 'work' ). vram_reserve_mib , 1536 , 'RTX 5070: 2437 gave 38 tok/s, 1536 gave 46 (Gyro-S 64K), with 1.1 GiB still free' ); 225assert . equal ( resourceSettings ({ gpu :0 , args :[] }, card ( 16 ), 'work' ). vram_reserve_mib , 1536 ); 226assert . equal ( resourceSettings ({ gpu :0 , args :[] }, card ( 24 ), 'work' ). vram_reserve_mib , 4915 , 'above 16 GB the fifth stays' ); 227assert . equal ( resourceSettings ({ gpu :0 , args :[], vision :{ gpu :false } }, card ( 12 ), 'performance' ). vram_reserve_mib , 1536 , 'the CPU reader takes no VRAM' ); 228assert . equal ( resourceSettings ({ gpu :0 , args :[], vision :{ gpu :false } }, card ( 12 ), 'work' ). vram_reserve_mib , 1536 ); 229assert . equal ( resourceSettings ({ gpu :0 , args :[], vision :{ gpu :true } }, card ( 12 ), 'performance' ). vram_reserve_mib , 2048 , 'the GPU reader keeps its 2048' ); 230assert . equal ( resourceSettings ({ gpu :0 , args :[], vision :{ gpu :true } }, card ( 12 ), 'work' ). vram_reserve_mib , 2048 ); 231assert . equal ( resourceSettings ({ gpu :0 , args :[ '--vram-reserve-mib' , '3000' ], user_args :[ '--vram-reserve-mib' , '3000' ] }, card ( 12 ), 'work' ). vram_reserve_mib , 3000 , 'the person\'s own number is kept' ); 232}); 233 234test ( 'an engine that refused the prompt chunk at the start is not retried with a memory setting: the same chunk would fail again' , () => { 235const line = 'strata generate: a 32768-token prompt chunk does not fit beside the 52.1 GiB expert cache on this GPU (a stream could not be created): use --prefill auto:16384, or a smaller --expert-cache' ; 236const withBudget = { ...config , args :[ ...config . args , '--resident-budget-gib' , '40' ] }; 237assert . equal ( saferStart ( withBudget , pc64 , iq3s , `server_exited (exit code 2): ${ line } ` ), null ); 238assert . equal ( saferStart ( config , pc64 , iq3s , `Engine stopped (exit code 2): ${ line } ` ), null ); 239assert . ok ( saferStart ( withBudget , pc64 , iq3s , 'server_exited: memory guard: 1.9 GiB free' ), 'a real memory stop still gets its safer try' ); 240});