okami.mom/strata

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

Niko1221Tests that pinned old values follow the merged decisions: native-fit (MTP layer 1.08 GB), tune-outcome (calm running step, GUI feedback 2 item 3), setup tests (128K default context on every card; the picture-file host in strata_control/pictures.py is behind acquisition.require)c0380157d

main
7.0 KiB97 linesraw
1/** Items 10 and 11: what a version needs of RAM + VRAM (without the n-gram table) and how much would be read from the SSD. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { readFile } from 'node:fs/promises';
5import { transform } from 'esbuild';
6
7const { code } = await transform(await readFile(new URL('../src/lib/native-fit.ts', import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' });
8const { fitOn, cacheGb, memoryNeeded, RECOMMENDED, VERSION_GROUPS, groupOpen, recommendedVersions, PICK_NOTE, OTHER_NOTE, MTP_VRAM_GB } = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
9
10const swift = { ram_needed_gb: 48, experts_gb: 35.5 };
11const gyroS = { ram_needed_gb: 27.6, experts_gb: 25.8, mem_total: true };
12const q4 = { ram_needed_gb: 48, experts_gb: 77 };
13
14test('the memory a version needs is RAM + VRAM without the n-gram table', () => {
15  assert.equal(memoryNeeded(swift), 36.5, 'experts plus about 1 GB for the dense part');
16  assert.equal(memoryNeeded(gyroS), 27.6, 'Gyro states its total');
17  assert.equal(memoryNeeded({ ...swift, memory_gb: 36.5 }), 36.5, 'the catalog figure wins when it is sent');
18});
19
20test('a PC with room reads nothing from the SSD', () => {
21  const f = fitOn(swift, { ram_gb: 64, vram_gb: 12 });
22  assert.equal(f.known, true); assert.equal(f.spillGb, 0);
23  assert.ok(f.vramUseGb > 0 && f.vramUseGb <= 12 && f.ramUseGb > 0 && f.ramUseGb <= 54);
24});
25
26test('a PC without room reads the rest from the SSD, and the amount is real', () => {
27  const f = fitOn(q4, { ram_gb: 64, vram_gb: 12 });          // 77 GB of experts: 6 on the card (the draft layer takes 1.08 GB), 54 in RAM, 17.1 from the SSD
28  assert.equal(f.spillGb, 17.1);
29  assert.equal(fitOn(q4, { ram_gb: 64, vram_gb: 12 }, false).spillGb, 16, 'with the draft layer off the card holds 1 GB more');
30  assert.equal(fitOn(q4, { ram_gb: 192, vram_gb: 24 }).spillGb, 0);
31  assert.ok(fitOn(gyroS, { ram_gb: 16, vram_gb: 8 }).spillGb > 10, 'a small PC spills a lot');
32});
33
34test('unknown hardware gives no verdict instead of a made-up one', () => {
35  const f = fitOn(swift, null);
36  assert.equal(f.known, false); assert.equal(f.spillGb, 0); assert.equal(f.memoryGb, 36.5);
37  assert.equal(fitOn(swift, { ram_gb: 0 }).known, false);
38});
39
40test('Recommended is the fixed four, in the owner\'s order; the groups are Swift, GSQ-RCO, NVFP4, Gyro (Unsloth for the rest)', () => {
41  assert.deepEqual(RECOMMENDED.map(r => `${r.family}:${r.model}`), ['gyro:Gyro-S', 'swift:IQ2_XS', 'qwen:IQ3_S', 'unsloth:UD-Q4_K_XL']);
42  assert.deepEqual(VERSION_GROUPS.map(g => g.title), ['Swift models', 'GSQ-RCO models', 'NVFP4 models', 'Gyro models', 'Unsloth models']);
43  assert.ok(RECOMMENDED.every(r => r.note.length > 0 && r.note.length < 40), 'one short note each');
44});
45
46test('the group of the running version can be collapsed (Gyro-M running, the Gyro group stayed open)', () => {
47  let opened = {};
48  assert.equal(groupOpen(opened, 'gyro', true), true, 'it starts open: it holds the selected version');
49  assert.equal(groupOpen(opened, 'swift', false), false, 'the others start closed');
50  opened = { ...opened, gyro: !groupOpen(opened, 'gyro', true) };   // the person clicks the Gyro header
51  assert.equal(groupOpen(opened, 'gyro', true), false, 'one click closes it');
52  opened = { ...opened, gyro: !groupOpen(opened, 'gyro', true) };
53  assert.equal(groupOpen(opened, 'gyro', true), true, 'and one more opens it again');
54});
55
56test('the draft layer (MTP) counts about 1 GB of the card', () => {
57  assert.equal(MTP_VRAM_GB, 1.08);   // the engine's measured 1,082 MiB (strata_control/drafting.py DRAFTER_MIB)
58  const on = fitOn(swift, { ram_gb: 40, vram_gb: 12 }), off = fitOn(swift, { ram_gb: 40, vram_gb: 12 }, false);
59  assert.equal(Math.round((on.vramUseGb - off.vramUseGb) * 10) / 10, 0, 'the card is full either way here; the experts it cannot hold move to RAM');
60  assert.equal(Math.round((on.ramUseGb - off.ramUseGb) * 10) / 10, 1.1);
61  assert.equal(fitOn(swift, { ram_gb: 40, vram_gb: 0 }).vramUseGb, 0, 'no card, no draft layer on it');
62});
63
64const v = (sourceFamily, model) => ({ sourceFamily, model, id: sourceFamily + '-' + model });
65const all = [v('qwen', 'Q2_0'), v('gyro', 'Gyro-S'), v('gyro', 'Gyro-M'), v('swift', 'IQ2_XS'), v('qwen', 'IQ3_XXS'), v('qwen', 'IQ3_S'), v('unsloth', 'UD-Q4_K_XL')];
66
67test('the page shows the own pick of the engine for this PC first (the same one strata launch prints), per memory tier', () => {
68  const names = rows => rows.map(x => x.v.model + (x.r.note === PICK_NOTE ? '*' : x.r.note === OTHER_NOTE ? '+' : ''));
69  assert.deepEqual(names(recommendedVersions(all)), ['Gyro-S', 'IQ2_XS', 'IQ3_S', 'UD-Q4_K_XL'], 'no pick: the fixed list');
70  const t40 = { family: 'swift', model: 'IQ2_XS', why: '40 GB tier: Swift 1.5 IQ2_XS; Gyro-M (35 GB) is the other choice there' };
71  assert.deepEqual(names(recommendedVersions(all, t40)), ['IQ2_XS*', 'Gyro-M+', 'Gyro-S', 'IQ3_S', 'UD-Q4_K_XL']);
72  assert.deepEqual(names(recommendedVersions(all, { family: 'swift', model: 'IQ2_XS', why: 'the 40 GB tier' })), ['IQ2_XS*', 'Gyro-S', 'IQ3_S', 'UD-Q4_K_XL'], 'no Gyro-M when the engine does not name it (Intel, Mac)');
73  assert.deepEqual(names(recommendedVersions(all, { family: 'qwen', model: 'IQ3_XXS', why: '48 GB tier' })), ['IQ3_XXS*', 'Gyro-S', 'IQ2_XS', 'IQ3_S', 'UD-Q4_K_XL']);
74  assert.deepEqual(names(recommendedVersions(all, { family: 'qwen', model: 'IQ3_S', why: '64 GB tier' })), ['IQ3_S*', 'Gyro-S', 'IQ2_XS', 'UD-Q4_K_XL']);
75  assert.deepEqual(names(recommendedVersions(all, { family: null, model: null })), ['Gyro-S', 'IQ2_XS', 'IQ3_S', 'UD-Q4_K_XL']);
76});
77
78test('the tiers of the engine are 40 GB Swift IQ2_XS, 48 GB IQ3_XXS, 64 GB IQ3_S in both Python places the page and strata launch read', async () => {
79  for (const file of ['../../../setup.py', '../../../tools/strata_mcp.py']) {
80    const text = await readFile(new URL(file, import.meta.url), 'utf8');
81    const m = /^MEMORY_TIERS\s*=\s*(.*)$/m.exec(text);
82    assert.ok(m, file);
83    assert.deepEqual([...m[1].matchAll(/\(([\d.]+),\s*"(\w+)",\s*"(\w+)"\)/g)].map(x => [Number(x[1]), x[2], x[3]]), [[62, 'qwen', 'IQ3_S'], [46, 'qwen', 'IQ3_XXS'], [38, 'swift', 'IQ2_XS']], file);
84  }
85});
86
87test('the conversation context and cache format move the estimate (#3832)', () => {
88  const pc = { ram_gb: 64, vram_gb: 16 };
89  const base = fitOn(swift, pc);
90  assert.deepEqual(fitOn(swift, pc, true, { context: 32768, kv: 'int8' }), base, 'the default context is what the fixed figure already held');
91  const big = fitOn(swift, pc, true, { context: 524288, kv: 'int8' });
92  assert.ok(big.vramUseGb >= base.vramUseGb && big.ramUseGb > base.ramUseGb, 'a bigger cache takes graphics memory from the experts, which then sit in RAM');
93  assert.ok(fitOn(swift, pc, true, { context: 524288, kv: 'q4_0' }).ramUseGb < big.ramUseGb, 'a smaller cache format leaves more room');
94  assert.ok(Math.abs(cacheGb(524288, 'int8') * 1024 - 7361) < 25, 'the 512K Int8 cache is the 7361 MiB the engine reports');
95  const tight = fitOn(q4, pc, true, { context: 524288, kv: 'int8' });
96  assert.ok(tight.spillGb > fitOn(q4, pc).spillGb, 'what no longer fits is read from the SSD and the card says so');
97});