@genai-fi/nanogpt 0.9.0 → 0.10.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 (343) hide show
  1. package/README.md +352 -14
  2. package/dist/Generator.js +69 -78
  3. package/dist/{RealDiv-D4EzDsC0.js → RealDiv-DgA3z9oO.js} +32 -206
  4. package/dist/Reshape-CF6odzV4.js +16 -0
  5. package/dist/Reshape-_kILl6tK.js +81 -0
  6. package/dist/TeachableLLM.js +28 -22
  7. package/dist/Trainer.d.ts +2 -0
  8. package/dist/Trainer.js +3 -2
  9. package/dist/{axis_util-TbGYJ208.js → axis_util-BvHEw88j.js} +7 -23
  10. package/dist/backend.d.ts +2 -1
  11. package/dist/backend.js +10 -4
  12. package/dist/backend_util-D-rUb2ty.js +474 -0
  13. package/dist/backend_webgpu-B0u2ndUn.js +547 -0
  14. package/dist/binary_op_util-pKXltfxI.js +192 -0
  15. package/dist/broadcast_to-CwF7XIeu.js +30 -0
  16. package/dist/checks/appendCache.js +2 -2
  17. package/dist/checks/attentionMask.js +3 -3
  18. package/dist/checks/check.d.ts +1 -1
  19. package/dist/checks/check.js +8 -8
  20. package/dist/checks/gelu.js +2 -2
  21. package/dist/checks/index.d.ts +2 -0
  22. package/dist/checks/index.js +7 -5
  23. package/dist/checks/matMulGelu.js +6 -6
  24. package/dist/checks/normRMS.js +7 -7
  25. package/dist/checks/normRMSGrad.js +3 -3
  26. package/dist/checks/packUnpack.d.ts +1 -0
  27. package/dist/checks/packUnpack.js +18 -0
  28. package/dist/checks/qkv.js +12 -27
  29. package/dist/checks/rope.js +2 -2
  30. package/dist/checks/weights.js +18 -16
  31. package/dist/complex-CSlYz-2T.js +13 -0
  32. package/dist/complex_util-Yc1A_gV1.js +55 -0
  33. package/dist/concat-BHlIJeyT.js +19 -0
  34. package/dist/concat_util-DcJk7YHS.js +22 -0
  35. package/dist/data/docx.js +1 -1
  36. package/dist/data/parquet.js +2 -2
  37. package/dist/data/pdf.js +1 -1
  38. package/dist/data/textLoader.js +1 -1
  39. package/dist/{dataset-DlZtKmBq.js → dataset-0xP8GjwI.js} +136 -236
  40. package/dist/dropout-C1pM3f11.js +99 -0
  41. package/dist/expand_dims-BPG4fwBP.js +13 -0
  42. package/dist/exports_initializers-xuidcwI4.js +7 -0
  43. package/dist/gather-DykLGqmW.js +10 -0
  44. package/dist/{gelu-Bp_-935b.js → gelu-CNLFZWea.js} +11 -10
  45. package/dist/{gpgpu_math-CDaYiyE_.js → gpgpu_math-DDVJCn6-.js} +90 -265
  46. package/dist/{index-C4L8Cm77.js → index-CieiGp4Y.js} +14 -14
  47. package/dist/index-CjOj7j-u.js +7308 -0
  48. package/dist/{index-Tf7vU29b.js → index-Cp39cXWe.js} +3 -10
  49. package/dist/{index-Dwqa6Zy2.js → index-DvYrXKkX.js} +2 -2
  50. package/dist/index-ZyQhjEPo.js +2157 -0
  51. package/dist/{jszip.min-CjP2V1VV.js → jszip.min-Bz5-11Bk.js} +56 -57
  52. package/dist/kernel_funcs_utils-Dg_-E44D.js +308 -0
  53. package/dist/layers/BaseLayer.d.ts +1 -0
  54. package/dist/layers/BaseLayer.js +7 -6
  55. package/dist/layers/CausalSelfAttention.d.ts +0 -1
  56. package/dist/layers/CausalSelfAttention.js +56 -55
  57. package/dist/layers/MLP.js +15 -16
  58. package/dist/layers/PositionEmbedding.js +5 -14
  59. package/dist/layers/RMSNorm.js +3 -3
  60. package/dist/layers/RoPECache.d.ts +2 -0
  61. package/dist/layers/RoPECache.js +22 -17
  62. package/dist/layers/TiedEmbedding.js +22 -17
  63. package/dist/layers/TransformerBlock.js +21 -20
  64. package/dist/loader/load.js +1 -1
  65. package/dist/loader/loadTransformers.js +1 -1
  66. package/dist/loader/oldZipLoad.js +39 -33
  67. package/dist/loader/save.js +1 -1
  68. package/dist/log_sum_exp-DWI-76TI.js +41 -0
  69. package/dist/main.d.ts +8 -0
  70. package/dist/main.js +63 -52
  71. package/dist/matMul16--R5hOwDG.js +77 -0
  72. package/dist/mat_mul-DeAh4uTH.js +12 -0
  73. package/dist/mod-Gt1rMB4n.js +12 -0
  74. package/dist/models/NanoGPTV1.js +40 -31
  75. package/dist/models/model.d.ts +2 -0
  76. package/dist/models/model.js +37 -29
  77. package/dist/{mulmat_packed_gpu-BT60jmzP.js → mulmat_packed_gpu-BMFhLwta.js} +1 -17
  78. package/dist/{non_max_suppression_impl-CsEgBuMA.js → non_max_suppression_impl-B2W7YjZB.js} +0 -32
  79. package/dist/ones-CAMiP4I2.js +15 -0
  80. package/dist/ops/adamAdjust.js +1 -1
  81. package/dist/ops/adamMoments.d.ts +1 -1
  82. package/dist/ops/adamMoments.js +4 -4
  83. package/dist/ops/add16.d.ts +2 -0
  84. package/dist/ops/add16.js +9 -0
  85. package/dist/ops/appendCache.js +16 -9
  86. package/dist/ops/attentionMask.js +4 -4
  87. package/dist/ops/concat16.d.ts +2 -0
  88. package/dist/ops/concat16.js +9 -0
  89. package/dist/ops/cpu/adamAdjust.js +14 -13
  90. package/dist/ops/cpu/adamMoments.js +10 -9
  91. package/dist/ops/cpu/appendCache.js +9 -8
  92. package/dist/ops/cpu/attentionMask.js +15 -14
  93. package/dist/ops/cpu/fusedSoftmax.js +13 -12
  94. package/dist/ops/cpu/gatherSub.js +9 -24
  95. package/dist/ops/cpu/gelu.js +13 -12
  96. package/dist/ops/cpu/matMul16.d.ts +1 -0
  97. package/dist/ops/cpu/matMul16.js +16 -0
  98. package/dist/ops/cpu/matMulGelu.js +18 -16
  99. package/dist/ops/cpu/matMulMul.js +8 -7
  100. package/dist/ops/cpu/mulDropout.js +4 -3
  101. package/dist/ops/cpu/normRMS.js +11 -10
  102. package/dist/ops/cpu/qkv.js +17 -13
  103. package/dist/ops/cpu/rope.js +23 -22
  104. package/dist/ops/cpu/scatterSub.js +16 -30
  105. package/dist/ops/dot16.d.ts +2 -0
  106. package/dist/ops/dot16.js +42 -0
  107. package/dist/ops/gatherSub.js +1 -1
  108. package/dist/ops/gelu.js +2 -2
  109. package/dist/ops/grads/add16.d.ts +1 -0
  110. package/dist/ops/grads/add16.js +27 -0
  111. package/dist/ops/grads/attentionMask.js +12 -19
  112. package/dist/ops/grads/gelu.js +4 -3
  113. package/dist/ops/grads/matMul16.d.ts +2 -0
  114. package/dist/ops/grads/matMul16.js +9 -0
  115. package/dist/ops/grads/matMulGelu.js +8 -7
  116. package/dist/ops/grads/normRMS.js +8 -7
  117. package/dist/ops/grads/{fusedSoftmax.d.ts → pack16.d.ts} +1 -1
  118. package/dist/ops/grads/pack16.js +7 -0
  119. package/dist/ops/grads/qkv.d.ts +3 -1
  120. package/dist/ops/grads/qkv.js +28 -22
  121. package/dist/ops/grads/rope.d.ts +2 -1
  122. package/dist/ops/grads/rope.js +6 -13
  123. package/dist/ops/grads/softmax16.d.ts +2 -0
  124. package/dist/ops/grads/softmax16.js +26 -0
  125. package/dist/ops/grads/unpack16.d.ts +2 -0
  126. package/dist/ops/grads/unpack16.js +6 -0
  127. package/dist/ops/grads/utils.d.ts +3 -0
  128. package/dist/ops/grads/utils.js +10 -0
  129. package/dist/ops/matMul16.d.ts +15 -0
  130. package/dist/ops/matMul16.js +13 -0
  131. package/dist/ops/matMulGelu.js +1 -1
  132. package/dist/ops/matMulMul.js +1 -1
  133. package/dist/ops/mul16.d.ts +2 -0
  134. package/dist/ops/mul16.js +8 -0
  135. package/dist/ops/mulDrop.js +1 -1
  136. package/dist/ops/normRMS.js +1 -1
  137. package/dist/ops/pack16.d.ts +2 -0
  138. package/dist/ops/pack16.js +6 -0
  139. package/dist/ops/qkv.d.ts +1 -1
  140. package/dist/ops/qkv.js +8 -4
  141. package/dist/ops/reshape16.d.ts +2 -0
  142. package/dist/ops/reshape16.js +43 -0
  143. package/dist/ops/rope.d.ts +1 -1
  144. package/dist/ops/rope.js +8 -10
  145. package/dist/ops/scatterSub.js +1 -1
  146. package/dist/ops/slice16.d.ts +2 -0
  147. package/dist/ops/slice16.js +9 -0
  148. package/dist/ops/softmax16.d.ts +2 -0
  149. package/dist/ops/softmax16.js +12 -0
  150. package/dist/ops/sub16.d.ts +2 -0
  151. package/dist/ops/sub16.js +8 -0
  152. package/dist/ops/sum16.d.ts +2 -0
  153. package/dist/ops/sum16.js +13 -0
  154. package/dist/ops/transpose16.d.ts +3 -0
  155. package/dist/ops/transpose16.js +41 -0
  156. package/dist/ops/unpack16.d.ts +2 -0
  157. package/dist/ops/unpack16.js +6 -0
  158. package/dist/ops/webgl/adamAdjust.js +3 -2
  159. package/dist/ops/webgl/adamMoments.js +2 -1
  160. package/dist/ops/webgl/appendCache.js +2 -1
  161. package/dist/ops/webgl/attentionMask.js +5 -4
  162. package/dist/ops/webgl/fusedSoftmax.js +6 -4
  163. package/dist/ops/webgl/gatherSub.js +7 -6
  164. package/dist/ops/webgl/gelu.js +3 -2
  165. package/dist/ops/webgl/log.js +12 -27
  166. package/dist/ops/webgl/matMul16.d.ts +1 -0
  167. package/dist/ops/webgl/matMul16.js +37 -0
  168. package/dist/ops/webgl/matMulGelu.js +17 -15
  169. package/dist/ops/webgl/matMulMul.js +13 -12
  170. package/dist/ops/webgl/mulDropout.js +9 -8
  171. package/dist/ops/webgl/normRMS.js +8 -7
  172. package/dist/ops/webgl/qkv.js +6 -5
  173. package/dist/ops/webgl/rope.js +11 -10
  174. package/dist/ops/webgl/scatterSub.js +6 -5
  175. package/dist/ops/webgpu/adamAdjust.js +12 -10
  176. package/dist/ops/webgpu/adamMoments.js +27 -22
  177. package/dist/ops/webgpu/add16.d.ts +1 -0
  178. package/dist/ops/webgpu/add16.js +14 -0
  179. package/dist/ops/webgpu/appendCache.js +64 -17
  180. package/dist/ops/webgpu/attentionMask.js +19 -62
  181. package/dist/ops/webgpu/attentionMask32_program.d.ts +19 -0
  182. package/dist/ops/webgpu/attentionMask32_program.js +54 -0
  183. package/dist/ops/webgpu/concat16.d.ts +19 -0
  184. package/dist/ops/webgpu/concat16.js +128 -0
  185. package/dist/ops/webgpu/gatherSub.js +9 -7
  186. package/dist/ops/webgpu/gelu.js +78 -31
  187. package/dist/ops/webgpu/index.js +12 -0
  188. package/dist/ops/webgpu/matMul16.d.ts +1 -0
  189. package/dist/ops/webgpu/matMul16.js +58 -0
  190. package/dist/ops/webgpu/matMul16_program.d.ts +42 -0
  191. package/dist/ops/webgpu/matMul16_program.js +336 -0
  192. package/dist/ops/webgpu/mul16.d.ts +1 -0
  193. package/dist/ops/webgpu/mul16.js +14 -0
  194. package/dist/ops/webgpu/normRMS.js +21 -40
  195. package/dist/ops/webgpu/normRMS16_program.d.ts +9 -0
  196. package/dist/ops/webgpu/normRMS16_program.js +24 -0
  197. package/dist/ops/webgpu/normRMS32_program.d.ts +9 -0
  198. package/dist/ops/webgpu/normRMS32_program.js +24 -0
  199. package/dist/ops/webgpu/normRMSGrad.js +113 -64
  200. package/dist/ops/webgpu/pack16.d.ts +1 -0
  201. package/dist/ops/webgpu/pack16.js +19 -0
  202. package/dist/ops/webgpu/pack16_program.d.ts +19 -0
  203. package/dist/ops/webgpu/pack16_program.js +92 -0
  204. package/dist/ops/webgpu/qkv.js +20 -55
  205. package/dist/ops/webgpu/rope.js +77 -22
  206. package/dist/ops/webgpu/scatterSub.js +9 -7
  207. package/dist/ops/webgpu/slice16.d.ts +7 -0
  208. package/dist/ops/webgpu/slice16.js +71 -0
  209. package/dist/{variable-Bm2OFwGI.js → ops/webgpu/softmax16.d.ts} +2 -8
  210. package/dist/ops/webgpu/softmax16.js +23 -0
  211. package/dist/ops/webgpu/softmax16_program.d.ts +13 -0
  212. package/dist/ops/webgpu/softmax16_program.js +73 -0
  213. package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +17 -0
  214. package/dist/ops/webgpu/softmax16_subgroup_program.js +75 -0
  215. package/dist/ops/webgpu/softmax16grad.d.ts +1 -0
  216. package/dist/ops/webgpu/softmax16grad.js +38 -0
  217. package/dist/ops/webgpu/sub16.d.ts +1 -0
  218. package/dist/ops/webgpu/sub16.js +14 -0
  219. package/dist/ops/webgpu/sum16.d.ts +1 -0
  220. package/dist/ops/webgpu/sum16.js +40 -0
  221. package/dist/ops/webgpu/transpose16.d.ts +1 -0
  222. package/dist/ops/webgpu/transpose16.js +35 -0
  223. package/dist/ops/webgpu/transpose16_program.d.ts +16 -0
  224. package/dist/ops/webgpu/transpose16_program.js +50 -0
  225. package/dist/ops/webgpu/transpose16_shared_program.d.ts +15 -0
  226. package/dist/ops/webgpu/transpose16_shared_program.js +71 -0
  227. package/dist/ops/webgpu/unpack16.d.ts +1 -0
  228. package/dist/ops/webgpu/unpack16.js +49 -0
  229. package/dist/ops/webgpu/utils/binary_op.d.ts +19 -0
  230. package/dist/ops/webgpu/utils/binary_op.js +79 -0
  231. package/dist/ops/webgpu/utils/deviceInfo.d.ts +7 -0
  232. package/dist/ops/webgpu/utils/deviceInfo.js +11 -0
  233. package/dist/ops/webgpu/utils/reductions.d.ts +32 -4
  234. package/dist/ops/webgpu/utils/reductions.js +236 -45
  235. package/dist/ops-CNI3TwqM.js +645 -0
  236. package/dist/pack16-CFUqumar.js +41 -0
  237. package/dist/{papaparse.min-C8l2Kvo1.js → papaparse.min-C0cScC2i.js} +2 -8
  238. package/dist/{parquet-C0Tlmv9c.js → parquet-BE8MU_ge.js} +201 -278
  239. package/dist/patches/PackedTensor.d.ts +12 -0
  240. package/dist/patches/PackedTensor.js +11 -0
  241. package/dist/patches/engine.d.ts +261 -0
  242. package/dist/patches/engine.js +10 -0
  243. package/dist/patches/tape.d.ts +12 -0
  244. package/dist/patches/tape.js +5 -0
  245. package/dist/patches/webgpu_backend.d.ts +18 -0
  246. package/dist/patches/webgpu_backend.js +57 -0
  247. package/dist/{tensor-CZr4dh61.js → patches/webgpu_base.d.ts} +5 -8
  248. package/dist/patches/webgpu_base.js +34 -0
  249. package/dist/patches/webgpu_program.d.ts +36 -0
  250. package/dist/patches/webgpu_program.js +401 -0
  251. package/dist/{pdf-kJD-f258.js → pdf-NIhmP3sq.js} +424 -428
  252. package/dist/random_width-DY6Kk2Dl.js +10051 -0
  253. package/dist/range-BMS52eQi.js +11 -0
  254. package/dist/reciprocal-CTmshQ9J.js +10 -0
  255. package/dist/{register_all_kernels-DIGpEwcf.js → register_all_kernels-Bwu1PTuU.js} +719 -9766
  256. package/dist/relu-yZ2-7WxU.js +10 -0
  257. package/dist/reshape-DevtBWtf.js +10 -0
  258. package/dist/rope-B5UUMsPi.js +32 -0
  259. package/dist/{scatter_nd_util-BQdz--Gn.js → scatter_nd_util-5EL-8VAQ.js} +1 -1
  260. package/dist/selu_util-D1w6yyTO.js +303 -0
  261. package/dist/{shared-DuP7ue-R.js → shared-BRksrJb3.js} +1 -17
  262. package/dist/shared-BuAXb4CI.js +2145 -0
  263. package/dist/sin-BGfy2HZo.js +16 -0
  264. package/dist/slice-D_gkkqZK.js +13 -0
  265. package/dist/slice_util-DtEldBfK.js +261 -0
  266. package/dist/softmax-ZHVebtR1.js +13 -0
  267. package/dist/split-DrfihRpZ.js +10 -0
  268. package/dist/squeeze-DZEpeblb.js +11 -0
  269. package/dist/stack-yOIAalTq.js +13 -0
  270. package/dist/sum-_fzj5ZTB.js +12 -0
  271. package/dist/tensor-DdQUJZlz.js +909 -0
  272. package/dist/tensor-f35l8Odg.js +8 -0
  273. package/dist/tensor1d-CeZuc-Rv.js +12 -0
  274. package/dist/tensor2d-G4Ys2GxX.js +15 -0
  275. package/dist/tensor4d-B8roDgtc.js +15 -0
  276. package/dist/tensor_util-DV-FP5Q3.js +523 -0
  277. package/dist/tfjs_backend-kNyO5L2d.js +653 -0
  278. package/dist/tile-BzyEiF-F.js +13 -0
  279. package/dist/tokeniser/CharTokeniser.js +1 -1
  280. package/dist/tokeniser/bpe.js +1 -1
  281. package/dist/training/Adam.d.ts +2 -1
  282. package/dist/training/Adam.js +12 -28
  283. package/dist/training/AdamExt.d.ts +1 -0
  284. package/dist/training/AdamExt.js +2 -2
  285. package/dist/training/DatasetBuilder.js +3 -20
  286. package/dist/training/FullTrainer.js +82 -64
  287. package/dist/training/Trainer.d.ts +11 -6
  288. package/dist/training/Trainer.js +51 -39
  289. package/dist/training/sparseCrossEntropy.js +3 -3
  290. package/dist/transpose-DKELTqhe.js +38 -0
  291. package/dist/utilities/arrayClose.js +7 -7
  292. package/dist/utilities/dummy.js +35 -27
  293. package/dist/utilities/multinomialCPU.js +2 -2
  294. package/dist/utilities/packed.d.ts +7 -0
  295. package/dist/utilities/packed.js +716 -0
  296. package/dist/utilities/performance.js +1 -1
  297. package/dist/utilities/profile.js +1 -1
  298. package/dist/utilities/safetensors.js +2 -2
  299. package/dist/utilities/sentences.d.ts +5 -0
  300. package/dist/utilities/sentences.js +41 -0
  301. package/dist/utilities/weights.js +2 -2
  302. package/dist/variable-Bhn5bHYv.js +7 -0
  303. package/dist/{webgpu_program-DkQJOJSd.js → webgpu_program-Cigz-7RF.js} +15 -44
  304. package/dist/webgpu_util-BBCnKm2X.js +65 -0
  305. package/dist/zeros-2gldETuK.js +14 -0
  306. package/package.json +4 -3
  307. package/dist/Reshape-Bowtk9BP.js +0 -127
  308. package/dist/Reshape-DUqYftGC.js +0 -30
  309. package/dist/backend_util-CJIiDoV1.js +0 -749
  310. package/dist/broadcast_to-DzlNweb8.js +0 -44
  311. package/dist/concat-B912vBbo.js +0 -33
  312. package/dist/dropout-C-csYCLj.js +0 -193
  313. package/dist/exports_initializers-B8iZMgQ0.js +0 -16
  314. package/dist/gather-Dnpgw-YQ.js +0 -25
  315. package/dist/index-BzFyqcy-.js +0 -4457
  316. package/dist/index-C1rx_Ajs.js +0 -12076
  317. package/dist/kernel_funcs_utils-DKLK0Mg3.js +0 -466
  318. package/dist/log_sum_exp-DO6z8tSE.js +0 -103
  319. package/dist/mat_mul-DzjTFx-u.js +0 -27
  320. package/dist/mod-Dobti4j4.js +0 -27
  321. package/dist/ones-tIJeHlq-.js +0 -29
  322. package/dist/ops/fusedSoftmax.d.ts +0 -2
  323. package/dist/ops/fusedSoftmax.js +0 -10
  324. package/dist/ops/grads/fusedSoftmax.js +0 -22
  325. package/dist/ops-LuCMAnmM.js +0 -1525
  326. package/dist/random_width-CXVRloNK.js +0 -13670
  327. package/dist/range-CWcz7xFA.js +0 -26
  328. package/dist/reciprocal-C4rNcM-S.js +0 -25
  329. package/dist/relu-BjCh_SYb.js +0 -25
  330. package/dist/reshape-CnIwVG1c.js +0 -25
  331. package/dist/selu_util-OtRzVwW5.js +0 -719
  332. package/dist/shared-DmRsFyaJ.js +0 -3134
  333. package/dist/sin-gpDNRxE0.js +0 -47
  334. package/dist/slice-d0Vo9XTN.js +0 -28
  335. package/dist/softmax-D7Jj3p_P.js +0 -28
  336. package/dist/split-DK2k5eHf.js +0 -25
  337. package/dist/stack-DFatutCx.js +0 -27
  338. package/dist/sum-CJ0ULhmt.js +0 -27
  339. package/dist/tensor1d-vML0r3q6.js +0 -27
  340. package/dist/tensor2d-D76QGjF3.js +0 -30
  341. package/dist/tensor4d-Df1WlVDY.js +0 -30
  342. package/dist/webgpu_util-pLEV9tks.js +0 -80
  343. package/dist/zeros-Bj5rMYA7.js +0 -52
@@ -1,4 +1,4 @@
1
- import { t as s } from "../index-BzFyqcy-.js";
1
+ import { t as s } from "../index-ZyQhjEPo.js";
2
2
  async function f(e, o = 10, r = !1) {
3
3
  for (let t = 0; t < 100; t++) {
4
4
  const a = r ? await e() : s(e);
@@ -1,4 +1,4 @@
1
- import { m as a } from "../index-BzFyqcy-.js";
1
+ import { a } from "../index-ZyQhjEPo.js";
2
2
  const s = 1024 * 1024;
3
3
  class l {
4
4
  log = /* @__PURE__ */ new Map();
@@ -1,5 +1,5 @@
1
- import "../index-BzFyqcy-.js";
2
- import { t as y } from "../tensor-CZr4dh61.js";
1
+ import "../index-ZyQhjEPo.js";
2
+ import { t as y } from "../tensor-f35l8Odg.js";
3
3
  function l(t) {
4
4
  if (t === "float32") return "F32";
5
5
  if (t === "int32") return "I32";
@@ -0,0 +1,5 @@
1
+ import { default as TeachableLLM } from '../TeachableLLM';
2
+ import { Tensor2D, Tensor3D } from '@tensorflow/tfjs-core';
3
+ export declare function meanPooling(embeddings: Tensor3D, attentionMask?: Tensor2D): Tensor2D;
4
+ export declare function sentenceEmbeddingsTensor(model: TeachableLLM, sentences: string[], batchSize?: number): Promise<Tensor2D>;
5
+ export declare function sentenceEmbeddings(model: TeachableLLM, sentences: string[], batchSize?: number): Promise<number[][]>;
@@ -0,0 +1,41 @@
1
+ import { m as w } from "../index-ZyQhjEPo.js";
2
+ import { t as g } from "../tensor2d-G4Ys2GxX.js";
3
+ import { e as y } from "../expand_dims-BPG4fwBP.js";
4
+ import { s as h } from "../sum-_fzj5ZTB.js";
5
+ import { c as T } from "../concat-BHlIJeyT.js";
6
+ const p = 16;
7
+ function A(o, t) {
8
+ if (!t)
9
+ return o.mean(1);
10
+ const r = y(t, 2), i = w(o, r), e = h(i, 1), s = h(t, 1, !0), c = e.div(s.maximum(1e-9));
11
+ return r.dispose(), i.dispose(), e.dispose(), s.dispose(), c;
12
+ }
13
+ async function E(o, t, r = p) {
14
+ const i = o.tokeniser, e = o.config.blockSize;
15
+ let s = null, c = 0;
16
+ for (; c < t.length; ) {
17
+ const m = t.slice(c, c + p), k = await i.tokenise(m, !0), l = [], d = [];
18
+ for (const n of k)
19
+ n.length > e ? (l.push(n.slice(n.length - e, n.length)), d.push(new Array(e).fill(1))) : n.length < e ? (l.push(n.concat(new Array(e - n.length).fill(0))), d.push(
20
+ new Array(n.length).fill(1).concat(new Array(e - n.length).fill(0))
21
+ )) : (l.push(n), d.push(new Array(e).fill(1)));
22
+ const b = g(l, [l.length, e], "int32"), u = g(d, [d.length, e], "float32"), f = o.model.forward({ skipLogits: !0, training: !1 }, b)[0], a = A(f, u);
23
+ if (u.dispose(), f.dispose(), s === null)
24
+ s = a;
25
+ else {
26
+ const n = s;
27
+ s = T([s, a], 0), n.dispose(), a.dispose();
28
+ }
29
+ c += r;
30
+ }
31
+ return s;
32
+ }
33
+ async function v(o, t, r = p) {
34
+ const i = await E(o, t, r), e = await i.array();
35
+ return i.dispose(), e;
36
+ }
37
+ export {
38
+ A as meanPooling,
39
+ v as sentenceEmbeddings,
40
+ E as sentenceEmbeddingsTensor
41
+ };
@@ -1,5 +1,5 @@
1
- import "../index-BzFyqcy-.js";
2
- import { t as p } from "../tensor-CZr4dh61.js";
1
+ import "../index-ZyQhjEPo.js";
2
+ import { t as p } from "../tensor-f35l8Odg.js";
3
3
  function h(n) {
4
4
  const e = n.reduce((s, o) => s + o.length, 0), a = new Float32Array(e);
5
5
  let t = 0;
@@ -0,0 +1,7 @@
1
+ import { E as i } from "./index-ZyQhjEPo.js";
2
+ function m(r, a = !0, e, t) {
3
+ return i.makeVariable(r, a, e, t);
4
+ }
5
+ export {
6
+ m as v
7
+ };
@@ -1,20 +1,5 @@
1
- import { ae as k, af as z, ag as E, a3 as j, n as A } from "./index-BzFyqcy-.js";
2
- /**
3
- * @license
4
- * Copyright 2019 Google LLC. All Rights Reserved.
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- * =============================================================================
17
- */
1
+ import { h as k } from "./index-ZyQhjEPo.js";
2
+ import { b as z, e as E, i as j, a as A } from "./tensor-DdQUJZlz.js";
18
3
  function L(e, s) {
19
4
  if (Math.max(...e) > 5)
20
5
  throw new Error("Cannot symbolically compute strides for rank > 6 tensor.");
@@ -24,7 +9,7 @@ function L(e, s) {
24
9
  u[n] = `(${u[n + 1]} * ${i[n + 1]})`;
25
10
  return u;
26
11
  }
27
- const X = (e, s, t) => t === "int32" ? `atomicAdd(${e}, bitcast<i32>(${s}));` : `
12
+ const H = (e, s, t) => t === "int32" ? `atomicAdd(${e}, bitcast<i32>(${s}));` : `
28
13
  {
29
14
  var oldValue = 0;
30
15
  loop {
@@ -37,27 +22,11 @@ const X = (e, s, t) => t === "int32" ? `atomicAdd(${e}, bitcast<i32>(${s}));` :
37
22
  oldValue = res.old_value;
38
23
  }
39
24
  }`;
40
- /**
41
- * @license
42
- * Copyright 2022 Google LLC. All Rights Reserved.
43
- * Licensed under the Apache License, Version 2.0 (the "License");
44
- * you may not use this file except in compliance with the License.
45
- * You may obtain a copy of the License at
46
- *
47
- * http://www.apache.org/licenses/LICENSE-2.0
48
- *
49
- * Unless required by applicable law or agreed to in writing, software
50
- * distributed under the License is distributed on an "AS IS" BASIS,
51
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
- * See the License for the specific language governing permissions and
53
- * limitations under the License.
54
- * =============================================================================
55
- */
56
25
  var b;
57
26
  (function(e) {
58
27
  e[e.FROM_PIXELS = 0] = "FROM_PIXELS", e[e.DRAW = 1] = "DRAW";
59
28
  })(b || (b = {}));
60
- const H = (e, s, t, o, i) => {
29
+ const Y = (e, s, t, o, i) => {
61
30
  const u = { dtype: o.dtype, shape: o.shape }, n = D(t, u, s), r = e.createShaderModule({ code: n, label: s.constructor.name });
62
31
  let d = E().get("WEBGPU_PRINT_SHADER");
63
32
  if (d !== "") {
@@ -118,7 +87,7 @@ function I(e) {
118
87
  return "v";
119
88
  throw Error(`Index ${e} is not yet supported`);
120
89
  }
121
- function Y(...e) {
90
+ function q(...e) {
122
91
  let s;
123
92
  switch (e.length) {
124
93
  case 0:
@@ -236,7 +205,7 @@ function D(e, s, t) {
236
205
  return a.push(w(l, t)), a.join(`
237
206
  `);
238
207
  }
239
- function q(e, s, t) {
208
+ function Z(e, s, t) {
240
209
  let o = e.shaderKey;
241
210
  if (e.pixelsOpType != null)
242
211
  return o;
@@ -536,13 +505,15 @@ function m(e) {
536
505
  }
537
506
  export {
538
507
  b as P,
539
- X as a,
508
+ y as a,
540
509
  v as b,
541
- H as c,
542
- I as d,
543
- x as e,
544
- y as f,
545
- Y as g,
546
- q as m,
510
+ I as c,
511
+ x as d,
512
+ q as e,
513
+ Y as f,
514
+ N as g,
515
+ H as h,
516
+ Z as m,
517
+ L as s,
547
518
  f as t
548
519
  };
@@ -0,0 +1,65 @@
1
+ import "./index-ZyQhjEPo.js";
2
+ import { a as u } from "./tensor-DdQUJZlz.js";
3
+ const e = (r) => {
4
+ let n = 1;
5
+ for (let t = 0; t < r.length; t++)
6
+ n *= r[t];
7
+ return n;
8
+ };
9
+ function d(r, n, t = [1, 1, 1], a = [1, 1, 1]) {
10
+ const [o, i, f] = [
11
+ Math.ceil(e(r.x.map((c) => n[c])) / (t[0] * a[0])),
12
+ r.y ? Math.ceil(e(r.y.map((c) => n[c])) / (t[1] * a[1])) : 1,
13
+ r.z ? Math.ceil(e(r.z.map((c) => n[c])) / (t[2] * a[2])) : 1
14
+ ];
15
+ return [o, i, f];
16
+ }
17
+ function p(r, n, t, a = !1) {
18
+ const o = [8, 8, 1], i = [4, 4, 1];
19
+ return a || (r <= 8 && (i[1] = 1), n <= 16 && t <= 16 && (o[0] = 4)), { workgroupSize: o, elementsPerThread: i };
20
+ }
21
+ function M(r, n, t = !1) {
22
+ if (t)
23
+ return [8, 8, 1];
24
+ const a = e(r.x.map((i) => n[i])), o = e(r.y.map((i) => n[i]));
25
+ return a <= 4 ? [4, 16, 1] : o <= 4 ? [16, 4, 1] : [16, 16, 1];
26
+ }
27
+ function h(r, n, t = !1) {
28
+ if (t)
29
+ return [4, 4, 1];
30
+ const a = e(r.x.map((i) => n[i])), o = e(r.y.map((i) => n[i]));
31
+ return a <= 4 ? [1, 2, 1] : o <= 4 ? [2, 1, 1] : [2, 2, 1];
32
+ }
33
+ function x(r) {
34
+ return { x: r.map((n, t) => t) };
35
+ }
36
+ function g(r) {
37
+ if (r === "float32" || r === "int32" || r === "bool" || r === "string")
38
+ return 4;
39
+ if (r === "complex64")
40
+ return 8;
41
+ throw new Error(`Unknown dtype ${r}`);
42
+ }
43
+ function b() {
44
+ return !!(typeof globalThis < "u" && globalThis.navigator && globalThis.navigator.gpu);
45
+ }
46
+ function P(r, n) {
47
+ Array.isArray(r) || (r = [r]), r.forEach((t) => {
48
+ t != null && u(t.dtype !== "complex64", () => `${n} does not support complex64 tensors in the WebGPU backend.`);
49
+ });
50
+ }
51
+ var s;
52
+ (function(r) {
53
+ r[r.MatMulReduceProgram = 0] = "MatMulReduceProgram", r[r.MatMulSplitKProgram = 1] = "MatMulSplitKProgram", r[r.MatMulSmallOutputSizeProgram = 2] = "MatMulSmallOutputSizeProgram", r[r.MatMulPackedProgram = 3] = "MatMulPackedProgram", r[r.MatMulMax = 4] = "MatMulMax";
54
+ })(s || (s = {}));
55
+ export {
56
+ g as G,
57
+ s as M,
58
+ p as a,
59
+ P as b,
60
+ d as c,
61
+ M as d,
62
+ h as e,
63
+ x as f,
64
+ b as i
65
+ };
@@ -0,0 +1,14 @@
1
+ import { E as m } from "./index-ZyQhjEPo.js";
2
+ import { c as n } from "./complex-CSlYz-2T.js";
3
+ import { d as i, f, s as c } from "./tensor-DdQUJZlz.js";
4
+ function e(o, r = "float32") {
5
+ if (i(o), r === "complex64") {
6
+ const a = e(o, "float32"), t = e(o, "float32");
7
+ return n(a, t);
8
+ }
9
+ const s = f(c(o), r);
10
+ return m.makeTensor(s, o, r);
11
+ }
12
+ export {
13
+ e as z
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -36,14 +36,15 @@
36
36
  "dayjs": "^1.11.13",
37
37
  "eslint": "^9.32.0",
38
38
  "glob": "^11.0.3",
39
- "jsdom": "^26.1.0",
39
+ "jsdom": "^27.4.0",
40
40
  "tsx": "^4.20.3",
41
41
  "typescript": "^5.8.3",
42
42
  "typescript-eslint": "^8.38.0",
43
- "vite": "^7.0.6",
43
+ "vite": "^7.3.0",
44
44
  "vite-plugin-dts": "^4.5.4",
45
45
  "vite-plugin-node-polyfills": "^0.24.0",
46
46
  "vitest": "^3.2.4",
47
+ "webgpu": "^0.3.8",
47
48
  "yargs": "^18.0.0"
48
49
  },
49
50
  "dependencies": {
@@ -1,127 +0,0 @@
1
- import { j as c, a5 as C, n as f, V as R } from "./index-BzFyqcy-.js";
2
- import { u as g, g as I, a as x, b as F, c as $, d as u, e as m, i as l } from "./gpgpu_math-CDaYiyE_.js";
3
- /**
4
- * @license
5
- * Copyright 2018 Google LLC. All Rights Reserved.
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- * =============================================================================
18
- */
19
- class S {
20
- constructor(t, i) {
21
- this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "inputShape", type: "ivec3" }], this.outputShape = t, this.enableShapeUniforms = g(this.outputShape.length);
22
- let a = "";
23
- for (let e = 0; e < 4; e++) {
24
- let o = "thisRC = rc;";
25
- e % 2 === 1 && (o += "thisRC.z += 1;"), e > 1 && (o += "thisRC.y += 1;"), a += `
26
- ${o}
27
- ${e > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : ""}
28
- int flatIndex = getFlatIndex(thisRC);
29
-
30
- ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
31
- vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));
32
-
33
- result[${e}] =
34
- getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
35
- ${e > 0 ? "}" : ""}
36
- `;
37
- }
38
- this.userCode = `
39
- ${v(i, this.enableShapeUniforms)}
40
- ${this.enableShapeUniforms ? I() : x(t)}
41
-
42
- void main() {
43
- ivec3 rc = getOutputCoords();
44
-
45
- vec4 result = vec4(0.);
46
-
47
- ivec3 thisRC;
48
- int rows = ${this.enableShapeUniforms ? "outShape[1]" : t[1]};
49
- int cols = ${this.enableShapeUniforms ? "outShape[2]" : t[2]};
50
-
51
- ${a}
52
-
53
- setOutput(result);
54
- }
55
- `;
56
- }
57
- }
58
- function v(s, t) {
59
- return `
60
- ivec3 inputCoordsFromReshapedOutCoords(int index) {
61
- ${t ? F(["r", "c", "d"], "inputShape") : $(["r", "c", "d"], s)}
62
- return ivec3(r, c, d);
63
- }
64
- `;
65
- }
66
- /**
67
- * @license
68
- * Copyright 2020 Google LLC. All Rights Reserved.
69
- * Licensed under the Apache License, Version 2.0 (the "License");
70
- * you may not use this file except in compliance with the License.
71
- * You may obtain a copy of the License at
72
- *
73
- * http://www.apache.org/licenses/LICENSE-2.0
74
- *
75
- * Unless required by applicable law or agreed to in writing, software
76
- * distributed under the License is distributed on an "AS IS" BASIS,
77
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78
- * See the License for the specific language governing permissions and
79
- * limitations under the License.
80
- * =============================================================================
81
- */
82
- function b(s, t, i) {
83
- const a = [
84
- u(s.shape),
85
- ...m(s.shape)
86
- ], e = {
87
- dtype: s.dtype,
88
- shape: a,
89
- dataId: s.dataId
90
- }, o = [
91
- u(t),
92
- ...m(t)
93
- ], r = new S(o, a), p = !0, n = [a], h = i.runWebGLProgram(r, [e], s.dtype, n, p);
94
- return { dataId: h.dataId, shape: t, dtype: h.dtype };
95
- }
96
- /**
97
- * @license
98
- * Copyright 2020 Google LLC. All Rights Reserved.
99
- * Licensed under the Apache License, Version 2.0 (the "License");
100
- * you may not use this file except in compliance with the License.
101
- * You may obtain a copy of the License at
102
- *
103
- * http://www.apache.org/licenses/LICENSE-2.0
104
- *
105
- * Unless required by applicable law or agreed to in writing, software
106
- * distributed under the License is distributed on an "AS IS" BASIS,
107
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
108
- * See the License for the specific language governing permissions and
109
- * limitations under the License.
110
- * =============================================================================
111
- */
112
- function y(s) {
113
- const { inputs: t, backend: i, attrs: a } = s, { x: e } = t, { shape: o } = a, r = i, p = c(e.shape), n = C(o, p), h = c(n);
114
- f(p === h, () => `The new shape (${n}) has ${h} elements and the old shape (${e.shape}) has ${p} elements. The new shape and old shape must have the same number of elements.`);
115
- const d = r.texData.get(e.dataId);
116
- return d.isPacked && !l(e.shape, n) && !(d.texture !== null && l(d.shape, n)) ? b(e, n, r) : (r.incRef(e.dataId), { dataId: e.dataId, shape: n, dtype: e.dtype });
117
- }
118
- const U = {
119
- kernelName: R,
120
- backendName: "webgl",
121
- kernelFunc: y
122
- };
123
- export {
124
- S as R,
125
- U as a,
126
- y as r
127
- };
@@ -1,30 +0,0 @@
1
- import { j as h, a5 as d, n as c, V as m } from "./index-BzFyqcy-.js";
2
- /**
3
- * @license
4
- * Copyright 2021 Google LLC. All Rights Reserved.
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- * =============================================================================
17
- */
18
- function i(n) {
19
- const { inputs: p, attrs: o } = n, { x: e } = p, { shape: r } = o, a = h(e.shape), s = d(r, a), t = h(s);
20
- return c(a === t, () => `The new shape (${s}) has ${t} elements and the old shape (${e.shape}) has ${a} elements. The new shape and old shape must have the same number of elements.`), n.backend.incRef(e.dataId), { dataId: e.dataId, shape: s, dtype: e.dtype };
21
- }
22
- const u = {
23
- kernelName: m,
24
- backendName: "webgpu",
25
- kernelFunc: i
26
- };
27
- export {
28
- u as a,
29
- i as r
30
- };