@genai-fi/nanogpt 1.6.0 → 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.
- package/dist/{binary_op_util-WY9YIl0q.js → Reshape-CqftURg0.js} +75 -60
- package/dist/TeachableLLM.d.ts +12 -12
- package/dist/api/beamer.d.ts +4 -4
- package/dist/api/responses.d.ts +4 -4
- package/dist/api/training.d.ts +9 -9
- package/dist/backend.d.ts +1 -1
- package/dist/backend_util-DZIc6pyV.js +1081 -0
- package/dist/checks/index.d.ts +11 -11
- package/dist/checks/weights.d.ts +1 -1
- package/dist/data/docx.d.ts +1 -1
- package/dist/data/pdf.d.ts +1 -1
- package/dist/data/stream.d.ts +1 -1
- package/dist/data/textLoader.d.ts +1 -1
- package/dist/data.d.ts +3 -3
- package/dist/device-CZPGtQBU.js +9 -0
- package/dist/device.d.ts +2 -0
- package/dist/{dist-DeVH1nGn.js → dist-DiszGjH-.js} +1833 -1844
- package/dist/{dist-CMMLi-qO.js → dist-JOPw9zTN.js} +69 -11
- package/dist/inference/Beamer.d.ts +3 -3
- package/dist/inference/Generator.d.ts +4 -4
- package/dist/inference/tokenisePrompt.d.ts +2 -2
- package/dist/inference/types.d.ts +1 -1
- package/dist/inference/utilities.d.ts +1 -1
- package/dist/layers/BaseLayer.d.ts +5 -4
- package/dist/layers/GQA.d.ts +24 -26
- package/dist/layers/HeadLayer.d.ts +2 -2
- package/dist/layers/LoRA.d.ts +1 -1
- package/dist/layers/MHA.d.ts +3 -4
- package/dist/layers/MLP.d.ts +2 -2
- package/dist/layers/PositionEmbedding.d.ts +3 -3
- package/dist/layers/RMSNorm.d.ts +2 -2
- package/dist/layers/RoPECache.d.ts +2 -1
- package/dist/layers/TiedEmbedding.d.ts +2 -2
- package/dist/layers/TransformerBlock.d.ts +9 -6
- package/dist/layers.d.ts +4 -4
- package/dist/loader/load.d.ts +1 -1
- package/dist/loader/loadHF.d.ts +3 -3
- package/dist/loader/loadTransformers.d.ts +2 -2
- package/dist/loader/loadZipMeta.d.ts +2 -2
- package/dist/loader/newZipLoad.d.ts +2 -2
- package/dist/loader/oldZipLoad.d.ts +4 -4
- package/dist/loader/save.d.ts +5 -5
- package/dist/loader/types.d.ts +23 -10
- package/dist/main.d.ts +40 -24
- package/dist/matMul16-CiMKJM8v.js +2610 -0
- package/dist/models/Llama.d.ts +2 -2
- package/dist/models/LoopNano.d.ts +16 -0
- package/dist/models/NanoGPTV1.d.ts +2 -2
- package/dist/models/NanoGPTV2.d.ts +2 -2
- package/dist/models/Qwen3.d.ts +2 -2
- package/dist/models/config.d.ts +11 -1
- package/dist/models/factory.d.ts +2 -2
- package/dist/models/model.d.ts +6 -6
- package/dist/models.d.ts +4 -4
- package/dist/nanogpt.js +37041 -0
- package/dist/ops/adamAdjust.d.ts +2 -0
- package/dist/ops/adamMoments.d.ts +2 -0
- package/dist/ops/adamW.d.ts +2 -0
- package/dist/ops/add16.d.ts +1 -0
- package/dist/ops/appendCache.d.ts +2 -0
- package/dist/ops/attentionMask.d.ts +11 -1
- package/dist/ops/dropout16.d.ts +2 -0
- package/dist/ops/gatherSub.d.ts +2 -0
- package/dist/ops/gelu.d.ts +3 -0
- package/dist/ops/log.d.ts +1 -0
- package/dist/ops/matMul16.d.ts +4 -0
- package/dist/ops/matMulGelu.d.ts +3 -0
- package/dist/ops/matMulMul.d.ts +2 -0
- package/dist/ops/mul16.d.ts +1 -0
- package/dist/ops/mulDrop.d.ts +2 -0
- package/dist/ops/normRMS.d.ts +3 -0
- package/dist/ops/pack16.d.ts +1 -0
- package/dist/ops/qkv.d.ts +13 -1
- package/dist/ops/rope.d.ts +4 -1
- package/dist/ops/scatterSub.d.ts +4 -1
- package/dist/ops/silu.d.ts +1 -0
- package/dist/ops/softmax16.d.ts +1 -0
- package/dist/ops/sparseCrossEntropy.d.ts +15 -0
- package/dist/ops/unpack16.d.ts +1 -0
- package/dist/ops/webgl/sparseCrossEntropy.d.ts +1 -0
- package/dist/ops/webgpu/adamW.d.ts +1 -0
- package/dist/ops/webgpu/concat16.d.ts +16 -0
- package/dist/ops/webgpu/index.d.ts +29 -0
- package/dist/ops/webgpu/normRMS16_program.d.ts +2 -2
- package/dist/ops/webgpu/normRMS32_program.d.ts +2 -2
- package/dist/ops/webgpu/pack16_program.d.ts +1 -1
- package/dist/ops/webgpu/softmax16_program.d.ts +16 -0
- package/dist/ops/webgpu/sparseCrossEntropy.d.ts +1 -0
- package/dist/ops/webgpu/utils/binary_op.d.ts +16 -0
- package/dist/ops/webgpu/utils/deviceInfo.d.ts +1 -1
- package/dist/ops/webgpu/utils/reductions.d.ts +1 -1
- package/dist/patches/webgpu_backend.d.ts +2 -1
- package/dist/patches/webgpu_base.d.ts +0 -1
- package/dist/patches/webgpu_program.d.ts +21 -0
- package/dist/{shared-BIDMUBCs.js → shared-BARkvvG4.js} +587 -505
- package/dist/tokenise.d.ts +4 -4
- package/dist/tokeniser/BaseTokeniser.d.ts +3 -3
- package/dist/tokeniser/CharTokeniser.d.ts +2 -2
- package/dist/tokeniser/bpe.d.ts +2 -2
- package/dist/tokeniser/type.d.ts +2 -2
- package/dist/training/AdamW.d.ts +19 -2
- package/dist/training/BasicTrainer.d.ts +5 -5
- package/dist/training/DatasetBuilder.d.ts +2 -2
- package/dist/training/Evaluator.d.ts +1 -1
- package/dist/training/LRScheduler.d.ts +1 -1
- package/dist/training/PreTrainer.d.ts +6 -6
- package/dist/training/SFTTrainer.d.ts +6 -6
- package/dist/training/configure.d.ts +2 -2
- package/dist/training/factory.d.ts +6 -5
- package/dist/training/prepareData.d.ts +6 -6
- package/dist/training/tasks/tokenStream.d.ts +3 -3
- package/dist/training/types.d.ts +6 -5
- package/dist/training/validateOptions.d.ts +1 -1
- package/dist/training/validation.d.ts +3 -3
- package/dist/utilities/datasetID.d.ts +1 -1
- package/dist/utilities/dummy.d.ts +1 -1
- package/dist/utilities/packed.d.ts +1 -1
- package/dist/utilities/parameters.d.ts +1 -1
- package/dist/utilities/sentences.d.ts +1 -1
- package/dist/utilities/waitForModel.d.ts +1 -1
- package/dist/webgpu-D4syGmzo.js +3221 -0
- package/dist/webgpu-wUCQopBN.js +1007 -0
- package/dist/{webgpu_program-DvkFqRlR.js → webgpu_backend-CzY9TzvA.js} +174 -223
- package/dist/{patches/webgpu_base.js → webgpu_base-Bjg7okYf.js} +6 -9
- package/package.json +12 -9
- package/dist/DatasetBuilder-DRDW8tcM.js +0 -731
- package/dist/Generator-BcR_14Cj.js +0 -316
- package/dist/RealDiv-Cl8k3YTx.js +0 -354
- package/dist/Reshape-CKxKPKqi.js +0 -91
- package/dist/Reshape-H5zZRgr9.js +0 -16
- package/dist/RoPECache-dYscFINl.js +0 -722
- package/dist/TeachableLLM.js +0 -220
- package/dist/api/beamer.js +0 -61
- package/dist/api/responses.js +0 -177
- package/dist/api/training.js +0 -215
- package/dist/axis_util-rF9RnwKE.js +0 -37
- package/dist/backend.js +0 -12
- package/dist/backend_util-Cpp0Gwlp.js +0 -394
- package/dist/broadcast_to-CGvLNiQ0.js +0 -20
- package/dist/checks/appendCache.js +0 -55
- package/dist/checks/attentionMask.js +0 -57
- package/dist/checks/check.js +0 -31
- package/dist/checks/gelu.js +0 -46
- package/dist/checks/index.js +0 -27
- package/dist/checks/matMulGelu.js +0 -84
- package/dist/checks/normRMS.js +0 -30
- package/dist/checks/normRMSGrad.js +0 -23
- package/dist/checks/packUnpack.js +0 -46
- package/dist/checks/qkv.js +0 -1
- package/dist/checks/rope.js +0 -30
- package/dist/checks/weights.js +0 -26
- package/dist/clip_by_value-D-UX9am5.js +0 -13
- package/dist/complex-Cl904TqN.js +0 -13
- package/dist/complex_util-BBlPAm-s.js +0 -59
- package/dist/concat-Oip5acVY.js +0 -14
- package/dist/concat_util-CY45Hf4F.js +0 -18
- package/dist/data/docx.js +0 -17
- package/dist/data/pdf.js +0 -14
- package/dist/data/stream.js +0 -1
- package/dist/data/textLoader.js +0 -575
- package/dist/data-CV_i_H6B.js +0 -11
- package/dist/data.js +0 -5
- package/dist/dist-DyL7qSLJ.js +0 -7809
- package/dist/dropout16-CA31Ud5a.js +0 -20
- package/dist/dropout_util-SiFMbFXz.js +0 -22
- package/dist/eventemitter3-wmfmOP_f.js +0 -90
- package/dist/expand_dims-Dh3Fulyn.js +0 -10
- package/dist/floor-BwjmUb7X.js +0 -8
- package/dist/gather-B5Z1RFt5.js +0 -14
- package/dist/gatherSub-CRUfUzBa.js +0 -22
- package/dist/gelu-Xx9-ohH9.js +0 -25
- package/dist/gpgpu_math-48m8q3jI.js +0 -1591
- package/dist/inference/Beamer.js +0 -215
- package/dist/inference/Generator.js +0 -1
- package/dist/inference/tokenisePrompt.js +0 -17
- package/dist/inference/types.js +0 -0
- package/dist/inference/utilities.js +0 -31
- package/dist/jszip.min-Btv48m44.js +0 -3037
- package/dist/kernel_funcs_utils-BYRpSfV_.js +0 -229
- package/dist/layers/BaseLayer.js +0 -75
- package/dist/layers/GQA.js +0 -102
- package/dist/layers/HeadLayer.js +0 -28
- package/dist/layers/LoRA.js +0 -45
- package/dist/layers/MHA.js +0 -102
- package/dist/layers/MLP.js +0 -47
- package/dist/layers/PositionEmbedding.js +0 -28
- package/dist/layers/RMSNorm.js +0 -25
- package/dist/layers/RoPECache.js +0 -1
- package/dist/layers/TiedEmbedding.js +0 -33
- package/dist/layers/TransformerBlock.js +0 -50
- package/dist/layers/WeightStore.js +0 -68
- package/dist/layers-CFqEip3s.js +0 -13
- package/dist/layers.js +0 -6
- package/dist/loader/load.js +0 -63
- package/dist/loader/loadHF.js +0 -17
- package/dist/loader/loadTransformers.js +0 -61
- package/dist/loader/loadZipMeta.js +0 -15
- package/dist/loader/newZipLoad.js +0 -24
- package/dist/loader/oldZipLoad.js +0 -36
- package/dist/loader/save.js +0 -89
- package/dist/loader/types.js +0 -0
- package/dist/main.js +0 -12145
- package/dist/matMul16-tE26fnhf.js +0 -87
- package/dist/matMulGelu-ASUWlKqu.js +0 -162
- package/dist/mat_mul-R9_DWmIT.js +0 -16
- package/dist/models/Llama.js +0 -88
- package/dist/models/NanoGPTV1.js +0 -94
- package/dist/models/NanoGPTV2.js +0 -85
- package/dist/models/Qwen3.js +0 -88
- package/dist/models/config.js +0 -32
- package/dist/models/factory.js +0 -16
- package/dist/models/model.js +0 -75
- package/dist/models-DyBpJJwM.js +0 -13
- package/dist/models.js +0 -6
- package/dist/mul16-C7sqgqik.js +0 -41
- package/dist/non_max_suppression_impl-B0H318rb.js +0 -72
- package/dist/not_equal-Bu3O8rh_.js +0 -67
- package/dist/one_hot-TEMPumJj.js +0 -14
- package/dist/ones-DpPXWa6A.js +0 -13
- package/dist/ops/adamAdjust.js +0 -17
- package/dist/ops/adamMoments.js +0 -15
- package/dist/ops/add16.js +0 -11
- package/dist/ops/appendCache.js +0 -26
- package/dist/ops/attentionMask.js +0 -19
- package/dist/ops/concat16.js +0 -8
- package/dist/ops/cpu/adamAdjust.js +0 -15
- package/dist/ops/cpu/adamMoments.js +0 -16
- package/dist/ops/cpu/appendCache.js +0 -65
- package/dist/ops/cpu/attentionMask.js +0 -20
- package/dist/ops/cpu/fusedSoftmax.js +0 -22
- package/dist/ops/cpu/gatherSub.js +0 -1
- package/dist/ops/cpu/gelu.js +0 -35
- package/dist/ops/cpu/matMul16.js +0 -14
- package/dist/ops/cpu/matMulGelu.js +0 -44
- package/dist/ops/cpu/matMulMul.js +0 -19
- package/dist/ops/cpu/mulDropout.js +0 -19
- package/dist/ops/cpu/normRMS.js +0 -34
- package/dist/ops/cpu/qkv.js +0 -74
- package/dist/ops/cpu/rope.js +0 -84
- package/dist/ops/cpu/scatterSub.js +0 -1
- package/dist/ops/dot16.js +0 -28
- package/dist/ops/dropout.js +0 -12
- package/dist/ops/dropout16.js +0 -1
- package/dist/ops/gatherSub.js +0 -12
- package/dist/ops/gelu.js +0 -1
- package/dist/ops/globalNorm.js +0 -19
- package/dist/ops/grads/add16.js +0 -26
- package/dist/ops/grads/attentionMask.js +0 -25
- package/dist/ops/grads/dropout16.js +0 -1
- package/dist/ops/grads/gelu.js +0 -1
- package/dist/ops/grads/matMul16.js +0 -1
- package/dist/ops/grads/matMulGelu.js +0 -21
- package/dist/ops/grads/mul16.js +0 -1
- package/dist/ops/grads/normRMS.js +0 -36
- package/dist/ops/grads/pack16.js +0 -1
- package/dist/ops/grads/qkv.js +0 -46
- package/dist/ops/grads/rope.js +0 -1
- package/dist/ops/grads/silu.js +0 -1
- package/dist/ops/grads/softmax16.js +0 -22
- package/dist/ops/grads/unpack16.js +0 -1
- package/dist/ops/grads/utils.js +0 -11
- package/dist/ops/log.js +0 -1
- package/dist/ops/matMul16.js +0 -1
- package/dist/ops/matMulGelu.js +0 -19
- package/dist/ops/matMulMul.js +0 -15
- package/dist/ops/mul16.js +0 -1
- package/dist/ops/mulDrop.js +0 -14
- package/dist/ops/normRMS.js +0 -21
- package/dist/ops/pack16.js +0 -1
- package/dist/ops/qkv.js +0 -15
- package/dist/ops/reshape16.js +0 -33
- package/dist/ops/rope.js +0 -1
- package/dist/ops/scatterSub.js +0 -12
- package/dist/ops/silu.js +0 -1
- package/dist/ops/slice16.js +0 -11
- package/dist/ops/softmax16.js +0 -8
- package/dist/ops/sub16.js +0 -10
- package/dist/ops/sum16.js +0 -13
- package/dist/ops/transpose16.js +0 -33
- package/dist/ops/unpack16.js +0 -1
- package/dist/ops/webgl/adamAdjust.js +0 -81
- package/dist/ops/webgl/adamMoments.js +0 -43
- package/dist/ops/webgl/appendCache.js +0 -52
- package/dist/ops/webgl/attentionMask.js +0 -63
- package/dist/ops/webgl/dropout16.js +0 -11
- package/dist/ops/webgl/fusedSoftmax.js +0 -70
- package/dist/ops/webgl/gatherSub.js +0 -27
- package/dist/ops/webgl/gelu.js +0 -47
- package/dist/ops/webgl/log.js +0 -14
- package/dist/ops/webgl/matMul16.js +0 -48
- package/dist/ops/webgl/matMulGelu.js +0 -1
- package/dist/ops/webgl/matMulMul.js +0 -23
- package/dist/ops/webgl/mulDropout.js +0 -31
- package/dist/ops/webgl/normRMS.js +0 -115
- package/dist/ops/webgl/qkv.js +0 -53
- package/dist/ops/webgl/rope.js +0 -73
- package/dist/ops/webgl/scatterSub.js +0 -27
- package/dist/ops/webgpu/adamAdjust.js +0 -76
- package/dist/ops/webgpu/adamMoments.js +0 -75
- package/dist/ops/webgpu/add16.js +0 -13
- package/dist/ops/webgpu/appendCache.js +0 -129
- package/dist/ops/webgpu/attentionMask.js +0 -41
- package/dist/ops/webgpu/attentionMask32_program.js +0 -61
- package/dist/ops/webgpu/clipScale.js +0 -44
- package/dist/ops/webgpu/concat16.js +0 -110
- package/dist/ops/webgpu/dropout16.js +0 -58
- package/dist/ops/webgpu/gatherSub.js +0 -51
- package/dist/ops/webgpu/gelu.js +0 -146
- package/dist/ops/webgpu/index.js +0 -27
- package/dist/ops/webgpu/matMul16.js +0 -91
- package/dist/ops/webgpu/matMul16_program.js +0 -311
- package/dist/ops/webgpu/mul16.js +0 -13
- package/dist/ops/webgpu/norm2.js +0 -45
- package/dist/ops/webgpu/normRMS.js +0 -25
- package/dist/ops/webgpu/normRMS16_program.js +0 -28
- package/dist/ops/webgpu/normRMS32_program.js +0 -28
- package/dist/ops/webgpu/normRMSGrad.js +0 -225
- package/dist/ops/webgpu/pack16.js +0 -20
- package/dist/ops/webgpu/pack16_program.js +0 -92
- package/dist/ops/webgpu/qkv.js +0 -63
- package/dist/ops/webgpu/rope.js +0 -227
- package/dist/ops/webgpu/scatterSub.js +0 -52
- package/dist/ops/webgpu/silu.js +0 -117
- package/dist/ops/webgpu/slice16.js +0 -73
- package/dist/ops/webgpu/softmax16.js +0 -18
- package/dist/ops/webgpu/softmax16_program.js +0 -88
- package/dist/ops/webgpu/softmax16_subgroup_program.js +0 -69
- package/dist/ops/webgpu/softmax16grad.js +0 -30
- package/dist/ops/webgpu/sub16.js +0 -13
- package/dist/ops/webgpu/sum16.js +0 -30
- package/dist/ops/webgpu/transpose16.js +0 -38
- package/dist/ops/webgpu/transpose16_program.js +0 -50
- package/dist/ops/webgpu/transpose16_shared_program.js +0 -78
- package/dist/ops/webgpu/unpack16.js +0 -59
- package/dist/ops/webgpu/utils/binary_op.js +0 -140
- package/dist/ops/webgpu/utils/deviceInfo.js +0 -10
- package/dist/ops/webgpu/utils/reductions.js +0 -264
- package/dist/ops-Be5ACU5R.js +0 -13
- package/dist/ops-C1UpdEYM.js +0 -509
- package/dist/pack16-BHO4t1-M.js +0 -36
- package/dist/pad-Dy-1IP3A.js +0 -13
- package/dist/patches/webgpu_backend.js +0 -42
- package/dist/patches/webgpu_program.js +0 -292
- package/dist/picomatch--TW6gyBJ.js +0 -999
- package/dist/qkv-BQfNPucX.js +0 -42
- package/dist/rand_util-_vCY93Uw.js +0 -44
- package/dist/random_normal-DUIT8kyC.js +0 -11
- package/dist/range-CYvQC3fW.js +0 -13
- package/dist/relu-C4XULT8A.js +0 -8
- package/dist/reshape-DJb1jgMt.js +0 -8
- package/dist/resize_nearest_neighbor-DAqcTYUe.js +0 -188
- package/dist/rope-JjBVufF_.js +0 -24
- package/dist/scatterSub-BOnqk-uY.js +0 -27
- package/dist/scatter_nd_util-BepMCpLY.js +0 -34
- package/dist/seedrandom-SHEGFK6H.js +0 -282
- package/dist/selu_util-DeOTf-sc.js +0 -27
- package/dist/shared-CX_iPI5K.js +0 -4
- package/dist/silu-DsAE2cJ5.js +0 -23
- package/dist/slice-Dlb1FlzG.js +0 -13
- package/dist/slice_util-BVgPRoij.js +0 -207
- package/dist/softmax-Dpav_dWw.js +0 -10
- package/dist/split-DYnT8chz.js +0 -11
- package/dist/squeeze-B3XYGAlg.js +0 -9
- package/dist/stack-Dbbt9mIk.js +0 -10
- package/dist/step-DA-5DNu9.js +0 -348
- package/dist/stream-BBe2apn4.js +0 -2280
- package/dist/sum-C8qNbFNp.js +0 -13
- package/dist/tensor-ALxWZfmz.js +0 -7
- package/dist/tensor1d-BHgkkhTE.js +0 -9
- package/dist/tensor2d-ARItvqVn.js +0 -10
- package/dist/tensor4d-D1zRBipJ.js +0 -10
- package/dist/tfjs_backend-CsXOum0h.js +0 -685
- package/dist/tile-DfyQ0KX-.js +0 -10
- package/dist/tokenise-DbS2Ea-T.js +0 -14
- package/dist/tokenise.js +0 -6
- package/dist/tokeniser/BaseTokeniser.js +0 -137
- package/dist/tokeniser/CharTokeniser.js +0 -85
- package/dist/tokeniser/bpe.js +0 -156
- package/dist/tokeniser/messages.js +0 -0
- package/dist/tokeniser/type.js +0 -0
- package/dist/topk-BrU2pkrR.js +0 -19
- package/dist/training/AdamW.js +0 -132
- package/dist/training/BasicTrainer.js +0 -274
- package/dist/training/DatasetBuilder.js +0 -1
- package/dist/training/Evaluator.js +0 -51
- package/dist/training/LRScheduler.js +0 -37
- package/dist/training/PreTrainer.js +0 -21
- package/dist/training/SFTTrainer.js +0 -23
- package/dist/training/configure.js +0 -33
- package/dist/training/factory.js +0 -7
- package/dist/training/loss.js +0 -18
- package/dist/training/orthoGrad.js +0 -9
- package/dist/training/prepareData.js +0 -51
- package/dist/training/sparseCrossEntropy.js +0 -53
- package/dist/training/tasks/TokenStore.js +0 -217
- package/dist/training/tasks/tokenStream.js +0 -45
- package/dist/training/types.js +0 -0
- package/dist/training/validateOptions.js +0 -18
- package/dist/training/validation.js +0 -30
- package/dist/transpose-BC-M_OoT.js +0 -34
- package/dist/unsorted_segment_sum-BelC7R-q.js +0 -408
- package/dist/utilities/arrayClose.js +0 -29
- package/dist/utilities/arrayShape.js +0 -7
- package/dist/utilities/datasetID.js +0 -17
- package/dist/utilities/dummy.js +0 -36
- package/dist/utilities/float16.js +0 -46
- package/dist/utilities/maxHeap.js +0 -54
- package/dist/utilities/multinomialCPU.js +0 -7
- package/dist/utilities/naming.js +0 -0
- package/dist/utilities/packed.js +0 -12
- package/dist/utilities/parameters.js +0 -53
- package/dist/utilities/performance.js +0 -15
- package/dist/utilities/profile.js +0 -32
- package/dist/utilities/random.js +0 -18
- package/dist/utilities/safetensors.js +0 -63
- package/dist/utilities/sentences.js +0 -35
- package/dist/utilities/tokenParse.js +0 -16
- package/dist/utilities/tokens.js +0 -39
- package/dist/utilities/topP.js +0 -25
- package/dist/utilities/waitForModel.js +0 -11
- package/dist/utilities/weights.js +0 -40
- package/dist/utilities/yielder.js +0 -6
- package/dist/v4-YCkfo8OR.js +0 -27
- package/dist/webgpu-BHX-uBym.js +0 -518
- package/dist/webgpu_util-5QTyovaf.js +0 -105
- package/dist/zeros-hxKGkRfl.js +0 -12
package/dist/webgpu-BHX-uBym.js
DELETED
|
@@ -1,518 +0,0 @@
|
|
|
1
|
-
import { l as e, t } from "./webgpu_util-5QTyovaf.js";
|
|
2
|
-
import { s as n } from "./complex_util-BBlPAm-s.js";
|
|
3
|
-
import { $i as r, Ei as i, H as a, Ii as o, Oi as s, P as c, Ti as l, Xi as u, _i as d, ea as f, gt as p, ht as m, mt as h, qi as g, yi as _ } from "./dist-CMMLi-qO.js";
|
|
4
|
-
import { l as v, n as y, t as b } from "./webgpu_program-DvkFqRlR.js";
|
|
5
|
-
// node_modules/@tensorflow/tfjs-backend-webgpu/dist/flags_webgpu.js
|
|
6
|
-
var x = d();
|
|
7
|
-
x.registerFlag("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE", () => 15), x.registerFlag("WEBGPU_CPU_FORWARD", () => !0), x.registerFlag("WEBGPU_MATMUL_PROGRAM_TYPE", () => -1), x.registerFlag("WEBGPU_USE_NAIVE_CONV2D_TRANSPOSE", () => !0), x.registerFlag("WEBGPU_USE_LOW_POWER_GPU", () => !1), x.registerFlag("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD", () => 1e3), x.registerFlag("WEBGPU_USE_PROFILE_TOOL", () => !1), x.registerFlag("WEBGPU_IMPORT_EXTERNAL_TEXTURE", () => !0), x.registerFlag("WEBGPU_USE_NAIVE_CONV2D_DEBUG", () => !1), x.registerFlag("WEBGPU_THRESHOLD_TO_INCREASE_WORKGROUPS_FOR_MATMUL", () => -1), x.registerFlag("WEBGPU_CONV_SEPARATE_IM2COL_SHADER", () => !1), x.registerFlag("WEBGPU_PRINT_SHADER", () => ""), x.registerFlag("WEBGPU_ENGINE_COMPILE_ONLY", () => !1);
|
|
8
|
-
// node_modules/@tensorflow/tfjs-backend-webgpu/dist/adapter_info.js
|
|
9
|
-
var S = class {
|
|
10
|
-
constructor(e) {
|
|
11
|
-
e && (this.vendor = e.vendor, this.architecture = e.architecture, this.intelGPUGeneration = this.getIntelGPUGeneration());
|
|
12
|
-
}
|
|
13
|
-
getIntelGPUGeneration() {
|
|
14
|
-
if (this.isIntel()) {
|
|
15
|
-
if (this.architecture.startsWith("gen")) return Number(this.architecture.match(/\d+/));
|
|
16
|
-
if (this.architecture.startsWith("xe")) return 12;
|
|
17
|
-
}
|
|
18
|
-
return 0;
|
|
19
|
-
}
|
|
20
|
-
isIntel() {
|
|
21
|
-
return this.vendor === "intel";
|
|
22
|
-
}
|
|
23
|
-
}, C = class {
|
|
24
|
-
constructor(e) {
|
|
25
|
-
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;
|
|
26
|
-
}
|
|
27
|
-
acquireBuffer(e, t, n = !1, r = !0) {
|
|
28
|
-
let i, a = w(e, t);
|
|
29
|
-
return r ? (this.freeBuffers.has(a) || this.freeBuffers.set(a, []), this.freeBuffers.get(a).length > 0 ? (i = this.freeBuffers.get(a).pop(), this.numFreeBuffers--) : (i = this.device.createBuffer({
|
|
30
|
-
size: e,
|
|
31
|
-
usage: t,
|
|
32
|
-
mappedAtCreation: n
|
|
33
|
-
}), this.numBytesAllocated += e)) : (i = this.device.createBuffer({
|
|
34
|
-
size: e,
|
|
35
|
-
usage: t,
|
|
36
|
-
mappedAtCreation: n
|
|
37
|
-
}), this.numBytesAllocated += e), this.usedBuffers.has(a) || this.usedBuffers.set(a, []), this.usedBuffers.get(a).push(i), this.numUsedBuffers++, this.numBytesUsed += e, i;
|
|
38
|
-
}
|
|
39
|
-
releaseBuffer(e, t = !0) {
|
|
40
|
-
if (this.freeBuffers.size === 0) return;
|
|
41
|
-
let n = e.size, r = e.usage, i = w(n, r), a = this.usedBuffers.get(i), o = a.indexOf(e);
|
|
42
|
-
if (o < 0) throw Error("Cannot find the buffer in buffer manager");
|
|
43
|
-
a[o] = a[a.length - 1], a.pop(), this.numUsedBuffers--, this.numBytesUsed -= n, t ? (this.freeBuffers.get(i).push(e), this.numFreeBuffers++) : (e.destroy(), this.numBytesAllocated -= n);
|
|
44
|
-
}
|
|
45
|
-
getNumUsedBuffers() {
|
|
46
|
-
return this.numUsedBuffers;
|
|
47
|
-
}
|
|
48
|
-
getNumFreeBuffers() {
|
|
49
|
-
return this.numFreeBuffers;
|
|
50
|
-
}
|
|
51
|
-
dispose() {
|
|
52
|
-
this.freeBuffers.forEach((e, t) => {
|
|
53
|
-
e.forEach((e) => {
|
|
54
|
-
e.destroy();
|
|
55
|
-
});
|
|
56
|
-
}), this.usedBuffers.forEach((e, t) => {
|
|
57
|
-
e.forEach((e) => {
|
|
58
|
-
e.destroy();
|
|
59
|
-
});
|
|
60
|
-
}), this.freeBuffers = /* @__PURE__ */ new Map(), this.usedBuffers = /* @__PURE__ */ new Map(), this.numUsedBuffers = 0, this.numFreeBuffers = 0, this.numBytesUsed = 0, this.numBytesAllocated = 0;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
function w(e, t) {
|
|
64
|
-
return `${e}_${t}`;
|
|
65
|
-
}
|
|
66
|
-
// node_modules/@tensorflow/tfjs-backend-webgpu/dist/texture_manager.js
|
|
67
|
-
var T = class {
|
|
68
|
-
constructor(e) {
|
|
69
|
-
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;
|
|
70
|
-
}
|
|
71
|
-
acquireTexture(e, t, n, r) {
|
|
72
|
-
let i = D(n), a = e * t * i, o = E(e, t, n, r);
|
|
73
|
-
if (this.freeTextures.has(o) || this.freeTextures.set(o, []), this.usedTextures.has(o) || this.usedTextures.set(o, []), this.numBytesUsed += a, this.numUsedTextures++, this.freeTextures.get(o).length > 0) {
|
|
74
|
-
this.numFreeTextures--;
|
|
75
|
-
let e = this.freeTextures.get(o).shift();
|
|
76
|
-
return this.usedTextures.get(o).push(e), e;
|
|
77
|
-
}
|
|
78
|
-
this.numBytesAllocated += a;
|
|
79
|
-
let s = this.device.createTexture({
|
|
80
|
-
size: [e, t],
|
|
81
|
-
format: n,
|
|
82
|
-
usage: r
|
|
83
|
-
});
|
|
84
|
-
return this.usedTextures.get(o).push(s), s;
|
|
85
|
-
}
|
|
86
|
-
releaseTexture(e) {
|
|
87
|
-
if (this.freeTextures.size === 0) return;
|
|
88
|
-
let t = e.width, n = e.height, r = e.format, i = e.usage, a = E(t, n, r, i);
|
|
89
|
-
this.freeTextures.has(a) || this.freeTextures.set(a, []), this.freeTextures.get(a).push(e), this.numFreeTextures++, this.numUsedTextures--;
|
|
90
|
-
let o = this.usedTextures.get(a), s = o.indexOf(e);
|
|
91
|
-
if (s < 0) throw Error("Cannot release a texture that was never provided by this texture manager");
|
|
92
|
-
o.splice(s, 1);
|
|
93
|
-
let c = D(r), l = t * n * c;
|
|
94
|
-
this.numBytesUsed -= l;
|
|
95
|
-
}
|
|
96
|
-
getNumUsedTextures() {
|
|
97
|
-
return this.numUsedTextures;
|
|
98
|
-
}
|
|
99
|
-
getNumFreeTextures() {
|
|
100
|
-
return this.numFreeTextures;
|
|
101
|
-
}
|
|
102
|
-
dispose() {
|
|
103
|
-
this.freeTextures.forEach((e, t) => {
|
|
104
|
-
e.forEach((e) => {
|
|
105
|
-
e.destroy();
|
|
106
|
-
});
|
|
107
|
-
}), this.usedTextures.forEach((e, t) => {
|
|
108
|
-
e.forEach((e) => {
|
|
109
|
-
e.destroy();
|
|
110
|
-
});
|
|
111
|
-
}), this.freeTextures = /* @__PURE__ */ new Map(), this.usedTextures = /* @__PURE__ */ new Map(), this.numUsedTextures = 0, this.numFreeTextures = 0, this.numBytesUsed = 0, this.numBytesAllocated = 0;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
function E(e, t, n, r) {
|
|
115
|
-
return `${e}_${t}_${n}_${r}`;
|
|
116
|
-
}
|
|
117
|
-
function D(e) {
|
|
118
|
-
if (e === "rgba8unorm") return 16;
|
|
119
|
-
throw Error(`${e} is not supported!`);
|
|
120
|
-
}
|
|
121
|
-
// node_modules/@tensorflow/tfjs-backend-webgpu/dist/backend_webgpu.js
|
|
122
|
-
var O = d().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"), k = (e, t) => {
|
|
123
|
-
let n = e.limits.maxComputeWorkgroupsPerDimension, r = t.dispatchLayout, i = t.dispatch;
|
|
124
|
-
if (i.every((e) => e <= n)) return i;
|
|
125
|
-
_(i[0] > n && r.y === void 0 && r.z === void 0, () => "Dispatch size exceeds WebGPU limits in Y or Z dimension.");
|
|
126
|
-
let a = Math.ceil(Math.sqrt(i[0]));
|
|
127
|
-
return a > n ? (a = Math.ceil(Math.cbrt(i[0])), _(a <= n, () => "Total dispatch size exceeds WebGPU maximum."), [
|
|
128
|
-
a,
|
|
129
|
-
a,
|
|
130
|
-
a
|
|
131
|
-
]) : [
|
|
132
|
-
a,
|
|
133
|
-
a,
|
|
134
|
-
1
|
|
135
|
-
];
|
|
136
|
-
}, A = class x extends f {
|
|
137
|
-
nextDataId() {
|
|
138
|
-
return x.nextDataId++;
|
|
139
|
-
}
|
|
140
|
-
constructor(t, n) {
|
|
141
|
-
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, !e()) throw Error("WebGPU is not supported on this device");
|
|
142
|
-
this.pipelineCache = {}, this.device = t, this.queue = t.queue, this.commandEncoder = null, this.computePassEncoder = null, this.adapterInfo = new S(n), this.supportTimestampQuery = this.device.features.has("timestamp-query"), this.thresholdToIncreaseWorkgroups = this.adapterInfo.intelGPUGeneration >= 12 ? 16 : 8, this.bufferManager = new C(this.device), this.textureManager = new T(this.device), this.tensorMap = new r(this, a()), d().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({
|
|
143
|
-
device: t,
|
|
144
|
-
format: "bgra8unorm"
|
|
145
|
-
}), document.body.appendChild(this.dummyCanvas));
|
|
146
|
-
}
|
|
147
|
-
floatPrecision() {
|
|
148
|
-
return 32;
|
|
149
|
-
}
|
|
150
|
-
disposeData(e, t = !1) {
|
|
151
|
-
if (!this.tensorMap.has(e)) return !0;
|
|
152
|
-
let n = this.tensorMap.get(e);
|
|
153
|
-
return t ? n.refCount = 0 : n.refCount--, n.refCount > 0 ? !1 : (n.complexTensorInfos != null && (this.disposeData(n.complexTensorInfos.real.dataId), this.disposeData(n.complexTensorInfos.imag.dataId)), this.commandQueueOwnedIds.has(e) ? (this.tensorDataPendingDisposal.push(e), !0) : (this.releaseResource(e), this.tensorMap.delete(e), !0));
|
|
154
|
-
}
|
|
155
|
-
memory() {
|
|
156
|
-
return {
|
|
157
|
-
numBytesInGPU: this.bufferManager.numBytesUsed,
|
|
158
|
-
numBytesAllocatedInGPU: this.bufferManager.numBytesAllocated,
|
|
159
|
-
unreliable: !1
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
releaseResource(e) {
|
|
163
|
-
let t = this.tensorMap.get(e);
|
|
164
|
-
t && t.resource && (t.external || (t.resource instanceof GPUBuffer ? this.bufferManager.releaseBuffer(t.resource) : t.resource instanceof GPUTexture && this.textureManager.releaseTexture(t.resource)), t.resource = null);
|
|
165
|
-
}
|
|
166
|
-
refCount(e) {
|
|
167
|
-
return this.tensorMap.has(e) ? this.tensorMap.get(e).refCount : 0;
|
|
168
|
-
}
|
|
169
|
-
incRef(e) {
|
|
170
|
-
let t = this.tensorMap.get(e);
|
|
171
|
-
t.refCount++;
|
|
172
|
-
}
|
|
173
|
-
decRef(e) {
|
|
174
|
-
if (this.tensorMap.has(e)) {
|
|
175
|
-
let t = this.tensorMap.get(e);
|
|
176
|
-
t.refCount--;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
write(e, t, n) {
|
|
180
|
-
if (n === "complex64" && e != null) throw Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
|
|
181
|
-
let r = { id: this.nextDataId() };
|
|
182
|
-
return this.tensorMap.set(r, {
|
|
183
|
-
dtype: n,
|
|
184
|
-
shape: t,
|
|
185
|
-
values: e,
|
|
186
|
-
refCount: 1
|
|
187
|
-
}), r;
|
|
188
|
-
}
|
|
189
|
-
move(e, t, n, r, i) {
|
|
190
|
-
if (r === "complex64") throw Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");
|
|
191
|
-
this.tensorMap.set(e, {
|
|
192
|
-
dtype: r,
|
|
193
|
-
shape: n,
|
|
194
|
-
values: t,
|
|
195
|
-
refCount: i
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
submitQueue() {
|
|
199
|
-
this.queue.submit([this.commandEncoder.finish()]), this.commandEncoder = null, this.dispatchCountInPass = 0, this.commandQueueOwnedIds = /* @__PURE__ */ new WeakSet(), this.tensorDataPendingDisposal.forEach((e) => {
|
|
200
|
-
this.releaseResource(e), this.tensorMap.delete(e);
|
|
201
|
-
}), this.uniformPendingDisposal.forEach((e) => this.bufferManager.releaseBuffer(e)), this.stagingPendingDisposal.forEach((e) => this.bufferManager.releaseBuffer(e, !1)), this.tensorDataPendingDisposal = [], this.uniformPendingDisposal = [], this.stagingPendingDisposal = [];
|
|
202
|
-
}
|
|
203
|
-
ensureCommandEncoderReady() {
|
|
204
|
-
this.commandEncoder ||= this.device.createCommandEncoder();
|
|
205
|
-
}
|
|
206
|
-
endComputePassEncoder() {
|
|
207
|
-
this.computePassEncoder &&= (this.computePassEncoder.end(), null);
|
|
208
|
-
}
|
|
209
|
-
async checkCompileCompletionAsync() {
|
|
210
|
-
let e;
|
|
211
|
-
try {
|
|
212
|
-
e = await Promise.all(Object.values(this.pipelineCache));
|
|
213
|
-
} catch (e) {
|
|
214
|
-
throw Error(e.message);
|
|
215
|
-
}
|
|
216
|
-
Object.keys(this.pipelineCache).map((t, n) => {
|
|
217
|
-
this.pipelineCache[t] = e[n];
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
async getBufferData(e) {
|
|
221
|
-
if (d().getBool("WEBGPU_ENGINE_COMPILE_ONLY")) 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;
|
|
222
|
-
let t = e.size, n = this.bufferManager.acquireBuffer(t, GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ);
|
|
223
|
-
this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(e, 0, n, 0, t), this.submitQueue(), await n.mapAsync(GPUMapMode.READ);
|
|
224
|
-
let r = n.getMappedRange().slice(0);
|
|
225
|
-
return n.unmap(), n != null && this.bufferManager.releaseBuffer(n), d().getBool("WEBGPU_USE_PROFILE_TOOL") && (_(this.dummyContext !== void 0, () => "Fail to get context for profiling tool"), this.dummyContext.getCurrentTexture()), r;
|
|
226
|
-
}
|
|
227
|
-
convertAndCacheOnCPU(e, t) {
|
|
228
|
-
let n = this.tensorMap.get(e);
|
|
229
|
-
return n.values = t, n.values;
|
|
230
|
-
}
|
|
231
|
-
readSync(e) {
|
|
232
|
-
let t = this.tensorMap.get(e), { values: r, complexTensorInfos: a } = t;
|
|
233
|
-
if (r != null || t.dtype === "string") return r;
|
|
234
|
-
if (t.dtype === "complex64") {
|
|
235
|
-
let t = this.readSync(a.real.dataId), r = this.readSync(a.imag.dataId), o = i(n(t, r).buffer, "float32");
|
|
236
|
-
return this.convertAndCacheOnCPU(e, o), o;
|
|
237
|
-
}
|
|
238
|
-
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."));
|
|
239
|
-
let o = ["opaque", "premultiplied"], s = t.resource, c = s.size;
|
|
240
|
-
_(c % 4 == 0, () => "Because there is 4 bytes for one pixel, buffer size must be multiple of 4.");
|
|
241
|
-
let l = c / 4, u = new ArrayBuffer(c), d = o.map((e) => new OffscreenCanvas(256, 256)), f = new OffscreenCanvas(256, 256);
|
|
242
|
-
this.endComputePassEncoder(), d.map((e, t) => {
|
|
243
|
-
let n = e.getContext("webgpu");
|
|
244
|
-
return n.configure({
|
|
245
|
-
device: this.device,
|
|
246
|
-
format: "bgra8unorm",
|
|
247
|
-
usage: GPUTextureUsage.COPY_DST,
|
|
248
|
-
alphaMode: o[t]
|
|
249
|
-
}), n.getCurrentTexture();
|
|
250
|
-
}).map((e, t) => {
|
|
251
|
-
let n = (n, r, i) => {
|
|
252
|
-
this.ensureCommandEncoderReady(), this.commandEncoder.copyBufferToTexture({
|
|
253
|
-
buffer: s,
|
|
254
|
-
bytesPerRow: 1024,
|
|
255
|
-
offset: i
|
|
256
|
-
}, { texture: e }, {
|
|
257
|
-
width: n,
|
|
258
|
-
height: r
|
|
259
|
-
}), this.submitQueue();
|
|
260
|
-
let a = f.getContext("2d", { willReadFrequently: !0 });
|
|
261
|
-
a.clearRect(0, 0, n, r), a.drawImage(d[t], 0, 0);
|
|
262
|
-
let c = a.getImageData(0, 0, n, r).data, l = o[t], p = new Uint8ClampedArray(u, i, n * r * 4);
|
|
263
|
-
for (let e = 0; e < p.length; e += 4) if (l === "premultiplied") p[e + 3] = c[e + 3];
|
|
264
|
-
else {
|
|
265
|
-
let t = c[e];
|
|
266
|
-
p[e] = c[e + 2], p[e + 1] = c[e + 1], p[e + 2] = t;
|
|
267
|
-
}
|
|
268
|
-
}, r = Math.floor(l / 65536), i = 256, a = 256, c = 0;
|
|
269
|
-
for (let e = 0; e < r; e++) n(i, a, c), c += 262144;
|
|
270
|
-
let p = l % 65536;
|
|
271
|
-
a = Math.floor(p / 256), a > 0 && (n(i, a, c), c += a * 1024), i = p % 256, i > 0 && n(i, 1, c);
|
|
272
|
-
});
|
|
273
|
-
let p = i(u, t.dtype);
|
|
274
|
-
return this.convertAndCacheOnCPU(e, p), p;
|
|
275
|
-
}
|
|
276
|
-
async read(e) {
|
|
277
|
-
if (!this.tensorMap.has(e)) throw Error(`Tensor ${e} was not registered!`);
|
|
278
|
-
let t = this.tensorMap.get(e), { values: r } = t;
|
|
279
|
-
if (r != null) return r;
|
|
280
|
-
let a;
|
|
281
|
-
if (t.dtype === "complex64") {
|
|
282
|
-
let e = await Promise.all([this.read(t.complexTensorInfos.real.dataId), this.read(t.complexTensorInfos.imag.dataId)]), r = e[0], i = e[1];
|
|
283
|
-
a = n(r, i);
|
|
284
|
-
} else {
|
|
285
|
-
let e = await this.getBufferData(t.resource);
|
|
286
|
-
a = i(e, t.dtype);
|
|
287
|
-
}
|
|
288
|
-
return this.convertAndCacheOnCPU(e, a), a;
|
|
289
|
-
}
|
|
290
|
-
copyBuffer(e) {
|
|
291
|
-
let t = e.size, n = e.usage, r = this.bufferManager.acquireBuffer(t, n);
|
|
292
|
-
return this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(e, 0, r, 0, t), this.submitQueue(), r;
|
|
293
|
-
}
|
|
294
|
-
createTensorFromGPUData(e, n, r) {
|
|
295
|
-
let i = e.buffer;
|
|
296
|
-
if (r === "complex64") throw Error("Cannot write to a complex64 dtype. ");
|
|
297
|
-
let o = { id: this.nextDataId() };
|
|
298
|
-
this.tensorMap.set(o, {
|
|
299
|
-
dtype: r,
|
|
300
|
-
shape: n,
|
|
301
|
-
values: null,
|
|
302
|
-
refCount: 1,
|
|
303
|
-
external: e.zeroCopy
|
|
304
|
-
});
|
|
305
|
-
let s = this.tensorMap.get(o), c = t(s.dtype) * g(s.shape);
|
|
306
|
-
if (e.buffer.size < c) throw Error(`GPUBuffer size(${e.buffer.size}) is smaller than tensor size(${c})!`);
|
|
307
|
-
if ((e.buffer.usage & (GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC)) !== (GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC)) throw Error("GPUBuffer.usage should include GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC!");
|
|
308
|
-
return e.zeroCopy !== !0 && (i = this.copyBuffer(i)), s.resource = i, a().makeTensorFromDataId(o, n, r, this);
|
|
309
|
-
}
|
|
310
|
-
readToGPU(e) {
|
|
311
|
-
let { values: t, dtype: n, shape: r, resource: i } = this.tensorMap.get(e);
|
|
312
|
-
if (n === "complex64") throw Error("Does not support reading buffer for complex64 dtype.");
|
|
313
|
-
if (i == null) throw Error(t == null ? "There is no data on GPU or CPU." : "Data is not on GPU but on CPU.");
|
|
314
|
-
let o = i, s = o.size, c = o.usage, l = this.bufferManager.acquireBuffer(s, c);
|
|
315
|
-
this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(i, 0, l, 0, s), this.submitQueue();
|
|
316
|
-
let u = this.makeTensorInfo(r, n), d = a().makeTensorFromTensorInfo(u), f = this.tensorMap.get(u.dataId);
|
|
317
|
-
return f.resource = l, {
|
|
318
|
-
tensorRef: d,
|
|
319
|
-
buffer: l
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
bufferSync(e) {
|
|
323
|
-
let t = this.readSync(e.dataId);
|
|
324
|
-
if (e.dtype === "string") try {
|
|
325
|
-
let n = t.map((e) => h(e));
|
|
326
|
-
return c(e.shape, e.dtype, n);
|
|
327
|
-
} catch {
|
|
328
|
-
throw Error("Failed to decode encoded string bytes into utf-8");
|
|
329
|
-
}
|
|
330
|
-
return c(e.shape, e.dtype, t);
|
|
331
|
-
}
|
|
332
|
-
async time(e) {
|
|
333
|
-
!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);
|
|
334
|
-
let t = this.activeTimers, n = [], r = !1;
|
|
335
|
-
this.programTimersStack == null ? (this.programTimersStack = n, r = !0) : this.activeTimers.push(n), this.activeTimers = n, e();
|
|
336
|
-
let i = p(this.activeTimers.map((e) => e.query)).filter((e) => e != null), a = p(this.activeTimers.map((e) => e.name)).filter((e) => e != null);
|
|
337
|
-
this.activeTimers = t, r && (this.programTimersStack = null);
|
|
338
|
-
let o = {
|
|
339
|
-
uploadWaitMs: this.uploadWaitMs,
|
|
340
|
-
downloadWaitMs: this.downloadWaitMs,
|
|
341
|
-
kernelMs: null,
|
|
342
|
-
wallMs: null
|
|
343
|
-
}, s = await Promise.all(i);
|
|
344
|
-
return o.kernelMs = u(s), o.getExtraProfileInfo = () => s.map((e, t) => ({
|
|
345
|
-
name: a[t],
|
|
346
|
-
ms: e
|
|
347
|
-
})).map((e) => `${e.name}: ${e.ms}`).join(", "), this.uploadWaitMs = 0, this.downloadWaitMs = 0, o;
|
|
348
|
-
}
|
|
349
|
-
makeTensorInfo(e, t, n) {
|
|
350
|
-
return t === "string" && n != null && n.length > 0 && o(n[0]) && (n = n.map((e) => m(e))), {
|
|
351
|
-
dataId: this.write(n, e, t),
|
|
352
|
-
shape: e,
|
|
353
|
-
dtype: t
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
tensorToBinding(e) {
|
|
357
|
-
if (!e) return null;
|
|
358
|
-
let t = this.tensorMap.get(e.dataId).resource;
|
|
359
|
-
return t instanceof GPUBuffer ? { buffer: t } : t instanceof GPUTexture ? t.createView() : t;
|
|
360
|
-
}
|
|
361
|
-
uploadToGPU(e) {
|
|
362
|
-
let n = this.tensorMap.get(e);
|
|
363
|
-
if (n.resource != null) return;
|
|
364
|
-
let r = t(n.dtype) * g(n.shape), i, a = GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST;
|
|
365
|
-
if (n.values) {
|
|
366
|
-
if (i = this.bufferManager.acquireBuffer(r, a, !0), i.mapState === "unmapped") {
|
|
367
|
-
let e = this.bufferManager.acquireBuffer(r, GPUBufferUsage.MAP_WRITE | GPUBufferUsage.COPY_SRC, !0, !1), t = e.getMappedRange();
|
|
368
|
-
n.dtype === "int32" || n.dtype === "packedF16" || n.dtype === "bool" ? new Int32Array(t).set(n.values) : new Float32Array(t).set(n.values), e.unmap(), this.ensureCommandEncoderReady(), this.endComputePassEncoder(), this.commandEncoder.copyBufferToBuffer(e, 0, i, 0, r), this.stagingPendingDisposal.push(e);
|
|
369
|
-
} else {
|
|
370
|
-
let e = i.getMappedRange();
|
|
371
|
-
n.dtype === "int32" || n.dtype === "packedF16" || n.dtype === "bool" ? new Int32Array(e).set(n.values) : new Float32Array(e).set(n.values), i.unmap();
|
|
372
|
-
}
|
|
373
|
-
n.values = null;
|
|
374
|
-
} else i = this.bufferManager.acquireBuffer(r, a);
|
|
375
|
-
n.resource = i;
|
|
376
|
-
}
|
|
377
|
-
makeUniforms(e) {
|
|
378
|
-
let t = 0, n = 0, r = [], i = 1;
|
|
379
|
-
e.forEach((e) => {
|
|
380
|
-
e.data.length === 0 && (e.data = [1]);
|
|
381
|
-
let a;
|
|
382
|
-
switch (e.data.length) {
|
|
383
|
-
case 1:
|
|
384
|
-
a = 4;
|
|
385
|
-
break;
|
|
386
|
-
case 2:
|
|
387
|
-
a = 8;
|
|
388
|
-
break;
|
|
389
|
-
case 3:
|
|
390
|
-
a = 16;
|
|
391
|
-
break;
|
|
392
|
-
case 4:
|
|
393
|
-
a = 16;
|
|
394
|
-
break;
|
|
395
|
-
case 5:
|
|
396
|
-
a = 16;
|
|
397
|
-
break;
|
|
398
|
-
case 6:
|
|
399
|
-
a = 16;
|
|
400
|
-
break;
|
|
401
|
-
default: _(!1, () => `Unsupported ${e.data.length}D shape`);
|
|
402
|
-
}
|
|
403
|
-
(n === 5 || n === 6) && (a = 16), a > i && (i = a), t = Math.ceil(t / a) * a, n = e.data.length, r.push(t), t += e.data.length * 4;
|
|
404
|
-
}), t = Math.ceil(t / i) * i;
|
|
405
|
-
let a = new ArrayBuffer(t);
|
|
406
|
-
e.forEach((e, t) => {
|
|
407
|
-
let n = r[t];
|
|
408
|
-
e.type === "int32" ? new Int32Array(a, n, e.data.length).set(e.data) : e.type === "uint32" ? new Uint32Array(a, n, e.data.length).set(e.data) : new Float32Array(a, n, e.data.length).set(e.data);
|
|
409
|
-
});
|
|
410
|
-
let o = this.bufferManager.acquireBuffer(t, GPUBufferUsage.COPY_DST | GPUBufferUsage.UNIFORM);
|
|
411
|
-
return this.queue.writeBuffer(o, 0, a, 0, t), this.uniformPendingDisposal.push(o), {
|
|
412
|
-
offset: 0,
|
|
413
|
-
size: t,
|
|
414
|
-
buffer: o
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
runWebGPUProgram(e, t, n, r, i) {
|
|
418
|
-
if (i ||= this.makeTensorInfo(e.outputShape, n), g(i.shape) === 0) return this.tensorMap.get(i.dataId).values = s(i.dtype, 0), i;
|
|
419
|
-
this.uploadToGPU(i.dataId), e.dispatch = k(this.device, e);
|
|
420
|
-
let a = t.map((t, n) => {
|
|
421
|
-
if (t.dtype === "complex64") throw Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");
|
|
422
|
-
return this.uploadToGPU(t.dataId), {
|
|
423
|
-
dtype: this.tensorMap.get(t.dataId).dtype,
|
|
424
|
-
shape: t.shape,
|
|
425
|
-
name: e.variableNames[n]
|
|
426
|
-
};
|
|
427
|
-
});
|
|
428
|
-
e.shaderKey = v(e, a, i);
|
|
429
|
-
let o = d().getBool("WEBGPU_ENGINE_COMPILE_ONLY");
|
|
430
|
-
return e.shaderKey in this.pipelineCache || (this.pipelineCache[e.shaderKey] = y(this.device, e, a, i, o)), e.pipeline = this.pipelineCache[e.shaderKey], o || this.recordAndSubmit(e, i, t, r), i;
|
|
431
|
-
}
|
|
432
|
-
recordAndSubmit(e, t, n, r) {
|
|
433
|
-
if (e.pipeline instanceof Promise) throw Error("Please call checkCompileCompletionAsync to ensure parallel compilation is done!");
|
|
434
|
-
let i = [], a = [], o = "int32";
|
|
435
|
-
if (e.pixelsOpType == null) {
|
|
436
|
-
i.push({
|
|
437
|
-
type: "float32",
|
|
438
|
-
data: [NaN]
|
|
439
|
-
}, {
|
|
440
|
-
type: "float32",
|
|
441
|
-
data: [Infinity]
|
|
442
|
-
}), a = n.concat(t).map((e) => e.shape);
|
|
443
|
-
let e = "int32";
|
|
444
|
-
a.map((t) => {
|
|
445
|
-
i.push({
|
|
446
|
-
type: e,
|
|
447
|
-
data: t
|
|
448
|
-
});
|
|
449
|
-
let n = l(t);
|
|
450
|
-
i.push({
|
|
451
|
-
type: e,
|
|
452
|
-
data: n
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
} else {
|
|
456
|
-
let e = l(t.shape);
|
|
457
|
-
i.push({
|
|
458
|
-
type: o,
|
|
459
|
-
data: e
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
if (e.size) {
|
|
463
|
-
let t = g(e.outputShape);
|
|
464
|
-
i.push({
|
|
465
|
-
type: o,
|
|
466
|
-
data: [e.outputComponent ? t / e.outputComponent : t]
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
r && (i = [...i, ...r]);
|
|
470
|
-
let s = [
|
|
471
|
-
this.tensorToBinding(t),
|
|
472
|
-
...n.map((e) => this.tensorToBinding(e)),
|
|
473
|
-
this.makeUniforms(i)
|
|
474
|
-
];
|
|
475
|
-
n.forEach((e) => {
|
|
476
|
-
this.commandQueueOwnedIds.add(e.dataId);
|
|
477
|
-
}), this.commandQueueOwnedIds.add(t.dataId);
|
|
478
|
-
let c = this.device.createBindGroup({
|
|
479
|
-
layout: e.pipeline.getBindGroupLayout(0),
|
|
480
|
-
entries: s.map((e, t) => ({
|
|
481
|
-
binding: t,
|
|
482
|
-
resource: e
|
|
483
|
-
}))
|
|
484
|
-
}), u = this.activeTimers != null;
|
|
485
|
-
this.ensureCommandEncoderReady();
|
|
486
|
-
let f = {};
|
|
487
|
-
u && this.supportTimestampQuery ? (this.endComputePassEncoder(), this.querySet ??= this.device.createQuerySet({
|
|
488
|
-
type: "timestamp",
|
|
489
|
-
count: this.querySetCount
|
|
490
|
-
}), f.timestampWrites = {
|
|
491
|
-
querySet: this.querySet,
|
|
492
|
-
beginningOfPassWriteIndex: 0,
|
|
493
|
-
endOfPassWriteIndex: 1
|
|
494
|
-
}, this.computePassEncoder = this.commandEncoder.beginComputePass(f)) : this.computePassEncoder ||= this.commandEncoder.beginComputePass(f), this.computePassEncoder.setPipeline(e.pipeline), this.computePassEncoder.setBindGroup(0, c), this.computePassEncoder.dispatchWorkgroups(e.dispatch[0], e.dispatch[1], e.dispatch[2]), this.dispatchCountInPass++, (u || d().get("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE") <= this.dispatchCountInPass || e.pixelsOpType === b.DRAW) && (this.endComputePassEncoder(), u ? this.activeTimers.push({
|
|
495
|
-
name: e.constructor.name,
|
|
496
|
-
query: this.getQueryTime()
|
|
497
|
-
}) : this.submitQueue());
|
|
498
|
-
}
|
|
499
|
-
async getQueryTime() {
|
|
500
|
-
if (!this.supportTimestampQuery) return 0;
|
|
501
|
-
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);
|
|
502
|
-
let e = this.bufferManager.acquireBuffer(this.querySetCount * 8, GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST);
|
|
503
|
-
this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer, 0, e, 0, this.querySetCount * 8), this.submitQueue(), await e.mapAsync(GPUMapMode.READ);
|
|
504
|
-
let t = new BigUint64Array(e.getMappedRange()), n = Number(t[1] - t[0]) / 1e6;
|
|
505
|
-
return e.unmap(), this.bufferManager.releaseBuffer(e), n;
|
|
506
|
-
}
|
|
507
|
-
shouldExecuteOnCPU(e, t = O) {
|
|
508
|
-
return d().getBool("WEBGPU_CPU_FORWARD") && e.every((e) => this.tensorMap.get(e.dataId).resource == null && g(e.shape) < t);
|
|
509
|
-
}
|
|
510
|
-
numDataIds() {
|
|
511
|
-
return this.tensorMap.numDataIds() - this.tensorDataPendingDisposal.length;
|
|
512
|
-
}
|
|
513
|
-
dispose() {
|
|
514
|
-
this.disposed ||= (this.querySet != null && this.querySet.destroy(), this.bufferManager.dispose(), this.textureManager.dispose(), !0);
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
A.nextDataId = 0;
|
|
518
|
-
export { A as t };
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { yi as e } from "./dist-CMMLi-qO.js";
|
|
2
|
-
// node_modules/@tensorflow/tfjs-backend-webgpu/dist/webgpu_util.js
|
|
3
|
-
var t = (e) => {
|
|
4
|
-
let t = 1;
|
|
5
|
-
for (let n = 0; n < e.length; n++) t *= e[n];
|
|
6
|
-
return t;
|
|
7
|
-
};
|
|
8
|
-
function n(e, n, r = [
|
|
9
|
-
1,
|
|
10
|
-
1,
|
|
11
|
-
1
|
|
12
|
-
], i = [
|
|
13
|
-
1,
|
|
14
|
-
1,
|
|
15
|
-
1
|
|
16
|
-
]) {
|
|
17
|
-
let [a, o, s] = [
|
|
18
|
-
Math.ceil(t(e.x.map((e) => n[e])) / (r[0] * i[0])),
|
|
19
|
-
e.y ? Math.ceil(t(e.y.map((e) => n[e])) / (r[1] * i[1])) : 1,
|
|
20
|
-
e.z ? Math.ceil(t(e.z.map((e) => n[e])) / (r[2] * i[2])) : 1
|
|
21
|
-
];
|
|
22
|
-
return [
|
|
23
|
-
a,
|
|
24
|
-
o,
|
|
25
|
-
s
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
function r(e, t, n, r = !1) {
|
|
29
|
-
let i = [
|
|
30
|
-
8,
|
|
31
|
-
8,
|
|
32
|
-
1
|
|
33
|
-
], a = [
|
|
34
|
-
4,
|
|
35
|
-
4,
|
|
36
|
-
1
|
|
37
|
-
];
|
|
38
|
-
return r || (e <= 8 && (a[1] = 1), t <= 16 && n <= 16 && (i[0] = 4)), {
|
|
39
|
-
workgroupSize: i,
|
|
40
|
-
elementsPerThread: a
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function i(e, n, r = !1) {
|
|
44
|
-
if (r) return [
|
|
45
|
-
8,
|
|
46
|
-
8,
|
|
47
|
-
1
|
|
48
|
-
];
|
|
49
|
-
let i = t(e.x.map((e) => n[e])), a = t(e.y.map((e) => n[e]));
|
|
50
|
-
return i <= 4 ? [
|
|
51
|
-
4,
|
|
52
|
-
16,
|
|
53
|
-
1
|
|
54
|
-
] : a <= 4 ? [
|
|
55
|
-
16,
|
|
56
|
-
4,
|
|
57
|
-
1
|
|
58
|
-
] : [
|
|
59
|
-
16,
|
|
60
|
-
16,
|
|
61
|
-
1
|
|
62
|
-
];
|
|
63
|
-
}
|
|
64
|
-
function a(e, n, r = !1) {
|
|
65
|
-
if (r) return [
|
|
66
|
-
4,
|
|
67
|
-
4,
|
|
68
|
-
1
|
|
69
|
-
];
|
|
70
|
-
let i = t(e.x.map((e) => n[e])), a = t(e.y.map((e) => n[e]));
|
|
71
|
-
return i <= 4 ? [
|
|
72
|
-
1,
|
|
73
|
-
2,
|
|
74
|
-
1
|
|
75
|
-
] : a <= 4 ? [
|
|
76
|
-
2,
|
|
77
|
-
1,
|
|
78
|
-
1
|
|
79
|
-
] : [
|
|
80
|
-
2,
|
|
81
|
-
2,
|
|
82
|
-
1
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
function o(e) {
|
|
86
|
-
return { x: e.map((e, t) => t) };
|
|
87
|
-
}
|
|
88
|
-
function s(e) {
|
|
89
|
-
if (e === "float32" || e === "int32" || e === "bool" || e === "string" || e === "packedF16") return 4;
|
|
90
|
-
if (e === "complex64") return 8;
|
|
91
|
-
throw Error(`Unknown dtype ${e}`);
|
|
92
|
-
}
|
|
93
|
-
function c() {
|
|
94
|
-
return !!(typeof globalThis < "u" && globalThis.navigator && globalThis.navigator.gpu);
|
|
95
|
-
}
|
|
96
|
-
function l(t, n) {
|
|
97
|
-
Array.isArray(t) || (t = [t]), t.forEach((t) => {
|
|
98
|
-
t != null && e(t.dtype !== "complex64", () => `${n} does not support complex64 tensors in the WebGPU backend.`);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
var u;
|
|
102
|
-
(function(e) {
|
|
103
|
-
e[e.MatMulReduceProgram = 0] = "MatMulReduceProgram", e[e.MatMulSplitKProgram = 1] = "MatMulSplitKProgram", e[e.MatMulSmallOutputSizeProgram = 2] = "MatMulSmallOutputSizeProgram", e[e.MatMulPackedProgram = 3] = "MatMulPackedProgram", e[e.MatMulMax = 4] = "MatMulMax";
|
|
104
|
-
})(u ||= {});
|
|
105
|
-
export { a, o as c, n as i, c as l, u as n, r as o, l as r, i as s, s as t };
|
package/dist/zeros-hxKGkRfl.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Bi as e, bi as t, qi as n, rt as r } from "./dist-CMMLi-qO.js";
|
|
2
|
-
import { t as i } from "./complex-Cl904TqN.js";
|
|
3
|
-
// node_modules/@tensorflow/tfjs-core/dist/ops/zeros.js
|
|
4
|
-
function a(o, s = "float32") {
|
|
5
|
-
if (t(o), s === "complex64") {
|
|
6
|
-
let e = a(o, "float32"), t = a(o, "float32");
|
|
7
|
-
return i(e, t);
|
|
8
|
-
}
|
|
9
|
-
let c = e(n(o), s);
|
|
10
|
-
return r.makeTensor(c, o, s);
|
|
11
|
-
}
|
|
12
|
-
export { a as t };
|