@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,20 +1,32 @@
1
- import { arraysClose as p } from "../utilities/arrayClose.js";
2
- async function d(c, o, n) {
3
- const u = n ?? ["cpu", "webgl", "webgpu"], t = [];
4
- for (const e of u)
5
- try {
6
- const r = await c(e);
7
- t.push({ backend: e, result: r, passed: !0 });
8
- } catch (r) {
9
- t.push({ backend: e, error: r.message, result: [], passed: !1 });
10
- }
11
- const s = await Promise.all(t), l = s[0].result;
12
- for (let e = 1; e < s.length; e++) {
13
- const r = s[e].result, a = p(l, r);
14
- s[e].passed = a <= (o ?? 1e-6), s[e].maxError = a;
15
- }
16
- return s;
1
+ import { arraysClose as e } from "../utilities/arrayClose.js";
2
+ //#region lib/checks/check.ts
3
+ async function t(t, n, r) {
4
+ let i = r ?? [
5
+ "cpu",
6
+ "webgl",
7
+ "webgpu"
8
+ ], a = [];
9
+ for (let e of i) try {
10
+ let n = await t(e);
11
+ a.push({
12
+ backend: e,
13
+ result: n,
14
+ passed: !0
15
+ });
16
+ } catch (t) {
17
+ a.push({
18
+ backend: e,
19
+ error: t.message,
20
+ result: [],
21
+ passed: !1
22
+ });
23
+ }
24
+ let o = await Promise.all(a), s = o[0].result;
25
+ for (let t = 1; t < o.length; t++) {
26
+ let r = o[t].result, i = e(s, r);
27
+ o[t].passed = i <= (n ?? 1e-6), o[t].maxError = i;
28
+ }
29
+ return o;
17
30
  }
18
- export {
19
- d as default
20
- };
31
+ //#endregion
32
+ export { t as default };
@@ -1,18 +1,46 @@
1
- import { s as e, h as o } from "../index-CUXkjxiT.js";
2
- import { t as s } from "../tensor2d-BnXMKScO.js";
3
- async function m(t) {
4
- await e(t);
5
- const r = s(
6
- [
7
- [0.1, 0.2, 0, 0, 1230, 1232331234, -12234234],
8
- [0.1, 0.2, 0, 0, -1230, -1232331234, 12234234],
9
- [0, 0, 0, 0, -1, 0, 0],
10
- [0, 0, 0, 0, -0.1, 1e-3, 0]
11
- ],
12
- [4, 7]
13
- );
14
- return await o().runKernel("Gelu", { x: r }).array();
1
+ import { I as e, ii as t, ui as n } from "../dist-BewPQWjc.js";
2
+ //#region lib/checks/gelu.ts
3
+ async function r(r) {
4
+ await n(r);
5
+ let i = e([
6
+ [
7
+ .1,
8
+ .2,
9
+ 0,
10
+ 0,
11
+ 1230,
12
+ 1232331234,
13
+ -12234234
14
+ ],
15
+ [
16
+ .1,
17
+ .2,
18
+ 0,
19
+ 0,
20
+ -1230,
21
+ -1232331234,
22
+ 12234234
23
+ ],
24
+ [
25
+ 0,
26
+ 0,
27
+ 0,
28
+ 0,
29
+ -1,
30
+ 0,
31
+ 0
32
+ ],
33
+ [
34
+ 0,
35
+ 0,
36
+ 0,
37
+ 0,
38
+ -.1,
39
+ .001,
40
+ 0
41
+ ]
42
+ ], [4, 7]);
43
+ return await t().runKernel("Gelu", { x: i }).array();
15
44
  }
16
- export {
17
- m as execute
18
- };
45
+ //#endregion
46
+ export { r as execute };
@@ -1,28 +1,28 @@
1
- import { execute as e } from "./rope.js";
2
- import { execute as t } from "./normRMS.js";
3
- import { execute as r } from "./qkv.js";
4
- import { execute as c } from "./gelu.js";
1
+ import { createTensorStatistics as e, createWeightStatistics as t } from "./weights.js";
2
+ import { execute as n } from "./rope.js";
3
+ import { execute as r } from "./normRMS.js";
4
+ import { execute as i } from "./qkv.js";
5
+ import { execute as a } from "./gelu.js";
5
6
  import { execute as o } from "./normRMSGrad.js";
6
- import { execute as a } from "./appendCache.js";
7
- import { execute as m } from "./attentionMask.js";
8
- import { execute as i } from "./matMulGelu.js";
7
+ import { execute as s } from "./appendCache.js";
8
+ import { execute as c } from "./attentionMask.js";
9
+ import { execute as l } from "./matMulGelu.js";
9
10
  import { execute as u } from "./packUnpack.js";
10
- import s from "./check.js";
11
- import { createTensorStatistics as x, createWeightStatistics as p } from "./weights.js";
12
- const C = {
13
- rope: e,
14
- qkv: r,
15
- gelu: c,
16
- normRMS: t,
17
- normRMSGrad: o,
18
- appendCache: a,
19
- attentionMask: m,
20
- matMulGelu: i,
21
- packUnpack: u,
22
- runCheck: s,
23
- createLayerWeightStatistics: p,
24
- createWeightStatistics: x
25
- };
26
- export {
27
- C as default
11
+ import d from "./check.js";
12
+ //#region lib/checks/index.ts
13
+ var f = {
14
+ rope: n,
15
+ qkv: i,
16
+ gelu: a,
17
+ normRMS: r,
18
+ normRMSGrad: o,
19
+ appendCache: s,
20
+ attentionMask: c,
21
+ matMulGelu: l,
22
+ packUnpack: u,
23
+ runCheck: d,
24
+ createLayerWeightStatistics: t,
25
+ createWeightStatistics: e
28
26
  };
27
+ //#endregion
28
+ export { f as default };
@@ -1,28 +1,84 @@
1
- import { s as o, h as s } from "../index-CUXkjxiT.js";
2
- import { t as e } from "../tensor2d-BnXMKScO.js";
3
- async function i(t) {
4
- await o(t);
5
- const r = e(
6
- [
7
- [0.1, 0.2, 9, 10, 11],
8
- [0.3, 0.4, -9, -10, -11],
9
- [0.3, 0.4, -9, -10, -11],
10
- [0.3, 0.4, -9, -10, -11],
11
- [0.3, 0.4, -9, -10, -11]
12
- ],
13
- [5, 5]
14
- ), n = e(
15
- [
16
- [0.5, 0.6, 7e4, -8e3, 0],
17
- [0.7, 0.8, -7e4, 8e4, 0],
18
- [0.7, 0.8, -7e4, 8e4, 0],
19
- [0.7, 0.8, -7e4, 8e4, 0],
20
- [0.7, 0.8, -7e4, 8e4, 0]
21
- ],
22
- [5, 5]
23
- );
24
- return await s().runKernel("MatMulGelu", { x: n, kernel: r }).array();
1
+ import { I as e, ii as t, ui as n } from "../dist-BewPQWjc.js";
2
+ //#region lib/checks/matMulGelu.ts
3
+ async function r(r) {
4
+ await n(r);
5
+ let i = e([
6
+ [
7
+ .1,
8
+ .2,
9
+ 9,
10
+ 10,
11
+ 11
12
+ ],
13
+ [
14
+ .3,
15
+ .4,
16
+ -9,
17
+ -10,
18
+ -11
19
+ ],
20
+ [
21
+ .3,
22
+ .4,
23
+ -9,
24
+ -10,
25
+ -11
26
+ ],
27
+ [
28
+ .3,
29
+ .4,
30
+ -9,
31
+ -10,
32
+ -11
33
+ ],
34
+ [
35
+ .3,
36
+ .4,
37
+ -9,
38
+ -10,
39
+ -11
40
+ ]
41
+ ], [5, 5]), a = e([
42
+ [
43
+ .5,
44
+ .6,
45
+ 7e4,
46
+ -8e3,
47
+ 0
48
+ ],
49
+ [
50
+ .7,
51
+ .8,
52
+ -7e4,
53
+ 8e4,
54
+ 0
55
+ ],
56
+ [
57
+ .7,
58
+ .8,
59
+ -7e4,
60
+ 8e4,
61
+ 0
62
+ ],
63
+ [
64
+ .7,
65
+ .8,
66
+ -7e4,
67
+ 8e4,
68
+ 0
69
+ ],
70
+ [
71
+ .7,
72
+ .8,
73
+ -7e4,
74
+ 8e4,
75
+ 0
76
+ ]
77
+ ], [5, 5]);
78
+ return await t().runKernel("MatMulGelu", {
79
+ x: a,
80
+ kernel: i
81
+ }).array();
25
82
  }
26
- export {
27
- i as execute
28
- };
83
+ //#endregion
84
+ export { r as execute };
@@ -1,16 +1,28 @@
1
- import { s as u, a0 as A, h } from "../index-CUXkjxiT.js";
2
- import { a as y } from "../ops-CsXeTq1P.js";
3
- import { t as p } from "../tensor1d-LMGMIUlr.js";
4
- import { t as r } from "../tensor-BWFldCso.js";
5
- const w = Array.from({ length: 2048 * 192 }, () => Math.random()), x = Array.from({ length: 192 }, () => Math.random()), M = Array.from({ length: 2048 * 192 }, () => Math.random());
6
- async function k(t) {
7
- await u(t);
8
- const o = p(x, "float32"), n = r(w, [16, 128, 192], "float32"), s = r(M, [16, 128, 192], "float32"), e = (d, g) => {
9
- const i = h().runKernel("RMSNorm", { x: d, gamma: g });
10
- return y.meanSquaredError(i, s);
11
- }, { value: m, grads: a } = A(e)([n, o]), c = await m.array(), f = await a[0].array(), l = await a[1].array();
12
- return [c, f, l];
1
+ import { Kt as e, L as t, fi as n, ii as r, m as i, ui as a } from "../dist-BewPQWjc.js";
2
+ //#region lib/checks/normRMS.ts
3
+ var o = Array.from({ length: 2048 * 192 }, () => Math.random()), s = Array.from({ length: 192 }, () => Math.random()), c = Array.from({ length: 2048 * 192 }, () => Math.random());
4
+ async function l(l) {
5
+ await a(l);
6
+ let u = t(s, "float32"), d = n(o, [
7
+ 16,
8
+ 128,
9
+ 192
10
+ ], "float32"), f = n(c, [
11
+ 16,
12
+ 128,
13
+ 192
14
+ ], "float32"), { value: p, grads: m } = e((e, t) => {
15
+ let n = r().runKernel("RMSNorm", {
16
+ x: e,
17
+ gamma: t
18
+ });
19
+ return i.meanSquaredError(n, f);
20
+ })([d, u]);
21
+ return [
22
+ await p.array(),
23
+ await m[0].array(),
24
+ await m[1].array()
25
+ ];
13
26
  }
14
- export {
15
- k as execute
16
- };
27
+ //#endregion
28
+ export { l as execute };
@@ -1,12 +1,22 @@
1
- import { s as c, h as d } from "../index-CUXkjxiT.js";
2
- import { t as f } from "../tensor1d-LMGMIUlr.js";
3
- import { t as r } from "../tensor-BWFldCso.js";
4
- const y = Array.from({ length: 2048 * 192 }, () => Math.random()), i = Array.from({ length: 192 }, () => Math.random()), l = Array.from({ length: 2048 * 192 }, () => Math.random());
5
- async function x(t) {
6
- await c(t);
7
- const o = f(i, "float32"), n = r(y, [16, 128, 192], "float32"), m = r(l, [16, 128, 192], "float32"), a = d().runKernel("RMSNormGrad", { x: n, gamma: o, dy: m }), s = await a[0].array(), e = await a[1].array();
8
- return [s, e];
1
+ import { L as e, fi as t, ii as n, ui as r } from "../dist-BewPQWjc.js";
2
+ //#region lib/checks/normRMSGrad.ts
3
+ var i = Array.from({ length: 2048 * 192 }, () => Math.random()), a = Array.from({ length: 192 }, () => Math.random()), o = Array.from({ length: 2048 * 192 }, () => Math.random());
4
+ async function s(s) {
5
+ await r(s);
6
+ let c = e(a, "float32"), l = t(i, [
7
+ 16,
8
+ 128,
9
+ 192
10
+ ], "float32"), u = t(o, [
11
+ 16,
12
+ 128,
13
+ 192
14
+ ], "float32"), d = n().runKernel("RMSNormGrad", {
15
+ x: l,
16
+ gamma: c,
17
+ dy: u
18
+ });
19
+ return [await d[0].array(), await d[1].array()];
9
20
  }
10
- export {
11
- x as execute
12
- };
21
+ //#endregion
22
+ export { s as execute };
@@ -1,18 +1,46 @@
1
- import { s as a, h as n } from "../index-CUXkjxiT.js";
2
- import { t as c } from "../tensor2d-BnXMKScO.js";
3
- async function i(e) {
4
- await a(e);
5
- const r = c(
6
- [
7
- [0.1, 0.2, 0, 0, 1230, 1232331234, -12234234],
8
- [0.1, 0.2, 0, 0, -1230, -1232331234, 12234234],
9
- [0, 0, 0, 0, -1, 0, 0],
10
- [0, 0, 0, 0, -0.1, 1e-3, 0]
11
- ],
12
- [4, 7]
13
- ), t = n().runKernel("Pack16", { x: r });
14
- return await n().runKernel("Unpack16", { x: t }).array();
1
+ import { I as e, ii as t, ui as n } from "../dist-BewPQWjc.js";
2
+ //#region lib/checks/packUnpack.ts
3
+ async function r(r) {
4
+ await n(r);
5
+ let i = e([
6
+ [
7
+ .1,
8
+ .2,
9
+ 0,
10
+ 0,
11
+ 1230,
12
+ 1232331234,
13
+ -12234234
14
+ ],
15
+ [
16
+ .1,
17
+ .2,
18
+ 0,
19
+ 0,
20
+ -1230,
21
+ -1232331234,
22
+ 12234234
23
+ ],
24
+ [
25
+ 0,
26
+ 0,
27
+ 0,
28
+ 0,
29
+ -1,
30
+ 0,
31
+ 0
32
+ ],
33
+ [
34
+ 0,
35
+ 0,
36
+ 0,
37
+ 0,
38
+ -.1,
39
+ .001,
40
+ 0
41
+ ]
42
+ ], [4, 7]), a = t().runKernel("Pack16", { x: i });
43
+ return await t().runKernel("Unpack16", { x: a }).array();
15
44
  }
16
- export {
17
- i as execute
18
- };
45
+ //#endregion
46
+ export { r as execute };
@@ -1,34 +1,34 @@
1
- import { W as i, X as u, Y as c, s as l, h } from "../index-CUXkjxiT.js";
2
- import { t as f } from "../tensor2d-BnXMKScO.js";
3
- function m(t, e, n) {
4
- if (i(t), e != null && e.length !== 3)
5
- throw new Error("tensor3d() requires shape to have three numbers");
6
- const r = u(t, n);
7
- if (r.length !== 3 && r.length !== 1)
8
- throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");
9
- if (r.length === 1 && e == null)
10
- throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");
11
- return c(t, e, r, n);
1
+ import { F as e, I as t, ii as n, ui as r } from "../dist-BewPQWjc.js";
2
+ //#region lib/checks/qkv.ts
3
+ async function i(i) {
4
+ await r(i);
5
+ let a = e([[[.1, .2], [.3, .4]]], [
6
+ 1,
7
+ 2,
8
+ 2
9
+ ]), o = t([[
10
+ .5,
11
+ .6,
12
+ .9,
13
+ 1,
14
+ 1.3,
15
+ 1.4
16
+ ], [
17
+ .7,
18
+ .8,
19
+ 1.1,
20
+ 1.2,
21
+ 1.5,
22
+ 1.6
23
+ ]], [2, 6]), s = n().runKernel("QKV", {
24
+ x: a,
25
+ kernel: o
26
+ }, { heads: 1 });
27
+ return [
28
+ await s[0].array(),
29
+ await s[1].array(),
30
+ await s[2].array()
31
+ ];
12
32
  }
13
- async function y(t) {
14
- await l(t);
15
- const e = m(
16
- [
17
- [
18
- [0.1, 0.2],
19
- [0.3, 0.4]
20
- ]
21
- ],
22
- [1, 2, 2]
23
- ), n = f(
24
- [
25
- [0.5, 0.6, 0.9, 1, 1.3, 1.4],
26
- [0.7, 0.8, 1.1, 1.2, 1.5, 1.6]
27
- ],
28
- [2, 6]
29
- ), r = h().runKernel("QKV", { x: e, kernel: n }, { heads: 1 }), o = await r[0].array(), a = await r[1].array(), s = await r[2].array();
30
- return [o, a, s];
31
- }
32
- export {
33
- y as execute
34
- };
33
+ //#endregion
34
+ export { i as execute };
@@ -1,36 +1,30 @@
1
- import s from "../layers/RoPECache.js";
2
- import { s as c, h as i } from "../index-CUXkjxiT.js";
3
- import { t as p } from "../tensor4d-C6UCG_u8.js";
4
- async function f(r) {
5
- await c(r);
6
- const n = p(
7
- [
8
- [
9
- [
10
- [0.1, 0.2],
11
- [0.3, 0.4]
12
- ]
13
- ]
14
- ],
15
- [1, 1, 2, 2]
16
- ), a = {
17
- modelType: "GenAI_NanoGPT_v1",
18
- vocabSize: 20,
19
- nEmbed: 16,
20
- nHead: 2,
21
- nLayer: 1,
22
- blockSize: 128,
23
- mlpFactor: 4,
24
- useRope: !0
25
- }, e = new s(a);
26
- e.ensureRopeCache(120);
27
- const o = i().runKernel(
28
- "Rope",
29
- { x: n, sin: e.getSin(), cos: e.getCos() },
30
- { pastLen: 20 }
31
- );
32
- return Array.isArray(o) ? o.map((t) => t.array()) : o.array();
1
+ import { P as e, ii as t, ui as n } from "../dist-BewPQWjc.js";
2
+ import r from "../layers/RoPECache.js";
3
+ //#region lib/checks/rope.ts
4
+ async function i(i) {
5
+ await n(i);
6
+ let a = e([[[[.1, .2], [.3, .4]]]], [
7
+ 1,
8
+ 1,
9
+ 2,
10
+ 2
11
+ ]), o = new r({
12
+ modelType: "GenAI_NanoGPT_v1",
13
+ vocabSize: 20,
14
+ nEmbed: 16,
15
+ nHead: 2,
16
+ nLayer: 1,
17
+ blockSize: 128,
18
+ mlpFactor: 4,
19
+ useRope: !0
20
+ });
21
+ o.ensureRopeCache(120);
22
+ let s = t().runKernel("Rope", {
23
+ x: a,
24
+ sin: o.getSin(),
25
+ cos: o.getCos()
26
+ }, { pastLen: 20 });
27
+ return Array.isArray(s) ? s.map((e) => e.array()) : s.array();
33
28
  }
34
- export {
35
- f as execute
36
- };
29
+ //#endregion
30
+ export { i as execute };
@@ -1,4 +1,4 @@
1
- import { default as BaseLayer } from '../layers/BaseLayer';
1
+ import { default as BaseLayer } from '../../layers/BaseLayer';
2
2
  import { Tensor } from '@tensorflow/tfjs-core';
3
3
  export interface TensorStatistics {
4
4
  mean: number;
@@ -1,31 +1,27 @@
1
- async function b(s) {
2
- if (!Array.isArray(s) && s.dtype !== "float32")
3
- throw new Error(`Unsupported dtype ${s.dtype} for weight statistics.`);
4
- const e = Array.isArray(s) ? s : await s.data(), a = e.length;
5
- let r = 0, l = 0, n = e[0], i = e[0], f = 0, d = !0, u = !1, y = 0;
6
- for (let c = 0; c < a; c++) {
7
- const t = e[c];
8
- r += t, l += t * t, t < n && (n = t), t > i && (i = t), t === 0 && f++, Math.abs(t) < 1e-8 && y++, Number.isNaN(t) && (u = !0);
9
- }
10
- const o = r / a, m = l / a - o * o, p = Math.sqrt(m), N = f / a;
11
- return {
12
- mean: o,
13
- std: p,
14
- min: n,
15
- max: i,
16
- sparsity: N,
17
- isFinite: d,
18
- hasNaN: u,
19
- closeToZeroCount: y
20
- };
1
+ //#region lib/checks/weights.ts
2
+ async function e(e) {
3
+ if (!Array.isArray(e) && e.dtype !== "float32") throw Error(`Unsupported dtype ${e.dtype} for weight statistics.`);
4
+ let t = Array.isArray(e) ? e : await e.data(), n = t.length, r = 0, i = 0, a = t[0], o = t[0], s = 0, c = !0, l = !1, u = 0;
5
+ for (let e = 0; e < n; e++) {
6
+ let n = t[e];
7
+ r += n, i += n * n, n < a && (a = n), n > o && (o = n), n === 0 && s++, Math.abs(n) < 1e-8 && u++, !c && c !== !1 && (c = Number.isFinite(n)), Number.isNaN(n) && (l = !0);
8
+ }
9
+ let d = r / n, f = i / n - d * d, p = Math.sqrt(f), m = s / n;
10
+ return {
11
+ mean: d,
12
+ std: p,
13
+ min: a,
14
+ max: o,
15
+ sparsity: m,
16
+ isFinite: c,
17
+ hasNaN: l,
18
+ closeToZeroCount: u
19
+ };
21
20
  }
22
- async function h(s) {
23
- const e = s.trainableVariables, a = {};
24
- for (const r of e)
25
- a[r.name] = await b(r);
26
- return a;
21
+ async function t(t) {
22
+ let n = t.trainableVariables, r = {};
23
+ for (let t of n) r[t.name] = await e(t);
24
+ return r;
27
25
  }
28
- export {
29
- b as createTensorStatistics,
30
- h as createWeightStatistics
31
- };
26
+ //#endregion
27
+ export { e as createTensorStatistics, t as createWeightStatistics };
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (e && (t = e(e = 0)), t), s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), c = (e, n) => {
3
+ let r = {};
4
+ for (var i in e) t(r, i, {
5
+ get: e[i],
6
+ enumerable: !0
7
+ });
8
+ return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ }, l = (e, i, o, s) => {
10
+ if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
11
+ get: ((e) => i[e]).bind(null, d),
12
+ enumerable: !(s = n(i, d)) || s.enumerable
13
+ });
14
+ return e;
15
+ }, u = (n, r, a) => (a = n == null ? {} : e(i(n)), l(r || !n || !n.__esModule ? t(a, "default", {
16
+ value: n,
17
+ enumerable: !0
18
+ }) : a, n)), d = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
19
+ if (typeof require < "u") return require.apply(this, arguments);
20
+ throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
21
+ });
22
+ //#endregion
23
+ export { u as a, d as i, o as n, c as r, s as t };