Files
leleka/engine/strata/apps/host/tests/native-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

96 lines
4.8 KiB
JavaScript

/** GPU roles in the host: a load writes the roles and the legacy mirror (Main last), a file that names roles keeps them, every card Off is allowed. */
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { nativeFixture, finishJob } from './helpers/native-fixture.mjs';
const load = async (f, args) => { const done = await finishJob(f.control, f.control.operation('load', { model: 'iq2_xs', ...args }).id); return done; };
const written = (f, done) => JSON.parse(readFileSync(f.control.resolveInstance(done.result.instanceId).configPath, 'utf8'));
test('roles chosen in the screen: Helpers first, Main LAST, Off left out, and "gpu_roles" beside the mirror', async () => {
const f = nativeFixture();
try {
await f.control.refresh(true);
const done = await load(f, { gpuRoles: { 0: 'main', 1: 'helper' } });
assert.equal(done.state, 'done', done.error);
const cfg = written(f, done);
assert.deepEqual(cfg.gpu, [1, 0], 'card 0 is Main, so it is the last stage');
assert.equal(cfg.gpu_order, 'as_given');
assert.deepEqual(cfg.gpu_roles, { 0: 'main', 1: 'helper' });
assert.equal(cfg.layer_split, 'auto');
assert.deepEqual(f.control.resolveInstance(done.result.instanceId).gpus, [1, 0]);
await f.control.unload(done.result.instanceId);
const one = await load(f, { gpuRoles: { 0: 'off', 1: 'main' } });
assert.equal(one.state, 'done', one.error);
const c1 = written(f, one);
assert.equal(c1.gpu, 1, 'one card is a number, never a list');
assert.deepEqual(c1.gpu_roles, { 0: 'off', 1: 'main' });
} finally { await f.cleanup(); }
});
test('every card Off is allowed: no card in the list, "gpu_none" says it was meant', async () => {
const f = nativeFixture();
try {
await f.control.refresh(true);
const done = await load(f, { gpuRoles: { 0: 'off', 1: 'off' } });
assert.equal(done.state, 'done', done.error);
const cfg = written(f, done);
assert.deepEqual(cfg.gpu, []);
assert.equal(cfg.gpu_none, true);
} finally { await f.cleanup(); }
});
test('a settings file that names roles keeps them when the screen only suggests cards; a plain card list replaces them', async () => {
const f = nativeFixture();
try {
await f.control.refresh(true);
const path = join(f.repo, 'strata-iq2_xs.json');
const config = JSON.parse(readFileSync(path, 'utf8'));
Object.assign(config, { gpu: [0, 1], gpu_order: 'as_given', gpu_roles: { 0: 'helper', 1: 'main' } });
writeFileSync(path, JSON.stringify(config));
await f.control.refresh(true);
const kept = await load(f, { gpus: [1, 0], gpusFromRecommendation: true });
assert.equal(kept.state, 'done', kept.error);
assert.deepEqual(written(f, kept).gpu, [0, 1]);
await f.control.unload(kept.result.instanceId);
const picked = await load(f, { gpus: [1] });
assert.equal(picked.state, 'done', picked.error);
const cfg = written(f, picked);
assert.equal(cfg.gpu, 1);
assert.equal('gpu_roles' in cfg, false, 'a card list picked by hand replaces the roles');
} finally { await f.cleanup(); }
});
test('roles that make no sense are refused with a plain line', async () => {
const f = nativeFixture();
try {
await f.control.refresh(true);
const two = await load(f, { gpuRoles: { 0: 'main', 1: 'main' } });
assert.equal(two.state, 'error');
assert.match(two.error, /Main, Helper or Off/);
const nope = await load(f, { gpuRoles: { 5: 'main' } });
assert.equal(nope.state, 'error');
assert.match(nope.error, /detected graphics cards/);
} finally { await f.cleanup(); }
});
test('"Tune this model" keeps a two-card role map exactly as the person set it, in the file and in the engine it starts (#3655)', async () => {
const f = nativeFixture();
try {
await f.control.refresh(true);
const path = join(f.repo, 'strata-iq2_xs.json');
const config = JSON.parse(readFileSync(path, 'utf8'));
Object.assign(config, { gpu: [0, 1], gpu_order: 'as_given', gpu_roles: { 0: 'helper', 1: 'main' }, gpu_cards: { 0: 'GTX 1080', 1: 'GTX 1080' } });
writeFileSync(path, JSON.stringify(config));
await f.control.refresh(true);
const tuned = await finishJob(f.control, f.control.operation('tune', { model: 'iq2_xs', profile: 'performance', calibrate: false }).id);
assert.equal(tuned.state, 'done', tuned.error);
const after = JSON.parse(readFileSync(path, 'utf8'));
for (const key of ['gpu', 'gpu_order', 'gpu_roles', 'gpu_cards']) assert.deepEqual(after[key], config[key], `${key} in the settings file is untouched by Tune`);
const started = written(f, tuned);
assert.deepEqual(started.gpu, [0, 1], 'and the engine Tune loads runs on both cards');
assert.deepEqual(started.gpu_roles, { 0: 'helper', 1: 'main' });
} finally { await f.cleanup(); }
});