@flaxia/node 0.5.0 → 0.6.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/dist/assets/ai-inference.js +288 -86
- package/dist/assets/transformers.web.js +2 -2
- package/dist/assets/vector-embed.js +1 -1
- package/dist/assets/webgpuProbe.js +365 -0
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/__tests__/light-preloader.test.d.ts +2 -0
- package/dist/client/__tests__/light-preloader.test.d.ts.map +1 -0
- package/dist/client/__tests__/mobile-lifecycle.test.d.ts +2 -0
- package/dist/client/__tests__/mobile-lifecycle.test.d.ts.map +1 -0
- package/dist/client/light-preloader.d.ts +47 -0
- package/dist/client/light-preloader.d.ts.map +1 -0
- package/dist/client/mobile-lifecycle.d.ts +20 -0
- package/dist/client/mobile-lifecycle.d.ts.map +1 -0
- package/dist/executor/WorkerPool.d.ts +7 -1
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/executor/__tests__/resourceReporter.test.d.ts +2 -0
- package/dist/executor/__tests__/resourceReporter.test.d.ts.map +1 -0
- package/dist/executor/memoryProbe.d.ts +5 -0
- package/dist/executor/memoryProbe.d.ts.map +1 -1
- package/dist/executor/resourceReporter.d.ts +15 -0
- package/dist/executor/resourceReporter.d.ts.map +1 -0
- package/dist/executor/webgpuProbe.d.ts +16 -5
- package/dist/executor/webgpuProbe.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1093 -354
- package/dist/swarm/__tests__/peer-quality.test.d.ts +2 -0
- package/dist/swarm/__tests__/peer-quality.test.d.ts.map +1 -0
- package/dist/swarm/__tests__/peer-transport.test.d.ts +2 -0
- package/dist/swarm/__tests__/peer-transport.test.d.ts.map +1 -0
- package/dist/swarm/adapter.d.ts +1 -1
- package/dist/swarm/adapter.d.ts.map +1 -1
- package/dist/swarm/controller.d.ts +4 -0
- package/dist/swarm/controller.d.ts.map +1 -1
- package/dist/swarm/messages.d.ts +2 -2
- package/dist/swarm/messages.d.ts.map +1 -1
- package/dist/swarm/peer-quality.d.ts +14 -0
- package/dist/swarm/peer-quality.d.ts.map +1 -0
- package/dist/swarm/peer-transport.d.ts +81 -0
- package/dist/swarm/peer-transport.d.ts.map +1 -0
- package/dist/swarm/runtime.d.ts +5 -1
- package/dist/swarm/runtime.d.ts.map +1 -1
- package/dist/swarm-engine.js +39 -20
- package/dist/worker.js +317 -185
- package/dist/workloads/__tests__/model-pipeline-cache.test.d.ts +2 -0
- package/dist/workloads/__tests__/model-pipeline-cache.test.d.ts.map +1 -0
- package/dist/workloads/ai-inference.d.ts +27 -0
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/ai-model-registry.d.ts +6 -0
- package/dist/workloads/ai-model-registry.d.ts.map +1 -1
- package/dist/workloads/model-pipeline-cache.d.ts +48 -0
- package/dist/workloads/model-pipeline-cache.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/assets/dist.js +0 -209
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as e } from "./chunk.js";
|
|
2
|
+
import { E as t, x as n } from "./webgpuProbe.js";
|
|
3
|
+
import { n as r, r as i, t as a } from "./transformers.web.js";
|
|
2
4
|
//#region src/workloads/ai-model-registry.ts
|
|
3
|
-
var
|
|
5
|
+
var o = 512 * 1024 * 1024, s = 4 * 1024 ** 3, c = new Map(Object.entries({
|
|
4
6
|
"Xenova/bert-base-multilingual-uncased-sentiment": {
|
|
5
7
|
repo: "Xenova/bert-base-multilingual-uncased-sentiment",
|
|
6
8
|
revision: "main",
|
|
7
|
-
maxBytes:
|
|
9
|
+
maxBytes: o
|
|
8
10
|
},
|
|
9
11
|
"onnx-community/Qwen3-Embedding-0.6B-ONNX": {
|
|
10
12
|
repo: "onnx-community/Qwen3-Embedding-0.6B-ONNX",
|
|
11
13
|
revision: "main",
|
|
12
|
-
maxBytes:
|
|
14
|
+
maxBytes: o
|
|
15
|
+
},
|
|
16
|
+
"Xenova/m2m100_418M": {
|
|
17
|
+
repo: "Xenova/m2m100_418M",
|
|
18
|
+
revision: "main",
|
|
19
|
+
maxBytes: o
|
|
13
20
|
}
|
|
14
|
-
}).map(([e, t]) => [e, { ...t }])),
|
|
21
|
+
}).map(([e, t]) => [e, { ...t }])), l = [
|
|
15
22
|
"wasm",
|
|
16
23
|
"cpu",
|
|
17
24
|
"webgpu"
|
|
18
|
-
],
|
|
25
|
+
], u = [
|
|
19
26
|
"q4",
|
|
20
27
|
"q4f16",
|
|
21
28
|
"q8",
|
|
22
29
|
"int8",
|
|
23
30
|
"uint8"
|
|
24
|
-
],
|
|
31
|
+
], d = {
|
|
25
32
|
max_new_tokens: {
|
|
26
33
|
min: 1,
|
|
27
34
|
max: 1024
|
|
@@ -42,45 +49,50 @@ var r = 512 * 1024 * 1024, i = 4 * 1024 ** 3, a = new Map(Object.entries({
|
|
|
42
49
|
min: 0,
|
|
43
50
|
max: 4
|
|
44
51
|
}
|
|
45
|
-
},
|
|
46
|
-
function
|
|
47
|
-
return [...
|
|
52
|
+
}, f = 1e5;
|
|
53
|
+
function p() {
|
|
54
|
+
return [...c.keys()];
|
|
48
55
|
}
|
|
49
|
-
function
|
|
56
|
+
function m(e) {
|
|
50
57
|
if (typeof e != "string" || !e) throw Error(`ai-inference: model must be a non-empty string, got ${JSON.stringify(e)}`);
|
|
51
|
-
let t =
|
|
52
|
-
if (!t) throw Error(`ai-inference: model not allowed: ${e} (allowed: ${
|
|
58
|
+
let t = c.get(e);
|
|
59
|
+
if (!t) throw Error(`ai-inference: model not allowed: ${e} (allowed: ${p().join(", ") || "none"})`);
|
|
53
60
|
return t;
|
|
54
61
|
}
|
|
55
|
-
function
|
|
62
|
+
function h(e) {
|
|
56
63
|
if (e != null) {
|
|
57
|
-
if (typeof e != "string" || !
|
|
64
|
+
if (typeof e != "string" || !l.includes(e)) throw Error(`ai-inference: device not allowed: ${JSON.stringify(e)} (allowed: ${l.join(", ")})`);
|
|
58
65
|
return e;
|
|
59
66
|
}
|
|
60
67
|
}
|
|
61
|
-
function
|
|
68
|
+
function g(e) {
|
|
62
69
|
if (e != null) {
|
|
63
|
-
if (typeof e != "string" || !
|
|
70
|
+
if (typeof e != "string" || !u.includes(e)) throw Error(`ai-inference: dtype not allowed: ${JSON.stringify(e)} (allowed: ${u.join(", ")})`);
|
|
64
71
|
return e;
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
|
-
function
|
|
74
|
+
function _(e) {
|
|
75
|
+
if (e == null) return !1;
|
|
76
|
+
if (typeof e != "boolean") throw Error(`ai-inference: option ondeviceOnly must be a boolean, got ${JSON.stringify(e)}`);
|
|
77
|
+
return e;
|
|
78
|
+
}
|
|
79
|
+
function v(e) {
|
|
68
80
|
if (typeof e == "string") {
|
|
69
|
-
if (e.length > 1e5) throw Error(`ai-inference: input exceeds ${
|
|
81
|
+
if (e.length > 1e5) throw Error(`ai-inference: input exceeds ${f} characters`);
|
|
70
82
|
return e;
|
|
71
83
|
}
|
|
72
84
|
if (Array.isArray(e)) {
|
|
73
85
|
if (e.length === 0 || e.length > 64) throw Error("ai-inference: input array must hold 1..64 items");
|
|
74
86
|
for (let t of e) {
|
|
75
87
|
if (typeof t != "string") throw Error("ai-inference: input array items must be strings");
|
|
76
|
-
if (t.length > 1e5) throw Error(`ai-inference: input exceeds ${
|
|
88
|
+
if (t.length > 1e5) throw Error(`ai-inference: input exceeds ${f} characters`);
|
|
77
89
|
}
|
|
78
90
|
return e;
|
|
79
91
|
}
|
|
80
92
|
throw Error("ai-inference: input must be a string or an array of strings");
|
|
81
93
|
}
|
|
82
|
-
function
|
|
83
|
-
for (let [n, r] of Object.entries(
|
|
94
|
+
function y(e, t) {
|
|
95
|
+
for (let [n, r] of Object.entries(d)) {
|
|
84
96
|
let i = t[n];
|
|
85
97
|
if (i != null) {
|
|
86
98
|
if (typeof i != "number" || !Number.isFinite(i) || i < r.min || i > r.max) throw Error(`ai-inference: option ${n} must be a number within ${r.min}..${r.max}, got ${JSON.stringify(i)}`);
|
|
@@ -99,9 +111,153 @@ function h(e, t) {
|
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
113
|
}
|
|
114
|
+
var b = class {
|
|
115
|
+
constructor(e = {}) {
|
|
116
|
+
this.options = e, this.entries = /* @__PURE__ */ new Map();
|
|
117
|
+
}
|
|
118
|
+
async acquire(e, t, r, i) {
|
|
119
|
+
let a = this.entries.get(e);
|
|
120
|
+
if (a?.state === "ready" && a.references === 0 && a.expiresAt <= this.now() && (await this.disposeEntry(a), a = this.entries.get(e)), a?.state === "failed" && (this.entries.delete(e), a = void 0), a || (await this.evictExpired(), a = this.entries.get(e), a)) return this.acquireEntry(a);
|
|
121
|
+
let o = Math.max(1, Math.floor(this.options.capacity ?? 2));
|
|
122
|
+
if (this.entries.size >= o && await this.makeRoom(), a = this.entries.get(e), a) return this.acquireEntry(a);
|
|
123
|
+
let s = this.now(), c = {
|
|
124
|
+
key: e,
|
|
125
|
+
descriptor: { ...t },
|
|
126
|
+
state: "loading",
|
|
127
|
+
references: 1,
|
|
128
|
+
updatedAt: s,
|
|
129
|
+
lastUsedAt: s,
|
|
130
|
+
expiresAt: s + this.ttlMs(),
|
|
131
|
+
promise: Promise.resolve(void 0),
|
|
132
|
+
dispose: i
|
|
133
|
+
};
|
|
134
|
+
this.entries.set(e, c), c.promise = (async () => {
|
|
135
|
+
try {
|
|
136
|
+
let e = await r();
|
|
137
|
+
return c.value = e.value, c.descriptor = {
|
|
138
|
+
...c.descriptor,
|
|
139
|
+
...e.descriptor
|
|
140
|
+
}, c.state === "loading" && (c.state = "ready"), c.updatedAt = this.now(), c.expiresAt = this.now() + this.ttlMs(), e.value;
|
|
141
|
+
} catch (e) {
|
|
142
|
+
throw c.state = "failed", c.updatedAt = this.now(), c.expiresAt = this.now() + Math.min(this.ttlMs(), n), e;
|
|
143
|
+
}
|
|
144
|
+
})();
|
|
145
|
+
try {
|
|
146
|
+
let e = await c.promise;
|
|
147
|
+
return this.createLease(c, e);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
throw c.references = Math.max(0, c.references - 1), e;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async acquireEntry(e) {
|
|
153
|
+
if (e.state === "failed") throw this.entries.delete(e.key), Error("model cache entry failed before it could be acquired");
|
|
154
|
+
if (e.state === "evicting") throw Error("model cache entry is being evicted");
|
|
155
|
+
e.references++, e.lastUsedAt = this.now(), e.expiresAt = this.now() + this.ttlMs();
|
|
156
|
+
try {
|
|
157
|
+
let t = await e.promise;
|
|
158
|
+
return this.createLease(e, t);
|
|
159
|
+
} catch (t) {
|
|
160
|
+
throw e.references = Math.max(0, e.references - 1), t;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
getSnapshot(e = this.now()) {
|
|
164
|
+
return {
|
|
165
|
+
version: 1,
|
|
166
|
+
sampledAt: e,
|
|
167
|
+
expiresAt: e + n,
|
|
168
|
+
entries: [...this.entries.values()].slice(0, 8).map((e) => ({
|
|
169
|
+
...e.descriptor,
|
|
170
|
+
state: e.state,
|
|
171
|
+
referenceCount: e.references
|
|
172
|
+
}))
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async releaseAll() {
|
|
176
|
+
let e = [];
|
|
177
|
+
for (let t of this.entries.values()) {
|
|
178
|
+
if (t.state === "failed") {
|
|
179
|
+
this.entries.delete(t.key);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
t.state = "evicting", t.updatedAt = this.now(), t.references === 0 && t.value !== void 0 && e.push(this.disposeEntry(t));
|
|
183
|
+
}
|
|
184
|
+
await Promise.all(e);
|
|
185
|
+
}
|
|
186
|
+
createLease(e, t) {
|
|
187
|
+
let n = !1;
|
|
188
|
+
return {
|
|
189
|
+
value: t,
|
|
190
|
+
updateDescriptor: (t) => {
|
|
191
|
+
n || (e.descriptor = {
|
|
192
|
+
...e.descriptor,
|
|
193
|
+
...t
|
|
194
|
+
}, e.updatedAt = this.now());
|
|
195
|
+
},
|
|
196
|
+
invalidate: () => {
|
|
197
|
+
n || (e.state = "evicting", e.updatedAt = this.now());
|
|
198
|
+
},
|
|
199
|
+
release: async () => {
|
|
200
|
+
n || (n = !0, e.references = Math.max(0, e.references - 1), e.lastUsedAt = this.now(), e.updatedAt = this.now(), e.references === 0 && e.state === "evicting" ? await this.disposeEntry(e) : e.references === 0 && e.state === "ready" && (e.expiresAt = this.now() + this.ttlMs()));
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
async evictExpired() {
|
|
205
|
+
let e = this.now();
|
|
206
|
+
for (let t of [...this.entries.values()]) t.state === "failed" && t.expiresAt <= e ? this.entries.delete(t.key) : t.state === "ready" && t.references === 0 && t.expiresAt <= e && await this.disposeEntry(t);
|
|
207
|
+
}
|
|
208
|
+
async makeRoom() {
|
|
209
|
+
let e = Math.max(1, Math.floor(this.options.capacity ?? 2));
|
|
210
|
+
for (; this.entries.size >= e;) {
|
|
211
|
+
let e = [...this.entries.values()].filter((e) => e.references === 0 && (e.state === "failed" || e.state === "ready")).sort((e, t) => Number(t.state === "failed") - Number(e.state === "failed") || e.lastUsedAt - t.lastUsedAt)[0];
|
|
212
|
+
if (!e) throw Error("model cache capacity is occupied by active entries");
|
|
213
|
+
e.state === "failed" ? this.entries.delete(e.key) : await this.disposeEntry(e);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async disposeEntry(e) {
|
|
217
|
+
if (e.references > 0 || e.state === "loading") return;
|
|
218
|
+
e.state = "evicting", e.updatedAt = this.now();
|
|
219
|
+
let t = e.value;
|
|
220
|
+
e.value = void 0;
|
|
221
|
+
try {
|
|
222
|
+
t !== void 0 && await e.dispose(t);
|
|
223
|
+
} finally {
|
|
224
|
+
this.entries.get(e.key) === e && this.entries.delete(e.key);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
now() {
|
|
228
|
+
return this.options.now?.() ?? Date.now();
|
|
229
|
+
}
|
|
230
|
+
ttlMs() {
|
|
231
|
+
return Math.max(1, this.options.ttlMs ?? 18e5);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
function x(e) {
|
|
235
|
+
return JSON.stringify([
|
|
236
|
+
e.task,
|
|
237
|
+
e.modelId,
|
|
238
|
+
e.revision,
|
|
239
|
+
e.dtype,
|
|
240
|
+
e.backend,
|
|
241
|
+
e.layerRange ?? null
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
102
244
|
//#endregion
|
|
103
245
|
//#region src/workloads/ai-inference.ts
|
|
104
|
-
var
|
|
246
|
+
var S = /* @__PURE__ */ e({
|
|
247
|
+
DEFAULT_AI_MODEL_MAX_BYTES: () => o,
|
|
248
|
+
LIGHT_INFERENCE_TRANSLATE_DTYPE: () => k,
|
|
249
|
+
LIGHT_INFERENCE_TRANSLATE_MODEL: () => D,
|
|
250
|
+
LIGHT_INFERENCE_TRANSLATE_TASK: () => O,
|
|
251
|
+
MAX_AI_INPUT_CHARS: () => f,
|
|
252
|
+
MAX_AI_INPUT_ITEMS: () => 64,
|
|
253
|
+
MAX_PENDING_TOKEN_CALLBACKS: () => 64,
|
|
254
|
+
MAX_PENDING_TOKEN_CHARS: () => T,
|
|
255
|
+
getModelCacheSnapshot: () => j,
|
|
256
|
+
handleAiInference: () => P,
|
|
257
|
+
isAiModelPreloaded: () => E,
|
|
258
|
+
preloadAiModel: () => F,
|
|
259
|
+
releaseCache: () => A
|
|
260
|
+
}), C = [
|
|
105
261
|
"text-classification",
|
|
106
262
|
"token-classification",
|
|
107
263
|
"question-answering",
|
|
@@ -127,90 +283,136 @@ var g = [
|
|
|
127
283
|
"depth-estimation",
|
|
128
284
|
"feature-extraction",
|
|
129
285
|
"image-feature-extraction"
|
|
130
|
-
],
|
|
131
|
-
|
|
132
|
-
},
|
|
133
|
-
let n = "", r = null, i = Promise.resolve(), a, o = !1,
|
|
134
|
-
|
|
135
|
-
|
|
286
|
+
], w = new b(), T = 256 * 1024, E = (e) => j().entries.some((t) => t.modelId === e && t.state === "ready"), D = "Xenova/m2m100_418M", O = "translation", k = "q4f16", A = () => {
|
|
287
|
+
w.releaseAll();
|
|
288
|
+
}, j = () => w.getSnapshot(), M = (e, t) => {
|
|
289
|
+
let n = "", r = null, i = Promise.resolve(), a = 0, o = 0, s, c = !1, l = !1, u = (t) => {
|
|
290
|
+
if (a >= 64 || o + t.length > 262144) throw c = !0, s = /* @__PURE__ */ Error("ai-inference token consumer is too slow; generation stopped at the bounded stream buffer"), s;
|
|
291
|
+
a++, o += t.length, i = i.then(() => {
|
|
292
|
+
if (!c) return e(t);
|
|
136
293
|
}).then(() => void 0, (e) => {
|
|
137
|
-
|
|
294
|
+
c = !0, s = e;
|
|
295
|
+
}).finally(() => {
|
|
296
|
+
a--, o -= t.length;
|
|
138
297
|
});
|
|
139
|
-
},
|
|
298
|
+
}, d = () => {
|
|
140
299
|
r !== null && clearTimeout(r), r = null;
|
|
141
300
|
let e = n;
|
|
142
|
-
n = "", e && !
|
|
143
|
-
},
|
|
144
|
-
if (!
|
|
145
|
-
if (
|
|
301
|
+
n = "", e && !c && u(e);
|
|
302
|
+
}, f = (e) => {
|
|
303
|
+
if (!l) {
|
|
304
|
+
if (c) throw s;
|
|
146
305
|
if (!t.tokenBuffer) {
|
|
147
|
-
|
|
306
|
+
u(e);
|
|
148
307
|
return;
|
|
149
308
|
}
|
|
150
|
-
n
|
|
309
|
+
if (n.length + e.length > 262144) throw c = !0, s = /* @__PURE__ */ Error("ai-inference token consumer is too slow; generation stopped at the bounded stream buffer"), s;
|
|
310
|
+
n += e, r === null && (r = setTimeout(() => {
|
|
311
|
+
try {
|
|
312
|
+
d();
|
|
313
|
+
} catch (e) {
|
|
314
|
+
c = !0, s = e;
|
|
315
|
+
}
|
|
316
|
+
}, t.tokenBufferIntervalMs ?? 50));
|
|
151
317
|
}
|
|
152
|
-
},
|
|
153
|
-
if (
|
|
318
|
+
}, p = async (e) => {
|
|
319
|
+
if (l = !0, r !== null && clearTimeout(r), r = null, e && !c ? d() : n = "", await i, c) throw s;
|
|
154
320
|
};
|
|
155
321
|
return {
|
|
156
|
-
callback:
|
|
157
|
-
finish: () =>
|
|
158
|
-
cancel: () =>
|
|
322
|
+
callback: f,
|
|
323
|
+
finish: () => p(!0),
|
|
324
|
+
cancel: () => p(!1)
|
|
159
325
|
};
|
|
160
326
|
};
|
|
161
|
-
function
|
|
327
|
+
function N() {
|
|
162
328
|
let e = globalThis.fetch.bind(globalThis);
|
|
163
|
-
|
|
329
|
+
r.fetch = async (t, n) => {
|
|
164
330
|
let r = new URL(String(t));
|
|
165
331
|
if (!/(^|\.)huggingface\.co$/.test(r.hostname) && !/(^|\.)hf\.co$/.test(r.hostname)) throw Error(`ai-inference: model download blocked from ${r.hostname}`);
|
|
166
|
-
let
|
|
167
|
-
if (Number.isFinite(
|
|
168
|
-
return
|
|
332
|
+
let i = await e(r, n), a = Number(i.headers.get("content-length"));
|
|
333
|
+
if (Number.isFinite(a) && a > s) throw Error(`ai-inference: model file too large (${a} bytes > ${s})`);
|
|
334
|
+
return i;
|
|
169
335
|
};
|
|
170
336
|
}
|
|
171
|
-
|
|
172
|
-
var
|
|
173
|
-
let { task:
|
|
174
|
-
if (!
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
let S =
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
337
|
+
N(), r.backends?.onnx?.wasm && (r.backends.onnx.wasm.numThreads = 1, r.backends.onnx.wasm.proxy = !1);
|
|
338
|
+
var P = async (e, n) => {
|
|
339
|
+
let { task: r, model: o, input: s, options: c = {} } = e;
|
|
340
|
+
if (!C.includes(r)) throw Error(`Invalid or unsupported task: ${r}. Supported tasks are: ${C.join(", ")}`);
|
|
341
|
+
let l = m(o), u = h(c.device), d = g(c.dtype), f = _(c.ondeviceOnly), p = v(s), b = {};
|
|
342
|
+
if (y(b, c), f && !E(o)) throw new t(`ondeviceOnly: model ${o} is not preloaded on this device`, "preloading");
|
|
343
|
+
let S = d ?? "q4f16", T = u ?? "wasm", D = x({
|
|
344
|
+
task: r,
|
|
345
|
+
modelId: o,
|
|
346
|
+
revision: l.revision,
|
|
347
|
+
dtype: S,
|
|
348
|
+
backend: T
|
|
349
|
+
}), O = performance.now(), k = await w.acquire(D, {
|
|
350
|
+
modelId: o,
|
|
351
|
+
revision: l.revision,
|
|
352
|
+
dtype: S,
|
|
353
|
+
backend: T
|
|
354
|
+
}, async () => {
|
|
183
355
|
let e = {
|
|
184
|
-
dtype:
|
|
185
|
-
device:
|
|
186
|
-
|
|
187
|
-
|
|
356
|
+
dtype: S,
|
|
357
|
+
device: u,
|
|
358
|
+
revision: l.revision
|
|
359
|
+
};
|
|
360
|
+
console.log(`[flaxia-node] ai-inference: loading pipeline task=${r} model=${l.repo} revision=${l.revision} dtype=${e.dtype} device=${u ?? "wasm"}`);
|
|
361
|
+
let t;
|
|
188
362
|
try {
|
|
189
|
-
|
|
190
|
-
} catch (
|
|
191
|
-
if (
|
|
192
|
-
else throw console.error(`[flaxia-node] ai-inference: pipeline load FAILED task=${
|
|
363
|
+
t = await i(r, l.repo, e);
|
|
364
|
+
} catch (n) {
|
|
365
|
+
if (u && u !== "wasm") console.warn(`[AiInference] ${u} failed, falling back to wasm:`, n), e.device = "wasm", t = await i(r, l.repo, e);
|
|
366
|
+
else throw console.error(`[flaxia-node] ai-inference: pipeline load FAILED task=${r} model=${l.repo} error=${n instanceof Error ? n.message : String(n)}`), n;
|
|
193
367
|
}
|
|
194
|
-
console.log(`[flaxia-node] ai-inference: pipeline ready task=${
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
};
|
|
200
|
-
for (let [e, t] of Object.entries(x)) e === "max_new_tokens" || e === "do_sample" || (w[e] = t);
|
|
201
|
-
let T = r && C.tokenizer ? b(r, s) : null;
|
|
202
|
-
T && (w.streamer = new e(C.tokenizer, {
|
|
203
|
-
skip_prompt: !0,
|
|
204
|
-
skip_special_tokens: !0,
|
|
205
|
-
callback_function: T.callback
|
|
206
|
-
}));
|
|
207
|
-
let E = performance.now(), D;
|
|
368
|
+
return console.log(`[flaxia-node] ai-inference: pipeline ready task=${r} model=${l.repo} loadMs=${Math.round(performance.now() - O)}`), {
|
|
369
|
+
value: t,
|
|
370
|
+
descriptor: { backend: e.device ?? "wasm" }
|
|
371
|
+
};
|
|
372
|
+
}, (e) => e.dispose?.()), A = k.value;
|
|
208
373
|
try {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
374
|
+
let e = {
|
|
375
|
+
max_new_tokens: b.max_new_tokens ?? 128,
|
|
376
|
+
do_sample: b.do_sample ?? !1
|
|
377
|
+
};
|
|
378
|
+
for (let [t, n] of Object.entries(b)) t === "max_new_tokens" || t === "do_sample" || (e[t] = n);
|
|
379
|
+
let t = n && A.tokenizer ? M(n, c) : null;
|
|
380
|
+
t && (e.streamer = new a(A.tokenizer, {
|
|
381
|
+
skip_prompt: !0,
|
|
382
|
+
skip_special_tokens: !0,
|
|
383
|
+
callback_function: t.callback
|
|
384
|
+
}));
|
|
385
|
+
let i = performance.now(), o;
|
|
386
|
+
try {
|
|
387
|
+
o = await A(p, e);
|
|
388
|
+
} catch (e) {
|
|
389
|
+
throw /out of memory|oom|allocation failed|could not allocate/i.test(e instanceof Error ? e.message : String(e)) && k.invalidate(), t && await t.cancel(), e;
|
|
390
|
+
}
|
|
391
|
+
return await t?.finish(), console.log(`[flaxia-node] ai-inference: done task=${r} model=${l.repo} execMs=${Math.round(performance.now() - i)} inputLen=${String(p).length}`), { output: o };
|
|
392
|
+
} finally {
|
|
393
|
+
await k.release();
|
|
212
394
|
}
|
|
213
|
-
|
|
395
|
+
}, F = async (e) => {
|
|
396
|
+
let { task: t, model: n } = e, r = m(n), a = h(e.device), o = g(e.dtype) ?? "q4f16", s = a ?? "wasm", c = x({
|
|
397
|
+
task: t,
|
|
398
|
+
modelId: n,
|
|
399
|
+
revision: r.revision,
|
|
400
|
+
dtype: o,
|
|
401
|
+
backend: s
|
|
402
|
+
});
|
|
403
|
+
await (await w.acquire(c, {
|
|
404
|
+
modelId: n,
|
|
405
|
+
revision: r.revision,
|
|
406
|
+
dtype: o,
|
|
407
|
+
backend: s
|
|
408
|
+
}, async () => (console.log(`[flaxia-node] ai-inference: preloading task=${t} model=${r.repo}`), {
|
|
409
|
+
value: await i(t, r.repo, {
|
|
410
|
+
dtype: o,
|
|
411
|
+
device: a,
|
|
412
|
+
revision: r.revision
|
|
413
|
+
}),
|
|
414
|
+
descriptor: { backend: s }
|
|
415
|
+
}), (e) => e.dispose?.())).release();
|
|
214
416
|
};
|
|
215
417
|
//#endregion
|
|
216
|
-
export { S as
|
|
418
|
+
export { E as a, S as i, D as n, F as o, O as r, k as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/assets/transformers.web.js
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 63528578 bytes
|
|
4
|
+
sha256: c4ea4c2cc11efabbcbd71ff8631ac3d08593a8cde1a4a2a64518ac81f837f4b0
|
|
@@ -7,7 +7,7 @@ async function n(t) {
|
|
|
7
7
|
if (!e) {
|
|
8
8
|
let t = performance.now();
|
|
9
9
|
console.log("[flaxia-node] vector-embed: loading pipeline model=onnx-community/Qwen3-Embedding-0.6B-ONNX device=wasm");
|
|
10
|
-
let { pipeline: n, env: r } = await import("./transformers.web.js");
|
|
10
|
+
let { pipeline: n, env: r } = await import("./transformers.web.js").then((e) => e.i);
|
|
11
11
|
r?.backends?.onnx?.wasm && (r.backends.onnx.wasm.numThreads = 1, r.backends.onnx.wasm.proxy = !1);
|
|
12
12
|
try {
|
|
13
13
|
e = await n("feature-extraction", "onnx-community/Qwen3-Embedding-0.6B-ONNX", { device: "wasm" });
|