okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0351ecb11
main
1/** GPU roles in the host: a load writes the roles and the legacy mirror (Main last), a file that names roles keeps them, every card Off is allowed. */ 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { readFileSync , writeFileSync } from 'node:fs' ; 5import { join } from 'node:path' ; 6import { nativeFixture , finishJob } from './helpers/native-fixture.mjs' ; 7 8const load = async ( f , args ) => { const done = await finishJob ( f . control , f . control . operation ( 'load' , { model :'iq2_xs' , ...args }). id ); return done ; }; 9const written = ( f , done ) => JSON . parse ( readFileSync ( f . control . resolveInstance ( done . result . instanceId ). configPath , 'utf8' )); 10 11test ( 'roles chosen in the screen: Helpers first, Main LAST, Off left out, and "gpu_roles" beside the mirror' , async () => { 12const f = nativeFixture (); 13try { 14await f . control . refresh ( true ); 15const done = await load ( f , { gpuRoles :{ 0 :'main' , 1 :'helper' } }); 16assert . equal ( done . state , 'done' , done . error ); 17const cfg = written ( f , done ); 18assert . deepEqual ( cfg . gpu , [ 1 , 0 ], 'card 0 is Main, so it is the last stage' ); 19assert . equal ( cfg . gpu_order , 'as_given' ); 20assert . deepEqual ( cfg . gpu_roles , { 0 :'main' , 1 :'helper' }); 21assert . equal ( cfg . layer_split , 'auto' ); 22assert . deepEqual ( f . control . resolveInstance ( done . result . instanceId ). gpus , [ 1 , 0 ]); 23await f . control . unload ( done . result . instanceId ); 24const one = await load ( f , { gpuRoles :{ 0 :'off' , 1 :'main' } }); 25assert . equal ( one . state , 'done' , one . error ); 26const c1 = written ( f , one ); 27assert . equal ( c1 . gpu , 1 , 'one card is a number, never a list' ); 28assert . deepEqual ( c1 . gpu_roles , { 0 :'off' , 1 :'main' }); 29} finally { await f . cleanup (); } 30}); 31 32test ( 'every card Off is allowed: no card in the list, "gpu_none" says it was meant' , async () => { 33const f = nativeFixture (); 34try { 35await f . control . refresh ( true ); 36const done = await load ( f , { gpuRoles :{ 0 :'off' , 1 :'off' } }); 37assert . equal ( done . state , 'done' , done . error ); 38const cfg = written ( f , done ); 39assert . deepEqual ( cfg . gpu , []); 40assert . equal ( cfg . gpu_none , true ); 41} finally { await f . cleanup (); } 42}); 43 44test ( 'a settings file that names roles keeps them when the screen only suggests cards; a plain card list replaces them' , async () => { 45const f = nativeFixture (); 46try { 47await f . control . refresh ( true ); 48const path = join ( f . repo , 'strata-iq2_xs.json' ); 49const config = JSON . parse ( readFileSync ( path , 'utf8' )); 50Object . assign ( config , { gpu :[ 0 , 1 ], gpu_order :'as_given' , gpu_roles :{ 0 :'helper' , 1 :'main' } }); 51writeFileSync ( path , JSON . stringify ( config )); 52await f . control . refresh ( true ); 53const kept = await load ( f , { gpus :[ 1 , 0 ], gpusFromRecommendation :true }); 54assert . equal ( kept . state , 'done' , kept . error ); 55assert . deepEqual ( written ( f , kept ). gpu , [ 0 , 1 ]); 56await f . control . unload ( kept . result . instanceId ); 57const picked = await load ( f , { gpus :[ 1 ] }); 58assert . equal ( picked . state , 'done' , picked . error ); 59const cfg = written ( f , picked ); 60assert . equal ( cfg . gpu , 1 ); 61assert . equal ( 'gpu_roles' in cfg , false , 'a card list picked by hand replaces the roles' ); 62} finally { await f . cleanup (); } 63}); 64 65test ( 'roles that make no sense are refused with a plain line' , async () => { 66const f = nativeFixture (); 67try { 68await f . control . refresh ( true ); 69const two = await load ( f , { gpuRoles :{ 0 :'main' , 1 :'main' } }); 70assert . equal ( two . state , 'error' ); 71assert . match ( two . error , / Main, Helper or Off / ); 72const nope = await load ( f , { gpuRoles :{ 5 :'main' } }); 73assert . equal ( nope . state , 'error' ); 74assert . match ( nope . error , / detected graphics cards / ); 75} finally { await f . cleanup (); } 76}); 77 78test ( '"Tune this model" keeps a two-card role map exactly as the person set it, in the file and in the engine it starts (#3655)' , async () => { 79const f = nativeFixture (); 80try { 81await f . control . refresh ( true ); 82const path = join ( f . repo , 'strata-iq2_xs.json' ); 83const config = JSON . parse ( readFileSync ( path , 'utf8' )); 84Object . assign ( config , { gpu :[ 0 , 1 ], gpu_order :'as_given' , gpu_roles :{ 0 :'helper' , 1 :'main' }, gpu_cards :{ 0 :'GTX 1080' , 1 :'GTX 1080' } }); 85writeFileSync ( path , JSON . stringify ( config )); 86await f . control . refresh ( true ); 87const tuned = await finishJob ( f . control , f . control . operation ( 'tune' , { model :'iq2_xs' , profile :'performance' , calibrate :false }). id ); 88assert . equal ( tuned . state , 'done' , tuned . error ); 89const after = JSON . parse ( readFileSync ( path , 'utf8' )); 90for ( const key of [ 'gpu' , 'gpu_order' , 'gpu_roles' , 'gpu_cards' ]) assert . deepEqual ( after [ key ], config [ key ], ` ${ key } in the settings file is untouched by Tune` ); 91const started = written ( f , tuned ); 92assert . deepEqual ( started . gpu , [ 0 , 1 ], 'and the engine Tune loads runs on both cards' ); 93assert . deepEqual ( started . gpu_roles , { 0 :'helper' , 1 :'main' }); 94} finally { await f . cleanup (); } 95});