@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,474 @@
1
+ import { s as m, i as w, L as I, a as d, A, t as _ } from "./tensor-DdQUJZlz.js";
2
+ import { d as y, f as M, h as T, c as b, e as D, a as L, b as x, g as W } from "./axis_util-BvHEw88j.js";
3
+ import { j as v, h as F, q as N } from "./index-ZyQhjEPo.js";
4
+ import { a as C, c as P } from "./concat_util-DcJk7YHS.js";
5
+ import { S as z, a as B, b as U, c as j, d as q, e as G, f as H, g as V, h as Z, i as k, j as J, k as K, l as X, m as Y, s as Q, n as ee, t as te } from "./selu_util-D1w6yyTO.js";
6
+ import { s as se } from "./slice_util-DtEldBfK.js";
7
+ import { a0 as ne, u as re, w as oe } from "./tensor_util-DV-FP5Q3.js";
8
+ import { c as ae, v as ie, a as ue } from "./scatter_nd_util-5EL-8VAQ.js";
9
+ import { a as le, c as pe, b as ce, e as he, d as fe, g as ge, m as de, s as me } from "./complex_util-Yc1A_gV1.js";
10
+ function Ee(e, t) {
11
+ const r = e.shape.length, s = t.shape.length;
12
+ if (r < 1)
13
+ throw new Error(`tf.gatherND() expects the input to be rank 1 or higher, but the rank was ${r}.`);
14
+ if (s < 1)
15
+ throw new Error(`tf.gatherND() expects the indices to be rank 1 or higher, but the rank was ${s}.`);
16
+ if (t.dtype !== "int32")
17
+ throw new Error(`tf.gatherND() expects the indices to be int32 type, but the dtype was ${t.dtype}.`);
18
+ if (t.shape[s - 1] > r)
19
+ throw new Error(`index innermost dimension length must be <= tensor rank; saw: ${t.shape[s - 1]} vs. ${r}`);
20
+ if (m(e.shape) === 0)
21
+ throw new Error(`Requested more than 0 entries, but input is empty. Input shape: ${e.shape}.`);
22
+ const n = t.shape, o = n[n.length - 1];
23
+ let a = 1;
24
+ for (let i = 0; i < n.length - 1; ++i)
25
+ a *= n[i];
26
+ const u = e.shape, p = n.slice();
27
+ p.pop();
28
+ let c = 1;
29
+ for (let i = o; i < r; ++i)
30
+ c *= u[i], p.push(u[i]);
31
+ const g = [
32
+ ...w(e.shape).map((i) => i / c),
33
+ 1
34
+ ].slice(0, o);
35
+ return [p, a, c, g];
36
+ }
37
+ var f;
38
+ (function(e) {
39
+ e[e.FIRST_DIM_SIZE = 0] = "FIRST_DIM_SIZE", e[e.VALUE_ROWIDS = 1] = "VALUE_ROWIDS", e[e.ROW_LENGTHS = 2] = "ROW_LENGTHS", e[e.ROW_SPLITS = 3] = "ROW_SPLITS", e[e.ROW_LIMITS = 4] = "ROW_LIMITS", e[e.ROW_STARTS = 5] = "ROW_STARTS";
40
+ })(f || (f = {}));
41
+ function Ie(e, t, r) {
42
+ let s = new Array();
43
+ if (r == null && t == null)
44
+ return s;
45
+ if (t == null)
46
+ for (; s.length < e + r.length; )
47
+ s.push(-1);
48
+ else
49
+ s = t.slice();
50
+ if (r == null)
51
+ return s;
52
+ if (e + r.length !== s.length)
53
+ throw new Error(`rt input.shape and shape=${t} are incompatible: rt input.rank = ${e + r.length}, but shape.rank = ${s.length}`);
54
+ for (let n = 1; n < r.length; ++n) {
55
+ const o = r[n], a = s[s.length - r.length + n], u = s[a];
56
+ if (o >= 0)
57
+ if (u >= 0) {
58
+ if (u !== o)
59
+ throw new Error(`rt input.shape and shape=${t} are incompatible: rt input.shape[${n + e}] = ${o} but shape[${n + e}] = ${u}`);
60
+ } else
61
+ s[a] = o;
62
+ }
63
+ return s;
64
+ }
65
+ function $e(e) {
66
+ const t = {
67
+ FIRST_DIM_SIZE: f.FIRST_DIM_SIZE,
68
+ VALUE_ROWIDS: f.VALUE_ROWIDS,
69
+ ROW_LENGTHS: f.ROW_LENGTHS,
70
+ ROW_SPLITS: f.ROW_SPLITS,
71
+ ROW_LIMITS: f.ROW_LIMITS,
72
+ ROW_STARTS: f.ROW_STARTS
73
+ }, r = [];
74
+ for (const s of e)
75
+ if (s in t)
76
+ r.push(t[s]);
77
+ else
78
+ break;
79
+ return r;
80
+ }
81
+ function Se(e) {
82
+ return e.length === 0 ? 0 : e[0] === f.FIRST_DIM_SIZE ? e.length - 1 : e.length;
83
+ }
84
+ function Re(e, t) {
85
+ if (e == null || t == null)
86
+ return;
87
+ const r = e.length, s = t.length;
88
+ if (r >= s)
89
+ throw new Error(`defaultValue.shape=${e} and ragged tensor flatValues.shape=${t}, are incompatible: defaultValue.rank = ${r} must be less than ragged tensor input flatValues.rank = ${s})`);
90
+ for (let n = 0; n < Math.min(r, s - 1); ++n) {
91
+ const o = e[n], a = t[n + 1];
92
+ if (o >= 0 && a >= 0 && o !== 1 && o !== a)
93
+ throw new Error(`defaultValue.shape=${e}, and ragged tensor input flatValues.shape=${t} are incompatible: defaultValue.shape[${n - e.length}] = ${o} but ragged tensor input.flatValues.shape[${n - e.length}] = ${a}`);
94
+ }
95
+ }
96
+ const $ = 30;
97
+ function Oe(e) {
98
+ return e <= $ ? e : I(e, Math.floor(Math.sqrt(e)));
99
+ }
100
+ function we(e, t, r) {
101
+ const s = r * (typeof e == "number" ? e : e[0]), n = t * (typeof e == "number" ? e : e[1]);
102
+ return [s, n];
103
+ }
104
+ function Ae(e, t, r, s = !0) {
105
+ let n = [];
106
+ if (s)
107
+ n = n.concat(t.slice(0)), n.push(e[0] / r), n = n.concat(e.slice(1));
108
+ else {
109
+ n = n.concat(e[0]);
110
+ const o = t.length;
111
+ for (let a = 0; a < o; ++a)
112
+ n = n.concat([e[a + 1] / t[a], t[a]]);
113
+ n = n.concat(e.slice(o + 1));
114
+ }
115
+ return n;
116
+ }
117
+ function _e(e, t, r = !0) {
118
+ const s = [];
119
+ if (r) {
120
+ s.push(t);
121
+ for (let n = t + 1; n < e; ++n)
122
+ n <= 2 * t ? (s.push(n), s.push(n - (t + 1))) : s.push(n);
123
+ } else {
124
+ const n = [], o = [];
125
+ for (let a = 1; a < e; ++a)
126
+ a >= t * 2 + 1 || a % 2 === 1 ? o.push(a) : n.push(a);
127
+ s.push(...n), s.push(0), s.push(...o);
128
+ }
129
+ return s;
130
+ }
131
+ function ye(e, t, r, s = !0) {
132
+ const n = [];
133
+ s ? n.push(e[0] / r) : n.push(e[0] * r);
134
+ for (let o = 1; o < e.length; ++o)
135
+ o <= t.length ? s ? n.push(t[o - 1] * e[o]) : n.push(e[o] / t[o - 1]) : n.push(e[o]);
136
+ return n;
137
+ }
138
+ function Me(e, t) {
139
+ const r = [0];
140
+ for (let s = 0; s < t; ++s)
141
+ r.push(e[s][0]);
142
+ return r;
143
+ }
144
+ function Te(e, t, r) {
145
+ const s = e.slice(0, 1);
146
+ for (let n = 0; n < r; ++n)
147
+ s.push(e[n + 1] - t[n][0] - t[n][1]);
148
+ return s;
149
+ }
150
+ const be = 0.3275911, De = 0.254829592, Le = -0.284496736, xe = 1.421413741, We = -1.453152027, ve = 1.061405429;
151
+ const E = "->", Fe = /->/g, S = ",", R = "...";
152
+ function Ne(e, t) {
153
+ e = e.replace(/\s/g, "");
154
+ const r = (e.length - e.replace(Fe, "").length) / E.length;
155
+ if (r < 1)
156
+ throw new Error("Equations without an arrow are not supported.");
157
+ if (r > 1)
158
+ throw new Error(`Equation must contain exactly one arrow ("${E}").`);
159
+ const [s, n] = e.split(E);
160
+ d(s.indexOf(R) === -1, () => `The ellipsis notation ("${R}") is not supported yet.`);
161
+ const o = s.split(S), a = o.length;
162
+ if (t !== a)
163
+ throw new Error(`Expected ${a} input tensors, received ${t}`);
164
+ if (a > 2)
165
+ throw new Error("Support for more than 2 input tensors is not implemented yet.");
166
+ const u = [];
167
+ for (let l = 0; l < n.length; ++l) {
168
+ const h = n[l];
169
+ if (!o.some((O) => O.indexOf(h) !== -1))
170
+ throw new Error(`Output subscripts contain the label ${h} not present in the input subscripts.`);
171
+ u.indexOf(h) === -1 && u.push(h);
172
+ }
173
+ for (let l = 0; l < s.length; ++l) {
174
+ const h = s[l];
175
+ u.indexOf(h) === -1 && h !== S && u.push(h);
176
+ }
177
+ const p = new Array(o.length);
178
+ for (let l = 0; l < a; ++l) {
179
+ if (new Set(o[l].split("")).size !== o[l].length)
180
+ throw new Error(`Found duplicate axes in input component ${o[l]}. Support for duplicate axes in input is not implemented yet.`);
181
+ p[l] = [];
182
+ for (let h = 0; h < o[l].length; ++h)
183
+ p[l].push(u.indexOf(o[l][h]));
184
+ }
185
+ const c = u.length, g = n.length, i = [];
186
+ for (let l = g; l < c; ++l)
187
+ i.push(l);
188
+ return { allDims: u, summedDims: i, idDims: p };
189
+ }
190
+ function Ce(e, t) {
191
+ let r = new Array(e);
192
+ r.fill(-1);
193
+ for (let n = 0; n < t.length; ++n)
194
+ r[t[n]] = n;
195
+ const s = [];
196
+ for (let n = 0; n < e; ++n)
197
+ r[n] === -1 && s.push(n);
198
+ return r = r.filter((n) => n !== -1), { permutationIndices: r, expandDims: s };
199
+ }
200
+ function Pe(e, t, r) {
201
+ const s = new Array(e);
202
+ for (let n = 0; n < r.length; ++n) {
203
+ const o = r[n].shape;
204
+ for (let a = 0; a < t[n].length; ++a)
205
+ s[t[n][a]] === void 0 ? s[t[n][a]] = o[a] : d(s[t[n][a]] === o[a], () => `Expected dimension ${s[t[n][a]]} at axis ${a} of input shaped ${JSON.stringify(o)}, but got dimension ${o[a]}`);
206
+ }
207
+ }
208
+ function ze(e, t) {
209
+ const r = e, s = [];
210
+ let n = 0;
211
+ e.length === 0 && r.push(-1), n = e.length + 1;
212
+ for (let a = 0; a < n; ++a)
213
+ s.push([]);
214
+ const o = [];
215
+ for (let a = 0; a < r.length; ++a) {
216
+ const u = r[a], p = Ue(t, u);
217
+ for (const c of p)
218
+ o.indexOf(c) === -1 && (s[a].push(c), o.push(c));
219
+ }
220
+ return { path: r, steps: s };
221
+ }
222
+ function Be(e) {
223
+ return e.every((t, r) => t === r);
224
+ }
225
+ function Ue(e, t) {
226
+ const r = [];
227
+ for (let s = 0; s < e.length; ++s)
228
+ (e[s].length === 0 || e[s].indexOf(t) !== -1 || t === -1) && r.push(s);
229
+ return r;
230
+ }
231
+ function je(e, t, r = 0) {
232
+ let s = [];
233
+ if (typeof t == "number")
234
+ d(e.shape[r] % t === 0, () => "Number of splits must evenly divide the axis."), s = new Array(t).fill(e.shape[r] / t);
235
+ else {
236
+ const n = t.reduce((a, u) => (u === -1 && (a += 1), a), 0);
237
+ d(n <= 1, () => "There should be only one negative value in split array.");
238
+ const o = t.indexOf(-1);
239
+ if (o !== -1) {
240
+ const a = t.reduce((u, p) => p > 0 ? u + p : u);
241
+ t[o] = e.shape[r] - a;
242
+ }
243
+ d(e.shape[r] === t.reduce((a, u) => a + u), () => "The sum of sizes must match the size of the axis dimension."), s = t;
244
+ }
245
+ return s;
246
+ }
247
+ function qe(e) {
248
+ return `Received SparseTensor with denseShape[0] = 0 but
249
+ indices.shape[0] = ${e}`;
250
+ }
251
+ function Ge(e, t) {
252
+ return `indices(${e}, 0) is invalid: ${t} < 0`;
253
+ }
254
+ function He(e, t, r) {
255
+ return `indices(${e}, 0) is invalid: ${t} >= ${r}`;
256
+ }
257
+ function Ve(e, t) {
258
+ return `only one output dimension may be -1, not both ${e} and ${t}`;
259
+ }
260
+ function Ze(e, t) {
261
+ return `size ${e} must be non-negative, not ${t}`;
262
+ }
263
+ function ke() {
264
+ return "reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero";
265
+ }
266
+ function Je(e, t) {
267
+ const r = m(e), s = m(t);
268
+ return `Input to reshape is a SparseTensor with ${r}
269
+ dense values, but the requested shape requires a multiple of ${s}. inputShape=${e} outputShape= ${t}`;
270
+ }
271
+ function Ke(e, t) {
272
+ const r = m(e), s = m(t);
273
+ return `Input to reshape is a tensor with ${r} dense values, but the requested shape has ${s}. inputShape=${e} outputShape=${t}`;
274
+ }
275
+ function Xe() {
276
+ return "segment ids must be >= 0";
277
+ }
278
+ function Ye() {
279
+ return "segment ids are not increasing";
280
+ }
281
+ function Qe(e, t) {
282
+ return `Segment id ${e} out of range [0, ${t}), possibly because segmentIds input is not sorted.`;
283
+ }
284
+ function et(e, t, r) {
285
+ return `Bad: indices[${e}] == ${t} out of range [0, ${r})`;
286
+ }
287
+ function tt(e, t) {
288
+ let r = !1, s;
289
+ for (e <= $ ? (s = e, r = !0) : s = I(e, Math.floor(Math.sqrt(e))); !r; )
290
+ s > t || s === e ? r = !0 : s = I(e, s + 1);
291
+ return s;
292
+ }
293
+ function st(e, t, r) {
294
+ const s = [], n = e.length;
295
+ for (let o = 0; o < n; o++)
296
+ o !== t ? s.push(e[o]) : s.push(r);
297
+ return s;
298
+ }
299
+ function nt(e, t, r, s) {
300
+ const n = t.shape.length, o = e.shape.length;
301
+ if (s !== 0 && (s < -n || s > n))
302
+ throw new Error(`Expect batchDims in the range of [-${n}, ${n}], but got ${s}`);
303
+ if (s < 0 && (s += n), s > o)
304
+ throw new Error(`batchDims (${s}) must be less than rank(x) (
305
+ ${o}).`);
306
+ if (r < s)
307
+ throw new Error(`batchDims (${s}) must be less than or equal to axis (${r}).`);
308
+ for (let i = 0; i < s; ++i)
309
+ if (e.shape[i] !== t.shape[i])
310
+ throw new Error(`x.shape[${i}]: ${e.shape[i]} should be equal to indices.shape[${i}]: ${t.shape[i]}.`);
311
+ const a = e.shape[r], u = [];
312
+ let p = 1, c = 1, g = 1;
313
+ for (let i = 0; i < s; ++i)
314
+ u.push(e.shape[i]), p *= e.shape[i];
315
+ for (let i = s; i < r; i++)
316
+ u.push(e.shape[i]), c *= e.shape[i];
317
+ for (let i = s; i < n; i++)
318
+ u.push(t.shape[i]);
319
+ for (let i = r + 1; i < o; i++)
320
+ u.push(e.shape[i]), g *= e.shape[i];
321
+ return { batchSize: p, sliceSize: g, outerSize: c, dimSize: a, outputShape: u };
322
+ }
323
+ const rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
324
+ __proto__: null,
325
+ collectGatherOpShapeInfo: nt,
326
+ computeOutShape: st,
327
+ segOpComputeOptimalWindowSize: tt
328
+ }, Symbol.toStringTag, { value: "Module" }));
329
+ function ot(e) {
330
+ try {
331
+ return e.map((t) => A(t));
332
+ } catch (t) {
333
+ throw new Error(`Failed to decode encoded string bytes into utf-8, error: ${t}`);
334
+ }
335
+ }
336
+ function at(e) {
337
+ return e.map((t) => _(t));
338
+ }
339
+ const mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
340
+ __proto__: null,
341
+ ERF_A1: De,
342
+ ERF_A2: Le,
343
+ ERF_A3: xe,
344
+ ERF_A4: We,
345
+ ERF_A5: ve,
346
+ ERF_P: be,
347
+ PARALLELIZE_THRESHOLD: $,
348
+ get RowPartitionType() {
349
+ return f;
350
+ },
351
+ SELU_SCALE: z,
352
+ SELU_SCALEALPHA: B,
353
+ applyActivation: U,
354
+ assertAndGetBroadcastShape: v,
355
+ assertAxesAreInnerMostDims: y,
356
+ assertParamsConsistent: C,
357
+ assignToTypedArray: le,
358
+ axesAreInnerMostDims: M,
359
+ calculateShapes: ae,
360
+ checkEinsumDimSizes: Pe,
361
+ checkPadOnDimRoundingMode: j,
362
+ combineLocations: T,
363
+ combineRaggedTensorToTensorShapes: Ie,
364
+ complexWithEvenIndex: pe,
365
+ complexWithOddIndex: ce,
366
+ computeConv2DInfo: q,
367
+ computeConv3DInfo: G,
368
+ computeDefaultPad: H,
369
+ computeDilation2DInfo: V,
370
+ computeOptimalWindowSize: Oe,
371
+ computeOutAndReduceShapes: b,
372
+ computeOutShape: P,
373
+ computePool2DInfo: Z,
374
+ computePool3DInfo: k,
375
+ convertConv2DDataFormat: J,
376
+ decodeEinsumEquation: Ne,
377
+ eitherStridesOrDilationsAreOne: K,
378
+ expandShapeToKeepDim: D,
379
+ exponent: he,
380
+ exponents: fe,
381
+ fromStringArrayToUint8: at,
382
+ fromUint8ToStringArray: ot,
383
+ getAxesPermutation: L,
384
+ getBroadcastDims: F,
385
+ getComplexWithIndex: ge,
386
+ getEinsumComputePath: ze,
387
+ getEinsumPermutation: Ce,
388
+ getFusedBiasGradient: X,
389
+ getFusedDyActivation: Y,
390
+ getImageCenter: we,
391
+ getInnerMostAxes: x,
392
+ getPermuted: _e,
393
+ getRaggedRank: Se,
394
+ getReductionAxes: N,
395
+ getReshaped: Ae,
396
+ getReshapedPermuted: ye,
397
+ getRowPartitionTypesHelper: $e,
398
+ getSliceBeginCoords: Me,
399
+ getSliceSize: Te,
400
+ getSparseFillEmptyRowsIndicesDenseShapeMismatch: qe,
401
+ getSparseFillEmptyRowsNegativeIndexErrorMessage: Ge,
402
+ getSparseFillEmptyRowsOutOfRangeIndexErrorMessage: He,
403
+ getSparseReshapeEmptyTensorZeroOutputDimErrorMessage: ke,
404
+ getSparseReshapeInputOutputMismatchErrorMessage: Ke,
405
+ getSparseReshapeInputOutputMultipleErrorMessage: Je,
406
+ getSparseReshapeMultipleNegativeOneOutputDimErrorMessage: Ve,
407
+ getSparseReshapeNegativeOutputDimErrorMessage: Ze,
408
+ getSparseSegmentReductionIndicesOutOfRangeErrorMessage: et,
409
+ getSparseSegmentReductionNegativeSegmentIdsErrorMessage: Xe,
410
+ getSparseSegmentReductionNonIncreasingSegmentIdsErrorMessage: Ye,
411
+ getSparseSegmentReductionSegmentIdOutOfRangeErrorMessage: Qe,
412
+ getUndoAxesPermutation: W,
413
+ isIdentityPermutation: Be,
414
+ log: ne,
415
+ mergeRealAndImagArrays: de,
416
+ prepareAndValidate: Ee,
417
+ prepareSplitSize: je,
418
+ segment_util: rt,
419
+ shouldFuse: Q,
420
+ slice_util: se,
421
+ splitRealAndImagArrays: me,
422
+ stridesOrDilationsArePositive: ee,
423
+ tupleValuesAreOne: te,
424
+ upcastType: re,
425
+ validateDefaultValueShape: Re,
426
+ validateInput: ie,
427
+ validateUpdateShape: ue,
428
+ warn: oe
429
+ }, Symbol.toStringTag, { value: "Module" }));
430
+ export {
431
+ _e as A,
432
+ ye as B,
433
+ Me as C,
434
+ Te as D,
435
+ be as E,
436
+ Ne as F,
437
+ Pe as G,
438
+ ze as H,
439
+ Ce as I,
440
+ Be as J,
441
+ Ee as K,
442
+ nt as L,
443
+ we as M,
444
+ je as N,
445
+ st as O,
446
+ tt as P,
447
+ f as R,
448
+ Se as a,
449
+ mt as b,
450
+ Oe as c,
451
+ Ie as d,
452
+ at as e,
453
+ ot as f,
454
+ $e as g,
455
+ qe as h,
456
+ Ge as i,
457
+ He as j,
458
+ Ve as k,
459
+ Ze as l,
460
+ ke as m,
461
+ Je as n,
462
+ Ke as o,
463
+ Xe as p,
464
+ Ye as q,
465
+ Qe as r,
466
+ et as s,
467
+ De as t,
468
+ Le as u,
469
+ Re as v,
470
+ xe as w,
471
+ We as x,
472
+ ve as y,
473
+ Ae as z
474
+ };