@genai-fi/nanogpt 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{binary_op_util-WY9YIl0q.js → Reshape-CqftURg0.js} +75 -60
- package/dist/TeachableLLM.d.ts +12 -12
- package/dist/api/beamer.d.ts +4 -4
- package/dist/api/responses.d.ts +4 -4
- package/dist/api/training.d.ts +9 -9
- package/dist/backend.d.ts +1 -1
- package/dist/backend_util-DZIc6pyV.js +1081 -0
- package/dist/checks/index.d.ts +11 -11
- package/dist/checks/weights.d.ts +1 -1
- package/dist/data/docx.d.ts +1 -1
- package/dist/data/pdf.d.ts +1 -1
- package/dist/data/stream.d.ts +1 -1
- package/dist/data/textLoader.d.ts +1 -1
- package/dist/data.d.ts +3 -3
- package/dist/device-CZPGtQBU.js +9 -0
- package/dist/device.d.ts +2 -0
- package/dist/{dist-DeVH1nGn.js → dist-DiszGjH-.js} +1833 -1844
- package/dist/{dist-CMMLi-qO.js → dist-JOPw9zTN.js} +69 -11
- package/dist/inference/Beamer.d.ts +3 -3
- package/dist/inference/Generator.d.ts +4 -4
- package/dist/inference/tokenisePrompt.d.ts +2 -2
- package/dist/inference/types.d.ts +1 -1
- package/dist/inference/utilities.d.ts +1 -1
- package/dist/layers/BaseLayer.d.ts +5 -4
- package/dist/layers/GQA.d.ts +24 -26
- package/dist/layers/HeadLayer.d.ts +2 -2
- package/dist/layers/LoRA.d.ts +1 -1
- package/dist/layers/MHA.d.ts +3 -4
- package/dist/layers/MLP.d.ts +2 -2
- package/dist/layers/PositionEmbedding.d.ts +3 -3
- package/dist/layers/RMSNorm.d.ts +2 -2
- package/dist/layers/RoPECache.d.ts +2 -1
- package/dist/layers/TiedEmbedding.d.ts +2 -2
- package/dist/layers/TransformerBlock.d.ts +9 -6
- package/dist/layers.d.ts +4 -4
- package/dist/loader/load.d.ts +1 -1
- package/dist/loader/loadHF.d.ts +3 -3
- package/dist/loader/loadTransformers.d.ts +2 -2
- package/dist/loader/loadZipMeta.d.ts +2 -2
- package/dist/loader/newZipLoad.d.ts +2 -2
- package/dist/loader/oldZipLoad.d.ts +4 -4
- package/dist/loader/save.d.ts +5 -5
- package/dist/loader/types.d.ts +23 -10
- package/dist/main.d.ts +40 -24
- package/dist/matMul16-CiMKJM8v.js +2610 -0
- package/dist/models/Llama.d.ts +2 -2
- package/dist/models/LoopNano.d.ts +16 -0
- package/dist/models/NanoGPTV1.d.ts +2 -2
- package/dist/models/NanoGPTV2.d.ts +2 -2
- package/dist/models/Qwen3.d.ts +2 -2
- package/dist/models/config.d.ts +11 -1
- package/dist/models/factory.d.ts +2 -2
- package/dist/models/model.d.ts +6 -6
- package/dist/models.d.ts +4 -4
- package/dist/nanogpt.js +37041 -0
- package/dist/ops/adamAdjust.d.ts +2 -0
- package/dist/ops/adamMoments.d.ts +2 -0
- package/dist/ops/adamW.d.ts +2 -0
- package/dist/ops/add16.d.ts +1 -0
- package/dist/ops/appendCache.d.ts +2 -0
- package/dist/ops/attentionMask.d.ts +11 -1
- package/dist/ops/dropout16.d.ts +2 -0
- package/dist/ops/gatherSub.d.ts +2 -0
- package/dist/ops/gelu.d.ts +3 -0
- package/dist/ops/log.d.ts +1 -0
- package/dist/ops/matMul16.d.ts +4 -0
- package/dist/ops/matMulGelu.d.ts +3 -0
- package/dist/ops/matMulMul.d.ts +2 -0
- package/dist/ops/mul16.d.ts +1 -0
- package/dist/ops/mulDrop.d.ts +2 -0
- package/dist/ops/normRMS.d.ts +3 -0
- package/dist/ops/pack16.d.ts +1 -0
- package/dist/ops/qkv.d.ts +13 -1
- package/dist/ops/rope.d.ts +4 -1
- package/dist/ops/scatterSub.d.ts +4 -1
- package/dist/ops/silu.d.ts +1 -0
- package/dist/ops/softmax16.d.ts +1 -0
- package/dist/ops/sparseCrossEntropy.d.ts +15 -0
- package/dist/ops/unpack16.d.ts +1 -0
- package/dist/ops/webgl/sparseCrossEntropy.d.ts +1 -0
- package/dist/ops/webgpu/adamW.d.ts +1 -0
- package/dist/ops/webgpu/concat16.d.ts +16 -0
- package/dist/ops/webgpu/index.d.ts +29 -0
- package/dist/ops/webgpu/normRMS16_program.d.ts +2 -2
- package/dist/ops/webgpu/normRMS32_program.d.ts +2 -2
- package/dist/ops/webgpu/pack16_program.d.ts +1 -1
- package/dist/ops/webgpu/softmax16_program.d.ts +16 -0
- package/dist/ops/webgpu/sparseCrossEntropy.d.ts +1 -0
- package/dist/ops/webgpu/utils/binary_op.d.ts +16 -0
- package/dist/ops/webgpu/utils/deviceInfo.d.ts +1 -1
- package/dist/ops/webgpu/utils/reductions.d.ts +1 -1
- package/dist/patches/webgpu_backend.d.ts +2 -1
- package/dist/patches/webgpu_base.d.ts +0 -1
- package/dist/patches/webgpu_program.d.ts +21 -0
- package/dist/{shared-BIDMUBCs.js → shared-BARkvvG4.js} +587 -505
- package/dist/tokenise.d.ts +4 -4
- package/dist/tokeniser/BaseTokeniser.d.ts +3 -3
- package/dist/tokeniser/CharTokeniser.d.ts +2 -2
- package/dist/tokeniser/bpe.d.ts +2 -2
- package/dist/tokeniser/type.d.ts +2 -2
- package/dist/training/AdamW.d.ts +19 -2
- package/dist/training/BasicTrainer.d.ts +5 -5
- package/dist/training/DatasetBuilder.d.ts +2 -2
- package/dist/training/Evaluator.d.ts +1 -1
- package/dist/training/LRScheduler.d.ts +1 -1
- package/dist/training/PreTrainer.d.ts +6 -6
- package/dist/training/SFTTrainer.d.ts +6 -6
- package/dist/training/configure.d.ts +2 -2
- package/dist/training/factory.d.ts +6 -5
- package/dist/training/prepareData.d.ts +6 -6
- package/dist/training/tasks/tokenStream.d.ts +3 -3
- package/dist/training/types.d.ts +6 -5
- package/dist/training/validateOptions.d.ts +1 -1
- package/dist/training/validation.d.ts +3 -3
- package/dist/utilities/datasetID.d.ts +1 -1
- package/dist/utilities/dummy.d.ts +1 -1
- package/dist/utilities/packed.d.ts +1 -1
- package/dist/utilities/parameters.d.ts +1 -1
- package/dist/utilities/sentences.d.ts +1 -1
- package/dist/utilities/waitForModel.d.ts +1 -1
- package/dist/webgpu-D4syGmzo.js +3221 -0
- package/dist/webgpu-wUCQopBN.js +1007 -0
- package/dist/{webgpu_program-DvkFqRlR.js → webgpu_backend-CzY9TzvA.js} +174 -223
- package/dist/{patches/webgpu_base.js → webgpu_base-Bjg7okYf.js} +6 -9
- package/package.json +12 -9
- package/dist/DatasetBuilder-DRDW8tcM.js +0 -731
- package/dist/Generator-BcR_14Cj.js +0 -316
- package/dist/RealDiv-Cl8k3YTx.js +0 -354
- package/dist/Reshape-CKxKPKqi.js +0 -91
- package/dist/Reshape-H5zZRgr9.js +0 -16
- package/dist/RoPECache-dYscFINl.js +0 -722
- package/dist/TeachableLLM.js +0 -220
- package/dist/api/beamer.js +0 -61
- package/dist/api/responses.js +0 -177
- package/dist/api/training.js +0 -215
- package/dist/axis_util-rF9RnwKE.js +0 -37
- package/dist/backend.js +0 -12
- package/dist/backend_util-Cpp0Gwlp.js +0 -394
- package/dist/broadcast_to-CGvLNiQ0.js +0 -20
- package/dist/checks/appendCache.js +0 -55
- package/dist/checks/attentionMask.js +0 -57
- package/dist/checks/check.js +0 -31
- package/dist/checks/gelu.js +0 -46
- package/dist/checks/index.js +0 -27
- package/dist/checks/matMulGelu.js +0 -84
- package/dist/checks/normRMS.js +0 -30
- package/dist/checks/normRMSGrad.js +0 -23
- package/dist/checks/packUnpack.js +0 -46
- package/dist/checks/qkv.js +0 -1
- package/dist/checks/rope.js +0 -30
- package/dist/checks/weights.js +0 -26
- package/dist/clip_by_value-D-UX9am5.js +0 -13
- package/dist/complex-Cl904TqN.js +0 -13
- package/dist/complex_util-BBlPAm-s.js +0 -59
- package/dist/concat-Oip5acVY.js +0 -14
- package/dist/concat_util-CY45Hf4F.js +0 -18
- package/dist/data/docx.js +0 -17
- package/dist/data/pdf.js +0 -14
- package/dist/data/stream.js +0 -1
- package/dist/data/textLoader.js +0 -575
- package/dist/data-CV_i_H6B.js +0 -11
- package/dist/data.js +0 -5
- package/dist/dist-DyL7qSLJ.js +0 -7809
- package/dist/dropout16-CA31Ud5a.js +0 -20
- package/dist/dropout_util-SiFMbFXz.js +0 -22
- package/dist/eventemitter3-wmfmOP_f.js +0 -90
- package/dist/expand_dims-Dh3Fulyn.js +0 -10
- package/dist/floor-BwjmUb7X.js +0 -8
- package/dist/gather-B5Z1RFt5.js +0 -14
- package/dist/gatherSub-CRUfUzBa.js +0 -22
- package/dist/gelu-Xx9-ohH9.js +0 -25
- package/dist/gpgpu_math-48m8q3jI.js +0 -1591
- package/dist/inference/Beamer.js +0 -215
- package/dist/inference/Generator.js +0 -1
- package/dist/inference/tokenisePrompt.js +0 -17
- package/dist/inference/types.js +0 -0
- package/dist/inference/utilities.js +0 -31
- package/dist/jszip.min-Btv48m44.js +0 -3037
- package/dist/kernel_funcs_utils-BYRpSfV_.js +0 -229
- package/dist/layers/BaseLayer.js +0 -75
- package/dist/layers/GQA.js +0 -102
- package/dist/layers/HeadLayer.js +0 -28
- package/dist/layers/LoRA.js +0 -45
- package/dist/layers/MHA.js +0 -102
- package/dist/layers/MLP.js +0 -47
- package/dist/layers/PositionEmbedding.js +0 -28
- package/dist/layers/RMSNorm.js +0 -25
- package/dist/layers/RoPECache.js +0 -1
- package/dist/layers/TiedEmbedding.js +0 -33
- package/dist/layers/TransformerBlock.js +0 -50
- package/dist/layers/WeightStore.js +0 -68
- package/dist/layers-CFqEip3s.js +0 -13
- package/dist/layers.js +0 -6
- package/dist/loader/load.js +0 -63
- package/dist/loader/loadHF.js +0 -17
- package/dist/loader/loadTransformers.js +0 -61
- package/dist/loader/loadZipMeta.js +0 -15
- package/dist/loader/newZipLoad.js +0 -24
- package/dist/loader/oldZipLoad.js +0 -36
- package/dist/loader/save.js +0 -89
- package/dist/loader/types.js +0 -0
- package/dist/main.js +0 -12145
- package/dist/matMul16-tE26fnhf.js +0 -87
- package/dist/matMulGelu-ASUWlKqu.js +0 -162
- package/dist/mat_mul-R9_DWmIT.js +0 -16
- package/dist/models/Llama.js +0 -88
- package/dist/models/NanoGPTV1.js +0 -94
- package/dist/models/NanoGPTV2.js +0 -85
- package/dist/models/Qwen3.js +0 -88
- package/dist/models/config.js +0 -32
- package/dist/models/factory.js +0 -16
- package/dist/models/model.js +0 -75
- package/dist/models-DyBpJJwM.js +0 -13
- package/dist/models.js +0 -6
- package/dist/mul16-C7sqgqik.js +0 -41
- package/dist/non_max_suppression_impl-B0H318rb.js +0 -72
- package/dist/not_equal-Bu3O8rh_.js +0 -67
- package/dist/one_hot-TEMPumJj.js +0 -14
- package/dist/ones-DpPXWa6A.js +0 -13
- package/dist/ops/adamAdjust.js +0 -17
- package/dist/ops/adamMoments.js +0 -15
- package/dist/ops/add16.js +0 -11
- package/dist/ops/appendCache.js +0 -26
- package/dist/ops/attentionMask.js +0 -19
- package/dist/ops/concat16.js +0 -8
- package/dist/ops/cpu/adamAdjust.js +0 -15
- package/dist/ops/cpu/adamMoments.js +0 -16
- package/dist/ops/cpu/appendCache.js +0 -65
- package/dist/ops/cpu/attentionMask.js +0 -20
- package/dist/ops/cpu/fusedSoftmax.js +0 -22
- package/dist/ops/cpu/gatherSub.js +0 -1
- package/dist/ops/cpu/gelu.js +0 -35
- package/dist/ops/cpu/matMul16.js +0 -14
- package/dist/ops/cpu/matMulGelu.js +0 -44
- package/dist/ops/cpu/matMulMul.js +0 -19
- package/dist/ops/cpu/mulDropout.js +0 -19
- package/dist/ops/cpu/normRMS.js +0 -34
- package/dist/ops/cpu/qkv.js +0 -74
- package/dist/ops/cpu/rope.js +0 -84
- package/dist/ops/cpu/scatterSub.js +0 -1
- package/dist/ops/dot16.js +0 -28
- package/dist/ops/dropout.js +0 -12
- package/dist/ops/dropout16.js +0 -1
- package/dist/ops/gatherSub.js +0 -12
- package/dist/ops/gelu.js +0 -1
- package/dist/ops/globalNorm.js +0 -19
- package/dist/ops/grads/add16.js +0 -26
- package/dist/ops/grads/attentionMask.js +0 -25
- package/dist/ops/grads/dropout16.js +0 -1
- package/dist/ops/grads/gelu.js +0 -1
- package/dist/ops/grads/matMul16.js +0 -1
- package/dist/ops/grads/matMulGelu.js +0 -21
- package/dist/ops/grads/mul16.js +0 -1
- package/dist/ops/grads/normRMS.js +0 -36
- package/dist/ops/grads/pack16.js +0 -1
- package/dist/ops/grads/qkv.js +0 -46
- package/dist/ops/grads/rope.js +0 -1
- package/dist/ops/grads/silu.js +0 -1
- package/dist/ops/grads/softmax16.js +0 -22
- package/dist/ops/grads/unpack16.js +0 -1
- package/dist/ops/grads/utils.js +0 -11
- package/dist/ops/log.js +0 -1
- package/dist/ops/matMul16.js +0 -1
- package/dist/ops/matMulGelu.js +0 -19
- package/dist/ops/matMulMul.js +0 -15
- package/dist/ops/mul16.js +0 -1
- package/dist/ops/mulDrop.js +0 -14
- package/dist/ops/normRMS.js +0 -21
- package/dist/ops/pack16.js +0 -1
- package/dist/ops/qkv.js +0 -15
- package/dist/ops/reshape16.js +0 -33
- package/dist/ops/rope.js +0 -1
- package/dist/ops/scatterSub.js +0 -12
- package/dist/ops/silu.js +0 -1
- package/dist/ops/slice16.js +0 -11
- package/dist/ops/softmax16.js +0 -8
- package/dist/ops/sub16.js +0 -10
- package/dist/ops/sum16.js +0 -13
- package/dist/ops/transpose16.js +0 -33
- package/dist/ops/unpack16.js +0 -1
- package/dist/ops/webgl/adamAdjust.js +0 -81
- package/dist/ops/webgl/adamMoments.js +0 -43
- package/dist/ops/webgl/appendCache.js +0 -52
- package/dist/ops/webgl/attentionMask.js +0 -63
- package/dist/ops/webgl/dropout16.js +0 -11
- package/dist/ops/webgl/fusedSoftmax.js +0 -70
- package/dist/ops/webgl/gatherSub.js +0 -27
- package/dist/ops/webgl/gelu.js +0 -47
- package/dist/ops/webgl/log.js +0 -14
- package/dist/ops/webgl/matMul16.js +0 -48
- package/dist/ops/webgl/matMulGelu.js +0 -1
- package/dist/ops/webgl/matMulMul.js +0 -23
- package/dist/ops/webgl/mulDropout.js +0 -31
- package/dist/ops/webgl/normRMS.js +0 -115
- package/dist/ops/webgl/qkv.js +0 -53
- package/dist/ops/webgl/rope.js +0 -73
- package/dist/ops/webgl/scatterSub.js +0 -27
- package/dist/ops/webgpu/adamAdjust.js +0 -76
- package/dist/ops/webgpu/adamMoments.js +0 -75
- package/dist/ops/webgpu/add16.js +0 -13
- package/dist/ops/webgpu/appendCache.js +0 -129
- package/dist/ops/webgpu/attentionMask.js +0 -41
- package/dist/ops/webgpu/attentionMask32_program.js +0 -61
- package/dist/ops/webgpu/clipScale.js +0 -44
- package/dist/ops/webgpu/concat16.js +0 -110
- package/dist/ops/webgpu/dropout16.js +0 -58
- package/dist/ops/webgpu/gatherSub.js +0 -51
- package/dist/ops/webgpu/gelu.js +0 -146
- package/dist/ops/webgpu/index.js +0 -27
- package/dist/ops/webgpu/matMul16.js +0 -91
- package/dist/ops/webgpu/matMul16_program.js +0 -311
- package/dist/ops/webgpu/mul16.js +0 -13
- package/dist/ops/webgpu/norm2.js +0 -45
- package/dist/ops/webgpu/normRMS.js +0 -25
- package/dist/ops/webgpu/normRMS16_program.js +0 -28
- package/dist/ops/webgpu/normRMS32_program.js +0 -28
- package/dist/ops/webgpu/normRMSGrad.js +0 -225
- package/dist/ops/webgpu/pack16.js +0 -20
- package/dist/ops/webgpu/pack16_program.js +0 -92
- package/dist/ops/webgpu/qkv.js +0 -63
- package/dist/ops/webgpu/rope.js +0 -227
- package/dist/ops/webgpu/scatterSub.js +0 -52
- package/dist/ops/webgpu/silu.js +0 -117
- package/dist/ops/webgpu/slice16.js +0 -73
- package/dist/ops/webgpu/softmax16.js +0 -18
- package/dist/ops/webgpu/softmax16_program.js +0 -88
- package/dist/ops/webgpu/softmax16_subgroup_program.js +0 -69
- package/dist/ops/webgpu/softmax16grad.js +0 -30
- package/dist/ops/webgpu/sub16.js +0 -13
- package/dist/ops/webgpu/sum16.js +0 -30
- package/dist/ops/webgpu/transpose16.js +0 -38
- package/dist/ops/webgpu/transpose16_program.js +0 -50
- package/dist/ops/webgpu/transpose16_shared_program.js +0 -78
- package/dist/ops/webgpu/unpack16.js +0 -59
- package/dist/ops/webgpu/utils/binary_op.js +0 -140
- package/dist/ops/webgpu/utils/deviceInfo.js +0 -10
- package/dist/ops/webgpu/utils/reductions.js +0 -264
- package/dist/ops-Be5ACU5R.js +0 -13
- package/dist/ops-C1UpdEYM.js +0 -509
- package/dist/pack16-BHO4t1-M.js +0 -36
- package/dist/pad-Dy-1IP3A.js +0 -13
- package/dist/patches/webgpu_backend.js +0 -42
- package/dist/patches/webgpu_program.js +0 -292
- package/dist/picomatch--TW6gyBJ.js +0 -999
- package/dist/qkv-BQfNPucX.js +0 -42
- package/dist/rand_util-_vCY93Uw.js +0 -44
- package/dist/random_normal-DUIT8kyC.js +0 -11
- package/dist/range-CYvQC3fW.js +0 -13
- package/dist/relu-C4XULT8A.js +0 -8
- package/dist/reshape-DJb1jgMt.js +0 -8
- package/dist/resize_nearest_neighbor-DAqcTYUe.js +0 -188
- package/dist/rope-JjBVufF_.js +0 -24
- package/dist/scatterSub-BOnqk-uY.js +0 -27
- package/dist/scatter_nd_util-BepMCpLY.js +0 -34
- package/dist/seedrandom-SHEGFK6H.js +0 -282
- package/dist/selu_util-DeOTf-sc.js +0 -27
- package/dist/shared-CX_iPI5K.js +0 -4
- package/dist/silu-DsAE2cJ5.js +0 -23
- package/dist/slice-Dlb1FlzG.js +0 -13
- package/dist/slice_util-BVgPRoij.js +0 -207
- package/dist/softmax-Dpav_dWw.js +0 -10
- package/dist/split-DYnT8chz.js +0 -11
- package/dist/squeeze-B3XYGAlg.js +0 -9
- package/dist/stack-Dbbt9mIk.js +0 -10
- package/dist/step-DA-5DNu9.js +0 -348
- package/dist/stream-BBe2apn4.js +0 -2280
- package/dist/sum-C8qNbFNp.js +0 -13
- package/dist/tensor-ALxWZfmz.js +0 -7
- package/dist/tensor1d-BHgkkhTE.js +0 -9
- package/dist/tensor2d-ARItvqVn.js +0 -10
- package/dist/tensor4d-D1zRBipJ.js +0 -10
- package/dist/tfjs_backend-CsXOum0h.js +0 -685
- package/dist/tile-DfyQ0KX-.js +0 -10
- package/dist/tokenise-DbS2Ea-T.js +0 -14
- package/dist/tokenise.js +0 -6
- package/dist/tokeniser/BaseTokeniser.js +0 -137
- package/dist/tokeniser/CharTokeniser.js +0 -85
- package/dist/tokeniser/bpe.js +0 -156
- package/dist/tokeniser/messages.js +0 -0
- package/dist/tokeniser/type.js +0 -0
- package/dist/topk-BrU2pkrR.js +0 -19
- package/dist/training/AdamW.js +0 -132
- package/dist/training/BasicTrainer.js +0 -274
- package/dist/training/DatasetBuilder.js +0 -1
- package/dist/training/Evaluator.js +0 -51
- package/dist/training/LRScheduler.js +0 -37
- package/dist/training/PreTrainer.js +0 -21
- package/dist/training/SFTTrainer.js +0 -23
- package/dist/training/configure.js +0 -33
- package/dist/training/factory.js +0 -7
- package/dist/training/loss.js +0 -18
- package/dist/training/orthoGrad.js +0 -9
- package/dist/training/prepareData.js +0 -51
- package/dist/training/sparseCrossEntropy.js +0 -53
- package/dist/training/tasks/TokenStore.js +0 -217
- package/dist/training/tasks/tokenStream.js +0 -45
- package/dist/training/types.js +0 -0
- package/dist/training/validateOptions.js +0 -18
- package/dist/training/validation.js +0 -30
- package/dist/transpose-BC-M_OoT.js +0 -34
- package/dist/unsorted_segment_sum-BelC7R-q.js +0 -408
- package/dist/utilities/arrayClose.js +0 -29
- package/dist/utilities/arrayShape.js +0 -7
- package/dist/utilities/datasetID.js +0 -17
- package/dist/utilities/dummy.js +0 -36
- package/dist/utilities/float16.js +0 -46
- package/dist/utilities/maxHeap.js +0 -54
- package/dist/utilities/multinomialCPU.js +0 -7
- package/dist/utilities/naming.js +0 -0
- package/dist/utilities/packed.js +0 -12
- package/dist/utilities/parameters.js +0 -53
- package/dist/utilities/performance.js +0 -15
- package/dist/utilities/profile.js +0 -32
- package/dist/utilities/random.js +0 -18
- package/dist/utilities/safetensors.js +0 -63
- package/dist/utilities/sentences.js +0 -35
- package/dist/utilities/tokenParse.js +0 -16
- package/dist/utilities/tokens.js +0 -39
- package/dist/utilities/topP.js +0 -25
- package/dist/utilities/waitForModel.js +0 -11
- package/dist/utilities/weights.js +0 -40
- package/dist/utilities/yielder.js +0 -6
- package/dist/v4-YCkfo8OR.js +0 -27
- package/dist/webgpu-BHX-uBym.js +0 -518
- package/dist/webgpu_util-5QTyovaf.js +0 -105
- package/dist/zeros-hxKGkRfl.js +0 -12
|
@@ -1,126 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
var o = (e, t, n) => n === "int32" ? `atomicAdd(${e}, bitcast<i32>(${t}));` : `
|
|
11
|
-
{
|
|
12
|
-
var oldValue = 0;
|
|
13
|
-
loop {
|
|
14
|
-
let newValueF32 = bitcast<f32>(oldValue) + (${t});
|
|
15
|
-
let newValue = bitcast<i32>(newValueF32);
|
|
16
|
-
let res = atomicCompareExchangeWeak(${e}, oldValue, newValue);
|
|
17
|
-
if res.exchanged {
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
oldValue = res.old_value;
|
|
21
|
-
}
|
|
22
|
-
}`, s;
|
|
23
|
-
(function(e) {
|
|
24
|
-
e[e.FROM_PIXELS = 0] = "FROM_PIXELS", e[e.DRAW = 1] = "DRAW";
|
|
25
|
-
})(s ||= {});
|
|
26
|
-
var c = (e, n, r, i, a) => {
|
|
27
|
-
let o = h(r, {
|
|
28
|
-
dtype: i.dtype,
|
|
29
|
-
shape: i.shape
|
|
30
|
-
}, n), s = e.createShaderModule({
|
|
1
|
+
import { Di as e, Ei as t, Ii as n, M as r, Ti as i, ta as a } from "./dist-JOPw9zTN.js";
|
|
2
|
+
import { _ as o, b as s, d as c, f as l, g as u, m as d, p as f, t as p, v as m } from "./webgpu-wUCQopBN.js";
|
|
3
|
+
// lib/patches/webgpu_program.ts
|
|
4
|
+
var h = (e, t, n, r, a) => {
|
|
5
|
+
let o = g(n, {
|
|
6
|
+
dtype: r.dtype,
|
|
7
|
+
shape: r.shape
|
|
8
|
+
}, t), s = e.createShaderModule({
|
|
31
9
|
code: o,
|
|
32
|
-
label:
|
|
33
|
-
}), c =
|
|
10
|
+
label: t.constructor.name
|
|
11
|
+
}), c = i().get("WEBGPU_PRINT_SHADER");
|
|
34
12
|
if (c !== "") {
|
|
35
13
|
c = c.toLowerCase();
|
|
36
14
|
let e = c.split(",");
|
|
37
|
-
(c === "all" || e.some((e) =>
|
|
15
|
+
(c === "all" || e.some((e) => t.shaderKey.toLowerCase().includes(e))) && (console.group(t.shaderKey), console.debug(o), console.groupEnd());
|
|
38
16
|
}
|
|
39
17
|
return a ? e.createComputePipelineAsync({
|
|
40
18
|
compute: {
|
|
41
19
|
module: s,
|
|
42
20
|
entryPoint: "_start"
|
|
43
21
|
},
|
|
44
|
-
label:
|
|
22
|
+
label: t.constructor.name,
|
|
45
23
|
layout: "auto"
|
|
46
24
|
}) : e.createComputePipeline({
|
|
47
25
|
compute: {
|
|
48
26
|
module: s,
|
|
49
27
|
entryPoint: "_start"
|
|
50
28
|
},
|
|
51
|
-
label:
|
|
29
|
+
label: t.constructor.name,
|
|
52
30
|
layout: "auto"
|
|
53
31
|
});
|
|
54
|
-
}, l = (e, t = "f32") => {
|
|
55
|
-
switch (e) {
|
|
56
|
-
case 1: return `${t}`;
|
|
57
|
-
case 2: return `vec2<${t}>`;
|
|
58
|
-
case 3: return `vec3<${t}>`;
|
|
59
|
-
case 4: return `vec4<${t}>`;
|
|
60
|
-
default: throw Error(`${e}-component ${t} is not supported.`);
|
|
61
|
-
}
|
|
62
32
|
};
|
|
63
|
-
function
|
|
64
|
-
if (e <= 1) return "i32";
|
|
65
|
-
if (e === 2) return "vec2<i32>";
|
|
66
|
-
if (e === 3) return "vec3<i32>";
|
|
67
|
-
if (e === 4) return "vec4<i32>";
|
|
68
|
-
if (e === 5) return "vec5";
|
|
69
|
-
if (e === 6) return "vec6";
|
|
70
|
-
throw Error(`GPU for rank ${e} is not yet supported`);
|
|
71
|
-
}
|
|
72
|
-
function d(e) {
|
|
73
|
-
if (e === 0) return "x";
|
|
74
|
-
if (e === 1) return "y";
|
|
75
|
-
if (e === 2) return "z";
|
|
76
|
-
if (e === 3) return "w";
|
|
77
|
-
if (e === 4) return "u";
|
|
78
|
-
if (e === 5) return "v";
|
|
79
|
-
throw Error(`Index ${e} is not yet supported`);
|
|
80
|
-
}
|
|
81
|
-
function f(...e) {
|
|
82
|
-
let t;
|
|
83
|
-
switch (e.length) {
|
|
84
|
-
case 0:
|
|
85
|
-
t = "\n fn main()\n ";
|
|
86
|
-
break;
|
|
87
|
-
case 1:
|
|
88
|
-
t = `
|
|
89
|
-
fn main(${e[0]} : i32)
|
|
90
|
-
`;
|
|
91
|
-
break;
|
|
92
|
-
default: throw Error("Unreachable");
|
|
93
|
-
}
|
|
94
|
-
return t;
|
|
95
|
-
}
|
|
96
|
-
function p(e, t) {
|
|
97
|
-
let n;
|
|
98
|
-
return n = `
|
|
99
|
-
${m(t)}
|
|
100
|
-
fn _start(@builtin(local_invocation_id) LocalId : vec3<u32>,
|
|
101
|
-
@builtin(global_invocation_id) GlobalId : vec3<u32>,
|
|
102
|
-
@builtin(local_invocation_index) LocalIndex: u32,
|
|
103
|
-
@builtin(workgroup_id) WorkgroupId : vec3<u32>,
|
|
104
|
-
${t.subgroupBuiltins ? "@builtin(subgroup_invocation_id) SubgroupInvocationId : u32," : ""}
|
|
105
|
-
${t.subgroupBuiltins ? "@builtin(subgroup_size) SubgroupSize : u32," : ""}
|
|
106
|
-
@builtin(num_workgroups) NumWorkgroups : vec3<u32>) {
|
|
107
|
-
localId = LocalId;
|
|
108
|
-
localIndex = LocalIndex;
|
|
109
|
-
globalId = GlobalId;
|
|
110
|
-
numWorkgroups = NumWorkgroups;
|
|
111
|
-
workgroupId = WorkgroupId;
|
|
112
|
-
${t.subgroupBuiltins ? "subgroupInvocationId = SubgroupInvocationId" : ""};
|
|
113
|
-
${t.subgroupBuiltins ? "subgroupSize = SubgroupSize" : ""};
|
|
114
|
-
${e ? "main(getGlobalIndex());" : "main();"};
|
|
115
|
-
}
|
|
116
|
-
`, n;
|
|
117
|
-
}
|
|
118
|
-
function m(e) {
|
|
119
|
-
return `
|
|
120
|
-
@compute @workgroup_size(${e.workgroupSize[0]}, ${e.workgroupSize[1]}, ${e.workgroupSize[2]})
|
|
121
|
-
`;
|
|
122
|
-
}
|
|
123
|
-
function h(e, t, n) {
|
|
33
|
+
function g(e, t, n) {
|
|
124
34
|
let r = [], i = n.workgroupSize[0] * n.workgroupSize[1] * n.workgroupSize[2];
|
|
125
35
|
if (n.outputComponent = n.outputComponent ? n.outputComponent : 1, r.push(`
|
|
126
36
|
|
|
@@ -129,18 +39,18 @@ function h(e, t, n) {
|
|
|
129
39
|
var<private> globalId: vec3<u32>;
|
|
130
40
|
var<private> numWorkgroups: vec3<u32>;
|
|
131
41
|
var<private> workgroupId: vec3<u32>;
|
|
132
|
-
|
|
133
|
-
|
|
42
|
+
${n.subgroupBuiltins ? "var<private> subgroupInvocationId: u32;" : ""}
|
|
43
|
+
${n.subgroupBuiltins ? "var<private> subgroupSize: u32;" : ""}
|
|
134
44
|
|
|
135
45
|
// Only used when the y/z dimension of workgroup size is 1.
|
|
136
46
|
fn getGlobalIndex() -> i32 {
|
|
137
|
-
${
|
|
47
|
+
${w(n) ? " return i32(globalId.x);" : ` return i32((workgroupId.z * numWorkgroups.x * numWorkgroups.y +
|
|
138
48
|
workgroupId.y * numWorkgroups.x + workgroupId.x) * ${i}u +
|
|
139
49
|
localIndex);
|
|
140
50
|
`}
|
|
141
51
|
}
|
|
142
52
|
`), n.pixelsOpType != null) {
|
|
143
|
-
let i = n.pixelsOpType ===
|
|
53
|
+
let i = n.pixelsOpType === 0 ? `@group(0) @binding(0) var<storage, read_write> result: array<${c(t.dtype, n.outputComponent)}>;` : `@group(0) @binding(1) var<storage, read> inBuf : array<${c(e[0].dtype, n.outputComponent)}>;`, a = t.shape.length === 3 ? "vec2<i32>" : "i32";
|
|
144
54
|
r.push(`
|
|
145
55
|
struct Uniform {
|
|
146
56
|
outShapeStrides : ${a},
|
|
@@ -152,77 +62,50 @@ function h(e, t, n) {
|
|
|
152
62
|
${i}
|
|
153
63
|
@group(0) @binding(2) var<uniform> uniforms: Uniform;
|
|
154
64
|
`);
|
|
155
|
-
let o =
|
|
65
|
+
let o = D(n);
|
|
156
66
|
return [
|
|
157
67
|
_,
|
|
158
68
|
r.join("\n"),
|
|
159
|
-
|
|
69
|
+
f(t.shape),
|
|
160
70
|
n.getUserCode(),
|
|
161
|
-
|
|
71
|
+
O(o, n)
|
|
162
72
|
].join("\n");
|
|
163
73
|
}
|
|
164
|
-
let a, o,
|
|
74
|
+
let a, o, s = "struct Uniforms { NAN : f32, INFINITY : f32, ";
|
|
165
75
|
n.variableNames.forEach((t, n) => {
|
|
166
|
-
let r =
|
|
167
|
-
|
|
76
|
+
let r = l(e[n].shape.length);
|
|
77
|
+
s += `${t.charAt(0).toLowerCase() + t.slice(1)}Shape : ${r}, `, a = e[n].shape.length - 1, o = l(a), s += `${t.charAt(0).toLowerCase() + t.slice(1)}ShapeStrides: ${o}, `;
|
|
168
78
|
});
|
|
169
|
-
let
|
|
170
|
-
|
|
171
|
-
outShapeStrides: ${o}, `, n.size && (
|
|
172
|
-
@group(0) @binding(0) var<storage, read_write> result: array<${
|
|
79
|
+
let u = l(t.shape.length);
|
|
80
|
+
s += `outShape : ${u}, `, a = t.shape.length - 1, o = l(a), s += `
|
|
81
|
+
outShapeStrides: ${o}, `, n.size && (s += "size : i32, "), n.uniforms && (s += n.uniforms), s += "};", s = E(s), r.push(s), n.atomic ? r.push("\n @group(0) @binding(0) var<storage, read_write> result: array<atomic<i32>>;\n ") : r.push(`
|
|
82
|
+
@group(0) @binding(0) var<storage, read_write> result: array<${c(t.dtype, n.outputComponent)}>;
|
|
173
83
|
`), n.variableNames.forEach((t, i) => {
|
|
174
84
|
r.push(`
|
|
175
|
-
@group(0) @binding(${1 + i}) var<storage, read> ${t}: array<${n.variableComponents ?
|
|
85
|
+
@group(0) @binding(${1 + i}) var<storage, ${n.auxiliaryOutputs?.some((e) => e.name === t) ? "read_write" : "read"}> ${t}: array<${n.variableComponents ? c(e[i].dtype, n.variableComponents[i]) : c(e[i].dtype, n.outputComponent)}>;
|
|
176
86
|
`);
|
|
177
|
-
}),
|
|
87
|
+
}), s !== "" && r.push(`
|
|
178
88
|
@group(0) @binding(${1 + n.variableNames.length}) var<uniform> uniforms: Uniforms;
|
|
179
89
|
`);
|
|
180
|
-
let d =
|
|
90
|
+
let d = S(t.shape, n.dispatchLayout), p = [
|
|
181
91
|
n.subgroups ? "enable subgroups;" : "",
|
|
182
92
|
_,
|
|
183
93
|
r.join("\n") + v,
|
|
184
|
-
|
|
94
|
+
f(t.shape),
|
|
185
95
|
d,
|
|
186
|
-
|
|
96
|
+
C(t.shape.length)
|
|
187
97
|
];
|
|
188
|
-
n.atomic ||
|
|
189
|
-
|
|
98
|
+
n.atomic || p.push(T(t.shape, t.dtype, n.outputComponent)), n.variableNames.forEach((t, n) => {
|
|
99
|
+
p.push(`${f(e[n].shape, t)}`);
|
|
190
100
|
});
|
|
191
|
-
let m = e.map((e, r) =>
|
|
192
|
-
|
|
193
|
-
let h =
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
function g(e, t, i) {
|
|
197
|
-
let a = e.shaderKey;
|
|
198
|
-
if (e.pixelsOpType != null) return a;
|
|
199
|
-
let o = [], s = [];
|
|
200
|
-
t.forEach((e) => {
|
|
201
|
-
o.push(e.shape), s.push(e.dtype);
|
|
202
|
-
}), o.push(i.shape), s.push(i.dtype);
|
|
203
|
-
let c = t.map((e) => r(e.shape, i.shape)), l = t.map((e) => n(e.shape, i.shape)).join("_"), u = c.map((e) => e.join("_")).join(";"), d = T(e) ? "flatDispatch" : "";
|
|
204
|
-
return a += "_" + (e.workgroupSize ? e.workgroupSize.join(",") : "") + o.map((e) => e.length).join(",") + s.join(",") + e.variableNames.join(",") + u + l + d, a;
|
|
101
|
+
let m = e.map((e, r) => x(e, t.shape, n.variableComponents ? n.variableComponents[r] : n.outputComponent, n.dispatchLayout.x.length === t.shape.length)).join("\n");
|
|
102
|
+
p.push(m), p.push(n.getUserCode());
|
|
103
|
+
let h = D(n);
|
|
104
|
+
return p.push(O(h, n)), p.join("\n");
|
|
205
105
|
}
|
|
206
106
|
var _ = "\n struct vec5 {x: i32, y: i32, z: i32, w: i32, u: i32};\n struct vec6 {x: i32, y: i32, z: i32, w: i32, u: i32, v: i32};\n\n // Checks whether coordinates lie within the bounds of the shape.\n fn coordsInBounds2D(coord : vec2<i32>, shape : vec2<i32>) -> bool {\n return all(coord >= vec2<i32>(0)) && all(coord < shape);\n }\n fn coordsInBounds3D(coord : vec3<i32>, shape : vec3<i32>) -> bool {\n return all(coord >= vec3<i32>(0)) && all(coord < shape);\n }\n fn coordsInBounds4D(coord : vec4<i32>, shape : vec4<i32>) -> bool {\n return all(coord >= vec4<i32>(0)) && all(coord < shape);\n }\n\n fn getIndexFromCoords1D(coord : i32, shape : i32) -> i32 {\n return coord;\n }\n fn getIndexFromCoords2D(coords : vec2<i32>, shape : vec2<i32>) -> i32 {\n return dot(coords, vec2<i32>(shape.y, 1));\n }\n fn getIndexFromCoords3D(coords : vec3<i32>, shape : vec3<i32>) -> i32 {\n return dot(coords, vec3<i32>(shape.y * shape.z, shape.z, 1));\n }\n fn getIndexFromCoords4D(coords : vec4<i32>, shape : vec4<i32>) -> i32 {\n return dot(coords, vec4<i32>(\n shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1));\n }\n fn getIndexFromCoords5D(coords : vec5, shape : vec5) -> i32 {\n let shapeStrides: vec5 = vec5(shape.y * shape.z * shape.w * shape.u, shape.z * shape.w * shape.u, shape.w * shape.u, shape.u, 1);\n return coords.x*shapeStrides.x + coords.y*shapeStrides.y + coords.z*shapeStrides.z + coords.w*shapeStrides.w + coords.u*shapeStrides.u;\n }\n fn getIndexFromCoords6D(coords : vec6, shape : vec6) -> i32 {\n let shapeStrides: vec6 = vec6(shape.y * shape.z * shape.w * shape.u * shape.v, shape.z * shape.w * shape.u * shape.v, shape.w * shape.u * shape.v, shape.u * shape.v, shape.v, 1);\n return coords.x*shapeStrides.x + coords.y*shapeStrides.y + coords.z*shapeStrides.z + coords.w*shapeStrides.w + coords.u*shapeStrides.u + coords.v*shapeStrides.v;\n }\n\n // NaN defination in IEEE 754-1985 is :\n // - sign = either 0 or 1.\n // - biased exponent = all 1 bits.\n // - fraction = anything except all 0 bits (since all 0 bits represents infinity).\n // https://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbers\n fn isnan(val: f32) -> bool {\n let floatToUint: u32 = bitcast<u32>(val);\n return (floatToUint & 0x7fffffffu) > 0x7f800000u;\n }\n fn isnanVec4(val : vec4<f32>) -> vec4<bool> {\n let floatToUint: vec4<u32> = bitcast<vec4<u32>>(val);\n return (floatToUint & vec4<u32>(0x7fffffffu)) > vec4<u32>(0x7f800000u);\n }\n", v = "\n fn isinf(val: f32) -> bool {\n return abs(val) == uniforms.INFINITY;\n }\n";
|
|
207
|
-
function y(
|
|
208
|
-
let r =
|
|
209
|
-
if (r <= 1) return `fn ${i}(index : i32) -> i32 { return index; }`;
|
|
210
|
-
let o = e(t), s = u(r), c = [];
|
|
211
|
-
for (let e = 0; e < r; e++) c.push(`d${e}`);
|
|
212
|
-
if (o.length === 1) return ` fn ${i}(index : i32) -> vec2<i32> {
|
|
213
|
-
let d0 = index / uniforms.${a}; let d1 = index - d0 * uniforms.${a};
|
|
214
|
-
return vec2<i32>(d0, d1);
|
|
215
|
-
}`;
|
|
216
|
-
let l;
|
|
217
|
-
return l = "var index2 = index;" + o.map((e, t) => `${`let ${c[t]} = index2 / uniforms.${a}.${d(t)}`}; ${t === o.length - 1 ? `let ${c[t + 1]} = index2 - ${c[t]} * uniforms.${a}.${d(t)}` : `index2 = index2 - ${c[t]} * uniforms.${a}.${d(t)}`};`).join(""), `
|
|
218
|
-
fn ${i}(index : i32) -> ${s} {
|
|
219
|
-
${l}
|
|
220
|
-
return ${s}(${c.join(",")});
|
|
221
|
-
}
|
|
222
|
-
`;
|
|
223
|
-
}
|
|
224
|
-
function b(e, t) {
|
|
225
|
-
let n = e.name, r = e.shape.length, i = u(r), a = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = [
|
|
107
|
+
function y(e, t) {
|
|
108
|
+
let n = e.name, r = e.shape.length, i = l(r), a = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = [
|
|
226
109
|
"d0",
|
|
227
110
|
"d1",
|
|
228
111
|
"d2",
|
|
@@ -231,132 +114,127 @@ function b(e, t) {
|
|
|
231
114
|
"d5"
|
|
232
115
|
].slice(0, r), s = o.map((e) => `${e} : i32`).join(", ");
|
|
233
116
|
if (r < 1) return `
|
|
234
|
-
fn ${a}() -> ${
|
|
235
|
-
return ${
|
|
117
|
+
fn ${a}() -> ${m(t)} {
|
|
118
|
+
return ${m(t)}(${n}[0]);
|
|
236
119
|
}
|
|
237
120
|
`;
|
|
238
|
-
let c = `uniforms.${n.charAt(0).toLowerCase() + n.slice(1)}Shape`,
|
|
239
|
-
return r === 0 && (
|
|
240
|
-
fn ${a}(${s}) -> ${
|
|
241
|
-
return ${
|
|
121
|
+
let c = `uniforms.${n.charAt(0).toLowerCase() + n.slice(1)}Shape`, u = `${r}D`;
|
|
122
|
+
return r === 0 && (u = "1D"), `
|
|
123
|
+
fn ${a}(${s}) -> ${m(t)} {
|
|
124
|
+
return ${m(t)}(${n}[getIndexFromCoords${u}(${i}(${o.join(",")}),
|
|
242
125
|
${c})${t === 1 ? "" : ` / ${t}`}]);
|
|
243
126
|
}
|
|
244
127
|
`;
|
|
245
128
|
}
|
|
246
|
-
function
|
|
247
|
-
let o = e.name, s = o.charAt(0).toUpperCase() + o.slice(1), c = "get" + s + "ByOutput",
|
|
248
|
-
if (
|
|
249
|
-
fn ${c}Index(globalIndex : i32) -> ${
|
|
250
|
-
return ${
|
|
129
|
+
function b(e, n, i, a) {
|
|
130
|
+
let o = e.name, s = o.charAt(0).toUpperCase() + o.slice(1), c = "get" + s + "ByOutput", u = e.shape.length, f = n.length, p = l(f);
|
|
131
|
+
if (t(e.shape, n) && a) return `
|
|
132
|
+
fn ${c}Index(globalIndex : i32) -> ${m(i)} {
|
|
133
|
+
return ${m(i)}(${o}[globalIndex]);
|
|
251
134
|
}
|
|
252
135
|
|
|
253
|
-
fn ${c}Coords(coords : ${
|
|
254
|
-
return ${
|
|
136
|
+
fn ${c}Coords(coords : ${p}) -> ${m(i)} {
|
|
137
|
+
return ${m(i)}(${o}[${f > 1 ? "getOutputIndexFromCoords(coords)" : "coords"}${i === 1 ? "" : ` / ${i}`}]);
|
|
255
138
|
}
|
|
256
139
|
`;
|
|
257
|
-
let h = r(e.shape,
|
|
258
|
-
if (
|
|
259
|
-
fn ${c}Index(globalIndex : i32) -> ${
|
|
140
|
+
let h = r(e.shape, n), g = f - u, _;
|
|
141
|
+
if (u === 0) return `
|
|
142
|
+
fn ${c}Index(globalIndex : i32) -> ${m(i)}{
|
|
260
143
|
return get${s}();
|
|
261
144
|
}
|
|
262
145
|
|
|
263
|
-
fn ${c}Coords(coords : ${
|
|
146
|
+
fn ${c}Coords(coords : ${p}) -> ${m(i)}{
|
|
264
147
|
return get${s}();
|
|
265
148
|
}
|
|
266
149
|
`;
|
|
267
|
-
_ =
|
|
268
|
-
let v
|
|
269
|
-
v =
|
|
270
|
-
let y = `uniforms.${o.charAt(0).toLowerCase() + o.slice(1)}Shape`, b = `${
|
|
150
|
+
_ = f < 2 && h.length >= 1 ? "coords = 0;" : h.map((e) => `coords.${d(e + g)} = 0;`).join("\n");
|
|
151
|
+
let v;
|
|
152
|
+
v = f < 2 && u > 0 ? "coords" : f > 1 ? `${l(u)}(${e.shape.map((e, t) => `coords.${d(t + g)}`).join(", ")})` : "coords";
|
|
153
|
+
let y = `uniforms.${o.charAt(0).toLowerCase() + o.slice(1)}Shape`, b = `${u}D`;
|
|
271
154
|
return `
|
|
272
|
-
fn ${c}Index(globalIndex : i32) -> ${
|
|
155
|
+
fn ${c}Index(globalIndex : i32) -> ${m(i)} {
|
|
273
156
|
var coords = getCoordsFromIndex(globalIndex);
|
|
274
157
|
${_}
|
|
275
|
-
return ${
|
|
158
|
+
return ${m(i)}(${o}[getIndexFromCoords${b}(${v}, ${y})${i === 1 ? "" : ` / ${i}`}]);
|
|
276
159
|
}
|
|
277
160
|
|
|
278
|
-
fn ${c}Coords(coordsIn : ${
|
|
161
|
+
fn ${c}Coords(coordsIn : ${p}) -> ${m(i)} {
|
|
279
162
|
var coords = coordsIn;
|
|
280
163
|
${_}
|
|
281
|
-
return ${
|
|
164
|
+
return ${m(i)}(${o}[getIndexFromCoords${b}(${v}, ${y})${i === 1 ? "" : ` / ${i}`}]);
|
|
282
165
|
}
|
|
283
166
|
`;
|
|
284
167
|
}
|
|
285
|
-
function
|
|
286
|
-
let i =
|
|
287
|
-
return e.shape.length <= t.length && (i +=
|
|
168
|
+
function x(e, t, n, r) {
|
|
169
|
+
let i = y(e, n);
|
|
170
|
+
return e.shape.length <= t.length && (i += b(e, t, n, r)), i;
|
|
288
171
|
}
|
|
289
|
-
function
|
|
290
|
-
let { x: n, y: r = [], z: i = [] } = t,
|
|
291
|
-
if (
|
|
292
|
-
if (n.length ===
|
|
172
|
+
function S(e, t) {
|
|
173
|
+
let { x: n, y: r = [], z: i = [] } = t, a = e.length, o = n.length + r.length + i.length;
|
|
174
|
+
if (o !== a) return "";
|
|
175
|
+
if (n.length === a) return `fn getOutputCoords() -> ${l(a)}{
|
|
293
176
|
let globalIndex = getGlobalIndex();
|
|
294
177
|
return getCoordsFromIndex(globalIndex);
|
|
295
178
|
}
|
|
296
179
|
`;
|
|
297
|
-
let c = "",
|
|
180
|
+
let c = "", u = [
|
|
298
181
|
n,
|
|
299
182
|
r,
|
|
300
183
|
i
|
|
301
184
|
];
|
|
302
|
-
for (let e = 0; e <
|
|
303
|
-
let t =
|
|
185
|
+
for (let e = 0; e < u.length; e++) {
|
|
186
|
+
let t = u[e];
|
|
304
187
|
if (t.length !== 0) {
|
|
305
188
|
if (t.length === 1) c += `let d${t[0]} = i32(globalId[${e}]);`;
|
|
306
189
|
else {
|
|
307
|
-
let n =
|
|
190
|
+
let n = s(t, "uniforms.outShape");
|
|
308
191
|
c += `var index${e} = i32(globalId[${e}]);`;
|
|
309
192
|
for (let r = 0; r < n.length; r++) c += `let d${t[r]} = index${e} / ${n[r]};`, r === n.length - 1 ? c += `let d${t[r + 1]} = index${e} - d${t[r]} * ${n[r]};` : c += `index${e} = index${e} - d${t[r]} * ${n[r]};`;
|
|
310
193
|
}
|
|
311
194
|
}
|
|
312
195
|
}
|
|
313
196
|
let d = [];
|
|
314
|
-
for (let e = 0; e <
|
|
315
|
-
let f =
|
|
197
|
+
for (let e = 0; e < o; e++) d.push(`d${e}`);
|
|
198
|
+
let f = l(o), p = `fn getOutputCoords() -> ${f} {
|
|
316
199
|
${c}
|
|
317
200
|
`;
|
|
318
201
|
return d.length === 0 ? p += `return ${f}(0); }` : p += `return ${f}(${d.join(",")}); }`, p;
|
|
319
202
|
}
|
|
320
|
-
function
|
|
321
|
-
let
|
|
322
|
-
switch (
|
|
203
|
+
function C(t) {
|
|
204
|
+
let n = "";
|
|
205
|
+
switch (t) {
|
|
323
206
|
case 0:
|
|
324
207
|
case 1:
|
|
325
|
-
|
|
208
|
+
n += "\n fn getOutputIndexFromCoords(coords : i32) -> i32 {\n return coords;\n }\n ";
|
|
326
209
|
break;
|
|
327
210
|
case 2:
|
|
328
|
-
|
|
211
|
+
n += "\n fn getOutputIndexFromCoords(coords : vec2<i32>) -> i32 {\n return dot(coords, vec2<i32>(uniforms.outShapeStrides, 1));\n }\n ";
|
|
329
212
|
break;
|
|
330
213
|
case 3:
|
|
331
|
-
|
|
214
|
+
n += "\n fn getOutputIndexFromCoords(coords : vec3<i32>) -> i32 {\n return dot(coords, vec3<i32>(uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, 1));\n }\n ";
|
|
332
215
|
break;
|
|
333
216
|
case 4:
|
|
334
|
-
|
|
217
|
+
n += "\n fn getOutputIndexFromCoords(coords : vec4<i32>) -> i32 {\n return dot(coords, vec4<i32>(\n uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, uniforms.outShapeStrides.z, 1));\n }\n ";
|
|
335
218
|
break;
|
|
336
219
|
case 5:
|
|
337
|
-
|
|
220
|
+
n += "\n fn getOutputIndexFromCoords(coords : vec5) -> i32 {\n return coords.x * uniforms.outShapeStrides.x +\n coords.y * uniforms.outShapeStrides.y +\n coords.z * uniforms.outShapeStrides.z +\n coords.w * uniforms.outShapeStrides.w +\n coords.u;\n }\n ";
|
|
338
221
|
break;
|
|
339
222
|
case 6:
|
|
340
|
-
|
|
223
|
+
n += "\n fn getOutputIndexFromCoords(coords : vec6) -> i32 {\n return coords.x * uniforms.outShapeStrides.x +\n coords.y * uniforms.outShapeStrides.y +\n coords.z * uniforms.outShapeStrides.z +\n coords.w * uniforms.outShapeStrides.w +\n coords.u * uniforms.outShapeStrides.u +\n coords.v;\n }\n ";
|
|
341
224
|
break;
|
|
342
|
-
default:
|
|
225
|
+
default: e(!1, () => `Unsupported ${t}D shape`);
|
|
343
226
|
}
|
|
344
|
-
return
|
|
227
|
+
return n;
|
|
345
228
|
}
|
|
346
|
-
function
|
|
229
|
+
function w(e) {
|
|
347
230
|
return e.dispatch[1] === 1 && e.dispatch[2] === 1;
|
|
348
231
|
}
|
|
349
|
-
function
|
|
350
|
-
|
|
351
|
-
if (e === "int32" || e === "bool" || e === "packedF16") return l(t, "i32");
|
|
352
|
-
throw Error(`type ${e} is not supported.`);
|
|
353
|
-
}
|
|
354
|
-
function D(e, t, n) {
|
|
355
|
-
let r = e.length, i = E(t, n), a = `fn setOutputAtIndex(flatIndex : i32, value : ${l(n)}) {
|
|
232
|
+
function T(e, t, n) {
|
|
233
|
+
let r = e.length, i = c(t, n), a = `fn setOutputAtIndex(flatIndex : i32, value : ${m(n)}) {
|
|
356
234
|
result[flatIndex] = ${i}(value);
|
|
357
235
|
}
|
|
358
236
|
|
|
359
|
-
fn setOutputAtIndexI32(flatIndex : i32, value : ${
|
|
237
|
+
fn setOutputAtIndexI32(flatIndex : i32, value : ${m(n, "i32")}) {
|
|
360
238
|
result[flatIndex] = ${i}(value);
|
|
361
239
|
}
|
|
362
240
|
`;
|
|
@@ -368,13 +246,13 @@ function D(e, t, n) {
|
|
|
368
246
|
"d3",
|
|
369
247
|
"d4",
|
|
370
248
|
"d5"
|
|
371
|
-
].slice(0, r), t =
|
|
249
|
+
].slice(0, r), t = l(r);
|
|
372
250
|
a += `
|
|
373
|
-
fn setOutputAtCoords(${e.map((e) => `${e} : i32`).join(", ")}, value : ${
|
|
251
|
+
fn setOutputAtCoords(${e.map((e) => `${e} : i32`).join(", ")}, value : ${m(n)}) {
|
|
374
252
|
let flatIndex = getOutputIndexFromCoords(${t}(${e.join(", ")}));
|
|
375
253
|
setOutputAtIndex(flatIndex${n === 1 ? "" : ` / ${n}`}, value);
|
|
376
254
|
}
|
|
377
|
-
fn setOutputAtCoordsI32(${e.map((e) => `${e} : i32`).join(", ")}, value : ${
|
|
255
|
+
fn setOutputAtCoordsI32(${e.map((e) => `${e} : i32`).join(", ")}, value : ${m(n, "i32")}) {
|
|
378
256
|
let flatIndex = getOutputIndexFromCoords(${t}(${e.join(", ")}));
|
|
379
257
|
setOutputAtIndexI32(flatIndex${n === 1 ? "" : ` / ${n}`}, value);
|
|
380
258
|
}
|
|
@@ -382,10 +260,83 @@ function D(e, t, n) {
|
|
|
382
260
|
}
|
|
383
261
|
return a;
|
|
384
262
|
}
|
|
385
|
-
function
|
|
263
|
+
function E(e) {
|
|
386
264
|
return e = e.replace(/(\w+)\s*:\s*vec(5|6)/g, (e) => "@align(16) " + e), e = e.replace(/vec(5|6)\s*,\s*(\w+)/g, (e, t, n) => `vec${t}, @align(16) ${n}`), e;
|
|
387
265
|
}
|
|
388
|
-
function
|
|
389
|
-
return !(e.dispatchLayout.hasOwnProperty("y") && e.dispatchLayout.y
|
|
266
|
+
function D(e) {
|
|
267
|
+
return !(e.dispatchLayout.hasOwnProperty("y") && e.dispatchLayout.y?.length !== 0 || e.dispatchLayout.hasOwnProperty("z") && e.dispatchLayout.z?.length !== 0);
|
|
390
268
|
}
|
|
391
|
-
|
|
269
|
+
function O(e, t) {
|
|
270
|
+
return `
|
|
271
|
+
${u(t)}
|
|
272
|
+
fn _start(@builtin(local_invocation_id) LocalId : vec3<u32>,
|
|
273
|
+
@builtin(global_invocation_id) GlobalId : vec3<u32>,
|
|
274
|
+
@builtin(local_invocation_index) LocalIndex: u32,
|
|
275
|
+
@builtin(workgroup_id) WorkgroupId : vec3<u32>,
|
|
276
|
+
${t.subgroupBuiltins ? "@builtin(subgroup_invocation_id) SubgroupInvocationId : u32," : ""}
|
|
277
|
+
${t.subgroupBuiltins ? "@builtin(subgroup_size) SubgroupSize : u32," : ""}
|
|
278
|
+
@builtin(num_workgroups) NumWorkgroups : vec3<u32>) {
|
|
279
|
+
localId = LocalId;
|
|
280
|
+
localIndex = LocalIndex;
|
|
281
|
+
globalId = GlobalId;
|
|
282
|
+
numWorkgroups = NumWorkgroups;
|
|
283
|
+
workgroupId = WorkgroupId;
|
|
284
|
+
${t.subgroupBuiltins ? "subgroupInvocationId = SubgroupInvocationId" : ""};
|
|
285
|
+
${t.subgroupBuiltins ? "subgroupSize = SubgroupSize" : ""};
|
|
286
|
+
${e ? "main(getGlobalIndex());" : "main();"};
|
|
287
|
+
}
|
|
288
|
+
`;
|
|
289
|
+
}
|
|
290
|
+
// lib/patches/webgpu_backend.ts
|
|
291
|
+
var k = (t, n) => {
|
|
292
|
+
let r = t.limits.maxComputeWorkgroupsPerDimension, i = n.dispatchLayout, a = n.dispatch;
|
|
293
|
+
if (a.every((e) => e <= r)) return a;
|
|
294
|
+
e(a[0] > r && i.y === void 0 && i.z === void 0, () => "Dispatch size exceeds WebGPU limits in Y or Z dimension.");
|
|
295
|
+
let o = Math.ceil(Math.sqrt(a[0]));
|
|
296
|
+
return o > r ? (o = Math.ceil(Math.cbrt(a[0])), e(o <= r, () => "Total dispatch size exceeds WebGPU maximum."), [
|
|
297
|
+
o,
|
|
298
|
+
o,
|
|
299
|
+
o
|
|
300
|
+
]) : [
|
|
301
|
+
o,
|
|
302
|
+
o,
|
|
303
|
+
1
|
|
304
|
+
];
|
|
305
|
+
}, A = class extends p {
|
|
306
|
+
subgroupMaxSize;
|
|
307
|
+
subgroupMinSize;
|
|
308
|
+
constructor(e, t) {
|
|
309
|
+
super(e, t), this.subgroupMaxSize = t?.subgroupMaxSize ?? 0, this.subgroupMinSize = t?.subgroupMinSize ?? 0;
|
|
310
|
+
}
|
|
311
|
+
runWebGPUProgramWithOutputs(t, r, i, o) {
|
|
312
|
+
let s = t.auxiliaryOutputs ?? [];
|
|
313
|
+
e(t.variableNames.length === r.length + s.length && s.every((e, n) => e.name === t.variableNames[r.length + n]), () => "Auxiliary outputs must match the final WebGPU variable bindings."), e(1 + t.variableNames.length <= this.device.limits.maxStorageBuffersPerShaderStage, () => "WebGPU program exceeds the storage buffer binding limit."), e(a(t.outputShape) !== 0 || s.every((e) => a(e.shape) === 0), () => "Empty primary outputs require empty auxiliary outputs.");
|
|
314
|
+
let c = [];
|
|
315
|
+
try {
|
|
316
|
+
return c.push(this.makeTensorInfo(t.outputShape, i)), s.forEach((e) => {
|
|
317
|
+
c.push(this.makeTensorInfo(e.shape, e.dtype));
|
|
318
|
+
}), this.runWebGPUProgram(t, [...r, ...c.slice(1)], i, o, c[0]), a(t.outputShape) === 0 && c.slice(1).forEach((e) => {
|
|
319
|
+
if (e.dtype === "string" || e.dtype === "complex64") throw Error(`Unsupported WebGPU auxiliary output dtype: ${e.dtype}`);
|
|
320
|
+
this.tensorMap.get(e.dataId).values = n(e.dtype, 0);
|
|
321
|
+
}), c;
|
|
322
|
+
} catch (e) {
|
|
323
|
+
throw c.forEach((e) => this.disposeData(e.dataId)), e;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
runWebGPUProgram(e, t, r, s, c) {
|
|
327
|
+
if (c ||= this.makeTensorInfo(e.outputShape, r), a(c.shape) === 0) return this.tensorMap.get(c.dataId).values = n(c.dtype, 0), c;
|
|
328
|
+
this.uploadToGPU(c.dataId), e.dispatch = k(this.device, e);
|
|
329
|
+
let l = t.map((t, n) => {
|
|
330
|
+
if (t.dtype === "complex64") throw Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");
|
|
331
|
+
return this.uploadToGPU(t.dataId), {
|
|
332
|
+
dtype: this.tensorMap.get(t.dataId).dtype,
|
|
333
|
+
shape: t.shape,
|
|
334
|
+
name: e.variableNames[n]
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
e.shaderKey = o(e, l, c) + (e.auxiliaryOutputs?.length ? `_outputs:${e.auxiliaryOutputs.map((e) => e.name).join(",")}_components:${e.outputComponent ?? 1}:${e.variableComponents?.join(",") ?? ""}` : "");
|
|
338
|
+
let u = i().getBool("WEBGPU_ENGINE_COMPILE_ONLY");
|
|
339
|
+
return e.shaderKey in this.pipelineCache || (this.pipelineCache[e.shaderKey] = h(this.device, e, l, c, u)), e.pipeline = this.pipelineCache[e.shaderKey], u || this.recordAndSubmit(e, c, t, s), c;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
export { A as t };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import t from "./webgpu_backend.js";
|
|
1
|
+
import { tt as e } from "./dist-JOPw9zTN.js";
|
|
2
|
+
import { t } from "./webgpu_backend-CzY9TzvA.js";
|
|
3
|
+
import { n } from "./device-CZPGtQBU.js";
|
|
3
4
|
// lib/patches/webgpu_base.ts
|
|
4
|
-
|
|
5
|
-
function r() {
|
|
6
|
-
return n;
|
|
7
|
-
}
|
|
8
|
-
function i(r) {
|
|
5
|
+
function r(r) {
|
|
9
6
|
e("webgpu", async () => {
|
|
10
7
|
let e = { powerPreference: r?.powerPreference ?? "high-performance" };
|
|
11
8
|
console.log("Using custom WebGPU backend with power preference:", e.powerPreference);
|
|
@@ -21,7 +18,7 @@ function i(r) {
|
|
|
21
18
|
maxComputeInvocationsPerWorkgroup: s.maxComputeInvocationsPerWorkgroup
|
|
22
19
|
};
|
|
23
20
|
let c = await i.requestDevice(a), l = "info" in i ? i.info : "requestAdapterInfo" in i ? await i.requestAdapterInfo() : void 0;
|
|
24
|
-
return n
|
|
21
|
+
return n(c), new t(c, l);
|
|
25
22
|
}, 3);
|
|
26
23
|
}
|
|
27
|
-
export { r as
|
|
24
|
+
export { r as registerWebGPUBackend };
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genai-fi/nanogpt",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "dist/
|
|
5
|
+
"main": "dist/nanogpt.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"exports": {
|
|
11
|
-
".":
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/main.d.ts",
|
|
13
|
+
"import": "./dist/nanogpt.js"
|
|
14
|
+
}
|
|
12
15
|
},
|
|
13
16
|
"repository": {
|
|
14
17
|
"url": "https://github.com/knicos/genai-nanogpt.git",
|
|
@@ -16,15 +19,16 @@
|
|
|
16
19
|
},
|
|
17
20
|
"scripts": {
|
|
18
21
|
"dev": "vite",
|
|
19
|
-
"build": "
|
|
22
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
20
23
|
"build:script": "tsc -p scripts/tsconfig.json",
|
|
21
24
|
"preview": "vite preview",
|
|
22
25
|
"lint": "eslint",
|
|
23
|
-
"test": "vitest
|
|
26
|
+
"test": "vitest",
|
|
24
27
|
"test:gl": "playwright test",
|
|
25
28
|
"ci:test": "vitest --coverage --reporter=junit --outputFile=junit.xml",
|
|
26
29
|
"coverage": "vitest run --coverage",
|
|
27
|
-
"postinstall": "patch-package"
|
|
30
|
+
"postinstall": "patch-package",
|
|
31
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"@eslint/js": "^10.0.1",
|
|
@@ -44,7 +48,6 @@
|
|
|
44
48
|
"typescript": "^6.0.3",
|
|
45
49
|
"typescript-eslint": "^8.61.1",
|
|
46
50
|
"vite": "^8.0.16",
|
|
47
|
-
"vite-plugin-dts": "^5.0.2",
|
|
48
51
|
"vitest": "^5.0.5",
|
|
49
52
|
"webgpu": "^0.4.0",
|
|
50
53
|
"yargs": "^18.0.0"
|
|
@@ -57,9 +60,9 @@
|
|
|
57
60
|
"jszip": "^3.10.1",
|
|
58
61
|
"papaparse": "^5.5.3",
|
|
59
62
|
"patch-package": "^8.0.1",
|
|
63
|
+
"pdfjs-dist": "^6.2.108",
|
|
60
64
|
"picomatch": "^4.0.3",
|
|
61
|
-
"uuid": "^14.0.0"
|
|
62
|
-
"pdfjs-dist": "^6.2.108"
|
|
65
|
+
"uuid": "^14.0.0"
|
|
63
66
|
},
|
|
64
67
|
"allowScripts": {
|
|
65
68
|
"webgpu@0.4.0": true,
|