@genai-fi/nanogpt 1.4.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/dist/{DatasetBuilder-DU1G1OKX.js → DatasetBuilder-DRDW8tcM.js} +85 -86
  2. package/dist/Generator-BcR_14Cj.js +316 -0
  3. package/dist/{RealDiv-CSnvtN2E.js → RealDiv-Cl8k3YTx.js} +54 -62
  4. package/dist/{Reshape-BlylqwWy.js → Reshape-CKxKPKqi.js} +9 -12
  5. package/dist/Reshape-H5zZRgr9.js +16 -0
  6. package/dist/RoPECache-dYscFINl.js +722 -0
  7. package/dist/TeachableLLM.js +29 -34
  8. package/dist/api/beamer.d.ts +1 -0
  9. package/dist/api/beamer.js +19 -10
  10. package/dist/api/responses.js +11 -12
  11. package/dist/api/training.js +12 -14
  12. package/dist/axis_util-rF9RnwKE.js +37 -0
  13. package/dist/backend.js +5 -6
  14. package/dist/{backend_util-DAV0I34P.js → backend_util-Cpp0Gwlp.js} +180 -185
  15. package/dist/{binary_op_util-CrYk9LXL.js → binary_op_util-WY9YIl0q.js} +3 -7
  16. package/dist/broadcast_to-CGvLNiQ0.js +20 -0
  17. package/dist/checks/appendCache.js +7 -7
  18. package/dist/checks/attentionMask.js +9 -8
  19. package/dist/checks/check.js +1 -2
  20. package/dist/checks/gelu.js +6 -6
  21. package/dist/checks/index.js +24 -25
  22. package/dist/checks/matMulGelu.js +7 -7
  23. package/dist/checks/normRMS.js +14 -12
  24. package/dist/checks/normRMSGrad.js +9 -8
  25. package/dist/checks/packUnpack.js +7 -7
  26. package/dist/checks/qkv.js +1 -34
  27. package/dist/checks/rope.js +6 -6
  28. package/dist/checks/weights.js +1 -2
  29. package/dist/clip_by_value-D-UX9am5.js +13 -0
  30. package/dist/complex-Cl904TqN.js +13 -0
  31. package/dist/{complex_util-CkazZsaH.js → complex_util-BBlPAm-s.js} +1 -2
  32. package/dist/concat-Oip5acVY.js +14 -0
  33. package/dist/{concat_util-CWzvQQlK.js → concat_util-CY45Hf4F.js} +2 -3
  34. package/dist/data/docx.js +3 -4
  35. package/dist/data/pdf.js +11 -14
  36. package/dist/data/stream.js +1 -2
  37. package/dist/data/textLoader.js +16 -15
  38. package/dist/data-CV_i_H6B.js +11 -0
  39. package/dist/data.js +5 -12
  40. package/dist/dist-CMMLi-qO.js +2675 -0
  41. package/dist/{dist-BGVm64AY.js → dist-DeVH1nGn.js} +1465 -1573
  42. package/dist/{dist-CwK5S7Ls.js → dist-DyL7qSLJ.js} +2664 -2400
  43. package/dist/dropout16-CA31Ud5a.js +20 -0
  44. package/dist/dropout_util-SiFMbFXz.js +22 -0
  45. package/dist/{eventemitter3-D_qV3Lof.js → eventemitter3-wmfmOP_f.js} +2 -3
  46. package/dist/expand_dims-Dh3Fulyn.js +10 -0
  47. package/dist/floor-BwjmUb7X.js +8 -0
  48. package/dist/gather-B5Z1RFt5.js +14 -0
  49. package/dist/gatherSub-CRUfUzBa.js +22 -0
  50. package/dist/gelu-Xx9-ohH9.js +25 -0
  51. package/dist/{gpgpu_math-20tPK8LM.js → gpgpu_math-48m8q3jI.js} +265 -286
  52. package/dist/inference/Beamer.d.ts +14 -2
  53. package/dist/inference/Beamer.js +170 -105
  54. package/dist/inference/Generator.js +1 -259
  55. package/dist/inference/tokenisePrompt.d.ts +2 -1
  56. package/dist/inference/tokenisePrompt.js +15 -11
  57. package/dist/inference/types.d.ts +7 -0
  58. package/dist/inference/utilities.js +1 -2
  59. package/dist/{jszip.min-DKa1Rjyn.js → jszip.min-Btv48m44.js} +68 -64
  60. package/dist/{kernel_funcs_utils-ql8Y8qPn.js → kernel_funcs_utils-BYRpSfV_.js} +39 -42
  61. package/dist/layers/BaseLayer.js +9 -10
  62. package/dist/layers/{CausalSelfAttention.d.ts → GQA.d.ts} +8 -3
  63. package/dist/layers/GQA.js +102 -0
  64. package/dist/layers/HeadLayer.d.ts +12 -0
  65. package/dist/layers/HeadLayer.js +28 -0
  66. package/dist/layers/LoRA.js +17 -20
  67. package/dist/layers/MHA.d.ts +43 -0
  68. package/dist/layers/MHA.js +102 -0
  69. package/dist/layers/MLP.d.ts +5 -1
  70. package/dist/layers/MLP.js +33 -20
  71. package/dist/layers/PositionEmbedding.js +14 -13
  72. package/dist/layers/RMSNorm.d.ts +2 -0
  73. package/dist/layers/RMSNorm.js +16 -11
  74. package/dist/layers/RoPECache.js +1 -337
  75. package/dist/layers/TiedEmbedding.js +15 -14
  76. package/dist/layers/TransformerBlock.d.ts +4 -10
  77. package/dist/layers/TransformerBlock.js +29 -30
  78. package/dist/layers/WeightStore.js +4 -5
  79. package/dist/layers-CFqEip3s.js +13 -0
  80. package/dist/layers.d.ts +1 -1
  81. package/dist/layers.js +4 -12
  82. package/dist/loader/load.js +27 -24
  83. package/dist/loader/loadHF.js +3 -3
  84. package/dist/loader/loadTransformers.js +22 -7
  85. package/dist/loader/loadZipMeta.js +1 -2
  86. package/dist/loader/newZipLoad.js +1 -2
  87. package/dist/loader/oldZipLoad.js +8 -9
  88. package/dist/loader/save.js +31 -17
  89. package/dist/loader/types.d.ts +8 -2
  90. package/dist/main.js +3281 -3463
  91. package/dist/matMul16-tE26fnhf.js +87 -0
  92. package/dist/{matMulGelu-CBoqTZM7.js → matMulGelu-ASUWlKqu.js} +33 -33
  93. package/dist/mat_mul-R9_DWmIT.js +16 -0
  94. package/dist/models/Llama.d.ts +16 -0
  95. package/dist/models/Llama.js +88 -0
  96. package/dist/models/NanoGPTV1.js +53 -54
  97. package/dist/models/NanoGPTV2.js +48 -49
  98. package/dist/models/Qwen3.d.ts +16 -0
  99. package/dist/models/Qwen3.js +88 -0
  100. package/dist/models/config.d.ts +18 -1
  101. package/dist/models/config.js +3 -8
  102. package/dist/models/factory.js +14 -11
  103. package/dist/models/model.d.ts +5 -7
  104. package/dist/models/model.js +1 -2
  105. package/dist/models-DyBpJJwM.js +13 -0
  106. package/dist/models.js +6 -14
  107. package/dist/mul16-C7sqgqik.js +41 -0
  108. package/dist/non_max_suppression_impl-B0H318rb.js +72 -0
  109. package/dist/not_equal-Bu3O8rh_.js +67 -0
  110. package/dist/one_hot-TEMPumJj.js +14 -0
  111. package/dist/ones-DpPXWa6A.js +13 -0
  112. package/dist/ops/adamAdjust.js +2 -3
  113. package/dist/ops/adamMoments.js +2 -3
  114. package/dist/ops/add16.js +2 -3
  115. package/dist/ops/appendCache.js +9 -8
  116. package/dist/ops/attentionMask.d.ts +1 -1
  117. package/dist/ops/attentionMask.js +8 -5
  118. package/dist/ops/concat16.js +5 -5
  119. package/dist/ops/cpu/adamAdjust.js +7 -8
  120. package/dist/ops/cpu/adamMoments.js +5 -5
  121. package/dist/ops/cpu/appendCache.js +3 -3
  122. package/dist/ops/cpu/attentionMask.js +12 -8
  123. package/dist/ops/cpu/fusedSoftmax.js +3 -3
  124. package/dist/ops/cpu/gatherSub.js +1 -12
  125. package/dist/ops/cpu/gelu.js +12 -13
  126. package/dist/ops/cpu/matMul16.js +7 -7
  127. package/dist/ops/cpu/matMulGelu.js +21 -18
  128. package/dist/ops/cpu/matMulMul.js +8 -9
  129. package/dist/ops/cpu/mulDropout.js +8 -9
  130. package/dist/ops/cpu/normRMS.js +12 -13
  131. package/dist/ops/cpu/qkv.js +14 -13
  132. package/dist/ops/cpu/rope.js +11 -8
  133. package/dist/ops/cpu/scatterSub.js +1 -12
  134. package/dist/ops/dot16.js +16 -17
  135. package/dist/ops/dropout.js +9 -8
  136. package/dist/ops/dropout16.js +1 -22
  137. package/dist/ops/gatherSub.js +3 -4
  138. package/dist/ops/gelu.js +1 -2
  139. package/dist/ops/globalNorm.js +14 -14
  140. package/dist/ops/grads/add16.js +16 -17
  141. package/dist/ops/grads/attentionMask.js +6 -7
  142. package/dist/ops/grads/dropout16.js +1 -1
  143. package/dist/ops/grads/gelu.js +1 -2
  144. package/dist/ops/grads/matMul16.js +1 -2
  145. package/dist/ops/grads/matMulGelu.js +6 -7
  146. package/dist/ops/grads/mul16.js +1 -1
  147. package/dist/ops/grads/normRMS.js +8 -9
  148. package/dist/ops/grads/pack16.js +1 -2
  149. package/dist/ops/grads/qkv.js +10 -10
  150. package/dist/ops/grads/rope.js +1 -2
  151. package/dist/ops/grads/silu.d.ts +2 -0
  152. package/dist/ops/grads/silu.js +1 -0
  153. package/dist/ops/grads/softmax16.js +6 -7
  154. package/dist/ops/grads/unpack16.js +1 -2
  155. package/dist/ops/grads/utils.js +1 -2
  156. package/dist/ops/matMul16.d.ts +2 -2
  157. package/dist/ops/matMul16.js +1 -2
  158. package/dist/ops/matMulGelu.js +3 -4
  159. package/dist/ops/matMulMul.js +2 -3
  160. package/dist/ops/mul16.js +1 -43
  161. package/dist/ops/mulDrop.js +2 -3
  162. package/dist/ops/normRMS.d.ts +1 -1
  163. package/dist/ops/normRMS.js +10 -11
  164. package/dist/ops/pack16.js +1 -2
  165. package/dist/ops/qkv.js +2 -3
  166. package/dist/ops/reshape16.js +11 -11
  167. package/dist/ops/rope.d.ts +1 -1
  168. package/dist/ops/rope.js +1 -2
  169. package/dist/ops/scatterSub.js +3 -4
  170. package/dist/ops/silu.d.ts +3 -0
  171. package/dist/ops/silu.js +1 -0
  172. package/dist/ops/slice16.js +5 -5
  173. package/dist/ops/softmax16.js +3 -4
  174. package/dist/ops/sub16.js +3 -4
  175. package/dist/ops/sum16.js +3 -3
  176. package/dist/ops/transpose16.js +16 -15
  177. package/dist/ops/unpack16.js +1 -2
  178. package/dist/ops/webgl/adamAdjust.js +8 -9
  179. package/dist/ops/webgl/adamMoments.js +2 -3
  180. package/dist/ops/webgl/appendCache.js +2 -3
  181. package/dist/ops/webgl/attentionMask.js +2 -3
  182. package/dist/ops/webgl/dropout16.js +2 -3
  183. package/dist/ops/webgl/fusedSoftmax.js +13 -13
  184. package/dist/ops/webgl/gatherSub.js +2 -3
  185. package/dist/ops/webgl/gelu.js +11 -12
  186. package/dist/ops/webgl/log.js +10 -10
  187. package/dist/ops/webgl/matMul16.js +31 -24
  188. package/dist/ops/webgl/matMulGelu.js +1 -2
  189. package/dist/ops/webgl/matMulMul.js +3 -4
  190. package/dist/ops/webgl/mulDropout.js +2 -3
  191. package/dist/ops/webgl/normRMS.js +11 -10
  192. package/dist/ops/webgl/qkv.js +2 -3
  193. package/dist/ops/webgl/rope.js +10 -9
  194. package/dist/ops/webgl/scatterSub.js +2 -3
  195. package/dist/ops/webgpu/adamAdjust.js +13 -14
  196. package/dist/ops/webgpu/adamMoments.js +13 -14
  197. package/dist/ops/webgpu/add16.js +3 -4
  198. package/dist/ops/webgpu/appendCache.js +20 -21
  199. package/dist/ops/webgpu/attentionMask.js +18 -19
  200. package/dist/ops/webgpu/attentionMask32_program.js +7 -8
  201. package/dist/ops/webgpu/clipScale.js +11 -12
  202. package/dist/ops/webgpu/concat16.js +17 -18
  203. package/dist/ops/webgpu/dropout16.js +6 -7
  204. package/dist/ops/webgpu/gatherSub.js +11 -12
  205. package/dist/ops/webgpu/gelu.js +10 -11
  206. package/dist/ops/webgpu/index.js +17 -16
  207. package/dist/ops/webgpu/matMul16.js +74 -57
  208. package/dist/ops/webgpu/matMul16_program.d.ts +4 -3
  209. package/dist/ops/webgpu/matMul16_program.js +30 -22
  210. package/dist/ops/webgpu/mul16.js +3 -4
  211. package/dist/ops/webgpu/norm2.js +9 -10
  212. package/dist/ops/webgpu/normRMS.js +13 -14
  213. package/dist/ops/webgpu/normRMS16_program.d.ts +2 -1
  214. package/dist/ops/webgpu/normRMS16_program.js +5 -5
  215. package/dist/ops/webgpu/normRMS32_program.d.ts +2 -1
  216. package/dist/ops/webgpu/normRMS32_program.js +5 -5
  217. package/dist/ops/webgpu/normRMSGrad.js +30 -30
  218. package/dist/ops/webgpu/pack16.js +2 -3
  219. package/dist/ops/webgpu/pack16_program.js +3 -4
  220. package/dist/ops/webgpu/qkv.js +10 -11
  221. package/dist/ops/webgpu/rope.js +113 -49
  222. package/dist/ops/webgpu/scatterSub.js +12 -13
  223. package/dist/ops/webgpu/silu.d.ts +14 -0
  224. package/dist/ops/webgpu/silu.js +117 -0
  225. package/dist/ops/webgpu/slice16.js +17 -18
  226. package/dist/ops/webgpu/softmax16.js +9 -9
  227. package/dist/ops/webgpu/softmax16_program.js +9 -10
  228. package/dist/ops/webgpu/softmax16_subgroup_program.js +11 -12
  229. package/dist/ops/webgpu/softmax16grad.js +8 -9
  230. package/dist/ops/webgpu/sub16.js +3 -4
  231. package/dist/ops/webgpu/sum16.js +16 -15
  232. package/dist/ops/webgpu/transpose16.js +13 -12
  233. package/dist/ops/webgpu/transpose16_program.js +3 -4
  234. package/dist/ops/webgpu/transpose16_shared_program.js +17 -18
  235. package/dist/ops/webgpu/unpack16.js +8 -9
  236. package/dist/ops/webgpu/utils/binary_op.js +20 -21
  237. package/dist/ops/webgpu/utils/deviceInfo.js +1 -2
  238. package/dist/ops/webgpu/utils/reductions.js +21 -20
  239. package/dist/ops-Be5ACU5R.js +13 -0
  240. package/dist/ops-C1UpdEYM.js +509 -0
  241. package/dist/{pack16-BhuXNUS7.js → pack16-BHO4t1-M.js} +14 -17
  242. package/dist/pad-Dy-1IP3A.js +13 -0
  243. package/dist/patches/webgpu_backend.js +18 -19
  244. package/dist/patches/webgpu_base.js +2 -3
  245. package/dist/patches/webgpu_program.js +21 -22
  246. package/dist/{pdf-Bzuk68Vy.js → pdf-CbnQ75VG.js} +380 -701
  247. package/dist/{picomatch-BO4HbNfo.js → picomatch--TW6gyBJ.js} +229 -291
  248. package/dist/qkv-BQfNPucX.js +42 -0
  249. package/dist/rand_util-_vCY93Uw.js +44 -0
  250. package/dist/random_normal-DUIT8kyC.js +11 -0
  251. package/dist/range-CYvQC3fW.js +13 -0
  252. package/dist/relu-C4XULT8A.js +8 -0
  253. package/dist/reshape-DJb1jgMt.js +8 -0
  254. package/dist/resize_nearest_neighbor-DAqcTYUe.js +188 -0
  255. package/dist/{chunk-CWhphoD1.js → rolldown-runtime-CwxnZyOB.js} +4 -5
  256. package/dist/rope-JjBVufF_.js +24 -0
  257. package/dist/scatterSub-BOnqk-uY.js +27 -0
  258. package/dist/scatter_nd_util-BepMCpLY.js +34 -0
  259. package/dist/seedrandom-SHEGFK6H.js +282 -0
  260. package/dist/selu_util-DeOTf-sc.js +27 -0
  261. package/dist/shared-BIDMUBCs.js +1864 -0
  262. package/dist/{shared-CfTzpULd.js → shared-CX_iPI5K.js} +2 -3
  263. package/dist/silu-DsAE2cJ5.js +23 -0
  264. package/dist/slice-Dlb1FlzG.js +13 -0
  265. package/dist/{slice_util-Dve4TkDn.js → slice_util-BVgPRoij.js} +3 -4
  266. package/dist/softmax-Dpav_dWw.js +10 -0
  267. package/dist/split-DYnT8chz.js +11 -0
  268. package/dist/squeeze-B3XYGAlg.js +9 -0
  269. package/dist/stack-Dbbt9mIk.js +10 -0
  270. package/dist/step-DA-5DNu9.js +348 -0
  271. package/dist/{stream-BpAwcvHz.js → stream-BBe2apn4.js} +68 -88
  272. package/dist/sum-C8qNbFNp.js +13 -0
  273. package/dist/tensor-ALxWZfmz.js +7 -0
  274. package/dist/tensor1d-BHgkkhTE.js +9 -0
  275. package/dist/tensor2d-ARItvqVn.js +10 -0
  276. package/dist/tensor4d-D1zRBipJ.js +10 -0
  277. package/dist/tfjs_backend-CsXOum0h.js +685 -0
  278. package/dist/tile-DfyQ0KX-.js +10 -0
  279. package/dist/tokenise-DbS2Ea-T.js +14 -0
  280. package/dist/tokenise.js +6 -15
  281. package/dist/tokeniser/BaseTokeniser.js +5 -9
  282. package/dist/tokeniser/CharTokeniser.js +1 -2
  283. package/dist/tokeniser/bpe.js +19 -20
  284. package/dist/topk-BrU2pkrR.js +19 -0
  285. package/dist/training/AdamW.js +35 -31
  286. package/dist/training/BasicTrainer.js +56 -56
  287. package/dist/training/DatasetBuilder.js +1 -2
  288. package/dist/training/Evaluator.js +8 -5
  289. package/dist/training/LRScheduler.js +1 -2
  290. package/dist/training/PreTrainer.js +7 -8
  291. package/dist/training/SFTTrainer.js +7 -8
  292. package/dist/training/configure.js +16 -15
  293. package/dist/training/factory.js +1 -2
  294. package/dist/training/loss.js +1 -2
  295. package/dist/training/orthoGrad.js +2 -3
  296. package/dist/training/prepareData.js +18 -17
  297. package/dist/training/sparseCrossEntropy.js +38 -32
  298. package/dist/training/tasks/TokenStore.js +21 -22
  299. package/dist/training/tasks/tokenStream.js +1 -2
  300. package/dist/training/validateOptions.js +1 -2
  301. package/dist/training/validation.js +1 -2
  302. package/dist/transpose-BC-M_OoT.js +34 -0
  303. package/dist/unsorted_segment_sum-BelC7R-q.js +408 -0
  304. package/dist/utilities/arrayClose.js +5 -4
  305. package/dist/utilities/arrayShape.js +1 -2
  306. package/dist/utilities/datasetID.js +1 -2
  307. package/dist/utilities/dummy.js +15 -15
  308. package/dist/utilities/float16.js +10 -10
  309. package/dist/utilities/maxHeap.d.ts +16 -0
  310. package/dist/utilities/maxHeap.js +54 -0
  311. package/dist/utilities/multinomialCPU.d.ts +1 -2
  312. package/dist/utilities/multinomialCPU.js +6 -8
  313. package/dist/utilities/packed.js +2 -3
  314. package/dist/utilities/parameters.js +34 -19
  315. package/dist/utilities/performance.js +2 -3
  316. package/dist/utilities/profile.js +3 -4
  317. package/dist/utilities/random.js +1 -2
  318. package/dist/utilities/safetensors.js +14 -14
  319. package/dist/utilities/sentences.js +16 -13
  320. package/dist/utilities/tokenParse.js +1 -2
  321. package/dist/utilities/tokens.js +5 -6
  322. package/dist/utilities/topP.d.ts +1 -0
  323. package/dist/utilities/topP.js +20 -13
  324. package/dist/utilities/waitForModel.js +1 -2
  325. package/dist/utilities/weights.js +4 -4
  326. package/dist/utilities/yielder.js +1 -2
  327. package/dist/{v4-BK7K-jy_.js → v4-YCkfo8OR.js} +4 -7
  328. package/dist/{webgpu-IAn9VotJ.js → webgpu-BHX-uBym.js} +156 -163
  329. package/dist/{webgpu_program-B0PokuRJ.js → webgpu_program-DvkFqRlR.js} +28 -29
  330. package/dist/{webgpu_util-DfODg6XI.js → webgpu_util-5QTyovaf.js} +2 -3
  331. package/dist/zeros-hxKGkRfl.js +12 -0
  332. package/package.json +3 -3
  333. package/dist/Reshape-CwxdaU8n.js +0 -17
  334. package/dist/dist-Da20xy8E.js +0 -6375
  335. package/dist/gelu-B6637MKa.js +0 -27
  336. package/dist/layers/CausalSelfAttention.js +0 -99
  337. package/dist/matMul16-DGtlziMn.js +0 -81
  338. package/dist/rope-C8EAiSGY.js +0 -25
  339. package/dist/selu_util-B_AFEfoz.js +0 -24
  340. package/dist/shared-24EoeHJl.js +0 -1314
  341. package/dist/tfjs_backend-h5weiy1O.js +0 -614
package/dist/tokenise.js CHANGED
@@ -1,15 +1,6 @@
1
- import { n as e } from "./chunk-CWhphoD1.js";
2
- import t from "./tokeniser/CharTokeniser.js";
3
- import n from "./tokeniser/bpe.js";
4
- import { TokenStore as r, createTokenStore as i } from "./training/tasks/TokenStore.js";
5
- import { tokensFromStreams as a } from "./training/tasks/tokenStream.js";
6
- //#region lib/tokenise.ts
7
- var o = /* @__PURE__ */ e({
8
- BPETokeniser: () => n,
9
- CharTokeniser: () => t,
10
- TokenStore: () => r,
11
- createTokenStore: () => i,
12
- tokensFromStreams: () => a
13
- });
14
- //#endregion
15
- export { n as BPETokeniser, t as CharTokeniser, r as TokenStore, i as createTokenStore, o as t, a as tokensFromStreams };
1
+ import e from "./tokeniser/CharTokeniser.js";
2
+ import t from "./tokeniser/bpe.js";
3
+ import { TokenStore as n, createTokenStore as r } from "./training/tasks/TokenStore.js";
4
+ import { tokensFromStreams as i } from "./training/tasks/tokenStream.js";
5
+ import "./tokenise-DbS2Ea-T.js";
6
+ export { t as BPETokeniser, e as CharTokeniser, n as TokenStore, r as createTokenStore, i as tokensFromStreams };
@@ -1,5 +1,5 @@
1
- import { t as e } from "../eventemitter3-D_qV3Lof.js";
2
- //#region lib/tokeniser/BaseTokeniser.ts
1
+ import { t as e } from "../eventemitter3-wmfmOP_f.js";
2
+ // lib/tokeniser/BaseTokeniser.ts
3
3
  var t = [
4
4
  "<eos>",
5
5
  "<bos>",
@@ -53,6 +53,7 @@ var t = [
53
53
  ];
54
54
  }
55
55
  encodeAsSequence(e, t) {
56
+ if (!e || e.length === 0) return t ? [this.bosToken] : [];
56
57
  let n = e.flatMap((e) => this.encode(e.content));
57
58
  return t ? [
58
59
  this.bosToken,
@@ -89,9 +90,7 @@ var t = [
89
90
  case "system":
90
91
  r.push([a[2]]), e = !0;
91
92
  break;
92
- case "text":
93
- r[r.length - 1][0] !== this.bosToken && r.push([this.bosToken]);
94
- break;
93
+ case "text": r[r.length - 1][0] !== this.bosToken && r.push([this.bosToken]);
95
94
  }
96
95
  switch (r.push(s), t.role) {
97
96
  case "user":
@@ -103,9 +102,7 @@ var t = [
103
102
  case "system":
104
103
  r.push([o[2]]);
105
104
  break;
106
- case "text":
107
- r.push([this.eosToken]);
108
- break;
105
+ case "text": r.push([this.eosToken]);
109
106
  }
110
107
  n && i && e ? (i.push([!1]), i.push(s.map(() => !1)), i.push([!1])) : n && i && (i.push([!1]), i.push(s.map(() => !0)), i.push([!0]));
111
108
  }
@@ -137,5 +134,4 @@ var t = [
137
134
  return this.specialTokens.get(e);
138
135
  }
139
136
  };
140
- //#endregion
141
137
  export { t as SPECIALS, n as default };
@@ -1,5 +1,5 @@
1
1
  import e, { SPECIALS as t } from "./BaseTokeniser.js";
2
- //#region lib/tokeniser/CharTokeniser.ts
2
+ // lib/tokeniser/CharTokeniser.ts
3
3
  var n = ["<eos>", "<unk>"], r = class extends e {
4
4
  vocabSize = 0;
5
5
  eosToken = 0;
@@ -82,5 +82,4 @@ var n = ["<eos>", "<unk>"], r = class extends e {
82
82
  return [r, i];
83
83
  }
84
84
  };
85
- //#endregion
86
85
  export { r as default };
@@ -1,7 +1,7 @@
1
- import e, { SPECIALS as t } from "./BaseTokeniser.js";
2
- import { yieldIfNeeded as n } from "../utilities/yielder.js";
3
- import r from "../utilities/tokenParse.js";
4
- //#region lib/tokeniser/bpe.ts
1
+ import { yieldIfNeeded as e } from "../utilities/yielder.js";
2
+ import t from "../utilities/tokenParse.js";
3
+ import n, { SPECIALS as r } from "./BaseTokeniser.js";
4
+ // lib/tokeniser/bpe.ts
5
5
  function i(e, t) {
6
6
  return `${e}-::-${t}`;
7
7
  }
@@ -33,7 +33,7 @@ function o(e, t, n, r, a) {
33
33
  a: t,
34
34
  b: n,
35
35
  count: a,
36
- instances: new Set([r])
36
+ instances: /* @__PURE__ */ new Set([r])
37
37
  });
38
38
  }
39
39
  function s(e) {
@@ -58,16 +58,16 @@ function l(e, t) {
58
58
  e.tokens[n] = i;
59
59
  }), e.pairs.delete(i(t.a, t.b));
60
60
  }
61
- var u = class extends e {
61
+ var u = class extends n {
62
62
  targetSize;
63
63
  vocab = /* @__PURE__ */ new Set();
64
64
  vocabIndex = /* @__PURE__ */ new Map();
65
65
  merges = [];
66
66
  pretokenMap = /* @__PURE__ */ new Map();
67
- constructor(e, n) {
67
+ constructor(e, t) {
68
68
  super(), Array.isArray(e) ? (e.forEach((e, t) => {
69
69
  this.vocab.add(e), this.vocabIndex.set(e, t);
70
- }), n && (this.merges = n), this.targetSize = e.length, t.forEach((t) => {
70
+ }), t && (this.merges = t), this.targetSize = e.length, r.forEach((t) => {
71
71
  let n = e.indexOf(t);
72
72
  n !== -1 && this.addSpecialToken(t, n);
73
73
  })) : (this.addSpecialTokens(), this.targetSize = e);
@@ -84,7 +84,7 @@ var u = class extends e {
84
84
  this.vocab.clear(), this.vocabIndex.clear(), this.merges = [], this.pretokenMap.clear();
85
85
  }
86
86
  get trained() {
87
- return this.vocab.size > t.length && this.vocab.size <= this.targetSize;
87
+ return this.vocab.size > r.length && this.vocab.size <= this.targetSize;
88
88
  }
89
89
  get vocabSize() {
90
90
  return this.vocab.size;
@@ -98,22 +98,22 @@ var u = class extends e {
98
98
  get unkToken() {
99
99
  return this.vocabIndex.get("") ?? 1;
100
100
  }
101
- async train(e = [], t, i) {
101
+ async train(n = [], r, i) {
102
102
  this.datasetID = i;
103
103
  let o = /* @__PURE__ */ new Set();
104
104
  this.vocab = /* @__PURE__ */ new Set(), this.pretokenMap.clear(), this.merges = [], this.addSpecialTokens();
105
- for (let n of e) await n.begin((e) => {
106
- for (let t of e) {
107
- let e = r(t.content);
105
+ for (let e of n) await e.begin((e) => {
106
+ for (let n of e) {
107
+ let e = t(n.content);
108
108
  for (let t of e) o.has(t) || (o.add(t), Array.from(t).forEach((e) => this.vocab.add(e)));
109
109
  }
110
- }, t ? () => t(this.vocab.size) : void 0);
110
+ }, r ? () => r(this.vocab.size) : void 0);
111
111
  let c = performance.now(), u = Array.from(o), d = u.map((e) => Array.from(e)), f = a(d);
112
- if (c = await n(c, t, this.vocab.size), this.vocab.size >= this.targetSize) throw console.warn("Initial vocab size is greater than or equal to target size. No merges will be performed.", this.vocab.size, this.targetSize), Error("too_small_vocab");
112
+ if (c = await e(c, r, this.vocab.size), this.vocab.size >= this.targetSize) throw console.warn("Initial vocab size is greater than or equal to target size. No merges will be performed.", this.vocab.size, this.targetSize), Error("too_small_vocab");
113
113
  for (; this.vocab.size < this.targetSize && this.merges.length < this.targetSize;) {
114
- let e = s(f);
115
- if (!e) break;
116
- this.merges.push([e.a, e.b]), this.vocab.add(e.a + e.b), l(f, e), c = await n(c, t, this.vocab.size);
114
+ let t = s(f);
115
+ if (!t) break;
116
+ this.merges.push([t.a, t.b]), this.vocab.add(t.a + t.b), l(f, t), c = await e(c, r, this.vocab.size);
117
117
  }
118
118
  u.forEach((e, t) => {
119
119
  let n = d[t];
@@ -136,7 +136,7 @@ var u = class extends e {
136
136
  }), this.pretokenMap.set(e, t), t;
137
137
  }
138
138
  tokeniseStrings(e) {
139
- return e.map((e) => r(e).map((e) => this.pretokenMap.has(e) ? this.pretokenMap.get(e) : this.tokeniseWord(e)).flat(1));
139
+ return e.map((e) => t(e).map((e) => this.pretokenMap.has(e) ? this.pretokenMap.get(e) : this.tokeniseWord(e)).flat(1));
140
140
  }
141
141
  tokenise(e, t) {
142
142
  let n = this.tokeniseStrings(e);
@@ -153,5 +153,4 @@ var u = class extends e {
153
153
  return this.detokenise([e])[0];
154
154
  }
155
155
  };
156
- //#endregion
157
156
  export { u as default };
@@ -0,0 +1,19 @@
1
+ import { Q as e, Z as t, li as n, rt as r } from "./dist-CMMLi-qO.js";
2
+ // node_modules/@tensorflow/tfjs-core/dist/ops/topk.js
3
+ function i(t, i = 1, a = !0) {
4
+ let o = e(t, "x", "topk");
5
+ if (o.rank === 0) throw Error("topk() expects the input to be of rank 1 or higher");
6
+ let s = o.shape[o.shape.length - 1];
7
+ if (i < 0) throw Error(`'k' passed to topk() must be >= 0 but got ${i}`);
8
+ if (i > s) throw Error(`'k' passed to topk() must be <= the last dimension (${s}) but got ${i}`);
9
+ let c = { x: o }, l = {
10
+ k: i,
11
+ sorted: a
12
+ }, [u, d] = r.runKernel(n, c, l);
13
+ return {
14
+ values: u,
15
+ indices: d
16
+ };
17
+ }
18
+ var a = /* @__PURE__ */ t({ topk_: i });
19
+ export { a as t };
@@ -1,11 +1,12 @@
1
- import { _n as e, c as t, di as n, ii as r, kt as i, ni as a } from "../dist-Da20xy8E.js";
2
- import { load_safetensors as o, save_safetensors as s } from "../utilities/safetensors.js";
3
- import { adamAdjust as c } from "../ops/adamAdjust.js";
4
- import { adamMoments as l } from "../ops/adamMoments.js";
5
- import u from "./LRScheduler.js";
6
- import { clipScale as d } from "../ops/globalNorm.js";
7
- //#region lib/training/AdamW.ts
8
- var f = class extends t {
1
+ import { adamAdjust as e } from "../ops/adamAdjust.js";
2
+ import { t } from "../zeros-hxKGkRfl.js";
3
+ import { adamMoments as n } from "../ops/adamMoments.js";
4
+ import { B as r, H as i, Y as a, b as o, c as s } from "../dist-CMMLi-qO.js";
5
+ import c from "./LRScheduler.js";
6
+ import { clipScale as l } from "../ops/globalNorm.js";
7
+ import { load_safetensors as u, save_safetensors as d } from "../utilities/safetensors.js";
8
+ // lib/training/AdamW.ts
9
+ var f = class extends s {
9
10
  config;
10
11
  className = "AdamW";
11
12
  accBeta1 = 0;
@@ -22,7 +23,7 @@ var f = class extends t {
22
23
  orthGradEpsilon = 1e-30;
23
24
  orthGrad;
24
25
  constructor(e) {
25
- super(), this.config = e, this.accBeta1 = e.accBeta1 ?? e.beta1, this.accBeta2 = e.accBeta2 ?? e.beta2, this.learningRate = e.learningRate, this.beta1 = e.beta1, this.beta2 = e.beta2, this.weightDecay = e.weightDecay, this.lossScaling = e.lossScaling, this.clipNorm = e.clipNorm, this.orthGrad = e.orthoGrad ?? !1, e.epsilon === null || e.epsilon === void 0 ? this.epsilon = r().backend.epsilon() : this.epsilon = e.epsilon, this.lrScheduler = new u(e.learningRate, e);
26
+ super(), this.config = e, this.accBeta1 = e.accBeta1 ?? e.beta1, this.accBeta2 = e.accBeta2 ?? e.beta2, this.learningRate = e.learningRate, this.beta1 = e.beta1, this.beta2 = e.beta2, this.weightDecay = e.weightDecay, this.lossScaling = e.lossScaling, this.clipNorm = e.clipNorm, this.orthGrad = e.orthoGrad ?? !1, this.epsilon = e.epsilon === null || e.epsilon === void 0 ? i().backend.epsilon() : e.epsilon, this.lrScheduler = new c(e.learningRate, e);
26
27
  }
27
28
  get lr() {
28
29
  return this.learningRate;
@@ -31,10 +32,10 @@ var f = class extends t {
31
32
  let e = {};
32
33
  return this.accumulatedMoments.forEach((t) => {
33
34
  e[t.originalName] = t.variable;
34
- }), s(e);
35
+ }), d(e);
35
36
  }
36
37
  async loadMoments(e) {
37
- let t = await o(e);
38
+ let t = await u(e);
38
39
  Object.entries(t).forEach(([e, t]) => {
39
40
  let n = t.variable(!1);
40
41
  this.accumulatedMoments.push({
@@ -59,7 +60,7 @@ var f = class extends t {
59
60
  };
60
61
  }
61
62
  orthogonalizeGradient(e, t) {
62
- return n(() => {
63
+ return a(() => {
63
64
  let n = e.reshape([-1]), r = t.reshape([-1]), i = n.mul(n).sum().add(this.orthGradEpsilon), a = n.mul(r).sum().div(i), o = r.sub(n.mul(a)), s = r.norm(), c = o.norm().add(this.orthGradEpsilon);
64
65
  return o.mul(s.div(c)).reshape(t.shape);
65
66
  });
@@ -71,29 +72,33 @@ var f = class extends t {
71
72
  };
72
73
  this.learningRate = t.learningRate, this.beta1 = t.beta1, this.beta2 = t.beta2, this.weightDecay = t.weightDecay, this.lossScaling = t.lossScaling, this.epsilon = t.epsilon ?? this.epsilon, this.clipNorm = t.clipNorm, this.lrScheduler.updateConfig(t, t.learningRate);
73
74
  }
74
- applyGradients(t) {
75
- let a = this.lrScheduler.getNextLR();
76
- this.learningRate = a;
77
- let o = Array.isArray(t) ? t.map((e) => e.name) : Object.keys(t), s = n(() => {
78
- let a = 1 - this.accBeta1, s = 1 - this.accBeta2, u;
79
- return u = this.clipNorm === void 0 ? e(1 / this.lossScaling) : d(o.map((e, n) => Array.isArray(t) ? t[n].tensor : t[e]), 1 / this.lossScaling, this.clipNorm), o.forEach((e, o) => {
80
- let d = r().registeredVariables[e];
81
- this.accumulatedMoments[o] ?? (this.accumulatedMoments[o] = {
82
- originalName: `${e}/m`,
83
- variable: n(() => i([...d.shape, 2]).variable(!1))
75
+ applyGradients(r) {
76
+ let s = this.lrScheduler.getNextLR();
77
+ this.learningRate = s;
78
+ let c = Array.isArray(r) ? r.map((e) => e.name) : Object.keys(r), u = a(() => {
79
+ let s = 1 - this.accBeta1, u = 1 - this.accBeta2, d;
80
+ if (this.clipNorm !== void 0) {
81
+ let e = c.map((e, t) => Array.isArray(r) ? r[t].tensor : r[e]);
82
+ d = l(e, 1 / this.lossScaling, this.clipNorm);
83
+ } else d = o(1 / this.lossScaling);
84
+ return c.forEach((o, c) => {
85
+ let l = i().registeredVariables[o];
86
+ this.accumulatedMoments[c] ?? (this.accumulatedMoments[c] = {
87
+ originalName: `${o}/m`,
88
+ variable: a(() => t([...l.shape, 2]).variable(!1))
84
89
  });
85
- let f = Array.isArray(t) ? t[o].tensor : t[e];
90
+ let f = Array.isArray(r) ? r[c].tensor : r[o];
86
91
  if (f == null) return;
87
- let p = this.orthGrad ? this.orthogonalizeGradient(d, f) : f, m = this.accumulatedMoments[o].variable, h = l(m, p, this.beta1, this.beta2, u);
92
+ let p = this.orthGrad ? this.orthogonalizeGradient(l, f) : f, m = this.accumulatedMoments[c].variable, h = n(m, p, this.beta1, this.beta2, d);
88
93
  m.assign(h), this.orthGrad && p.dispose();
89
- let g = c(h, d, a, s, this.epsilon ?? 1e-8, this.learningRate, d.shape.length > 1 ? this.weightDecay : 0);
90
- d.assign(g);
91
- }), this.accBeta1 *= this.beta1, this.accBeta2 *= this.beta2, u;
94
+ let g = e(h, l, s, u, this.epsilon ?? 1e-8, this.learningRate, l.shape.length > 1 ? this.weightDecay : 0);
95
+ l.assign(g);
96
+ }), this.accBeta1 *= this.beta1, this.accBeta2 *= this.beta2, d;
92
97
  });
93
- return this.incrementIterations(), s;
98
+ return this.incrementIterations(), u;
94
99
  }
95
100
  dispose() {
96
- this.accumulatedMoments != null && a(this.accumulatedMoments.map((e) => e.variable));
101
+ this.accumulatedMoments != null && r(this.accumulatedMoments.map((e) => e.variable));
97
102
  }
98
103
  async getWeights() {
99
104
  let e = [...this.accumulatedMoments];
@@ -103,7 +108,7 @@ var f = class extends t {
103
108
  })));
104
109
  }
105
110
  async setWeights(e) {
106
- e = await this.extractIterations(e), n(() => {
111
+ e = await this.extractIterations(e), a(() => {
107
112
  this.accBeta1 = this.beta1 ** +(this.iterations_ + 1), this.accBeta2 = this.beta2 ** +(this.iterations_ + 1);
108
113
  });
109
114
  let t = e.length / 2;
@@ -124,5 +129,4 @@ var f = class extends t {
124
129
  return new e(t.learningRate, t.beta1, t.beta2, t.epsilon);
125
130
  }
126
131
  };
127
- //#endregion
128
132
  export { f as AdamWOptimizer };
@@ -1,11 +1,12 @@
1
- import { _n as e, di as t, kt as n, ni as r, oi as i, qt as a } from "../dist-Da20xy8E.js";
2
- import { AdamWOptimizer as o } from "./AdamW.js";
1
+ import e from "./Evaluator.js";
2
+ import { t } from "../zeros-hxKGkRfl.js";
3
+ import { B as n, W as r, Y as i, _ as a, b as o } from "../dist-CMMLi-qO.js";
3
4
  import s from "../utilities/profile.js";
4
- import { calculateAccuracy as c, calculateLoss as l } from "./loss.js";
5
- import u from "./Evaluator.js";
6
- import { createTensorStatistics as d } from "../checks/weights.js";
5
+ import { createTensorStatistics as c } from "../checks/weights.js";
6
+ import { calculateAccuracy as l, calculateLoss as u } from "./loss.js";
7
+ import { AdamWOptimizer as d } from "./AdamW.js";
7
8
  import f from "./configure.js";
8
- //#region lib/training/BasicTrainer.ts
9
+ // lib/training/BasicTrainer.ts
9
10
  var p = {
10
11
  logInterval: 200,
11
12
  maxEpochs: 100,
@@ -44,7 +45,7 @@ var p = {
44
45
  ...n,
45
46
  lossScaling: n?.lossScaling ?? e.lossScaling
46
47
  };
47
- let i = r || new o(this.optimizerConfig);
48
+ let i = r || new d(this.optimizerConfig);
48
49
  r && r.updateConfig(this.optimizerConfig), this.optimizer = i;
49
50
  }
50
51
  setLossMasking() {
@@ -96,7 +97,7 @@ var p = {
96
97
  }), this.optimizer.updateConfig(this.optimizerConfig);
97
98
  }
98
99
  resumeFromLog(e) {
99
- (!this.lastState || this.lastState.step === 0) && (this.lastState = {
100
+ this.lastState && this.lastState.step !== 0 || (this.lastState = {
100
101
  losses: [],
101
102
  validationLosses: [],
102
103
  logStartTime: 0,
@@ -106,44 +107,44 @@ var p = {
106
107
  trainingDuration: e.duration
107
108
  });
108
109
  }
109
- trainStep(n, o, s = !1, u = !1) {
110
- return t(() => {
110
+ trainStep(e, t, s = !1, c = !1) {
111
+ return i(() => {
111
112
  this.model.getProfiler()?.startMemory();
112
- let { xs: t, ys: d } = o, { value: f, grads: p } = a(() => {
113
- let r = this.model.forward({
113
+ let { xs: i, ys: d } = t, { value: f, grads: p } = a(() => {
114
+ let t = this.model.forward({
114
115
  training: !0,
115
116
  checkpointing: this._gradientCheckpointing,
116
117
  mixedPrecision: this._mixedPrecision,
117
118
  dropout: this._dropout,
118
119
  layerDrop: this._layerDrop,
119
120
  ropePositionOffset: 0
120
- }, t), a = l(r, d, this.maskedLoss, !1, this._labelSmoothing);
121
- this.metrics.has("accuracy") && (n.accuracy = c(r, d), i(n.accuracy)), r.dispose();
122
- let o = a.mul(e(this.optimizerConfig.lossScaling));
123
- return a.dispose(), o;
121
+ }, i), n = u(t, d, this.maskedLoss, !1, this._labelSmoothing);
122
+ this.metrics.has("accuracy") && (e.accuracy = l(t, d), r(e.accuracy)), t.dispose();
123
+ let a = n.mul(o(this.optimizerConfig.lossScaling));
124
+ return n.dispose(), a;
124
125
  });
125
126
  if (s) this.model.getProfiler()?.endMemory("Training");
126
127
  else {
127
- let e = this.optimizer.applyGradients(p);
128
- this.metrics.has("gradientNorm") ? (n.gradientNorm = e, i(e)) : (n.gradientNorm = void 0, e.dispose());
129
- let t = Object.keys(p);
130
- this.model.weightStore.touchVariables(t), this.model.getProfiler()?.endMemory("Training"), u ? (n.gradients = p, Object.values(p).forEach((e) => i(e))) : r(p);
128
+ let t = this.optimizer.applyGradients(p);
129
+ this.metrics.has("gradientNorm") ? (e.gradientNorm = t, r(t)) : (e.gradientNorm = void 0, t.dispose());
130
+ let i = Object.keys(p);
131
+ this.model.weightStore.touchVariables(i), this.model.getProfiler()?.endMemory("Training"), c ? (e.gradients = p, Object.values(p).forEach((e) => r(e))) : n(p);
131
132
  }
132
- return f.mul(e(1 / this.optimizerConfig.lossScaling));
133
+ return f.mul(o(1 / this.optimizerConfig.lossScaling));
133
134
  });
134
135
  }
135
136
  async dummyPass() {
136
- let e = n([1, this.model.config.blockSize], "int32"), t = n([1, this.model.config.blockSize], "int32");
137
+ let e = t([1, this.model.config.blockSize], "int32"), n = t([1, this.model.config.blockSize], "int32");
137
138
  try {
138
- let n = this.trainStep({}, {
139
+ let t = this.trainStep({}, {
139
140
  xs: e,
140
- ys: t
141
+ ys: n
141
142
  }, !0);
142
- await n.data(), n.dispose();
143
+ await t.data(), t.dispose();
143
144
  } catch (e) {
144
145
  console.error("Error during dummy pass:", e);
145
146
  } finally {
146
- e.dispose(), t.dispose();
147
+ e.dispose(), n.dispose();
147
148
  }
148
149
  }
149
150
  dispose() {
@@ -164,19 +165,19 @@ var p = {
164
165
  async performLogging(e, t, n, r) {
165
166
  let i = this.metrics.has("gradientStatistics"), a = this.lastState, o = [];
166
167
  o.push(e.data()), o.push(a.accuracy ? a.accuracy.data() : null), o.push(a.gradientNorm ? a.gradientNorm.data() : null);
167
- let s = await Promise.all(o), c = s[0]?.[0] ?? 0, l = s[1] ? s[1][0] : void 0, u = s[2] ? s[2][1] : void 0;
168
- a.lastLoss = c, a.trainingDuration += Date.now() - a.logStartTime;
168
+ let s = await Promise.all(o), l = s[0]?.[0] ?? 0, u = s[1] ? s[1][0] : void 0, d = s[2] ? s[2][1] : void 0;
169
+ a.lastLoss = l, a.trainingDuration += Date.now() - a.logStartTime;
169
170
  let f = a.totalSteps * t * this.model.config.blockSize;
170
171
  this._tokensProcessed = f;
171
172
  let p = {
172
173
  trainingMetrics: {
173
174
  loss: a.lastLoss,
174
175
  perplexity: this.metrics.has("perplexity") ? Math.exp(a.lastLoss) : void 0,
175
- accuracy: l
176
+ accuracy: u
176
177
  },
177
178
  step: a.step,
178
179
  time: Date.now() - a.logStartTime,
179
- gradientNorm: u,
180
+ gradientNorm: d,
180
181
  batchSize: t,
181
182
  learningRate: this.metrics.has("learningRate") ? this.optimizer.lr : void 0,
182
183
  duration: a.trainingDuration,
@@ -193,7 +194,7 @@ var p = {
193
194
  duration: a.trainingDuration
194
195
  }, i && a.gradients) {
195
196
  let e = /* @__PURE__ */ new Map();
196
- for (let [t, n] of Object.entries(a.gradients)) e.set(t, await d(n)), n.dispose();
197
+ for (let [t, n] of Object.entries(a.gradients)) e.set(t, await c(n)), n.dispose();
197
198
  p.gradientMetrics = e;
198
199
  }
199
200
  if (n) try {
@@ -226,49 +227,48 @@ var p = {
226
227
  };
227
228
  this.running = !0;
228
229
  }
229
- async trainOnDataset(e, t, n, i) {
230
- let { logInterval: a = 40, maxEpochs: o = Infinity } = {
230
+ async trainOnDataset(t, r, i, a) {
231
+ let { logInterval: o = 40, maxEpochs: c = Infinity } = {
231
232
  ...p,
232
- ...t
233
- }, c = o * (t?.epochSteps || 1e3);
234
- await this.dummyPass(), t?.metrics?.includes("memoryUsage") && (this.model.getProfiler() || this.model.setProfiler(new s()));
235
- let l = this.lastState;
236
- if (!l) throw Error("Trainer state has not been initialized. Call prepareToTrain() first.");
233
+ ...r
234
+ }, l = c * (r?.epochSteps || 1e3);
235
+ await this.dummyPass(), r?.metrics?.includes("memoryUsage") && (this.model.getProfiler() || this.model.setProfiler(new s()));
236
+ let u = this.lastState;
237
+ if (!u) throw Error("Trainer state has not been initialized. Call prepareToTrain() first.");
237
238
  let d = Date.now();
238
- l.logStartTime = d;
239
- let f = d, m = n ? new u(this.model, n, this.maskedLoss) : void 0, h = await e.iterator(), g = h.next();
239
+ u.logStartTime = d;
240
+ let f = d, m = i ? new e(this.model, i, this.maskedLoss) : void 0, h = await t.iterator(), g = h.next();
240
241
  try {
241
242
  for (; this.running;) {
242
243
  let e = await g;
243
244
  if (g = h.next(), e.done) break;
244
- let n = e.value, r = Date.now(), o = r - f >= a;
245
- o && (f = r);
246
- let s = (t?.metrics?.includes("gradientStatistics") || !1) && o, u = this.trainStep(l, n, !1, s);
247
- if (t.debug) {
248
- let e = (await u.data())[0];
249
- if (isNaN(e) || !isFinite(e)) throw console.error("Invalid loss value:", e), console.error("Batch xs:", await n.xs.array()), console.error("Batch ys:", await n.ys.array()), console.error("State:", l), Error("Loss is NaN or Infinity");
250
- console.log(`Step ${l.step}: Loss = ${e}`);
245
+ let t = e.value, n = Date.now(), i = n - f >= o;
246
+ i && (f = n);
247
+ let s = (r?.metrics?.includes("gradientStatistics") || !1) && i, c = this.trainStep(u, t, !1, s);
248
+ if (r.debug) {
249
+ let e = (await c.data())[0];
250
+ if (isNaN(e) || !isFinite(e)) throw console.error("Invalid loss value:", e), console.error("Batch xs:", await t.xs.array()), console.error("Batch ys:", await t.ys.array()), console.error("State:", u), Error("Loss is NaN or Infinity");
251
+ console.log(`Step ${u.step}: Loss = ${e}`);
251
252
  }
252
- n.xs.dispose(), n.ys.dispose(), l.step++, l.totalSteps++;
253
- let d = l.step >= c;
254
- o || d ? await this.performLogging(u, n.xs.shape[0], m, i) : (l.gradientNorm &&= (l.gradientNorm.dispose(), void 0), l.accuracy &&= (l.accuracy.dispose(), void 0)), u.dispose(), d && this.stop();
253
+ t.xs.dispose(), t.ys.dispose(), u.step++, u.totalSteps++;
254
+ let d = u.step >= l;
255
+ i || d ? await this.performLogging(c, t.xs.shape[0], m, a) : (u.gradientNorm &&= (u.gradientNorm.dispose(), void 0), u.accuracy &&= (u.accuracy.dispose(), void 0)), c.dispose(), d && this.stop();
255
256
  }
256
257
  } catch (e) {
257
- throw console.error("Training error:", e), r(), e;
258
+ throw console.error("Training error:", e), n(), e;
258
259
  }
259
- r(), this.running = !1, this.model.metaData.actionLog = this.model.metaData.actionLog || [];
260
+ n(), this.running = !1, this.model.metaData.actionLog = this.model.metaData.actionLog || [];
260
261
  let _ = Date.now();
261
262
  return this.model.metaData.actionLog.push({
262
263
  action: "pretrain",
263
264
  timestamp: _,
264
265
  duration: _ - d,
265
266
  tokensProcessed: this.tokensProcessed,
266
- options: t
267
+ options: r
267
268
  }), {
268
- losses: l.losses,
269
- validationLosses: l.validationLosses
269
+ losses: u.losses,
270
+ validationLosses: u.validationLosses
270
271
  };
271
272
  }
272
273
  };
273
- //#endregion
274
274
  export { h as default };
@@ -1,2 +1 @@
1
- import { a as e, i as t, n, r, t as i } from "../DatasetBuilder-DU1G1OKX.js";
2
- export { i as DatasetBuilder, n as flattenTokens, r as flattenTokensWithMask, t as moveToNext, e as shuffle };
1
+ export { t as DatasetBuilder, n as flattenTokens, r as flattenTokensWithMask, i as moveToNext, a as shuffle } from "../DatasetBuilder-DRDW8tcM.js";
@@ -1,6 +1,6 @@
1
- import { di as e } from "../dist-Da20xy8E.js";
1
+ import { Y as e } from "../dist-CMMLi-qO.js";
2
2
  import { calculateAccuracy as t, calculateLoss as n } from "./loss.js";
3
- //#region lib/training/Evaluator.ts
3
+ // lib/training/Evaluator.ts
4
4
  var r = class {
5
5
  model;
6
6
  iterator;
@@ -15,7 +15,10 @@ var r = class {
15
15
  }
16
16
  async calculateBatchLoss(r, i, a, o) {
17
17
  let [s, c] = e(() => {
18
- let e = this.model.forward({ training: !1 }, r), s = n(e, i, o, a), c = t(e, i);
18
+ let e = this.model.forward({
19
+ training: !1,
20
+ mixedPrecision: !0
21
+ }, r), s = n(e, i, o, a), c = t(e, i);
19
22
  return e.dispose(), [s, c];
20
23
  }), l = await s.array(), u = await c.array(), d = l, f = u;
21
24
  return c.dispose(), s.dispose(), Array.isArray(d) ? d.map((e) => ({
@@ -40,9 +43,9 @@ var r = class {
40
43
  loss: t / r,
41
44
  accuracy: n / r
42
45
  };
43
- } else if (this.xs && this.ys) return this.calculateBatchLoss(this.xs, this.ys, !0, !0);
46
+ }
47
+ if (this.xs && this.ys) return this.calculateBatchLoss(this.xs, this.ys, !0, !0);
44
48
  throw Error("No data available for evaluation");
45
49
  }
46
50
  };
47
- //#endregion
48
51
  export { r as default };
@@ -1,4 +1,4 @@
1
- //#region lib/training/LRScheduler.ts
1
+ // lib/training/LRScheduler.ts
2
2
  var e = class {
3
3
  learningRate;
4
4
  config;
@@ -34,5 +34,4 @@ var e = class {
34
34
  return this.learningRate = i, this.step++, i;
35
35
  }
36
36
  };
37
- //#endregion
38
37
  export { e as default };
@@ -1,6 +1,6 @@
1
- import { t as e } from "../DatasetBuilder-DU1G1OKX.js";
2
- import t from "./BasicTrainer.js";
3
- //#region lib/training/PreTrainer.ts
1
+ import e from "./BasicTrainer.js";
2
+ import { t } from "../DatasetBuilder-DRDW8tcM.js";
3
+ // lib/training/PreTrainer.ts
4
4
  var n = {
5
5
  decayEpochs: 100,
6
6
  epochSteps: 1e4,
@@ -8,15 +8,14 @@ var n = {
8
8
  minLearningRate: 3e-5,
9
9
  weightDecay: .1,
10
10
  learningRate: 3e-4
11
- }, r = class extends t {
11
+ }, r = class extends e {
12
12
  tokenizer;
13
13
  datasetBuilder;
14
- constructor(t, r, i, a) {
15
- super(t, r, {
14
+ constructor(e, r, i, a) {
15
+ super(e, r, {
16
16
  ...n,
17
17
  ...i
18
- }, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new e(r, t.config.blockSize);
18
+ }, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new t(r, e.config.blockSize);
19
19
  }
20
20
  };
21
- //#endregion
22
21
  export { r as default };
@@ -1,6 +1,6 @@
1
- import { t as e } from "../DatasetBuilder-DU1G1OKX.js";
2
- import t from "./BasicTrainer.js";
3
- //#region lib/training/SFTTrainer.ts
1
+ import e from "./BasicTrainer.js";
2
+ import { t } from "../DatasetBuilder-DRDW8tcM.js";
3
+ // lib/training/SFTTrainer.ts
4
4
  var n = {
5
5
  decayEpochs: 100,
6
6
  epochSteps: 1e4,
@@ -9,16 +9,15 @@ var n = {
9
9
  weightDecay: .1,
10
10
  beta2: .95,
11
11
  learningRate: 3e-4
12
- }, r = class extends t {
12
+ }, r = class extends e {
13
13
  tokenizer;
14
14
  datasetBuilder;
15
15
  loraName;
16
- constructor(t, r, i, a) {
17
- super(t, r, {
16
+ constructor(e, r, i, a) {
17
+ super(e, r, {
18
18
  ...n,
19
19
  ...i
20
- }, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new e(r, t.config.blockSize), this.maskedLoss = !0;
20
+ }, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new t(r, e.config.blockSize), this.maskedLoss = !0;
21
21
  }
22
22
  };
23
- //#endregion
24
23
  export { r as default };