@genai-fi/nanogpt 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (433) hide show
  1. package/dist/BaseTokeniser-DSg9zcYq.js +221 -0
  2. package/dist/DatasetBuilder-DgURD85T.js +712 -0
  3. package/dist/Generator.d.ts +82 -0
  4. package/dist/Generator.js +2 -0
  5. package/dist/RealDiv-DBu0FQqT.js +362 -0
  6. package/dist/Reshape-CABOPB9d.js +94 -0
  7. package/dist/Reshape-DqO3r8BC.js +17 -0
  8. package/dist/TeachableLLM.d.ts +70 -0
  9. package/dist/TeachableLLM.js +2 -0
  10. package/dist/Trainer.d.ts +43 -0
  11. package/dist/Trainer.js +2 -0
  12. package/dist/backend.d.ts +2 -0
  13. package/dist/backend.js +13 -0
  14. package/dist/backend_util-Cg-roD1p.js +399 -0
  15. package/dist/binary_op_util-CrYk9LXL.js +103 -0
  16. package/dist/checks/appendCache.d.ts +1 -0
  17. package/dist/checks/appendCache.js +55 -0
  18. package/dist/checks/attentionMask.d.ts +1 -0
  19. package/dist/checks/attentionMask.js +56 -0
  20. package/dist/checks/check.d.ts +9 -0
  21. package/dist/checks/check.js +32 -0
  22. package/dist/checks/gelu.d.ts +1 -0
  23. package/dist/checks/gelu.js +46 -0
  24. package/dist/checks/index.d.ts +26 -0
  25. package/dist/checks/index.js +28 -0
  26. package/dist/checks/matMulGelu.d.ts +1 -0
  27. package/dist/checks/matMulGelu.js +84 -0
  28. package/dist/checks/normRMS.d.ts +1 -0
  29. package/dist/checks/normRMS.js +28 -0
  30. package/dist/checks/normRMSGrad.d.ts +1 -0
  31. package/dist/checks/normRMSGrad.js +22 -0
  32. package/dist/checks/packUnpack.d.ts +1 -0
  33. package/dist/checks/packUnpack.js +46 -0
  34. package/dist/checks/qkv.d.ts +1 -0
  35. package/dist/checks/qkv.js +34 -0
  36. package/dist/checks/rope.d.ts +1 -0
  37. package/dist/checks/rope.js +30 -0
  38. package/dist/checks/weights.d.ts +14 -0
  39. package/dist/checks/weights.js +27 -0
  40. package/dist/chunk-BPntVaq0.js +23 -0
  41. package/dist/complex_util-CkazZsaH.js +60 -0
  42. package/dist/concat_util-CWDZCBlA.js +19 -0
  43. package/dist/data/docx.d.ts +2 -0
  44. package/dist/data/docx.js +3046 -0
  45. package/dist/data/pdf.d.ts +2 -0
  46. package/dist/data/pdf.js +17 -0
  47. package/dist/data/textLoader.d.ts +7 -0
  48. package/dist/data/textLoader.js +613 -0
  49. package/dist/dist-BewPQWjc.js +7572 -0
  50. package/dist/dist-DVmq73nz.js +8775 -0
  51. package/dist/dist-DXwIvKxl.js +896 -0
  52. package/dist/dist-VEU5mfO0.js +7545 -0
  53. package/dist/gelu-Bf1HW1RY.js +27 -0
  54. package/dist/gpgpu_math-DvLcCH6u.js +1612 -0
  55. package/dist/inference/types.d.ts +16 -0
  56. package/dist/inference/types.js +0 -0
  57. package/dist/kernel_funcs_utils-HiXOOx3f.js +229 -0
  58. package/dist/layers/BaseLayer.d.ts +44 -0
  59. package/dist/layers/BaseLayer.js +76 -0
  60. package/dist/layers/CausalSelfAttention.d.ts +39 -0
  61. package/dist/layers/CausalSelfAttention.js +99 -0
  62. package/dist/layers/LoRA.d.ts +14 -0
  63. package/dist/layers/LoRA.js +48 -0
  64. package/dist/layers/MLP.d.ts +17 -0
  65. package/dist/layers/MLP.js +34 -0
  66. package/dist/layers/PositionEmbedding.d.ts +8 -0
  67. package/dist/layers/PositionEmbedding.js +27 -0
  68. package/dist/layers/RMSNorm.d.ts +12 -0
  69. package/dist/layers/RMSNorm.js +20 -0
  70. package/dist/layers/RoPECache.d.ts +18 -0
  71. package/dist/layers/RoPECache.js +337 -0
  72. package/dist/layers/TiedEmbedding.d.ts +13 -0
  73. package/dist/layers/TiedEmbedding.js +32 -0
  74. package/dist/layers/TransformerBlock.d.ts +27 -0
  75. package/dist/layers/TransformerBlock.js +51 -0
  76. package/dist/layers/WeightStore.d.ts +20 -0
  77. package/dist/layers/WeightStore.js +69 -0
  78. package/dist/loader/load.d.ts +6 -0
  79. package/dist/loader/load.js +2 -0
  80. package/dist/loader/loadHF.d.ts +8 -0
  81. package/dist/loader/loadHF.js +2 -0
  82. package/dist/loader/loadTransformers.d.ts +4 -0
  83. package/dist/loader/loadTransformers.js +2 -0
  84. package/dist/loader/loadZipMeta.d.ts +3 -0
  85. package/dist/loader/loadZipMeta.js +16 -0
  86. package/dist/loader/newZipLoad.d.ts +3 -0
  87. package/dist/loader/newZipLoad.js +2 -0
  88. package/dist/loader/oldZipLoad.d.ts +9 -0
  89. package/dist/loader/oldZipLoad.js +2 -0
  90. package/dist/loader/save.d.ts +16 -0
  91. package/dist/loader/save.js +2 -0
  92. package/dist/loader/types.d.ts +68 -0
  93. package/dist/loader/types.js +0 -0
  94. package/dist/main-CPjeMv0G.js +13500 -0
  95. package/dist/main.d.ts +50 -0
  96. package/dist/main.js +16 -0
  97. package/dist/matMul16-BNfZSnNM.js +81 -0
  98. package/dist/matMulGelu-CPTntosE.js +162 -0
  99. package/dist/models/NanoGPTV1.d.ts +16 -0
  100. package/dist/models/NanoGPTV1.js +2 -0
  101. package/dist/models/NanoGPTV2.d.ts +16 -0
  102. package/dist/models/NanoGPTV2.js +2 -0
  103. package/dist/models/config.d.ts +27 -0
  104. package/dist/models/config.js +37 -0
  105. package/dist/models/factory.d.ts +3 -0
  106. package/dist/models/factory.js +2 -0
  107. package/dist/models/model.d.ts +44 -0
  108. package/dist/models/model.js +2 -0
  109. package/dist/ops/adamAdjust.d.ts +2 -0
  110. package/dist/ops/adamAdjust.js +18 -0
  111. package/dist/ops/adamMoments.d.ts +2 -0
  112. package/dist/ops/adamMoments.js +16 -0
  113. package/dist/ops/add16.d.ts +2 -0
  114. package/dist/ops/add16.js +12 -0
  115. package/dist/ops/appendCache.d.ts +2 -0
  116. package/dist/ops/appendCache.js +25 -0
  117. package/dist/ops/attentionMask.d.ts +2 -0
  118. package/dist/ops/attentionMask.js +16 -0
  119. package/dist/ops/concat16.d.ts +2 -0
  120. package/dist/ops/concat16.js +8 -0
  121. package/dist/ops/cpu/adamAdjust.d.ts +1 -0
  122. package/dist/ops/cpu/adamAdjust.js +16 -0
  123. package/dist/ops/cpu/adamMoments.d.ts +1 -0
  124. package/dist/ops/cpu/adamMoments.js +16 -0
  125. package/dist/ops/cpu/appendCache.d.ts +1 -0
  126. package/dist/ops/cpu/appendCache.js +65 -0
  127. package/dist/ops/cpu/attentionMask.d.ts +1 -0
  128. package/dist/ops/cpu/attentionMask.js +16 -0
  129. package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
  130. package/dist/ops/cpu/fusedSoftmax.js +22 -0
  131. package/dist/ops/cpu/gatherSub.d.ts +1 -0
  132. package/dist/ops/cpu/gatherSub.js +12 -0
  133. package/dist/ops/cpu/gelu.d.ts +1 -0
  134. package/dist/ops/cpu/gelu.js +36 -0
  135. package/dist/ops/cpu/matMul16.d.ts +1 -0
  136. package/dist/ops/cpu/matMul16.js +14 -0
  137. package/dist/ops/cpu/matMulGelu.d.ts +1 -0
  138. package/dist/ops/cpu/matMulGelu.js +41 -0
  139. package/dist/ops/cpu/matMulMul.d.ts +1 -0
  140. package/dist/ops/cpu/matMulMul.js +20 -0
  141. package/dist/ops/cpu/mulDropout.d.ts +1 -0
  142. package/dist/ops/cpu/mulDropout.js +20 -0
  143. package/dist/ops/cpu/normRMS.d.ts +1 -0
  144. package/dist/ops/cpu/normRMS.js +35 -0
  145. package/dist/ops/cpu/qkv.d.ts +5 -0
  146. package/dist/ops/cpu/qkv.js +73 -0
  147. package/dist/ops/cpu/rope.d.ts +6 -0
  148. package/dist/ops/cpu/rope.js +81 -0
  149. package/dist/ops/cpu/scatterSub.d.ts +1 -0
  150. package/dist/ops/cpu/scatterSub.js +12 -0
  151. package/dist/ops/dot16.d.ts +2 -0
  152. package/dist/ops/dot16.js +29 -0
  153. package/dist/ops/dropout.d.ts +2 -0
  154. package/dist/ops/dropout.js +11 -0
  155. package/dist/ops/dropout16.d.ts +2 -0
  156. package/dist/ops/dropout16.js +22 -0
  157. package/dist/ops/gatherSub.d.ts +2 -0
  158. package/dist/ops/gatherSub.js +13 -0
  159. package/dist/ops/gelu.d.ts +3 -0
  160. package/dist/ops/gelu.js +2 -0
  161. package/dist/ops/globalNorm.d.ts +2 -0
  162. package/dist/ops/globalNorm.js +19 -0
  163. package/dist/ops/grads/add16.d.ts +1 -0
  164. package/dist/ops/grads/add16.js +27 -0
  165. package/dist/ops/grads/attentionMask.d.ts +1 -0
  166. package/dist/ops/grads/attentionMask.js +26 -0
  167. package/dist/ops/grads/dropout16.d.ts +1 -0
  168. package/dist/ops/grads/dropout16.js +1 -0
  169. package/dist/ops/grads/gelu.d.ts +2 -0
  170. package/dist/ops/grads/gelu.js +2 -0
  171. package/dist/ops/grads/matMul16.d.ts +2 -0
  172. package/dist/ops/grads/matMul16.js +2 -0
  173. package/dist/ops/grads/matMulGelu.d.ts +1 -0
  174. package/dist/ops/grads/matMulGelu.js +22 -0
  175. package/dist/ops/grads/mul16.d.ts +1 -0
  176. package/dist/ops/grads/mul16.js +1 -0
  177. package/dist/ops/grads/normRMS.d.ts +3 -0
  178. package/dist/ops/grads/normRMS.js +37 -0
  179. package/dist/ops/grads/pack16.d.ts +2 -0
  180. package/dist/ops/grads/pack16.js +2 -0
  181. package/dist/ops/grads/qkv.d.ts +3 -0
  182. package/dist/ops/grads/qkv.js +46 -0
  183. package/dist/ops/grads/rope.d.ts +2 -0
  184. package/dist/ops/grads/rope.js +2 -0
  185. package/dist/ops/grads/softmax16.d.ts +2 -0
  186. package/dist/ops/grads/softmax16.js +23 -0
  187. package/dist/ops/grads/unpack16.d.ts +2 -0
  188. package/dist/ops/grads/unpack16.js +2 -0
  189. package/dist/ops/grads/utils.d.ts +4 -0
  190. package/dist/ops/grads/utils.js +12 -0
  191. package/dist/ops/log.d.ts +0 -0
  192. package/dist/ops/log.js +1 -0
  193. package/dist/ops/matMul16.d.ts +15 -0
  194. package/dist/ops/matMul16.js +2 -0
  195. package/dist/ops/matMulGelu.d.ts +3 -0
  196. package/dist/ops/matMulGelu.js +20 -0
  197. package/dist/ops/matMulMul.d.ts +2 -0
  198. package/dist/ops/matMulMul.js +16 -0
  199. package/dist/ops/mul16.d.ts +2 -0
  200. package/dist/ops/mul16.js +43 -0
  201. package/dist/ops/mulDrop.d.ts +2 -0
  202. package/dist/ops/mulDrop.js +15 -0
  203. package/dist/ops/normRMS.d.ts +2 -0
  204. package/dist/ops/normRMS.js +22 -0
  205. package/dist/ops/pack16.d.ts +2 -0
  206. package/dist/ops/pack16.js +2 -0
  207. package/dist/ops/qkv.d.ts +2 -0
  208. package/dist/ops/qkv.js +16 -0
  209. package/dist/ops/reshape16.d.ts +2 -0
  210. package/dist/ops/reshape16.js +33 -0
  211. package/dist/ops/rope.d.ts +3 -0
  212. package/dist/ops/rope.js +2 -0
  213. package/dist/ops/scatterSub.d.ts +2 -0
  214. package/dist/ops/scatterSub.js +13 -0
  215. package/dist/ops/slice16.d.ts +2 -0
  216. package/dist/ops/slice16.js +11 -0
  217. package/dist/ops/softmax16.d.ts +2 -0
  218. package/dist/ops/softmax16.js +9 -0
  219. package/dist/ops/sub16.d.ts +2 -0
  220. package/dist/ops/sub16.js +11 -0
  221. package/dist/ops/sum16.d.ts +2 -0
  222. package/dist/ops/sum16.js +13 -0
  223. package/dist/ops/transpose16.d.ts +3 -0
  224. package/dist/ops/transpose16.js +32 -0
  225. package/dist/ops/unpack16.d.ts +2 -0
  226. package/dist/ops/unpack16.js +2 -0
  227. package/dist/ops/webgl/adamAdjust.d.ts +1 -0
  228. package/dist/ops/webgl/adamAdjust.js +82 -0
  229. package/dist/ops/webgl/adamMoments.d.ts +1 -0
  230. package/dist/ops/webgl/adamMoments.js +44 -0
  231. package/dist/ops/webgl/appendCache.d.ts +1 -0
  232. package/dist/ops/webgl/appendCache.js +53 -0
  233. package/dist/ops/webgl/attentionMask.d.ts +1 -0
  234. package/dist/ops/webgl/attentionMask.js +64 -0
  235. package/dist/ops/webgl/dropout16.d.ts +1 -0
  236. package/dist/ops/webgl/dropout16.js +12 -0
  237. package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
  238. package/dist/ops/webgl/fusedSoftmax.js +70 -0
  239. package/dist/ops/webgl/gatherSub.d.ts +1 -0
  240. package/dist/ops/webgl/gatherSub.js +28 -0
  241. package/dist/ops/webgl/gelu.d.ts +2 -0
  242. package/dist/ops/webgl/gelu.js +48 -0
  243. package/dist/ops/webgl/log.d.ts +17 -0
  244. package/dist/ops/webgl/log.js +14 -0
  245. package/dist/ops/webgl/matMul16.d.ts +1 -0
  246. package/dist/ops/webgl/matMul16.js +37 -0
  247. package/dist/ops/webgl/matMulGelu.d.ts +21 -0
  248. package/dist/ops/webgl/matMulGelu.js +2 -0
  249. package/dist/ops/webgl/matMulMul.d.ts +14 -0
  250. package/dist/ops/webgl/matMulMul.js +24 -0
  251. package/dist/ops/webgl/mulDropout.d.ts +1 -0
  252. package/dist/ops/webgl/mulDropout.js +32 -0
  253. package/dist/ops/webgl/normRMS.d.ts +1 -0
  254. package/dist/ops/webgl/normRMS.js +114 -0
  255. package/dist/ops/webgl/qkv.d.ts +1 -0
  256. package/dist/ops/webgl/qkv.js +54 -0
  257. package/dist/ops/webgl/rope.d.ts +1 -0
  258. package/dist/ops/webgl/rope.js +72 -0
  259. package/dist/ops/webgl/scatterSub.d.ts +1 -0
  260. package/dist/ops/webgl/scatterSub.js +28 -0
  261. package/dist/ops/webgpu/adamAdjust.d.ts +1 -0
  262. package/dist/ops/webgpu/adamAdjust.js +77 -0
  263. package/dist/ops/webgpu/adamMoments.d.ts +1 -0
  264. package/dist/ops/webgpu/adamMoments.js +76 -0
  265. package/dist/ops/webgpu/add16.d.ts +1 -0
  266. package/dist/ops/webgpu/add16.js +14 -0
  267. package/dist/ops/webgpu/appendCache.d.ts +1 -0
  268. package/dist/ops/webgpu/appendCache.js +130 -0
  269. package/dist/ops/webgpu/attentionMask.d.ts +1 -0
  270. package/dist/ops/webgpu/attentionMask.js +42 -0
  271. package/dist/ops/webgpu/attentionMask32_program.d.ts +19 -0
  272. package/dist/ops/webgpu/attentionMask32_program.js +62 -0
  273. package/dist/ops/webgpu/clipScale.d.ts +1 -0
  274. package/dist/ops/webgpu/clipScale.js +45 -0
  275. package/dist/ops/webgpu/concat16.d.ts +19 -0
  276. package/dist/ops/webgpu/concat16.js +111 -0
  277. package/dist/ops/webgpu/dropout16.d.ts +1 -0
  278. package/dist/ops/webgpu/dropout16.js +59 -0
  279. package/dist/ops/webgpu/gatherSub.d.ts +1 -0
  280. package/dist/ops/webgpu/gatherSub.js +52 -0
  281. package/dist/ops/webgpu/gelu.d.ts +14 -0
  282. package/dist/ops/webgpu/gelu.js +147 -0
  283. package/dist/ops/webgpu/index.d.ts +0 -0
  284. package/dist/ops/webgpu/index.js +26 -0
  285. package/dist/ops/webgpu/matMul16.d.ts +1 -0
  286. package/dist/ops/webgpu/matMul16.js +70 -0
  287. package/dist/ops/webgpu/matMul16_program.d.ts +42 -0
  288. package/dist/ops/webgpu/matMul16_program.js +303 -0
  289. package/dist/ops/webgpu/mul16.d.ts +1 -0
  290. package/dist/ops/webgpu/mul16.js +14 -0
  291. package/dist/ops/webgpu/norm2.d.ts +1 -0
  292. package/dist/ops/webgpu/norm2.js +46 -0
  293. package/dist/ops/webgpu/normRMS.d.ts +1 -0
  294. package/dist/ops/webgpu/normRMS.js +26 -0
  295. package/dist/ops/webgpu/normRMS16_program.d.ts +10 -0
  296. package/dist/ops/webgpu/normRMS16_program.js +28 -0
  297. package/dist/ops/webgpu/normRMS32_program.d.ts +10 -0
  298. package/dist/ops/webgpu/normRMS32_program.js +28 -0
  299. package/dist/ops/webgpu/normRMSGrad.d.ts +1 -0
  300. package/dist/ops/webgpu/normRMSGrad.js +225 -0
  301. package/dist/ops/webgpu/pack16.d.ts +1 -0
  302. package/dist/ops/webgpu/pack16.js +21 -0
  303. package/dist/ops/webgpu/pack16_program.d.ts +19 -0
  304. package/dist/ops/webgpu/pack16_program.js +93 -0
  305. package/dist/ops/webgpu/qkv.d.ts +1 -0
  306. package/dist/ops/webgpu/qkv.js +64 -0
  307. package/dist/ops/webgpu/rope.d.ts +1 -0
  308. package/dist/ops/webgpu/rope.js +163 -0
  309. package/dist/ops/webgpu/scatterSub.d.ts +1 -0
  310. package/dist/ops/webgpu/scatterSub.js +53 -0
  311. package/dist/ops/webgpu/slice16.d.ts +7 -0
  312. package/dist/ops/webgpu/slice16.js +74 -0
  313. package/dist/ops/webgpu/softmax16.d.ts +17 -0
  314. package/dist/ops/webgpu/softmax16.js +18 -0
  315. package/dist/ops/webgpu/softmax16_program.d.ts +13 -0
  316. package/dist/ops/webgpu/softmax16_program.js +89 -0
  317. package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +17 -0
  318. package/dist/ops/webgpu/softmax16_subgroup_program.js +70 -0
  319. package/dist/ops/webgpu/softmax16grad.d.ts +1 -0
  320. package/dist/ops/webgpu/softmax16grad.js +31 -0
  321. package/dist/ops/webgpu/sub16.d.ts +1 -0
  322. package/dist/ops/webgpu/sub16.js +14 -0
  323. package/dist/ops/webgpu/sum16.d.ts +1 -0
  324. package/dist/ops/webgpu/sum16.js +29 -0
  325. package/dist/ops/webgpu/transpose16.d.ts +1 -0
  326. package/dist/ops/webgpu/transpose16.js +37 -0
  327. package/dist/ops/webgpu/transpose16_program.d.ts +16 -0
  328. package/dist/ops/webgpu/transpose16_program.js +51 -0
  329. package/dist/ops/webgpu/transpose16_shared_program.d.ts +15 -0
  330. package/dist/ops/webgpu/transpose16_shared_program.js +79 -0
  331. package/dist/ops/webgpu/unpack16.d.ts +1 -0
  332. package/dist/ops/webgpu/unpack16.js +60 -0
  333. package/dist/ops/webgpu/utils/binary_op.d.ts +35 -0
  334. package/dist/ops/webgpu/utils/binary_op.js +141 -0
  335. package/dist/ops/webgpu/utils/deviceInfo.d.ts +7 -0
  336. package/dist/ops/webgpu/utils/deviceInfo.js +11 -0
  337. package/dist/ops/webgpu/utils/reductions.d.ts +43 -0
  338. package/dist/ops/webgpu/utils/reductions.js +263 -0
  339. package/dist/pack16-Ck-spx_F.js +39 -0
  340. package/dist/patches/webgpu_backend.d.ts +18 -0
  341. package/dist/patches/webgpu_backend.js +43 -0
  342. package/dist/patches/webgpu_base.d.ts +21 -0
  343. package/dist/patches/webgpu_base.js +22 -0
  344. package/dist/patches/webgpu_program.d.ts +36 -0
  345. package/dist/patches/webgpu_program.js +293 -0
  346. package/dist/pdf-UoDqCYzz.js +16726 -0
  347. package/dist/picomatch-3tUnMMbd.js +1063 -0
  348. package/dist/rope-CbeGlsV8.js +25 -0
  349. package/dist/selu_util-zkAx5doH.js +24 -0
  350. package/dist/shared-D1coEFea.js +1314 -0
  351. package/dist/shared-DOgWaqvL.js +5 -0
  352. package/dist/slice_util-Dgb3ANWI.js +208 -0
  353. package/dist/tfjs_backend-BjuQ5FqB.js +614 -0
  354. package/dist/tokeniser/BaseTokeniser.d.ts +33 -0
  355. package/dist/tokeniser/BaseTokeniser.js +2 -0
  356. package/dist/tokeniser/CharTokeniser.d.ts +24 -0
  357. package/dist/tokeniser/CharTokeniser.js +92 -0
  358. package/dist/tokeniser/bpe.d.ts +28 -0
  359. package/dist/tokeniser/bpe.js +170 -0
  360. package/dist/tokeniser/messages.d.ts +61 -0
  361. package/dist/tokeniser/messages.js +0 -0
  362. package/dist/tokeniser/type.d.ts +34 -0
  363. package/dist/tokeniser/type.js +0 -0
  364. package/dist/training/AdamW.d.ts +36 -0
  365. package/dist/training/AdamW.js +128 -0
  366. package/dist/training/BasicTrainer.d.ts +63 -0
  367. package/dist/training/BasicTrainer.js +265 -0
  368. package/dist/training/DatasetBuilder.d.ts +26 -0
  369. package/dist/training/DatasetBuilder.js +2 -0
  370. package/dist/training/Evaluator.d.ts +19 -0
  371. package/dist/training/Evaluator.js +48 -0
  372. package/dist/training/LRScheduler.d.ts +12 -0
  373. package/dist/training/LRScheduler.js +38 -0
  374. package/dist/training/PreTrainer.d.ts +11 -0
  375. package/dist/training/PreTrainer.js +22 -0
  376. package/dist/training/SFTTrainer.d.ts +12 -0
  377. package/dist/training/SFTTrainer.js +24 -0
  378. package/dist/training/loss.d.ts +3 -0
  379. package/dist/training/loss.js +19 -0
  380. package/dist/training/orthoGrad.d.ts +2 -0
  381. package/dist/training/orthoGrad.js +10 -0
  382. package/dist/training/sparseCrossEntropy.d.ts +7 -0
  383. package/dist/training/sparseCrossEntropy.js +47 -0
  384. package/dist/training/tasks/ConversationTask.d.ts +18 -0
  385. package/dist/training/tasks/ConversationTask.js +38 -0
  386. package/dist/training/tasks/PretrainingTask.d.ts +17 -0
  387. package/dist/training/tasks/PretrainingTask.js +42 -0
  388. package/dist/training/tasks/StartSentenceTask.d.ts +18 -0
  389. package/dist/training/tasks/StartSentenceTask.js +45 -0
  390. package/dist/training/tasks/Task.d.ts +22 -0
  391. package/dist/training/tasks/Task.js +55 -0
  392. package/dist/training/tasks/splitter.d.ts +5 -0
  393. package/dist/training/tasks/splitter.js +18 -0
  394. package/dist/training/types.d.ts +78 -0
  395. package/dist/training/types.js +0 -0
  396. package/dist/training/validation.d.ts +17 -0
  397. package/dist/training/validation.js +2 -0
  398. package/dist/utilities/arrayClose.d.ts +1 -0
  399. package/dist/utilities/arrayClose.js +16 -0
  400. package/dist/utilities/datasetID.d.ts +2 -0
  401. package/dist/utilities/datasetID.js +18 -0
  402. package/dist/utilities/dummy.d.ts +9 -0
  403. package/dist/utilities/dummy.js +36 -0
  404. package/dist/utilities/multinomialCPU.d.ts +2 -0
  405. package/dist/utilities/multinomialCPU.js +9 -0
  406. package/dist/utilities/naming.d.ts +4 -0
  407. package/dist/utilities/naming.js +0 -0
  408. package/dist/utilities/packed.d.ts +4 -0
  409. package/dist/utilities/packed.js +13 -0
  410. package/dist/utilities/parameters.d.ts +11 -0
  411. package/dist/utilities/parameters.js +38 -0
  412. package/dist/utilities/performance.d.ts +2 -0
  413. package/dist/utilities/performance.js +16 -0
  414. package/dist/utilities/profile.d.ts +17 -0
  415. package/dist/utilities/profile.js +33 -0
  416. package/dist/utilities/safetensors.d.ts +3 -0
  417. package/dist/utilities/safetensors.js +53 -0
  418. package/dist/utilities/sentences.d.ts +5 -0
  419. package/dist/utilities/sentences.js +32 -0
  420. package/dist/utilities/tokenParse.d.ts +1 -0
  421. package/dist/utilities/tokenParse.js +17 -0
  422. package/dist/utilities/topP.d.ts +1 -0
  423. package/dist/utilities/topP.js +12 -0
  424. package/dist/utilities/waitForModel.d.ts +2 -0
  425. package/dist/utilities/waitForModel.js +12 -0
  426. package/dist/utilities/weights.d.ts +12 -0
  427. package/dist/utilities/weights.js +40 -0
  428. package/dist/utilities/yielder.d.ts +1 -0
  429. package/dist/utilities/yielder.js +7 -0
  430. package/dist/webgpu-Dt7BMzWz.js +525 -0
  431. package/dist/webgpu_program-WOyIVMlZ.js +392 -0
  432. package/dist/webgpu_util-B_F3SShA.js +106 -0
  433. package/package.json +1 -1
@@ -0,0 +1,712 @@
1
+ import { a as e } from "./chunk-BPntVaq0.js";
2
+ import { Mi as t, Ms as n, Ps as r, V as i, Zr as a, bi as o, di as s, fi as c, ji as l, mt as ee, ni as u, wi as d, yi as f } from "./dist-BewPQWjc.js";
3
+ import { n as p } from "./dist-DXwIvKxl.js";
4
+ //#region node_modules/@tensorflow/tfjs-data/dist/util/deep_map.js
5
+ var m = /* @__PURE__ */ e(ee());
6
+ function h(e, t) {
7
+ return g(e, t);
8
+ }
9
+ function g(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
10
+ if (e == null) return null;
11
+ if (typeof Blob == "function" && e instanceof Blob) return e.slice();
12
+ if (r.has(e)) throw Error("Circular references are not supported.");
13
+ if (n.has(e)) return n.get(e);
14
+ let i = t(e);
15
+ if (i.recurse && i.value !== null) throw Error("A deep map function may not return both a value and recurse=true.");
16
+ if (!i.recurse) return n.set(e, i.value), i.value;
17
+ if (b(e)) {
18
+ let i = Array.isArray(e) ? [] : {};
19
+ r.add(e);
20
+ for (let a in e) {
21
+ let o = e[a];
22
+ i[a] = g(o, t, n, r);
23
+ }
24
+ return r.delete(e), e.__proto__ && (i.__proto__ = e.__proto__), i;
25
+ } else throw Error(`Can't recurse into non-iterable type: ${e}`);
26
+ }
27
+ function _(e, t = y) {
28
+ return v(e, t);
29
+ }
30
+ function v(e, t, n = /* @__PURE__ */ new Set()) {
31
+ let r = e[0];
32
+ if (n.has(r)) throw Error("Circular references are not supported.");
33
+ let i = t(e);
34
+ if (i.recurse && i.value !== null) throw Error("A deep zip function may not return both a value and recurse=true.");
35
+ if (!i.recurse) return i.value;
36
+ if (b(r)) {
37
+ let i = Array.isArray(r) ? [] : {};
38
+ n.add(r);
39
+ for (let a in r) i[a] = v(e.map((e) => e[a]), t, n);
40
+ return n.delete(r), i;
41
+ } else throw Error(`Can't recurse into non-iterable type: ${r}`);
42
+ }
43
+ function y(e) {
44
+ return e === null ? null : b(e[0]) ? {
45
+ value: null,
46
+ recurse: !0
47
+ } : {
48
+ value: e,
49
+ recurse: !1
50
+ };
51
+ }
52
+ function b(e) {
53
+ let t = !1;
54
+ if (n().get("IS_BROWSER")) t = e instanceof TextDecoder;
55
+ else {
56
+ let { StringDecoder: n } = a();
57
+ t = e instanceof n;
58
+ }
59
+ return e != null && !ArrayBuffer.isView(e) && (Array.isArray(e) || typeof e == "object" && !(e instanceof d) && !(e instanceof Promise) && !t);
60
+ }
61
+ function x(e) {
62
+ return e == null || S(e) || Array.isArray(e) || typeof e == "object" && e instanceof d || l(e);
63
+ }
64
+ function S(e) {
65
+ return e === null || typeof e != "object" && typeof e != "function";
66
+ }
67
+ //#endregion
68
+ //#region node_modules/@tensorflow/tfjs-data/dist/util/deep_clone.js
69
+ function C(e) {
70
+ return h(e, w);
71
+ }
72
+ function w(e) {
73
+ return e instanceof d ? {
74
+ value: e.clone(),
75
+ recurse: !1
76
+ } : b(e) ? {
77
+ value: null,
78
+ recurse: !0
79
+ } : {
80
+ value: e,
81
+ recurse: !1
82
+ };
83
+ }
84
+ //#endregion
85
+ //#region node_modules/@tensorflow/tfjs-data/dist/util/ring_buffer.js
86
+ var T = class {
87
+ constructor(e) {
88
+ if (this.capacity = e, this.begin = 0, this.end = 0, e == null) throw RangeError("Can't create a ring buffer of unknown capacity.");
89
+ if (e < 1) throw RangeError("Can't create ring buffer of capacity < 1.");
90
+ this.data = Array(e), this.doubledCapacity = 2 * e;
91
+ }
92
+ wrap(e) {
93
+ for (; e < 0;) e += this.doubledCapacity;
94
+ return e % this.doubledCapacity;
95
+ }
96
+ get(e) {
97
+ if (e < 0) throw RangeError("Can't get item at a negative index.");
98
+ return this.data[e % this.capacity];
99
+ }
100
+ set(e, t) {
101
+ if (e < 0) throw RangeError("Can't set item at a negative index.");
102
+ this.data[e % this.capacity] = t;
103
+ }
104
+ length() {
105
+ let e = this.end - this.begin;
106
+ return e < 0 && (e = this.doubledCapacity + e), e;
107
+ }
108
+ isFull() {
109
+ return this.length() === this.capacity;
110
+ }
111
+ isEmpty() {
112
+ return this.length() === 0;
113
+ }
114
+ push(e) {
115
+ if (this.isFull()) throw RangeError("Ring buffer is full.");
116
+ this.set(this.end, e), this.end = this.wrap(this.end + 1);
117
+ }
118
+ pushAll(e) {
119
+ for (let t of e) this.push(t);
120
+ }
121
+ pop() {
122
+ if (this.isEmpty()) throw RangeError("Ring buffer is empty.");
123
+ this.end = this.wrap(this.end - 1);
124
+ let e = this.get(this.end);
125
+ return this.set(this.end, void 0), e;
126
+ }
127
+ unshift(e) {
128
+ if (this.isFull()) throw RangeError("Ring buffer is full.");
129
+ this.begin = this.wrap(this.begin - 1), this.set(this.begin, e);
130
+ }
131
+ shift() {
132
+ if (this.isEmpty()) throw RangeError("Ring buffer is empty.");
133
+ let e = this.get(this.begin);
134
+ return this.set(this.begin, void 0), this.begin = this.wrap(this.begin + 1), e;
135
+ }
136
+ shuffleExcise(e) {
137
+ if (this.isEmpty()) throw RangeError("Ring buffer is empty.");
138
+ let t = this.wrap(this.begin + e), n = this.get(t);
139
+ return this.set(t, this.pop()), n;
140
+ }
141
+ }, E = class e extends T {
142
+ constructor() {
143
+ super(e.INITIAL_CAPACITY);
144
+ }
145
+ isFull() {
146
+ return !1;
147
+ }
148
+ push(e) {
149
+ super.isFull() && this.expand(), super.push(e);
150
+ }
151
+ unshift(e) {
152
+ super.isFull() && this.expand(), super.unshift(e);
153
+ }
154
+ expand() {
155
+ let e = this.capacity * 2, t = Array(e), n = this.length();
156
+ for (let e = 0; e < n; e++) t[e] = this.get(this.wrap(this.begin + e));
157
+ this.data = t, this.capacity = e, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = n;
158
+ }
159
+ };
160
+ E.INITIAL_CAPACITY = 32;
161
+ //#endregion
162
+ //#region node_modules/@tensorflow/tfjs-data/dist/iterators/lazy_iterator.js
163
+ function D(e) {
164
+ return new j(e);
165
+ }
166
+ function O(e) {
167
+ return new M(e);
168
+ }
169
+ function k(e, t) {
170
+ return new U(e, t);
171
+ }
172
+ var A = class {
173
+ async toArray() {
174
+ let e = [], t = await this.next();
175
+ for (; !t.done;) e.push(t.value), t = await this.next();
176
+ return e;
177
+ }
178
+ async toArrayForTest() {
179
+ let e = this.prefetch(100), t = [], n = await e.next();
180
+ for (; !n.done;) t.push(n.value), n = await e.next();
181
+ return t;
182
+ }
183
+ async resolveFully() {
184
+ let e = await this.next();
185
+ for (; !e.done;) e = await this.next();
186
+ }
187
+ async resolveWhile(e) {
188
+ let t = await this.next(), n = e(t.value);
189
+ for (; !t.done && n;) t = await this.next(), n = e(t.value);
190
+ }
191
+ handleErrors(e) {
192
+ return new z(this, e);
193
+ }
194
+ filter(e) {
195
+ return new L(this, e);
196
+ }
197
+ map(e) {
198
+ return new R(this, e);
199
+ }
200
+ mapAsync(e) {
201
+ return new B(this, e);
202
+ }
203
+ serialMapAsync(e) {
204
+ return new B(this, e).serial();
205
+ }
206
+ flatmap(e) {
207
+ return new H(this, e);
208
+ }
209
+ async forEachAsync(e) {
210
+ return this.map(e).resolveFully();
211
+ }
212
+ async serialForEach(e) {
213
+ return this.serialMapAsync(e).resolveWhile((e) => e === !0);
214
+ }
215
+ rowMajorBatch(e, t = !0) {
216
+ return new I(this, e, t);
217
+ }
218
+ columnMajorBatch(e, t = !0, n = y) {
219
+ return this.rowMajorBatch(e, t).map((e) => _(e, n));
220
+ }
221
+ concatenate(e, t) {
222
+ return new U(D([this, e]), t);
223
+ }
224
+ take(e) {
225
+ return e < 0 || e == null ? this : new F(this, e);
226
+ }
227
+ skip(e) {
228
+ return e < 0 || e == null ? this : new P(this, e);
229
+ }
230
+ prefetch(e) {
231
+ return new G(this, e);
232
+ }
233
+ shuffle(e, t) {
234
+ return new K(this, e, t);
235
+ }
236
+ serial() {
237
+ return new N(this);
238
+ }
239
+ }, j = class extends A {
240
+ constructor(e) {
241
+ super(), this.items = e, this.trav = 0;
242
+ }
243
+ summary() {
244
+ return `Array of ${this.items.length} items`;
245
+ }
246
+ async next() {
247
+ if (this.trav >= this.items.length) return {
248
+ value: null,
249
+ done: !0
250
+ };
251
+ let e = this.items[this.trav];
252
+ return this.trav++, {
253
+ value: C(e),
254
+ done: !1
255
+ };
256
+ }
257
+ }, M = class extends A {
258
+ constructor(e) {
259
+ super(), this.nextFn = e;
260
+ }
261
+ summary() {
262
+ return "Function call";
263
+ }
264
+ async next() {
265
+ try {
266
+ return this.nextFn();
267
+ } catch (e) {
268
+ throw e.message = `Error thrown while iterating through a dataset: ${e.message}`, e;
269
+ }
270
+ }
271
+ }, N = class extends A {
272
+ constructor(e) {
273
+ super(), this.upstream = e, this.lastRead = Promise.resolve({
274
+ value: null,
275
+ done: !1
276
+ });
277
+ }
278
+ summary() {
279
+ return `${this.upstream.summary()} -> Serial`;
280
+ }
281
+ async next() {
282
+ return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
283
+ }
284
+ async serialNext() {
285
+ return this.upstream.next();
286
+ }
287
+ }, P = class extends A {
288
+ constructor(e, t) {
289
+ super(), this.upstream = e, this.maxCount = t, this.count = 0, this.lastRead = Promise.resolve({
290
+ value: null,
291
+ done: !1
292
+ });
293
+ }
294
+ summary() {
295
+ return `${this.upstream.summary()} -> Skip`;
296
+ }
297
+ async next() {
298
+ return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
299
+ }
300
+ async serialNext() {
301
+ for (; this.count++ < this.maxCount;) {
302
+ let e = await this.upstream.next();
303
+ if (e.done) return e;
304
+ u(e.value);
305
+ }
306
+ return this.upstream.next();
307
+ }
308
+ }, F = class extends A {
309
+ constructor(e, t) {
310
+ super(), this.upstream = e, this.maxCount = t, this.count = 0;
311
+ }
312
+ summary() {
313
+ return `${this.upstream.summary()} -> Take`;
314
+ }
315
+ async next() {
316
+ return this.count++ >= this.maxCount ? {
317
+ value: null,
318
+ done: !0
319
+ } : this.upstream.next();
320
+ }
321
+ }, I = class extends A {
322
+ constructor(e, t, n = !0) {
323
+ super(), this.upstream = e, this.batchSize = t, this.enableSmallLastBatch = n, this.lastRead = Promise.resolve({
324
+ value: null,
325
+ done: !1
326
+ });
327
+ }
328
+ summary() {
329
+ return `${this.upstream.summary()} -> RowMajorBatch`;
330
+ }
331
+ async next() {
332
+ return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
333
+ }
334
+ async serialNext() {
335
+ let e = [];
336
+ for (; e.length < this.batchSize;) {
337
+ let t = await this.upstream.next();
338
+ if (t.done) return this.enableSmallLastBatch && e.length > 0 ? {
339
+ value: e,
340
+ done: !1
341
+ } : {
342
+ value: null,
343
+ done: !0
344
+ };
345
+ e.push(t.value);
346
+ }
347
+ return {
348
+ value: e,
349
+ done: !1
350
+ };
351
+ }
352
+ }, L = class extends A {
353
+ constructor(e, t) {
354
+ super(), this.upstream = e, this.predicate = t, this.lastRead = Promise.resolve({
355
+ value: null,
356
+ done: !1
357
+ });
358
+ }
359
+ summary() {
360
+ return `${this.upstream.summary()} -> Filter`;
361
+ }
362
+ async next() {
363
+ return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
364
+ }
365
+ async serialNext() {
366
+ for (;;) {
367
+ let e = await this.upstream.next();
368
+ if (e.done || this.predicate(e.value)) return e;
369
+ u(e.value);
370
+ }
371
+ }
372
+ }, R = class extends A {
373
+ constructor(e, t) {
374
+ super(), this.upstream = e, this.transform = t;
375
+ }
376
+ summary() {
377
+ return `${this.upstream.summary()} -> Map`;
378
+ }
379
+ async next() {
380
+ let e = await this.upstream.next();
381
+ if (e.done) return {
382
+ value: null,
383
+ done: !0
384
+ };
385
+ let t = f(e.value), n = this.transform(e.value), r = f(n);
386
+ for (let e of t) o(e, r) || e.dispose();
387
+ return {
388
+ value: n,
389
+ done: !1
390
+ };
391
+ }
392
+ }, z = class extends A {
393
+ constructor(e, t) {
394
+ super(), this.upstream = e, this.handler = t, this.count = 0, this.lastRead = Promise.resolve({
395
+ value: null,
396
+ done: !1
397
+ });
398
+ }
399
+ summary() {
400
+ return `${this.upstream.summary()} -> handleErrors`;
401
+ }
402
+ async next() {
403
+ return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
404
+ }
405
+ async serialNext() {
406
+ for (;;) try {
407
+ return await this.upstream.next();
408
+ } catch (e) {
409
+ if (!this.handler(e)) return {
410
+ value: null,
411
+ done: !0
412
+ };
413
+ }
414
+ }
415
+ }, B = class extends A {
416
+ constructor(e, t) {
417
+ super(), this.upstream = e, this.transform = t;
418
+ }
419
+ summary() {
420
+ return `${this.upstream.summary()} -> AsyncMap`;
421
+ }
422
+ async next() {
423
+ let e = await this.upstream.next();
424
+ if (e.done) return {
425
+ value: null,
426
+ done: !0
427
+ };
428
+ let t = f(e.value), n = await this.transform(e.value), r = f(n);
429
+ for (let e of t) o(e, r) || e.dispose();
430
+ return {
431
+ value: n,
432
+ done: !1
433
+ };
434
+ }
435
+ }, V = class extends A {
436
+ constructor() {
437
+ super(), this.outputQueue = new E(), this.lastRead = Promise.resolve({
438
+ value: null,
439
+ done: !1
440
+ });
441
+ }
442
+ async next() {
443
+ return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
444
+ }
445
+ async serialNext() {
446
+ for (; this.outputQueue.length() === 0;) if (!await this.pump()) return {
447
+ value: null,
448
+ done: !0
449
+ };
450
+ return {
451
+ value: this.outputQueue.shift(),
452
+ done: !1
453
+ };
454
+ }
455
+ }, H = class extends V {
456
+ constructor(e, t) {
457
+ super(), this.upstream = e, this.transform = t;
458
+ }
459
+ summary() {
460
+ return `${this.upstream.summary()} -> Flatmap`;
461
+ }
462
+ async pump() {
463
+ let e = await this.upstream.next();
464
+ if (e.done) return !1;
465
+ let t = f(e.value), n = this.transform(e.value), r = f(n);
466
+ this.outputQueue.pushAll(n);
467
+ for (let e of t) o(e, r) || e.dispose();
468
+ return !0;
469
+ }
470
+ }, U = class extends A {
471
+ constructor(e, t) {
472
+ super(), this.baseErrorHandler = t, this.lastRead = null, this.iterator = null, this.moreIterators = e;
473
+ }
474
+ summary() {
475
+ return "TODO: fill in upstream of chained summaries -> Chained";
476
+ }
477
+ async next() {
478
+ return this.lastRead = this.readFromChain(this.lastRead), this.lastRead;
479
+ }
480
+ async readFromChain(e) {
481
+ if (await e, this.iterator == null) {
482
+ let e = await this.moreIterators.next();
483
+ if (e.done) return {
484
+ value: null,
485
+ done: !0
486
+ };
487
+ this.iterator = e.value, this.baseErrorHandler != null && (this.iterator = this.iterator.handleErrors(this.baseErrorHandler));
488
+ }
489
+ let t = await this.iterator.next();
490
+ return t.done ? (this.iterator = null, this.readFromChain(e)) : t;
491
+ }
492
+ }, W;
493
+ (function(e) {
494
+ e[e.FAIL = 0] = "FAIL", e[e.SHORTEST = 1] = "SHORTEST", e[e.LONGEST = 2] = "LONGEST";
495
+ })(W ||= {});
496
+ var G = class extends A {
497
+ constructor(e, t) {
498
+ super(), this.upstream = e, this.bufferSize = t, this.buffer = new T(t);
499
+ }
500
+ summary() {
501
+ return `${this.upstream.summary()} -> Prefetch`;
502
+ }
503
+ refill() {
504
+ for (; !this.buffer.isFull();) {
505
+ let e = this.upstream.next();
506
+ this.buffer.push(e);
507
+ }
508
+ }
509
+ next() {
510
+ return this.refill(), this.buffer.shift();
511
+ }
512
+ }, K = class extends G {
513
+ constructor(e, n, r) {
514
+ super(e, n), this.upstream = e, this.windowSize = n, this.upstreamExhausted = !1, this.random = m.alea(r || t().toString()), this.lastRead = Promise.resolve({
515
+ value: null,
516
+ done: !1
517
+ });
518
+ }
519
+ async next() {
520
+ return this.lastRead = this.lastRead.then(() => this.serialNext()), this.lastRead;
521
+ }
522
+ randomInt(e) {
523
+ return Math.floor(this.random() * e);
524
+ }
525
+ chooseIndex() {
526
+ return this.randomInt(this.buffer.length());
527
+ }
528
+ async serialNext() {
529
+ for (this.upstreamExhausted || this.refill(); !this.buffer.isEmpty();) {
530
+ let e = this.chooseIndex(), t = await this.buffer.shuffleExcise(e);
531
+ if (t.done) this.upstreamExhausted = !0;
532
+ else return this.refill(), t;
533
+ }
534
+ return {
535
+ value: null,
536
+ done: !0
537
+ };
538
+ }
539
+ }, q = class {
540
+ constructor() {
541
+ this.size = null;
542
+ }
543
+ batch(e, t = !0) {
544
+ let n = this;
545
+ r(e > 0, () => `batchSize needs to be positive, but it is
546
+ ${e}`);
547
+ let i;
548
+ return i = this.size === Infinity || this.size == null ? this.size : t ? Math.ceil(this.size / e) : Math.floor(this.size / e), J(async () => (await n.iterator()).columnMajorBatch(e, t, Y), i);
549
+ }
550
+ concatenate(e) {
551
+ let t = this, n;
552
+ return n = this.size === Infinity || e.size === Infinity ? Infinity : this.size != null && e.size != null ? this.size + e.size : null, J(async () => (await t.iterator()).concatenate(await e.iterator()), n);
553
+ }
554
+ filter(e) {
555
+ let t = this, n;
556
+ return n = this.size === Infinity ? Infinity : null, J(async () => (await t.iterator()).filter((t) => s(() => e(t))), n);
557
+ }
558
+ async forEachAsync(e) {
559
+ return (await this.iterator()).forEachAsync(e);
560
+ }
561
+ map(e) {
562
+ let t = this;
563
+ return J(async () => (await t.iterator()).map((t) => s(() => e(t))), this.size);
564
+ }
565
+ mapAsync(e) {
566
+ let t = this;
567
+ return J(async () => (await t.iterator()).mapAsync(e), this.size);
568
+ }
569
+ prefetch(e) {
570
+ if (e == null) throw RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
571
+ let t = this;
572
+ return J(async () => (await t.iterator()).prefetch(e), this.size);
573
+ }
574
+ repeat(e) {
575
+ let t = this, n;
576
+ return n = this.size != null && e > 0 ? this.size * e : e === 0 ? 0 : this.size != null && (e === void 0 || e < 0) ? Infinity : null, J(async () => k(O(async () => ({
577
+ value: await t.iterator(),
578
+ done: !1
579
+ })).take(e)), n);
580
+ }
581
+ skip(e) {
582
+ let t = this, n;
583
+ 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, J(async () => (await t.iterator()).skip(e), n);
584
+ }
585
+ shuffle(e, n, r = !0) {
586
+ 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)`);
587
+ let i = this, a = m.alea(n || t().toString());
588
+ return J(async () => {
589
+ let t = a.int32();
590
+ return r && (t += a.int32()), (await i.iterator()).shuffle(e, t.toString());
591
+ }, this.size);
592
+ }
593
+ take(e) {
594
+ let t = this, n;
595
+ return n = this.size != null && this.size > e ? e : this.size != null && this.size <= e ? this.size : null, J(async () => (await t.iterator()).take(e), n);
596
+ }
597
+ async toArray() {
598
+ if (this.size === Infinity) throw Error("Can not convert infinite data stream to array.");
599
+ return (await this.iterator()).toArray();
600
+ }
601
+ async toArrayForTest() {
602
+ if (this.size === Infinity) throw Error("Can not convert infinite data stream to array.");
603
+ return (await this.iterator()).toArrayForTest();
604
+ }
605
+ };
606
+ q.MAX_BUFFER_SIZE = 1e4;
607
+ function J(e, t = null) {
608
+ return new class extends q {
609
+ constructor() {
610
+ super(...arguments), this.size = t;
611
+ }
612
+ async iterator() {
613
+ return e();
614
+ }
615
+ }();
616
+ }
617
+ function Y(e) {
618
+ if (e === null) return null;
619
+ let t = e[0];
620
+ return x(t) ? {
621
+ value: X(e),
622
+ recurse: !1
623
+ } : {
624
+ value: null,
625
+ recurse: !0
626
+ };
627
+ }
628
+ function X(e) {
629
+ if (e.length === 0) throw Error("Can't make a batch of zero elements.");
630
+ return e[0] instanceof d ? i(e) : c(e);
631
+ }
632
+ //#endregion
633
+ //#region node_modules/@tensorflow/tfjs-data/dist/iterators/string_iterator.js
634
+ p();
635
+ //#endregion
636
+ //#region node_modules/@tensorflow/tfjs-data/dist/readers.js
637
+ function Z(e) {
638
+ return J(async () => {
639
+ let t = await e();
640
+ return O(() => t.next());
641
+ });
642
+ }
643
+ //#endregion
644
+ //#region lib/training/DatasetBuilder.ts
645
+ var Q = 8;
646
+ function te(e, t) {
647
+ let n = e.map((e) => t.encodeConversation(e)).flat();
648
+ return new Uint16Array(n);
649
+ }
650
+ function ne(e, t) {
651
+ let n = e.map((e) => t.encodeConversation(e, !1, !0));
652
+ console.log("Tokenised Texts with Mask:", n);
653
+ let r = n.map((e) => e.tokens).flat(), i = n.map((e) => e.mask).flat();
654
+ return {
655
+ tokens: new Uint16Array(r),
656
+ mask: new Uint8Array(i.map((e) => +!!e))
657
+ };
658
+ }
659
+ function $(e) {
660
+ for (let t = e.length - 1; t > 0; t--) {
661
+ let n = Math.floor(Math.random() * (t + 1));
662
+ [e[t], e[n]] = [e[n], e[t]];
663
+ }
664
+ return e;
665
+ }
666
+ var re = class {
667
+ tokenizer;
668
+ blockSize;
669
+ constructor(e, t = 128) {
670
+ this.tokenizer = e, this.blockSize = t;
671
+ }
672
+ async createTextDataset(e, t = 32, n, r, i = 65535) {
673
+ if (e.length < this.blockSize + 1) throw Error(`Not enough tokens (${e.length}) for block size ${this.blockSize}`);
674
+ let a = {
675
+ shuffledIndexes: new Uint32Array(e.length),
676
+ step: 0
677
+ };
678
+ if (n) a.shuffledIndexes = n;
679
+ else {
680
+ a.shuffledIndexes = new Uint32Array(e.length);
681
+ for (let t = 0; t < e.length; t++) a.shuffledIndexes[t] = t;
682
+ $(a.shuffledIndexes);
683
+ }
684
+ return {
685
+ dataset: Z(function* () {
686
+ for (;;) {
687
+ let t = a.shuffledIndexes[a.step++];
688
+ if (a.step >= a.shuffledIndexes.length && (a.step = 0, $(a.shuffledIndexes)), t + this.blockSize + 1 > e.length) continue;
689
+ let n = new Int32Array(e.subarray(t, t + this.blockSize)), o = e.subarray(t + 1, t + this.blockSize + 1), s = new Int32Array(o);
690
+ if (r) {
691
+ let e = 0;
692
+ for (let n = 0; n < s.length; n++) r[t + 1 + n] === 0 && (s[n] = i, e++);
693
+ if (e === s.length) continue;
694
+ }
695
+ yield {
696
+ xs: n,
697
+ ys: s
698
+ };
699
+ }
700
+ }.bind(this)).batch(t).map((e) => {
701
+ let t = e;
702
+ return s(() => ({
703
+ xs: t.xs.cast("int32"),
704
+ ys: t.ys.cast("int32")
705
+ }));
706
+ }).prefetch(2),
707
+ state: a
708
+ };
709
+ }
710
+ };
711
+ //#endregion
712
+ export { $ as a, ne as i, Q as n, te as r, re as t };