@genai-fi/nanogpt 0.10.1 → 0.10.3
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/Generator.js +11761 -171
- package/dist/{RealDiv-DgA3z9oO.js → RealDiv-KAPDe8zB.js} +28 -30
- package/dist/Reshape-BYkmUnAv.js +14 -0
- package/dist/{Reshape-_kILl6tK.js → Reshape-Zt6eb7yh.js} +18 -20
- package/dist/TeachableLLM.js +10 -11
- package/dist/{axis_util-BvHEw88j.js → axis_util-BaG7mf5A.js} +3 -3
- package/dist/backend.js +2 -2
- package/dist/{backend_util-D-rUb2ty.js → backend_util-RCe-rHaj.js} +59 -60
- package/dist/{backend_webgpu-B0u2ndUn.js → backend_webgpu-DE3ACOLx.js} +45 -47
- package/dist/broadcast_to-B3eYlZm7.js +28 -0
- package/dist/checks/appendCache.js +2 -2
- package/dist/checks/attentionMask.js +3 -3
- package/dist/checks/gelu.js +2 -2
- package/dist/checks/matMulGelu.js +7 -11
- package/dist/checks/normRMS.js +9 -9
- package/dist/checks/normRMSGrad.js +3 -3
- package/dist/checks/packUnpack.js +2 -2
- package/dist/checks/qkv.js +12 -13
- package/dist/checks/rope.js +2 -2
- package/dist/clip_by_value-BnO7-a88.js +12 -0
- package/dist/complex-DjxcVmoX.js +11 -0
- package/dist/concat-BV8bt5H-.js +17 -0
- package/dist/{concat_util-DcJk7YHS.js → concat_util-DpW8mL_l.js} +1 -1
- package/dist/{dataset-0xP8GjwI.js → dataset-BcwmTGYc.js} +137 -139
- package/dist/dropout-BcvN9JYi.js +92 -0
- package/dist/expand_dims-DT4tEPwA.js +11 -0
- package/dist/{exports_initializers-xuidcwI4.js → exports_initializers-Hta_rEnm.js} +1 -1
- package/dist/floor-D5QdR_le.js +9 -0
- package/dist/gather-D3JcZUaI.js +9 -0
- package/dist/{gelu-CNLFZWea.js → gelu-CjNPL4OH.js} +10 -11
- package/dist/{gpgpu_math-DDVJCn6-.js → gpgpu_math-DAOmgtXR.js} +841 -1015
- package/dist/{index-CjOj7j-u.js → index-BwexR4lA.js} +262 -263
- package/dist/index-DOvlwCh-.js +3520 -0
- package/dist/{kernel_funcs_utils-Dg_-E44D.js → kernel_funcs_utils-CCzYdUZg.js} +129 -131
- package/dist/layers/BaseLayer.js +14 -15
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/MLP.js +4 -4
- package/dist/layers/PositionEmbedding.js +7 -7
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +9 -9
- package/dist/layers/TiedEmbedding.js +6 -6
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +13 -14
- package/dist/log_sum_exp-ngO0-4pK.js +39 -0
- package/dist/main.js +49 -50
- package/dist/{matMul16--R5hOwDG.js → matMul16-BWRSOCWB.js} +14 -15
- package/dist/matMulGelu-CzfgT6Wq.js +163 -0
- package/dist/mat_mul-SjpJRLyL.js +11 -0
- package/dist/mod-AnXEvvpo.js +11 -0
- package/dist/models/NanoGPTV1.js +2 -2
- package/dist/models/model.js +13 -14
- package/dist/ones-D2rT0xk2.js +14 -0
- package/dist/ops/adamAdjust.js +1 -1
- package/dist/ops/adamMoments.js +1 -1
- package/dist/ops/add16.js +1 -1
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/concat16.js +2 -2
- package/dist/ops/cpu/adamAdjust.js +13 -14
- package/dist/ops/cpu/adamMoments.js +6 -7
- package/dist/ops/cpu/appendCache.js +7 -8
- package/dist/ops/cpu/attentionMask.js +7 -7
- package/dist/ops/cpu/fusedSoftmax.js +10 -11
- package/dist/ops/cpu/gatherSub.js +9 -10
- package/dist/ops/cpu/gelu.js +9 -10
- package/dist/ops/cpu/matMul16.js +6 -7
- package/dist/ops/cpu/matMulGelu.js +5 -6
- package/dist/ops/cpu/matMulMul.js +3 -4
- package/dist/ops/cpu/mulDropout.js +3 -4
- package/dist/ops/cpu/normRMS.js +10 -11
- package/dist/ops/cpu/qkv.js +8 -9
- package/dist/ops/cpu/rope.js +5 -6
- package/dist/ops/cpu/scatterSub.js +17 -19
- package/dist/ops/dot16.js +2 -2
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/add16.js +11 -12
- package/dist/ops/grads/attentionMask.js +5 -6
- package/dist/ops/grads/gelu.js +3 -4
- package/dist/ops/grads/matMul16.js +4 -5
- package/dist/ops/grads/matMulGelu.js +9 -10
- package/dist/ops/grads/normRMS.js +7 -8
- package/dist/ops/grads/pack16.js +4 -5
- package/dist/ops/grads/qkv.js +17 -19
- package/dist/ops/grads/rope.js +3 -5
- package/dist/ops/grads/softmax16.js +3 -4
- package/dist/ops/grads/unpack16.js +3 -4
- package/dist/ops/grads/utils.d.ts +1 -0
- package/dist/ops/grads/utils.js +8 -4
- package/dist/ops/matMul16.js +3 -3
- package/dist/ops/matMulGelu.js +2 -2
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mul16.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/pack16.js +3 -4
- package/dist/ops/qkv.js +4 -8
- package/dist/ops/reshape16.js +14 -16
- package/dist/ops/rope.d.ts +1 -1
- package/dist/ops/rope.js +3 -8
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/slice16.js +2 -2
- package/dist/ops/softmax16.js +5 -8
- package/dist/ops/sub16.js +1 -1
- package/dist/ops/sum16.js +2 -2
- package/dist/ops/transpose16.js +23 -24
- package/dist/ops/unpack16.js +2 -2
- package/dist/ops/webgl/adamAdjust.js +2 -3
- package/dist/ops/webgl/adamMoments.js +1 -2
- package/dist/ops/webgl/appendCache.js +1 -2
- package/dist/ops/webgl/attentionMask.js +4 -5
- package/dist/ops/webgl/fusedSoftmax.js +4 -6
- package/dist/ops/webgl/gatherSub.js +6 -7
- package/dist/ops/webgl/gelu.js +2 -3
- package/dist/ops/webgl/log.js +11 -12
- package/dist/ops/webgl/matMul16.js +10 -11
- package/dist/ops/webgl/matMulGelu.js +7 -111
- package/dist/ops/webgl/matMulMul.js +9 -10
- package/dist/ops/webgl/mulDropout.js +8 -9
- package/dist/ops/webgl/normRMS.js +2 -3
- package/dist/ops/webgl/qkv.js +5 -6
- package/dist/ops/webgl/rope.js +7 -8
- package/dist/ops/webgl/scatterSub.js +5 -6
- package/dist/ops/webgpu/adamAdjust.js +10 -12
- package/dist/ops/webgpu/adamMoments.js +8 -10
- package/dist/ops/webgpu/add16.js +8 -9
- package/dist/ops/webgpu/appendCache.js +23 -25
- package/dist/ops/webgpu/attentionMask.js +8 -10
- package/dist/ops/webgpu/attentionMask32_program.js +2 -2
- package/dist/ops/webgpu/concat16.js +12 -14
- package/dist/ops/webgpu/gatherSub.js +11 -13
- package/dist/ops/webgpu/gelu.js +28 -29
- package/dist/ops/webgpu/matMul16.js +26 -28
- package/dist/ops/webgpu/matMul16_program.js +4 -5
- package/dist/ops/webgpu/mul16.js +9 -10
- package/dist/ops/webgpu/normRMS.js +15 -17
- package/dist/ops/webgpu/normRMSGrad.js +21 -28
- package/dist/ops/webgpu/pack16.js +12 -13
- package/dist/ops/webgpu/pack16_program.js +2 -2
- package/dist/ops/webgpu/qkv.js +16 -18
- package/dist/ops/webgpu/rope.js +25 -27
- package/dist/ops/webgpu/scatterSub.js +7 -9
- package/dist/ops/webgpu/slice16.js +21 -23
- package/dist/ops/webgpu/softmax16.js +17 -19
- package/dist/ops/webgpu/softmax16_program.js +2 -2
- package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
- package/dist/ops/webgpu/softmax16grad.js +7 -8
- package/dist/ops/webgpu/sub16.js +7 -8
- package/dist/ops/webgpu/sum16.js +18 -20
- package/dist/ops/webgpu/transpose16.js +19 -20
- package/dist/ops/webgpu/transpose16_program.js +2 -2
- package/dist/ops/webgpu/transpose16_shared_program.js +11 -12
- package/dist/ops/webgpu/unpack16.js +3 -4
- package/dist/ops/webgpu/utils/binary_op.js +7 -8
- package/dist/ops/webgpu/utils/reductions.js +14 -22
- package/dist/ops-B5yanEdW.js +476 -0
- package/dist/pack16-nQ6JaLo-.js +39 -0
- package/dist/patches/webgpu_backend.js +19 -20
- package/dist/patches/webgpu_base.js +1 -1
- package/dist/patches/webgpu_program.js +21 -22
- package/dist/{random_width-DY6Kk2Dl.js → random_width-or-CEftb.js} +2506 -2761
- package/dist/range-BklejeeW.js +10 -0
- package/dist/relu-CP0ZcxWO.js +9 -0
- package/dist/reshape-ByE68wS9.js +9 -0
- package/dist/resize_nearest_neighbor-B19mCEg2.js +175 -0
- package/dist/rope-Ir4mTyD1.js +24 -0
- package/dist/{scatter_nd_util-5EL-8VAQ.js → scatter_nd_util-lvSiX8q4.js} +1 -1
- package/dist/selu_util-kbhpTdYD.js +44 -0
- package/dist/{shared-BRksrJb3.js → shared-DT1TkE6w.js} +1 -1
- package/dist/{shared-BuAXb4CI.js → shared-dntlHIDQ.js} +343 -345
- package/dist/slice-BfEGSH82.js +12 -0
- package/dist/{slice_util-DtEldBfK.js → slice_util-uTKwiEpW.js} +1 -1
- package/dist/{softmax-ZHVebtR1.js → softmax-CA5jFsLR.js} +4 -5
- package/dist/split-CVLc0w--.js +9 -0
- package/dist/squeeze-C7Z2srUo.js +10 -0
- package/dist/stack-Cf4n9h0N.js +11 -0
- package/dist/step-CINUs5QB.js +261 -0
- package/dist/sum-DWAtNGez.js +11 -0
- package/dist/tensor-DJoc7gJU.js +8 -0
- package/dist/tensor1d-D11P_7Dp.js +11 -0
- package/dist/{tensor2d-G4Ys2GxX.js → tensor2d-Bs9wZRc7.js} +6 -7
- package/dist/{tensor4d-B8roDgtc.js → tensor4d-BARPdTaS.js} +6 -7
- package/dist/{tfjs_backend-kNyO5L2d.js → tfjs_backend-y1cvNhLA.js} +244 -253
- package/dist/tile-mbfagpsB.js +11 -0
- package/dist/training/Adam.js +2 -2
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +2 -2
- package/dist/training/sparseCrossEntropy.js +5 -5
- package/dist/transpose-ClWiBS_b.js +36 -0
- package/dist/unsorted_segment_sum-BDDhB_E6.js +277 -0
- package/dist/utilities/dummy.js +3 -3
- package/dist/utilities/multinomialCPU.js +2 -2
- package/dist/utilities/packed.d.ts +1 -4
- package/dist/utilities/packed.js +10 -711
- package/dist/utilities/performance.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/sentences.js +5 -5
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-Bhn5bHYv.js → variable-WawDEaAb.js} +1 -1
- package/dist/{webgpu_program-Cigz-7RF.js → webgpu_program-DuOXPQol.js} +178 -172
- package/dist/{webgpu_util-BBCnKm2X.js → webgpu_util-RxEF33Rj.js} +34 -35
- package/dist/zeros-KnWaWf-X.js +13 -0
- package/dist/zeros_like-DvE73F4e.js +721 -0
- package/package.json +4 -2
- package/dist/Reshape-CF6odzV4.js +0 -16
- package/dist/broadcast_to-CwF7XIeu.js +0 -30
- package/dist/complex-CSlYz-2T.js +0 -13
- package/dist/concat-BHlIJeyT.js +0 -19
- package/dist/dropout-C1pM3f11.js +0 -99
- package/dist/expand_dims-BPG4fwBP.js +0 -13
- package/dist/gather-DykLGqmW.js +0 -10
- package/dist/index-ZyQhjEPo.js +0 -2157
- package/dist/log_sum_exp-DWI-76TI.js +0 -41
- package/dist/mat_mul-DeAh4uTH.js +0 -12
- package/dist/mod-Gt1rMB4n.js +0 -12
- package/dist/mulmat_packed_gpu-BMFhLwta.js +0 -55
- package/dist/ones-CAMiP4I2.js +0 -15
- package/dist/ops-CNI3TwqM.js +0 -645
- package/dist/pack16-CFUqumar.js +0 -41
- package/dist/patches/PackedTensor.d.ts +0 -12
- package/dist/patches/PackedTensor.js +0 -11
- package/dist/patches/engine.d.ts +0 -261
- package/dist/patches/engine.js +0 -10
- package/dist/patches/tape.d.ts +0 -12
- package/dist/patches/tape.js +0 -5
- package/dist/range-BMS52eQi.js +0 -11
- package/dist/reciprocal-CTmshQ9J.js +0 -10
- package/dist/register_all_kernels-Bwu1PTuU.js +0 -12307
- package/dist/relu-yZ2-7WxU.js +0 -10
- package/dist/reshape-DevtBWtf.js +0 -10
- package/dist/rope-B5UUMsPi.js +0 -32
- package/dist/selu_util-D1w6yyTO.js +0 -303
- package/dist/sin-BGfy2HZo.js +0 -16
- package/dist/slice-D_gkkqZK.js +0 -13
- package/dist/split-DrfihRpZ.js +0 -10
- package/dist/squeeze-DZEpeblb.js +0 -11
- package/dist/stack-yOIAalTq.js +0 -13
- package/dist/sum-_fzj5ZTB.js +0 -12
- package/dist/tensor-DdQUJZlz.js +0 -909
- package/dist/tensor-f35l8Odg.js +0 -8
- package/dist/tensor1d-CeZuc-Rv.js +0 -12
- package/dist/tensor_util-DV-FP5Q3.js +0 -523
- package/dist/tile-BzyEiF-F.js +0 -13
- package/dist/transpose-DKELTqhe.js +0 -38
- package/dist/zeros-2gldETuK.js +0 -14
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import { A as b, B as u, l as p, E as k, bf as hs, bg as bs, at as ds, bh as gs, bi as Es, X as W, bj as $s, bk as ys, bl as _s, bm as Ns, b as $, m as h, x as G, w as S, q as Ss, c as d, bn as ks, D as K, d as Is, ab as B, aZ as ns, b0 as Ts, a6 as Ms } from "./index-DOvlwCh-.js";
|
|
2
|
+
import { t as j } from "./tile-mbfagpsB.js";
|
|
3
|
+
import { e as R } from "./expand_dims-DT4tEPwA.js";
|
|
4
|
+
import { t as x } from "./tensor1d-D11P_7Dp.js";
|
|
5
|
+
import { n as xs, a as As, b as ws } from "./non_max_suppression_impl-B2W7YjZB.js";
|
|
6
|
+
import { r as Os, l as ls, g as ts, w as q, a as rs, m as Q, b as Gs, c as Bs, u as us, n as ps, d as Ds, e as Ls, s as Ws, f as Rs, h as qs, i as zs } from "./resize_nearest_neighbor-B19mCEg2.js";
|
|
7
|
+
import { s as ms } from "./split-CVLc0w--.js";
|
|
8
|
+
import { s as _ } from "./sum-DWAtNGez.js";
|
|
9
|
+
import { s as T } from "./slice-BfEGSH82.js";
|
|
10
|
+
import { r as F } from "./range-BklejeeW.js";
|
|
11
|
+
import { t as Vs } from "./tensor-DJoc7gJU.js";
|
|
12
|
+
import { n as C, t as as } from "./transpose-ClWiBS_b.js";
|
|
13
|
+
import { r as O } from "./reshape-ByE68wS9.js";
|
|
14
|
+
import { s as Z } from "./stack-Cf4n9h0N.js";
|
|
15
|
+
import { z as Cs } from "./zeros-KnWaWf-X.js";
|
|
16
|
+
import { s as Ps } from "./squeeze-C7Z2srUo.js";
|
|
17
|
+
import { c as X } from "./concat-BV8bt5H-.js";
|
|
18
|
+
import { m as w } from "./mat_mul-SjpJRLyL.js";
|
|
19
|
+
import { t as J } from "./tensor2d-Bs9wZRc7.js";
|
|
20
|
+
import { o as Ys } from "./ones-D2rT0xk2.js";
|
|
21
|
+
import { r as fs } from "./relu-CP0ZcxWO.js";
|
|
22
|
+
import { a as is, e as ss, l as vs } from "./log_sum_exp-ngO0-4pK.js";
|
|
23
|
+
import { e as js } from "./axis_util-BaG7mf5A.js";
|
|
24
|
+
function Fs(e, a, n) {
|
|
25
|
+
const r = u(e, "x", "bincount"), t = u(a, "weights", "bincount");
|
|
26
|
+
p(r.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${r.dtype}`), p(n >= 0, () => `size must be non-negative, but got ${n}.`), p(t.size === r.size || t.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${r.shape}, weights shape: ${t.shape}.`);
|
|
27
|
+
const s = { x: r, weights: t }, o = { size: n };
|
|
28
|
+
return k.runKernel(hs, s, o);
|
|
29
|
+
}
|
|
30
|
+
const Zs = /* @__PURE__ */ b({ bincount_: Fs });
|
|
31
|
+
function Us(e, ...a) {
|
|
32
|
+
const n = a.map((t, s) => u(t, `tensors${s}`, "einsum")), r = { equation: e };
|
|
33
|
+
return k.runKernel(bs, n, r);
|
|
34
|
+
}
|
|
35
|
+
const V = /* @__PURE__ */ b({ einsum_: Us });
|
|
36
|
+
function Hs(e, a, n, r = "float32") {
|
|
37
|
+
a == null && (a = e);
|
|
38
|
+
const t = ds([e, a], r), s = e <= a ? e : a;
|
|
39
|
+
for (let i = 0; i < s; ++i)
|
|
40
|
+
t.set(1, i, i);
|
|
41
|
+
const o = O(t.toTensor(), [e, a]);
|
|
42
|
+
if (n == null)
|
|
43
|
+
return o;
|
|
44
|
+
if (n.length === 1)
|
|
45
|
+
return j(R(o, 0), [n[0], 1, 1]);
|
|
46
|
+
if (n.length === 2)
|
|
47
|
+
return j(R(R(o, 0), 0), [n[0], n[1], 1, 1]);
|
|
48
|
+
if (n.length === 3)
|
|
49
|
+
return j(R(R(R(o, 0), 0), 0), [
|
|
50
|
+
n[0],
|
|
51
|
+
n[1],
|
|
52
|
+
n[2],
|
|
53
|
+
1,
|
|
54
|
+
1
|
|
55
|
+
]);
|
|
56
|
+
throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${n.length}D.`);
|
|
57
|
+
}
|
|
58
|
+
const Ks = /* @__PURE__ */ b({ eye_: Hs });
|
|
59
|
+
function Xs(e, a, n, r, t = "bilinear", s = 0) {
|
|
60
|
+
const o = u(e, "image", "cropAndResize"), i = u(a, "boxes", "cropAndResize", "float32"), l = u(n, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
|
|
61
|
+
p(o.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${o.rank}.`), p(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${c},4] but had shape ${i.shape}.`), p(l.rank === 1 && l.shape[0] === c, () => `Error in cropAndResize: boxInd must be have size [${c}] but had shape ${i.shape}.`), p(r.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${r.length}.`), p(r[0] >= 1 && r[1] >= 1, () => `cropSize must be atleast [1,1], but was ${r}`), p(t === "bilinear" || t === "nearest", () => `method must be bilinear or nearest, but was ${t}`);
|
|
62
|
+
const f = { image: o, boxes: i, boxInd: l }, m = { method: t, extrapolationValue: s, cropSize: r };
|
|
63
|
+
return k.runKernel(gs, f, m);
|
|
64
|
+
}
|
|
65
|
+
const Js = /* @__PURE__ */ b({ cropAndResize_: Xs });
|
|
66
|
+
function Qs(e) {
|
|
67
|
+
const a = u(e, "image", "flipLeftRight", "float32");
|
|
68
|
+
p(a.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${a.rank}.`);
|
|
69
|
+
const n = { image: a };
|
|
70
|
+
return k.runKernel(Es, n, {});
|
|
71
|
+
}
|
|
72
|
+
const sn = /* @__PURE__ */ b({ flipLeftRight_: Qs });
|
|
73
|
+
function nn(e) {
|
|
74
|
+
const a = u(e, "image", "grayscaleToRGB"), n = a.rank - 1, r = a.shape[n];
|
|
75
|
+
p(a.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${a.rank}.`), p(r === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${r}.`);
|
|
76
|
+
const t = new Array(a.rank);
|
|
77
|
+
return t.fill(1, 0, n), t[n] = 3, j(a, t);
|
|
78
|
+
}
|
|
79
|
+
const tn = /* @__PURE__ */ b({ grayscaleToRGB_: nn });
|
|
80
|
+
function en(e) {
|
|
81
|
+
const a = u(e, "image", "RGBToGrayscale"), n = a.rank - 1, r = a.shape[n];
|
|
82
|
+
p(a.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${a.rank}.`), p(r === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${r}.`);
|
|
83
|
+
const t = a.dtype, s = W(a, "float32"), o = x([0.2989, 0.587, 0.114]);
|
|
84
|
+
let i;
|
|
85
|
+
switch (a.rank) {
|
|
86
|
+
case 2:
|
|
87
|
+
i = V("ij,j->i", s, o);
|
|
88
|
+
break;
|
|
89
|
+
case 3:
|
|
90
|
+
i = V("ijk,k->ij", s, o);
|
|
91
|
+
break;
|
|
92
|
+
case 4:
|
|
93
|
+
i = V("ijkl,l->ijk", s, o);
|
|
94
|
+
break;
|
|
95
|
+
case 5:
|
|
96
|
+
i = V("ijklm,m->ijkl", s, o);
|
|
97
|
+
break;
|
|
98
|
+
case 6:
|
|
99
|
+
i = V("ijklmn,n->ijklm", s, o);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
throw new Error("Not a valid tensor rank.");
|
|
103
|
+
}
|
|
104
|
+
return i = R(i, -1), W(i, t);
|
|
105
|
+
}
|
|
106
|
+
const on = /* @__PURE__ */ b({ rgbToGrayscale_: en });
|
|
107
|
+
function rn(e, a, n = 0, r = 0.5) {
|
|
108
|
+
const t = u(e, "image", "rotateWithOffset", "float32");
|
|
109
|
+
p(t.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${t.rank}.`);
|
|
110
|
+
const s = { image: t }, o = { radians: a, fillValue: n, center: r };
|
|
111
|
+
return k.runKernel($s, s, o);
|
|
112
|
+
}
|
|
113
|
+
const an = /* @__PURE__ */ b({ rotateWithOffset_: rn });
|
|
114
|
+
function z(e, a, n, r, t, s) {
|
|
115
|
+
r == null && (r = 0.5), t == null && (t = Number.NEGATIVE_INFINITY), s == null && (s = 0);
|
|
116
|
+
const o = e.shape[0];
|
|
117
|
+
return n = Math.min(n, o), p(0 <= r && r <= 1, () => `iouThreshold must be in [0, 1], but was '${r}'`), p(e.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${e.rank}'`), p(e.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${e.shape[1]}`), p(a.rank === 1, () => "scores must be a 1D tensor"), p(a.shape[0] === o, () => `scores has incompatible shape with boxes. Expected ${o}, but was ${a.shape[0]}`), p(0 <= s && s <= 1, () => `softNmsSigma must be in [0, 1], but was '${s}'`), { maxOutputSize: n, iouThreshold: r, scoreThreshold: t, softNmsSigma: s };
|
|
118
|
+
}
|
|
119
|
+
function cn(e, a, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
|
|
120
|
+
const s = u(e, "boxes", "nonMaxSuppression", "float32"), o = u(a, "scores", "nonMaxSuppression", "float32"), i = z(s, o, n, r, t);
|
|
121
|
+
n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
|
|
122
|
+
const l = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t };
|
|
123
|
+
return k.runKernel(ys, { boxes: s, scores: o }, l);
|
|
124
|
+
}
|
|
125
|
+
const ln = /* @__PURE__ */ b({ nonMaxSuppression_: cn });
|
|
126
|
+
async function un(e, a, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
|
|
127
|
+
const s = u(e, "boxes", "nonMaxSuppressionAsync"), o = u(a, "scores", "nonMaxSuppressionAsync"), i = z(s, o, n, r, t);
|
|
128
|
+
n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
|
|
129
|
+
const l = await Promise.all([s.data(), o.data()]), c = l[0], f = l[1], { selectedIndices: m } = xs(c, f, n, r, t);
|
|
130
|
+
return s !== e && s.dispose(), o !== a && o.dispose(), x(m, "int32");
|
|
131
|
+
}
|
|
132
|
+
const pn = un;
|
|
133
|
+
function mn(e, a, n, r = 0.5, t = Number.NEGATIVE_INFINITY, s = 0) {
|
|
134
|
+
const o = u(e, "boxes", "nonMaxSuppression"), i = u(a, "scores", "nonMaxSuppression"), l = z(o, i, n, r, t, s);
|
|
135
|
+
n = l.maxOutputSize, r = l.iouThreshold, t = l.scoreThreshold, s = l.softNmsSigma;
|
|
136
|
+
const c = { boxes: o, scores: i }, f = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t, softNmsSigma: s }, m = k.runKernel(_s, c, f);
|
|
137
|
+
return { selectedIndices: m[0], selectedScores: m[1] };
|
|
138
|
+
}
|
|
139
|
+
const fn = /* @__PURE__ */ b({ nonMaxSuppressionWithScore_: mn });
|
|
140
|
+
async function hn(e, a, n, r = 0.5, t = Number.NEGATIVE_INFINITY, s = 0) {
|
|
141
|
+
const o = u(e, "boxes", "nonMaxSuppressionAsync"), i = u(a, "scores", "nonMaxSuppressionAsync"), l = z(o, i, n, r, t, s);
|
|
142
|
+
n = l.maxOutputSize, r = l.iouThreshold, t = l.scoreThreshold, s = l.softNmsSigma;
|
|
143
|
+
const c = await Promise.all([o.data(), i.data()]), f = c[0], m = c[1], { selectedIndices: E, selectedScores: g } = As(f, m, n, r, t, s);
|
|
144
|
+
return o !== e && o.dispose(), i !== a && i.dispose(), {
|
|
145
|
+
selectedIndices: x(E, "int32"),
|
|
146
|
+
selectedScores: x(g)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const bn = hn;
|
|
150
|
+
function dn(e, a, n, r = 0.5, t = Number.NEGATIVE_INFINITY, s = !1) {
|
|
151
|
+
const o = u(e, "boxes", "nonMaxSuppression"), i = u(a, "scores", "nonMaxSuppression"), l = z(
|
|
152
|
+
o,
|
|
153
|
+
i,
|
|
154
|
+
n,
|
|
155
|
+
r,
|
|
156
|
+
t,
|
|
157
|
+
null
|
|
158
|
+
/* softNmsSigma */
|
|
159
|
+
), c = l.maxOutputSize, f = l.iouThreshold, m = l.scoreThreshold, E = { boxes: o, scores: i }, g = {
|
|
160
|
+
maxOutputSize: c,
|
|
161
|
+
iouThreshold: f,
|
|
162
|
+
scoreThreshold: m,
|
|
163
|
+
padToMaxOutputSize: s
|
|
164
|
+
}, y = k.runKernel(Ns, E, g);
|
|
165
|
+
return { selectedIndices: y[0], validOutputs: y[1] };
|
|
166
|
+
}
|
|
167
|
+
const gn = /* @__PURE__ */ b({ nonMaxSuppressionPadded_: dn });
|
|
168
|
+
async function En(e, a, n, r = 0.5, t = Number.NEGATIVE_INFINITY, s = !1) {
|
|
169
|
+
const o = u(e, "boxes", "nonMaxSuppressionAsync"), i = u(a, "scores", "nonMaxSuppressionAsync"), l = z(
|
|
170
|
+
o,
|
|
171
|
+
i,
|
|
172
|
+
n,
|
|
173
|
+
r,
|
|
174
|
+
t,
|
|
175
|
+
null
|
|
176
|
+
/* softNmsSigma */
|
|
177
|
+
), c = l.maxOutputSize, f = l.iouThreshold, m = l.scoreThreshold, [E, g] = await Promise.all([o.data(), i.data()]), { selectedIndices: y, validOutputs: M } = ws(E, g, c, f, m, s);
|
|
178
|
+
return o !== e && o.dispose(), i !== a && i.dispose(), {
|
|
179
|
+
selectedIndices: x(y, "int32"),
|
|
180
|
+
validOutputs: $(M, "int32")
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const $n = En;
|
|
184
|
+
function yn(e, a = "binary", n = !1, r = 0.5) {
|
|
185
|
+
const t = u(e, "image", "threshold"), s = 0.2989, o = 0.587, i = 0.114, l = t.shape[0] * t.shape[1];
|
|
186
|
+
let c = h(x([r]), 255), f, m, E, g;
|
|
187
|
+
if (p(t.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${t.rank}.`), p(t.shape[2] === 3 || t.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${t.shape[2]}.`), p(t.dtype === "int32" || t.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${t.dtype}.`), p(a === "otsu" || a === "binary", () => `Method must be binary or otsu, but was ${a}`), t.shape[2] === 3) {
|
|
188
|
+
[f, m, E] = ms(t, [1, 1, 1], -1);
|
|
189
|
+
const I = h(f, s), A = h(m, o), L = h(E, i);
|
|
190
|
+
g = G(G(I, A), L);
|
|
191
|
+
} else
|
|
192
|
+
g = e;
|
|
193
|
+
if (a === "otsu") {
|
|
194
|
+
const I = Zs(W(Os(g), "int32"), Vs([]), 256);
|
|
195
|
+
c = _n(I, l);
|
|
196
|
+
}
|
|
197
|
+
const y = n ? ls(g, c) : ts(g, c);
|
|
198
|
+
return W(h(y, 255), "int32");
|
|
199
|
+
}
|
|
200
|
+
function _n(e, a) {
|
|
201
|
+
let n = x([-1]), r = x([0]), t = x([0]), s, o, i, l, c, f;
|
|
202
|
+
for (let m = 0; m < e.size - 1; m++) {
|
|
203
|
+
s = T(e, 0, m + 1), o = T(e, m + 1), c = S(_(s), a), f = S(_(o), a);
|
|
204
|
+
const E = _(h(s, F(0, s.size)));
|
|
205
|
+
i = S(E, _(s));
|
|
206
|
+
const g = Ss(o.shape, s.size), y = G(F(0, o.size), g), M = h(o, y);
|
|
207
|
+
l = S(_(M), _(o));
|
|
208
|
+
const I = d(i, l), A = d(i, l), L = h(c, f);
|
|
209
|
+
t = h(h(L, I), A);
|
|
210
|
+
const P = ts(t, r);
|
|
211
|
+
r = q(P, t, r), n = q(P, x([m]), n);
|
|
212
|
+
}
|
|
213
|
+
return n;
|
|
214
|
+
}
|
|
215
|
+
const Nn = /* @__PURE__ */ b({ threshold_: yn });
|
|
216
|
+
function Sn(e, a, n = "nearest", r = "constant", t = 0, s) {
|
|
217
|
+
const o = u(e, "image", "transform", "float32"), i = u(a, "transforms", "transform", "float32");
|
|
218
|
+
p(o.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${o.rank}.`), p(i.rank === 2 && (i.shape[0] === o.shape[0] || i.shape[0] === 1) && i.shape[1] === 8, () => "Error in transform: Input transform should be batch x 8 or 1 x 8"), p(s == null || s.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${s}.`);
|
|
219
|
+
const l = { image: o, transforms: i }, c = { interpolation: n, fillMode: r, fillValue: t, outputShape: s };
|
|
220
|
+
return k.runKernel(ks, l, c);
|
|
221
|
+
}
|
|
222
|
+
const kn = /* @__PURE__ */ b({ transform_: Sn });
|
|
223
|
+
function In(e, a, n) {
|
|
224
|
+
const r = u(e, "a", "bandPart");
|
|
225
|
+
p(r.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${r.rank}.`);
|
|
226
|
+
const t = r.shape, [s, o] = r.shape.slice(-2);
|
|
227
|
+
let i, l;
|
|
228
|
+
typeof a == "number" ? (p(a % 1 === 0, () => `bandPart(): numLower must be an integer, got ${a}.`), p(a <= s, () => `bandPart(): numLower (${a}) must not be greater than the number of rows (${s}).`), i = u(a < 0 ? s : a, "numLower", "bandPart")) : (p(a.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = q(rs(a, 0), s, Q(a, s))), typeof n == "number" ? (p(n % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${n}.`), p(n <= o, () => `bandPart(): numUpper (${n}) must not be greater than the number of columns (${o}).`), l = u(n < 0 ? o : n, "numUpper", "bandPart")) : (p(n.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), l = q(rs(n, 0), o, Q(n, o)));
|
|
229
|
+
const c = O(F(0, s, 1, "int32"), [-1, 1]), f = F(0, o, 1, "int32"), m = d(c, f), E = Gs(ls(m, i), Bs(m, C(l))), g = Cs([s, o], r.dtype);
|
|
230
|
+
return O(Z(us(O(r, [-1, s, o])).map((y) => q(E, y, g))), t);
|
|
231
|
+
}
|
|
232
|
+
const Tn = /* @__PURE__ */ b({ bandPart_: In });
|
|
233
|
+
function Mn(e) {
|
|
234
|
+
let a;
|
|
235
|
+
if (Array.isArray(e)) {
|
|
236
|
+
a = !1, p(e != null && e.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
|
|
237
|
+
const t = e[0].shape[0];
|
|
238
|
+
for (let s = 1; s < e.length; ++s)
|
|
239
|
+
p(e[s].shape[0] === t, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${e[s].shape[0]} vs. ${t})`);
|
|
240
|
+
} else
|
|
241
|
+
a = !0, e = ms(e, e.shape[0], 0).map((t) => Ps(t, [0]));
|
|
242
|
+
p(e.length <= e[0].shape[0], () => `Gram-Schmidt: Number of vectors (${e.length}) exceeds number of dimensions (${e[0].shape[0]}).`);
|
|
243
|
+
const n = [], r = e;
|
|
244
|
+
for (let t = 0; t < e.length; ++t)
|
|
245
|
+
n.push(k.tidy(() => {
|
|
246
|
+
let s = r[t];
|
|
247
|
+
if (t > 0)
|
|
248
|
+
for (let o = 0; o < t; ++o) {
|
|
249
|
+
const i = h(_(h(n[o], s)), n[o]);
|
|
250
|
+
s = d(s, i);
|
|
251
|
+
}
|
|
252
|
+
return S(s, ps(s, "euclidean"));
|
|
253
|
+
}));
|
|
254
|
+
return a ? Z(n, 0) : n;
|
|
255
|
+
}
|
|
256
|
+
const xn = /* @__PURE__ */ b({ gramSchmidt_: Mn });
|
|
257
|
+
function An(e, a = !1) {
|
|
258
|
+
if (p(e.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${e.rank}`), e.rank === 2)
|
|
259
|
+
return cs(e, a);
|
|
260
|
+
{
|
|
261
|
+
const n = e.shape.slice(0, e.shape.length - 2).reduce((l, c) => l * c), r = us(O(e, [
|
|
262
|
+
n,
|
|
263
|
+
e.shape[e.shape.length - 2],
|
|
264
|
+
e.shape[e.shape.length - 1]
|
|
265
|
+
]), 0), t = [], s = [];
|
|
266
|
+
r.forEach((l) => {
|
|
267
|
+
const [c, f] = cs(l, a);
|
|
268
|
+
t.push(c), s.push(f);
|
|
269
|
+
});
|
|
270
|
+
const o = O(Z(t, 0), e.shape), i = O(Z(s, 0), e.shape);
|
|
271
|
+
return [o, i];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function cs(e, a = !1) {
|
|
275
|
+
return k.tidy(() => {
|
|
276
|
+
p(e.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${e.shape.length}D Tensor.`);
|
|
277
|
+
const n = e.shape[0], r = e.shape[1];
|
|
278
|
+
let t = Ks(n), s = K(e);
|
|
279
|
+
const o = J([[1]], [1, 1]);
|
|
280
|
+
let i = K(o);
|
|
281
|
+
const l = n >= r ? r : n;
|
|
282
|
+
for (let c = 0; c < l; ++c) {
|
|
283
|
+
const f = s, m = i, E = t;
|
|
284
|
+
[i, s, t] = k.tidy(() => {
|
|
285
|
+
const g = T(s, [c, c], [n - c, 1]), y = ps(g), M = T(s, [c, c], [1, 1]), I = q(ts(M, 0), J([[-1]]), J([[1]])), A = d(M, h(I, y)), L = S(g, A);
|
|
286
|
+
L.shape[0] === 1 ? i = K(o) : i = X([
|
|
287
|
+
o,
|
|
288
|
+
T(L, [1, 0], [L.shape[0] - 1, L.shape[1]])
|
|
289
|
+
], 0);
|
|
290
|
+
const P = C(S(w(I, A), y)), Y = T(s, [c, 0], [n - c, r]), U = h(P, i), es = as(i);
|
|
291
|
+
if (c === 0)
|
|
292
|
+
s = d(Y, w(U, w(es, Y)));
|
|
293
|
+
else {
|
|
294
|
+
const H = d(Y, w(U, w(es, Y)));
|
|
295
|
+
s = X([T(s, [0, 0], [c, r]), H], 0);
|
|
296
|
+
}
|
|
297
|
+
const os = as(U), v = T(t, [0, c], [n, t.shape[1] - c]);
|
|
298
|
+
if (c === 0)
|
|
299
|
+
t = d(v, w(w(v, i), os));
|
|
300
|
+
else {
|
|
301
|
+
const H = d(v, w(w(v, i), os));
|
|
302
|
+
t = X([T(t, [0, 0], [n, c]), H], 1);
|
|
303
|
+
}
|
|
304
|
+
return [i, s, t];
|
|
305
|
+
}), Is([f, m, E]);
|
|
306
|
+
}
|
|
307
|
+
return !a && n > r && (t = T(t, [0, 0], [n, r]), s = T(s, [0, 0], [r, r])), [t, s];
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
const wn = /* @__PURE__ */ b({ qr_: An });
|
|
311
|
+
var N;
|
|
312
|
+
(function(e) {
|
|
313
|
+
e[e.NONE = 0] = "NONE", e[e.MEAN = 1] = "MEAN", e[e.SUM = 2] = "SUM", e[e.SUM_BY_NONZERO_WEIGHTS = 3] = "SUM_BY_NONZERO_WEIGHTS";
|
|
314
|
+
})(N || (N = {}));
|
|
315
|
+
function On(e, a, n = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
316
|
+
const r = u(e, "losses", "computeWeightedLoss");
|
|
317
|
+
let t = null;
|
|
318
|
+
a != null && (t = u(a, "weights", "computeWeightedLoss"));
|
|
319
|
+
const s = t == null ? r : h(r, t);
|
|
320
|
+
if (n === N.NONE)
|
|
321
|
+
return s;
|
|
322
|
+
if (n === N.SUM)
|
|
323
|
+
return _(s);
|
|
324
|
+
if (n === N.MEAN) {
|
|
325
|
+
if (t == null)
|
|
326
|
+
return Ds(s);
|
|
327
|
+
{
|
|
328
|
+
const o = r.size / t.size, i = S(_(s), _(t));
|
|
329
|
+
return o > 1 ? S(i, $(o)) : i;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (n === N.SUM_BY_NONZERO_WEIGHTS) {
|
|
333
|
+
if (t == null)
|
|
334
|
+
return S(_(s), $(r.size));
|
|
335
|
+
{
|
|
336
|
+
const o = h(t, Ys(r.shape)), i = W(_(Ls(o, $(0))), "float32");
|
|
337
|
+
return S(_(s), i);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
throw Error(`Unknown reduction: ${n}`);
|
|
341
|
+
}
|
|
342
|
+
const D = /* @__PURE__ */ b({ computeWeightedLoss_: On });
|
|
343
|
+
function Gn(e, a, n, r = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
344
|
+
const t = u(e, "labels", "absoluteDifference"), s = u(a, "predictions", "absoluteDifference");
|
|
345
|
+
let o = null;
|
|
346
|
+
n != null && (o = u(n, "weights", "absoluteDifference")), B(t.shape, s.shape, "Error in absoluteDifference: ");
|
|
347
|
+
const i = ns(d(t, s));
|
|
348
|
+
return D(i, o, r);
|
|
349
|
+
}
|
|
350
|
+
const Bn = /* @__PURE__ */ b({ absoluteDifference_: Gn });
|
|
351
|
+
function Dn(e, a, n, r, t = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
352
|
+
const s = u(e, "labels", "cosineDistance"), o = u(a, "predictions", "cosineDistance");
|
|
353
|
+
let i = null;
|
|
354
|
+
r != null && (i = u(r, "weights", "cosineDistance")), B(s.shape, o.shape, "Error in cosineDistance: ");
|
|
355
|
+
const l = $(1), c = d(l, _(h(s, o), n, !0));
|
|
356
|
+
return D(c, i, t);
|
|
357
|
+
}
|
|
358
|
+
const Ln = /* @__PURE__ */ b({ cosineDistance_: Dn });
|
|
359
|
+
function Wn(e, a, n, r = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
360
|
+
let t = u(e, "labels", "hingeLoss");
|
|
361
|
+
const s = u(a, "predictions", "hingeLoss");
|
|
362
|
+
let o = null;
|
|
363
|
+
n != null && (o = u(n, "weights", "hingeLoss")), B(t.shape, s.shape, "Error in hingeLoss: ");
|
|
364
|
+
const i = $(1);
|
|
365
|
+
t = d(h($(2), t), i);
|
|
366
|
+
const l = fs(d(i, h(t, s)));
|
|
367
|
+
return D(l, o, r);
|
|
368
|
+
}
|
|
369
|
+
const Rn = /* @__PURE__ */ b({ hingeLoss_: Wn });
|
|
370
|
+
function qn(e, a, n, r = 1, t = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
371
|
+
const s = u(e, "labels", "huberLoss"), o = u(a, "predictions", "huberLoss");
|
|
372
|
+
let i = null;
|
|
373
|
+
n != null && (i = u(n, "weights", "huberLoss")), B(s.shape, o.shape, "Error in huberLoss: ");
|
|
374
|
+
const l = $(r), c = ns(d(o, s)), f = Q(c, l), m = d(c, f), E = G(h($(0.5), Ts(f)), h(l, m));
|
|
375
|
+
return D(E, i, t);
|
|
376
|
+
}
|
|
377
|
+
const zn = /* @__PURE__ */ b({ huberLoss_: qn });
|
|
378
|
+
function Vn(e, a, n, r = 1e-7, t = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
379
|
+
const s = u(e, "labels", "logLoss"), o = u(a, "predictions", "logLoss");
|
|
380
|
+
let i = null;
|
|
381
|
+
n != null && (i = u(n, "weights", "logLoss")), B(s.shape, o.shape, "Error in logLoss: ");
|
|
382
|
+
const l = $(1), c = $(r), f = C(h(s, is(G(o, c)))), m = h(d(l, s), is(G(d(l, o), c))), E = d(f, m);
|
|
383
|
+
return D(E, i, t);
|
|
384
|
+
}
|
|
385
|
+
const Cn = /* @__PURE__ */ b({ logLoss_: Vn });
|
|
386
|
+
function Pn(e, a, n, r = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
387
|
+
const t = u(e, "labels", "meanSquaredError"), s = u(a, "predictions", "meanSquaredError");
|
|
388
|
+
let o = null;
|
|
389
|
+
n != null && (o = u(n, "weights", "meanSquaredError")), B(t.shape, s.shape, "Error in meanSquaredError: ");
|
|
390
|
+
const i = Ws(t, s);
|
|
391
|
+
return D(i, o, r);
|
|
392
|
+
}
|
|
393
|
+
const Yn = /* @__PURE__ */ b({ meanSquaredError_: Pn });
|
|
394
|
+
function vn(e, a) {
|
|
395
|
+
const n = u(e, "labels", "sigmoidCrossEntropyWithLogits"), r = u(a, "logits", "sigmoidCrossEntropyWithLogits");
|
|
396
|
+
B(n.shape, r.shape, "Error in sigmoidCrossEntropyWithLogits: ");
|
|
397
|
+
const t = fs(r), s = h(r, n), o = Rs(ss(C(ns(r))));
|
|
398
|
+
return G(d(t, s), o);
|
|
399
|
+
}
|
|
400
|
+
function jn(e, a, n, r = 0, t = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
401
|
+
let s = u(e, "multiClassLabels", "sigmoidCrossEntropy");
|
|
402
|
+
const o = u(a, "logits", "sigmoidCrossEntropy");
|
|
403
|
+
let i = null;
|
|
404
|
+
if (n != null && (i = u(n, "weights", "sigmoidCrossEntropy")), B(s.shape, o.shape, "Error in sigmoidCrossEntropy: "), r > 0) {
|
|
405
|
+
const c = $(r), f = $(1), m = $(0.5);
|
|
406
|
+
s = G(h(s, d(f, c)), h(m, c));
|
|
407
|
+
}
|
|
408
|
+
const l = vn(s, o);
|
|
409
|
+
return D(l, i, t);
|
|
410
|
+
}
|
|
411
|
+
const Fn = /* @__PURE__ */ b({ sigmoidCrossEntropy_: jn });
|
|
412
|
+
function Zn(e, a, n = -1) {
|
|
413
|
+
if (n === -1 && (n = a.rank - 1), n !== a.rank - 1)
|
|
414
|
+
throw Error(`Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank ${a.rank} and dim was ${n}`);
|
|
415
|
+
return Ms((t, s, o) => {
|
|
416
|
+
const l = vs(s, [n], !0), c = d(W(s, "float32"), l);
|
|
417
|
+
o([t, c]);
|
|
418
|
+
const f = C(h(c, t));
|
|
419
|
+
return { value: _(f, [n]), gradFunc: (g, y) => {
|
|
420
|
+
const [M, I] = y, A = js(g.shape, [n]);
|
|
421
|
+
return [
|
|
422
|
+
h(O(g, A), d(W(M, "float32"), ss(I))),
|
|
423
|
+
h(O(g, A), d(ss(I), W(M, "float32")))
|
|
424
|
+
];
|
|
425
|
+
} };
|
|
426
|
+
})(e, a);
|
|
427
|
+
}
|
|
428
|
+
function Un(e, a, n, r = 0, t = N.SUM_BY_NONZERO_WEIGHTS) {
|
|
429
|
+
let s = u(e, "onehotLabels", "softmaxCrossEntropy");
|
|
430
|
+
const o = u(a, "logits", "softmaxCrossEntropy");
|
|
431
|
+
let i = null;
|
|
432
|
+
if (n != null && (i = u(n, "weights", "softmaxCrossEntropy")), B(s.shape, o.shape, "Error in softmaxCrossEntropy: "), r > 0) {
|
|
433
|
+
const c = $(r), f = $(1), m = $(s.shape[1]);
|
|
434
|
+
s = G(h(s, d(f, c)), S(c, m));
|
|
435
|
+
}
|
|
436
|
+
const l = Zn(s, o);
|
|
437
|
+
return D(l, i, t);
|
|
438
|
+
}
|
|
439
|
+
const Hn = /* @__PURE__ */ b({ softmaxCrossEntropy_: Un });
|
|
440
|
+
const $t = {
|
|
441
|
+
flipLeftRight: sn,
|
|
442
|
+
grayscaleToRGB: tn,
|
|
443
|
+
resizeNearestNeighbor: qs,
|
|
444
|
+
resizeBilinear: zs,
|
|
445
|
+
rgbToGrayscale: on,
|
|
446
|
+
rotateWithOffset: an,
|
|
447
|
+
cropAndResize: Js,
|
|
448
|
+
nonMaxSuppression: ln,
|
|
449
|
+
nonMaxSuppressionAsync: pn,
|
|
450
|
+
nonMaxSuppressionWithScore: fn,
|
|
451
|
+
nonMaxSuppressionWithScoreAsync: bn,
|
|
452
|
+
nonMaxSuppressionPadded: gn,
|
|
453
|
+
nonMaxSuppressionPaddedAsync: $n,
|
|
454
|
+
threshold: Nn,
|
|
455
|
+
transform: kn
|
|
456
|
+
}, yt = {
|
|
457
|
+
bandPart: Tn,
|
|
458
|
+
gramSchmidt: xn,
|
|
459
|
+
qr: wn
|
|
460
|
+
}, _t = {
|
|
461
|
+
absoluteDifference: Bn,
|
|
462
|
+
computeWeightedLoss: D,
|
|
463
|
+
cosineDistance: Ln,
|
|
464
|
+
hingeLoss: Rn,
|
|
465
|
+
huberLoss: zn,
|
|
466
|
+
logLoss: Cn,
|
|
467
|
+
meanSquaredError: Yn,
|
|
468
|
+
sigmoidCrossEntropy: Fn,
|
|
469
|
+
softmaxCrossEntropy: Hn
|
|
470
|
+
};
|
|
471
|
+
export {
|
|
472
|
+
_t as a,
|
|
473
|
+
Ks as e,
|
|
474
|
+
$t as i,
|
|
475
|
+
yt as l
|
|
476
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { u as o, e as u } from "./index-DOvlwCh-.js";
|
|
2
|
+
import { isPackedTensor as i } from "./utilities/packed.js";
|
|
3
|
+
import { s as t } from "./slice-BfEGSH82.js";
|
|
4
|
+
const s = {
|
|
5
|
+
kernelName: "Unpack16",
|
|
6
|
+
inputsToSave: [],
|
|
7
|
+
outputsToSave: [],
|
|
8
|
+
gradFunc: (n) => ({
|
|
9
|
+
x: () => d(n)
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
o(s);
|
|
13
|
+
function p(n, a = 1, e = !1) {
|
|
14
|
+
if (!i(n))
|
|
15
|
+
return n;
|
|
16
|
+
const r = u().runKernel("Unpack16", { x: n }, { scaling: a });
|
|
17
|
+
return e && n.dispose(), r;
|
|
18
|
+
}
|
|
19
|
+
const c = {
|
|
20
|
+
kernelName: "Pack16",
|
|
21
|
+
inputsToSave: [],
|
|
22
|
+
outputsToSave: [],
|
|
23
|
+
gradFunc: (n, a, e) => ({
|
|
24
|
+
x: () => {
|
|
25
|
+
const r = p(n);
|
|
26
|
+
return e.originalShape && e.padding && e.padding > 0 ? t(r, new Array(r.shape.length).fill(0), e.originalShape) : r;
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
o(c);
|
|
31
|
+
function d(n, a = 1, e = 0) {
|
|
32
|
+
return u().runKernel("Pack16", { x: n }, { scaling: a, padding: e });
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
s as a,
|
|
36
|
+
c as b,
|
|
37
|
+
d as p,
|
|
38
|
+
p as u
|
|
39
|
+
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import "../webgpu_util-
|
|
3
|
-
import { W as
|
|
4
|
-
import { compileProgram as
|
|
5
|
-
import { m } from "../webgpu_program-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const i = h.limits.maxComputeWorkgroupsPerDimension, t = s.dispatchLayout, a = s.dispatch;
|
|
1
|
+
import { h as c, i as l, j as m, l as n } from "../index-DOvlwCh-.js";
|
|
2
|
+
import "../webgpu_util-RxEF33Rj.js";
|
|
3
|
+
import { W as P } from "../backend_webgpu-DE3ACOLx.js";
|
|
4
|
+
import { compileProgram as y } from "./webgpu_program.js";
|
|
5
|
+
import { m as M } from "../webgpu_program-DuOXPQol.js";
|
|
6
|
+
const b = (o, s) => {
|
|
7
|
+
const i = o.limits.maxComputeWorkgroupsPerDimension, t = s.dispatchLayout, a = s.dispatch;
|
|
9
8
|
if (a.every((r) => r <= i))
|
|
10
9
|
return a;
|
|
11
10
|
n(
|
|
@@ -18,32 +17,32 @@ const b = (h, s) => {
|
|
|
18
17
|
() => "Total dispatch size exceeds WebGPU maximum."
|
|
19
18
|
), [e, e, e]) : [e, e, 1];
|
|
20
19
|
};
|
|
21
|
-
class
|
|
20
|
+
class z extends P {
|
|
22
21
|
subgroupMaxSize;
|
|
23
22
|
subgroupMinSize;
|
|
24
23
|
constructor(s, i) {
|
|
25
24
|
super(s, i), this.subgroupMaxSize = i?.subgroupMaxSize ?? 0, this.subgroupMinSize = i?.subgroupMinSize ?? 0;
|
|
26
25
|
}
|
|
27
26
|
runWebGPUProgram(s, i, t, a, e) {
|
|
28
|
-
if (e || (e = this.makeTensorInfo(s.outputShape, t)),
|
|
29
|
-
return this.tensorMap.get(e.dataId).values =
|
|
27
|
+
if (e || (e = this.makeTensorInfo(s.outputShape, t)), c(e.shape) === 0)
|
|
28
|
+
return this.tensorMap.get(e.dataId).values = l(e.dtype, 0), e;
|
|
30
29
|
this.uploadToGPU(e.dataId), s.dispatch = b(this.device, s);
|
|
31
|
-
const r = i.map((
|
|
32
|
-
if (
|
|
30
|
+
const r = i.map((h, p) => {
|
|
31
|
+
if (h.dtype === "complex64")
|
|
33
32
|
throw new Error(
|
|
34
33
|
"GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts."
|
|
35
34
|
);
|
|
36
|
-
return this.uploadToGPU(
|
|
35
|
+
return this.uploadToGPU(h.dataId), {
|
|
37
36
|
// Returning dtype from tensorMap because it reflects dtype
|
|
38
37
|
// of underlying buffer, rather than abstract dtype.
|
|
39
|
-
dtype: this.tensorMap.get(
|
|
40
|
-
shape:
|
|
38
|
+
dtype: this.tensorMap.get(h.dataId).dtype,
|
|
39
|
+
shape: h.shape,
|
|
41
40
|
name: s.variableNames[p]
|
|
42
41
|
};
|
|
43
42
|
});
|
|
44
|
-
s.shaderKey =
|
|
45
|
-
const d =
|
|
46
|
-
return s.shaderKey in this.pipelineCache || (this.pipelineCache[s.shaderKey] =
|
|
43
|
+
s.shaderKey = M(s, r, e);
|
|
44
|
+
const d = m().getBool("WEBGPU_ENGINE_COMPILE_ONLY");
|
|
45
|
+
return s.shaderKey in this.pipelineCache || (this.pipelineCache[s.shaderKey] = y(
|
|
47
46
|
this.device,
|
|
48
47
|
s,
|
|
49
48
|
r,
|
|
@@ -53,5 +52,5 @@ class U extends c {
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
export {
|
|
56
|
-
|
|
55
|
+
z as default
|
|
57
56
|
};
|