@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,32 @@
|
|
|
1
|
+
import { Fi as e, Ii as t, On as n, ii as r, w as i } from "../dist-BewPQWjc.js";
|
|
2
|
+
import { forceFloat as a, forcePacked as o } from "./grads/utils.js";
|
|
3
|
+
import { isPackedTensor as s } from "../utilities/packed.js";
|
|
4
|
+
//#region lib/ops/transpose16.ts
|
|
5
|
+
var c = {
|
|
6
|
+
kernelName: "Transpose16",
|
|
7
|
+
gradFunc: (e, t, r) => {
|
|
8
|
+
if (Array.isArray(e)) throw Error("Transpose16 gradient does not support multiple outputs.");
|
|
9
|
+
let { perm: i } = r, a = n(i);
|
|
10
|
+
return { x: () => u(e, a) };
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
e(c);
|
|
14
|
+
function l(e) {
|
|
15
|
+
let { inputs: t, attrs: n } = e, { x: r } = t, { perm: c } = n, l = s(r);
|
|
16
|
+
if (l && c[c.length - 1] !== r.shape.length - 1) throw Error("Transpose16 currently only supports the last axis being unchanged.");
|
|
17
|
+
return l ? o(i(a(r), c)) : i(r, c);
|
|
18
|
+
}
|
|
19
|
+
t({
|
|
20
|
+
kernelName: "Transpose16",
|
|
21
|
+
backendName: "webgl",
|
|
22
|
+
kernelFunc: l
|
|
23
|
+
}), t({
|
|
24
|
+
kernelName: "Transpose16",
|
|
25
|
+
backendName: "cpu",
|
|
26
|
+
kernelFunc: l
|
|
27
|
+
});
|
|
28
|
+
function u(e, t) {
|
|
29
|
+
return t ??= e.shape.map((e, t) => t).reverse(), r().runKernel("Transpose16", { x: e }, { perm: t });
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { u as transpose16, c as transpose16GradConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
import { t } from "../../Reshape-CABOPB9d.js";
|
|
3
|
+
//#region lib/ops/webgl/adamAdjust.ts
|
|
4
|
+
var n = class {
|
|
5
|
+
variableNames = ["moments", "value"];
|
|
6
|
+
outputShape;
|
|
7
|
+
userCode;
|
|
8
|
+
customUniforms = [
|
|
9
|
+
{
|
|
10
|
+
name: "invBeta1",
|
|
11
|
+
type: "float"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "invBeta2",
|
|
15
|
+
type: "float"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "learningRate",
|
|
19
|
+
type: "float"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "epsilon",
|
|
23
|
+
type: "float"
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
constructor(e, t) {
|
|
27
|
+
this.outputShape = e, t && this.customUniforms.push({
|
|
28
|
+
name: "weightDecay",
|
|
29
|
+
type: "float"
|
|
30
|
+
}), this.userCode = `
|
|
31
|
+
void main() {
|
|
32
|
+
float v = getValueAtOutCoords();
|
|
33
|
+
int coords = getOutputCoords();
|
|
34
|
+
coords *= 2;
|
|
35
|
+
float m1 = getMoments(coords);
|
|
36
|
+
float m2 = getMoments(coords + 1);
|
|
37
|
+
|
|
38
|
+
float m1Hat = m1 * invBeta1;
|
|
39
|
+
float m2Hat = m2 * invBeta2;
|
|
40
|
+
|
|
41
|
+
float invSqrt = inversesqrt(max(m2Hat, 1e-30));
|
|
42
|
+
float invDenom = invSqrt / (1.0 + epsilon * invSqrt);
|
|
43
|
+
float adjustedValue = -learningRate * m1Hat * invDenom + v;
|
|
44
|
+
|
|
45
|
+
${t ? "adjustedValue = adjustedValue - learningRate * weightDecay * v;" : ""}
|
|
46
|
+
|
|
47
|
+
setOutput(adjustedValue);
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function r(e) {
|
|
53
|
+
let { moments: r, value: i } = e.inputs, { beta1: a, beta2: o, learningRate: s, epsilon: c, weightDecay: l } = e.attrs, u = e.backend, d = t({
|
|
54
|
+
inputs: { x: r },
|
|
55
|
+
backend: u,
|
|
56
|
+
attrs: { shape: [-1] }
|
|
57
|
+
}), f = t({
|
|
58
|
+
inputs: { x: i },
|
|
59
|
+
backend: u,
|
|
60
|
+
attrs: { shape: [-1] }
|
|
61
|
+
}), p = new n(f.shape, l > 0), m = [
|
|
62
|
+
[1 / a],
|
|
63
|
+
[1 / o],
|
|
64
|
+
[s],
|
|
65
|
+
[c]
|
|
66
|
+
];
|
|
67
|
+
l > 0 && m.push([l]);
|
|
68
|
+
let h = u.runWebGLProgram(p, [d, f], "float32", m);
|
|
69
|
+
u.disposeIntermediateTensorInfo(d), u.disposeIntermediateTensorInfo(f);
|
|
70
|
+
let g = t({
|
|
71
|
+
inputs: { x: h },
|
|
72
|
+
backend: u,
|
|
73
|
+
attrs: { shape: i.shape }
|
|
74
|
+
});
|
|
75
|
+
return u.disposeIntermediateTensorInfo(h), g;
|
|
76
|
+
}
|
|
77
|
+
e({
|
|
78
|
+
kernelName: "AdamAdjust",
|
|
79
|
+
backendName: "webgl",
|
|
80
|
+
kernelFunc: r
|
|
81
|
+
});
|
|
82
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/ops/webgl/adamMoments.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
variableNames = ["moments", "gradient"];
|
|
5
|
+
outputShape;
|
|
6
|
+
userCode;
|
|
7
|
+
customUniforms = [{
|
|
8
|
+
name: "beta1",
|
|
9
|
+
type: "float"
|
|
10
|
+
}, {
|
|
11
|
+
name: "beta2",
|
|
12
|
+
type: "float"
|
|
13
|
+
}];
|
|
14
|
+
constructor(e) {
|
|
15
|
+
this.outputShape = e;
|
|
16
|
+
let t = e.length, n = t === 1 ? "int" : `ivec${Math.min(t, 4)}`, r = t === 1 ? "coords" : `coords[${t - 1}]`, i = t === 1 ? "coords" : e.slice(0, -1).map((e, t) => `coords[${t}]`).join(", ");
|
|
17
|
+
this.userCode = `
|
|
18
|
+
void main() {
|
|
19
|
+
float m = getMomentsAtOutCoords();
|
|
20
|
+
${n} coords = getOutputCoords();
|
|
21
|
+
|
|
22
|
+
// Add gradient clipping here
|
|
23
|
+
float g = clamp(getGradient(${i}), -1.0, 1.0);
|
|
24
|
+
int which = ${r};
|
|
25
|
+
|
|
26
|
+
float beta = which == 0 ? beta1 : beta2;
|
|
27
|
+
float gg = which == 0 ? g : g * g;
|
|
28
|
+
|
|
29
|
+
float newM = m * beta + gg * (1.0 - beta);
|
|
30
|
+
setOutput(newM);
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
function n(e) {
|
|
36
|
+
let { moments: n, gradient: r } = e.inputs, { beta1: i, beta2: a } = e.attrs, o = e.backend, s = new t(n.shape);
|
|
37
|
+
return o.runWebGLProgram(s, [n, r], "float32", [[i], [a]]);
|
|
38
|
+
}
|
|
39
|
+
e({
|
|
40
|
+
kernelName: "AdamMoments",
|
|
41
|
+
backendName: "webgl",
|
|
42
|
+
kernelFunc: n
|
|
43
|
+
});
|
|
44
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/ops/webgl/appendCache.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
variableNames = ["cache", "item"];
|
|
5
|
+
outputShape;
|
|
6
|
+
userCode;
|
|
7
|
+
customUniforms = [{
|
|
8
|
+
name: "cacheT",
|
|
9
|
+
type: "int"
|
|
10
|
+
}];
|
|
11
|
+
constructor(e, t, n, r, i) {
|
|
12
|
+
let a = Math.min(n + 1, i);
|
|
13
|
+
this.outputShape = [
|
|
14
|
+
e,
|
|
15
|
+
t,
|
|
16
|
+
a,
|
|
17
|
+
r
|
|
18
|
+
], this.userCode = `
|
|
19
|
+
void main() {
|
|
20
|
+
ivec4 coords = getOutputCoords(); // [b, h, t, d]
|
|
21
|
+
int b = coords.x;
|
|
22
|
+
int h = coords.y;
|
|
23
|
+
int t = coords.z;
|
|
24
|
+
int d = coords.w;
|
|
25
|
+
|
|
26
|
+
int itemT = 1;
|
|
27
|
+
int maxSize = ${i};
|
|
28
|
+
int totalT = cacheT + itemT;
|
|
29
|
+
int start = totalT >= maxSize ? 1 : 0;
|
|
30
|
+
|
|
31
|
+
int srcT = t + start;
|
|
32
|
+
float val = 0.0;
|
|
33
|
+
if (srcT < cacheT) {
|
|
34
|
+
val = getCache(b, h, srcT, d);
|
|
35
|
+
} else if (srcT == cacheT) {
|
|
36
|
+
val = getItem(b, h, 0, d);
|
|
37
|
+
} else {
|
|
38
|
+
val = 0.0;}
|
|
39
|
+
setOutput(val);
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function n(e) {
|
|
45
|
+
let { cache: n, item: r } = e.inputs, { maxSize: i, pastLen: a } = e.attrs, o = e.backend, s = n.shape[0], c = n.shape[2], l = n.shape[1], u = new t(s, l, c, r.shape[3], i);
|
|
46
|
+
return o.runWebGLProgram(u, [n, r], "float32", [[a]]);
|
|
47
|
+
}
|
|
48
|
+
e({
|
|
49
|
+
kernelName: "AppendCache",
|
|
50
|
+
backendName: "webgl",
|
|
51
|
+
kernelFunc: n
|
|
52
|
+
});
|
|
53
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/ops/webgl/attentionMask.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
variableNames = ["q", "k"];
|
|
5
|
+
outputShape;
|
|
6
|
+
userCode;
|
|
7
|
+
customUniforms = [
|
|
8
|
+
{
|
|
9
|
+
name: "divisor",
|
|
10
|
+
type: "float"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "pastLen",
|
|
14
|
+
type: "int"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "inf",
|
|
18
|
+
type: "float"
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
constructor(e, t, n, r, i) {
|
|
22
|
+
this.outputShape = [
|
|
23
|
+
e,
|
|
24
|
+
t,
|
|
25
|
+
n,
|
|
26
|
+
r
|
|
27
|
+
], this.userCode = `
|
|
28
|
+
void main() {
|
|
29
|
+
ivec4 coords = getOutputCoords(); // [batch, nh, t1, t2]
|
|
30
|
+
int b = coords.x;
|
|
31
|
+
int h = coords.y;
|
|
32
|
+
int t1 = coords.z;
|
|
33
|
+
int t2 = coords.w;
|
|
34
|
+
|
|
35
|
+
float sum = 0.0;
|
|
36
|
+
for (int i = 0; i < ${i}; ++i) {
|
|
37
|
+
float qv = getQ(b, h, t1, i);
|
|
38
|
+
float kv = getK(b, h, t2, i);
|
|
39
|
+
sum += qv * kv;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Scale by divisor
|
|
43
|
+
float scaled = sum * divisor;
|
|
44
|
+
|
|
45
|
+
// Mask out future positions
|
|
46
|
+
setOutput((t2 > t1 + pastLen) ? inf : scaled);
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function n(e) {
|
|
52
|
+
let { q: n, k: r } = e.inputs, { divisor: i, pastLen: a } = e.attrs, o = e.backend, s = n.shape[0], c = n.shape[2], l = r.shape[2], u = n.shape[1], d = n.shape[3], f = new t(s, u, c, l, d);
|
|
53
|
+
return o.runWebGLProgram(f, [n, r], "float32", [
|
|
54
|
+
[i],
|
|
55
|
+
[a],
|
|
56
|
+
[-Infinity]
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
e({
|
|
60
|
+
kernelName: "AttentionMask",
|
|
61
|
+
backendName: "webgl",
|
|
62
|
+
kernelFunc: n
|
|
63
|
+
});
|
|
64
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SoftmaxAttrs, SoftmaxInputs, TensorInfo } from '@tensorflow/tfjs-core';
|
|
2
|
+
interface FusedSoftmaxAttrs extends SoftmaxAttrs {
|
|
3
|
+
dropoutRate?: number;
|
|
4
|
+
seed?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function softmax(args: {
|
|
7
|
+
inputs: SoftmaxInputs;
|
|
8
|
+
backend: unknown;
|
|
9
|
+
attrs: FusedSoftmaxAttrs;
|
|
10
|
+
}): TensorInfo;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Ii as e, Tn as t, nc as n } from "../../dist-BewPQWjc.js";
|
|
2
|
+
import { t as r } from "../../Reshape-CABOPB9d.js";
|
|
3
|
+
import { a as i, r as a, t as o } from "../../RealDiv-DBu0FQqT.js";
|
|
4
|
+
//#region lib/ops/webgl/fusedSoftmax.ts
|
|
5
|
+
var s = class {
|
|
6
|
+
variableNames = ["logits", "maxLogits"];
|
|
7
|
+
outputShape;
|
|
8
|
+
userCode;
|
|
9
|
+
constructor(e) {
|
|
10
|
+
this.outputShape = e, this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords(); // [batch, nh, t1, t2]\n int b = coords.x;\n int h = coords.y;\n int t1 = coords.z;\n int t2 = coords.w;\n float x = getLogitsAtOutCoords();\n float maxLogit = getMaxLogits(b, h, t1);\n setOutput(exp(x - maxLogit));\n }\n ";
|
|
11
|
+
}
|
|
12
|
+
}, c = class {
|
|
13
|
+
variableNames = ["exp", "sum"];
|
|
14
|
+
outputShape;
|
|
15
|
+
userCode;
|
|
16
|
+
customUniforms = [{
|
|
17
|
+
name: "dropoutRate",
|
|
18
|
+
type: "float"
|
|
19
|
+
}, {
|
|
20
|
+
name: "seed",
|
|
21
|
+
type: "float"
|
|
22
|
+
}];
|
|
23
|
+
constructor(e) {
|
|
24
|
+
this.outputShape = e, this.userCode = "\n float random(ivec4 coords) {\n float x = float(coords.x * 4096 + coords.y * 256 + coords.z * 16 + coords.w);\n return fract(sin(seed + x) * 43758.5453123);\n }\n void main() {\n ivec4 coords = getOutputCoords();\n float numerator = getExp(coords.x, coords.y, coords.z, coords.w);\n float denominator = getSum(coords.x, coords.y, coords.z, coords.w);\n float val = numerator / denominator;\n float keepProb = 1.0 - dropoutRate;\n float rand = random(coords);\n float mask = step(rand, keepProb);\n setOutput(val * mask / keepProb);\n }\n ";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function l(e) {
|
|
28
|
+
let { inputs: l, attrs: u } = e, { logits: d } = l, { dim: f, dropoutRate: p, seed: m } = u, h = e.backend;
|
|
29
|
+
if (!d) throw Error("Error in softmax: input logits is null");
|
|
30
|
+
let g = n([f], d.shape), _ = a({
|
|
31
|
+
inputs: { x: d },
|
|
32
|
+
backend: h,
|
|
33
|
+
attrs: {
|
|
34
|
+
reductionIndices: g,
|
|
35
|
+
keepDims: !1
|
|
36
|
+
}
|
|
37
|
+
}), v = t(_.shape, g), y = new s(d.shape), b = h.runWebGLProgram(y, [d, _], "float32");
|
|
38
|
+
h.disposeIntermediateTensorInfo(_);
|
|
39
|
+
let x = i({
|
|
40
|
+
inputs: { x: b },
|
|
41
|
+
backend: h,
|
|
42
|
+
attrs: {
|
|
43
|
+
axis: g,
|
|
44
|
+
keepDims: !1
|
|
45
|
+
}
|
|
46
|
+
}), S = r({
|
|
47
|
+
inputs: { x },
|
|
48
|
+
backend: h,
|
|
49
|
+
attrs: { shape: v }
|
|
50
|
+
});
|
|
51
|
+
if (p !== void 0 && p > 0) {
|
|
52
|
+
let e = new c(d.shape), t = h.runWebGLProgram(e, [b, S], "float32", [[p], [m ?? Math.random() * 1e4]]);
|
|
53
|
+
return h.disposeIntermediateTensorInfo(b), h.disposeIntermediateTensorInfo(x), h.disposeIntermediateTensorInfo(S), t;
|
|
54
|
+
}
|
|
55
|
+
let C = o({
|
|
56
|
+
inputs: {
|
|
57
|
+
a: b,
|
|
58
|
+
b: S
|
|
59
|
+
},
|
|
60
|
+
backend: h
|
|
61
|
+
});
|
|
62
|
+
return h.disposeIntermediateTensorInfo(b), h.disposeIntermediateTensorInfo(x), h.disposeIntermediateTensorInfo(S), C;
|
|
63
|
+
}
|
|
64
|
+
e({
|
|
65
|
+
kernelName: "FusedSoftmax",
|
|
66
|
+
backendName: "webgl",
|
|
67
|
+
kernelFunc: l
|
|
68
|
+
});
|
|
69
|
+
//#endregion
|
|
70
|
+
export { l as softmax };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/ops/webgl/gatherSub.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
variableNames = [
|
|
5
|
+
"labels",
|
|
6
|
+
"logits",
|
|
7
|
+
"values"
|
|
8
|
+
];
|
|
9
|
+
outputShape;
|
|
10
|
+
userCode;
|
|
11
|
+
constructor(e) {
|
|
12
|
+
this.outputShape = [e], this.userCode = "\n void main() {\n int coords = getOutputCoords();\n int index = int(getLabelsAtOutCoords());\n float val = getValuesAtOutCoords();\n float logit = getLogits(coords, index);\n setOutput(val - logit);\n }\n ";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function n(e) {
|
|
16
|
+
let { logits: n, labels: r, values: i } = e.inputs, a = e.backend, o = r.shape[0], s = new t(o);
|
|
17
|
+
return a.runWebGLProgram(s, [
|
|
18
|
+
r,
|
|
19
|
+
n,
|
|
20
|
+
i
|
|
21
|
+
], "float32");
|
|
22
|
+
}
|
|
23
|
+
e({
|
|
24
|
+
kernelName: "EfficientGatherSub",
|
|
25
|
+
backendName: "webgl",
|
|
26
|
+
kernelFunc: n
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
import { _ as t, i as n } from "../../kernel_funcs_utils-HiXOOx3f.js";
|
|
3
|
+
//#region lib/ops/webgl/gelu.ts
|
|
4
|
+
var r = .7978845608028654, i = .044715, a = n({ opSnippet: t + `
|
|
5
|
+
float x3 = x * x * x;
|
|
6
|
+
float inner = x + ${i} * x3;
|
|
7
|
+
inner = ${r} * inner;
|
|
8
|
+
inner = abs(inner) > 15.0 ? sign(inner) : tanh(inner);
|
|
9
|
+
inner = 0.5 * (1.0 + inner);
|
|
10
|
+
inner = x * inner;
|
|
11
|
+
return inner;
|
|
12
|
+
` });
|
|
13
|
+
e({
|
|
14
|
+
kernelName: "Gelu",
|
|
15
|
+
backendName: "webgl",
|
|
16
|
+
kernelFunc: a
|
|
17
|
+
});
|
|
18
|
+
var o = class {
|
|
19
|
+
variableNames = ["dy", "x"];
|
|
20
|
+
outputShape;
|
|
21
|
+
userCode;
|
|
22
|
+
constructor(e) {
|
|
23
|
+
this.outputShape = e, this.userCode = `
|
|
24
|
+
void main() {
|
|
25
|
+
float dy = getDyAtOutCoords();
|
|
26
|
+
float x = getXAtOutCoords();
|
|
27
|
+
float x2 = x * x;
|
|
28
|
+
float x3 = x2 * x;
|
|
29
|
+
float u = ${r} * (x + ${i} * x3);
|
|
30
|
+
float t = abs(u) > 15.0 ? sign(u) : tanh(u);
|
|
31
|
+
float sech2 = 1.0 - t * t;
|
|
32
|
+
float du_dx = ${r} * (1.0 + 3.0 * ${i} * x2);
|
|
33
|
+
float dgelu = 0.5 * (1.0 + t) + 0.5 * x * sech2 * du_dx;
|
|
34
|
+
setOutput(dy * dgelu);
|
|
35
|
+
}`;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function s(e) {
|
|
39
|
+
let { dy: t, x: n } = e.inputs, r = e.backend, i = new o(n.shape);
|
|
40
|
+
return r.runWebGLProgram(i, [t, n], "float32");
|
|
41
|
+
}
|
|
42
|
+
e({
|
|
43
|
+
kernelName: "GeluGrad",
|
|
44
|
+
backendName: "webgl",
|
|
45
|
+
kernelFunc: s
|
|
46
|
+
});
|
|
47
|
+
//#endregion
|
|
48
|
+
export { a as gelu };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
* =============================================================================
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
import { y as t } from "../../shared-DOgWaqvL.js";
|
|
3
|
+
import { i as n, t as r } from "../../kernel_funcs_utils-HiXOOx3f.js";
|
|
4
|
+
//#region lib/ops/webgl/log.ts
|
|
5
|
+
e({
|
|
6
|
+
kernelName: "Log",
|
|
7
|
+
backendName: "webgl",
|
|
8
|
+
kernelFunc: n({
|
|
9
|
+
opSnippet: r + "\n return x < 0.0 ? NAN : log(x);\n",
|
|
10
|
+
packedOpSnippet: "\n vec4 result = log(x);\n bvec4 isNaN = isnan(x);\n result.r = isNaN.r ? x.r : (x.r < 0.0 ? NAN : result.r);\n result.g = isNaN.g ? x.g : (x.g < 0.0 ? NAN : result.g);\n result.b = isNaN.b ? x.b : (x.b < 0.0 ? NAN : result.b);\n result.a = isNaN.a ? x.a : (x.a < 0.0 ? NAN : result.a);\n return result;\n",
|
|
11
|
+
cpuKernelImpl: t
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Ii as e, Wr as t, _n as n, br as r, gr as i, hn as a, lt as o, w as s } from "../../dist-BewPQWjc.js";
|
|
2
|
+
import { isPackedTensor as c } from "../../utilities/packed.js";
|
|
3
|
+
import { matMulMul as l } from "../matMulMul.js";
|
|
4
|
+
import { matMulGelu as u } from "../matMulGelu.js";
|
|
5
|
+
//#region lib/ops/webgl/matMul16.ts
|
|
6
|
+
function d(e) {
|
|
7
|
+
let { A: d, B: f } = e.inputs, { transposeA: p, transposeB: m, scale: h, activation: g, scaleA: _, scaleB: v, forceOutputShape: y, perm: b } = e.attrs, x = !c(d), S = !c(f);
|
|
8
|
+
if (x && S) {
|
|
9
|
+
let e = _ === void 0 ? d : t(d, n(_)), c = v === void 0 ? f : t(f, n(v)), x;
|
|
10
|
+
if (h !== void 0) x = l(e, c, n(h), p, m);
|
|
11
|
+
else if (g === "gelu") x = u(e, c);
|
|
12
|
+
else if (g === "relu2") {
|
|
13
|
+
let t = i(e, c, p, m), n = o(t);
|
|
14
|
+
t.dispose(), x = a(n), n.dispose();
|
|
15
|
+
} else x = g === "relu" ? o(i(e, c, p, m)) : i(e, c, p, m);
|
|
16
|
+
if (b) if (y) {
|
|
17
|
+
let e = r(x, y);
|
|
18
|
+
x.dispose();
|
|
19
|
+
let t = s(e, b);
|
|
20
|
+
return e.dispose(), t;
|
|
21
|
+
} else {
|
|
22
|
+
let e = s(x, b);
|
|
23
|
+
return x.dispose(), e;
|
|
24
|
+
}
|
|
25
|
+
else if (y) {
|
|
26
|
+
let e = r(x, y);
|
|
27
|
+
return x.dispose(), e;
|
|
28
|
+
} else return x;
|
|
29
|
+
}
|
|
30
|
+
throw Error("Not implemented: matMul16 with packed inputs");
|
|
31
|
+
}
|
|
32
|
+
e({
|
|
33
|
+
kernelName: "MatMul16",
|
|
34
|
+
backendName: "webgl",
|
|
35
|
+
kernelFunc: d
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TensorInfo } from '@tensorflow/tfjs-core';
|
|
2
|
+
import { MathBackendWebGL } from '@tensorflow/tfjs-backend-webgl';
|
|
3
|
+
export declare const MATMUL_SHARED_DIM_THRESHOLD = 1000;
|
|
4
|
+
interface BatchMatMulConfig {
|
|
5
|
+
a: TensorInfo;
|
|
6
|
+
b: TensorInfo;
|
|
7
|
+
transposeA: boolean;
|
|
8
|
+
transposeB: boolean;
|
|
9
|
+
backend: MathBackendWebGL;
|
|
10
|
+
activationSnippet?: string;
|
|
11
|
+
multiplier?: TensorInfo;
|
|
12
|
+
}
|
|
13
|
+
export declare function batchMatMulGeluImpl({ a, b, transposeA, transposeB, backend, activationSnippet, multiplier, }: BatchMatMulConfig): TensorInfo;
|
|
14
|
+
export declare function batchMatMulKernel(args: {
|
|
15
|
+
inputs: {
|
|
16
|
+
x: TensorInfo;
|
|
17
|
+
kernel: TensorInfo;
|
|
18
|
+
};
|
|
19
|
+
backend: MathBackendWebGL;
|
|
20
|
+
}): TensorInfo;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TensorInfo } from '@tensorflow/tfjs-core';
|
|
2
|
+
import { MathBackendWebGL } from '@tensorflow/tfjs-backend-webgl';
|
|
3
|
+
export declare function batchMatMulKernel(args: {
|
|
4
|
+
inputs: {
|
|
5
|
+
x: TensorInfo;
|
|
6
|
+
kernel: TensorInfo;
|
|
7
|
+
y: TensorInfo;
|
|
8
|
+
};
|
|
9
|
+
attrs: {
|
|
10
|
+
transposeA: boolean;
|
|
11
|
+
transposeB: boolean;
|
|
12
|
+
};
|
|
13
|
+
backend: MathBackendWebGL;
|
|
14
|
+
}): TensorInfo;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
import { n as t } from "../../matMulGelu-CPTntosE.js";
|
|
3
|
+
//#region lib/ops/webgl/matMulMul.ts
|
|
4
|
+
var n = "\n return a * b;\n";
|
|
5
|
+
function r(e) {
|
|
6
|
+
let { inputs: r, backend: i, attrs: a } = e, { x: o, kernel: s, y: c } = r, { transposeA: l, transposeB: u } = a;
|
|
7
|
+
if (o === void 0 || s === void 0) throw Error("BatchMatMul requires two input tensors.");
|
|
8
|
+
return t({
|
|
9
|
+
a: o,
|
|
10
|
+
b: s,
|
|
11
|
+
transposeA: l,
|
|
12
|
+
transposeB: u,
|
|
13
|
+
backend: i,
|
|
14
|
+
activationSnippet: n,
|
|
15
|
+
multiplier: c
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
e({
|
|
19
|
+
kernelName: "MatMulMul",
|
|
20
|
+
backendName: "webgl",
|
|
21
|
+
kernelFunc: r
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
export { r as batchMatMulKernel };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Ii as e } from "../../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/ops/webgl/mulDropout.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
variableNames = ["a", "b"];
|
|
5
|
+
outputShape;
|
|
6
|
+
userCode;
|
|
7
|
+
customUniforms = [{
|
|
8
|
+
name: "dropoutRate",
|
|
9
|
+
type: "float"
|
|
10
|
+
}, {
|
|
11
|
+
name: "seed",
|
|
12
|
+
type: "float"
|
|
13
|
+
}];
|
|
14
|
+
constructor(e, t, n) {
|
|
15
|
+
this.outputShape = [
|
|
16
|
+
e,
|
|
17
|
+
t,
|
|
18
|
+
n,
|
|
19
|
+
n
|
|
20
|
+
], this.userCode = "\n float random(ivec4 coords) {\n float x = float(coords.x * 4096 + coords.y * 256 + coords.z * 16 + coords.w);\n return fract(sin(seed + x) * 43758.5453123);\n }\n void main() {\n ivec4 coords = getOutputCoords();\n float a = getA(coords.x, coords.y, coords.z, coords.w);\n float b = getB(coords.x, coords.y, coords.z, coords.w);\n \n float keepProb = 1.0 - dropoutRate;\n float rand = random(coords);\n float mask = step(rand, keepProb);\n setOutput(a * b * mask / keepProb);\n }\n ";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function n(e) {
|
|
24
|
+
let { inputs: n, attrs: r } = e, { a: i, b: a } = n, { dropoutRate: o, seed: s } = r, c = e.backend, l = i.shape[0], u = i.shape[2], d = i.shape[1], f = new t(l, d, u);
|
|
25
|
+
return c.runWebGLProgram(f, [i, a], "float32", [[o ?? 0], [s ?? Math.random() * 1e4]]);
|
|
26
|
+
}
|
|
27
|
+
e({
|
|
28
|
+
kernelName: "MulDropout",
|
|
29
|
+
backendName: "webgl",
|
|
30
|
+
kernelFunc: n
|
|
31
|
+
});
|
|
32
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|