@genai-fi/nanogpt 0.20.0 → 0.20.2
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/BaseTokeniser-DSg9zcYq.js +221 -0
- package/dist/DatasetBuilder-DgURD85T.js +712 -0
- package/dist/Generator.d.ts +82 -0
- package/dist/Generator.js +2 -0
- package/dist/RealDiv-DBu0FQqT.js +362 -0
- package/dist/Reshape-CABOPB9d.js +94 -0
- package/dist/Reshape-DqO3r8BC.js +17 -0
- package/dist/TeachableLLM.d.ts +70 -0
- package/dist/TeachableLLM.js +2 -0
- package/dist/Trainer.d.ts +43 -0
- package/dist/Trainer.js +2 -0
- package/dist/backend.d.ts +2 -0
- package/dist/backend.js +13 -0
- package/dist/backend_util-Cg-roD1p.js +399 -0
- package/dist/binary_op_util-CrYk9LXL.js +103 -0
- package/dist/checks/appendCache.d.ts +1 -0
- package/dist/checks/appendCache.js +55 -0
- package/dist/checks/attentionMask.d.ts +1 -0
- package/dist/checks/attentionMask.js +56 -0
- package/dist/checks/check.d.ts +9 -0
- package/dist/checks/check.js +32 -0
- package/dist/checks/gelu.d.ts +1 -0
- package/dist/checks/gelu.js +46 -0
- package/dist/checks/index.d.ts +26 -0
- package/dist/checks/index.js +28 -0
- package/dist/checks/matMulGelu.d.ts +1 -0
- package/dist/checks/matMulGelu.js +84 -0
- package/dist/checks/normRMS.d.ts +1 -0
- package/dist/checks/normRMS.js +28 -0
- package/dist/checks/normRMSGrad.d.ts +1 -0
- package/dist/checks/normRMSGrad.js +22 -0
- package/dist/checks/packUnpack.d.ts +1 -0
- package/dist/checks/packUnpack.js +46 -0
- package/dist/checks/qkv.d.ts +1 -0
- package/dist/checks/qkv.js +34 -0
- package/dist/checks/rope.d.ts +1 -0
- package/dist/checks/rope.js +30 -0
- package/dist/checks/weights.d.ts +14 -0
- package/dist/checks/weights.js +27 -0
- package/dist/chunk-BPntVaq0.js +23 -0
- package/dist/complex_util-CkazZsaH.js +60 -0
- package/dist/concat_util-CWDZCBlA.js +19 -0
- package/dist/data/docx.d.ts +2 -0
- package/dist/data/docx.js +3046 -0
- package/dist/data/pdf.d.ts +2 -0
- package/dist/data/pdf.js +17 -0
- package/dist/data/textLoader.d.ts +7 -0
- package/dist/data/textLoader.js +613 -0
- package/dist/dist-BewPQWjc.js +7572 -0
- package/dist/dist-DVmq73nz.js +8775 -0
- package/dist/dist-DXwIvKxl.js +896 -0
- package/dist/dist-VEU5mfO0.js +7545 -0
- package/dist/gelu-Bf1HW1RY.js +27 -0
- package/dist/gpgpu_math-DvLcCH6u.js +1612 -0
- package/dist/inference/types.d.ts +16 -0
- package/dist/inference/types.js +0 -0
- package/dist/kernel_funcs_utils-HiXOOx3f.js +229 -0
- package/dist/layers/BaseLayer.d.ts +44 -0
- package/dist/layers/BaseLayer.js +76 -0
- package/dist/layers/CausalSelfAttention.d.ts +39 -0
- package/dist/layers/CausalSelfAttention.js +99 -0
- package/dist/layers/LoRA.d.ts +14 -0
- package/dist/layers/LoRA.js +48 -0
- package/dist/layers/MLP.d.ts +17 -0
- package/dist/layers/MLP.js +34 -0
- package/dist/layers/PositionEmbedding.d.ts +8 -0
- package/dist/layers/PositionEmbedding.js +27 -0
- package/dist/layers/RMSNorm.d.ts +12 -0
- package/dist/layers/RMSNorm.js +20 -0
- package/dist/layers/RoPECache.d.ts +18 -0
- package/dist/layers/RoPECache.js +337 -0
- package/dist/layers/TiedEmbedding.d.ts +13 -0
- package/dist/layers/TiedEmbedding.js +32 -0
- package/dist/layers/TransformerBlock.d.ts +27 -0
- package/dist/layers/TransformerBlock.js +51 -0
- package/dist/layers/WeightStore.d.ts +20 -0
- package/dist/layers/WeightStore.js +69 -0
- package/dist/loader/load.d.ts +6 -0
- package/dist/loader/load.js +2 -0
- package/dist/loader/loadHF.d.ts +8 -0
- package/dist/loader/loadHF.js +2 -0
- package/dist/loader/loadTransformers.d.ts +4 -0
- package/dist/loader/loadTransformers.js +2 -0
- package/dist/loader/loadZipMeta.d.ts +3 -0
- package/dist/loader/loadZipMeta.js +16 -0
- package/dist/loader/newZipLoad.d.ts +3 -0
- package/dist/loader/newZipLoad.js +2 -0
- package/dist/loader/oldZipLoad.d.ts +9 -0
- package/dist/loader/oldZipLoad.js +2 -0
- package/dist/loader/save.d.ts +16 -0
- package/dist/loader/save.js +2 -0
- package/dist/loader/types.d.ts +68 -0
- package/dist/loader/types.js +0 -0
- package/dist/main-D5CbfCiV.js +13500 -0
- package/dist/main.d.ts +50 -0
- package/dist/main.js +16 -0
- package/dist/matMul16-BNfZSnNM.js +81 -0
- package/dist/matMulGelu-CPTntosE.js +162 -0
- package/dist/models/NanoGPTV1.d.ts +16 -0
- package/dist/models/NanoGPTV1.js +2 -0
- package/dist/models/NanoGPTV2.d.ts +16 -0
- package/dist/models/NanoGPTV2.js +2 -0
- package/dist/models/config.d.ts +27 -0
- package/dist/models/config.js +37 -0
- package/dist/models/factory.d.ts +3 -0
- package/dist/models/factory.js +2 -0
- package/dist/models/model.d.ts +44 -0
- package/dist/models/model.js +2 -0
- package/dist/ops/adamAdjust.d.ts +2 -0
- package/dist/ops/adamAdjust.js +18 -0
- package/dist/ops/adamMoments.d.ts +2 -0
- package/dist/ops/adamMoments.js +16 -0
- package/dist/ops/add16.d.ts +2 -0
- package/dist/ops/add16.js +12 -0
- package/dist/ops/appendCache.d.ts +2 -0
- package/dist/ops/appendCache.js +25 -0
- package/dist/ops/attentionMask.d.ts +2 -0
- package/dist/ops/attentionMask.js +16 -0
- package/dist/ops/concat16.d.ts +2 -0
- package/dist/ops/concat16.js +8 -0
- package/dist/ops/cpu/adamAdjust.d.ts +1 -0
- package/dist/ops/cpu/adamAdjust.js +16 -0
- package/dist/ops/cpu/adamMoments.d.ts +1 -0
- package/dist/ops/cpu/adamMoments.js +16 -0
- package/dist/ops/cpu/appendCache.d.ts +1 -0
- package/dist/ops/cpu/appendCache.js +65 -0
- package/dist/ops/cpu/attentionMask.d.ts +1 -0
- package/dist/ops/cpu/attentionMask.js +16 -0
- package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
- package/dist/ops/cpu/fusedSoftmax.js +22 -0
- package/dist/ops/cpu/gatherSub.d.ts +1 -0
- package/dist/ops/cpu/gatherSub.js +12 -0
- package/dist/ops/cpu/gelu.d.ts +1 -0
- package/dist/ops/cpu/gelu.js +36 -0
- package/dist/ops/cpu/matMul16.d.ts +1 -0
- package/dist/ops/cpu/matMul16.js +14 -0
- package/dist/ops/cpu/matMulGelu.d.ts +1 -0
- package/dist/ops/cpu/matMulGelu.js +41 -0
- package/dist/ops/cpu/matMulMul.d.ts +1 -0
- package/dist/ops/cpu/matMulMul.js +20 -0
- package/dist/ops/cpu/mulDropout.d.ts +1 -0
- package/dist/ops/cpu/mulDropout.js +20 -0
- package/dist/ops/cpu/normRMS.d.ts +1 -0
- package/dist/ops/cpu/normRMS.js +35 -0
- package/dist/ops/cpu/qkv.d.ts +5 -0
- package/dist/ops/cpu/qkv.js +73 -0
- package/dist/ops/cpu/rope.d.ts +6 -0
- package/dist/ops/cpu/rope.js +81 -0
- package/dist/ops/cpu/scatterSub.d.ts +1 -0
- package/dist/ops/cpu/scatterSub.js +12 -0
- package/dist/ops/dot16.d.ts +2 -0
- package/dist/ops/dot16.js +29 -0
- package/dist/ops/dropout.d.ts +2 -0
- package/dist/ops/dropout.js +11 -0
- package/dist/ops/dropout16.d.ts +2 -0
- package/dist/ops/dropout16.js +22 -0
- package/dist/ops/gatherSub.d.ts +2 -0
- package/dist/ops/gatherSub.js +13 -0
- package/dist/ops/gelu.d.ts +3 -0
- package/dist/ops/gelu.js +2 -0
- package/dist/ops/globalNorm.d.ts +2 -0
- package/dist/ops/globalNorm.js +19 -0
- package/dist/ops/grads/add16.d.ts +1 -0
- package/dist/ops/grads/add16.js +27 -0
- package/dist/ops/grads/attentionMask.d.ts +1 -0
- package/dist/ops/grads/attentionMask.js +26 -0
- package/dist/ops/grads/dropout16.d.ts +1 -0
- package/dist/ops/grads/dropout16.js +1 -0
- package/dist/ops/grads/gelu.d.ts +2 -0
- package/dist/ops/grads/gelu.js +2 -0
- package/dist/ops/grads/matMul16.d.ts +2 -0
- package/dist/ops/grads/matMul16.js +2 -0
- package/dist/ops/grads/matMulGelu.d.ts +1 -0
- package/dist/ops/grads/matMulGelu.js +22 -0
- package/dist/ops/grads/mul16.d.ts +1 -0
- package/dist/ops/grads/mul16.js +1 -0
- package/dist/ops/grads/normRMS.d.ts +3 -0
- package/dist/ops/grads/normRMS.js +37 -0
- package/dist/ops/grads/pack16.d.ts +2 -0
- package/dist/ops/grads/pack16.js +2 -0
- package/dist/ops/grads/qkv.d.ts +3 -0
- package/dist/ops/grads/qkv.js +46 -0
- package/dist/ops/grads/rope.d.ts +2 -0
- package/dist/ops/grads/rope.js +2 -0
- package/dist/ops/grads/softmax16.d.ts +2 -0
- package/dist/ops/grads/softmax16.js +23 -0
- package/dist/ops/grads/unpack16.d.ts +2 -0
- package/dist/ops/grads/unpack16.js +2 -0
- package/dist/ops/grads/utils.d.ts +4 -0
- package/dist/ops/grads/utils.js +12 -0
- package/dist/ops/log.d.ts +0 -0
- package/dist/ops/log.js +1 -0
- package/dist/ops/matMul16.d.ts +15 -0
- package/dist/ops/matMul16.js +2 -0
- package/dist/ops/matMulGelu.d.ts +3 -0
- package/dist/ops/matMulGelu.js +20 -0
- package/dist/ops/matMulMul.d.ts +2 -0
- package/dist/ops/matMulMul.js +16 -0
- package/dist/ops/mul16.d.ts +2 -0
- package/dist/ops/mul16.js +43 -0
- package/dist/ops/mulDrop.d.ts +2 -0
- package/dist/ops/mulDrop.js +15 -0
- package/dist/ops/normRMS.d.ts +2 -0
- package/dist/ops/normRMS.js +22 -0
- package/dist/ops/pack16.d.ts +2 -0
- package/dist/ops/pack16.js +2 -0
- package/dist/ops/qkv.d.ts +2 -0
- package/dist/ops/qkv.js +16 -0
- package/dist/ops/reshape16.d.ts +2 -0
- package/dist/ops/reshape16.js +33 -0
- package/dist/ops/rope.d.ts +3 -0
- package/dist/ops/rope.js +2 -0
- package/dist/ops/scatterSub.d.ts +2 -0
- package/dist/ops/scatterSub.js +13 -0
- package/dist/ops/slice16.d.ts +2 -0
- package/dist/ops/slice16.js +11 -0
- package/dist/ops/softmax16.d.ts +2 -0
- package/dist/ops/softmax16.js +9 -0
- package/dist/ops/sub16.d.ts +2 -0
- package/dist/ops/sub16.js +11 -0
- package/dist/ops/sum16.d.ts +2 -0
- package/dist/ops/sum16.js +13 -0
- package/dist/ops/transpose16.d.ts +3 -0
- package/dist/ops/transpose16.js +32 -0
- package/dist/ops/unpack16.d.ts +2 -0
- package/dist/ops/unpack16.js +2 -0
- package/dist/ops/webgl/adamAdjust.d.ts +1 -0
- package/dist/ops/webgl/adamAdjust.js +82 -0
- package/dist/ops/webgl/adamMoments.d.ts +1 -0
- package/dist/ops/webgl/adamMoments.js +44 -0
- package/dist/ops/webgl/appendCache.d.ts +1 -0
- package/dist/ops/webgl/appendCache.js +53 -0
- package/dist/ops/webgl/attentionMask.d.ts +1 -0
- package/dist/ops/webgl/attentionMask.js +64 -0
- package/dist/ops/webgl/dropout16.d.ts +1 -0
- package/dist/ops/webgl/dropout16.js +12 -0
- package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
- package/dist/ops/webgl/fusedSoftmax.js +70 -0
- package/dist/ops/webgl/gatherSub.d.ts +1 -0
- package/dist/ops/webgl/gatherSub.js +28 -0
- package/dist/ops/webgl/gelu.d.ts +2 -0
- package/dist/ops/webgl/gelu.js +48 -0
- package/dist/ops/webgl/log.d.ts +17 -0
- package/dist/ops/webgl/log.js +14 -0
- package/dist/ops/webgl/matMul16.d.ts +1 -0
- package/dist/ops/webgl/matMul16.js +37 -0
- package/dist/ops/webgl/matMulGelu.d.ts +21 -0
- package/dist/ops/webgl/matMulGelu.js +2 -0
- package/dist/ops/webgl/matMulMul.d.ts +14 -0
- package/dist/ops/webgl/matMulMul.js +24 -0
- package/dist/ops/webgl/mulDropout.d.ts +1 -0
- package/dist/ops/webgl/mulDropout.js +32 -0
- package/dist/ops/webgl/normRMS.d.ts +1 -0
- package/dist/ops/webgl/normRMS.js +114 -0
- package/dist/ops/webgl/qkv.d.ts +1 -0
- package/dist/ops/webgl/qkv.js +54 -0
- package/dist/ops/webgl/rope.d.ts +1 -0
- package/dist/ops/webgl/rope.js +72 -0
- package/dist/ops/webgl/scatterSub.d.ts +1 -0
- package/dist/ops/webgl/scatterSub.js +28 -0
- package/dist/ops/webgpu/adamAdjust.d.ts +1 -0
- package/dist/ops/webgpu/adamAdjust.js +77 -0
- package/dist/ops/webgpu/adamMoments.d.ts +1 -0
- package/dist/ops/webgpu/adamMoments.js +76 -0
- package/dist/ops/webgpu/add16.d.ts +1 -0
- package/dist/ops/webgpu/add16.js +14 -0
- package/dist/ops/webgpu/appendCache.d.ts +1 -0
- package/dist/ops/webgpu/appendCache.js +130 -0
- package/dist/ops/webgpu/attentionMask.d.ts +1 -0
- package/dist/ops/webgpu/attentionMask.js +42 -0
- package/dist/ops/webgpu/attentionMask32_program.d.ts +19 -0
- package/dist/ops/webgpu/attentionMask32_program.js +62 -0
- package/dist/ops/webgpu/clipScale.d.ts +1 -0
- package/dist/ops/webgpu/clipScale.js +45 -0
- package/dist/ops/webgpu/concat16.d.ts +19 -0
- package/dist/ops/webgpu/concat16.js +111 -0
- package/dist/ops/webgpu/dropout16.d.ts +1 -0
- package/dist/ops/webgpu/dropout16.js +59 -0
- package/dist/ops/webgpu/gatherSub.d.ts +1 -0
- package/dist/ops/webgpu/gatherSub.js +52 -0
- package/dist/ops/webgpu/gelu.d.ts +14 -0
- package/dist/ops/webgpu/gelu.js +147 -0
- package/dist/ops/webgpu/index.d.ts +0 -0
- package/dist/ops/webgpu/index.js +26 -0
- package/dist/ops/webgpu/matMul16.d.ts +1 -0
- package/dist/ops/webgpu/matMul16.js +70 -0
- package/dist/ops/webgpu/matMul16_program.d.ts +42 -0
- package/dist/ops/webgpu/matMul16_program.js +303 -0
- package/dist/ops/webgpu/mul16.d.ts +1 -0
- package/dist/ops/webgpu/mul16.js +14 -0
- package/dist/ops/webgpu/norm2.d.ts +1 -0
- package/dist/ops/webgpu/norm2.js +46 -0
- package/dist/ops/webgpu/normRMS.d.ts +1 -0
- package/dist/ops/webgpu/normRMS.js +26 -0
- package/dist/ops/webgpu/normRMS16_program.d.ts +10 -0
- package/dist/ops/webgpu/normRMS16_program.js +28 -0
- package/dist/ops/webgpu/normRMS32_program.d.ts +10 -0
- package/dist/ops/webgpu/normRMS32_program.js +28 -0
- package/dist/ops/webgpu/normRMSGrad.d.ts +1 -0
- package/dist/ops/webgpu/normRMSGrad.js +225 -0
- package/dist/ops/webgpu/pack16.d.ts +1 -0
- package/dist/ops/webgpu/pack16.js +21 -0
- package/dist/ops/webgpu/pack16_program.d.ts +19 -0
- package/dist/ops/webgpu/pack16_program.js +93 -0
- package/dist/ops/webgpu/qkv.d.ts +1 -0
- package/dist/ops/webgpu/qkv.js +64 -0
- package/dist/ops/webgpu/rope.d.ts +1 -0
- package/dist/ops/webgpu/rope.js +163 -0
- package/dist/ops/webgpu/scatterSub.d.ts +1 -0
- package/dist/ops/webgpu/scatterSub.js +53 -0
- package/dist/ops/webgpu/slice16.d.ts +7 -0
- package/dist/ops/webgpu/slice16.js +74 -0
- package/dist/ops/webgpu/softmax16.d.ts +17 -0
- package/dist/ops/webgpu/softmax16.js +18 -0
- package/dist/ops/webgpu/softmax16_program.d.ts +13 -0
- package/dist/ops/webgpu/softmax16_program.js +89 -0
- package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +17 -0
- package/dist/ops/webgpu/softmax16_subgroup_program.js +70 -0
- package/dist/ops/webgpu/softmax16grad.d.ts +1 -0
- package/dist/ops/webgpu/softmax16grad.js +31 -0
- package/dist/ops/webgpu/sub16.d.ts +1 -0
- package/dist/ops/webgpu/sub16.js +14 -0
- package/dist/ops/webgpu/sum16.d.ts +1 -0
- package/dist/ops/webgpu/sum16.js +29 -0
- package/dist/ops/webgpu/transpose16.d.ts +1 -0
- package/dist/ops/webgpu/transpose16.js +37 -0
- package/dist/ops/webgpu/transpose16_program.d.ts +16 -0
- package/dist/ops/webgpu/transpose16_program.js +51 -0
- package/dist/ops/webgpu/transpose16_shared_program.d.ts +15 -0
- package/dist/ops/webgpu/transpose16_shared_program.js +79 -0
- package/dist/ops/webgpu/unpack16.d.ts +1 -0
- package/dist/ops/webgpu/unpack16.js +60 -0
- package/dist/ops/webgpu/utils/binary_op.d.ts +35 -0
- package/dist/ops/webgpu/utils/binary_op.js +141 -0
- package/dist/ops/webgpu/utils/deviceInfo.d.ts +7 -0
- package/dist/ops/webgpu/utils/deviceInfo.js +11 -0
- package/dist/ops/webgpu/utils/reductions.d.ts +43 -0
- package/dist/ops/webgpu/utils/reductions.js +263 -0
- package/dist/pack16-Ck-spx_F.js +39 -0
- package/dist/patches/webgpu_backend.d.ts +18 -0
- package/dist/patches/webgpu_backend.js +43 -0
- package/dist/patches/webgpu_base.d.ts +21 -0
- package/dist/patches/webgpu_base.js +22 -0
- package/dist/patches/webgpu_program.d.ts +36 -0
- package/dist/patches/webgpu_program.js +293 -0
- package/dist/pdf-UoDqCYzz.js +16726 -0
- package/dist/picomatch-3tUnMMbd.js +1063 -0
- package/dist/rope-CbeGlsV8.js +25 -0
- package/dist/selu_util-zkAx5doH.js +24 -0
- package/dist/shared-D1coEFea.js +1314 -0
- package/dist/shared-DOgWaqvL.js +5 -0
- package/dist/slice_util-Dgb3ANWI.js +208 -0
- package/dist/tfjs_backend-BjuQ5FqB.js +614 -0
- package/dist/tokeniser/BaseTokeniser.d.ts +33 -0
- package/dist/tokeniser/BaseTokeniser.js +2 -0
- package/dist/tokeniser/CharTokeniser.d.ts +24 -0
- package/dist/tokeniser/CharTokeniser.js +92 -0
- package/dist/tokeniser/bpe.d.ts +28 -0
- package/dist/tokeniser/bpe.js +170 -0
- package/dist/tokeniser/messages.d.ts +61 -0
- package/dist/tokeniser/messages.js +0 -0
- package/dist/tokeniser/type.d.ts +34 -0
- package/dist/tokeniser/type.js +0 -0
- package/dist/training/AdamW.d.ts +36 -0
- package/dist/training/AdamW.js +128 -0
- package/dist/training/BasicTrainer.d.ts +63 -0
- package/dist/training/BasicTrainer.js +265 -0
- package/dist/training/DatasetBuilder.d.ts +26 -0
- package/dist/training/DatasetBuilder.js +2 -0
- package/dist/training/Evaluator.d.ts +19 -0
- package/dist/training/Evaluator.js +48 -0
- package/dist/training/LRScheduler.d.ts +12 -0
- package/dist/training/LRScheduler.js +38 -0
- package/dist/training/PreTrainer.d.ts +11 -0
- package/dist/training/PreTrainer.js +22 -0
- package/dist/training/SFTTrainer.d.ts +12 -0
- package/dist/training/SFTTrainer.js +24 -0
- package/dist/training/loss.d.ts +3 -0
- package/dist/training/loss.js +19 -0
- package/dist/training/orthoGrad.d.ts +2 -0
- package/dist/training/orthoGrad.js +10 -0
- package/dist/training/sparseCrossEntropy.d.ts +7 -0
- package/dist/training/sparseCrossEntropy.js +47 -0
- package/dist/training/tasks/ConversationTask.d.ts +18 -0
- package/dist/training/tasks/ConversationTask.js +38 -0
- package/dist/training/tasks/PretrainingTask.d.ts +17 -0
- package/dist/training/tasks/PretrainingTask.js +42 -0
- package/dist/training/tasks/StartSentenceTask.d.ts +18 -0
- package/dist/training/tasks/StartSentenceTask.js +45 -0
- package/dist/training/tasks/Task.d.ts +22 -0
- package/dist/training/tasks/Task.js +55 -0
- package/dist/training/tasks/splitter.d.ts +5 -0
- package/dist/training/tasks/splitter.js +18 -0
- package/dist/training/types.d.ts +78 -0
- package/dist/training/types.js +0 -0
- package/dist/training/validation.d.ts +17 -0
- package/dist/training/validation.js +2 -0
- package/dist/utilities/arrayClose.d.ts +1 -0
- package/dist/utilities/arrayClose.js +16 -0
- package/dist/utilities/datasetID.d.ts +2 -0
- package/dist/utilities/datasetID.js +18 -0
- package/dist/utilities/dummy.d.ts +9 -0
- package/dist/utilities/dummy.js +36 -0
- package/dist/utilities/multinomialCPU.d.ts +2 -0
- package/dist/utilities/multinomialCPU.js +9 -0
- package/dist/utilities/naming.d.ts +4 -0
- package/dist/utilities/naming.js +0 -0
- package/dist/utilities/packed.d.ts +4 -0
- package/dist/utilities/packed.js +13 -0
- package/dist/utilities/parameters.d.ts +11 -0
- package/dist/utilities/parameters.js +38 -0
- package/dist/utilities/performance.d.ts +2 -0
- package/dist/utilities/performance.js +16 -0
- package/dist/utilities/profile.d.ts +17 -0
- package/dist/utilities/profile.js +33 -0
- package/dist/utilities/safetensors.d.ts +3 -0
- package/dist/utilities/safetensors.js +53 -0
- package/dist/utilities/sentences.d.ts +5 -0
- package/dist/utilities/sentences.js +32 -0
- package/dist/utilities/tokenParse.d.ts +1 -0
- package/dist/utilities/tokenParse.js +17 -0
- package/dist/utilities/topP.d.ts +1 -0
- package/dist/utilities/topP.js +12 -0
- package/dist/utilities/waitForModel.d.ts +2 -0
- package/dist/utilities/waitForModel.js +12 -0
- package/dist/utilities/weights.d.ts +12 -0
- package/dist/utilities/weights.js +40 -0
- package/dist/utilities/yielder.d.ts +1 -0
- package/dist/utilities/yielder.js +7 -0
- package/dist/webgpu-Dt7BMzWz.js +525 -0
- package/dist/webgpu_program-WOyIVMlZ.js +392 -0
- package/dist/webgpu_util-B_F3SShA.js +106 -0
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Ot as e, T as t, di as n } from "../dist-BewPQWjc.js";
|
|
2
|
+
import r from "./BaseLayer.js";
|
|
3
|
+
import { normRMS as i } from "../ops/normRMS.js";
|
|
4
|
+
//#region lib/layers/RMSNorm.ts
|
|
5
|
+
var a = class extends r {
|
|
6
|
+
GAMMA;
|
|
7
|
+
rmsConfig;
|
|
8
|
+
constructor(n, r, i = "", a) {
|
|
9
|
+
super(n, a), this.GAMMA = i, this.rmsConfig = r, (this.rmsConfig.useGamma ?? !0) && this.addVariable(this.GAMMA, t(e([n.nEmbed]), !0, this.GAMMA, "float32"));
|
|
10
|
+
}
|
|
11
|
+
forward(e, t) {
|
|
12
|
+
return n(() => {
|
|
13
|
+
this.startMemory();
|
|
14
|
+
let e = i(t, this.rmsConfig.useGamma ?? !0 ? this.getVariable(this.GAMMA) : void 0);
|
|
15
|
+
return this.endMemory("RMSNorm"), e;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { a as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Tensor } from '@tensorflow/tfjs-core';
|
|
2
|
+
import { GPTConfig } from '../models/config';
|
|
3
|
+
export default class RoPECache {
|
|
4
|
+
private readonly config;
|
|
5
|
+
readonly rotaryDim: number;
|
|
6
|
+
private ropeBase;
|
|
7
|
+
private ropeInvFreq;
|
|
8
|
+
private ropeCos;
|
|
9
|
+
private ropeSin;
|
|
10
|
+
private ropeNegSin;
|
|
11
|
+
private ropeCacheLen;
|
|
12
|
+
constructor(config: GPTConfig);
|
|
13
|
+
ensureRopeCache(needed: number): void;
|
|
14
|
+
getCos(): Tensor | null;
|
|
15
|
+
getSin(): Tensor | null;
|
|
16
|
+
getNegSin(): Tensor | null;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { $n as e, $t as t, A as n, An as r, At as i, B as a, Bn as o, Br as s, Bt as ee, D as te, Dt as c, E as ne, Ei as l, Et as re, Fn as ie, Fr as ae, Ft as oe, G as se, Gn as ce, Gr as u, H as le, Hr as ue, Ht as de, Ir as d, It as f, J as p, Jt as m, K as h, Kn as g, Kr as _, Lr as v, Lt as y, Mn as b, Mr as x, Nn as S, Nr as C, Nt as w, O as T, Pn as E, Pr as D, Ps as O, Pt as k, Qn as A, Qt as j, R as M, Rr as N, Rt as P, St as F, Tt as I, U as L, Un as R, Ur as z, Ut as B, V, Vn as H, Vr as fe, Vt as pe, W as me, Wn as he, Wr as ge, Xn as _e, Xt as ve, Y as ye, Yr as U, Yt as be, Zt as xe, _n as W, _r as Se, _t as Ce, an as we, at as Te, bn as Ee, br as G, bt as De, cn as Oe, ct as ke, di as K, dn as Ae, dr as q, dt as J, en as je, et as Me, fn as Ne, fr as Pe, g as Fe, gn as Ie, gr as Le, gt as Re, h as ze, hn as Be, hr as Ve, ht as He, in as Ue, ir as We, it as Ge, jn as Ke, jt as qe, kn as Je, ln as Ye, lt as Xe, mn as Ze, mr as Qe, nn as $e, nt as et, oi as Y, on as tt, or as nt, ot as rt, pn as it, pr as at, q as ot, qr as st, rn as ct, rt as lt, sr as ut, st as dt, tn as ft, tt as X, un as pt, ut as Z, vn as Q, vt as mt, w as ht, wi as $, xt as gt, yn as _t, yr as vt, yt, z as bt, zn as xt, zr as St, zt as Ct } from "../dist-BewPQWjc.js";
|
|
2
|
+
//#endregion
|
|
3
|
+
//#region node_modules/@tensorflow/tfjs-core/dist/public/chained_ops/zeros_like.js
|
|
4
|
+
l().prototype.abs = function() {
|
|
5
|
+
return this.throwIfDisposed(), z(this);
|
|
6
|
+
}, l().prototype.acos = function() {
|
|
7
|
+
return this.throwIfDisposed(), ue(this);
|
|
8
|
+
}, l().prototype.acosh = function() {
|
|
9
|
+
return this.throwIfDisposed(), fe(this);
|
|
10
|
+
}, l().prototype.add = function(e) {
|
|
11
|
+
return this.throwIfDisposed(), st(this, e);
|
|
12
|
+
}, l().prototype.all = function(e, t) {
|
|
13
|
+
return this.throwIfDisposed(), s(this, e, t);
|
|
14
|
+
}, l().prototype.any = function(e, t) {
|
|
15
|
+
return this.throwIfDisposed(), St(this, e, t);
|
|
16
|
+
}, l().prototype.argMax = function(e) {
|
|
17
|
+
return this.throwIfDisposed(), N(this, e);
|
|
18
|
+
}, l().prototype.argMin = function(e) {
|
|
19
|
+
return this.throwIfDisposed(), v(this, e);
|
|
20
|
+
}, l().prototype.asScalar = function() {
|
|
21
|
+
return this.throwIfDisposed(), O(this.size === 1, () => "The array must have only 1 element."), G(this, []);
|
|
22
|
+
}, l().prototype.asType = function(e) {
|
|
23
|
+
return this.throwIfDisposed(), U(this, e);
|
|
24
|
+
}, l().prototype.as1D = function() {
|
|
25
|
+
return this.throwIfDisposed(), G(this, [this.size]);
|
|
26
|
+
}, l().prototype.as2D = function(e, t) {
|
|
27
|
+
return this.throwIfDisposed(), G(this, [e, t]);
|
|
28
|
+
}, l().prototype.as3D = function(e, t, n) {
|
|
29
|
+
return this.throwIfDisposed(), G(this, [
|
|
30
|
+
e,
|
|
31
|
+
t,
|
|
32
|
+
n
|
|
33
|
+
]);
|
|
34
|
+
}, l().prototype.as4D = function(e, t, n, r) {
|
|
35
|
+
return this.throwIfDisposed(), G(this, [
|
|
36
|
+
e,
|
|
37
|
+
t,
|
|
38
|
+
n,
|
|
39
|
+
r
|
|
40
|
+
]);
|
|
41
|
+
}, l().prototype.as5D = function(e, t, n, r, i) {
|
|
42
|
+
return this.throwIfDisposed(), G(this, [
|
|
43
|
+
e,
|
|
44
|
+
t,
|
|
45
|
+
n,
|
|
46
|
+
r,
|
|
47
|
+
i
|
|
48
|
+
]);
|
|
49
|
+
}, l().prototype.asin = function() {
|
|
50
|
+
return this.throwIfDisposed(), d(this);
|
|
51
|
+
}, l().prototype.asinh = function() {
|
|
52
|
+
return this.throwIfDisposed(), ae(this);
|
|
53
|
+
}, l().prototype.atan = function() {
|
|
54
|
+
return this.throwIfDisposed(), D(this);
|
|
55
|
+
}, l().prototype.atan2 = function(e) {
|
|
56
|
+
return this.throwIfDisposed(), C(this, e);
|
|
57
|
+
}, l().prototype.atanh = function() {
|
|
58
|
+
return this.throwIfDisposed(), x(this);
|
|
59
|
+
}, l().prototype.avgPool = function(e, t, n, r) {
|
|
60
|
+
return this.throwIfDisposed(), vt(this, e, t, n, r);
|
|
61
|
+
}, l().prototype.batchToSpaceND = function(e, t) {
|
|
62
|
+
return this.throwIfDisposed(), Pe(this, e, t);
|
|
63
|
+
}, l().prototype.batchNorm = function(e, t, n, r, i) {
|
|
64
|
+
return this.throwIfDisposed(), q(this, e, t, n, r, i);
|
|
65
|
+
}, l().prototype.broadcastTo = function(e) {
|
|
66
|
+
return this.throwIfDisposed(), ut(this, e);
|
|
67
|
+
}, l().prototype.cast = function(e) {
|
|
68
|
+
return this.throwIfDisposed(), U(this, e);
|
|
69
|
+
}, l().prototype.ceil = function() {
|
|
70
|
+
return this.throwIfDisposed(), nt(this);
|
|
71
|
+
}, l().prototype.clipByValue = function(e, t) {
|
|
72
|
+
return this.throwIfDisposed(), We(this, e, t);
|
|
73
|
+
}, l().prototype.concat = function(e, t) {
|
|
74
|
+
return this.throwIfDisposed(), e instanceof $ && (e = [e]), Se([this, ...e], t);
|
|
75
|
+
}, l().prototype.conv1d = function(e, t, n, r, i, a) {
|
|
76
|
+
return this.throwIfDisposed(), A(this, e, t, n, r, i, a);
|
|
77
|
+
}, l().prototype.conv2dTranspose = function(e, t, n, r, i) {
|
|
78
|
+
return this.throwIfDisposed(), _e(this, e, t, n, r, i);
|
|
79
|
+
}, l().prototype.conv2d = function(t, n, r, i, a, o) {
|
|
80
|
+
return this.throwIfDisposed(), e(this, t, n, r, i, a, o);
|
|
81
|
+
}, l().prototype.cos = function() {
|
|
82
|
+
return this.throwIfDisposed(), g(this);
|
|
83
|
+
}, l().prototype.cosh = function() {
|
|
84
|
+
return this.throwIfDisposed(), ce(this);
|
|
85
|
+
}, l().prototype.cumprod = function(e, t, n) {
|
|
86
|
+
return this.throwIfDisposed(), he(this, e, t, n);
|
|
87
|
+
}, l().prototype.cumsum = function(e, t, n) {
|
|
88
|
+
return this.throwIfDisposed(), R(this, e, t, n);
|
|
89
|
+
}, l().prototype.depthToSpace = function(e, t) {
|
|
90
|
+
return this.throwIfDisposed(), H(this, e, t);
|
|
91
|
+
}, l().prototype.depthwiseConv2d = function(e, t, n, r, i, a) {
|
|
92
|
+
return this.throwIfDisposed(), o(this, e, t, n, r, i, a);
|
|
93
|
+
}, l().prototype.dilation2d = function(e, t, n, r, i) {
|
|
94
|
+
return this.throwIfDisposed(), xt(this, e, t, n, r, i);
|
|
95
|
+
}, l().prototype.divNoNan = function(e) {
|
|
96
|
+
return this.throwIfDisposed(), b(this, e);
|
|
97
|
+
}, l().prototype.div = function(e) {
|
|
98
|
+
return this.throwIfDisposed(), u(this, e);
|
|
99
|
+
}, l().prototype.dot = function(e) {
|
|
100
|
+
return this.throwIfDisposed(), Ke(this, e);
|
|
101
|
+
}, l().prototype.elu = function() {
|
|
102
|
+
return this.throwIfDisposed(), r(this);
|
|
103
|
+
}, l().prototype.equal = function(e) {
|
|
104
|
+
return this.throwIfDisposed(), ie(this, e);
|
|
105
|
+
}, l().prototype.erf = function() {
|
|
106
|
+
return this.throwIfDisposed(), Je(this);
|
|
107
|
+
}, l().prototype.euclideanNorm = function(e, t) {
|
|
108
|
+
return this.throwIfDisposed(), Ne(this, e, t);
|
|
109
|
+
}, l().prototype.exp = function() {
|
|
110
|
+
return this.throwIfDisposed(), Ae(this);
|
|
111
|
+
}, l().prototype.expandDims = function(e) {
|
|
112
|
+
return this.throwIfDisposed(), pt(this, e);
|
|
113
|
+
}, l().prototype.expm1 = function() {
|
|
114
|
+
return this.throwIfDisposed(), Ye(this);
|
|
115
|
+
}, l().prototype.fft = function() {
|
|
116
|
+
return this.throwIfDisposed(), p(this);
|
|
117
|
+
}, l().prototype.flatten = function() {
|
|
118
|
+
return this.throwIfDisposed(), G(this, [this.size]);
|
|
119
|
+
}, l().prototype.floor = function() {
|
|
120
|
+
return this.throwIfDisposed(), tt(this);
|
|
121
|
+
}, l().prototype.floorDiv = function(e) {
|
|
122
|
+
return this.throwIfDisposed(), _(this, e);
|
|
123
|
+
}, l().prototype.gather = function(e, t, n) {
|
|
124
|
+
return this.throwIfDisposed(), we(this, e, t, n);
|
|
125
|
+
}, l().prototype.greaterEqual = function(e) {
|
|
126
|
+
return this.throwIfDisposed(), ct(this, e);
|
|
127
|
+
}, l().prototype.greater = function(e) {
|
|
128
|
+
return this.throwIfDisposed(), Ue(this, e);
|
|
129
|
+
}, l().prototype.ifft = function() {
|
|
130
|
+
return this.throwIfDisposed(), ot(this);
|
|
131
|
+
}, l().prototype.irfft = function() {
|
|
132
|
+
return this.throwIfDisposed(), h(this);
|
|
133
|
+
}, l().prototype.isFinite = function() {
|
|
134
|
+
return this.throwIfDisposed(), $e(this);
|
|
135
|
+
}, l().prototype.isInf = function() {
|
|
136
|
+
return this.throwIfDisposed(), ft(this);
|
|
137
|
+
}, l().prototype.isNaN = function() {
|
|
138
|
+
return this.throwIfDisposed(), je(this);
|
|
139
|
+
}, l().prototype.leakyRelu = function(e) {
|
|
140
|
+
return this.throwIfDisposed(), t(this, e);
|
|
141
|
+
}, l().prototype.lessEqual = function(e) {
|
|
142
|
+
return this.throwIfDisposed(), xe(this, e);
|
|
143
|
+
}, l().prototype.less = function(e) {
|
|
144
|
+
return this.throwIfDisposed(), j(this, e);
|
|
145
|
+
}, l().prototype.localResponseNormalization = function(e, t, n, r) {
|
|
146
|
+
return this.throwIfDisposed(), ve(this, e, t, n, r);
|
|
147
|
+
}, l().prototype.logSigmoid = function() {
|
|
148
|
+
return this.throwIfDisposed(), pe(this);
|
|
149
|
+
}, l().prototype.logSoftmax = function(e) {
|
|
150
|
+
return this.throwIfDisposed(), Ct(this, e);
|
|
151
|
+
}, l().prototype.logSumExp = function(e, t) {
|
|
152
|
+
return this.throwIfDisposed(), P(this, e, t);
|
|
153
|
+
}, l().prototype.log = function() {
|
|
154
|
+
return this.throwIfDisposed(), be(this);
|
|
155
|
+
}, l().prototype.log1p = function() {
|
|
156
|
+
return this.throwIfDisposed(), m(this);
|
|
157
|
+
}, l().prototype.logicalAnd = function(e) {
|
|
158
|
+
return this.throwIfDisposed(), y(this, e);
|
|
159
|
+
}, l().prototype.logicalNot = function() {
|
|
160
|
+
return this.throwIfDisposed(), f(this);
|
|
161
|
+
}, l().prototype.logicalOr = function(e) {
|
|
162
|
+
return this.throwIfDisposed(), oe(this, e);
|
|
163
|
+
}, l().prototype.logicalXor = function(e) {
|
|
164
|
+
return this.throwIfDisposed(), k(this, e);
|
|
165
|
+
}, l().prototype.matMul = function(e, t, n) {
|
|
166
|
+
return this.throwIfDisposed(), Le(this, e, t, n);
|
|
167
|
+
}, l().prototype.maxPool = function(e, t, n, r) {
|
|
168
|
+
return this.throwIfDisposed(), w(this, e, t, n, r);
|
|
169
|
+
}, l().prototype.max = function(e, t) {
|
|
170
|
+
return this.throwIfDisposed(), Ee(this, e, t);
|
|
171
|
+
}, l().prototype.maximum = function(e) {
|
|
172
|
+
return this.throwIfDisposed(), qe(this, e);
|
|
173
|
+
}, l().prototype.mean = function(e, t) {
|
|
174
|
+
return this.throwIfDisposed(), i(this, e, t);
|
|
175
|
+
}, l().prototype.min = function(e, t) {
|
|
176
|
+
return this.throwIfDisposed(), _t(this, e, t);
|
|
177
|
+
}, l().prototype.minimum = function(e) {
|
|
178
|
+
return this.throwIfDisposed(), c(this, e);
|
|
179
|
+
}, l().prototype.mirrorPad = function(e, t) {
|
|
180
|
+
return this.throwIfDisposed(), re(this, e, t);
|
|
181
|
+
}, l().prototype.mod = function(e) {
|
|
182
|
+
return this.throwIfDisposed(), I(this, e);
|
|
183
|
+
}, l().prototype.mul = function(e) {
|
|
184
|
+
return this.throwIfDisposed(), ge(this, e);
|
|
185
|
+
}, l().prototype.neg = function() {
|
|
186
|
+
return this.throwIfDisposed(), B(this);
|
|
187
|
+
}, l().prototype.norm = function(e, t, n) {
|
|
188
|
+
return this.throwIfDisposed(), it(this, e, t, n);
|
|
189
|
+
}, l().prototype.notEqual = function(e) {
|
|
190
|
+
return this.throwIfDisposed(), F(this, e);
|
|
191
|
+
}, l().prototype.oneHot = function(e, t = 1, n = 0) {
|
|
192
|
+
return this.throwIfDisposed(), gt(this, e, t, n);
|
|
193
|
+
}, l().prototype.onesLike = function() {
|
|
194
|
+
return this.throwIfDisposed(), De(this);
|
|
195
|
+
}, l().prototype.pad = function(e, t) {
|
|
196
|
+
return this.throwIfDisposed(), yt(this, e, t);
|
|
197
|
+
}, l().prototype.pool = function(e, t, n, r, i, a) {
|
|
198
|
+
return this.throwIfDisposed(), Ce(this, e, t, n, r, i, a);
|
|
199
|
+
}, l().prototype.pow = function(e) {
|
|
200
|
+
return this.throwIfDisposed(), Q(this, e);
|
|
201
|
+
}, l().prototype.prelu = function(e) {
|
|
202
|
+
return this.throwIfDisposed(), Re(this, e);
|
|
203
|
+
}, l().prototype.prod = function(e, t) {
|
|
204
|
+
return this.throwIfDisposed(), He(this, e, t);
|
|
205
|
+
}, l().prototype.reciprocal = function() {
|
|
206
|
+
return this.throwIfDisposed(), Z(this);
|
|
207
|
+
}, l().prototype.relu = function() {
|
|
208
|
+
return this.throwIfDisposed(), Xe(this);
|
|
209
|
+
}, l().prototype.relu6 = function() {
|
|
210
|
+
return this.throwIfDisposed(), ke(this);
|
|
211
|
+
}, l().prototype.reshapeAs = function(e) {
|
|
212
|
+
return this.throwIfDisposed(), G(this, e.shape);
|
|
213
|
+
}, l().prototype.reshape = function(e) {
|
|
214
|
+
return this.throwIfDisposed(), G(this, e);
|
|
215
|
+
}, l().prototype.resizeBilinear = function(e, t, n) {
|
|
216
|
+
return this.throwIfDisposed(), Fe(this, e, t, n);
|
|
217
|
+
}, l().prototype.resizeNearestNeighbor = function(e, t, n) {
|
|
218
|
+
return this.throwIfDisposed(), ze(this, e, t, n);
|
|
219
|
+
}, l().prototype.reverse = function(e) {
|
|
220
|
+
return this.throwIfDisposed(), dt(this, e);
|
|
221
|
+
}, l().prototype.rfft = function() {
|
|
222
|
+
return this.throwIfDisposed(), me(this);
|
|
223
|
+
}, l().prototype.round = function() {
|
|
224
|
+
return this.throwIfDisposed(), rt(this);
|
|
225
|
+
}, l().prototype.rsqrt = function() {
|
|
226
|
+
return this.throwIfDisposed(), Te(this);
|
|
227
|
+
}, l().prototype.selu = function() {
|
|
228
|
+
return this.throwIfDisposed(), Ge(this);
|
|
229
|
+
}, l().prototype.separableConv2d = function(e, t, n, r, i, a) {
|
|
230
|
+
return this.throwIfDisposed(), lt(this, e, t, n, r, i, a);
|
|
231
|
+
}, l().prototype.sigmoid = function() {
|
|
232
|
+
return this.throwIfDisposed(), Ve(this);
|
|
233
|
+
}, l().prototype.sign = function() {
|
|
234
|
+
return this.throwIfDisposed(), et(this);
|
|
235
|
+
}, l().prototype.sin = function() {
|
|
236
|
+
return this.throwIfDisposed(), X(this);
|
|
237
|
+
}, l().prototype.sinh = function() {
|
|
238
|
+
return this.throwIfDisposed(), Me(this);
|
|
239
|
+
}, l().prototype.slice = function(e, t) {
|
|
240
|
+
return this.throwIfDisposed(), Qe(this, e, t);
|
|
241
|
+
}, l().prototype.softmax = function(e) {
|
|
242
|
+
return this.throwIfDisposed(), ye(this, e);
|
|
243
|
+
}, l().prototype.softplus = function() {
|
|
244
|
+
return this.throwIfDisposed(), de(this);
|
|
245
|
+
}, l().prototype.spaceToBatchND = function(e, t) {
|
|
246
|
+
return this.throwIfDisposed(), mt(this, e, t);
|
|
247
|
+
}, l().prototype.split = function(e, t) {
|
|
248
|
+
return this.throwIfDisposed(), se(this, e, t);
|
|
249
|
+
}, l().prototype.sqrt = function() {
|
|
250
|
+
return this.throwIfDisposed(), Ie(this);
|
|
251
|
+
}, l().prototype.square = function() {
|
|
252
|
+
return this.throwIfDisposed(), Be(this);
|
|
253
|
+
}, l().prototype.squaredDifference = function(e) {
|
|
254
|
+
return this.throwIfDisposed(), L(this, e);
|
|
255
|
+
}, l().prototype.squeeze = function(e) {
|
|
256
|
+
return this.throwIfDisposed(), le(this, e);
|
|
257
|
+
}, l().prototype.stack = function(e, t) {
|
|
258
|
+
return this.throwIfDisposed(), V(e instanceof $ ? [this, e] : [this, ...e], t);
|
|
259
|
+
}, l().prototype.step = function(e) {
|
|
260
|
+
return this.throwIfDisposed(), a(this, e);
|
|
261
|
+
}, l().prototype.stridedSlice = function(e, t, n, r, i, a, o, s) {
|
|
262
|
+
return this.throwIfDisposed(), bt(this, e, t, n, r, i, a, o, s);
|
|
263
|
+
}, l().prototype.sub = function(e) {
|
|
264
|
+
return this.throwIfDisposed(), ee(this, e);
|
|
265
|
+
}, l().prototype.sum = function(e, t) {
|
|
266
|
+
return this.throwIfDisposed(), Ze(this, e, t);
|
|
267
|
+
}, l().prototype.tan = function() {
|
|
268
|
+
return this.throwIfDisposed(), M(this);
|
|
269
|
+
}, l().prototype.tanh = function() {
|
|
270
|
+
return this.throwIfDisposed(), at(this);
|
|
271
|
+
}, l().prototype.tile = function(e) {
|
|
272
|
+
return this.throwIfDisposed(), Oe(this, e);
|
|
273
|
+
}, l().prototype.toBool = function() {
|
|
274
|
+
return this.throwIfDisposed(), U(this, "bool");
|
|
275
|
+
}, l().prototype.toFloat = function() {
|
|
276
|
+
return this.throwIfDisposed(), U(this, "float32");
|
|
277
|
+
}, l().prototype.toInt = function() {
|
|
278
|
+
return this.throwIfDisposed(), U(this, "int32");
|
|
279
|
+
}, l().prototype.topk = function(e, t) {
|
|
280
|
+
return this.throwIfDisposed(), n(this, e, t);
|
|
281
|
+
}, l().prototype.transpose = function(e) {
|
|
282
|
+
return this.throwIfDisposed(), ht(this, e);
|
|
283
|
+
}, l().prototype.unique = function(e) {
|
|
284
|
+
return this.throwIfDisposed(), T(this, e);
|
|
285
|
+
}, l().prototype.unsortedSegmentSum = function(e, t) {
|
|
286
|
+
return this.throwIfDisposed(), te(this, e, t);
|
|
287
|
+
}, l().prototype.unstack = function(e) {
|
|
288
|
+
return this.throwIfDisposed(), ne(this, e);
|
|
289
|
+
}, l().prototype.where = function(e, t) {
|
|
290
|
+
return this.throwIfDisposed(), E(e, this, t);
|
|
291
|
+
}, l().prototype.zerosLike = function() {
|
|
292
|
+
return this.throwIfDisposed(), S(this);
|
|
293
|
+
};
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region lib/layers/RoPECache.ts
|
|
296
|
+
var wt = class {
|
|
297
|
+
config;
|
|
298
|
+
rotaryDim;
|
|
299
|
+
ropeBase;
|
|
300
|
+
ropeInvFreq;
|
|
301
|
+
ropeCos = null;
|
|
302
|
+
ropeSin = null;
|
|
303
|
+
ropeNegSin = null;
|
|
304
|
+
ropeCacheLen = 0;
|
|
305
|
+
constructor(e) {
|
|
306
|
+
this.config = e;
|
|
307
|
+
let t = this.config.nEmbed / this.config.nHead;
|
|
308
|
+
if (this.rotaryDim = t, this.rotaryDim % 2 != 0) throw Error("rotaryDim must be even");
|
|
309
|
+
this.ropeBase = 1e4;
|
|
310
|
+
let n = J(0, this.rotaryDim, 2, "float32"), r = u(n, W(this.rotaryDim, "float32")), i = Q(W(this.ropeBase, "float32"), r);
|
|
311
|
+
this.ropeInvFreq = Z(i), r.dispose(), i.dispose(), n.dispose(), (this.config.modelType === "GenAI_NanoGPT_v1" ? this.config.useRope ?? !0 : !0) === !1 ? (this.ropeCos = null, this.ropeSin = null, this.ropeNegSin = null, this.ropeCacheLen = 0) : K(() => {
|
|
312
|
+
this.ensureRopeCache(this.config.blockSize * 4);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
ensureRopeCache(e) {
|
|
316
|
+
K(() => {
|
|
317
|
+
if (e <= this.ropeCacheLen) return;
|
|
318
|
+
this.ropeCos && this.ropeCos.dispose(), this.ropeSin && this.ropeSin.dispose();
|
|
319
|
+
let t = Math.max(e, this.ropeCacheLen + this.config.blockSize * 4), n = J(0, t, 1, "float32").expandDims(1).mul(this.ropeInvFreq.expandDims(0));
|
|
320
|
+
this.ropeCos = Y(g(n).expandDims(-1)), this.ropeSin = Y(X(n).expandDims(-1)), this.ropeNegSin = Y(this.ropeSin.neg()), this.ropeCacheLen = t;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
getCos() {
|
|
324
|
+
return this.ropeCos;
|
|
325
|
+
}
|
|
326
|
+
getSin() {
|
|
327
|
+
return this.ropeSin;
|
|
328
|
+
}
|
|
329
|
+
getNegSin() {
|
|
330
|
+
return this.ropeNegSin;
|
|
331
|
+
}
|
|
332
|
+
dispose() {
|
|
333
|
+
this.ropeCos && this.ropeCos.dispose(), this.ropeSin && this.ropeSin.dispose(), this.ropeInvFreq.dispose();
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
//#endregion
|
|
337
|
+
export { wt as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Tensor } from '@tensorflow/tfjs-core';
|
|
2
|
+
import { default as BaseLayer, ForwardAttributes } from './BaseLayer';
|
|
3
|
+
import { GPTConfig } from '../../models/config';
|
|
4
|
+
export default class TiedEmbeddingOutputLayer extends BaseLayer {
|
|
5
|
+
private vocabSize;
|
|
6
|
+
private embedDim;
|
|
7
|
+
private initializer;
|
|
8
|
+
private WEIGHTS;
|
|
9
|
+
constructor(config: GPTConfig, name: string, parent?: BaseLayer);
|
|
10
|
+
embed(inputs: Tensor): Tensor;
|
|
11
|
+
project(inputs: Tensor): Tensor;
|
|
12
|
+
forward(_: ForwardAttributes, x: Tensor): Tensor;
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { T as e, an as t } from "../dist-BewPQWjc.js";
|
|
2
|
+
import { n } from "../dist-VEU5mfO0.js";
|
|
3
|
+
import { isPackedTensor as r } from "../utilities/packed.js";
|
|
4
|
+
import { transpose16 as i } from "../ops/transpose16.js";
|
|
5
|
+
import { t as a } from "../pack16-Ck-spx_F.js";
|
|
6
|
+
import o from "./BaseLayer.js";
|
|
7
|
+
import { dot16 as s } from "../ops/dot16.js";
|
|
8
|
+
//#region lib/layers/TiedEmbedding.ts
|
|
9
|
+
var c = class extends o {
|
|
10
|
+
vocabSize;
|
|
11
|
+
embedDim;
|
|
12
|
+
initializer;
|
|
13
|
+
WEIGHTS;
|
|
14
|
+
constructor(t, r, i) {
|
|
15
|
+
super(t, i), this.WEIGHTS = r, this.vocabSize = t.vocabSize, this.embedDim = t.nEmbed, this.initializer = n({
|
|
16
|
+
mean: 0,
|
|
17
|
+
stddev: .02
|
|
18
|
+
}), this.addVariable(this.WEIGHTS, e(this.initializer.apply([this.vocabSize, this.embedDim]), !0, r));
|
|
19
|
+
}
|
|
20
|
+
embed(e) {
|
|
21
|
+
return t(this.getVariable(this.WEIGHTS), e, 0);
|
|
22
|
+
}
|
|
23
|
+
project(e) {
|
|
24
|
+
let t = r(e) ? a(this.getVariable(this.WEIGHTS), void 0, 32) : this.getVariable(this.WEIGHTS), n = i(t);
|
|
25
|
+
return r(e) && t.dispose(), s(e, n);
|
|
26
|
+
}
|
|
27
|
+
forward(e, t) {
|
|
28
|
+
return this.project(t);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { c as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AttentionScores, CausalSelfAttentionConfig, KVCache } from './CausalSelfAttention';
|
|
2
|
+
import { MLPConfig } from './MLP';
|
|
3
|
+
import { RMSNormConfig } from './RMSNorm';
|
|
4
|
+
import { default as BaseLayer, ForwardAttributes } from './BaseLayer';
|
|
5
|
+
import { Tensor } from '@tensorflow/tfjs-core';
|
|
6
|
+
import { GPTConfig } from '../../models/config';
|
|
7
|
+
interface BlockAttributes extends ForwardAttributes {
|
|
8
|
+
pastKV?: KVCache;
|
|
9
|
+
seed?: number;
|
|
10
|
+
attentionScores?: AttentionScores;
|
|
11
|
+
ropePositionOffset?: number;
|
|
12
|
+
}
|
|
13
|
+
export type TransformerBlockConfig = MLPConfig & RMSNormConfig & CausalSelfAttentionConfig;
|
|
14
|
+
export default class Block extends BaseLayer<BlockAttributes> {
|
|
15
|
+
private ln1;
|
|
16
|
+
private attn;
|
|
17
|
+
private ln2;
|
|
18
|
+
private mlp;
|
|
19
|
+
private index;
|
|
20
|
+
skipped: boolean;
|
|
21
|
+
private blockConfig;
|
|
22
|
+
constructor(index: number, config: GPTConfig, blockConfig: TransformerBlockConfig, parent?: BaseLayer);
|
|
23
|
+
private getMLPOutput;
|
|
24
|
+
forward(attrs: BlockAttributes, x: Tensor): Tensor;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { di as e, oi as t } from "../dist-BewPQWjc.js";
|
|
2
|
+
import n from "./BaseLayer.js";
|
|
3
|
+
import r from "./CausalSelfAttention.js";
|
|
4
|
+
import i from "./MLP.js";
|
|
5
|
+
import a from "./RMSNorm.js";
|
|
6
|
+
import { add16 as o } from "../ops/add16.js";
|
|
7
|
+
//#region lib/layers/TransformerBlock.ts
|
|
8
|
+
var s = class extends n {
|
|
9
|
+
ln1;
|
|
10
|
+
attn;
|
|
11
|
+
ln2;
|
|
12
|
+
mlp;
|
|
13
|
+
index;
|
|
14
|
+
skipped = !1;
|
|
15
|
+
blockConfig;
|
|
16
|
+
constructor(e, t, n, o) {
|
|
17
|
+
super(t, o), this.index = e, this.blockConfig = n, this.ln1 = new a(t, this.blockConfig, `block_${this.index}_rms1`, this), this.attn = new r(this.index, t, this.blockConfig, this), this.ln2 = new a(t, this.blockConfig, `block_${this.index}_rms2`, this), this.mlp = new i(this.index, t, this.blockConfig, this);
|
|
18
|
+
}
|
|
19
|
+
getMLPOutput(e, n) {
|
|
20
|
+
let r = this.ln2.call({ training: n.training }, e), i = this.mlp.call(n, r);
|
|
21
|
+
n.outputEmbeddings ? (t(r), n.embeddings.push({
|
|
22
|
+
name: `block_ln2_${this.index}`,
|
|
23
|
+
tensor: r
|
|
24
|
+
})) : r.dispose();
|
|
25
|
+
let a = o(e, i);
|
|
26
|
+
return e.dispose(), n.outputEmbeddings ? (t(i), n.embeddings.push({
|
|
27
|
+
name: `block_mlp_out_${this.index}`,
|
|
28
|
+
tensor: i
|
|
29
|
+
})) : i.dispose(), a;
|
|
30
|
+
}
|
|
31
|
+
forward(n, r) {
|
|
32
|
+
return e(() => {
|
|
33
|
+
if (this.skipped) return r;
|
|
34
|
+
let e = this.ln1.call(n, r), i = this.attn.call(n, e);
|
|
35
|
+
n.outputEmbeddings ? (t(e), n.embeddings.push({
|
|
36
|
+
name: `block_ln1_${this.index}`,
|
|
37
|
+
tensor: e
|
|
38
|
+
})) : e.dispose();
|
|
39
|
+
let a = o(r, i);
|
|
40
|
+
return n.outputEmbeddings ? (t(i), n.embeddings.push({
|
|
41
|
+
name: `block_attn_out_${this.index}`,
|
|
42
|
+
tensor: i
|
|
43
|
+
})) : i.dispose(), this.getMLPOutput(a, n);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
dispose() {
|
|
47
|
+
this.ln1.dispose(), this.attn.dispose(), this.ln2.dispose(), this.mlp.dispose();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { s as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Tensor, Variable } from '@tensorflow/tfjs-core';
|
|
2
|
+
export default class WeightStore {
|
|
3
|
+
private _variables;
|
|
4
|
+
private touchedVariables;
|
|
5
|
+
onWeightRead?: (name: string, variable: Variable) => Tensor;
|
|
6
|
+
saveWeights(map: Map<string, Tensor[]>): void;
|
|
7
|
+
loadWeights(weights: Map<string, Tensor[]>, reference: boolean, trainable?: boolean): void;
|
|
8
|
+
addVariable(name: string, variable?: Variable): void;
|
|
9
|
+
deleteVariable(name: string): void;
|
|
10
|
+
get variables(): Variable[];
|
|
11
|
+
get variableNames(): string[];
|
|
12
|
+
get trainableVariables(): Variable[];
|
|
13
|
+
getRawVariable(name: string): Variable;
|
|
14
|
+
getVariable(name: string): Tensor;
|
|
15
|
+
setTrainable(names: string[]): void;
|
|
16
|
+
hasVariable(name: string): boolean;
|
|
17
|
+
setVariable(name: string, variable: Variable): void;
|
|
18
|
+
touchVariables(names: string[]): void;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { a as e } from "../chunk-BPntVaq0.js";
|
|
2
|
+
import { Jr as t, T as n } from "../dist-BewPQWjc.js";
|
|
3
|
+
import { t as r } from "../picomatch-3tUnMMbd.js";
|
|
4
|
+
//#region lib/layers/WeightStore.ts
|
|
5
|
+
var i = /* @__PURE__ */ e(r(), 1), a = class {
|
|
6
|
+
_variables = /* @__PURE__ */ new Map();
|
|
7
|
+
touchedVariables = /* @__PURE__ */ new Set();
|
|
8
|
+
onWeightRead;
|
|
9
|
+
saveWeights(e) {
|
|
10
|
+
this._variables.forEach((n, r) => {
|
|
11
|
+
n && this.touchedVariables.has(r) && e.set(r, [t(n)]);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
loadWeights(e, t, r = !0) {
|
|
15
|
+
e.forEach((e, i) => {
|
|
16
|
+
let a = e[0], o = this._variables.get(i);
|
|
17
|
+
o ? o.assign(a) : this._variables.set(i, n(a, r, i)), t ? this.touchedVariables.delete(i) : this.touchedVariables.add(i);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
addVariable(e, t) {
|
|
21
|
+
this._variables.set(e, t || null);
|
|
22
|
+
}
|
|
23
|
+
deleteVariable(e) {
|
|
24
|
+
let t = this._variables.get(e);
|
|
25
|
+
t && t.dispose(), this._variables.delete(e), this.touchedVariables.delete(e);
|
|
26
|
+
}
|
|
27
|
+
get variables() {
|
|
28
|
+
return Array.from(this._variables.values()).filter((e) => e !== null);
|
|
29
|
+
}
|
|
30
|
+
get variableNames() {
|
|
31
|
+
return Array.from(this._variables.keys());
|
|
32
|
+
}
|
|
33
|
+
get trainableVariables() {
|
|
34
|
+
return Array.from(this._variables.values()).filter((e) => e !== null && e.trainable);
|
|
35
|
+
}
|
|
36
|
+
getRawVariable(e) {
|
|
37
|
+
let t = this._variables.get(e);
|
|
38
|
+
if (!t) throw Error(`Variable ${e} not found`);
|
|
39
|
+
return t;
|
|
40
|
+
}
|
|
41
|
+
getVariable(e) {
|
|
42
|
+
let t = this._variables.get(e);
|
|
43
|
+
if (!t) throw Error(`Variable ${e} not found`);
|
|
44
|
+
return this.onWeightRead ? this.onWeightRead(e, t) : t;
|
|
45
|
+
}
|
|
46
|
+
setTrainable(e) {
|
|
47
|
+
let t = (0, i.default)(e);
|
|
48
|
+
this._variables.forEach((e, n) => {
|
|
49
|
+
e && (e.trainable = t(n));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
hasVariable(e) {
|
|
53
|
+
return !!this._variables.get(e);
|
|
54
|
+
}
|
|
55
|
+
setVariable(e, t) {
|
|
56
|
+
if (!this._variables.has(e)) throw Error(`Variable ${e} not found`);
|
|
57
|
+
this._variables.set(e, t);
|
|
58
|
+
}
|
|
59
|
+
touchVariables(e) {
|
|
60
|
+
for (let t of e) this._variables.get(t) && this.touchedVariables.add(t);
|
|
61
|
+
}
|
|
62
|
+
dispose() {
|
|
63
|
+
this._variables.forEach((e) => {
|
|
64
|
+
e?.dispose();
|
|
65
|
+
}), this._variables.clear();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { a as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ITokeniser } from '../../main';
|
|
2
|
+
import { default as Model, ModelForwardAttributes } from '../../models/model';
|
|
3
|
+
import { TransformersMetadata } from './types';
|
|
4
|
+
export default function loadHuggingFace(name: string): Promise<{
|
|
5
|
+
model: Model<ModelForwardAttributes>;
|
|
6
|
+
tokeniser: ITokeniser;
|
|
7
|
+
metaData: TransformersMetadata;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GPTConfig } from '../../models/config';
|
|
2
|
+
import { LoadResult, TransformersConfig, TransformersMetadata, TransformersTokeniser } from './types';
|
|
3
|
+
export declare function mapTransformersConfigToGPTConfig(config: TransformersConfig): GPTConfig;
|
|
4
|
+
export default function loadTransformers(config: TransformersConfig, tokeniser: TransformersTokeniser, metadata: TransformersMetadata, weightData: ArrayBuffer): Promise<LoadResult>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region lib/loader/loadZipMeta.ts
|
|
2
|
+
async function e(e) {
|
|
3
|
+
let t = await e.file("meta.json")?.async("string"), n = {
|
|
4
|
+
version: 0,
|
|
5
|
+
application: ""
|
|
6
|
+
};
|
|
7
|
+
if (t) try {
|
|
8
|
+
n = JSON.parse(t);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw console.error(e), Error("Failed to parse meta.json in the zip archive");
|
|
11
|
+
}
|
|
12
|
+
else console.warn("meta.json not found in the zip archive, using default metadata");
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { e as loadZipMeta };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as zip } from 'jszip';
|
|
2
|
+
import { ITokeniser } from '../../main';
|
|
3
|
+
import { default as Model, ModelForwardAttributes } from '../../models/model';
|
|
4
|
+
import { TransformersMetadata } from './types';
|
|
5
|
+
export default function loadOldModel(zipFile: zip, metaData: TransformersMetadata): Promise<{
|
|
6
|
+
model: Model<ModelForwardAttributes>;
|
|
7
|
+
tokeniser: ITokeniser;
|
|
8
|
+
metaData: TransformersMetadata;
|
|
9
|
+
}>;
|