@genai-fi/nanogpt 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +352 -14
- package/dist/Generator.js +69 -78
- package/dist/{RealDiv-D4EzDsC0.js → RealDiv-DgA3z9oO.js} +32 -206
- package/dist/Reshape-CF6odzV4.js +16 -0
- package/dist/Reshape-_kILl6tK.js +81 -0
- package/dist/TeachableLLM.js +28 -22
- package/dist/Trainer.d.ts +2 -0
- package/dist/Trainer.js +3 -2
- package/dist/{axis_util-TbGYJ208.js → axis_util-BvHEw88j.js} +7 -23
- package/dist/backend.d.ts +2 -1
- package/dist/backend.js +10 -4
- package/dist/backend_util-D-rUb2ty.js +474 -0
- package/dist/backend_webgpu-B0u2ndUn.js +547 -0
- package/dist/binary_op_util-pKXltfxI.js +192 -0
- package/dist/broadcast_to-CwF7XIeu.js +30 -0
- package/dist/checks/appendCache.js +2 -2
- package/dist/checks/attentionMask.js +3 -3
- package/dist/checks/check.d.ts +1 -1
- package/dist/checks/check.js +8 -8
- package/dist/checks/gelu.js +2 -2
- package/dist/checks/index.d.ts +2 -0
- package/dist/checks/index.js +7 -5
- package/dist/checks/matMulGelu.js +6 -6
- package/dist/checks/normRMS.js +7 -7
- package/dist/checks/normRMSGrad.js +3 -3
- package/dist/checks/packUnpack.d.ts +1 -0
- package/dist/checks/packUnpack.js +18 -0
- package/dist/checks/qkv.js +12 -27
- package/dist/checks/rope.js +2 -2
- package/dist/checks/weights.js +18 -16
- package/dist/complex-CSlYz-2T.js +13 -0
- package/dist/complex_util-Yc1A_gV1.js +55 -0
- package/dist/concat-BHlIJeyT.js +19 -0
- package/dist/concat_util-DcJk7YHS.js +22 -0
- package/dist/data/docx.js +1 -1
- package/dist/data/parquet.js +2 -2
- package/dist/data/pdf.js +1 -1
- package/dist/data/textLoader.js +1 -1
- package/dist/{dataset-DlZtKmBq.js → dataset-0xP8GjwI.js} +136 -236
- package/dist/dropout-C1pM3f11.js +99 -0
- package/dist/expand_dims-BPG4fwBP.js +13 -0
- package/dist/exports_initializers-xuidcwI4.js +7 -0
- package/dist/gather-DykLGqmW.js +10 -0
- package/dist/{gelu-Bp_-935b.js → gelu-CNLFZWea.js} +11 -10
- package/dist/{gpgpu_math-CDaYiyE_.js → gpgpu_math-DDVJCn6-.js} +90 -265
- package/dist/{index-C4L8Cm77.js → index-CieiGp4Y.js} +14 -14
- package/dist/index-CjOj7j-u.js +7308 -0
- package/dist/{index-Tf7vU29b.js → index-Cp39cXWe.js} +3 -10
- package/dist/{index-Dwqa6Zy2.js → index-DvYrXKkX.js} +2 -2
- package/dist/index-ZyQhjEPo.js +2157 -0
- package/dist/{jszip.min-CjP2V1VV.js → jszip.min-Bz5-11Bk.js} +56 -57
- package/dist/kernel_funcs_utils-Dg_-E44D.js +308 -0
- package/dist/layers/BaseLayer.d.ts +1 -0
- package/dist/layers/BaseLayer.js +7 -6
- package/dist/layers/CausalSelfAttention.d.ts +0 -1
- package/dist/layers/CausalSelfAttention.js +56 -55
- package/dist/layers/MLP.js +15 -16
- package/dist/layers/PositionEmbedding.js +5 -14
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.d.ts +2 -0
- package/dist/layers/RoPECache.js +22 -17
- package/dist/layers/TiedEmbedding.js +22 -17
- package/dist/layers/TransformerBlock.js +21 -20
- package/dist/loader/load.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +39 -33
- package/dist/loader/save.js +1 -1
- package/dist/log_sum_exp-DWI-76TI.js +41 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.js +63 -52
- package/dist/matMul16--R5hOwDG.js +77 -0
- package/dist/mat_mul-DeAh4uTH.js +12 -0
- package/dist/mod-Gt1rMB4n.js +12 -0
- package/dist/models/NanoGPTV1.js +40 -31
- package/dist/models/model.d.ts +2 -0
- package/dist/models/model.js +37 -29
- package/dist/{mulmat_packed_gpu-BT60jmzP.js → mulmat_packed_gpu-BMFhLwta.js} +1 -17
- package/dist/{non_max_suppression_impl-CsEgBuMA.js → non_max_suppression_impl-B2W7YjZB.js} +0 -32
- package/dist/ones-CAMiP4I2.js +15 -0
- package/dist/ops/adamAdjust.js +1 -1
- package/dist/ops/adamMoments.d.ts +1 -1
- package/dist/ops/adamMoments.js +4 -4
- package/dist/ops/add16.d.ts +2 -0
- package/dist/ops/add16.js +9 -0
- package/dist/ops/appendCache.js +16 -9
- package/dist/ops/attentionMask.js +4 -4
- package/dist/ops/concat16.d.ts +2 -0
- package/dist/ops/concat16.js +9 -0
- package/dist/ops/cpu/adamAdjust.js +14 -13
- package/dist/ops/cpu/adamMoments.js +10 -9
- package/dist/ops/cpu/appendCache.js +9 -8
- package/dist/ops/cpu/attentionMask.js +15 -14
- package/dist/ops/cpu/fusedSoftmax.js +13 -12
- package/dist/ops/cpu/gatherSub.js +9 -24
- package/dist/ops/cpu/gelu.js +13 -12
- package/dist/ops/cpu/matMul16.d.ts +1 -0
- package/dist/ops/cpu/matMul16.js +16 -0
- package/dist/ops/cpu/matMulGelu.js +18 -16
- package/dist/ops/cpu/matMulMul.js +8 -7
- package/dist/ops/cpu/mulDropout.js +4 -3
- package/dist/ops/cpu/normRMS.js +11 -10
- package/dist/ops/cpu/qkv.js +17 -13
- package/dist/ops/cpu/rope.js +23 -22
- package/dist/ops/cpu/scatterSub.js +16 -30
- package/dist/ops/dot16.d.ts +2 -0
- package/dist/ops/dot16.js +42 -0
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/add16.d.ts +1 -0
- package/dist/ops/grads/add16.js +27 -0
- package/dist/ops/grads/attentionMask.js +12 -19
- package/dist/ops/grads/gelu.js +4 -3
- package/dist/ops/grads/matMul16.d.ts +2 -0
- package/dist/ops/grads/matMul16.js +9 -0
- package/dist/ops/grads/matMulGelu.js +8 -7
- package/dist/ops/grads/normRMS.js +8 -7
- package/dist/ops/grads/{fusedSoftmax.d.ts → pack16.d.ts} +1 -1
- package/dist/ops/grads/pack16.js +7 -0
- package/dist/ops/grads/qkv.d.ts +3 -1
- package/dist/ops/grads/qkv.js +28 -22
- package/dist/ops/grads/rope.d.ts +2 -1
- package/dist/ops/grads/rope.js +6 -13
- package/dist/ops/grads/softmax16.d.ts +2 -0
- package/dist/ops/grads/softmax16.js +26 -0
- package/dist/ops/grads/unpack16.d.ts +2 -0
- package/dist/ops/grads/unpack16.js +6 -0
- package/dist/ops/grads/utils.d.ts +3 -0
- package/dist/ops/grads/utils.js +10 -0
- package/dist/ops/matMul16.d.ts +15 -0
- package/dist/ops/matMul16.js +13 -0
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mul16.d.ts +2 -0
- package/dist/ops/mul16.js +8 -0
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/pack16.d.ts +2 -0
- package/dist/ops/pack16.js +6 -0
- package/dist/ops/qkv.d.ts +1 -1
- package/dist/ops/qkv.js +8 -4
- package/dist/ops/reshape16.d.ts +2 -0
- package/dist/ops/reshape16.js +43 -0
- package/dist/ops/rope.d.ts +1 -1
- package/dist/ops/rope.js +8 -10
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/slice16.d.ts +2 -0
- package/dist/ops/slice16.js +9 -0
- package/dist/ops/softmax16.d.ts +2 -0
- package/dist/ops/softmax16.js +12 -0
- package/dist/ops/sub16.d.ts +2 -0
- package/dist/ops/sub16.js +8 -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 +41 -0
- package/dist/ops/unpack16.d.ts +2 -0
- package/dist/ops/unpack16.js +6 -0
- package/dist/ops/webgl/adamAdjust.js +3 -2
- package/dist/ops/webgl/adamMoments.js +2 -1
- package/dist/ops/webgl/appendCache.js +2 -1
- package/dist/ops/webgl/attentionMask.js +5 -4
- package/dist/ops/webgl/fusedSoftmax.js +6 -4
- package/dist/ops/webgl/gatherSub.js +7 -6
- package/dist/ops/webgl/gelu.js +3 -2
- package/dist/ops/webgl/log.js +12 -27
- package/dist/ops/webgl/matMul16.d.ts +1 -0
- package/dist/ops/webgl/matMul16.js +37 -0
- package/dist/ops/webgl/matMulGelu.js +17 -15
- package/dist/ops/webgl/matMulMul.js +13 -12
- package/dist/ops/webgl/mulDropout.js +9 -8
- package/dist/ops/webgl/normRMS.js +8 -7
- package/dist/ops/webgl/qkv.js +6 -5
- package/dist/ops/webgl/rope.js +11 -10
- package/dist/ops/webgl/scatterSub.js +6 -5
- package/dist/ops/webgpu/adamAdjust.js +12 -10
- package/dist/ops/webgpu/adamMoments.js +27 -22
- package/dist/ops/webgpu/add16.d.ts +1 -0
- package/dist/ops/webgpu/add16.js +14 -0
- package/dist/ops/webgpu/appendCache.js +64 -17
- package/dist/ops/webgpu/attentionMask.js +19 -62
- package/dist/ops/webgpu/attentionMask32_program.d.ts +19 -0
- package/dist/ops/webgpu/attentionMask32_program.js +54 -0
- package/dist/ops/webgpu/concat16.d.ts +19 -0
- package/dist/ops/webgpu/concat16.js +128 -0
- package/dist/ops/webgpu/gatherSub.js +9 -7
- package/dist/ops/webgpu/gelu.js +78 -31
- package/dist/ops/webgpu/index.js +12 -0
- package/dist/ops/webgpu/matMul16.d.ts +1 -0
- package/dist/ops/webgpu/matMul16.js +58 -0
- package/dist/ops/webgpu/matMul16_program.d.ts +42 -0
- package/dist/ops/webgpu/matMul16_program.js +336 -0
- package/dist/ops/webgpu/mul16.d.ts +1 -0
- package/dist/ops/webgpu/mul16.js +14 -0
- package/dist/ops/webgpu/normRMS.js +21 -40
- package/dist/ops/webgpu/normRMS16_program.d.ts +9 -0
- package/dist/ops/webgpu/normRMS16_program.js +24 -0
- package/dist/ops/webgpu/normRMS32_program.d.ts +9 -0
- package/dist/ops/webgpu/normRMS32_program.js +24 -0
- package/dist/ops/webgpu/normRMSGrad.js +113 -64
- package/dist/ops/webgpu/pack16.d.ts +1 -0
- package/dist/ops/webgpu/pack16.js +19 -0
- package/dist/ops/webgpu/pack16_program.d.ts +19 -0
- package/dist/ops/webgpu/pack16_program.js +92 -0
- package/dist/ops/webgpu/qkv.js +20 -55
- package/dist/ops/webgpu/rope.js +77 -22
- package/dist/ops/webgpu/scatterSub.js +9 -7
- package/dist/ops/webgpu/slice16.d.ts +7 -0
- package/dist/ops/webgpu/slice16.js +71 -0
- package/dist/{variable-Bm2OFwGI.js → ops/webgpu/softmax16.d.ts} +2 -8
- package/dist/ops/webgpu/softmax16.js +23 -0
- package/dist/ops/webgpu/softmax16_program.d.ts +13 -0
- package/dist/ops/webgpu/softmax16_program.js +73 -0
- package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +17 -0
- package/dist/ops/webgpu/softmax16_subgroup_program.js +75 -0
- package/dist/ops/webgpu/softmax16grad.d.ts +1 -0
- package/dist/ops/webgpu/softmax16grad.js +38 -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 +40 -0
- package/dist/ops/webgpu/transpose16.d.ts +1 -0
- package/dist/ops/webgpu/transpose16.js +35 -0
- package/dist/ops/webgpu/transpose16_program.d.ts +16 -0
- package/dist/ops/webgpu/transpose16_program.js +50 -0
- package/dist/ops/webgpu/transpose16_shared_program.d.ts +15 -0
- package/dist/ops/webgpu/transpose16_shared_program.js +71 -0
- package/dist/ops/webgpu/unpack16.d.ts +1 -0
- package/dist/ops/webgpu/unpack16.js +49 -0
- package/dist/ops/webgpu/utils/binary_op.d.ts +19 -0
- package/dist/ops/webgpu/utils/binary_op.js +79 -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 +32 -4
- package/dist/ops/webgpu/utils/reductions.js +236 -45
- package/dist/ops-CNI3TwqM.js +645 -0
- package/dist/pack16-CFUqumar.js +41 -0
- package/dist/{papaparse.min-C8l2Kvo1.js → papaparse.min-C0cScC2i.js} +2 -8
- package/dist/{parquet-C0Tlmv9c.js → parquet-BE8MU_ge.js} +201 -278
- package/dist/patches/PackedTensor.d.ts +12 -0
- package/dist/patches/PackedTensor.js +11 -0
- package/dist/patches/engine.d.ts +261 -0
- package/dist/patches/engine.js +10 -0
- package/dist/patches/tape.d.ts +12 -0
- package/dist/patches/tape.js +5 -0
- package/dist/patches/webgpu_backend.d.ts +18 -0
- package/dist/patches/webgpu_backend.js +57 -0
- package/dist/{tensor-CZr4dh61.js → patches/webgpu_base.d.ts} +5 -8
- package/dist/patches/webgpu_base.js +34 -0
- package/dist/patches/webgpu_program.d.ts +36 -0
- package/dist/patches/webgpu_program.js +401 -0
- package/dist/{pdf-kJD-f258.js → pdf-NIhmP3sq.js} +424 -428
- package/dist/random_width-DY6Kk2Dl.js +10051 -0
- package/dist/range-BMS52eQi.js +11 -0
- package/dist/reciprocal-CTmshQ9J.js +10 -0
- package/dist/{register_all_kernels-DIGpEwcf.js → register_all_kernels-Bwu1PTuU.js} +719 -9766
- package/dist/relu-yZ2-7WxU.js +10 -0
- package/dist/reshape-DevtBWtf.js +10 -0
- package/dist/rope-B5UUMsPi.js +32 -0
- package/dist/{scatter_nd_util-BQdz--Gn.js → scatter_nd_util-5EL-8VAQ.js} +1 -1
- package/dist/selu_util-D1w6yyTO.js +303 -0
- package/dist/{shared-DuP7ue-R.js → shared-BRksrJb3.js} +1 -17
- package/dist/shared-BuAXb4CI.js +2145 -0
- package/dist/sin-BGfy2HZo.js +16 -0
- package/dist/slice-D_gkkqZK.js +13 -0
- package/dist/slice_util-DtEldBfK.js +261 -0
- package/dist/softmax-ZHVebtR1.js +13 -0
- package/dist/split-DrfihRpZ.js +10 -0
- package/dist/squeeze-DZEpeblb.js +11 -0
- package/dist/stack-yOIAalTq.js +13 -0
- package/dist/sum-_fzj5ZTB.js +12 -0
- package/dist/tensor-DdQUJZlz.js +909 -0
- package/dist/tensor-f35l8Odg.js +8 -0
- package/dist/tensor1d-CeZuc-Rv.js +12 -0
- package/dist/tensor2d-G4Ys2GxX.js +15 -0
- package/dist/tensor4d-B8roDgtc.js +15 -0
- package/dist/tensor_util-DV-FP5Q3.js +523 -0
- package/dist/tfjs_backend-kNyO5L2d.js +653 -0
- package/dist/tile-BzyEiF-F.js +13 -0
- package/dist/tokeniser/CharTokeniser.js +1 -1
- package/dist/tokeniser/bpe.js +1 -1
- package/dist/training/Adam.d.ts +2 -1
- package/dist/training/Adam.js +12 -28
- package/dist/training/AdamExt.d.ts +1 -0
- package/dist/training/AdamExt.js +2 -2
- package/dist/training/DatasetBuilder.js +3 -20
- package/dist/training/FullTrainer.js +55 -48
- package/dist/training/Trainer.d.ts +11 -6
- package/dist/training/Trainer.js +51 -39
- package/dist/training/sparseCrossEntropy.js +3 -3
- package/dist/transpose-DKELTqhe.js +38 -0
- package/dist/utilities/arrayClose.js +7 -7
- package/dist/utilities/dummy.js +35 -27
- package/dist/utilities/multinomialCPU.js +2 -2
- package/dist/utilities/packed.d.ts +7 -0
- package/dist/utilities/packed.js +716 -0
- package/dist/utilities/performance.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/sentences.d.ts +5 -0
- package/dist/utilities/sentences.js +41 -0
- package/dist/utilities/weights.js +2 -2
- package/dist/variable-Bhn5bHYv.js +7 -0
- package/dist/{webgpu_program-DkQJOJSd.js → webgpu_program-Cigz-7RF.js} +15 -44
- package/dist/webgpu_util-BBCnKm2X.js +65 -0
- package/dist/zeros-2gldETuK.js +14 -0
- package/package.json +4 -3
- package/dist/Reshape-Bowtk9BP.js +0 -127
- package/dist/Reshape-DUqYftGC.js +0 -30
- package/dist/backend_util-CJIiDoV1.js +0 -749
- package/dist/broadcast_to-DzlNweb8.js +0 -44
- package/dist/concat-B912vBbo.js +0 -33
- package/dist/dropout-C-csYCLj.js +0 -193
- package/dist/exports_initializers-B8iZMgQ0.js +0 -16
- package/dist/gather-Dnpgw-YQ.js +0 -25
- package/dist/index-BzFyqcy-.js +0 -4457
- package/dist/index-C1rx_Ajs.js +0 -12076
- package/dist/kernel_funcs_utils-DKLK0Mg3.js +0 -466
- package/dist/log_sum_exp-DO6z8tSE.js +0 -103
- package/dist/mat_mul-DzjTFx-u.js +0 -27
- package/dist/mod-Dobti4j4.js +0 -27
- package/dist/ones-tIJeHlq-.js +0 -29
- package/dist/ops/fusedSoftmax.d.ts +0 -2
- package/dist/ops/fusedSoftmax.js +0 -10
- package/dist/ops/grads/fusedSoftmax.js +0 -22
- package/dist/ops-LuCMAnmM.js +0 -1525
- package/dist/random_width-CXVRloNK.js +0 -13670
- package/dist/range-CWcz7xFA.js +0 -26
- package/dist/reciprocal-C4rNcM-S.js +0 -25
- package/dist/relu-BjCh_SYb.js +0 -25
- package/dist/reshape-CnIwVG1c.js +0 -25
- package/dist/selu_util-OtRzVwW5.js +0 -719
- package/dist/shared-DmRsFyaJ.js +0 -3134
- package/dist/sin-gpDNRxE0.js +0 -47
- package/dist/slice-d0Vo9XTN.js +0 -28
- package/dist/softmax-D7Jj3p_P.js +0 -28
- package/dist/split-DK2k5eHf.js +0 -25
- package/dist/stack-DFatutCx.js +0 -27
- package/dist/sum-CJ0ULhmt.js +0 -27
- package/dist/tensor1d-vML0r3q6.js +0 -27
- package/dist/tensor2d-D76QGjF3.js +0 -30
- package/dist/tensor4d-Df1WlVDY.js +0 -30
- package/dist/webgpu_util-pLEV9tks.js +0 -80
- package/dist/zeros-Bj5rMYA7.js +0 -52
package/dist/ops/webgl/log.js
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { u as
|
|
3
|
-
import { y as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
* =============================================================================
|
|
19
|
-
*/
|
|
20
|
-
const a = N + `
|
|
1
|
+
import "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { u as r, l as e } from "../../kernel_funcs_utils-Dg_-E44D.js";
|
|
3
|
+
import { y as s } from "../../shared-BRksrJb3.js";
|
|
4
|
+
import { r as N, L as l } from "../../tensor_util-DV-FP5Q3.js";
|
|
5
|
+
const t = e + `
|
|
21
6
|
return x < 0.0 ? NAN : log(x);
|
|
22
|
-
`,
|
|
7
|
+
`, a = `
|
|
23
8
|
vec4 result = log(x);
|
|
24
9
|
bvec4 isNaN = isnan(x);
|
|
25
10
|
result.r = isNaN.r ? x.r : (x.r < 0.0 ? NAN : result.r);
|
|
@@ -27,13 +12,13 @@ const a = N + `
|
|
|
27
12
|
result.b = isNaN.b ? x.b : (x.b < 0.0 ? NAN : result.b);
|
|
28
13
|
result.a = isNaN.a ? x.a : (x.a < 0.0 ? NAN : result.a);
|
|
29
14
|
return result;
|
|
30
|
-
`, n =
|
|
31
|
-
opSnippet:
|
|
32
|
-
packedOpSnippet:
|
|
33
|
-
cpuKernelImpl:
|
|
15
|
+
`, n = r({
|
|
16
|
+
opSnippet: t,
|
|
17
|
+
packedOpSnippet: a,
|
|
18
|
+
cpuKernelImpl: s
|
|
34
19
|
}), o = {
|
|
35
|
-
kernelName:
|
|
20
|
+
kernelName: l,
|
|
36
21
|
backendName: "webgl",
|
|
37
22
|
kernelFunc: n
|
|
38
23
|
};
|
|
39
|
-
|
|
24
|
+
N(o);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isPackedTensor as k } from "../../utilities/packed.js";
|
|
2
|
+
import { m as M, b as m } from "../../index-ZyQhjEPo.js";
|
|
3
|
+
import { matMulMul as g } from "../matMulMul.js";
|
|
4
|
+
import { matMulGelu as N } from "../matMulGelu.js";
|
|
5
|
+
import { r as U } from "../../tensor_util-DV-FP5Q3.js";
|
|
6
|
+
import { m as G } from "../../mat_mul-DeAh4uTH.js";
|
|
7
|
+
import { r as w } from "../../reshape-DevtBWtf.js";
|
|
8
|
+
import { t as h } from "../../transpose-DKELTqhe.js";
|
|
9
|
+
function P(p) {
|
|
10
|
+
const { A: r, B: o } = p.inputs, { transposeA: l, transposeB: c, scale: u, activation: A, scaleA: f, scaleB: d, forceOutputShape: t, perm: n } = p.attrs, B = !k(r), v = !k(o);
|
|
11
|
+
if (B && v) {
|
|
12
|
+
const a = f !== void 0 ? M(r, m(f)) : r, i = d !== void 0 ? M(o, m(d)) : o;
|
|
13
|
+
let e;
|
|
14
|
+
if (u !== void 0 ? e = g(a, i, m(u), l, c) : A === "gelu" ? e = N(a, i) : e = G(a, i, l, c), n)
|
|
15
|
+
if (t) {
|
|
16
|
+
const s = w(e, t);
|
|
17
|
+
e.dispose();
|
|
18
|
+
const b = h(s, n);
|
|
19
|
+
return s.dispose(), b;
|
|
20
|
+
} else {
|
|
21
|
+
const s = h(e, n);
|
|
22
|
+
return e.dispose(), s;
|
|
23
|
+
}
|
|
24
|
+
else if (t) {
|
|
25
|
+
const s = w(e, t);
|
|
26
|
+
return e.dispose(), s;
|
|
27
|
+
} else
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
throw new Error("Not implemented: matMul16 with packed inputs");
|
|
31
|
+
}
|
|
32
|
+
const C = {
|
|
33
|
+
kernelName: "MatMul16",
|
|
34
|
+
backendName: "webgl",
|
|
35
|
+
kernelFunc: P
|
|
36
|
+
};
|
|
37
|
+
U(C);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as f } from "../../Reshape-
|
|
3
|
-
import { M as
|
|
4
|
-
import {
|
|
1
|
+
import { t as R, e as C, j as N } from "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { r as f } from "../../Reshape-_kILl6tK.js";
|
|
3
|
+
import { M as H } from "../../mulmat_packed_gpu-BMFhLwta.js";
|
|
4
|
+
import { r as E, u as O } from "../../tensor_util-DV-FP5Q3.js";
|
|
5
|
+
import { m as $ } from "../../mat_mul-DeAh4uTH.js";
|
|
6
|
+
import { s as A, a as U } from "../../tensor-DdQUJZlz.js";
|
|
5
7
|
const M = 0.7978845608028654, g = 0.044715, j = `
|
|
6
8
|
vec4 x3 = x * x * x;
|
|
7
9
|
vec4 inner = x + ${g} * x3;
|
|
@@ -29,25 +31,25 @@ const M = 0.7978845608028654, g = 0.044715, j = `
|
|
|
29
31
|
vec4 du_dx = ${M} * (1.0 + 3.0 * ${g} * a2);
|
|
30
32
|
vec4 dgelu = 0.5 * (1.0 + t) + 0.5 * a * sech2 * du_dx;
|
|
31
33
|
return dgelu * b;
|
|
32
|
-
`,
|
|
34
|
+
`, se = 1e3;
|
|
33
35
|
function _({
|
|
34
36
|
a: e,
|
|
35
37
|
b: n,
|
|
36
38
|
transposeA: s,
|
|
37
39
|
transposeB: t,
|
|
38
40
|
backend: a,
|
|
39
|
-
activationSnippet:
|
|
41
|
+
activationSnippet: i,
|
|
40
42
|
multiplier: o
|
|
41
43
|
}) {
|
|
42
|
-
const r = e.shape.length,
|
|
43
|
-
|
|
44
|
-
u ===
|
|
45
|
-
() => `Error in matMul: inner shapes (${u}) and (${
|
|
44
|
+
const r = e.shape.length, c = n.shape.length, u = s ? e.shape[r - 2] : e.shape[r - 1], p = t ? n.shape[c - 1] : n.shape[c - 2], h = s ? e.shape[r - 1] : e.shape[r - 2], l = t ? n.shape[c - 2] : n.shape[c - 1], w = e.shape.slice(0, -2), K = n.shape.slice(0, -2), m = A(w), d = A(K), T = N(e.shape.slice(0, -2), n.shape.slice(0, -2)).concat([h, l]);
|
|
45
|
+
U(
|
|
46
|
+
u === p,
|
|
47
|
+
() => `Error in matMul: inner shapes (${u}) and (${p}) of Tensors with shapes ${e.shape} and ${n.shape} and transposeA=${s} and transposeB=${t} must match.`
|
|
46
48
|
);
|
|
47
|
-
const v = s ? [
|
|
49
|
+
const v = s ? [m, u, h] : [m, h, u], x = t ? [d, l, p] : [d, p, l], S = f({ inputs: { x: e }, backend: a, attrs: { shape: v } }), b = f({ inputs: { x: n }, backend: a, attrs: { shape: x } }), D = [S, b], y = Math.max(m, d), L = i, B = O(e.dtype, n.dtype), F = new H(
|
|
48
50
|
v,
|
|
49
51
|
x,
|
|
50
|
-
[y,
|
|
52
|
+
[y, h, l],
|
|
51
53
|
s,
|
|
52
54
|
t,
|
|
53
55
|
!1,
|
|
@@ -84,7 +86,7 @@ E(W);
|
|
|
84
86
|
function J(e) {
|
|
85
87
|
const { dy: n, x: s, kernel: t } = e.inputs, a = e.backend;
|
|
86
88
|
return R(() => {
|
|
87
|
-
const
|
|
89
|
+
const i = C().makeTensorFromTensorInfo(
|
|
88
90
|
_({
|
|
89
91
|
a: s,
|
|
90
92
|
b: t,
|
|
@@ -94,7 +96,7 @@ function J(e) {
|
|
|
94
96
|
activationSnippet: q,
|
|
95
97
|
multiplier: n
|
|
96
98
|
})
|
|
97
|
-
), o =
|
|
99
|
+
), o = $(i, t, !1, !0), r = $(s, i, !0, !1);
|
|
98
100
|
return [o, r];
|
|
99
101
|
});
|
|
100
102
|
}
|
|
@@ -105,7 +107,7 @@ const Q = {
|
|
|
105
107
|
};
|
|
106
108
|
E(Q);
|
|
107
109
|
export {
|
|
108
|
-
|
|
110
|
+
se as MATMUL_SHARED_DIM_THRESHOLD,
|
|
109
111
|
_ as batchMatMulGeluImpl,
|
|
110
112
|
z as batchMatMulKernel
|
|
111
113
|
};
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { batchMatMulGeluImpl as
|
|
3
|
-
|
|
1
|
+
import "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { batchMatMulGeluImpl as u } from "./matMulGelu.js";
|
|
3
|
+
import { r as c } from "../../tensor_util-DV-FP5Q3.js";
|
|
4
|
+
const p = `
|
|
4
5
|
return a * b;
|
|
5
6
|
`;
|
|
6
|
-
function
|
|
7
|
-
const { inputs: n, backend: o, attrs: a } = r, { x: t, kernel: e, y:
|
|
7
|
+
function M(r) {
|
|
8
|
+
const { inputs: n, backend: o, attrs: a } = r, { x: t, kernel: e, y: i } = n, { transposeA: l, transposeB: s } = a;
|
|
8
9
|
if (t === void 0 || e === void 0)
|
|
9
10
|
throw new Error("BatchMatMul requires two input tensors.");
|
|
10
|
-
return
|
|
11
|
+
return u({
|
|
11
12
|
a: t,
|
|
12
13
|
b: e,
|
|
13
|
-
transposeA:
|
|
14
|
+
transposeA: l,
|
|
14
15
|
transposeB: s,
|
|
15
16
|
backend: o,
|
|
16
|
-
activationSnippet:
|
|
17
|
-
multiplier:
|
|
17
|
+
activationSnippet: p,
|
|
18
|
+
multiplier: i
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
const m = {
|
|
21
22
|
kernelName: "MatMulMul",
|
|
22
23
|
backendName: "webgl",
|
|
23
|
-
kernelFunc:
|
|
24
|
+
kernelFunc: M
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
+
c(m);
|
|
26
27
|
export {
|
|
27
|
-
|
|
28
|
+
M as batchMatMulKernel
|
|
28
29
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { r as m } from "../../tensor_util-DV-FP5Q3.js";
|
|
2
3
|
class f {
|
|
3
4
|
variableNames = ["a", "b"];
|
|
4
5
|
outputShape;
|
|
@@ -7,8 +8,8 @@ class f {
|
|
|
7
8
|
{ name: "dropoutRate", type: "float" },
|
|
8
9
|
{ name: "seed", type: "float" }
|
|
9
10
|
];
|
|
10
|
-
constructor(
|
|
11
|
-
this.outputShape = [
|
|
11
|
+
constructor(r, t, o) {
|
|
12
|
+
this.outputShape = [r, t, o, o], this.userCode = `
|
|
12
13
|
float random(ivec4 coords) {
|
|
13
14
|
float x = float(coords.x * 4096 + coords.y * 256 + coords.z * 16 + coords.w);
|
|
14
15
|
return fract(sin(seed + x) * 43758.5453123);
|
|
@@ -26,16 +27,16 @@ class f {
|
|
|
26
27
|
`;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
-
const { inputs:
|
|
30
|
+
function i(e) {
|
|
31
|
+
const { inputs: r, attrs: t } = e, { a: o, b: s } = r, { dropoutRate: a, seed: c } = t, n = e.backend, d = o.shape[0], u = o.shape[2], p = o.shape[1], l = new f(d, p, u);
|
|
31
32
|
return n.runWebGLProgram(l, [o, s], "float32", [
|
|
32
33
|
[a ?? 0],
|
|
33
34
|
[c ?? Math.random() * 1e4]
|
|
34
35
|
]);
|
|
35
36
|
}
|
|
36
|
-
const
|
|
37
|
+
const b = {
|
|
37
38
|
kernelName: "MulDropout",
|
|
38
39
|
backendName: "webgl",
|
|
39
|
-
kernelFunc:
|
|
40
|
+
kernelFunc: i
|
|
40
41
|
};
|
|
41
|
-
m(
|
|
42
|
+
m(b);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { e as G } from "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { r as g } from "../../tensor_util-DV-FP5Q3.js";
|
|
3
|
+
import { s as x } from "../../sum-_fzj5ZTB.js";
|
|
3
4
|
class y {
|
|
4
5
|
variableNames = ["x", "meanSquare", "gamma"];
|
|
5
6
|
outputShape;
|
|
@@ -28,7 +29,7 @@ const C = {
|
|
|
28
29
|
backendName: "webgl",
|
|
29
30
|
kernelFunc: v
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
+
g(C);
|
|
32
33
|
class b {
|
|
33
34
|
variableNames = ["x", "meanSquare", "dyGamma", "dyXMean"];
|
|
34
35
|
outputShape;
|
|
@@ -73,14 +74,14 @@ function M(t) {
|
|
|
73
74
|
l.dispose();
|
|
74
75
|
const f = new b(n, m, u), S = r.runWebGLProgram(f, [e, d, s, i], "float32");
|
|
75
76
|
s.dispose(), i.dispose();
|
|
76
|
-
const h = new N(n, m, u),
|
|
77
|
+
const h = new N(n, m, u), p = r.runWebGLProgram(h, [e, d, a], "float32");
|
|
77
78
|
d.dispose();
|
|
78
|
-
const q = x(G().makeTensorFromTensorInfo(
|
|
79
|
-
return r.disposeIntermediateTensorInfo(
|
|
79
|
+
const q = x(G().makeTensorFromTensorInfo(p), [0, 1]);
|
|
80
|
+
return r.disposeIntermediateTensorInfo(p), [S, q];
|
|
80
81
|
}
|
|
81
82
|
const k = {
|
|
82
83
|
kernelName: "RMSNormGrad",
|
|
83
84
|
backendName: "webgl",
|
|
84
85
|
kernelFunc: M
|
|
85
86
|
};
|
|
86
|
-
|
|
87
|
+
g(k);
|
package/dist/ops/webgl/qkv.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { r as i } from "../../tensor_util-DV-FP5Q3.js";
|
|
3
|
+
class m {
|
|
3
4
|
variableNames = ["x", "kernel"];
|
|
4
5
|
outputShape;
|
|
5
6
|
userCode;
|
|
@@ -30,8 +31,8 @@ class l {
|
|
|
30
31
|
`;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
function
|
|
34
|
-
const { x: e, kernel: t } = r.inputs, { heads: s } = r.attrs, o = r.backend, n = e.shape[0], c = e.shape[1], u = e.shape[2], a = new
|
|
34
|
+
function l(r) {
|
|
35
|
+
const { x: e, kernel: t } = r.inputs, { heads: s } = r.attrs, o = r.backend, n = e.shape[0], c = e.shape[1], u = e.shape[2], a = new m(n, s, c, u);
|
|
35
36
|
return [
|
|
36
37
|
o.runWebGLProgram(a, [e, t], "float32", [[0]]),
|
|
37
38
|
o.runWebGLProgram(a, [e, t], "float32", [[1]]),
|
|
@@ -41,6 +42,6 @@ function m(r) {
|
|
|
41
42
|
const d = {
|
|
42
43
|
kernelName: "QKV",
|
|
43
44
|
backendName: "webgl",
|
|
44
|
-
kernelFunc:
|
|
45
|
+
kernelFunc: l
|
|
45
46
|
};
|
|
46
47
|
i(d);
|
package/dist/ops/webgl/rope.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { r as h } from "../../tensor_util-DV-FP5Q3.js";
|
|
3
|
+
class g {
|
|
3
4
|
variableNames = ["x", "sin", "cos"];
|
|
4
5
|
outputShape;
|
|
5
6
|
userCode;
|
|
6
7
|
// enableShapeUniforms = true;
|
|
7
8
|
customUniforms = [{ name: "pastLen", type: "int" }];
|
|
8
|
-
constructor(t,
|
|
9
|
-
this.outputShape = [t,
|
|
9
|
+
constructor(t, s, e, n) {
|
|
10
|
+
this.outputShape = [t, s, e, n], this.userCode = `
|
|
10
11
|
void main() {
|
|
11
12
|
ivec4 coords = getOutputCoords(); // [b, h, t, d]
|
|
12
13
|
int b = coords.x;
|
|
@@ -14,7 +15,7 @@ class l {
|
|
|
14
15
|
int t = coords.z;
|
|
15
16
|
int d = coords.w;
|
|
16
17
|
|
|
17
|
-
int rotaryDim = ${
|
|
18
|
+
int rotaryDim = ${n};
|
|
18
19
|
|
|
19
20
|
float outVal = 0.0;
|
|
20
21
|
|
|
@@ -44,13 +45,13 @@ class l {
|
|
|
44
45
|
`;
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
function
|
|
48
|
-
const { x: t,
|
|
49
|
-
return
|
|
48
|
+
function m(o) {
|
|
49
|
+
const { x: t } = o.inputs, { pastLen: s, ropeCache: e, negSin: n } = o.attrs, a = n ? e.getNegSin() : e.getSin(), r = e.getCos(), i = o.backend, d = t.shape[0], c = t.shape[1], p = t.shape[2], u = t.shape[3], l = new g(d, c, p, u);
|
|
50
|
+
return i.runWebGLProgram(l, [t, a, r], "float32", [[s]]);
|
|
50
51
|
}
|
|
51
52
|
const f = {
|
|
52
53
|
kernelName: "Rope",
|
|
53
54
|
backendName: "webgl",
|
|
54
|
-
kernelFunc:
|
|
55
|
+
kernelFunc: m
|
|
55
56
|
};
|
|
56
|
-
|
|
57
|
+
h(f);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { r as i } from "../../tensor_util-DV-FP5Q3.js";
|
|
2
3
|
class u {
|
|
3
4
|
variableNames = ["labels", "softmaxProbs", "dy"];
|
|
4
5
|
outputShape;
|
|
5
6
|
userCode;
|
|
6
|
-
constructor(
|
|
7
|
-
this.outputShape = [
|
|
7
|
+
constructor(t, e) {
|
|
8
|
+
this.outputShape = [t, e], this.userCode = `
|
|
8
9
|
void main() {
|
|
9
10
|
ivec2 coords = getOutputCoords();
|
|
10
11
|
int index = int(getLabels(coords.x));
|
|
@@ -16,8 +17,8 @@ class u {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
function d(o) {
|
|
19
|
-
const { logits:
|
|
20
|
-
return s.runWebGLProgram(c, [
|
|
20
|
+
const { logits: t, labels: e, dy: r } = o.inputs, s = o.backend, n = e.shape[0], a = t.shape[1], c = new u(n, a);
|
|
21
|
+
return s.runWebGLProgram(c, [e, t, r], "float32");
|
|
21
22
|
}
|
|
22
23
|
const b = {
|
|
23
24
|
kernelName: "EfficientScatterSub",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as d, c as l } from "../../webgpu_util-
|
|
3
|
-
import
|
|
1
|
+
import { e as p } from "../../webgpu_program-Cigz-7RF.js";
|
|
2
|
+
import { f as d, c as l } from "../../webgpu_util-BBCnKm2X.js";
|
|
3
|
+
import "../../index-ZyQhjEPo.js";
|
|
4
|
+
import { j as f } from "../../tensor-DdQUJZlz.js";
|
|
5
|
+
import { r as c } from "../../tensor_util-DV-FP5Q3.js";
|
|
4
6
|
class h {
|
|
5
7
|
variableNames = ["moments", "value"];
|
|
6
8
|
outputShape;
|
|
@@ -36,19 +38,19 @@ class h {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
function v(t) {
|
|
39
|
-
const { moments: e, value: a } = t.inputs, { beta1: n, beta2:
|
|
40
|
-
|
|
41
|
-
const
|
|
41
|
+
const { moments: e, value: a } = t.inputs, { beta1: n, beta2: o, learningRate: s, epsilon: i } = t.attrs, r = t.backend;
|
|
42
|
+
f(e.shape, [...a.shape, 2], "Error in AdamAdjust: ");
|
|
43
|
+
const m = new h(a.shape), u = [
|
|
42
44
|
{ type: "float32", data: [1 / n] },
|
|
43
|
-
{ type: "float32", data: [1 /
|
|
44
|
-
{ type: "float32", data: [
|
|
45
|
+
{ type: "float32", data: [1 / o] },
|
|
46
|
+
{ type: "float32", data: [s] },
|
|
45
47
|
{ type: "float32", data: [i] }
|
|
46
48
|
];
|
|
47
|
-
return r.runWebGPUProgram(
|
|
49
|
+
return r.runWebGPUProgram(m, [e, a], "float32", u);
|
|
48
50
|
}
|
|
49
51
|
const b = {
|
|
50
52
|
kernelName: "AdamAdjust",
|
|
51
53
|
backendName: "webgpu",
|
|
52
54
|
kernelFunc: v
|
|
53
55
|
};
|
|
54
|
-
|
|
56
|
+
c(b);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as u, c as
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { e as p } from "../../webgpu_program-Cigz-7RF.js";
|
|
2
|
+
import { f as u, c as d } from "../../webgpu_util-BBCnKm2X.js";
|
|
3
|
+
import "../../index-ZyQhjEPo.js";
|
|
4
|
+
import { j as f } from "../../tensor-DdQUJZlz.js";
|
|
5
|
+
import { r as c } from "../../tensor_util-DV-FP5Q3.js";
|
|
6
|
+
class l {
|
|
5
7
|
variableNames = ["moments", "gradient"];
|
|
6
8
|
outputShape;
|
|
7
9
|
shaderKey = "AdamMoments";
|
|
@@ -9,11 +11,11 @@ class h {
|
|
|
9
11
|
dispatch;
|
|
10
12
|
workgroupSize = [64, 1, 1];
|
|
11
13
|
size = !0;
|
|
12
|
-
uniforms = "beta1: f32, beta2: f32";
|
|
14
|
+
uniforms = "beta1: f32, beta2: f32, lossScaling: f32";
|
|
13
15
|
outputComponent = 2;
|
|
14
16
|
variableComponents = [2, 1];
|
|
15
|
-
constructor(
|
|
16
|
-
this.outputShape =
|
|
17
|
+
constructor(t) {
|
|
18
|
+
this.outputShape = t, this.dispatchLayout = u(this.outputShape.slice(0, -1)), this.dispatch = d(
|
|
17
19
|
this.dispatchLayout,
|
|
18
20
|
this.outputShape.slice(0, -1),
|
|
19
21
|
this.workgroupSize,
|
|
@@ -22,12 +24,12 @@ class h {
|
|
|
22
24
|
}
|
|
23
25
|
getUserCode() {
|
|
24
26
|
return `
|
|
25
|
-
${
|
|
27
|
+
${p("index")} {
|
|
26
28
|
if (index < uniforms.size) {
|
|
27
29
|
let m: vec2<f32> = moments[index];
|
|
28
30
|
|
|
29
31
|
// Add gradient clipping here
|
|
30
|
-
let g: f32 = clamp(gradient[index], -1.0, 1.0);
|
|
32
|
+
let g: f32 = clamp(gradient[index] * uniforms.lossScaling, -1.0, 1.0);
|
|
31
33
|
|
|
32
34
|
let newM1 = fma(m.x, uniforms.beta1, g * (1.0 - uniforms.beta1));
|
|
33
35
|
let newM2 = fma(m.y, uniforms.beta2, g * g * (1.0 - uniforms.beta2));
|
|
@@ -38,21 +40,24 @@ class h {
|
|
|
38
40
|
`;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
|
-
function
|
|
42
|
-
const { moments:
|
|
43
|
-
if (
|
|
44
|
-
throw new Error(`
|
|
45
|
-
if (n < 0 || n >= 1)
|
|
46
|
-
throw new Error(`Invalid
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
function h(e) {
|
|
44
|
+
const { moments: t, gradient: a } = e.inputs, { beta1: n, beta2: o, lossScaling: r } = e.attrs, s = e.backend;
|
|
45
|
+
if (a.dtype !== "float32")
|
|
46
|
+
throw new Error(`Gradient must be float32, but got ${a.dtype}`);
|
|
47
|
+
if (f(t.shape, [...a.shape, 2], "Error in AdamMoments: "), n < 0 || n >= 1)
|
|
48
|
+
throw new Error(`Invalid beta1 value: ${n}. Must be in the range [0, 1).`);
|
|
49
|
+
if (o < 0 || o >= 1)
|
|
50
|
+
throw new Error(`Invalid beta2 value: ${o}. Must be in the range [0, 1).`);
|
|
51
|
+
const i = new l(t.shape), m = [
|
|
52
|
+
{ type: "float32", data: [n] },
|
|
53
|
+
{ type: "float32", data: [o] },
|
|
54
|
+
{ type: "float32", data: [1 / r] }
|
|
50
55
|
];
|
|
51
|
-
return
|
|
56
|
+
return s.runWebGPUProgram(i, [t, a], "float32", m);
|
|
52
57
|
}
|
|
53
|
-
const
|
|
58
|
+
const g = {
|
|
54
59
|
kernelName: "AdamMoments",
|
|
55
60
|
backendName: "webgpu",
|
|
56
|
-
kernelFunc:
|
|
61
|
+
kernelFunc: h
|
|
57
62
|
};
|
|
58
|
-
|
|
63
|
+
c(g);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "../../index-ZyQhjEPo.js";
|
|
2
|
+
import { BinaryOpProgram as p } from "./utils/binary_op.js";
|
|
3
|
+
import { B as m } from "../../binary_op_util-pKXltfxI.js";
|
|
4
|
+
import { r as c } from "../../tensor_util-DV-FP5Q3.js";
|
|
5
|
+
function i(r) {
|
|
6
|
+
const { a: e, b: n } = r.inputs, a = r.backend, t = new p(m.ADD, e.shape, n.shape), o = a.runWebGPUProgram(t, [e, n], "int32");
|
|
7
|
+
return o.packed = !0, o;
|
|
8
|
+
}
|
|
9
|
+
const s = {
|
|
10
|
+
kernelName: "Add16",
|
|
11
|
+
backendName: "webgpu",
|
|
12
|
+
kernelFunc: i
|
|
13
|
+
};
|
|
14
|
+
c(s);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { f as
|
|
4
|
-
|
|
1
|
+
import { isPackedTensor as S } from "../../utilities/packed.js";
|
|
2
|
+
import { e as d } from "../../webgpu_program-Cigz-7RF.js";
|
|
3
|
+
import { f as u, c as m } from "../../webgpu_util-BBCnKm2X.js";
|
|
4
|
+
import "../../index-ZyQhjEPo.js";
|
|
5
|
+
import { j as g } from "../../tensor-DdQUJZlz.js";
|
|
6
|
+
import { r as x } from "../../tensor_util-DV-FP5Q3.js";
|
|
7
|
+
class b {
|
|
5
8
|
variableNames = ["cache", "item"];
|
|
6
9
|
outputShape;
|
|
7
10
|
shaderKey = "AppendCache";
|
|
@@ -10,14 +13,14 @@ class g {
|
|
|
10
13
|
workgroupSize = [64, 1, 1];
|
|
11
14
|
size = !0;
|
|
12
15
|
uniforms = "cacheT: i32";
|
|
13
|
-
constructor(e, t, s,
|
|
14
|
-
const
|
|
15
|
-
this.shaderKey = `AppendCache_${
|
|
16
|
+
constructor(e, t, s, o, i) {
|
|
17
|
+
const a = Math.min(s + 1, i);
|
|
18
|
+
this.shaderKey = `AppendCache_${a}`, this.outputShape = [e, t, a, o], this.dispatchLayout = u(this.outputShape), this.dispatch = m(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
16
19
|
}
|
|
17
20
|
getUserCode() {
|
|
18
21
|
const e = this.outputShape[2];
|
|
19
22
|
return `
|
|
20
|
-
${
|
|
23
|
+
${d("index")} {
|
|
21
24
|
if (index < uniforms.size) {
|
|
22
25
|
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
23
26
|
let b = coords[0];
|
|
@@ -45,16 +48,60 @@ class g {
|
|
|
45
48
|
`;
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
class C {
|
|
52
|
+
variableNames = ["cache", "item"];
|
|
53
|
+
outputShape;
|
|
54
|
+
shaderKey = "AppendCache";
|
|
55
|
+
dispatchLayout;
|
|
56
|
+
dispatch;
|
|
57
|
+
workgroupSize = [64, 1, 1];
|
|
58
|
+
size = !0;
|
|
59
|
+
uniforms = "cacheT: i32";
|
|
60
|
+
constructor(e, t, s, o, i) {
|
|
61
|
+
const a = Math.min(s + 1, i);
|
|
62
|
+
this.shaderKey = `AppendCache_${a}`, this.outputShape = [e, t, a, o], this.dispatchLayout = u(this.outputShape), this.dispatch = m(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
63
|
+
}
|
|
64
|
+
getUserCode() {
|
|
65
|
+
const e = this.outputShape[2];
|
|
66
|
+
return `
|
|
67
|
+
${d("index")} {
|
|
68
|
+
if (index < uniforms.size) {
|
|
69
|
+
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
70
|
+
let b = coords[0];
|
|
71
|
+
let h = coords[1];
|
|
72
|
+
let t = coords[2];
|
|
73
|
+
let d = coords[3];
|
|
74
|
+
|
|
75
|
+
let itemT = 1;
|
|
76
|
+
let maxSize = ${e};
|
|
77
|
+
let totalT = uniforms.cacheT + itemT;
|
|
78
|
+
let start = select(0, 1, totalT >= maxSize);
|
|
79
|
+
|
|
80
|
+
let srcT = t + start;
|
|
81
|
+
var val: i32 = 0i;
|
|
82
|
+
if (srcT < uniforms.cacheT) {
|
|
83
|
+
val = cache[getIndexFromCoords4D(vec4<i32>(b, h, srcT, d), uniforms.cacheShape)];
|
|
84
|
+
}
|
|
85
|
+
if (srcT == uniforms.cacheT) {
|
|
86
|
+
val = item[getIndexFromCoords4D(vec4<i32>(b, h, 0, d), uniforms.itemShape)];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
result[index] = val;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function v(r) {
|
|
96
|
+
const { cache: e, item: t } = r.inputs, { maxSize: s, pastLen: o } = r.attrs, i = r.backend, a = S(e), c = e.shape[0], n = e.shape[2], h = e.shape[1];
|
|
97
|
+
if (g(t.shape, [c, h, 1, t.shape[3]], "Error in AppendCache: "), o < 0 || o > s)
|
|
98
|
+
throw new Error(`Invalid pastLen value: ${o}. Must be in the range [0, ${s}].`);
|
|
99
|
+
const l = a ? new C(c, h, n, t.shape[3], s) : new b(c, h, n, t.shape[3], s), f = [{ type: "int32", data: [o] }], T = a ? "int32" : e.dtype, p = i.runWebGPUProgram(l, [e, t], T, f);
|
|
100
|
+
return p.packed = a, p;
|
|
54
101
|
}
|
|
55
|
-
const
|
|
102
|
+
const z = {
|
|
56
103
|
kernelName: "AppendCache",
|
|
57
104
|
backendName: "webgpu",
|
|
58
|
-
kernelFunc:
|
|
105
|
+
kernelFunc: v
|
|
59
106
|
};
|
|
60
|
-
|
|
107
|
+
x(z);
|