okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main (87dfca0e7) into f-own-int: the 0.2.14 app branch, fixtures and CI fixes, the Qwen4-readiness tools, the shape-engine build scriptsffb3d9b31

main
5.0 KiB85 linesraw
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
21  strix: { 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
23  apu: { ram: 32, cards: [{ name: 'iGPU', uma: true, vram_gb: 16 }] },
24  // RTX 5070 12 GB, 64 GB RAM (the owner PC)
25  rtx12: { ram: 63.9, cards: [{ name: 'RTX 5070', vram_gb: 11.9 }] },
26  // two cards: the larger counts
27  two: { ram: 32, cards: [{ name: 'A', vram_gb: 8 }, { name: 'B', vram_gb: 24 }] },
28  nocard: { 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() {
34  for (const exe of process.platform === 'win32' ? ['python', 'py'] : ['python3', 'python']) {
35    const r = spawnSync(exe, ['--version'], { encoding: 'utf8' });
36    if (r.status === 0) return exe;
37  }
38  return 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' }, () => {
42  const exe = python();
43  const 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()}))';
45  const r = spawnSync(exe, ['-I', '-B', '-c', script, repo, JSON.stringify(PCS), JSON.stringify(SIZES)], { encoding: 'utf8' });
46  assert.equal(r.status, 0, r.stderr);
47  const control = JSON.parse(r.stdout);
48  for (const [name, pc] of Object.entries(PCS)) {
49    const hw = { ram_gb: pc.ram, vram_gb: cardRoomGb(pc.cards) };
50    const app = SIZES.map(size => versionFit({ fit_gb: size, memory_gb: size }, hw) === 'fits' ? 'fits' : 'may run slower');
51    assert.deepEqual(app, control[name], name);
52  }
53  assert.equal(control.strix[SIZES.indexOf(133.8)], 'may run slower', 'Strix Q8_0: may run slower');
54  assert.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', () => {
58  assert.equal(cardRoomGb(PCS.strix.cards), 64);
59  assert.equal(cardRoomGb(PCS.apu.cards), 0);
60  assert.equal(cardRoomGb(PCS.rtx12.cards), 11.9);
61  assert.equal(cardRoomGb(PCS.two.cards), 24);
62  assert.equal(cardRoomGb([]), 0);
63  assert.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', () => {
67  const read = f => readFileSync(resolve(root, 'src', f), 'utf8');
68  const models = read('components/NativeModels.tsx');
69  assert.match(models, /cardRoomGb\(pcGpu \? \[pcGpu\] : \[\]\)/);
70  assert.match(models, /versionFit\(selectedSize, labelHardware,/);
71  assert.match(models, /hardware=\{labelHardware\}/);
72  assert.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', () => {
76  const q8 = { model: 'Q8_0', experts_gb: 128.3, fit_gb: 133.8 };
77  const now = fitOn(q8, { ram_gb: 63.6, vram_gb: cardRoomGb(PCS.strix.cards) }, true, { context: 131072, kv: 'int8' });
78  const before = fitOn(q8, { ram_gb: 63.6, vram_gb: 95.8 }, true, { context: 131072, kv: 'int8' });
79  assert.ok(now.spillGb > 0, 'some of it from the SSD: ' + JSON.stringify(now));
80  assert.equal(before.spillGb, 0, 'the shared pool counted twice said it all fits');
81  assert.ok(now.vramUseGb + now.ramUseGb <= 63.6 + 64, 'never more than the memory there is');
82  const models = readFileSync(resolve(root, 'src/components/NativeModels.tsx'), 'utf8');
83  assert.match(models, /fit=\{selectedSize \? fitOn\(selectedSize, labelHardware,/);
84  assert.match(models, /vram_gb: cardRoomGb\(\[card \?\? pcGpu\]/);
85});