@genai-fi/nanogpt 0.10.2 → 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.
Files changed (249) hide show
  1. package/dist/Generator.js +11761 -171
  2. package/dist/{RealDiv-zz7FpkKX.js → RealDiv-KAPDe8zB.js} +23 -25
  3. package/dist/Reshape-BYkmUnAv.js +14 -0
  4. package/dist/{Reshape-CHdUjC72.js → Reshape-Zt6eb7yh.js} +18 -20
  5. package/dist/TeachableLLM.js +10 -11
  6. package/dist/{axis_util-BsIr9ZNu.js → axis_util-BaG7mf5A.js} +3 -3
  7. package/dist/backend.js +2 -2
  8. package/dist/{backend_util-B1XRLuq9.js → backend_util-RCe-rHaj.js} +72 -73
  9. package/dist/{backend_webgpu-CqpfEImu.js → backend_webgpu-DE3ACOLx.js} +45 -47
  10. package/dist/broadcast_to-B3eYlZm7.js +28 -0
  11. package/dist/checks/appendCache.js +2 -2
  12. package/dist/checks/attentionMask.js +3 -3
  13. package/dist/checks/gelu.js +2 -2
  14. package/dist/checks/matMulGelu.js +7 -11
  15. package/dist/checks/normRMS.js +9 -9
  16. package/dist/checks/normRMSGrad.js +3 -3
  17. package/dist/checks/packUnpack.js +2 -2
  18. package/dist/checks/qkv.js +12 -13
  19. package/dist/checks/rope.js +2 -2
  20. package/dist/clip_by_value-BnO7-a88.js +12 -0
  21. package/dist/complex-DjxcVmoX.js +11 -0
  22. package/dist/concat-BV8bt5H-.js +17 -0
  23. package/dist/{concat_util-iBYIyuQe.js → concat_util-DpW8mL_l.js} +1 -1
  24. package/dist/{dataset-D2P7rHAw.js → dataset-BcwmTGYc.js} +137 -139
  25. package/dist/dropout-BcvN9JYi.js +92 -0
  26. package/dist/expand_dims-DT4tEPwA.js +11 -0
  27. package/dist/{exports_initializers-CZSUJoVE.js → exports_initializers-Hta_rEnm.js} +1 -1
  28. package/dist/floor-D5QdR_le.js +9 -0
  29. package/dist/gather-D3JcZUaI.js +9 -0
  30. package/dist/{gelu-Bmhopi0J.js → gelu-CjNPL4OH.js} +10 -11
  31. package/dist/{gpgpu_math-DsCcikas.js → gpgpu_math-DAOmgtXR.js} +841 -1015
  32. package/dist/{index-DRyE072i.js → index-BwexR4lA.js} +262 -263
  33. package/dist/index-DOvlwCh-.js +3520 -0
  34. package/dist/{kernel_funcs_utils-CWfOAPGO.js → kernel_funcs_utils-CCzYdUZg.js} +130 -132
  35. package/dist/layers/BaseLayer.js +15 -16
  36. package/dist/layers/CausalSelfAttention.js +6 -6
  37. package/dist/layers/MLP.js +4 -4
  38. package/dist/layers/PositionEmbedding.js +7 -7
  39. package/dist/layers/RMSNorm.js +3 -3
  40. package/dist/layers/RoPECache.js +9 -9
  41. package/dist/layers/TiedEmbedding.js +6 -6
  42. package/dist/layers/TransformerBlock.js +1 -1
  43. package/dist/loader/loadTransformers.js +1 -1
  44. package/dist/loader/oldZipLoad.js +13 -14
  45. package/dist/log_sum_exp-ngO0-4pK.js +39 -0
  46. package/dist/main.js +49 -50
  47. package/dist/{matMul16-fEAJ4smh.js → matMul16-BWRSOCWB.js} +14 -15
  48. package/dist/matMulGelu-CzfgT6Wq.js +163 -0
  49. package/dist/mat_mul-SjpJRLyL.js +11 -0
  50. package/dist/mod-AnXEvvpo.js +11 -0
  51. package/dist/models/NanoGPTV1.js +2 -2
  52. package/dist/models/model.js +13 -14
  53. package/dist/ones-D2rT0xk2.js +14 -0
  54. package/dist/ops/adamAdjust.js +1 -1
  55. package/dist/ops/adamMoments.js +1 -1
  56. package/dist/ops/add16.js +1 -1
  57. package/dist/ops/appendCache.js +3 -3
  58. package/dist/ops/attentionMask.js +1 -1
  59. package/dist/ops/concat16.js +2 -2
  60. package/dist/ops/cpu/adamAdjust.js +13 -14
  61. package/dist/ops/cpu/adamMoments.js +6 -7
  62. package/dist/ops/cpu/appendCache.js +7 -8
  63. package/dist/ops/cpu/attentionMask.js +7 -7
  64. package/dist/ops/cpu/fusedSoftmax.js +10 -11
  65. package/dist/ops/cpu/gatherSub.js +9 -10
  66. package/dist/ops/cpu/gelu.js +9 -10
  67. package/dist/ops/cpu/matMul16.js +6 -7
  68. package/dist/ops/cpu/matMulGelu.js +5 -6
  69. package/dist/ops/cpu/matMulMul.js +3 -4
  70. package/dist/ops/cpu/mulDropout.js +3 -4
  71. package/dist/ops/cpu/normRMS.js +10 -11
  72. package/dist/ops/cpu/qkv.js +8 -9
  73. package/dist/ops/cpu/rope.js +5 -6
  74. package/dist/ops/cpu/scatterSub.js +17 -19
  75. package/dist/ops/dot16.js +2 -2
  76. package/dist/ops/gatherSub.js +1 -1
  77. package/dist/ops/gelu.js +2 -2
  78. package/dist/ops/grads/add16.js +11 -12
  79. package/dist/ops/grads/attentionMask.js +5 -6
  80. package/dist/ops/grads/gelu.js +3 -4
  81. package/dist/ops/grads/matMul16.js +4 -5
  82. package/dist/ops/grads/matMulGelu.js +9 -10
  83. package/dist/ops/grads/normRMS.js +7 -8
  84. package/dist/ops/grads/pack16.js +4 -5
  85. package/dist/ops/grads/qkv.js +17 -19
  86. package/dist/ops/grads/rope.js +3 -5
  87. package/dist/ops/grads/softmax16.js +3 -4
  88. package/dist/ops/grads/unpack16.js +3 -4
  89. package/dist/ops/grads/utils.d.ts +1 -0
  90. package/dist/ops/grads/utils.js +8 -4
  91. package/dist/ops/matMul16.js +3 -3
  92. package/dist/ops/matMulGelu.js +2 -2
  93. package/dist/ops/matMulMul.js +1 -1
  94. package/dist/ops/mul16.js +1 -1
  95. package/dist/ops/mulDrop.js +1 -1
  96. package/dist/ops/normRMS.js +1 -1
  97. package/dist/ops/pack16.js +3 -4
  98. package/dist/ops/qkv.js +4 -8
  99. package/dist/ops/reshape16.js +14 -16
  100. package/dist/ops/rope.d.ts +1 -1
  101. package/dist/ops/rope.js +3 -8
  102. package/dist/ops/scatterSub.js +1 -1
  103. package/dist/ops/slice16.js +2 -2
  104. package/dist/ops/softmax16.js +5 -8
  105. package/dist/ops/sub16.js +1 -1
  106. package/dist/ops/sum16.js +2 -2
  107. package/dist/ops/transpose16.js +23 -24
  108. package/dist/ops/unpack16.js +2 -2
  109. package/dist/ops/webgl/adamAdjust.js +2 -3
  110. package/dist/ops/webgl/adamMoments.js +1 -2
  111. package/dist/ops/webgl/appendCache.js +1 -2
  112. package/dist/ops/webgl/attentionMask.js +4 -5
  113. package/dist/ops/webgl/fusedSoftmax.js +4 -6
  114. package/dist/ops/webgl/gatherSub.js +6 -7
  115. package/dist/ops/webgl/gelu.js +2 -3
  116. package/dist/ops/webgl/log.js +11 -12
  117. package/dist/ops/webgl/matMul16.js +10 -11
  118. package/dist/ops/webgl/matMulGelu.js +7 -111
  119. package/dist/ops/webgl/matMulMul.js +9 -10
  120. package/dist/ops/webgl/mulDropout.js +8 -9
  121. package/dist/ops/webgl/normRMS.js +2 -3
  122. package/dist/ops/webgl/qkv.js +5 -6
  123. package/dist/ops/webgl/rope.js +7 -8
  124. package/dist/ops/webgl/scatterSub.js +5 -6
  125. package/dist/ops/webgpu/adamAdjust.js +10 -12
  126. package/dist/ops/webgpu/adamMoments.js +8 -10
  127. package/dist/ops/webgpu/add16.js +8 -9
  128. package/dist/ops/webgpu/appendCache.js +23 -25
  129. package/dist/ops/webgpu/attentionMask.js +8 -10
  130. package/dist/ops/webgpu/attentionMask32_program.js +2 -2
  131. package/dist/ops/webgpu/concat16.js +12 -14
  132. package/dist/ops/webgpu/gatherSub.js +11 -13
  133. package/dist/ops/webgpu/gelu.js +28 -29
  134. package/dist/ops/webgpu/matMul16.js +26 -28
  135. package/dist/ops/webgpu/matMul16_program.js +4 -5
  136. package/dist/ops/webgpu/mul16.js +9 -10
  137. package/dist/ops/webgpu/normRMS.js +15 -17
  138. package/dist/ops/webgpu/normRMSGrad.js +21 -28
  139. package/dist/ops/webgpu/pack16.js +12 -13
  140. package/dist/ops/webgpu/pack16_program.js +2 -2
  141. package/dist/ops/webgpu/qkv.js +16 -18
  142. package/dist/ops/webgpu/rope.js +25 -27
  143. package/dist/ops/webgpu/scatterSub.js +7 -9
  144. package/dist/ops/webgpu/slice16.js +21 -23
  145. package/dist/ops/webgpu/softmax16.js +17 -19
  146. package/dist/ops/webgpu/softmax16_program.js +2 -2
  147. package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
  148. package/dist/ops/webgpu/softmax16grad.js +7 -8
  149. package/dist/ops/webgpu/sub16.js +7 -8
  150. package/dist/ops/webgpu/sum16.js +18 -20
  151. package/dist/ops/webgpu/transpose16.js +19 -20
  152. package/dist/ops/webgpu/transpose16_program.js +2 -2
  153. package/dist/ops/webgpu/transpose16_shared_program.js +11 -12
  154. package/dist/ops/webgpu/unpack16.js +3 -4
  155. package/dist/ops/webgpu/utils/binary_op.js +7 -8
  156. package/dist/ops/webgpu/utils/reductions.js +14 -22
  157. package/dist/ops-B5yanEdW.js +476 -0
  158. package/dist/pack16-nQ6JaLo-.js +39 -0
  159. package/dist/patches/webgpu_backend.js +19 -20
  160. package/dist/patches/webgpu_base.js +1 -1
  161. package/dist/patches/webgpu_program.js +21 -22
  162. package/dist/{random_width-BVV9HveY.js → random_width-or-CEftb.js} +2506 -2761
  163. package/dist/range-BklejeeW.js +10 -0
  164. package/dist/relu-CP0ZcxWO.js +9 -0
  165. package/dist/reshape-ByE68wS9.js +9 -0
  166. package/dist/resize_nearest_neighbor-B19mCEg2.js +175 -0
  167. package/dist/rope-Ir4mTyD1.js +24 -0
  168. package/dist/{scatter_nd_util-C7zXRT_h.js → scatter_nd_util-lvSiX8q4.js} +1 -1
  169. package/dist/selu_util-kbhpTdYD.js +44 -0
  170. package/dist/{shared-CHhxz-O5.js → shared-DT1TkE6w.js} +1 -1
  171. package/dist/{shared-D2NP_CpY.js → shared-dntlHIDQ.js} +343 -345
  172. package/dist/slice-BfEGSH82.js +12 -0
  173. package/dist/{slice_util-DyjSAD0u.js → slice_util-uTKwiEpW.js} +1 -1
  174. package/dist/{softmax-C9JQEtnO.js → softmax-CA5jFsLR.js} +4 -5
  175. package/dist/split-CVLc0w--.js +9 -0
  176. package/dist/squeeze-C7Z2srUo.js +10 -0
  177. package/dist/stack-Cf4n9h0N.js +11 -0
  178. package/dist/step-CINUs5QB.js +261 -0
  179. package/dist/sum-DWAtNGez.js +11 -0
  180. package/dist/tensor-DJoc7gJU.js +8 -0
  181. package/dist/tensor1d-D11P_7Dp.js +11 -0
  182. package/dist/{tensor2d-CSB4KOb0.js → tensor2d-Bs9wZRc7.js} +6 -7
  183. package/dist/{tensor4d-D7bLqGqz.js → tensor4d-BARPdTaS.js} +6 -7
  184. package/dist/{tfjs_backend-CNkSTL0c.js → tfjs_backend-y1cvNhLA.js} +255 -264
  185. package/dist/tile-mbfagpsB.js +11 -0
  186. package/dist/training/Adam.js +2 -2
  187. package/dist/training/AdamExt.js +1 -1
  188. package/dist/training/DatasetBuilder.js +2 -2
  189. package/dist/training/FullTrainer.js +1 -1
  190. package/dist/training/Trainer.js +2 -2
  191. package/dist/training/sparseCrossEntropy.js +5 -5
  192. package/dist/transpose-ClWiBS_b.js +36 -0
  193. package/dist/unsorted_segment_sum-BDDhB_E6.js +277 -0
  194. package/dist/utilities/dummy.js +3 -3
  195. package/dist/utilities/multinomialCPU.js +2 -2
  196. package/dist/utilities/packed.d.ts +1 -4
  197. package/dist/utilities/packed.js +10 -745
  198. package/dist/utilities/performance.js +1 -1
  199. package/dist/utilities/profile.js +1 -1
  200. package/dist/utilities/safetensors.js +2 -2
  201. package/dist/utilities/sentences.js +5 -5
  202. package/dist/utilities/weights.js +2 -2
  203. package/dist/{variable-DzfrwYuP.js → variable-WawDEaAb.js} +1 -1
  204. package/dist/{webgpu_program-DzaQiqel.js → webgpu_program-DuOXPQol.js} +178 -172
  205. package/dist/{webgpu_util-0_ubCEHJ.js → webgpu_util-RxEF33Rj.js} +34 -35
  206. package/dist/zeros-KnWaWf-X.js +13 -0
  207. package/dist/zeros_like-DvE73F4e.js +721 -0
  208. package/package.json +4 -2
  209. package/dist/Reshape-CDVLyVfz.js +0 -16
  210. package/dist/broadcast_to-B0ChcDaz.js +0 -30
  211. package/dist/complex-BBiRlsVq.js +0 -13
  212. package/dist/concat-DmBLPVGC.js +0 -19
  213. package/dist/dropout-B1x1kYMa.js +0 -99
  214. package/dist/expand_dims-ouvfxQ1n.js +0 -13
  215. package/dist/gather-CH9sdacz.js +0 -10
  216. package/dist/index-D6Q1lPZO.js +0 -2157
  217. package/dist/log_sum_exp-D3ftBNY5.js +0 -41
  218. package/dist/mat_mul-C59XWcJd.js +0 -12
  219. package/dist/mod-DESSvHIU.js +0 -12
  220. package/dist/mulmat_packed_gpu-Coh6qbJk.js +0 -55
  221. package/dist/ones-jU9jlQvM.js +0 -15
  222. package/dist/ops-BFDtP6th.js +0 -645
  223. package/dist/pack16-CmVZs6af.js +0 -41
  224. package/dist/patches/PackedTensor.d.ts +0 -12
  225. package/dist/patches/PackedTensor.js +0 -11
  226. package/dist/patches/engine.d.ts +0 -261
  227. package/dist/patches/engine.js +0 -12
  228. package/dist/patches/tape.d.ts +0 -12
  229. package/dist/patches/tape.js +0 -5
  230. package/dist/range-ZZZD60Fx.js +0 -11
  231. package/dist/reciprocal-CrYlsAGD.js +0 -10
  232. package/dist/register_all_kernels-nvj2k7OC.js +0 -12307
  233. package/dist/relu-BYDneVPn.js +0 -10
  234. package/dist/reshape-CaPQzFvz.js +0 -10
  235. package/dist/rope-s4W2XO9B.js +0 -32
  236. package/dist/selu_util-BGPXmd4B.js +0 -303
  237. package/dist/sin-Djs4aQiu.js +0 -16
  238. package/dist/slice-DvovR5wq.js +0 -13
  239. package/dist/split-DBck65sX.js +0 -10
  240. package/dist/squeeze-C00Ipm_7.js +0 -11
  241. package/dist/stack-ChnHwRpX.js +0 -13
  242. package/dist/sum-ywRJj3Zr.js +0 -12
  243. package/dist/tensor-0r5yOo2R.js +0 -8
  244. package/dist/tensor-CzmOBsdf.js +0 -909
  245. package/dist/tensor1d-BlUT89BP.js +0 -12
  246. package/dist/tensor_util-DfwaWayG.js +0 -523
  247. package/dist/tile-CR074jmp.js +0 -13
  248. package/dist/transpose-DH4gmHvu.js +0 -38
  249. package/dist/zeros-DBFVbpv5.js +0 -14
@@ -1,645 +0,0 @@
1
- import { A as f, B as c, E as d, j as B, S as A, o as ls, p as Ns, b as y, T as bs, J as Is, G as D, m as b, n as O, l as S, i as Ss, c as g, D as Q, d as Ts, w as Ms } from "./index-D6Q1lPZO.js";
2
- import { ag as As, ah as ws, ai as qs, aj as Ds, m as v, ak as Bs, al as xs, am as Gs, an as Os, ao as Ls, ap as zs, aq as Rs, ar as Ws, as as vs, at as Cs, au as Ks, av as Vs, aw as js, ax as Ps, ay as Ys, az as Fs, aA as Us, aB as Zs, aC as Hs, aD as Js, aE as Xs } from "./tensor_util-DfwaWayG.js";
3
- import { a as p, p as Qs, j as L } from "./tensor-CzmOBsdf.js";
4
- import { t as U } from "./tile-CR074jmp.js";
5
- import { e as W } from "./expand_dims-ouvfxQ1n.js";
6
- import { t as q } from "./tensor1d-BlUT89BP.js";
7
- import { n as sn, a as nn, b as en } from "./non_max_suppression_impl-B2W7YjZB.js";
8
- import { r as I } from "./reshape-CaPQzFvz.js";
9
- import { s as ds } from "./split-DBck65sX.js";
10
- import { s as E } from "./sum-ywRJj3Zr.js";
11
- import { b as ss } from "./broadcast_to-B0ChcDaz.js";
12
- import { s as M } from "./slice-DvovR5wq.js";
13
- import { r as Z } from "./range-ZZZD60Fx.js";
14
- import { t as tn } from "./tensor-0r5yOo2R.js";
15
- import { n as j, t as us } from "./transpose-DH4gmHvu.js";
16
- import { s as H } from "./stack-ChnHwRpX.js";
17
- import { z as rn } from "./zeros-DBFVbpv5.js";
18
- import { e as gs } from "./axis_util-BsIr9ZNu.js";
19
- import { m as ns, a as ps, e as rs, l as on } from "./log_sum_exp-D3ftBNY5.js";
20
- import { s as an } from "./squeeze-C00Ipm_7.js";
21
- import { c as es } from "./concat-DmBLPVGC.js";
22
- import { m as G } from "./mat_mul-C59XWcJd.js";
23
- import { t as ts } from "./tensor2d-CSB4KOb0.js";
24
- import { o as cn } from "./ones-jU9jlQvM.js";
25
- import { r as $s } from "./relu-BYDneVPn.js";
26
- function ln(e, r, s) {
27
- const t = c(e, "x", "bincount"), n = c(r, "weights", "bincount");
28
- p(t.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${t.dtype}`), p(s >= 0, () => `size must be non-negative, but got ${s}.`), p(n.size === t.size || n.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${t.shape}, weights shape: ${n.shape}.`);
29
- const o = { x: t, weights: n }, a = { size: s };
30
- return d.runKernel(As, o, a);
31
- }
32
- const un = /* @__PURE__ */ f({ bincount_: ln });
33
- function pn(e, r, s) {
34
- const t = c(r, "a", "where"), n = c(s, "b", "where"), o = c(e, "condition", "where", "bool"), a = B(B(o.shape, t.shape), n.shape), i = ss(o, a), u = ss(t, a), l = ss(n, a), m = {
35
- condition: i,
36
- t: u,
37
- e: l
38
- };
39
- return d.runKernel(ws, m);
40
- }
41
- const C = /* @__PURE__ */ f({ where_: pn });
42
- function fn(e, ...r) {
43
- const s = r.map((n, o) => c(n, `tensors${o}`, "einsum")), t = { equation: e };
44
- return d.runKernel(qs, s, t);
45
- }
46
- const V = /* @__PURE__ */ f({ einsum_: fn });
47
- function mn(e, r = null, s = !1) {
48
- const n = { x: c(e, "x", "min") }, o = { axis: r, keepDims: s };
49
- return d.runKernel(Ds, n, o);
50
- }
51
- const fs = /* @__PURE__ */ f({ min_: mn });
52
- function hn(e, r = "euclidean", s = null, t = !1) {
53
- e = c(e, "x", "norm");
54
- const n = Es(e, r, s);
55
- let o = n.shape;
56
- if (t) {
57
- const a = Qs(s, e.shape);
58
- o = gs(n.shape, a);
59
- }
60
- return I(n, o);
61
- }
62
- function Es(e, r, s = null) {
63
- if (e.rank === 0)
64
- return A(e);
65
- if (e.rank !== 1 && s === null)
66
- return Es(I(e, [-1]), r, s);
67
- if (e.rank === 1 || typeof s == "number" || Array.isArray(s) && s.length === 1) {
68
- if (r === 1)
69
- return E(A(e), s);
70
- if (r === 1 / 0)
71
- return ns(A(e), s);
72
- if (r === -1 / 0)
73
- return fs(A(e), s);
74
- if (r === "euclidean" || r === 2)
75
- return ls(E(Ns(A(e), y(2, "int32")), s));
76
- throw new Error(`Error in norm: invalid ord value: ${r}`);
77
- }
78
- if (Array.isArray(s) && s.length === 2) {
79
- if (r === 1)
80
- return ns(E(A(e), s[0]), s[1] - 1);
81
- if (r === 1 / 0)
82
- return ns(E(A(e), s[1]), s[0]);
83
- if (r === -1 / 0)
84
- return fs(E(A(e), s[1]), s[0]);
85
- if (r === "fro" || r === "euclidean")
86
- return ls(E(bs(e), s));
87
- throw new Error(`Error in norm: invalid ord value: ${r}`);
88
- }
89
- throw new Error(`Error in norm: invalid axis: ${s}`);
90
- }
91
- const _s = /* @__PURE__ */ f({ norm_: hn });
92
- function bn(e, r, s, t = "float32") {
93
- r == null && (r = e);
94
- const n = Is([e, r], t), o = e <= r ? e : r;
95
- for (let i = 0; i < o; ++i)
96
- n.set(1, i, i);
97
- const a = I(n.toTensor(), [e, r]);
98
- if (s == null)
99
- return a;
100
- if (s.length === 1)
101
- return U(W(a, 0), [s[0], 1, 1]);
102
- if (s.length === 2)
103
- return U(W(W(a, 0), 0), [s[0], s[1], 1, 1]);
104
- if (s.length === 3)
105
- return U(W(W(W(a, 0), 0), 0), [
106
- s[0],
107
- s[1],
108
- s[2],
109
- 1,
110
- 1
111
- ]);
112
- throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${s.length}D.`);
113
- }
114
- const dn = /* @__PURE__ */ f({ eye_: bn });
115
- function gn(e, r) {
116
- let s = c(e, "a", "greater", "string_or_numeric"), t = c(r, "b", "greater", "string_or_numeric");
117
- [s, t] = v(s, t), B(s.shape, t.shape);
118
- const n = { a: s, b: t };
119
- return d.runKernel(Bs, n);
120
- }
121
- const as = /* @__PURE__ */ f({ greater_: gn });
122
- function $n(e, r) {
123
- let s = c(e, "a", "greaterEqual", "string_or_numeric"), t = c(r, "b", "greaterEqual", "string_or_numeric");
124
- [s, t] = v(s, t), B(s.shape, t.shape);
125
- const n = { a: s, b: t };
126
- return d.runKernel(xs, n);
127
- }
128
- const En = /* @__PURE__ */ f({ greaterEqual_: $n });
129
- function _n(e, r) {
130
- let s = c(e, "a", "less", "string_or_numeric"), t = c(r, "b", "less", "string_or_numeric");
131
- [s, t] = v(s, t), B(s.shape, t.shape);
132
- const n = { a: s, b: t };
133
- return d.runKernel(Gs, n);
134
- }
135
- const ms = /* @__PURE__ */ f({ less_: _n });
136
- function yn(e, r) {
137
- let s = c(e, "a", "lessEqual", "string_or_numeric"), t = c(r, "b", "lessEqual", "string_or_numeric");
138
- [s, t] = v(s, t), B(s.shape, t.shape);
139
- const n = { a: s, b: t };
140
- return d.runKernel(Os, n);
141
- }
142
- const ys = /* @__PURE__ */ f({ lessEqual_: yn });
143
- function kn(e) {
144
- const s = { x: c(e, "x", "log1p") };
145
- return d.runKernel(Ls, s);
146
- }
147
- const Nn = /* @__PURE__ */ f({ log1p_: kn });
148
- function In(e, r) {
149
- const s = c(e, "a", "logicalAnd", "bool"), t = c(r, "b", "logicalAnd", "bool");
150
- B(s.shape, t.shape);
151
- const n = { a: s, b: t };
152
- return d.runKernel(zs, n);
153
- }
154
- const Sn = /* @__PURE__ */ f({ logicalAnd_: In });
155
- function Tn(e, r = null, s = !1) {
156
- const n = { x: c(e, "x", "mean") }, o = { axis: r, keepDims: s };
157
- return d.runKernel(Rs, n, o);
158
- }
159
- const Mn = /* @__PURE__ */ f({ mean_: Tn });
160
- function An(e, r) {
161
- let s = c(e, "a", "minimum"), t = c(r, "b", "minimum");
162
- [s, t] = v(s, t), s.dtype === "bool" && (s = D(s, "int32"), t = D(t, "int32")), B(s.shape, t.shape);
163
- const n = { a: s, b: t };
164
- return d.runKernel(Ws, n);
165
- }
166
- const os = /* @__PURE__ */ f({ minimum_: An });
167
- function wn(e, r) {
168
- let s = c(e, "a", "notEqual", "string_or_numeric"), t = c(r, "b", "notEqual", "string_or_numeric");
169
- [s, t] = v(s, t), B(s.shape, t.shape);
170
- const n = { a: s, b: t };
171
- return d.runKernel(vs, n);
172
- }
173
- const qn = /* @__PURE__ */ f({ notEqual_: wn });
174
- function Dn(e) {
175
- const s = { x: c(e, "x", "round") };
176
- return d.runKernel(Cs, s);
177
- }
178
- const Bn = /* @__PURE__ */ f({ round_: Dn });
179
- function xn(e, r) {
180
- let s = c(e, "a", "squaredDifference"), t = c(r, "b", "squaredDifference");
181
- [s, t] = v(s, t), B(s.shape, t.shape);
182
- const n = { a: s, b: t }, o = {};
183
- return d.runKernel(Ks, n, o);
184
- }
185
- const Gn = /* @__PURE__ */ f({ squaredDifference_: xn });
186
- function On(e, r = 0) {
187
- const s = c(e, "x", "unstack", "string_or_numeric");
188
- p(r >= -s.shape.length && r < s.shape.length, () => `Axis = ${r} is not in [-${s.shape.length}, ${s.shape.length})`);
189
- const t = { value: s }, n = { axis: r };
190
- return d.runKernel(Vs, t, n);
191
- }
192
- const ks = /* @__PURE__ */ f({ unstack_: On });
193
- function Ln(e, r, s, t, n = "bilinear", o = 0) {
194
- const a = c(e, "image", "cropAndResize"), i = c(r, "boxes", "cropAndResize", "float32"), u = c(s, "boxInd", "cropAndResize", "int32"), l = i.shape[0];
195
- p(a.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${a.rank}.`), p(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${l},4] but had shape ${i.shape}.`), p(u.rank === 1 && u.shape[0] === l, () => `Error in cropAndResize: boxInd must be have size [${l}] but had shape ${i.shape}.`), p(t.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${t.length}.`), p(t[0] >= 1 && t[1] >= 1, () => `cropSize must be atleast [1,1], but was ${t}`), p(n === "bilinear" || n === "nearest", () => `method must be bilinear or nearest, but was ${n}`);
196
- const m = { image: a, boxes: i, boxInd: u }, h = { method: n, extrapolationValue: o, cropSize: t };
197
- return d.runKernel(js, m, h);
198
- }
199
- const zn = /* @__PURE__ */ f({ cropAndResize_: Ln });
200
- function Rn(e) {
201
- const r = c(e, "image", "flipLeftRight", "float32");
202
- p(r.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${r.rank}.`);
203
- const s = { image: r };
204
- return d.runKernel(Ps, s, {});
205
- }
206
- const Wn = /* @__PURE__ */ f({ flipLeftRight_: Rn });
207
- function vn(e) {
208
- const r = c(e, "image", "grayscaleToRGB"), s = r.rank - 1, t = r.shape[s];
209
- p(r.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${r.rank}.`), p(t === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${t}.`);
210
- const n = new Array(r.rank);
211
- return n.fill(1, 0, s), n[s] = 3, U(r, n);
212
- }
213
- const Cn = /* @__PURE__ */ f({ grayscaleToRGB_: vn });
214
- function Kn(e) {
215
- const r = c(e, "image", "RGBToGrayscale"), s = r.rank - 1, t = r.shape[s];
216
- p(r.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${r.rank}.`), p(t === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${t}.`);
217
- const n = r.dtype, o = D(r, "float32"), a = q([0.2989, 0.587, 0.114]);
218
- let i;
219
- switch (r.rank) {
220
- case 2:
221
- i = V("ij,j->i", o, a);
222
- break;
223
- case 3:
224
- i = V("ijk,k->ij", o, a);
225
- break;
226
- case 4:
227
- i = V("ijkl,l->ijk", o, a);
228
- break;
229
- case 5:
230
- i = V("ijklm,m->ijkl", o, a);
231
- break;
232
- case 6:
233
- i = V("ijklmn,n->ijklm", o, a);
234
- break;
235
- default:
236
- throw new Error("Not a valid tensor rank.");
237
- }
238
- return i = W(i, -1), D(i, n);
239
- }
240
- const Vn = /* @__PURE__ */ f({ rgbToGrayscale_: Kn });
241
- function jn(e, r, s = 0, t = 0.5) {
242
- const n = c(e, "image", "rotateWithOffset", "float32");
243
- p(n.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${n.rank}.`);
244
- const o = { image: n }, a = { radians: r, fillValue: s, center: t };
245
- return d.runKernel(Ys, o, a);
246
- }
247
- const Pn = /* @__PURE__ */ f({ rotateWithOffset_: jn });
248
- function K(e, r, s, t, n, o) {
249
- t == null && (t = 0.5), n == null && (n = Number.NEGATIVE_INFINITY), o == null && (o = 0);
250
- const a = e.shape[0];
251
- return s = Math.min(s, a), p(0 <= t && t <= 1, () => `iouThreshold must be in [0, 1], but was '${t}'`), 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(r.rank === 1, () => "scores must be a 1D tensor"), p(r.shape[0] === a, () => `scores has incompatible shape with boxes. Expected ${a}, but was ${r.shape[0]}`), p(0 <= o && o <= 1, () => `softNmsSigma must be in [0, 1], but was '${o}'`), { maxOutputSize: s, iouThreshold: t, scoreThreshold: n, softNmsSigma: o };
252
- }
253
- function Yn(e, r, s, t = 0.5, n = Number.NEGATIVE_INFINITY) {
254
- const o = c(e, "boxes", "nonMaxSuppression", "float32"), a = c(r, "scores", "nonMaxSuppression", "float32"), i = K(o, a, s, t, n);
255
- s = i.maxOutputSize, t = i.iouThreshold, n = i.scoreThreshold;
256
- const u = { maxOutputSize: s, iouThreshold: t, scoreThreshold: n };
257
- return d.runKernel(Fs, { boxes: o, scores: a }, u);
258
- }
259
- const Fn = /* @__PURE__ */ f({ nonMaxSuppression_: Yn });
260
- async function Un(e, r, s, t = 0.5, n = Number.NEGATIVE_INFINITY) {
261
- const o = c(e, "boxes", "nonMaxSuppressionAsync"), a = c(r, "scores", "nonMaxSuppressionAsync"), i = K(o, a, s, t, n);
262
- s = i.maxOutputSize, t = i.iouThreshold, n = i.scoreThreshold;
263
- const u = await Promise.all([o.data(), a.data()]), l = u[0], m = u[1], { selectedIndices: h } = sn(l, m, s, t, n);
264
- return o !== e && o.dispose(), a !== r && a.dispose(), q(h, "int32");
265
- }
266
- const Zn = Un;
267
- function Hn(e, r, s, t = 0.5, n = Number.NEGATIVE_INFINITY, o = 0) {
268
- const a = c(e, "boxes", "nonMaxSuppression"), i = c(r, "scores", "nonMaxSuppression"), u = K(a, i, s, t, n, o);
269
- s = u.maxOutputSize, t = u.iouThreshold, n = u.scoreThreshold, o = u.softNmsSigma;
270
- const l = { boxes: a, scores: i }, m = { maxOutputSize: s, iouThreshold: t, scoreThreshold: n, softNmsSigma: o }, h = d.runKernel(Us, l, m);
271
- return { selectedIndices: h[0], selectedScores: h[1] };
272
- }
273
- const Jn = /* @__PURE__ */ f({ nonMaxSuppressionWithScore_: Hn });
274
- async function Xn(e, r, s, t = 0.5, n = Number.NEGATIVE_INFINITY, o = 0) {
275
- const a = c(e, "boxes", "nonMaxSuppressionAsync"), i = c(r, "scores", "nonMaxSuppressionAsync"), u = K(a, i, s, t, n, o);
276
- s = u.maxOutputSize, t = u.iouThreshold, n = u.scoreThreshold, o = u.softNmsSigma;
277
- const l = await Promise.all([a.data(), i.data()]), m = l[0], h = l[1], { selectedIndices: _, selectedScores: $ } = nn(m, h, s, t, n, o);
278
- return a !== e && a.dispose(), i !== r && i.dispose(), {
279
- selectedIndices: q(_, "int32"),
280
- selectedScores: q($)
281
- };
282
- }
283
- const Qn = Xn;
284
- function se(e, r, s, t = 0.5, n = Number.NEGATIVE_INFINITY, o = !1) {
285
- const a = c(e, "boxes", "nonMaxSuppression"), i = c(r, "scores", "nonMaxSuppression"), u = K(
286
- a,
287
- i,
288
- s,
289
- t,
290
- n,
291
- null
292
- /* softNmsSigma */
293
- ), l = u.maxOutputSize, m = u.iouThreshold, h = u.scoreThreshold, _ = { boxes: a, scores: i }, $ = {
294
- maxOutputSize: l,
295
- iouThreshold: m,
296
- scoreThreshold: h,
297
- padToMaxOutputSize: o
298
- }, k = d.runKernel(Zs, _, $);
299
- return { selectedIndices: k[0], validOutputs: k[1] };
300
- }
301
- const ne = /* @__PURE__ */ f({ nonMaxSuppressionPadded_: se });
302
- async function ee(e, r, s, t = 0.5, n = Number.NEGATIVE_INFINITY, o = !1) {
303
- const a = c(e, "boxes", "nonMaxSuppressionAsync"), i = c(r, "scores", "nonMaxSuppressionAsync"), u = K(
304
- a,
305
- i,
306
- s,
307
- t,
308
- n,
309
- null
310
- /* softNmsSigma */
311
- ), l = u.maxOutputSize, m = u.iouThreshold, h = u.scoreThreshold, [_, $] = await Promise.all([a.data(), i.data()]), { selectedIndices: k, validOutputs: w } = en(_, $, l, m, h, o);
312
- return a !== e && a.dispose(), i !== r && i.dispose(), {
313
- selectedIndices: q(k, "int32"),
314
- validOutputs: y(w, "int32")
315
- };
316
- }
317
- const te = ee;
318
- function re(e, r, s = !1, t = !1) {
319
- const n = c(e, "images", "resizeBilinear");
320
- p(n.rank === 3 || n.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${n.rank}.`), p(r.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${r}.`), p(t === !1 || s === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.");
321
- let o = n, a = !1;
322
- n.rank === 3 && (a = !0, o = I(n, [1, n.shape[0], n.shape[1], n.shape[2]]));
323
- const i = { images: o }, u = { alignCorners: s, halfPixelCenters: t, size: r }, l = d.runKernel(Hs, i, u);
324
- return a ? I(l, [l.shape[1], l.shape[2], l.shape[3]]) : l;
325
- }
326
- const oe = /* @__PURE__ */ f({ resizeBilinear_: re });
327
- function ae(e, r, s = !1, t = !1) {
328
- const n = c(e, "images", "resizeNearestNeighbor");
329
- p(n.rank === 3 || n.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${n.rank}.`), p(r.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${r}.`), p(n.dtype === "float32" || n.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), p(t === !1 || s === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.");
330
- let o = n, a = !1;
331
- n.rank === 3 && (a = !0, o = I(n, [1, n.shape[0], n.shape[1], n.shape[2]]));
332
- const i = { images: o }, u = { alignCorners: s, halfPixelCenters: t, size: r }, l = d.runKernel(Js, i, u);
333
- return a ? I(l, [l.shape[1], l.shape[2], l.shape[3]]) : l;
334
- }
335
- const ie = /* @__PURE__ */ f({ resizeNearestNeighbor_: ae });
336
- function ce(e, r = "binary", s = !1, t = 0.5) {
337
- const n = c(e, "image", "threshold"), o = 0.2989, a = 0.587, i = 0.114, u = n.shape[0] * n.shape[1];
338
- let l = b(q([t]), 255), m, h, _, $;
339
- if (p(n.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${n.rank}.`), p(n.shape[2] === 3 || n.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${n.shape[2]}.`), p(n.dtype === "int32" || n.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${n.dtype}.`), p(r === "otsu" || r === "binary", () => `Method must be binary or otsu, but was ${r}`), n.shape[2] === 3) {
340
- [m, h, _] = ds(n, [1, 1, 1], -1);
341
- const T = b(m, o), x = b(h, a), R = b(_, i);
342
- $ = O(O(T, x), R);
343
- } else
344
- $ = e;
345
- if (r === "otsu") {
346
- const T = un(D(Bn($), "int32"), tn([]), 256);
347
- l = le(T, u);
348
- }
349
- const k = s ? ys($, l) : as($, l);
350
- return D(b(k, 255), "int32");
351
- }
352
- function le(e, r) {
353
- let s = q([-1]), t = q([0]), n = q([0]), o, a, i, u, l, m;
354
- for (let h = 0; h < e.size - 1; h++) {
355
- o = M(e, 0, h + 1), a = M(e, h + 1), l = S(E(o), r), m = S(E(a), r);
356
- const _ = E(b(o, Z(0, o.size)));
357
- i = S(_, E(o));
358
- const $ = Ss(a.shape, o.size), k = O(Z(0, a.size), $), w = b(a, k);
359
- u = S(E(w), E(a));
360
- const T = g(i, u), x = g(i, u), R = b(l, m);
361
- n = b(b(R, T), x);
362
- const P = as(n, t);
363
- t = C(P, n, t), s = C(P, q([h]), s);
364
- }
365
- return s;
366
- }
367
- const ue = /* @__PURE__ */ f({ threshold_: ce });
368
- function pe(e, r, s = "nearest", t = "constant", n = 0, o) {
369
- const a = c(e, "image", "transform", "float32"), i = c(r, "transforms", "transform", "float32");
370
- p(a.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${a.rank}.`), p(i.rank === 2 && (i.shape[0] === a.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(o == null || o.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${o}.`);
371
- const u = { image: a, transforms: i }, l = { interpolation: s, fillMode: t, fillValue: n, outputShape: o };
372
- return d.runKernel(Xs, u, l);
373
- }
374
- const fe = /* @__PURE__ */ f({ transform_: pe });
375
- function me(e, r, s) {
376
- const t = c(e, "a", "bandPart");
377
- p(t.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${t.rank}.`);
378
- const n = t.shape, [o, a] = t.shape.slice(-2);
379
- let i, u;
380
- typeof r == "number" ? (p(r % 1 === 0, () => `bandPart(): numLower must be an integer, got ${r}.`), p(r <= o, () => `bandPart(): numLower (${r}) must not be greater than the number of rows (${o}).`), i = c(r < 0 ? o : r, "numLower", "bandPart")) : (p(r.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = C(ms(r, 0), o, os(r, o))), typeof s == "number" ? (p(s % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${s}.`), p(s <= a, () => `bandPart(): numUpper (${s}) must not be greater than the number of columns (${a}).`), u = c(s < 0 ? a : s, "numUpper", "bandPart")) : (p(s.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), u = C(ms(s, 0), a, os(s, a)));
381
- const l = I(Z(0, o, 1, "int32"), [-1, 1]), m = Z(0, a, 1, "int32"), h = g(l, m), _ = Sn(ys(h, i), En(h, j(u))), $ = rn([o, a], t.dtype);
382
- return I(H(ks(I(t, [-1, o, a])).map((k) => C(_, k, $))), n);
383
- }
384
- const he = /* @__PURE__ */ f({ bandPart_: me });
385
- function be(e) {
386
- let r;
387
- if (Array.isArray(e)) {
388
- r = !1, p(e != null && e.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
389
- const n = e[0].shape[0];
390
- for (let o = 1; o < e.length; ++o)
391
- p(e[o].shape[0] === n, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${e[o].shape[0]} vs. ${n})`);
392
- } else
393
- r = !0, e = ds(e, e.shape[0], 0).map((n) => an(n, [0]));
394
- p(e.length <= e[0].shape[0], () => `Gram-Schmidt: Number of vectors (${e.length}) exceeds number of dimensions (${e[0].shape[0]}).`);
395
- const s = [], t = e;
396
- for (let n = 0; n < e.length; ++n)
397
- s.push(d.tidy(() => {
398
- let o = t[n];
399
- if (n > 0)
400
- for (let a = 0; a < n; ++a) {
401
- const i = b(E(b(s[a], o)), s[a]);
402
- o = g(o, i);
403
- }
404
- return S(o, _s(o, "euclidean"));
405
- }));
406
- return r ? H(s, 0) : s;
407
- }
408
- const de = /* @__PURE__ */ f({ gramSchmidt_: be });
409
- function ge(e, r = !1) {
410
- if (p(e.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${e.rank}`), e.rank === 2)
411
- return hs(e, r);
412
- {
413
- const s = e.shape.slice(0, e.shape.length - 2).reduce((u, l) => u * l), t = ks(I(e, [
414
- s,
415
- e.shape[e.shape.length - 2],
416
- e.shape[e.shape.length - 1]
417
- ]), 0), n = [], o = [];
418
- t.forEach((u) => {
419
- const [l, m] = hs(u, r);
420
- n.push(l), o.push(m);
421
- });
422
- const a = I(H(n, 0), e.shape), i = I(H(o, 0), e.shape);
423
- return [a, i];
424
- }
425
- }
426
- function hs(e, r = !1) {
427
- return d.tidy(() => {
428
- p(e.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${e.shape.length}D Tensor.`);
429
- const s = e.shape[0], t = e.shape[1];
430
- let n = dn(s), o = Q(e);
431
- const a = ts([[1]], [1, 1]);
432
- let i = Q(a);
433
- const u = s >= t ? t : s;
434
- for (let l = 0; l < u; ++l) {
435
- const m = o, h = i, _ = n;
436
- [i, o, n] = d.tidy(() => {
437
- const $ = M(o, [l, l], [s - l, 1]), k = _s($), w = M(o, [l, l], [1, 1]), T = C(as(w, 0), ts([[-1]]), ts([[1]])), x = g(w, b(T, k)), R = S($, x);
438
- R.shape[0] === 1 ? i = Q(a) : i = es([
439
- a,
440
- M(R, [1, 0], [R.shape[0] - 1, R.shape[1]])
441
- ], 0);
442
- const P = j(S(G(T, x), k)), Y = M(o, [l, 0], [s - l, t]), J = b(P, i), is = us(i);
443
- if (l === 0)
444
- o = g(Y, G(J, G(is, Y)));
445
- else {
446
- const X = g(Y, G(J, G(is, Y)));
447
- o = es([M(o, [0, 0], [l, t]), X], 0);
448
- }
449
- const cs = us(J), F = M(n, [0, l], [s, n.shape[1] - l]);
450
- if (l === 0)
451
- n = g(F, G(G(F, i), cs));
452
- else {
453
- const X = g(F, G(G(F, i), cs));
454
- n = es([M(n, [0, 0], [s, l]), X], 1);
455
- }
456
- return [i, o, n];
457
- }), Ts([m, h, _]);
458
- }
459
- return !r && s > t && (n = M(n, [0, 0], [s, t]), o = M(o, [0, 0], [t, t])), [n, o];
460
- });
461
- }
462
- const $e = /* @__PURE__ */ f({ qr_: ge });
463
- var N;
464
- (function(e) {
465
- 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";
466
- })(N || (N = {}));
467
- function Ee(e, r, s = N.SUM_BY_NONZERO_WEIGHTS) {
468
- const t = c(e, "losses", "computeWeightedLoss");
469
- let n = null;
470
- r != null && (n = c(r, "weights", "computeWeightedLoss"));
471
- const o = n == null ? t : b(t, n);
472
- if (s === N.NONE)
473
- return o;
474
- if (s === N.SUM)
475
- return E(o);
476
- if (s === N.MEAN) {
477
- if (n == null)
478
- return Mn(o);
479
- {
480
- const a = t.size / n.size, i = S(E(o), E(n));
481
- return a > 1 ? S(i, y(a)) : i;
482
- }
483
- }
484
- if (s === N.SUM_BY_NONZERO_WEIGHTS) {
485
- if (n == null)
486
- return S(E(o), y(t.size));
487
- {
488
- const a = b(n, cn(t.shape)), i = D(E(qn(a, y(0))), "float32");
489
- return S(E(o), i);
490
- }
491
- }
492
- throw Error(`Unknown reduction: ${s}`);
493
- }
494
- const z = /* @__PURE__ */ f({ computeWeightedLoss_: Ee });
495
- function _e(e, r, s, t = N.SUM_BY_NONZERO_WEIGHTS) {
496
- const n = c(e, "labels", "absoluteDifference"), o = c(r, "predictions", "absoluteDifference");
497
- let a = null;
498
- s != null && (a = c(s, "weights", "absoluteDifference")), L(n.shape, o.shape, "Error in absoluteDifference: ");
499
- const i = A(g(n, o));
500
- return z(i, a, t);
501
- }
502
- const ye = /* @__PURE__ */ f({ absoluteDifference_: _e });
503
- function ke(e, r, s, t, n = N.SUM_BY_NONZERO_WEIGHTS) {
504
- const o = c(e, "labels", "cosineDistance"), a = c(r, "predictions", "cosineDistance");
505
- let i = null;
506
- t != null && (i = c(t, "weights", "cosineDistance")), L(o.shape, a.shape, "Error in cosineDistance: ");
507
- const u = y(1), l = g(u, E(b(o, a), s, !0));
508
- return z(l, i, n);
509
- }
510
- const Ne = /* @__PURE__ */ f({ cosineDistance_: ke });
511
- function Ie(e, r, s, t = N.SUM_BY_NONZERO_WEIGHTS) {
512
- let n = c(e, "labels", "hingeLoss");
513
- const o = c(r, "predictions", "hingeLoss");
514
- let a = null;
515
- s != null && (a = c(s, "weights", "hingeLoss")), L(n.shape, o.shape, "Error in hingeLoss: ");
516
- const i = y(1);
517
- n = g(b(y(2), n), i);
518
- const u = $s(g(i, b(n, o)));
519
- return z(u, a, t);
520
- }
521
- const Se = /* @__PURE__ */ f({ hingeLoss_: Ie });
522
- function Te(e, r, s, t = 1, n = N.SUM_BY_NONZERO_WEIGHTS) {
523
- const o = c(e, "labels", "huberLoss"), a = c(r, "predictions", "huberLoss");
524
- let i = null;
525
- s != null && (i = c(s, "weights", "huberLoss")), L(o.shape, a.shape, "Error in huberLoss: ");
526
- const u = y(t), l = A(g(a, o)), m = os(l, u), h = g(l, m), _ = O(b(y(0.5), bs(m)), b(u, h));
527
- return z(_, i, n);
528
- }
529
- const Me = /* @__PURE__ */ f({ huberLoss_: Te });
530
- function Ae(e, r, s, t = 1e-7, n = N.SUM_BY_NONZERO_WEIGHTS) {
531
- const o = c(e, "labels", "logLoss"), a = c(r, "predictions", "logLoss");
532
- let i = null;
533
- s != null && (i = c(s, "weights", "logLoss")), L(o.shape, a.shape, "Error in logLoss: ");
534
- const u = y(1), l = y(t), m = j(b(o, ps(O(a, l)))), h = b(g(u, o), ps(O(g(u, a), l))), _ = g(m, h);
535
- return z(_, i, n);
536
- }
537
- const we = /* @__PURE__ */ f({ logLoss_: Ae });
538
- function qe(e, r, s, t = N.SUM_BY_NONZERO_WEIGHTS) {
539
- const n = c(e, "labels", "meanSquaredError"), o = c(r, "predictions", "meanSquaredError");
540
- let a = null;
541
- s != null && (a = c(s, "weights", "meanSquaredError")), L(n.shape, o.shape, "Error in meanSquaredError: ");
542
- const i = Gn(n, o);
543
- return z(i, a, t);
544
- }
545
- const De = /* @__PURE__ */ f({ meanSquaredError_: qe });
546
- function Be(e, r) {
547
- const s = c(e, "labels", "sigmoidCrossEntropyWithLogits"), t = c(r, "logits", "sigmoidCrossEntropyWithLogits");
548
- L(s.shape, t.shape, "Error in sigmoidCrossEntropyWithLogits: ");
549
- const n = $s(t), o = b(t, s), a = Nn(rs(j(A(t))));
550
- return O(g(n, o), a);
551
- }
552
- function xe(e, r, s, t = 0, n = N.SUM_BY_NONZERO_WEIGHTS) {
553
- let o = c(e, "multiClassLabels", "sigmoidCrossEntropy");
554
- const a = c(r, "logits", "sigmoidCrossEntropy");
555
- let i = null;
556
- if (s != null && (i = c(s, "weights", "sigmoidCrossEntropy")), L(o.shape, a.shape, "Error in sigmoidCrossEntropy: "), t > 0) {
557
- const l = y(t), m = y(1), h = y(0.5);
558
- o = O(b(o, g(m, l)), b(h, l));
559
- }
560
- const u = Be(o, a);
561
- return z(u, i, n);
562
- }
563
- const Ge = /* @__PURE__ */ f({ sigmoidCrossEntropy_: xe });
564
- function Oe(e, r, s = -1) {
565
- if (s === -1 && (s = r.rank - 1), s !== r.rank - 1)
566
- throw Error(`Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank ${r.rank} and dim was ${s}`);
567
- return Ms((n, o, a) => {
568
- const u = on(o, [s], !0), l = g(D(o, "float32"), u);
569
- a([n, l]);
570
- const m = j(b(l, n));
571
- return { value: E(m, [s]), gradFunc: ($, k) => {
572
- const [w, T] = k, x = gs($.shape, [s]);
573
- return [
574
- b(I($, x), g(D(w, "float32"), rs(T))),
575
- b(I($, x), g(rs(T), D(w, "float32")))
576
- ];
577
- } };
578
- })(e, r);
579
- }
580
- function Le(e, r, s, t = 0, n = N.SUM_BY_NONZERO_WEIGHTS) {
581
- let o = c(e, "onehotLabels", "softmaxCrossEntropy");
582
- const a = c(r, "logits", "softmaxCrossEntropy");
583
- let i = null;
584
- if (s != null && (i = c(s, "weights", "softmaxCrossEntropy")), L(o.shape, a.shape, "Error in softmaxCrossEntropy: "), t > 0) {
585
- const l = y(t), m = y(1), h = y(o.shape[1]);
586
- o = O(b(o, g(m, l)), S(l, h));
587
- }
588
- const u = Oe(o, a);
589
- return z(u, i, n);
590
- }
591
- const ze = /* @__PURE__ */ f({ softmaxCrossEntropy_: Le });
592
- const lt = {
593
- flipLeftRight: Wn,
594
- grayscaleToRGB: Cn,
595
- resizeNearestNeighbor: ie,
596
- resizeBilinear: oe,
597
- rgbToGrayscale: Vn,
598
- rotateWithOffset: Pn,
599
- cropAndResize: zn,
600
- nonMaxSuppression: Fn,
601
- nonMaxSuppressionAsync: Zn,
602
- nonMaxSuppressionWithScore: Jn,
603
- nonMaxSuppressionWithScoreAsync: Qn,
604
- nonMaxSuppressionPadded: ne,
605
- nonMaxSuppressionPaddedAsync: te,
606
- threshold: ue,
607
- transform: fe
608
- }, ut = {
609
- bandPart: he,
610
- gramSchmidt: de,
611
- qr: $e
612
- }, pt = {
613
- absoluteDifference: ye,
614
- computeWeightedLoss: z,
615
- cosineDistance: Ne,
616
- hingeLoss: Se,
617
- huberLoss: Me,
618
- logLoss: we,
619
- meanSquaredError: De,
620
- sigmoidCrossEntropy: Ge,
621
- softmaxCrossEntropy: ze
622
- };
623
- export {
624
- pt as a,
625
- Sn as b,
626
- ys as c,
627
- as as d,
628
- ms as e,
629
- dn as f,
630
- En as g,
631
- Nn as h,
632
- os as i,
633
- lt as j,
634
- fs as k,
635
- ut as l,
636
- Mn as m,
637
- qn as n,
638
- _s as o,
639
- ie as p,
640
- Bn as q,
641
- oe as r,
642
- Gn as s,
643
- ks as u,
644
- C as w
645
- };
@@ -1,41 +0,0 @@
1
- import { isPackedTensor as t, packTensor as u } from "./utilities/packed.js";
2
- import { e as o } from "./index-D6Q1lPZO.js";
3
- import { a as i } from "./tensor_util-DfwaWayG.js";
4
- import { s as p } from "./slice-DvovR5wq.js";
5
- const s = {
6
- kernelName: "Unpack16",
7
- inputsToSave: [],
8
- outputsToSave: [],
9
- gradFunc: (n) => ({
10
- x: () => k(n)
11
- })
12
- };
13
- i(s);
14
- function c(n, a = 1, e = !1) {
15
- if (!t(n))
16
- return n;
17
- const r = o().runKernel("Unpack16", { x: n }, { scaling: a });
18
- return e && n.dispose(), r;
19
- }
20
- const f = {
21
- kernelName: "Pack16",
22
- inputsToSave: [],
23
- outputsToSave: [],
24
- gradFunc: (n, a, e) => ({
25
- x: () => {
26
- const r = c(n);
27
- return e.originalShape && e.padding && e.padding > 0 ? p(r, new Array(r.shape.length).fill(0), e.originalShape) : r;
28
- }
29
- })
30
- };
31
- i(f);
32
- function k(n, a = 1, e = 0) {
33
- const r = o().runKernel("Pack16", { x: n }, { scaling: a, padding: e });
34
- return u(r), r;
35
- }
36
- export {
37
- s as a,
38
- f as b,
39
- k as p,
40
- c as u
41
- };