okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1/** 2* The version list's fit word and Control's (strata_control/fit_label.py) are one rule (owner 11-08): the weight files without the lookup table against 3* RAM + the graphics memory that counts. QAGUI-STRIX 11-09: the app counted a unified-memory chip's shared memory (the RAM again) as graphics memory, so 4* Q8_0 on Strix Halo said nothing while the catalog and the Terminal said "may run slower". This test runs the Python rule and the app's on the same 5* computers and sizes and needs them to agree. 6*/ 7import test from 'node:test' ; 8import assert from 'node:assert/strict' ; 9import { spawnSync } from 'node:child_process' ; 10import { readFileSync } from 'node:fs' ; 11import { resolve } from 'node:path' ; 12import { transform } from 'esbuild' ; 13 14const root = resolve ( import . meta. dirname , '..' ); 15const repo = resolve ( root , '../..' ); 16const { code} = await transform ( readFileSync ( resolve ( root , 'src/lib/native-fit.ts' ), 'utf8' ), { loader :'ts' , format :'esm' }); 17const { cardRoomGb, fitOn, versionFit} = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 18 19const PCS = { 20// Strix Halo, Windows (QAGUI-STRIX 11-09): 63.6 GB RAM, a 64 GB BIOS carve-out + 31.8 GB shared = 95.8 GB the GPU can reach 21strix :{ ram :63.6 , cards :[{ name :'AMD Radeon 8060S' , uma :true , dedicated_gb :64 , shared_gb :31.8 , vram_gb :95.8 }] }, 22// an APU whose report has no carve-out 23apu :{ ram :32 , cards :[{ name :'iGPU' , uma :true , vram_gb :16 }] }, 24// RTX 5070 12 GB, 64 GB RAM (the owner PC) 25rtx12 :{ ram :63.9 , cards :[{ name :'RTX 5070' , vram_gb :11.9 }] }, 26// two cards: the larger counts 27two :{ ram :32 , cards :[{ name :'A' , vram_gb :8 }, { name :'B' , vram_gb :24 }] }, 28nocard :{ ram :64 , cards :[] }, 29}; 30// sizes of the files without the table (Q8_0 133.8 = 188.2 - 54.4) and edges around each PC's RAM + card room 31const SIZES = [ 27.6 , 44.7 , 54.4 , 64.0 , 75.8 , 75.9 , 96.0 , 127.6 , 127.7 , 133.8 ]; 32 33function python () { 34for ( const exe of process . platform === 'win32' ?[ 'python' , 'py' ] :[ 'python3' , 'python' ]) { 35const r = spawnSync ( exe , [ '--version' ], { encoding :'utf8' }); 36if ( r . status === 0 ) return exe ; 37} 38return null ; 39} 40 41test ( 'the app\'s fit word is Control\'s (fit_label.py) on Strix Halo, an APU, a 12 GB card, two cards and no card' , { skip :! python () && 'no python here' }, () => { 42const exe = python (); 43const script = 'import json,sys; sys.path.insert(0, sys.argv[1]); from strata_control import fit_label as f; pcs=json.loads(sys.argv[2]); sizes=json.loads(sys.argv[3]); ' 44+ 'print(json.dumps({k: [f.label(s, p["ram"], f.card_room_gb(p["cards"])) for s in sizes] for k, p in pcs.items()}))' ; 45const r = spawnSync ( exe , [ '-I' , '-B' , '-c' , script , repo , JSON . stringify ( PCS ), JSON . stringify ( SIZES )], { encoding :'utf8' }); 46assert . equal ( r . status , 0 , r . stderr ); 47const control = JSON . parse ( r . stdout ); 48for ( const [ name , pc ] of Object . entries ( PCS )) { 49const hw = { ram_gb :pc . ram , vram_gb :cardRoomGb ( pc . cards ) }; 50const app = SIZES . map ( size => versionFit ({ fit_gb :size , memory_gb :size }, hw ) === 'fits' ?'fits' :'may run slower' ); 51assert . deepEqual ( app , control [ name ], name ); 52} 53assert . equal ( control . strix [ SIZES . indexOf ( 133.8 )], 'may run slower' , 'Strix Q8_0: may run slower' ); 54assert . equal ( control . strix [ SIZES . indexOf ( 127.6 )], 'fits' , 'up to RAM + carve-out it fits' ); 55}); 56 57test ( 'a unified-memory chip counts only its carve-out; a card its memory; the largest card counts' , () => { 58assert . equal ( cardRoomGb ( PCS . strix . cards ), 64 ); 59assert . equal ( cardRoomGb ( PCS . apu . cards ), 0 ); 60assert . equal ( cardRoomGb ( PCS . rtx12 . cards ), 11.9 ); 61assert . equal ( cardRoomGb ( PCS . two . cards ), 24 ); 62assert . equal ( cardRoomGb ([]), 0 ); 63assert . equal ( cardRoomGb ( undefined ), 0 ); 64}); 65 66test ( 'the Models page and the first-run page give the label the card room, not the shared pool' , () => { 67const read = f => readFileSync ( resolve ( root , 'src' , f ), 'utf8' ); 68const models = read ( 'components/NativeModels.tsx' ); 69assert . match ( models , / cardRoomGb\(pcGpu \? \[pcGpu\] : \[\]\) / ); 70assert . match ( models , / versionFit\(selectedSize, labelHardware, / ); 71assert . match ( models , / hardware=\{labelHardware\} / ); 72assert . match ( read ( 'components/GuidedSetup.tsx' ), / vram_gb: cardRoomGb\( / ); 73}); 74 75test ( 'the This computer card follows the same rule: on Strix Halo Q8_0 now says part is read from the SSD, as the label does' , () => { 76const q8 = { model :'Q8_0' , experts_gb :128.3 , fit_gb :133.8 }; 77const now = fitOn ( q8 , { ram_gb :63.6 , vram_gb :cardRoomGb ( PCS . strix . cards ) }, true , { context :131072 , kv :'int8' }); 78const before = fitOn ( q8 , { ram_gb :63.6 , vram_gb :95.8 }, true , { context :131072 , kv :'int8' }); 79assert . ok ( now . spillGb > 0 , 'some of it from the SSD: ' + JSON . stringify ( now )); 80assert . equal ( before . spillGb , 0 , 'the shared pool counted twice said it all fits' ); 81assert . ok ( now . vramUseGb + now . ramUseGb <= 63.6 + 64 , 'never more than the memory there is' ); 82const models = readFileSync ( resolve ( root , 'src/components/NativeModels.tsx' ), 'utf8' ); 83assert . match ( models , / fit=\{selectedSize \? fitOn\(selectedSize, labelHardware, / ); 84assert . match ( models , / vram_gb: cardRoomGb\(\[card \?\? pcGpu\] / ); 85});