Files
leleka/engine/strata/apps/host/tests/gpu-roles.test.mjs
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

75 lines
4.2 KiB
JavaScript

/** GPU roles (Main / Helper / Off): src/lib/gpu-roles.ts and server/gpu-roles.mjs run the vectors strata_control/gpu_roles.py runs (tests/data/gpu_roles_vectors.json). */
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { transform } from 'esbuild';
const { code } = await transform(await readFile(new URL('../src/lib/gpu-roles.ts', import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' });
const R = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
const S = await import('../server/gpu-roles.mjs');
const V = JSON.parse(await readFile(new URL('../../../tests/data/gpu_roles_vectors.json', import.meta.url), 'utf8'));
const roles = d => d === null || d === undefined ? d : Object.fromEntries(Object.entries(d).map(([k, v]) => [Number(k), v]));
test('recommend: the best card is Main, others Helper, 8 GB or less / built-in / unusable start Off', () => {
for (const c of V.recommend) {
const r = R.recommend(V.hw[c.hw]);
assert.deepEqual(r.roles, roles(c.roles), c.hw);
assert.equal(r.main, c.main, c.hw);
assert.equal(r.why, c.why, c.hw);
}
});
test('setRole: one click, exactly one Main among the cards that are on', () => {
for (const c of V.set_role) {
const out = R.setRole(roles(c.roles), V.hw[c.hw], c.card, c.role);
assert.deepEqual(out.roles, roles(c.after), JSON.stringify(c));
assert.equal(out.note, c.note, JSON.stringify(c));
}
});
test('order: Helpers first, Main LAST, Off left out; one card is a number in the mirror', () => {
for (const c of V.order) {
assert.deepEqual(R.order(roles(c.roles), V.hw[c.hw]), c.gpu, JSON.stringify(c));
assert.deepEqual(S.order(roles(c.roles), V.hw[c.hw]), c.gpu, 'server copy: ' + JSON.stringify(c));
}
const m = R.mirror({ 0: 'off', 1: 'main' }, V.hw.two);
assert.equal(m.gpu, 1);
assert.equal(m.gpu_order, 'as_given');
assert.deepEqual(R.mirror({ 0: 'helper', 1: 'main' }, V.hw.two).gpu, [0, 1]);
const none = R.mirror({ 0: 'off', 1: 'off' }, V.hw.two);
assert.deepEqual([none.gpu, none.gpu_none], [[], true]);
assert.deepEqual(S.mirror({ 0: 'helper', 1: 'main' }, V.hw.two), R.mirror({ 0: 'helper', 1: 'main' }, V.hw.two));
assert.deepEqual(S.mirror({ 0: 'off', 1: 'off' }, V.hw.two), none);
});
test('warnings: only built-in graphics as Main, a card the engine cannot run, too little memory, CPU only', () => {
for (const c of V.warnings) {
const w = R.warnings(roles(c.roles), V.hw[c.hw], { spillGb: c.spill_gb ?? 0 });
assert.deepEqual(w.map(x => x.code), c.codes, JSON.stringify(c));
if (c.fix) assert.deepEqual(w[0].fix, c.fix);
for (const x of w) assert.ok(x.text.length < 90, x.text);
}
// a slower card as Main is understood by people: no warning
assert.deepEqual(R.warnings({ 0: 'main', 1: 'helper' }, V.hw.two), []);
assert.equal(R.warnings({ 0: 'off', 1: 'off' }, V.hw.two, { engineRunsCpuOnly: true })[0].text, 'Performance is degraded on CPU only.');
assert.equal(R.warnings({ 0: 'off', 1: 'off' }, V.hw.two)[0].text, R.NO_CARD_LINE);
});
test('legacy gpu settings show the roles the engine really uses', () => {
for (const c of V.legacy) assert.deepEqual(R.fromLegacy(c.gpu, V.hw[c.hw], c.gpu_order), roles(c.roles), JSON.stringify(c));
});
test('saved roles: parse; the server copy agrees on which are usable', () => {
assert.deepEqual(R.parseSaved({ 0: 'helper', 1: 'main' }), { 0: 'helper', 1: 'main' });
for (const bad of [{ 0: 'boss' }, { 0: 'main', 1: 'main' }, 'x', {}, null]) { assert.equal(R.parseSaved(bad), null); assert.equal(S.parseSaved(bad), null); }
});
test('words: the sentence and the one-line summary', () => {
assert.equal(R.sentence(V.hw.one), 'Strata will use your RTX 4070 Ti.');
assert.match(R.sentence(V.hw.three), /RTX 4070 Ti is Main: it is faster\./);
assert.match(R.sentence(V.hw.three), /RTX 2060 starts Off: 8 GB or less\./);
assert.equal(R.describe({ 0: 'helper', 1: 'main' }, V.hw.two), 'Main: GPU 2 RTX 4070 Ti. Helper: GPU 1 RTX 3060.');
assert.equal(R.noteText('old_main_helper:1', V.hw.two), 'RTX 4070 Ti is now a Helper.');
assert.equal(R.noteText('only_main', V.hw.two), 'The only card that is on has to be Main.');
});