File size: 2,391 Bytes
bc50ea0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node

import assert from "node:assert/strict";
import {readFile} from "node:fs/promises";
import {
    LORA_ROUTE_LETTERS,
    availableLoRARoutes,
    connectedLoRARoutes,
    loraInputRoute,
    loraRouteLabel,
    nextLoRARoute,
} from "../web/h3_lora_scheduler_core.mjs";

const plan = {id: 1, type: "MiniMaxH3ChainPlan", inputs: []};
const current = {
    id: 2,
    type: "MiniMaxH3ChainCurrentShot",
    inputs: [{name: "state", link: 11}],
};
const scheduler = {
    id: 3,
    type: "MiniMaxH3ChainLoRAScheduler",
    inputs: [
        {name: "state", link: 12},
        {name: "base_model", link: 13},
        {name: "lora_a", link: 14},
        {name: "lora_b", link: null},
        {name: "lora_d", link: 15},
    ],
};
const unrelatedPlan = {id: 4, type: "MiniMaxH3ChainPlan", inputs: []};
const nodes = [plan, current, scheduler, unrelatedPlan];
const graph = {
    _nodes: nodes,
    links: {
        11: {origin_id: 1},
        12: {origin_id: 2},
        13: {origin_id: 20},
        14: {origin_id: 21},
        15: {origin_id: 22},
    },
    getNodeById(id) { return nodes.find((node) => node.id === id) ?? null; },
};
for (const node of nodes) node.graph = graph;

assert.equal(LORA_ROUTE_LETTERS.length, 26);
assert.equal(loraInputRoute("lora_z"), "z");
assert.equal(loraInputRoute("base_model"), null);
assert.deepEqual(connectedLoRARoutes(scheduler), ["a", "d"]);
assert.equal(nextLoRARoute(scheduler), "b");
assert.equal(loraRouteLabel("base"), "Base model");
assert.equal(loraRouteLabel("z"), "LoRA Z");
assert.deepEqual(availableLoRARoutes(graph, [plan]), ["base", "a", "d"]);
assert.deepEqual(
    availableLoRARoutes(graph, [plan], "z"),
    ["base", "a", "d", "z"],
);
assert.deepEqual(
    availableLoRARoutes(graph, [unrelatedPlan]),
    ["base"],
);

const frontend = await readFile(
    new URL("../web/h3_chain_lora_scheduler.js", import.meta.url), "utf8",
);
assert.match(frontend, /function stabilizeRouteInputs\(node\)/);
assert.match(frontend, /node\.removeInput\(index\)/);
assert.match(frontend, /node\.addInput\(`lora_\$\{next\}`, "MODEL"\)/);
assert.match(frontend, /Connect next LoRA route/);
assert.match(frontend, /h3-lora-routes-changed/);
assert.match(frontend, /onConnectionsChange/);
assert.match(frontend, /onGraphConfigured/);

console.log("H3 dynamic LoRA scheduler: progressive A-Z inputs and Plan route discovery pass");