@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,8 @@
1
+ import { x as t, y as a } from "./index-ZyQhjEPo.js";
2
+ function f(r, n, e) {
3
+ const o = t(r, e);
4
+ return a(r, n, o, e);
5
+ }
6
+ export {
7
+ f as t
8
+ };
@@ -0,0 +1,12 @@
1
+ import { x as n, y as t } from "./index-ZyQhjEPo.js";
2
+ import { c as s } from "./tensor-DdQUJZlz.js";
3
+ function p(r, e) {
4
+ s(r);
5
+ const o = n(r, e);
6
+ if (o.length !== 1)
7
+ throw new Error("tensor1d() requires values to be a flat/TypedArray");
8
+ return t(r, null, o, e);
9
+ }
10
+ export {
11
+ p as t
12
+ };
@@ -0,0 +1,15 @@
1
+ import { x as t, y as s } from "./index-ZyQhjEPo.js";
2
+ import { c as a } from "./tensor-DdQUJZlz.js";
3
+ function f(o, r, n) {
4
+ if (a(o), r != null && r.length !== 2)
5
+ throw new Error("tensor2d() requires shape to have two numbers");
6
+ const e = t(o, n);
7
+ if (e.length !== 2 && e.length !== 1)
8
+ throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");
9
+ if (e.length === 1 && r == null)
10
+ throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");
11
+ return s(o, r, e, n);
12
+ }
13
+ export {
14
+ f as t
15
+ };
@@ -0,0 +1,15 @@
1
+ import { x as t, y as a } from "./index-ZyQhjEPo.js";
2
+ import { c as s } from "./tensor-DdQUJZlz.js";
3
+ function f(o, r, n) {
4
+ if (s(o), r != null && r.length !== 4)
5
+ throw new Error("tensor4d() requires shape to have four numbers");
6
+ const e = t(o, n);
7
+ if (e.length !== 4 && e.length !== 1)
8
+ throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");
9
+ if (e.length === 1 && r == null)
10
+ throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");
11
+ return a(o, r, e, n);
12
+ }
13
+ export {
14
+ f as t
15
+ };
@@ -0,0 +1,523 @@
1
+ import { e as g, F, x as v, G as D, b as M, T as w } from "./tensor-DdQUJZlz.js";
2
+ const A = 1e-7, G = 1e-4;
3
+ class z {
4
+ constructor(s, o) {
5
+ this.backend = s, this.dataMover = o, this.data = /* @__PURE__ */ new WeakMap(), this.dataIdsCount = 0;
6
+ }
7
+ get(s) {
8
+ return this.data.has(s) || this.dataMover.moveData(this.backend, s), this.data.get(s);
9
+ }
10
+ set(s, o) {
11
+ this.dataIdsCount++, this.data.set(s, o);
12
+ }
13
+ has(s) {
14
+ return this.data.has(s);
15
+ }
16
+ delete(s) {
17
+ return this.dataIdsCount--, this.data.delete(s);
18
+ }
19
+ numDataIds() {
20
+ return this.dataIdsCount;
21
+ }
22
+ }
23
+ class K {
24
+ refCount(s) {
25
+ return d("refCount");
26
+ }
27
+ incRef(s) {
28
+ return d("incRef");
29
+ }
30
+ timerAvailable() {
31
+ return !0;
32
+ }
33
+ time(s) {
34
+ return d("time");
35
+ }
36
+ read(s) {
37
+ return d("read");
38
+ }
39
+ readSync(s) {
40
+ return d("readSync");
41
+ }
42
+ readToGPU(s, o) {
43
+ return d("readToGPU");
44
+ }
45
+ numDataIds() {
46
+ return d("numDataIds");
47
+ }
48
+ disposeData(s, o) {
49
+ return d("disposeData");
50
+ }
51
+ write(s, o, c) {
52
+ return d("write");
53
+ }
54
+ move(s, o, c, a, r) {
55
+ return d("move");
56
+ }
57
+ createTensorFromGPUData(s, o, c) {
58
+ return d("createTensorFromGPUData");
59
+ }
60
+ memory() {
61
+ return d("memory");
62
+ }
63
+ /** Returns the highest precision for floats in bits (e.g. 16 or 32) */
64
+ floatPrecision() {
65
+ return d("floatPrecision");
66
+ }
67
+ /** Returns the smallest representable number. */
68
+ epsilon() {
69
+ return this.floatPrecision() === 32 ? A : G;
70
+ }
71
+ dispose() {
72
+ return d("dispose");
73
+ }
74
+ }
75
+ function d(t) {
76
+ throw new Error(`'${t}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`);
77
+ }
78
+ const _ = "Abs", U = "Acos", W = "Acosh", j = "Add", H = "AddN", X = "All", Y = "Any", Z = "ArgMax", J = "ArgMin", Q = "Asin", tt = "Asinh", st = "Atan", ot = "Atanh", et = "Atan2", nt = "AvgPool", at = "AvgPoolGrad", rt = "AvgPool3D", ct = "AvgPool3DGrad", it = "BatchMatMul", lt = "BatchToSpaceND", ut = "Bincount", pt = "BitwiseAnd", dt = "BroadcastTo", ft = "BroadcastArgs", ht = "Cast", gt = "Ceil", mt = "ClipByValue", bt = "Complex", St = "ComplexAbs", Dt = "Concat", Rt = "Conv2D", Tt = "Conv2DBackpropFilter", kt = "Conv2DBackpropInput", Nt = "Conv3D", xt = "Conv3DBackpropFilterV2", Pt = "Conv3DBackpropInputV2", vt = "Cos", Ct = "Cosh", Ft = "Cumprod", yt = "Cumsum", It = "CropAndResize", Bt = "DenseBincount", Et = "DepthToSpace", Mt = "DepthwiseConv2dNative", wt = "DepthwiseConv2dNativeBackpropFilter", At = "DepthwiseConv2dNativeBackpropInput", Gt = "Diag", Lt = "Dilation2D", $t = "Dilation2DBackpropInput", Ot = "Dilation2DBackpropFilter", qt = "Draw", Vt = "RealDiv", zt = "Einsum", Kt = "Elu", _t = "EluGrad", Ut = "Erf", Wt = "Equal", jt = "Exp", Ht = "ExpandDims", Xt = "Expm1", Yt = "FFT", Zt = "Fill", Jt = "FlipLeftRight", Qt = "Floor", ts = "FloorDiv", ss = "FusedBatchNorm", os = "GatherV2", es = "GatherNd", ns = "Greater", as = "GreaterEqual", rs = "Identity", cs = "IFFT", is = "Imag", ls = "IsFinite", us = "IsInf", ps = "IsNan", ds = "LeakyRelu", fs = "Less", hs = "LessEqual", gs = "LinSpace", ms = "Log", bs = "Log1p", Ss = "LogicalAnd", Ds = "LogicalNot", Rs = "LogicalOr", Ts = "LogSoftmax", ks = "LRN", Ns = "LRNGrad", xs = "Max", Ps = "Maximum", vs = "MaxPool", Cs = "MaxPoolGrad", Fs = "MaxPool3D", ys = "MaxPool3DGrad", Is = "MaxPoolWithArgmax", Bs = "Mean", Es = "Min", Ms = "Minimum", ws = "MirrorPad", As = "Mod", Gs = "Multinomial", Ls = "Multiply", $s = "Neg", Os = "NotEqual", qs = "NonMaxSuppressionV3", Vs = "NonMaxSuppressionV4", zs = "NonMaxSuppressionV5", Ks = "OnesLike", _s = "OneHot", Us = "Pack", Ws = "PadV2", js = "Pow", Hs = "Prelu", Xs = "Prod", Ys = "RaggedGather", Zs = "RaggedRange", Js = "RaggedTensorToTensor", Qs = "Range", to = "Real", so = "Reciprocal", oo = "Relu", eo = "Reshape", no = "ResizeNearestNeighbor", ao = "ResizeNearestNeighborGrad", ro = "ResizeBilinear", co = "ResizeBilinearGrad", io = "Relu6", lo = "Reverse", uo = "Round", po = "Rsqrt", fo = "ScatterNd", ho = "TensorScatterUpdate", go = "SearchSorted", mo = "Select", bo = "Selu", So = "Slice", Do = "Sin", Ro = "Sinh", To = "Sign", ko = "Sigmoid", No = "Softplus", xo = "Sqrt", Po = "Sum", vo = "SpaceToBatchND", Co = "SplitV", Fo = "Softmax", yo = "SparseFillEmptyRows", Io = "SparseReshape", Bo = "SparseSegmentMean", Eo = "SparseSegmentSum", Mo = "SparseToDense", wo = "SquaredDifference", Ao = "Square", Go = "StaticRegexReplace", Lo = "StridedSlice", $o = "StringNGrams", Oo = "StringSplit", qo = "StringToHashBucketFast", Vo = "Sub", zo = "Tan", Ko = "Tanh", _o = "Tile", Uo = "TopK", Wo = "Transform", jo = "Transpose", Ho = "Unique", Xo = "Unpack", Yo = "UnsortedSegmentSum", Zo = "ZerosLike", Jo = "Step", Qo = "FromPixels", te = "RotateWithOffset", se = "_FusedMatMul", oe = "FusedConv2D", ee = "FusedDepthwiseConv2D";
79
+ function y(...t) {
80
+ g().getBool("IS_TEST") || g().getBool("PROD") || console.warn(...t);
81
+ }
82
+ function ne(...t) {
83
+ g().getBool("IS_TEST") || g().getBool("PROD") || console.log(...t);
84
+ }
85
+ const S = F("kernelRegistry", () => /* @__PURE__ */ new Map()), R = F("gradRegistry", () => /* @__PURE__ */ new Map());
86
+ function ae(t, s) {
87
+ const o = I(t, s);
88
+ return S.get(o);
89
+ }
90
+ function re(t) {
91
+ return R.get(t);
92
+ }
93
+ function ce(t) {
94
+ const s = S.entries(), o = [];
95
+ for (; ; ) {
96
+ const { done: c, value: a } = s.next();
97
+ if (c)
98
+ break;
99
+ const [r, l] = a, [p] = r.split("_");
100
+ p === t && o.push(l);
101
+ }
102
+ return o;
103
+ }
104
+ function ie(t) {
105
+ const { kernelName: s, backendName: o } = t, c = I(s, o);
106
+ S.has(c) && y(`The kernel '${s}' for backend '${o}' is already registered`), S.set(c, t);
107
+ }
108
+ function le(t) {
109
+ const { kernelName: s } = t;
110
+ R.has(s) && g().getBool("DEBUG") && y(`Overriding the gradient for '${s}'`), R.set(s, t);
111
+ }
112
+ function I(t, s) {
113
+ return `${s}_${t}`;
114
+ }
115
+ class ue {
116
+ constructor(s, o) {
117
+ this.backendTimer = s, this.logger = o, o == null && (this.logger = new $());
118
+ }
119
+ profileKernel(s, o, c) {
120
+ let a;
121
+ const r = () => {
122
+ a = c();
123
+ };
124
+ let l;
125
+ const p = v();
126
+ if (this.backendTimer.timerAvailable())
127
+ l = this.backendTimer.time(r);
128
+ else {
129
+ r();
130
+ for (const e of a)
131
+ e.dataSync();
132
+ l = Promise.resolve({ kernelMs: v() - p });
133
+ }
134
+ if (g().getBool("CHECK_COMPUTATION_FOR_ERRORS"))
135
+ for (let e = 0; e < a.length; e++) {
136
+ const i = a[e];
137
+ i.data().then((u) => {
138
+ L(u, i.dtype, s);
139
+ });
140
+ }
141
+ return {
142
+ kernelName: s,
143
+ outputs: a,
144
+ inputs: o,
145
+ timeMs: l.then((e) => e.kernelMs),
146
+ extraInfo: l.then((e) => e.getExtraProfileInfo != null ? e.getExtraProfileInfo() : "")
147
+ };
148
+ }
149
+ logKernelProfile(s) {
150
+ const { kernelName: o, outputs: c, timeMs: a, inputs: r, extraInfo: l } = s;
151
+ c.forEach((p) => {
152
+ Promise.all([p.data(), a, l]).then((n) => {
153
+ this.logger.logKernelProfile(o, p, n[0], n[1], r, n[2]);
154
+ });
155
+ });
156
+ }
157
+ }
158
+ function L(t, s, o) {
159
+ if (s !== "float32")
160
+ return !1;
161
+ for (let c = 0; c < t.length; c++) {
162
+ const a = t[c];
163
+ if (isNaN(a) || !isFinite(a))
164
+ return console.warn(`Found ${a} in the result of '${o}'`), !0;
165
+ }
166
+ return !1;
167
+ }
168
+ class $ {
169
+ logKernelProfile(s, o, c, a, r, l) {
170
+ const p = typeof a == "number" ? D(`${a}ms`, 9) : a.error, n = D(s, 25), e = o.rank, i = o.size, u = D(o.shape.toString(), 14);
171
+ let f = "";
172
+ for (const h in r) {
173
+ const m = r[h];
174
+ if (m != null) {
175
+ const b = m.shape || o.shape, P = b.length;
176
+ f += `${h}: ${P}D ${P > 0 ? b : ""} `;
177
+ }
178
+ }
179
+ console.log(`%c${n} %c${p} %c${e}D ${u} %c${i} %c${f} %c${l}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
180
+ }
181
+ }
182
+ function pe(t, s, o) {
183
+ const c = {}, a = {};
184
+ for (let n = 0; n < s.length; n++)
185
+ c[s[n].id] = !0;
186
+ for (let n = 0; n < t.length; n++) {
187
+ const e = t[n], i = e.inputs;
188
+ for (const u in i) {
189
+ const f = i[u];
190
+ let h = !1;
191
+ for (let m = 0; m < s.length; m++)
192
+ if (c[f.id]) {
193
+ e.outputs.forEach((b) => c[b.id] = !0), h = !0, a[e.id] = !0;
194
+ break;
195
+ }
196
+ if (h)
197
+ break;
198
+ }
199
+ }
200
+ const r = {};
201
+ r[o.id] = !0;
202
+ const l = {};
203
+ for (let n = t.length - 1; n >= 0; n--) {
204
+ const e = t[n], i = e.inputs;
205
+ for (let u = 0; u < e.outputs.length; u++)
206
+ if (r[e.outputs[u].id]) {
207
+ for (const f in i)
208
+ r[i[f].id] = !0, l[e.id] = !0;
209
+ break;
210
+ }
211
+ }
212
+ const p = [];
213
+ for (let n = 0; n < t.length; n++) {
214
+ const e = t[n];
215
+ if (a[e.id] && l[e.id]) {
216
+ const i = {};
217
+ for (const f in e.inputs) {
218
+ const h = e.inputs[f];
219
+ c[h.id] && (i[f] = h);
220
+ }
221
+ const u = Object.assign({}, e);
222
+ u.inputs = i, u.outputs = e.outputs, p.push(u);
223
+ }
224
+ }
225
+ return p;
226
+ }
227
+ function de(t, s, o, c) {
228
+ for (let a = s.length - 1; a >= 0; a--) {
229
+ const r = s[a], l = [];
230
+ if (r.outputs.forEach((n) => {
231
+ const e = t[n.id];
232
+ e != null ? l.push(e) : l.push(null);
233
+ }), r.gradient == null)
234
+ throw new Error(`Cannot compute gradient: gradient function not found for ${r.kernelName}.`);
235
+ const p = r.gradient(l);
236
+ for (const n in r.inputs) {
237
+ if (!(n in p))
238
+ throw new Error(`Cannot backprop through input ${n}. Available gradients found: ${Object.keys(p)}.`);
239
+ const e = o(() => p[n]());
240
+ if (e.dtype !== "float32")
241
+ throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input ${n} must have 'float32' dtype, but has '${e.dtype}'`);
242
+ const i = r.inputs[n];
243
+ if (!M(e.shape, i.shape))
244
+ throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input '${n}' has shape '${e.shape}', which does not match the shape of the input '${i.shape}'`);
245
+ if (t[i.id] == null)
246
+ t[i.id] = e;
247
+ else {
248
+ const u = t[i.id];
249
+ t[i.id] = c(u, e), u.dispose();
250
+ }
251
+ }
252
+ }
253
+ }
254
+ var C;
255
+ (function(t) {
256
+ t.R0 = "R0", t.R1 = "R1", t.R2 = "R2", t.R3 = "R3", t.R4 = "R4", t.R5 = "R5", t.R6 = "R6";
257
+ })(C || (C = {}));
258
+ var T;
259
+ (function(t) {
260
+ t.float32 = "float32", t.int32 = "int32", t.bool = "int32", t.complex64 = "complex64";
261
+ })(T || (T = {}));
262
+ var k;
263
+ (function(t) {
264
+ t.float32 = "float32", t.int32 = "int32", t.bool = "bool", t.complex64 = "complex64";
265
+ })(k || (k = {}));
266
+ var N;
267
+ (function(t) {
268
+ t.float32 = "float32", t.int32 = "float32", t.bool = "float32", t.complex64 = "complex64";
269
+ })(N || (N = {}));
270
+ var x;
271
+ (function(t) {
272
+ t.float32 = "complex64", t.int32 = "complex64", t.bool = "complex64", t.complex64 = "complex64";
273
+ })(x || (x = {}));
274
+ const O = {
275
+ float32: N,
276
+ int32: T,
277
+ bool: k,
278
+ complex64: x
279
+ };
280
+ function B(t, s) {
281
+ if (t === "string" || s === "string") {
282
+ if (t === "string" && s === "string")
283
+ return "string";
284
+ throw new Error(`Can not upcast ${t} with ${s}`);
285
+ }
286
+ return O[t][s];
287
+ }
288
+ function fe(t) {
289
+ return B(t, "int32");
290
+ }
291
+ function he(t) {
292
+ return t != null && typeof t == "object" && "texture" in t && t.texture instanceof WebGLTexture;
293
+ }
294
+ function ge(t) {
295
+ return typeof GPUBuffer < "u" && t != null && typeof t == "object" && "buffer" in t && t.buffer instanceof GPUBuffer;
296
+ }
297
+ function me(t, s) {
298
+ if (t.dtype === s.dtype)
299
+ return [t, s];
300
+ const o = B(t.dtype, s.dtype);
301
+ return [t.cast(o), s.cast(o)];
302
+ }
303
+ function be(t, s) {
304
+ return s.some((o) => o.id === t.id);
305
+ }
306
+ function Se(t) {
307
+ const s = [];
308
+ return E(t, s, /* @__PURE__ */ new Set()), s;
309
+ }
310
+ function E(t, s, o) {
311
+ if (t == null)
312
+ return;
313
+ if (t instanceof w) {
314
+ s.push(t);
315
+ return;
316
+ }
317
+ if (!q(t))
318
+ return;
319
+ const c = t;
320
+ for (const a in c) {
321
+ const r = c[a];
322
+ o.has(r) || (o.add(r), E(r, s, o));
323
+ }
324
+ }
325
+ function q(t) {
326
+ return Array.isArray(t) || typeof t == "object";
327
+ }
328
+ export {
329
+ Vt as $,
330
+ j as A,
331
+ it as B,
332
+ Dt as C,
333
+ is as D,
334
+ Ht as E,
335
+ to as F,
336
+ os as G,
337
+ jo as H,
338
+ rs as I,
339
+ z as J,
340
+ K,
341
+ ms as L,
342
+ As as M,
343
+ $s as N,
344
+ be as O,
345
+ Us as P,
346
+ Qt as Q,
347
+ Qs as R,
348
+ Fo as S,
349
+ _o as T,
350
+ ko as U,
351
+ Kt as V,
352
+ ds as W,
353
+ Hs as X,
354
+ io as Y,
355
+ Jo as Z,
356
+ fe as _,
357
+ le as a,
358
+ Bt as a$,
359
+ ne as a0,
360
+ mt as a1,
361
+ se as a2,
362
+ de as a3,
363
+ he as a4,
364
+ ge as a5,
365
+ ts as a6,
366
+ Ls as a7,
367
+ St as a8,
368
+ _ as a9,
369
+ zs as aA,
370
+ Vs as aB,
371
+ ro as aC,
372
+ no as aD,
373
+ Wo as aE,
374
+ pt as aF,
375
+ gt as aG,
376
+ Wt as aH,
377
+ Xt as aI,
378
+ Xs as aJ,
379
+ po as aK,
380
+ Go as aL,
381
+ X as aM,
382
+ Y as aN,
383
+ Z as aO,
384
+ nt as aP,
385
+ rt as aQ,
386
+ Ko as aR,
387
+ lt as aS,
388
+ ss as aT,
389
+ Rt as aU,
390
+ kt as aV,
391
+ Nt as aW,
392
+ Pt as aX,
393
+ Ct as aY,
394
+ Ft as aZ,
395
+ yt as a_,
396
+ Zt as aa,
397
+ Zo as ab,
398
+ js as ac,
399
+ xo as ad,
400
+ Vo as ae,
401
+ Ps as af,
402
+ ut as ag,
403
+ mo as ah,
404
+ zt as ai,
405
+ Es as aj,
406
+ ns as ak,
407
+ as as al,
408
+ fs as am,
409
+ hs as an,
410
+ bs as ao,
411
+ Ss as ap,
412
+ Bs as aq,
413
+ Ms as ar,
414
+ Os as as,
415
+ uo as at,
416
+ wo as au,
417
+ Xo as av,
418
+ It as aw,
419
+ Jt as ax,
420
+ te as ay,
421
+ qs as az,
422
+ eo as b,
423
+ Mo as b$,
424
+ Mt as b0,
425
+ Ut as b1,
426
+ No as b2,
427
+ Ds as b3,
428
+ vs as b4,
429
+ Fs as b5,
430
+ _s as b6,
431
+ Ks as b7,
432
+ Ws as b8,
433
+ vo as b9,
434
+ us as bA,
435
+ ps as bB,
436
+ Ts as bC,
437
+ Ns as bD,
438
+ ks as bE,
439
+ ys as bF,
440
+ Cs as bG,
441
+ ws as bH,
442
+ co as bI,
443
+ ao as bJ,
444
+ To as bK,
445
+ Ao as bL,
446
+ zo as bM,
447
+ ft as bN,
448
+ Et as bO,
449
+ Gt as bP,
450
+ qt as bQ,
451
+ Yt as bR,
452
+ Qo as bS,
453
+ ee as bT,
454
+ cs as bU,
455
+ gs as bV,
456
+ Rs as bW,
457
+ Is as bX,
458
+ go as bY,
459
+ Bo as bZ,
460
+ Eo as b_,
461
+ lo as ba,
462
+ bo as bb,
463
+ Ro as bc,
464
+ Yo as bd,
465
+ Tt as be,
466
+ oe as bf,
467
+ wt as bg,
468
+ At as bh,
469
+ U as bi,
470
+ W as bj,
471
+ H as bk,
472
+ J as bl,
473
+ Q as bm,
474
+ tt as bn,
475
+ et as bo,
476
+ st as bp,
477
+ ot as bq,
478
+ ct as br,
479
+ at as bs,
480
+ dt as bt,
481
+ xt as bu,
482
+ Lt as bv,
483
+ Ot as bw,
484
+ $t as bx,
485
+ _t as by,
486
+ ls as bz,
487
+ Co as c,
488
+ Lo as c0,
489
+ $o as c1,
490
+ ho as c2,
491
+ Uo as c3,
492
+ Ho as c4,
493
+ Ys as c5,
494
+ Zs as c6,
495
+ Js as c7,
496
+ yo as c8,
497
+ Io as c9,
498
+ Oo as ca,
499
+ qo as cb,
500
+ so as d,
501
+ oo as e,
502
+ So as f,
503
+ Po as g,
504
+ bt as h,
505
+ Gs as i,
506
+ fo as j,
507
+ es as k,
508
+ vt as l,
509
+ me as m,
510
+ Do as n,
511
+ ue as o,
512
+ ce as p,
513
+ ae as q,
514
+ ie as r,
515
+ re as s,
516
+ Se as t,
517
+ B as u,
518
+ pe as v,
519
+ y as w,
520
+ ht as x,
521
+ xs as y,
522
+ jt as z
523
+ };