@genai-fi/nanogpt 0.19.0 → 0.20.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 (482) hide show
  1. package/package.json +9 -10
  2. package/dist/Generator.d.ts +0 -82
  3. package/dist/Generator.js +0 -11941
  4. package/dist/RealDiv-CGwv0liw.js +0 -365
  5. package/dist/Reshape-BW__R4mZ.js +0 -79
  6. package/dist/Reshape-CPBkTIH2.js +0 -14
  7. package/dist/TeachableLLM.d.ts +0 -70
  8. package/dist/TeachableLLM.js +0 -273
  9. package/dist/Trainer.d.ts +0 -43
  10. package/dist/Trainer.js +0 -244
  11. package/dist/_commonjsHelpers-ByX85dGu.js +0 -33
  12. package/dist/axis_util-GTVlo58H.js +0 -55
  13. package/dist/backend.d.ts +0 -2
  14. package/dist/backend.js +0 -13
  15. package/dist/backend_util-GaFarB78.js +0 -425
  16. package/dist/backend_webgpu-BqASlsbV.js +0 -545
  17. package/dist/binary_op_util-pKXltfxI.js +0 -192
  18. package/dist/broadcast_to-eS93CCN_.js +0 -28
  19. package/dist/checks/appendCache.d.ts +0 -1
  20. package/dist/checks/appendCache.js +0 -22
  21. package/dist/checks/attentionMask.d.ts +0 -1
  22. package/dist/checks/attentionMask.js +0 -37
  23. package/dist/checks/check.d.ts +0 -9
  24. package/dist/checks/check.js +0 -20
  25. package/dist/checks/gelu.d.ts +0 -1
  26. package/dist/checks/gelu.js +0 -18
  27. package/dist/checks/index.d.ts +0 -26
  28. package/dist/checks/index.js +0 -28
  29. package/dist/checks/matMulGelu.d.ts +0 -1
  30. package/dist/checks/matMulGelu.js +0 -28
  31. package/dist/checks/normRMS.d.ts +0 -1
  32. package/dist/checks/normRMS.js +0 -16
  33. package/dist/checks/normRMSGrad.d.ts +0 -1
  34. package/dist/checks/normRMSGrad.js +0 -12
  35. package/dist/checks/packUnpack.d.ts +0 -1
  36. package/dist/checks/packUnpack.js +0 -18
  37. package/dist/checks/qkv.d.ts +0 -1
  38. package/dist/checks/qkv.js +0 -34
  39. package/dist/checks/rope.d.ts +0 -1
  40. package/dist/checks/rope.js +0 -36
  41. package/dist/checks/weights.d.ts +0 -14
  42. package/dist/checks/weights.js +0 -31
  43. package/dist/clip_by_value-DDA7rrcT.js +0 -12
  44. package/dist/complex-DI35Q-gW.js +0 -11
  45. package/dist/complex_util-Yc1A_gV1.js +0 -55
  46. package/dist/concat-CAQpCret.js +0 -17
  47. package/dist/concat_util-D18dJ4fD.js +0 -22
  48. package/dist/data/docx.d.ts +0 -2
  49. package/dist/data/docx.js +0 -15
  50. package/dist/data/parquet.d.ts +0 -2
  51. package/dist/data/parquet.js +0 -17
  52. package/dist/data/pdf.d.ts +0 -2
  53. package/dist/data/pdf.js +0 -14
  54. package/dist/data/textLoader.d.ts +0 -7
  55. package/dist/data/textLoader.js +0 -108
  56. package/dist/dataset-CGGp1z9P.js +0 -1124
  57. package/dist/dropout_util--NxWuYg2.js +0 -27
  58. package/dist/expand_dims-Bkd1YD5x.js +0 -11
  59. package/dist/exports_initializers-CYzKLjN7.js +0 -7
  60. package/dist/floor-BQtb-Azg.js +0 -9
  61. package/dist/gather-qIqEqaGn.js +0 -9
  62. package/dist/gelu-B220X1Go.js +0 -26
  63. package/dist/gpgpu_math-BwvV12df.js +0 -2022
  64. package/dist/index-CUXkjxiT.js +0 -3516
  65. package/dist/index-CieiGp4Y.js +0 -349
  66. package/dist/index-CjOWnMXP.js +0 -7308
  67. package/dist/index-Cp39cXWe.js +0 -1016
  68. package/dist/index-D5v913EJ.js +0 -4
  69. package/dist/index-DmeWGGmS.js +0 -1074
  70. package/dist/index-DvYrXKkX.js +0 -113
  71. package/dist/index-Ksja3su6.js +0 -151
  72. package/dist/index-xuotMAFm.js +0 -118
  73. package/dist/inference/types.d.ts +0 -16
  74. package/dist/inference/types.js +0 -1
  75. package/dist/jszip.min-BZhlzntC.js +0 -2313
  76. package/dist/kernel_funcs_utils-pq0CK9co.js +0 -306
  77. package/dist/layers/BaseLayer.d.ts +0 -44
  78. package/dist/layers/BaseLayer.js +0 -74
  79. package/dist/layers/CausalSelfAttention.d.ts +0 -39
  80. package/dist/layers/CausalSelfAttention.js +0 -86
  81. package/dist/layers/LoRA.d.ts +0 -14
  82. package/dist/layers/LoRA.js +0 -58
  83. package/dist/layers/MLP.d.ts +0 -17
  84. package/dist/layers/MLP.js +0 -44
  85. package/dist/layers/PositionEmbedding.d.ts +0 -8
  86. package/dist/layers/PositionEmbedding.js +0 -31
  87. package/dist/layers/RMSNorm.d.ts +0 -12
  88. package/dist/layers/RMSNorm.js +0 -22
  89. package/dist/layers/RoPECache.d.ts +0 -18
  90. package/dist/layers/RoPECache.js +0 -50
  91. package/dist/layers/TiedEmbedding.d.ts +0 -13
  92. package/dist/layers/TiedEmbedding.js +0 -36
  93. package/dist/layers/TransformerBlock.d.ts +0 -27
  94. package/dist/layers/TransformerBlock.js +0 -40
  95. package/dist/layers/WeightStore.d.ts +0 -20
  96. package/dist/layers/WeightStore.js +0 -76
  97. package/dist/loader/load.d.ts +0 -6
  98. package/dist/loader/load.js +0 -68
  99. package/dist/loader/loadHF.d.ts +0 -8
  100. package/dist/loader/loadHF.js +0 -22
  101. package/dist/loader/loadTransformers.d.ts +0 -4
  102. package/dist/loader/loadTransformers.js +0 -44
  103. package/dist/loader/loadZipMeta.d.ts +0 -3
  104. package/dist/loader/loadZipMeta.js +0 -16
  105. package/dist/loader/newZipLoad.d.ts +0 -3
  106. package/dist/loader/newZipLoad.js +0 -31
  107. package/dist/loader/oldZipLoad.d.ts +0 -9
  108. package/dist/loader/oldZipLoad.js +0 -80
  109. package/dist/loader/save.d.ts +0 -16
  110. package/dist/loader/save.js +0 -90
  111. package/dist/loader/types.d.ts +0 -67
  112. package/dist/loader/types.js +0 -1
  113. package/dist/main.d.ts +0 -50
  114. package/dist/main.js +0 -109
  115. package/dist/matMul16-BcVC_E62.js +0 -80
  116. package/dist/matMulGelu-JNLZqKQp.js +0 -163
  117. package/dist/mat_mul-DhG0Newp.js +0 -11
  118. package/dist/mod-CSdCpRjf.js +0 -11
  119. package/dist/models/NanoGPTV1.d.ts +0 -16
  120. package/dist/models/NanoGPTV1.js +0 -99
  121. package/dist/models/NanoGPTV2.d.ts +0 -16
  122. package/dist/models/NanoGPTV2.js +0 -90
  123. package/dist/models/config.d.ts +0 -27
  124. package/dist/models/config.js +0 -50
  125. package/dist/models/factory.d.ts +0 -3
  126. package/dist/models/factory.js +0 -16
  127. package/dist/models/model.d.ts +0 -44
  128. package/dist/models/model.js +0 -134
  129. package/dist/non_max_suppression_impl-B2W7YjZB.js +0 -102
  130. package/dist/not_equal-hurPF26l.js +0 -64
  131. package/dist/ones-BytntneX.js +0 -14
  132. package/dist/ops/adamAdjust.d.ts +0 -2
  133. package/dist/ops/adamAdjust.js +0 -9
  134. package/dist/ops/adamMoments.d.ts +0 -2
  135. package/dist/ops/adamMoments.js +0 -9
  136. package/dist/ops/add16.d.ts +0 -2
  137. package/dist/ops/add16.js +0 -9
  138. package/dist/ops/appendCache.d.ts +0 -2
  139. package/dist/ops/appendCache.js +0 -22
  140. package/dist/ops/attentionMask.d.ts +0 -2
  141. package/dist/ops/attentionMask.js +0 -10
  142. package/dist/ops/concat16.d.ts +0 -2
  143. package/dist/ops/concat16.js +0 -9
  144. package/dist/ops/cpu/adamAdjust.d.ts +0 -1
  145. package/dist/ops/cpu/adamAdjust.js +0 -18
  146. package/dist/ops/cpu/adamMoments.d.ts +0 -1
  147. package/dist/ops/cpu/adamMoments.js +0 -16
  148. package/dist/ops/cpu/appendCache.d.ts +0 -1
  149. package/dist/ops/cpu/appendCache.js +0 -23
  150. package/dist/ops/cpu/attentionMask.d.ts +0 -1
  151. package/dist/ops/cpu/attentionMask.js +0 -22
  152. package/dist/ops/cpu/fusedSoftmax.d.ts +0 -9
  153. package/dist/ops/cpu/fusedSoftmax.js +0 -29
  154. package/dist/ops/cpu/gatherSub.d.ts +0 -1
  155. package/dist/ops/cpu/gatherSub.js +0 -18
  156. package/dist/ops/cpu/gelu.d.ts +0 -1
  157. package/dist/ops/cpu/gelu.js +0 -40
  158. package/dist/ops/cpu/matMul16.d.ts +0 -1
  159. package/dist/ops/cpu/matMul16.js +0 -15
  160. package/dist/ops/cpu/matMulGelu.d.ts +0 -1
  161. package/dist/ops/cpu/matMulGelu.js +0 -53
  162. package/dist/ops/cpu/matMulMul.d.ts +0 -1
  163. package/dist/ops/cpu/matMulMul.js +0 -23
  164. package/dist/ops/cpu/mulDropout.d.ts +0 -1
  165. package/dist/ops/cpu/mulDropout.js +0 -23
  166. package/dist/ops/cpu/normRMS.d.ts +0 -1
  167. package/dist/ops/cpu/normRMS.js +0 -39
  168. package/dist/ops/cpu/qkv.d.ts +0 -5
  169. package/dist/ops/cpu/qkv.js +0 -41
  170. package/dist/ops/cpu/rope.d.ts +0 -6
  171. package/dist/ops/cpu/rope.js +0 -38
  172. package/dist/ops/cpu/scatterSub.d.ts +0 -1
  173. package/dist/ops/cpu/scatterSub.js +0 -23
  174. package/dist/ops/dot16.d.ts +0 -2
  175. package/dist/ops/dot16.js +0 -42
  176. package/dist/ops/dropout.d.ts +0 -2
  177. package/dist/ops/dropout.js +0 -14
  178. package/dist/ops/dropout16.d.ts +0 -2
  179. package/dist/ops/dropout16.js +0 -25
  180. package/dist/ops/gatherSub.d.ts +0 -2
  181. package/dist/ops/gatherSub.js +0 -9
  182. package/dist/ops/gelu.d.ts +0 -3
  183. package/dist/ops/gelu.js +0 -8
  184. package/dist/ops/globalNorm.d.ts +0 -2
  185. package/dist/ops/globalNorm.js +0 -13
  186. package/dist/ops/grads/add16.d.ts +0 -1
  187. package/dist/ops/grads/add16.js +0 -26
  188. package/dist/ops/grads/attentionMask.d.ts +0 -1
  189. package/dist/ops/grads/attentionMask.js +0 -21
  190. package/dist/ops/grads/dropout16.d.ts +0 -1
  191. package/dist/ops/grads/dropout16.js +0 -2
  192. package/dist/ops/grads/gelu.d.ts +0 -2
  193. package/dist/ops/grads/gelu.js +0 -5
  194. package/dist/ops/grads/matMul16.d.ts +0 -2
  195. package/dist/ops/grads/matMul16.js +0 -9
  196. package/dist/ops/grads/matMulGelu.d.ts +0 -1
  197. package/dist/ops/grads/matMulGelu.js +0 -17
  198. package/dist/ops/grads/mul16.d.ts +0 -1
  199. package/dist/ops/grads/mul16.js +0 -4
  200. package/dist/ops/grads/normRMS.d.ts +0 -3
  201. package/dist/ops/grads/normRMS.js +0 -33
  202. package/dist/ops/grads/pack16.d.ts +0 -2
  203. package/dist/ops/grads/pack16.js +0 -6
  204. package/dist/ops/grads/qkv.d.ts +0 -3
  205. package/dist/ops/grads/qkv.js +0 -34
  206. package/dist/ops/grads/rope.d.ts +0 -2
  207. package/dist/ops/grads/rope.js +0 -5
  208. package/dist/ops/grads/softmax16.d.ts +0 -2
  209. package/dist/ops/grads/softmax16.js +0 -25
  210. package/dist/ops/grads/unpack16.d.ts +0 -2
  211. package/dist/ops/grads/unpack16.js +0 -5
  212. package/dist/ops/grads/utils.d.ts +0 -4
  213. package/dist/ops/grads/utils.js +0 -14
  214. package/dist/ops/log.d.ts +0 -0
  215. package/dist/ops/log.js +0 -1
  216. package/dist/ops/matMul16.d.ts +0 -15
  217. package/dist/ops/matMul16.js +0 -13
  218. package/dist/ops/matMulGelu.d.ts +0 -3
  219. package/dist/ops/matMulGelu.js +0 -14
  220. package/dist/ops/matMulMul.d.ts +0 -2
  221. package/dist/ops/matMulMul.js +0 -9
  222. package/dist/ops/mul16.d.ts +0 -2
  223. package/dist/ops/mul16.js +0 -39
  224. package/dist/ops/mulDrop.d.ts +0 -2
  225. package/dist/ops/mulDrop.js +0 -9
  226. package/dist/ops/normRMS.d.ts +0 -2
  227. package/dist/ops/normRMS.js +0 -19
  228. package/dist/ops/pack16.d.ts +0 -2
  229. package/dist/ops/pack16.js +0 -5
  230. package/dist/ops/qkv.d.ts +0 -2
  231. package/dist/ops/qkv.js +0 -10
  232. package/dist/ops/reshape16.d.ts +0 -2
  233. package/dist/ops/reshape16.js +0 -41
  234. package/dist/ops/rope.d.ts +0 -3
  235. package/dist/ops/rope.js +0 -7
  236. package/dist/ops/scatterSub.d.ts +0 -2
  237. package/dist/ops/scatterSub.js +0 -9
  238. package/dist/ops/slice16.d.ts +0 -2
  239. package/dist/ops/slice16.js +0 -9
  240. package/dist/ops/softmax16.d.ts +0 -2
  241. package/dist/ops/softmax16.js +0 -9
  242. package/dist/ops/sub16.d.ts +0 -2
  243. package/dist/ops/sub16.js +0 -8
  244. package/dist/ops/sum16.d.ts +0 -2
  245. package/dist/ops/sum16.js +0 -13
  246. package/dist/ops/transpose16.d.ts +0 -3
  247. package/dist/ops/transpose16.js +0 -40
  248. package/dist/ops/unpack16.d.ts +0 -2
  249. package/dist/ops/unpack16.js +0 -6
  250. package/dist/ops/webgl/adamAdjust.d.ts +0 -1
  251. package/dist/ops/webgl/adamAdjust.js +0 -49
  252. package/dist/ops/webgl/adamMoments.d.ts +0 -1
  253. package/dist/ops/webgl/adamMoments.js +0 -40
  254. package/dist/ops/webgl/appendCache.d.ts +0 -1
  255. package/dist/ops/webgl/appendCache.js +0 -44
  256. package/dist/ops/webgl/attentionMask.d.ts +0 -1
  257. package/dist/ops/webgl/attentionMask.js +0 -45
  258. package/dist/ops/webgl/dropout16.d.ts +0 -1
  259. package/dist/ops/webgl/dropout16.js +0 -11
  260. package/dist/ops/webgl/fusedSoftmax.d.ts +0 -11
  261. package/dist/ops/webgl/fusedSoftmax.js +0 -80
  262. package/dist/ops/webgl/gatherSub.d.ts +0 -1
  263. package/dist/ops/webgl/gatherSub.js +0 -27
  264. package/dist/ops/webgl/gelu.d.ts +0 -2
  265. package/dist/ops/webgl/gelu.js +0 -50
  266. package/dist/ops/webgl/log.d.ts +0 -17
  267. package/dist/ops/webgl/log.js +0 -23
  268. package/dist/ops/webgl/matMul16.d.ts +0 -1
  269. package/dist/ops/webgl/matMul16.js +0 -45
  270. package/dist/ops/webgl/matMulGelu.d.ts +0 -21
  271. package/dist/ops/webgl/matMulGelu.js +0 -9
  272. package/dist/ops/webgl/matMulMul.d.ts +0 -14
  273. package/dist/ops/webgl/matMulMul.js +0 -28
  274. package/dist/ops/webgl/mulDropout.d.ts +0 -1
  275. package/dist/ops/webgl/mulDropout.js +0 -41
  276. package/dist/ops/webgl/normRMS.d.ts +0 -1
  277. package/dist/ops/webgl/normRMS.js +0 -93
  278. package/dist/ops/webgl/qkv.d.ts +0 -1
  279. package/dist/ops/webgl/qkv.js +0 -46
  280. package/dist/ops/webgl/rope.d.ts +0 -1
  281. package/dist/ops/webgl/rope.js +0 -56
  282. package/dist/ops/webgl/scatterSub.d.ts +0 -1
  283. package/dist/ops/webgl/scatterSub.js +0 -27
  284. package/dist/ops/webgpu/adamAdjust.d.ts +0 -1
  285. package/dist/ops/webgpu/adamAdjust.js +0 -57
  286. package/dist/ops/webgpu/adamMoments.d.ts +0 -1
  287. package/dist/ops/webgpu/adamMoments.js +0 -60
  288. package/dist/ops/webgpu/add16.d.ts +0 -1
  289. package/dist/ops/webgpu/add16.js +0 -13
  290. package/dist/ops/webgpu/appendCache.d.ts +0 -1
  291. package/dist/ops/webgpu/appendCache.js +0 -105
  292. package/dist/ops/webgpu/attentionMask.d.ts +0 -1
  293. package/dist/ops/webgpu/attentionMask.js +0 -26
  294. package/dist/ops/webgpu/attentionMask32_program.d.ts +0 -19
  295. package/dist/ops/webgpu/attentionMask32_program.js +0 -54
  296. package/dist/ops/webgpu/clipScale.d.ts +0 -1
  297. package/dist/ops/webgpu/clipScale.js +0 -58
  298. package/dist/ops/webgpu/concat16.d.ts +0 -19
  299. package/dist/ops/webgpu/concat16.js +0 -126
  300. package/dist/ops/webgpu/dropout16.d.ts +0 -1
  301. package/dist/ops/webgpu/dropout16.js +0 -51
  302. package/dist/ops/webgpu/gatherSub.d.ts +0 -1
  303. package/dist/ops/webgpu/gatherSub.js +0 -39
  304. package/dist/ops/webgpu/gelu.d.ts +0 -14
  305. package/dist/ops/webgpu/gelu.js +0 -141
  306. package/dist/ops/webgpu/index.d.ts +0 -0
  307. package/dist/ops/webgpu/index.js +0 -26
  308. package/dist/ops/webgpu/matMul16.d.ts +0 -1
  309. package/dist/ops/webgpu/matMul16.js +0 -65
  310. package/dist/ops/webgpu/matMul16_program.d.ts +0 -42
  311. package/dist/ops/webgpu/matMul16_program.js +0 -343
  312. package/dist/ops/webgpu/mul16.d.ts +0 -1
  313. package/dist/ops/webgpu/mul16.js +0 -13
  314. package/dist/ops/webgpu/norm2.d.ts +0 -1
  315. package/dist/ops/webgpu/norm2.js +0 -76
  316. package/dist/ops/webgpu/normRMS.d.ts +0 -1
  317. package/dist/ops/webgpu/normRMS.js +0 -34
  318. package/dist/ops/webgpu/normRMS16_program.d.ts +0 -10
  319. package/dist/ops/webgpu/normRMS16_program.js +0 -25
  320. package/dist/ops/webgpu/normRMS32_program.d.ts +0 -10
  321. package/dist/ops/webgpu/normRMS32_program.js +0 -25
  322. package/dist/ops/webgpu/normRMSGrad.d.ts +0 -1
  323. package/dist/ops/webgpu/normRMSGrad.js +0 -284
  324. package/dist/ops/webgpu/pack16.d.ts +0 -1
  325. package/dist/ops/webgpu/pack16.js +0 -18
  326. package/dist/ops/webgpu/pack16_program.d.ts +0 -19
  327. package/dist/ops/webgpu/pack16_program.js +0 -92
  328. package/dist/ops/webgpu/qkv.d.ts +0 -1
  329. package/dist/ops/webgpu/qkv.js +0 -24
  330. package/dist/ops/webgpu/rope.d.ts +0 -1
  331. package/dist/ops/webgpu/rope.js +0 -135
  332. package/dist/ops/webgpu/scatterSub.d.ts +0 -1
  333. package/dist/ops/webgpu/scatterSub.js +0 -40
  334. package/dist/ops/webgpu/slice16.d.ts +0 -7
  335. package/dist/ops/webgpu/slice16.js +0 -69
  336. package/dist/ops/webgpu/softmax16.d.ts +0 -17
  337. package/dist/ops/webgpu/softmax16.js +0 -21
  338. package/dist/ops/webgpu/softmax16_program.d.ts +0 -13
  339. package/dist/ops/webgpu/softmax16_program.js +0 -73
  340. package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +0 -17
  341. package/dist/ops/webgpu/softmax16_subgroup_program.js +0 -75
  342. package/dist/ops/webgpu/softmax16grad.d.ts +0 -1
  343. package/dist/ops/webgpu/softmax16grad.js +0 -37
  344. package/dist/ops/webgpu/sub16.d.ts +0 -1
  345. package/dist/ops/webgpu/sub16.js +0 -13
  346. package/dist/ops/webgpu/sum16.d.ts +0 -1
  347. package/dist/ops/webgpu/sum16.js +0 -38
  348. package/dist/ops/webgpu/transpose16.d.ts +0 -1
  349. package/dist/ops/webgpu/transpose16.js +0 -34
  350. package/dist/ops/webgpu/transpose16_program.d.ts +0 -16
  351. package/dist/ops/webgpu/transpose16_program.js +0 -50
  352. package/dist/ops/webgpu/transpose16_shared_program.d.ts +0 -15
  353. package/dist/ops/webgpu/transpose16_shared_program.js +0 -70
  354. package/dist/ops/webgpu/unpack16.d.ts +0 -1
  355. package/dist/ops/webgpu/unpack16.js +0 -48
  356. package/dist/ops/webgpu/utils/binary_op.d.ts +0 -35
  357. package/dist/ops/webgpu/utils/binary_op.js +0 -139
  358. package/dist/ops/webgpu/utils/deviceInfo.d.ts +0 -7
  359. package/dist/ops/webgpu/utils/deviceInfo.js +0 -11
  360. package/dist/ops/webgpu/utils/reductions.d.ts +0 -43
  361. package/dist/ops/webgpu/utils/reductions.js +0 -275
  362. package/dist/ops-CsXeTq1P.js +0 -476
  363. package/dist/pack16-bqltoUlR.js +0 -39
  364. package/dist/papaparse.min-C0cScC2i.js +0 -418
  365. package/dist/parquet-Bqjmp2vo.js +0 -44231
  366. package/dist/patches/webgpu_backend.d.ts +0 -18
  367. package/dist/patches/webgpu_backend.js +0 -56
  368. package/dist/patches/webgpu_base.d.ts +0 -21
  369. package/dist/patches/webgpu_base.js +0 -34
  370. package/dist/patches/webgpu_program.d.ts +0 -36
  371. package/dist/patches/webgpu_program.js +0 -400
  372. package/dist/pdf-NIhmP3sq.js +0 -19477
  373. package/dist/rand_util-CZ7yLoUm.js +0 -50
  374. package/dist/random_normal-IBRrha8a.js +0 -14
  375. package/dist/random_width-DN5ZtQkM.js +0 -9796
  376. package/dist/range-C-CjF-LI.js +0 -10
  377. package/dist/relu-J_X6MUzx.js +0 -9
  378. package/dist/reshape-BDOuCSNW.js +0 -9
  379. package/dist/resize_nearest_neighbor-BojqlfRe.js +0 -150
  380. package/dist/rope-DcrZM_e6.js +0 -24
  381. package/dist/scatter_nd_util-ByNJaL6I.js +0 -46
  382. package/dist/segment_util-Dasb2Zaf.js +0 -43
  383. package/dist/selu_util-BLhIqRkw.js +0 -44
  384. package/dist/shared-3agzAqQ_.js +0 -53
  385. package/dist/shared-CagdqkLh.js +0 -2143
  386. package/dist/slice-BzS11Qh0.js +0 -12
  387. package/dist/slice_util-CC35pLmT.js +0 -153
  388. package/dist/softmax-D4q1LJN7.js +0 -12
  389. package/dist/split-C2Sj255c.js +0 -9
  390. package/dist/squeeze-ho4wLUek.js +0 -10
  391. package/dist/stack-DudVrtmG.js +0 -11
  392. package/dist/step-BTxPtq1r.js +0 -261
  393. package/dist/sum-BpiwSWvg.js +0 -11
  394. package/dist/tensor-BWFldCso.js +0 -8
  395. package/dist/tensor1d-LMGMIUlr.js +0 -11
  396. package/dist/tensor2d-BnXMKScO.js +0 -14
  397. package/dist/tensor4d-C6UCG_u8.js +0 -14
  398. package/dist/tfjs_backend-BGnG-ppu.js +0 -654
  399. package/dist/tile-CFy-xTO6.js +0 -11
  400. package/dist/tokeniser/BaseTokeniser.d.ts +0 -33
  401. package/dist/tokeniser/BaseTokeniser.js +0 -124
  402. package/dist/tokeniser/CharTokeniser.d.ts +0 -24
  403. package/dist/tokeniser/CharTokeniser.js +0 -107
  404. package/dist/tokeniser/bpe.d.ts +0 -28
  405. package/dist/tokeniser/bpe.js +0 -173
  406. package/dist/tokeniser/messages.d.ts +0 -61
  407. package/dist/tokeniser/messages.js +0 -1
  408. package/dist/tokeniser/type.d.ts +0 -34
  409. package/dist/tokeniser/type.js +0 -1
  410. package/dist/training/AdamW.d.ts +0 -36
  411. package/dist/training/AdamW.js +0 -138
  412. package/dist/training/BasicTrainer.d.ts +0 -63
  413. package/dist/training/BasicTrainer.js +0 -265
  414. package/dist/training/DatasetBuilder.d.ts +0 -26
  415. package/dist/training/DatasetBuilder.js +0 -86
  416. package/dist/training/Evaluator.d.ts +0 -19
  417. package/dist/training/Evaluator.js +0 -39
  418. package/dist/training/LRScheduler.d.ts +0 -12
  419. package/dist/training/LRScheduler.js +0 -34
  420. package/dist/training/PreTrainer.d.ts +0 -11
  421. package/dist/training/PreTrainer.js +0 -20
  422. package/dist/training/SFTTrainer.d.ts +0 -12
  423. package/dist/training/SFTTrainer.js +0 -22
  424. package/dist/training/loss.d.ts +0 -3
  425. package/dist/training/loss.js +0 -24
  426. package/dist/training/orthoGrad.d.ts +0 -2
  427. package/dist/training/orthoGrad.js +0 -10
  428. package/dist/training/sparseCrossEntropy.d.ts +0 -7
  429. package/dist/training/sparseCrossEntropy.js +0 -69
  430. package/dist/training/tasks/ConversationTask.d.ts +0 -18
  431. package/dist/training/tasks/ConversationTask.js +0 -40
  432. package/dist/training/tasks/PretrainingTask.d.ts +0 -17
  433. package/dist/training/tasks/PretrainingTask.js +0 -47
  434. package/dist/training/tasks/StartSentenceTask.d.ts +0 -18
  435. package/dist/training/tasks/StartSentenceTask.js +0 -49
  436. package/dist/training/tasks/Task.d.ts +0 -22
  437. package/dist/training/tasks/Task.js +0 -68
  438. package/dist/training/tasks/splitter.d.ts +0 -5
  439. package/dist/training/tasks/splitter.js +0 -21
  440. package/dist/training/types.d.ts +0 -78
  441. package/dist/training/types.js +0 -1
  442. package/dist/training/validation.d.ts +0 -17
  443. package/dist/training/validation.js +0 -84
  444. package/dist/transpose-9kRxIXWR.js +0 -36
  445. package/dist/unsorted_segment_sum-DJvk5xnh.js +0 -277
  446. package/dist/utilities/arrayClose.d.ts +0 -1
  447. package/dist/utilities/arrayClose.js +0 -20
  448. package/dist/utilities/datasetID.d.ts +0 -2
  449. package/dist/utilities/datasetID.js +0 -21
  450. package/dist/utilities/dummy.d.ts +0 -9
  451. package/dist/utilities/dummy.js +0 -43
  452. package/dist/utilities/multinomialCPU.d.ts +0 -2
  453. package/dist/utilities/multinomialCPU.js +0 -13
  454. package/dist/utilities/naming.d.ts +0 -4
  455. package/dist/utilities/naming.js +0 -1
  456. package/dist/utilities/packed.d.ts +0 -4
  457. package/dist/utilities/packed.js +0 -15
  458. package/dist/utilities/parameters.d.ts +0 -11
  459. package/dist/utilities/parameters.js +0 -57
  460. package/dist/utilities/performance.d.ts +0 -2
  461. package/dist/utilities/performance.js +0 -16
  462. package/dist/utilities/profile.d.ts +0 -17
  463. package/dist/utilities/profile.js +0 -38
  464. package/dist/utilities/safetensors.d.ts +0 -3
  465. package/dist/utilities/safetensors.js +0 -83
  466. package/dist/utilities/sentences.d.ts +0 -5
  467. package/dist/utilities/sentences.js +0 -41
  468. package/dist/utilities/tokenParse.d.ts +0 -1
  469. package/dist/utilities/tokenParse.js +0 -21
  470. package/dist/utilities/topP.d.ts +0 -1
  471. package/dist/utilities/topP.js +0 -13
  472. package/dist/utilities/waitForModel.d.ts +0 -2
  473. package/dist/utilities/waitForModel.js +0 -12
  474. package/dist/utilities/weights.d.ts +0 -12
  475. package/dist/utilities/weights.js +0 -45
  476. package/dist/utilities/yielder.d.ts +0 -1
  477. package/dist/utilities/yielder.js +0 -7
  478. package/dist/variable-Ck482e3n.js +0 -7
  479. package/dist/webgpu_program-B4HmApL1.js +0 -525
  480. package/dist/webgpu_util-DYlGSwOJ.js +0 -64
  481. package/dist/zeros-DvZpK8s6.js +0 -13
  482. package/dist/zeros_like-CWjDdwr-.js +0 -721
@@ -1,545 +0,0 @@
1
- import { ab as g, as as $, at as K, h as D, x as _, au as O, U as x, av as Z, a5 as W, aw as F, ax as j, ay as X, az as J, af as ee, a9 as k } from "./index-CUXkjxiT.js";
2
- import { m as te, f as se, P as re } from "./webgpu_program-B4HmApL1.js";
3
- import { i as ne, G as q } from "./webgpu_util-DYlGSwOJ.js";
4
- import { m as N } from "./complex_util-Yc1A_gV1.js";
5
- const d = g();
6
- d.registerFlag("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE", () => 15);
7
- d.registerFlag("WEBGPU_CPU_FORWARD", () => !0);
8
- d.registerFlag("WEBGPU_MATMUL_PROGRAM_TYPE", () => -1);
9
- d.registerFlag("WEBGPU_USE_NAIVE_CONV2D_TRANSPOSE", () => !0);
10
- d.registerFlag("WEBGPU_USE_LOW_POWER_GPU", () => !1);
11
- d.registerFlag("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD", () => 1e3);
12
- d.registerFlag("WEBGPU_USE_PROFILE_TOOL", () => !1);
13
- d.registerFlag("WEBGPU_IMPORT_EXTERNAL_TEXTURE", () => !0);
14
- d.registerFlag("WEBGPU_USE_NAIVE_CONV2D_DEBUG", () => !1);
15
- d.registerFlag("WEBGPU_THRESHOLD_TO_INCREASE_WORKGROUPS_FOR_MATMUL", () => -1);
16
- d.registerFlag("WEBGPU_CONV_SEPARATE_IM2COL_SHADER", () => !1);
17
- d.registerFlag("WEBGPU_PRINT_SHADER", () => "");
18
- d.registerFlag("WEBGPU_ENGINE_COMPILE_ONLY", () => !1);
19
- class ae {
20
- constructor(e) {
21
- e && (this.vendor = e.vendor, this.architecture = e.architecture, this.intelGPUGeneration = this.getIntelGPUGeneration());
22
- }
23
- getIntelGPUGeneration() {
24
- if (this.isIntel()) {
25
- if (this.architecture.startsWith("gen"))
26
- return Number(this.architecture.match(/\d+/));
27
- if (this.architecture.startsWith("xe"))
28
- return 12;
29
- }
30
- return 0;
31
- }
32
- isIntel() {
33
- return this.vendor === "intel";
34
- }
35
- }
36
- class ie {
37
- constructor(e) {
38
- this.device = e, this.numUsedBuffers = 0, this.numFreeBuffers = 0, this.freeBuffers = /* @__PURE__ */ new Map(), this.usedBuffers = /* @__PURE__ */ new Map(), this.numBytesUsed = 0, this.numBytesAllocated = 0;
39
- }
40
- acquireBuffer(e, t, s = !1, n = !0) {
41
- let r;
42
- const a = z(e, t);
43
- return n ? (this.freeBuffers.has(a) || this.freeBuffers.set(a, []), this.freeBuffers.get(a).length > 0 ? (r = this.freeBuffers.get(a).pop(), this.numFreeBuffers--) : (r = this.device.createBuffer({ size: e, usage: t, mappedAtCreation: s }), this.numBytesAllocated += e)) : (r = this.device.createBuffer({ size: e, usage: t, mappedAtCreation: s }), this.numBytesAllocated += e), this.usedBuffers.has(a) || this.usedBuffers.set(a, []), this.usedBuffers.get(a).push(r), this.numUsedBuffers++, this.numBytesUsed += e, r;
44
- }
45
- releaseBuffer(e, t = !0) {
46
- if (this.freeBuffers.size === 0)
47
- return;
48
- const s = e.size, n = e.usage, r = z(s, n), a = this.usedBuffers.get(r), i = a.indexOf(e);
49
- if (i < 0)
50
- throw new Error("Cannot find the buffer in buffer manager");
51
- a[i] = a[a.length - 1], a.pop(), this.numUsedBuffers--, this.numBytesUsed -= s, t ? (this.freeBuffers.get(r).push(e), this.numFreeBuffers++) : (e.destroy(), this.numBytesAllocated -= s);
52
- }
53
- getNumUsedBuffers() {
54
- return this.numUsedBuffers;
55
- }
56
- getNumFreeBuffers() {
57
- return this.numFreeBuffers;
58
- }
59
- dispose() {
60
- this.freeBuffers.forEach((e, t) => {
61
- e.forEach((s) => {
62
- s.destroy();
63
- });
64
- }), this.usedBuffers.forEach((e, t) => {
65
- e.forEach((s) => {
66
- s.destroy();
67
- });
68
- }), this.freeBuffers = /* @__PURE__ */ new Map(), this.usedBuffers = /* @__PURE__ */ new Map(), this.numUsedBuffers = 0, this.numFreeBuffers = 0, this.numBytesUsed = 0, this.numBytesAllocated = 0;
69
- }
70
- }
71
- function z(l, e) {
72
- return `${l}_${e}`;
73
- }
74
- class oe {
75
- constructor(e) {
76
- this.device = e, this.numUsedTextures = 0, this.numFreeTextures = 0, this.freeTextures = /* @__PURE__ */ new Map(), this.usedTextures = /* @__PURE__ */ new Map(), this.numBytesUsed = 0, this.numBytesAllocated = 0;
77
- }
78
- acquireTexture(e, t, s, n) {
79
- const r = Q(s), a = e * t * r, i = L(e, t, s, n);
80
- if (this.freeTextures.has(i) || this.freeTextures.set(i, []), this.usedTextures.has(i) || this.usedTextures.set(i, []), this.numBytesUsed += a, this.numUsedTextures++, this.freeTextures.get(i).length > 0) {
81
- this.numFreeTextures--;
82
- const o = this.freeTextures.get(i).shift();
83
- return this.usedTextures.get(i).push(o), o;
84
- }
85
- this.numBytesAllocated += a;
86
- const u = this.device.createTexture({
87
- size: [e, t],
88
- format: s,
89
- usage: n
90
- });
91
- return this.usedTextures.get(i).push(u), u;
92
- }
93
- releaseTexture(e) {
94
- if (this.freeTextures.size === 0)
95
- return;
96
- const t = e.width, s = e.height, n = e.format, r = e.usage, a = L(t, s, n, r);
97
- this.freeTextures.has(a) || this.freeTextures.set(a, []), this.freeTextures.get(a).push(e), this.numFreeTextures++, this.numUsedTextures--;
98
- const i = this.usedTextures.get(a), u = i.indexOf(e);
99
- if (u < 0)
100
- throw new Error("Cannot release a texture that was never provided by this texture manager");
101
- i.splice(u, 1);
102
- const o = Q(n), f = t * s * o;
103
- this.numBytesUsed -= f;
104
- }
105
- getNumUsedTextures() {
106
- return this.numUsedTextures;
107
- }
108
- getNumFreeTextures() {
109
- return this.numFreeTextures;
110
- }
111
- dispose() {
112
- this.freeTextures.forEach((e, t) => {
113
- e.forEach((s) => {
114
- s.destroy();
115
- });
116
- }), this.usedTextures.forEach((e, t) => {
117
- e.forEach((s) => {
118
- s.destroy();
119
- });
120
- }), this.freeTextures = /* @__PURE__ */ new Map(), this.usedTextures = /* @__PURE__ */ new Map(), this.numUsedTextures = 0, this.numFreeTextures = 0, this.numBytesUsed = 0, this.numBytesAllocated = 0;
121
- }
122
- }
123
- function L(l, e, t, s) {
124
- return `${l}_${e}_${t}_${s}`;
125
- }
126
- function Q(l) {
127
- if (l === "rgba8unorm")
128
- return 16;
129
- throw new Error(`${l} is not supported!`);
130
- }
131
- const ue = g().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"), fe = (l, e) => {
132
- const t = l.limits.maxComputeWorkgroupsPerDimension, s = e.dispatchLayout, n = e.dispatch;
133
- if (n.every((a) => a <= t))
134
- return n;
135
- _(n[0] > t && s.y === void 0 && s.z === void 0, () => "Dispatch size exceeds WebGPU limits in Y or Z dimension.");
136
- let r = Math.ceil(Math.sqrt(n[0]));
137
- return r > t ? (r = Math.ceil(Math.cbrt(n[0])), _(r <= t, () => "Total dispatch size exceeds WebGPU maximum."), [r, r, r]) : [r, r, 1];
138
- };
139
- class R extends $ {
140
- nextDataId() {
141
- return R.nextDataId++;
142
- }
143
- constructor(e, t) {
144
- if (super(), this.commandQueueOwnedIds = /* @__PURE__ */ new WeakSet(), this.dispatchCountInPass = 0, this.disposed = !1, this.downloadWaitMs = 0, this.tensorDataPendingDisposal = [], this.queryResolveBuffer = null, this.querySet = null, this.querySetCount = 2, this.stagingPendingDisposal = [], this.uniformPendingDisposal = [], this.uploadWaitMs = 0, this.hasReadSyncWarned = !1, this.hasTimestampQueryWarned = !1, !ne())
145
- throw new Error("WebGPU is not supported on this device");
146
- this.pipelineCache = {}, this.device = e, this.queue = e.queue, this.commandEncoder = null, this.computePassEncoder = null, this.adapterInfo = new ae(t), this.supportTimestampQuery = this.device.features.has("timestamp-query"), this.thresholdToIncreaseWorkgroups = this.adapterInfo.intelGPUGeneration >= 12 ? 16 : 8, this.bufferManager = new ie(this.device), this.textureManager = new oe(this.device), this.tensorMap = new K(this, D()), g().getBool("WEBGPU_USE_PROFILE_TOOL") && (this.dummyCanvas = document.createElement("canvas"), this.dummyCanvas.width = 1, this.dummyCanvas.height = 1, this.dummyContext = this.dummyCanvas.getContext("webgpu"), this.dummyContext.configure({
147
- device: e,
148
- format: "bgra8unorm"
149
- }), document.body.appendChild(this.dummyCanvas));
150
- }
151
- floatPrecision() {
152
- return 32;
153
- }
154
- /**
155
- * Dispose the memory if the dataId has 0 refCount. Return true if the memory
156
- * is released or delayed in this backend, false if there are still
157
- * references.
158
- * @param dataId
159
- * @oaram force Optional, remove the data regardless of refCount
160
- */
161
- disposeData(e, t = !1) {
162
- if (!this.tensorMap.has(e))
163
- return !0;
164
- const s = this.tensorMap.get(e);
165
- return t ? s.refCount = 0 : s.refCount--, s.refCount > 0 ? !1 : (s.complexTensorInfos != null && (this.disposeData(s.complexTensorInfos.real.dataId), this.disposeData(s.complexTensorInfos.imag.dataId)), this.commandQueueOwnedIds.has(e) ? (this.tensorDataPendingDisposal.push(e), !0) : (this.releaseResource(e), this.tensorMap.delete(e), !0));
166
- }
167
- memory() {
168
- return {
169
- numBytesInGPU: this.bufferManager.numBytesUsed,
170
- numBytesAllocatedInGPU: this.bufferManager.numBytesAllocated,
171
- unreliable: !1
172
- };
173
- }
174
- releaseResource(e) {
175
- const t = this.tensorMap.get(e);
176
- if (!(!t || !t.resource)) {
177
- if (t.external) {
178
- t.resource = null;
179
- return;
180
- }
181
- t.resource instanceof GPUBuffer ? this.bufferManager.releaseBuffer(t.resource) : t.resource instanceof GPUTexture && this.textureManager.releaseTexture(t.resource), t.resource = null;
182
- }
183
- }
184
- /** Return refCount of a `TensorData`. */
185
- refCount(e) {
186
- return this.tensorMap.has(e) ? this.tensorMap.get(e).refCount : 0;
187
- }
188
- /** Increase refCount of a `TensorData`. */
189
- incRef(e) {
190
- const t = this.tensorMap.get(e);
191
- t.refCount++;
192
- }
193
- /** Decrease refCount of a `TensorData`. */
194
- decRef(e) {
195
- if (this.tensorMap.has(e)) {
196
- const t = this.tensorMap.get(e);
197
- t.refCount--;
198
- }
199
- }
200
- write(e, t, s) {
201
- if (s === "complex64" && e != null)
202
- throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
203
- const n = { id: this.nextDataId() };
204
- return this.tensorMap.set(n, { dtype: s, shape: t, values: e, refCount: 1 }), n;
205
- }
206
- move(e, t, s, n, r) {
207
- if (n === "complex64")
208
- throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
209
- this.tensorMap.set(e, { dtype: n, shape: s, values: t, refCount: r });
210
- }
211
- submitQueue() {
212
- this.queue.submit([this.commandEncoder.finish()]), this.commandEncoder = null, this.dispatchCountInPass = 0, this.commandQueueOwnedIds = /* @__PURE__ */ new WeakSet(), this.tensorDataPendingDisposal.forEach((e) => {
213
- this.releaseResource(e), this.tensorMap.delete(e);
214
- }), this.uniformPendingDisposal.forEach((e) => this.bufferManager.releaseBuffer(e)), this.stagingPendingDisposal.forEach((e) => this.bufferManager.releaseBuffer(e, !1)), this.tensorDataPendingDisposal = [], this.uniformPendingDisposal = [], this.stagingPendingDisposal = [];
215
- }
216
- ensureCommandEncoderReady() {
217
- this.commandEncoder || (this.commandEncoder = this.device.createCommandEncoder());
218
- }
219
- endComputePassEncoder() {
220
- this.computePassEncoder && (this.computePassEncoder.end(), this.computePassEncoder = null);
221
- }
222
- // Check if parallel compilation is done.
223
- async checkCompileCompletionAsync() {
224
- let e;
225
- try {
226
- e = await Promise.all(Object.values(this.pipelineCache));
227
- } catch (t) {
228
- throw new Error(t.message);
229
- }
230
- Object.keys(this.pipelineCache).map((t, s) => {
231
- this.pipelineCache[t] = e[s];
232
- });
233
- }
234
- async getBufferData(e) {
235
- if (g().getBool("WEBGPU_ENGINE_COMPILE_ONLY"))
236
- return console.warn("The data may be invalid since WEBGPU_ENGINE_COMPILE_ONLY is true, this can only be called when WEBGPU_ENGINE_COMPILE_ONLY is false"), null;
237
- const t = e.size, s = this.bufferManager.acquireBuffer(t, GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ);
238
- this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(e, 0, s, 0, t), this.submitQueue(), await s.mapAsync(GPUMapMode.READ);
239
- const n = s.getMappedRange().slice(0);
240
- return s.unmap(), s != null && this.bufferManager.releaseBuffer(s), g().getBool("WEBGPU_USE_PROFILE_TOOL") && (_(this.dummyContext !== void 0, () => "Fail to get context for profiling tool"), this.dummyContext.getCurrentTexture()), n;
241
- }
242
- convertAndCacheOnCPU(e, t) {
243
- const s = this.tensorMap.get(e);
244
- return s.values = t, s.values;
245
- }
246
- readSync(e) {
247
- const t = this.tensorMap.get(e), { values: s, complexTensorInfos: n } = t;
248
- if (s != null || t.dtype === "string")
249
- return s;
250
- if (t.dtype === "complex64") {
251
- const E = this.readSync(n.real.dataId), B = this.readSync(n.imag.dataId), y = O(N(E, B).buffer, "float32");
252
- return this.convertAndCacheOnCPU(e, y), y;
253
- }
254
- this.hasReadSyncWarned || (this.hasReadSyncWarned = !0, console.warn("The performance of synchronously reading data from GPU to CPU is poor on the webgpu backend, please use asynchronous APIs instead."));
255
- const r = ["opaque", "premultiplied"], a = t.resource, i = a.size;
256
- _(i % 4 === 0, () => "Because there is 4 bytes for one pixel, buffer size must be multiple of 4.");
257
- const u = i / 4, o = new ArrayBuffer(i), f = 256, c = 256, h = r.map((E) => new OffscreenCanvas(f, c)), m = new OffscreenCanvas(f, c);
258
- this.endComputePassEncoder(), h.map((E, B) => {
259
- const y = E.getContext("webgpu");
260
- return y.configure({
261
- device: this.device,
262
- format: "bgra8unorm",
263
- usage: GPUTextureUsage.COPY_DST,
264
- alphaMode: r[B]
265
- }), y.getCurrentTexture();
266
- }).map((E, B) => {
267
- const y = f * 4, G = (P, S, v) => {
268
- this.ensureCommandEncoderReady(), this.commandEncoder.copyBufferToTexture({
269
- buffer: a,
270
- bytesPerRow: y,
271
- offset: v
272
- }, {
273
- texture: E
274
- }, {
275
- width: P,
276
- height: S
277
- }), this.submitQueue();
278
- const I = m.getContext("2d", {
279
- willReadFrequently: !0
280
- });
281
- I.clearRect(0, 0, P, S), I.drawImage(h[B], 0, 0);
282
- const b = I.getImageData(0, 0, P, S).data, H = r[B], M = new Uint8ClampedArray(o, v, P * S * 4);
283
- for (let p = 0; p < M.length; p += 4)
284
- if (H === "premultiplied")
285
- M[p + 3] = b[p + 3];
286
- else {
287
- const V = b[p];
288
- M[p] = b[p + 2], M[p + 1] = b[p + 1], M[p + 2] = V;
289
- }
290
- }, Y = Math.floor(u / (f * c));
291
- let T = f, U = c, C = 0;
292
- for (let P = 0; P < Y; P++)
293
- G(T, U, C), C += f * c * 4;
294
- const A = u % (f * c);
295
- U = Math.floor(A / f), U > 0 && (G(T, U, C), C += U * (f * 4)), T = A % f, T > 0 && G(T, 1, C);
296
- });
297
- const w = O(o, t.dtype);
298
- return this.convertAndCacheOnCPU(e, w), w;
299
- }
300
- async read(e) {
301
- if (!this.tensorMap.has(e))
302
- throw new Error(`Tensor ${e} was not registered!`);
303
- const t = this.tensorMap.get(e), { values: s } = t;
304
- if (s != null)
305
- return s;
306
- let n;
307
- if (t.dtype === "complex64") {
308
- const r = await Promise.all([
309
- this.read(t.complexTensorInfos.real.dataId),
310
- this.read(t.complexTensorInfos.imag.dataId)
311
- ]), a = r[0], i = r[1];
312
- n = N(a, i);
313
- } else {
314
- const r = await this.getBufferData(t.resource);
315
- n = O(r, t.dtype);
316
- }
317
- return this.convertAndCacheOnCPU(e, n), n;
318
- }
319
- // The source GPUBuffer and destination GPUBuffer have the same size and
320
- // usage.
321
- copyBuffer(e) {
322
- const t = e.size, s = e.usage, n = this.bufferManager.acquireBuffer(t, s);
323
- return this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(e, 0, n, 0, t), this.submitQueue(), n;
324
- }
325
- /**
326
- * Create a TF.js tensor out of an existing WebGPU buffer.
327
- */
328
- createTensorFromGPUData(e, t, s) {
329
- let n = e.buffer;
330
- if (s === "complex64")
331
- throw new Error("Cannot write to a complex64 dtype. ");
332
- const r = { id: this.nextDataId() };
333
- this.tensorMap.set(r, {
334
- dtype: s,
335
- shape: t,
336
- values: null,
337
- refCount: 1,
338
- external: e.zeroCopy
339
- });
340
- const a = this.tensorMap.get(r), i = q(a.dtype) * x(a.shape);
341
- if (e.buffer.size < i)
342
- throw new Error(`GPUBuffer size(${e.buffer.size}) is smaller than tensor size(${i})!`);
343
- if ((e.buffer.usage & (GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC)) !== (GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC))
344
- throw new Error("GPUBuffer.usage should include GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC!");
345
- return e.zeroCopy !== !0 && (n = this.copyBuffer(n)), a.resource = n, D().makeTensorFromDataId(r, t, s, this);
346
- }
347
- /**
348
- * Read tensor to a new GPUBuffer.
349
- * @param dataId The source tensor.
350
- */
351
- readToGPU(e) {
352
- const t = this.tensorMap.get(e), { values: s, dtype: n, shape: r, resource: a } = t;
353
- if (n === "complex64")
354
- throw new Error("Does not support reading buffer for complex64 dtype.");
355
- if (a == null)
356
- throw s != null ? new Error("Data is not on GPU but on CPU.") : new Error("There is no data on GPU or CPU.");
357
- const i = a, u = i.size, o = i.usage, f = this.bufferManager.acquireBuffer(u, o);
358
- this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(a, 0, f, 0, u), this.submitQueue();
359
- const c = this.makeTensorInfo(r, n), h = D().makeTensorFromTensorInfo(c), m = this.tensorMap.get(c.dataId);
360
- return m.resource = f, { tensorRef: h, buffer: f };
361
- }
362
- bufferSync(e) {
363
- const t = this.readSync(e.dataId);
364
- if (e.dtype === "string")
365
- try {
366
- const s = t.map((n) => Z(n));
367
- return W(e.shape, e.dtype, s);
368
- } catch {
369
- throw new Error("Failed to decode encoded string bytes into utf-8");
370
- }
371
- return W(e.shape, e.dtype, t);
372
- }
373
- async time(e) {
374
- !this.supportTimestampQuery && !this.hasTimestampQueryWarned && (console.warn("This device doesn't support timestamp-query extension. Start Chrome browser with flag --enable-dawn-features=allow_unsafe_apis to try it again. Otherwise, zero will be shown for the kernel time when profiling mode is enabled."), this.hasTimestampQueryWarned = !0);
375
- const t = this.activeTimers, s = [];
376
- let n = !1;
377
- this.programTimersStack == null ? (this.programTimersStack = s, n = !0) : this.activeTimers.push(s), this.activeTimers = s, e();
378
- const r = F(this.activeTimers.map((o) => o.query)).filter((o) => o != null), a = F(this.activeTimers.map((o) => o.name)).filter((o) => o != null);
379
- this.activeTimers = t, n && (this.programTimersStack = null);
380
- const i = {
381
- uploadWaitMs: this.uploadWaitMs,
382
- downloadWaitMs: this.downloadWaitMs,
383
- kernelMs: null,
384
- wallMs: null
385
- }, u = await Promise.all(r);
386
- return i.kernelMs = j(u), i.getExtraProfileInfo = () => u.map((o, f) => ({ name: a[f], ms: o })).map((o) => `${o.name}: ${o.ms}`).join(", "), this.uploadWaitMs = 0, this.downloadWaitMs = 0, i;
387
- }
388
- makeTensorInfo(e, t, s) {
389
- return t === "string" && s != null && s.length > 0 && X(s[0]) && (s = s.map((r) => J(r))), { dataId: this.write(s, e, t), shape: e, dtype: t };
390
- }
391
- tensorToBinding(e) {
392
- if (!e)
393
- return null;
394
- const s = this.tensorMap.get(e.dataId).resource;
395
- return s instanceof GPUBuffer ? { buffer: s } : s instanceof GPUTexture ? s.createView() : s;
396
- }
397
- uploadToGPU(e) {
398
- const t = this.tensorMap.get(e);
399
- if (t.resource != null)
400
- return;
401
- const s = q(t.dtype) * x(t.shape);
402
- let n;
403
- const r = GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST;
404
- if (t.values) {
405
- if (n = this.bufferManager.acquireBuffer(s, r, !0), n.mapState === "unmapped") {
406
- const a = this.bufferManager.acquireBuffer(s, GPUBufferUsage.MAP_WRITE | GPUBufferUsage.COPY_SRC, !0, !1), i = a.getMappedRange();
407
- t.dtype === "int32" || t.dtype === "packedF16" || t.dtype === "bool" ? new Int32Array(i).set(t.values) : new Float32Array(i).set(t.values), a.unmap(), this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(a, 0, n, 0, s), this.stagingPendingDisposal.push(a);
408
- } else {
409
- const a = n.getMappedRange();
410
- t.dtype === "int32" || t.dtype === "packedF16" || t.dtype === "bool" ? new Int32Array(a).set(t.values) : new Float32Array(a).set(t.values), n.unmap();
411
- }
412
- t.values = null;
413
- } else
414
- n = this.bufferManager.acquireBuffer(s, r);
415
- t.resource = n;
416
- }
417
- makeUniforms(e) {
418
- let t = 0, s = 0;
419
- const n = [];
420
- let r = 1;
421
- e.forEach((u) => {
422
- u.data.length === 0 && (u.data = [1]);
423
- let o;
424
- switch (u.data.length) {
425
- case 1:
426
- o = 4;
427
- break;
428
- case 2:
429
- o = 8;
430
- break;
431
- case 3:
432
- o = 16;
433
- break;
434
- case 4:
435
- o = 16;
436
- break;
437
- case 5:
438
- o = 16;
439
- break;
440
- case 6:
441
- o = 16;
442
- break;
443
- default:
444
- _(!1, () => `Unsupported ${u.data.length}D shape`);
445
- }
446
- (s === 5 || s === 6) && (o = 16), o > r && (r = o), t = Math.ceil(t / o) * o, s = u.data.length, n.push(t), t += u.data.length * 4;
447
- }), t = Math.ceil(t / r) * r;
448
- const a = new ArrayBuffer(t);
449
- e.forEach((u, o) => {
450
- const f = n[o];
451
- u.type === "int32" ? new Int32Array(a, f, u.data.length).set(u.data) : u.type === "uint32" ? new Uint32Array(a, f, u.data.length).set(u.data) : new Float32Array(a, f, u.data.length).set(u.data);
452
- });
453
- const i = this.bufferManager.acquireBuffer(t, GPUBufferUsage.COPY_DST | GPUBufferUsage.UNIFORM);
454
- return this.queue.writeBuffer(i, 0, a, 0, t), this.uniformPendingDisposal.push(i), { offset: 0, size: t, buffer: i };
455
- }
456
- runWebGPUProgram(e, t, s, n, r) {
457
- if (r || (r = this.makeTensorInfo(e.outputShape, s)), x(r.shape) === 0)
458
- return this.tensorMap.get(r.dataId).values = ee(r.dtype, 0), r;
459
- this.uploadToGPU(r.dataId), e.dispatch = fe(this.device, e);
460
- const a = t.map((u, o) => {
461
- if (u.dtype === "complex64")
462
- throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");
463
- return this.uploadToGPU(u.dataId), {
464
- // Returning dtype from tensorMap because it reflects dtype
465
- // of underlying buffer, rather than abstract dtype.
466
- dtype: this.tensorMap.get(u.dataId).dtype,
467
- shape: u.shape,
468
- name: e.variableNames[o]
469
- };
470
- });
471
- e.shaderKey = te(e, a, r);
472
- const i = g().getBool("WEBGPU_ENGINE_COMPILE_ONLY");
473
- return e.shaderKey in this.pipelineCache || (this.pipelineCache[e.shaderKey] = se(this.device, e, a, r, i)), e.pipeline = this.pipelineCache[e.shaderKey], i || this.recordAndSubmit(e, r, t, n), r;
474
- }
475
- recordAndSubmit(e, t, s, n) {
476
- if (e.pipeline instanceof Promise)
477
- throw new Error("Please call checkCompileCompletionAsync to ensure parallel compilation is done!");
478
- let r = [], a = [];
479
- const i = "int32";
480
- if (e.pixelsOpType == null) {
481
- r.push({ type: "float32", data: [NaN] }, { type: "float32", data: [1 / 0] }), a = s.concat(t).map((m) => m.shape);
482
- const h = "int32";
483
- a.map((m) => {
484
- r.push({ type: h, data: m });
485
- const w = k(m);
486
- r.push({ type: h, data: w });
487
- });
488
- } else {
489
- const h = k(t.shape);
490
- r.push({ type: i, data: h });
491
- }
492
- if (e.size) {
493
- const h = x(e.outputShape);
494
- r.push({
495
- type: i,
496
- data: [e.outputComponent ? h / e.outputComponent : h]
497
- });
498
- }
499
- n && (r = [...r, ...n]);
500
- const u = [
501
- this.tensorToBinding(t),
502
- ...s.map((h) => this.tensorToBinding(h)),
503
- this.makeUniforms(r)
504
- ];
505
- s.forEach((h) => {
506
- this.commandQueueOwnedIds.add(h.dataId);
507
- }), this.commandQueueOwnedIds.add(t.dataId);
508
- const o = this.device.createBindGroup({
509
- layout: e.pipeline.getBindGroupLayout(0),
510
- entries: u.map((h, m) => ({ binding: m, resource: h }))
511
- }), f = this.activeTimers != null;
512
- this.ensureCommandEncoderReady();
513
- const c = {};
514
- f && this.supportTimestampQuery ? (this.endComputePassEncoder(), this.querySet == null && (this.querySet = this.device.createQuerySet({
515
- type: "timestamp",
516
- count: this.querySetCount
517
- })), c.timestampWrites = {
518
- querySet: this.querySet,
519
- beginningOfPassWriteIndex: 0,
520
- endOfPassWriteIndex: 1
521
- }, this.computePassEncoder = this.commandEncoder.beginComputePass(c)) : this.computePassEncoder || (this.computePassEncoder = this.commandEncoder.beginComputePass(c)), this.computePassEncoder.setPipeline(e.pipeline), this.computePassEncoder.setBindGroup(0, o), this.computePassEncoder.dispatchWorkgroups(e.dispatch[0], e.dispatch[1], e.dispatch[2]), this.dispatchCountInPass++, (f || g().get("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE") <= this.dispatchCountInPass || e.pixelsOpType === re.DRAW) && (this.endComputePassEncoder(), f ? this.activeTimers.push({ name: e.constructor.name, query: this.getQueryTime() }) : this.submitQueue());
522
- }
523
- async getQueryTime() {
524
- if (!this.supportTimestampQuery)
525
- return 0;
526
- this.queryResolveBuffer == null && (this.queryResolveBuffer = this.bufferManager.acquireBuffer(this.querySetCount * 8, GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST | GPUBufferUsage.QUERY_RESOLVE)), this.commandEncoder.resolveQuerySet(this.querySet, 0, this.querySetCount, this.queryResolveBuffer, 0);
527
- const e = this.bufferManager.acquireBuffer(this.querySetCount * 8, GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST);
528
- this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer, 0, e, 0, this.querySetCount * 8), this.submitQueue(), await e.mapAsync(GPUMapMode.READ);
529
- const t = new BigUint64Array(e.getMappedRange()), s = Number(t[1] - t[0]) / 1e6;
530
- return e.unmap(), this.bufferManager.releaseBuffer(e), s;
531
- }
532
- shouldExecuteOnCPU(e, t = ue) {
533
- return g().getBool("WEBGPU_CPU_FORWARD") && e.every((s) => this.tensorMap.get(s.dataId).resource == null && x(s.shape) < t);
534
- }
535
- numDataIds() {
536
- return this.tensorMap.numDataIds() - this.tensorDataPendingDisposal.length;
537
- }
538
- dispose() {
539
- this.disposed || (this.querySet != null && this.querySet.destroy(), this.bufferManager.dispose(), this.textureManager.dispose(), this.disposed = !0);
540
- }
541
- }
542
- R.nextDataId = 0;
543
- export {
544
- R as W
545
- };