okami.mom/strata

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

Niko1221Two GTX 1080s are a working PC: an 8 GB card starts Off only beside a bigger card, and a PC whose only NVIDIA cards are Pascal uses them on the CUDA 12 engine (#3655)0351ecb11

main
4.8 KiB95 linesraw
1/** 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. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { readFileSync, writeFileSync } from 'node:fs';
5import { join } from 'node:path';
6import { nativeFixture, finishJob } from './helpers/native-fixture.mjs';
7
8const load = async (f, args) => { const done = await finishJob(f.control, f.control.operation('load', { model: 'iq2_xs', ...args }).id); return done; };
9const written = (f, done) => JSON.parse(readFileSync(f.control.resolveInstance(done.result.instanceId).configPath, 'utf8'));
10
11test('roles chosen in the screen: Helpers first, Main LAST, Off left out, and "gpu_roles" beside the mirror', async () => {
12  const f = nativeFixture();
13  try {
14    await f.control.refresh(true);
15    const done = await load(f, { gpuRoles: { 0: 'main', 1: 'helper' } });
16    assert.equal(done.state, 'done', done.error);
17    const cfg = written(f, done);
18    assert.deepEqual(cfg.gpu, [1, 0], 'card 0 is Main, so it is the last stage');
19    assert.equal(cfg.gpu_order, 'as_given');
20    assert.deepEqual(cfg.gpu_roles, { 0: 'main', 1: 'helper' });
21    assert.equal(cfg.layer_split, 'auto');
22    assert.deepEqual(f.control.resolveInstance(done.result.instanceId).gpus, [1, 0]);
23    await f.control.unload(done.result.instanceId);
24    const one = await load(f, { gpuRoles: { 0: 'off', 1: 'main' } });
25    assert.equal(one.state, 'done', one.error);
26    const c1 = written(f, one);
27    assert.equal(c1.gpu, 1, 'one card is a number, never a list');
28    assert.deepEqual(c1.gpu_roles, { 0: 'off', 1: 'main' });
29  } finally { await f.cleanup(); }
30});
31
32test('every card Off is allowed: no card in the list, "gpu_none" says it was meant', async () => {
33  const f = nativeFixture();
34  try {
35    await f.control.refresh(true);
36    const done = await load(f, { gpuRoles: { 0: 'off', 1: 'off' } });
37    assert.equal(done.state, 'done', done.error);
38    const cfg = written(f, done);
39    assert.deepEqual(cfg.gpu, []);
40    assert.equal(cfg.gpu_none, true);
41  } finally { await f.cleanup(); }
42});
43
44test('a settings file that names roles keeps them when the screen only suggests cards; a plain card list replaces them', async () => {
45  const f = nativeFixture();
46  try {
47    await f.control.refresh(true);
48    const path = join(f.repo, 'strata-iq2_xs.json');
49    const config = JSON.parse(readFileSync(path, 'utf8'));
50    Object.assign(config, { gpu: [0, 1], gpu_order: 'as_given', gpu_roles: { 0: 'helper', 1: 'main' } });
51    writeFileSync(path, JSON.stringify(config));
52    await f.control.refresh(true);
53    const kept = await load(f, { gpus: [1, 0], gpusFromRecommendation: true });
54    assert.equal(kept.state, 'done', kept.error);
55    assert.deepEqual(written(f, kept).gpu, [0, 1]);
56    await f.control.unload(kept.result.instanceId);
57    const picked = await load(f, { gpus: [1] });
58    assert.equal(picked.state, 'done', picked.error);
59    const cfg = written(f, picked);
60    assert.equal(cfg.gpu, 1);
61    assert.equal('gpu_roles' in cfg, false, 'a card list picked by hand replaces the roles');
62  } finally { await f.cleanup(); }
63});
64
65test('roles that make no sense are refused with a plain line', async () => {
66  const f = nativeFixture();
67  try {
68    await f.control.refresh(true);
69    const two = await load(f, { gpuRoles: { 0: 'main', 1: 'main' } });
70    assert.equal(two.state, 'error');
71    assert.match(two.error, /Main, Helper or Off/);
72    const nope = await load(f, { gpuRoles: { 5: 'main' } });
73    assert.equal(nope.state, 'error');
74    assert.match(nope.error, /detected graphics cards/);
75  } finally { await f.cleanup(); }
76});
77
78test('"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 () => {
79  const f = nativeFixture();
80  try {
81    await f.control.refresh(true);
82    const path = join(f.repo, 'strata-iq2_xs.json');
83    const config = JSON.parse(readFileSync(path, 'utf8'));
84    Object.assign(config, { gpu: [0, 1], gpu_order: 'as_given', gpu_roles: { 0: 'helper', 1: 'main' }, gpu_cards: { 0: 'GTX 1080', 1: 'GTX 1080' } });
85    writeFileSync(path, JSON.stringify(config));
86    await f.control.refresh(true);
87    const tuned = await finishJob(f.control, f.control.operation('tune', { model: 'iq2_xs', profile: 'performance', calibrate: false }).id);
88    assert.equal(tuned.state, 'done', tuned.error);
89    const after = JSON.parse(readFileSync(path, 'utf8'));
90    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`);
91    const started = written(f, tuned);
92    assert.deepEqual(started.gpu, [0, 1], 'and the engine Tune loads runs on both cards');
93    assert.deepEqual(started.gpu_roles, { 0: 'helper', 1: 'main' });
94  } finally { await f.cleanup(); }
95});