@genai-fi/nanogpt 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/dist/{DatasetBuilder-DU1G1OKX.js → DatasetBuilder-DRDW8tcM.js} +85 -86
  2. package/dist/Generator-BcR_14Cj.js +316 -0
  3. package/dist/{RealDiv-CSnvtN2E.js → RealDiv-Cl8k3YTx.js} +54 -62
  4. package/dist/{Reshape-BlylqwWy.js → Reshape-CKxKPKqi.js} +9 -12
  5. package/dist/Reshape-H5zZRgr9.js +16 -0
  6. package/dist/RoPECache-dYscFINl.js +722 -0
  7. package/dist/TeachableLLM.js +29 -34
  8. package/dist/api/beamer.js +5 -6
  9. package/dist/api/responses.js +11 -12
  10. package/dist/api/training.js +12 -14
  11. package/dist/axis_util-rF9RnwKE.js +37 -0
  12. package/dist/backend.js +5 -6
  13. package/dist/{backend_util-DAV0I34P.js → backend_util-Cpp0Gwlp.js} +180 -185
  14. package/dist/{binary_op_util-CrYk9LXL.js → binary_op_util-WY9YIl0q.js} +3 -7
  15. package/dist/broadcast_to-CGvLNiQ0.js +20 -0
  16. package/dist/checks/appendCache.js +7 -7
  17. package/dist/checks/attentionMask.js +9 -8
  18. package/dist/checks/check.js +1 -2
  19. package/dist/checks/gelu.js +6 -6
  20. package/dist/checks/index.js +24 -25
  21. package/dist/checks/matMulGelu.js +7 -7
  22. package/dist/checks/normRMS.js +14 -12
  23. package/dist/checks/normRMSGrad.js +9 -8
  24. package/dist/checks/packUnpack.js +7 -7
  25. package/dist/checks/qkv.js +1 -34
  26. package/dist/checks/rope.js +6 -6
  27. package/dist/checks/weights.js +1 -2
  28. package/dist/clip_by_value-D-UX9am5.js +13 -0
  29. package/dist/complex-Cl904TqN.js +13 -0
  30. package/dist/{complex_util-CkazZsaH.js → complex_util-BBlPAm-s.js} +1 -2
  31. package/dist/concat-Oip5acVY.js +14 -0
  32. package/dist/{concat_util-CWzvQQlK.js → concat_util-CY45Hf4F.js} +2 -3
  33. package/dist/data/docx.js +3 -4
  34. package/dist/data/pdf.js +11 -14
  35. package/dist/data/stream.js +1 -2
  36. package/dist/data/textLoader.js +16 -15
  37. package/dist/data-CV_i_H6B.js +11 -0
  38. package/dist/data.js +5 -12
  39. package/dist/dist-CMMLi-qO.js +2675 -0
  40. package/dist/{dist-BGVm64AY.js → dist-DeVH1nGn.js} +1465 -1573
  41. package/dist/{dist-CwK5S7Ls.js → dist-DyL7qSLJ.js} +2664 -2400
  42. package/dist/dropout16-CA31Ud5a.js +20 -0
  43. package/dist/dropout_util-SiFMbFXz.js +22 -0
  44. package/dist/{eventemitter3-D_qV3Lof.js → eventemitter3-wmfmOP_f.js} +2 -3
  45. package/dist/expand_dims-Dh3Fulyn.js +10 -0
  46. package/dist/floor-BwjmUb7X.js +8 -0
  47. package/dist/gather-B5Z1RFt5.js +14 -0
  48. package/dist/gatherSub-CRUfUzBa.js +22 -0
  49. package/dist/gelu-Xx9-ohH9.js +25 -0
  50. package/dist/{gpgpu_math-20tPK8LM.js → gpgpu_math-48m8q3jI.js} +265 -286
  51. package/dist/inference/Beamer.js +34 -27
  52. package/dist/inference/Generator.js +1 -273
  53. package/dist/inference/tokenisePrompt.js +5 -4
  54. package/dist/inference/types.d.ts +6 -0
  55. package/dist/inference/utilities.js +1 -2
  56. package/dist/{jszip.min-DKa1Rjyn.js → jszip.min-Btv48m44.js} +68 -64
  57. package/dist/{kernel_funcs_utils-ql8Y8qPn.js → kernel_funcs_utils-BYRpSfV_.js} +39 -42
  58. package/dist/layers/BaseLayer.js +9 -10
  59. package/dist/layers/GQA.js +45 -44
  60. package/dist/layers/HeadLayer.js +13 -13
  61. package/dist/layers/LoRA.js +17 -20
  62. package/dist/layers/MHA.d.ts +2 -2
  63. package/dist/layers/MHA.js +46 -45
  64. package/dist/layers/MLP.js +22 -21
  65. package/dist/layers/PositionEmbedding.js +14 -13
  66. package/dist/layers/RMSNorm.js +14 -13
  67. package/dist/layers/RoPECache.js +1 -338
  68. package/dist/layers/TiedEmbedding.js +15 -14
  69. package/dist/layers/TransformerBlock.d.ts +3 -9
  70. package/dist/layers/TransformerBlock.js +29 -30
  71. package/dist/layers/WeightStore.js +4 -5
  72. package/dist/layers-CFqEip3s.js +13 -0
  73. package/dist/layers.js +3 -11
  74. package/dist/loader/load.js +27 -24
  75. package/dist/loader/loadHF.js +3 -3
  76. package/dist/loader/loadTransformers.js +5 -6
  77. package/dist/loader/loadZipMeta.js +1 -2
  78. package/dist/loader/newZipLoad.js +1 -2
  79. package/dist/loader/oldZipLoad.js +8 -9
  80. package/dist/loader/save.js +15 -16
  81. package/dist/main.js +3281 -3463
  82. package/dist/{matMul16-CO1QhsRt.js → matMul16-tE26fnhf.js} +29 -27
  83. package/dist/{matMulGelu-CBoqTZM7.js → matMulGelu-ASUWlKqu.js} +33 -33
  84. package/dist/mat_mul-R9_DWmIT.js +16 -0
  85. package/dist/models/Llama.js +48 -49
  86. package/dist/models/NanoGPTV1.js +53 -54
  87. package/dist/models/NanoGPTV2.js +48 -49
  88. package/dist/models/Qwen3.js +48 -49
  89. package/dist/models/config.js +3 -8
  90. package/dist/models/factory.js +7 -8
  91. package/dist/models/model.d.ts +5 -7
  92. package/dist/models/model.js +1 -2
  93. package/dist/models-DyBpJJwM.js +13 -0
  94. package/dist/models.js +6 -14
  95. package/dist/mul16-C7sqgqik.js +41 -0
  96. package/dist/non_max_suppression_impl-B0H318rb.js +72 -0
  97. package/dist/not_equal-Bu3O8rh_.js +67 -0
  98. package/dist/one_hot-TEMPumJj.js +14 -0
  99. package/dist/ones-DpPXWa6A.js +13 -0
  100. package/dist/ops/adamAdjust.js +2 -3
  101. package/dist/ops/adamMoments.js +2 -3
  102. package/dist/ops/add16.js +2 -3
  103. package/dist/ops/appendCache.js +9 -8
  104. package/dist/ops/attentionMask.d.ts +1 -1
  105. package/dist/ops/attentionMask.js +8 -5
  106. package/dist/ops/concat16.js +5 -5
  107. package/dist/ops/cpu/adamAdjust.js +7 -8
  108. package/dist/ops/cpu/adamMoments.js +5 -5
  109. package/dist/ops/cpu/appendCache.js +3 -3
  110. package/dist/ops/cpu/attentionMask.js +12 -8
  111. package/dist/ops/cpu/fusedSoftmax.js +3 -3
  112. package/dist/ops/cpu/gatherSub.js +1 -12
  113. package/dist/ops/cpu/gelu.js +12 -13
  114. package/dist/ops/cpu/matMul16.js +7 -7
  115. package/dist/ops/cpu/matMulGelu.js +21 -18
  116. package/dist/ops/cpu/matMulMul.js +8 -9
  117. package/dist/ops/cpu/mulDropout.js +8 -9
  118. package/dist/ops/cpu/normRMS.js +12 -13
  119. package/dist/ops/cpu/qkv.js +14 -13
  120. package/dist/ops/cpu/rope.js +11 -8
  121. package/dist/ops/cpu/scatterSub.js +1 -12
  122. package/dist/ops/dot16.js +16 -17
  123. package/dist/ops/dropout.js +9 -8
  124. package/dist/ops/dropout16.js +1 -22
  125. package/dist/ops/gatherSub.js +3 -4
  126. package/dist/ops/gelu.js +1 -2
  127. package/dist/ops/globalNorm.js +10 -10
  128. package/dist/ops/grads/add16.js +16 -17
  129. package/dist/ops/grads/attentionMask.js +6 -7
  130. package/dist/ops/grads/dropout16.js +1 -1
  131. package/dist/ops/grads/gelu.js +1 -2
  132. package/dist/ops/grads/matMul16.js +1 -2
  133. package/dist/ops/grads/matMulGelu.js +6 -7
  134. package/dist/ops/grads/mul16.js +1 -1
  135. package/dist/ops/grads/normRMS.js +8 -9
  136. package/dist/ops/grads/pack16.js +1 -2
  137. package/dist/ops/grads/qkv.js +10 -10
  138. package/dist/ops/grads/rope.js +1 -2
  139. package/dist/ops/grads/silu.js +1 -2
  140. package/dist/ops/grads/softmax16.js +6 -7
  141. package/dist/ops/grads/unpack16.js +1 -2
  142. package/dist/ops/grads/utils.js +1 -2
  143. package/dist/ops/matMul16.d.ts +1 -1
  144. package/dist/ops/matMul16.js +1 -2
  145. package/dist/ops/matMulGelu.js +3 -4
  146. package/dist/ops/matMulMul.js +2 -3
  147. package/dist/ops/mul16.js +1 -43
  148. package/dist/ops/mulDrop.js +2 -3
  149. package/dist/ops/normRMS.js +2 -3
  150. package/dist/ops/pack16.js +1 -2
  151. package/dist/ops/qkv.js +2 -3
  152. package/dist/ops/reshape16.js +11 -11
  153. package/dist/ops/rope.js +1 -2
  154. package/dist/ops/scatterSub.js +3 -4
  155. package/dist/ops/silu.js +1 -2
  156. package/dist/ops/slice16.js +5 -5
  157. package/dist/ops/softmax16.js +3 -4
  158. package/dist/ops/sub16.js +3 -4
  159. package/dist/ops/sum16.js +3 -3
  160. package/dist/ops/transpose16.js +16 -15
  161. package/dist/ops/unpack16.js +1 -2
  162. package/dist/ops/webgl/adamAdjust.js +8 -9
  163. package/dist/ops/webgl/adamMoments.js +2 -3
  164. package/dist/ops/webgl/appendCache.js +2 -3
  165. package/dist/ops/webgl/attentionMask.js +2 -3
  166. package/dist/ops/webgl/dropout16.js +2 -3
  167. package/dist/ops/webgl/fusedSoftmax.js +13 -13
  168. package/dist/ops/webgl/gatherSub.js +2 -3
  169. package/dist/ops/webgl/gelu.js +11 -12
  170. package/dist/ops/webgl/log.js +10 -10
  171. package/dist/ops/webgl/matMul16.js +31 -24
  172. package/dist/ops/webgl/matMulGelu.js +1 -2
  173. package/dist/ops/webgl/matMulMul.js +3 -4
  174. package/dist/ops/webgl/mulDropout.js +2 -3
  175. package/dist/ops/webgl/normRMS.js +11 -10
  176. package/dist/ops/webgl/qkv.js +2 -3
  177. package/dist/ops/webgl/rope.js +4 -5
  178. package/dist/ops/webgl/scatterSub.js +2 -3
  179. package/dist/ops/webgpu/adamAdjust.js +13 -14
  180. package/dist/ops/webgpu/adamMoments.js +13 -14
  181. package/dist/ops/webgpu/add16.js +3 -4
  182. package/dist/ops/webgpu/appendCache.js +20 -21
  183. package/dist/ops/webgpu/attentionMask.js +18 -19
  184. package/dist/ops/webgpu/attentionMask32_program.js +7 -8
  185. package/dist/ops/webgpu/clipScale.js +11 -12
  186. package/dist/ops/webgpu/concat16.js +17 -18
  187. package/dist/ops/webgpu/dropout16.js +6 -7
  188. package/dist/ops/webgpu/gatherSub.js +11 -12
  189. package/dist/ops/webgpu/gelu.js +10 -11
  190. package/dist/ops/webgpu/index.js +17 -17
  191. package/dist/ops/webgpu/matMul16.js +74 -63
  192. package/dist/ops/webgpu/matMul16_program.d.ts +2 -1
  193. package/dist/ops/webgpu/matMul16_program.js +29 -21
  194. package/dist/ops/webgpu/mul16.js +3 -4
  195. package/dist/ops/webgpu/norm2.js +9 -10
  196. package/dist/ops/webgpu/normRMS.js +9 -10
  197. package/dist/ops/webgpu/normRMS16_program.js +1 -2
  198. package/dist/ops/webgpu/normRMS32_program.js +1 -2
  199. package/dist/ops/webgpu/normRMSGrad.js +30 -30
  200. package/dist/ops/webgpu/pack16.js +2 -3
  201. package/dist/ops/webgpu/pack16_program.js +3 -4
  202. package/dist/ops/webgpu/qkv.js +10 -11
  203. package/dist/ops/webgpu/rope.js +26 -27
  204. package/dist/ops/webgpu/scatterSub.js +12 -13
  205. package/dist/ops/webgpu/silu.js +10 -11
  206. package/dist/ops/webgpu/slice16.js +17 -18
  207. package/dist/ops/webgpu/softmax16.js +9 -9
  208. package/dist/ops/webgpu/softmax16_program.js +9 -10
  209. package/dist/ops/webgpu/softmax16_subgroup_program.js +11 -12
  210. package/dist/ops/webgpu/softmax16grad.js +8 -9
  211. package/dist/ops/webgpu/sub16.js +3 -4
  212. package/dist/ops/webgpu/sum16.js +16 -15
  213. package/dist/ops/webgpu/transpose16.js +13 -12
  214. package/dist/ops/webgpu/transpose16_program.js +3 -4
  215. package/dist/ops/webgpu/transpose16_shared_program.js +17 -18
  216. package/dist/ops/webgpu/unpack16.js +8 -9
  217. package/dist/ops/webgpu/utils/binary_op.js +20 -21
  218. package/dist/ops/webgpu/utils/deviceInfo.js +1 -2
  219. package/dist/ops/webgpu/utils/reductions.js +21 -20
  220. package/dist/ops-Be5ACU5R.js +13 -0
  221. package/dist/ops-C1UpdEYM.js +509 -0
  222. package/dist/{pack16-BhuXNUS7.js → pack16-BHO4t1-M.js} +14 -17
  223. package/dist/pad-Dy-1IP3A.js +13 -0
  224. package/dist/patches/webgpu_backend.js +18 -19
  225. package/dist/patches/webgpu_base.js +2 -3
  226. package/dist/patches/webgpu_program.js +21 -22
  227. package/dist/{pdf-Bzuk68Vy.js → pdf-CbnQ75VG.js} +380 -701
  228. package/dist/{picomatch-BO4HbNfo.js → picomatch--TW6gyBJ.js} +229 -291
  229. package/dist/qkv-BQfNPucX.js +42 -0
  230. package/dist/rand_util-_vCY93Uw.js +44 -0
  231. package/dist/random_normal-DUIT8kyC.js +11 -0
  232. package/dist/range-CYvQC3fW.js +13 -0
  233. package/dist/relu-C4XULT8A.js +8 -0
  234. package/dist/reshape-DJb1jgMt.js +8 -0
  235. package/dist/resize_nearest_neighbor-DAqcTYUe.js +188 -0
  236. package/dist/{chunk-CWhphoD1.js → rolldown-runtime-CwxnZyOB.js} +4 -5
  237. package/dist/{rope-BPu_uooz.js → rope-JjBVufF_.js} +6 -8
  238. package/dist/scatterSub-BOnqk-uY.js +27 -0
  239. package/dist/scatter_nd_util-BepMCpLY.js +34 -0
  240. package/dist/seedrandom-SHEGFK6H.js +282 -0
  241. package/dist/selu_util-DeOTf-sc.js +27 -0
  242. package/dist/shared-BIDMUBCs.js +1864 -0
  243. package/dist/{shared-CfTzpULd.js → shared-CX_iPI5K.js} +2 -3
  244. package/dist/silu-DsAE2cJ5.js +23 -0
  245. package/dist/slice-Dlb1FlzG.js +13 -0
  246. package/dist/{slice_util-Dve4TkDn.js → slice_util-BVgPRoij.js} +3 -4
  247. package/dist/softmax-Dpav_dWw.js +10 -0
  248. package/dist/split-DYnT8chz.js +11 -0
  249. package/dist/squeeze-B3XYGAlg.js +9 -0
  250. package/dist/stack-Dbbt9mIk.js +10 -0
  251. package/dist/step-DA-5DNu9.js +348 -0
  252. package/dist/{stream-BpAwcvHz.js → stream-BBe2apn4.js} +68 -88
  253. package/dist/sum-C8qNbFNp.js +13 -0
  254. package/dist/tensor-ALxWZfmz.js +7 -0
  255. package/dist/tensor1d-BHgkkhTE.js +9 -0
  256. package/dist/tensor2d-ARItvqVn.js +10 -0
  257. package/dist/tensor4d-D1zRBipJ.js +10 -0
  258. package/dist/tfjs_backend-CsXOum0h.js +685 -0
  259. package/dist/tile-DfyQ0KX-.js +10 -0
  260. package/dist/tokenise-DbS2Ea-T.js +14 -0
  261. package/dist/tokenise.js +6 -15
  262. package/dist/tokeniser/BaseTokeniser.js +5 -9
  263. package/dist/tokeniser/CharTokeniser.js +1 -2
  264. package/dist/tokeniser/bpe.js +19 -20
  265. package/dist/topk-BrU2pkrR.js +19 -0
  266. package/dist/training/AdamW.js +35 -31
  267. package/dist/training/BasicTrainer.js +56 -56
  268. package/dist/training/DatasetBuilder.js +1 -2
  269. package/dist/training/Evaluator.js +4 -4
  270. package/dist/training/LRScheduler.js +1 -2
  271. package/dist/training/PreTrainer.js +7 -8
  272. package/dist/training/SFTTrainer.js +7 -8
  273. package/dist/training/configure.js +16 -15
  274. package/dist/training/factory.js +1 -2
  275. package/dist/training/loss.js +1 -2
  276. package/dist/training/orthoGrad.js +2 -3
  277. package/dist/training/prepareData.js +18 -17
  278. package/dist/training/sparseCrossEntropy.js +38 -32
  279. package/dist/training/tasks/TokenStore.js +21 -22
  280. package/dist/training/tasks/tokenStream.js +1 -2
  281. package/dist/training/validateOptions.js +1 -2
  282. package/dist/training/validation.js +1 -2
  283. package/dist/transpose-BC-M_OoT.js +34 -0
  284. package/dist/unsorted_segment_sum-BelC7R-q.js +408 -0
  285. package/dist/utilities/arrayClose.js +5 -4
  286. package/dist/utilities/arrayShape.js +1 -2
  287. package/dist/utilities/datasetID.js +1 -2
  288. package/dist/utilities/dummy.js +15 -15
  289. package/dist/utilities/float16.js +10 -10
  290. package/dist/utilities/maxHeap.js +1 -2
  291. package/dist/utilities/multinomialCPU.d.ts +1 -2
  292. package/dist/utilities/multinomialCPU.js +6 -8
  293. package/dist/utilities/packed.js +2 -3
  294. package/dist/utilities/parameters.js +3 -4
  295. package/dist/utilities/performance.js +2 -3
  296. package/dist/utilities/profile.js +3 -4
  297. package/dist/utilities/random.js +1 -2
  298. package/dist/utilities/safetensors.js +14 -14
  299. package/dist/utilities/sentences.js +16 -13
  300. package/dist/utilities/tokenParse.js +1 -2
  301. package/dist/utilities/tokens.js +5 -6
  302. package/dist/utilities/topP.d.ts +1 -0
  303. package/dist/utilities/topP.js +20 -13
  304. package/dist/utilities/waitForModel.js +1 -2
  305. package/dist/utilities/weights.js +4 -4
  306. package/dist/utilities/yielder.js +1 -2
  307. package/dist/{v4-BK7K-jy_.js → v4-YCkfo8OR.js} +4 -7
  308. package/dist/{webgpu-IAn9VotJ.js → webgpu-BHX-uBym.js} +156 -163
  309. package/dist/{webgpu_program-B0PokuRJ.js → webgpu_program-DvkFqRlR.js} +28 -29
  310. package/dist/{webgpu_util-DfODg6XI.js → webgpu_util-5QTyovaf.js} +2 -3
  311. package/dist/zeros-hxKGkRfl.js +12 -0
  312. package/package.json +3 -3
  313. package/dist/Reshape-CwxdaU8n.js +0 -17
  314. package/dist/dist-Da20xy8E.js +0 -6375
  315. package/dist/gelu-B6637MKa.js +0 -27
  316. package/dist/selu_util-B_AFEfoz.js +0 -24
  317. package/dist/shared-24EoeHJl.js +0 -1314
  318. package/dist/silu-B6bvCgJ7.js +0 -25
  319. package/dist/tfjs_backend-h5weiy1O.js +0 -614
@@ -0,0 +1,2675 @@
1
+ import { t as e } from "./rolldown-runtime-CwxnZyOB.js";
2
+ // node_modules/@tensorflow/tfjs-core/dist/backends/backend.js
3
+ var t = 1e-7, n = 1e-4, r = class {
4
+ constructor(e, t) {
5
+ this.backend = e, this.dataMover = t, this.data = /* @__PURE__ */ new WeakMap(), this.dataIdsCount = 0;
6
+ }
7
+ get(e) {
8
+ return this.data.has(e) || this.dataMover.moveData(this.backend, e), this.data.get(e);
9
+ }
10
+ set(e, t) {
11
+ this.dataIdsCount++, this.data.set(e, t);
12
+ }
13
+ has(e) {
14
+ return this.data.has(e);
15
+ }
16
+ delete(e) {
17
+ return this.dataIdsCount--, this.data.delete(e);
18
+ }
19
+ numDataIds() {
20
+ return this.dataIdsCount;
21
+ }
22
+ }, i = class {
23
+ refCount(e) {
24
+ return a("refCount");
25
+ }
26
+ incRef(e) {
27
+ return a("incRef");
28
+ }
29
+ timerAvailable() {
30
+ return !0;
31
+ }
32
+ time(e) {
33
+ return a("time");
34
+ }
35
+ read(e) {
36
+ return a("read");
37
+ }
38
+ readSync(e) {
39
+ return a("readSync");
40
+ }
41
+ readToGPU(e, t) {
42
+ return a("readToGPU");
43
+ }
44
+ numDataIds() {
45
+ return a("numDataIds");
46
+ }
47
+ disposeData(e, t) {
48
+ return a("disposeData");
49
+ }
50
+ write(e, t, n) {
51
+ return a("write");
52
+ }
53
+ move(e, t, n, r, i) {
54
+ return a("move");
55
+ }
56
+ createTensorFromGPUData(e, t, n) {
57
+ return a("createTensorFromGPUData");
58
+ }
59
+ memory() {
60
+ return a("memory");
61
+ }
62
+ floatPrecision() {
63
+ return a("floatPrecision");
64
+ }
65
+ epsilon() {
66
+ return this.floatPrecision() === 32 ? t : n;
67
+ }
68
+ dispose() {
69
+ return a("dispose");
70
+ }
71
+ };
72
+ function a(e) {
73
+ throw Error(`'${e}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`);
74
+ }
75
+ // node_modules/@tensorflow/tfjs-core/dist/util_base.js
76
+ function o(e) {
77
+ let t = e.length, n = 0;
78
+ for (; t > 0;) n = Math.random() * t | 0, t--, l(e, t, n);
79
+ }
80
+ function s(e, t, n) {
81
+ return Math.max(e, Math.min(t, n));
82
+ }
83
+ function c(e) {
84
+ return e % 2 == 0 ? e : e + 1;
85
+ }
86
+ function l(e, t, n) {
87
+ let r = e[t];
88
+ e[t] = e[n], e[n] = r;
89
+ }
90
+ function u(e) {
91
+ let t = 0;
92
+ for (let n = 0; n < e.length; n++) t += e[n];
93
+ return t;
94
+ }
95
+ function d(e, t) {
96
+ if (!e) throw Error(typeof t == "string" ? t : t());
97
+ }
98
+ function f(e, t, n = "") {
99
+ d(te(e, t), () => n + ` Shapes ${e} and ${t} must match`);
100
+ }
101
+ function p(e) {
102
+ d(e != null, () => "The input to the tensor constructor must be a non-null value.");
103
+ }
104
+ function m(e) {
105
+ if (e.length === 0) return 1;
106
+ let t = e[0];
107
+ for (let n = 1; n < e.length; n++) t *= e[n];
108
+ return t;
109
+ }
110
+ function ee(e) {
111
+ return e.length === 0;
112
+ }
113
+ function te(e, t) {
114
+ if (e === t) return !0;
115
+ if (e == null || t == null || e.length !== t.length) return !1;
116
+ for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
117
+ return !0;
118
+ }
119
+ function ne(e) {
120
+ return e % 1 == 0;
121
+ }
122
+ function re(e) {
123
+ let t = Math.ceil(Math.sqrt(e));
124
+ return [t, Math.ceil(e / t)];
125
+ }
126
+ function h(e, t) {
127
+ return t <= e.length ? e : e + " ".repeat(t - e.length);
128
+ }
129
+ function ie(e, t = (e) => 0, n, r) {
130
+ return new Promise((i, a) => {
131
+ let o = 0, s = () => {
132
+ if (e()) {
133
+ i();
134
+ return;
135
+ }
136
+ o++;
137
+ let c = t(o);
138
+ n != null && o >= n ? a() : r == null ? setTimeout(s, c) : r(s, c);
139
+ };
140
+ s();
141
+ });
142
+ }
143
+ function ae(e, t) {
144
+ let n = 1, r = -1;
145
+ for (let t = 0; t < e.length; ++t) if (e[t] >= 0) n *= e[t];
146
+ else if (e[t] === -1) {
147
+ if (r !== -1) throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${r} and dim ${t}`);
148
+ r = t;
149
+ } else if (e[t] < 0) throw Error(`Shapes can not be < 0. Found ${e[t]} at dim ${t}`);
150
+ if (r === -1) {
151
+ if (t > 0 && t !== n) throw Error(`Size(${t}) must match the product of shape ${e}`);
152
+ return e;
153
+ }
154
+ if (n === 0) throw Error(`Cannot infer the missing size in [${e}] when there are 0 elements`);
155
+ if (t % n !== 0) throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${n}`);
156
+ let i = e.slice();
157
+ return i[r] = t / n, i;
158
+ }
159
+ function oe(e, t) {
160
+ let n = t.length;
161
+ return e = e == null ? t.map((e, t) => t) : [].concat(e), d(e.every((e) => e >= -n && e < n), () => `All values in axis param must be in range [-${n}, ${n}) but got axis ${e}`), d(e.every((e) => ne(e)), () => `All values in axis param must be integers but got axis ${e}`), e.map((e) => e < 0 ? n + e : e);
162
+ }
163
+ function se(e, t) {
164
+ let n = [], r = [], i = t != null && Array.isArray(t) && t.length === 0, a = t == null || i ? null : oe(t, e).sort(), o = 0;
165
+ for (let t = 0; t < e.length; ++t) {
166
+ if (a != null) {
167
+ if (a[o] === t && e[t] !== 1) throw Error(`Can't squeeze axis ${t} since its dim '${e[t]}' is not 1`);
168
+ (a[o] == null || a[o] > t) && e[t] === 1 && (n.push(e[t]), r.push(t)), a[o] <= t && o++;
169
+ }
170
+ e[t] !== 1 && (n.push(e[t]), r.push(t));
171
+ }
172
+ return {
173
+ newShape: n,
174
+ keptDims: r
175
+ };
176
+ }
177
+ function ce(e, t) {
178
+ return le(e, t);
179
+ }
180
+ function le(e, t) {
181
+ let n = null;
182
+ if (e == null || e === "float32") n = new Float32Array(t);
183
+ else if (e === "int32" || e === "packedF16") n = new Int32Array(t);
184
+ else if (e === "bool") n = new Uint8Array(t);
185
+ else if (e === "string") n = Array(t);
186
+ else throw Error(`Unknown data type ${e}`);
187
+ return n;
188
+ }
189
+ function ue(e, t) {
190
+ for (let n = 0; n < e.length; n++) {
191
+ let r = e[n];
192
+ if (isNaN(r) || !isFinite(r)) throw Error(`A tensor of type ${t} being uploaded contains ${r}.`);
193
+ }
194
+ }
195
+ function de(e) {
196
+ return e === "bool" || e === "complex64" || e === "float32" || e === "int32" || e === "string" || e === "packedF16";
197
+ }
198
+ function fe(e, t) {
199
+ return !(t === "complex64" || t === "float32" && e !== "complex64" || t === "int32" && e !== "float32" && e !== "complex64" || t === "bool" && e === "bool");
200
+ }
201
+ function g(e) {
202
+ if (e === "float32" || e === "int32" || e === "packedF16") return 4;
203
+ if (e === "complex64") return 8;
204
+ if (e === "bool") return 1;
205
+ throw Error(`Unknown dtype ${e}`);
206
+ }
207
+ function pe(e) {
208
+ if (e == null) return 0;
209
+ let t = 0;
210
+ return e.forEach((e) => t += e.length), t;
211
+ }
212
+ function me(e) {
213
+ return typeof e == "string" || e instanceof String;
214
+ }
215
+ function he(e) {
216
+ return typeof e == "boolean";
217
+ }
218
+ function ge(e) {
219
+ return typeof e == "number";
220
+ }
221
+ function _(e) {
222
+ return Array.isArray(e) ? _(e[0]) : e instanceof Float32Array ? "float32" : e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray ? "int32" : ge(e) ? "float32" : me(e) ? "string" : he(e) ? "bool" : "float32";
223
+ }
224
+ function v(e) {
225
+ return !!(e && e.constructor && e.call && e.apply);
226
+ }
227
+ function _e(e, t) {
228
+ for (let n = t; n < e; ++n) if (e % n === 0) return n;
229
+ return e;
230
+ }
231
+ function ve(e) {
232
+ let t = e.length;
233
+ if (t < 2) return [];
234
+ let n = Array(t - 1);
235
+ n[t - 2] = e[t - 1];
236
+ for (let r = t - 3; r >= 0; --r) n[r] = n[r + 1] * e[r + 1];
237
+ return n;
238
+ }
239
+ function ye(e, t, n, r = !1) {
240
+ let i = [];
241
+ if (t.length === 1) {
242
+ let a = t[0] * (r ? 2 : 1);
243
+ for (let t = 0; t < a; t++) i[t] = n[e + t];
244
+ } else {
245
+ let a = t[0], o = t.slice(1), s = o.reduce((e, t) => e * t) * (r ? 2 : 1);
246
+ for (let t = 0; t < a; t++) i[t] = ye(e + t * s, o, n, r);
247
+ }
248
+ return i;
249
+ }
250
+ function y(e, t, n = !1) {
251
+ if (e.length === 0) return t[0];
252
+ let r = e.reduce((e, t) => e * t) * (n ? 2 : 1);
253
+ if (r === 0) return [];
254
+ if (r !== t.length) throw Error(`[${e}] does not match the input size ${t.length}${n ? " for a complex tensor" : ""}.`);
255
+ return ye(0, e, t, n);
256
+ }
257
+ function be(e, t) {
258
+ if (Array.isArray(e)) return e;
259
+ if (t === "float32") return e instanceof Float32Array ? e : new Float32Array(e);
260
+ if (t === "int32" || t === "packedF16") return e instanceof Int32Array ? e : new Int32Array(e);
261
+ if (t === "bool" || t === "string") return Uint8Array.from(new Int32Array(e));
262
+ throw Error(`Unknown dtype ${t}`);
263
+ }
264
+ function xe(e, t) {
265
+ let n = Se(e, t);
266
+ for (let e = 0; e < n.length; e++) n[e] = t === "packedF16" ? 1006648320 : 1;
267
+ return n;
268
+ }
269
+ function Se(e, t) {
270
+ if (t == null || t === "float32" || t === "complex64") return new Float32Array(e);
271
+ if (t === "int32" || t === "packedF16") return new Int32Array(e);
272
+ if (t === "bool") return new Uint8Array(e);
273
+ throw Error(`Unknown data type ${t}`);
274
+ }
275
+ function Ce(e, t) {
276
+ let n = e.reduce((e, t) => e * t, 1);
277
+ if (t == null || t === "float32") return y(e, new Float32Array(n));
278
+ if (t === "int32" || t === "packedF16") return y(e, new Int32Array(n));
279
+ if (t === "bool") return y(e, new Uint8Array(n));
280
+ throw Error(`Unknown data type ${t}`);
281
+ }
282
+ function we(e) {
283
+ e.forEach((t) => {
284
+ d(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${e}].`);
285
+ });
286
+ }
287
+ function Te(e, t, n) {
288
+ if (t === 0) return 0;
289
+ if (t === 1) return e[0];
290
+ let r = e[e.length - 1];
291
+ for (let t = 0; t < e.length - 1; ++t) r += n[t] * e[t];
292
+ return r;
293
+ }
294
+ function Ee(e, t, n) {
295
+ if (t === 0) return [];
296
+ if (t === 1) return [e];
297
+ let r = Array(t);
298
+ for (let t = 0; t < r.length - 1; ++t) r[t] = Math.floor(e / n[t]), e -= r[t] * n[t];
299
+ return r[r.length - 1] = e, r;
300
+ }
301
+ function De(e) {
302
+ return e && e.then && typeof e.then == "function";
303
+ }
304
+ // node_modules/@tensorflow/tfjs-core/dist/environment.js
305
+ var Oe = "tfjsflags", ke = class {
306
+ constructor(e) {
307
+ this.global = e, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = Ae, this.populateURLFlags();
308
+ }
309
+ setPlatform(e, t) {
310
+ this.platform != null && (b().getBool("IS_TEST") || b().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${e}.`)), this.platformName = e, this.platform = t;
311
+ }
312
+ registerFlag(e, t, n) {
313
+ if (this.flagRegistry[e] = {
314
+ evaluationFn: t,
315
+ setHook: n
316
+ }, this.urlFlags[e] != null) {
317
+ let t = this.urlFlags[e];
318
+ b().getBool("IS_TEST") || b().getBool("PROD") || console.warn(`Setting feature override from URL ${e}: ${t}.`), this.set(e, t);
319
+ }
320
+ }
321
+ async getAsync(e) {
322
+ return e in this.flags || (this.flags[e] = await this.evaluateFlag(e)), this.flags[e];
323
+ }
324
+ get(e) {
325
+ if (e in this.flags) return this.flags[e];
326
+ let t = this.evaluateFlag(e);
327
+ if (De(t)) throw Error(`Flag ${e} cannot be synchronously evaluated. Please use getAsync() instead.`);
328
+ return this.flags[e] = t, this.flags[e];
329
+ }
330
+ getNumber(e) {
331
+ return this.get(e);
332
+ }
333
+ getBool(e) {
334
+ return this.get(e);
335
+ }
336
+ getString(e) {
337
+ return this.get(e);
338
+ }
339
+ getFlags() {
340
+ return this.flags;
341
+ }
342
+ get features() {
343
+ return this.flags;
344
+ }
345
+ set(e, t) {
346
+ if (this.flagRegistry[e] == null) throw Error(`Cannot set flag ${e} as it has not been registered.`);
347
+ this.flags[e] = t, this.flagRegistry[e].setHook != null && this.flagRegistry[e].setHook(t);
348
+ }
349
+ evaluateFlag(e) {
350
+ if (this.flagRegistry[e] == null) throw Error(`Cannot evaluate flag '${e}': no evaluation function found.`);
351
+ return this.flagRegistry[e].evaluationFn();
352
+ }
353
+ setFlags(e) {
354
+ this.flags = Object.assign({}, e);
355
+ }
356
+ reset() {
357
+ this.flags = {}, this.urlFlags = {}, this.populateURLFlags();
358
+ }
359
+ populateURLFlags() {
360
+ if (this.global === void 0 || this.global.location === void 0 || this.global.location.search === void 0) return;
361
+ let e = this.getQueryParams(this.global.location.search);
362
+ Oe in e && e[Oe].split(",").forEach((e) => {
363
+ let [t, n] = e.split(":");
364
+ this.urlFlags[t] = Me(t, n);
365
+ });
366
+ }
367
+ };
368
+ function Ae(e) {
369
+ let t = {};
370
+ return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (e, ...n) => (je(t, n[0], n[1]), n.join("="))), t;
371
+ }
372
+ function je(e, t, n) {
373
+ e[decodeURIComponent(t)] = decodeURIComponent(n || "");
374
+ }
375
+ function Me(e, t) {
376
+ let n = t.toLowerCase();
377
+ return n === "true" || n === "false" ? n === "true" : `${+n}` === n ? +n : t;
378
+ }
379
+ function b() {
380
+ return Ne;
381
+ }
382
+ var Ne = null;
383
+ function Pe(e) {
384
+ Ne = e;
385
+ }
386
+ // node_modules/@tensorflow/tfjs-core/dist/global_util.js
387
+ var Fe;
388
+ function Ie() {
389
+ if (Fe == null) {
390
+ let e;
391
+ if (typeof window < "u") e = window;
392
+ else if (typeof global < "u") e = global;
393
+ else if (typeof process < "u") e = process;
394
+ else if (typeof self < "u") e = self;
395
+ else throw Error("Could not find a global object");
396
+ Fe = e;
397
+ }
398
+ return Fe;
399
+ }
400
+ function Le() {
401
+ let e = Ie();
402
+ return e._tfGlobals ??= /* @__PURE__ */ new Map(), e._tfGlobals;
403
+ }
404
+ function Re(e, t) {
405
+ let n = Le();
406
+ if (n.has(e)) return n.get(e);
407
+ {
408
+ let r = t();
409
+ return n.set(e, r), n.get(e);
410
+ }
411
+ }
412
+ // node_modules/@tensorflow/tfjs-core/dist/kernel_names.js
413
+ var ze = "Acos", Be = "Acosh", Ve = "AddN", He = "ArgMax", Ue = "ArgMin", We = "Asin", Ge = "Asinh", Ke = "Atan", qe = "Atanh", Je = "Atan2", Ye = "AvgPool", Xe = "AvgPoolGrad", Ze = "AvgPool3D", Qe = "AvgPool3DGrad", $e = "BatchMatMul", et = "BatchToSpaceND", tt = "Bincount", nt = "BitwiseAnd", rt = "BroadcastTo", it = "BroadcastArgs", at = "Cast", ot = "Ceil", st = "ClipByValue", ct = "Complex", lt = "ComplexAbs", ut = "Concat", dt = "Conv2D", ft = "Conv2DBackpropFilter", pt = "Conv2DBackpropInput", mt = "Conv3D", ht = "Conv3DBackpropFilterV2", gt = "Conv3DBackpropInputV2", _t = "Cosh", vt = "Cumprod", yt = "Cumsum", bt = "CropAndResize", xt = "DenseBincount", St = "DepthToSpace", Ct = "DepthwiseConv2dNative", wt = "DepthwiseConv2dNativeBackpropFilter", Tt = "DepthwiseConv2dNativeBackpropInput", Et = "Diag", Dt = "Dilation2D", Ot = "Dilation2DBackpropInput", kt = "Dilation2DBackpropFilter", At = "Draw", jt = "RealDiv", Mt = "Einsum", Nt = "EluGrad", Pt = "Equal", Ft = "ExpandDims", It = "Expm1", Lt = "Fill", Rt = "FlipLeftRight", zt = "Floor", Bt = "FloorDiv", Vt = "FusedBatchNorm", Ht = "GatherV2", Ut = "GatherNd", Wt = "Greater", Gt = "GreaterEqual", Kt = "Identity", qt = "IFFT", Jt = "Imag", Yt = "IsFinite", Xt = "IsInf", Zt = "IsNan", Qt = "LeakyRelu", $t = "Less", en = "LessEqual", tn = "LinSpace", nn = "Log1p", rn = "LogicalAnd", an = "LogicalNot", on = "LogicalOr", sn = "LogSoftmax", cn = "LRNGrad", ln = "Maximum", un = "MaxPool", dn = "MaxPoolGrad", fn = "MaxPool3D", pn = "MaxPool3DGrad", mn = "MaxPoolWithArgmax", hn = "Mean", gn = "Minimum", _n = "MirrorPad", vn = "Multinomial", yn = "Multiply", bn = "NotEqual", xn = "NonMaxSuppressionV3", Sn = "NonMaxSuppressionV4", Cn = "NonMaxSuppressionV5", wn = "OnesLike", Tn = "OneHot", En = "Pack", Dn = "PadV2", On = "Prelu", kn = "Prod", An = "RaggedGather", jn = "RaggedRange", Mn = "RaggedTensorToTensor", Nn = "Range", Pn = "Real", Fn = "Reciprocal", In = "Relu", Ln = "Reshape", Rn = "ResizeNearestNeighbor", zn = "ResizeNearestNeighborGrad", Bn = "ResizeBilinear", Vn = "ResizeBilinearGrad", Hn = "Relu6", Un = "Reverse", Wn = "Round", Gn = "Rsqrt", Kn = "ScatterNd", qn = "TensorScatterUpdate", Jn = "SearchSorted", Yn = "Select", Xn = "Selu", Zn = "Slice", Qn = "Sinh", $n = "Sign", er = "Sigmoid", tr = "Softplus", nr = "Sqrt", rr = "SpaceToBatchND", ir = "SplitV", ar = "Softmax", or = "SparseFillEmptyRows", sr = "SparseReshape", cr = "SparseSegmentMean", lr = "SparseSegmentSum", ur = "SparseToDense", dr = "SquaredDifference", fr = "Square", pr = "StaticRegexReplace", mr = "StridedSlice", hr = "StringNGrams", gr = "StringSplit", _r = "StringToHashBucketFast", vr = "Tanh", yr = "Tile", br = "TopK", xr = "Transform", Sr = "Transpose", Cr = "Unique", wr = "Unpack", Tr = "UnsortedSegmentSum", Er = "ZerosLike", Dr = "Step", Or = "FromPixels", kr = "RotateWithOffset", Ar = "_FusedMatMul", jr = "FusedConv2D", Mr = "FusedDepthwiseConv2D";
414
+ // node_modules/@tensorflow/tfjs-core/dist/log.js
415
+ function x(...e) {
416
+ b().getBool("IS_TEST") || b().getBool("PROD") || console.warn(...e);
417
+ }
418
+ function Nr(...e) {
419
+ b().getBool("IS_TEST") || b().getBool("PROD") || console.log(...e);
420
+ }
421
+ // node_modules/@tensorflow/tfjs-core/dist/kernel_registry.js
422
+ var Pr = Re("kernelRegistry", () => /* @__PURE__ */ new Map()), Fr = Re("gradRegistry", () => /* @__PURE__ */ new Map());
423
+ function Ir(e, t) {
424
+ let n = Vr(e, t);
425
+ return Pr.get(n);
426
+ }
427
+ function Lr(e) {
428
+ return Fr.get(e);
429
+ }
430
+ function Rr(e) {
431
+ let t = Pr.entries(), n = [];
432
+ for (;;) {
433
+ let { done: r, value: i } = t.next();
434
+ if (r) break;
435
+ let [a, o] = i, [s] = a.split("_");
436
+ s === e && n.push(o);
437
+ }
438
+ return n;
439
+ }
440
+ function zr(e) {
441
+ let { kernelName: t, backendName: n } = e, r = Vr(t, n);
442
+ Pr.has(r) && x(`The kernel '${t}' for backend '${n}' is already registered`), Pr.set(r, e);
443
+ }
444
+ function Br(e) {
445
+ let { kernelName: t } = e;
446
+ Fr.has(t) && b().getBool("DEBUG") && x(`Overriding the gradient for '${t}'`), Fr.set(t, e);
447
+ }
448
+ function Vr(e, t) {
449
+ return `${t}_${e}`;
450
+ }
451
+ // node_modules/@tensorflow/tfjs-core/dist/platforms/is_typed_array_browser.js
452
+ function Hr(e) {
453
+ return e instanceof Float32Array || e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray;
454
+ }
455
+ // node_modules/@tensorflow/tfjs-core/dist/util.js
456
+ function Ur(e, t) {
457
+ return t === "string" ? Kr(e) : Gr([e], t);
458
+ }
459
+ function Wr(e, t) {
460
+ return e instanceof Float32Array && t === "float32" || e instanceof Int32Array && (t === "int32" || t === "packedF16") || e instanceof Uint8Array && t === "bool";
461
+ }
462
+ function Gr(e, t) {
463
+ if (t === "string") throw Error("Cannot convert a string[] to a TypedArray");
464
+ if (Array.isArray(e) && (e = w(e)), b().getBool("DEBUG") && ue(e, t), Wr(e, t)) return e;
465
+ if (t == null || t === "float32" || t === "complex64") return new Float32Array(e);
466
+ if (t === "int32" || t === "packedF16") return new Int32Array(e);
467
+ if (t === "bool") {
468
+ let t = new Uint8Array(e.length);
469
+ for (let n = 0; n < t.length; ++n) Math.round(e[n]) !== 0 && (t[n] = 1);
470
+ return t;
471
+ }
472
+ throw Error(`Unknown data type ${t}`);
473
+ }
474
+ function S() {
475
+ return b().platform.now();
476
+ }
477
+ function Kr(e, t = "utf-8") {
478
+ return t ||= "utf-8", b().platform.encode(e, t);
479
+ }
480
+ function qr(e, t = "utf-8") {
481
+ return t ||= "utf-8", b().platform.decode(e, t);
482
+ }
483
+ function C(e) {
484
+ return b().platform.isTypedArray == null ? Hr(e) : b().platform.isTypedArray(e);
485
+ }
486
+ function w(e, t = [], n = !1) {
487
+ if (t ??= [], typeof e == "boolean" || typeof e == "number" || typeof e == "string" || De(e) || e == null || C(e) && n) t.push(e);
488
+ else if (Array.isArray(e) || C(e)) for (let r = 0; r < e.length; ++r) w(e[r], t, n);
489
+ else {
490
+ let r = -1;
491
+ for (let t of Object.keys(e)) /^([1-9]+[0-9]*|0)$/.test(t) && (r = Math.max(r, Number(t)));
492
+ for (let i = 0; i <= r; i++) w(e[i], t, n);
493
+ }
494
+ return t;
495
+ }
496
+ // node_modules/@tensorflow/tfjs-core/dist/profiler.js
497
+ var Jr = class {
498
+ constructor(e, t) {
499
+ this.backendTimer = e, this.logger = t, t ?? (this.logger = new Xr());
500
+ }
501
+ profileKernel(e, t, n) {
502
+ let r, i = () => {
503
+ r = n();
504
+ }, a, o = S();
505
+ if (this.backendTimer.timerAvailable()) a = this.backendTimer.time(i);
506
+ else {
507
+ i();
508
+ for (let e of r) e.dataSync();
509
+ a = Promise.resolve({ kernelMs: S() - o });
510
+ }
511
+ if (b().getBool("CHECK_COMPUTATION_FOR_ERRORS")) for (let t = 0; t < r.length; t++) {
512
+ let n = r[t];
513
+ n.data().then((t) => {
514
+ Yr(t, n.dtype, e);
515
+ });
516
+ }
517
+ return {
518
+ kernelName: e,
519
+ outputs: r,
520
+ inputs: t,
521
+ timeMs: a.then((e) => e.kernelMs),
522
+ extraInfo: a.then((e) => e.getExtraProfileInfo == null ? "" : e.getExtraProfileInfo())
523
+ };
524
+ }
525
+ logKernelProfile(e) {
526
+ let { kernelName: t, outputs: n, timeMs: r, inputs: i, extraInfo: a } = e;
527
+ n.forEach((e) => {
528
+ Promise.all([
529
+ e.data(),
530
+ r,
531
+ a
532
+ ]).then((n) => {
533
+ this.logger.logKernelProfile(t, e, n[0], n[1], i, n[2]);
534
+ });
535
+ });
536
+ }
537
+ };
538
+ function Yr(e, t, n) {
539
+ if (t !== "float32") return !1;
540
+ for (let t = 0; t < e.length; t++) {
541
+ let r = e[t];
542
+ if (isNaN(r) || !isFinite(r)) return console.warn(`Found ${r} in the result of '${n}'`), !0;
543
+ }
544
+ return !1;
545
+ }
546
+ var Xr = class {
547
+ logKernelProfile(e, t, n, r, i, a) {
548
+ let o = typeof r == "number" ? h(`${r}ms`, 9) : r.error, s = h(e, 25), c = t.rank, l = t.size, u = h(t.shape.toString(), 14), d = "";
549
+ for (let e in i) {
550
+ let n = i[e];
551
+ if (n != null) {
552
+ let r = n.shape || t.shape, i = r.length;
553
+ d += `${e}: ${i}D ${i > 0 ? r : ""} `;
554
+ }
555
+ }
556
+ console.log(`%c${s}\t%c${o}\t%c${c}D ${u}\t%c${l}\t%c${d}\t%c${a}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
557
+ }
558
+ };
559
+ // node_modules/@tensorflow/tfjs-core/dist/tape.js
560
+ function Zr(e, t, n) {
561
+ let r = {}, i = {};
562
+ for (let e = 0; e < t.length; e++) r[t[e].id] = !0;
563
+ for (let n = 0; n < e.length; n++) {
564
+ let a = e[n], o = a.inputs;
565
+ for (let e in o) {
566
+ let n = o[e], s = !1;
567
+ for (let e = 0; e < t.length; e++) if (r[n.id]) {
568
+ a.outputs.forEach((e) => r[e.id] = !0), s = !0, i[a.id] = !0;
569
+ break;
570
+ }
571
+ if (s) break;
572
+ }
573
+ }
574
+ let a = {};
575
+ a[n.id] = !0;
576
+ let o = {};
577
+ for (let t = e.length - 1; t >= 0; t--) {
578
+ let n = e[t], r = n.inputs;
579
+ for (let e = 0; e < n.outputs.length; e++) if (a[n.outputs[e].id]) {
580
+ for (let e in r) a[r[e].id] = !0, o[n.id] = !0;
581
+ break;
582
+ }
583
+ }
584
+ let s = [];
585
+ for (let t = 0; t < e.length; t++) {
586
+ let n = e[t];
587
+ if (i[n.id] && o[n.id]) {
588
+ let e = {};
589
+ for (let t in n.inputs) {
590
+ let i = n.inputs[t];
591
+ r[i.id] && (e[t] = i);
592
+ }
593
+ let t = Object.assign({}, n);
594
+ t.inputs = e, t.outputs = n.outputs, s.push(t);
595
+ }
596
+ }
597
+ return s;
598
+ }
599
+ function Qr(e, t, n, r) {
600
+ for (let i = t.length - 1; i >= 0; i--) {
601
+ let a = t[i], o = [];
602
+ if (a.outputs.forEach((t) => {
603
+ let n = e[t.id];
604
+ n == null ? o.push(null) : o.push(n);
605
+ }), a.gradient == null) throw Error(`Cannot compute gradient: gradient function not found for ${a.kernelName}.`);
606
+ let s = a.gradient(o);
607
+ for (let t in a.inputs) {
608
+ if (!(t in s)) throw Error(`Cannot backprop through input ${t}. Available gradients found: ${Object.keys(s)}.`);
609
+ let i = n(() => s[t]());
610
+ if (i.dtype !== "float32" && i.dtype !== "packedF16") throw Error(`Error in gradient for op ${a.kernelName}. The gradient of input ${t} must have 'float32' or 'packedF16' dtype, but has '${i.dtype}'`);
611
+ let o = a.inputs[t];
612
+ if (!te(i.shape, o.shape)) throw Error(`Error in gradient for op ${a.kernelName}. The gradient of input '${t}' has shape '${i.shape}', which does not match the shape of the input '${o.shape}'`);
613
+ if (e[o.id] == null) e[o.id] = i;
614
+ else {
615
+ let t = e[o.id];
616
+ e[o.id] = r(t, i), t.dispose();
617
+ }
618
+ }
619
+ }
620
+ }
621
+ // node_modules/@tensorflow/tfjs-core/dist/tensor_format.js
622
+ var $r = 20, T = 3, ei = 7;
623
+ function ti(e, t, n, r) {
624
+ let i = ve(t), a = ni(e, t, n, i), o = t.length, s = ii(e, t, n, i, a), c = ["Tensor"];
625
+ return r && (c.push(` dtype: ${n}`), c.push(` rank: ${o}`), c.push(` shape: [${t}]`), c.push(" values:")), c.push(s.map((e) => " " + e).join("\n")), c.join("\n");
626
+ }
627
+ function ni(e, t, n, r) {
628
+ let i = m(t), a = r[r.length - 1], o = Array(a).fill(0), s = t.length, c = n === "complex64" ? D(e) : e;
629
+ if (s > 1) for (let e = 0; e < i / a; e++) {
630
+ let t = e * a;
631
+ for (let e = 0; e < a; e++) o[e] = Math.max(o[e], E(c[t + e], 0, n).length);
632
+ }
633
+ return o;
634
+ }
635
+ function E(e, t, n) {
636
+ let r;
637
+ return r = Array.isArray(e) ? `${parseFloat(e[0].toFixed(ei))} + ${parseFloat(e[1].toFixed(ei))}j` : me(e) ? `'${e}'` : n === "bool" ? ri(e) : parseFloat(e.toFixed(ei)).toString(), h(r, t);
638
+ }
639
+ function ri(e) {
640
+ return e === 0 ? "false" : "true";
641
+ }
642
+ function ii(e, t, n, r, i, a = !0) {
643
+ let o = n === "complex64" ? 2 : 1, s = t[0], c = t.length;
644
+ if (c === 0) return n === "complex64" ? [E(D(e)[0], 0, n)] : n === "bool" ? [ri(e[0])] : [e[0].toString()];
645
+ if (c === 1) {
646
+ if (s > $r) {
647
+ let t = T * o, r = Array.from(e.slice(0, t)), a = Array.from(e.slice((s - T) * o, s * o));
648
+ return n === "complex64" && (r = D(r), a = D(a)), ["[" + r.map((e, t) => E(e, i[t], n)).join(", ") + ", ..., " + a.map((e, t) => E(e, i[s - T + t], n)).join(", ") + "]"];
649
+ }
650
+ return ["[" + (n === "complex64" ? D(e) : Array.from(e)).map((e, t) => E(e, i[t], n)).join(", ") + "]"];
651
+ }
652
+ let l = t.slice(1), u = r.slice(1), d = r[0] * o, f = [];
653
+ if (s > $r) {
654
+ for (let t = 0; t < T; t++) {
655
+ let r = t * d, a = r + d;
656
+ f.push(...ii(e.slice(r, a), l, n, u, i, !1));
657
+ }
658
+ f.push("...");
659
+ for (let t = s - T; t < s; t++) {
660
+ let r = t * d, a = r + d;
661
+ f.push(...ii(e.slice(r, a), l, n, u, i, t === s - 1));
662
+ }
663
+ } else for (let t = 0; t < s; t++) {
664
+ let r = t * d, a = r + d;
665
+ f.push(...ii(e.slice(r, a), l, n, u, i, t === s - 1));
666
+ }
667
+ let p = c === 2 ? "," : "";
668
+ f[0] = "[" + (s > 0 ? f[0] + p : "");
669
+ for (let e = 1; e < f.length - 1; e++) f[e] = " " + f[e] + p;
670
+ let m = ",\n";
671
+ for (let e = 2; e < c; e++) m += "\n";
672
+ return f[f.length - 1] = " " + f[f.length - 1] + "]" + (a ? "" : m), f;
673
+ }
674
+ function D(e) {
675
+ let t = [];
676
+ for (let n = 0; n < e.length; n += 2) t.push([e[n], e[n + 1]]);
677
+ return t;
678
+ }
679
+ // node_modules/@tensorflow/tfjs-core/dist/tensor.js
680
+ var ai = class {
681
+ constructor(e, t, n) {
682
+ if (this.dtype = t, this.shape = e.slice(), this.size = m(e), n != null) {
683
+ let e = n.length;
684
+ d(e === this.size, () => `Length of values '${e}' does not match the size inferred by the shape '${this.size}'.`);
685
+ }
686
+ if (t === "complex64") throw Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");
687
+ this.values = n || le(t, this.size), this.strides = ve(e);
688
+ }
689
+ set(e, ...t) {
690
+ t.length === 0 && (t = [0]), d(t.length === this.rank, () => `The number of provided coordinates (${t.length}) must match the rank (${this.rank})`);
691
+ let n = this.locToIndex(t);
692
+ this.values[n] = e;
693
+ }
694
+ get(...e) {
695
+ e.length === 0 && (e = [0]);
696
+ let t = 0;
697
+ for (let n of e) {
698
+ if (n < 0 || n >= this.shape[t]) {
699
+ let t = `Requested out of range element at ${e}. Buffer shape=${this.shape}`;
700
+ throw Error(t);
701
+ }
702
+ t++;
703
+ }
704
+ let n = e[e.length - 1];
705
+ for (let t = 0; t < e.length - 1; ++t) n += this.strides[t] * e[t];
706
+ return this.values[n];
707
+ }
708
+ locToIndex(e) {
709
+ if (this.rank === 0) return 0;
710
+ if (this.rank === 1) return e[0];
711
+ let t = e[e.length - 1];
712
+ for (let n = 0; n < e.length - 1; ++n) t += this.strides[n] * e[n];
713
+ return t;
714
+ }
715
+ indexToLoc(e) {
716
+ if (this.rank === 0) return [];
717
+ if (this.rank === 1) return [e];
718
+ let t = Array(this.shape.length);
719
+ for (let n = 0; n < t.length - 1; ++n) t[n] = Math.floor(e / this.strides[n]), e -= t[n] * this.strides[n];
720
+ return t[t.length - 1] = e, t;
721
+ }
722
+ get rank() {
723
+ return this.shape.length;
724
+ }
725
+ toTensor() {
726
+ return O().makeTensor(this.values, this.shape, this.dtype);
727
+ }
728
+ }, O = null, k = null;
729
+ function oi(e) {
730
+ O = e;
731
+ }
732
+ function si(e) {
733
+ k = e;
734
+ }
735
+ var A = class {
736
+ constructor(e, t, n, r) {
737
+ this.kept = !1, this.isDisposedInternal = !1, this.shape = e.slice(), this.dtype = t || "float32", this.size = m(e), this.strides = ve(e), this.dataId = n, this.id = r, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
738
+ }
739
+ get rank() {
740
+ return this.shape.length;
741
+ }
742
+ async buffer() {
743
+ let e = await this.data();
744
+ return k.buffer(this.shape, this.dtype, e);
745
+ }
746
+ bufferSync() {
747
+ return k.buffer(this.shape, this.dtype, this.dataSync());
748
+ }
749
+ async array() {
750
+ let e = await this.data();
751
+ return y(this.shape, e, this.dtype === "complex64");
752
+ }
753
+ arraySync() {
754
+ return y(this.shape, this.dataSync(), this.dtype === "complex64");
755
+ }
756
+ async data() {
757
+ this.throwIfDisposed();
758
+ let e = O().read(this.dataId);
759
+ if (this.dtype === "string") {
760
+ let t = await e;
761
+ try {
762
+ return t.map((e) => qr(e));
763
+ } catch {
764
+ throw Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
765
+ }
766
+ }
767
+ return e;
768
+ }
769
+ dataToGPU(e) {
770
+ return this.throwIfDisposed(), O().readToGPU(this.dataId, e);
771
+ }
772
+ dataSync() {
773
+ this.throwIfDisposed();
774
+ let e = O().readSync(this.dataId);
775
+ if (this.dtype === "string") try {
776
+ return e.map((e) => qr(e));
777
+ } catch {
778
+ throw Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
779
+ }
780
+ return e;
781
+ }
782
+ async bytes() {
783
+ this.throwIfDisposed();
784
+ let e = await O().read(this.dataId);
785
+ return this.dtype === "string" ? e : new Uint8Array(e.buffer);
786
+ }
787
+ dispose() {
788
+ this.isDisposed || (this.kerasMask && this.kerasMask.dispose(), O().disposeTensor(this), this.isDisposedInternal = !0);
789
+ }
790
+ get isDisposed() {
791
+ return this.isDisposedInternal;
792
+ }
793
+ throwIfDisposed() {
794
+ if (this.isDisposed) throw Error("Tensor is disposed.");
795
+ }
796
+ print(e = !1) {
797
+ return k.print(this, e);
798
+ }
799
+ clone() {
800
+ return this.throwIfDisposed(), k.clone(this);
801
+ }
802
+ toString(e = !1) {
803
+ return ti(this.dataSync(), this.shape, this.dtype, e);
804
+ }
805
+ cast(e) {
806
+ return this.throwIfDisposed(), k.cast(this, e);
807
+ }
808
+ variable(e = !0, t, n) {
809
+ return this.throwIfDisposed(), O().makeVariable(this, e, t, n);
810
+ }
811
+ };
812
+ Object.defineProperty(A, Symbol.hasInstance, { value: (e) => !!e && e.data != null && e.dataSync != null && e.throwIfDisposed != null });
813
+ function ci() {
814
+ return Re("Tensor", () => A);
815
+ }
816
+ ci();
817
+ var li = class extends A {
818
+ constructor(e, t, n, r) {
819
+ super(e.shape, e.dtype, e.dataId, r), this.trainable = t, this.name = n;
820
+ }
821
+ assign(e) {
822
+ if (e.dtype !== this.dtype) throw Error(`dtype of the new value (${e.dtype}) and previous value (${this.dtype}) must match`);
823
+ if (!te(e.shape, this.shape)) throw Error(`shape of the new value (${e.shape}) and previous value (${this.shape}) must match`);
824
+ O().disposeTensor(this), this.dataId = e.dataId, O().incRef(this, null);
825
+ }
826
+ dispose() {
827
+ O().disposeVariable(this), this.isDisposedInternal = !0;
828
+ }
829
+ };
830
+ Object.defineProperty(li, Symbol.hasInstance, { value: (e) => e instanceof A && e.assign != null && e.assign instanceof Function });
831
+ // node_modules/@tensorflow/tfjs-core/dist/types.js
832
+ var ui;
833
+ (function(e) {
834
+ e.R0 = "R0", e.R1 = "R1", e.R2 = "R2", e.R3 = "R3", e.R4 = "R4", e.R5 = "R5", e.R6 = "R6";
835
+ })(ui ||= {});
836
+ var di;
837
+ (function(e) {
838
+ e.float32 = "float32", e.int32 = "int32", e.packedF16 = "int32", e.bool = "int32", e.complex64 = "complex64";
839
+ })(di ||= {});
840
+ var fi;
841
+ (function(e) {
842
+ e.float32 = "float32", e.int32 = "int32", e.packedF16 = "int32", e.bool = "bool", e.complex64 = "complex64";
843
+ })(fi ||= {});
844
+ var pi;
845
+ (function(e) {
846
+ e.float32 = "float32", e.int32 = "float32", e.packedF16 = "float32", e.bool = "float32", e.complex64 = "complex64";
847
+ })(pi ||= {});
848
+ var mi;
849
+ (function(e) {
850
+ e.float32 = "complex64", e.int32 = "complex64", e.packedF16 = "complex64", e.bool = "complex64", e.complex64 = "complex64";
851
+ })(mi ||= {});
852
+ var hi = {
853
+ float32: pi,
854
+ int32: di,
855
+ packedF16: di,
856
+ bool: fi,
857
+ complex64: mi
858
+ };
859
+ function gi(e, t) {
860
+ if (e === "string" || t === "string") {
861
+ if (e === "string" && t === "string") return "string";
862
+ throw Error(`Can not upcast ${e} with ${t}`);
863
+ }
864
+ return hi[e][t];
865
+ }
866
+ function _i(e) {
867
+ return gi(e, "int32");
868
+ }
869
+ function vi(e) {
870
+ return typeof e == "object" && !!e && "texture" in e && e.texture instanceof WebGLTexture;
871
+ }
872
+ function yi(e) {
873
+ return typeof GPUBuffer < "u" && typeof e == "object" && !!e && "buffer" in e && e.buffer instanceof GPUBuffer;
874
+ }
875
+ // node_modules/@tensorflow/tfjs-core/dist/tensor_util.js
876
+ function j(e, t) {
877
+ if (e.dtype === t.dtype) return [e, t];
878
+ let n = gi(e.dtype, t.dtype);
879
+ return [e.cast(n), t.cast(n)];
880
+ }
881
+ function bi(e, t) {
882
+ return t.some((t) => t.id === e.id);
883
+ }
884
+ function xi(e) {
885
+ let t = [];
886
+ return Si(e, t, /* @__PURE__ */ new Set()), t;
887
+ }
888
+ function Si(e, t, n) {
889
+ if (e == null) return;
890
+ if (e instanceof A) {
891
+ t.push(e);
892
+ return;
893
+ }
894
+ if (!Ci(e)) return;
895
+ let r = e;
896
+ for (let e in r) {
897
+ let i = r[e];
898
+ n.has(i) || (n.add(i), Si(i, t, n));
899
+ }
900
+ }
901
+ function Ci(e) {
902
+ return Array.isArray(e) || typeof e == "object";
903
+ }
904
+ // node_modules/@tensorflow/tfjs-core/dist/engine.js
905
+ function wi(e) {
906
+ return e.kernelName != null;
907
+ }
908
+ var Ti = class {
909
+ constructor() {
910
+ this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = /* @__PURE__ */ new WeakMap(), this.profiling = !1, this.activeProfile = {
911
+ newBytes: 0,
912
+ newTensors: 0,
913
+ peakBytes: 0,
914
+ kernels: [],
915
+ result: null,
916
+ get kernelNames() {
917
+ return Array.from(new Set(this.kernels.map((e) => e.name)));
918
+ }
919
+ };
920
+ }
921
+ dispose() {
922
+ for (let e in this.registeredVariables) this.registeredVariables[e].dispose();
923
+ }
924
+ }, Ei = class e {
925
+ constructor(e) {
926
+ this.ENV = e, this.version = "GENAI_PATCH_1", this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new Ti();
927
+ }
928
+ async ready() {
929
+ if (this.pendingBackendInit != null) return this.pendingBackendInit.then(() => {});
930
+ if (this.backendInstance != null) return;
931
+ let e = this.getSortedBackends();
932
+ for (let t = 0; t < e.length; t++) {
933
+ let n = e[t];
934
+ if (await this.initializeBackend(n).success) {
935
+ await this.setBackend(n);
936
+ return;
937
+ }
938
+ }
939
+ throw Error("Could not initialize any backends, all backend initializations failed.");
940
+ }
941
+ get backend() {
942
+ if (this.pendingBackendInit != null) throw Error(`Backend '${this.backendName}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);
943
+ if (this.backendInstance == null) {
944
+ let { name: e, asyncInit: t } = this.initializeBackendsAndReturnBest();
945
+ if (t) throw Error(`The highest priority backend '${e}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);
946
+ this.setBackend(e);
947
+ }
948
+ return this.backendInstance;
949
+ }
950
+ backendNames() {
951
+ return Object.keys(this.registryFactory);
952
+ }
953
+ findBackend(e) {
954
+ if (!(e in this.registry)) {
955
+ if (e in this.registryFactory) {
956
+ let { asyncInit: t } = this.initializeBackend(e);
957
+ if (t) return null;
958
+ } else return null;
959
+ }
960
+ return this.registry[e];
961
+ }
962
+ findBackendFactory(e) {
963
+ return e in this.registryFactory ? this.registryFactory[e].factory : null;
964
+ }
965
+ registerBackend(e, t, n = 1) {
966
+ return e in this.registryFactory ? (x(`${e} backend was already registered. Reusing existing backend factory.`), !1) : (this.registryFactory[e] = {
967
+ factory: t,
968
+ priority: n
969
+ }, !0);
970
+ }
971
+ async setBackend(e) {
972
+ if (this.registryFactory[e] == null) throw Error(`Backend name '${e}' not found in registry`);
973
+ if (this.backendName = e, this.registry[e] == null) {
974
+ this.backendInstance = null;
975
+ let { success: t, asyncInit: n } = this.initializeBackend(e);
976
+ if (!(n ? await t : t)) return !1;
977
+ }
978
+ return this.backendInstance = this.registry[e], this.setupRegisteredKernels(), this.profiler = new Jr(this.backendInstance), !0;
979
+ }
980
+ setupRegisteredKernels() {
981
+ Rr(this.backendName).forEach((e) => {
982
+ e.setupFunc != null && e.setupFunc(this.backendInstance);
983
+ });
984
+ }
985
+ disposeRegisteredKernels(e) {
986
+ Rr(e).forEach((t) => {
987
+ t.disposeFunc != null && t.disposeFunc(this.registry[e]);
988
+ });
989
+ }
990
+ initializeBackend(e) {
991
+ let t = this.registryFactory[e];
992
+ if (t == null) throw Error(`Cannot initialize backend ${e}, no registration found.`);
993
+ try {
994
+ let n = t.factory();
995
+ if (n && !(n instanceof i) && typeof n.then == "function") {
996
+ let t = ++this.pendingBackendInitId, r = n.then((n) => t < this.pendingBackendInitId ? !1 : (this.registry[e] = n, this.pendingBackendInit = null, !0)).catch((n) => (t < this.pendingBackendInitId || (this.pendingBackendInit = null, x(`Initialization of backend ${e} failed`), x(n.stack || n.message)), !1));
997
+ return this.pendingBackendInit = r, {
998
+ success: r,
999
+ asyncInit: !0
1000
+ };
1001
+ }
1002
+ return this.registry[e] = n, {
1003
+ success: !0,
1004
+ asyncInit: !1
1005
+ };
1006
+ } catch (t) {
1007
+ return x(`Initialization of backend ${e} failed`), x(t.stack || t.message), {
1008
+ success: !1,
1009
+ asyncInit: !1
1010
+ };
1011
+ }
1012
+ }
1013
+ removeBackend(e) {
1014
+ if (!(e in this.registryFactory)) throw Error(`${e} backend not found in registry`);
1015
+ this.backendName === e && this.pendingBackendInit != null && this.pendingBackendInitId++, e in this.registry && (this.disposeRegisteredKernels(e), this.registry[e].dispose(), delete this.registry[e]), delete this.registryFactory[e], this.backendName === e && (this.pendingBackendInit = null, this.backendName = null, this.backendInstance = null);
1016
+ }
1017
+ getSortedBackends() {
1018
+ if (Object.keys(this.registryFactory).length === 0) throw Error("No backend found in registry.");
1019
+ return Object.keys(this.registryFactory).sort((e, t) => this.registryFactory[t].priority - this.registryFactory[e].priority);
1020
+ }
1021
+ initializeBackendsAndReturnBest() {
1022
+ let e = this.getSortedBackends();
1023
+ for (let t = 0; t < e.length; t++) {
1024
+ let n = e[t], { success: r, asyncInit: i } = this.initializeBackend(n);
1025
+ if (i || r) return {
1026
+ name: n,
1027
+ asyncInit: i
1028
+ };
1029
+ }
1030
+ throw Error("Could not initialize any backends, all backend initializations failed.");
1031
+ }
1032
+ moveData(e, t) {
1033
+ let n = this.state.tensorInfo.get(t), r = n.backend, i = this.readSync(t), a = r.refCount(t);
1034
+ r.disposeData(t, !0), n.backend = e, e.move(t, i, n.shape, n.dtype, a), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++;
1035
+ }
1036
+ tidy(e, t) {
1037
+ let n = null;
1038
+ if (t == null) {
1039
+ if (typeof e != "function") throw Error("Please provide a function to tidy()");
1040
+ t = e;
1041
+ } else {
1042
+ if (typeof e != "string" && !(e instanceof String)) throw Error("When calling with two arguments, the first argument to tidy() must be a string");
1043
+ if (typeof t != "function") throw Error("When calling with two arguments, the 2nd argument to tidy() must be a function");
1044
+ n = e;
1045
+ }
1046
+ let r;
1047
+ return this.scopedRun(() => this.startScope(n), () => this.endScope(r), () => (r = t(), r instanceof Promise && console.error("Cannot return a Promise inside of tidy."), r));
1048
+ }
1049
+ scopedRun(e, t, n) {
1050
+ e();
1051
+ try {
1052
+ let e = n();
1053
+ return t(), e;
1054
+ } catch (e) {
1055
+ throw t(), e;
1056
+ }
1057
+ }
1058
+ nextTensorId() {
1059
+ return e.nextTensorId++;
1060
+ }
1061
+ nextVariableId() {
1062
+ return e.nextVariableId++;
1063
+ }
1064
+ clone(e) {
1065
+ let t = M.runKernel(Kt, { x: e }), n = { x: e };
1066
+ return this.addTapeNode(this.state.activeScope.name, n, [t], (t) => ({ x: () => {
1067
+ let n = e.dtype === "packedF16" ? "packedF16" : "float32", r = { x: t }, i = { dtype: n };
1068
+ return M.runKernel(at, r, i);
1069
+ } }), [], {}), t;
1070
+ }
1071
+ runKernel(e, t, n) {
1072
+ if (this.backendName ?? this.backend, Ir(e, this.backendName) == null) throw Error(`Kernel '${e}' not registered for backend '${this.backendName}'`);
1073
+ return this.runKernelFunc({
1074
+ kernelName: e,
1075
+ inputs: t,
1076
+ attrs: n
1077
+ });
1078
+ }
1079
+ shouldCheckForMemLeaks() {
1080
+ return this.ENV.getBool("IS_TEST");
1081
+ }
1082
+ checkKernelForMemLeak(e, t, n) {
1083
+ let r = this.backend.numDataIds(), i = 0;
1084
+ n.forEach((e) => {
1085
+ i += e.dtype === "complex64" ? 3 : 1;
1086
+ });
1087
+ let a = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], o = r - t - i - a;
1088
+ if (o > 0) throw Error(`Backend '${this.backendName}' has an internal memory leak (${o} data ids) after running '${e}'`);
1089
+ }
1090
+ runKernelFunc(e) {
1091
+ let t, n = [], r = this.isTapeOn(), i = this.state.numBytes, a = this.state.numTensors;
1092
+ this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0);
1093
+ let o;
1094
+ this.backendName ?? this.backend;
1095
+ let s, c = wi(e) ? e.kernelName : this.state.activeScope == null ? "" : this.state.activeScope.name;
1096
+ if (wi(e)) {
1097
+ let { kernelName: t, inputs: i, attrs: a } = e;
1098
+ this.backendName ?? this.backend;
1099
+ let c = Ir(t, this.backendName);
1100
+ d(c != null, () => `Cannot find registered kernel '${t}' for backend '${this.backendName}'`), o = () => {
1101
+ let e = this.backend.numDataIds();
1102
+ s = c.kernelFunc({
1103
+ inputs: i,
1104
+ attrs: a,
1105
+ backend: this.backend
1106
+ });
1107
+ let o = Array.isArray(s) ? s : [s];
1108
+ this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(t, e, o);
1109
+ let l = o.map((e) => e.rank == null ? this.makeTensorFromTensorInfo(e) : e);
1110
+ if (r) {
1111
+ let e = this.getTensorsForGradient(t, i, l);
1112
+ n = this.saveTensorsForBackwardMode(e);
1113
+ }
1114
+ return l;
1115
+ };
1116
+ } else {
1117
+ let { forwardFunc: t } = e, i = (e) => {
1118
+ r && (n = e.map((e) => this.keep(this.clone(e))));
1119
+ };
1120
+ o = () => {
1121
+ let e = this.backend.numDataIds();
1122
+ s = this.tidy(() => t(this.backend, i));
1123
+ let n = Array.isArray(s) ? s : [s];
1124
+ return this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(c, e, n), n;
1125
+ };
1126
+ }
1127
+ let { inputs: l, attrs: u } = e, f = wi(e) ? null : e.backwardsFunc, p;
1128
+ return this.scopedRun(() => this.state.kernelDepth++, () => this.state.kernelDepth--, () => {
1129
+ !this.ENV.getBool("DEBUG") && !this.state.profiling ? t = o() : (p = this.profiler.profileKernel(c, l, () => o()), this.ENV.getBool("DEBUG") && this.profiler.logKernelProfile(p), t = p.outputs);
1130
+ }), r && this.addTapeNode(c, l, t, f, n, u), this.state.profiling && this.state.activeProfile.kernels.push({
1131
+ name: c,
1132
+ bytesAdded: this.state.numBytes - i,
1133
+ totalBytesSnapshot: this.state.numBytes,
1134
+ tensorsAdded: this.state.numTensors - a,
1135
+ totalTensorsSnapshot: this.state.numTensors,
1136
+ inputShapes: Object.keys(l).map((e) => l[e] == null ? null : l[e].shape),
1137
+ outputShapes: t.map((e) => e.shape),
1138
+ kernelTimeMs: p.timeMs,
1139
+ extraInfo: p.extraInfo
1140
+ }), Array.isArray(s) ? t : t[0];
1141
+ }
1142
+ saveTensorsForBackwardMode(e) {
1143
+ return e.map((e) => this.keep(this.clone(e)));
1144
+ }
1145
+ getTensorsForGradient(e, t, n) {
1146
+ let r = Lr(e);
1147
+ if (r != null) {
1148
+ let e = r.inputsToSave || [], i = r.outputsToSave || [], a;
1149
+ r.saveAllInputs ? (d(Array.isArray(t), () => "saveAllInputs is true, expected inputs to be an array."), a = Object.keys(t).map((e) => t[e])) : a = e.map((e) => t[e]);
1150
+ let o = n.filter((e, t) => i[t]);
1151
+ return a.concat(o);
1152
+ }
1153
+ return [];
1154
+ }
1155
+ makeTensor(e, t, n, r) {
1156
+ if (e == null) throw Error("Values passed to engine.makeTensor() are null");
1157
+ n ||= "float32", r ||= this.backend;
1158
+ let i = e;
1159
+ n === "string" && me(e[0]) && (i = e.map((e) => Kr(e)));
1160
+ let a = r.write(i, t, n), o = new A(t, n, a, this.nextTensorId());
1161
+ if (this.trackTensor(o, r), n === "string") {
1162
+ let e = this.state.tensorInfo.get(a), t = pe(i);
1163
+ this.state.numBytes += t - e.bytes, e.bytes = t;
1164
+ }
1165
+ return o;
1166
+ }
1167
+ makeTensorFromDataId(e, t, n, r) {
1168
+ n ||= "float32";
1169
+ let i = {
1170
+ dataId: e,
1171
+ shape: t,
1172
+ dtype: n
1173
+ };
1174
+ return this.makeTensorFromTensorInfo(i, r);
1175
+ }
1176
+ makeTensorFromTensorInfo(e, t) {
1177
+ let { dataId: n, shape: r, dtype: i } = e, a = new A(r, i, n, this.nextTensorId());
1178
+ return this.trackTensor(a, t), a;
1179
+ }
1180
+ makeVariable(e, t = !0, n, r) {
1181
+ n ||= this.nextVariableId().toString(), r != null && r !== e.dtype && (e = e.cast(r));
1182
+ let i = new li(e, t, n, this.nextTensorId());
1183
+ if (this.state.registeredVariables[i.name] != null) throw Error(`Variable with name ${i.name} was already registered`);
1184
+ return this.state.registeredVariables[i.name] = i, this.incRef(i, this.backend), i;
1185
+ }
1186
+ trackTensor(e, t) {
1187
+ this.state.numTensors++, e.dtype === "string" && this.state.numStringTensors++;
1188
+ let n = 0;
1189
+ e.dtype !== "complex64" && e.dtype !== "string" && (n = e.size * g(e.dtype)), this.state.numBytes += n, this.state.tensorInfo.has(e.dataId) || (this.state.numDataBuffers++, this.state.tensorInfo.set(e.dataId, {
1190
+ backend: t || this.backend,
1191
+ dtype: e.dtype,
1192
+ shape: e.shape,
1193
+ bytes: n
1194
+ })), e instanceof li || this.track(e);
1195
+ }
1196
+ incRef(e, t) {
1197
+ this.trackTensor(e, t), this.backend.incRef(e.dataId);
1198
+ }
1199
+ removeDataId(e, t) {
1200
+ this.state.tensorInfo.has(e) && this.state.tensorInfo.get(e).backend === t && (this.state.tensorInfo.delete(e), this.state.numDataBuffers--);
1201
+ }
1202
+ disposeTensor(e) {
1203
+ if (!this.state.tensorInfo.has(e.dataId)) return;
1204
+ let t = this.state.tensorInfo.get(e.dataId);
1205
+ if (this.state.numTensors--, e.dtype === "string" && (this.state.numStringTensors--, this.state.numBytes -= t.bytes), e.dtype !== "complex64" && e.dtype !== "string") {
1206
+ let t = e.size * g(e.dtype);
1207
+ this.state.numBytes -= t;
1208
+ }
1209
+ t.backend.disposeData(e.dataId) && this.removeDataId(e.dataId, t.backend);
1210
+ }
1211
+ disposeVariables() {
1212
+ for (let e in this.state.registeredVariables) {
1213
+ let t = this.state.registeredVariables[e];
1214
+ this.disposeVariable(t);
1215
+ }
1216
+ }
1217
+ disposeVariable(e) {
1218
+ this.disposeTensor(e), this.state.registeredVariables[e.name] != null && delete this.state.registeredVariables[e.name];
1219
+ }
1220
+ memory() {
1221
+ let e = this.backend.memory();
1222
+ return e.numTensors = this.state.numTensors, e.numDataBuffers = this.state.numDataBuffers, e.numBytes = this.state.numBytes, this.state.numStringTensors > 0 && (e.unreliable = !0, e.reasons ??= [], e.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")), e;
1223
+ }
1224
+ async profile(e) {
1225
+ this.state.profiling = !0;
1226
+ let t = this.state.numBytes, n = this.state.numTensors;
1227
+ this.state.activeProfile.kernels = [], this.state.activeProfile.result = await e(), this.state.profiling = !1, this.state.activeProfile.peakBytes = Math.max(...this.state.activeProfile.kernels.map((e) => e.totalBytesSnapshot)), this.state.activeProfile.newBytes = this.state.numBytes - t, this.state.activeProfile.newTensors = this.state.numTensors - n;
1228
+ for (let e of this.state.activeProfile.kernels) e.kernelTimeMs = await e.kernelTimeMs, e.extraInfo = await e.extraInfo;
1229
+ return this.state.activeProfile;
1230
+ }
1231
+ isTapeOn() {
1232
+ return this.state.gradientDepth > 0 && this.state.kernelDepth === 0;
1233
+ }
1234
+ addTapeNode(e, t, n, r, i, a) {
1235
+ let o = {
1236
+ id: this.state.nextTapeNodeId++,
1237
+ kernelName: e,
1238
+ inputs: t,
1239
+ outputs: n,
1240
+ saved: i
1241
+ }, s = Lr(e);
1242
+ s != null && (r = s.gradFunc), r != null && (o.gradient = (e) => (e = e.map((e, t) => {
1243
+ if (e == null) {
1244
+ let e = n[t], r = Se(e.size, e.dtype);
1245
+ return this.makeTensor(r, e.shape, e.dtype);
1246
+ }
1247
+ return e;
1248
+ }), r(e.length > 1 ? e : e[0], i, a))), this.state.activeTape.push(o);
1249
+ }
1250
+ keep(e) {
1251
+ return e.kept = !0, e;
1252
+ }
1253
+ startTape() {
1254
+ this.state.gradientDepth === 0 && (this.state.activeTape = []), this.state.gradientDepth++;
1255
+ }
1256
+ endTape() {
1257
+ this.state.gradientDepth--;
1258
+ }
1259
+ startScope(e) {
1260
+ let t = {
1261
+ track: [],
1262
+ name: "unnamed scope",
1263
+ id: this.state.nextScopeId++
1264
+ };
1265
+ e && (t.name = e), this.state.scopeStack.push(t), this.state.activeScope = t;
1266
+ }
1267
+ endScope(e) {
1268
+ let t = xi(e), n = new Set(t.map((e) => e.id));
1269
+ for (let e = 0; e < this.state.activeScope.track.length; e++) {
1270
+ let t = this.state.activeScope.track[e];
1271
+ !t.kept && !n.has(t.id) && t.dispose();
1272
+ }
1273
+ let r = this.state.scopeStack.pop();
1274
+ this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], t.forEach((e) => {
1275
+ !e.kept && e.scopeId === r.id && this.track(e);
1276
+ });
1277
+ }
1278
+ gradients(e, t, n, r = !1) {
1279
+ if (d(t.length > 0, () => "gradients() received an empty list of xs."), n != null && n.dtype !== "float32" && n.dtype !== "packedF16") throw Error(`dy must have 'float32' dtype, but has '${n.dtype}'`);
1280
+ let i = this.scopedRun(() => this.startTape(), () => this.endTape(), () => this.tidy("forward", e));
1281
+ d(i instanceof A, () => "The result y returned by f() must be a tensor.");
1282
+ let a = Zr(this.state.activeTape, t, i);
1283
+ if (!r && a.length === 0 && t.length > 0) throw Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");
1284
+ return this.tidy("backward", () => {
1285
+ let e = {};
1286
+ e[i.id] = n ?? Di(i.shape), Qr(e, a, (e) => this.tidy(e), ki);
1287
+ let r = t.map((t) => e[t.id]);
1288
+ return this.state.gradientDepth === 0 && (this.state.activeTape.forEach((e) => {
1289
+ for (let t of e.saved) t.dispose();
1290
+ }), this.state.activeTape = null), {
1291
+ value: i,
1292
+ grads: r
1293
+ };
1294
+ });
1295
+ }
1296
+ customGrad(e) {
1297
+ return d(v(e), () => "The f passed in customGrad(f) must be a function."), (...t) => {
1298
+ d(t.every((e) => e instanceof A), () => "The args passed in customGrad(f)(x1, x2,...) must all be tensors");
1299
+ let n, r = {};
1300
+ return t.forEach((e, t) => {
1301
+ r[t] = e;
1302
+ }), this.runKernelFunc({
1303
+ forwardFunc: (r, i) => (n = e(...t, i), d(n.value instanceof A, () => "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"), d(v(n.gradFunc), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."), n.value),
1304
+ backwardsFunc: (e, r) => {
1305
+ let i = n.gradFunc(e, r), a = Array.isArray(i) ? i : [i];
1306
+ d(a.length === t.length, () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."), d(a.every((e) => e instanceof A), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.");
1307
+ let o = {};
1308
+ return a.forEach((e, t) => {
1309
+ o[t] = () => e;
1310
+ }), o;
1311
+ },
1312
+ inputs: r
1313
+ });
1314
+ };
1315
+ }
1316
+ readSync(e) {
1317
+ return this.state.tensorInfo.get(e).backend.readSync(e);
1318
+ }
1319
+ read(e) {
1320
+ return this.state.tensorInfo.get(e).backend.read(e);
1321
+ }
1322
+ readToGPU(e, t) {
1323
+ return this.state.tensorInfo.get(e).backend.readToGPU(e, t);
1324
+ }
1325
+ async time(e) {
1326
+ let t = S(), n = await this.backend.time(e);
1327
+ return n.wallMs = S() - t, n;
1328
+ }
1329
+ track(e) {
1330
+ return this.state.activeScope != null && (e.scopeId = this.state.activeScope.id, this.state.activeScope.track.push(e)), e;
1331
+ }
1332
+ get registeredVariables() {
1333
+ return this.state.registeredVariables;
1334
+ }
1335
+ reset() {
1336
+ this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new Ti();
1337
+ for (let e in this.registry) this.disposeRegisteredKernels(e), this.registry[e].dispose(), delete this.registry[e];
1338
+ this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null;
1339
+ }
1340
+ };
1341
+ Ei.nextTensorId = 0, Ei.nextVariableId = 0;
1342
+ function Di(e) {
1343
+ let t = xe(m(e), "float32");
1344
+ return M.makeTensor(t, e, "float32");
1345
+ }
1346
+ function Oi() {
1347
+ let e = Ie();
1348
+ return e._tfengine ??= new Ei(new ke(e)), Pe(e._tfengine.ENV), oi(() => e._tfengine), e._tfengine;
1349
+ }
1350
+ var M = Oi();
1351
+ function ki(e, t) {
1352
+ let n = {
1353
+ a: e,
1354
+ b: t
1355
+ }, r = e.dtype === "packedF16" || t.dtype === "packedF16";
1356
+ return M.runKernel(r ? "Add16" : "Add", n);
1357
+ }
1358
+ // node_modules/@tensorflow/tfjs-core/dist/device_util.js
1359
+ function Ai() {
1360
+ return typeof navigator < "u" && navigator != null;
1361
+ }
1362
+ function ji(e) {
1363
+ if (e || Ai()) {
1364
+ if (e ||= navigator, e.product === "ReactNative") return !0;
1365
+ let t = e.userAgent || e.vendor || (typeof window < "u" ? window.opera : "");
1366
+ if (!t) {
1367
+ let t = e;
1368
+ return t.userAgentData && t.userAgentData.mobile;
1369
+ }
1370
+ return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0, 4));
1371
+ }
1372
+ return !1;
1373
+ }
1374
+ function Mi() {
1375
+ return typeof window < "u" && window.document != null || typeof WorkerGlobalScope < "u";
1376
+ }
1377
+ // node_modules/@tensorflow/tfjs-core/dist/flags.js
1378
+ var N = b();
1379
+ N.registerFlag("DEBUG", () => !1, (e) => {
1380
+ e && console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.");
1381
+ }), N.registerFlag("IS_BROWSER", () => Mi()), N.registerFlag("IS_NODE", () => typeof process < "u" && process.versions !== void 0 && process.versions.node !== void 0), N.registerFlag("IS_CHROME", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)), N.registerFlag("IS_SAFARI", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Safari/.test(navigator.userAgent) && /Apple/.test(navigator.vendor)), N.registerFlag("PROD", () => !1), N.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", () => N.getBool("DEBUG")), N.registerFlag("DEPRECATION_WARNINGS_ENABLED", () => !0), N.registerFlag("IS_TEST", () => !1), N.registerFlag("CHECK_COMPUTATION_FOR_ERRORS", () => N.getBool("DEBUG")), N.registerFlag("WRAP_TO_IMAGEBITMAP", () => !1), N.registerFlag("CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU", () => !1), N.registerFlag("USE_SETTIMEOUTCUSTOM", () => !1);
1382
+ // node_modules/@tensorflow/tfjs-core/dist/tensor_util_env.js
1383
+ function Ni(e, t) {
1384
+ let n = e;
1385
+ if (C(e)) return t === "string" ? [] : [e.length];
1386
+ if (vi(e)) {
1387
+ let t = e.channels || "RGBA";
1388
+ return [e.height, e.width * t.length];
1389
+ }
1390
+ if (yi(e)) return [e.buffer.size / (t == null ? 4 : g(t))];
1391
+ if (!Array.isArray(e)) return [];
1392
+ let r = [];
1393
+ for (; Array.isArray(n) || C(n) && t !== "string";) r.push(n.length), n = n[0];
1394
+ return Array.isArray(e) && b().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && Pi(e, r, []), r;
1395
+ }
1396
+ function Pi(e, t, n) {
1397
+ if (n ||= [], !Array.isArray(e) && !C(e)) {
1398
+ d(t.length === 0, () => `Element arr[${n.join("][")}] is a primitive, but should be an array/TypedArray of ${t[0]} elements`);
1399
+ return;
1400
+ }
1401
+ d(t.length > 0, () => `Element arr[${n.join("][")}] should be a primitive, but is an array of ${e.length} elements`), d(e.length === t[0], () => `Element arr[${n.join("][")}] should have ${t[0]} elements, but has ${e.length} elements`);
1402
+ let r = t.slice(1);
1403
+ for (let t = 0; t < e.length; ++t) Pi(e[t], r, n.concat(t));
1404
+ }
1405
+ function Fi(e, t, n, r) {
1406
+ if (e !== "string_or_numeric") {
1407
+ if (e == null) throw Error("Expected dtype cannot be null.");
1408
+ if (e !== "numeric" && e !== t || e === "numeric" && t === "string") throw Error(`Argument '${n}' passed to '${r}' must be ${e} tensor, but got ${t} tensor`);
1409
+ }
1410
+ }
1411
+ function P(e, t, n, r = "numeric") {
1412
+ if (e instanceof ci()) return Fi(r, e.dtype, t, n), e;
1413
+ let i = _(e);
1414
+ if (i !== "string" && [
1415
+ "bool",
1416
+ "int32",
1417
+ "float32"
1418
+ ].indexOf(r) >= 0 && (i = r), Fi(r, i, t, n), e == null || !C(e) && !Array.isArray(e) && typeof e != "number" && typeof e != "boolean" && typeof e != "string") {
1419
+ let r = e == null ? "null" : e.constructor.name;
1420
+ throw Error(`Argument '${t}' passed to '${n}' must be a Tensor or TensorLike, but got '${r}'`);
1421
+ }
1422
+ let a = Ni(e, i);
1423
+ !C(e) && !Array.isArray(e) && (e = [e]);
1424
+ let o = i === "string" ? w(e, [], !0) : Gr(e, i);
1425
+ return M.makeTensor(o, a, i);
1426
+ }
1427
+ function Ii(e, t, n, r = "numeric") {
1428
+ if (!Array.isArray(e)) throw Error(`Argument ${t} passed to ${n} must be a \`Tensor[]\` or \`TensorLike[]\``);
1429
+ return e.map((e, i) => P(e, `${t}[${i}]`, n, r));
1430
+ }
1431
+ // node_modules/@tensorflow/tfjs-core/dist/ops/operation.js
1432
+ var Li = "__op";
1433
+ function F(e) {
1434
+ let t = Object.keys(e);
1435
+ if (t.length !== 1) throw Error(`Please provide an object with a single key (operation name) mapping to a function. Got an object with ${t.length} keys.`);
1436
+ let n = t[0], r = e[n];
1437
+ n.endsWith("_") && (n = n.substring(0, n.length - 1)), n += Li;
1438
+ let i = (...e) => {
1439
+ M.startScope(n);
1440
+ try {
1441
+ let t = r(...e);
1442
+ return De(t) && console.error("Cannot return a Promise inside of tidy."), M.endScope(t), t;
1443
+ } catch (e) {
1444
+ throw M.endScope(null), e;
1445
+ }
1446
+ };
1447
+ return Object.defineProperty(i, "name", {
1448
+ value: n,
1449
+ configurable: !0
1450
+ }), i;
1451
+ }
1452
+ // node_modules/@tensorflow/tfjs-core/dist/ops/tensor_ops_util.js
1453
+ function Ri(e, t, n, r) {
1454
+ if (r == null) r = _(e);
1455
+ else if (r === "complex64") throw Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");
1456
+ if (yi(e) || vi(e)) {
1457
+ if (r !== "float32" && r !== "int32") throw Error(`Creating tensor from GPU data only supports 'float32'|'int32' dtype, while the dtype is ${r}.`);
1458
+ return M.backend.createTensorFromGPUData(e, t || n, r);
1459
+ }
1460
+ if (!C(e) && !Array.isArray(e) && typeof e != "number" && typeof e != "boolean" && typeof e != "string") throw Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");
1461
+ if (t != null) {
1462
+ we(t);
1463
+ let e = m(t), r = m(n);
1464
+ d(e === r, () => `Based on the provided shape, [${t}], the tensor should have ${e} values but has ${r}`);
1465
+ for (let e = 0; e < n.length; ++e) {
1466
+ let r = n[e], i = e !== n.length - 1 || r !== m(t.slice(e));
1467
+ d(n[e] === t[e] || !i, () => `Error creating a new Tensor. Inferred shape (${n}) does not match the provided shape (${t}). `);
1468
+ }
1469
+ }
1470
+ return !C(e) && !Array.isArray(e) && (e = [e]), t ||= n, e = r === "string" ? w(e, [], !0) : Gr(e, r), M.makeTensor(e, t, r);
1471
+ }
1472
+ // node_modules/@tensorflow/tfjs-core/dist/io/composite_array_buffer.js
1473
+ var zi = class e {
1474
+ static join(t) {
1475
+ return new e(t).slice();
1476
+ }
1477
+ constructor(e) {
1478
+ if (this.shards = [], this.previousShardIndex = 0, e == null || (e instanceof Array || (e = [e]), e = e.map((e) => C(e) ? e.buffer : e), e.length === 0)) return;
1479
+ this.bufferUniformSize = e[0].byteLength;
1480
+ let t = 0;
1481
+ for (let n = 0; n < e.length; n++) {
1482
+ let r = e[n];
1483
+ n !== e.length - 1 && r.byteLength !== this.bufferUniformSize && (this.bufferUniformSize = void 0);
1484
+ let i = t + r.byteLength;
1485
+ this.shards.push({
1486
+ buffer: r,
1487
+ start: t,
1488
+ end: i
1489
+ }), t = i;
1490
+ }
1491
+ this.shards.length === 0 && (this.byteLength = 0), this.byteLength = this.shards[this.shards.length - 1].end;
1492
+ }
1493
+ slice(e = 0, t = this.byteLength) {
1494
+ if (this.shards.length === 0 || (e = isNaN(Number(e)) ? 0 : e, t = isNaN(Number(t)) ? 0 : t, e = Math.max(0, e), t = Math.min(this.byteLength, t), t <= e)) return /* @__PURE__ */ new ArrayBuffer(0);
1495
+ let n = this.findShardForByte(e);
1496
+ if (n === -1) throw Error(`Could not find start shard for byte ${e}`);
1497
+ let r = t - e, i = new ArrayBuffer(r), a = new Uint8Array(i), o = 0;
1498
+ for (let r = n; r < this.shards.length; r++) {
1499
+ let n = this.shards[r], i = e + o - n.start, s = o, c = Math.min(t, n.end) - n.start, l = new Uint8Array(n.buffer, i, c - i);
1500
+ if (a.set(l, s), o += l.length, t < n.end) break;
1501
+ }
1502
+ return i;
1503
+ }
1504
+ findShardForByte(e) {
1505
+ if (this.shards.length === 0 || e < 0 || e >= this.byteLength) return -1;
1506
+ if (this.bufferUniformSize != null) return this.previousShardIndex = Math.floor(e / this.bufferUniformSize), this.previousShardIndex;
1507
+ function t(t) {
1508
+ return e < t.start ? -1 : +(e >= t.end);
1509
+ }
1510
+ if (t(this.shards[this.previousShardIndex]) === 0) return this.previousShardIndex;
1511
+ let n = Bi(this.shards, t);
1512
+ return n === -1 ? -1 : (this.previousShardIndex = n, this.previousShardIndex);
1513
+ }
1514
+ };
1515
+ function Bi(e, t) {
1516
+ let n = 0, r = e.length;
1517
+ for (; n <= r;) {
1518
+ let i = Math.floor((r - n) / 2) + n, a = t(e[i]);
1519
+ if (a === 0) return i;
1520
+ a < 0 ? r = i : n = i + 1;
1521
+ }
1522
+ return -1;
1523
+ }
1524
+ // node_modules/@tensorflow/tfjs-core/dist/globals.js
1525
+ function Vi() {
1526
+ M.disposeVariables();
1527
+ }
1528
+ function Hi() {
1529
+ return M;
1530
+ }
1531
+ function Ui() {
1532
+ return M.memory();
1533
+ }
1534
+ function I(e, t) {
1535
+ return M.tidy(e, t);
1536
+ }
1537
+ function L(e) {
1538
+ xi(e).forEach((e) => e.dispose());
1539
+ }
1540
+ function Wi(e) {
1541
+ return M.keep(e);
1542
+ }
1543
+ function Gi(e) {
1544
+ return M.setBackend(e);
1545
+ }
1546
+ function Ki() {
1547
+ return M.ready();
1548
+ }
1549
+ function qi() {
1550
+ return M.backendName;
1551
+ }
1552
+ function Ji(e, t, n = 1) {
1553
+ return M.registerBackend(e, t, n);
1554
+ }
1555
+ function Yi() {
1556
+ return M.backend;
1557
+ }
1558
+ // node_modules/@tensorflow/tfjs-core/dist/io/io_utils.js
1559
+ var Xi = 4;
1560
+ async function Zi(e, t) {
1561
+ let n = [], r = [], i = Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e);
1562
+ for (let a = 0; a < i.length; ++a) {
1563
+ let o = i[a], s = Array.isArray(e) ? e[a].tensor : e[o];
1564
+ if (s.dtype !== "float32" && s.dtype !== "int32" && s.dtype !== "bool" && s.dtype !== "string" && s.dtype !== "complex64") throw Error(`Unsupported dtype in weight '${o}': ${s.dtype}`);
1565
+ let c = {
1566
+ name: o,
1567
+ shape: s.shape,
1568
+ dtype: s.dtype
1569
+ };
1570
+ if (s.dtype === "string") {
1571
+ let e = new Promise(async (e) => {
1572
+ let t = await s.bytes(), n = t.reduce((e, t) => e + t.length, 0) + Xi * t.length, r = new Uint8Array(n), i = 0;
1573
+ for (let e = 0; e < t.length; e++) {
1574
+ let n = t[e], a = new Uint8Array(new Uint32Array([n.length]).buffer);
1575
+ r.set(a, i), i += Xi, r.set(n, i), i += n.length;
1576
+ }
1577
+ e(r);
1578
+ });
1579
+ r.push(e);
1580
+ } else r.push(s.data());
1581
+ t != null && (c.group = t), n.push(c);
1582
+ }
1583
+ return {
1584
+ data: Qi(await Promise.all(r)),
1585
+ specs: n
1586
+ };
1587
+ }
1588
+ function Qi(e) {
1589
+ if (e === null) throw Error(`Invalid input value: ${JSON.stringify(e)}`);
1590
+ let t = 0, n = [];
1591
+ e.forEach((e) => {
1592
+ if (t += e.byteLength, n.push(e.byteLength === e.buffer.byteLength ? e : new e.constructor(e)), !(e instanceof Float32Array || e instanceof Int32Array || e instanceof Uint8Array)) throw Error(`Unsupported TypedArray subtype: ${e.constructor.name}`);
1593
+ });
1594
+ let r = new Uint8Array(t), i = 0;
1595
+ return n.forEach((e) => {
1596
+ r.set(new Uint8Array(e.buffer), i), i += e.byteLength;
1597
+ }), r.buffer;
1598
+ }
1599
+ var $i = typeof Buffer < "u" && (typeof Blob > "u" || typeof atob > "u" || typeof btoa > "u");
1600
+ function ea(e) {
1601
+ return $i ? Buffer.byteLength(e, "utf8") : new Blob([e]).size;
1602
+ }
1603
+ function ta(e) {
1604
+ if ($i) return Buffer.from(e).toString("base64");
1605
+ let t = new Uint8Array(e), n = "";
1606
+ for (let e = 0, r = t.length; e < r; e++) n += String.fromCharCode(t[e]);
1607
+ return btoa(n);
1608
+ }
1609
+ function na(e) {
1610
+ if ($i) {
1611
+ let t = Buffer.from(e, "base64");
1612
+ return t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength);
1613
+ }
1614
+ let t = atob(e), n = new Uint8Array(t.length);
1615
+ for (let e = 0; e < t.length; ++e) n.set([t.charCodeAt(e)], e);
1616
+ return n.buffer;
1617
+ }
1618
+ function ra(e) {
1619
+ return zi.join(e);
1620
+ }
1621
+ function ia(e) {
1622
+ if (e.modelTopology instanceof ArrayBuffer) throw Error("Expected JSON model topology, received ArrayBuffer.");
1623
+ return {
1624
+ dateSaved: /* @__PURE__ */ new Date(),
1625
+ modelTopologyType: "JSON",
1626
+ modelTopologyBytes: e.modelTopology == null ? 0 : ea(JSON.stringify(e.modelTopology)),
1627
+ weightSpecsBytes: e.weightSpecs == null ? 0 : ea(JSON.stringify(e.weightSpecs)),
1628
+ weightDataBytes: e.weightData == null ? 0 : new zi(e.weightData).byteLength
1629
+ };
1630
+ }
1631
+ // node_modules/@tensorflow/tfjs-core/dist/io/router_registry.js
1632
+ var R = class e {
1633
+ constructor() {
1634
+ this.saveRouters = [], this.loadRouters = [];
1635
+ }
1636
+ static getInstance() {
1637
+ return e.instance ??= new e(), e.instance;
1638
+ }
1639
+ static registerSaveRouter(t) {
1640
+ e.getInstance().saveRouters.push(t);
1641
+ }
1642
+ static registerLoadRouter(t) {
1643
+ e.getInstance().loadRouters.push(t);
1644
+ }
1645
+ static getSaveHandlers(t) {
1646
+ return e.getHandlers(t, "save");
1647
+ }
1648
+ static getLoadHandlers(t, n) {
1649
+ return e.getHandlers(t, "load", n);
1650
+ }
1651
+ static getHandlers(t, n, r) {
1652
+ let i = [];
1653
+ return (n === "load" ? e.getInstance().loadRouters : e.getInstance().saveRouters).forEach((e) => {
1654
+ let n = e(t, r);
1655
+ n !== null && i.push(n);
1656
+ }), i;
1657
+ }
1658
+ }, aa = (e) => R.getSaveHandlers(e), oa = "tensorflowjs", sa = 1, z = "models_store", B = "model_info_store";
1659
+ function ca() {
1660
+ if (!b().getBool("IS_BROWSER")) throw Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");
1661
+ let e = typeof window > "u" ? self : window, t = e.indexedDB || e.mozIndexedDB || e.webkitIndexedDB || e.msIndexedDB || e.shimIndexedDB;
1662
+ if (t == null) throw Error("The current browser does not appear to support IndexedDB.");
1663
+ return t;
1664
+ }
1665
+ function la(e) {
1666
+ let t = e.result;
1667
+ t.createObjectStore(z, { keyPath: "modelPath" }), t.createObjectStore(B, { keyPath: "modelPath" });
1668
+ }
1669
+ var V = class {
1670
+ constructor(e) {
1671
+ if (this.indexedDB = ca(), e == null || !e) throw Error("For IndexedDB, modelPath must not be null, undefined or empty.");
1672
+ this.modelPath = e;
1673
+ }
1674
+ async save(e) {
1675
+ if (e.modelTopology instanceof ArrayBuffer) throw Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
1676
+ return this.databaseAction(this.modelPath, e);
1677
+ }
1678
+ async load() {
1679
+ return this.databaseAction(this.modelPath);
1680
+ }
1681
+ databaseAction(e, t) {
1682
+ return new Promise((e, n) => {
1683
+ let r = this.indexedDB.open(oa, sa);
1684
+ r.onupgradeneeded = () => la(r), r.onsuccess = () => {
1685
+ let i = r.result;
1686
+ if (t == null) {
1687
+ let t = i.transaction(z, "readonly"), r = t.objectStore(z).get(this.modelPath);
1688
+ r.onsuccess = () => {
1689
+ if (r.result == null) return i.close(), n(/* @__PURE__ */ Error(`Cannot find model with path '${this.modelPath}' in IndexedDB.`));
1690
+ e(r.result.modelArtifacts);
1691
+ }, r.onerror = (e) => (i.close(), n(r.error)), t.oncomplete = () => i.close();
1692
+ } else {
1693
+ t.weightData = zi.join(t.weightData);
1694
+ let r = ia(t), a = i.transaction(B, "readwrite"), o = a.objectStore(B), s;
1695
+ try {
1696
+ s = o.put({
1697
+ modelPath: this.modelPath,
1698
+ modelArtifactsInfo: r
1699
+ });
1700
+ } catch (e) {
1701
+ return n(e);
1702
+ }
1703
+ let c;
1704
+ s.onsuccess = () => {
1705
+ c = i.transaction(z, "readwrite");
1706
+ let s = c.objectStore(z), l;
1707
+ try {
1708
+ l = s.put({
1709
+ modelPath: this.modelPath,
1710
+ modelArtifacts: t,
1711
+ modelArtifactsInfo: r
1712
+ });
1713
+ } catch (e) {
1714
+ return n(e);
1715
+ }
1716
+ l.onsuccess = () => e({ modelArtifactsInfo: r }), l.onerror = (e) => {
1717
+ o = a.objectStore(B);
1718
+ let t = o.delete(this.modelPath);
1719
+ t.onsuccess = () => (i.close(), n(l.error)), t.onerror = (e) => (i.close(), n(l.error));
1720
+ };
1721
+ }, s.onerror = (e) => (i.close(), n(s.error)), a.oncomplete = () => {
1722
+ c == null ? i.close() : c.oncomplete = () => i.close();
1723
+ };
1724
+ }
1725
+ }, r.onerror = (e) => n(r.error);
1726
+ });
1727
+ }
1728
+ };
1729
+ V.URL_SCHEME = "indexeddb://";
1730
+ var ua = (e) => b().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(V.URL_SCHEME) ? da(e.slice(V.URL_SCHEME.length)) : null;
1731
+ R.registerSaveRouter(ua), R.registerLoadRouter(ua);
1732
+ function da(e) {
1733
+ return new V(e);
1734
+ }
1735
+ function fa(e) {
1736
+ return e.startsWith(V.URL_SCHEME) ? e.slice(V.URL_SCHEME.length) : e;
1737
+ }
1738
+ var pa = class {
1739
+ constructor() {
1740
+ this.indexedDB = ca();
1741
+ }
1742
+ async listModels() {
1743
+ return new Promise((e, t) => {
1744
+ let n = this.indexedDB.open(oa, sa);
1745
+ n.onupgradeneeded = () => la(n), n.onsuccess = () => {
1746
+ let r = n.result, i = r.transaction(B, "readonly"), a = i.objectStore(B).getAll();
1747
+ a.onsuccess = () => {
1748
+ let t = {};
1749
+ for (let e of a.result) t[e.modelPath] = e.modelArtifactsInfo;
1750
+ e(t);
1751
+ }, a.onerror = (e) => (r.close(), t(a.error)), i.oncomplete = () => r.close();
1752
+ }, n.onerror = (e) => t(n.error);
1753
+ });
1754
+ }
1755
+ async removeModel(e) {
1756
+ return e = fa(e), new Promise((t, n) => {
1757
+ let r = this.indexedDB.open(oa, sa);
1758
+ r.onupgradeneeded = () => la(r), r.onsuccess = () => {
1759
+ let i = r.result, a = i.transaction(B, "readwrite"), o = a.objectStore(B), s = o.get(e), c;
1760
+ s.onsuccess = () => {
1761
+ if (s.result == null) return i.close(), n(/* @__PURE__ */ Error(`Cannot find model with path '${e}' in IndexedDB.`));
1762
+ {
1763
+ let r = o.delete(e), a = () => {
1764
+ c = i.transaction(z, "readwrite");
1765
+ let r = c.objectStore(z).delete(e);
1766
+ r.onsuccess = () => t(s.result.modelArtifactsInfo), r.onerror = (e) => n(s.error);
1767
+ };
1768
+ r.onsuccess = a, r.onerror = (e) => (a(), i.close(), n(s.error));
1769
+ }
1770
+ }, s.onerror = (e) => (i.close(), n(s.error)), a.oncomplete = () => {
1771
+ c == null ? i.close() : c.oncomplete = () => i.close();
1772
+ };
1773
+ }, r.onerror = (e) => n(r.error);
1774
+ });
1775
+ }
1776
+ }, H = "/", U = "tensorflowjs_models", ma = "info", ha = "model_topology", ga = "weight_specs", _a = "weight_data", va = "model_metadata";
1777
+ function ya(e) {
1778
+ return {
1779
+ info: [
1780
+ U,
1781
+ e,
1782
+ ma
1783
+ ].join(H),
1784
+ topology: [
1785
+ U,
1786
+ e,
1787
+ ha
1788
+ ].join(H),
1789
+ weightSpecs: [
1790
+ U,
1791
+ e,
1792
+ ga
1793
+ ].join(H),
1794
+ weightData: [
1795
+ U,
1796
+ e,
1797
+ _a
1798
+ ].join(H),
1799
+ modelMetadata: [
1800
+ U,
1801
+ e,
1802
+ va
1803
+ ].join(H)
1804
+ };
1805
+ }
1806
+ function ba(e) {
1807
+ for (let t of Object.values(e)) window.localStorage.removeItem(t);
1808
+ }
1809
+ function xa(e) {
1810
+ let t = e.split(H);
1811
+ if (t.length < 3) throw Error(`Invalid key format: ${e}`);
1812
+ return t.slice(1, t.length - 1).join(H);
1813
+ }
1814
+ function Sa(e) {
1815
+ return e.startsWith(W.URL_SCHEME) ? e.slice(W.URL_SCHEME.length) : e;
1816
+ }
1817
+ var W = class {
1818
+ constructor(e) {
1819
+ if (!b().getBool("IS_BROWSER") || typeof window > "u" || window.localStorage === void 0) throw Error("The current environment does not support local storage.");
1820
+ if (this.LS = window.localStorage, e == null || !e) throw Error("For local storage, modelPath must not be null, undefined or empty.");
1821
+ this.modelPath = e, this.keys = ya(this.modelPath);
1822
+ }
1823
+ async save(e) {
1824
+ if (e.modelTopology instanceof ArrayBuffer) throw Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
1825
+ {
1826
+ let t = JSON.stringify(e.modelTopology), n = JSON.stringify(e.weightSpecs), r = ia(e), i = zi.join(e.weightData);
1827
+ try {
1828
+ this.LS.setItem(this.keys.info, JSON.stringify(r)), this.LS.setItem(this.keys.topology, t), this.LS.setItem(this.keys.weightSpecs, n), this.LS.setItem(this.keys.weightData, ta(i));
1829
+ let a = {
1830
+ format: e.format,
1831
+ generatedBy: e.generatedBy,
1832
+ convertedBy: e.convertedBy,
1833
+ signature: e.signature == null ? void 0 : e.signature,
1834
+ userDefinedMetadata: e.userDefinedMetadata == null ? void 0 : e.userDefinedMetadata,
1835
+ modelInitializer: e.modelInitializer == null ? void 0 : e.modelInitializer,
1836
+ initializerSignature: e.initializerSignature == null ? void 0 : e.initializerSignature,
1837
+ trainingConfig: e.trainingConfig == null ? void 0 : e.trainingConfig
1838
+ };
1839
+ return this.LS.setItem(this.keys.modelMetadata, JSON.stringify(a)), { modelArtifactsInfo: r };
1840
+ } catch {
1841
+ throw ba(this.keys), Error(`Failed to save model '${this.modelPath}' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=${r.modelTopologyBytes}, weightSpecsBytes=${r.weightSpecsBytes}, weightDataBytes=${r.weightDataBytes}.`);
1842
+ }
1843
+ }
1844
+ }
1845
+ async load() {
1846
+ let e = JSON.parse(this.LS.getItem(this.keys.info));
1847
+ if (e == null) throw Error(`In local storage, there is no model with name '${this.modelPath}'`);
1848
+ if (e.modelTopologyType !== "JSON") throw Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");
1849
+ let t = {}, n = JSON.parse(this.LS.getItem(this.keys.topology));
1850
+ if (n == null) throw Error(`In local storage, the topology of model '${this.modelPath}' is missing.`);
1851
+ t.modelTopology = n;
1852
+ let r = JSON.parse(this.LS.getItem(this.keys.weightSpecs));
1853
+ if (r == null) throw Error(`In local storage, the weight specs of model '${this.modelPath}' are missing.`);
1854
+ t.weightSpecs = r;
1855
+ let i = this.LS.getItem(this.keys.modelMetadata);
1856
+ if (i != null) {
1857
+ let e = JSON.parse(i);
1858
+ t.format = e.format, t.generatedBy = e.generatedBy, t.convertedBy = e.convertedBy, e.signature != null && (t.signature = e.signature), e.userDefinedMetadata != null && (t.userDefinedMetadata = e.userDefinedMetadata), e.modelInitializer != null && (t.modelInitializer = e.modelInitializer), e.initializerSignature != null && (t.initializerSignature = e.initializerSignature), e.trainingConfig != null && (t.trainingConfig = e.trainingConfig);
1859
+ }
1860
+ let a = this.LS.getItem(this.keys.weightData);
1861
+ if (a == null) throw Error(`In local storage, the binary weight values of model '${this.modelPath}' are missing.`);
1862
+ return t.weightData = na(a), t;
1863
+ }
1864
+ };
1865
+ W.URL_SCHEME = "localstorage://";
1866
+ var Ca = (e) => b().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(W.URL_SCHEME) ? wa(e.slice(W.URL_SCHEME.length)) : null;
1867
+ R.registerSaveRouter(Ca), R.registerLoadRouter(Ca);
1868
+ function wa(e) {
1869
+ return new W(e);
1870
+ }
1871
+ var Ta = class {
1872
+ constructor() {
1873
+ d(b().getBool("IS_BROWSER"), () => "Current environment is not a web browser"), d(typeof window > "u" || window.localStorage !== void 0, () => "Current browser does not appear to support localStorage"), this.LS = window.localStorage;
1874
+ }
1875
+ async listModels() {
1876
+ let e = {};
1877
+ for (let t = 0; t < this.LS.length; ++t) {
1878
+ let n = this.LS.key(t);
1879
+ if (n.startsWith("tensorflowjs_models/") && n.endsWith("/info")) {
1880
+ let t = xa(n);
1881
+ e[t] = JSON.parse(this.LS.getItem(n));
1882
+ }
1883
+ }
1884
+ return e;
1885
+ }
1886
+ async removeModel(e) {
1887
+ e = Sa(e);
1888
+ let t = ya(e);
1889
+ if (this.LS.getItem(t.info) == null) throw Error(`Cannot find model at path '${e}'`);
1890
+ let n = JSON.parse(this.LS.getItem(t.info));
1891
+ return ba(t), n;
1892
+ }
1893
+ }, Ea = "://", Da = class e {
1894
+ constructor() {
1895
+ this.managers = {};
1896
+ }
1897
+ static getInstance() {
1898
+ return e.instance ??= new e(), e.instance;
1899
+ }
1900
+ static registerManager(t, n) {
1901
+ d(t != null, () => "scheme must not be undefined or null."), t.endsWith(Ea) && (t = t.slice(0, t.indexOf(Ea))), d(t.length > 0, () => "scheme must not be an empty string.");
1902
+ let r = e.getInstance();
1903
+ d(r.managers[t] == null, () => `A model store manager is already registered for scheme '${t}'.`), r.managers[t] = n;
1904
+ }
1905
+ static getManager(t) {
1906
+ let n = e.getInstance().managers[t];
1907
+ if (n == null) throw Error(`Cannot find model manager for scheme '${t}'`);
1908
+ return n;
1909
+ }
1910
+ static getSchemes() {
1911
+ return Object.keys(e.getInstance().managers);
1912
+ }
1913
+ }, Oa = class {
1914
+ constructor() {
1915
+ this.messageName = "setTimeoutCustom", this.functionRefs = [], this.handledMessageCount = 0, this.hasEventListener = !1;
1916
+ }
1917
+ fetch(e, t) {
1918
+ return fetch(e, t);
1919
+ }
1920
+ now() {
1921
+ return performance.now();
1922
+ }
1923
+ encode(e, t) {
1924
+ if (t !== "utf-8" && t !== "utf8") throw Error(`Browser's encoder only supports utf-8, but got ${t}`);
1925
+ return this.textEncoder ??= new TextEncoder(), this.textEncoder.encode(e);
1926
+ }
1927
+ decode(e, t) {
1928
+ return new TextDecoder(t).decode(e);
1929
+ }
1930
+ setTimeoutCustom(e, t) {
1931
+ typeof window > "u" || !b().getBool("USE_SETTIMEOUTCUSTOM") ? setTimeout(e, t) : (this.functionRefs.push(e), setTimeout(() => {
1932
+ window.postMessage({
1933
+ name: this.messageName,
1934
+ index: this.functionRefs.length - 1
1935
+ }, "*");
1936
+ }, t), this.hasEventListener || (this.hasEventListener = !0, window.addEventListener("message", (e) => {
1937
+ if (e.source === window && e.data.name === this.messageName) {
1938
+ e.stopPropagation();
1939
+ let t = this.functionRefs[e.data.index];
1940
+ t(), this.handledMessageCount++, this.handledMessageCount === this.functionRefs.length && (this.functionRefs = [], this.handledMessageCount = 0);
1941
+ }
1942
+ }, !0)));
1943
+ }
1944
+ isTypedArray(e) {
1945
+ return Hr(e);
1946
+ }
1947
+ };
1948
+ if (b().get("IS_BROWSER")) {
1949
+ b().setPlatform("browser", new Oa());
1950
+ try {
1951
+ Da.registerManager(W.URL_SCHEME, new Ta());
1952
+ } catch {}
1953
+ try {
1954
+ Da.registerManager(V.URL_SCHEME, new pa());
1955
+ } catch {}
1956
+ }
1957
+ // __vite-browser-external
1958
+ var ka = /* @__PURE__ */ e(((e, t) => {
1959
+ t.exports = {};
1960
+ })), Aa = { importFetch: () => ka() }, ja, Ma = class {
1961
+ constructor() {
1962
+ this.util = ka(), this.textEncoder = new this.util.TextEncoder();
1963
+ }
1964
+ fetch(e, t) {
1965
+ return b().global.fetch == null ? (ja ??= Aa.importFetch(), ja(e, t)) : b().global.fetch(e, t);
1966
+ }
1967
+ now() {
1968
+ let e = process.hrtime();
1969
+ return e[0] * 1e3 + e[1] / 1e6;
1970
+ }
1971
+ encode(e, t) {
1972
+ if (t !== "utf-8" && t !== "utf8") throw Error(`Node built-in encoder only supports utf-8, but got ${t}`);
1973
+ return this.textEncoder.encode(e);
1974
+ }
1975
+ decode(e, t) {
1976
+ return e.length === 0 ? "" : new this.util.TextDecoder(t).decode(e);
1977
+ }
1978
+ isTypedArray(e) {
1979
+ return this.util.types.isFloat32Array(e) || this.util.types.isInt32Array(e) || this.util.types.isUint8Array(e) || this.util.types.isUint8ClampedArray(e);
1980
+ }
1981
+ };
1982
+ b().get("IS_NODE") && !b().get("IS_BROWSER") && b().setPlatform("node", new Ma());
1983
+ // node_modules/@tensorflow/tfjs-core/dist/ops/buffer.js
1984
+ function Na(e, t = "float32", n) {
1985
+ return t ||= "float32", we(e), new ai(e, t, n);
1986
+ }
1987
+ // node_modules/@tensorflow/tfjs-core/dist/ops/cast.js
1988
+ function Pa(e, t) {
1989
+ let n = P(e, "x", "cast");
1990
+ if (!de(t)) throw Error(`Failed to cast to unknown dtype ${t}`);
1991
+ if (t === "string" && n.dtype !== "string" || t !== "string" && n.dtype === "string") throw Error("Only strings can be casted to strings");
1992
+ let r = { x: n }, i = { dtype: t };
1993
+ return M.runKernel(at, r, i);
1994
+ }
1995
+ var Fa = /* @__PURE__ */ F({ cast_: Pa });
1996
+ // node_modules/@tensorflow/tfjs-core/dist/ops/clone.js
1997
+ function Ia(e) {
1998
+ let t = { x: P(e, "x", "clone", "string_or_numeric") };
1999
+ return M.runKernel(Kt, t);
2000
+ }
2001
+ var La = /* @__PURE__ */ F({ clone_: Ia });
2002
+ // node_modules/@tensorflow/tfjs-core/dist/ops/print.js
2003
+ function Ra(e, t = !1) {
2004
+ console.log(e.toString(t));
2005
+ }
2006
+ Oi(), si({
2007
+ buffer: Na,
2008
+ cast: Fa,
2009
+ clone: La,
2010
+ print: Ra
2011
+ });
2012
+ // node_modules/@tensorflow/tfjs-core/dist/ops/add.js
2013
+ function za(e, t) {
2014
+ let n = P(e, "a", "add"), r = P(t, "b", "add");
2015
+ [n, r] = j(n, r);
2016
+ let i = {
2017
+ a: n,
2018
+ b: r
2019
+ };
2020
+ return M.runKernel("Add", i);
2021
+ }
2022
+ var G = /* @__PURE__ */ F({ add_: za });
2023
+ // node_modules/@tensorflow/tfjs-core/dist/ops/floorDiv.js
2024
+ function Ba(e, t) {
2025
+ let n = P(e, "a", "floorDiv"), r = P(t, "b", "floorDiv");
2026
+ [n, r] = j(n, r);
2027
+ let i = {
2028
+ a: n,
2029
+ b: r
2030
+ };
2031
+ return M.runKernel(Bt, i);
2032
+ }
2033
+ var Va = /* @__PURE__ */ F({ floorDiv_: Ba });
2034
+ // node_modules/@tensorflow/tfjs-core/dist/ops/div.js
2035
+ function Ha(e, t) {
2036
+ let n = P(e, "a", "div"), r = P(t, "b", "div");
2037
+ if ([n, r] = j(n, r), n.dtype === "int32" && r.dtype === "int32") return Va(n, r);
2038
+ let i = {
2039
+ a: n,
2040
+ b: r
2041
+ };
2042
+ return M.runKernel(jt, i, {});
2043
+ }
2044
+ var K = /* @__PURE__ */ F({ div_: Ha });
2045
+ // node_modules/@tensorflow/tfjs-core/dist/ops/mul.js
2046
+ function Ua(e, t) {
2047
+ let n = P(e, "a", "mul"), r = P(t, "b", "mul");
2048
+ [n, r] = j(n, r);
2049
+ let i = {
2050
+ a: n,
2051
+ b: r
2052
+ };
2053
+ return M.runKernel(yn, i);
2054
+ }
2055
+ var q = /* @__PURE__ */ F({ mul_: Ua });
2056
+ // node_modules/@tensorflow/tfjs-core/dist/ops/abs.js
2057
+ function Wa(e) {
2058
+ let t = P(e, "x", "abs");
2059
+ if (t.dtype === "complex64") {
2060
+ let e = { x: t };
2061
+ return M.runKernel(lt, e);
2062
+ }
2063
+ {
2064
+ let e = { x: t };
2065
+ return M.runKernel("Abs", e);
2066
+ }
2067
+ }
2068
+ var Ga = /* @__PURE__ */ F({ abs_: Wa });
2069
+ // node_modules/@tensorflow/tfjs-core/dist/ops/fill.js
2070
+ function Ka(e, t, n) {
2071
+ we(e), n ||= _(t);
2072
+ let r = {
2073
+ shape: e,
2074
+ value: t,
2075
+ dtype: n
2076
+ };
2077
+ return M.runKernel(Lt, {}, r);
2078
+ }
2079
+ // node_modules/@tensorflow/tfjs-core/dist/ops/broadcast_util.js
2080
+ function qa(e, t) {
2081
+ let n = e.length, r = [];
2082
+ for (let i = 0; i < n; i++) {
2083
+ let a = n - 1 - i, o = e[a] || 1;
2084
+ (t[t.length - 1 - i] || 1) > 1 && o === 1 && r.unshift(a);
2085
+ }
2086
+ return r;
2087
+ }
2088
+ function Ja(e, t) {
2089
+ let n = [];
2090
+ for (let r = 0; r < t.length; r++) {
2091
+ let i = e[e.length - r - 1], a = t.length - r - 1, o = t[a];
2092
+ (i == null || i === 1 && o > 1) && n.unshift(a);
2093
+ }
2094
+ return n;
2095
+ }
2096
+ function Ya(e, t) {
2097
+ let n = Math.max(e.length, t.length), r = Array(n);
2098
+ for (let i = 0; i < n; i++) {
2099
+ let a = e[e.length - i - 1];
2100
+ a ??= 1;
2101
+ let o = t[t.length - i - 1];
2102
+ if (o ??= 1, a === 1) r[n - i - 1] = o;
2103
+ else if (o === 1) r[n - i - 1] = a;
2104
+ else if (a !== o) {
2105
+ let n = `Operands could not be broadcast together with shapes ${e} and ${t}.`;
2106
+ throw Error(n);
2107
+ } else r[n - i - 1] = a;
2108
+ }
2109
+ return r;
2110
+ }
2111
+ // node_modules/@tensorflow/tfjs-core/dist/ops/zeros_like.js
2112
+ function Xa(e) {
2113
+ let t = { x: P(e, "x", "zerosLike") };
2114
+ return M.runKernel(Er, t);
2115
+ }
2116
+ var J = /* @__PURE__ */ F({ zerosLike_: Xa });
2117
+ // node_modules/@tensorflow/tfjs-core/dist/ops/pow.js
2118
+ function Za(e, t) {
2119
+ let n = P(e, "base", "pow"), r = P(t, "exp", "pow");
2120
+ [n, r] = j(n, r);
2121
+ let i = {
2122
+ a: n,
2123
+ b: r
2124
+ };
2125
+ return M.runKernel("Pow", i);
2126
+ }
2127
+ var Qa = /* @__PURE__ */ F({ pow_: Za });
2128
+ // node_modules/@tensorflow/tfjs-core/dist/ops/scalar.js
2129
+ function Y(e, t) {
2130
+ if ((C(e) && t !== "string" || Array.isArray(e)) && t !== "complex64") throw Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");
2131
+ if (t === "string" && C(e) && !(e instanceof Uint8Array)) throw Error("When making a scalar from encoded string, the value must be `Uint8Array`.");
2132
+ return Ri(e, [], [], t);
2133
+ }
2134
+ // node_modules/@tensorflow/tfjs-core/dist/ops/sqrt.js
2135
+ function $a(e) {
2136
+ let t = { x: P(e, "x", "sqrt", "float32") };
2137
+ return M.runKernel(nr, t);
2138
+ }
2139
+ var X = /* @__PURE__ */ F({ sqrt_: $a });
2140
+ // node_modules/@tensorflow/tfjs-core/dist/ops/square.js
2141
+ function eo(e) {
2142
+ let t = P(e, "x", "square");
2143
+ return M.runKernel("Square", { x: t }, {});
2144
+ }
2145
+ var Z = /* @__PURE__ */ F({ square_: eo });
2146
+ // node_modules/@tensorflow/tfjs-core/dist/gradients.js
2147
+ function to(e) {
2148
+ return d(v(e), () => "The f passed in grads(f) must be a function"), (t, n) => {
2149
+ d(Array.isArray(t), () => "The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s");
2150
+ let r = Ii(t, "args", "tf.grads", "string_or_numeric"), i = n == null ? null : P(n, "dy", "tf.grads");
2151
+ return M.tidy(() => {
2152
+ let { value: t, grads: n } = M.gradients(() => e(...r), r, i);
2153
+ return i != null && f(t.shape, i.shape, "The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), ao(n), n;
2154
+ });
2155
+ };
2156
+ }
2157
+ function no(e) {
2158
+ return d(v(e), () => "The f passed in valueAndGrads(f) must be a function"), (t, n) => {
2159
+ d(Array.isArray(t) && t.every((e) => e instanceof A), () => "The args passed in valueAndGrads(f)(args) must be array of tensors"), d(n == null || n instanceof A, () => "The dy passed in valueAndGrads(f)(args, dy) must be a tensor");
2160
+ let r = M.gradients(() => e(...t), t, n);
2161
+ return n != null && f(r.value.shape, n.shape, "The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), ao(r.grads), r;
2162
+ };
2163
+ }
2164
+ function ro(e, t) {
2165
+ d(v(e), () => "The f passed in variableGrads(f) must be a function"), d(t == null || Array.isArray(t) && t.every((e) => e instanceof li), () => "The varList passed in variableGrads(f, varList) must be an array of variables");
2166
+ let n = t != null;
2167
+ if (!n) {
2168
+ t = [];
2169
+ for (let e in M.registeredVariables) t.push(M.registeredVariables[e]);
2170
+ }
2171
+ let r = n ? t.filter((e) => !e.trainable) : null, i = t.length;
2172
+ t = t.filter((e) => e.trainable), d(t.length > 0, () => `variableGrads() expects at least one of the input variables to be trainable, but none of the ${i} variables is trainable.`);
2173
+ let { value: a, grads: o } = M.gradients(e, t, null, !0);
2174
+ d(o.some((e) => e != null), () => "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."), d(a.rank === 0, () => `The f passed in variableGrads(f) must return a scalar, but it returned a rank-${a.rank} tensor`);
2175
+ let s = {};
2176
+ return t.forEach((e, t) => {
2177
+ o[t] != null && (s[e.name] = o[t]);
2178
+ }), r?.forEach((e) => s[e.name] = null), {
2179
+ value: a,
2180
+ grads: s
2181
+ };
2182
+ }
2183
+ function io(e) {
2184
+ return M.customGrad(e);
2185
+ }
2186
+ function ao(e) {
2187
+ if (e.filter((e) => e == null).length > 0) throw Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.");
2188
+ }
2189
+ // node_modules/@tensorflow/tfjs-core/dist/ops/sub.js
2190
+ function oo(e, t) {
2191
+ let n = P(e, "a", "sub"), r = P(t, "b", "sub");
2192
+ [n, r] = j(n, r);
2193
+ let i = {
2194
+ a: n,
2195
+ b: r
2196
+ };
2197
+ return M.runKernel("Sub", i);
2198
+ }
2199
+ var Q = /* @__PURE__ */ F({ sub_: oo });
2200
+ // node_modules/@tensorflow/tfjs-core/dist/ops/maximum.js
2201
+ function so(e, t) {
2202
+ let n = P(e, "a", "maximum"), r = P(t, "b", "maximum");
2203
+ [n, r] = j(n, r), n.dtype === "bool" && (n = Fa(n, "int32"), r = Fa(r, "int32")), Ya(n.shape, r.shape);
2204
+ let i = {
2205
+ a: n,
2206
+ b: r
2207
+ };
2208
+ return M.runKernel(ln, i);
2209
+ }
2210
+ var co = /* @__PURE__ */ F({ maximum_: so }), lo = /* @__PURE__ */ new Map(), uo = /* @__PURE__ */ new Map(), fo = class {
2211
+ getClassName() {
2212
+ return this.constructor.className;
2213
+ }
2214
+ static fromConfig(e, t) {
2215
+ return new e(t);
2216
+ }
2217
+ }, po = class e {
2218
+ constructor() {
2219
+ this.classNameMap = {};
2220
+ }
2221
+ static getMap() {
2222
+ return e.instance ??= new e(), e.instance;
2223
+ }
2224
+ static register(t) {
2225
+ e.getMap().classNameMap[t.className] = [t, t.fromConfig];
2226
+ }
2227
+ };
2228
+ function mo(e, t, n) {
2229
+ d(e.className != null, () => "Class being registered does not have the static className property defined."), d(typeof e.className == "string", () => "className is required to be a string, but got type " + typeof e.className), d(e.className.length > 0, () => "Class being registered has an empty-string as its className, which is disallowed."), t === void 0 && (t = "Custom"), n === void 0 && (n = e.className);
2230
+ let r = n, i = t + ">" + r;
2231
+ return po.register(e), lo.set(i, e), uo.set(e, i), e;
2232
+ }
2233
+ // node_modules/@tensorflow/tfjs-core/dist/optimizers/optimizer.js
2234
+ var $ = class extends fo {
2235
+ minimize(e, t = !1, n) {
2236
+ let { value: r, grads: i } = this.computeGradients(e, n);
2237
+ if (n != null) {
2238
+ let e = n.map((e) => ({
2239
+ name: e.name,
2240
+ tensor: i[e.name]
2241
+ }));
2242
+ this.applyGradients(e);
2243
+ } else this.applyGradients(i);
2244
+ return L(i), t ? r : (r.dispose(), null);
2245
+ }
2246
+ get iterations() {
2247
+ return this.iterations_ ??= 0, this.iterations_;
2248
+ }
2249
+ incrementIterations() {
2250
+ this.iterations_ = this.iterations + 1;
2251
+ }
2252
+ computeGradients(e, t) {
2253
+ return ro(e, t);
2254
+ }
2255
+ dispose() {
2256
+ this.iterations_ != null && L(this.iterations_);
2257
+ }
2258
+ async saveIterations() {
2259
+ return this.iterations_ ??= 0, {
2260
+ name: "iter",
2261
+ tensor: Y(this.iterations_, "int32")
2262
+ };
2263
+ }
2264
+ async getWeights() {
2265
+ throw Error("getWeights() is not implemented for this optimizer yet.");
2266
+ }
2267
+ async setWeights(e) {
2268
+ throw Error(`setWeights() is not implemented for this optimizer class ${this.getClassName()}`);
2269
+ }
2270
+ async extractIterations(e) {
2271
+ return this.iterations_ = (await e[0].tensor.data())[0], e.slice(1);
2272
+ }
2273
+ };
2274
+ Object.defineProperty($, Symbol.hasInstance, { value: (e) => e.minimize != null && e.computeGradients != null && e.applyGradients != null });
2275
+ // node_modules/@tensorflow/tfjs-core/dist/optimizers/adadelta_optimizer.js
2276
+ var ho = class extends $ {
2277
+ static get className() {
2278
+ return "Adadelta";
2279
+ }
2280
+ constructor(e, t, n = null) {
2281
+ super(), this.learningRate = e, this.rho = t, this.epsilon = n, this.accumulatedGrads = [], this.accumulatedUpdates = [], n ?? (this.epsilon = M.backend.epsilon());
2282
+ }
2283
+ applyGradients(e) {
2284
+ (Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e)).forEach((t, n) => {
2285
+ let r = M.registeredVariables[t];
2286
+ this.accumulatedGrads[n] ?? (this.accumulatedGrads[n] = {
2287
+ originalName: `${t}/accum_grad`,
2288
+ variable: I(() => J(r).variable(!1))
2289
+ }), this.accumulatedUpdates[n] ?? (this.accumulatedUpdates[n] = {
2290
+ originalName: `${t}/accum_var`,
2291
+ variable: I(() => J(r).variable(!1))
2292
+ });
2293
+ let i = Array.isArray(e) ? e[n].tensor : e[t];
2294
+ if (i == null) return;
2295
+ let a = this.accumulatedGrads[n].variable, o = this.accumulatedUpdates[n].variable;
2296
+ I(() => {
2297
+ let e = G(q(a, this.rho), q(Z(i), 1 - this.rho)), t = q(K(X(G(o, this.epsilon)), X(G(a, this.epsilon))), i), n = G(q(o, this.rho), q(Z(t), 1 - this.rho));
2298
+ a.assign(e), o.assign(n);
2299
+ let s = G(q(t, -this.learningRate), r);
2300
+ r.assign(s);
2301
+ });
2302
+ }), this.incrementIterations();
2303
+ }
2304
+ dispose() {
2305
+ this.accumulatedUpdates != null && (L(this.accumulatedGrads.map((e) => e.variable)), L(this.accumulatedUpdates.map((e) => e.variable)));
2306
+ }
2307
+ async getWeights() {
2308
+ let e = [...this.accumulatedGrads, ...this.accumulatedUpdates];
2309
+ return [await this.saveIterations()].concat(e.map((e) => ({
2310
+ name: e.originalName,
2311
+ tensor: e.variable
2312
+ })));
2313
+ }
2314
+ async setWeights(e) {
2315
+ e = await this.extractIterations(e);
2316
+ let t = e.length / 2;
2317
+ this.accumulatedGrads = e.slice(0, t).map((e) => ({
2318
+ originalName: e.name,
2319
+ variable: e.tensor.variable(!1)
2320
+ })), this.accumulatedUpdates = e.slice(t, t * 2).map((e) => ({
2321
+ originalName: e.name,
2322
+ variable: e.tensor.variable(!1)
2323
+ }));
2324
+ }
2325
+ getConfig() {
2326
+ return {
2327
+ learningRate: this.learningRate,
2328
+ rho: this.rho,
2329
+ epsilon: this.epsilon
2330
+ };
2331
+ }
2332
+ static fromConfig(e, t) {
2333
+ return new e(t.learningRate, t.rho, t.epsilon);
2334
+ }
2335
+ }, go = class extends $ {
2336
+ static get className() {
2337
+ return "Adagrad";
2338
+ }
2339
+ constructor(e, t = .1) {
2340
+ super(), this.learningRate = e, this.initialAccumulatorValue = t, this.accumulatedGrads = [];
2341
+ }
2342
+ applyGradients(e) {
2343
+ (Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e)).forEach((t, n) => {
2344
+ let r = M.registeredVariables[t];
2345
+ this.accumulatedGrads[n] ?? (this.accumulatedGrads[n] = {
2346
+ originalName: `${t}/accumulator`,
2347
+ variable: I(() => Ka(r.shape, this.initialAccumulatorValue).variable(!1))
2348
+ });
2349
+ let i = Array.isArray(e) ? e[n].tensor : e[t];
2350
+ if (i == null) return;
2351
+ let a = this.accumulatedGrads[n].variable;
2352
+ I(() => {
2353
+ let e = G(a, Z(i));
2354
+ a.assign(e);
2355
+ let t = G(q(K(i, X(G(e, M.backend.epsilon()))), -this.learningRate), r);
2356
+ r.assign(t);
2357
+ });
2358
+ }), this.incrementIterations();
2359
+ }
2360
+ dispose() {
2361
+ this.accumulatedGrads != null && L(this.accumulatedGrads.map((e) => e.variable));
2362
+ }
2363
+ async getWeights() {
2364
+ return [await this.saveIterations()].concat(this.accumulatedGrads.map((e) => ({
2365
+ name: e.originalName,
2366
+ tensor: e.variable
2367
+ })));
2368
+ }
2369
+ async setWeights(e) {
2370
+ e = await this.extractIterations(e), this.accumulatedGrads = e.map((e) => ({
2371
+ originalName: e.name,
2372
+ variable: e.tensor.variable(!1)
2373
+ }));
2374
+ }
2375
+ getConfig() {
2376
+ return {
2377
+ learningRate: this.learningRate,
2378
+ initialAccumulatorValue: this.initialAccumulatorValue
2379
+ };
2380
+ }
2381
+ static fromConfig(e, t) {
2382
+ return new e(t.learningRate, t.initialAccumulatorValue);
2383
+ }
2384
+ }, _o = class extends $ {
2385
+ static get className() {
2386
+ return "Adam";
2387
+ }
2388
+ constructor(e, t, n, r = null) {
2389
+ super(), this.learningRate = e, this.beta1 = t, this.beta2 = n, this.epsilon = r, this.accumulatedFirstMoment = [], this.accumulatedSecondMoment = [], I(() => {
2390
+ this.accBeta1 = Y(t).variable(), this.accBeta2 = Y(n).variable();
2391
+ }), r ?? (this.epsilon = M.backend.epsilon());
2392
+ }
2393
+ applyGradients(e) {
2394
+ let t = Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e);
2395
+ I(() => {
2396
+ let n = Q(1, this.accBeta1), r = Q(1, this.accBeta2);
2397
+ t.forEach((t, i) => {
2398
+ let a = M.registeredVariables[t];
2399
+ this.accumulatedFirstMoment[i] ?? (this.accumulatedFirstMoment[i] = {
2400
+ originalName: `${t}/m`,
2401
+ variable: I(() => J(a).variable(!1))
2402
+ }), this.accumulatedSecondMoment[i] ?? (this.accumulatedSecondMoment[i] = {
2403
+ originalName: `${t}/v`,
2404
+ variable: I(() => J(a).variable(!1))
2405
+ });
2406
+ let o = Array.isArray(e) ? e[i].tensor : e[t];
2407
+ if (o == null) return;
2408
+ let s = this.accumulatedFirstMoment[i].variable, c = this.accumulatedSecondMoment[i].variable, l = G(q(s, this.beta1), q(o, 1 - this.beta1)), u = G(q(c, this.beta2), q(Z(o), 1 - this.beta2)), d = K(l, n), f = K(u, r);
2409
+ s.assign(l), c.assign(u);
2410
+ let p = G(q(K(d, G(X(f), this.epsilon)), -this.learningRate), a);
2411
+ a.assign(p);
2412
+ }), this.accBeta1.assign(q(this.accBeta1, this.beta1)), this.accBeta2.assign(q(this.accBeta2, this.beta2));
2413
+ }), this.incrementIterations();
2414
+ }
2415
+ dispose() {
2416
+ this.accBeta1.dispose(), this.accBeta2.dispose(), this.accumulatedFirstMoment != null && L(this.accumulatedFirstMoment.map((e) => e.variable)), this.accumulatedSecondMoment != null && L(this.accumulatedSecondMoment.map((e) => e.variable));
2417
+ }
2418
+ async getWeights() {
2419
+ let e = [...this.accumulatedFirstMoment, ...this.accumulatedSecondMoment];
2420
+ return [await this.saveIterations()].concat(e.map((e) => ({
2421
+ name: e.originalName,
2422
+ tensor: e.variable
2423
+ })));
2424
+ }
2425
+ async setWeights(e) {
2426
+ e = await this.extractIterations(e), I(() => {
2427
+ this.accBeta1.assign(Qa(this.beta1, this.iterations_ + 1)), this.accBeta2.assign(Qa(this.beta2, this.iterations_ + 1));
2428
+ });
2429
+ let t = e.length / 2;
2430
+ this.accumulatedFirstMoment = e.slice(0, t).map((e) => ({
2431
+ originalName: e.name,
2432
+ variable: e.tensor.variable(!1)
2433
+ })), this.accumulatedSecondMoment = e.slice(t, t * 2).map((e) => ({
2434
+ originalName: e.name,
2435
+ variable: e.tensor.variable(!1)
2436
+ }));
2437
+ }
2438
+ getConfig() {
2439
+ return {
2440
+ learningRate: this.learningRate,
2441
+ beta1: this.beta1,
2442
+ beta2: this.beta2,
2443
+ epsilon: this.epsilon
2444
+ };
2445
+ }
2446
+ static fromConfig(e, t) {
2447
+ return new e(t.learningRate, t.beta1, t.beta2, t.epsilon);
2448
+ }
2449
+ }, vo = class extends $ {
2450
+ static get className() {
2451
+ return "Adamax";
2452
+ }
2453
+ constructor(e, t, n, r = null, i = 0) {
2454
+ super(), this.learningRate = e, this.beta1 = t, this.beta2 = n, this.epsilon = r, this.decay = i, this.accumulatedFirstMoment = [], this.accumulatedWeightedInfNorm = [], I(() => {
2455
+ this.iteration = Y(0).variable(), this.accBeta1 = Y(t).variable();
2456
+ }), r ?? (this.epsilon = M.backend.epsilon());
2457
+ }
2458
+ applyGradients(e) {
2459
+ let t = Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e);
2460
+ I(() => {
2461
+ let n = Q(1, this.accBeta1), r = K(-this.learningRate, G(q(this.iteration, this.decay), 1));
2462
+ t.forEach((t, i) => {
2463
+ let a = M.registeredVariables[t];
2464
+ this.accumulatedFirstMoment[i] ?? (this.accumulatedFirstMoment[i] = {
2465
+ originalName: `${t}/m`,
2466
+ variable: J(a).variable(!1)
2467
+ }), this.accumulatedWeightedInfNorm[i] ?? (this.accumulatedWeightedInfNorm[i] = {
2468
+ originalName: `${t}/v`,
2469
+ variable: J(a).variable(!1)
2470
+ });
2471
+ let o = Array.isArray(e) ? e[i].tensor : e[t];
2472
+ if (o == null) return;
2473
+ let s = this.accumulatedFirstMoment[i].variable, c = this.accumulatedWeightedInfNorm[i].variable, l = G(q(s, this.beta1), q(o, 1 - this.beta1)), u = co(q(c, this.beta2), Ga(o));
2474
+ s.assign(l), c.assign(u);
2475
+ let d = G(q(K(r, n), K(l, G(u, this.epsilon))), a);
2476
+ a.assign(d);
2477
+ }), this.iteration.assign(G(this.iteration, 1)), this.accBeta1.assign(q(this.accBeta1, this.beta1));
2478
+ }), this.incrementIterations();
2479
+ }
2480
+ dispose() {
2481
+ this.accBeta1.dispose(), this.iteration.dispose(), this.accumulatedFirstMoment != null && L(this.accumulatedFirstMoment.map((e) => e.variable)), this.accumulatedWeightedInfNorm != null && L(this.accumulatedWeightedInfNorm.map((e) => e.variable));
2482
+ }
2483
+ async getWeights() {
2484
+ throw Error("getWeights() is not implemented for Adamax yet.");
2485
+ }
2486
+ async setWeights(e) {
2487
+ throw Error("setWeights() is not implemented for Adamax yet.");
2488
+ }
2489
+ getConfig() {
2490
+ return {
2491
+ learningRate: this.learningRate,
2492
+ beta1: this.beta1,
2493
+ beta2: this.beta2,
2494
+ epsilon: this.epsilon,
2495
+ decay: this.decay
2496
+ };
2497
+ }
2498
+ static fromConfig(e, t) {
2499
+ return new e(t.learningRate, t.beta1, t.beta2, t.epsilon, t.decay);
2500
+ }
2501
+ }, yo = class extends $ {
2502
+ static get className() {
2503
+ return "SGD";
2504
+ }
2505
+ constructor(e) {
2506
+ super(), this.learningRate = e, this.setLearningRate(e);
2507
+ }
2508
+ applyGradients(e) {
2509
+ (Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e)).forEach((t, n) => {
2510
+ let r = Array.isArray(e) ? e[n].tensor : e[t];
2511
+ if (r == null) return;
2512
+ let i = M.registeredVariables[t];
2513
+ I(() => {
2514
+ let e = G(q(this.c, r), i);
2515
+ i.assign(e);
2516
+ });
2517
+ }), this.incrementIterations();
2518
+ }
2519
+ setLearningRate(e) {
2520
+ this.learningRate = e, this.c != null && this.c.dispose(), this.c = Wi(Y(-e));
2521
+ }
2522
+ dispose() {
2523
+ this.c.dispose();
2524
+ }
2525
+ async getWeights() {
2526
+ return [await this.saveIterations()];
2527
+ }
2528
+ async setWeights(e) {
2529
+ if (e = await this.extractIterations(e), e.length !== 0) throw Error("SGD optimizer does not have settable weights.");
2530
+ }
2531
+ getConfig() {
2532
+ return { learningRate: this.learningRate };
2533
+ }
2534
+ static fromConfig(e, t) {
2535
+ return new e(t.learningRate);
2536
+ }
2537
+ }, bo = class extends yo {
2538
+ static get className() {
2539
+ return "Momentum";
2540
+ }
2541
+ constructor(e, t, n = !1) {
2542
+ super(e), this.learningRate = e, this.momentum = t, this.useNesterov = n, this.accumulations = [], this.m = Y(this.momentum);
2543
+ }
2544
+ applyGradients(e) {
2545
+ (Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e)).forEach((t, n) => {
2546
+ let r = M.registeredVariables[t];
2547
+ this.accumulations[n] ?? (this.accumulations[n] = {
2548
+ originalName: `${t}/momentum`,
2549
+ variable: I(() => J(r).variable(!1))
2550
+ });
2551
+ let i = this.accumulations[n].variable, a = Array.isArray(e) ? e[n].tensor : e[t];
2552
+ a != null && I(() => {
2553
+ let e, t = G(q(this.m, i), a);
2554
+ e = this.useNesterov ? G(q(this.c, G(a, q(t, this.m))), r) : G(q(this.c, t), r), i.assign(t), r.assign(e);
2555
+ });
2556
+ }), this.incrementIterations();
2557
+ }
2558
+ dispose() {
2559
+ this.m.dispose(), this.accumulations != null && L(this.accumulations.map((e) => e.variable));
2560
+ }
2561
+ setMomentum(e) {
2562
+ this.momentum = e;
2563
+ }
2564
+ async getWeights() {
2565
+ return [await this.saveIterations()].concat(this.accumulations.map((e) => ({
2566
+ name: e.originalName,
2567
+ tensor: e.variable
2568
+ })));
2569
+ }
2570
+ async setWeights(e) {
2571
+ e = await this.extractIterations(e), this.accumulations = e.map((e) => ({
2572
+ originalName: e.name,
2573
+ variable: e.tensor.variable(!1)
2574
+ }));
2575
+ }
2576
+ getConfig() {
2577
+ return {
2578
+ learningRate: this.learningRate,
2579
+ momentum: this.momentum,
2580
+ useNesterov: this.useNesterov
2581
+ };
2582
+ }
2583
+ static fromConfig(e, t) {
2584
+ return new e(t.learningRate, t.momentum, t.useNesterov);
2585
+ }
2586
+ }, xo = class extends $ {
2587
+ static get className() {
2588
+ return "RMSProp";
2589
+ }
2590
+ constructor(e, t = .9, n = 0, r = null, i = !1) {
2591
+ if (super(), this.learningRate = e, this.decay = t, this.momentum = n, this.epsilon = r, this.accumulatedMeanSquares = [], this.accumulatedMoments = [], this.accumulatedMeanGrads = [], this.centered = i, r ?? (this.epsilon = M.backend.epsilon()), e == null) throw Error("learningRate for RMSPropOptimizer must be defined.");
2592
+ }
2593
+ applyGradients(e) {
2594
+ (Array.isArray(e) ? e.map((e) => e.name) : Object.keys(e)).forEach((t, n) => {
2595
+ let r = M.registeredVariables[t];
2596
+ this.accumulatedMeanSquares[n] ?? (this.accumulatedMeanSquares[n] = {
2597
+ originalName: `${t}/rms`,
2598
+ variable: I(() => J(r).variable(!1))
2599
+ }), this.accumulatedMoments[n] ?? (this.accumulatedMoments[n] = {
2600
+ originalName: `${t}/momentum`,
2601
+ variable: I(() => J(r).variable(!1))
2602
+ }), this.accumulatedMeanGrads[n] == null && this.centered && (this.accumulatedMeanGrads[n] = {
2603
+ originalName: `${t}/mg`,
2604
+ variable: I(() => J(r).variable(!1))
2605
+ });
2606
+ let i = Array.isArray(e) ? e[n].tensor : e[t];
2607
+ if (i == null) return;
2608
+ let a = this.accumulatedMeanSquares[n].variable, o = this.accumulatedMoments[n].variable;
2609
+ I(() => {
2610
+ let e = G(q(a, this.decay), q(Z(i), 1 - this.decay));
2611
+ if (this.centered) {
2612
+ let t = this.accumulatedMeanGrads[n].variable, s = G(q(t, this.decay), q(i, 1 - this.decay)), c = K(q(i, this.learningRate), X(Q(e, G(Z(s), this.epsilon)))), l = G(q(o, this.momentum), c);
2613
+ a.assign(e), t.assign(s), o.assign(l);
2614
+ let u = Q(r, l);
2615
+ r.assign(u);
2616
+ } else {
2617
+ let e = G(q(a, this.decay), q(Z(i), 1 - this.decay)), t = G(q(o, this.momentum), K(q(i, this.learningRate), X(G(e, this.epsilon))));
2618
+ a.assign(e), o.assign(t);
2619
+ let n = Q(r, t);
2620
+ r.assign(n);
2621
+ }
2622
+ });
2623
+ }), this.incrementIterations();
2624
+ }
2625
+ dispose() {
2626
+ this.accumulatedMeanSquares != null && L(this.accumulatedMeanSquares.map((e) => e.variable)), this.accumulatedMeanGrads != null && this.centered && L(this.accumulatedMeanGrads.map((e) => e.variable)), this.accumulatedMoments != null && L(this.accumulatedMoments.map((e) => e.variable));
2627
+ }
2628
+ async getWeights() {
2629
+ let e = [...this.accumulatedMeanSquares, ...this.accumulatedMoments];
2630
+ return this.centered && e.push(...this.accumulatedMeanGrads), [await this.saveIterations()].concat(e.map((e) => ({
2631
+ name: e.originalName,
2632
+ tensor: e.variable
2633
+ })));
2634
+ }
2635
+ async setWeights(e) {
2636
+ e = await this.extractIterations(e);
2637
+ let t = this.centered ? e.length / 3 : e.length / 2;
2638
+ this.accumulatedMeanSquares = e.slice(0, t).map((e) => ({
2639
+ originalName: e.name,
2640
+ variable: e.tensor.variable(!1)
2641
+ })), this.accumulatedMoments = e.slice(t, t * 2).map((e) => ({
2642
+ originalName: e.name,
2643
+ variable: e.tensor.variable(!1)
2644
+ })), this.centered && (this.accumulatedMeanGrads = e.slice(t * 2, t * 3).map((e) => ({
2645
+ originalName: e.name,
2646
+ variable: e.tensor.variable(!1)
2647
+ })));
2648
+ }
2649
+ getConfig() {
2650
+ return {
2651
+ learningRate: this.learningRate,
2652
+ decay: this.decay,
2653
+ momentum: this.momentum,
2654
+ epsilon: this.epsilon,
2655
+ centered: this.centered
2656
+ };
2657
+ }
2658
+ static fromConfig(e, t) {
2659
+ return new e(t.learningRate, t.decay, t.momentum, t.epsilon, t.centered);
2660
+ }
2661
+ }, So = [
2662
+ ho,
2663
+ go,
2664
+ _o,
2665
+ vo,
2666
+ bo,
2667
+ xo,
2668
+ yo
2669
+ ];
2670
+ function Co() {
2671
+ for (let e of So) mo(e);
2672
+ }
2673
+ // node_modules/@tensorflow/tfjs-core/dist/index.js
2674
+ Co();
2675
+ export { Ii as $, r as $i, mn as $n, dr as $r, mt as $t, Va as A, Ee as Ai, Ht as An, Un as Ar, Ge as At, L as B, Se as Bi, Qt as Bn, Qn as Br, tt as Bt, Ya as C, g as Ci, zt as Cn, In as Cr, x as Ct, Ga as D, le as Di, jr as Dn, Vn as Dr, He as Dt, Ka as E, be as Ei, Vt as En, Bn as Er, Ve as Et, ka as F, ee as Fi, Jt as Fn, Jn as Fr, Ze as Ft, Ui as G, h as Gi, sn as Gn, or as Gr, ot as Gt, Hi as H, c as Hi, en as Hn, ar as Hr, it as Ht, aa as I, me as Ii, Yt as In, Yn as Ir, Qe as It, Gi as J, re as Ji, on as Jn, lr as Jr, lt as Jt, Ki as K, o as Ki, rn as Kn, sr as Kr, st as Kt, ra as L, Te as Li, Xt as Ln, Xn as Lr, Xe as Lt, La as M, ae as Mi, Gt as Mn, Wn as Mr, Je as Mt, Fa as N, ne as Ni, qt as Nn, Gn as Nr, qe as Nt, q as O, ce as Oi, Mr as On, Rn as Or, Ue as Ot, Na as P, ge as Pi, Kt as Pn, Kn as Pr, Ye as Pt, P as Q, y as Qi, dn as Qn, fr as Qr, pt as Qt, Zi as R, xe as Ri, Zt as Rn, er as Rr, $e as Rt, J as S, f as Si, Rt as Sn, Fn as Sr, Nr as St, Ja as T, ve as Ti, Or as Tn, Ln as Tr, Be as Tt, qi as U, oe as Ui, tn as Un, tr as Ur, rt as Ut, Vi as V, _e as Vi, $t as Vn, Zn as Vr, nt as Vt, Wi as W, ie as Wi, nn as Wn, rr as Wr, at as Wt, Ri as X, u as Xi, fn as Xn, ir as Xr, dt as Xt, I as Y, se as Yi, un as Yn, ur as Yr, ut as Yt, F as Z, l as Zi, pn as Zn, nr as Zr, ft as Zt, ro as _, b as _i, Nt as _n, jn as _r, C as _t, _o as a, _r as ai, yt as an, yn as ar, xi as at, Y as b, we as bi, It as bn, Pn as br, Br as bt, $ as c, yr as ci, Ct as cn, Cn as cr, _i as ct, mo as d, Sr as di, Et as dn, wn as dr, ai as dt, i as ea, pr as ei, ht as en, ln as er, Ni as et, co as f, Cr as fi, Dt as fn, En as fr, ci as ft, no as g, Ar as gi, Mt as gn, An as gr, w as gt, to as h, Er as hi, At as hn, kn as hr, Kr as ht, vo as i, gr as ii, vt as in, vn as ir, ki as it, G as j, _ as ji, Wt as jn, kr as jr, Ke as jt, K as k, fe as ki, Ut as kn, zn as kr, We as kt, fo as l, br as li, wt as ln, bn as lr, gi as lt, io as m, Tr as mi, Ot as mn, On as mr, qr as mt, bo as n, mr as ni, _t as nn, gn as nr, ji as nt, go as o, vr as oi, xt as on, xn as or, bi as ot, Q as p, wr as pi, kt as pn, Dn as pr, Ur as pt, Ji as q, m as qi, an as qn, cr as qr, ct as qt, yo as r, hr as ri, bt as rn, _n as rr, M as rt, ho as s, qn as si, St as sn, Sn as sr, j as st, xo as t, Dr as ti, gt as tn, hn as tr, Mi as tt, po as u, xr as ui, Tt as un, Tn as ur, A as ut, Z as v, te as vi, Pt as vn, Mn as vr, S as vt, qa as w, s as wi, Bt as wn, Hn as wr, ze as wt, Qa as x, p as xi, Lt as xn, jt as xr, zr as xt, X as y, d as yi, Ft as yn, Nn as yr, Gr as yt, Yi as z, Ce as zi, cn as zn, $n as zr, et as zt };