@genai-fi/nanogpt 1.6.1 → 1.7.1
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 +10 -10
- 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 +37052 -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 +16 -9
- 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 +7 -7
- package/dist/training/tasks/TokenStore.d.ts +4 -4
- package/dist/training/tasks/tokenStream.d.ts +3 -3
- package/dist/training/types.d.ts +8 -7
- package/dist/training/validateOptions.d.ts +1 -1
- package/dist/training/validation.d.ts +5 -5
- 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
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { Bn as e, C as t, Pn as n, _i as r, lt as i, mr as a, pt as o, qi as s, qt as c } from "./dist-CMMLi-qO.js";
|
|
2
|
-
import { r as l } from "./backend_util-Cpp0Gwlp.js";
|
|
3
|
-
import { Z as u, a as d } from "./gpgpu_math-48m8q3jI.js";
|
|
4
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/binaryop_gpu.js
|
|
5
|
-
var f = "\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n", p = class {
|
|
6
|
-
constructor(e, n, r) {
|
|
7
|
-
this.variableNames = ["A", "B"], this.outputShape = t(n, r), this.enableShapeUniforms = d(this.outputShape.length), this.userCode = `
|
|
8
|
-
float binaryOperation(float a, float b) {
|
|
9
|
-
${e}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
void main() {
|
|
13
|
-
float a = getAAtOutCoords();
|
|
14
|
-
float b = getBAtOutCoords();
|
|
15
|
-
setOutput(binaryOperation(a, b));
|
|
16
|
-
}
|
|
17
|
-
`;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/packing_util.js
|
|
21
|
-
function m(e, t) {
|
|
22
|
-
return [
|
|
23
|
-
"x",
|
|
24
|
-
"y",
|
|
25
|
-
"z",
|
|
26
|
-
"w",
|
|
27
|
-
"u",
|
|
28
|
-
"v"
|
|
29
|
-
].slice(0, t).map((t) => `${e}.${t}`);
|
|
30
|
-
}
|
|
31
|
-
function h(e, t) {
|
|
32
|
-
return t === 1 ? [e] : m(e, t);
|
|
33
|
-
}
|
|
34
|
-
function g(e, t) {
|
|
35
|
-
if (e === 1) return "rc";
|
|
36
|
-
let n = "";
|
|
37
|
-
for (let r = 0; r < e; r++) n += t[r], r < e - 1 && (n += ",");
|
|
38
|
-
return n;
|
|
39
|
-
}
|
|
40
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/binaryop_packed_gpu.js
|
|
41
|
-
var _ = "\n result.r = isNaN.r ? NAN : result.r;\n result.g = isNaN.g ? NAN : result.g;\n result.b = isNaN.b ? NAN : result.b;\n result.a = isNaN.a ? NAN : result.a;\n", v = class {
|
|
42
|
-
constructor(e, n, r, i = !1) {
|
|
43
|
-
this.variableNames = ["A", "B"], this.supportsBroadcasting = !0, this.packedInputs = !0, this.packedOutput = !0, this.outputShape = t(n, r);
|
|
44
|
-
let a = this.outputShape.length;
|
|
45
|
-
this.enableShapeUniforms = d(a);
|
|
46
|
-
let o = "";
|
|
47
|
-
if (i) {
|
|
48
|
-
if (a === 0 || s(this.outputShape) === 1) o = "\n result.y = 0.;\n result.z = 0.;\n result.w = 0.;\n ";
|
|
49
|
-
else if (o = `
|
|
50
|
-
${u(a)} coords = getOutputCoords();
|
|
51
|
-
`, a === 1) this.enableShapeUniforms ? o += "\n result.y = (coords + 1) >= outShape ? 0. : result.y;\n result.z = 0.;\n result.w = 0.;\n " : o += `
|
|
52
|
-
result.y = (coords + 1) >= ${this.outputShape[0]} ? 0. : result.y;
|
|
53
|
-
result.z = 0.;
|
|
54
|
-
result.w = 0.;
|
|
55
|
-
`;
|
|
56
|
-
else {
|
|
57
|
-
let e = h("coords", a);
|
|
58
|
-
this.enableShapeUniforms ? o += `
|
|
59
|
-
bool nextRowOutOfBounds =
|
|
60
|
-
(${e[a - 2]} + 1) >= outShape[${a} - 2];
|
|
61
|
-
bool nextColOutOfBounds =
|
|
62
|
-
(${e[a - 1]} + 1) >= outShape[${a} - 1];
|
|
63
|
-
result.y = nextColOutOfBounds ? 0. : result.y;
|
|
64
|
-
result.z = nextRowOutOfBounds ? 0. : result.z;
|
|
65
|
-
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
|
|
66
|
-
` : o += `
|
|
67
|
-
bool nextRowOutOfBounds =
|
|
68
|
-
(${e[a - 2]} + 1) >= ${this.outputShape[a - 2]};
|
|
69
|
-
bool nextColOutOfBounds =
|
|
70
|
-
(${e[a - 1]} + 1) >= ${this.outputShape[a - 1]};
|
|
71
|
-
result.y = nextColOutOfBounds ? 0. : result.y;
|
|
72
|
-
result.z = nextRowOutOfBounds ? 0. : result.z;
|
|
73
|
-
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
|
|
74
|
-
`;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
this.userCode = `
|
|
78
|
-
vec4 binaryOperation(vec4 a, vec4 b) {
|
|
79
|
-
${e}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
void main() {
|
|
83
|
-
vec4 a = getAAtOutCoords();
|
|
84
|
-
vec4 b = getBAtOutCoords();
|
|
85
|
-
|
|
86
|
-
vec4 result = binaryOperation(a, b);
|
|
87
|
-
${o}
|
|
88
|
-
|
|
89
|
-
setOutput(result);
|
|
90
|
-
}
|
|
91
|
-
`;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Identity.js
|
|
95
|
-
function y(e) {
|
|
96
|
-
let { inputs: t, backend: n } = e, { x: r } = t;
|
|
97
|
-
return n.incRef(r.dataId), {
|
|
98
|
-
dataId: r.dataId,
|
|
99
|
-
shape: r.shape,
|
|
100
|
-
dtype: r.dtype
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
var b = {
|
|
104
|
-
kernelName: n,
|
|
105
|
-
backendName: "webgl",
|
|
106
|
-
kernelFunc: y
|
|
107
|
-
};
|
|
108
|
-
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Complex.js
|
|
109
|
-
function x(e) {
|
|
110
|
-
let { inputs: t, backend: n } = e, { real: r, imag: i } = t, a = n.makeTensorInfo(r.shape, "complex64"), o = n.texData.get(a.dataId);
|
|
111
|
-
return o.complexTensorInfos = {
|
|
112
|
-
real: y({
|
|
113
|
-
inputs: { x: r },
|
|
114
|
-
backend: n
|
|
115
|
-
}),
|
|
116
|
-
imag: y({
|
|
117
|
-
inputs: { x: i },
|
|
118
|
-
backend: n
|
|
119
|
-
})
|
|
120
|
-
}, a;
|
|
121
|
-
}
|
|
122
|
-
var S = {
|
|
123
|
-
kernelName: c,
|
|
124
|
-
backendName: "webgl",
|
|
125
|
-
kernelFunc: x
|
|
126
|
-
}, C = "return (a < 0.) ? b * a : a;", w = "\n vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));\n return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);\n";
|
|
127
|
-
function T(e) {
|
|
128
|
-
let { inputs: t, backend: n, attrs: i } = e, { x: a } = t, { alpha: s } = i, c = n.makeTensorInfo([], "float32", o(s, "float32")), l = r().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new v(w, a.shape, c.shape) : new p(C, a.shape, c.shape), u = n.runWebGLProgram(l, [a, c], "float32");
|
|
129
|
-
return n.disposeIntermediateTensorInfo(c), u;
|
|
130
|
-
}
|
|
131
|
-
var E = {
|
|
132
|
-
kernelName: e,
|
|
133
|
-
backendName: "webgl",
|
|
134
|
-
kernelFunc: T
|
|
135
|
-
}, D = "return (a < 0.) ? b * a : a;", O = "\n vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));\n return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);\n";
|
|
136
|
-
function k(e) {
|
|
137
|
-
let { inputs: t, backend: n } = e, { x: i, alpha: a } = t, o = r().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new v(O, i.shape, a.shape) : new p(D, i.shape, a.shape);
|
|
138
|
-
return n.runWebGLProgram(o, [i, a], "float32");
|
|
139
|
-
}
|
|
140
|
-
var A = {
|
|
141
|
-
kernelName: a,
|
|
142
|
-
backendName: "webgl",
|
|
143
|
-
kernelFunc: k
|
|
144
|
-
}, j = class {
|
|
145
|
-
constructor(e, t) {
|
|
146
|
-
this.variableNames = ["A"], this.outputShape = e, this.enableShapeUniforms = d(this.outputShape.length), this.userCode = `
|
|
147
|
-
float unaryOperation(float x) {
|
|
148
|
-
${t}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
void main() {
|
|
152
|
-
float x = getAAtOutCoords();
|
|
153
|
-
float y = unaryOperation(x);
|
|
154
|
-
|
|
155
|
-
setOutput(y);
|
|
156
|
-
}
|
|
157
|
-
`;
|
|
158
|
-
}
|
|
159
|
-
}, M = "if (isnan(x)) return x;", N = "return x;", P = "return abs(x);", F = "return (x >= 0.0) ? x : (exp(x) - 1.0);", I = M + "\n return (x < 0.0) ? 0.0 : x;\n", L = M + "\n return (x < 0.0) ? 0.0 : min(6.0, x);\n", R = "return x;", z = "return 1.0 / (1.0 + exp(-1.0 * x));", B = "return x;", V = "\n vec4 result;\n\n result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);\n result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);\n result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);\n result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);\n\n return result;\n", H = "\n vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n", U = "\n vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n", W = "return 1.0 / (1.0 + exp(-1.0 * x));", G = class {
|
|
160
|
-
constructor(e, t) {
|
|
161
|
-
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e, this.enableShapeUniforms = d(this.outputShape.length), this.userCode = `
|
|
162
|
-
vec4 unaryOperation(vec4 x) {
|
|
163
|
-
${t}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
void main() {
|
|
167
|
-
vec4 x = getAAtOutCoords();
|
|
168
|
-
vec4 y = unaryOperation(x);
|
|
169
|
-
|
|
170
|
-
setOutput(y);
|
|
171
|
-
}
|
|
172
|
-
`;
|
|
173
|
-
}
|
|
174
|
-
}, K = "if (isnan(x)) return x;";
|
|
175
|
-
function q({ opSnippet: e, packedOpSnippet: t, cpuKernelImpl: n, dtype: i }) {
|
|
176
|
-
return ({ inputs: a, backend: o }) => {
|
|
177
|
-
let { x: s } = a, c = o, l = i || s.dtype;
|
|
178
|
-
if (c.shouldExecuteOnCPU([s]) && n != null) {
|
|
179
|
-
let e = n(c.texData.get(s.dataId).values, l);
|
|
180
|
-
return c.makeTensorInfo(s.shape, l, e);
|
|
181
|
-
}
|
|
182
|
-
let u = r().getBool("WEBGL_PACK_UNARY_OPERATIONS") && t != null, d;
|
|
183
|
-
return d = u ? new G(s.shape, t) : new j(s.shape, e), c.runWebGLProgram(d, [s], l);
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function J({ opSnippet: e, packedOpSnippet: t, checkOutOfBounds: n = !1, supportsComplex: a = !1, cpuKernelImpl: o, dtype: s }) {
|
|
187
|
-
return ({ inputs: c, backend: u }) => {
|
|
188
|
-
let { a: d, b: f } = c, m = u;
|
|
189
|
-
if (a && d.dtype === "complex64") {
|
|
190
|
-
let t = m.texData.get(d.dataId), n = m.texData.get(f.dataId), [r, a] = [[t.complexTensorInfos.real, n.complexTensorInfos.real], [t.complexTensorInfos.imag, n.complexTensorInfos.imag]].map((t) => {
|
|
191
|
-
let [n, r] = t, a = {
|
|
192
|
-
dataId: n.dataId,
|
|
193
|
-
dtype: n.dtype,
|
|
194
|
-
shape: d.shape
|
|
195
|
-
}, o = {
|
|
196
|
-
dataId: r.dataId,
|
|
197
|
-
dtype: r.dtype,
|
|
198
|
-
shape: f.shape
|
|
199
|
-
}, s = new p(e, d.shape, f.shape);
|
|
200
|
-
return m.runWebGLProgram(s, [a, o], i(n.dtype, r.dtype));
|
|
201
|
-
}), o = x({
|
|
202
|
-
inputs: {
|
|
203
|
-
real: r,
|
|
204
|
-
imag: a
|
|
205
|
-
},
|
|
206
|
-
backend: m
|
|
207
|
-
});
|
|
208
|
-
return m.disposeIntermediateTensorInfo(r), m.disposeIntermediateTensorInfo(a), o;
|
|
209
|
-
}
|
|
210
|
-
let h = s || i(d.dtype, f.dtype);
|
|
211
|
-
if ((d.dtype === "string" || f.dtype === "string" || m.shouldExecuteOnCPU([d, f])) && o != null) {
|
|
212
|
-
let e = m.texData.get(d.dataId).values, t = m.texData.get(f.dataId).values, n = d.dtype === "string" ? l(e) : e, r = d.dtype === "string" ? l(t) : t, [i, a] = o(d.shape, f.shape, n, r, h), s = m.makeTensorInfo(a, h), c = m.texData.get(s.dataId);
|
|
213
|
-
return c.values = i, s;
|
|
214
|
-
}
|
|
215
|
-
let g = r().getBool("WEBGL_PACK_BINARY_OPERATIONS") && t != null, _;
|
|
216
|
-
return _ = g ? new v(t, d.shape, f.shape, n) : new p(e, d.shape, f.shape), m.runWebGLProgram(_, [d, f], h);
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
function Y(e, t = !1) {
|
|
220
|
-
if (e === "linear") return t ? B : N;
|
|
221
|
-
if (e === "relu") return t ? H : I;
|
|
222
|
-
if (e === "elu") return t ? V : F;
|
|
223
|
-
if (e === "relu6") return t ? U : L;
|
|
224
|
-
if (e === "prelu") return t ? O : D;
|
|
225
|
-
if (e === "leakyrelu") return t ? w : C;
|
|
226
|
-
if (e === "sigmoid") return t ? W : z;
|
|
227
|
-
throw Error(`Activation ${e} has not been implemented for the WebGL backend.`);
|
|
228
|
-
}
|
|
229
|
-
export { f as S, _, G as a, m as b, R as c, E as d, x as f, v as g, b as h, q as i, j as l, y as m, J as n, P as o, S as p, Y as r, M as s, K as t, A as u, h as v, p as x, g as y };
|
package/dist/layers/BaseLayer.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { H as e, h as t, m as n } from "../dist-CMMLi-qO.js";
|
|
2
|
-
import r from "./WeightStore.js";
|
|
3
|
-
// lib/layers/BaseLayer.ts
|
|
4
|
-
var i = class {
|
|
5
|
-
parent;
|
|
6
|
-
config;
|
|
7
|
-
weightStore;
|
|
8
|
-
children = [];
|
|
9
|
-
profiler;
|
|
10
|
-
ownVariables = /* @__PURE__ */ new Set();
|
|
11
|
-
constructor(e, t) {
|
|
12
|
-
this.config = e, this.parent = t, this.parent ? (this.parent.children.push(this), this.weightStore = this.parent.weightStore) : this.weightStore = new r();
|
|
13
|
-
}
|
|
14
|
-
getProfiler() {
|
|
15
|
-
return this.profiler;
|
|
16
|
-
}
|
|
17
|
-
setProfiler(e) {
|
|
18
|
-
this.profiler = e || void 0, this.children.forEach((t) => {
|
|
19
|
-
t.setProfiler(e);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
startMemory() {
|
|
23
|
-
this.profiler?.startMemory();
|
|
24
|
-
}
|
|
25
|
-
endMemory(e) {
|
|
26
|
-
this.profiler?.endMemory(e);
|
|
27
|
-
}
|
|
28
|
-
addVariable(e, t) {
|
|
29
|
-
this.weightStore.addVariable(e, t), this.ownVariables.add(e), this.parent && this.parent.addChildVariable(e);
|
|
30
|
-
}
|
|
31
|
-
addChildVariable(e) {
|
|
32
|
-
this.ownVariables.add(e);
|
|
33
|
-
}
|
|
34
|
-
get variables() {
|
|
35
|
-
return this.weightStore.variables;
|
|
36
|
-
}
|
|
37
|
-
get trainableVariables() {
|
|
38
|
-
return this.weightStore.trainableVariables.filter((e) => this.ownVariables.has(e.name));
|
|
39
|
-
}
|
|
40
|
-
getVariable(e) {
|
|
41
|
-
return this.weightStore.getVariable(e);
|
|
42
|
-
}
|
|
43
|
-
hasVariable(e) {
|
|
44
|
-
return this.weightStore.hasVariable(e);
|
|
45
|
-
}
|
|
46
|
-
setVariable(e, t) {
|
|
47
|
-
this.weightStore.setVariable(e, t);
|
|
48
|
-
}
|
|
49
|
-
dispose() {
|
|
50
|
-
this.weightStore.dispose();
|
|
51
|
-
}
|
|
52
|
-
build() {}
|
|
53
|
-
call(e, ...t) {
|
|
54
|
-
return this.build(), this.forward(e, ...t);
|
|
55
|
-
}
|
|
56
|
-
callCheckpoint(e, ...t) {
|
|
57
|
-
return this.build(), this.checkpointingFn(e, ...t);
|
|
58
|
-
}
|
|
59
|
-
checkpointingFn(r, ...i) {
|
|
60
|
-
let a = this.trainableVariables;
|
|
61
|
-
return n((...n) => {
|
|
62
|
-
let o = n[n.length - 1], s = n.slice(0, i.length), c = this.forward(r, ...s);
|
|
63
|
-
return o(s), {
|
|
64
|
-
value: c,
|
|
65
|
-
gradFunc: (n, i) => {
|
|
66
|
-
let o = e().state.activeTape;
|
|
67
|
-
e().state.activeTape = [];
|
|
68
|
-
let c = t((...e) => this.forward(r, ...e.slice(0, s.length)))([...i, ...a], n);
|
|
69
|
-
return e().state.activeTape = o, c;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
})(...i, ...a);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
export { i as default };
|
package/dist/layers/GQA.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { attentionMask as e } from "../ops/attentionMask.js";
|
|
2
|
-
import { t } from "../random_normal-DUIT8kyC.js";
|
|
3
|
-
import { n } from "../picomatch--TW6gyBJ.js";
|
|
4
|
-
import r from "./BaseLayer.js";
|
|
5
|
-
import { t as i } from "../rope-JjBVufF_.js";
|
|
6
|
-
import { appendCache as a } from "../ops/appendCache.js";
|
|
7
|
-
import { W as o, Y as s } from "../dist-CMMLi-qO.js";
|
|
8
|
-
import { softmax16 as c } from "../ops/softmax16.js";
|
|
9
|
-
import { t as l } from "../matMul16-tE26fnhf.js";
|
|
10
|
-
import { t as u } from "../pack16-BHO4t1-M.js";
|
|
11
|
-
import { transpose16 as d } from "../ops/transpose16.js";
|
|
12
|
-
import { dot16 as f } from "../ops/dot16.js";
|
|
13
|
-
import { reshape16 as p } from "../ops/reshape16.js";
|
|
14
|
-
import { isPackedTensor as m } from "../utilities/packed.js";
|
|
15
|
-
import { qkv as h } from "../ops/qkv.js";
|
|
16
|
-
import { t as g } from "../dropout16-CA31Ud5a.js";
|
|
17
|
-
import _ from "./RMSNorm.js";
|
|
18
|
-
// lib/layers/GQA.ts
|
|
19
|
-
var v = class extends r {
|
|
20
|
-
attentionConfig;
|
|
21
|
-
divisor;
|
|
22
|
-
index;
|
|
23
|
-
units;
|
|
24
|
-
projUnits;
|
|
25
|
-
ATTN;
|
|
26
|
-
PROJ;
|
|
27
|
-
qNorm = null;
|
|
28
|
-
kNorm = null;
|
|
29
|
-
constructor(e, t, n, r) {
|
|
30
|
-
super(t, r), this.attentionConfig = n, this.index = e, this.units = t.nEmbed * 3, this.projUnits = t.nEmbed, this.ATTN = `block_${this.index}_cAttn`, this.PROJ = `block_${this.index}_cProj`, this.addVariable(this.ATTN), this.addVariable(this.PROJ), this.divisor = 1 / Math.sqrt(t.nEmbed / t.nHead), (this.attentionConfig.useQKNorm ?? !1) && (this.qNorm = new _(t, n, `block_${this.index}_qNorm`, this), this.kNorm = new _(t, n, `block_${this.index}_kNorm`, this));
|
|
31
|
-
}
|
|
32
|
-
build() {
|
|
33
|
-
this.hasVariable(this.ATTN) === !1 && this.setVariable(this.ATTN, n(t([this.config.nEmbed, this.units], 0, .02), !0, this.ATTN)), this.hasVariable(this.PROJ) === !1 && this.setVariable(this.PROJ, n(t([this.projUnits, this.config.nEmbed], 0, .02), !0, this.PROJ));
|
|
34
|
-
}
|
|
35
|
-
getAttentionScores(t, n, r) {
|
|
36
|
-
let i = e(t, n, this.divisor, r), a = c(i);
|
|
37
|
-
return i.dispose(), a;
|
|
38
|
-
}
|
|
39
|
-
getQKV(e) {
|
|
40
|
-
let t = m(e) ? u(this.getVariable(this.ATTN)) : this.getVariable(this.ATTN), n = h(e, t, this.config.nHead);
|
|
41
|
-
return m(e) && t.dispose(), n;
|
|
42
|
-
}
|
|
43
|
-
getOutputProjection(e) {
|
|
44
|
-
let t = e.shape[0], n = e.shape[2], r = this.config.nEmbed, i = m(e), a = d(e, [
|
|
45
|
-
0,
|
|
46
|
-
2,
|
|
47
|
-
1,
|
|
48
|
-
3
|
|
49
|
-
]), o = p(a, [
|
|
50
|
-
t,
|
|
51
|
-
n,
|
|
52
|
-
i ? r / 2 : r
|
|
53
|
-
]);
|
|
54
|
-
a.dispose();
|
|
55
|
-
let s = i ? u(this.getVariable(this.PROJ)) : this.getVariable(this.PROJ), c = f(o, s);
|
|
56
|
-
return i && s.dispose(), o.dispose(), c;
|
|
57
|
-
}
|
|
58
|
-
updateCache(e, t, n) {
|
|
59
|
-
let r = this.config.blockSize, i = e.shape[2], s = n.length || 0, c = a(e, r, s, n.k);
|
|
60
|
-
e.dispose(), n.k && n.k.dispose();
|
|
61
|
-
let l = a(t, r, s, n.v);
|
|
62
|
-
t.dispose(), n.v && n.v.dispose();
|
|
63
|
-
let u = Math.min(s + i, r), d = n.cumulativeLength + i;
|
|
64
|
-
n.length = u, n.cumulativeLength = d, n.k = o(c), n.v = o(l);
|
|
65
|
-
}
|
|
66
|
-
forward(e, t) {
|
|
67
|
-
return s(() => {
|
|
68
|
-
this.startMemory();
|
|
69
|
-
let [n, r, a] = this.getQKV(t), s = e.pastKV ? e.pastKV.cumulativeLength : e.ropePositionOffset || 0, c = e.ropeCache, u = this.attentionConfig.ropeInterleaved ?? !0, d = c ? i(n, c, s, !1, u) : n, f = c ? i(r, c, s, !1, u) : r, p = this.qNorm ? this.qNorm.call(e, d) : d;
|
|
70
|
-
this.qNorm && d.dispose();
|
|
71
|
-
let m = this.kNorm ? this.kNorm.call(e, f) : f;
|
|
72
|
-
this.kNorm && f.dispose(), c && (n.dispose(), r.dispose());
|
|
73
|
-
let h = e.pastKV ? e.pastKV.length : 0;
|
|
74
|
-
e.pastKV && !e.training && this.updateCache(m, a, e.pastKV);
|
|
75
|
-
let _ = e.pastKV?.k ? e.pastKV.k : m, v = e.pastKV?.v ? e.pastKV.v : a, y;
|
|
76
|
-
y = h > 0 ? this.getAttentionScores(p, _, h) : this.getAttentionScores(p, _), p.dispose(), e.pastKV || _.dispose();
|
|
77
|
-
let b = l(y, v), x = e.attentionScores !== void 0 && e.attentionScores.attentionOut !== void 0;
|
|
78
|
-
x || y.dispose(), e.pastKV || v.dispose();
|
|
79
|
-
let S = this.getOutputProjection(b);
|
|
80
|
-
if (b.dispose(), x && e.attentionScores && e.attentionScores.attentionOut !== void 0) {
|
|
81
|
-
let t = y.shape[1], n = y.shape[2];
|
|
82
|
-
e.attentionScores.attentionOut?.push(o(y.slice([
|
|
83
|
-
0,
|
|
84
|
-
0,
|
|
85
|
-
0,
|
|
86
|
-
0
|
|
87
|
-
], [
|
|
88
|
-
1,
|
|
89
|
-
-1,
|
|
90
|
-
-1,
|
|
91
|
-
-1
|
|
92
|
-
]).reshape([
|
|
93
|
-
t,
|
|
94
|
-
n,
|
|
95
|
-
-1
|
|
96
|
-
])));
|
|
97
|
-
}
|
|
98
|
-
return this.endMemory("CausalSelfAttention"), e.dropout && e.dropout > 0 ? g(S, e.dropout) : S;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
export { v as default };
|
package/dist/layers/HeadLayer.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { n as e } from "../dist-DyL7qSLJ.js";
|
|
2
|
-
import "../dist-CMMLi-qO.js";
|
|
3
|
-
import { n as t } from "../picomatch--TW6gyBJ.js";
|
|
4
|
-
import n from "./BaseLayer.js";
|
|
5
|
-
import { dot16 as r } from "../ops/dot16.js";
|
|
6
|
-
import { isPackedTensor as i } from "../utilities/packed.js";
|
|
7
|
-
import { t as a } from "../pack16-BHO4t1-M.js";
|
|
8
|
-
// lib/layers/HeadLayer.ts
|
|
9
|
-
var o = class extends n {
|
|
10
|
-
vocabSize;
|
|
11
|
-
embedDim;
|
|
12
|
-
initializer;
|
|
13
|
-
WEIGHTS;
|
|
14
|
-
constructor(n, r, i) {
|
|
15
|
-
super(n, i), this.WEIGHTS = r, this.vocabSize = n.vocabSize, this.embedDim = n.nEmbed, this.initializer = e({
|
|
16
|
-
mean: 0,
|
|
17
|
-
stddev: .02
|
|
18
|
-
}), this.addVariable(this.WEIGHTS, t(this.initializer.apply([this.embedDim, this.vocabSize]), !0, r));
|
|
19
|
-
}
|
|
20
|
-
project(e) {
|
|
21
|
-
let t = i(e) ? a(this.getVariable(this.WEIGHTS), void 0, 32) : this.getVariable(this.WEIGHTS), n = r(e, t);
|
|
22
|
-
return i(e) && t.dispose(), n;
|
|
23
|
-
}
|
|
24
|
-
forward(e, t) {
|
|
25
|
-
return this.project(t);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export { o as default };
|
package/dist/layers/LoRA.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { i as e } from "../rolldown-runtime-CwxnZyOB.js";
|
|
2
|
-
import { Y as t, b as n } from "../dist-CMMLi-qO.js";
|
|
3
|
-
import { t as r } from "../zeros-hxKGkRfl.js";
|
|
4
|
-
import { t as i } from "../random_normal-DUIT8kyC.js";
|
|
5
|
-
import { n as a, t as o } from "../picomatch--TW6gyBJ.js";
|
|
6
|
-
// lib/layers/LoRA.ts
|
|
7
|
-
var s = /* @__PURE__ */ e(o(), 1), c = class {
|
|
8
|
-
weightStore;
|
|
9
|
-
alpha;
|
|
10
|
-
rank;
|
|
11
|
-
variables;
|
|
12
|
-
scale;
|
|
13
|
-
name;
|
|
14
|
-
constructor(e, t, o, c, l) {
|
|
15
|
-
this.name = e, this.weightStore = t, this.alpha = o, this.rank = c;
|
|
16
|
-
let u = (0, s.default)(l), d = t.variableNames.filter((e) => u(e) && !e.endsWith("_loraA") && !e.endsWith("_loraB"));
|
|
17
|
-
this.variables = new Set(d), this.scale = n(o / c), this.variables.forEach((e) => {
|
|
18
|
-
let t = this.weightStore.getRawVariable(e), [n, o] = t.shape, s = `${e}_${this.name}_loraA`, c = `${e}_${this.name}_loraB`;
|
|
19
|
-
t.shape.length === 2 ? this.weightStore.hasVariable(s) || this.weightStore.hasVariable(c) || (this.weightStore.addVariable(s, a(i([n, this.rank], 0, .02), !0, s)), this.weightStore.addVariable(c, a(r([this.rank, o]), !0, c))) : (console.warn(`LoRA currently only supports 2D weight matrices. Variable ${e} has shape ${t.shape}`), this.variables.delete(e));
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
attach() {
|
|
23
|
-
if (this.weightStore.onWeightRead) throw Error("LoRA cannot be applied to a WeightStore that already has a onWeightRead hook.");
|
|
24
|
-
this.weightStore.onWeightRead = (e, n) => this.variables.has(e) ? t(() => {
|
|
25
|
-
let t = this.weightStore.getRawVariable(`${e}_${this.name}_loraA`), r = this.weightStore.getRawVariable(`${e}_${this.name}_loraB`);
|
|
26
|
-
return n.add(t.matMul(r).mul(this.scale));
|
|
27
|
-
}) : n, this.weightStore.setTrainable([`*_${this.name}_loraA`, `*_${this.name}_loraB`]);
|
|
28
|
-
}
|
|
29
|
-
merge() {
|
|
30
|
-
this.variables.forEach((e) => {
|
|
31
|
-
let n = this.weightStore.getRawVariable(e), r = this.weightStore.getRawVariable(`${e}_${this.name}_loraA`), i = this.weightStore.getRawVariable(`${e}_${this.name}_loraB`), a = t(() => n.add(r.matMul(i).mul(this.scale)));
|
|
32
|
-
n.assign(a), a.dispose();
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
detach() {
|
|
36
|
-
this.weightStore.onWeightRead = void 0, this.weightStore.setTrainable(["*"]);
|
|
37
|
-
}
|
|
38
|
-
dispose() {
|
|
39
|
-
this.detach(), this.scale.dispose(), this.variables.forEach((e) => {
|
|
40
|
-
let t = `${e}_${this.name}_loraA`, n = `${e}_${this.name}_loraB`;
|
|
41
|
-
this.weightStore.getRawVariable(t).dispose(), this.weightStore.getRawVariable(n).dispose(), this.weightStore.deleteVariable(t), this.weightStore.deleteVariable(n);
|
|
42
|
-
}), this.variables.clear();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
export { c as default };
|
package/dist/layers/MHA.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { attentionMask as e } from "../ops/attentionMask.js";
|
|
2
|
-
import { t } from "../random_normal-DUIT8kyC.js";
|
|
3
|
-
import { n } from "../picomatch--TW6gyBJ.js";
|
|
4
|
-
import r from "./BaseLayer.js";
|
|
5
|
-
import { t as i } from "../rope-JjBVufF_.js";
|
|
6
|
-
import { appendCache as a } from "../ops/appendCache.js";
|
|
7
|
-
import { W as o, Y as s } from "../dist-CMMLi-qO.js";
|
|
8
|
-
import { softmax16 as c } from "../ops/softmax16.js";
|
|
9
|
-
import { t as l } from "../matMul16-tE26fnhf.js";
|
|
10
|
-
import { t as u } from "../pack16-BHO4t1-M.js";
|
|
11
|
-
import { transpose16 as d } from "../ops/transpose16.js";
|
|
12
|
-
import { dot16 as f } from "../ops/dot16.js";
|
|
13
|
-
import { reshape16 as p } from "../ops/reshape16.js";
|
|
14
|
-
import { isPackedTensor as m } from "../utilities/packed.js";
|
|
15
|
-
import { qkv as h } from "../ops/qkv.js";
|
|
16
|
-
import { t as g } from "../dropout16-CA31Ud5a.js";
|
|
17
|
-
import _ from "./RMSNorm.js";
|
|
18
|
-
// lib/layers/MHA.ts
|
|
19
|
-
var v = class extends r {
|
|
20
|
-
attentionConfig;
|
|
21
|
-
divisor;
|
|
22
|
-
index;
|
|
23
|
-
units;
|
|
24
|
-
projUnits;
|
|
25
|
-
ATTN;
|
|
26
|
-
PROJ;
|
|
27
|
-
qNorm = null;
|
|
28
|
-
kNorm = null;
|
|
29
|
-
constructor(e, t, n, r) {
|
|
30
|
-
super(t, r), this.attentionConfig = n, this.index = e, this.units = t.nEmbed * 3, this.projUnits = t.nEmbed, this.ATTN = `block_${this.index}_cAttn`, this.PROJ = `block_${this.index}_cProj`, this.addVariable(this.ATTN), this.addVariable(this.PROJ), this.divisor = 1 / Math.sqrt(t.nEmbed / t.nHead), (this.attentionConfig.useQKNorm ?? !1) && (this.qNorm = new _(t, n, `block_${this.index}_qNorm`, this), this.kNorm = new _(t, n, `block_${this.index}_kNorm`, this));
|
|
31
|
-
}
|
|
32
|
-
build() {
|
|
33
|
-
this.hasVariable(this.ATTN) === !1 && this.setVariable(this.ATTN, n(t([this.config.nEmbed, this.units], 0, .02), !0, this.ATTN)), this.hasVariable(this.PROJ) === !1 && this.setVariable(this.PROJ, n(t([this.projUnits, this.config.nEmbed], 0, .02), !0, this.PROJ));
|
|
34
|
-
}
|
|
35
|
-
getAttentionScores(t, n, r, i) {
|
|
36
|
-
let a = e(t, n, this.divisor, r, i), o = c(a);
|
|
37
|
-
return a.dispose(), o;
|
|
38
|
-
}
|
|
39
|
-
getQKV(e) {
|
|
40
|
-
let t = m(e) ? u(this.getVariable(this.ATTN)) : this.getVariable(this.ATTN), n = h(e, t, this.config.nHead);
|
|
41
|
-
return m(e) && t.dispose(), n;
|
|
42
|
-
}
|
|
43
|
-
getOutputProjection(e) {
|
|
44
|
-
let t = e.shape[0], n = e.shape[2], r = this.config.nEmbed, i = m(e), a = d(e, [
|
|
45
|
-
0,
|
|
46
|
-
2,
|
|
47
|
-
1,
|
|
48
|
-
3
|
|
49
|
-
]), o = p(a, [
|
|
50
|
-
t,
|
|
51
|
-
n,
|
|
52
|
-
i ? r / 2 : r
|
|
53
|
-
]);
|
|
54
|
-
a.dispose();
|
|
55
|
-
let s = i ? u(this.getVariable(this.PROJ)) : this.getVariable(this.PROJ), c = f(o, s);
|
|
56
|
-
return i && s.dispose(), o.dispose(), c;
|
|
57
|
-
}
|
|
58
|
-
updateCache(e, t, n) {
|
|
59
|
-
let r = this.config.blockSize, i = e.shape[2], s = n.length || 0, c = a(e, r, s, n.k);
|
|
60
|
-
e.dispose(), n.k && n.k.dispose();
|
|
61
|
-
let l = a(t, r, s, n.v);
|
|
62
|
-
t.dispose(), n.v && n.v.dispose();
|
|
63
|
-
let u = Math.min(s + i, r), d = n.cumulativeLength + i;
|
|
64
|
-
n.length = u, n.cumulativeLength = d, n.k = o(c), n.v = o(l);
|
|
65
|
-
}
|
|
66
|
-
forward(e, t) {
|
|
67
|
-
return s(() => {
|
|
68
|
-
this.startMemory();
|
|
69
|
-
let [n, r, a] = this.getQKV(t), s = e.pastKV ? e.pastKV.cumulativeLength : e.ropePositionOffset || 0, c = e.ropeCache, u = this.attentionConfig.ropeInterleaved ?? !0, d = c ? i(n, c, s, !1, u) : n, f = c ? i(r, c, s, !1, u) : r, p = this.qNorm ? this.qNorm.call(e, d) : d;
|
|
70
|
-
this.qNorm && d.dispose();
|
|
71
|
-
let m = this.kNorm ? this.kNorm.call(e, f) : f;
|
|
72
|
-
this.kNorm && f.dispose(), c && (n.dispose(), r.dispose());
|
|
73
|
-
let h = e.pastKV ? e.pastKV.length : 0;
|
|
74
|
-
e.pastKV && !e.training && this.updateCache(m, a, e.pastKV);
|
|
75
|
-
let _ = e.pastKV?.k ? e.pastKV.k : m, v = e.pastKV?.v ? e.pastKV.v : a, y;
|
|
76
|
-
y = h > 0 ? this.getAttentionScores(p, _, h, e.mask) : this.getAttentionScores(p, _, void 0, e.mask), p.dispose(), e.pastKV || _.dispose();
|
|
77
|
-
let b = l(y, v), x = e.attentionScores !== void 0 && e.attentionScores.attentionOut !== void 0;
|
|
78
|
-
x || y.dispose(), e.pastKV || v.dispose();
|
|
79
|
-
let S = this.getOutputProjection(b);
|
|
80
|
-
if (b.dispose(), x && e.attentionScores && e.attentionScores.attentionOut !== void 0) {
|
|
81
|
-
let t = y.shape[1], n = y.shape[2];
|
|
82
|
-
e.attentionScores.attentionOut?.push(o(y.slice([
|
|
83
|
-
0,
|
|
84
|
-
0,
|
|
85
|
-
0,
|
|
86
|
-
0
|
|
87
|
-
], [
|
|
88
|
-
1,
|
|
89
|
-
-1,
|
|
90
|
-
-1,
|
|
91
|
-
-1
|
|
92
|
-
]).reshape([
|
|
93
|
-
t,
|
|
94
|
-
n,
|
|
95
|
-
-1
|
|
96
|
-
])));
|
|
97
|
-
}
|
|
98
|
-
return this.endMemory("CausalSelfAttention"), e.dropout && e.dropout > 0 ? g(S, e.dropout) : S;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
export { v as default };
|
package/dist/layers/MLP.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Y as e } from "../dist-CMMLi-qO.js";
|
|
2
|
-
import { t } from "../random_normal-DUIT8kyC.js";
|
|
3
|
-
import { n } from "../picomatch--TW6gyBJ.js";
|
|
4
|
-
import r from "./BaseLayer.js";
|
|
5
|
-
import { t as i } from "../matMul16-tE26fnhf.js";
|
|
6
|
-
import { reshape16 as a } from "../ops/reshape16.js";
|
|
7
|
-
import { t as o } from "../dropout16-CA31Ud5a.js";
|
|
8
|
-
import { t as s } from "../mul16-C7sqgqik.js";
|
|
9
|
-
// lib/layers/MLP.ts
|
|
10
|
-
function c(e, t = 8 / 3, n = 32) {
|
|
11
|
-
let r = Math.round(t * e);
|
|
12
|
-
return Math.max(n, Math.round(r / n) * n);
|
|
13
|
-
}
|
|
14
|
-
var l = class extends r {
|
|
15
|
-
index;
|
|
16
|
-
hiddenUnits;
|
|
17
|
-
MLPHIDDEN;
|
|
18
|
-
MLPOUT;
|
|
19
|
-
MLPGATE;
|
|
20
|
-
MLPUP;
|
|
21
|
-
mlpConfig;
|
|
22
|
-
constructor(e, t, n, r) {
|
|
23
|
-
super(t, r), this.index = e, this.mlpConfig = n, this.hiddenUnits = n.hiddenSize ?? c(t.nEmbed, n.hiddenFactor ?? t.mlpFactor), this.MLPHIDDEN = `block_${this.index}_mlpHidden`, this.MLPOUT = `block_${this.index}_mlpOut`, this.addVariable(this.MLPOUT), this.MLPGATE = `block_${this.index}_mlpGate`, this.MLPUP = `block_${this.index}_mlpUp`, this.mlpConfig.activation === "swiglu" ? (this.addVariable(this.MLPGATE), this.addVariable(this.MLPUP)) : this.addVariable(this.MLPHIDDEN);
|
|
24
|
-
}
|
|
25
|
-
build() {
|
|
26
|
-
this.mlpConfig.activation === "swiglu" ? (this.hasVariable(this.MLPGATE) === !1 && this.setVariable(this.MLPGATE, n(t([this.config.nEmbed, this.hiddenUnits], 0, .02), !0, this.MLPGATE)), this.hasVariable(this.MLPUP) === !1 && this.setVariable(this.MLPUP, n(t([this.config.nEmbed, this.hiddenUnits], 0, .02), !0, this.MLPUP))) : this.hasVariable(this.MLPHIDDEN) === !1 && this.setVariable(this.MLPHIDDEN, n(t([this.config.nEmbed, this.hiddenUnits], 0, .02), !0, this.MLPHIDDEN)), this.hasVariable(this.MLPOUT) === !1 && this.setVariable(this.MLPOUT, n(t([this.hiddenUnits, this.config.nEmbed], 0, .02 / Math.sqrt(2 * this.config.nLayer)), !0, this.MLPOUT));
|
|
27
|
-
}
|
|
28
|
-
forward(t, n) {
|
|
29
|
-
return e(() => {
|
|
30
|
-
this.startMemory();
|
|
31
|
-
let [e, r, c] = n.shape, l = a(n, [e * r, c]), u;
|
|
32
|
-
if (this.mlpConfig.activation === "swiglu") {
|
|
33
|
-
let e = i(l, this.getVariable(this.MLPGATE), !1, !1, { activation: "silu" }), t = i(l, this.getVariable(this.MLPUP));
|
|
34
|
-
u = s(e, t), e.dispose(), t.dispose();
|
|
35
|
-
} else u = i(l, this.getVariable(this.MLPHIDDEN), !1, !1, { activation: this.mlpConfig.activation ?? "gelu" });
|
|
36
|
-
let d = i(u, this.getVariable(this.MLPOUT));
|
|
37
|
-
u.dispose();
|
|
38
|
-
let f = a(d, [
|
|
39
|
-
e,
|
|
40
|
-
r,
|
|
41
|
-
c
|
|
42
|
-
]);
|
|
43
|
-
return this.endMemory("MLP"), t.dropout && t.dropout > 0 ? o(f, t.dropout) : f;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
export { l as default, c as swigluHidden };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Y as e, b as t, it as n } from "../dist-CMMLi-qO.js";
|
|
2
|
-
import r from "./BaseLayer.js";
|
|
3
|
-
import { t as i } from "../ops-Be5ACU5R.js";
|
|
4
|
-
import { t as a } from "../range-CYvQC3fW.js";
|
|
5
|
-
import { n as o, t as s } from "../dist-DyL7qSLJ.js";
|
|
6
|
-
// lib/layers/PositionEmbedding.ts
|
|
7
|
-
var c = class extends r {
|
|
8
|
-
wpe;
|
|
9
|
-
constructor(e, t = "", n) {
|
|
10
|
-
super(e, n), this.wpe = s({
|
|
11
|
-
inputDim: this.config.blockSize,
|
|
12
|
-
outputDim: this.config.nEmbed,
|
|
13
|
-
name: t,
|
|
14
|
-
embeddingsInitializer: o({
|
|
15
|
-
mean: 0,
|
|
16
|
-
stddev: .02
|
|
17
|
-
})
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
forward(r, o) {
|
|
21
|
-
let s = r.cache?.[0]?.length ?? 0;
|
|
22
|
-
return e(() => {
|
|
23
|
-
let [, e] = o.shape, r = this.config.blockSize, c = a(0, e, 1, "int32"), l = i(n(c, t(s, "int32")), t(r, "int32")), u = this.wpe.apply(l);
|
|
24
|
-
return o.add(u);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export { c as default };
|