@genai-fi/nanogpt 1.6.1 → 1.7.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 (427) 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 +10 -10
  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 +37052 -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 +16 -9
  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 +7 -7
  111. package/dist/training/tasks/TokenStore.d.ts +4 -4
  112. package/dist/training/tasks/tokenStream.d.ts +3 -3
  113. package/dist/training/types.d.ts +8 -7
  114. package/dist/training/validateOptions.d.ts +1 -1
  115. package/dist/training/validation.d.ts +5 -5
  116. package/dist/utilities/datasetID.d.ts +1 -1
  117. package/dist/utilities/dummy.d.ts +1 -1
  118. package/dist/utilities/packed.d.ts +1 -1
  119. package/dist/utilities/parameters.d.ts +1 -1
  120. package/dist/utilities/sentences.d.ts +1 -1
  121. package/dist/utilities/waitForModel.d.ts +1 -1
  122. package/dist/webgpu-D4syGmzo.js +3221 -0
  123. package/dist/webgpu-wUCQopBN.js +1007 -0
  124. package/dist/{webgpu_program-DvkFqRlR.js → webgpu_backend-CzY9TzvA.js} +174 -223
  125. package/dist/{patches/webgpu_base.js → webgpu_base-Bjg7okYf.js} +6 -9
  126. package/package.json +12 -9
  127. package/dist/DatasetBuilder-DRDW8tcM.js +0 -731
  128. package/dist/Generator-8IK28IWR.js +0 -316
  129. package/dist/RealDiv-Cl8k3YTx.js +0 -354
  130. package/dist/Reshape-CKxKPKqi.js +0 -91
  131. package/dist/Reshape-H5zZRgr9.js +0 -16
  132. package/dist/RoPECache-dYscFINl.js +0 -722
  133. package/dist/TeachableLLM.js +0 -220
  134. package/dist/api/beamer.js +0 -61
  135. package/dist/api/responses.js +0 -177
  136. package/dist/api/training.js +0 -215
  137. package/dist/axis_util-rF9RnwKE.js +0 -37
  138. package/dist/backend.js +0 -12
  139. package/dist/backend_util-Cpp0Gwlp.js +0 -394
  140. package/dist/broadcast_to-CGvLNiQ0.js +0 -20
  141. package/dist/checks/appendCache.js +0 -55
  142. package/dist/checks/attentionMask.js +0 -57
  143. package/dist/checks/check.js +0 -31
  144. package/dist/checks/gelu.js +0 -46
  145. package/dist/checks/index.js +0 -27
  146. package/dist/checks/matMulGelu.js +0 -84
  147. package/dist/checks/normRMS.js +0 -30
  148. package/dist/checks/normRMSGrad.js +0 -23
  149. package/dist/checks/packUnpack.js +0 -46
  150. package/dist/checks/qkv.js +0 -1
  151. package/dist/checks/rope.js +0 -30
  152. package/dist/checks/weights.js +0 -26
  153. package/dist/clip_by_value-D-UX9am5.js +0 -13
  154. package/dist/complex-Cl904TqN.js +0 -13
  155. package/dist/complex_util-BBlPAm-s.js +0 -59
  156. package/dist/concat-Oip5acVY.js +0 -14
  157. package/dist/concat_util-CY45Hf4F.js +0 -18
  158. package/dist/data/docx.js +0 -17
  159. package/dist/data/pdf.js +0 -14
  160. package/dist/data/stream.js +0 -1
  161. package/dist/data/textLoader.js +0 -575
  162. package/dist/data-CV_i_H6B.js +0 -11
  163. package/dist/data.js +0 -5
  164. package/dist/dist-DyL7qSLJ.js +0 -7809
  165. package/dist/dropout16-CA31Ud5a.js +0 -20
  166. package/dist/dropout_util-SiFMbFXz.js +0 -22
  167. package/dist/eventemitter3-wmfmOP_f.js +0 -90
  168. package/dist/expand_dims-Dh3Fulyn.js +0 -10
  169. package/dist/floor-BwjmUb7X.js +0 -8
  170. package/dist/gather-B5Z1RFt5.js +0 -14
  171. package/dist/gatherSub-CRUfUzBa.js +0 -22
  172. package/dist/gelu-Xx9-ohH9.js +0 -25
  173. package/dist/gpgpu_math-48m8q3jI.js +0 -1591
  174. package/dist/inference/Beamer.js +0 -215
  175. package/dist/inference/Generator.js +0 -1
  176. package/dist/inference/tokenisePrompt.js +0 -17
  177. package/dist/inference/types.js +0 -0
  178. package/dist/inference/utilities.js +0 -31
  179. package/dist/jszip.min-Btv48m44.js +0 -3037
  180. package/dist/kernel_funcs_utils-BYRpSfV_.js +0 -229
  181. package/dist/layers/BaseLayer.js +0 -75
  182. package/dist/layers/GQA.js +0 -102
  183. package/dist/layers/HeadLayer.js +0 -28
  184. package/dist/layers/LoRA.js +0 -45
  185. package/dist/layers/MHA.js +0 -102
  186. package/dist/layers/MLP.js +0 -47
  187. package/dist/layers/PositionEmbedding.js +0 -28
  188. package/dist/layers/RMSNorm.js +0 -25
  189. package/dist/layers/RoPECache.js +0 -1
  190. package/dist/layers/TiedEmbedding.js +0 -33
  191. package/dist/layers/TransformerBlock.js +0 -50
  192. package/dist/layers/WeightStore.js +0 -68
  193. package/dist/layers-CFqEip3s.js +0 -13
  194. package/dist/layers.js +0 -6
  195. package/dist/loader/load.js +0 -63
  196. package/dist/loader/loadHF.js +0 -17
  197. package/dist/loader/loadTransformers.js +0 -61
  198. package/dist/loader/loadZipMeta.js +0 -15
  199. package/dist/loader/newZipLoad.js +0 -24
  200. package/dist/loader/oldZipLoad.js +0 -36
  201. package/dist/loader/save.js +0 -89
  202. package/dist/loader/types.js +0 -0
  203. package/dist/main.js +0 -12145
  204. package/dist/matMul16-tE26fnhf.js +0 -87
  205. package/dist/matMulGelu-ASUWlKqu.js +0 -162
  206. package/dist/mat_mul-R9_DWmIT.js +0 -16
  207. package/dist/models/Llama.js +0 -88
  208. package/dist/models/NanoGPTV1.js +0 -94
  209. package/dist/models/NanoGPTV2.js +0 -85
  210. package/dist/models/Qwen3.js +0 -88
  211. package/dist/models/config.js +0 -32
  212. package/dist/models/factory.js +0 -16
  213. package/dist/models/model.js +0 -75
  214. package/dist/models-DyBpJJwM.js +0 -13
  215. package/dist/models.js +0 -6
  216. package/dist/mul16-C7sqgqik.js +0 -41
  217. package/dist/non_max_suppression_impl-B0H318rb.js +0 -72
  218. package/dist/not_equal-Bu3O8rh_.js +0 -67
  219. package/dist/one_hot-TEMPumJj.js +0 -14
  220. package/dist/ones-DpPXWa6A.js +0 -13
  221. package/dist/ops/adamAdjust.js +0 -17
  222. package/dist/ops/adamMoments.js +0 -15
  223. package/dist/ops/add16.js +0 -11
  224. package/dist/ops/appendCache.js +0 -26
  225. package/dist/ops/attentionMask.js +0 -19
  226. package/dist/ops/concat16.js +0 -8
  227. package/dist/ops/cpu/adamAdjust.js +0 -15
  228. package/dist/ops/cpu/adamMoments.js +0 -16
  229. package/dist/ops/cpu/appendCache.js +0 -65
  230. package/dist/ops/cpu/attentionMask.js +0 -20
  231. package/dist/ops/cpu/fusedSoftmax.js +0 -22
  232. package/dist/ops/cpu/gatherSub.js +0 -1
  233. package/dist/ops/cpu/gelu.js +0 -35
  234. package/dist/ops/cpu/matMul16.js +0 -14
  235. package/dist/ops/cpu/matMulGelu.js +0 -44
  236. package/dist/ops/cpu/matMulMul.js +0 -19
  237. package/dist/ops/cpu/mulDropout.js +0 -19
  238. package/dist/ops/cpu/normRMS.js +0 -34
  239. package/dist/ops/cpu/qkv.js +0 -74
  240. package/dist/ops/cpu/rope.js +0 -84
  241. package/dist/ops/cpu/scatterSub.js +0 -1
  242. package/dist/ops/dot16.js +0 -28
  243. package/dist/ops/dropout.js +0 -12
  244. package/dist/ops/dropout16.js +0 -1
  245. package/dist/ops/gatherSub.js +0 -12
  246. package/dist/ops/gelu.js +0 -1
  247. package/dist/ops/globalNorm.js +0 -19
  248. package/dist/ops/grads/add16.js +0 -26
  249. package/dist/ops/grads/attentionMask.js +0 -25
  250. package/dist/ops/grads/dropout16.js +0 -1
  251. package/dist/ops/grads/gelu.js +0 -1
  252. package/dist/ops/grads/matMul16.js +0 -1
  253. package/dist/ops/grads/matMulGelu.js +0 -21
  254. package/dist/ops/grads/mul16.js +0 -1
  255. package/dist/ops/grads/normRMS.js +0 -36
  256. package/dist/ops/grads/pack16.js +0 -1
  257. package/dist/ops/grads/qkv.js +0 -46
  258. package/dist/ops/grads/rope.js +0 -1
  259. package/dist/ops/grads/silu.js +0 -1
  260. package/dist/ops/grads/softmax16.js +0 -22
  261. package/dist/ops/grads/unpack16.js +0 -1
  262. package/dist/ops/grads/utils.js +0 -11
  263. package/dist/ops/log.js +0 -1
  264. package/dist/ops/matMul16.js +0 -1
  265. package/dist/ops/matMulGelu.js +0 -19
  266. package/dist/ops/matMulMul.js +0 -15
  267. package/dist/ops/mul16.js +0 -1
  268. package/dist/ops/mulDrop.js +0 -14
  269. package/dist/ops/normRMS.js +0 -21
  270. package/dist/ops/pack16.js +0 -1
  271. package/dist/ops/qkv.js +0 -15
  272. package/dist/ops/reshape16.js +0 -33
  273. package/dist/ops/rope.js +0 -1
  274. package/dist/ops/scatterSub.js +0 -12
  275. package/dist/ops/silu.js +0 -1
  276. package/dist/ops/slice16.js +0 -11
  277. package/dist/ops/softmax16.js +0 -8
  278. package/dist/ops/sub16.js +0 -10
  279. package/dist/ops/sum16.js +0 -13
  280. package/dist/ops/transpose16.js +0 -33
  281. package/dist/ops/unpack16.js +0 -1
  282. package/dist/ops/webgl/adamAdjust.js +0 -81
  283. package/dist/ops/webgl/adamMoments.js +0 -43
  284. package/dist/ops/webgl/appendCache.js +0 -52
  285. package/dist/ops/webgl/attentionMask.js +0 -63
  286. package/dist/ops/webgl/dropout16.js +0 -11
  287. package/dist/ops/webgl/fusedSoftmax.js +0 -70
  288. package/dist/ops/webgl/gatherSub.js +0 -27
  289. package/dist/ops/webgl/gelu.js +0 -47
  290. package/dist/ops/webgl/log.js +0 -14
  291. package/dist/ops/webgl/matMul16.js +0 -48
  292. package/dist/ops/webgl/matMulGelu.js +0 -1
  293. package/dist/ops/webgl/matMulMul.js +0 -23
  294. package/dist/ops/webgl/mulDropout.js +0 -31
  295. package/dist/ops/webgl/normRMS.js +0 -115
  296. package/dist/ops/webgl/qkv.js +0 -53
  297. package/dist/ops/webgl/rope.js +0 -73
  298. package/dist/ops/webgl/scatterSub.js +0 -27
  299. package/dist/ops/webgpu/adamAdjust.js +0 -76
  300. package/dist/ops/webgpu/adamMoments.js +0 -75
  301. package/dist/ops/webgpu/add16.js +0 -13
  302. package/dist/ops/webgpu/appendCache.js +0 -129
  303. package/dist/ops/webgpu/attentionMask.js +0 -41
  304. package/dist/ops/webgpu/attentionMask32_program.js +0 -61
  305. package/dist/ops/webgpu/clipScale.js +0 -44
  306. package/dist/ops/webgpu/concat16.js +0 -110
  307. package/dist/ops/webgpu/dropout16.js +0 -58
  308. package/dist/ops/webgpu/gatherSub.js +0 -51
  309. package/dist/ops/webgpu/gelu.js +0 -146
  310. package/dist/ops/webgpu/index.js +0 -27
  311. package/dist/ops/webgpu/matMul16.js +0 -91
  312. package/dist/ops/webgpu/matMul16_program.js +0 -311
  313. package/dist/ops/webgpu/mul16.js +0 -13
  314. package/dist/ops/webgpu/norm2.js +0 -45
  315. package/dist/ops/webgpu/normRMS.js +0 -25
  316. package/dist/ops/webgpu/normRMS16_program.js +0 -28
  317. package/dist/ops/webgpu/normRMS32_program.js +0 -28
  318. package/dist/ops/webgpu/normRMSGrad.js +0 -225
  319. package/dist/ops/webgpu/pack16.js +0 -20
  320. package/dist/ops/webgpu/pack16_program.js +0 -92
  321. package/dist/ops/webgpu/qkv.js +0 -63
  322. package/dist/ops/webgpu/rope.js +0 -227
  323. package/dist/ops/webgpu/scatterSub.js +0 -52
  324. package/dist/ops/webgpu/silu.js +0 -117
  325. package/dist/ops/webgpu/slice16.js +0 -73
  326. package/dist/ops/webgpu/softmax16.js +0 -18
  327. package/dist/ops/webgpu/softmax16_program.js +0 -88
  328. package/dist/ops/webgpu/softmax16_subgroup_program.js +0 -69
  329. package/dist/ops/webgpu/softmax16grad.js +0 -30
  330. package/dist/ops/webgpu/sub16.js +0 -13
  331. package/dist/ops/webgpu/sum16.js +0 -30
  332. package/dist/ops/webgpu/transpose16.js +0 -38
  333. package/dist/ops/webgpu/transpose16_program.js +0 -50
  334. package/dist/ops/webgpu/transpose16_shared_program.js +0 -78
  335. package/dist/ops/webgpu/unpack16.js +0 -59
  336. package/dist/ops/webgpu/utils/binary_op.js +0 -140
  337. package/dist/ops/webgpu/utils/deviceInfo.js +0 -10
  338. package/dist/ops/webgpu/utils/reductions.js +0 -264
  339. package/dist/ops-Be5ACU5R.js +0 -13
  340. package/dist/ops-C1UpdEYM.js +0 -509
  341. package/dist/pack16-BHO4t1-M.js +0 -36
  342. package/dist/pad-Dy-1IP3A.js +0 -13
  343. package/dist/patches/webgpu_backend.js +0 -42
  344. package/dist/patches/webgpu_program.js +0 -292
  345. package/dist/picomatch--TW6gyBJ.js +0 -999
  346. package/dist/qkv-BQfNPucX.js +0 -42
  347. package/dist/rand_util-_vCY93Uw.js +0 -44
  348. package/dist/random_normal-DUIT8kyC.js +0 -11
  349. package/dist/range-CYvQC3fW.js +0 -13
  350. package/dist/relu-C4XULT8A.js +0 -8
  351. package/dist/reshape-DJb1jgMt.js +0 -8
  352. package/dist/resize_nearest_neighbor-DAqcTYUe.js +0 -188
  353. package/dist/rope-JjBVufF_.js +0 -24
  354. package/dist/scatterSub-BOnqk-uY.js +0 -27
  355. package/dist/scatter_nd_util-BepMCpLY.js +0 -34
  356. package/dist/seedrandom-SHEGFK6H.js +0 -282
  357. package/dist/selu_util-DeOTf-sc.js +0 -27
  358. package/dist/shared-CX_iPI5K.js +0 -4
  359. package/dist/silu-DsAE2cJ5.js +0 -23
  360. package/dist/slice-Dlb1FlzG.js +0 -13
  361. package/dist/slice_util-BVgPRoij.js +0 -207
  362. package/dist/softmax-Dpav_dWw.js +0 -10
  363. package/dist/split-DYnT8chz.js +0 -11
  364. package/dist/squeeze-B3XYGAlg.js +0 -9
  365. package/dist/stack-Dbbt9mIk.js +0 -10
  366. package/dist/step-DA-5DNu9.js +0 -348
  367. package/dist/stream-BBe2apn4.js +0 -2280
  368. package/dist/sum-C8qNbFNp.js +0 -13
  369. package/dist/tensor-ALxWZfmz.js +0 -7
  370. package/dist/tensor1d-BHgkkhTE.js +0 -9
  371. package/dist/tensor2d-ARItvqVn.js +0 -10
  372. package/dist/tensor4d-D1zRBipJ.js +0 -10
  373. package/dist/tfjs_backend-CsXOum0h.js +0 -685
  374. package/dist/tile-DfyQ0KX-.js +0 -10
  375. package/dist/tokenise-DbS2Ea-T.js +0 -14
  376. package/dist/tokenise.js +0 -6
  377. package/dist/tokeniser/BaseTokeniser.js +0 -137
  378. package/dist/tokeniser/CharTokeniser.js +0 -85
  379. package/dist/tokeniser/bpe.js +0 -156
  380. package/dist/tokeniser/messages.js +0 -0
  381. package/dist/tokeniser/type.js +0 -0
  382. package/dist/topk-BrU2pkrR.js +0 -19
  383. package/dist/training/AdamW.js +0 -132
  384. package/dist/training/BasicTrainer.js +0 -274
  385. package/dist/training/DatasetBuilder.js +0 -1
  386. package/dist/training/Evaluator.js +0 -51
  387. package/dist/training/LRScheduler.js +0 -37
  388. package/dist/training/PreTrainer.js +0 -21
  389. package/dist/training/SFTTrainer.js +0 -23
  390. package/dist/training/configure.js +0 -33
  391. package/dist/training/factory.js +0 -7
  392. package/dist/training/loss.js +0 -18
  393. package/dist/training/orthoGrad.js +0 -9
  394. package/dist/training/prepareData.js +0 -51
  395. package/dist/training/sparseCrossEntropy.js +0 -53
  396. package/dist/training/tasks/TokenStore.js +0 -217
  397. package/dist/training/tasks/tokenStream.js +0 -45
  398. package/dist/training/types.js +0 -0
  399. package/dist/training/validateOptions.js +0 -18
  400. package/dist/training/validation.js +0 -30
  401. package/dist/transpose-BC-M_OoT.js +0 -34
  402. package/dist/unsorted_segment_sum-BelC7R-q.js +0 -408
  403. package/dist/utilities/arrayClose.js +0 -29
  404. package/dist/utilities/arrayShape.js +0 -7
  405. package/dist/utilities/datasetID.js +0 -17
  406. package/dist/utilities/dummy.js +0 -36
  407. package/dist/utilities/float16.js +0 -46
  408. package/dist/utilities/maxHeap.js +0 -54
  409. package/dist/utilities/multinomialCPU.js +0 -7
  410. package/dist/utilities/naming.js +0 -0
  411. package/dist/utilities/packed.js +0 -12
  412. package/dist/utilities/parameters.js +0 -53
  413. package/dist/utilities/performance.js +0 -15
  414. package/dist/utilities/profile.js +0 -32
  415. package/dist/utilities/random.js +0 -18
  416. package/dist/utilities/safetensors.js +0 -63
  417. package/dist/utilities/sentences.js +0 -35
  418. package/dist/utilities/tokenParse.js +0 -16
  419. package/dist/utilities/tokens.js +0 -39
  420. package/dist/utilities/topP.js +0 -25
  421. package/dist/utilities/waitForModel.js +0 -11
  422. package/dist/utilities/weights.js +0 -40
  423. package/dist/utilities/yielder.js +0 -6
  424. package/dist/v4-YCkfo8OR.js +0 -27
  425. package/dist/webgpu-BHX-uBym.js +0 -518
  426. package/dist/webgpu_util-5QTyovaf.js +0 -105
  427. package/dist/zeros-hxKGkRfl.js +0 -12
@@ -1,87 +0,0 @@
1
- import { H as e, bt as t } from "./dist-CMMLi-qO.js";
2
- import { t as n } from "./gelu-Xx9-ohH9.js";
3
- import { transpose16 as r } from "./ops/transpose16.js";
4
- import { reshape16 as i } from "./ops/reshape16.js";
5
- import { t as a } from "./mul16-C7sqgqik.js";
6
- import { t as o } from "./silu-DsAE2cJ5.js";
7
- import "./ops/webgl/matMul16.js";
8
- import "./ops/cpu/matMul16.js";
9
- import { isPackedTensor as s } from "./utilities/packed.js";
10
- import { t as c } from "./pack16-BHO4t1-M.js";
11
- // lib/ops/grads/matMul16.ts
12
- var l = {
13
- kernelName: "MatMul16",
14
- inputsToSave: ["A", "B"],
15
- outputsToSave: [],
16
- gradFunc: (e, t, s) => {
17
- let [c, l] = t;
18
- if (Array.isArray(e)) throw Error("Expected dy to be a single Tensor");
19
- let d = e, { transposeA: m, transposeB: h, scale: g, activation: _, originalShape: v, perm: y } = s;
20
- if (y && v) {
21
- let e = Array(y.length);
22
- for (let t = 0; t < y.length; ++t) e[y[t]] = t;
23
- let t = d;
24
- d = r(d, e), t.dispose();
25
- }
26
- if (v) {
27
- let e = d;
28
- d = i(d, v), e.dispose();
29
- }
30
- if (_ === "gelu") {
31
- let e = d, t = u(c, l, m, h);
32
- d = n(e, t), e.dispose(), t.dispose();
33
- } else if (_ === "relu2") {
34
- let e = d, t = u(c, l, m, h, {
35
- activation: "relu",
36
- scale: 2
37
- });
38
- d = a(e, t), e.dispose(), t.dispose();
39
- } else if (_ === "silu") {
40
- let e = d, t = u(c, l, m, h);
41
- d = o(e, t), e.dispose(), t.dispose();
42
- }
43
- if (!m && !h) return {
44
- A: () => g === void 0 ? u(d, l, !1, !0) : f(d, l, g, !1, !0),
45
- B: () => g === void 0 ? u(c, d, !0, !1) : p(c, d, g, !0, !1)
46
- };
47
- if (!m && h) return {
48
- A: () => g === void 0 ? u(d, l, !1, !1) : f(d, l, g, !1, !1),
49
- B: () => g === void 0 ? u(c, d, !0, !1) : p(c, d, g, !0, !1)
50
- };
51
- if (m && !h) return {
52
- A: () => g === void 0 ? u(l, d, !1, !0) : p(l, d, g, !1, !0),
53
- B: () => g === void 0 ? u(c, d, !1, !1) : p(c, d, g, !1, !1)
54
- };
55
- throw Error("Gradient for transposeA=true and transposeB=true is not supported yet.");
56
- }
57
- };
58
- t(l);
59
- // lib/ops/matMul16.ts
60
- function u(t, n, r = !1, i = !1, a = {}, o) {
61
- let l = s(t), u = s(n), d = l || u, f = !d || l ? t : c(t), p = !d || u ? n : c(n), m = e().runKernel("MatMul16", o ? {
62
- A: f,
63
- B: p,
64
- mask: o
65
- } : {
66
- A: f,
67
- B: p
68
- }, {
69
- transposeA: r,
70
- transposeB: i,
71
- ...a
72
- });
73
- return d && !l && f.dispose(), d && !u && p.dispose(), m;
74
- }
75
- function d(e, t, n, r = !1, i = !1) {
76
- return u(e, t, r, i, { scale: n });
77
- }
78
- function f(e, t, n, r = !1, i = !1) {
79
- return u(e, t, r, i, { scaleA: n });
80
- }
81
- function p(e, t, n, r = !1, i = !1) {
82
- return u(e, t, r, i, { scaleB: n });
83
- }
84
- function m(e, t, n = !1, r = !1) {
85
- return u(e, t, n, r, { activation: "gelu" });
86
- }
87
- export { d as a, p as i, m as n, l as o, f as r, u as t };
@@ -1,162 +0,0 @@
1
- import { C as e, H as t, Y as n, lt as r, qi as i, xt as a, yi as o } from "./dist-CMMLi-qO.js";
2
- import { t as s } from "./mat_mul-R9_DWmIT.js";
3
- import { t as c } from "./Reshape-CKxKPKqi.js";
4
- import { a as l } from "./gpgpu_math-48m8q3jI.js";
5
- // node_modules/@tensorflow/tfjs-backend-webgl/dist/mulmat_packed_gpu.js
6
- var u = class {
7
- constructor(e, t, n, r = !1, i = !1, a = !1, o = null, s = !1, c = !1) {
8
- this.variableNames = ["matrixA", "matrixB"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = n, this.enableShapeUniforms = l(this.outputShape.length);
9
- let u = r ? e[1] : e[2], d = Math.ceil(u / 2), f = r ? "i * 2, rc.y" : "rc.y, i * 2", p = i ? "rc.z, i * 2" : "i * 2, rc.z", m = r ? ["a.xxyy", "a.zzww"] : ["a.xxzz", "a.yyww"], h = i ? ["b.xzxz", "b.ywyw"] : ["b.xyxy", "b.zwzw"], g = "", _ = "";
10
- o && (g = s ? `vec4 activation(vec4 a) {
11
- vec4 b = getPreluActivationWeightsAtOutCoords();
12
- ${o}
13
- }` : c ? `vec4 activation(vec4 a) {
14
- vec4 b = getLeakyreluAlphaAtOutCoords();
15
- ${o}
16
- }` : `vec4 activation(vec4 x) {
17
- ${o}
18
- }`, _ = "result = activation(result);");
19
- let v = a ? "result += getBiasAtOutCoords();" : "";
20
- a && this.variableNames.push("bias"), s && this.variableNames.push("preluActivationWeights"), c && this.variableNames.push("leakyreluAlpha");
21
- let y = "rc.x", b = "rc.x";
22
- e[0] < t[0] ? y = `imod(rc.x, ${e[0]})` : t[0] < e[0] && (b = `imod(rc.x, ${t[0]})`), this.userCode = `
23
- ${g}
24
- // Don't use uniform for sharedDimensionPacked for performance.
25
- const float sharedDimension = ${d}.0;
26
-
27
- vec4 dot2x2ARowBCol(ivec3 rc) {
28
- vec4 result = vec4(0);
29
- int batchA = ${y};
30
- int batchB = ${b};
31
- for (int i = 0; i < ${d}; i++) {
32
- vec4 a = getMatrixA(batchA, ${f});
33
- vec4 b = getMatrixB(batchB, ${p});
34
-
35
- // These swizzled products need to be separately added.
36
- // See: https://github.com/tensorflow/tfjs/issues/1735
37
- result += (${m[0]} * ${h[0]});
38
- result += (${m[1]} * ${h[1]});
39
- }
40
- return result;
41
- }
42
-
43
- void main() {
44
- ivec3 rc = getOutputCoords();
45
- vec4 result = dot2x2ARowBCol(rc);
46
-
47
- ${v}
48
-
49
- ${_}
50
-
51
- setOutput(result);
52
- }
53
- `;
54
- }
55
- }, d = .7978845608028654, f = .044715, p = `
56
- vec4 x3 = x * x * x;
57
- vec4 inner = x + ${f} * x3;
58
- inner = ${d} * inner;
59
- inner = vec4(
60
- abs(inner[0]) > 15.0 ? sign(inner[0]) : tanh(inner[0]),
61
- abs(inner[1]) > 15.0 ? sign(inner[1]) : tanh(inner[1]),
62
- abs(inner[2]) > 15.0 ? sign(inner[2]) : tanh(inner[2]),
63
- abs(inner[3]) > 15.0 ? sign(inner[3]) : tanh(inner[3])
64
- );
65
- inner = 0.5 * (1.0 + inner);
66
- vec4 result = x * inner;
67
- return result;
68
- `, m = `
69
- vec4 a2 = a * a;
70
- vec4 a3 = a2 * a;
71
- vec4 u = ${d} * (a + ${f} * a3);
72
- vec4 t = vec4(
73
- abs(u[0]) > 15.0 ? sign(u[0]) : tanh(u[0]),
74
- abs(u[1]) > 15.0 ? sign(u[1]) : tanh(u[1]),
75
- abs(u[2]) > 15.0 ? sign(u[2]) : tanh(u[2]),
76
- abs(u[3]) > 15.0 ? sign(u[3]) : tanh(u[3])
77
- );
78
- vec4 sech2 = 1.0 - t * t;
79
- vec4 du_dx = ${d} * (1.0 + 3.0 * ${f} * a2);
80
- vec4 dgelu = 0.5 * (1.0 + t) + 0.5 * a * sech2 * du_dx;
81
- return dgelu * b;
82
- `, h = 1e3;
83
- function g({ a: t, b: n, transposeA: a, transposeB: s, backend: l, activationSnippet: d, multiplier: f }) {
84
- let p = t.shape.length, m = n.shape.length, h = a ? t.shape[p - 2] : t.shape[p - 1], g = s ? n.shape[m - 1] : n.shape[m - 2], _ = a ? t.shape[p - 1] : t.shape[p - 2], v = s ? n.shape[m - 2] : n.shape[m - 1], y = t.shape.slice(0, -2), b = n.shape.slice(0, -2), x = i(y), S = i(b), C = e(t.shape.slice(0, -2), n.shape.slice(0, -2)).concat([_, v]);
85
- o(h === g, () => `Error in matMul: inner shapes (${h}) and (${g}) of Tensors with shapes ${t.shape} and ${n.shape} and transposeA=${a} and transposeB=${s} must match.`);
86
- let w = a ? [
87
- x,
88
- h,
89
- _
90
- ] : [
91
- x,
92
- _,
93
- h
94
- ], T = s ? [
95
- S,
96
- v,
97
- g
98
- ] : [
99
- S,
100
- g,
101
- v
102
- ], E = c({
103
- inputs: { x: t },
104
- backend: l,
105
- attrs: { shape: w }
106
- }), D = c({
107
- inputs: { x: n },
108
- backend: l,
109
- attrs: { shape: T }
110
- }), O = [E, D], k = Math.max(x, S), A = d, j = r(t.dtype, n.dtype), M = new u(w, T, [
111
- k,
112
- _,
113
- v
114
- ], a, s, !1, A, !!f, !1), N = [E, D];
115
- f && N.push(f);
116
- let P = l.runWebGLProgram(M, N, j), F = c({
117
- inputs: { x: P },
118
- backend: l,
119
- attrs: { shape: C }
120
- });
121
- O.push(P);
122
- for (let e of O) l.disposeIntermediateTensorInfo(e);
123
- return F;
124
- }
125
- function _(e) {
126
- let { inputs: t, backend: n } = e, { x: r, kernel: i } = t;
127
- if (r === void 0 || i === void 0) throw Error("BatchMatMul requires two input tensors.");
128
- return g({
129
- a: r,
130
- b: i,
131
- transposeA: !1,
132
- transposeB: !1,
133
- backend: n,
134
- activationSnippet: p
135
- });
136
- }
137
- a({
138
- kernelName: "MatMulGelu",
139
- backendName: "webgl",
140
- kernelFunc: _
141
- });
142
- function v(e) {
143
- let { dy: r, x: i, kernel: a } = e.inputs, o = e.backend;
144
- return n(() => {
145
- let e = t().makeTensorFromTensorInfo(g({
146
- a: i,
147
- b: a,
148
- transposeA: !1,
149
- transposeB: !1,
150
- backend: o,
151
- activationSnippet: m,
152
- multiplier: r
153
- }));
154
- return [s(e, a, !1, !0), s(i, e, !0, !1)];
155
- });
156
- }
157
- a({
158
- kernelName: "MatMulGeluGrad",
159
- backendName: "webgl",
160
- kernelFunc: v
161
- });
162
- export { u as i, g as n, _ as r, h as t };
@@ -1,16 +0,0 @@
1
- import { Q as e, Rt as t, Z as n, rt as r, st as i } from "./dist-CMMLi-qO.js";
2
- // node_modules/@tensorflow/tfjs-core/dist/ops/mat_mul.js
3
- function a(n, a, o = !1, s = !1) {
4
- let c = e(n, "a", "matMul"), l = e(a, "b", "matMul");
5
- [c, l] = i(c, l);
6
- let u = {
7
- a: c,
8
- b: l
9
- }, d = {
10
- transposeA: o,
11
- transposeB: s
12
- };
13
- return r.runKernel(t, u, d);
14
- }
15
- var o = /* @__PURE__ */ n({ matMul_: a });
16
- export { o as t };
@@ -1,88 +0,0 @@
1
- import e from "../layers/TransformerBlock.js";
2
- import t from "../layers/TiedEmbedding.js";
3
- import { t as n } from "../RoPECache-dYscFINl.js";
4
- import r from "../layers/RMSNorm.js";
5
- import { W as i, Y as a } from "../dist-CMMLi-qO.js";
6
- import o from "./model.js";
7
- import { packingSupported as s } from "../utilities/packed.js";
8
- import { r as c, t as l } from "../pack16-BHO4t1-M.js";
9
- import u from "../layers/HeadLayer.js";
10
- // lib/models/Llama.ts
11
- var d = {
12
- modelType: "llama",
13
- vocabSize: 2e3,
14
- blockSize: 128,
15
- nLayer: 6,
16
- nHead: 4,
17
- nEmbed: 256,
18
- mlpFactor: 4
19
- }, f = class extends o {
20
- wte;
21
- head;
22
- blocks;
23
- lnF;
24
- ropeCache;
25
- constructor(i = {}) {
26
- super({
27
- ...d,
28
- ...i
29
- });
30
- let a = {
31
- activation: "swiglu",
32
- hiddenSize: Math.max(256, Math.ceil(this.config.nEmbed * (8 / 3) / 256) * 256),
33
- useGamma: !0,
34
- useQKNorm: !1,
35
- ropeInterleaved: !1
36
- };
37
- this.wte = new t(this.config, "token_embedding", this), this.ropeCache = new n(this.config), this.blocks = [];
38
- for (let t = 0; t < this.config.nLayer; t++) this.blocks.push(new e(t, this.config, a, this));
39
- this.lnF = new r(this.config, a, "final_rms_norm", this), this.head = new u(this.config, "lm_head", this);
40
- }
41
- getClassName() {
42
- return "llama";
43
- }
44
- inputPhase(e) {
45
- return a(() => this.wte.embed(e));
46
- }
47
- forward(e, t) {
48
- return this.validateInput(t), e.ropeCache = this.ropeCache, e.outputEmbeddings && (e.embeddings = []), a(() => {
49
- this.startMemory();
50
- let n = this.inputPhase(t);
51
- if (e.cache && e.cache.length !== this.blocks.length) throw console.error("Cache", e.cache), Error(`Cache length ${e.cache.length} does not match number of blocks ${this.blocks.length}`);
52
- let r = e.mixedPrecision === !0 && s(), a = r ? l(n) : n;
53
- r && n !== a && n.dispose();
54
- for (let t = 0; t < this.blocks.length; t++) {
55
- if (e.layerDrop && Math.random() < e.layerDrop * (t / this.blocks.length)) continue;
56
- let n = this.blocks[t], o = Math.random() * 1e9, s = {
57
- ...e,
58
- seed: o,
59
- pastKV: e.cache ? e.cache[t] : void 0,
60
- mixedPrecision: r,
61
- epsilon: 1e-6
62
- }, c = e.checkpointing && e.training ? n.callCheckpoint(s, a) : n.call(s, a);
63
- e.outputEmbeddings ? (i(a), e.embeddings.push({
64
- name: `block_output_${t}`,
65
- tensor: a
66
- })) : a.dispose(), a = c;
67
- }
68
- if (n = this.lnF.call({
69
- ...e,
70
- mixedPrecision: r
71
- }, a), a.dispose(), e.skipLogits) return this.endMemory("Forward"), n;
72
- let o = this.head.project(n);
73
- e.outputEmbeddings ? (i(n), e.embeddings.push({
74
- name: "final_norm_output",
75
- tensor: n
76
- })) : n.dispose();
77
- let u = r ? c(o) : o;
78
- return r && o !== u && o.dispose(), u;
79
- });
80
- }
81
- project(e) {
82
- return a(() => this.head.project(e));
83
- }
84
- dispose() {
85
- this.weightStore.dispose(), this.wte.dispose(), this.head.dispose(), this.blocks.forEach((e) => e.dispose()), this.lnF.dispose();
86
- }
87
- };
88
- export { f as default };
@@ -1,94 +0,0 @@
1
- import e from "../layers/TransformerBlock.js";
2
- import t from "../layers/TiedEmbedding.js";
3
- import { t as n } from "../RoPECache-dYscFINl.js";
4
- import r from "../layers/RMSNorm.js";
5
- import { W as i, Y as a } from "../dist-CMMLi-qO.js";
6
- import o from "./model.js";
7
- import s from "../layers/PositionEmbedding.js";
8
- import { packingSupported as c } from "../utilities/packed.js";
9
- import { r as l, t as u } from "../pack16-BHO4t1-M.js";
10
- // lib/models/NanoGPTV1.ts
11
- var d = {
12
- modelType: "GenAI_NanoGPT_v1",
13
- vocabSize: 2e3,
14
- blockSize: 128,
15
- nLayer: 6,
16
- nHead: 4,
17
- nEmbed: 256,
18
- mlpFactor: 4,
19
- useRope: !0
20
- }, f = class extends o {
21
- wte;
22
- wpe;
23
- blocks;
24
- lnF;
25
- ropeCache;
26
- constructor(i = {}) {
27
- super({
28
- ...d,
29
- ...i
30
- });
31
- let a = {
32
- activation: "gelu",
33
- hiddenFactor: this.config.mlpFactor,
34
- useGamma: !0,
35
- useQKNorm: !1
36
- };
37
- this.wte = new t(this.config, "token_embedding", this), this.config.useRope === !1 ? this.wpe = new s(this.config, "positional_embedding", this) : this.ropeCache = new n(this.config), this.blocks = [];
38
- for (let t = 0; t < this.config.nLayer; t++) this.blocks.push(new e(t, this.config, a, this));
39
- this.lnF = new r(this.config, a, "final_rms_norm", this);
40
- }
41
- getClassName() {
42
- return "GenAI_NanoGPT_v1";
43
- }
44
- inputPhase(e, t) {
45
- return a(() => {
46
- let n = this.wte.embed(e);
47
- if (this.config.useRope === !1) {
48
- let e = this.wpe.call(t, n);
49
- if (Array.isArray(e)) throw Error("PositionEmbedding output should not be an array");
50
- return e;
51
- }
52
- return n;
53
- });
54
- }
55
- forward(e, t) {
56
- return this.validateInput(t), e.ropeCache = this.ropeCache, e.outputEmbeddings && (e.embeddings = []), a(() => {
57
- this.startMemory();
58
- let n = this.inputPhase(t, e);
59
- if (e.cache && e.cache.length !== this.blocks.length) throw console.error("Cache", e.cache), Error(`Cache length ${e.cache.length} does not match number of blocks ${this.blocks.length}`);
60
- let r = e.mixedPrecision === !0 && c(), a = r ? u(n) : n;
61
- r && n !== a && n.dispose();
62
- for (let t = 0; t < this.blocks.length; t++) {
63
- let n = this.blocks[t], o = Math.random() * 1e9, s = {
64
- ...e,
65
- seed: o,
66
- pastKV: e.cache ? e.cache[t] : void 0,
67
- mixedPrecision: r
68
- }, c = e.checkpointing && e.training ? n.callCheckpoint(s, a) : n.call(s, a);
69
- e.outputEmbeddings ? (i(a), e.embeddings.push({
70
- name: `block_output_${t}`,
71
- tensor: a
72
- })) : a.dispose(), a = c;
73
- }
74
- if (n = this.lnF.call({
75
- ...e,
76
- mixedPrecision: r
77
- }, a), a.dispose(), e.skipLogits) return this.endMemory("Forward"), n;
78
- let o = this.wte.project(n);
79
- e.outputEmbeddings ? (i(n), e.embeddings.push({
80
- name: "final_norm_output",
81
- tensor: n
82
- })) : n.dispose();
83
- let s = r ? l(o) : o;
84
- return r && o !== s && o.dispose(), s;
85
- });
86
- }
87
- project(e) {
88
- return a(() => this.wte.project(e));
89
- }
90
- dispose() {
91
- this.weightStore.dispose(), this.wte.dispose(), this.wpe && this.wpe.dispose(), this.blocks.forEach((e) => e.dispose()), this.lnF.dispose();
92
- }
93
- };
94
- export { f as default };
@@ -1,85 +0,0 @@
1
- import e from "../layers/TransformerBlock.js";
2
- import t from "../layers/TiedEmbedding.js";
3
- import { t as n } from "../RoPECache-dYscFINl.js";
4
- import r from "../layers/RMSNorm.js";
5
- import { W as i, Y as a } from "../dist-CMMLi-qO.js";
6
- import o from "./model.js";
7
- import { packingSupported as s } from "../utilities/packed.js";
8
- import { r as c, t as l } from "../pack16-BHO4t1-M.js";
9
- // lib/models/NanoGPTV2.ts
10
- var u = {
11
- modelType: "GenAI_NanoGPT_v2",
12
- vocabSize: 2e3,
13
- blockSize: 128,
14
- nLayer: 6,
15
- nHead: 4,
16
- nEmbed: 256,
17
- mlpFactor: 4
18
- }, d = class extends o {
19
- wte;
20
- wpe;
21
- blocks;
22
- lnF;
23
- ropeCache;
24
- constructor(i = {}) {
25
- super({
26
- ...u,
27
- ...i
28
- });
29
- let a = {
30
- activation: "relu2",
31
- hiddenFactor: this.config.mlpFactor,
32
- useGamma: !1,
33
- useQKNorm: !0
34
- };
35
- this.wte = new t(this.config, "token_embedding", this), this.ropeCache = new n(this.config), this.blocks = [];
36
- for (let t = 0; t < this.config.nLayer; t++) this.blocks.push(new e(t, this.config, a, this));
37
- this.lnF = new r(this.config, a, "final_rms_norm", this);
38
- }
39
- getClassName() {
40
- return "GenAI_NanoGPT_v2";
41
- }
42
- inputPhase(e) {
43
- return a(() => this.wte.embed(e));
44
- }
45
- forward(e, t) {
46
- return this.validateInput(t), e.ropeCache = this.ropeCache, e.outputEmbeddings && (e.embeddings = []), a(() => {
47
- this.startMemory();
48
- let n = this.inputPhase(t);
49
- if (e.cache && e.cache.length !== this.blocks.length) throw console.error("Cache", e.cache), Error(`Cache length ${e.cache.length} does not match number of blocks ${this.blocks.length}`);
50
- let r = e.mixedPrecision === !0 && s(), a = r ? l(n) : n;
51
- r && n !== a && n.dispose();
52
- for (let t = 0; t < this.blocks.length; t++) {
53
- if (e.layerDrop && Math.random() < e.layerDrop * (t / this.blocks.length)) continue;
54
- let n = this.blocks[t], o = Math.random() * 1e9, s = {
55
- ...e,
56
- seed: o,
57
- pastKV: e.cache ? e.cache[t] : void 0,
58
- mixedPrecision: r
59
- }, c = e.checkpointing && e.training ? n.callCheckpoint(s, a) : n.call(s, a);
60
- e.outputEmbeddings ? (i(a), e.embeddings.push({
61
- name: `block_output_${t}`,
62
- tensor: a
63
- })) : a.dispose(), a = c;
64
- }
65
- if (n = this.lnF.call({
66
- ...e,
67
- mixedPrecision: r
68
- }, a), a.dispose(), e.skipLogits) return this.endMemory("Forward"), n;
69
- let o = this.wte.project(n);
70
- e.outputEmbeddings ? (i(n), e.embeddings.push({
71
- name: "final_norm_output",
72
- tensor: n
73
- })) : n.dispose();
74
- let u = r ? c(o) : o;
75
- return r && o !== u && o.dispose(), u;
76
- });
77
- }
78
- project(e) {
79
- return a(() => this.wte.project(e));
80
- }
81
- dispose() {
82
- this.weightStore.dispose(), this.wte.dispose(), this.wpe && this.wpe.dispose(), this.blocks.forEach((e) => e.dispose()), this.lnF.dispose();
83
- }
84
- };
85
- export { d as default };
@@ -1,88 +0,0 @@
1
- import e from "../layers/TransformerBlock.js";
2
- import t from "../layers/TiedEmbedding.js";
3
- import { t as n } from "../RoPECache-dYscFINl.js";
4
- import r from "../layers/RMSNorm.js";
5
- import { W as i, Y as a } from "../dist-CMMLi-qO.js";
6
- import o from "./model.js";
7
- import { packingSupported as s } from "../utilities/packed.js";
8
- import { r as c, t as l } from "../pack16-BHO4t1-M.js";
9
- import u from "../layers/HeadLayer.js";
10
- // lib/models/Qwen3.ts
11
- var d = {
12
- modelType: "qwen3",
13
- vocabSize: 2e3,
14
- blockSize: 128,
15
- nLayer: 6,
16
- nHead: 4,
17
- nEmbed: 256,
18
- mlpFactor: 4
19
- }, f = class extends o {
20
- wte;
21
- head;
22
- blocks;
23
- lnF;
24
- ropeCache;
25
- constructor(i = {}) {
26
- super({
27
- ...d,
28
- ...i
29
- });
30
- let a = {
31
- activation: "swiglu",
32
- hiddenSize: this.config.mlpSize ?? Math.max(256, Math.ceil(this.config.nEmbed * (8 / 3) / 256) * 256),
33
- useGamma: !0,
34
- useQKNorm: !0,
35
- ropeInterleaved: !1,
36
- epsilon: this.config.rmsNormEpsilon ?? 1e-6
37
- };
38
- this.wte = new t(this.config, "token_embedding", this), this.ropeCache = new n(this.config), this.blocks = [];
39
- for (let t = 0; t < this.config.nLayer; t++) this.blocks.push(new e(t, this.config, a, this));
40
- this.lnF = new r(this.config, a, "final_rms_norm", this), this.head = this.config.tieEmbeddings ?? !0 ? new u(this.config, "lm_head", this) : null;
41
- }
42
- getClassName() {
43
- return "qwen3";
44
- }
45
- inputPhase(e) {
46
- return a(() => this.wte.embed(e));
47
- }
48
- forward(e, t) {
49
- return this.validateInput(t), e.ropeCache = this.ropeCache, e.outputEmbeddings && (e.embeddings = []), a(() => {
50
- this.startMemory();
51
- let n = this.inputPhase(t);
52
- if (e.cache && e.cache.length !== this.blocks.length) throw console.error("Cache", e.cache), Error(`Cache length ${e.cache.length} does not match number of blocks ${this.blocks.length}`);
53
- let r = e.mixedPrecision === !0 && s(), a = r ? l(n) : n;
54
- r && n !== a && n.dispose();
55
- for (let t = 0; t < this.blocks.length; t++) {
56
- if (e.layerDrop && Math.random() < e.layerDrop * (t / this.blocks.length)) continue;
57
- let n = this.blocks[t], o = Math.random() * 1e9, s = {
58
- ...e,
59
- seed: o,
60
- pastKV: e.cache ? e.cache[t] : void 0,
61
- mixedPrecision: r
62
- }, c = e.checkpointing && e.training ? n.callCheckpoint(s, a) : n.call(s, a);
63
- e.outputEmbeddings ? (i(a), e.embeddings.push({
64
- name: `block_output_${t}`,
65
- tensor: a
66
- })) : a.dispose(), a = c;
67
- }
68
- if (n = this.lnF.call({
69
- ...e,
70
- mixedPrecision: r
71
- }, a), a.dispose(), e.skipLogits) return this.endMemory("Forward"), n;
72
- let o = this.head ? this.head.project(n) : this.wte.project(n);
73
- e.outputEmbeddings ? (i(n), e.embeddings.push({
74
- name: "final_norm_output",
75
- tensor: n
76
- })) : n.dispose();
77
- let u = r ? c(o) : o;
78
- return r && o !== u && o.dispose(), u;
79
- });
80
- }
81
- project(e) {
82
- return a(() => this.wte.project(e));
83
- }
84
- dispose() {
85
- this.weightStore.dispose(), this.wte.dispose(), this.head && this.head.dispose(), this.blocks.forEach((e) => e.dispose()), this.lnF.dispose();
86
- }
87
- };
88
- export { f as default };
@@ -1,32 +0,0 @@
1
- // lib/models/config.ts
2
- var e = {
3
- modelType: "GenAI_NanoGPT_v2",
4
- vocabSize: 2e3,
5
- blockSize: 128,
6
- nLayer: 6,
7
- nHead: 4,
8
- nEmbed: 256,
9
- mlpFactor: 4
10
- };
11
- function t(e, t) {
12
- if (typeof e[t] != "number" || Number.isNaN(e[t])) throw Error(`Invalid config: "${t}" must be a number.`);
13
- }
14
- function n(e) {
15
- let n = (e) => typeof e == "object" && !!e && !Array.isArray(e);
16
- if (!n(e)) throw Error("Invalid config: expected an object.");
17
- if (t(e, "vocabSize"), t(e, "blockSize"), t(e, "nLayer"), t(e, "nHead"), t(e, "nEmbed"), t(e, "mlpFactor"), e.loraConfig !== void 0) {
18
- if (!n(e.loraConfig)) throw Error("Invalid config: \"loraConfig\" must be an object.");
19
- let r = Object.values(e.loraConfig);
20
- if (!r.every((e) => n(e))) throw Error("Invalid config: each entry in \"loraConfig\" must be an object.");
21
- if (!r.every((e) => "rank" in e && "alpha" in e && "variables" in e)) throw Error("Invalid config: each LoRA config must have \"rank\", \"alpha\", and \"variables\" fields.");
22
- r.forEach((e) => {
23
- if (t(e, "rank"), t(e, "alpha"), !Array.isArray(e.variables) || !e.variables.every((e) => typeof e == "string")) throw Error("Invalid config: \"variables\" must be a string array.");
24
- });
25
- }
26
- if (e.modelType === "GenAI_NanoGPT_v1") {
27
- if (typeof e.useRope != "boolean") throw Error("Invalid config: \"useRope\" must be a boolean for GenAI_NanoGPT_v1.");
28
- } else if (e.modelType === "GenAI_NanoGPT_v2") {
29
- if (e.windowSize !== void 0 && typeof e.windowSize != "string") throw Error("Invalid config: \"windowSize\" must be a string for GenAI_NanoGPT_v2.");
30
- } else if (e.modelType !== "qwen3" && e.modelType !== "llama") throw Error("invalid_model_type");
31
- }
32
- export { e as defaultConfig, n as validateConfig };
@@ -1,16 +0,0 @@
1
- import e from "./Llama.js";
2
- import t from "./NanoGPTV1.js";
3
- import n from "./NanoGPTV2.js";
4
- import r from "./Qwen3.js";
5
- // lib/models/factory.ts
6
- function i(i) {
7
- let a = i.modelType || "GenAI_NanoGPT_v1";
8
- switch (a) {
9
- case "GenAI_NanoGPT_v1": return new t(i);
10
- case "GenAI_NanoGPT_v2": return new n(i);
11
- case "qwen3": return new r(i);
12
- case "llama": return new e(i);
13
- default: throw Error(`Unsupported model type: ${a}`);
14
- }
15
- }
16
- export { i as default };