@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
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./eventemitter3-wmfmOP_f.js";
|
|
2
|
-
import t from "./tokeniser/CharTokeniser.js";
|
|
3
|
-
import { Q as n, W as r, Y as i, Z as a, b as o, ir as s, rt as c } from "./dist-CMMLi-qO.js";
|
|
4
|
-
import { t as l } from "./reshape-DJb1jgMt.js";
|
|
5
|
-
import { t as u } from "./concat-Oip5acVY.js";
|
|
6
|
-
import { t as d } from "./gather-B5Z1RFt5.js";
|
|
7
|
-
import { t as f } from "./pad-Dy-1IP3A.js";
|
|
8
|
-
import { t as p } from "./softmax-Dpav_dWw.js";
|
|
9
|
-
import { t as m } from "./tensor2d-ARItvqVn.js";
|
|
10
|
-
import { t as h } from "./topk-BrU2pkrR.js";
|
|
11
|
-
import g from "./utilities/multinomialCPU.js";
|
|
12
|
-
import _ from "./utilities/topP.js";
|
|
13
|
-
import { sparseSoftmaxCrossEntropy as v } from "./training/sparseCrossEntropy.js";
|
|
14
|
-
import y, { tensorFromTokens as b } from "./inference/tokenisePrompt.js";
|
|
15
|
-
import { CHARS as x, getTokenConfidence as S, padArray as C } from "./inference/utilities.js";
|
|
16
|
-
// node_modules/@tensorflow/tfjs-core/dist/ops/multinomial.js
|
|
17
|
-
function w(e, t, r, i = !1) {
|
|
18
|
-
let a = n(e, "logits", "multinomial"), o = a.size, u = a.rank;
|
|
19
|
-
if (o < 2) throw Error(`Error in multinomial: you need at least 2 outcomes, but got ${o}.`);
|
|
20
|
-
if (u > 2) throw Error(`Rank of probabilities must be 1 or 2, but is ${u}`);
|
|
21
|
-
r ||= Math.random();
|
|
22
|
-
let d = { logits: u === 1 ? l(a, [1, -1]) : a }, f = {
|
|
23
|
-
numSamples: t,
|
|
24
|
-
seed: r,
|
|
25
|
-
normalized: i
|
|
26
|
-
}, p = c.runKernel(s, d, f);
|
|
27
|
-
return u === 1 ? l(p, [p.size]) : p;
|
|
28
|
-
}
|
|
29
|
-
var T = /* @__PURE__ */ a({ multinomial_: w });
|
|
30
|
-
// lib/inference/Generator.ts
|
|
31
|
-
function E(e) {
|
|
32
|
-
return Array.isArray(e);
|
|
33
|
-
}
|
|
34
|
-
var D = class extends e {
|
|
35
|
-
model;
|
|
36
|
-
tokeniser;
|
|
37
|
-
active = !1;
|
|
38
|
-
cache = null;
|
|
39
|
-
initialPrompt = null;
|
|
40
|
-
outputConversation = [];
|
|
41
|
-
actualTokeniser;
|
|
42
|
-
lastToken = -1;
|
|
43
|
-
lastLoss = null;
|
|
44
|
-
rawOutput = [];
|
|
45
|
-
jobQueue = [];
|
|
46
|
-
processingJob = !1;
|
|
47
|
-
startTime = null;
|
|
48
|
-
tokenCount = 0;
|
|
49
|
-
constructor(e, t) {
|
|
50
|
-
super(), this.model = e, this.tokeniser = t, this.actualTokeniser = t;
|
|
51
|
-
}
|
|
52
|
-
shouldTerminate(e, t) {
|
|
53
|
-
if (e) return !1;
|
|
54
|
-
let n = this.tokeniser.getSpecialTokenIndex("<|assistant_end|>");
|
|
55
|
-
return t === this.actualTokeniser.eosToken || t === n;
|
|
56
|
-
}
|
|
57
|
-
async _generateToken(e, t, n) {
|
|
58
|
-
let a = n?.temperature ?? 1, s = n?.topK, c = n?.topP, l = n?.usePadding ?? !1, u = {
|
|
59
|
-
training: !1,
|
|
60
|
-
attentionScores: n?.outputAttention ? { attentionOut: [] } : void 0,
|
|
61
|
-
cache: t,
|
|
62
|
-
outputEmbeddings: !!n?.outputHiddenStates,
|
|
63
|
-
mixedPrecision: !1
|
|
64
|
-
}, [y, b] = i(() => {
|
|
65
|
-
let t = e, i = t.shape[1], o = i <= this.model.config.blockSize ? t : t.slice([0, i - this.model.config.blockSize], [t.shape[0], this.model.config.blockSize]), s = l ? this.model.config.blockSize - o.shape[1] : 0, c = s > 0 ? f(o, [[0, 0], [0, s]]) : o, d = this.model.forward(u, c), p = d.shape[1] - 1 - s, h = d.slice([
|
|
66
|
-
0,
|
|
67
|
-
p,
|
|
68
|
-
0
|
|
69
|
-
], [
|
|
70
|
-
d.shape[0],
|
|
71
|
-
1,
|
|
72
|
-
d.shape[2]
|
|
73
|
-
]), g;
|
|
74
|
-
if (n?.targets) {
|
|
75
|
-
let e = n.targets.shift();
|
|
76
|
-
if (e !== void 0) {
|
|
77
|
-
let t = m([[e]], [1, 1], "int32"), n = v(h, t);
|
|
78
|
-
g = n.mean(), t.dispose(), n.dispose();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return u.attentionScores?.attentionOut && u.attentionScores.attentionOut.forEach((e, t) => {
|
|
82
|
-
e.shape[1] !== 1 && (u.attentionScores.attentionOut[t] = r(e.slice([
|
|
83
|
-
0,
|
|
84
|
-
p,
|
|
85
|
-
0
|
|
86
|
-
], [
|
|
87
|
-
e.shape[0],
|
|
88
|
-
1,
|
|
89
|
-
e.shape[2]
|
|
90
|
-
])), e.dispose());
|
|
91
|
-
}), d.dispose(), [h.div(a).squeeze([1]), g];
|
|
92
|
-
}), x, C, w, E, D = Math.random(), O = n?.rescore ?? !1;
|
|
93
|
-
if (O) {
|
|
94
|
-
let e = p(y), t = await e.array();
|
|
95
|
-
e.dispose();
|
|
96
|
-
let n = this.rawOutput[this.tokenCount];
|
|
97
|
-
if (!n) return null;
|
|
98
|
-
w = t, C = n.token, x = o(n.token, "int32");
|
|
99
|
-
} else if (c) {
|
|
100
|
-
let e = p(y), t = await e.array();
|
|
101
|
-
e.dispose();
|
|
102
|
-
let r = _(t, c);
|
|
103
|
-
(n?.outputScores || n?.outputConfidence || n?.outputScore) && (w = t), C = g(r, D), x = o(C, "int32");
|
|
104
|
-
} else if (s) {
|
|
105
|
-
let { values: e, indices: t } = h(y, s), r = s === 1 ? o(0, "int32") : T(e, 1);
|
|
106
|
-
if (x = d(t, r, 1), n?.outputScores || n?.outputConfidence || n?.outputScore) {
|
|
107
|
-
let e = p(y), t = await e.array();
|
|
108
|
-
e.dispose(), w = t;
|
|
109
|
-
}
|
|
110
|
-
e.dispose(), t.dispose(), r.dispose();
|
|
111
|
-
} else if (x = T(y, 1), n?.outputScores || n?.outputConfidence) {
|
|
112
|
-
let e = p(y);
|
|
113
|
-
w = await e.array(), e.dispose();
|
|
114
|
-
}
|
|
115
|
-
if (u.embeddings) {
|
|
116
|
-
let e = (n?.outputHiddenStates === "all" ? u.embeddings : u.embeddings.filter((e) => e.name.startsWith("block_output_"))).map(async (e) => {
|
|
117
|
-
let t = e.tensor.shape[1], r = e.tensor.slice([
|
|
118
|
-
0,
|
|
119
|
-
t - 1,
|
|
120
|
-
0
|
|
121
|
-
], [
|
|
122
|
-
e.tensor.shape[0],
|
|
123
|
-
1,
|
|
124
|
-
e.tensor.shape[2]
|
|
125
|
-
]);
|
|
126
|
-
e.tensor.dispose();
|
|
127
|
-
let i = r.squeeze([1]);
|
|
128
|
-
if (r.dispose(), n?.outputHiddenStates === "softmax") {
|
|
129
|
-
let t = this.model.project(i);
|
|
130
|
-
i.dispose();
|
|
131
|
-
let n = p(t, -1);
|
|
132
|
-
t.dispose();
|
|
133
|
-
let r = {
|
|
134
|
-
name: e.name,
|
|
135
|
-
tensor: await n.array()
|
|
136
|
-
};
|
|
137
|
-
return n.dispose(), r;
|
|
138
|
-
}
|
|
139
|
-
if (n?.outputHiddenStates === "logits") {
|
|
140
|
-
let t = this.model.project(i);
|
|
141
|
-
i.dispose();
|
|
142
|
-
let n = {
|
|
143
|
-
name: e.name,
|
|
144
|
-
tensor: await t.array()
|
|
145
|
-
};
|
|
146
|
-
return t.dispose(), n;
|
|
147
|
-
}
|
|
148
|
-
{
|
|
149
|
-
let t = await i.array();
|
|
150
|
-
return i.dispose(), {
|
|
151
|
-
name: e.name,
|
|
152
|
-
tensor: t
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
E = await Promise.all(e);
|
|
157
|
-
}
|
|
158
|
-
let k = x.reshape([1, 1]);
|
|
159
|
-
x.dispose(), x = k;
|
|
160
|
-
let A = C === void 0 ? (await x.array())[0][0] : C, j = this.actualTokeniser.decode([A]);
|
|
161
|
-
this.lastToken = A;
|
|
162
|
-
let M = this.shouldTerminate(n?.allowSpecial ?? !1, A), N;
|
|
163
|
-
if (!O) N = {
|
|
164
|
-
outputTensor: x,
|
|
165
|
-
token: A,
|
|
166
|
-
text: j,
|
|
167
|
-
confidence: n?.outputConfidence && w ? S(w[0]) : null,
|
|
168
|
-
score: n?.outputScore && w ? w[0][A] : null,
|
|
169
|
-
logits: n?.outputLogits ? (await y.array())[0] : null,
|
|
170
|
-
scores: n?.outputScores && w ? w[0] : null,
|
|
171
|
-
hiddenStates: E ? E.map((e) => e.tensor[0]) : null,
|
|
172
|
-
attention: n?.outputAttention ? await Promise.all(u.attentionScores?.attentionOut?.map((e) => e.array()) ?? []) : null,
|
|
173
|
-
loss: this.lastLoss,
|
|
174
|
-
multinomialRand: D,
|
|
175
|
-
terminated: M
|
|
176
|
-
}, this.rawOutput.push(N);
|
|
177
|
-
else if (N = this.rawOutput[this.tokenCount], N.outputTensor = x, N.rescore = w ? w[0][A] : void 0, !N) throw Error(`No raw output found for token index ${this.tokenCount}`);
|
|
178
|
-
if (y.dispose(), b) {
|
|
179
|
-
let e = await b.array();
|
|
180
|
-
b.dispose(), N.loss = e;
|
|
181
|
-
}
|
|
182
|
-
return n?.chunkSize && this.tokenCount % n.chunkSize !== 0 || (this.emit("tokens", N), n?._onChunk && await n._onChunk(N)), this.tokenCount++, N;
|
|
183
|
-
}
|
|
184
|
-
async _generate(e, t) {
|
|
185
|
-
let n = !1;
|
|
186
|
-
if (e?.rescore && this.outputConversation.length > 0) {
|
|
187
|
-
let e = this.outputConversation.pop();
|
|
188
|
-
if (!e || !e._output) throw Error("No raw output found for the last conversation entry");
|
|
189
|
-
this.rawOutput = e?._output;
|
|
190
|
-
}
|
|
191
|
-
this.outputConversation.length === 0 || this.outputConversation[this.outputConversation.length - 1]._completed || this.outputConversation[this.outputConversation.length - 1].role !== "assistant" && e?.nonConversational !== !0 || this.outputConversation[this.outputConversation.length - 1].role !== "text" && e?.nonConversational === !0 ? (this.outputConversation.push({
|
|
192
|
-
role: e?.nonConversational === !0 ? "text" : "assistant",
|
|
193
|
-
content: "",
|
|
194
|
-
_timestamp: Date.now()
|
|
195
|
-
}), n = !0, this.resetCache(!e?.noCache)) : (this.lastToken < 0 || t) && this.resetCache(!e?.noCache);
|
|
196
|
-
let r = this.outputConversation[this.outputConversation.length - 1];
|
|
197
|
-
r.content.length > 0 && (!r._output || r._output.length === 0) && (r._output = this.actualTokeniser.encode(r.content).map((e) => ({
|
|
198
|
-
token: e,
|
|
199
|
-
text: this.actualTokeniser.decode([e]),
|
|
200
|
-
confidence: 1,
|
|
201
|
-
score: 1,
|
|
202
|
-
logits: null,
|
|
203
|
-
hiddenStates: null,
|
|
204
|
-
scores: null,
|
|
205
|
-
attention: null,
|
|
206
|
-
loss: null,
|
|
207
|
-
multinomialRand: null,
|
|
208
|
-
terminated: !1
|
|
209
|
-
})));
|
|
210
|
-
let i = this.lastToken >= 0 && this.cache ? m([this.lastToken], [1, 1], "int32") : b(await y(this.actualTokeniser, this.model.config.blockSize, t ? n ? this.outputConversation.slice(0, -1) : this.outputConversation : void 0, n ? e : {
|
|
211
|
-
...e,
|
|
212
|
-
continuation: !0
|
|
213
|
-
})), a = e?.maxLength ?? 1e3;
|
|
214
|
-
for (let t = 0; t < a && this.active; t++) {
|
|
215
|
-
let n = await this._generateToken(i, this.cache ? this.cache : void 0, {
|
|
216
|
-
...e,
|
|
217
|
-
usePadding: !this.cache
|
|
218
|
-
}), r = this.outputConversation[this.outputConversation.length - 1];
|
|
219
|
-
if (!n) {
|
|
220
|
-
r._completed = !0;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
if (this.cache) i.dispose(), i = n.outputTensor;
|
|
224
|
-
else {
|
|
225
|
-
let e = i;
|
|
226
|
-
i = u([i, n.outputTensor], 1), e.dispose();
|
|
227
|
-
}
|
|
228
|
-
if (this.cache || n.outputTensor.dispose(), n.terminated) {
|
|
229
|
-
r._completed = !0;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
t === a - 1 && a > 1 && (r._completed = !0, n.terminated = !0), r.content += n.text, r._output ||= [], r._output.push(n);
|
|
233
|
-
}
|
|
234
|
-
return i.dispose(), this.outputConversation;
|
|
235
|
-
}
|
|
236
|
-
resetCache(e) {
|
|
237
|
-
this.cache && (this.cache.forEach((e) => {
|
|
238
|
-
e && (e.k && e.k.dispose(), e.v && e.v.dispose(), e.k = void 0, e.v = void 0, e.cumulativeLength = 0, e.length = 0);
|
|
239
|
-
}), e || (this.cache = null)), this.lastToken = -1;
|
|
240
|
-
}
|
|
241
|
-
reset() {
|
|
242
|
-
this.resetCache(), this.outputConversation = [], this.initialPrompt = null, this.rawOutput = [], this.lastLoss = null, this.emit("reset");
|
|
243
|
-
}
|
|
244
|
-
dispose() {
|
|
245
|
-
this.reset();
|
|
246
|
-
}
|
|
247
|
-
initialise(e, n) {
|
|
248
|
-
if (this.cache && n?.noCache && this.reset(), this.initialPrompt = e || null, this.lastToken === -1 && this.outputConversation.length === 0 ? this.outputConversation = this.initialPrompt || [] : e && e.length > 0 && (e.forEach((e) => {
|
|
249
|
-
this.outputConversation.push(e);
|
|
250
|
-
}), this.resetCache()), !this.cache && !n?.noCache && (this.model.config.modelType !== "GenAI_NanoGPT_v1" || this.model.config.useRope)) {
|
|
251
|
-
let e = Array(this.model.config.nLayer);
|
|
252
|
-
for (let t = 0; t < this.model.config.nLayer; t++) e[t] = {
|
|
253
|
-
k: void 0,
|
|
254
|
-
v: void 0,
|
|
255
|
-
length: 0,
|
|
256
|
-
cumulativeLength: 0
|
|
257
|
-
};
|
|
258
|
-
this.cache = e, this.lastToken = -1;
|
|
259
|
-
}
|
|
260
|
-
let r = this.tokeniser.trained ? this.tokeniser : new t(C(x, this.tokeniser.vocabSize));
|
|
261
|
-
this.actualTokeniser = r, n?.loraName ? this.model.attachLoRA(n.loraName) : this.model.hasLoRA() && this.model.detachLoRA();
|
|
262
|
-
}
|
|
263
|
-
async step(e, t) {
|
|
264
|
-
let n = {
|
|
265
|
-
...t,
|
|
266
|
-
maxLength: 1
|
|
267
|
-
};
|
|
268
|
-
return E(e) ? this.generate(e, n) : this.generate({
|
|
269
|
-
...e,
|
|
270
|
-
...n
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
async generate(e, t) {
|
|
274
|
-
let n;
|
|
275
|
-
if (Array.isArray(e) ? n = e : typeof e == "object" && (t = e), this.processingJob) {
|
|
276
|
-
if (this.jobQueue.length > 10) throw Error("Job queue is too long, rejecting new job");
|
|
277
|
-
return new Promise((e, r) => {
|
|
278
|
-
this.jobQueue.push({
|
|
279
|
-
prompt: n,
|
|
280
|
-
options: t,
|
|
281
|
-
resolve: e,
|
|
282
|
-
reject: r
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
this.processingJob = !0, this.startTime = Date.now();
|
|
287
|
-
try {
|
|
288
|
-
let e = await this.startJob(n, t);
|
|
289
|
-
if (this.processingJob = !1, this.jobQueue.length > 0) {
|
|
290
|
-
let e = this.jobQueue.shift();
|
|
291
|
-
this.generate(e.prompt || [], e.options).then(e.resolve).catch(e.reject);
|
|
292
|
-
}
|
|
293
|
-
return e;
|
|
294
|
-
} catch (e) {
|
|
295
|
-
throw this.processingJob = !1, e;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
async startJob(e, t) {
|
|
299
|
-
this.initialise(e, t), this.active = !0, this.model.metaData.generationSettings = t, t?.maxLength !== 1 && this.emit("start");
|
|
300
|
-
let n = await this._generate(t, !!e);
|
|
301
|
-
return this.active = !1, this.startTime !== null && (this.startTime = null), this.emit("stop"), n;
|
|
302
|
-
}
|
|
303
|
-
getQueueLength() {
|
|
304
|
-
return this.jobQueue.length;
|
|
305
|
-
}
|
|
306
|
-
stop() {
|
|
307
|
-
this.active = !1;
|
|
308
|
-
}
|
|
309
|
-
getConversation() {
|
|
310
|
-
return this.outputConversation;
|
|
311
|
-
}
|
|
312
|
-
getRawOutput() {
|
|
313
|
-
return this.rawOutput;
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
export { E as n, D as t };
|
package/dist/RealDiv-Cl8k3YTx.js
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { Ni as e, Ui as t, _i as n, ct as r, qi as i, xr as a } from "./dist-CMMLi-qO.js";
|
|
2
|
-
import { a as o, i as s, o as c, s as l, t as u } from "./axis_util-rF9RnwKE.js";
|
|
3
|
-
import { L as d } from "./backend_util-Cpp0Gwlp.js";
|
|
4
|
-
import { Z as f } from "./gpgpu_math-48m8q3jI.js";
|
|
5
|
-
import { b as p, n as m } from "./kernel_funcs_utils-BYRpSfV_.js";
|
|
6
|
-
import { t as h } from "./Reshape-CKxKPKqi.js";
|
|
7
|
-
import { J as g, b as _ } from "./shared-CX_iPI5K.js";
|
|
8
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/mean_gpu.js
|
|
9
|
-
var v = class {
|
|
10
|
-
constructor(t, n) {
|
|
11
|
-
this.variableNames = ["x"];
|
|
12
|
-
let { windowSize: r, batchSize: i, inSize: a, outSize: o } = t;
|
|
13
|
-
this.outputShape = [i, o];
|
|
14
|
-
let s = Math.floor(r / 4) * 4, c = r % 4, l = "sumValue += dot(values, ones);";
|
|
15
|
-
if (n != null) {
|
|
16
|
-
let t = 1 / n;
|
|
17
|
-
l = `sumValue += dot(values * ${e(t) ? t.toPrecision(2) : t}, ones);`;
|
|
18
|
-
}
|
|
19
|
-
let u = "";
|
|
20
|
-
a % r > 0 && (u = `
|
|
21
|
-
if (inIdx < 0 || inIdx >= ${a}) {
|
|
22
|
-
return 0.0;
|
|
23
|
-
}
|
|
24
|
-
`), this.userCode = `
|
|
25
|
-
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
26
|
-
|
|
27
|
-
float getValue(int batch, int inIdx) {
|
|
28
|
-
${u}
|
|
29
|
-
return getX(batch, inIdx);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
void main() {
|
|
33
|
-
ivec2 coords = getOutputCoords();
|
|
34
|
-
int batch = coords[0];
|
|
35
|
-
int outIdx = coords[1];
|
|
36
|
-
int inOffset = outIdx * ${r};
|
|
37
|
-
|
|
38
|
-
float sumValue = 0.0;
|
|
39
|
-
|
|
40
|
-
for (int i = 0; i < ${s}; i += 4) {
|
|
41
|
-
int inIdx = inOffset + i;
|
|
42
|
-
vec4 values = vec4(
|
|
43
|
-
getValue(batch, inIdx),
|
|
44
|
-
getValue(batch, inIdx + 1),
|
|
45
|
-
getValue(batch, inIdx + 2),
|
|
46
|
-
getValue(batch, inIdx + 3)
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
${l}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
int inIdx = inOffset + ${s};
|
|
53
|
-
if (${c === 1}) {
|
|
54
|
-
vec4 values = vec4(getValue(batch, inIdx), 0.0, 0.0, 0.0);
|
|
55
|
-
|
|
56
|
-
${l}
|
|
57
|
-
} else if (${c === 2}) {
|
|
58
|
-
vec4 values = vec4(
|
|
59
|
-
getValue(batch, inIdx),
|
|
60
|
-
getValue(batch, inIdx + 1), 0.0, 0.0);
|
|
61
|
-
|
|
62
|
-
${l}
|
|
63
|
-
} else if (${c === 3}) {
|
|
64
|
-
vec4 values = vec4(
|
|
65
|
-
getValue(batch, inIdx),
|
|
66
|
-
getValue(batch, inIdx + 1),
|
|
67
|
-
getValue(batch, inIdx + 2), 0.0);
|
|
68
|
-
|
|
69
|
-
${l}
|
|
70
|
-
}
|
|
71
|
-
setOutput(sumValue);
|
|
72
|
-
}
|
|
73
|
-
`;
|
|
74
|
-
}
|
|
75
|
-
}, y = class {
|
|
76
|
-
constructor(e, t) {
|
|
77
|
-
this.variableNames = ["x"];
|
|
78
|
-
let { windowSize: n, batchSize: r, inSize: i, outSize: a } = e;
|
|
79
|
-
this.outputShape = [r, a];
|
|
80
|
-
let o = "0.0", s = "";
|
|
81
|
-
t === "prod" ? o = "1.0" : t === "min" ? (o = "1.0 / 1e-20", s = "min") : t === "max" && (o = "-1.0 / 1e-20", s = "max");
|
|
82
|
-
let c = `${t}(${t}(${t}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`;
|
|
83
|
-
t === "sum" ? c = "sumValue" : t === "prod" ? c = "prodValue" : t === "all" ? c = "allValue" : t === "any" && (c = "anyValue");
|
|
84
|
-
let l = Math.floor(n / 4) * 4, u = n % 4, d = `
|
|
85
|
-
if (${t === "sum"}) {
|
|
86
|
-
sumValue += dot(values, ones);
|
|
87
|
-
} else if (${t === "prod"}) {
|
|
88
|
-
vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);
|
|
89
|
-
prodValue *= tmp[0] * tmp[1];
|
|
90
|
-
} else {
|
|
91
|
-
minMaxValue = ${s}(values, minMaxValue);
|
|
92
|
-
if (${t === "min"} || ${t === "max"}) {
|
|
93
|
-
minMaxValue = ${s}(values, minMaxValue);
|
|
94
|
-
bvec4 isNaN = isnan(values);
|
|
95
|
-
if (isNaN.r || isNaN.g || isNaN.b || isNaN.a) {
|
|
96
|
-
minMaxValue = vec4(NAN);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
`, f = "vec4";
|
|
101
|
-
t === "all" ? (o = "1.0", d = "\n bool reducedAllValue = all(values);\n float floatedReducedAllValue = float(reducedAllValue);\n allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);\n ", f = "bvec4") : t === "any" && (o = "0.0", d = "\n bool reducedAnyValue = any(values);\n float floatedReducedAnyValue = float(reducedAnyValue);\n anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);\n ", f = "bvec4");
|
|
102
|
-
let p = "";
|
|
103
|
-
i % n > 0 && (p = `
|
|
104
|
-
if (inIdx < 0 || inIdx >= ${i}) {
|
|
105
|
-
return initializationValue;
|
|
106
|
-
}
|
|
107
|
-
`), this.userCode = `
|
|
108
|
-
const float initializationValue = ${o};
|
|
109
|
-
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
110
|
-
|
|
111
|
-
float getValue(int batch, int inIdx) {
|
|
112
|
-
${p}
|
|
113
|
-
return getX(batch, inIdx);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
void main() {
|
|
117
|
-
ivec2 coords = getOutputCoords();
|
|
118
|
-
int batch = coords[0];
|
|
119
|
-
int outIdx = coords[1];
|
|
120
|
-
int inOffset = outIdx * ${n};
|
|
121
|
-
|
|
122
|
-
vec4 minMaxValue = vec4(${o});
|
|
123
|
-
float prodValue = 1.0;
|
|
124
|
-
float sumValue = 0.0;
|
|
125
|
-
float allValue = 1.0;
|
|
126
|
-
float anyValue = 0.0;
|
|
127
|
-
|
|
128
|
-
for (int i = 0; i < ${l}; i += 4) {
|
|
129
|
-
int inIdx = inOffset + i;
|
|
130
|
-
${f} values = ${f}(
|
|
131
|
-
getValue(batch, inIdx),
|
|
132
|
-
getValue(batch, inIdx + 1),
|
|
133
|
-
getValue(batch, inIdx + 2),
|
|
134
|
-
getValue(batch, inIdx + 3)
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
${d}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
int inIdx = inOffset + ${l};
|
|
141
|
-
if (${u === 1}) {
|
|
142
|
-
${f} values = ${f}(
|
|
143
|
-
getValue(batch, inIdx),
|
|
144
|
-
initializationValue,
|
|
145
|
-
initializationValue,
|
|
146
|
-
initializationValue
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
${d}
|
|
150
|
-
} else if (${u === 2}) {
|
|
151
|
-
${f} values = ${f}(
|
|
152
|
-
getValue(batch, inIdx),
|
|
153
|
-
getValue(batch, inIdx + 1),
|
|
154
|
-
initializationValue,
|
|
155
|
-
initializationValue
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
${d}
|
|
159
|
-
} else if (${u === 3}) {
|
|
160
|
-
${f} values = ${f}(
|
|
161
|
-
getValue(batch, inIdx),
|
|
162
|
-
getValue(batch, inIdx + 1),
|
|
163
|
-
getValue(batch, inIdx + 2),
|
|
164
|
-
initializationValue
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
${d}
|
|
168
|
-
}
|
|
169
|
-
setOutput(${c});
|
|
170
|
-
}
|
|
171
|
-
`;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernel_utils/reduce.js
|
|
175
|
-
function b(e) {
|
|
176
|
-
let t = [];
|
|
177
|
-
for (; t.length === 0 || t[t.length - 1].outSize !== 1;) {
|
|
178
|
-
let n = t.length ? t[t.length - 1].outSize : e[1], r = d(n);
|
|
179
|
-
t.push({
|
|
180
|
-
inSize: n,
|
|
181
|
-
windowSize: r,
|
|
182
|
-
outSize: Math.ceil(n / r)
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
return t;
|
|
186
|
-
}
|
|
187
|
-
function x(e, t, n, r) {
|
|
188
|
-
let i = b(e.shape), a = e;
|
|
189
|
-
for (let o = 0; o < i.length; o++) {
|
|
190
|
-
let { inSize: s, windowSize: c, outSize: l } = i[o], u, d;
|
|
191
|
-
u = n === "mean" ? o === 0 ? new v({
|
|
192
|
-
windowSize: c,
|
|
193
|
-
inSize: s,
|
|
194
|
-
batchSize: e.shape[0],
|
|
195
|
-
outSize: l
|
|
196
|
-
}, s) : new v({
|
|
197
|
-
windowSize: c,
|
|
198
|
-
inSize: s,
|
|
199
|
-
batchSize: e.shape[0],
|
|
200
|
-
outSize: l
|
|
201
|
-
}) : new y({
|
|
202
|
-
windowSize: c,
|
|
203
|
-
inSize: s,
|
|
204
|
-
batchSize: e.shape[0],
|
|
205
|
-
outSize: l
|
|
206
|
-
}, n), d = a, a = r.runWebGLProgram(u, [a], t), d.dataId !== e.dataId && r.disposeIntermediateTensorInfo(d);
|
|
207
|
-
}
|
|
208
|
-
return a;
|
|
209
|
-
}
|
|
210
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/transpose_gpu.js
|
|
211
|
-
var S = class {
|
|
212
|
-
constructor(e, t) {
|
|
213
|
-
this.variableNames = ["A"];
|
|
214
|
-
let n = Array(e.length);
|
|
215
|
-
for (let r = 0; r < n.length; r++) n[r] = e[t[r]];
|
|
216
|
-
this.outputShape = n, this.rank = n.length;
|
|
217
|
-
let r = f(this.rank), i = C(t);
|
|
218
|
-
this.userCode = `
|
|
219
|
-
void main() {
|
|
220
|
-
${r} resRC = getOutputCoords();
|
|
221
|
-
setOutput(getA(${i}));
|
|
222
|
-
}
|
|
223
|
-
`;
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
function C(e) {
|
|
227
|
-
let t = e.length;
|
|
228
|
-
if (t > 6) throw Error(`Transpose for rank ${t} is not yet supported`);
|
|
229
|
-
let n = [
|
|
230
|
-
"resRC.x",
|
|
231
|
-
"resRC.y",
|
|
232
|
-
"resRC.z",
|
|
233
|
-
"resRC.w",
|
|
234
|
-
"resRC.u",
|
|
235
|
-
"resRC.v"
|
|
236
|
-
], r = Array(t);
|
|
237
|
-
for (let t = 0; t < e.length; t++) r[e[t]] = n[t];
|
|
238
|
-
return r.join();
|
|
239
|
-
}
|
|
240
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/transpose_packed_gpu.js
|
|
241
|
-
var w = class {
|
|
242
|
-
constructor(e, t) {
|
|
243
|
-
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0;
|
|
244
|
-
let n = Array(e.length);
|
|
245
|
-
for (let r = 0; r < n.length; r++) n[r] = e[t[r]];
|
|
246
|
-
if (this.outputShape = n, this.rank = n.length, this.rank > 6) throw Error(`Packed transpose for rank ${this.rank} is not yet supported.`);
|
|
247
|
-
let r = f(this.rank), i = p("rc", this.rank), a = Array(this.rank);
|
|
248
|
-
for (let e = 0; e < t.length; e++) a[t[e]] = i[e];
|
|
249
|
-
let o = `vec2(${a.slice(-2).join()})`, s = `++${i[this.rank - 1]} < ${n[this.rank - 1]}`, c = `getChannel(getA(${a.join()}), ${o})`;
|
|
250
|
-
this.userCode = `
|
|
251
|
-
void main() {
|
|
252
|
-
${r} rc = getOutputCoords();
|
|
253
|
-
vec4 result = vec4(0.);
|
|
254
|
-
result[0] = ${c};
|
|
255
|
-
if(${s}) {
|
|
256
|
-
result[1] = ${c};
|
|
257
|
-
}
|
|
258
|
-
--${i[this.rank - 1]};
|
|
259
|
-
if(++${i[this.rank - 2]} < ${n[this.rank - 2]}) {
|
|
260
|
-
result[2] = ${c};
|
|
261
|
-
if(${s}) {
|
|
262
|
-
result[3] = ${c};
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
setOutput(result);
|
|
266
|
-
}
|
|
267
|
-
`;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Transpose_impl.js
|
|
271
|
-
function T(e, t, r) {
|
|
272
|
-
let i = n().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new w(e.shape, t) : new S(e.shape, t);
|
|
273
|
-
return r.runWebGLProgram(i, [e], e.dtype);
|
|
274
|
-
}
|
|
275
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Sum_impl.js
|
|
276
|
-
function E(e, n, a, d) {
|
|
277
|
-
let f = n, p = e.shape.length, m = t(f, e.shape), g = m, _ = c(g, p), v = _ != null, y = e;
|
|
278
|
-
v && (y = T(e, _, d), g = l(g.length, p)), u("sum", g, p);
|
|
279
|
-
let [b, S] = s(y.shape, g), C = b;
|
|
280
|
-
a && (C = o(b, m));
|
|
281
|
-
let w = i(S), E = i(e.shape) / w, D = h({
|
|
282
|
-
inputs: { x: y },
|
|
283
|
-
attrs: { shape: [E, w] },
|
|
284
|
-
backend: d
|
|
285
|
-
}), O = x(D, r(e.dtype), "sum", d), k = h({
|
|
286
|
-
inputs: { x: O },
|
|
287
|
-
attrs: { shape: C },
|
|
288
|
-
backend: d
|
|
289
|
-
});
|
|
290
|
-
return d.disposeIntermediateTensorInfo(D), d.disposeIntermediateTensorInfo(O), v && d.disposeIntermediateTensorInfo(y), k;
|
|
291
|
-
}
|
|
292
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Sum.js
|
|
293
|
-
function D(e) {
|
|
294
|
-
let { inputs: t, backend: n, attrs: r } = e, { x: i } = t, { axis: a, keepDims: o } = r;
|
|
295
|
-
return E(i, a, o, n);
|
|
296
|
-
}
|
|
297
|
-
var O = {
|
|
298
|
-
kernelName: "Sum",
|
|
299
|
-
backendName: "webgl",
|
|
300
|
-
kernelFunc: D
|
|
301
|
-
};
|
|
302
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Max_impl.js
|
|
303
|
-
function k(e, t, n, r) {
|
|
304
|
-
let a = i(t), o = i(e.shape) / a, s = h({
|
|
305
|
-
inputs: { x: e },
|
|
306
|
-
attrs: { shape: [o, a] },
|
|
307
|
-
backend: r
|
|
308
|
-
}), c = x(s, e.dtype, "max", r), l = h({
|
|
309
|
-
inputs: { x: c },
|
|
310
|
-
attrs: { shape: n },
|
|
311
|
-
backend: r
|
|
312
|
-
});
|
|
313
|
-
return r.disposeIntermediateTensorInfo(s), r.disposeIntermediateTensorInfo(c), l;
|
|
314
|
-
}
|
|
315
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Max.js
|
|
316
|
-
function A(e) {
|
|
317
|
-
let { inputs: n, backend: r, attrs: a } = e, { x: d } = n, { reductionIndices: f, keepDims: p } = a, m = d.shape.length, h = t(f, d.shape), v = h, y = c(v, m), b = y != null, x = r.shouldExecuteOnCPU([d]), S = d;
|
|
318
|
-
if (b) {
|
|
319
|
-
if (x) {
|
|
320
|
-
let e = r.texData.get(S.dataId).values, t = Array(m);
|
|
321
|
-
for (let e = 0; e < t.length; e++) t[e] = d.shape[y[e]];
|
|
322
|
-
let n = g(e, d.shape, d.dtype, y, t);
|
|
323
|
-
S = r.makeTensorInfo(t, d.dtype);
|
|
324
|
-
let i = r.texData.get(S.dataId);
|
|
325
|
-
i.values = n;
|
|
326
|
-
} else S = T(d, y, r);
|
|
327
|
-
v = l(v.length, m);
|
|
328
|
-
}
|
|
329
|
-
u("max", v, m);
|
|
330
|
-
let [C, w] = s(S.shape, v), E = C;
|
|
331
|
-
p && (E = o(C, h));
|
|
332
|
-
let D;
|
|
333
|
-
if (x) {
|
|
334
|
-
let e = r.texData.get(S.dataId).values, t = _(e, i(w), E, d.dtype);
|
|
335
|
-
D = r.makeTensorInfo(E, d.dtype);
|
|
336
|
-
let n = r.texData.get(D.dataId);
|
|
337
|
-
n.values = t;
|
|
338
|
-
} else D = k(S, w, E, r);
|
|
339
|
-
return b && r.disposeIntermediateTensorInfo(S), D;
|
|
340
|
-
}
|
|
341
|
-
var j = {
|
|
342
|
-
kernelName: "Max",
|
|
343
|
-
backendName: "webgl",
|
|
344
|
-
kernelFunc: A
|
|
345
|
-
}, M = m({
|
|
346
|
-
opSnippet: "\nif (a == b) {\n return 1.0;\n};\nreturn a / b;",
|
|
347
|
-
packedOpSnippet: "\n // vec4 one = vec4(equal(a, b));\n // return one + (vec4(1.0) - one) * a / b;\n vec4 result = a / b;\n if(a.x == b.x) {\n result.x = 1.;\n }\n if(a.y == b.y) {\n result.y = 1.;\n }\n if(a.z == b.z) {\n result.z = 1.;\n }\n if(a.w == b.w) {\n result.w = 1.;\n }\n\n return result;\n",
|
|
348
|
-
checkOutOfBounds: !0
|
|
349
|
-
}), N = {
|
|
350
|
-
kernelName: a,
|
|
351
|
-
backendName: "webgl",
|
|
352
|
-
kernelFunc: M
|
|
353
|
-
};
|
|
354
|
-
export { D as a, x as c, j as i, N as n, O as o, A as r, T as s, M as t };
|