@genai-fi/nanogpt 1.5.0 → 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 (319) 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.js +5 -6
  9. package/dist/api/responses.js +11 -12
  10. package/dist/api/training.js +12 -14
  11. package/dist/axis_util-rF9RnwKE.js +37 -0
  12. package/dist/backend.js +5 -6
  13. package/dist/{backend_util-DAV0I34P.js → backend_util-Cpp0Gwlp.js} +180 -185
  14. package/dist/{binary_op_util-CrYk9LXL.js → binary_op_util-WY9YIl0q.js} +3 -7
  15. package/dist/broadcast_to-CGvLNiQ0.js +20 -0
  16. package/dist/checks/appendCache.js +7 -7
  17. package/dist/checks/attentionMask.js +9 -8
  18. package/dist/checks/check.js +1 -2
  19. package/dist/checks/gelu.js +6 -6
  20. package/dist/checks/index.js +24 -25
  21. package/dist/checks/matMulGelu.js +7 -7
  22. package/dist/checks/normRMS.js +14 -12
  23. package/dist/checks/normRMSGrad.js +9 -8
  24. package/dist/checks/packUnpack.js +7 -7
  25. package/dist/checks/qkv.js +1 -34
  26. package/dist/checks/rope.js +6 -6
  27. package/dist/checks/weights.js +1 -2
  28. package/dist/clip_by_value-D-UX9am5.js +13 -0
  29. package/dist/complex-Cl904TqN.js +13 -0
  30. package/dist/{complex_util-CkazZsaH.js → complex_util-BBlPAm-s.js} +1 -2
  31. package/dist/concat-Oip5acVY.js +14 -0
  32. package/dist/{concat_util-CWzvQQlK.js → concat_util-CY45Hf4F.js} +2 -3
  33. package/dist/data/docx.js +3 -4
  34. package/dist/data/pdf.js +11 -14
  35. package/dist/data/stream.js +1 -2
  36. package/dist/data/textLoader.js +16 -15
  37. package/dist/data-CV_i_H6B.js +11 -0
  38. package/dist/data.js +5 -12
  39. package/dist/dist-CMMLi-qO.js +2675 -0
  40. package/dist/{dist-BGVm64AY.js → dist-DeVH1nGn.js} +1465 -1573
  41. package/dist/{dist-CwK5S7Ls.js → dist-DyL7qSLJ.js} +2664 -2400
  42. package/dist/dropout16-CA31Ud5a.js +20 -0
  43. package/dist/dropout_util-SiFMbFXz.js +22 -0
  44. package/dist/{eventemitter3-D_qV3Lof.js → eventemitter3-wmfmOP_f.js} +2 -3
  45. package/dist/expand_dims-Dh3Fulyn.js +10 -0
  46. package/dist/floor-BwjmUb7X.js +8 -0
  47. package/dist/gather-B5Z1RFt5.js +14 -0
  48. package/dist/gatherSub-CRUfUzBa.js +22 -0
  49. package/dist/gelu-Xx9-ohH9.js +25 -0
  50. package/dist/{gpgpu_math-20tPK8LM.js → gpgpu_math-48m8q3jI.js} +265 -286
  51. package/dist/inference/Beamer.js +34 -27
  52. package/dist/inference/Generator.js +1 -273
  53. package/dist/inference/tokenisePrompt.js +5 -4
  54. package/dist/inference/types.d.ts +6 -0
  55. package/dist/inference/utilities.js +1 -2
  56. package/dist/{jszip.min-DKa1Rjyn.js → jszip.min-Btv48m44.js} +68 -64
  57. package/dist/{kernel_funcs_utils-ql8Y8qPn.js → kernel_funcs_utils-BYRpSfV_.js} +39 -42
  58. package/dist/layers/BaseLayer.js +9 -10
  59. package/dist/layers/GQA.js +45 -44
  60. package/dist/layers/HeadLayer.js +13 -13
  61. package/dist/layers/LoRA.js +17 -20
  62. package/dist/layers/MHA.d.ts +2 -2
  63. package/dist/layers/MHA.js +46 -45
  64. package/dist/layers/MLP.js +22 -21
  65. package/dist/layers/PositionEmbedding.js +14 -13
  66. package/dist/layers/RMSNorm.js +14 -13
  67. package/dist/layers/RoPECache.js +1 -338
  68. package/dist/layers/TiedEmbedding.js +15 -14
  69. package/dist/layers/TransformerBlock.d.ts +3 -9
  70. package/dist/layers/TransformerBlock.js +29 -30
  71. package/dist/layers/WeightStore.js +4 -5
  72. package/dist/layers-CFqEip3s.js +13 -0
  73. package/dist/layers.js +3 -11
  74. package/dist/loader/load.js +27 -24
  75. package/dist/loader/loadHF.js +3 -3
  76. package/dist/loader/loadTransformers.js +5 -6
  77. package/dist/loader/loadZipMeta.js +1 -2
  78. package/dist/loader/newZipLoad.js +1 -2
  79. package/dist/loader/oldZipLoad.js +8 -9
  80. package/dist/loader/save.js +15 -16
  81. package/dist/main.js +3281 -3463
  82. package/dist/{matMul16-CO1QhsRt.js → matMul16-tE26fnhf.js} +29 -27
  83. package/dist/{matMulGelu-CBoqTZM7.js → matMulGelu-ASUWlKqu.js} +33 -33
  84. package/dist/mat_mul-R9_DWmIT.js +16 -0
  85. package/dist/models/Llama.js +48 -49
  86. package/dist/models/NanoGPTV1.js +53 -54
  87. package/dist/models/NanoGPTV2.js +48 -49
  88. package/dist/models/Qwen3.js +48 -49
  89. package/dist/models/config.js +3 -8
  90. package/dist/models/factory.js +7 -8
  91. package/dist/models/model.d.ts +5 -7
  92. package/dist/models/model.js +1 -2
  93. package/dist/models-DyBpJJwM.js +13 -0
  94. package/dist/models.js +6 -14
  95. package/dist/mul16-C7sqgqik.js +41 -0
  96. package/dist/non_max_suppression_impl-B0H318rb.js +72 -0
  97. package/dist/not_equal-Bu3O8rh_.js +67 -0
  98. package/dist/one_hot-TEMPumJj.js +14 -0
  99. package/dist/ones-DpPXWa6A.js +13 -0
  100. package/dist/ops/adamAdjust.js +2 -3
  101. package/dist/ops/adamMoments.js +2 -3
  102. package/dist/ops/add16.js +2 -3
  103. package/dist/ops/appendCache.js +9 -8
  104. package/dist/ops/attentionMask.d.ts +1 -1
  105. package/dist/ops/attentionMask.js +8 -5
  106. package/dist/ops/concat16.js +5 -5
  107. package/dist/ops/cpu/adamAdjust.js +7 -8
  108. package/dist/ops/cpu/adamMoments.js +5 -5
  109. package/dist/ops/cpu/appendCache.js +3 -3
  110. package/dist/ops/cpu/attentionMask.js +12 -8
  111. package/dist/ops/cpu/fusedSoftmax.js +3 -3
  112. package/dist/ops/cpu/gatherSub.js +1 -12
  113. package/dist/ops/cpu/gelu.js +12 -13
  114. package/dist/ops/cpu/matMul16.js +7 -7
  115. package/dist/ops/cpu/matMulGelu.js +21 -18
  116. package/dist/ops/cpu/matMulMul.js +8 -9
  117. package/dist/ops/cpu/mulDropout.js +8 -9
  118. package/dist/ops/cpu/normRMS.js +12 -13
  119. package/dist/ops/cpu/qkv.js +14 -13
  120. package/dist/ops/cpu/rope.js +11 -8
  121. package/dist/ops/cpu/scatterSub.js +1 -12
  122. package/dist/ops/dot16.js +16 -17
  123. package/dist/ops/dropout.js +9 -8
  124. package/dist/ops/dropout16.js +1 -22
  125. package/dist/ops/gatherSub.js +3 -4
  126. package/dist/ops/gelu.js +1 -2
  127. package/dist/ops/globalNorm.js +10 -10
  128. package/dist/ops/grads/add16.js +16 -17
  129. package/dist/ops/grads/attentionMask.js +6 -7
  130. package/dist/ops/grads/dropout16.js +1 -1
  131. package/dist/ops/grads/gelu.js +1 -2
  132. package/dist/ops/grads/matMul16.js +1 -2
  133. package/dist/ops/grads/matMulGelu.js +6 -7
  134. package/dist/ops/grads/mul16.js +1 -1
  135. package/dist/ops/grads/normRMS.js +8 -9
  136. package/dist/ops/grads/pack16.js +1 -2
  137. package/dist/ops/grads/qkv.js +10 -10
  138. package/dist/ops/grads/rope.js +1 -2
  139. package/dist/ops/grads/silu.js +1 -2
  140. package/dist/ops/grads/softmax16.js +6 -7
  141. package/dist/ops/grads/unpack16.js +1 -2
  142. package/dist/ops/grads/utils.js +1 -2
  143. package/dist/ops/matMul16.d.ts +1 -1
  144. package/dist/ops/matMul16.js +1 -2
  145. package/dist/ops/matMulGelu.js +3 -4
  146. package/dist/ops/matMulMul.js +2 -3
  147. package/dist/ops/mul16.js +1 -43
  148. package/dist/ops/mulDrop.js +2 -3
  149. package/dist/ops/normRMS.js +2 -3
  150. package/dist/ops/pack16.js +1 -2
  151. package/dist/ops/qkv.js +2 -3
  152. package/dist/ops/reshape16.js +11 -11
  153. package/dist/ops/rope.js +1 -2
  154. package/dist/ops/scatterSub.js +3 -4
  155. package/dist/ops/silu.js +1 -2
  156. package/dist/ops/slice16.js +5 -5
  157. package/dist/ops/softmax16.js +3 -4
  158. package/dist/ops/sub16.js +3 -4
  159. package/dist/ops/sum16.js +3 -3
  160. package/dist/ops/transpose16.js +16 -15
  161. package/dist/ops/unpack16.js +1 -2
  162. package/dist/ops/webgl/adamAdjust.js +8 -9
  163. package/dist/ops/webgl/adamMoments.js +2 -3
  164. package/dist/ops/webgl/appendCache.js +2 -3
  165. package/dist/ops/webgl/attentionMask.js +2 -3
  166. package/dist/ops/webgl/dropout16.js +2 -3
  167. package/dist/ops/webgl/fusedSoftmax.js +13 -13
  168. package/dist/ops/webgl/gatherSub.js +2 -3
  169. package/dist/ops/webgl/gelu.js +11 -12
  170. package/dist/ops/webgl/log.js +10 -10
  171. package/dist/ops/webgl/matMul16.js +31 -24
  172. package/dist/ops/webgl/matMulGelu.js +1 -2
  173. package/dist/ops/webgl/matMulMul.js +3 -4
  174. package/dist/ops/webgl/mulDropout.js +2 -3
  175. package/dist/ops/webgl/normRMS.js +11 -10
  176. package/dist/ops/webgl/qkv.js +2 -3
  177. package/dist/ops/webgl/rope.js +4 -5
  178. package/dist/ops/webgl/scatterSub.js +2 -3
  179. package/dist/ops/webgpu/adamAdjust.js +13 -14
  180. package/dist/ops/webgpu/adamMoments.js +13 -14
  181. package/dist/ops/webgpu/add16.js +3 -4
  182. package/dist/ops/webgpu/appendCache.js +20 -21
  183. package/dist/ops/webgpu/attentionMask.js +18 -19
  184. package/dist/ops/webgpu/attentionMask32_program.js +7 -8
  185. package/dist/ops/webgpu/clipScale.js +11 -12
  186. package/dist/ops/webgpu/concat16.js +17 -18
  187. package/dist/ops/webgpu/dropout16.js +6 -7
  188. package/dist/ops/webgpu/gatherSub.js +11 -12
  189. package/dist/ops/webgpu/gelu.js +10 -11
  190. package/dist/ops/webgpu/index.js +17 -17
  191. package/dist/ops/webgpu/matMul16.js +74 -63
  192. package/dist/ops/webgpu/matMul16_program.d.ts +2 -1
  193. package/dist/ops/webgpu/matMul16_program.js +29 -21
  194. package/dist/ops/webgpu/mul16.js +3 -4
  195. package/dist/ops/webgpu/norm2.js +9 -10
  196. package/dist/ops/webgpu/normRMS.js +9 -10
  197. package/dist/ops/webgpu/normRMS16_program.js +1 -2
  198. package/dist/ops/webgpu/normRMS32_program.js +1 -2
  199. package/dist/ops/webgpu/normRMSGrad.js +30 -30
  200. package/dist/ops/webgpu/pack16.js +2 -3
  201. package/dist/ops/webgpu/pack16_program.js +3 -4
  202. package/dist/ops/webgpu/qkv.js +10 -11
  203. package/dist/ops/webgpu/rope.js +26 -27
  204. package/dist/ops/webgpu/scatterSub.js +12 -13
  205. package/dist/ops/webgpu/silu.js +10 -11
  206. package/dist/ops/webgpu/slice16.js +17 -18
  207. package/dist/ops/webgpu/softmax16.js +9 -9
  208. package/dist/ops/webgpu/softmax16_program.js +9 -10
  209. package/dist/ops/webgpu/softmax16_subgroup_program.js +11 -12
  210. package/dist/ops/webgpu/softmax16grad.js +8 -9
  211. package/dist/ops/webgpu/sub16.js +3 -4
  212. package/dist/ops/webgpu/sum16.js +16 -15
  213. package/dist/ops/webgpu/transpose16.js +13 -12
  214. package/dist/ops/webgpu/transpose16_program.js +3 -4
  215. package/dist/ops/webgpu/transpose16_shared_program.js +17 -18
  216. package/dist/ops/webgpu/unpack16.js +8 -9
  217. package/dist/ops/webgpu/utils/binary_op.js +20 -21
  218. package/dist/ops/webgpu/utils/deviceInfo.js +1 -2
  219. package/dist/ops/webgpu/utils/reductions.js +21 -20
  220. package/dist/ops-Be5ACU5R.js +13 -0
  221. package/dist/ops-C1UpdEYM.js +509 -0
  222. package/dist/{pack16-BhuXNUS7.js → pack16-BHO4t1-M.js} +14 -17
  223. package/dist/pad-Dy-1IP3A.js +13 -0
  224. package/dist/patches/webgpu_backend.js +18 -19
  225. package/dist/patches/webgpu_base.js +2 -3
  226. package/dist/patches/webgpu_program.js +21 -22
  227. package/dist/{pdf-Bzuk68Vy.js → pdf-CbnQ75VG.js} +380 -701
  228. package/dist/{picomatch-BO4HbNfo.js → picomatch--TW6gyBJ.js} +229 -291
  229. package/dist/qkv-BQfNPucX.js +42 -0
  230. package/dist/rand_util-_vCY93Uw.js +44 -0
  231. package/dist/random_normal-DUIT8kyC.js +11 -0
  232. package/dist/range-CYvQC3fW.js +13 -0
  233. package/dist/relu-C4XULT8A.js +8 -0
  234. package/dist/reshape-DJb1jgMt.js +8 -0
  235. package/dist/resize_nearest_neighbor-DAqcTYUe.js +188 -0
  236. package/dist/{chunk-CWhphoD1.js → rolldown-runtime-CwxnZyOB.js} +4 -5
  237. package/dist/{rope-BPu_uooz.js → rope-JjBVufF_.js} +6 -8
  238. package/dist/scatterSub-BOnqk-uY.js +27 -0
  239. package/dist/scatter_nd_util-BepMCpLY.js +34 -0
  240. package/dist/seedrandom-SHEGFK6H.js +282 -0
  241. package/dist/selu_util-DeOTf-sc.js +27 -0
  242. package/dist/shared-BIDMUBCs.js +1864 -0
  243. package/dist/{shared-CfTzpULd.js → shared-CX_iPI5K.js} +2 -3
  244. package/dist/silu-DsAE2cJ5.js +23 -0
  245. package/dist/slice-Dlb1FlzG.js +13 -0
  246. package/dist/{slice_util-Dve4TkDn.js → slice_util-BVgPRoij.js} +3 -4
  247. package/dist/softmax-Dpav_dWw.js +10 -0
  248. package/dist/split-DYnT8chz.js +11 -0
  249. package/dist/squeeze-B3XYGAlg.js +9 -0
  250. package/dist/stack-Dbbt9mIk.js +10 -0
  251. package/dist/step-DA-5DNu9.js +348 -0
  252. package/dist/{stream-BpAwcvHz.js → stream-BBe2apn4.js} +68 -88
  253. package/dist/sum-C8qNbFNp.js +13 -0
  254. package/dist/tensor-ALxWZfmz.js +7 -0
  255. package/dist/tensor1d-BHgkkhTE.js +9 -0
  256. package/dist/tensor2d-ARItvqVn.js +10 -0
  257. package/dist/tensor4d-D1zRBipJ.js +10 -0
  258. package/dist/tfjs_backend-CsXOum0h.js +685 -0
  259. package/dist/tile-DfyQ0KX-.js +10 -0
  260. package/dist/tokenise-DbS2Ea-T.js +14 -0
  261. package/dist/tokenise.js +6 -15
  262. package/dist/tokeniser/BaseTokeniser.js +5 -9
  263. package/dist/tokeniser/CharTokeniser.js +1 -2
  264. package/dist/tokeniser/bpe.js +19 -20
  265. package/dist/topk-BrU2pkrR.js +19 -0
  266. package/dist/training/AdamW.js +35 -31
  267. package/dist/training/BasicTrainer.js +56 -56
  268. package/dist/training/DatasetBuilder.js +1 -2
  269. package/dist/training/Evaluator.js +4 -4
  270. package/dist/training/LRScheduler.js +1 -2
  271. package/dist/training/PreTrainer.js +7 -8
  272. package/dist/training/SFTTrainer.js +7 -8
  273. package/dist/training/configure.js +16 -15
  274. package/dist/training/factory.js +1 -2
  275. package/dist/training/loss.js +1 -2
  276. package/dist/training/orthoGrad.js +2 -3
  277. package/dist/training/prepareData.js +18 -17
  278. package/dist/training/sparseCrossEntropy.js +38 -32
  279. package/dist/training/tasks/TokenStore.js +21 -22
  280. package/dist/training/tasks/tokenStream.js +1 -2
  281. package/dist/training/validateOptions.js +1 -2
  282. package/dist/training/validation.js +1 -2
  283. package/dist/transpose-BC-M_OoT.js +34 -0
  284. package/dist/unsorted_segment_sum-BelC7R-q.js +408 -0
  285. package/dist/utilities/arrayClose.js +5 -4
  286. package/dist/utilities/arrayShape.js +1 -2
  287. package/dist/utilities/datasetID.js +1 -2
  288. package/dist/utilities/dummy.js +15 -15
  289. package/dist/utilities/float16.js +10 -10
  290. package/dist/utilities/maxHeap.js +1 -2
  291. package/dist/utilities/multinomialCPU.d.ts +1 -2
  292. package/dist/utilities/multinomialCPU.js +6 -8
  293. package/dist/utilities/packed.js +2 -3
  294. package/dist/utilities/parameters.js +3 -4
  295. package/dist/utilities/performance.js +2 -3
  296. package/dist/utilities/profile.js +3 -4
  297. package/dist/utilities/random.js +1 -2
  298. package/dist/utilities/safetensors.js +14 -14
  299. package/dist/utilities/sentences.js +16 -13
  300. package/dist/utilities/tokenParse.js +1 -2
  301. package/dist/utilities/tokens.js +5 -6
  302. package/dist/utilities/topP.d.ts +1 -0
  303. package/dist/utilities/topP.js +20 -13
  304. package/dist/utilities/waitForModel.js +1 -2
  305. package/dist/utilities/weights.js +4 -4
  306. package/dist/utilities/yielder.js +1 -2
  307. package/dist/{v4-BK7K-jy_.js → v4-YCkfo8OR.js} +4 -7
  308. package/dist/{webgpu-IAn9VotJ.js → webgpu-BHX-uBym.js} +156 -163
  309. package/dist/{webgpu_program-B0PokuRJ.js → webgpu_program-DvkFqRlR.js} +28 -29
  310. package/dist/{webgpu_util-DfODg6XI.js → webgpu_util-5QTyovaf.js} +2 -3
  311. package/dist/zeros-hxKGkRfl.js +12 -0
  312. package/package.json +3 -3
  313. package/dist/Reshape-CwxdaU8n.js +0 -17
  314. package/dist/dist-Da20xy8E.js +0 -6375
  315. package/dist/gelu-B6637MKa.js +0 -27
  316. package/dist/selu_util-B_AFEfoz.js +0 -24
  317. package/dist/shared-24EoeHJl.js +0 -1314
  318. package/dist/silu-B6bvCgJ7.js +0 -25
  319. package/dist/tfjs_backend-h5weiy1O.js +0 -614
@@ -1,32 +1,33 @@
1
- import { t as e } from "../v4-BK7K-jy_.js";
2
- //#region lib/training/configure.ts
1
+ import { t as e } from "../v4-YCkfo8OR.js";
2
+ // lib/training/configure.ts
3
3
  function t(t, n) {
4
4
  let r = n?.method.supervised || "full", i = n?.method.type || "pretraining";
5
5
  if (i === "pretraining" && (t.hasLoRA() && t.detachLoRA(), t.weightStore.setTrainable(["*"]), n && (t.metaData.pretrainingSettings = n)), i === "supervised") {
6
6
  if (r === "lora") {
7
7
  if (n?.loraName) {
8
- if (!t.hasLoRA(n.loraName)) if (n.loraConfig) t.createLoRA(n.loraName, n.loraConfig), t.attachLoRA(n.loraName);
9
- else throw Error(`LoRA configuration must be provided to create LoRA with name ${n.loraName}`);
10
- else if (t.attachLoRA(n.loraName), n.loraConfig) {
8
+ if (!t.hasLoRA(n.loraName)) {
9
+ if (n.loraConfig) t.createLoRA(n.loraName, n.loraConfig), t.attachLoRA(n.loraName);
10
+ else throw Error(`LoRA configuration must be provided to create LoRA with name ${n.loraName}`);
11
+ } else if (t.attachLoRA(n.loraName), n.loraConfig) {
11
12
  let e = t.lora;
12
13
  (e.alpha !== n.loraConfig.alpha || e.rank !== n.loraConfig.rank) && (t.detachLoRA(), t.deleteLoRA(n.loraName), t.createLoRA(n.loraName, n.loraConfig), t.attachLoRA(n.loraName), console.warn("Resetting LoRA with new configuration."));
13
14
  }
14
- } else if (n?.loraConfig) if (t.hasLoRA()) {
15
- let r = t.lora;
16
- if (r.alpha !== n.loraConfig.alpha || r.rank !== n.loraConfig.rank) {
17
- t.detachLoRA();
15
+ } else if (n?.loraConfig) {
16
+ if (t.hasLoRA()) {
17
+ let r = t.lora;
18
+ if (r.alpha !== n.loraConfig.alpha || r.rank !== n.loraConfig.rank) {
19
+ t.detachLoRA();
20
+ let r = n.loraName || e();
21
+ t.createLoRA(r, n.loraConfig), t.attachLoRA(r);
22
+ }
23
+ } else {
18
24
  let r = n.loraName || e();
19
25
  t.createLoRA(r, n.loraConfig), t.attachLoRA(r);
20
26
  }
21
- } else {
22
- let r = n.loraName || e();
23
- t.createLoRA(r, n.loraConfig), t.attachLoRA(r);
24
- }
25
- else if (!t.hasLoRA()) throw Error("LoRA configuration must be provided for lora SFT mode");
27
+ } else if (!t.hasLoRA()) throw Error("LoRA configuration must be provided for lora SFT mode");
26
28
  } else t.hasLoRA() && t.detachLoRA();
27
29
  r === "last-layer" ? t.weightStore.setTrainable([`block_${t.config.nLayer - 1}_*`, "token_embedding"]) : r === "full" && t.weightStore.setTrainable(["*"]);
28
30
  }
29
31
  n?.trainableWeights && t.weightStore.setTrainable(n.trainableWeights);
30
32
  }
31
- //#endregion
32
33
  export { t as default };
@@ -1,8 +1,7 @@
1
1
  import e from "./SFTTrainer.js";
2
2
  import t from "./PreTrainer.js";
3
- //#region lib/training/factory.ts
3
+ // lib/training/factory.ts
4
4
  function n(n, r, i, a) {
5
5
  return i?.method.type === "supervised" ? new e(n, r, i, a) : new t(n, r, i, a);
6
6
  }
7
- //#endregion
8
7
  export { n as default };
@@ -1,5 +1,5 @@
1
1
  import { createSoftmaxCrossEntropyWithGrad as e } from "./sparseCrossEntropy.js";
2
- //#region lib/training/loss.ts
2
+ // lib/training/loss.ts
3
3
  function t(t, n, r, i, a) {
4
4
  try {
5
5
  return e(r, i, a && a > 0 ? a : void 0)(t, n);
@@ -15,5 +15,4 @@ function n(e, t) {
15
15
  throw console.error("Error computing accuracy:", e), Error("Accuracy computation failed.", { cause: e });
16
16
  }
17
17
  }
18
- //#endregion
19
18
  export { n as calculateAccuracy, t as calculateLoss };
@@ -1,10 +1,9 @@
1
- import { di as e } from "../dist-Da20xy8E.js";
2
- //#region lib/training/orthoGrad.ts
1
+ import { Y as e } from "../dist-CMMLi-qO.js";
2
+ // lib/training/orthoGrad.ts
3
3
  function t(t, n, r) {
4
4
  return e(() => {
5
5
  let e = t.reshape([-1]), i = n.reshape([-1]), a = e.mul(e).sum().add(r), o = e.mul(i).sum().div(a), s = i.sub(e.mul(o)), c = i.norm(), l = s.norm().add(r);
6
6
  return s.mul(c.div(l)).reshape(n.shape);
7
7
  });
8
8
  }
9
- //#endregion
10
9
  export { t as orthogonalizeGradient };
@@ -1,8 +1,8 @@
1
1
  import { TokenStore as e } from "./tasks/TokenStore.js";
2
2
  import { tokensFromStreams as t } from "./tasks/tokenStream.js";
3
- import { t as n } from "../DatasetBuilder-DU1G1OKX.js";
4
- import { createTrainValidationDatasets as r, storeFromArray as i } from "./validation.js";
5
- //#region lib/training/prepareData.ts
3
+ import { createTrainValidationDatasets as n, storeFromArray as r } from "./validation.js";
4
+ import { t as i } from "../DatasetBuilder-DRDW8tcM.js";
5
+ // lib/training/prepareData.ts
6
6
  async function a(a, o, s, c, l, u, d) {
7
7
  let f = a.loraName || a.loraConfig;
8
8
  if (!d && !f) throw Error("Must specify datasets for non-LoRA training");
@@ -17,28 +17,30 @@ async function a(a, o, s, c, l, u, d) {
17
17
  }))), e ? o.metaData.mode = "conversational" : o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
18
18
  } else o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
19
19
  let p = a.maskedLoss ?? a.method.type === "supervised", m, h = u;
20
- if (Array.isArray(c)) if (c[0] instanceof Uint16Array) m = c;
21
- else {
22
- let e = await t(c, s, l, {
23
- masking: p,
24
- validationSplit: a.validationSplit
25
- });
26
- m = e.trainingTokens, u || (h = e.validationTokens);
27
- }
28
- else m = c;
20
+ if (Array.isArray(c)) {
21
+ if (c[0] instanceof Uint16Array) m = c;
22
+ else {
23
+ let e = await t(c, s, l, {
24
+ masking: p,
25
+ validationSplit: a.validationSplit
26
+ });
27
+ m = e.trainingTokens, u || (h = e.validationTokens);
28
+ }
29
+ } else m = c;
29
30
  console.log("Training tokens", m);
30
31
  let g = m instanceof e ? m.getTokenCount() : m.reduce((e, t) => e + t.length, 0);
31
32
  a.epochSteps = Math.max(1, Math.floor(g / ((a?.batchSize || 32) * o.config.blockSize)));
32
- let _ = new n(s, o.config.blockSize);
33
+ let _ = new i(s, o.config.blockSize);
33
34
  if (h) {
34
- let { trainDataset: e, validationDataset: t } = await r(m, h, s, _, a?.batchSize || 32);
35
+ let { trainDataset: e, validationDataset: t } = await n(m, h, s, _, a?.batchSize || 32);
35
36
  return {
36
37
  trainDataset: e,
37
38
  validationDataset: t,
38
39
  totalTokens: g
39
40
  };
40
- } else {
41
- let t = m instanceof e ? m : await i(m, s);
41
+ }
42
+ {
43
+ let t = m instanceof e ? m : await r(m, s);
42
44
  return {
43
45
  trainDataset: (await _.createTextDataset(t, a)).dataset,
44
46
  validationDataset: void 0,
@@ -46,5 +48,4 @@ async function a(a, o, s, c, l, u, d) {
46
48
  };
47
49
  }
48
50
  }
49
- //#endregion
50
51
  export { a as default };
@@ -1,47 +1,53 @@
1
- import { At as e, Bt as t, Gr as n, Nn as r, Pn as i, Rt as a, St as o, Wr as s, Wt as c, Y as l, _n as u, bn as d, di as f, mn as p, qr as m } from "../dist-Da20xy8E.js";
2
- import { gatherSub as h } from "../ops/gatherSub.js";
3
- import { scatterSub as g } from "../ops/scatterSub.js";
4
- //#region lib/training/sparseCrossEntropy.ts
5
- function _(r, i, o, c, l, u = 0) {
6
- return f(() => {
7
- let f = r.shape[r.shape.length - 1], g = l || r.shape.slice(0, -1), _ = g.reduce((e, t) => e * t, 1), v = r.shape.length > 2 ? r.reshape([_, f]) : r, y = i.shape.length > 1 ? i.reshape([_]).cast("int32") : i.cast("int32"), b = t(v, d(v, -1, !0)), x = a(b, -1), S = h(x, y, b), C;
8
- if (u > 0) {
9
- let n = t(x, e(b, -1));
10
- C = m(s(S, 1 - u), s(n, u));
11
- } else C = S;
12
- if (o) if (C = s(C, o), c) {
13
- let e = p(o.reshape(g), -1);
14
- C = n(p(C.reshape(g), -1), e);
15
- } else {
16
- let e = p(o);
17
- C = n(p(C), e);
18
- }
19
- else C = c ? e(C.reshape(g), -1) : e(C);
20
- return C;
1
+ import { gatherSub as e } from "../ops/gatherSub.js";
2
+ import { n as t, o as n, r, s as i, t as a } from "../not_equal-Bu3O8rh_.js";
3
+ import { t as o } from "../sum-C8qNbFNp.js";
4
+ import { t as s } from "../softmax-Dpav_dWw.js";
5
+ import { scatterSub as c } from "../ops/scatterSub.js";
6
+ import { O as l, S as u, Y as d, b as f, j as p, k as m, m as h, p as g } from "../dist-CMMLi-qO.js";
7
+ // lib/training/sparseCrossEntropy.ts
8
+ function _(i, a, s, c, u, f = 0) {
9
+ return d(() => {
10
+ let d = i.shape[i.shape.length - 1], h = u || i.shape.slice(0, -1), _ = h.reduce((e, t) => e * t, 1), v = i.shape.length > 2 ? i.reshape([_, d]) : i, y = a.shape.length > 1 ? a.reshape([_]).cast("int32") : a.cast("int32"), b = n(v, -1, !0), x = g(v, b), S = r(x, -1), C = e(S, y, x), w;
11
+ if (f > 0) {
12
+ let e = g(S, t(x, -1));
13
+ w = p(l(C, 1 - f), l(e, f));
14
+ } else w = C;
15
+ if (s) {
16
+ if (w = l(w, s), c) {
17
+ let e = o(s.reshape(h), -1);
18
+ w = m(o(w.reshape(h), -1), e);
19
+ } else {
20
+ let e = o(s);
21
+ w = m(o(w), e);
22
+ }
23
+ } else w = c ? t(w.reshape(h), -1) : t(w);
24
+ return w;
21
25
  });
22
26
  }
23
- function v(e, n, a = 0) {
24
- return c((c, d, m) => {
25
- let h = c.shape[c.shape.length - 1], v = c.shape.slice(0, -1), y = v.reduce((e, t) => e * t, 1), b = c.reshape([y, h]), x = d.reshape([y]).cast("int32"), S, C = null;
27
+ function v(e, t, n = 0) {
28
+ return h((r, p, m) => {
29
+ let h = r.shape[r.shape.length - 1], v = r.shape.slice(0, -1), y = v.reduce((e, t) => e * t, 1), b = r.reshape([y, h]), x = p.reshape([y]).cast("int32"), S, C = null;
26
30
  if (e) {
27
- let e = u(65535, "int32"), t = o(x, e);
28
- C = t.cast("float32"), S = i(t, x, r(x)), e.dispose(), t.dispose();
31
+ let e = f(65535, "int32"), t = a(x, e);
32
+ C = t.cast("float32"), S = i(t, x, u(x)), e.dispose(), t.dispose();
29
33
  } else S = x;
30
- let w = _(b, S, C || void 0, n, v, a);
34
+ let w = _(b, S, C || void 0, t, v, n);
31
35
  return m(C ? [
32
36
  b,
33
37
  S,
34
38
  C
35
39
  ] : [b, S]), b.dispose(), x.dispose(), {
36
40
  value: w,
37
- gradFunc: (n, i) => f(() => {
38
- let o = i[0], f = i[1], m = e ? i[2] : void 0, _ = l(o), v = m ? p(m) : u(o.shape[0], "float32"), y = n.div(v).broadcastTo([o.shape[0]]), b = m && e ? s(y, m) : y, x;
39
- x = a > 0 ? g(t(_, a / h), f, s(b, 1 - a)) : g(_, f, b);
40
- let S = r(d);
41
- return [x.reshape(c.shape), S];
41
+ gradFunc: (t, i) => d(() => {
42
+ let a = i[0], d = i[1], m = e ? i[2] : void 0, _ = s(a), v = m ? o(m) : f(a.shape[0], "float32"), y = t.div(v).broadcastTo([a.shape[0]]), b = m && e ? l(y, m) : y, x;
43
+ if (n > 0) {
44
+ let e = n / h, t = g(_, e);
45
+ x = c(t, d, l(b, 1 - n));
46
+ } else x = c(_, d, b);
47
+ let S = u(p);
48
+ return [x.reshape(r.shape), S];
42
49
  })
43
50
  };
44
51
  });
45
52
  }
46
- //#endregion
47
53
  export { v as createSoftmaxCrossEntropyWithGrad, _ as sparseSoftmaxCrossEntropy };
@@ -1,5 +1,5 @@
1
- //#region lib/training/tasks/TokenStore.ts
2
- var e = "llm-tokenstore", t = class {
1
+ // lib/training/tasks/TokenStore.ts
2
+ var e = class {
3
3
  name;
4
4
  tokeniserId;
5
5
  datasetId;
@@ -7,13 +7,13 @@ var e = "llm-tokenstore", t = class {
7
7
  masks;
8
8
  shardCount = 0;
9
9
  lastShardLength = -1;
10
- _shardSize = 8e3 * 1024;
10
+ _shardSize = 8192e3;
11
11
  dirHandle = null;
12
12
  opfsAvailable = !1;
13
13
  lru = /* @__PURE__ */ new Map();
14
14
  maxCachedShards;
15
- constructor(t, n, r, i = 2, a = 8e3 * 1024) {
16
- this.tokeniserId = t, this.datasetId = n, this.maxCachedShards = Math.max(1, Math.trunc(i)), this._shardSize = Math.max(1, Math.trunc(a)), this.name = r ?? e;
15
+ constructor(e, t, n, r = 2, i = 8192e3) {
16
+ this.tokeniserId = e, this.datasetId = t, this.maxCachedShards = Math.max(1, Math.trunc(r)), this._shardSize = Math.max(1, Math.trunc(i)), this.name = n ?? "llm-tokenstore";
17
17
  }
18
18
  get shardSize() {
19
19
  return this._shardSize;
@@ -74,7 +74,7 @@ var e = "llm-tokenstore", t = class {
74
74
  await t.write(JSON.stringify(e)), await t.close();
75
75
  }
76
76
  async readManifest() {
77
- if (!(!this.opfsAvailable || !this.dirHandle)) try {
77
+ if (this.opfsAvailable && this.dirHandle) try {
78
78
  let e = await (await (await this.dirHandle.getFileHandle("manifest.json")).getFile()).text();
79
79
  return JSON.parse(e);
80
80
  } catch {
@@ -98,7 +98,7 @@ var e = "llm-tokenstore", t = class {
98
98
  await r.write(t.buffer), await r.close();
99
99
  }
100
100
  async readShardFromOPFS(e) {
101
- if (!(!this.opfsAvailable || !this.dirHandle)) try {
101
+ if (this.opfsAvailable && this.dirHandle) try {
102
102
  let t = await (await (await this.dirHandle.getFileHandle(this.shardFilename(e))).getFile()).arrayBuffer();
103
103
  return new Uint16Array(t);
104
104
  } catch {
@@ -106,7 +106,7 @@ var e = "llm-tokenstore", t = class {
106
106
  }
107
107
  }
108
108
  async readMaskFromOPFS(e) {
109
- if (!(!this.opfsAvailable || !this.dirHandle)) try {
109
+ if (this.opfsAvailable && this.dirHandle) try {
110
110
  let t = await (await (await this.dirHandle.getFileHandle(this.maskFilename(e))).getFile()).arrayBuffer();
111
111
  return new Uint8Array(t);
112
112
  } catch {
@@ -191,14 +191,14 @@ var e = "llm-tokenstore", t = class {
191
191
  await this.writeManifest();
192
192
  } catch {}
193
193
  }
194
- }, n = /* @__PURE__ */ new Map();
195
- function r(e, t, r) {
196
- let i = n.get(e);
197
- return i && i.tokeniserId === t && i.datasetId === r ? i : null;
194
+ }, t = /* @__PURE__ */ new Map();
195
+ function n(e, n, r) {
196
+ let i = t.get(e);
197
+ return i && i.tokeniserId === n && i.datasetId === r ? i : null;
198
198
  }
199
- async function i(e) {
200
- let t = n.get(e);
201
- if (t) await t.dispose(), n.delete(e);
199
+ async function r(e) {
200
+ let n = t.get(e);
201
+ if (n) await n.dispose(), t.delete(e);
202
202
  else try {
203
203
  let t = globalThis.navigator;
204
204
  if (t?.storage?.getDirectory) {
@@ -207,12 +207,11 @@ async function i(e) {
207
207
  }
208
208
  } catch {}
209
209
  }
210
- async function a(e, r, i, a) {
211
- let o = n.get(e);
210
+ async function i(n, r, i, a) {
211
+ let o = t.get(n);
212
212
  if (o && o.tokeniserId === r && o.datasetId === i) return o;
213
- o && (await o.dispose(), n.delete(e));
214
- let s = new t(r, i, e, a?.maxCachedShards, a?.shardSize);
215
- return a?.noOPFS || await s.init(), n.set(e, s), s;
213
+ o && (await o.dispose(), t.delete(n));
214
+ let s = new e(r, i, n, a?.maxCachedShards, a?.shardSize);
215
+ return a?.noOPFS || await s.init(), t.set(n, s), s;
216
216
  }
217
- //#endregion
218
- export { t as TokenStore, a as createTokenStore, i as deleteTokenStore, r as getTokenStore };
217
+ export { e as TokenStore, i as createTokenStore, r as deleteTokenStore, n as getTokenStore };
@@ -1,6 +1,6 @@
1
1
  import { createTokenStore as e, deleteTokenStore as t } from "./TokenStore.js";
2
2
  import { seededRng as n } from "../../utilities/random.js";
3
- //#region lib/training/tasks/tokenStream.ts
3
+ // lib/training/tasks/tokenStream.ts
4
4
  function r(e, t, n, r, i, a) {
5
5
  let o = n.encodeConversation(e, !1, !!a);
6
6
  if (o) {
@@ -42,5 +42,4 @@ async function i(i, a, o, s) {
42
42
  validationTokens: p ? l : void 0
43
43
  };
44
44
  }
45
- //#endregion
46
45
  export { i as tokensFromStreams };
@@ -1,4 +1,4 @@
1
- //#region lib/training/validateOptions.ts
1
+ // lib/training/validateOptions.ts
2
2
  function e(e, t, n) {
3
3
  let r = new Set(Object.keys(e).filter((t) => e[t] !== n?.[t]));
4
4
  if (t) {
@@ -15,5 +15,4 @@ function e(e, t, n) {
15
15
  ...e
16
16
  };
17
17
  }
18
- //#endregion
19
18
  export { e as default };
@@ -1,5 +1,5 @@
1
1
  import { TokenStore as e, createTokenStore as t } from "./tasks/TokenStore.js";
2
- //#region lib/training/validation.ts
2
+ // lib/training/validation.ts
3
3
  async function n(e, n) {
4
4
  let r = await t("training-tokens", n.id, n.datasetID ?? "");
5
5
  return e.forEach((e) => {
@@ -27,5 +27,4 @@ async function r(t, r, i, a, o) {
27
27
  trainState: d
28
28
  };
29
29
  }
30
- //#endregion
31
30
  export { r as createTrainValidationDatasets, n as storeFromArray };
@@ -0,0 +1,34 @@
1
+ import { Fn as e, Q as t, Y as n, Z as r, br as i, di as a, rt as o, yi as s } from "./dist-CMMLi-qO.js";
2
+ import { t as c } from "./complex-Cl904TqN.js";
3
+ // node_modules/@tensorflow/tfjs-core/dist/ops/imag.js
4
+ function l(n) {
5
+ let r = { input: t(n, "input", "imag") };
6
+ return o.runKernel(e, r);
7
+ }
8
+ var u = /* @__PURE__ */ r({ imag_: l });
9
+ // node_modules/@tensorflow/tfjs-core/dist/ops/neg.js
10
+ function d(e) {
11
+ let n = { x: t(e, "x", "neg") };
12
+ return o.runKernel("Neg", n);
13
+ }
14
+ var f = /* @__PURE__ */ r({ neg_: d });
15
+ // node_modules/@tensorflow/tfjs-core/dist/ops/real.js
16
+ function p(e) {
17
+ let n = { input: t(e, "input", "real") };
18
+ return o.runKernel(i, n);
19
+ }
20
+ var m = /* @__PURE__ */ r({ real_: p });
21
+ // node_modules/@tensorflow/tfjs-core/dist/ops/transpose.js
22
+ function h(e, r, i) {
23
+ let l = t(e, "x", "transpose");
24
+ if (r ??= l.shape.map((e, t) => t).reverse(), s(l.rank === r.length, () => `Error in transpose: rank of input ${l.rank} must match length of perm ${r}.`), r.forEach((e) => {
25
+ s(e >= 0 && e < l.rank, () => `All entries in 'perm' must be between 0 and ${l.rank - 1} but got ${r}`);
26
+ }), l.rank <= 1) return l.clone();
27
+ let d = { x: l }, p = { perm: r };
28
+ return l.dtype === "complex64" ? n(() => {
29
+ let e = m(l), t = u(l);
30
+ return e = o.runKernel(a, { x: e }, p), t = o.runKernel(a, { x: t }, p), i && (t = f(t)), c(e, t);
31
+ }) : o.runKernel(a, d, p);
32
+ }
33
+ var g = /* @__PURE__ */ r({ transpose_: h });
34
+ export { u as i, m as n, f as r, g as t };