okami.mom/strata

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

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
7.7 KiB113 linesraw
1/**
2 * The model's own choices outlive setup: "Draft layer (MTP)" off, picture reading off, a context size set by hand.
3 * Setup writes --mtp, --spec-min-p and --vision into the arguments every time it runs; the host applies the saved choices on every
4 * load. Nothing here starts an engine; Control is a fake that records what the host saved and asked it to start.
5 */
6import './helpers/isolate-profile.mjs';   // a test run never writes the owner's real Strata profile
7import test from 'node:test';
8import assert from 'node:assert/strict';
9import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
10import { join } from 'node:path';
11import { tmpdir } from 'node:os';
12import { createNativeControl } from '../server/native-control.mjs';
13import { withoutDraftLayer, NATIVE_FIELDS, APP_OWNED_FIELDS, validateNativeSettings } from '../server/native-settings.mjs';
14import { checkRunConfig } from '../server/run-config-check.mjs';
15
16const ARGS = ['--pack', '/p', '--expert-cache', 'auto', '--spec', '4', '--spec-min-p', '0.5', '--mtp', '/m/rt', '--max-context', '40000', '--kv', 'int8', '--vision'];
17
18function fixture(config = {}, { gpuGb = 12 } = {}) {
19  const root = mkdtempSync(join(tmpdir(), 'strata-draft-test-'));
20  const install = join(root, 'install'), data = join(root, 'data');
21  mkdirSync(install, { recursive: true });
22  process.env.STRATA_INSTALL_DIR = install;
23  const path = join(install, 'strata-q2_0.json');
24  writeFileSync(path, JSON.stringify({ exe: 'component:strata-engine', tokenizer: join(install, 'tok'), args: ARGS, model_name: 'Qwen q2_0', port: 8080, ...config }));
25  const saved = [];
26  const control = {
27    control: { dir: join(root, 'control') }, version: '0.2.0',
28    async installedModels() { return { install_dir: install, models: [{ id: 'q2_0', name: 'Qwen q2_0', source_config: path, component_status: 'present', context_tokens: 40000 }] }; },
29    async engine() { return { usable: true, backend: 'cuda', components_dir: 'E:\\c', engine: { version: '0.2.0', platform: 'windows-x86_64', backend: 'cuda', exe: 'E:\\e\\strata.exe', root: 'E:\\e' } }; },
30    async saveProfile(name, file) { saved.push(JSON.parse(readFileSync(file, 'utf8'))); return {}; },
31    async start() { return { ok: true, state: 'ready' }; },
32    async stop() { return { ok: true }; },
33  };
34  const native = createNativeControl({ control, hardwareProbe: () => [{ index: 0, vram_gb: gpuGb }], directory: data, spawnProcess: () => { throw new Error('no process'); }, fetcher: async () => Response.json({ status: 'ok' }), requests: () => [] });
35  return { native, saved, path, cleanup: () => rmSync(root, { recursive: true, force: true }) };
36}
37const finish = async (native, id) => { for (let i = 0; i < 500; i++) { const job = native.state().jobs.find(j => j.id === id); if (job.state !== 'running') return job; await new Promise(r => setTimeout(r, 10)); } throw new Error('job did not finish'); };
38const visionSection = { exe: 'E:\\e\\strata-vision.exe', mmproj: 'E:\\mm.gguf', model: 'E:\\m.gguf', gpu: false, max_tokens: 300 };
39
40test('withoutDraftLayer takes out --mtp, --spec-min-p and --batch-mtp and keeps --spec', () => {
41  assert.deepEqual(withoutDraftLayer(ARGS), ['--pack', '/p', '--expert-cache', 'auto', '--spec', '4', '--max-context', '40000', '--kv', 'int8', '--vision']);
42  assert.deepEqual(withoutDraftLayer(['--mtp', '2', '--spec', '2', '--batch-mtp']), ['--spec', '2'], 'Qwen3.6: a draft count');
43  assert.deepEqual(withoutDraftLayer(['--spec', '4', '--mtp']), ['--spec', '4'], 'a flag with no value at the end');
44  assert.deepEqual(withoutDraftLayer(['--mtp', '--spec', '4']), ['--spec', '4'], 'a flag whose next word is another flag');
45});
46
47test('"Draft layer (MTP)" is a setting of the app, not frozen, and "MTP per request" is not frozen either', async () => {
48  assert.ok(NATIVE_FIELDS.some(f => f.id === 'mtp' && f.type === 'boolean'));
49  assert.deepEqual(APP_OWNED_FIELDS.sort(), ['batchMtp', 'drafting', 'mtp']);
50  const f = fixture();
51  try {
52    await f.native.refresh(true);
53    for (const id of ['mtp', 'batchMtp', 'drafting']) assert.equal(f.native.state().fields.find(x => x.id === id).supported, true, `${id} must not be disabled`);
54    assert.deepEqual(validateNativeSettings({ mtp: false }), { mtp: false });
55    assert.equal(checkRunConfig(JSON.stringify({ exe: 'e', tokenizer: 't', args: [], mtp: false })).issues.length, 0, 'the file check knows the key');
56  } finally { await f.native.close(); f.cleanup(); }
57});
58
59test('saving "Draft layer" off keeps it in the model file, and every load starts without --mtp', async () => {
60  const f = fixture();
61  try {
62    await f.native.refresh(true);
63    f.native.save('q2_0', { values: { mtp: false } });
64    assert.equal(JSON.parse(readFileSync(f.path, 'utf8')).mtp, false);
65    // a setup run rewrites the arguments (here: the same text with --mtp back) and keeps the key; the load applies it
66    const job = await finish(f.native, f.native.operation('load', { model: 'q2_0', vision: 'no' }).id);
67    assert.equal(job.state, 'done', job.error);
68    const args = f.saved[0].args;
69    assert.ok(!args.includes('--mtp') && !args.includes('--spec-min-p') && !args.includes('--batch-mtp'), args.join(' '));
70    assert.equal(args[args.indexOf('--spec') + 1], '4', '--spec stays: prompt lookup still uses its windows');
71    assert.equal(args[args.indexOf('--max-context') + 1], '40000', 'a context set by hand is not touched');
72    // and back to the default: the key goes, the draft layer is in again
73    f.native.save('q2_0', { values: { mtp: null } });
74    assert.equal('mtp' in JSON.parse(readFileSync(f.path, 'utf8')), false);
75  } finally { await f.native.close(); f.cleanup(); }
76});
77
78test('the load with the draft layer off in its own values, and a retry, both keep it off', async () => {
79  const f = fixture();
80  try {
81    await f.native.refresh(true);
82    const job = await finish(f.native, f.native.operation('load', { model: 'q2_0', vision: 'no', values: { mtp: false } }).id);
83    assert.equal(job.state, 'done', job.error);
84    assert.ok(!f.saved[0].args.includes('--mtp'));
85    assert.ok(!f.saved[0].args.includes('--batch-mtp'), 'no draft layer, so no draft layer per request either, even on a big card');
86  } finally { await f.native.close(); f.cleanup(); }
87});
88
89test('picture reading off sticks: no vision section and no --vision on the engine, whatever setup wrote', async () => {
90  const f = fixture({ vision: visionSection, ui_vision_enabled: false, ui_vision_device: 'yes' });
91  try {
92    await f.native.refresh(true);
93    const job = await finish(f.native, f.native.operation('load', { model: 'q2_0' }).id);   // the screen sends nothing: the saved choice decides
94    assert.equal(job.state, 'done', job.error);
95    assert.equal(f.saved[0].vision, undefined);
96    assert.ok(!f.saved[0].args.includes('--vision'));
97    assert.equal(JSON.parse(readFileSync(f.path, 'utf8')).ui_vision_enabled, false, 'the choice stays saved');
98  } finally { await f.native.close(); f.cleanup(); }
99});
100
101test('picture reading on keeps --vision; the Models screen sees the prepared pictures instead of "off"', async () => {
102  const f = fixture({ vision: visionSection });
103  try {
104    await f.native.refresh(true);
105    assert.equal(f.native.state().installed.models[0].images, 'yes', 'prepared: the screen loads straight away, no setup run');
106    const job = await finish(f.native, f.native.operation('load', { model: 'q2_0' }).id);
107    assert.equal(job.state, 'done', job.error);
108    assert.ok(f.saved[0].args.includes('--vision'));
109    assert.ok(f.saved[0].vision);
110  } finally { await f.native.close(); f.cleanup(); }
111  const g = fixture();
112  try { await g.native.refresh(true); assert.equal(g.native.state().installed.models[0].images, 'off', 'no vision section: not prepared'); } finally { await g.native.close(); g.cleanup(); }
113});