@genai-fi/nanogpt 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (426) hide show
  1. package/dist/{binary_op_util-WY9YIl0q.js → Reshape-CqftURg0.js} +75 -60
  2. package/dist/TeachableLLM.d.ts +12 -12
  3. package/dist/api/beamer.d.ts +4 -4
  4. package/dist/api/responses.d.ts +4 -4
  5. package/dist/api/training.d.ts +9 -9
  6. package/dist/backend.d.ts +1 -1
  7. package/dist/backend_util-DZIc6pyV.js +1081 -0
  8. package/dist/checks/index.d.ts +11 -11
  9. package/dist/checks/weights.d.ts +1 -1
  10. package/dist/data/docx.d.ts +1 -1
  11. package/dist/data/pdf.d.ts +1 -1
  12. package/dist/data/stream.d.ts +1 -1
  13. package/dist/data/textLoader.d.ts +1 -1
  14. package/dist/data.d.ts +3 -3
  15. package/dist/device-CZPGtQBU.js +9 -0
  16. package/dist/device.d.ts +2 -0
  17. package/dist/{dist-DeVH1nGn.js → dist-DiszGjH-.js} +1833 -1844
  18. package/dist/{dist-CMMLi-qO.js → dist-JOPw9zTN.js} +69 -11
  19. package/dist/inference/Beamer.d.ts +3 -3
  20. package/dist/inference/Generator.d.ts +4 -4
  21. package/dist/inference/tokenisePrompt.d.ts +2 -2
  22. package/dist/inference/types.d.ts +1 -1
  23. package/dist/inference/utilities.d.ts +1 -1
  24. package/dist/layers/BaseLayer.d.ts +5 -4
  25. package/dist/layers/GQA.d.ts +24 -26
  26. package/dist/layers/HeadLayer.d.ts +2 -2
  27. package/dist/layers/LoRA.d.ts +1 -1
  28. package/dist/layers/MHA.d.ts +3 -4
  29. package/dist/layers/MLP.d.ts +2 -2
  30. package/dist/layers/PositionEmbedding.d.ts +3 -3
  31. package/dist/layers/RMSNorm.d.ts +2 -2
  32. package/dist/layers/RoPECache.d.ts +2 -1
  33. package/dist/layers/TiedEmbedding.d.ts +2 -2
  34. package/dist/layers/TransformerBlock.d.ts +9 -6
  35. package/dist/layers.d.ts +4 -4
  36. package/dist/loader/load.d.ts +1 -1
  37. package/dist/loader/loadHF.d.ts +3 -3
  38. package/dist/loader/loadTransformers.d.ts +2 -2
  39. package/dist/loader/loadZipMeta.d.ts +2 -2
  40. package/dist/loader/newZipLoad.d.ts +2 -2
  41. package/dist/loader/oldZipLoad.d.ts +4 -4
  42. package/dist/loader/save.d.ts +5 -5
  43. package/dist/loader/types.d.ts +23 -10
  44. package/dist/main.d.ts +40 -24
  45. package/dist/matMul16-CiMKJM8v.js +2610 -0
  46. package/dist/models/Llama.d.ts +2 -2
  47. package/dist/models/LoopNano.d.ts +16 -0
  48. package/dist/models/NanoGPTV1.d.ts +2 -2
  49. package/dist/models/NanoGPTV2.d.ts +2 -2
  50. package/dist/models/Qwen3.d.ts +2 -2
  51. package/dist/models/config.d.ts +11 -1
  52. package/dist/models/factory.d.ts +2 -2
  53. package/dist/models/model.d.ts +6 -6
  54. package/dist/models.d.ts +4 -4
  55. package/dist/nanogpt.js +37041 -0
  56. package/dist/ops/adamAdjust.d.ts +2 -0
  57. package/dist/ops/adamMoments.d.ts +2 -0
  58. package/dist/ops/adamW.d.ts +2 -0
  59. package/dist/ops/add16.d.ts +1 -0
  60. package/dist/ops/appendCache.d.ts +2 -0
  61. package/dist/ops/attentionMask.d.ts +11 -1
  62. package/dist/ops/dropout16.d.ts +2 -0
  63. package/dist/ops/gatherSub.d.ts +2 -0
  64. package/dist/ops/gelu.d.ts +3 -0
  65. package/dist/ops/log.d.ts +1 -0
  66. package/dist/ops/matMul16.d.ts +4 -0
  67. package/dist/ops/matMulGelu.d.ts +3 -0
  68. package/dist/ops/matMulMul.d.ts +2 -0
  69. package/dist/ops/mul16.d.ts +1 -0
  70. package/dist/ops/mulDrop.d.ts +2 -0
  71. package/dist/ops/normRMS.d.ts +3 -0
  72. package/dist/ops/pack16.d.ts +1 -0
  73. package/dist/ops/qkv.d.ts +13 -1
  74. package/dist/ops/rope.d.ts +4 -1
  75. package/dist/ops/scatterSub.d.ts +4 -1
  76. package/dist/ops/silu.d.ts +1 -0
  77. package/dist/ops/softmax16.d.ts +1 -0
  78. package/dist/ops/sparseCrossEntropy.d.ts +15 -0
  79. package/dist/ops/unpack16.d.ts +1 -0
  80. package/dist/ops/webgl/sparseCrossEntropy.d.ts +1 -0
  81. package/dist/ops/webgpu/adamW.d.ts +1 -0
  82. package/dist/ops/webgpu/concat16.d.ts +16 -0
  83. package/dist/ops/webgpu/index.d.ts +29 -0
  84. package/dist/ops/webgpu/normRMS16_program.d.ts +2 -2
  85. package/dist/ops/webgpu/normRMS32_program.d.ts +2 -2
  86. package/dist/ops/webgpu/pack16_program.d.ts +1 -1
  87. package/dist/ops/webgpu/softmax16_program.d.ts +16 -0
  88. package/dist/ops/webgpu/sparseCrossEntropy.d.ts +1 -0
  89. package/dist/ops/webgpu/utils/binary_op.d.ts +16 -0
  90. package/dist/ops/webgpu/utils/deviceInfo.d.ts +1 -1
  91. package/dist/ops/webgpu/utils/reductions.d.ts +1 -1
  92. package/dist/patches/webgpu_backend.d.ts +2 -1
  93. package/dist/patches/webgpu_base.d.ts +0 -1
  94. package/dist/patches/webgpu_program.d.ts +21 -0
  95. package/dist/{shared-BIDMUBCs.js → shared-BARkvvG4.js} +587 -505
  96. package/dist/tokenise.d.ts +4 -4
  97. package/dist/tokeniser/BaseTokeniser.d.ts +3 -3
  98. package/dist/tokeniser/CharTokeniser.d.ts +2 -2
  99. package/dist/tokeniser/bpe.d.ts +2 -2
  100. package/dist/tokeniser/type.d.ts +2 -2
  101. package/dist/training/AdamW.d.ts +19 -2
  102. package/dist/training/BasicTrainer.d.ts +5 -5
  103. package/dist/training/DatasetBuilder.d.ts +2 -2
  104. package/dist/training/Evaluator.d.ts +1 -1
  105. package/dist/training/LRScheduler.d.ts +1 -1
  106. package/dist/training/PreTrainer.d.ts +6 -6
  107. package/dist/training/SFTTrainer.d.ts +6 -6
  108. package/dist/training/configure.d.ts +2 -2
  109. package/dist/training/factory.d.ts +6 -5
  110. package/dist/training/prepareData.d.ts +6 -6
  111. package/dist/training/tasks/tokenStream.d.ts +3 -3
  112. package/dist/training/types.d.ts +6 -5
  113. package/dist/training/validateOptions.d.ts +1 -1
  114. package/dist/training/validation.d.ts +3 -3
  115. package/dist/utilities/datasetID.d.ts +1 -1
  116. package/dist/utilities/dummy.d.ts +1 -1
  117. package/dist/utilities/packed.d.ts +1 -1
  118. package/dist/utilities/parameters.d.ts +1 -1
  119. package/dist/utilities/sentences.d.ts +1 -1
  120. package/dist/utilities/waitForModel.d.ts +1 -1
  121. package/dist/webgpu-D4syGmzo.js +3221 -0
  122. package/dist/webgpu-wUCQopBN.js +1007 -0
  123. package/dist/{webgpu_program-DvkFqRlR.js → webgpu_backend-CzY9TzvA.js} +174 -223
  124. package/dist/{patches/webgpu_base.js → webgpu_base-Bjg7okYf.js} +6 -9
  125. package/package.json +12 -9
  126. package/dist/DatasetBuilder-DRDW8tcM.js +0 -731
  127. package/dist/Generator-8IK28IWR.js +0 -316
  128. package/dist/RealDiv-Cl8k3YTx.js +0 -354
  129. package/dist/Reshape-CKxKPKqi.js +0 -91
  130. package/dist/Reshape-H5zZRgr9.js +0 -16
  131. package/dist/RoPECache-dYscFINl.js +0 -722
  132. package/dist/TeachableLLM.js +0 -220
  133. package/dist/api/beamer.js +0 -61
  134. package/dist/api/responses.js +0 -177
  135. package/dist/api/training.js +0 -215
  136. package/dist/axis_util-rF9RnwKE.js +0 -37
  137. package/dist/backend.js +0 -12
  138. package/dist/backend_util-Cpp0Gwlp.js +0 -394
  139. package/dist/broadcast_to-CGvLNiQ0.js +0 -20
  140. package/dist/checks/appendCache.js +0 -55
  141. package/dist/checks/attentionMask.js +0 -57
  142. package/dist/checks/check.js +0 -31
  143. package/dist/checks/gelu.js +0 -46
  144. package/dist/checks/index.js +0 -27
  145. package/dist/checks/matMulGelu.js +0 -84
  146. package/dist/checks/normRMS.js +0 -30
  147. package/dist/checks/normRMSGrad.js +0 -23
  148. package/dist/checks/packUnpack.js +0 -46
  149. package/dist/checks/qkv.js +0 -1
  150. package/dist/checks/rope.js +0 -30
  151. package/dist/checks/weights.js +0 -26
  152. package/dist/clip_by_value-D-UX9am5.js +0 -13
  153. package/dist/complex-Cl904TqN.js +0 -13
  154. package/dist/complex_util-BBlPAm-s.js +0 -59
  155. package/dist/concat-Oip5acVY.js +0 -14
  156. package/dist/concat_util-CY45Hf4F.js +0 -18
  157. package/dist/data/docx.js +0 -17
  158. package/dist/data/pdf.js +0 -14
  159. package/dist/data/stream.js +0 -1
  160. package/dist/data/textLoader.js +0 -575
  161. package/dist/data-CV_i_H6B.js +0 -11
  162. package/dist/data.js +0 -5
  163. package/dist/dist-DyL7qSLJ.js +0 -7809
  164. package/dist/dropout16-CA31Ud5a.js +0 -20
  165. package/dist/dropout_util-SiFMbFXz.js +0 -22
  166. package/dist/eventemitter3-wmfmOP_f.js +0 -90
  167. package/dist/expand_dims-Dh3Fulyn.js +0 -10
  168. package/dist/floor-BwjmUb7X.js +0 -8
  169. package/dist/gather-B5Z1RFt5.js +0 -14
  170. package/dist/gatherSub-CRUfUzBa.js +0 -22
  171. package/dist/gelu-Xx9-ohH9.js +0 -25
  172. package/dist/gpgpu_math-48m8q3jI.js +0 -1591
  173. package/dist/inference/Beamer.js +0 -215
  174. package/dist/inference/Generator.js +0 -1
  175. package/dist/inference/tokenisePrompt.js +0 -17
  176. package/dist/inference/types.js +0 -0
  177. package/dist/inference/utilities.js +0 -31
  178. package/dist/jszip.min-Btv48m44.js +0 -3037
  179. package/dist/kernel_funcs_utils-BYRpSfV_.js +0 -229
  180. package/dist/layers/BaseLayer.js +0 -75
  181. package/dist/layers/GQA.js +0 -102
  182. package/dist/layers/HeadLayer.js +0 -28
  183. package/dist/layers/LoRA.js +0 -45
  184. package/dist/layers/MHA.js +0 -102
  185. package/dist/layers/MLP.js +0 -47
  186. package/dist/layers/PositionEmbedding.js +0 -28
  187. package/dist/layers/RMSNorm.js +0 -25
  188. package/dist/layers/RoPECache.js +0 -1
  189. package/dist/layers/TiedEmbedding.js +0 -33
  190. package/dist/layers/TransformerBlock.js +0 -50
  191. package/dist/layers/WeightStore.js +0 -68
  192. package/dist/layers-CFqEip3s.js +0 -13
  193. package/dist/layers.js +0 -6
  194. package/dist/loader/load.js +0 -63
  195. package/dist/loader/loadHF.js +0 -17
  196. package/dist/loader/loadTransformers.js +0 -61
  197. package/dist/loader/loadZipMeta.js +0 -15
  198. package/dist/loader/newZipLoad.js +0 -24
  199. package/dist/loader/oldZipLoad.js +0 -36
  200. package/dist/loader/save.js +0 -89
  201. package/dist/loader/types.js +0 -0
  202. package/dist/main.js +0 -12145
  203. package/dist/matMul16-tE26fnhf.js +0 -87
  204. package/dist/matMulGelu-ASUWlKqu.js +0 -162
  205. package/dist/mat_mul-R9_DWmIT.js +0 -16
  206. package/dist/models/Llama.js +0 -88
  207. package/dist/models/NanoGPTV1.js +0 -94
  208. package/dist/models/NanoGPTV2.js +0 -85
  209. package/dist/models/Qwen3.js +0 -88
  210. package/dist/models/config.js +0 -32
  211. package/dist/models/factory.js +0 -16
  212. package/dist/models/model.js +0 -75
  213. package/dist/models-DyBpJJwM.js +0 -13
  214. package/dist/models.js +0 -6
  215. package/dist/mul16-C7sqgqik.js +0 -41
  216. package/dist/non_max_suppression_impl-B0H318rb.js +0 -72
  217. package/dist/not_equal-Bu3O8rh_.js +0 -67
  218. package/dist/one_hot-TEMPumJj.js +0 -14
  219. package/dist/ones-DpPXWa6A.js +0 -13
  220. package/dist/ops/adamAdjust.js +0 -17
  221. package/dist/ops/adamMoments.js +0 -15
  222. package/dist/ops/add16.js +0 -11
  223. package/dist/ops/appendCache.js +0 -26
  224. package/dist/ops/attentionMask.js +0 -19
  225. package/dist/ops/concat16.js +0 -8
  226. package/dist/ops/cpu/adamAdjust.js +0 -15
  227. package/dist/ops/cpu/adamMoments.js +0 -16
  228. package/dist/ops/cpu/appendCache.js +0 -65
  229. package/dist/ops/cpu/attentionMask.js +0 -20
  230. package/dist/ops/cpu/fusedSoftmax.js +0 -22
  231. package/dist/ops/cpu/gatherSub.js +0 -1
  232. package/dist/ops/cpu/gelu.js +0 -35
  233. package/dist/ops/cpu/matMul16.js +0 -14
  234. package/dist/ops/cpu/matMulGelu.js +0 -44
  235. package/dist/ops/cpu/matMulMul.js +0 -19
  236. package/dist/ops/cpu/mulDropout.js +0 -19
  237. package/dist/ops/cpu/normRMS.js +0 -34
  238. package/dist/ops/cpu/qkv.js +0 -74
  239. package/dist/ops/cpu/rope.js +0 -84
  240. package/dist/ops/cpu/scatterSub.js +0 -1
  241. package/dist/ops/dot16.js +0 -28
  242. package/dist/ops/dropout.js +0 -12
  243. package/dist/ops/dropout16.js +0 -1
  244. package/dist/ops/gatherSub.js +0 -12
  245. package/dist/ops/gelu.js +0 -1
  246. package/dist/ops/globalNorm.js +0 -19
  247. package/dist/ops/grads/add16.js +0 -26
  248. package/dist/ops/grads/attentionMask.js +0 -25
  249. package/dist/ops/grads/dropout16.js +0 -1
  250. package/dist/ops/grads/gelu.js +0 -1
  251. package/dist/ops/grads/matMul16.js +0 -1
  252. package/dist/ops/grads/matMulGelu.js +0 -21
  253. package/dist/ops/grads/mul16.js +0 -1
  254. package/dist/ops/grads/normRMS.js +0 -36
  255. package/dist/ops/grads/pack16.js +0 -1
  256. package/dist/ops/grads/qkv.js +0 -46
  257. package/dist/ops/grads/rope.js +0 -1
  258. package/dist/ops/grads/silu.js +0 -1
  259. package/dist/ops/grads/softmax16.js +0 -22
  260. package/dist/ops/grads/unpack16.js +0 -1
  261. package/dist/ops/grads/utils.js +0 -11
  262. package/dist/ops/log.js +0 -1
  263. package/dist/ops/matMul16.js +0 -1
  264. package/dist/ops/matMulGelu.js +0 -19
  265. package/dist/ops/matMulMul.js +0 -15
  266. package/dist/ops/mul16.js +0 -1
  267. package/dist/ops/mulDrop.js +0 -14
  268. package/dist/ops/normRMS.js +0 -21
  269. package/dist/ops/pack16.js +0 -1
  270. package/dist/ops/qkv.js +0 -15
  271. package/dist/ops/reshape16.js +0 -33
  272. package/dist/ops/rope.js +0 -1
  273. package/dist/ops/scatterSub.js +0 -12
  274. package/dist/ops/silu.js +0 -1
  275. package/dist/ops/slice16.js +0 -11
  276. package/dist/ops/softmax16.js +0 -8
  277. package/dist/ops/sub16.js +0 -10
  278. package/dist/ops/sum16.js +0 -13
  279. package/dist/ops/transpose16.js +0 -33
  280. package/dist/ops/unpack16.js +0 -1
  281. package/dist/ops/webgl/adamAdjust.js +0 -81
  282. package/dist/ops/webgl/adamMoments.js +0 -43
  283. package/dist/ops/webgl/appendCache.js +0 -52
  284. package/dist/ops/webgl/attentionMask.js +0 -63
  285. package/dist/ops/webgl/dropout16.js +0 -11
  286. package/dist/ops/webgl/fusedSoftmax.js +0 -70
  287. package/dist/ops/webgl/gatherSub.js +0 -27
  288. package/dist/ops/webgl/gelu.js +0 -47
  289. package/dist/ops/webgl/log.js +0 -14
  290. package/dist/ops/webgl/matMul16.js +0 -48
  291. package/dist/ops/webgl/matMulGelu.js +0 -1
  292. package/dist/ops/webgl/matMulMul.js +0 -23
  293. package/dist/ops/webgl/mulDropout.js +0 -31
  294. package/dist/ops/webgl/normRMS.js +0 -115
  295. package/dist/ops/webgl/qkv.js +0 -53
  296. package/dist/ops/webgl/rope.js +0 -73
  297. package/dist/ops/webgl/scatterSub.js +0 -27
  298. package/dist/ops/webgpu/adamAdjust.js +0 -76
  299. package/dist/ops/webgpu/adamMoments.js +0 -75
  300. package/dist/ops/webgpu/add16.js +0 -13
  301. package/dist/ops/webgpu/appendCache.js +0 -129
  302. package/dist/ops/webgpu/attentionMask.js +0 -41
  303. package/dist/ops/webgpu/attentionMask32_program.js +0 -61
  304. package/dist/ops/webgpu/clipScale.js +0 -44
  305. package/dist/ops/webgpu/concat16.js +0 -110
  306. package/dist/ops/webgpu/dropout16.js +0 -58
  307. package/dist/ops/webgpu/gatherSub.js +0 -51
  308. package/dist/ops/webgpu/gelu.js +0 -146
  309. package/dist/ops/webgpu/index.js +0 -27
  310. package/dist/ops/webgpu/matMul16.js +0 -91
  311. package/dist/ops/webgpu/matMul16_program.js +0 -311
  312. package/dist/ops/webgpu/mul16.js +0 -13
  313. package/dist/ops/webgpu/norm2.js +0 -45
  314. package/dist/ops/webgpu/normRMS.js +0 -25
  315. package/dist/ops/webgpu/normRMS16_program.js +0 -28
  316. package/dist/ops/webgpu/normRMS32_program.js +0 -28
  317. package/dist/ops/webgpu/normRMSGrad.js +0 -225
  318. package/dist/ops/webgpu/pack16.js +0 -20
  319. package/dist/ops/webgpu/pack16_program.js +0 -92
  320. package/dist/ops/webgpu/qkv.js +0 -63
  321. package/dist/ops/webgpu/rope.js +0 -227
  322. package/dist/ops/webgpu/scatterSub.js +0 -52
  323. package/dist/ops/webgpu/silu.js +0 -117
  324. package/dist/ops/webgpu/slice16.js +0 -73
  325. package/dist/ops/webgpu/softmax16.js +0 -18
  326. package/dist/ops/webgpu/softmax16_program.js +0 -88
  327. package/dist/ops/webgpu/softmax16_subgroup_program.js +0 -69
  328. package/dist/ops/webgpu/softmax16grad.js +0 -30
  329. package/dist/ops/webgpu/sub16.js +0 -13
  330. package/dist/ops/webgpu/sum16.js +0 -30
  331. package/dist/ops/webgpu/transpose16.js +0 -38
  332. package/dist/ops/webgpu/transpose16_program.js +0 -50
  333. package/dist/ops/webgpu/transpose16_shared_program.js +0 -78
  334. package/dist/ops/webgpu/unpack16.js +0 -59
  335. package/dist/ops/webgpu/utils/binary_op.js +0 -140
  336. package/dist/ops/webgpu/utils/deviceInfo.js +0 -10
  337. package/dist/ops/webgpu/utils/reductions.js +0 -264
  338. package/dist/ops-Be5ACU5R.js +0 -13
  339. package/dist/ops-C1UpdEYM.js +0 -509
  340. package/dist/pack16-BHO4t1-M.js +0 -36
  341. package/dist/pad-Dy-1IP3A.js +0 -13
  342. package/dist/patches/webgpu_backend.js +0 -42
  343. package/dist/patches/webgpu_program.js +0 -292
  344. package/dist/picomatch--TW6gyBJ.js +0 -999
  345. package/dist/qkv-BQfNPucX.js +0 -42
  346. package/dist/rand_util-_vCY93Uw.js +0 -44
  347. package/dist/random_normal-DUIT8kyC.js +0 -11
  348. package/dist/range-CYvQC3fW.js +0 -13
  349. package/dist/relu-C4XULT8A.js +0 -8
  350. package/dist/reshape-DJb1jgMt.js +0 -8
  351. package/dist/resize_nearest_neighbor-DAqcTYUe.js +0 -188
  352. package/dist/rope-JjBVufF_.js +0 -24
  353. package/dist/scatterSub-BOnqk-uY.js +0 -27
  354. package/dist/scatter_nd_util-BepMCpLY.js +0 -34
  355. package/dist/seedrandom-SHEGFK6H.js +0 -282
  356. package/dist/selu_util-DeOTf-sc.js +0 -27
  357. package/dist/shared-CX_iPI5K.js +0 -4
  358. package/dist/silu-DsAE2cJ5.js +0 -23
  359. package/dist/slice-Dlb1FlzG.js +0 -13
  360. package/dist/slice_util-BVgPRoij.js +0 -207
  361. package/dist/softmax-Dpav_dWw.js +0 -10
  362. package/dist/split-DYnT8chz.js +0 -11
  363. package/dist/squeeze-B3XYGAlg.js +0 -9
  364. package/dist/stack-Dbbt9mIk.js +0 -10
  365. package/dist/step-DA-5DNu9.js +0 -348
  366. package/dist/stream-BBe2apn4.js +0 -2280
  367. package/dist/sum-C8qNbFNp.js +0 -13
  368. package/dist/tensor-ALxWZfmz.js +0 -7
  369. package/dist/tensor1d-BHgkkhTE.js +0 -9
  370. package/dist/tensor2d-ARItvqVn.js +0 -10
  371. package/dist/tensor4d-D1zRBipJ.js +0 -10
  372. package/dist/tfjs_backend-CsXOum0h.js +0 -685
  373. package/dist/tile-DfyQ0KX-.js +0 -10
  374. package/dist/tokenise-DbS2Ea-T.js +0 -14
  375. package/dist/tokenise.js +0 -6
  376. package/dist/tokeniser/BaseTokeniser.js +0 -137
  377. package/dist/tokeniser/CharTokeniser.js +0 -85
  378. package/dist/tokeniser/bpe.js +0 -156
  379. package/dist/tokeniser/messages.js +0 -0
  380. package/dist/tokeniser/type.js +0 -0
  381. package/dist/topk-BrU2pkrR.js +0 -19
  382. package/dist/training/AdamW.js +0 -132
  383. package/dist/training/BasicTrainer.js +0 -274
  384. package/dist/training/DatasetBuilder.js +0 -1
  385. package/dist/training/Evaluator.js +0 -51
  386. package/dist/training/LRScheduler.js +0 -37
  387. package/dist/training/PreTrainer.js +0 -21
  388. package/dist/training/SFTTrainer.js +0 -23
  389. package/dist/training/configure.js +0 -33
  390. package/dist/training/factory.js +0 -7
  391. package/dist/training/loss.js +0 -18
  392. package/dist/training/orthoGrad.js +0 -9
  393. package/dist/training/prepareData.js +0 -51
  394. package/dist/training/sparseCrossEntropy.js +0 -53
  395. package/dist/training/tasks/TokenStore.js +0 -217
  396. package/dist/training/tasks/tokenStream.js +0 -45
  397. package/dist/training/types.js +0 -0
  398. package/dist/training/validateOptions.js +0 -18
  399. package/dist/training/validation.js +0 -30
  400. package/dist/transpose-BC-M_OoT.js +0 -34
  401. package/dist/unsorted_segment_sum-BelC7R-q.js +0 -408
  402. package/dist/utilities/arrayClose.js +0 -29
  403. package/dist/utilities/arrayShape.js +0 -7
  404. package/dist/utilities/datasetID.js +0 -17
  405. package/dist/utilities/dummy.js +0 -36
  406. package/dist/utilities/float16.js +0 -46
  407. package/dist/utilities/maxHeap.js +0 -54
  408. package/dist/utilities/multinomialCPU.js +0 -7
  409. package/dist/utilities/naming.js +0 -0
  410. package/dist/utilities/packed.js +0 -12
  411. package/dist/utilities/parameters.js +0 -53
  412. package/dist/utilities/performance.js +0 -15
  413. package/dist/utilities/profile.js +0 -32
  414. package/dist/utilities/random.js +0 -18
  415. package/dist/utilities/safetensors.js +0 -63
  416. package/dist/utilities/sentences.js +0 -35
  417. package/dist/utilities/tokenParse.js +0 -16
  418. package/dist/utilities/tokens.js +0 -39
  419. package/dist/utilities/topP.js +0 -25
  420. package/dist/utilities/waitForModel.js +0 -11
  421. package/dist/utilities/weights.js +0 -40
  422. package/dist/utilities/yielder.js +0 -6
  423. package/dist/v4-YCkfo8OR.js +0 -27
  424. package/dist/webgpu-BHX-uBym.js +0 -518
  425. package/dist/webgpu_util-5QTyovaf.js +0 -105
  426. package/dist/zeros-hxKGkRfl.js +0 -12
@@ -1,117 +0,0 @@
1
- import { xt as e } from "../../dist-CMMLi-qO.js";
2
- import { s as t } from "../../webgpu_program-DvkFqRlR.js";
3
- import { c as n, i as r } from "../../webgpu_util-5QTyovaf.js";
4
- import { isPackedTensor as i } from "../../utilities/packed.js";
5
- // lib/ops/webgpu/silu.ts
6
- var a = class {
7
- outputShape;
8
- shaderKey;
9
- dispatchLayout;
10
- dispatch;
11
- variableNames = ["A"];
12
- workgroupSize;
13
- size = !0;
14
- constructor(e) {
15
- this.workgroupSize = [
16
- 128,
17
- 1,
18
- 1
19
- ], this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize), this.shaderKey = "unary_silu";
20
- }
21
- getUserCode() {
22
- return `
23
- fn unaryOperation(x : f32) -> f32 {
24
- return x / (1.0 + exp(-x));
25
- }
26
- ${t("index")} {
27
- if (index < uniforms.size) {
28
- let a = getAByOutputIndex(index);
29
- setOutputAtIndex(index, unaryOperation(a));
30
- }
31
- }
32
- `;
33
- }
34
- };
35
- function o(e) {
36
- let { x: t } = e.inputs, n = e.backend, r = new a(t.shape);
37
- return n.runWebGPUProgram(r, [t], "float32");
38
- }
39
- e({
40
- kernelName: "Silu",
41
- backendName: "webgpu",
42
- kernelFunc: o
43
- });
44
- var s = class {
45
- variableNames = ["dy", "x"];
46
- outputShape;
47
- shaderKey = "SiluGrad16";
48
- dispatchLayout;
49
- dispatch;
50
- workgroupSize = [
51
- 128,
52
- 1,
53
- 1
54
- ];
55
- size = !0;
56
- constructor(e) {
57
- this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
58
- }
59
- getUserCode() {
60
- return `
61
- fn activationGrad(dy: f32, X: f32) -> f32 {
62
- let sigmoid = 1.0 / (1.0 + exp(-X));
63
- return dy * (sigmoid + X * sigmoid * (1.0 - sigmoid));
64
- }
65
- ${t("index")} {
66
- if (index < uniforms.size) {
67
- let X = unpack2x16float(u32(x[index]));
68
- let DY = unpack2x16float(u32(dy[index]));
69
- let dsilu = vec2<f32>(
70
- activationGrad(DY.x, X.x),
71
- activationGrad(DY.y, X.y)
72
- );
73
- result[index] = i32(pack2x16float(dsilu));
74
- }
75
- }`;
76
- }
77
- }, c = class {
78
- variableNames = ["dy", "x"];
79
- outputShape;
80
- shaderKey = "SiluGrad32";
81
- dispatchLayout;
82
- dispatch;
83
- workgroupSize = [
84
- 128,
85
- 1,
86
- 1
87
- ];
88
- size = !0;
89
- constructor(e) {
90
- this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
91
- }
92
- getUserCode() {
93
- return `
94
- fn activationGrad(dy: f32, X: f32) -> f32 {
95
- let sigmoid = 1.0 / (1.0 + exp(-X));
96
- return dy * (sigmoid + X * sigmoid * (1.0 - sigmoid));
97
- }
98
- ${t("index")} {
99
- if (index < uniforms.size) {
100
- let X = getXByOutputIndex(index);
101
- let DY = getDyByOutputIndex(index);
102
- let dsilu = activationGrad(DY, X);
103
- setOutputAtIndex(index, dsilu);
104
- }
105
- }`;
106
- }
107
- };
108
- function l(e) {
109
- let { dy: t, x: n } = e.inputs, r = e.backend, a = i(t), o = a ? new s(n.shape) : new c(n.shape);
110
- return r.runWebGPUProgram(o, [t, n], a ? "packedF16" : "float32");
111
- }
112
- e({
113
- kernelName: "SiluGrad",
114
- backendName: "webgpu",
115
- kernelFunc: l
116
- });
117
- export { a as SiluProgram };
@@ -1,73 +0,0 @@
1
- import { i as e, o as t, s as n } from "../../webgpu_program-DvkFqRlR.js";
2
- import { a as r, t as i } from "../../slice_util-BVgPRoij.js";
3
- import { c as a, i as o } from "../../webgpu_util-5QTyovaf.js";
4
- import { qi as s, xt as c } from "../../dist-CMMLi-qO.js";
5
- // lib/ops/webgpu/slice16.ts
6
- function l(e) {
7
- switch (e) {
8
- case 1: return "1D";
9
- case 2: return "2D";
10
- case 3: return "3D";
11
- case 4: return "4D";
12
- }
13
- return "";
14
- }
15
- var u = class {
16
- variableNames = ["source"];
17
- uniforms;
18
- outputShape;
19
- shaderKey;
20
- rank;
21
- dispatchLayout;
22
- dispatch;
23
- workPerThread = 1;
24
- workgroupSize = [
25
- 64,
26
- 1,
27
- 1
28
- ];
29
- start;
30
- size = !0;
31
- constructor(t, n) {
32
- this.outputShape = n, this.rank = n.length, this.dispatchLayout = a(this.outputShape), this.dispatch = o(this.dispatchLayout, this.outputShape, this.workgroupSize, [
33
- this.workPerThread,
34
- 1,
35
- 1
36
- ]), this.start = t, this.uniforms = `start : ${e(t.length)}, `, this.shaderKey = "slice";
37
- }
38
- getUserCode() {
39
- let r = e(this.rank), i;
40
- return i = this.start.length === 1 ? this.outputShape.map(() => "sourceLoc = uniforms.start + coords;") : this.outputShape.map((e, n) => `sourceLoc.${d[n]} = uniforms.start.${t(n)} + coords.${d[n]};`), `
41
- ${n("index")} {
42
- if (index < uniforms.size) {
43
- var sourceLoc : ${r};
44
- let coords = getCoordsFromIndex(index);
45
- ${i.join("\n")}
46
- result[index] = source[getIndexFromCoords${l(this.rank)}(sourceLoc, uniforms.sourceShape)];
47
- }
48
- }
49
- `;
50
- }
51
- }, d = [
52
- "x",
53
- "y",
54
- "z",
55
- "w",
56
- "u",
57
- "v"
58
- ];
59
- function f(e) {
60
- let { inputs: t, backend: n, attrs: a } = e, { x: o } = t, { begin: c, size: l } = a, [d, f] = r(o, c, l);
61
- if (i(o, d, f), s(f) === 0) return n.makeTensorInfo(f, o.dtype, []);
62
- let p = new u(d, f), m = [{
63
- type: "int32",
64
- data: d
65
- }];
66
- return n.runWebGPUProgram(p, [o], o.dtype, m);
67
- }
68
- c({
69
- kernelName: "Slice16",
70
- backendName: "webgpu",
71
- kernelFunc: f
72
- });
73
- export { f as slice };
@@ -1,18 +0,0 @@
1
- import { H as e, qi as t, xt as n } from "../../dist-CMMLi-qO.js";
2
- import { t as r } from "../../reshape-DJb1jgMt.js";
3
- import { reshape16 as i } from "../reshape16.js";
4
- import a from "./softmax16_program.js";
5
- import o from "./softmax16_subgroup_program.js";
6
- import s from "./utils/deviceInfo.js";
7
- // lib/ops/webgpu/softmax16.ts
8
- function c(n) {
9
- let { inputs: c, backend: l, attrs: u } = n, { logits: d } = c, { dim: f } = u, p = l.subgroupMinSize, m = l.subgroupMaxSize, h = s(l).subgroupsSupported, g = r(d, [t(d.shape) / d.shape[f], d.shape[f]]), _ = h ? new o(g.shape, p, m) : new a(g.shape), v = l.runWebGPUProgram(_, [g], "packedF16");
10
- g.dispose();
11
- let y = e().makeTensorFromTensorInfo(v), b = i(y, d.shape);
12
- return y.dispose(), b;
13
- }
14
- n({
15
- kernelName: "Softmax16",
16
- backendName: "webgpu",
17
- kernelFunc: c
18
- });
@@ -1,88 +0,0 @@
1
- import { s as e } from "../../webgpu_program-DvkFqRlR.js";
2
- import { c as t } from "../../webgpu_util-5QTyovaf.js";
3
- // lib/ops/webgpu/softmax16_program.ts
4
- var n = class {
5
- variableNames = ["logits"];
6
- outputShape;
7
- shaderKey;
8
- dispatchLayout;
9
- dispatch;
10
- workgroupSize;
11
- constructor(e) {
12
- this.outputShape = e, this.dispatchLayout = t(this.outputShape), this.dispatch = [
13
- this.outputShape[0],
14
- 1,
15
- 1
16
- ], this.workgroupSize = this.outputShape[1] >= 4096 ? [
17
- 256,
18
- 1,
19
- 1
20
- ] : this.outputShape[1] < 64 ? [
21
- 32,
22
- 1,
23
- 1
24
- ] : [
25
- 64,
26
- 1,
27
- 1
28
- ], this.shaderKey = "softmax16";
29
- }
30
- getUserCode() {
31
- return `
32
- var<workgroup> buf : array<f32, ${this.workgroupSize[0]}>;
33
- const blockSize = ${this.workgroupSize[0]};
34
- ${e("index")} {
35
- let row = index / blockSize;
36
- let tid = i32(localId.x);
37
- let cols = uniforms.outShape[1];
38
- let rowIdx = row * cols;
39
-
40
- var threadMax = -3.402823e+38f;
41
- for (var col = tid; col < cols; col += blockSize) {
42
- let value = unpack2x16float(u32(logits[rowIdx + col]));
43
- threadMax = max(threadMax, max(value.x, value.y));
44
- }
45
- buf[tid] = threadMax;
46
- workgroupBarrier();
47
-
48
- for (var currSize = blockSize >> 1; currSize > 0; currSize = currSize >> 1) {
49
- if (tid < currSize) {
50
- buf[tid] = max(buf[tid], buf[tid + currSize]);
51
- }
52
- workgroupBarrier();
53
- }
54
-
55
- let rowMaxShared: f32 = buf[0];
56
- workgroupBarrier();
57
-
58
- var threadSum = 0.0f;
59
- for (var col = tid; col < cols; col += blockSize) {
60
- let value = unpack2x16float(u32(logits[rowIdx + col]));
61
- let subExp = exp(value.x - rowMaxShared);
62
- threadSum += subExp;
63
- let subExpY = exp(value.y - rowMaxShared);
64
- threadSum += subExpY;
65
- }
66
- buf[tid] = threadSum;
67
- workgroupBarrier();
68
-
69
- for (var currSize = blockSize >> 1; currSize > 0; currSize = currSize >> 1) {
70
- if (tid < currSize) {
71
- buf[tid] = buf[tid] + buf[tid + currSize];
72
- }
73
- workgroupBarrier();
74
- }
75
-
76
- let rowSumShared: f32 = buf[0];
77
-
78
- for (var col = tid; col < cols; col += blockSize) {
79
- let value = unpack2x16float(u32(logits[rowIdx + col]));
80
- let value1: f32 = exp(value.x - rowMaxShared) / rowSumShared;
81
- let value2: f32 = exp(value.y - rowMaxShared) / rowSumShared;
82
- result[rowIdx + col] = i32(pack2x16float(vec2<f32>(value1, value2)));
83
- }
84
- }
85
- `;
86
- }
87
- };
88
- export { n as default };
@@ -1,69 +0,0 @@
1
- import { s as e } from "../../webgpu_program-DvkFqRlR.js";
2
- import { c as t } from "../../webgpu_util-5QTyovaf.js";
3
- // lib/ops/webgpu/softmax16_subgroup_program.ts
4
- var n = class {
5
- variableNames = ["logits"];
6
- outputShape;
7
- shaderKey;
8
- dispatchLayout;
9
- dispatch;
10
- workgroupSize;
11
- minSubgroupSize;
12
- maxSubgroupSize;
13
- subgroups = !0;
14
- subgroupBuiltins = !1;
15
- constructor(e, n, r) {
16
- this.minSubgroupSize = n, this.maxSubgroupSize = r, this.outputShape = e, this.dispatchLayout = t(this.outputShape), this.dispatch = [
17
- this.outputShape[0],
18
- 1,
19
- 1
20
- ], this.workgroupSize = [
21
- Math.min(64, r),
22
- 1,
23
- 1
24
- ], n !== r && (this.subgroupBuiltins = !0, this.workgroupSize = [
25
- 64,
26
- 1,
27
- 1
28
- ]), this.shaderKey = "softmax16subgroup";
29
- }
30
- getUserCode() {
31
- let t = this.maxSubgroupSize !== this.minSubgroupSize;
32
- return `
33
- ${t ? `var<workgroup> bestValues : array<f32, ${this.workgroupSize[0]}>;` : ""}
34
- const blockSize = ${this.workgroupSize[0]};
35
- ${e("index")} {
36
- let row = index / blockSize;
37
- let tid = i32(localId.x);
38
- let cols = uniforms.outShape[1];
39
- let rowIdx = row * cols;
40
-
41
- var threadMax = -3.402823e+38f;
42
- for (var col = tid; col < cols; col += blockSize) {
43
- let value = unpack2x16float(u32(logits[rowIdx + col]));
44
- threadMax = max(threadMax, max(value.x, value.y));
45
- }
46
-
47
- threadMax = subgroupMax(threadMax);
48
- ${t ? "\n let lane = localId.x % subgroupSize;\n if (lane == 0) {\n bestValues[localId.x / subgroupSize] = threadMax;\n }\n workgroupBarrier();\n let numSubgroups = blockSize / subgroupSize;\n threadMax = select(-3.402823e+38f, bestValues[lane], lane < numSubgroups);\n threadMax = subgroupMax(threadMax);\n workgroupBarrier(); \n " : ""}
49
-
50
- var threadSum = 0.0f;
51
- for (var col = tid; col < cols; col += blockSize) {
52
- let value = unpack2x16float(u32(logits[rowIdx + col]));
53
- let subExp = exp(value - threadMax);
54
- threadSum += subExp.x + subExp.y;
55
- }
56
-
57
- threadSum = subgroupAdd(threadSum);
58
- ${t ? "\n if (lane == 0) {\n bestValues[localId.x / subgroupSize] = threadSum;\n }\n workgroupBarrier();\n threadSum = select(0.0f, bestValues[lane], lane < numSubgroups);\n threadSum = subgroupAdd(threadSum); \n " : ""}
59
-
60
- for (var col = tid; col < cols; col += ${t ? "i32(subgroupSize)" : "blockSize"}) {
61
- let value = unpack2x16float(u32(logits[rowIdx + col]));
62
- let valuePair: vec2<f32> = exp(value - threadMax) / threadSum;
63
- result[rowIdx + col] = i32(pack2x16float(valuePair));
64
- }
65
- }
66
- `;
67
- }
68
- };
69
- export { n as default };
@@ -1,30 +0,0 @@
1
- import { xt as e } from "../../dist-CMMLi-qO.js";
2
- import { ReduceProgram as t, createReduceInfo as n, reduce as r } from "./utils/reductions.js";
3
- import { isPackedTensor as i } from "../../utilities/packed.js";
4
- import a from "./utils/deviceInfo.js";
5
- // lib/ops/webgpu/softmax16grad.ts
6
- var o = class extends t {
7
- constructor(e, t) {
8
- super(e, t, {
9
- reductionOp: "sum",
10
- elementwise: !0
11
- }, !0), this.shaderKey = "SoftmaxGrad16", this.variableNames = ["dy", "softmaxOutput"], this.variableComponents = [1, 1];
12
- }
13
- getReadSnippet() {
14
- return "\n let d: vec2<f32> = unpack2x16float(u32(dy[index]));\n let l: vec2<f32> = unpack2x16float(u32(softmaxOutput[index]));\n return d * l;\n ";
15
- }
16
- getWriteSnippet() {
17
- return "\n let d: vec2<f32> = unpack2x16float(u32(dy[offset + k]));\n let l: vec2<f32> = unpack2x16float(u32(softmaxOutput[offset + k]));\n let outVal = l * (d - bestValue);\n result[offset + k] = i32(pack2x16float(outVal));\n ";
18
- }
19
- };
20
- function s(e) {
21
- let { dy: t, softmaxOutput: s } = e.inputs, c = e.backend, l = a(c), u = i(t), d = i(s);
22
- if (!(u && d)) throw Error("softmaxGradGPU: dy and softmaxOutput must be packed tensors");
23
- let f = [t, s], p = new o(l, n(f, -1));
24
- return r(p, f, c);
25
- }
26
- e({
27
- kernelName: "Softmax16Grad",
28
- backendName: "webgpu",
29
- kernelFunc: s
30
- });
@@ -1,13 +0,0 @@
1
- import { xt as e } from "../../dist-CMMLi-qO.js";
2
- import { t } from "../../binary_op_util-WY9YIl0q.js";
3
- import { BinaryOpProgram as n } from "./utils/binary_op.js";
4
- // lib/ops/webgpu/sub16.ts
5
- function r(e) {
6
- let { a: r, b: i } = e.inputs, a = e.backend, o = new n(t.SUB, r.shape, i.shape);
7
- return a.runWebGPUProgram(o, [r, i], "packedF16");
8
- }
9
- e({
10
- kernelName: "Sub16",
11
- backendName: "webgpu",
12
- kernelFunc: r
13
- });
@@ -1,30 +0,0 @@
1
- import { ReduceProgram as e, createReduceInfo as t, reduce as n } from "./utils/reductions.js";
2
- import { o as r } from "../../axis_util-rF9RnwKE.js";
3
- import { t as i } from "../../sum-C8qNbFNp.js";
4
- import { Ui as a, xt as o } from "../../dist-CMMLi-qO.js";
5
- import { isPackedTensor as s } from "../../utilities/packed.js";
6
- import { transpose16 as c } from "../transpose16.js";
7
- import l from "./utils/deviceInfo.js";
8
- // lib/ops/webgpu/sum16.ts
9
- var u = class extends e {
10
- shaderKey = "sum16";
11
- constructor(e, t, n) {
12
- super(e, t, {
13
- reductionOp: "sum",
14
- elementwise: !1
15
- }, n), n && (this.shaderKey += "_packed");
16
- }
17
- };
18
- function d(e) {
19
- let { x: o } = e.inputs, { axis: d, keepDims: f } = e.attrs, p = e.backend, m = [], h = l(p), g = s(o);
20
- if (!g) return i(o, d, f);
21
- let _ = a(d ?? -1, o.shape), v = r(_, o.shape.length), y = o;
22
- v != null && (y = c(o, v), m.push(y));
23
- let b = new u(h, t([y], -1), g), x = n(b, [y], p);
24
- return m.forEach((e) => e.dispose()), x;
25
- }
26
- o({
27
- kernelName: "Sum16",
28
- backendName: "webgpu",
29
- kernelFunc: d
30
- });
@@ -1,38 +0,0 @@
1
- import { isPackedTensor as e } from "../../utilities/packed.js";
2
- import { t } from "../../transpose-BC-M_OoT.js";
3
- import { H as n, xt as r } from "../../dist-CMMLi-qO.js";
4
- import { reshape16 as i } from "../reshape16.js";
5
- import a from "./transpose16_shared_program.js";
6
- import o from "./transpose16_program.js";
7
- // lib/ops/webgpu/transpose16.ts
8
- function s(r) {
9
- let { inputs: s, attrs: c } = r, { x: l } = s, { perm: u } = c, d = r.backend, f = e(l);
10
- if (f && u[u.length - 1] !== l.shape.length - 1) {
11
- let e = l.shape.length, t = e === 4 ? u.map((e) => e - 1).filter((e) => e >= 0) : u, r = e === 4 ? i(l, [
12
- l.shape[0] * l.shape[1],
13
- l.shape[2],
14
- l.shape[3]
15
- ]) : l, o = new a(r.shape, t), s = d.runWebGPUProgram(o, [r], "packedF16");
16
- if (e === 4) {
17
- r.dispose();
18
- let e = n().makeTensorFromTensorInfo(s), t = i(e, [
19
- l.shape[0],
20
- l.shape[1],
21
- s.shape[1],
22
- s.shape[2]
23
- ]);
24
- return e.dispose(), t;
25
- }
26
- return s;
27
- }
28
- if (f) {
29
- let e = new o(l.shape, u);
30
- return d.runWebGPUProgram(e, [l], "packedF16");
31
- }
32
- return t(l, u);
33
- }
34
- r({
35
- kernelName: "Transpose16",
36
- backendName: "webgpu",
37
- kernelFunc: s
38
- });
@@ -1,50 +0,0 @@
1
- import { c as e, i as t } from "../../webgpu_util-5QTyovaf.js";
2
- import { i as n, o as r, s as i } from "../../webgpu_program-DvkFqRlR.js";
3
- // lib/ops/webgpu/transpose16_program.ts
4
- function a(e) {
5
- let t = e.length;
6
- if (t > 6) throw Error(`Transpose for rank ${t} is not yet supported`);
7
- let n = Array(t);
8
- for (let t = 0; t < e.length; t++) n[e[t]] = `coords.${r(t)}`;
9
- return n.join();
10
- }
11
- var o = class {
12
- variableNames = ["A"];
13
- shaderKey;
14
- outputShape;
15
- dispatchLayout;
16
- dispatch;
17
- workPerThread = 1;
18
- workgroupSize = [
19
- 64,
20
- 1,
21
- 1
22
- ];
23
- newDim;
24
- size = !0;
25
- constructor(n, r) {
26
- let i = Array(n.length);
27
- for (let e = 0; e < i.length; e++) i[e] = n[r[e]];
28
- this.outputShape = i, this.dispatchLayout = e(this.outputShape), this.dispatch = t(this.dispatchLayout, this.outputShape, this.workgroupSize, [
29
- this.workPerThread,
30
- 1,
31
- 1
32
- ]), this.newDim = r, this.shaderKey = `transpose16_${r}`;
33
- }
34
- getUserCode() {
35
- let e = n(this.outputShape.length), t = a(this.newDim);
36
- return `
37
- ${i("index")} {
38
- for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
39
- let flatIndex = index * ${this.workPerThread} + i;
40
- if(flatIndex < uniforms.size) {
41
- let coords = getCoordsFromIndex(flatIndex);
42
- result[flatIndex] = A[getIndexFromCoords${this.outputShape.length}D(
43
- ${e}(${t}), uniforms.aShape)];
44
- }
45
- }
46
- }
47
- `;
48
- }
49
- };
50
- export { o as default };
@@ -1,78 +0,0 @@
1
- import { i as e } from "../../webgpu_util-5QTyovaf.js";
2
- import { s as t } from "../../webgpu_program-DvkFqRlR.js";
3
- import { yi as n } from "../../dist-CMMLi-qO.js";
4
- // lib/ops/webgpu/transpose16_shared_program.ts
5
- var r = class {
6
- variableNames = ["A"];
7
- outputShape;
8
- shaderKey;
9
- dispatchLayout;
10
- dispatch;
11
- workgroupSize = [
12
- 8,
13
- 8,
14
- 1
15
- ];
16
- constructor(t, n) {
17
- let r = t.length, i = Array(r), a = t.slice();
18
- a[a.length - 1] *= 2;
19
- for (let e = 0; e < i.length; e++) i[e] = a[n[e]];
20
- i[i.length - 1] /= 2, this.outputShape = i, this.dispatchLayout = r === 2 ? {
21
- x: [0],
22
- y: [1]
23
- } : {
24
- x: [1],
25
- y: [2],
26
- z: [0]
27
- }, this.dispatch = e(this.dispatchLayout, this.outputShape, this.workgroupSize, [
28
- 2,
29
- 1,
30
- 1
31
- ]), this.shaderKey = `transposeShared16_${r}`;
32
- }
33
- getUserCode() {
34
- let e = this.outputShape.length;
35
- n(this.workgroupSize[0] === this.workgroupSize[1], () => `Must be a square tile, current tile shape is ${this.workgroupSize[0]} x ${this.workgroupSize[1]}`);
36
- let r = this.workgroupSize[0] * 2;
37
- return `
38
- var<workgroup> tile : array<array<f32, ${r + 1}>, ${r}>;
39
- ${t()} {
40
- var x = i32(workgroupId.x) * ${r / 2} + i32(localId.x);
41
- var y = i32(workgroupId.y) * ${r} + i32(localId.y);
42
- let batch = ${e === 3 ? "i32(workgroupId.z)" : "0"};
43
- let batchOffsetA = ${e === 3 ? "batch * uniforms.aShapeStrides[0]" : "0"};
44
- let batchOffsetOut = ${e === 3 ? "batch * uniforms.outShapeStrides[0]" : "0"};
45
-
46
- let inputWidth = uniforms.outShape[${e === 3 ? "1" : "0"}] / 2; // Output height
47
- let inputHeight = uniforms.outShape[${e === 3 ? "2" : "1"}] * 2; // Output width
48
- if (x < inputWidth && y < inputHeight) {
49
- let unpackedA = unpack2x16float(u32(A[batchOffsetA + y * inputWidth + x]));
50
- tile[localId.y][localId.x * 2] = unpackedA.x;
51
- tile[localId.y][localId.x * 2 + 1] = unpackedA.y;
52
- }
53
- // Second load to cover the tile
54
- y = y + ${this.workgroupSize[0]};
55
- if (x < inputWidth && y < inputHeight) {
56
- let unpackedA = unpack2x16float(u32(A[batchOffsetA + y * inputWidth + x]));
57
- tile[localId.y + ${this.workgroupSize[0]}][localId.x * 2] = unpackedA.x;
58
- tile[localId.y + ${this.workgroupSize[0]}][localId.x * 2 + 1] = unpackedA.y;
59
- }
60
- workgroupBarrier();
61
-
62
- let outputWidth = uniforms.outShape[${e === 3 ? "2" : "1"}]; // Output width
63
- let outputHeight = uniforms.outShape[${e === 3 ? "1" : "0"}] * 2; // Output height
64
- x = i32(workgroupId.y) * ${r / 2} + i32(localId.x);
65
- y = i32(workgroupId.x) * ${r} + i32(localId.y);
66
- if (x < outputWidth && y < outputHeight) {
67
- result[batchOffsetOut + y * outputWidth + x] = i32(pack2x16float(vec2<f32>(tile[localId.x * 2][localId.y], tile[localId.x * 2 + 1][localId.y])));
68
- }
69
- // Second store to cover the tile
70
- y = y + ${this.workgroupSize[0]};
71
- if (x < outputWidth && y < outputHeight) {
72
- result[batchOffsetOut + y * outputWidth + x] = i32(pack2x16float(vec2<f32>(tile[localId.x * 2][localId.y + ${this.workgroupSize[0]}], tile[localId.x * 2 + 1][localId.y + ${this.workgroupSize[0]}])));
73
- }
74
- }
75
- `;
76
- }
77
- };
78
- export { r as default };
@@ -1,59 +0,0 @@
1
- import { c as e, i as t } from "../../webgpu_util-5QTyovaf.js";
2
- import { s as n } from "../../webgpu_program-DvkFqRlR.js";
3
- import { xt as r } from "../../dist-CMMLi-qO.js";
4
- // lib/ops/webgpu/unpack16.ts
5
- var i = class {
6
- outputShape;
7
- shaderKey = "Unpack16";
8
- dispatchLayout;
9
- dispatch;
10
- workgroupSize = [
11
- 64,
12
- 1,
13
- 1
14
- ];
15
- variableNames = ["x"];
16
- size = !0;
17
- uniforms;
18
- outputComponent = 4;
19
- variableComponents = [2];
20
- scaling = !1;
21
- constructor(n) {
22
- this.outputShape = [...n.slice(0, -1), n[n.length - 1] * 2], this.dispatchLayout = e(this.outputShape), this.dispatch = t(this.dispatchLayout, this.outputShape, this.workgroupSize, [
23
- 4,
24
- 1,
25
- 1
26
- ]);
27
- }
28
- useScaling() {
29
- this.shaderKey += "_Scaled", this.uniforms = "scaling : f32,", this.scaling = !0;
30
- }
31
- getUserCode() {
32
- return `
33
- ${n("index")} {
34
- let outIndex = index;
35
- if (outIndex < uniforms.size) {
36
- let xvec2 = x[index];
37
- let v1 = vec4<f32>(
38
- unpack2x16float(u32(xvec2.x)),
39
- unpack2x16float(u32(xvec2.y))
40
- ) ${this.scaling ? "* uniforms.scaling" : ""};
41
- result[outIndex] = v1;
42
- }
43
- }`;
44
- }
45
- };
46
- function a(e) {
47
- let { x: t } = e.inputs, { scaling: n } = e.attrs, r = e.backend, a = new i(t.shape), o = n !== 1;
48
- o && a.useScaling();
49
- let s = [{
50
- type: "float32",
51
- data: [1 / n]
52
- }];
53
- return r.runWebGPUProgram(a, [t], "float32", o ? s : void 0);
54
- }
55
- r({
56
- kernelName: "Unpack16",
57
- backendName: "webgpu",
58
- kernelFunc: a
59
- });