@genai-fi/nanogpt 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-8IK28IWR.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/ops/webgpu/silu.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
-
import { s as t } from "../../webgpu_program-DvkFqRlR.js";
|
|
3
|
-
import { c as n, i as r } from "../../webgpu_util-5QTyovaf.js";
|
|
4
|
-
import { isPackedTensor as i } from "../../utilities/packed.js";
|
|
5
|
-
// lib/ops/webgpu/silu.ts
|
|
6
|
-
var a = class {
|
|
7
|
-
outputShape;
|
|
8
|
-
shaderKey;
|
|
9
|
-
dispatchLayout;
|
|
10
|
-
dispatch;
|
|
11
|
-
variableNames = ["A"];
|
|
12
|
-
workgroupSize;
|
|
13
|
-
size = !0;
|
|
14
|
-
constructor(e) {
|
|
15
|
-
this.workgroupSize = [
|
|
16
|
-
128,
|
|
17
|
-
1,
|
|
18
|
-
1
|
|
19
|
-
], this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize), this.shaderKey = "unary_silu";
|
|
20
|
-
}
|
|
21
|
-
getUserCode() {
|
|
22
|
-
return `
|
|
23
|
-
fn unaryOperation(x : f32) -> f32 {
|
|
24
|
-
return x / (1.0 + exp(-x));
|
|
25
|
-
}
|
|
26
|
-
${t("index")} {
|
|
27
|
-
if (index < uniforms.size) {
|
|
28
|
-
let a = getAByOutputIndex(index);
|
|
29
|
-
setOutputAtIndex(index, unaryOperation(a));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
`;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
function o(e) {
|
|
36
|
-
let { x: t } = e.inputs, n = e.backend, r = new a(t.shape);
|
|
37
|
-
return n.runWebGPUProgram(r, [t], "float32");
|
|
38
|
-
}
|
|
39
|
-
e({
|
|
40
|
-
kernelName: "Silu",
|
|
41
|
-
backendName: "webgpu",
|
|
42
|
-
kernelFunc: o
|
|
43
|
-
});
|
|
44
|
-
var s = class {
|
|
45
|
-
variableNames = ["dy", "x"];
|
|
46
|
-
outputShape;
|
|
47
|
-
shaderKey = "SiluGrad16";
|
|
48
|
-
dispatchLayout;
|
|
49
|
-
dispatch;
|
|
50
|
-
workgroupSize = [
|
|
51
|
-
128,
|
|
52
|
-
1,
|
|
53
|
-
1
|
|
54
|
-
];
|
|
55
|
-
size = !0;
|
|
56
|
-
constructor(e) {
|
|
57
|
-
this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
58
|
-
}
|
|
59
|
-
getUserCode() {
|
|
60
|
-
return `
|
|
61
|
-
fn activationGrad(dy: f32, X: f32) -> f32 {
|
|
62
|
-
let sigmoid = 1.0 / (1.0 + exp(-X));
|
|
63
|
-
return dy * (sigmoid + X * sigmoid * (1.0 - sigmoid));
|
|
64
|
-
}
|
|
65
|
-
${t("index")} {
|
|
66
|
-
if (index < uniforms.size) {
|
|
67
|
-
let X = unpack2x16float(u32(x[index]));
|
|
68
|
-
let DY = unpack2x16float(u32(dy[index]));
|
|
69
|
-
let dsilu = vec2<f32>(
|
|
70
|
-
activationGrad(DY.x, X.x),
|
|
71
|
-
activationGrad(DY.y, X.y)
|
|
72
|
-
);
|
|
73
|
-
result[index] = i32(pack2x16float(dsilu));
|
|
74
|
-
}
|
|
75
|
-
}`;
|
|
76
|
-
}
|
|
77
|
-
}, c = class {
|
|
78
|
-
variableNames = ["dy", "x"];
|
|
79
|
-
outputShape;
|
|
80
|
-
shaderKey = "SiluGrad32";
|
|
81
|
-
dispatchLayout;
|
|
82
|
-
dispatch;
|
|
83
|
-
workgroupSize = [
|
|
84
|
-
128,
|
|
85
|
-
1,
|
|
86
|
-
1
|
|
87
|
-
];
|
|
88
|
-
size = !0;
|
|
89
|
-
constructor(e) {
|
|
90
|
-
this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
91
|
-
}
|
|
92
|
-
getUserCode() {
|
|
93
|
-
return `
|
|
94
|
-
fn activationGrad(dy: f32, X: f32) -> f32 {
|
|
95
|
-
let sigmoid = 1.0 / (1.0 + exp(-X));
|
|
96
|
-
return dy * (sigmoid + X * sigmoid * (1.0 - sigmoid));
|
|
97
|
-
}
|
|
98
|
-
${t("index")} {
|
|
99
|
-
if (index < uniforms.size) {
|
|
100
|
-
let X = getXByOutputIndex(index);
|
|
101
|
-
let DY = getDyByOutputIndex(index);
|
|
102
|
-
let dsilu = activationGrad(DY, X);
|
|
103
|
-
setOutputAtIndex(index, dsilu);
|
|
104
|
-
}
|
|
105
|
-
}`;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
function l(e) {
|
|
109
|
-
let { dy: t, x: n } = e.inputs, r = e.backend, a = i(t), o = a ? new s(n.shape) : new c(n.shape);
|
|
110
|
-
return r.runWebGPUProgram(o, [t, n], a ? "packedF16" : "float32");
|
|
111
|
-
}
|
|
112
|
-
e({
|
|
113
|
-
kernelName: "SiluGrad",
|
|
114
|
-
backendName: "webgpu",
|
|
115
|
-
kernelFunc: l
|
|
116
|
-
});
|
|
117
|
-
export { a as SiluProgram };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { i as e, o as t, s as n } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
-
import { a as r, t as i } from "../../slice_util-BVgPRoij.js";
|
|
3
|
-
import { c as a, i as o } from "../../webgpu_util-5QTyovaf.js";
|
|
4
|
-
import { qi as s, xt as c } from "../../dist-CMMLi-qO.js";
|
|
5
|
-
// lib/ops/webgpu/slice16.ts
|
|
6
|
-
function l(e) {
|
|
7
|
-
switch (e) {
|
|
8
|
-
case 1: return "1D";
|
|
9
|
-
case 2: return "2D";
|
|
10
|
-
case 3: return "3D";
|
|
11
|
-
case 4: return "4D";
|
|
12
|
-
}
|
|
13
|
-
return "";
|
|
14
|
-
}
|
|
15
|
-
var u = class {
|
|
16
|
-
variableNames = ["source"];
|
|
17
|
-
uniforms;
|
|
18
|
-
outputShape;
|
|
19
|
-
shaderKey;
|
|
20
|
-
rank;
|
|
21
|
-
dispatchLayout;
|
|
22
|
-
dispatch;
|
|
23
|
-
workPerThread = 1;
|
|
24
|
-
workgroupSize = [
|
|
25
|
-
64,
|
|
26
|
-
1,
|
|
27
|
-
1
|
|
28
|
-
];
|
|
29
|
-
start;
|
|
30
|
-
size = !0;
|
|
31
|
-
constructor(t, n) {
|
|
32
|
-
this.outputShape = n, this.rank = n.length, this.dispatchLayout = a(this.outputShape), this.dispatch = o(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
33
|
-
this.workPerThread,
|
|
34
|
-
1,
|
|
35
|
-
1
|
|
36
|
-
]), this.start = t, this.uniforms = `start : ${e(t.length)}, `, this.shaderKey = "slice";
|
|
37
|
-
}
|
|
38
|
-
getUserCode() {
|
|
39
|
-
let r = e(this.rank), i;
|
|
40
|
-
return i = this.start.length === 1 ? this.outputShape.map(() => "sourceLoc = uniforms.start + coords;") : this.outputShape.map((e, n) => `sourceLoc.${d[n]} = uniforms.start.${t(n)} + coords.${d[n]};`), `
|
|
41
|
-
${n("index")} {
|
|
42
|
-
if (index < uniforms.size) {
|
|
43
|
-
var sourceLoc : ${r};
|
|
44
|
-
let coords = getCoordsFromIndex(index);
|
|
45
|
-
${i.join("\n")}
|
|
46
|
-
result[index] = source[getIndexFromCoords${l(this.rank)}(sourceLoc, uniforms.sourceShape)];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
`;
|
|
50
|
-
}
|
|
51
|
-
}, d = [
|
|
52
|
-
"x",
|
|
53
|
-
"y",
|
|
54
|
-
"z",
|
|
55
|
-
"w",
|
|
56
|
-
"u",
|
|
57
|
-
"v"
|
|
58
|
-
];
|
|
59
|
-
function f(e) {
|
|
60
|
-
let { inputs: t, backend: n, attrs: a } = e, { x: o } = t, { begin: c, size: l } = a, [d, f] = r(o, c, l);
|
|
61
|
-
if (i(o, d, f), s(f) === 0) return n.makeTensorInfo(f, o.dtype, []);
|
|
62
|
-
let p = new u(d, f), m = [{
|
|
63
|
-
type: "int32",
|
|
64
|
-
data: d
|
|
65
|
-
}];
|
|
66
|
-
return n.runWebGPUProgram(p, [o], o.dtype, m);
|
|
67
|
-
}
|
|
68
|
-
c({
|
|
69
|
-
kernelName: "Slice16",
|
|
70
|
-
backendName: "webgpu",
|
|
71
|
-
kernelFunc: f
|
|
72
|
-
});
|
|
73
|
-
export { f as slice };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { H as e, qi as t, xt as n } from "../../dist-CMMLi-qO.js";
|
|
2
|
-
import { t as r } from "../../reshape-DJb1jgMt.js";
|
|
3
|
-
import { reshape16 as i } from "../reshape16.js";
|
|
4
|
-
import a from "./softmax16_program.js";
|
|
5
|
-
import o from "./softmax16_subgroup_program.js";
|
|
6
|
-
import s from "./utils/deviceInfo.js";
|
|
7
|
-
// lib/ops/webgpu/softmax16.ts
|
|
8
|
-
function c(n) {
|
|
9
|
-
let { inputs: c, backend: l, attrs: u } = n, { logits: d } = c, { dim: f } = u, p = l.subgroupMinSize, m = l.subgroupMaxSize, h = s(l).subgroupsSupported, g = r(d, [t(d.shape) / d.shape[f], d.shape[f]]), _ = h ? new o(g.shape, p, m) : new a(g.shape), v = l.runWebGPUProgram(_, [g], "packedF16");
|
|
10
|
-
g.dispose();
|
|
11
|
-
let y = e().makeTensorFromTensorInfo(v), b = i(y, d.shape);
|
|
12
|
-
return y.dispose(), b;
|
|
13
|
-
}
|
|
14
|
-
n({
|
|
15
|
-
kernelName: "Softmax16",
|
|
16
|
-
backendName: "webgpu",
|
|
17
|
-
kernelFunc: c
|
|
18
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { s as e } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
-
import { c as t } from "../../webgpu_util-5QTyovaf.js";
|
|
3
|
-
// lib/ops/webgpu/softmax16_program.ts
|
|
4
|
-
var n = class {
|
|
5
|
-
variableNames = ["logits"];
|
|
6
|
-
outputShape;
|
|
7
|
-
shaderKey;
|
|
8
|
-
dispatchLayout;
|
|
9
|
-
dispatch;
|
|
10
|
-
workgroupSize;
|
|
11
|
-
constructor(e) {
|
|
12
|
-
this.outputShape = e, this.dispatchLayout = t(this.outputShape), this.dispatch = [
|
|
13
|
-
this.outputShape[0],
|
|
14
|
-
1,
|
|
15
|
-
1
|
|
16
|
-
], this.workgroupSize = this.outputShape[1] >= 4096 ? [
|
|
17
|
-
256,
|
|
18
|
-
1,
|
|
19
|
-
1
|
|
20
|
-
] : this.outputShape[1] < 64 ? [
|
|
21
|
-
32,
|
|
22
|
-
1,
|
|
23
|
-
1
|
|
24
|
-
] : [
|
|
25
|
-
64,
|
|
26
|
-
1,
|
|
27
|
-
1
|
|
28
|
-
], this.shaderKey = "softmax16";
|
|
29
|
-
}
|
|
30
|
-
getUserCode() {
|
|
31
|
-
return `
|
|
32
|
-
var<workgroup> buf : array<f32, ${this.workgroupSize[0]}>;
|
|
33
|
-
const blockSize = ${this.workgroupSize[0]};
|
|
34
|
-
${e("index")} {
|
|
35
|
-
let row = index / blockSize;
|
|
36
|
-
let tid = i32(localId.x);
|
|
37
|
-
let cols = uniforms.outShape[1];
|
|
38
|
-
let rowIdx = row * cols;
|
|
39
|
-
|
|
40
|
-
var threadMax = -3.402823e+38f;
|
|
41
|
-
for (var col = tid; col < cols; col += blockSize) {
|
|
42
|
-
let value = unpack2x16float(u32(logits[rowIdx + col]));
|
|
43
|
-
threadMax = max(threadMax, max(value.x, value.y));
|
|
44
|
-
}
|
|
45
|
-
buf[tid] = threadMax;
|
|
46
|
-
workgroupBarrier();
|
|
47
|
-
|
|
48
|
-
for (var currSize = blockSize >> 1; currSize > 0; currSize = currSize >> 1) {
|
|
49
|
-
if (tid < currSize) {
|
|
50
|
-
buf[tid] = max(buf[tid], buf[tid + currSize]);
|
|
51
|
-
}
|
|
52
|
-
workgroupBarrier();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let rowMaxShared: f32 = buf[0];
|
|
56
|
-
workgroupBarrier();
|
|
57
|
-
|
|
58
|
-
var threadSum = 0.0f;
|
|
59
|
-
for (var col = tid; col < cols; col += blockSize) {
|
|
60
|
-
let value = unpack2x16float(u32(logits[rowIdx + col]));
|
|
61
|
-
let subExp = exp(value.x - rowMaxShared);
|
|
62
|
-
threadSum += subExp;
|
|
63
|
-
let subExpY = exp(value.y - rowMaxShared);
|
|
64
|
-
threadSum += subExpY;
|
|
65
|
-
}
|
|
66
|
-
buf[tid] = threadSum;
|
|
67
|
-
workgroupBarrier();
|
|
68
|
-
|
|
69
|
-
for (var currSize = blockSize >> 1; currSize > 0; currSize = currSize >> 1) {
|
|
70
|
-
if (tid < currSize) {
|
|
71
|
-
buf[tid] = buf[tid] + buf[tid + currSize];
|
|
72
|
-
}
|
|
73
|
-
workgroupBarrier();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let rowSumShared: f32 = buf[0];
|
|
77
|
-
|
|
78
|
-
for (var col = tid; col < cols; col += blockSize) {
|
|
79
|
-
let value = unpack2x16float(u32(logits[rowIdx + col]));
|
|
80
|
-
let value1: f32 = exp(value.x - rowMaxShared) / rowSumShared;
|
|
81
|
-
let value2: f32 = exp(value.y - rowMaxShared) / rowSumShared;
|
|
82
|
-
result[rowIdx + col] = i32(pack2x16float(vec2<f32>(value1, value2)));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
`;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
export { n as default };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { s as e } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
-
import { c as t } from "../../webgpu_util-5QTyovaf.js";
|
|
3
|
-
// lib/ops/webgpu/softmax16_subgroup_program.ts
|
|
4
|
-
var n = class {
|
|
5
|
-
variableNames = ["logits"];
|
|
6
|
-
outputShape;
|
|
7
|
-
shaderKey;
|
|
8
|
-
dispatchLayout;
|
|
9
|
-
dispatch;
|
|
10
|
-
workgroupSize;
|
|
11
|
-
minSubgroupSize;
|
|
12
|
-
maxSubgroupSize;
|
|
13
|
-
subgroups = !0;
|
|
14
|
-
subgroupBuiltins = !1;
|
|
15
|
-
constructor(e, n, r) {
|
|
16
|
-
this.minSubgroupSize = n, this.maxSubgroupSize = r, this.outputShape = e, this.dispatchLayout = t(this.outputShape), this.dispatch = [
|
|
17
|
-
this.outputShape[0],
|
|
18
|
-
1,
|
|
19
|
-
1
|
|
20
|
-
], this.workgroupSize = [
|
|
21
|
-
Math.min(64, r),
|
|
22
|
-
1,
|
|
23
|
-
1
|
|
24
|
-
], n !== r && (this.subgroupBuiltins = !0, this.workgroupSize = [
|
|
25
|
-
64,
|
|
26
|
-
1,
|
|
27
|
-
1
|
|
28
|
-
]), this.shaderKey = "softmax16subgroup";
|
|
29
|
-
}
|
|
30
|
-
getUserCode() {
|
|
31
|
-
let t = this.maxSubgroupSize !== this.minSubgroupSize;
|
|
32
|
-
return `
|
|
33
|
-
${t ? `var<workgroup> bestValues : array<f32, ${this.workgroupSize[0]}>;` : ""}
|
|
34
|
-
const blockSize = ${this.workgroupSize[0]};
|
|
35
|
-
${e("index")} {
|
|
36
|
-
let row = index / blockSize;
|
|
37
|
-
let tid = i32(localId.x);
|
|
38
|
-
let cols = uniforms.outShape[1];
|
|
39
|
-
let rowIdx = row * cols;
|
|
40
|
-
|
|
41
|
-
var threadMax = -3.402823e+38f;
|
|
42
|
-
for (var col = tid; col < cols; col += blockSize) {
|
|
43
|
-
let value = unpack2x16float(u32(logits[rowIdx + col]));
|
|
44
|
-
threadMax = max(threadMax, max(value.x, value.y));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
threadMax = subgroupMax(threadMax);
|
|
48
|
-
${t ? "\n let lane = localId.x % subgroupSize;\n if (lane == 0) {\n bestValues[localId.x / subgroupSize] = threadMax;\n }\n workgroupBarrier();\n let numSubgroups = blockSize / subgroupSize;\n threadMax = select(-3.402823e+38f, bestValues[lane], lane < numSubgroups);\n threadMax = subgroupMax(threadMax);\n workgroupBarrier(); \n " : ""}
|
|
49
|
-
|
|
50
|
-
var threadSum = 0.0f;
|
|
51
|
-
for (var col = tid; col < cols; col += blockSize) {
|
|
52
|
-
let value = unpack2x16float(u32(logits[rowIdx + col]));
|
|
53
|
-
let subExp = exp(value - threadMax);
|
|
54
|
-
threadSum += subExp.x + subExp.y;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
threadSum = subgroupAdd(threadSum);
|
|
58
|
-
${t ? "\n if (lane == 0) {\n bestValues[localId.x / subgroupSize] = threadSum;\n }\n workgroupBarrier();\n threadSum = select(0.0f, bestValues[lane], lane < numSubgroups);\n threadSum = subgroupAdd(threadSum); \n " : ""}
|
|
59
|
-
|
|
60
|
-
for (var col = tid; col < cols; col += ${t ? "i32(subgroupSize)" : "blockSize"}) {
|
|
61
|
-
let value = unpack2x16float(u32(logits[rowIdx + col]));
|
|
62
|
-
let valuePair: vec2<f32> = exp(value - threadMax) / threadSum;
|
|
63
|
-
result[rowIdx + col] = i32(pack2x16float(valuePair));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
export { n as default };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
-
import { ReduceProgram as t, createReduceInfo as n, reduce as r } from "./utils/reductions.js";
|
|
3
|
-
import { isPackedTensor as i } from "../../utilities/packed.js";
|
|
4
|
-
import a from "./utils/deviceInfo.js";
|
|
5
|
-
// lib/ops/webgpu/softmax16grad.ts
|
|
6
|
-
var o = class extends t {
|
|
7
|
-
constructor(e, t) {
|
|
8
|
-
super(e, t, {
|
|
9
|
-
reductionOp: "sum",
|
|
10
|
-
elementwise: !0
|
|
11
|
-
}, !0), this.shaderKey = "SoftmaxGrad16", this.variableNames = ["dy", "softmaxOutput"], this.variableComponents = [1, 1];
|
|
12
|
-
}
|
|
13
|
-
getReadSnippet() {
|
|
14
|
-
return "\n let d: vec2<f32> = unpack2x16float(u32(dy[index]));\n let l: vec2<f32> = unpack2x16float(u32(softmaxOutput[index]));\n return d * l;\n ";
|
|
15
|
-
}
|
|
16
|
-
getWriteSnippet() {
|
|
17
|
-
return "\n let d: vec2<f32> = unpack2x16float(u32(dy[offset + k]));\n let l: vec2<f32> = unpack2x16float(u32(softmaxOutput[offset + k]));\n let outVal = l * (d - bestValue);\n result[offset + k] = i32(pack2x16float(outVal));\n ";
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
function s(e) {
|
|
21
|
-
let { dy: t, softmaxOutput: s } = e.inputs, c = e.backend, l = a(c), u = i(t), d = i(s);
|
|
22
|
-
if (!(u && d)) throw Error("softmaxGradGPU: dy and softmaxOutput must be packed tensors");
|
|
23
|
-
let f = [t, s], p = new o(l, n(f, -1));
|
|
24
|
-
return r(p, f, c);
|
|
25
|
-
}
|
|
26
|
-
e({
|
|
27
|
-
kernelName: "Softmax16Grad",
|
|
28
|
-
backendName: "webgpu",
|
|
29
|
-
kernelFunc: s
|
|
30
|
-
});
|
package/dist/ops/webgpu/sub16.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
-
import { t } from "../../binary_op_util-WY9YIl0q.js";
|
|
3
|
-
import { BinaryOpProgram as n } from "./utils/binary_op.js";
|
|
4
|
-
// lib/ops/webgpu/sub16.ts
|
|
5
|
-
function r(e) {
|
|
6
|
-
let { a: r, b: i } = e.inputs, a = e.backend, o = new n(t.SUB, r.shape, i.shape);
|
|
7
|
-
return a.runWebGPUProgram(o, [r, i], "packedF16");
|
|
8
|
-
}
|
|
9
|
-
e({
|
|
10
|
-
kernelName: "Sub16",
|
|
11
|
-
backendName: "webgpu",
|
|
12
|
-
kernelFunc: r
|
|
13
|
-
});
|
package/dist/ops/webgpu/sum16.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ReduceProgram as e, createReduceInfo as t, reduce as n } from "./utils/reductions.js";
|
|
2
|
-
import { o as r } from "../../axis_util-rF9RnwKE.js";
|
|
3
|
-
import { t as i } from "../../sum-C8qNbFNp.js";
|
|
4
|
-
import { Ui as a, xt as o } from "../../dist-CMMLi-qO.js";
|
|
5
|
-
import { isPackedTensor as s } from "../../utilities/packed.js";
|
|
6
|
-
import { transpose16 as c } from "../transpose16.js";
|
|
7
|
-
import l from "./utils/deviceInfo.js";
|
|
8
|
-
// lib/ops/webgpu/sum16.ts
|
|
9
|
-
var u = class extends e {
|
|
10
|
-
shaderKey = "sum16";
|
|
11
|
-
constructor(e, t, n) {
|
|
12
|
-
super(e, t, {
|
|
13
|
-
reductionOp: "sum",
|
|
14
|
-
elementwise: !1
|
|
15
|
-
}, n), n && (this.shaderKey += "_packed");
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
function d(e) {
|
|
19
|
-
let { x: o } = e.inputs, { axis: d, keepDims: f } = e.attrs, p = e.backend, m = [], h = l(p), g = s(o);
|
|
20
|
-
if (!g) return i(o, d, f);
|
|
21
|
-
let _ = a(d ?? -1, o.shape), v = r(_, o.shape.length), y = o;
|
|
22
|
-
v != null && (y = c(o, v), m.push(y));
|
|
23
|
-
let b = new u(h, t([y], -1), g), x = n(b, [y], p);
|
|
24
|
-
return m.forEach((e) => e.dispose()), x;
|
|
25
|
-
}
|
|
26
|
-
o({
|
|
27
|
-
kernelName: "Sum16",
|
|
28
|
-
backendName: "webgpu",
|
|
29
|
-
kernelFunc: d
|
|
30
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { isPackedTensor as e } from "../../utilities/packed.js";
|
|
2
|
-
import { t } from "../../transpose-BC-M_OoT.js";
|
|
3
|
-
import { H as n, xt as r } from "../../dist-CMMLi-qO.js";
|
|
4
|
-
import { reshape16 as i } from "../reshape16.js";
|
|
5
|
-
import a from "./transpose16_shared_program.js";
|
|
6
|
-
import o from "./transpose16_program.js";
|
|
7
|
-
// lib/ops/webgpu/transpose16.ts
|
|
8
|
-
function s(r) {
|
|
9
|
-
let { inputs: s, attrs: c } = r, { x: l } = s, { perm: u } = c, d = r.backend, f = e(l);
|
|
10
|
-
if (f && u[u.length - 1] !== l.shape.length - 1) {
|
|
11
|
-
let e = l.shape.length, t = e === 4 ? u.map((e) => e - 1).filter((e) => e >= 0) : u, r = e === 4 ? i(l, [
|
|
12
|
-
l.shape[0] * l.shape[1],
|
|
13
|
-
l.shape[2],
|
|
14
|
-
l.shape[3]
|
|
15
|
-
]) : l, o = new a(r.shape, t), s = d.runWebGPUProgram(o, [r], "packedF16");
|
|
16
|
-
if (e === 4) {
|
|
17
|
-
r.dispose();
|
|
18
|
-
let e = n().makeTensorFromTensorInfo(s), t = i(e, [
|
|
19
|
-
l.shape[0],
|
|
20
|
-
l.shape[1],
|
|
21
|
-
s.shape[1],
|
|
22
|
-
s.shape[2]
|
|
23
|
-
]);
|
|
24
|
-
return e.dispose(), t;
|
|
25
|
-
}
|
|
26
|
-
return s;
|
|
27
|
-
}
|
|
28
|
-
if (f) {
|
|
29
|
-
let e = new o(l.shape, u);
|
|
30
|
-
return d.runWebGPUProgram(e, [l], "packedF16");
|
|
31
|
-
}
|
|
32
|
-
return t(l, u);
|
|
33
|
-
}
|
|
34
|
-
r({
|
|
35
|
-
kernelName: "Transpose16",
|
|
36
|
-
backendName: "webgpu",
|
|
37
|
-
kernelFunc: s
|
|
38
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { c as e, i as t } from "../../webgpu_util-5QTyovaf.js";
|
|
2
|
-
import { i as n, o as r, s as i } from "../../webgpu_program-DvkFqRlR.js";
|
|
3
|
-
// lib/ops/webgpu/transpose16_program.ts
|
|
4
|
-
function a(e) {
|
|
5
|
-
let t = e.length;
|
|
6
|
-
if (t > 6) throw Error(`Transpose for rank ${t} is not yet supported`);
|
|
7
|
-
let n = Array(t);
|
|
8
|
-
for (let t = 0; t < e.length; t++) n[e[t]] = `coords.${r(t)}`;
|
|
9
|
-
return n.join();
|
|
10
|
-
}
|
|
11
|
-
var o = class {
|
|
12
|
-
variableNames = ["A"];
|
|
13
|
-
shaderKey;
|
|
14
|
-
outputShape;
|
|
15
|
-
dispatchLayout;
|
|
16
|
-
dispatch;
|
|
17
|
-
workPerThread = 1;
|
|
18
|
-
workgroupSize = [
|
|
19
|
-
64,
|
|
20
|
-
1,
|
|
21
|
-
1
|
|
22
|
-
];
|
|
23
|
-
newDim;
|
|
24
|
-
size = !0;
|
|
25
|
-
constructor(n, r) {
|
|
26
|
-
let i = Array(n.length);
|
|
27
|
-
for (let e = 0; e < i.length; e++) i[e] = n[r[e]];
|
|
28
|
-
this.outputShape = i, this.dispatchLayout = e(this.outputShape), this.dispatch = t(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
29
|
-
this.workPerThread,
|
|
30
|
-
1,
|
|
31
|
-
1
|
|
32
|
-
]), this.newDim = r, this.shaderKey = `transpose16_${r}`;
|
|
33
|
-
}
|
|
34
|
-
getUserCode() {
|
|
35
|
-
let e = n(this.outputShape.length), t = a(this.newDim);
|
|
36
|
-
return `
|
|
37
|
-
${i("index")} {
|
|
38
|
-
for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
|
|
39
|
-
let flatIndex = index * ${this.workPerThread} + i;
|
|
40
|
-
if(flatIndex < uniforms.size) {
|
|
41
|
-
let coords = getCoordsFromIndex(flatIndex);
|
|
42
|
-
result[flatIndex] = A[getIndexFromCoords${this.outputShape.length}D(
|
|
43
|
-
${e}(${t}), uniforms.aShape)];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
`;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
export { o as default };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { i as e } from "../../webgpu_util-5QTyovaf.js";
|
|
2
|
-
import { s as t } from "../../webgpu_program-DvkFqRlR.js";
|
|
3
|
-
import { yi as n } from "../../dist-CMMLi-qO.js";
|
|
4
|
-
// lib/ops/webgpu/transpose16_shared_program.ts
|
|
5
|
-
var r = class {
|
|
6
|
-
variableNames = ["A"];
|
|
7
|
-
outputShape;
|
|
8
|
-
shaderKey;
|
|
9
|
-
dispatchLayout;
|
|
10
|
-
dispatch;
|
|
11
|
-
workgroupSize = [
|
|
12
|
-
8,
|
|
13
|
-
8,
|
|
14
|
-
1
|
|
15
|
-
];
|
|
16
|
-
constructor(t, n) {
|
|
17
|
-
let r = t.length, i = Array(r), a = t.slice();
|
|
18
|
-
a[a.length - 1] *= 2;
|
|
19
|
-
for (let e = 0; e < i.length; e++) i[e] = a[n[e]];
|
|
20
|
-
i[i.length - 1] /= 2, this.outputShape = i, this.dispatchLayout = r === 2 ? {
|
|
21
|
-
x: [0],
|
|
22
|
-
y: [1]
|
|
23
|
-
} : {
|
|
24
|
-
x: [1],
|
|
25
|
-
y: [2],
|
|
26
|
-
z: [0]
|
|
27
|
-
}, this.dispatch = e(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
28
|
-
2,
|
|
29
|
-
1,
|
|
30
|
-
1
|
|
31
|
-
]), this.shaderKey = `transposeShared16_${r}`;
|
|
32
|
-
}
|
|
33
|
-
getUserCode() {
|
|
34
|
-
let e = this.outputShape.length;
|
|
35
|
-
n(this.workgroupSize[0] === this.workgroupSize[1], () => `Must be a square tile, current tile shape is ${this.workgroupSize[0]} x ${this.workgroupSize[1]}`);
|
|
36
|
-
let r = this.workgroupSize[0] * 2;
|
|
37
|
-
return `
|
|
38
|
-
var<workgroup> tile : array<array<f32, ${r + 1}>, ${r}>;
|
|
39
|
-
${t()} {
|
|
40
|
-
var x = i32(workgroupId.x) * ${r / 2} + i32(localId.x);
|
|
41
|
-
var y = i32(workgroupId.y) * ${r} + i32(localId.y);
|
|
42
|
-
let batch = ${e === 3 ? "i32(workgroupId.z)" : "0"};
|
|
43
|
-
let batchOffsetA = ${e === 3 ? "batch * uniforms.aShapeStrides[0]" : "0"};
|
|
44
|
-
let batchOffsetOut = ${e === 3 ? "batch * uniforms.outShapeStrides[0]" : "0"};
|
|
45
|
-
|
|
46
|
-
let inputWidth = uniforms.outShape[${e === 3 ? "1" : "0"}] / 2; // Output height
|
|
47
|
-
let inputHeight = uniforms.outShape[${e === 3 ? "2" : "1"}] * 2; // Output width
|
|
48
|
-
if (x < inputWidth && y < inputHeight) {
|
|
49
|
-
let unpackedA = unpack2x16float(u32(A[batchOffsetA + y * inputWidth + x]));
|
|
50
|
-
tile[localId.y][localId.x * 2] = unpackedA.x;
|
|
51
|
-
tile[localId.y][localId.x * 2 + 1] = unpackedA.y;
|
|
52
|
-
}
|
|
53
|
-
// Second load to cover the tile
|
|
54
|
-
y = y + ${this.workgroupSize[0]};
|
|
55
|
-
if (x < inputWidth && y < inputHeight) {
|
|
56
|
-
let unpackedA = unpack2x16float(u32(A[batchOffsetA + y * inputWidth + x]));
|
|
57
|
-
tile[localId.y + ${this.workgroupSize[0]}][localId.x * 2] = unpackedA.x;
|
|
58
|
-
tile[localId.y + ${this.workgroupSize[0]}][localId.x * 2 + 1] = unpackedA.y;
|
|
59
|
-
}
|
|
60
|
-
workgroupBarrier();
|
|
61
|
-
|
|
62
|
-
let outputWidth = uniforms.outShape[${e === 3 ? "2" : "1"}]; // Output width
|
|
63
|
-
let outputHeight = uniforms.outShape[${e === 3 ? "1" : "0"}] * 2; // Output height
|
|
64
|
-
x = i32(workgroupId.y) * ${r / 2} + i32(localId.x);
|
|
65
|
-
y = i32(workgroupId.x) * ${r} + i32(localId.y);
|
|
66
|
-
if (x < outputWidth && y < outputHeight) {
|
|
67
|
-
result[batchOffsetOut + y * outputWidth + x] = i32(pack2x16float(vec2<f32>(tile[localId.x * 2][localId.y], tile[localId.x * 2 + 1][localId.y])));
|
|
68
|
-
}
|
|
69
|
-
// Second store to cover the tile
|
|
70
|
-
y = y + ${this.workgroupSize[0]};
|
|
71
|
-
if (x < outputWidth && y < outputHeight) {
|
|
72
|
-
result[batchOffsetOut + y * outputWidth + x] = i32(pack2x16float(vec2<f32>(tile[localId.x * 2][localId.y + ${this.workgroupSize[0]}], tile[localId.x * 2 + 1][localId.y + ${this.workgroupSize[0]}])));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
export { r as default };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { c as e, i as t } from "../../webgpu_util-5QTyovaf.js";
|
|
2
|
-
import { s as n } from "../../webgpu_program-DvkFqRlR.js";
|
|
3
|
-
import { xt as r } from "../../dist-CMMLi-qO.js";
|
|
4
|
-
// lib/ops/webgpu/unpack16.ts
|
|
5
|
-
var i = class {
|
|
6
|
-
outputShape;
|
|
7
|
-
shaderKey = "Unpack16";
|
|
8
|
-
dispatchLayout;
|
|
9
|
-
dispatch;
|
|
10
|
-
workgroupSize = [
|
|
11
|
-
64,
|
|
12
|
-
1,
|
|
13
|
-
1
|
|
14
|
-
];
|
|
15
|
-
variableNames = ["x"];
|
|
16
|
-
size = !0;
|
|
17
|
-
uniforms;
|
|
18
|
-
outputComponent = 4;
|
|
19
|
-
variableComponents = [2];
|
|
20
|
-
scaling = !1;
|
|
21
|
-
constructor(n) {
|
|
22
|
-
this.outputShape = [...n.slice(0, -1), n[n.length - 1] * 2], this.dispatchLayout = e(this.outputShape), this.dispatch = t(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
23
|
-
4,
|
|
24
|
-
1,
|
|
25
|
-
1
|
|
26
|
-
]);
|
|
27
|
-
}
|
|
28
|
-
useScaling() {
|
|
29
|
-
this.shaderKey += "_Scaled", this.uniforms = "scaling : f32,", this.scaling = !0;
|
|
30
|
-
}
|
|
31
|
-
getUserCode() {
|
|
32
|
-
return `
|
|
33
|
-
${n("index")} {
|
|
34
|
-
let outIndex = index;
|
|
35
|
-
if (outIndex < uniforms.size) {
|
|
36
|
-
let xvec2 = x[index];
|
|
37
|
-
let v1 = vec4<f32>(
|
|
38
|
-
unpack2x16float(u32(xvec2.x)),
|
|
39
|
-
unpack2x16float(u32(xvec2.y))
|
|
40
|
-
) ${this.scaling ? "* uniforms.scaling" : ""};
|
|
41
|
-
result[outIndex] = v1;
|
|
42
|
-
}
|
|
43
|
-
}`;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function a(e) {
|
|
47
|
-
let { x: t } = e.inputs, { scaling: n } = e.attrs, r = e.backend, a = new i(t.shape), o = n !== 1;
|
|
48
|
-
o && a.useScaling();
|
|
49
|
-
let s = [{
|
|
50
|
-
type: "float32",
|
|
51
|
-
data: [1 / n]
|
|
52
|
-
}];
|
|
53
|
-
return r.runWebGPUProgram(a, [t], "float32", o ? s : void 0);
|
|
54
|
-
}
|
|
55
|
-
r({
|
|
56
|
-
kernelName: "Unpack16",
|
|
57
|
-
backendName: "webgpu",
|
|
58
|
-
kernelFunc: a
|
|
59
|
-
});
|