@flaxia/node 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/assets/ai-inference.js +83 -175
- package/dist/assets/ai-model-registry.js +127 -0
- package/dist/assets/cc-extract.js +5166 -0
- package/dist/assets/decision.js +142 -0
- package/dist/assets/embed-gemma.js +97 -0
- package/dist/assets/transformers.web.js +2 -2
- package/dist/assets/vector-embed.js +136 -26
- package/dist/assets/webgpuProbe.js +83 -66
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/light-preloader.d.ts +19 -5
- package/dist/client/light-preloader.d.ts.map +1 -1
- package/dist/consent/notice.d.ts +3 -1
- package/dist/consent/notice.d.ts.map +1 -1
- package/dist/executor/WorkerPool.d.ts +1 -0
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +392 -365
- package/dist/worker.js +130 -121
- package/dist/workloads/__tests__/ai-model-registry.test.d.ts +2 -0
- package/dist/workloads/__tests__/ai-model-registry.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/cc-extract.test.d.ts +2 -0
- package/dist/workloads/__tests__/cc-extract.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/decision.test.d.ts +2 -0
- package/dist/workloads/__tests__/decision.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/embed-gemma.test.d.ts +2 -0
- package/dist/workloads/__tests__/embed-gemma.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/wasm-threads.test.d.ts.map +1 -1
- package/dist/workloads/ai-inference.d.ts +30 -2
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/ai-model-registry.d.ts.map +1 -1
- package/dist/workloads/cc-extract.d.ts +11 -0
- package/dist/workloads/cc-extract.d.ts.map +1 -0
- package/dist/workloads/decision.d.ts +21 -0
- package/dist/workloads/decision.d.ts.map +1 -0
- package/dist/workloads/embed-gemma.d.ts +8 -0
- package/dist/workloads/embed-gemma.d.ts.map +1 -0
- package/dist/workloads/vector-embed.d.ts +10 -0
- package/dist/workloads/vector-embed.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as e, J as t, V as n, X as r, Y as i, a, b as o, c as s, g as c, h as l, o as u, p as d, r as f, t as p, v as m, x as h, y as g, z as _ } from "./assets/webgpuProbe.js";
|
|
2
2
|
//#region src/executor/throttle.ts
|
|
3
3
|
function v(e) {
|
|
4
4
|
return new Promise((t) => setTimeout(t, e));
|
|
@@ -7,7 +7,7 @@ var y = 3e4, ee = 500, b = class extends Error {
|
|
|
7
7
|
constructor(e, t, n) {
|
|
8
8
|
super(`device is over its CPU budget (load ${e.toFixed(2)} > max ${t.toFixed(2)}) after waiting ${Math.round(n)}ms; task not started`), this.load = e, this.maxLoad = t, this.waitedMs = n, this.retryable = !0, this.name = "ThrottleBusyError";
|
|
9
9
|
}
|
|
10
|
-
},
|
|
10
|
+
}, te = class {
|
|
11
11
|
constructor(e = .15) {
|
|
12
12
|
this.windowStart = performance.now(), this.windowBusyMs = 0, this.lastLoad = 0, this.dutyStartedAt = null, this.maxLoad = Math.max(.05, Math.min(.3, e));
|
|
13
13
|
}
|
|
@@ -57,13 +57,13 @@ var y = 3e4, ee = 500, b = class extends Error {
|
|
|
57
57
|
get maxLoadValue() {
|
|
58
58
|
return this.maxLoad;
|
|
59
59
|
}
|
|
60
|
-
},
|
|
61
|
-
function
|
|
60
|
+
}, x = 4096;
|
|
61
|
+
function ne(e) {
|
|
62
62
|
let t = e.maxSeq;
|
|
63
|
-
return typeof t == "number" && Number.isInteger(t) && t > 0 ? t :
|
|
63
|
+
return typeof t == "number" && Number.isInteger(t) && t > 0 ? t : x;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
let { pos: r, tokens: i } = e.header, a =
|
|
65
|
+
function S(e, t, n) {
|
|
66
|
+
let { pos: r, tokens: i } = e.header, a = ne(t);
|
|
67
67
|
if (!Number.isInteger(i) || i < 1) return {
|
|
68
68
|
kind: "corrupt",
|
|
69
69
|
reason: `carried ${i} token columns`
|
|
@@ -95,15 +95,15 @@ function C(e, t, n) {
|
|
|
95
95
|
hidden: o
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
let
|
|
100
|
-
return
|
|
98
|
+
function re(e, t, n, r) {
|
|
99
|
+
let a = i(e);
|
|
100
|
+
return a ? a.header.pos !== t || a.header.requestId !== t ? { kind: "stale" } : S(a, n, r) : {
|
|
101
101
|
kind: "corrupt",
|
|
102
102
|
reason: "malformed frame header"
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
async function
|
|
106
|
-
let { engine: i, link: a, semantics: o, promptTokens: s, chainLength: c, maxNewTokens: l } =
|
|
105
|
+
async function C(n) {
|
|
106
|
+
let { engine: i, link: a, semantics: o, promptTokens: s, chainLength: c, maxNewTokens: l } = n;
|
|
107
107
|
if (s.length === 0) throw Error("swarm host requires at least one prompt token");
|
|
108
108
|
i.reset();
|
|
109
109
|
let u = null;
|
|
@@ -111,7 +111,7 @@ async function re(t) {
|
|
|
111
111
|
if (e(t)) return;
|
|
112
112
|
let n = u;
|
|
113
113
|
if (!n) return;
|
|
114
|
-
let r =
|
|
114
|
+
let r = re(t, n.pos, i, o);
|
|
115
115
|
if (r.kind !== "stale") {
|
|
116
116
|
if (u = null, r.kind === "corrupt") {
|
|
117
117
|
n.reject(/* @__PURE__ */ Error(`swarm hop failed: ${r.reason}`));
|
|
@@ -120,14 +120,14 @@ async function re(t) {
|
|
|
120
120
|
n.resolve(r.hidden);
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
|
-
let d = (e,
|
|
123
|
+
let d = (e, n) => c <= 1 ? Promise.resolve(e) : new Promise((r, i) => {
|
|
124
124
|
u = {
|
|
125
|
-
pos:
|
|
126
|
-
resolve:
|
|
125
|
+
pos: n,
|
|
126
|
+
resolve: r,
|
|
127
127
|
reject: i
|
|
128
|
-
}, a.send(
|
|
129
|
-
requestId:
|
|
130
|
-
pos:
|
|
128
|
+
}, a.send(t({
|
|
129
|
+
requestId: n,
|
|
130
|
+
pos: n,
|
|
131
131
|
tokens: 1
|
|
132
132
|
}, o.packHidden(e)));
|
|
133
133
|
}), f = async (e, t) => d(await i.embedRun(e, t), t), p = null;
|
|
@@ -137,36 +137,36 @@ async function re(t) {
|
|
|
137
137
|
}
|
|
138
138
|
if (!p) throw Error("swarm host produced no logits for the prompt");
|
|
139
139
|
let m = [], h = s.length, g = o.argmax(p);
|
|
140
|
-
for (; m.length < l && !(
|
|
140
|
+
for (; m.length < l && !(n.eosIds?.has(g) || (m.push(g), await n.onToken?.(g), m.length >= l));) {
|
|
141
141
|
let e = await f(g, h++);
|
|
142
142
|
p = await i.headFromHidden(e), g = o.argmax(p);
|
|
143
143
|
}
|
|
144
|
-
return c > 1 && a.send(
|
|
144
|
+
return c > 1 && a.send(r()), { tokens: m };
|
|
145
145
|
}
|
|
146
|
-
function ie(
|
|
147
|
-
let { engine:
|
|
148
|
-
return
|
|
149
|
-
let
|
|
150
|
-
|
|
151
|
-
if (!
|
|
152
|
-
if (e(
|
|
153
|
-
|
|
146
|
+
function ie(n) {
|
|
147
|
+
let { engine: r, link: a, semantics: o } = n;
|
|
148
|
+
return r.reset(), new Promise((n, s) => {
|
|
149
|
+
let c = Promise.resolve(), l = !1;
|
|
150
|
+
a.onFrame((u) => {
|
|
151
|
+
if (!l) {
|
|
152
|
+
if (e(u)) {
|
|
153
|
+
l = !0, a.send(u), c = c.then(() => n());
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
let e =
|
|
156
|
+
c = c.then(async () => {
|
|
157
|
+
if (l) return;
|
|
158
|
+
let e = i(u);
|
|
159
159
|
if (!e) throw Error("swarm frame has a malformed frame header");
|
|
160
|
-
let
|
|
161
|
-
if (
|
|
162
|
-
let
|
|
163
|
-
|
|
160
|
+
let n = S(e, r, o);
|
|
161
|
+
if (n.kind === "corrupt") throw Error(`swarm frame is unusable: ${n.reason}`);
|
|
162
|
+
let s = await r.runHidden(n.hidden, e.header.pos);
|
|
163
|
+
a.send(t({
|
|
164
164
|
requestId: e.header.requestId,
|
|
165
165
|
pos: e.header.pos,
|
|
166
166
|
tokens: e.header.tokens
|
|
167
|
-
},
|
|
167
|
+
}, o.packHidden(s)));
|
|
168
168
|
}).catch((e) => {
|
|
169
|
-
|
|
169
|
+
l = !0, s(e instanceof Error ? e : Error(String(e)));
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
});
|
|
@@ -223,7 +223,7 @@ var ae = class {
|
|
|
223
223
|
if (!Number.isInteger(e.chainLength) || e.chainLength < 1 || e.chainLength > 16) throw Error(`swarm slice has an invalid chain length: ${JSON.stringify(e.chainLength)}`);
|
|
224
224
|
if (!Number.isInteger(e.index) || e.index < 0 || e.index >= e.chainLength) throw Error(`swarm slice has an invalid index: ${JSON.stringify(e.index)}`);
|
|
225
225
|
if (e.role !== (e.index === 0 ? "host" : "worker")) throw Error(`swarm slice role ${e.role} does not match index ${e.index}`);
|
|
226
|
-
if (!
|
|
226
|
+
if (!s(e.slice)) throw Error(`swarm slice is out of bounds: ${JSON.stringify(e.slice)}`);
|
|
227
227
|
let t = e.index === 0;
|
|
228
228
|
if (e.slice.hasEmbed !== t || e.slice.hasHead !== t) throw Error("swarm slice embed/head ownership does not match the host position");
|
|
229
229
|
}
|
|
@@ -254,7 +254,7 @@ var ae = class {
|
|
|
254
254
|
let r = t.encodePrompt(this.prompt), i = e.maxSeq ?? 4096;
|
|
255
255
|
if (r.length + n > i) throw Error(`swarm request needs ${r.length + n} tokens but the model context holds ${i}`);
|
|
256
256
|
this.generationStarted = !0;
|
|
257
|
-
let a = performance.now(), { tokens: o } = await
|
|
257
|
+
let a = performance.now(), { tokens: o } = await C({
|
|
258
258
|
chainLength: this.chainLength,
|
|
259
259
|
promptTokens: r,
|
|
260
260
|
maxNewTokens: n,
|
|
@@ -325,8 +325,8 @@ var w = class extends Error {
|
|
|
325
325
|
super(e), this.name = "SwarmEngineUnavailableError";
|
|
326
326
|
}
|
|
327
327
|
};
|
|
328
|
-
async function
|
|
329
|
-
if (!(await
|
|
328
|
+
async function T(e, t) {
|
|
329
|
+
if (!(await p()).webgpu) throw new w("WebGPU is not available in this context");
|
|
330
330
|
let n = t ?? ((e) => import(
|
|
331
331
|
/* @vite-ignore */
|
|
332
332
|
e
|
|
@@ -340,7 +340,7 @@ async function se(e, t) {
|
|
|
340
340
|
if (!i || typeof i.create != "function") throw new w(`module at ${e} does not export Qwen35Engine.create`);
|
|
341
341
|
return r;
|
|
342
342
|
}
|
|
343
|
-
function
|
|
343
|
+
function se(e, t, n, r) {
|
|
344
344
|
let i = !1, a = async (e) => {
|
|
345
345
|
r?.();
|
|
346
346
|
let t = await e();
|
|
@@ -495,7 +495,7 @@ async function pe() {
|
|
|
495
495
|
maxStorageBufferBindingSize: t.limits.maxStorageBufferBindingSize
|
|
496
496
|
} });
|
|
497
497
|
}
|
|
498
|
-
function
|
|
498
|
+
function R(e, t) {
|
|
499
499
|
let n = t.vocab, r = n["<|im_start|>"], i = n["<|im_end|>"], a = n["<think>"], o = n["</think>"], s = (e) => [
|
|
500
500
|
r,
|
|
501
501
|
...t.encode("user\n" + e),
|
|
@@ -525,36 +525,36 @@ function me(e, t) {
|
|
|
525
525
|
eosIds: new Set(c)
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
|
-
function
|
|
529
|
-
let t = null,
|
|
528
|
+
function z(e) {
|
|
529
|
+
let t = null, r = null, i = () => {
|
|
530
530
|
if (!t) {
|
|
531
531
|
let n = new URL("./swarm-engine.js", "" + import.meta.url).href;
|
|
532
|
-
t = e ? e() :
|
|
532
|
+
t = e ? e() : T(n).then((e) => e);
|
|
533
533
|
}
|
|
534
534
|
return t;
|
|
535
|
-
},
|
|
536
|
-
let t = await
|
|
537
|
-
(!
|
|
538
|
-
url:
|
|
539
|
-
gguf: await fe(t,
|
|
535
|
+
}, a = async (e) => {
|
|
536
|
+
let t = await i(), n = M(e);
|
|
537
|
+
(!r || r.url !== n) && (r = {
|
|
538
|
+
url: n,
|
|
539
|
+
gguf: await fe(t, n)
|
|
540
540
|
});
|
|
541
|
-
let a = Number(
|
|
541
|
+
let a = Number(r.gguf.meta["qwen35.block_count"]) - Number(r.gguf.meta["qwen35.nextn_predict_layers"] || 0);
|
|
542
542
|
if (!Number.isInteger(a) || a < 1) throw new w(`model ${e} has no qwen35 trunk layers`);
|
|
543
543
|
return {
|
|
544
544
|
mod: t,
|
|
545
|
-
url:
|
|
546
|
-
gguf:
|
|
545
|
+
url: n,
|
|
546
|
+
gguf: r.gguf,
|
|
547
547
|
layers: a
|
|
548
548
|
};
|
|
549
549
|
};
|
|
550
550
|
return {
|
|
551
551
|
async plan(e, t) {
|
|
552
|
-
let { layers:
|
|
553
|
-
return
|
|
552
|
+
let { layers: r } = await a(t);
|
|
553
|
+
return n({
|
|
554
554
|
sessionId: "",
|
|
555
555
|
taskId: "",
|
|
556
556
|
model: t,
|
|
557
|
-
layers:
|
|
557
|
+
layers: r,
|
|
558
558
|
nodes: e.map((e) => ({
|
|
559
559
|
nodeId: e.nodeId,
|
|
560
560
|
capacity: e.capacity
|
|
@@ -569,9 +569,9 @@ function R(e) {
|
|
|
569
569
|
e.end
|
|
570
570
|
]);
|
|
571
571
|
k(n, A(t, e, "loading", 1));
|
|
572
|
-
let r,
|
|
572
|
+
let r, i = !1;
|
|
573
573
|
try {
|
|
574
|
-
let { mod: o, url: s, gguf: c } = await
|
|
574
|
+
let { mod: o, url: s, gguf: c } = await a(t);
|
|
575
575
|
r = await pe();
|
|
576
576
|
let l = null, u = r;
|
|
577
577
|
u.addEventListener?.("uncapturederror", () => {
|
|
@@ -581,7 +581,7 @@ function R(e) {
|
|
|
581
581
|
});
|
|
582
582
|
let d = () => {
|
|
583
583
|
if (l) throw new w(l);
|
|
584
|
-
}, f =
|
|
584
|
+
}, f = R(o, o.makeTokenizer(o.tokenizerFromGGUF(c.meta))), p = (e) => I(s, e.byteOffset, e.byteOffset + e.byteLength - 1);
|
|
585
585
|
c.streamEntry = (e) => o.streamEntryToGPU(r, e, (e) => L(s, e.byteOffset, e.byteOffset + e.byteLength - 1), { staging: 4 * 1024 * 1024 });
|
|
586
586
|
let m = await o.qwen35Weights(c, p, {
|
|
587
587
|
lo: e.start,
|
|
@@ -596,69 +596,69 @@ function R(e) {
|
|
|
596
596
|
hasEmbed: e.hasEmbed,
|
|
597
597
|
hasHead: e.hasHead,
|
|
598
598
|
vocab: h,
|
|
599
|
-
maxSeq: Math.min(
|
|
599
|
+
maxSeq: Math.min(x, Number(c.meta["qwen35.context_length"]) || 4096),
|
|
600
600
|
batchCols: 4,
|
|
601
601
|
weights: m
|
|
602
602
|
});
|
|
603
603
|
d();
|
|
604
|
-
let _ =
|
|
604
|
+
let _ = se(g, r, () => {
|
|
605
605
|
k(n, A(t, e, "evicting", 0)), queueMicrotask(() => O.delete(n));
|
|
606
606
|
}, d);
|
|
607
|
-
return
|
|
607
|
+
return i = !0, k(n, A(t, e, "ready", 1)), {
|
|
608
608
|
engine: _,
|
|
609
609
|
semantics: f,
|
|
610
610
|
warm: P > 0 && F === 0
|
|
611
611
|
};
|
|
612
|
-
} catch (
|
|
613
|
-
if (k(n, A(t, e, "failed", 0)), !
|
|
612
|
+
} catch (a) {
|
|
613
|
+
if (k(n, A(t, e, "failed", 0)), !i) try {
|
|
614
614
|
r?.destroy?.();
|
|
615
615
|
} catch {}
|
|
616
|
-
throw
|
|
616
|
+
throw a;
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
};
|
|
620
620
|
}
|
|
621
621
|
//#endregion
|
|
622
622
|
//#region src/swarm/messages.ts
|
|
623
|
-
function
|
|
624
|
-
return
|
|
623
|
+
function me(e) {
|
|
624
|
+
return _(e) || m(e) || o(e) || h(e) || d(e) || c(e);
|
|
625
625
|
}
|
|
626
|
-
function
|
|
626
|
+
function he(e) {
|
|
627
627
|
if (!e || typeof e != "object") return !1;
|
|
628
628
|
let t = e;
|
|
629
|
-
return t.type === "swarm-control" && typeof t.id == "string" &&
|
|
629
|
+
return t.type === "swarm-control" && typeof t.id == "string" && me(t.message);
|
|
630
630
|
}
|
|
631
631
|
//#endregion
|
|
632
632
|
//#region src/worker/main.worker.ts
|
|
633
|
-
var
|
|
634
|
-
function
|
|
635
|
-
|
|
636
|
-
let t =
|
|
633
|
+
var B = null, ge = y, _e = 1, V = 15e3, H = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Set(), W = /* @__PURE__ */ new Map();
|
|
634
|
+
function G(e) {
|
|
635
|
+
U.delete(e);
|
|
636
|
+
let t = W.get(e);
|
|
637
637
|
if (t) {
|
|
638
|
-
|
|
638
|
+
W.delete(e);
|
|
639
639
|
for (let e of t) e();
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
|
-
function
|
|
643
|
-
return
|
|
644
|
-
let n =
|
|
645
|
-
n.add(t),
|
|
642
|
+
function ve(e) {
|
|
643
|
+
return U.has(e) ? new Promise((t) => {
|
|
644
|
+
let n = W.get(e) ?? /* @__PURE__ */ new Set();
|
|
645
|
+
n.add(t), W.set(e, n);
|
|
646
646
|
}) : Promise.resolve();
|
|
647
647
|
}
|
|
648
|
-
var
|
|
649
|
-
async function
|
|
648
|
+
var K = null, q = null, J = null, ye = 6e4;
|
|
649
|
+
async function be() {
|
|
650
650
|
for (let e = 0;; e++) try {
|
|
651
|
-
await
|
|
651
|
+
await B.waitForSlot(ge);
|
|
652
652
|
return;
|
|
653
653
|
} catch (t) {
|
|
654
654
|
if (!(t instanceof b)) throw t;
|
|
655
|
-
if (e >=
|
|
656
|
-
console.warn(`[flaxia-node:worker] ${t.message}; cooling down ${
|
|
655
|
+
if (e >= _e) throw Error(`device CPU busy: ${t.message}; task not started, retry on an idle node (retryable)`);
|
|
656
|
+
console.warn(`[flaxia-node:worker] ${t.message}; cooling down ${V}ms before retrying`), await new Promise((e) => setTimeout(e, V));
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
|
-
function
|
|
659
|
+
function xe(e) {
|
|
660
660
|
let t = (t) => {
|
|
661
|
-
let n =
|
|
661
|
+
let n = H.get(e);
|
|
662
662
|
if (n !== void 0) throw Error(n);
|
|
663
663
|
self.postMessage({
|
|
664
664
|
id: e,
|
|
@@ -667,18 +667,18 @@ function Se(e) {
|
|
|
667
667
|
});
|
|
668
668
|
};
|
|
669
669
|
return async (n) => {
|
|
670
|
-
await
|
|
670
|
+
await ve(e), t(n), await B?.yieldIfOverloaded();
|
|
671
671
|
};
|
|
672
672
|
}
|
|
673
|
-
var
|
|
674
|
-
console.log(`[flaxia-node:worker] startup memory probe wasmMemoryBytes=${
|
|
675
|
-
function
|
|
676
|
-
return
|
|
673
|
+
var Y = u();
|
|
674
|
+
console.log(`[flaxia-node:worker] startup memory probe wasmMemoryBytes=${Y} capable=${Y >= f}`);
|
|
675
|
+
function Se() {
|
|
676
|
+
return a();
|
|
677
677
|
}
|
|
678
678
|
var X = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map();
|
|
679
679
|
Z.set("swarm-inference", j);
|
|
680
680
|
var Q = null;
|
|
681
|
-
function
|
|
681
|
+
function Ce() {
|
|
682
682
|
for (let e of X.values()) try {
|
|
683
683
|
e();
|
|
684
684
|
} catch {}
|
|
@@ -699,18 +699,21 @@ function $() {
|
|
|
699
699
|
entries: t
|
|
700
700
|
};
|
|
701
701
|
}
|
|
702
|
-
function
|
|
702
|
+
function we() {
|
|
703
703
|
Q && clearTimeout(Q), Q = setTimeout(() => {
|
|
704
|
-
Q = null,
|
|
705
|
-
},
|
|
704
|
+
Q = null, Ce();
|
|
705
|
+
}, ye);
|
|
706
706
|
}
|
|
707
|
-
async function
|
|
707
|
+
async function Te(e, t, n, r, i) {
|
|
708
708
|
switch (e) {
|
|
709
|
-
case "ai-inference":
|
|
710
|
-
let
|
|
711
|
-
|
|
709
|
+
case "ai-inference": {
|
|
710
|
+
let r = await import("./assets/ai-inference.js").then((e) => e.s);
|
|
711
|
+
X.set(e, r.releaseCache), Z.set(e, r.getModelCacheSnapshot);
|
|
712
|
+
let i = await import("./assets/decision.js");
|
|
713
|
+
return X.set("decision", i.releaseCache), await r.handleAiInference(t, n);
|
|
714
|
+
}
|
|
712
715
|
case "ai-preload": {
|
|
713
|
-
let e = await import("./assets/ai-inference.js").then((e) => e.
|
|
716
|
+
let e = await import("./assets/ai-inference.js").then((e) => e.s);
|
|
714
717
|
X.set("ai-inference", e.releaseCache), Z.set("ai-inference", e.getModelCacheSnapshot);
|
|
715
718
|
let n = t;
|
|
716
719
|
return await e.preloadAiModel(n), { preloaded: !0 };
|
|
@@ -729,14 +732,18 @@ async function Ee(e, t, n, r) {
|
|
|
729
732
|
case "nudenet":
|
|
730
733
|
let c = await import("./assets/nudenet.js");
|
|
731
734
|
return X.set(e, c.releaseCache), await c.handleNudeNet(t);
|
|
735
|
+
case "cc-extract": return await (await import("./assets/cc-extract.js")).handleCcExtract(t, r?.ccRangeOrigins ?? []);
|
|
736
|
+
case "embed-gemma":
|
|
737
|
+
let l = await import("./assets/embed-gemma.js");
|
|
738
|
+
return X.set(e, l.releaseCache), await l.handleEmbedGemma(t, i);
|
|
732
739
|
default: throw Error(`Unknown workload type: ${e}`);
|
|
733
740
|
}
|
|
734
741
|
}
|
|
735
|
-
function
|
|
742
|
+
function Ee(e, t, n) {
|
|
736
743
|
return new Promise((r, i) => {
|
|
737
744
|
let a = new ae({
|
|
738
745
|
initial: t,
|
|
739
|
-
runtime:
|
|
746
|
+
runtime: z(),
|
|
740
747
|
sendControl: (t) => self.postMessage({
|
|
741
748
|
id: e,
|
|
742
749
|
type: "swarm-message",
|
|
@@ -749,70 +756,72 @@ function De(e, t, n) {
|
|
|
749
756
|
}, [t]),
|
|
750
757
|
emitToken: n,
|
|
751
758
|
onDone: (e) => {
|
|
752
|
-
|
|
759
|
+
K === a && (K = null, q = null), r(e);
|
|
753
760
|
},
|
|
754
761
|
onError: (e) => {
|
|
755
|
-
|
|
762
|
+
K === a && (K = null, q = null), i(Error(e));
|
|
756
763
|
}
|
|
757
764
|
});
|
|
758
|
-
|
|
765
|
+
K = a, q = e, a.start();
|
|
759
766
|
});
|
|
760
767
|
}
|
|
761
768
|
self.onmessage = async (e) => {
|
|
762
769
|
let t = e.data;
|
|
763
770
|
if (t?.type === "token-flow") {
|
|
764
771
|
let e = typeof t.id == "string" ? t.id : "";
|
|
765
|
-
e &&
|
|
772
|
+
e && J === e && typeof t.paused == "boolean" && (t.paused ? U.add(e) : G(e));
|
|
766
773
|
return;
|
|
767
774
|
}
|
|
768
775
|
if (t?.type === "swarm-control") {
|
|
769
|
-
if (!
|
|
776
|
+
if (!he(t)) {
|
|
770
777
|
console.warn("[flaxia-node:worker] dropped malformed swarm-control message");
|
|
771
778
|
return;
|
|
772
779
|
}
|
|
773
|
-
|
|
780
|
+
K && K.handleControl(t.message);
|
|
774
781
|
return;
|
|
775
782
|
}
|
|
776
783
|
if (t?.type === "swarm-frame") {
|
|
777
|
-
t.frame instanceof ArrayBuffer ?
|
|
784
|
+
t.frame instanceof ArrayBuffer ? K?.handleFrame(t.frame) : console.warn("[flaxia-node:worker] dropped malformed swarm-frame message");
|
|
778
785
|
return;
|
|
779
786
|
}
|
|
780
787
|
if (t?.type === "abort") {
|
|
781
788
|
let e = t.id, n = typeof t.reason == "string" && t.reason ? t.reason : "aborted by the coordinator";
|
|
782
|
-
|
|
789
|
+
G(e), K && q === e ? K.abort(n) : J === e && H.set(e, n);
|
|
783
790
|
return;
|
|
784
791
|
}
|
|
785
792
|
let { id: n, workload: r, payload: i, config: a } = t, o = performance.now();
|
|
786
|
-
|
|
793
|
+
J = n, G(n);
|
|
787
794
|
try {
|
|
788
|
-
if (
|
|
789
|
-
|
|
790
|
-
await xe(), z.beginWork();
|
|
795
|
+
if (B ||= new te(a?.maxCpuLoad), console.log(`[flaxia-node:worker] task start id=${n} workload=${r}`), l.has(r) && !Se()) throw Error(`${r}: node incapable: insufficient WASM memory (${Y} bytes < ${f})`);
|
|
796
|
+
await be(), B.beginWork();
|
|
791
797
|
let e = setInterval(() => {
|
|
792
798
|
self.postMessage({
|
|
793
799
|
id: n,
|
|
794
800
|
type: "heartbeat",
|
|
795
|
-
cpuLoad:
|
|
801
|
+
cpuLoad: B?.lastMeasuredLoad ?? 0,
|
|
796
802
|
modelCache: $()
|
|
797
803
|
});
|
|
798
804
|
}, 1e4), t = performance.now();
|
|
799
805
|
try {
|
|
800
|
-
let e =
|
|
806
|
+
let e = xe(n), t = Array.isArray(a?.fileSourceOrigins) ? a.fileSourceOrigins.filter((e) => typeof e == "string") : [], s = Array.isArray(a?.containerImageOrigins) ? a.containerImageOrigins.filter((e) => typeof e == "string") : [], c = Array.isArray(a?.ccRangeOrigins) ? a.ccRangeOrigins.filter((e) => typeof e == "string") : [], l = r === "swarm-inference" ? await Ee(n, i, e) : await Te(r, i, e, {
|
|
801
807
|
fileSourceOrigins: t,
|
|
802
|
-
containerImageOrigins: s
|
|
808
|
+
containerImageOrigins: s,
|
|
809
|
+
ccRangeOrigins: c
|
|
810
|
+
}, async () => {
|
|
811
|
+
await B?.yieldIfOverloaded();
|
|
803
812
|
});
|
|
804
813
|
self.postMessage({
|
|
805
814
|
id: n,
|
|
806
815
|
type: "done",
|
|
807
|
-
result:
|
|
816
|
+
result: l,
|
|
808
817
|
modelCache: $()
|
|
809
818
|
}), console.log(`[flaxia-node:worker] task done id=${n} workload=${r} durationMs=${Math.round(performance.now() - o)}`);
|
|
810
819
|
} finally {
|
|
811
|
-
|
|
820
|
+
J = null, H.delete(n), G(n), clearInterval(e), B.markTaskComplete(performance.now() - t), we();
|
|
812
821
|
}
|
|
813
822
|
} catch (e) {
|
|
814
823
|
let t = e instanceof Error ? e.message : String(e), i = e, a = typeof i?.code == "string" ? i.code : void 0, o = typeof i?.status == "number" ? i.status : void 0, s = typeof i?.detail == "string" ? i.detail : void 0;
|
|
815
|
-
console.error(`[flaxia-node:worker] task error id=${n} workload=${r} error=${t}`),
|
|
824
|
+
console.error(`[flaxia-node:worker] task error id=${n} workload=${r} error=${t}`), J === n && (J = null), G(n), self.postMessage({
|
|
816
825
|
id: n,
|
|
817
826
|
type: "error",
|
|
818
827
|
error: t,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-model-registry.test.d.ts","sourceRoot":"","sources":["../../../src/workloads/__tests__/ai-model-registry.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cc-extract.test.d.ts","sourceRoot":"","sources":["../../../src/workloads/__tests__/cc-extract.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision.test.d.ts","sourceRoot":"","sources":["../../../src/workloads/__tests__/decision.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed-gemma.test.d.ts","sourceRoot":"","sources":["../../../src/workloads/__tests__/embed-gemma.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-threads.test.d.ts","sourceRoot":"","sources":["../../../src/workloads/__tests__/wasm-threads.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wasm-threads.test.d.ts","sourceRoot":"","sources":["../../../src/workloads/__tests__/wasm-threads.test.ts"],"names":[],"mappings":"AAkCA,OAAO,iBAAiB,CAAC"}
|
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
import type { AiInferencePayload, AiInferenceResult } from '@flaxia/sdk';
|
|
2
|
-
import type { NodeModelCacheSnapshot } from '@flaxia/sdk';
|
|
2
|
+
import type { ModelCacheBackend, NodeModelCacheSnapshot } from '@flaxia/sdk';
|
|
3
3
|
export { DEFAULT_AI_MODEL_MAX_BYTES, MAX_AI_MODEL_MAX_BYTES, MAX_AI_INPUT_CHARS, MAX_AI_INPUT_ITEMS, ALLOWED_AI_DEVICES, ALLOWED_AI_DTYPES, listAiModels, registerAiModels, unregisterAiModel, type AiModelDefinition, } from './ai-model-registry';
|
|
4
4
|
/** Bound work queued behind TextStreamer's synchronous callback API. */
|
|
5
5
|
export declare const MAX_PENDING_TOKEN_CALLBACKS = 64;
|
|
6
6
|
export declare const MAX_PENDING_TOKEN_CHARS: number;
|
|
7
|
+
/**
|
|
8
|
+
* Full cache identity for one model pipeline. The executable cache is keyed
|
|
9
|
+
* by `task/modelId/revision/dtype/backend` (see `modelPipelineKey`), but the
|
|
10
|
+
* snapshot descriptor carries everything except `task`. Checking only
|
|
11
|
+
* `modelId` lets an `ondeviceOnly` task for the same repo with a different
|
|
12
|
+
* `dtype`/`backend` pass the gate and then miss the cache, downloading a
|
|
13
|
+
* second quantization despite the caller forbidding downloads.
|
|
14
|
+
*/
|
|
15
|
+
export interface AiModelCacheIdentity {
|
|
16
|
+
modelId: string;
|
|
17
|
+
revision: string;
|
|
18
|
+
dtype: string;
|
|
19
|
+
backend: ModelCacheBackend;
|
|
20
|
+
}
|
|
7
21
|
/**
|
|
8
22
|
* Whether the model already has a `ready` executable pipeline in memory.
|
|
9
23
|
* Guards `ondeviceOnly` tasks: they must fail before any download when the
|
|
10
24
|
* model is absent, so the check runs on the snapshot (no side effects).
|
|
25
|
+
*
|
|
26
|
+
* The string form is a model-only check kept for the public
|
|
27
|
+
* `FlaxiaNodeController.isAiModelPreloaded(model)` API and the Light
|
|
28
|
+
* Preloader dedup. The `ondeviceOnly` gate must use the identity form so a
|
|
29
|
+
* different `dtype`/`backend`/`revision` does not pass.
|
|
11
30
|
*/
|
|
12
|
-
export declare const isAiModelPreloaded: (model: string) => boolean;
|
|
31
|
+
export declare const isAiModelPreloaded: (model: string | AiModelCacheIdentity) => boolean;
|
|
13
32
|
/** Model preloaded by the Light Inference idle preloader (small enough for WASM). */
|
|
14
33
|
export declare const LIGHT_INFERENCE_TRANSLATE_MODEL = "Xenova/m2m100_418M";
|
|
15
34
|
export declare const LIGHT_INFERENCE_TRANSLATE_TASK = "translation";
|
|
16
35
|
export declare const LIGHT_INFERENCE_TRANSLATE_DTYPE = "q4f16";
|
|
36
|
+
/**
|
|
37
|
+
* Flaxia's default translate model. PLaMO 3 Translate 0.8B is a decoder-only
|
|
38
|
+
* text-generation model, so its Light Inference task is `text-generation`,
|
|
39
|
+
* not `translation`. Kept warm alongside M2M100 so the default en↔ja pairs
|
|
40
|
+
* serve instantly on device instead of answering ONDEVICE_UNAVAILABLE.
|
|
41
|
+
*/
|
|
42
|
+
export declare const LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL = "TeamFlaxia/plamo-3-translate-0.8b-onnx";
|
|
43
|
+
export declare const LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK = "text-generation";
|
|
44
|
+
export declare const LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE = "q4f16";
|
|
17
45
|
/**
|
|
18
46
|
* Drops all cached model pipelines so the (potentially hundreds of MB of)
|
|
19
47
|
* transformers/onnxruntime memory can be garbage-collected. Called by the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-inference.d.ts","sourceRoot":"","sources":["../../src/workloads/ai-inference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAsB,MAAM,aAAa,CAAC;AAC7F,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ai-inference.d.ts","sourceRoot":"","sources":["../../src/workloads/ai-inference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAsB,MAAM,aAAa,CAAC;AAC7F,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAgB7E,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAC;AAa7B,wEAAwE;AACxE,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAC9C,eAAO,MAAM,uBAAuB,QAAa,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,GAAG,oBAAoB,KAAG,OAezE,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,+BAA+B,uBAAuB,CAAC;AACpE,eAAO,MAAM,8BAA8B,gBAAgB,CAAC;AAC5D,eAAO,MAAM,+BAA+B,UAAU,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,qCAAqC,2CAA2C,CAAC;AAC9F,eAAO,MAAM,oCAAoC,oBAAoB,CAAC;AACtE,eAAO,MAAM,qCAAqC,UAAU,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAAO,IAE/B,CAAC;AAEF,4GAA4G;AAC5G,eAAO,MAAM,qBAAqB,QAAO,sBAAqD,CAAC;AAkH/F,eAAO,MAAM,iBAAiB,GAC5B,SAAS,kBAAkB,EAC3B,UAAU,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAChD,OAAO,CAAC,iBAAiB,CA0I3B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAU,SAAS;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,KAAG,OAAO,CAAC,IAAI,CA6Bf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model-registry.d.ts","sourceRoot":"","sources":["../../src/workloads/ai-model-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,QAAoB,CAAC;AAC5D,kDAAkD;AAClD,eAAO,MAAM,sBAAsB,QAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-model-registry.d.ts","sourceRoot":"","sources":["../../src/workloads/ai-model-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,8CAA8C;AAC9C,eAAO,MAAM,0BAA0B,QAAoB,CAAC;AAC5D,kDAAkD;AAClD,eAAO,MAAM,sBAAsB,QAAgB,CAAC;AAgEpD,sEAAsE;AACtE,eAAO,MAAM,kBAAkB,oCAAqC,CAAC;AACrE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,iDAAkD,CAAC;AACjF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAWhE,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,SAAU,CAAC;AAC1C,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,IAAI,CAkBrF;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAElD;AAED,sEAAsE;AACtE,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,CAWhE;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAQ5E;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAQzE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAM3D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAsB/D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,IAAI,CAyBN"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CcExtractPayload, type CcExtractResult } from '@flaxia/sdk';
|
|
2
|
+
/** Hard ceiling for a decompressed WARC record before parsing. */
|
|
3
|
+
export declare const MAX_CC_WARC_DECOMPRESSED_BYTES: number;
|
|
4
|
+
/** Hard ceiling for the HTTP response body inside a WARC record. */
|
|
5
|
+
export declare const MAX_CC_HTTP_BODY_BYTES: number;
|
|
6
|
+
/** Per-record network timeout. The whole task is also bounded by the payload. */
|
|
7
|
+
export declare const CC_RECORD_TIMEOUT_MS = 20000;
|
|
8
|
+
/** Identifies Flaxia Crowd to Common Crawl's data host. */
|
|
9
|
+
export declare const CC_USER_AGENT = "FlaxiaCrowd/0.7 (+https://flaxia.app/crowd)";
|
|
10
|
+
export declare function handleCcExtract(payload: CcExtractPayload, allowedOrigins?: readonly string[]): Promise<CcExtractResult>;
|
|
11
|
+
//# sourceMappingURL=cc-extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cc-extract.d.ts","sourceRoot":"","sources":["../../src/workloads/cc-extract.ts"],"names":[],"mappings":"AACA,OAAO,EAaL,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAErB,kEAAkE;AAClE,eAAO,MAAM,8BAA8B,QAAkB,CAAC;AAC9D,oEAAoE;AACpE,eAAO,MAAM,sBAAsB,QAAkB,CAAC;AACtD,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,2DAA2D;AAC3D,eAAO,MAAM,aAAa,gDAAgD,CAAC;AA2c3E,wBAAsB,eAAe,CACnC,OAAO,EAAE,gBAAgB,EACzB,cAAc,GAAE,SAAS,MAAM,EAAO,GACrC,OAAO,CAAC,eAAe,CAAC,CAwE1B"}
|