@genai-fi/nanogpt 0.20.0 → 0.20.2

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-D5CbfCiV.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,293 @@
1
+ import { Ln as e, Ms as t, Ns as n, Ps as r } from "../dist-BewPQWjc.js";
2
+ import { a as i, c as a, f as o, i as s, o as c, r as l, u } from "../webgpu_program-WOyIVMlZ.js";
3
+ //#region lib/patches/webgpu_program.ts
4
+ var d = /* @__PURE__ */ function(e) {
5
+ return e[e.FROM_PIXELS = 0] = "FROM_PIXELS", e[e.DRAW = 1] = "DRAW", e;
6
+ }({}), f = (e, n, r, i, a) => {
7
+ let o = p(r, {
8
+ dtype: i.dtype,
9
+ shape: i.shape
10
+ }, n), s = e.createShaderModule({
11
+ code: o,
12
+ label: n.constructor.name
13
+ }), c = t().get("WEBGPU_PRINT_SHADER");
14
+ if (c !== "") {
15
+ c = c.toLowerCase();
16
+ let e = c.split(",");
17
+ (c === "all" || e.some((e) => n.shaderKey.toLowerCase().includes(e))) && (console.group(n.shaderKey), console.debug(o), console.groupEnd());
18
+ }
19
+ return a ? e.createComputePipelineAsync({
20
+ compute: {
21
+ module: s,
22
+ entryPoint: "_start"
23
+ },
24
+ label: n.constructor.name,
25
+ layout: "auto"
26
+ }) : e.createComputePipeline({
27
+ compute: {
28
+ module: s,
29
+ entryPoint: "_start"
30
+ },
31
+ label: n.constructor.name,
32
+ layout: "auto"
33
+ });
34
+ };
35
+ function p(e, t, n) {
36
+ let r = [], a = n.workgroupSize[0] * n.workgroupSize[1] * n.workgroupSize[2];
37
+ if (n.outputComponent = n.outputComponent ? n.outputComponent : 1, r.push(`
38
+
39
+ var<private> localId: vec3<u32>;
40
+ var<private> localIndex: u32;
41
+ var<private> globalId: vec3<u32>;
42
+ var<private> numWorkgroups: vec3<u32>;
43
+ var<private> workgroupId: vec3<u32>;
44
+ ${n.subgroupBuiltins ? "var<private> subgroupInvocationId: u32;" : ""}
45
+ ${n.subgroupBuiltins ? "var<private> subgroupSize: u32;" : ""}
46
+
47
+ // Only used when the y/z dimension of workgroup size is 1.
48
+ fn getGlobalIndex() -> i32 {
49
+ ${x(n) ? " return i32(globalId.x);" : ` return i32((workgroupId.z * numWorkgroups.x * numWorkgroups.y +
50
+ workgroupId.y * numWorkgroups.x + workgroupId.x) * ${a}u +
51
+ localIndex);
52
+ `}
53
+ }
54
+ `), n.pixelsOpType != null) {
55
+ let a = n.pixelsOpType === 0 ? `@group(0) @binding(0) var<storage, read_write> result: array<${l(t.dtype, n.outputComponent)}>;` : `@group(0) @binding(1) var<storage, read> inBuf : array<${l(e[0].dtype, n.outputComponent)}>;`, o = t.shape.length === 3 ? "vec2<i32>" : "i32";
56
+ r.push(`
57
+ struct Uniform {
58
+ outShapeStrides : ${o},
59
+ size : i32,
60
+ numChannels : i32,
61
+ alpha : f32,
62
+ };
63
+
64
+ ${a}
65
+ @group(0) @binding(2) var<uniform> uniforms: Uniform;
66
+ `);
67
+ let s = w(n);
68
+ return [
69
+ m,
70
+ r.join("\n"),
71
+ i(t.shape),
72
+ n.getUserCode(),
73
+ T(s, n)
74
+ ].join("\n");
75
+ }
76
+ let o, c, u = "struct Uniforms { NAN : f32, INFINITY : f32, ";
77
+ n.variableNames.forEach((t, n) => {
78
+ let r = s(e[n].shape.length);
79
+ u += `${t.charAt(0).toLowerCase() + t.slice(1)}Shape : ${r}, `, o = e[n].shape.length - 1, c = s(o), u += `${t.charAt(0).toLowerCase() + t.slice(1)}ShapeStrides: ${c}, `;
80
+ });
81
+ let d = s(t.shape.length);
82
+ u += `outShape : ${d}, `, o = t.shape.length - 1, c = s(o), u += `
83
+ outShapeStrides: ${c}, `, n.size && (u += "size : i32, "), n.uniforms && (u += n.uniforms), u += "};", u = C(u), r.push(u), n.atomic ? r.push("\n @group(0) @binding(0) var<storage, read_write> result: array<atomic<i32>>;\n ") : r.push(`
84
+ @group(0) @binding(0) var<storage, read_write> result: array<${l(t.dtype, n.outputComponent)}>;
85
+ `), n.variableNames.forEach((t, i) => {
86
+ r.push(`
87
+ @group(0) @binding(${1 + i}) var<storage, read> ${t}: array<${n.variableComponents ? l(e[i].dtype, n.variableComponents[i]) : l(e[i].dtype, n.outputComponent)}>;
88
+ `);
89
+ }), u !== "" && r.push(`
90
+ @group(0) @binding(${1 + n.variableNames.length}) var<uniform> uniforms: Uniforms;
91
+ `);
92
+ let f = y(t.shape, n.dispatchLayout), p = [
93
+ n.subgroups ? "enable subgroups;" : "",
94
+ m,
95
+ r.join("\n") + h,
96
+ i(t.shape),
97
+ f,
98
+ b(t.shape.length)
99
+ ];
100
+ n.atomic || p.push(S(t.shape, t.dtype, n.outputComponent)), n.variableNames.forEach((t, n) => {
101
+ p.push(`${i(e[n].shape, t)}`);
102
+ });
103
+ let g = e.map((e, r) => v(e, t.shape, n.variableComponents ? n.variableComponents[r] : n.outputComponent, n.dispatchLayout.x.length === t.shape.length)).join("\n");
104
+ p.push(g), p.push(n.getUserCode());
105
+ let _ = w(n);
106
+ return p.push(T(_, n)), p.join("\n");
107
+ }
108
+ var m = "\n struct vec5 {x: i32, y: i32, z: i32, w: i32, u: i32};\n struct vec6 {x: i32, y: i32, z: i32, w: i32, u: i32, v: i32};\n\n // Checks whether coordinates lie within the bounds of the shape.\n fn coordsInBounds2D(coord : vec2<i32>, shape : vec2<i32>) -> bool {\n return all(coord >= vec2<i32>(0)) && all(coord < shape);\n }\n fn coordsInBounds3D(coord : vec3<i32>, shape : vec3<i32>) -> bool {\n return all(coord >= vec3<i32>(0)) && all(coord < shape);\n }\n fn coordsInBounds4D(coord : vec4<i32>, shape : vec4<i32>) -> bool {\n return all(coord >= vec4<i32>(0)) && all(coord < shape);\n }\n\n fn getIndexFromCoords1D(coord : i32, shape : i32) -> i32 {\n return coord;\n }\n fn getIndexFromCoords2D(coords : vec2<i32>, shape : vec2<i32>) -> i32 {\n return dot(coords, vec2<i32>(shape.y, 1));\n }\n fn getIndexFromCoords3D(coords : vec3<i32>, shape : vec3<i32>) -> i32 {\n return dot(coords, vec3<i32>(shape.y * shape.z, shape.z, 1));\n }\n fn getIndexFromCoords4D(coords : vec4<i32>, shape : vec4<i32>) -> i32 {\n return dot(coords, vec4<i32>(\n shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1));\n }\n fn getIndexFromCoords5D(coords : vec5, shape : vec5) -> i32 {\n let shapeStrides: vec5 = vec5(shape.y * shape.z * shape.w * shape.u, shape.z * shape.w * shape.u, shape.w * shape.u, shape.u, 1);\n return coords.x*shapeStrides.x + coords.y*shapeStrides.y + coords.z*shapeStrides.z + coords.w*shapeStrides.w + coords.u*shapeStrides.u;\n }\n fn getIndexFromCoords6D(coords : vec6, shape : vec6) -> i32 {\n let shapeStrides: vec6 = vec6(shape.y * shape.z * shape.w * shape.u * shape.v, shape.z * shape.w * shape.u * shape.v, shape.w * shape.u * shape.v, shape.u * shape.v, shape.v, 1);\n return coords.x*shapeStrides.x + coords.y*shapeStrides.y + coords.z*shapeStrides.z + coords.w*shapeStrides.w + coords.u*shapeStrides.u + coords.v*shapeStrides.v;\n }\n\n // NaN defination in IEEE 754-1985 is :\n // - sign = either 0 or 1.\n // - biased exponent = all 1 bits.\n // - fraction = anything except all 0 bits (since all 0 bits represents infinity).\n // https://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbers\n fn isnan(val: f32) -> bool {\n let floatToUint: u32 = bitcast<u32>(val);\n return (floatToUint & 0x7fffffffu) > 0x7f800000u;\n }\n fn isnanVec4(val : vec4<f32>) -> vec4<bool> {\n let floatToUint: vec4<u32> = bitcast<vec4<u32>>(val);\n return (floatToUint & vec4<u32>(0x7fffffffu)) > vec4<u32>(0x7f800000u);\n }\n", h = "\n fn isinf(val: f32) -> bool {\n return abs(val) == uniforms.INFINITY;\n }\n";
109
+ function g(e, t) {
110
+ let n = e.name, r = e.shape.length, i = s(r), a = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = [
111
+ "d0",
112
+ "d1",
113
+ "d2",
114
+ "d3",
115
+ "d4",
116
+ "d5"
117
+ ].slice(0, r), c = o.map((e) => `${e} : i32`).join(", ");
118
+ if (r < 1) return `
119
+ fn ${a}() -> ${u(t)} {
120
+ return ${u(t)}(${n}[0]);
121
+ }
122
+ `;
123
+ let l = `uniforms.${n.charAt(0).toLowerCase() + n.slice(1)}Shape`, d = `${r}D`;
124
+ return r === 0 && (d = "1D"), `
125
+ fn ${a}(${c}) -> ${u(t)} {
126
+ return ${u(t)}(${n}[getIndexFromCoords${d}(${i}(${o.join(",")}),
127
+ ${l})${t === 1 ? "" : ` / ${t}`}]);
128
+ }
129
+ `;
130
+ }
131
+ function _(t, r, i, a) {
132
+ let o = t.name, l = o.charAt(0).toUpperCase() + o.slice(1), d = "get" + l + "ByOutput", f = t.shape.length, p = r.length, m = s(p);
133
+ if (n(t.shape, r) && a) return `
134
+ fn ${d}Index(globalIndex : i32) -> ${u(i)} {
135
+ return ${u(i)}(${o}[globalIndex]);
136
+ }
137
+
138
+ fn ${d}Coords(coords : ${m}) -> ${u(i)} {
139
+ return ${u(i)}(${o}[${p > 1 ? "getOutputIndexFromCoords(coords)" : "coords"}${i === 1 ? "" : ` / ${i}`}]);
140
+ }
141
+ `;
142
+ let h = e(t.shape, r), g = p - f, _ = "";
143
+ if (f === 0) return `
144
+ fn ${d}Index(globalIndex : i32) -> ${u(i)}{
145
+ return get${l}();
146
+ }
147
+
148
+ fn ${d}Coords(coords : ${m}) -> ${u(i)}{
149
+ return get${l}();
150
+ }
151
+ `;
152
+ _ = p < 2 && h.length >= 1 ? "coords = 0;" : h.map((e) => `coords.${c(e + g)} = 0;`).join("\n");
153
+ let v = "";
154
+ v = p < 2 && f > 0 ? "coords" : p > 1 ? `${s(f)}(${t.shape.map((e, t) => `coords.${c(t + g)}`).join(", ")})` : "coords";
155
+ let y = `uniforms.${o.charAt(0).toLowerCase() + o.slice(1)}Shape`, b = `${f}D`;
156
+ return `
157
+ fn ${d}Index(globalIndex : i32) -> ${u(i)} {
158
+ var coords = getCoordsFromIndex(globalIndex);
159
+ ${_}
160
+ return ${u(i)}(${o}[getIndexFromCoords${b}(${v}, ${y})${i === 1 ? "" : ` / ${i}`}]);
161
+ }
162
+
163
+ fn ${d}Coords(coordsIn : ${m}) -> ${u(i)} {
164
+ var coords = coordsIn;
165
+ ${_}
166
+ return ${u(i)}(${o}[getIndexFromCoords${b}(${v}, ${y})${i === 1 ? "" : ` / ${i}`}]);
167
+ }
168
+ `;
169
+ }
170
+ function v(e, t, n, r) {
171
+ let i = g(e, n);
172
+ return e.shape.length <= t.length && (i += _(e, t, n, r)), i;
173
+ }
174
+ function y(e, t) {
175
+ let { x: n, y: r = [], z: i = [] } = t, a = e.length, c = n.length + r.length + i.length;
176
+ if (c !== a) return "";
177
+ if (n.length === a) return `fn getOutputCoords() -> ${s(a)}{
178
+ let globalIndex = getGlobalIndex();
179
+ return getCoordsFromIndex(globalIndex);
180
+ }
181
+ `;
182
+ let l = "", u = [
183
+ n,
184
+ r,
185
+ i
186
+ ];
187
+ for (let e = 0; e < u.length; e++) {
188
+ let t = u[e];
189
+ if (t.length !== 0) if (t.length === 1) l += `let d${t[0]} = i32(globalId[${e}]);`;
190
+ else {
191
+ let n = o(t, "uniforms.outShape");
192
+ l += `var index${e} = i32(globalId[${e}]);`;
193
+ for (let r = 0; r < n.length; r++) l += `let d${t[r]} = index${e} / ${n[r]};`, r === n.length - 1 ? l += `let d${t[r + 1]} = index${e} - d${t[r]} * ${n[r]};` : l += `index${e} = index${e} - d${t[r]} * ${n[r]};`;
194
+ }
195
+ }
196
+ let d = [];
197
+ for (let e = 0; e < c; e++) d.push(`d${e}`);
198
+ let f = s(c), p = `fn getOutputCoords() -> ${f} {
199
+ ${l}
200
+ `;
201
+ return d.length === 0 ? p += `return ${f}(0); }` : p += `return ${f}(${d.join(",")}); }`, p;
202
+ }
203
+ function b(e) {
204
+ let t = "";
205
+ switch (e) {
206
+ case 0:
207
+ case 1:
208
+ t += "\n fn getOutputIndexFromCoords(coords : i32) -> i32 {\n return coords;\n }\n ";
209
+ break;
210
+ case 2:
211
+ t += "\n fn getOutputIndexFromCoords(coords : vec2<i32>) -> i32 {\n return dot(coords, vec2<i32>(uniforms.outShapeStrides, 1));\n }\n ";
212
+ break;
213
+ case 3:
214
+ t += "\n fn getOutputIndexFromCoords(coords : vec3<i32>) -> i32 {\n return dot(coords, vec3<i32>(uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, 1));\n }\n ";
215
+ break;
216
+ case 4:
217
+ t += "\n fn getOutputIndexFromCoords(coords : vec4<i32>) -> i32 {\n return dot(coords, vec4<i32>(\n uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, uniforms.outShapeStrides.z, 1));\n }\n ";
218
+ break;
219
+ case 5:
220
+ t += "\n fn getOutputIndexFromCoords(coords : vec5) -> i32 {\n return coords.x * uniforms.outShapeStrides.x +\n coords.y * uniforms.outShapeStrides.y +\n coords.z * uniforms.outShapeStrides.z +\n coords.w * uniforms.outShapeStrides.w +\n coords.u;\n }\n ";
221
+ break;
222
+ case 6:
223
+ t += "\n fn getOutputIndexFromCoords(coords : vec6) -> i32 {\n return coords.x * uniforms.outShapeStrides.x +\n coords.y * uniforms.outShapeStrides.y +\n coords.z * uniforms.outShapeStrides.z +\n coords.w * uniforms.outShapeStrides.w +\n coords.u * uniforms.outShapeStrides.u +\n coords.v;\n }\n ";
224
+ break;
225
+ default:
226
+ r(!1, () => `Unsupported ${e}D shape`);
227
+ break;
228
+ }
229
+ return t;
230
+ }
231
+ function x(e) {
232
+ return e.dispatch[1] === 1 && e.dispatch[2] === 1;
233
+ }
234
+ function S(e, t, n) {
235
+ let r = e.length, i = l(t, n), a = `fn setOutputAtIndex(flatIndex : i32, value : ${u(n)}) {
236
+ result[flatIndex] = ${i}(value);
237
+ }
238
+
239
+ fn setOutputAtIndexI32(flatIndex : i32, value : ${u(n, "i32")}) {
240
+ result[flatIndex] = ${i}(value);
241
+ }
242
+ `;
243
+ if (r >= 2) {
244
+ let e = [
245
+ "d0",
246
+ "d1",
247
+ "d2",
248
+ "d3",
249
+ "d4",
250
+ "d5"
251
+ ].slice(0, r), t = s(r);
252
+ a += `
253
+ fn setOutputAtCoords(${e.map((e) => `${e} : i32`).join(", ")}, value : ${u(n)}) {
254
+ let flatIndex = getOutputIndexFromCoords(${t}(${e.join(", ")}));
255
+ setOutputAtIndex(flatIndex${n === 1 ? "" : ` / ${n}`}, value);
256
+ }
257
+ fn setOutputAtCoordsI32(${e.map((e) => `${e} : i32`).join(", ")}, value : ${u(n, "i32")}) {
258
+ let flatIndex = getOutputIndexFromCoords(${t}(${e.join(", ")}));
259
+ setOutputAtIndexI32(flatIndex${n === 1 ? "" : ` / ${n}`}, value);
260
+ }
261
+ `;
262
+ }
263
+ return a;
264
+ }
265
+ function C(e) {
266
+ return e = e.replace(/(\w+)\s*:\s*vec(5|6)/g, (e) => "@align(16) " + e), e = e.replace(/vec(5|6)\s*,\s*(\w+)/g, (e, t, n) => `vec${t}, @align(16) ${n}`), e;
267
+ }
268
+ function w(e) {
269
+ return !(e.dispatchLayout.hasOwnProperty("y") && e.dispatchLayout.y?.length !== 0 || e.dispatchLayout.hasOwnProperty("z") && e.dispatchLayout.z?.length !== 0);
270
+ }
271
+ function T(e, t) {
272
+ return `
273
+ ${a(t)}
274
+ fn _start(@builtin(local_invocation_id) LocalId : vec3<u32>,
275
+ @builtin(global_invocation_id) GlobalId : vec3<u32>,
276
+ @builtin(local_invocation_index) LocalIndex: u32,
277
+ @builtin(workgroup_id) WorkgroupId : vec3<u32>,
278
+ ${t.subgroupBuiltins ? "@builtin(subgroup_invocation_id) SubgroupInvocationId : u32," : ""}
279
+ ${t.subgroupBuiltins ? "@builtin(subgroup_size) SubgroupSize : u32," : ""}
280
+ @builtin(num_workgroups) NumWorkgroups : vec3<u32>) {
281
+ localId = LocalId;
282
+ localIndex = LocalIndex;
283
+ globalId = GlobalId;
284
+ numWorkgroups = NumWorkgroups;
285
+ workgroupId = WorkgroupId;
286
+ ${t.subgroupBuiltins ? "subgroupInvocationId = SubgroupInvocationId" : ""};
287
+ ${t.subgroupBuiltins ? "subgroupSize = SubgroupSize" : ""};
288
+ ${e ? "main(getGlobalIndex());" : "main();"};
289
+ }
290
+ `;
291
+ }
292
+ //#endregion
293
+ export { d as PixelsOpType, f as compileProgram, T as getStartHeaderString };