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