@genai-fi/nanogpt 1.6.0 → 1.7.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 (426) hide show
  1. package/dist/{binary_op_util-WY9YIl0q.js → Reshape-CqftURg0.js} +75 -60
  2. package/dist/TeachableLLM.d.ts +12 -12
  3. package/dist/api/beamer.d.ts +4 -4
  4. package/dist/api/responses.d.ts +4 -4
  5. package/dist/api/training.d.ts +9 -9
  6. package/dist/backend.d.ts +1 -1
  7. package/dist/backend_util-DZIc6pyV.js +1081 -0
  8. package/dist/checks/index.d.ts +11 -11
  9. package/dist/checks/weights.d.ts +1 -1
  10. package/dist/data/docx.d.ts +1 -1
  11. package/dist/data/pdf.d.ts +1 -1
  12. package/dist/data/stream.d.ts +1 -1
  13. package/dist/data/textLoader.d.ts +1 -1
  14. package/dist/data.d.ts +3 -3
  15. package/dist/device-CZPGtQBU.js +9 -0
  16. package/dist/device.d.ts +2 -0
  17. package/dist/{dist-DeVH1nGn.js → dist-DiszGjH-.js} +1833 -1844
  18. package/dist/{dist-CMMLi-qO.js → dist-JOPw9zTN.js} +69 -11
  19. package/dist/inference/Beamer.d.ts +3 -3
  20. package/dist/inference/Generator.d.ts +4 -4
  21. package/dist/inference/tokenisePrompt.d.ts +2 -2
  22. package/dist/inference/types.d.ts +1 -1
  23. package/dist/inference/utilities.d.ts +1 -1
  24. package/dist/layers/BaseLayer.d.ts +5 -4
  25. package/dist/layers/GQA.d.ts +24 -26
  26. package/dist/layers/HeadLayer.d.ts +2 -2
  27. package/dist/layers/LoRA.d.ts +1 -1
  28. package/dist/layers/MHA.d.ts +3 -4
  29. package/dist/layers/MLP.d.ts +2 -2
  30. package/dist/layers/PositionEmbedding.d.ts +3 -3
  31. package/dist/layers/RMSNorm.d.ts +2 -2
  32. package/dist/layers/RoPECache.d.ts +2 -1
  33. package/dist/layers/TiedEmbedding.d.ts +2 -2
  34. package/dist/layers/TransformerBlock.d.ts +9 -6
  35. package/dist/layers.d.ts +4 -4
  36. package/dist/loader/load.d.ts +1 -1
  37. package/dist/loader/loadHF.d.ts +3 -3
  38. package/dist/loader/loadTransformers.d.ts +2 -2
  39. package/dist/loader/loadZipMeta.d.ts +2 -2
  40. package/dist/loader/newZipLoad.d.ts +2 -2
  41. package/dist/loader/oldZipLoad.d.ts +4 -4
  42. package/dist/loader/save.d.ts +5 -5
  43. package/dist/loader/types.d.ts +23 -10
  44. package/dist/main.d.ts +40 -24
  45. package/dist/matMul16-CiMKJM8v.js +2610 -0
  46. package/dist/models/Llama.d.ts +2 -2
  47. package/dist/models/LoopNano.d.ts +16 -0
  48. package/dist/models/NanoGPTV1.d.ts +2 -2
  49. package/dist/models/NanoGPTV2.d.ts +2 -2
  50. package/dist/models/Qwen3.d.ts +2 -2
  51. package/dist/models/config.d.ts +11 -1
  52. package/dist/models/factory.d.ts +2 -2
  53. package/dist/models/model.d.ts +6 -6
  54. package/dist/models.d.ts +4 -4
  55. package/dist/nanogpt.js +37041 -0
  56. package/dist/ops/adamAdjust.d.ts +2 -0
  57. package/dist/ops/adamMoments.d.ts +2 -0
  58. package/dist/ops/adamW.d.ts +2 -0
  59. package/dist/ops/add16.d.ts +1 -0
  60. package/dist/ops/appendCache.d.ts +2 -0
  61. package/dist/ops/attentionMask.d.ts +11 -1
  62. package/dist/ops/dropout16.d.ts +2 -0
  63. package/dist/ops/gatherSub.d.ts +2 -0
  64. package/dist/ops/gelu.d.ts +3 -0
  65. package/dist/ops/log.d.ts +1 -0
  66. package/dist/ops/matMul16.d.ts +4 -0
  67. package/dist/ops/matMulGelu.d.ts +3 -0
  68. package/dist/ops/matMulMul.d.ts +2 -0
  69. package/dist/ops/mul16.d.ts +1 -0
  70. package/dist/ops/mulDrop.d.ts +2 -0
  71. package/dist/ops/normRMS.d.ts +3 -0
  72. package/dist/ops/pack16.d.ts +1 -0
  73. package/dist/ops/qkv.d.ts +13 -1
  74. package/dist/ops/rope.d.ts +4 -1
  75. package/dist/ops/scatterSub.d.ts +4 -1
  76. package/dist/ops/silu.d.ts +1 -0
  77. package/dist/ops/softmax16.d.ts +1 -0
  78. package/dist/ops/sparseCrossEntropy.d.ts +15 -0
  79. package/dist/ops/unpack16.d.ts +1 -0
  80. package/dist/ops/webgl/sparseCrossEntropy.d.ts +1 -0
  81. package/dist/ops/webgpu/adamW.d.ts +1 -0
  82. package/dist/ops/webgpu/concat16.d.ts +16 -0
  83. package/dist/ops/webgpu/index.d.ts +29 -0
  84. package/dist/ops/webgpu/normRMS16_program.d.ts +2 -2
  85. package/dist/ops/webgpu/normRMS32_program.d.ts +2 -2
  86. package/dist/ops/webgpu/pack16_program.d.ts +1 -1
  87. package/dist/ops/webgpu/softmax16_program.d.ts +16 -0
  88. package/dist/ops/webgpu/sparseCrossEntropy.d.ts +1 -0
  89. package/dist/ops/webgpu/utils/binary_op.d.ts +16 -0
  90. package/dist/ops/webgpu/utils/deviceInfo.d.ts +1 -1
  91. package/dist/ops/webgpu/utils/reductions.d.ts +1 -1
  92. package/dist/patches/webgpu_backend.d.ts +2 -1
  93. package/dist/patches/webgpu_base.d.ts +0 -1
  94. package/dist/patches/webgpu_program.d.ts +21 -0
  95. package/dist/{shared-BIDMUBCs.js → shared-BARkvvG4.js} +587 -505
  96. package/dist/tokenise.d.ts +4 -4
  97. package/dist/tokeniser/BaseTokeniser.d.ts +3 -3
  98. package/dist/tokeniser/CharTokeniser.d.ts +2 -2
  99. package/dist/tokeniser/bpe.d.ts +2 -2
  100. package/dist/tokeniser/type.d.ts +2 -2
  101. package/dist/training/AdamW.d.ts +19 -2
  102. package/dist/training/BasicTrainer.d.ts +5 -5
  103. package/dist/training/DatasetBuilder.d.ts +2 -2
  104. package/dist/training/Evaluator.d.ts +1 -1
  105. package/dist/training/LRScheduler.d.ts +1 -1
  106. package/dist/training/PreTrainer.d.ts +6 -6
  107. package/dist/training/SFTTrainer.d.ts +6 -6
  108. package/dist/training/configure.d.ts +2 -2
  109. package/dist/training/factory.d.ts +6 -5
  110. package/dist/training/prepareData.d.ts +6 -6
  111. package/dist/training/tasks/tokenStream.d.ts +3 -3
  112. package/dist/training/types.d.ts +6 -5
  113. package/dist/training/validateOptions.d.ts +1 -1
  114. package/dist/training/validation.d.ts +3 -3
  115. package/dist/utilities/datasetID.d.ts +1 -1
  116. package/dist/utilities/dummy.d.ts +1 -1
  117. package/dist/utilities/packed.d.ts +1 -1
  118. package/dist/utilities/parameters.d.ts +1 -1
  119. package/dist/utilities/sentences.d.ts +1 -1
  120. package/dist/utilities/waitForModel.d.ts +1 -1
  121. package/dist/webgpu-D4syGmzo.js +3221 -0
  122. package/dist/webgpu-wUCQopBN.js +1007 -0
  123. package/dist/{webgpu_program-DvkFqRlR.js → webgpu_backend-CzY9TzvA.js} +174 -223
  124. package/dist/{patches/webgpu_base.js → webgpu_base-Bjg7okYf.js} +6 -9
  125. package/package.json +12 -9
  126. package/dist/DatasetBuilder-DRDW8tcM.js +0 -731
  127. package/dist/Generator-BcR_14Cj.js +0 -316
  128. package/dist/RealDiv-Cl8k3YTx.js +0 -354
  129. package/dist/Reshape-CKxKPKqi.js +0 -91
  130. package/dist/Reshape-H5zZRgr9.js +0 -16
  131. package/dist/RoPECache-dYscFINl.js +0 -722
  132. package/dist/TeachableLLM.js +0 -220
  133. package/dist/api/beamer.js +0 -61
  134. package/dist/api/responses.js +0 -177
  135. package/dist/api/training.js +0 -215
  136. package/dist/axis_util-rF9RnwKE.js +0 -37
  137. package/dist/backend.js +0 -12
  138. package/dist/backend_util-Cpp0Gwlp.js +0 -394
  139. package/dist/broadcast_to-CGvLNiQ0.js +0 -20
  140. package/dist/checks/appendCache.js +0 -55
  141. package/dist/checks/attentionMask.js +0 -57
  142. package/dist/checks/check.js +0 -31
  143. package/dist/checks/gelu.js +0 -46
  144. package/dist/checks/index.js +0 -27
  145. package/dist/checks/matMulGelu.js +0 -84
  146. package/dist/checks/normRMS.js +0 -30
  147. package/dist/checks/normRMSGrad.js +0 -23
  148. package/dist/checks/packUnpack.js +0 -46
  149. package/dist/checks/qkv.js +0 -1
  150. package/dist/checks/rope.js +0 -30
  151. package/dist/checks/weights.js +0 -26
  152. package/dist/clip_by_value-D-UX9am5.js +0 -13
  153. package/dist/complex-Cl904TqN.js +0 -13
  154. package/dist/complex_util-BBlPAm-s.js +0 -59
  155. package/dist/concat-Oip5acVY.js +0 -14
  156. package/dist/concat_util-CY45Hf4F.js +0 -18
  157. package/dist/data/docx.js +0 -17
  158. package/dist/data/pdf.js +0 -14
  159. package/dist/data/stream.js +0 -1
  160. package/dist/data/textLoader.js +0 -575
  161. package/dist/data-CV_i_H6B.js +0 -11
  162. package/dist/data.js +0 -5
  163. package/dist/dist-DyL7qSLJ.js +0 -7809
  164. package/dist/dropout16-CA31Ud5a.js +0 -20
  165. package/dist/dropout_util-SiFMbFXz.js +0 -22
  166. package/dist/eventemitter3-wmfmOP_f.js +0 -90
  167. package/dist/expand_dims-Dh3Fulyn.js +0 -10
  168. package/dist/floor-BwjmUb7X.js +0 -8
  169. package/dist/gather-B5Z1RFt5.js +0 -14
  170. package/dist/gatherSub-CRUfUzBa.js +0 -22
  171. package/dist/gelu-Xx9-ohH9.js +0 -25
  172. package/dist/gpgpu_math-48m8q3jI.js +0 -1591
  173. package/dist/inference/Beamer.js +0 -215
  174. package/dist/inference/Generator.js +0 -1
  175. package/dist/inference/tokenisePrompt.js +0 -17
  176. package/dist/inference/types.js +0 -0
  177. package/dist/inference/utilities.js +0 -31
  178. package/dist/jszip.min-Btv48m44.js +0 -3037
  179. package/dist/kernel_funcs_utils-BYRpSfV_.js +0 -229
  180. package/dist/layers/BaseLayer.js +0 -75
  181. package/dist/layers/GQA.js +0 -102
  182. package/dist/layers/HeadLayer.js +0 -28
  183. package/dist/layers/LoRA.js +0 -45
  184. package/dist/layers/MHA.js +0 -102
  185. package/dist/layers/MLP.js +0 -47
  186. package/dist/layers/PositionEmbedding.js +0 -28
  187. package/dist/layers/RMSNorm.js +0 -25
  188. package/dist/layers/RoPECache.js +0 -1
  189. package/dist/layers/TiedEmbedding.js +0 -33
  190. package/dist/layers/TransformerBlock.js +0 -50
  191. package/dist/layers/WeightStore.js +0 -68
  192. package/dist/layers-CFqEip3s.js +0 -13
  193. package/dist/layers.js +0 -6
  194. package/dist/loader/load.js +0 -63
  195. package/dist/loader/loadHF.js +0 -17
  196. package/dist/loader/loadTransformers.js +0 -61
  197. package/dist/loader/loadZipMeta.js +0 -15
  198. package/dist/loader/newZipLoad.js +0 -24
  199. package/dist/loader/oldZipLoad.js +0 -36
  200. package/dist/loader/save.js +0 -89
  201. package/dist/loader/types.js +0 -0
  202. package/dist/main.js +0 -12145
  203. package/dist/matMul16-tE26fnhf.js +0 -87
  204. package/dist/matMulGelu-ASUWlKqu.js +0 -162
  205. package/dist/mat_mul-R9_DWmIT.js +0 -16
  206. package/dist/models/Llama.js +0 -88
  207. package/dist/models/NanoGPTV1.js +0 -94
  208. package/dist/models/NanoGPTV2.js +0 -85
  209. package/dist/models/Qwen3.js +0 -88
  210. package/dist/models/config.js +0 -32
  211. package/dist/models/factory.js +0 -16
  212. package/dist/models/model.js +0 -75
  213. package/dist/models-DyBpJJwM.js +0 -13
  214. package/dist/models.js +0 -6
  215. package/dist/mul16-C7sqgqik.js +0 -41
  216. package/dist/non_max_suppression_impl-B0H318rb.js +0 -72
  217. package/dist/not_equal-Bu3O8rh_.js +0 -67
  218. package/dist/one_hot-TEMPumJj.js +0 -14
  219. package/dist/ones-DpPXWa6A.js +0 -13
  220. package/dist/ops/adamAdjust.js +0 -17
  221. package/dist/ops/adamMoments.js +0 -15
  222. package/dist/ops/add16.js +0 -11
  223. package/dist/ops/appendCache.js +0 -26
  224. package/dist/ops/attentionMask.js +0 -19
  225. package/dist/ops/concat16.js +0 -8
  226. package/dist/ops/cpu/adamAdjust.js +0 -15
  227. package/dist/ops/cpu/adamMoments.js +0 -16
  228. package/dist/ops/cpu/appendCache.js +0 -65
  229. package/dist/ops/cpu/attentionMask.js +0 -20
  230. package/dist/ops/cpu/fusedSoftmax.js +0 -22
  231. package/dist/ops/cpu/gatherSub.js +0 -1
  232. package/dist/ops/cpu/gelu.js +0 -35
  233. package/dist/ops/cpu/matMul16.js +0 -14
  234. package/dist/ops/cpu/matMulGelu.js +0 -44
  235. package/dist/ops/cpu/matMulMul.js +0 -19
  236. package/dist/ops/cpu/mulDropout.js +0 -19
  237. package/dist/ops/cpu/normRMS.js +0 -34
  238. package/dist/ops/cpu/qkv.js +0 -74
  239. package/dist/ops/cpu/rope.js +0 -84
  240. package/dist/ops/cpu/scatterSub.js +0 -1
  241. package/dist/ops/dot16.js +0 -28
  242. package/dist/ops/dropout.js +0 -12
  243. package/dist/ops/dropout16.js +0 -1
  244. package/dist/ops/gatherSub.js +0 -12
  245. package/dist/ops/gelu.js +0 -1
  246. package/dist/ops/globalNorm.js +0 -19
  247. package/dist/ops/grads/add16.js +0 -26
  248. package/dist/ops/grads/attentionMask.js +0 -25
  249. package/dist/ops/grads/dropout16.js +0 -1
  250. package/dist/ops/grads/gelu.js +0 -1
  251. package/dist/ops/grads/matMul16.js +0 -1
  252. package/dist/ops/grads/matMulGelu.js +0 -21
  253. package/dist/ops/grads/mul16.js +0 -1
  254. package/dist/ops/grads/normRMS.js +0 -36
  255. package/dist/ops/grads/pack16.js +0 -1
  256. package/dist/ops/grads/qkv.js +0 -46
  257. package/dist/ops/grads/rope.js +0 -1
  258. package/dist/ops/grads/silu.js +0 -1
  259. package/dist/ops/grads/softmax16.js +0 -22
  260. package/dist/ops/grads/unpack16.js +0 -1
  261. package/dist/ops/grads/utils.js +0 -11
  262. package/dist/ops/log.js +0 -1
  263. package/dist/ops/matMul16.js +0 -1
  264. package/dist/ops/matMulGelu.js +0 -19
  265. package/dist/ops/matMulMul.js +0 -15
  266. package/dist/ops/mul16.js +0 -1
  267. package/dist/ops/mulDrop.js +0 -14
  268. package/dist/ops/normRMS.js +0 -21
  269. package/dist/ops/pack16.js +0 -1
  270. package/dist/ops/qkv.js +0 -15
  271. package/dist/ops/reshape16.js +0 -33
  272. package/dist/ops/rope.js +0 -1
  273. package/dist/ops/scatterSub.js +0 -12
  274. package/dist/ops/silu.js +0 -1
  275. package/dist/ops/slice16.js +0 -11
  276. package/dist/ops/softmax16.js +0 -8
  277. package/dist/ops/sub16.js +0 -10
  278. package/dist/ops/sum16.js +0 -13
  279. package/dist/ops/transpose16.js +0 -33
  280. package/dist/ops/unpack16.js +0 -1
  281. package/dist/ops/webgl/adamAdjust.js +0 -81
  282. package/dist/ops/webgl/adamMoments.js +0 -43
  283. package/dist/ops/webgl/appendCache.js +0 -52
  284. package/dist/ops/webgl/attentionMask.js +0 -63
  285. package/dist/ops/webgl/dropout16.js +0 -11
  286. package/dist/ops/webgl/fusedSoftmax.js +0 -70
  287. package/dist/ops/webgl/gatherSub.js +0 -27
  288. package/dist/ops/webgl/gelu.js +0 -47
  289. package/dist/ops/webgl/log.js +0 -14
  290. package/dist/ops/webgl/matMul16.js +0 -48
  291. package/dist/ops/webgl/matMulGelu.js +0 -1
  292. package/dist/ops/webgl/matMulMul.js +0 -23
  293. package/dist/ops/webgl/mulDropout.js +0 -31
  294. package/dist/ops/webgl/normRMS.js +0 -115
  295. package/dist/ops/webgl/qkv.js +0 -53
  296. package/dist/ops/webgl/rope.js +0 -73
  297. package/dist/ops/webgl/scatterSub.js +0 -27
  298. package/dist/ops/webgpu/adamAdjust.js +0 -76
  299. package/dist/ops/webgpu/adamMoments.js +0 -75
  300. package/dist/ops/webgpu/add16.js +0 -13
  301. package/dist/ops/webgpu/appendCache.js +0 -129
  302. package/dist/ops/webgpu/attentionMask.js +0 -41
  303. package/dist/ops/webgpu/attentionMask32_program.js +0 -61
  304. package/dist/ops/webgpu/clipScale.js +0 -44
  305. package/dist/ops/webgpu/concat16.js +0 -110
  306. package/dist/ops/webgpu/dropout16.js +0 -58
  307. package/dist/ops/webgpu/gatherSub.js +0 -51
  308. package/dist/ops/webgpu/gelu.js +0 -146
  309. package/dist/ops/webgpu/index.js +0 -27
  310. package/dist/ops/webgpu/matMul16.js +0 -91
  311. package/dist/ops/webgpu/matMul16_program.js +0 -311
  312. package/dist/ops/webgpu/mul16.js +0 -13
  313. package/dist/ops/webgpu/norm2.js +0 -45
  314. package/dist/ops/webgpu/normRMS.js +0 -25
  315. package/dist/ops/webgpu/normRMS16_program.js +0 -28
  316. package/dist/ops/webgpu/normRMS32_program.js +0 -28
  317. package/dist/ops/webgpu/normRMSGrad.js +0 -225
  318. package/dist/ops/webgpu/pack16.js +0 -20
  319. package/dist/ops/webgpu/pack16_program.js +0 -92
  320. package/dist/ops/webgpu/qkv.js +0 -63
  321. package/dist/ops/webgpu/rope.js +0 -227
  322. package/dist/ops/webgpu/scatterSub.js +0 -52
  323. package/dist/ops/webgpu/silu.js +0 -117
  324. package/dist/ops/webgpu/slice16.js +0 -73
  325. package/dist/ops/webgpu/softmax16.js +0 -18
  326. package/dist/ops/webgpu/softmax16_program.js +0 -88
  327. package/dist/ops/webgpu/softmax16_subgroup_program.js +0 -69
  328. package/dist/ops/webgpu/softmax16grad.js +0 -30
  329. package/dist/ops/webgpu/sub16.js +0 -13
  330. package/dist/ops/webgpu/sum16.js +0 -30
  331. package/dist/ops/webgpu/transpose16.js +0 -38
  332. package/dist/ops/webgpu/transpose16_program.js +0 -50
  333. package/dist/ops/webgpu/transpose16_shared_program.js +0 -78
  334. package/dist/ops/webgpu/unpack16.js +0 -59
  335. package/dist/ops/webgpu/utils/binary_op.js +0 -140
  336. package/dist/ops/webgpu/utils/deviceInfo.js +0 -10
  337. package/dist/ops/webgpu/utils/reductions.js +0 -264
  338. package/dist/ops-Be5ACU5R.js +0 -13
  339. package/dist/ops-C1UpdEYM.js +0 -509
  340. package/dist/pack16-BHO4t1-M.js +0 -36
  341. package/dist/pad-Dy-1IP3A.js +0 -13
  342. package/dist/patches/webgpu_backend.js +0 -42
  343. package/dist/patches/webgpu_program.js +0 -292
  344. package/dist/picomatch--TW6gyBJ.js +0 -999
  345. package/dist/qkv-BQfNPucX.js +0 -42
  346. package/dist/rand_util-_vCY93Uw.js +0 -44
  347. package/dist/random_normal-DUIT8kyC.js +0 -11
  348. package/dist/range-CYvQC3fW.js +0 -13
  349. package/dist/relu-C4XULT8A.js +0 -8
  350. package/dist/reshape-DJb1jgMt.js +0 -8
  351. package/dist/resize_nearest_neighbor-DAqcTYUe.js +0 -188
  352. package/dist/rope-JjBVufF_.js +0 -24
  353. package/dist/scatterSub-BOnqk-uY.js +0 -27
  354. package/dist/scatter_nd_util-BepMCpLY.js +0 -34
  355. package/dist/seedrandom-SHEGFK6H.js +0 -282
  356. package/dist/selu_util-DeOTf-sc.js +0 -27
  357. package/dist/shared-CX_iPI5K.js +0 -4
  358. package/dist/silu-DsAE2cJ5.js +0 -23
  359. package/dist/slice-Dlb1FlzG.js +0 -13
  360. package/dist/slice_util-BVgPRoij.js +0 -207
  361. package/dist/softmax-Dpav_dWw.js +0 -10
  362. package/dist/split-DYnT8chz.js +0 -11
  363. package/dist/squeeze-B3XYGAlg.js +0 -9
  364. package/dist/stack-Dbbt9mIk.js +0 -10
  365. package/dist/step-DA-5DNu9.js +0 -348
  366. package/dist/stream-BBe2apn4.js +0 -2280
  367. package/dist/sum-C8qNbFNp.js +0 -13
  368. package/dist/tensor-ALxWZfmz.js +0 -7
  369. package/dist/tensor1d-BHgkkhTE.js +0 -9
  370. package/dist/tensor2d-ARItvqVn.js +0 -10
  371. package/dist/tensor4d-D1zRBipJ.js +0 -10
  372. package/dist/tfjs_backend-CsXOum0h.js +0 -685
  373. package/dist/tile-DfyQ0KX-.js +0 -10
  374. package/dist/tokenise-DbS2Ea-T.js +0 -14
  375. package/dist/tokenise.js +0 -6
  376. package/dist/tokeniser/BaseTokeniser.js +0 -137
  377. package/dist/tokeniser/CharTokeniser.js +0 -85
  378. package/dist/tokeniser/bpe.js +0 -156
  379. package/dist/tokeniser/messages.js +0 -0
  380. package/dist/tokeniser/type.js +0 -0
  381. package/dist/topk-BrU2pkrR.js +0 -19
  382. package/dist/training/AdamW.js +0 -132
  383. package/dist/training/BasicTrainer.js +0 -274
  384. package/dist/training/DatasetBuilder.js +0 -1
  385. package/dist/training/Evaluator.js +0 -51
  386. package/dist/training/LRScheduler.js +0 -37
  387. package/dist/training/PreTrainer.js +0 -21
  388. package/dist/training/SFTTrainer.js +0 -23
  389. package/dist/training/configure.js +0 -33
  390. package/dist/training/factory.js +0 -7
  391. package/dist/training/loss.js +0 -18
  392. package/dist/training/orthoGrad.js +0 -9
  393. package/dist/training/prepareData.js +0 -51
  394. package/dist/training/sparseCrossEntropy.js +0 -53
  395. package/dist/training/tasks/TokenStore.js +0 -217
  396. package/dist/training/tasks/tokenStream.js +0 -45
  397. package/dist/training/types.js +0 -0
  398. package/dist/training/validateOptions.js +0 -18
  399. package/dist/training/validation.js +0 -30
  400. package/dist/transpose-BC-M_OoT.js +0 -34
  401. package/dist/unsorted_segment_sum-BelC7R-q.js +0 -408
  402. package/dist/utilities/arrayClose.js +0 -29
  403. package/dist/utilities/arrayShape.js +0 -7
  404. package/dist/utilities/datasetID.js +0 -17
  405. package/dist/utilities/dummy.js +0 -36
  406. package/dist/utilities/float16.js +0 -46
  407. package/dist/utilities/maxHeap.js +0 -54
  408. package/dist/utilities/multinomialCPU.js +0 -7
  409. package/dist/utilities/naming.js +0 -0
  410. package/dist/utilities/packed.js +0 -12
  411. package/dist/utilities/parameters.js +0 -53
  412. package/dist/utilities/performance.js +0 -15
  413. package/dist/utilities/profile.js +0 -32
  414. package/dist/utilities/random.js +0 -18
  415. package/dist/utilities/safetensors.js +0 -63
  416. package/dist/utilities/sentences.js +0 -35
  417. package/dist/utilities/tokenParse.js +0 -16
  418. package/dist/utilities/tokens.js +0 -39
  419. package/dist/utilities/topP.js +0 -25
  420. package/dist/utilities/waitForModel.js +0 -11
  421. package/dist/utilities/weights.js +0 -40
  422. package/dist/utilities/yielder.js +0 -6
  423. package/dist/v4-YCkfo8OR.js +0 -27
  424. package/dist/webgpu-BHX-uBym.js +0 -518
  425. package/dist/webgpu_util-5QTyovaf.js +0 -105
  426. package/dist/zeros-hxKGkRfl.js +0 -12
@@ -1,731 +0,0 @@
1
- import { i as e } from "./rolldown-runtime-CwxnZyOB.js";
2
- import { B as t, F as n, Y as r, _i as i, _t as a, at as o, ot as s, ut as c, vt as l, yi as ee } from "./dist-CMMLi-qO.js";
3
- import { t as u } from "./tensor-ALxWZfmz.js";
4
- import { t as d } from "./seedrandom-SHEGFK6H.js";
5
- import { t as f } from "./stack-Dbbt9mIk.js";
6
- // node_modules/@tensorflow/tfjs-data/dist/util/deep_map.js
7
- var p = /* @__PURE__ */ e(d());
8
- function m(e, t) {
9
- return h(e, t);
10
- }
11
- function h(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
12
- if (e == null) return null;
13
- if (typeof Blob == "function" && e instanceof Blob) return e.slice();
14
- if (r.has(e)) throw Error("Circular references are not supported.");
15
- if (n.has(e)) return n.get(e);
16
- let i = t(e);
17
- if (i.recurse && i.value !== null) throw Error("A deep map function may not return both a value and recurse=true.");
18
- if (!i.recurse) return n.set(e, i.value), i.value;
19
- if (v(e)) {
20
- let i = Array.isArray(e) ? [] : {};
21
- r.add(e);
22
- for (let a in e) {
23
- let o = e[a];
24
- i[a] = h(o, t, n, r);
25
- }
26
- return r.delete(e), e.__proto__ && (i.__proto__ = e.__proto__), i;
27
- }
28
- throw Error(`Can't recurse into non-iterable type: ${e}`);
29
- }
30
- function te(e, t = _) {
31
- return g(e, t);
32
- }
33
- function g(e, t, n = /* @__PURE__ */ new Set()) {
34
- let r = e[0];
35
- if (n.has(r)) throw Error("Circular references are not supported.");
36
- let i = t(e);
37
- if (i.recurse && i.value !== null) throw Error("A deep zip function may not return both a value and recurse=true.");
38
- if (!i.recurse) return i.value;
39
- if (v(r)) {
40
- let i = Array.isArray(r) ? [] : {};
41
- n.add(r);
42
- for (let a in r) i[a] = g(e.map((e) => e[a]), t, n);
43
- return n.delete(r), i;
44
- }
45
- throw Error(`Can't recurse into non-iterable type: ${r}`);
46
- }
47
- function _(e) {
48
- return e === null ? null : v(e[0]) ? {
49
- value: null,
50
- recurse: !0
51
- } : {
52
- value: e,
53
- recurse: !1
54
- };
55
- }
56
- function v(e) {
57
- let t = !1;
58
- if (i().get("IS_BROWSER")) t = e instanceof TextDecoder;
59
- else {
60
- let { StringDecoder: r } = n();
61
- t = e instanceof r;
62
- }
63
- return e != null && !ArrayBuffer.isView(e) && (Array.isArray(e) || typeof e == "object" && !(e instanceof c) && !(e instanceof Promise) && !t);
64
- }
65
- function y(e) {
66
- return e == null || b(e) || Array.isArray(e) || typeof e == "object" && e instanceof c || a(e);
67
- }
68
- function b(e) {
69
- return e === null || typeof e != "object" && typeof e != "function";
70
- }
71
- // node_modules/@tensorflow/tfjs-data/dist/util/deep_clone.js
72
- function x(e) {
73
- return m(e, S);
74
- }
75
- function S(e) {
76
- return e instanceof c ? {
77
- value: e.clone(),
78
- recurse: !1
79
- } : v(e) ? {
80
- value: null,
81
- recurse: !0
82
- } : {
83
- value: e,
84
- recurse: !1
85
- };
86
- }
87
- // node_modules/@tensorflow/tfjs-data/dist/util/ring_buffer.js
88
- var C = class {
89
- constructor(e) {
90
- if (this.capacity = e, this.begin = 0, this.end = 0, e == null) throw RangeError("Can't create a ring buffer of unknown capacity.");
91
- if (e < 1) throw RangeError("Can't create ring buffer of capacity < 1.");
92
- this.data = Array(e), this.doubledCapacity = 2 * e;
93
- }
94
- wrap(e) {
95
- for (; e < 0;) e += this.doubledCapacity;
96
- return e % this.doubledCapacity;
97
- }
98
- get(e) {
99
- if (e < 0) throw RangeError("Can't get item at a negative index.");
100
- return this.data[e % this.capacity];
101
- }
102
- set(e, t) {
103
- if (e < 0) throw RangeError("Can't set item at a negative index.");
104
- this.data[e % this.capacity] = t;
105
- }
106
- length() {
107
- let e = this.end - this.begin;
108
- return e < 0 && (e = this.doubledCapacity + e), e;
109
- }
110
- isFull() {
111
- return this.length() === this.capacity;
112
- }
113
- isEmpty() {
114
- return this.length() === 0;
115
- }
116
- push(e) {
117
- if (this.isFull()) throw RangeError("Ring buffer is full.");
118
- this.set(this.end, e), this.end = this.wrap(this.end + 1);
119
- }
120
- pushAll(e) {
121
- for (let t of e) this.push(t);
122
- }
123
- pop() {
124
- if (this.isEmpty()) throw RangeError("Ring buffer is empty.");
125
- this.end = this.wrap(this.end - 1);
126
- let e = this.get(this.end);
127
- return this.set(this.end, void 0), e;
128
- }
129
- unshift(e) {
130
- if (this.isFull()) throw RangeError("Ring buffer is full.");
131
- this.begin = this.wrap(this.begin - 1), this.set(this.begin, e);
132
- }
133
- shift() {
134
- if (this.isEmpty()) throw RangeError("Ring buffer is empty.");
135
- let e = this.get(this.begin);
136
- return this.set(this.begin, void 0), this.begin = this.wrap(this.begin + 1), e;
137
- }
138
- shuffleExcise(e) {
139
- if (this.isEmpty()) throw RangeError("Ring buffer is empty.");
140
- let t = this.wrap(this.begin + e), n = this.get(t);
141
- return this.set(t, this.pop()), n;
142
- }
143
- }, w = class e extends C {
144
- constructor() {
145
- super(e.INITIAL_CAPACITY);
146
- }
147
- isFull() {
148
- return !1;
149
- }
150
- push(e) {
151
- super.isFull() && this.expand(), super.push(e);
152
- }
153
- unshift(e) {
154
- super.isFull() && this.expand(), super.unshift(e);
155
- }
156
- expand() {
157
- let e = this.capacity * 2, t = Array(e), n = this.length();
158
- for (let e = 0; e < n; e++) t[e] = this.get(this.wrap(this.begin + e));
159
- this.data = t, this.capacity = e, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = n;
160
- }
161
- };
162
- w.INITIAL_CAPACITY = 32;
163
- // node_modules/@tensorflow/tfjs-data/dist/iterators/lazy_iterator.js
164
- function T(e) {
165
- return new k(e);
166
- }
167
- function E(e) {
168
- return new A(e);
169
- }
170
- function D(e, t) {
171
- return new V(e, t);
172
- }
173
- var O = class {
174
- async toArray() {
175
- let e = [], t = await this.next();
176
- for (; !t.done;) e.push(t.value), t = await this.next();
177
- return e;
178
- }
179
- async toArrayForTest() {
180
- let e = this.prefetch(100), t = [], n = await e.next();
181
- for (; !n.done;) t.push(n.value), n = await e.next();
182
- return t;
183
- }
184
- async resolveFully() {
185
- let e = await this.next();
186
- for (; !e.done;) e = await this.next();
187
- }
188
- async resolveWhile(e) {
189
- let t = await this.next(), n = e(t.value);
190
- for (; !t.done && n;) t = await this.next(), n = e(t.value);
191
- }
192
- handleErrors(e) {
193
- return new L(this, e);
194
- }
195
- filter(e) {
196
- return new F(this, e);
197
- }
198
- map(e) {
199
- return new I(this, e);
200
- }
201
- mapAsync(e) {
202
- return new R(this, e);
203
- }
204
- serialMapAsync(e) {
205
- return new R(this, e).serial();
206
- }
207
- flatmap(e) {
208
- return new B(this, e);
209
- }
210
- async forEachAsync(e) {
211
- return this.map(e).resolveFully();
212
- }
213
- async serialForEach(e) {
214
- return this.serialMapAsync(e).resolveWhile((e) => e === !0);
215
- }
216
- rowMajorBatch(e, t = !0) {
217
- return new P(this, e, t);
218
- }
219
- columnMajorBatch(e, t = !0, n = _) {
220
- return this.rowMajorBatch(e, t).map((e) => te(e, n));
221
- }
222
- concatenate(e, t) {
223
- return new V(T([this, e]), t);
224
- }
225
- take(e) {
226
- return e < 0 || e == null ? this : new N(this, e);
227
- }
228
- skip(e) {
229
- return e < 0 || e == null ? this : new M(this, e);
230
- }
231
- prefetch(e) {
232
- return new U(this, e);
233
- }
234
- shuffle(e, t) {
235
- return new W(this, e, t);
236
- }
237
- serial() {
238
- return new j(this);
239
- }
240
- }, k = class extends O {
241
- constructor(e) {
242
- super(), this.items = e, this.trav = 0;
243
- }
244
- summary() {
245
- return `Array of ${this.items.length} items`;
246
- }
247
- async next() {
248
- if (this.trav >= this.items.length) return {
249
- value: null,
250
- done: !0
251
- };
252
- let e = this.items[this.trav];
253
- return this.trav++, {
254
- value: x(e),
255
- done: !1
256
- };
257
- }
258
- }, A = class extends O {
259
- constructor(e) {
260
- super(), this.nextFn = e;
261
- }
262
- summary() {
263
- return "Function call";
264
- }
265
- async next() {
266
- try {
267
- return this.nextFn();
268
- } catch (e) {
269
- throw e.message = `Error thrown while iterating through a dataset: ${e.message}`, e;
270
- }
271
- }
272
- }, j = class extends O {
273
- constructor(e) {
274
- super(), this.upstream = e, this.lastRead = Promise.resolve({
275
- value: null,
276
- done: !1
277
- });
278
- }
279
- summary() {
280
- return `${this.upstream.summary()} -> Serial`;
281
- }
282
- async next() {
283
- return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
284
- }
285
- async serialNext() {
286
- return this.upstream.next();
287
- }
288
- }, M = class extends O {
289
- constructor(e, t) {
290
- super(), this.upstream = e, this.maxCount = t, this.count = 0, this.lastRead = Promise.resolve({
291
- value: null,
292
- done: !1
293
- });
294
- }
295
- summary() {
296
- return `${this.upstream.summary()} -> Skip`;
297
- }
298
- async next() {
299
- return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
300
- }
301
- async serialNext() {
302
- for (; this.count++ < this.maxCount;) {
303
- let e = await this.upstream.next();
304
- if (e.done) return e;
305
- t(e.value);
306
- }
307
- return this.upstream.next();
308
- }
309
- }, N = class extends O {
310
- constructor(e, t) {
311
- super(), this.upstream = e, this.maxCount = t, this.count = 0;
312
- }
313
- summary() {
314
- return `${this.upstream.summary()} -> Take`;
315
- }
316
- async next() {
317
- return this.count++ >= this.maxCount ? {
318
- value: null,
319
- done: !0
320
- } : this.upstream.next();
321
- }
322
- }, P = class extends O {
323
- constructor(e, t, n = !0) {
324
- super(), this.upstream = e, this.batchSize = t, this.enableSmallLastBatch = n, this.lastRead = Promise.resolve({
325
- value: null,
326
- done: !1
327
- });
328
- }
329
- summary() {
330
- return `${this.upstream.summary()} -> RowMajorBatch`;
331
- }
332
- async next() {
333
- return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
334
- }
335
- async serialNext() {
336
- let e = [];
337
- for (; e.length < this.batchSize;) {
338
- let t = await this.upstream.next();
339
- if (t.done) return this.enableSmallLastBatch && e.length > 0 ? {
340
- value: e,
341
- done: !1
342
- } : {
343
- value: null,
344
- done: !0
345
- };
346
- e.push(t.value);
347
- }
348
- return {
349
- value: e,
350
- done: !1
351
- };
352
- }
353
- }, F = class extends O {
354
- constructor(e, t) {
355
- super(), this.upstream = e, this.predicate = t, this.lastRead = Promise.resolve({
356
- value: null,
357
- done: !1
358
- });
359
- }
360
- summary() {
361
- return `${this.upstream.summary()} -> Filter`;
362
- }
363
- async next() {
364
- return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
365
- }
366
- async serialNext() {
367
- for (;;) {
368
- let e = await this.upstream.next();
369
- if (e.done || this.predicate(e.value)) return e;
370
- t(e.value);
371
- }
372
- }
373
- }, I = class extends O {
374
- constructor(e, t) {
375
- super(), this.upstream = e, this.transform = t;
376
- }
377
- summary() {
378
- return `${this.upstream.summary()} -> Map`;
379
- }
380
- async next() {
381
- let e = await this.upstream.next();
382
- if (e.done) return {
383
- value: null,
384
- done: !0
385
- };
386
- let t = o(e.value), n = this.transform(e.value), r = o(n);
387
- for (let e of t) s(e, r) || e.dispose();
388
- return {
389
- value: n,
390
- done: !1
391
- };
392
- }
393
- }, L = class extends O {
394
- constructor(e, t) {
395
- super(), this.upstream = e, this.handler = t, this.count = 0, this.lastRead = Promise.resolve({
396
- value: null,
397
- done: !1
398
- });
399
- }
400
- summary() {
401
- return `${this.upstream.summary()} -> handleErrors`;
402
- }
403
- async next() {
404
- return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
405
- }
406
- async serialNext() {
407
- for (;;) try {
408
- return await this.upstream.next();
409
- } catch (e) {
410
- if (!this.handler(e)) return {
411
- value: null,
412
- done: !0
413
- };
414
- }
415
- }
416
- }, R = class extends O {
417
- constructor(e, t) {
418
- super(), this.upstream = e, this.transform = t;
419
- }
420
- summary() {
421
- return `${this.upstream.summary()} -> AsyncMap`;
422
- }
423
- async next() {
424
- let e = await this.upstream.next();
425
- if (e.done) return {
426
- value: null,
427
- done: !0
428
- };
429
- let t = o(e.value), n = await this.transform(e.value), r = o(n);
430
- for (let e of t) s(e, r) || e.dispose();
431
- return {
432
- value: n,
433
- done: !1
434
- };
435
- }
436
- }, z = class extends O {
437
- constructor() {
438
- super(), this.outputQueue = new w(), this.lastRead = Promise.resolve({
439
- value: null,
440
- done: !1
441
- });
442
- }
443
- async next() {
444
- return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
445
- }
446
- async serialNext() {
447
- for (; this.outputQueue.length() === 0;) if (!await this.pump()) return {
448
- value: null,
449
- done: !0
450
- };
451
- return {
452
- value: this.outputQueue.shift(),
453
- done: !1
454
- };
455
- }
456
- }, B = class extends z {
457
- constructor(e, t) {
458
- super(), this.upstream = e, this.transform = t;
459
- }
460
- summary() {
461
- return `${this.upstream.summary()} -> Flatmap`;
462
- }
463
- async pump() {
464
- let e = await this.upstream.next();
465
- if (e.done) return !1;
466
- let t = o(e.value), n = this.transform(e.value), r = o(n);
467
- this.outputQueue.pushAll(n);
468
- for (let e of t) s(e, r) || e.dispose();
469
- return !0;
470
- }
471
- }, V = class extends O {
472
- constructor(e, t) {
473
- super(), this.baseErrorHandler = t, this.lastRead = null, this.iterator = null, this.moreIterators = e;
474
- }
475
- summary() {
476
- return "TODO: fill in upstream of chained summaries -> Chained";
477
- }
478
- async next() {
479
- return this.lastRead = this.readFromChain(this.lastRead), this.lastRead;
480
- }
481
- async readFromChain(e) {
482
- if (await e, this.iterator == null) {
483
- let e = await this.moreIterators.next();
484
- if (e.done) return {
485
- value: null,
486
- done: !0
487
- };
488
- this.iterator = e.value, this.baseErrorHandler != null && (this.iterator = this.iterator.handleErrors(this.baseErrorHandler));
489
- }
490
- let t = await this.iterator.next();
491
- return t.done ? (this.iterator = null, this.readFromChain(e)) : t;
492
- }
493
- }, H;
494
- (function(e) {
495
- e[e.FAIL = 0] = "FAIL", e[e.SHORTEST = 1] = "SHORTEST", e[e.LONGEST = 2] = "LONGEST";
496
- })(H ||= {});
497
- var U = class extends O {
498
- constructor(e, t) {
499
- super(), this.upstream = e, this.bufferSize = t, this.buffer = new C(t);
500
- }
501
- summary() {
502
- return `${this.upstream.summary()} -> Prefetch`;
503
- }
504
- refill() {
505
- for (; !this.buffer.isFull();) {
506
- let e = this.upstream.next();
507
- this.buffer.push(e);
508
- }
509
- }
510
- next() {
511
- return this.refill(), this.buffer.shift();
512
- }
513
- }, W = class extends U {
514
- constructor(e, t, n) {
515
- super(e, t), this.upstream = e, this.windowSize = t, this.upstreamExhausted = !1, this.random = p.alea(n || l().toString()), this.lastRead = Promise.resolve({
516
- value: null,
517
- done: !1
518
- });
519
- }
520
- async next() {
521
- return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
522
- }
523
- randomInt(e) {
524
- return Math.floor(this.random() * e);
525
- }
526
- chooseIndex() {
527
- return this.randomInt(this.buffer.length());
528
- }
529
- async serialNext() {
530
- for (this.upstreamExhausted || this.refill(); !this.buffer.isEmpty();) {
531
- let e = this.chooseIndex(), t = await this.buffer.shuffleExcise(e);
532
- if (t.done) this.upstreamExhausted = !0;
533
- else return this.refill(), t;
534
- }
535
- return {
536
- value: null,
537
- done: !0
538
- };
539
- }
540
- }, G = class {
541
- constructor() {
542
- this.size = null;
543
- }
544
- batch(e, t = !0) {
545
- let n = this;
546
- ee(e > 0, () => `batchSize needs to be positive, but it is
547
- ${e}`);
548
- let r;
549
- return r = this.size === Infinity || this.size == null ? this.size : t ? Math.ceil(this.size / e) : Math.floor(this.size / e), K(async () => (await n.iterator()).columnMajorBatch(e, t, q), r);
550
- }
551
- concatenate(e) {
552
- let t = this, n;
553
- return n = this.size === Infinity || e.size === Infinity ? Infinity : this.size != null && e.size != null ? this.size + e.size : null, K(async () => (await t.iterator()).concatenate(await e.iterator()), n);
554
- }
555
- filter(e) {
556
- let t = this, n;
557
- return n = this.size === Infinity ? Infinity : null, K(async () => (await t.iterator()).filter((t) => r(() => e(t))), n);
558
- }
559
- async forEachAsync(e) {
560
- return (await this.iterator()).forEachAsync(e);
561
- }
562
- map(e) {
563
- let t = this;
564
- return K(async () => (await t.iterator()).map((t) => r(() => e(t))), this.size);
565
- }
566
- mapAsync(e) {
567
- let t = this;
568
- return K(async () => (await t.iterator()).mapAsync(e), this.size);
569
- }
570
- prefetch(e) {
571
- if (e == null) throw RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
572
- let t = this;
573
- return K(async () => (await t.iterator()).prefetch(e), this.size);
574
- }
575
- repeat(e) {
576
- let t = this, n;
577
- return n = this.size != null && e > 0 ? this.size * e : e === 0 ? 0 : this.size != null && (e === void 0 || e < 0) ? Infinity : null, K(async () => D(E(async () => ({
578
- value: await t.iterator(),
579
- done: !1
580
- })).take(e)), n);
581
- }
582
- skip(e) {
583
- let t = this, n;
584
- return n = this.size != null && e >= 0 && this.size >= e ? this.size - e : this.size != null && (this.size < e || e === void 0 || e < 0) ? 0 : null, K(async () => (await t.iterator()).skip(e), n);
585
- }
586
- shuffle(e, t, n = !0) {
587
- if (e == null || e < 0) throw this.size == null ? RangeError("`Dataset.shuffle()` requires bufferSize to be specified.") : RangeError(`\`Dataset.shuffle()\` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for \`tf.Tensor\`s), consider setting bufferSize to the dataset size (${this.size} elements)`);
588
- let r = this, i = p.alea(t || l().toString());
589
- return K(async () => {
590
- let t = i.int32();
591
- return n && (t += i.int32()), (await r.iterator()).shuffle(e, t.toString());
592
- }, this.size);
593
- }
594
- take(e) {
595
- let t = this, n;
596
- return n = this.size != null && this.size > e ? e : this.size != null && this.size <= e ? this.size : null, K(async () => (await t.iterator()).take(e), n);
597
- }
598
- async toArray() {
599
- if (this.size === Infinity) throw Error("Can not convert infinite data stream to array.");
600
- return (await this.iterator()).toArray();
601
- }
602
- async toArrayForTest() {
603
- if (this.size === Infinity) throw Error("Can not convert infinite data stream to array.");
604
- return (await this.iterator()).toArrayForTest();
605
- }
606
- };
607
- G.MAX_BUFFER_SIZE = 1e4;
608
- function K(e, t = null) {
609
- return new class extends G {
610
- constructor() {
611
- super(...arguments), this.size = t;
612
- }
613
- async iterator() {
614
- return e();
615
- }
616
- }();
617
- }
618
- function q(e) {
619
- if (e === null) return null;
620
- let t = e[0];
621
- return y(t) ? {
622
- value: J(e),
623
- recurse: !1
624
- } : {
625
- value: null,
626
- recurse: !0
627
- };
628
- }
629
- function J(e) {
630
- if (e.length === 0) throw Error("Can't make a batch of zero elements.");
631
- return e[0] instanceof c ? f(e) : u(e);
632
- }
633
- // node_modules/@tensorflow/tfjs-data/dist/readers.js
634
- function Y(e) {
635
- return K(async () => {
636
- let t = await e();
637
- return E(() => t.next());
638
- });
639
- }
640
- // lib/training/DatasetBuilder.ts
641
- function X(e, t) {
642
- let n = e.map((e) => t.encodeConversation(e)).flat();
643
- return new Uint16Array(n);
644
- }
645
- function Z(e, t) {
646
- let n = e.map((e) => t.encodeConversation(e, !1, !0)), r = n.map((e) => e.tokens).flat(), i = n.map((e) => e.mask).flat();
647
- return {
648
- tokens: new Uint16Array(r),
649
- mask: new Uint8Array(i.map((e) => +!!e))
650
- };
651
- }
652
- function Q(e) {
653
- for (let t = e.length - 1; t > 0; t--) {
654
- let n = Math.floor(Math.random() * (t + 1));
655
- [e[t], e[n]] = [e[n], e[t]];
656
- }
657
- return e;
658
- }
659
- async function $(e, t, n) {
660
- e.step += 1;
661
- let r = e.shardIndex === e.shuffledShards.length - 1 ? e.lastShardIndexes : e.shuffledIndexes;
662
- if (e.step >= r.length) {
663
- e.step = 0, e.shardIndex += 1, e.shardIndex >= e.shuffledShards.length && (e.shardIndex = 0, n || (Q(e.shuffledShards), Q(e.shuffledIndexes), Q(e.lastShardIndexes))), e.nextShard ? (e.currentShard = e.nextShard, e.nextShard = null) : e.currentShard = await t.getShard(e.shuffledShards[e.shardIndex]);
664
- let r = (e.shardIndex + 1) % e.shuffledShards.length;
665
- if (t.getShard(e.shuffledShards[r]).then((t) => {
666
- e.nextShard = t;
667
- }), t.hasMask()) {
668
- e.nextMask ? (e.currentMask = e.nextMask, e.nextMask = null) : e.currentMask = await t.getMask(e.shuffledShards[e.shardIndex]) ?? null;
669
- let n = (e.shardIndex + 1) % e.shuffledShards.length;
670
- t.getMask(e.shuffledShards[n]).then((t) => {
671
- e.nextMask = t ?? null;
672
- });
673
- }
674
- }
675
- }
676
- var ne = class {
677
- tokenizer;
678
- blockSize;
679
- constructor(e, t = 128) {
680
- this.tokenizer = e, this.blockSize = t;
681
- }
682
- async createTextDataset(e, t) {
683
- let { batchSize: n = 32, noShuffle: i = !1, ignoreIndex: a = 65535 } = t || {}, o = e.getTokenCount();
684
- if (o < this.blockSize + 1) throw Error(`Not enough tokens (${o}) for block size ${this.blockSize}`);
685
- let s = Math.ceil(e.shardSize / this.blockSize), c = {
686
- shuffledShards: new Uint16Array(e.getShardCount()),
687
- shuffledIndexes: new Uint16Array(s),
688
- lastShardIndexes: new Uint16Array(Math.ceil(e.getShardLength(e.getShardCount() - 1) / this.blockSize)),
689
- currentMask: null,
690
- nextMask: null,
691
- currentShard: null,
692
- nextShard: null,
693
- shardIndex: 0,
694
- step: 0
695
- };
696
- for (let e = 0; e < c.shuffledShards.length; e++) c.shuffledShards[e] = e;
697
- for (let e = 0; e < c.shuffledIndexes.length; e++) c.shuffledIndexes[e] = e;
698
- for (let e = 0; e < c.lastShardIndexes.length; e++) c.lastShardIndexes[e] = e;
699
- return t?.shuffleFirst && (Q(c.shuffledShards), Q(c.shuffledIndexes), Q(c.lastShardIndexes)), c.currentShard = await e.getShard(c.shuffledShards[c.shardIndex]), c.shardIndex + 1 < c.shuffledShards.length && e.getShard(c.shuffledShards[c.shardIndex + 1]).then((e) => {
700
- c.nextShard = e;
701
- }), e.hasMask() && (c.currentMask = await e.getMask(c.shuffledShards[c.shardIndex]) ?? null, c.shardIndex + 1 < c.shuffledShards.length && e.getMask(c.shuffledShards[c.shardIndex + 1]).then((e) => {
702
- c.nextMask = e ?? null;
703
- })), {
704
- dataset: Y(async function* () {
705
- for (;;) {
706
- let t = (c.shardIndex === c.shuffledShards.length - 1 ? c.lastShardIndexes : c.shuffledIndexes)[c.step] * this.blockSize, n = c.currentShard, r = c.currentMask, o = $(c, e, i);
707
- if (!n) break;
708
- t + this.blockSize + 1 > n.length && (t = n.length - this.blockSize - 1);
709
- let s = new Int32Array(n.slice(t, t + this.blockSize)), l = new Int32Array(n.slice(t + 1, t + this.blockSize + 1));
710
- if (r) {
711
- let e = 0, n = r.slice(t + 1, t + this.blockSize + 1);
712
- for (let t = 0; t < l.length; t++) n[t] === 0 && (l[t] = a, e++);
713
- if (e === l.length) continue;
714
- }
715
- yield {
716
- xs: s,
717
- ys: l
718
- }, await o;
719
- }
720
- }.bind(this)).batch(n).map((e) => {
721
- let t = e;
722
- return r(() => ({
723
- xs: t.xs.cast("int32"),
724
- ys: t.ys.cast("int32")
725
- }));
726
- }).prefetch(2),
727
- state: c
728
- };
729
- }
730
- };
731
- export { Q as a, $ as i, X as n, Z as r, ne as t };