@margoengine/compute 0.0.0-stage → 1.0.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.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +804 -2
  4. package/dist/array-C29noZq7.js +166 -0
  5. package/dist/array.d.ts +109 -0
  6. package/dist/autodiff.d.ts +22 -0
  7. package/dist/autodiff.js +143 -0
  8. package/dist/autotune.d.ts +100 -0
  9. package/dist/autotune.js +179 -0
  10. package/dist/compat-YK57ZCbA.js +4 -0
  11. package/dist/compat.d.ts +2 -0
  12. package/dist/context-CCvs3wkC.js +2479 -0
  13. package/dist/context.d.ts +376 -0
  14. package/dist/cpu-D4UQwJ9L.js +871 -0
  15. package/dist/cpu-kernel.wasm +0 -0
  16. package/dist/cpu-load-XFcM1TXj.js +5 -0
  17. package/dist/cpu-load.d.ts +3 -0
  18. package/dist/cpu-runtime.d.ts +8 -0
  19. package/dist/cpu-wasm.d.ts +42 -0
  20. package/dist/cpu-wasm.js +161 -0
  21. package/dist/cpu.d.ts +138 -0
  22. package/dist/decomp-kernel.wasm +0 -0
  23. package/dist/decomp.d.ts +42 -0
  24. package/dist/decomp.js +158 -0
  25. package/dist/distance.d.ts +85 -0
  26. package/dist/distance.js +256 -0
  27. package/dist/dtype.d.ts +36 -0
  28. package/dist/errors-CDgOgzCd.js +7 -0
  29. package/dist/expr-t3jm8acM.js +996 -0
  30. package/dist/expr.d.ts +196 -0
  31. package/dist/fft.d.ts +33 -0
  32. package/dist/fft.js +168 -0
  33. package/dist/frame.d.ts +76 -0
  34. package/dist/frame.js +85 -0
  35. package/dist/graph.d.ts +75 -0
  36. package/dist/graph.js +174 -0
  37. package/dist/histogram.d.ts +17 -0
  38. package/dist/index.d.ts +17 -0
  39. package/dist/index.js +4 -0
  40. package/dist/kernel.d.ts +65 -0
  41. package/dist/linalg.d.ts +21 -0
  42. package/dist/linalg.js +149 -0
  43. package/dist/nn-extra.d.ts +130 -0
  44. package/dist/nn-extra.js +322 -0
  45. package/dist/nn.d.ts +385 -0
  46. package/dist/nn.js +704 -0
  47. package/dist/onnx-image-D2qfYsXf.js +66 -0
  48. package/dist/onnx-image.d.ts +10 -0
  49. package/dist/onnx-kernel.wasm +0 -0
  50. package/dist/onnx-regex-DaesIdrm.js +331 -0
  51. package/dist/onnx-regex.d.ts +2 -0
  52. package/dist/onnx.d.ts +167 -0
  53. package/dist/onnx.js +885 -0
  54. package/dist/quant.d.ts +59 -0
  55. package/dist/quant.js +242 -0
  56. package/dist/random.d.ts +64 -0
  57. package/dist/random.js +150 -0
  58. package/dist/reduce.d.ts +34 -0
  59. package/dist/scan.d.ts +26 -0
  60. package/dist/select.d.ts +38 -0
  61. package/dist/shaders.d.ts +80 -0
  62. package/dist/shape.d.ts +23 -0
  63. package/dist/shape.js +134 -0
  64. package/dist/signal.d.ts +29 -0
  65. package/dist/signal.js +178 -0
  66. package/dist/sort.d.ts +38 -0
  67. package/dist/sparse.d.ts +136 -0
  68. package/dist/sparse.js +273 -0
  69. package/dist/stream.d.ts +39 -0
  70. package/dist/stream.js +100 -0
  71. package/dist/subgroups.d.ts +27 -0
  72. package/dist/subgroups.js +191 -0
  73. package/dist/usingCtx-igdMnAhr.js +57 -0
  74. package/dist/wgsl.d.ts +68 -0
  75. package/package.json +146 -4
@@ -0,0 +1,66 @@
1
+ //#region src/onnx-image.ts
2
+ async function e(e) {
3
+ let n = (...t) => t.every((t, n) => e[n] === t);
4
+ if (n(137, 80, 78, 71)) {
5
+ let { decodePNG: e } = await import("@margoengine/decoders/png");
6
+ return (t) => e(t);
7
+ }
8
+ if (n(255, 216, 255)) return (await import("@margoengine/decoders/jpeg")).decodeJPEG;
9
+ if (n(82, 73, 70, 70) && String.fromCharCode(...e.subarray(8, 12)) === "WEBP") return (await import("@margoengine/decoders/webp")).parseWebP;
10
+ if (n(66, 77)) return (await import("@margoengine/decoders/bmp")).parseBMP;
11
+ if (n(73, 73, 42, 0) || n(77, 77, 0, 42) || n(73, 73, 43, 0) || n(77, 77, 0, 43)) {
12
+ let [{ parseTIFF: n }, { loadTIFFCodecs: r }] = await Promise.all([import("@margoengine/decoders/tiff"), import("@margoengine/decoders/tiff-codecs")]), i = await r(e).catch((e) => {
13
+ if (t(e)) return {};
14
+ throw e;
15
+ });
16
+ return (e) => {
17
+ let t = n(e, { codecs: i });
18
+ if (t.format === "rgba8unorm") return t;
19
+ let r = Uint8Array.from(t.data, (e) => e > 0 ? Math.min(255, Math.round(e * 255)) : 0);
20
+ return {
21
+ width: t.width,
22
+ height: t.height,
23
+ data: r
24
+ };
25
+ };
26
+ }
27
+ if (e[0] === 80 && e[1] >= 49 && e[1] <= 54) return (await import("@margoengine/decoders/pnm")).parsePNM;
28
+ if (n(255, 79, 255, 81) || n(0, 0, 0, 12, 106, 80, 32, 32)) {
29
+ let { loadJPEG2000: e } = await import("@margoengine/decoders/jpeg2000"), t = await e();
30
+ return (e) => t(e);
31
+ }
32
+ }
33
+ function t(e) {
34
+ let t = e?.code;
35
+ return e instanceof RangeError || t === "failed" || t === "unsupported";
36
+ }
37
+ async function n(n, r) {
38
+ let i = r === "Grayscale" ? 1 : 3, a = {
39
+ data: /* @__PURE__ */ new Uint8Array(),
40
+ shape: [
41
+ 0,
42
+ 0,
43
+ i
44
+ ]
45
+ }, o = await e(n);
46
+ if (!o) return a;
47
+ let s;
48
+ try {
49
+ s = o(n);
50
+ } catch (e) {
51
+ if (t(e)) return a;
52
+ throw e;
53
+ }
54
+ let { width: c, height: l, data: u } = s, d = new Uint8Array(c * l * i), f = r === "BGR" ? 2 : 0;
55
+ for (let e = 0, t = 0; t < d.length; e += 4, t += i) i === 1 ? d[t] = (u[e] * 299 + u[e + 1] * 587 + u[e + 2] * 114 + 500) / 1e3 | 0 : (d[t] = u[e + f], d[t + 1] = u[e + 1], d[t + 2] = u[e + 2 - f]);
56
+ return {
57
+ data: d,
58
+ shape: [
59
+ l,
60
+ c,
61
+ i
62
+ ]
63
+ };
64
+ }
65
+ //#endregion
66
+ export { n as decodeImagePixels };
@@ -0,0 +1,10 @@
1
+ /** What ImageDecoder returns: bytes in height, width, channel order. */
2
+ export interface ImagePixels {
3
+ data: Uint8Array;
4
+ shape: [number, number, number];
5
+ }
6
+ /**
7
+ * Decodes one encoded image to `[height, width, 3]` (RGB or BGR) or `[height, width, 1]` (Grayscale) bytes, alpha
8
+ * dropped. A stream that cannot be decoded gives the empty matrix `[0, 0, channels]`, as the operator specifies.
9
+ */
10
+ export declare function decodeImagePixels(bytes: Uint8Array, format: string): Promise<ImagePixels>;
Binary file
@@ -0,0 +1,331 @@
1
+ import { r as e } from "./errors-CDgOgzCd.js";
2
+ //#region src/onnx-regex.ts
3
+ var t = 1e5, n = {
4
+ d: "09",
5
+ s: " \n\f\r ",
6
+ w: "09AZaz__"
7
+ }, r = {
8
+ alnum: "09AZaz",
9
+ alpha: "AZaz",
10
+ ascii: "\0",
11
+ blank: " ",
12
+ cntrl: "\0",
13
+ digit: "09",
14
+ graph: "!~",
15
+ lower: "az",
16
+ print: " ~",
17
+ punct: "!/:@[`{~",
18
+ space: " \r ",
19
+ upper: "AZ",
20
+ word: "09AZaz__",
21
+ xdigit: "09AFaf"
22
+ }, i = {
23
+ a: 7,
24
+ f: 12,
25
+ t: 9,
26
+ n: 10,
27
+ r: 13,
28
+ v: 11
29
+ }, a = (e) => `\\u{${e.toString(16)}}`;
30
+ function o(e, t, n) {
31
+ let r = RegExp(`^[${t ? "^" : ""}${e}]$`, n ? "iu" : "u");
32
+ return (e) => r.test(String.fromCodePoint(e));
33
+ }
34
+ function s(e) {
35
+ let t = "";
36
+ for (let n = 0; n < e.length; n += 2) t += `${a(e.charCodeAt(n))}-${a(e.charCodeAt(n + 1))}`;
37
+ return t;
38
+ }
39
+ var c = (e) => e >= 48 && e <= 57 || e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 95, l = class {
40
+ #e;
41
+ #t = 0;
42
+ #n = 0;
43
+ constructor(e) {
44
+ this.#e = Array.from(e);
45
+ }
46
+ fail(t) {
47
+ throw e(`ONNX RegexFullMatch pattern ${t} at character ${this.#t}; use RE2 syntax`, "compute");
48
+ }
49
+ #r(e = 0) {
50
+ return this.#e[this.#t + e];
51
+ }
52
+ #i() {
53
+ let e = this.#e[this.#t++];
54
+ return e === void 0 && this.fail("ends early"), e;
55
+ }
56
+ #a(e) {
57
+ return Array.from(e).every((e, t) => this.#r(t) === e) ? (this.#t += e.length, !0) : !1;
58
+ }
59
+ parse() {
60
+ let e = this.#o({
61
+ i: !1,
62
+ m: !1,
63
+ s: !1
64
+ });
65
+ return this.#t < this.#e.length && this.fail("has an unmatched )"), e;
66
+ }
67
+ #o(e) {
68
+ let t = { ...e }, n = [this.#s(t)];
69
+ for (; this.#a("|");) n.push(this.#s(t));
70
+ return n.length === 1 ? n[0] : {
71
+ op: "either",
72
+ items: n
73
+ };
74
+ }
75
+ #s(e) {
76
+ let t = [], n = !0;
77
+ for (; this.#r() !== void 0 && this.#r() !== "|" && this.#r() !== ")";) {
78
+ let r = this.#c();
79
+ if (r) {
80
+ let e = t.pop();
81
+ (!e || n) && this.fail("repeats nothing or repeats a repetition"), t.push({
82
+ op: "repeat",
83
+ item: e,
84
+ min: r[0],
85
+ max: r[1]
86
+ }), this.#a("?"), n = !0;
87
+ continue;
88
+ }
89
+ if (n = !1, this.#a("\\Q")) {
90
+ for (; this.#r() !== void 0 && !this.#a("\\E");) t.push(this.#l(this.#i().codePointAt(0), e));
91
+ continue;
92
+ }
93
+ let i = this.#u(e);
94
+ i ? t.push(i) : n = !0;
95
+ }
96
+ return {
97
+ op: "sequence",
98
+ items: t
99
+ };
100
+ }
101
+ #c() {
102
+ if (this.#a("*")) return [0, Infinity];
103
+ if (this.#a("+")) return [1, Infinity];
104
+ if (this.#a("?")) return [0, 1];
105
+ if (this.#r() !== "{") return null;
106
+ let e = /^\{(\d+)(,(\d*))?\}/.exec(this.#e.slice(this.#t, this.#t + 24).join(""));
107
+ if (!e) return null;
108
+ let t = Number(e[1]), n = e[2] === void 0 ? t : e[3] === "" ? Infinity : Number(e[3]);
109
+ return (t > 1e3 || n !== Infinity && n > 1e3 || n < t) && this.fail("has a repetition count outside 0..1000"), this.#t += e[0].length, [t, n];
110
+ }
111
+ #l(e, t) {
112
+ return {
113
+ op: "char",
114
+ test: t.i ? o(a(e), !1, !0) : (t) => t === e
115
+ };
116
+ }
117
+ #u(e) {
118
+ let t = this.#i();
119
+ if (t === ".") {
120
+ let t = e.s;
121
+ return {
122
+ op: "char",
123
+ test: (e) => t || e !== 10
124
+ };
125
+ }
126
+ if (t === "^") return {
127
+ op: "anchor",
128
+ at: e.m ? "line-start" : "text-start"
129
+ };
130
+ if (t === "$") return {
131
+ op: "anchor",
132
+ at: e.m ? "line-end" : "text-end"
133
+ };
134
+ if (t === "(") return this.#d(e);
135
+ if (t === "[") return {
136
+ op: "char",
137
+ test: this.#m(e)
138
+ };
139
+ if (t === "\\") {
140
+ if (this.#a("A")) return {
141
+ op: "anchor",
142
+ at: "text-start"
143
+ };
144
+ if (this.#a("z")) return {
145
+ op: "anchor",
146
+ at: "text-end"
147
+ };
148
+ if (this.#a("b")) return {
149
+ op: "anchor",
150
+ at: "word"
151
+ };
152
+ if (this.#a("B")) return {
153
+ op: "anchor",
154
+ at: "not-word"
155
+ };
156
+ let t = this.#f(e);
157
+ return t ? {
158
+ op: "char",
159
+ test: t
160
+ } : this.#l(this.#p(), e);
161
+ }
162
+ return this.#l(t.codePointAt(0), e);
163
+ }
164
+ #d(e) {
165
+ ++this.#n > 200 && this.fail("nests more than 200 groups");
166
+ let t = e;
167
+ if (this.#a("?")) {
168
+ if (this.#a("P<") || this.#r() === "<" && !"=!".includes(this.#r(1) ?? "=") && this.#a("<")) {
169
+ let e = "";
170
+ for (; this.#r() !== ">";) e += this.#i();
171
+ this.#t++, /^\w+$/.test(e) || this.fail("has a bad group name");
172
+ } else {
173
+ t = { ...e };
174
+ let n = !0;
175
+ for (;;) {
176
+ let r = this.#i();
177
+ if (r === ":") break;
178
+ if (r === ")") return Object.assign(e, t), this.#n--, null;
179
+ r === "-" && n ? n = !1 : r === "i" || r === "m" || r === "s" ? t[r] = n : r !== "U" && this.fail("has a group or flag RE2 does not support (no lookaround)");
180
+ }
181
+ }
182
+ }
183
+ let n = this.#o(t);
184
+ return this.#a(")") || this.fail("has an unclosed group"), this.#n--, n;
185
+ }
186
+ #f(e) {
187
+ let t = this.#r();
188
+ t === void 0 && this.fail("ends with a backslash");
189
+ let r = n[t.toLowerCase()];
190
+ if (r) return this.#t++, o(s(r), t !== t.toLowerCase(), e.i);
191
+ if (t !== "p" && t !== "P") return null;
192
+ this.#t++;
193
+ let i = this.#i();
194
+ if (i === "{") {
195
+ for (i = ""; this.#r() !== "}";) i += this.#i();
196
+ this.#t++;
197
+ }
198
+ /^\w+$/.test(i) || this.fail("has a bad Unicode class name");
199
+ for (let n of [i, `Script=${i}`]) try {
200
+ return o(`\\p{${n}}`, t === "P", e.i);
201
+ } catch (e) {
202
+ if (!(e instanceof SyntaxError)) throw e;
203
+ }
204
+ return this.fail(`names an unknown Unicode class ${i}`);
205
+ }
206
+ #p() {
207
+ let e = this.#i();
208
+ if (e in i) return i[e];
209
+ if (e === "x") {
210
+ let e = "";
211
+ if (this.#a("{")) {
212
+ for (; this.#r() !== "}";) e += this.#i();
213
+ this.#t++;
214
+ } else e = this.#i() + this.#i();
215
+ let t = /^[0-9a-f]+$/i.test(e) ? parseInt(e, 16) : Infinity;
216
+ return t > 1114111 && this.fail("has a bad hexadecimal escape"), t;
217
+ }
218
+ if (/[0-7]/.test(e)) {
219
+ e !== "0" && !/[0-7]/.test(this.#r() ?? "") && this.fail("uses a backreference");
220
+ let t = e;
221
+ for (; t.length < 3 && /[0-7]/.test(this.#r() ?? "");) t += this.#i();
222
+ return parseInt(t, 8);
223
+ }
224
+ let t = e.codePointAt(0);
225
+ return t < 128 && !/[0-9A-Za-z]/.test(e) ? t : this.fail(`has an unsupported escape \\${e}`);
226
+ }
227
+ #m(e) {
228
+ let t = this.#a("^"), n = [], i = "", c = !0;
229
+ for (; c || this.#r() !== "]";) {
230
+ if (c = !1, this.#r() === "[" && this.#r(1) === ":") {
231
+ let t = /^\[:(\^?)([a-z]+):\]/.exec(this.#e.slice(this.#t, this.#t + 12).join(""));
232
+ if (t) {
233
+ let i = r[t[2]];
234
+ i || this.fail(`names an unknown ASCII class ${t[2]}`), this.#t += t[0].length, n.push(o(s(i), t[1] === "^", e.i));
235
+ continue;
236
+ }
237
+ }
238
+ let t;
239
+ if (this.#a("\\")) {
240
+ let r = this.#f(e);
241
+ if (r) {
242
+ n.push(r);
243
+ continue;
244
+ }
245
+ t = this.#p();
246
+ } else t = this.#i().codePointAt(0);
247
+ if (this.#r() === "-" && this.#r(1) !== "]" && this.#r(1) !== void 0) {
248
+ this.#t++;
249
+ let e = this.#a("\\") ? this.#p() : this.#i().codePointAt(0);
250
+ e < t && this.fail("has a reversed range"), i += `${a(t)}-${a(e)}`;
251
+ } else i += a(t);
252
+ }
253
+ return this.#t++, i && n.push(o(i, !1, e.i)), (e) => n.some((t) => t(e)) !== t;
254
+ }
255
+ };
256
+ function u(e) {
257
+ return e.op === "sequence" ? e.items.every(u) : e.op === "repeat" && (e.max === 0 || u(e.item));
258
+ }
259
+ function d(n, r) {
260
+ let i = (n) => {
261
+ if (r.length >= t) throw e("ONNX RegexFullMatch pattern expands past 100000 instructions; lower its repetitions", "compute");
262
+ return r.push(n) - 1;
263
+ };
264
+ if (n.op === "char" || n.op === "anchor") i(n);
265
+ else if (n.op === "sequence") for (let e of n.items) d(e, r);
266
+ else if (n.op === "either") {
267
+ let e = {
268
+ op: "split",
269
+ to: []
270
+ };
271
+ i(e);
272
+ let t = [];
273
+ for (let a of n.items) {
274
+ e.to.push(r.length), d(a, r);
275
+ let n = {
276
+ op: "split",
277
+ to: []
278
+ };
279
+ i(n), t.push(n);
280
+ }
281
+ for (let e of t) e.to.push(r.length);
282
+ } else {
283
+ if (u(n)) return;
284
+ for (let e = 0; e < n.min; e++) d(n.item, r);
285
+ if (n.max === Infinity) {
286
+ let e = {
287
+ op: "split",
288
+ to: []
289
+ }, t = i(e);
290
+ e.to.push(r.length), d(n.item, r), i({
291
+ op: "split",
292
+ to: [t]
293
+ }), e.to.push(r.length);
294
+ } else {
295
+ let e = [];
296
+ for (let t = n.min; t < n.max; t++) {
297
+ let t = {
298
+ op: "split",
299
+ to: []
300
+ };
301
+ i(t), t.to.push(r.length), e.push(t), d(n.item, r);
302
+ }
303
+ for (let t of e) t.to.push(r.length);
304
+ }
305
+ }
306
+ }
307
+ function f(e) {
308
+ let t = [];
309
+ return d(new l(e).parse(), t), t.push({ op: "match" }), (e) => {
310
+ let n = Array.from(e, (e) => e.codePointAt(0)), r = new Int32Array(t.length).fill(-1), i = (e, t) => e === "text-start" ? t === 0 : e === "text-end" ? t === n.length : e === "line-start" ? t === 0 || n[t - 1] === 10 : e === "line-end" ? t === n.length || n[t] === 10 : (t > 0 && c(n[t - 1])) !== (t < n.length && c(n[t])) == (e === "word"), a = [0];
311
+ for (let e = 0;; e++) {
312
+ let o = [], s = a, c = !1;
313
+ for (; s.length;) {
314
+ let n = s.pop();
315
+ if (r[n] === e) continue;
316
+ r[n] = e;
317
+ let a = t[n];
318
+ a.op === "split" ? s.push(...a.to) : a.op === "anchor" ? i(a.at, e) && s.push(n + 1) : a.op === "char" ? o.push({
319
+ test: a.test,
320
+ next: n + 1
321
+ }) : c = !0;
322
+ }
323
+ if (e === n.length) return c;
324
+ a = [];
325
+ for (let { test: t, next: r } of o) t(n[e]) && a.push(r);
326
+ if (!a.length) return !1;
327
+ }
328
+ };
329
+ }
330
+ //#endregion
331
+ export { f as fullMatcher };
@@ -0,0 +1,2 @@
1
+ /** Compiles an RE2 pattern into a test of whether the whole string matches it. */
2
+ export declare function fullMatcher(pattern: string): (text: string) => boolean;
package/dist/onnx.d.ts ADDED
@@ -0,0 +1,167 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ /** ONNX's tensor storage types. Half, bfloat16 and the 8-bit floats use raw bits in Uint16 or Uint8 arrays; the 4-bit
3
+ * types pack two elements a byte and the 2-bit types four, first element in the low bits; the 6-bit floats are a
4
+ * little-endian bit stream. Complex values interleave
5
+ * real and imaginary parts. */
6
+ export type OnnxDType = 'float32' | 'uint8' | 'int8' | 'uint16' | 'int16' | 'int32' | 'int64' | 'string' | 'bool' | 'float16' | 'float64' | 'uint32' | 'uint64' | 'complex64' | 'complex128' | 'bfloat16' | 'float8e4m3fn' | 'float8e4m3fnuz' | 'float8e5m2' | 'float8e5m2fnuz' | 'uint4' | 'int4' | 'float4e2m1' | 'float8e8m0' | 'uint2' | 'int2' | 'float6e2m3' | 'float6e3m2';
7
+ /** Host storage accepted and copied by an ONNX tensor. */
8
+ export type OnnxData = Float32Array | Float64Array | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array | readonly string[];
9
+ /** Owned host tensor. Construction copies the supplied data; returned inference tensors outlive their model. */
10
+ export declare class OnnxTensor {
11
+ readonly dtype: OnnxDType;
12
+ readonly shape: readonly number[];
13
+ readonly data: OnnxData;
14
+ constructor(dtype: OnnxDType, data: OnnxData, shape: readonly number[]);
15
+ }
16
+ /** Sequences, maps and optional values retain their ONNX container structure. */
17
+ export type OnnxValue = OnnxTensor | readonly OnnxValue[] | ReadonlyMap<string | number | bigint, OnnxValue> | null;
18
+ /** Model-declared tensor or recursive container type, preserving symbolic and unknown dimensions. */
19
+ export interface OnnxType {
20
+ readonly tag: 'tensor' | 'sparse' | 'sequence' | 'map' | 'optional';
21
+ readonly kind?: number;
22
+ readonly shape?: readonly (number | string | null)[] | null;
23
+ readonly keyKind?: number;
24
+ readonly element?: OnnxType;
25
+ }
26
+ /** Named graph input/output and its optional model-declared type. */
27
+ export interface OnnxValueInfo {
28
+ readonly name: string;
29
+ readonly type: OnnxType | null;
30
+ }
31
+ /** Exact external initializer byte range requested from the application's resolver. */
32
+ export interface OnnxExternalRequest {
33
+ readonly location: string;
34
+ readonly offset: number;
35
+ readonly length: number;
36
+ readonly checksum?: string;
37
+ readonly signal?: AbortSignal;
38
+ }
39
+ /** Model loading, cancellation and persistent storage options. */
40
+ export interface OnnxLoadOptions {
41
+ readonly signal?: AbortSignal;
42
+ /** Persistent tensor storage budget, default 256 MiB; range 64 KiB..1 GiB. */
43
+ readonly memoryLimit?: number;
44
+ /** Resolve exactly the requested external byte range. URL sources otherwise use relative same-origin files. */
45
+ readonly externalData?: (request: OnnxExternalRequest) => Promise<Uint8Array>;
46
+ }
47
+ /** Output selection, cancellation and bounded graph execution options. */
48
+ export interface OnnxRunOptions {
49
+ readonly signal?: AbortSignal;
50
+ /** Default: every graph output. Names must identify graph outputs. */
51
+ readonly outputs?: readonly string[];
52
+ /** Safety bound for each Loop/Scan, default 10000. */
53
+ readonly maxIterations?: number;
54
+ /** Maximum expanded node invocations per run, default 1000000. Function calls and loop bodies count. */
55
+ readonly maxNodes?: number;
56
+ /** Yield to the event loop every this many nodes, default 16. */
57
+ readonly yieldEvery?: number;
58
+ }
59
+ interface Attribute {
60
+ name: string;
61
+ kind: number;
62
+ reference: string;
63
+ value: unknown;
64
+ }
65
+ interface Node {
66
+ name: string;
67
+ op: string;
68
+ domain: string;
69
+ overload: string;
70
+ inputs: string[];
71
+ outputs: string[];
72
+ attributes: Attribute[];
73
+ attributeSet: number;
74
+ kernelIndex: number;
75
+ }
76
+ interface Initializer {
77
+ name: string;
78
+ id: number;
79
+ kind: number;
80
+ shape: number[];
81
+ bytes: number;
82
+ externalStorage?: boolean;
83
+ external?: Record<string, string>;
84
+ sparseValues?: Initializer;
85
+ sparseIndices?: Initializer;
86
+ }
87
+ interface Graph {
88
+ name: string;
89
+ nodes: Node[];
90
+ inputs: OnnxValueInfo[];
91
+ outputs: OnnxValueInfo[];
92
+ initializers: Initializer[];
93
+ }
94
+ interface FunctionDef {
95
+ name: string;
96
+ domain: string;
97
+ overload: string;
98
+ inputs: string[];
99
+ outputs: string[];
100
+ nodes: Node[];
101
+ requiredAttributes: string[];
102
+ defaults: Attribute[];
103
+ defaultSet: number;
104
+ opsets: Record<string, number>;
105
+ }
106
+ interface Metadata {
107
+ irVersion: number;
108
+ opsets: Record<string, number>;
109
+ producer: string;
110
+ producerVersion: string;
111
+ domain: string;
112
+ version: string;
113
+ description: string;
114
+ metadata: Record<string, string>;
115
+ graph: Graph;
116
+ functions: FunctionDef[];
117
+ }
118
+ interface Kernel {
119
+ memory: WebAssembly.Memory;
120
+ reserve(n: number): number;
121
+ message_ptr(): number;
122
+ message_len(): number;
123
+ memory_limit(n: number): number;
124
+ load_model(n: number): number;
125
+ create_tensor(kind: number, rank: number, n: number): number;
126
+ fill_external(id: number, n: number): number;
127
+ fill_sparse(id: number, values: number, indices: number): number;
128
+ resolve_attributes(id: number, n: number): number;
129
+ supported(id: number, version: number): number;
130
+ execute(id: number, attributes: number, version: number, n: number, nout: number): number;
131
+ output(i: number): number;
132
+ describe(id: number): number;
133
+ data_ptr(id: number): number;
134
+ data_len(id: number): number;
135
+ scalar_bool(id: number): number;
136
+ drop_tensor(id: number): number;
137
+ live_bytes(): number;
138
+ simd_groups(): bigint;
139
+ random_seed(lo: number, hi: number): void;
140
+ random_stream(id: number): void;
141
+ release(): void;
142
+ slice_tensor(id: number, axis: number, index: number, keep: number): number;
143
+ concat_tensors(axis: number, newAxis: number, n: number): number;
144
+ }
145
+ /** An isolated model session with lazy SIMD Wasm kernels and owned output snapshots. */
146
+ export declare class OnnxModel implements Disposable {
147
+ #private;
148
+ readonly inputs: readonly OnnxValueInfo[];
149
+ readonly outputs: readonly OnnxValueInfo[];
150
+ readonly metadata: Readonly<Record<string, string>>;
151
+ readonly producer: string;
152
+ readonly irVersion: number;
153
+ /** @internal Use loadOnnx. */
154
+ constructor(kernel: Kernel, metadata: Metadata);
155
+ get work(): {
156
+ readonly simdGroups: bigint;
157
+ readonly liveBytes: number;
158
+ readonly validatedFunctions: number;
159
+ };
160
+ /** Execute one inference. A session rejects overlapping runs; use separate sessions for parallel inference. */
161
+ run(feeds: Readonly<Record<string, OnnxValue>>, options?: OnnxRunOptions): Promise<Readonly<Record<string, OnnxValue>>>;
162
+ dispose(): void;
163
+ [Symbol.dispose](): void;
164
+ }
165
+ /** Parse a binary ONNX ModelProto and load inline, sparse and external initializers. Nothing loads on import. */
166
+ export declare function loadOnnx(source: Uint8Array | ArrayBuffer | URL | string, options?: OnnxLoadOptions): Promise<OnnxModel>;
167
+ export {};