@genai-fi/nanogpt 0.19.1 → 0.20.1

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 (347) hide show
  1. package/dist/BaseTokeniser-DSg9zcYq.js +221 -0
  2. package/dist/DatasetBuilder-DgURD85T.js +712 -0
  3. package/dist/Generator.js +2 -11941
  4. package/dist/RealDiv-DBu0FQqT.js +362 -0
  5. package/dist/Reshape-CABOPB9d.js +94 -0
  6. package/dist/Reshape-DqO3r8BC.js +17 -0
  7. package/dist/TeachableLLM.d.ts +5 -5
  8. package/dist/TeachableLLM.js +2 -273
  9. package/dist/Trainer.js +2 -244
  10. package/dist/backend.js +12 -12
  11. package/dist/backend_util-Cg-roD1p.js +399 -0
  12. package/dist/binary_op_util-CrYk9LXL.js +103 -0
  13. package/dist/checks/appendCache.js +54 -21
  14. package/dist/checks/attentionMask.js +55 -36
  15. package/dist/checks/check.js +31 -19
  16. package/dist/checks/gelu.js +45 -17
  17. package/dist/checks/index.js +25 -25
  18. package/dist/checks/matMulGelu.js +83 -27
  19. package/dist/checks/normRMS.js +27 -15
  20. package/dist/checks/normRMSGrad.js +21 -11
  21. package/dist/checks/packUnpack.js +45 -17
  22. package/dist/checks/qkv.js +33 -33
  23. package/dist/checks/rope.js +29 -35
  24. package/dist/checks/weights.d.ts +1 -1
  25. package/dist/checks/weights.js +25 -29
  26. package/dist/chunk-BPntVaq0.js +23 -0
  27. package/dist/complex_util-CkazZsaH.js +60 -0
  28. package/dist/concat_util-CWDZCBlA.js +19 -0
  29. package/dist/data/docx.js +3044 -13
  30. package/dist/data/pdf.js +16 -13
  31. package/dist/data/textLoader.js +607 -112
  32. package/dist/dist-BewPQWjc.js +7572 -0
  33. package/dist/dist-DVmq73nz.js +8775 -0
  34. package/dist/dist-DXwIvKxl.js +896 -0
  35. package/dist/dist-VEU5mfO0.js +7545 -0
  36. package/dist/gelu-Bf1HW1RY.js +27 -0
  37. package/dist/gpgpu_math-DvLcCH6u.js +1612 -0
  38. package/dist/inference/types.js +0 -1
  39. package/dist/kernel_funcs_utils-HiXOOx3f.js +229 -0
  40. package/dist/layers/BaseLayer.d.ts +2 -2
  41. package/dist/layers/BaseLayer.js +75 -73
  42. package/dist/layers/CausalSelfAttention.d.ts +1 -1
  43. package/dist/layers/CausalSelfAttention.js +98 -85
  44. package/dist/layers/LoRA.js +47 -57
  45. package/dist/layers/MLP.d.ts +1 -1
  46. package/dist/layers/MLP.js +33 -43
  47. package/dist/layers/PositionEmbedding.d.ts +1 -1
  48. package/dist/layers/PositionEmbedding.js +26 -30
  49. package/dist/layers/RMSNorm.d.ts +1 -1
  50. package/dist/layers/RMSNorm.js +19 -21
  51. package/dist/layers/RoPECache.js +336 -49
  52. package/dist/layers/TiedEmbedding.d.ts +1 -1
  53. package/dist/layers/TiedEmbedding.js +30 -34
  54. package/dist/layers/TransformerBlock.d.ts +1 -1
  55. package/dist/layers/TransformerBlock.js +50 -39
  56. package/dist/layers/WeightStore.js +68 -75
  57. package/dist/loader/load.js +2 -68
  58. package/dist/loader/loadHF.d.ts +2 -2
  59. package/dist/loader/loadHF.js +2 -22
  60. package/dist/loader/loadTransformers.d.ts +1 -1
  61. package/dist/loader/loadTransformers.js +2 -44
  62. package/dist/loader/loadZipMeta.js +15 -15
  63. package/dist/loader/newZipLoad.js +2 -31
  64. package/dist/loader/oldZipLoad.d.ts +2 -2
  65. package/dist/loader/oldZipLoad.js +2 -80
  66. package/dist/loader/save.d.ts +5 -5
  67. package/dist/loader/save.js +2 -90
  68. package/dist/loader/types.d.ts +9 -8
  69. package/dist/loader/types.js +0 -1
  70. package/dist/main-CPjeMv0G.js +13500 -0
  71. package/dist/main.d.ts +1 -1
  72. package/dist/main.js +16 -109
  73. package/dist/matMul16-BNfZSnNM.js +81 -0
  74. package/dist/matMulGelu-CPTntosE.js +162 -0
  75. package/dist/models/NanoGPTV1.js +2 -99
  76. package/dist/models/NanoGPTV2.js +2 -90
  77. package/dist/models/config.js +34 -47
  78. package/dist/models/factory.d.ts +1 -1
  79. package/dist/models/factory.js +2 -16
  80. package/dist/models/model.d.ts +2 -2
  81. package/dist/models/model.js +2 -134
  82. package/dist/ops/adamAdjust.js +15 -6
  83. package/dist/ops/adamMoments.js +13 -6
  84. package/dist/ops/add16.js +9 -6
  85. package/dist/ops/appendCache.js +22 -19
  86. package/dist/ops/attentionMask.js +12 -6
  87. package/dist/ops/concat16.js +7 -8
  88. package/dist/ops/cpu/adamAdjust.js +15 -17
  89. package/dist/ops/cpu/adamMoments.js +15 -15
  90. package/dist/ops/cpu/appendCache.js +64 -22
  91. package/dist/ops/cpu/attentionMask.js +15 -21
  92. package/dist/ops/cpu/fusedSoftmax.js +21 -28
  93. package/dist/ops/cpu/gatherSub.js +11 -17
  94. package/dist/ops/cpu/gelu.js +34 -38
  95. package/dist/ops/cpu/matMul16.js +13 -14
  96. package/dist/ops/cpu/matMulGelu.js +39 -51
  97. package/dist/ops/cpu/matMulMul.js +19 -22
  98. package/dist/ops/cpu/mulDropout.js +19 -22
  99. package/dist/ops/cpu/normRMS.js +33 -37
  100. package/dist/ops/cpu/qkv.js +72 -40
  101. package/dist/ops/cpu/rope.js +79 -36
  102. package/dist/ops/cpu/scatterSub.js +11 -22
  103. package/dist/ops/dot16.js +28 -41
  104. package/dist/ops/dropout.js +10 -13
  105. package/dist/ops/dropout16.js +20 -23
  106. package/dist/ops/gatherSub.js +10 -6
  107. package/dist/ops/gelu.js +2 -8
  108. package/dist/ops/globalNorm.js +18 -12
  109. package/dist/ops/grads/add16.js +27 -26
  110. package/dist/ops/grads/attentionMask.js +26 -21
  111. package/dist/ops/grads/dropout16.js +0 -1
  112. package/dist/ops/grads/gelu.js +2 -5
  113. package/dist/ops/grads/matMul16.js +2 -9
  114. package/dist/ops/grads/matMulGelu.js +21 -16
  115. package/dist/ops/grads/mul16.js +0 -3
  116. package/dist/ops/grads/normRMS.js +34 -30
  117. package/dist/ops/grads/pack16.js +2 -6
  118. package/dist/ops/grads/qkv.js +44 -32
  119. package/dist/ops/grads/rope.js +2 -5
  120. package/dist/ops/grads/softmax16.js +21 -23
  121. package/dist/ops/grads/unpack16.js +2 -5
  122. package/dist/ops/grads/utils.js +9 -11
  123. package/dist/ops/matMul16.js +2 -13
  124. package/dist/ops/matMulGelu.js +16 -10
  125. package/dist/ops/matMulMul.js +13 -6
  126. package/dist/ops/mul16.js +42 -38
  127. package/dist/ops/mulDrop.js +12 -6
  128. package/dist/ops/normRMS.js +18 -15
  129. package/dist/ops/pack16.js +2 -5
  130. package/dist/ops/qkv.js +12 -6
  131. package/dist/ops/reshape16.js +31 -39
  132. package/dist/ops/rope.d.ts +1 -1
  133. package/dist/ops/rope.js +2 -7
  134. package/dist/ops/scatterSub.js +10 -6
  135. package/dist/ops/slice16.js +9 -7
  136. package/dist/ops/softmax16.js +7 -7
  137. package/dist/ops/sub16.js +9 -6
  138. package/dist/ops/sum16.js +12 -12
  139. package/dist/ops/transpose16.js +29 -37
  140. package/dist/ops/unpack16.js +2 -6
  141. package/dist/ops/webgl/adamAdjust.js +62 -29
  142. package/dist/ops/webgl/adamMoments.js +30 -26
  143. package/dist/ops/webgl/appendCache.js +30 -21
  144. package/dist/ops/webgl/attentionMask.js +43 -24
  145. package/dist/ops/webgl/dropout16.js +11 -10
  146. package/dist/ops/webgl/fusedSoftmax.js +69 -79
  147. package/dist/ops/webgl/gatherSub.js +27 -26
  148. package/dist/ops/webgl/gelu.js +32 -34
  149. package/dist/ops/webgl/log.js +14 -23
  150. package/dist/ops/webgl/matMul16.js +36 -44
  151. package/dist/ops/webgl/matMulGelu.js +2 -9
  152. package/dist/ops/webgl/matMulMul.js +23 -27
  153. package/dist/ops/webgl/mulDropout.js +31 -40
  154. package/dist/ops/webgl/normRMS.js +92 -71
  155. package/dist/ops/webgl/qkv.js +35 -27
  156. package/dist/ops/webgl/rope.js +37 -21
  157. package/dist/ops/webgl/scatterSub.js +27 -26
  158. package/dist/ops/webgpu/adamAdjust.js +59 -39
  159. package/dist/ops/webgpu/adamMoments.js +62 -46
  160. package/dist/ops/webgpu/add16.js +13 -12
  161. package/dist/ops/webgpu/appendCache.js +79 -54
  162. package/dist/ops/webgpu/attentionMask.js +41 -25
  163. package/dist/ops/webgpu/attentionMask32_program.js +34 -26
  164. package/dist/ops/webgpu/clipScale.js +44 -57
  165. package/dist/ops/webgpu/concat16.js +96 -111
  166. package/dist/ops/webgpu/dropout16.js +40 -32
  167. package/dist/ops/webgpu/gatherSub.js +43 -30
  168. package/dist/ops/webgpu/gelu.js +88 -82
  169. package/dist/ops/webgpu/index.js +16 -16
  170. package/dist/ops/webgpu/matMul16.js +69 -64
  171. package/dist/ops/webgpu/matMul16_program.js +152 -192
  172. package/dist/ops/webgpu/mul16.js +13 -12
  173. package/dist/ops/webgpu/norm2.js +45 -75
  174. package/dist/ops/webgpu/normRMS.js +25 -33
  175. package/dist/ops/webgpu/normRMS16_program.js +21 -18
  176. package/dist/ops/webgpu/normRMS32_program.js +21 -18
  177. package/dist/ops/webgpu/normRMSGrad.js +125 -184
  178. package/dist/ops/webgpu/pack16.js +20 -17
  179. package/dist/ops/webgpu/pack16_program.js +48 -47
  180. package/dist/ops/webgpu/qkv.js +63 -23
  181. package/dist/ops/webgpu/rope.js +85 -57
  182. package/dist/ops/webgpu/scatterSub.js +43 -30
  183. package/dist/ops/webgpu/slice16.js +66 -61
  184. package/dist/ops/webgpu/softmax16.js +17 -20
  185. package/dist/ops/webgpu/softmax16_program.js +34 -18
  186. package/dist/ops/webgpu/softmax16_subgroup_program.js +40 -45
  187. package/dist/ops/webgpu/softmax16grad.js +30 -36
  188. package/dist/ops/webgpu/sub16.js +13 -12
  189. package/dist/ops/webgpu/sum16.js +28 -37
  190. package/dist/ops/webgpu/transpose16.js +36 -33
  191. package/dist/ops/webgpu/transpose16_program.js +40 -39
  192. package/dist/ops/webgpu/transpose16_shared_program.js +53 -44
  193. package/dist/ops/webgpu/unpack16.js +49 -37
  194. package/dist/ops/webgpu/utils/binary_op.js +70 -68
  195. package/dist/ops/webgpu/utils/deviceInfo.d.ts +1 -1
  196. package/dist/ops/webgpu/utils/deviceInfo.js +10 -10
  197. package/dist/ops/webgpu/utils/reductions.js +136 -148
  198. package/dist/pack16-Ck-spx_F.js +39 -0
  199. package/dist/patches/webgpu_backend.d.ts +2 -2
  200. package/dist/patches/webgpu_backend.js +42 -55
  201. package/dist/patches/webgpu_base.js +21 -33
  202. package/dist/patches/webgpu_program.js +213 -320
  203. package/dist/pdf-UoDqCYzz.js +16726 -0
  204. package/dist/picomatch-3tUnMMbd.js +1063 -0
  205. package/dist/rope-CbeGlsV8.js +25 -0
  206. package/dist/selu_util-zkAx5doH.js +24 -0
  207. package/dist/shared-D1coEFea.js +1314 -0
  208. package/dist/shared-DOgWaqvL.js +5 -0
  209. package/dist/slice_util-Dgb3ANWI.js +208 -0
  210. package/dist/tfjs_backend-BjuQ5FqB.js +614 -0
  211. package/dist/tokeniser/BaseTokeniser.js +2 -124
  212. package/dist/tokeniser/CharTokeniser.js +91 -106
  213. package/dist/tokeniser/bpe.js +163 -166
  214. package/dist/tokeniser/messages.js +0 -1
  215. package/dist/tokeniser/type.js +0 -1
  216. package/dist/training/AdamW.js +127 -137
  217. package/dist/training/BasicTrainer.d.ts +1 -1
  218. package/dist/training/BasicTrainer.js +264 -264
  219. package/dist/training/DatasetBuilder.js +2 -86
  220. package/dist/training/Evaluator.d.ts +1 -1
  221. package/dist/training/Evaluator.js +47 -38
  222. package/dist/training/LRScheduler.js +37 -33
  223. package/dist/training/PreTrainer.d.ts +2 -2
  224. package/dist/training/PreTrainer.js +21 -19
  225. package/dist/training/SFTTrainer.d.ts +2 -2
  226. package/dist/training/SFTTrainer.js +23 -21
  227. package/dist/training/loss.js +17 -22
  228. package/dist/training/orthoGrad.js +9 -9
  229. package/dist/training/sparseCrossEntropy.js +45 -67
  230. package/dist/training/tasks/ConversationTask.d.ts +1 -1
  231. package/dist/training/tasks/ConversationTask.js +36 -38
  232. package/dist/training/tasks/PretrainingTask.d.ts +1 -1
  233. package/dist/training/tasks/PretrainingTask.js +41 -46
  234. package/dist/training/tasks/StartSentenceTask.d.ts +1 -1
  235. package/dist/training/tasks/StartSentenceTask.js +44 -48
  236. package/dist/training/tasks/Task.d.ts +1 -1
  237. package/dist/training/tasks/Task.js +53 -66
  238. package/dist/training/tasks/splitter.js +17 -20
  239. package/dist/training/types.d.ts +2 -2
  240. package/dist/training/types.js +0 -1
  241. package/dist/training/validation.d.ts +1 -1
  242. package/dist/training/validation.js +2 -84
  243. package/dist/utilities/arrayClose.js +15 -19
  244. package/dist/utilities/datasetID.js +17 -20
  245. package/dist/utilities/dummy.d.ts +1 -1
  246. package/dist/utilities/dummy.js +33 -40
  247. package/dist/utilities/multinomialCPU.js +8 -12
  248. package/dist/utilities/naming.js +0 -1
  249. package/dist/utilities/packed.js +10 -12
  250. package/dist/utilities/parameters.d.ts +1 -1
  251. package/dist/utilities/parameters.js +32 -51
  252. package/dist/utilities/performance.js +15 -15
  253. package/dist/utilities/profile.js +32 -37
  254. package/dist/utilities/safetensors.js +49 -79
  255. package/dist/utilities/sentences.d.ts +1 -1
  256. package/dist/utilities/sentences.js +29 -38
  257. package/dist/utilities/tokenParse.js +16 -20
  258. package/dist/utilities/topP.js +11 -12
  259. package/dist/utilities/waitForModel.d.ts +1 -1
  260. package/dist/utilities/waitForModel.js +11 -11
  261. package/dist/utilities/weights.js +37 -42
  262. package/dist/utilities/yielder.js +6 -6
  263. package/dist/webgpu-Dt7BMzWz.js +525 -0
  264. package/dist/webgpu_program-WOyIVMlZ.js +392 -0
  265. package/dist/webgpu_util-B_F3SShA.js +106 -0
  266. package/package.json +9 -10
  267. package/dist/RealDiv-CGwv0liw.js +0 -365
  268. package/dist/Reshape-BW__R4mZ.js +0 -79
  269. package/dist/Reshape-CPBkTIH2.js +0 -14
  270. package/dist/_commonjsHelpers-ByX85dGu.js +0 -33
  271. package/dist/axis_util-GTVlo58H.js +0 -55
  272. package/dist/backend_util-GaFarB78.js +0 -425
  273. package/dist/backend_webgpu-BqASlsbV.js +0 -545
  274. package/dist/binary_op_util-pKXltfxI.js +0 -192
  275. package/dist/broadcast_to-eS93CCN_.js +0 -28
  276. package/dist/clip_by_value-DDA7rrcT.js +0 -12
  277. package/dist/complex-DI35Q-gW.js +0 -11
  278. package/dist/complex_util-Yc1A_gV1.js +0 -55
  279. package/dist/concat-CAQpCret.js +0 -17
  280. package/dist/concat_util-D18dJ4fD.js +0 -22
  281. package/dist/data/parquet.d.ts +0 -2
  282. package/dist/data/parquet.js +0 -17
  283. package/dist/dataset-CGGp1z9P.js +0 -1124
  284. package/dist/dropout_util--NxWuYg2.js +0 -27
  285. package/dist/expand_dims-Bkd1YD5x.js +0 -11
  286. package/dist/exports_initializers-CYzKLjN7.js +0 -7
  287. package/dist/floor-BQtb-Azg.js +0 -9
  288. package/dist/gather-qIqEqaGn.js +0 -9
  289. package/dist/gelu-B220X1Go.js +0 -26
  290. package/dist/gpgpu_math-BwvV12df.js +0 -2022
  291. package/dist/index-CUXkjxiT.js +0 -3516
  292. package/dist/index-CieiGp4Y.js +0 -349
  293. package/dist/index-CjOWnMXP.js +0 -7308
  294. package/dist/index-Cp39cXWe.js +0 -1016
  295. package/dist/index-D5v913EJ.js +0 -4
  296. package/dist/index-DmeWGGmS.js +0 -1074
  297. package/dist/index-DvYrXKkX.js +0 -113
  298. package/dist/index-Ksja3su6.js +0 -151
  299. package/dist/index-xuotMAFm.js +0 -118
  300. package/dist/jszip.min-BZhlzntC.js +0 -2313
  301. package/dist/kernel_funcs_utils-pq0CK9co.js +0 -306
  302. package/dist/matMul16-BcVC_E62.js +0 -80
  303. package/dist/matMulGelu-JNLZqKQp.js +0 -163
  304. package/dist/mat_mul-DhG0Newp.js +0 -11
  305. package/dist/mod-CSdCpRjf.js +0 -11
  306. package/dist/non_max_suppression_impl-B2W7YjZB.js +0 -102
  307. package/dist/not_equal-hurPF26l.js +0 -64
  308. package/dist/ones-BytntneX.js +0 -14
  309. package/dist/ops-CsXeTq1P.js +0 -476
  310. package/dist/pack16-bqltoUlR.js +0 -39
  311. package/dist/papaparse.min-C0cScC2i.js +0 -418
  312. package/dist/parquet-Bqjmp2vo.js +0 -44231
  313. package/dist/pdf-NIhmP3sq.js +0 -19477
  314. package/dist/rand_util-CZ7yLoUm.js +0 -50
  315. package/dist/random_normal-IBRrha8a.js +0 -14
  316. package/dist/random_width-DN5ZtQkM.js +0 -9796
  317. package/dist/range-C-CjF-LI.js +0 -10
  318. package/dist/relu-J_X6MUzx.js +0 -9
  319. package/dist/reshape-BDOuCSNW.js +0 -9
  320. package/dist/resize_nearest_neighbor-BojqlfRe.js +0 -150
  321. package/dist/rope-DcrZM_e6.js +0 -24
  322. package/dist/scatter_nd_util-ByNJaL6I.js +0 -46
  323. package/dist/segment_util-Dasb2Zaf.js +0 -43
  324. package/dist/selu_util-BLhIqRkw.js +0 -44
  325. package/dist/shared-3agzAqQ_.js +0 -53
  326. package/dist/shared-CagdqkLh.js +0 -2143
  327. package/dist/slice-BzS11Qh0.js +0 -12
  328. package/dist/slice_util-CC35pLmT.js +0 -153
  329. package/dist/softmax-D4q1LJN7.js +0 -12
  330. package/dist/split-C2Sj255c.js +0 -9
  331. package/dist/squeeze-ho4wLUek.js +0 -10
  332. package/dist/stack-DudVrtmG.js +0 -11
  333. package/dist/step-BTxPtq1r.js +0 -261
  334. package/dist/sum-BpiwSWvg.js +0 -11
  335. package/dist/tensor-BWFldCso.js +0 -8
  336. package/dist/tensor1d-LMGMIUlr.js +0 -11
  337. package/dist/tensor2d-BnXMKScO.js +0 -14
  338. package/dist/tensor4d-C6UCG_u8.js +0 -14
  339. package/dist/tfjs_backend-BGnG-ppu.js +0 -654
  340. package/dist/tile-CFy-xTO6.js +0 -11
  341. package/dist/transpose-9kRxIXWR.js +0 -36
  342. package/dist/unsorted_segment_sum-DJvk5xnh.js +0 -277
  343. package/dist/variable-Ck482e3n.js +0 -7
  344. package/dist/webgpu_program-B4HmApL1.js +0 -525
  345. package/dist/webgpu_util-DYlGSwOJ.js +0 -64
  346. package/dist/zeros-DvZpK8s6.js +0 -13
  347. package/dist/zeros_like-CWjDdwr-.js +0 -721
@@ -1,365 +0,0 @@
1
- import { aE as E, ab as T, ah as O, U as V, aW as B, N as F, aM as U, aX as W } from "./index-CUXkjxiT.js";
2
- import { r as $ } from "./Reshape-BW__R4mZ.js";
3
- import { a as A, b as k, d as C, c as N, e as R } from "./axis_util-GTVlo58H.js";
4
- import { t as K, m as _ } from "./shared-3agzAqQ_.js";
5
- import { c as j } from "./backend_util-GaFarB78.js";
6
- import { f as y } from "./gpgpu_math-BwvV12df.js";
7
- import { g as G, b as L } from "./kernel_funcs_utils-pq0CK9co.js";
8
- class w {
9
- constructor(s, e) {
10
- this.variableNames = ["x"];
11
- const { windowSize: t, batchSize: n, inSize: l, outSize: r } = s;
12
- this.outputShape = [n, r];
13
- const i = Math.floor(t / 4) * 4, c = t % 4;
14
- let o = "sumValue += dot(values, ones);";
15
- if (e != null) {
16
- const p = 1 / e;
17
- o = `sumValue += dot(values * ${E(p) ? p.toPrecision(2) : p}, ones);`;
18
- }
19
- let u = "";
20
- l % t > 0 && (u = `
21
- if (inIdx < 0 || inIdx >= ${l}) {
22
- return 0.0;
23
- }
24
- `), this.userCode = `
25
- const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
26
-
27
- float getValue(int batch, int inIdx) {
28
- ${u}
29
- return getX(batch, inIdx);
30
- }
31
-
32
- void main() {
33
- ivec2 coords = getOutputCoords();
34
- int batch = coords[0];
35
- int outIdx = coords[1];
36
- int inOffset = outIdx * ${t};
37
-
38
- float sumValue = 0.0;
39
-
40
- for (int i = 0; i < ${i}; i += 4) {
41
- int inIdx = inOffset + i;
42
- vec4 values = vec4(
43
- getValue(batch, inIdx),
44
- getValue(batch, inIdx + 1),
45
- getValue(batch, inIdx + 2),
46
- getValue(batch, inIdx + 3)
47
- );
48
-
49
- ${o}
50
- }
51
-
52
- int inIdx = inOffset + ${i};
53
- if (${c === 1}) {
54
- vec4 values = vec4(getValue(batch, inIdx), 0.0, 0.0, 0.0);
55
-
56
- ${o}
57
- } else if (${c === 2}) {
58
- vec4 values = vec4(
59
- getValue(batch, inIdx),
60
- getValue(batch, inIdx + 1), 0.0, 0.0);
61
-
62
- ${o}
63
- } else if (${c === 3}) {
64
- vec4 values = vec4(
65
- getValue(batch, inIdx),
66
- getValue(batch, inIdx + 1),
67
- getValue(batch, inIdx + 2), 0.0);
68
-
69
- ${o}
70
- }
71
- setOutput(sumValue);
72
- }
73
- `;
74
- }
75
- }
76
- class X {
77
- constructor(s, e) {
78
- this.variableNames = ["x"];
79
- const { windowSize: t, batchSize: n, inSize: l, outSize: r } = s;
80
- this.outputShape = [n, r];
81
- let i = "0.0", c = "";
82
- e === "prod" ? i = "1.0" : e === "min" ? (i = "1.0 / 1e-20", c = "min") : e === "max" && (i = "-1.0 / 1e-20", c = "max");
83
- let o = `${e}(${e}(${e}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`;
84
- e === "sum" ? o = "sumValue" : e === "prod" ? o = "prodValue" : e === "all" ? o = "allValue" : e === "any" && (o = "anyValue");
85
- const u = Math.floor(t / 4) * 4, p = t % 4;
86
- let h = `
87
- if (${e === "sum"}) {
88
- sumValue += dot(values, ones);
89
- } else if (${e === "prod"}) {
90
- vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);
91
- prodValue *= tmp[0] * tmp[1];
92
- } else {
93
- minMaxValue = ${c}(values, minMaxValue);
94
- if (${e === "min"} || ${e === "max"}) {
95
- minMaxValue = ${c}(values, minMaxValue);
96
- bvec4 isNaN = isnan(values);
97
- if (isNaN.r || isNaN.g || isNaN.b || isNaN.a) {
98
- minMaxValue = vec4(NAN);
99
- }
100
- }
101
- }
102
- `, d = "vec4";
103
- e === "all" ? (i = "1.0", h = `
104
- bool reducedAllValue = all(values);
105
- float floatedReducedAllValue = float(reducedAllValue);
106
- allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);
107
- `, d = "bvec4") : e === "any" && (i = "0.0", h = `
108
- bool reducedAnyValue = any(values);
109
- float floatedReducedAnyValue = float(reducedAnyValue);
110
- anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);
111
- `, d = "bvec4");
112
- let f = "";
113
- l % t > 0 && (f = `
114
- if (inIdx < 0 || inIdx >= ${l}) {
115
- return initializationValue;
116
- }
117
- `), this.userCode = `
118
- const float initializationValue = ${i};
119
- const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
120
-
121
- float getValue(int batch, int inIdx) {
122
- ${f}
123
- return getX(batch, inIdx);
124
- }
125
-
126
- void main() {
127
- ivec2 coords = getOutputCoords();
128
- int batch = coords[0];
129
- int outIdx = coords[1];
130
- int inOffset = outIdx * ${t};
131
-
132
- vec4 minMaxValue = vec4(${i});
133
- float prodValue = 1.0;
134
- float sumValue = 0.0;
135
- float allValue = 1.0;
136
- float anyValue = 0.0;
137
-
138
- for (int i = 0; i < ${u}; i += 4) {
139
- int inIdx = inOffset + i;
140
- ${d} values = ${d}(
141
- getValue(batch, inIdx),
142
- getValue(batch, inIdx + 1),
143
- getValue(batch, inIdx + 2),
144
- getValue(batch, inIdx + 3)
145
- );
146
-
147
- ${h}
148
- }
149
-
150
- int inIdx = inOffset + ${u};
151
- if (${p === 1}) {
152
- ${d} values = ${d}(
153
- getValue(batch, inIdx),
154
- initializationValue,
155
- initializationValue,
156
- initializationValue
157
- );
158
-
159
- ${h}
160
- } else if (${p === 2}) {
161
- ${d} values = ${d}(
162
- getValue(batch, inIdx),
163
- getValue(batch, inIdx + 1),
164
- initializationValue,
165
- initializationValue
166
- );
167
-
168
- ${h}
169
- } else if (${p === 3}) {
170
- ${d} values = ${d}(
171
- getValue(batch, inIdx),
172
- getValue(batch, inIdx + 1),
173
- getValue(batch, inIdx + 2),
174
- initializationValue
175
- );
176
-
177
- ${h}
178
- }
179
- setOutput(${o});
180
- }
181
- `;
182
- }
183
- }
184
- function q(a) {
185
- const s = [];
186
- for (; s.length === 0 || s[s.length - 1].outSize !== 1; ) {
187
- const e = s.length ? s[s.length - 1].outSize : a[1], t = j(e);
188
- s.push({
189
- inSize: e,
190
- windowSize: t,
191
- outSize: Math.ceil(e / t)
192
- });
193
- }
194
- return s;
195
- }
196
- function M(a, s, e, t) {
197
- const n = q(a.shape);
198
- let l = a;
199
- for (let r = 0; r < n.length; r++) {
200
- const { inSize: i, windowSize: c, outSize: o } = n[r];
201
- let u, p;
202
- e === "mean" ? u = r === 0 ? new w({ windowSize: c, inSize: i, batchSize: a.shape[0], outSize: o }, i) : new w({ windowSize: c, inSize: i, batchSize: a.shape[0], outSize: o }) : u = new X({ windowSize: c, inSize: i, batchSize: a.shape[0], outSize: o }, e), p = l, l = t.runWebGLProgram(u, [l], s), p.dataId !== a.dataId && t.disposeIntermediateTensorInfo(p);
203
- }
204
- return l;
205
- }
206
- class Y {
207
- constructor(s, e) {
208
- this.variableNames = ["A"];
209
- const t = new Array(s.length);
210
- for (let r = 0; r < t.length; r++)
211
- t[r] = s[e[r]];
212
- this.outputShape = t, this.rank = t.length;
213
- const n = y(this.rank), l = H(e);
214
- this.userCode = `
215
- void main() {
216
- ${n} resRC = getOutputCoords();
217
- setOutput(getA(${l}));
218
- }
219
- `;
220
- }
221
- }
222
- function H(a) {
223
- const s = a.length;
224
- if (s > 6)
225
- throw Error(`Transpose for rank ${s} is not yet supported`);
226
- const e = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u", "resRC.v"], t = new Array(s);
227
- for (let n = 0; n < a.length; n++)
228
- t[a[n]] = e[n];
229
- return t.join();
230
- }
231
- class J {
232
- constructor(s, e) {
233
- this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0;
234
- const t = new Array(s.length);
235
- for (let u = 0; u < t.length; u++)
236
- t[u] = s[e[u]];
237
- if (this.outputShape = t, this.rank = t.length, this.rank > 6)
238
- throw Error(`Packed transpose for rank ${this.rank} is not yet supported.`);
239
- const n = y(this.rank), l = G("rc", this.rank), r = new Array(this.rank);
240
- for (let u = 0; u < e.length; u++)
241
- r[e[u]] = l[u];
242
- const i = `vec2(${r.slice(-2).join()})`, c = `++${l[this.rank - 1]} < ${t[this.rank - 1]}`, o = `getChannel(getA(${r.join()}), ${i})`;
243
- this.userCode = `
244
- void main() {
245
- ${n} rc = getOutputCoords();
246
- vec4 result = vec4(0.);
247
- result[0] = ${o};
248
- if(${c}) {
249
- result[1] = ${o};
250
- }
251
- --${l[this.rank - 1]};
252
- if(++${l[this.rank - 2]} < ${t[this.rank - 2]}) {
253
- result[2] = ${o};
254
- if(${c}) {
255
- result[3] = ${o};
256
- }
257
- }
258
- setOutput(result);
259
- }
260
- `;
261
- }
262
- }
263
- function P(a, s, e) {
264
- const t = T().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new J(a.shape, s) : new Y(a.shape, s);
265
- return e.runWebGLProgram(t, [a], a.dtype);
266
- }
267
- function Q(a, s, e, t) {
268
- const n = s, l = a.shape.length, r = O(n, a.shape);
269
- let i = r;
270
- const c = A(i, l), o = c != null;
271
- let u = a;
272
- o && (u = P(a, c, t), i = k(i.length, l)), C("sum", i, l);
273
- const [p, h] = N(u.shape, i);
274
- let d = p;
275
- e && (d = R(p, r));
276
- const f = V(h), g = V(a.shape) / f, x = $({ inputs: { x: u }, attrs: { shape: [g, f] }, backend: t }), S = B(a.dtype), I = M(x, S, "sum", t), m = $({ inputs: { x: I }, attrs: { shape: d }, backend: t });
277
- return t.disposeIntermediateTensorInfo(x), t.disposeIntermediateTensorInfo(I), o && t.disposeIntermediateTensorInfo(u), m;
278
- }
279
- function Z(a) {
280
- const { inputs: s, backend: e, attrs: t } = a, { x: n } = s, { axis: l, keepDims: r } = t;
281
- return Q(n, l, r, e);
282
- }
283
- const pe = {
284
- kernelName: F,
285
- backendName: "webgl",
286
- kernelFunc: Z
287
- };
288
- function ee(a, s, e, t) {
289
- const n = V(s), r = V(a.shape) / n, i = $({ inputs: { x: a }, attrs: { shape: [r, n] }, backend: t }), c = M(i, a.dtype, "max", t), o = $({ inputs: { x: c }, attrs: { shape: e }, backend: t });
290
- return t.disposeIntermediateTensorInfo(i), t.disposeIntermediateTensorInfo(c), o;
291
- }
292
- function te(a) {
293
- const { inputs: s, backend: e, attrs: t } = a, { x: n } = s, { reductionIndices: l, keepDims: r } = t, i = n.shape.length, c = O(l, n.shape);
294
- let o = c;
295
- const u = A(o, i), p = u != null, h = e.shouldExecuteOnCPU([n]);
296
- let d = n;
297
- if (p) {
298
- if (h) {
299
- const I = e.texData.get(d.dataId).values, m = new Array(i);
300
- for (let v = 0; v < m.length; v++)
301
- m[v] = n.shape[u[v]];
302
- const z = K(I, n.shape, n.dtype, u, m);
303
- d = e.makeTensorInfo(m, n.dtype);
304
- const D = e.texData.get(d.dataId);
305
- D.values = z;
306
- } else
307
- d = P(n, u, e);
308
- o = k(o.length, i);
309
- }
310
- C("max", o, i);
311
- const [f, b] = N(d.shape, o);
312
- let g = f;
313
- r && (g = R(f, c));
314
- let x;
315
- if (h) {
316
- const I = e.texData.get(d.dataId).values, m = _(I, V(b), g, n.dtype);
317
- x = e.makeTensorInfo(g, n.dtype);
318
- const z = e.texData.get(x.dataId);
319
- z.values = m;
320
- } else
321
- x = ee(d, b, g, e);
322
- return p && e.disposeIntermediateTensorInfo(d), x;
323
- }
324
- const he = {
325
- kernelName: U,
326
- backendName: "webgl",
327
- kernelFunc: te
328
- };
329
- const ae = `
330
- if (a == b) {
331
- return 1.0;
332
- };
333
- return a / b;`, se = `
334
- // vec4 one = vec4(equal(a, b));
335
- // return one + (vec4(1.0) - one) * a / b;
336
- vec4 result = a / b;
337
- if(a.x == b.x) {
338
- result.x = 1.;
339
- }
340
- if(a.y == b.y) {
341
- result.y = 1.;
342
- }
343
- if(a.z == b.z) {
344
- result.z = 1.;
345
- }
346
- if(a.w == b.w) {
347
- result.w = 1.;
348
- }
349
-
350
- return result;
351
- `, ne = L({ opSnippet: ae, packedOpSnippet: se, checkOutOfBounds: !0 }), fe = {
352
- kernelName: W,
353
- backendName: "webgl",
354
- kernelFunc: ne
355
- };
356
- export {
357
- M as a,
358
- he as b,
359
- fe as c,
360
- pe as d,
361
- te as m,
362
- ne as r,
363
- Z as s,
364
- P as t
365
- };
@@ -1,79 +0,0 @@
1
- import { R as C, U as c, aj as R, x as f } from "./index-CUXkjxiT.js";
2
- import { u as g, g as I, a as x, b as F, c as $, d as u, e as m, i as l } from "./gpgpu_math-BwvV12df.js";
3
- class S {
4
- constructor(t, i) {
5
- this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "inputShape", type: "ivec3" }], this.outputShape = t, this.enableShapeUniforms = g(this.outputShape.length);
6
- let a = "";
7
- for (let e = 0; e < 4; e++) {
8
- let o = "thisRC = rc;";
9
- e % 2 === 1 && (o += "thisRC.z += 1;"), e > 1 && (o += "thisRC.y += 1;"), a += `
10
- ${o}
11
- ${e > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : ""}
12
- int flatIndex = getFlatIndex(thisRC);
13
-
14
- ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
15
- vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));
16
-
17
- result[${e}] =
18
- getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
19
- ${e > 0 ? "}" : ""}
20
- `;
21
- }
22
- this.userCode = `
23
- ${v(i, this.enableShapeUniforms)}
24
- ${this.enableShapeUniforms ? I() : x(t)}
25
-
26
- void main() {
27
- ivec3 rc = getOutputCoords();
28
-
29
- vec4 result = vec4(0.);
30
-
31
- ivec3 thisRC;
32
- int rows = ${this.enableShapeUniforms ? "outShape[1]" : t[1]};
33
- int cols = ${this.enableShapeUniforms ? "outShape[2]" : t[2]};
34
-
35
- ${a}
36
-
37
- setOutput(result);
38
- }
39
- `;
40
- }
41
- }
42
- function v(s, t) {
43
- return `
44
- ivec3 inputCoordsFromReshapedOutCoords(int index) {
45
- ${t ? F(["r", "c", "d"], "inputShape") : $(["r", "c", "d"], s)}
46
- return ivec3(r, c, d);
47
- }
48
- `;
49
- }
50
- function b(s, t, i) {
51
- const a = [
52
- u(s.shape),
53
- ...m(s.shape)
54
- ], e = {
55
- dtype: s.dtype,
56
- shape: a,
57
- dataId: s.dataId
58
- }, o = [
59
- u(t),
60
- ...m(t)
61
- ], r = new S(o, a), p = !0, n = [a], h = i.runWebGLProgram(r, [e], s.dtype, n, p);
62
- return { dataId: h.dataId, shape: t, dtype: h.dtype };
63
- }
64
- function y(s) {
65
- const { inputs: t, backend: i, attrs: a } = s, { x: e } = t, { shape: o } = a, r = i, p = c(e.shape), n = R(o, p), h = c(n);
66
- f(p === h, () => `The new shape (${n}) has ${h} elements and the old shape (${e.shape}) has ${p} elements. The new shape and old shape must have the same number of elements.`);
67
- const d = r.texData.get(e.dataId);
68
- return d.isPacked && !l(e.shape, n) && !(d.texture !== null && l(d.shape, n)) ? b(e, n, r) : (r.incRef(e.dataId), { dataId: e.dataId, shape: n, dtype: e.dtype });
69
- }
70
- const U = {
71
- kernelName: C,
72
- backendName: "webgl",
73
- kernelFunc: y
74
- };
75
- export {
76
- S as R,
77
- U as a,
78
- y as r
79
- };
@@ -1,14 +0,0 @@
1
- import { U as h, aj as d, x as c, R as m } from "./index-CUXkjxiT.js";
2
- function i(n) {
3
- const { inputs: p, attrs: o } = n, { x: e } = p, { shape: r } = o, a = h(e.shape), s = d(r, a), t = h(s);
4
- return c(a === t, () => `The new shape (${s}) has ${t} elements and the old shape (${e.shape}) has ${a} elements. The new shape and old shape must have the same number of elements.`), n.backend.incRef(e.dataId), { dataId: e.dataId, shape: s, dtype: e.dtype };
5
- }
6
- const u = {
7
- kernelName: m,
8
- backendName: "webgpu",
9
- kernelFunc: i
10
- };
11
- export {
12
- u as a,
13
- i as r
14
- };
@@ -1,33 +0,0 @@
1
- var u = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
- function a(e) {
3
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
4
- }
5
- function f(e) {
6
- if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
7
- var n = e.default;
8
- if (typeof n == "function") {
9
- var t = function r() {
10
- var o = !1;
11
- try {
12
- o = this instanceof r;
13
- } catch {
14
- }
15
- return o ? Reflect.construct(n, arguments, this.constructor) : n.apply(this, arguments);
16
- };
17
- t.prototype = n.prototype;
18
- } else t = {};
19
- return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
20
- var o = Object.getOwnPropertyDescriptor(e, r);
21
- Object.defineProperty(t, r, o.get ? o : {
22
- enumerable: !0,
23
- get: function() {
24
- return e[r];
25
- }
26
- });
27
- }), t;
28
- }
29
- export {
30
- f as a,
31
- u as c,
32
- a as g
33
- };
@@ -1,55 +0,0 @@
1
- import { x as c } from "./index-CUXkjxiT.js";
2
- function i(e, n) {
3
- for (let t = 0; t < e.length; ++t)
4
- if (e[e.length - t - 1] !== n - 1 - t)
5
- return !1;
6
- return !0;
7
- }
8
- function a(e, n, t) {
9
- const r = e.length + n.length, s = [];
10
- let o = 0, f = 0;
11
- for (let u = 0; u < r; u++)
12
- t.indexOf(u) === -1 ? s.push(e[o++]) : s.push(n[f++]);
13
- return s;
14
- }
15
- function l(e, n) {
16
- const t = [], r = e.length;
17
- for (let o = 0; o < r; o++)
18
- n.indexOf(o) === -1 && t.push(e[o]);
19
- const s = n.map((o) => e[o]);
20
- return [t, s];
21
- }
22
- function h(e, n) {
23
- const t = n.map((r) => 1);
24
- return a(e, t, n);
25
- }
26
- function m(e, n, t) {
27
- c(i(n, t), () => `${e} supports only inner-most axes for now. Got axes ${n} and rank-${t} input.`);
28
- }
29
- function d(e, n) {
30
- if (i(e, n))
31
- return null;
32
- const t = [];
33
- for (let r = 0; r < n; ++r)
34
- e.indexOf(r) === -1 && t.push(r);
35
- return e.forEach((r) => t.push(r)), t;
36
- }
37
- function g(e) {
38
- return e.map((n, t) => [t, n]).sort((n, t) => n[1] - t[1]).map((n) => n[0]);
39
- }
40
- function x(e, n) {
41
- const t = [];
42
- for (let r = n - e; r < n; ++r)
43
- t.push(r);
44
- return t;
45
- }
46
- export {
47
- d as a,
48
- x as b,
49
- l as c,
50
- m as d,
51
- h as e,
52
- i as f,
53
- g,
54
- a as h
55
- };