@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,4 +1,4 @@
1
- import { Conversation, ITokeniser } from '../../main';
1
+ import { Conversation, ITokeniser } from '../../../main';
2
2
  import { Task } from './Task';
3
3
  export default class StartSentenceTask extends Task {
4
4
  private rawText;
@@ -1,49 +1,45 @@
1
- import { Task as r } from "./Task.js";
2
- class a extends r {
3
- rawText;
4
- index = 0;
5
- get length() {
6
- return this.rawText.length;
7
- }
8
- constructor(t) {
9
- super(), this.rawText = t;
10
- }
11
- hasMoreConversations() {
12
- return this.index < this.rawText.length;
13
- }
14
- nextConversation() {
15
- if (this.index >= this.rawText.length)
16
- return null;
17
- const t = this.rawText[this.index];
18
- return this.index++, this.conversationFromString(t);
19
- }
20
- nextTokens(t, n) {
21
- const e = this.nextConversation();
22
- return e ? t.encodeConversation(e, !1, n) : null;
23
- }
24
- shuffle() {
25
- this.index = 0;
26
- }
27
- conversationFromString(t) {
28
- const n = t.indexOf(".");
29
- return n === -1 ? [{
30
- role: "assistant",
31
- content: this.rawText[this.index]
32
- }] : [
33
- {
34
- role: "user",
35
- content: t.slice(0, n + 1).trim()
36
- },
37
- {
38
- role: "assistant",
39
- content: t.slice(n + 1).trim()
40
- }
41
- ];
42
- }
43
- async estimateTokens(t) {
44
- return (await t.encodeConversation(this.conversationFromString(this.rawText[0]))).length * this.length;
45
- }
46
- }
47
- export {
48
- a as default
1
+ import { Task as e } from "./Task.js";
2
+ //#region lib/training/tasks/StartSentenceTask.ts
3
+ var t = class extends e {
4
+ rawText;
5
+ index = 0;
6
+ get length() {
7
+ return this.rawText.length;
8
+ }
9
+ constructor(e) {
10
+ super(), this.rawText = e;
11
+ }
12
+ hasMoreConversations() {
13
+ return this.index < this.rawText.length;
14
+ }
15
+ nextConversation() {
16
+ if (this.index >= this.rawText.length) return null;
17
+ let e = this.rawText[this.index];
18
+ return this.index++, this.conversationFromString(e);
19
+ }
20
+ nextTokens(e, t) {
21
+ let n = this.nextConversation();
22
+ return n ? e.encodeConversation(n, !1, t) : null;
23
+ }
24
+ shuffle() {
25
+ this.index = 0;
26
+ }
27
+ conversationFromString(e) {
28
+ let t = e.indexOf(".");
29
+ return t === -1 ? [{
30
+ role: "assistant",
31
+ content: this.rawText[this.index]
32
+ }] : [{
33
+ role: "user",
34
+ content: e.slice(0, t + 1).trim()
35
+ }, {
36
+ role: "assistant",
37
+ content: e.slice(t + 1).trim()
38
+ }];
39
+ }
40
+ async estimateTokens(e) {
41
+ return (await e.encodeConversation(this.conversationFromString(this.rawText[0]))).length * this.length;
42
+ }
49
43
  };
44
+ //#endregion
45
+ export { t as default };
@@ -1,4 +1,4 @@
1
- import { Conversation, ITokeniser } from '../../main';
1
+ import { Conversation, ITokeniser } from '../../../main';
2
2
  export declare abstract class Task {
3
3
  abstract get length(): number;
4
4
  abstract hasMoreConversations(): boolean;
@@ -1,68 +1,55 @@
1
- import { yieldIfNeeded as k } from "../../utilities/yielder.js";
2
- class w {
1
+ import { yieldIfNeeded as e } from "../../utilities/yielder.js";
2
+ //#region lib/training/tasks/Task.ts
3
+ var t = class {};
4
+ function n(e, t, n, r, i, a) {
5
+ for (let o of e) {
6
+ let e = o.nextTokens(n, a ? !0 : void 0);
7
+ if (e) {
8
+ let n = Array.isArray(e) ? e : e.tokens;
9
+ r.total += n.length;
10
+ let o = t[t.length - 1], s = a ? a[a.length - 1] : null;
11
+ if (r.offset + n.length > o.length) {
12
+ let c = o.length - r.offset;
13
+ o.set(n.slice(0, c), r.offset);
14
+ let l = new Uint16Array(Math.floor(i * .1) + 100);
15
+ if (l.set(n.slice(c), 0), t.push(l), a && s && !Array.isArray(e)) {
16
+ s.set(e.mask.slice(0, c).map((e) => +!!e), r.offset);
17
+ let t = new Uint8Array(l.length);
18
+ t.set(e.mask.slice(c).map((e) => +!!e), 0), a.push(t);
19
+ }
20
+ r.offset = n.length - c;
21
+ } else o.set(n, r.offset), s && !Array.isArray(e) && s.set(e.mask.map((e) => +!!e), r.offset), r.offset += n.length;
22
+ }
23
+ }
3
24
  }
4
- function m(y, i, u, o, g, n) {
5
- for (const a of y) {
6
- const e = a.nextTokens(u, n ? !0 : void 0);
7
- if (e) {
8
- const f = Array.isArray(e) ? e : e.tokens;
9
- o.total += f.length;
10
- const c = i[i.length - 1], l = n ? n[n.length - 1] : null;
11
- if (o.offset + f.length > c.length) {
12
- const s = c.length - o.offset;
13
- c.set(f.slice(0, s), o.offset);
14
- const t = new Uint16Array(Math.floor(g * 0.1) + 100);
15
- if (t.set(f.slice(s), 0), i.push(t), n && l && !Array.isArray(e)) {
16
- l.set(
17
- e.mask.slice(0, s).map((h) => h ? 1 : 0),
18
- o.offset
19
- );
20
- const r = new Uint8Array(t.length);
21
- r.set(
22
- e.mask.slice(s).map((h) => h ? 1 : 0),
23
- 0
24
- ), n.push(r);
25
- }
26
- o.offset = f.length - s;
27
- } else
28
- c.set(f, o.offset), l && !Array.isArray(e) && l.set(
29
- e.mask.map((s) => s ? 1 : 0),
30
- o.offset
31
- ), o.offset += f.length;
32
- }
33
- }
25
+ async function r(t, r, i, a) {
26
+ let o = Math.min((await Promise.all(t.map((e) => e.estimateTokens(r)))).reduce((e, t) => e + t, 0), r.vocabSize * 1e4), s = [new Uint16Array(o)], c = a ? [new Uint8Array(o)] : null, l = {
27
+ offset: 0,
28
+ total: 0
29
+ }, u = performance.now();
30
+ for (; l.offset < o && (n(t, s, r, l, o, c || void 0), !t.every((e) => !e.hasMoreConversations()));) u = await e(u, i, l.total);
31
+ if (s.length === 1) return c ? {
32
+ tokens: s[0].subarray(0, l.offset),
33
+ mask: c[0].subarray(0, l.offset)
34
+ } : s[0].subarray(0, l.offset);
35
+ let d = s.reduce((e, t) => e + t.length, 0) - (s[s.length - 1].length - l.offset), f = new Uint16Array(d), p = 0;
36
+ for (let e = 0; e < s.length; e++) {
37
+ let t = s[e];
38
+ e === s.length - 1 ? (f.set(t.subarray(0, l.offset), p), p += l.offset) : (f.set(t, p), p += t.length);
39
+ }
40
+ if (c) {
41
+ let e = new Uint8Array(d);
42
+ p = 0;
43
+ for (let t = 0; t < c.length; t++) {
44
+ let n = c[t];
45
+ t === c.length - 1 ? (e.set(n.subarray(0, l.offset), p), p += l.offset) : (e.set(n, p), p += n.length);
46
+ }
47
+ return {
48
+ tokens: f,
49
+ mask: e
50
+ };
51
+ }
52
+ return f;
34
53
  }
35
- async function p(y, i, u, o) {
36
- const g = Math.min(
37
- (await Promise.all(y.map((t) => t.estimateTokens(i)))).reduce((t, r) => t + r, 0),
38
- i.vocabSize * 1e4
39
- ), n = [new Uint16Array(g)], a = o ? [new Uint8Array(g)] : null, e = {
40
- offset: 0,
41
- total: 0
42
- };
43
- let f = performance.now();
44
- for (; e.offset < g && (m(y, n, i, e, g, a || void 0), !y.every((t) => !t.hasMoreConversations())); )
45
- f = await k(f, u, e.total);
46
- if (n.length === 1)
47
- return a ? { tokens: n[0].subarray(0, e.offset), mask: a[0].subarray(0, e.offset) } : n[0].subarray(0, e.offset);
48
- const c = n.reduce((t, r) => t + r.length, 0) - (n[n.length - 1].length - e.offset), l = new Uint16Array(c);
49
- let s = 0;
50
- for (let t = 0; t < n.length; t++) {
51
- const r = n[t];
52
- t === n.length - 1 ? (l.set(r.subarray(0, e.offset), s), s += e.offset) : (l.set(r, s), s += r.length);
53
- }
54
- if (a) {
55
- const t = new Uint8Array(c);
56
- s = 0;
57
- for (let r = 0; r < a.length; r++) {
58
- const h = a[r];
59
- r === a.length - 1 ? (t.set(h.subarray(0, e.offset), s), s += e.offset) : (t.set(h, s), s += h.length);
60
- }
61
- return { tokens: l, mask: t };
62
- }
63
- return l;
64
- }
65
- export {
66
- w as Task,
67
- p as tokensFromTasks
68
- };
54
+ //#endregion
55
+ export { t as Task, r as tokensFromTasks };
@@ -1,21 +1,18 @@
1
- import s from "./ConversationTask.js";
2
- function f(e, o) {
3
- if (o <= 0 || o >= 1)
4
- throw new Error("validationSplit must be between 0 and 1");
5
- e.forEach((n) => n.shuffle());
6
- const r = [], a = [];
7
- for (const n of e)
8
- for (; n.hasMoreConversations(); ) {
9
- const t = n.nextConversation();
10
- if (!t)
11
- break;
12
- Math.random() < o ? a.push(t) : r.push(t);
13
- }
14
- return {
15
- training: new s(r),
16
- validation: new s(a)
17
- };
1
+ import e from "./ConversationTask.js";
2
+ //#region lib/training/tasks/splitter.ts
3
+ function t(t, n) {
4
+ if (n <= 0 || n >= 1) throw Error("validationSplit must be between 0 and 1");
5
+ t.forEach((e) => e.shuffle());
6
+ let r = [], i = [];
7
+ for (let e of t) for (; e.hasMoreConversations();) {
8
+ let t = e.nextConversation();
9
+ if (!t) break;
10
+ Math.random() < n ? i.push(t) : r.push(t);
11
+ }
12
+ return {
13
+ training: new e(r),
14
+ validation: new e(i)
15
+ };
18
16
  }
19
- export {
20
- f as default
21
- };
17
+ //#endregion
18
+ export { t as default };
@@ -1,5 +1,5 @@
1
- import { TensorStatistics } from '../checks/weights';
2
- import { LoRAConfig } from '../models/config';
1
+ import { TensorStatistics } from '../../checks/weights';
2
+ import { LoRAConfig } from '../../models/config';
3
3
  import { NamedTensorMap, Tensor } from '@tensorflow/tfjs-core';
4
4
  export interface Metrics {
5
5
  accuracy?: number;
@@ -1 +0,0 @@
1
-
@@ -1,4 +1,4 @@
1
- import { ITokeniser, Task } from '../main';
1
+ import { ITokeniser, Task } from '../../main';
2
2
  import { Tensor } from '@tensorflow/tfjs-core';
3
3
  import { Dataset } from '@tensorflow/tfjs-data';
4
4
  import { DatasetBuilder, DatasetState } from './DatasetBuilder';
@@ -1,84 +1,2 @@
1
- import "../index-CUXkjxiT.js";
2
- import "../random_width-DN5ZtQkM.js";
3
- import "../zeros_like-CWjDdwr-.js";
4
- import "../Generator.js";
5
- import "../index-Cp39cXWe.js";
6
- import "../dataset-CGGp1z9P.js";
7
- import "../ops/cpu/attentionMask.js";
8
- import "../ops/webgl/attentionMask.js";
9
- import "../ops/grads/attentionMask.js";
10
- import "../ops/cpu/rope.js";
11
- import "../ops/webgl/rope.js";
12
- import "../rope-DcrZM_e6.js";
13
- import "../ops/cpu/appendCache.js";
14
- import "../ops/webgl/appendCache.js";
15
- import "../ops/grads/softmax16.js";
16
- import "../matMul16-BcVC_E62.js";
17
- import "../ops/webgl/matMul16.js";
18
- import "../ops/cpu/matMul16.js";
19
- import "../pack16-bqltoUlR.js";
20
- import "../ops/transpose16.js";
21
- import "../ops/reshape16.js";
22
- import "../ops/cpu/qkv.js";
23
- import "../ops/webgl/qkv.js";
24
- import "../ops/grads/qkv.js";
25
- import "../ops/cpu/normRMS.js";
26
- import "../ops/webgl/normRMS.js";
27
- import "../ops/grads/normRMS.js";
28
- import "../ops/dropout16.js";
29
- import "../ops/webgl/dropout16.js";
30
- import "../ops/grads/add16.js";
31
- import "../jszip.min-BZhlzntC.js";
32
- import "../index-DvYrXKkX.js";
33
- import "../ops/cpu/adamAdjust.js";
34
- import "../ops/webgl/adamAdjust.js";
35
- import "../ops/cpu/adamMoments.js";
36
- import "../ops/webgl/adamMoments.js";
37
- import "../ops/cpu/gatherSub.js";
38
- import "../ops/webgl/gatherSub.js";
39
- import "../ops/cpu/scatterSub.js";
40
- import "../ops/webgl/scatterSub.js";
41
- import { PAGE_FACTOR as a, shuffle as k } from "./DatasetBuilder.js";
42
- import "../papaparse.min-C0cScC2i.js";
43
- import { tokensFromTasks as y } from "./tasks/Task.js";
44
- import "../ops/cpu/matMulGelu.js";
45
- import "../matMulGelu-JNLZqKQp.js";
46
- import "../ops/grads/matMulGelu.js";
47
- import "../ops/cpu/gelu.js";
48
- import "../ops/webgl/gelu.js";
49
- import "../gelu-B220X1Go.js";
50
- import "../ops/webgl/log.js";
51
- import "../checks/normRMS.js";
52
- import "../checks/normRMSGrad.js";
53
- async function Mt(n, x, o, l, c = 0.1, d) {
54
- const r = n instanceof Uint16Array ? n : await y(n, x, void 0, d), i = r instanceof Uint16Array ? r : r.tokens, f = r instanceof Uint16Array ? void 0 : r.mask, m = /* @__PURE__ */ new Set();
55
- if (c > 0) {
56
- const t = Math.floor(i.length / (o.blockSize * a)), s = Math.max(1, Math.floor(t * c));
57
- for (; m.size < s; ) {
58
- const M = Math.floor(Math.random() * t);
59
- m.add(M);
60
- }
61
- }
62
- const p = new Uint32Array(
63
- i.length - m.size * o.blockSize * a
64
- ), e = new Uint32Array(m.size * o.blockSize * a);
65
- let h = 0, g = 0;
66
- for (let t = 0; t < i.length; t++) {
67
- const s = Math.floor(t / (o.blockSize * a));
68
- m.has(s) ? g < e.length && (e[g++] = t) : h < p.length && (p[h++] = t);
69
- }
70
- const { dataset: v, state: w } = await o.createTextDataset(
71
- i,
72
- l,
73
- k(p),
74
- f || void 0
75
- ), { dataset: z, state: A } = await o.createTextDataset(
76
- i,
77
- l,
78
- k(e)
79
- );
80
- return { trainDataset: v, validationDataset: z, size: i.length, validationState: A, trainState: w };
81
- }
82
- export {
83
- Mt as createTrainValidationSplit
84
- };
1
+ import { o as e } from "../main-CPjeMv0G.js";
2
+ export { e as createTrainValidationSplit };
@@ -1,20 +1,16 @@
1
- function i(r, e) {
2
- let t = 0;
3
- if ((Array.isArray(r) || r instanceof Float32Array) && (Array.isArray(e) || e instanceof Float32Array)) {
4
- if (r.length !== e.length) return Number.POSITIVE_INFINITY;
5
- for (let n = 0; n < r.length; ++n)
6
- t = Math.max(t, i(r[n], e[n]));
7
- return t;
8
- } else if (typeof r == "number" && typeof e == "number") {
9
- if (isNaN(r) && isNaN(e))
10
- return 0;
11
- if (!isFinite(r) || !isFinite(e))
12
- return r === e ? 0 : Number.POSITIVE_INFINITY;
13
- const n = Math.abs(r - e);
14
- return t = Math.max(t, n), t;
15
- } else
16
- return Number.POSITIVE_INFINITY;
1
+ //#region lib/utilities/arrayClose.ts
2
+ function e(t, n) {
3
+ let r = 0;
4
+ if ((Array.isArray(t) || t instanceof Float32Array) && (Array.isArray(n) || n instanceof Float32Array)) {
5
+ if (t.length !== n.length) return Infinity;
6
+ for (let i = 0; i < t.length; ++i) r = Math.max(r, e(t[i], n[i]));
7
+ return r;
8
+ } else if (typeof t == "number" && typeof n == "number") {
9
+ if (isNaN(t) && isNaN(n)) return 0;
10
+ if (!isFinite(t) || !isFinite(n)) return t === n ? 0 : Infinity;
11
+ let e = Math.abs(t - n);
12
+ return r = Math.max(r, e), r;
13
+ } else return Infinity;
17
14
  }
18
- export {
19
- i as arraysClose
20
- };
15
+ //#endregion
16
+ export { e as arraysClose };
@@ -1,21 +1,18 @@
1
- function h(s) {
2
- const c = s.map((n) => String(n.id)).sort();
3
- let e = 2166136261, o = 2654435769;
4
- const t = (n) => {
5
- e ^= n & 255, e = Math.imul(e, 16777619), o ^= n & 255, o = Math.imul(o, 2246822507);
6
- }, g = (n) => {
7
- const r = n.length >>> 0;
8
- t(r & 255), t(r >>> 8 & 255), t(r >>> 16 & 255), t(r >>> 24 & 255);
9
- for (let a = 0; a < n.length; a++) {
10
- const l = n.charCodeAt(a);
11
- t(l & 255), t(l >>> 8 & 255);
12
- }
13
- }, i = c.length >>> 0;
14
- t(i & 255), t(i >>> 8 & 255), t(i >>> 16 & 255), t(i >>> 24 & 255);
15
- for (const n of c)
16
- g(n);
17
- return "dataset__" + (e >>> 0).toString(36) + "_" + (o >>> 0).toString(36);
1
+ //#region lib/utilities/datasetID.ts
2
+ function e(e) {
3
+ let t = e.map((e) => String(e.id)).sort(), n = 2166136261, r = 2654435769, i = (e) => {
4
+ n ^= e & 255, n = Math.imul(n, 16777619), r ^= e & 255, r = Math.imul(r, 2246822507);
5
+ }, a = (e) => {
6
+ let t = e.length >>> 0;
7
+ i(t & 255), i(t >>> 8 & 255), i(t >>> 16 & 255), i(t >>> 24 & 255);
8
+ for (let t = 0; t < e.length; t++) {
9
+ let n = e.charCodeAt(t);
10
+ i(n & 255), i(n >>> 8 & 255);
11
+ }
12
+ }, o = t.length >>> 0;
13
+ i(o & 255), i(o >>> 8 & 255), i(o >>> 16 & 255), i(o >>> 24 & 255);
14
+ for (let e of t) a(e);
15
+ return "dataset__" + (n >>> 0).toString(36) + "_" + (r >>> 0).toString(36);
18
16
  }
19
- export {
20
- h as default
21
- };
17
+ //#endregion
18
+ export { e as default };
@@ -1,4 +1,4 @@
1
- import { default as Model, ModelForwardAttributes } from '../models/model';
1
+ import { default as Model, ModelForwardAttributes } from '../../models/model';
2
2
  export declare function dummyPassAsync(model: Model<ModelForwardAttributes>): Promise<void>;
3
3
  export interface MemoryRequirements {
4
4
  perBatch: number;
@@ -1,43 +1,36 @@
1
- import { b as y, h as I, v as P } from "../index-CUXkjxiT.js";
2
- import { z as c } from "../zeros-DvZpK8s6.js";
3
- async function w(s) {
4
- const t = c([1, s.config.blockSize], "int32"), n = s.forward({ training: !1 }, t);
5
- await n.data(), n.dispose(), t.dispose();
1
+ import { ii as e, kt as t, qt as n, si as r } from "../dist-BewPQWjc.js";
2
+ //#region lib/utilities/dummy.ts
3
+ async function i(e) {
4
+ let n = t([1, e.config.blockSize], "int32"), r = e.forward({ training: !1 }, n);
5
+ await r.data(), r.dispose(), n.dispose();
6
6
  }
7
- async function b(s) {
8
- const t = y(), n = t.numBytesInGPUAllocated ?? t.numBytesAllocatedInGPU ?? t.numBytes;
9
- await w(s);
10
- const a = c([1, s.config.blockSize], "int32"), e = {
11
- perBatch: 0,
12
- tapeSize: 0,
13
- gradients: s.getNumParams() * 4
14
- };
15
- try {
16
- const i = () => {
17
- const o = s.forward({ training: !0 }, a), u = I().state.activeTape;
18
- let p = 0;
19
- if (u)
20
- for (const g of u)
21
- p += g.saved?.reduce((B, z) => B + z.size * 4, 0) || 0;
22
- e.tapeSize = p;
23
- const l = o.mean();
24
- return o.dispose(), l;
25
- }, { value: d, grads: m } = P(i), r = y(), f = r.numBytesInGPUAllocated ?? r.numBytesAllocatedInGPU ?? r.numBytes;
26
- e.perBatch = f - n - e.gradients, await d.data(), d.dispose();
27
- for (const o in m)
28
- m[o].dispose();
29
- a.dispose();
30
- } catch (i) {
31
- console.error("Error during dummy training pass:", i), a.dispose();
32
- }
33
- return e;
7
+ async function a(a) {
8
+ let o = r(), s = o.numBytesInGPUAllocated ?? o.numBytesAllocatedInGPU ?? o.numBytes;
9
+ await i(a);
10
+ let c = t([1, a.config.blockSize], "int32"), l = {
11
+ perBatch: 0,
12
+ tapeSize: 0,
13
+ gradients: a.getNumParams() * 4
14
+ };
15
+ try {
16
+ let { value: t, grads: i } = n(() => {
17
+ let t = a.forward({ training: !0 }, c), n = e().state.activeTape, r = 0;
18
+ if (n) for (let e of n) r += e.saved?.reduce((e, t) => e + t.size * 4, 0) || 0;
19
+ l.tapeSize = r;
20
+ let i = t.mean();
21
+ return t.dispose(), i;
22
+ }), o = r();
23
+ l.perBatch = (o.numBytesInGPUAllocated ?? o.numBytesAllocatedInGPU ?? o.numBytes) - s - l.gradients, await t.data(), t.dispose();
24
+ for (let e in i) i[e].dispose();
25
+ c.dispose();
26
+ } catch (e) {
27
+ console.error("Error during dummy training pass:", e), c.dispose();
28
+ }
29
+ return l;
34
30
  }
35
- function v(s) {
36
- const t = c([1, s.config.blockSize], "int32");
37
- s.forward({ training: !1 }, t).dispose(), t.dispose();
31
+ function o(e) {
32
+ let n = t([1, e.config.blockSize], "int32");
33
+ e.forward({ training: !1 }, n).dispose(), n.dispose();
38
34
  }
39
- export {
40
- v as dummyPass,
41
- w as dummyPassAsync,
42
- b as dummyPassTrainAsync
43
- };
35
+ //#endregion
36
+ export { o as dummyPass, i as dummyPassAsync, a as dummyPassTrainAsync };
@@ -1,13 +1,9 @@
1
- import "../index-CUXkjxiT.js";
2
- import { t as e } from "../tensor2d-BnXMKScO.js";
3
- function f(n, i) {
4
- let r = 0;
5
- const o = i ?? Math.random();
6
- for (let t = 0; t < n.length; t++)
7
- if (r += n[t], o < r)
8
- return e([[t]], [1, 1], "int32");
9
- return e([[n.length - 1]], [1, 1], "int32");
1
+ import { I as e } from "../dist-BewPQWjc.js";
2
+ //#region lib/utilities/multinomialCPU.ts
3
+ function t(t, n) {
4
+ let r = 0, i = n ?? Math.random();
5
+ for (let n = 0; n < t.length; n++) if (r += t[n], i < r) return e([[n]], [1, 1], "int32");
6
+ return e([[t.length - 1]], [1, 1], "int32");
10
7
  }
11
- export {
12
- f as default
13
- };
8
+ //#endregion
9
+ export { t as default };
@@ -1 +0,0 @@
1
-
@@ -1,15 +1,13 @@
1
- import { h as n } from "../index-CUXkjxiT.js";
2
- function o() {
3
- return n().backendName === "webgpu";
1
+ import { ii as e } from "../dist-BewPQWjc.js";
2
+ //#region lib/utilities/packed.ts
3
+ function t() {
4
+ return e().backendName === "webgpu";
4
5
  }
5
- function r(e) {
6
- return e.dtype === "packedF16";
6
+ function n(e) {
7
+ return e.dtype === "packedF16";
7
8
  }
8
- function a(e) {
9
- return r(e);
9
+ function r(e) {
10
+ return n(e);
10
11
  }
11
- export {
12
- r as isPackableTensor,
13
- a as isPackedTensor,
14
- o as packingSupported
15
- };
12
+ //#endregion
13
+ export { n as isPackableTensor, r as isPackedTensor, t as packingSupported };
@@ -1,4 +1,4 @@
1
- import { GPTConfig } from '../models/config';
1
+ import { GPTConfig } from '../../models/config';
2
2
  export declare function estimateLayerParameters(config: GPTConfig): number;
3
3
  export declare function estimateParameterCount(config: GPTConfig): number;
4
4
  export declare function estimateMemoryUsage(config: GPTConfig): number;