okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fefaa985c
main
1/** 2* Qwen3.6-35B-A3B's context against the card (GitHub #5715). The app's estimate and its warning under the context chooser use the catalog's figures from 3* strata_control/own_path_fit.py, the rule setup's context menu uses; the Flash-Next int8 formula said 1.9 GB at 128K where the engine allocates 5.8, so a 4* 12 GB card got no warning and the engine stopped with a bare out-of-memory line. This test runs the Python rule and the app's on the same cards and needs 5* 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 load = async ( f , deps = {}) => { 17let src = readFileSync ( resolve ( root , f ), 'utf8' ); 18for ( const [ from , to ] of Object . entries ( deps )) src = src . replace ( from , to ); 19const { code} = await transform ( src , { loader :'ts' , format :'esm' }); 20return import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 21}; 22const fit = await load ( 'src/lib/native-fit.ts' ); 23const fitUrl = `data:text/javascript;base64, ${ Buffer . from (( await transform ( readFileSync ( resolve ( root , 'src/lib/native-fit.ts' ), 'utf8' ), { loader : 'ts' , format : 'esm' })). code ). toString ( 'base64' )} ` ; 24const ctx = await load ( 'src/lib/default-context.ts' , { "'./native-fit'" :`' ${ fitUrl } '` }); 25 26const SIZES = [ 'UD-Q4_K_XL' , 'UD-Q6_K_XL' , 'Q8_0' ]; 27const CARDS = [ 8 , 10 , 11.94 , 12 , 15.93 , 16 , 23.99 , 32 ]; 28const CONTEXTS = [ 8192 , 32768 , 49152 , 65536 , 100000 , 131072 , 204800 , 262144 ]; 29 30function python () { 31for ( const exe of process . platform === 'win32' ?[ 'python' , 'py' ] :[ 'python3' , 'python' ]) { 32const r = spawnSync ( exe , [ '--version' ], { encoding :'utf8' }); 33if ( r . status === 0 ) return exe ; 34} 35return null ; 36} 37 38test ( 'the design catalog has Qwen3.6\'s conversation memory per token' , () => { 39const src = readFileSync ( resolve ( root , 'server/catalog.mjs' ), 'utf8' ); 40const kb = Number ( / id:'qwen36' [ ^ \n ] * kvKbPerToken: ( \d + ) / . exec ( src )?.[ 1 ]); 41assert . equal ( kb , Math . round ( 47104 / 1024 )); 42}); 43 44test ( 'the app\'s Qwen3.6 context rule is own_path_fit.py\'s on 8 to 32 GB cards' , { skip :! python () && 'no python here' }, () => { 45const script = 'import json,sys; sys.path.insert(0, sys.argv[1]); from strata_control import own_path_fit as F; ' 46+ 'sizes=json.loads(sys.argv[2]); cards=json.loads(sys.argv[3]); ctxs=json.loads(sys.argv[4]); ' 47+ 'out={m: {"in": F.inputs("qwen3.6-35b-a3b", m), "fits": [[F.fits(F.inputs("qwen3.6-35b-a3b", m), v, c) for c in ctxs] for v in cards], ' 48+ '"cache": [round(F.cache_gib(c), 6) for c in ctxs]} for m in sizes}; print(json.dumps(out))' ; 49const r = spawnSync ( python (), [ '-I' , '-B' , '-c' , script , repo , JSON . stringify ( SIZES ), JSON . stringify ( CARDS ), JSON . stringify ( CONTEXTS )], { encoding :'utf8' }); 50assert . equal ( r . status , 0 , r . stderr ); 51const py = JSON . parse ( r . stdout ); 52for ( const m of SIZES ) { 53const f = py [ m ]. in ; 54assert . ok ( f && f . bytes_per_token === 47104 , m ); 55CARDS . forEach (( v , i ) => CONTEXTS . forEach (( c , j ) => { 56assert . equal ( fit . ownPathFits ( f , v , c ), py [ m ]. fits [ i ][ j ], ` ${ m } ${ v } GB ${ c } ` ); 57assert . equal ( ctx . contextIsTight ( v , c , 'int8' , f ), ! py [ m ]. fits [ i ][ j ], ` ${ m } ${ v } GB ${ c } : the warning` ); 58})); 59CONTEXTS . forEach (( c , j ) => assert . ok ( Math . abs ( fit . contextCacheGb ( c , 'int8' , f ) - py [ m ]. cache [ j ]) < 1e-5 , ` ${ c } ` )); 60} 61}); 62 63test ( '#5715: an RTX 5070 at 128K gets the warning with the real figure; 32K none; other models keep the Flash-Next rule' , () => { 64const q4 = { bytes_per_token :47104 , fixed_gb :8.55 + 1256 / 1024 + 0.07e9 / 2 ** 30 }; 65assert . equal ( ctx . contextIsTight ( 11.94 , 131072 , 'int8' , q4 ), true ); 66assert . equal ( fit . contextCacheGb ( 131072 , 'int8' , q4 ). toFixed ( 1 ), '5.8' ); 67assert . equal ( ctx . contextIsTight ( 11.94 , 32768 , 'int8' , q4 ), false ); 68assert . equal ( ctx . contextIsTight ( 0 , 131072 , 'int8' , q4 ), false ); // no card known: nothing said 69// before: the Flash-Next int8 figure (1.9 GB at 128K) left "room" on the 12 GB card, so nothing was said 70assert . equal ( fit . cacheGb ( 131072 ). toFixed ( 1 ), '1.9' ); 71assert . equal ( ctx . contextIsTight ( 11.94 , 131072 , 'int8' ), false ); 72assert . equal ( ctx . contextIsTight ( 11.94 , 131072 , 'int8' , null ), false ); 73// the This computer card counts the real cache for Qwen3.6 74const v = { experts_gb :2 , context_fit :q4 }; 75const a = fit . fitOn ( v , { ram_gb :64 , vram_gb :32 }, false , { context :131072 , kv :'int8' }); 76const b = fit . fitOn ({ experts_gb :2 }, { ram_gb :64 , vram_gb :32 }, false , { context :131072 , kv :'int8' }); 77assert . ok ( a . vramUseGb > b . vramUseGb , JSON . stringify ([ a , b ])); 78}); 79 80test ( 'the Models page and the first-run page pass the catalog\'s figures to the warning' , () => { 81const read = f => readFileSync ( resolve ( root , 'src' , f ), 'utf8' ); 82assert . match ( read ( 'components/NativeModels.tsx' ), / contextIsTight\(fitHardware\.vram_gb, context, kv, selectedSize\?\.context_fit\) / ); 83assert . match ( read ( 'components/NativeModels.tsx' ), / contextCacheGb\(context, kv, selectedSize\?\.context_fit\) / ); 84assert . match ( read ( 'components/GuidedSetup.tsx' ), / contextIsTight\(topCardGb, context, 'int8', version\?\.context_fit\) / ); 85assert . match ( read ( 'components/GuidedSetup.tsx' ), / contextCacheGb\(context, 'int8', version\?\.context_fit\) / ); 86});