@genai-fi/nanogpt 1.5.0 → 1.6.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/{DatasetBuilder-DU1G1OKX.js → DatasetBuilder-DRDW8tcM.js} +85 -86
- package/dist/Generator-BcR_14Cj.js +316 -0
- package/dist/{RealDiv-CSnvtN2E.js → RealDiv-Cl8k3YTx.js} +54 -62
- package/dist/{Reshape-BlylqwWy.js → Reshape-CKxKPKqi.js} +9 -12
- package/dist/Reshape-H5zZRgr9.js +16 -0
- package/dist/RoPECache-dYscFINl.js +722 -0
- package/dist/TeachableLLM.js +29 -34
- package/dist/api/beamer.js +5 -6
- package/dist/api/responses.js +11 -12
- package/dist/api/training.js +12 -14
- package/dist/axis_util-rF9RnwKE.js +37 -0
- package/dist/backend.js +5 -6
- package/dist/{backend_util-DAV0I34P.js → backend_util-Cpp0Gwlp.js} +180 -185
- package/dist/{binary_op_util-CrYk9LXL.js → binary_op_util-WY9YIl0q.js} +3 -7
- package/dist/broadcast_to-CGvLNiQ0.js +20 -0
- package/dist/checks/appendCache.js +7 -7
- package/dist/checks/attentionMask.js +9 -8
- package/dist/checks/check.js +1 -2
- package/dist/checks/gelu.js +6 -6
- package/dist/checks/index.js +24 -25
- package/dist/checks/matMulGelu.js +7 -7
- package/dist/checks/normRMS.js +14 -12
- package/dist/checks/normRMSGrad.js +9 -8
- package/dist/checks/packUnpack.js +7 -7
- package/dist/checks/qkv.js +1 -34
- package/dist/checks/rope.js +6 -6
- package/dist/checks/weights.js +1 -2
- package/dist/clip_by_value-D-UX9am5.js +13 -0
- package/dist/complex-Cl904TqN.js +13 -0
- package/dist/{complex_util-CkazZsaH.js → complex_util-BBlPAm-s.js} +1 -2
- package/dist/concat-Oip5acVY.js +14 -0
- package/dist/{concat_util-CWzvQQlK.js → concat_util-CY45Hf4F.js} +2 -3
- package/dist/data/docx.js +3 -4
- package/dist/data/pdf.js +11 -14
- package/dist/data/stream.js +1 -2
- package/dist/data/textLoader.js +16 -15
- package/dist/data-CV_i_H6B.js +11 -0
- package/dist/data.js +5 -12
- package/dist/dist-CMMLi-qO.js +2675 -0
- package/dist/{dist-BGVm64AY.js → dist-DeVH1nGn.js} +1465 -1573
- package/dist/{dist-CwK5S7Ls.js → dist-DyL7qSLJ.js} +2664 -2400
- package/dist/dropout16-CA31Ud5a.js +20 -0
- package/dist/dropout_util-SiFMbFXz.js +22 -0
- package/dist/{eventemitter3-D_qV3Lof.js → eventemitter3-wmfmOP_f.js} +2 -3
- package/dist/expand_dims-Dh3Fulyn.js +10 -0
- package/dist/floor-BwjmUb7X.js +8 -0
- package/dist/gather-B5Z1RFt5.js +14 -0
- package/dist/gatherSub-CRUfUzBa.js +22 -0
- package/dist/gelu-Xx9-ohH9.js +25 -0
- package/dist/{gpgpu_math-20tPK8LM.js → gpgpu_math-48m8q3jI.js} +265 -286
- package/dist/inference/Beamer.js +34 -27
- package/dist/inference/Generator.js +1 -273
- package/dist/inference/tokenisePrompt.js +5 -4
- package/dist/inference/types.d.ts +6 -0
- package/dist/inference/utilities.js +1 -2
- package/dist/{jszip.min-DKa1Rjyn.js → jszip.min-Btv48m44.js} +68 -64
- package/dist/{kernel_funcs_utils-ql8Y8qPn.js → kernel_funcs_utils-BYRpSfV_.js} +39 -42
- package/dist/layers/BaseLayer.js +9 -10
- package/dist/layers/GQA.js +45 -44
- package/dist/layers/HeadLayer.js +13 -13
- package/dist/layers/LoRA.js +17 -20
- package/dist/layers/MHA.d.ts +2 -2
- package/dist/layers/MHA.js +46 -45
- package/dist/layers/MLP.js +22 -21
- package/dist/layers/PositionEmbedding.js +14 -13
- package/dist/layers/RMSNorm.js +14 -13
- package/dist/layers/RoPECache.js +1 -338
- package/dist/layers/TiedEmbedding.js +15 -14
- package/dist/layers/TransformerBlock.d.ts +3 -9
- package/dist/layers/TransformerBlock.js +29 -30
- package/dist/layers/WeightStore.js +4 -5
- package/dist/layers-CFqEip3s.js +13 -0
- package/dist/layers.js +3 -11
- package/dist/loader/load.js +27 -24
- package/dist/loader/loadHF.js +3 -3
- package/dist/loader/loadTransformers.js +5 -6
- package/dist/loader/loadZipMeta.js +1 -2
- package/dist/loader/newZipLoad.js +1 -2
- package/dist/loader/oldZipLoad.js +8 -9
- package/dist/loader/save.js +15 -16
- package/dist/main.js +3281 -3463
- package/dist/{matMul16-CO1QhsRt.js → matMul16-tE26fnhf.js} +29 -27
- package/dist/{matMulGelu-CBoqTZM7.js → matMulGelu-ASUWlKqu.js} +33 -33
- package/dist/mat_mul-R9_DWmIT.js +16 -0
- package/dist/models/Llama.js +48 -49
- package/dist/models/NanoGPTV1.js +53 -54
- package/dist/models/NanoGPTV2.js +48 -49
- package/dist/models/Qwen3.js +48 -49
- package/dist/models/config.js +3 -8
- package/dist/models/factory.js +7 -8
- package/dist/models/model.d.ts +5 -7
- package/dist/models/model.js +1 -2
- package/dist/models-DyBpJJwM.js +13 -0
- package/dist/models.js +6 -14
- package/dist/mul16-C7sqgqik.js +41 -0
- package/dist/non_max_suppression_impl-B0H318rb.js +72 -0
- package/dist/not_equal-Bu3O8rh_.js +67 -0
- package/dist/one_hot-TEMPumJj.js +14 -0
- package/dist/ones-DpPXWa6A.js +13 -0
- package/dist/ops/adamAdjust.js +2 -3
- package/dist/ops/adamMoments.js +2 -3
- package/dist/ops/add16.js +2 -3
- package/dist/ops/appendCache.js +9 -8
- package/dist/ops/attentionMask.d.ts +1 -1
- package/dist/ops/attentionMask.js +8 -5
- package/dist/ops/concat16.js +5 -5
- package/dist/ops/cpu/adamAdjust.js +7 -8
- package/dist/ops/cpu/adamMoments.js +5 -5
- package/dist/ops/cpu/appendCache.js +3 -3
- package/dist/ops/cpu/attentionMask.js +12 -8
- package/dist/ops/cpu/fusedSoftmax.js +3 -3
- package/dist/ops/cpu/gatherSub.js +1 -12
- package/dist/ops/cpu/gelu.js +12 -13
- package/dist/ops/cpu/matMul16.js +7 -7
- package/dist/ops/cpu/matMulGelu.js +21 -18
- package/dist/ops/cpu/matMulMul.js +8 -9
- package/dist/ops/cpu/mulDropout.js +8 -9
- package/dist/ops/cpu/normRMS.js +12 -13
- package/dist/ops/cpu/qkv.js +14 -13
- package/dist/ops/cpu/rope.js +11 -8
- package/dist/ops/cpu/scatterSub.js +1 -12
- package/dist/ops/dot16.js +16 -17
- package/dist/ops/dropout.js +9 -8
- package/dist/ops/dropout16.js +1 -22
- package/dist/ops/gatherSub.js +3 -4
- package/dist/ops/gelu.js +1 -2
- package/dist/ops/globalNorm.js +10 -10
- package/dist/ops/grads/add16.js +16 -17
- package/dist/ops/grads/attentionMask.js +6 -7
- package/dist/ops/grads/dropout16.js +1 -1
- package/dist/ops/grads/gelu.js +1 -2
- package/dist/ops/grads/matMul16.js +1 -2
- package/dist/ops/grads/matMulGelu.js +6 -7
- package/dist/ops/grads/mul16.js +1 -1
- package/dist/ops/grads/normRMS.js +8 -9
- package/dist/ops/grads/pack16.js +1 -2
- package/dist/ops/grads/qkv.js +10 -10
- package/dist/ops/grads/rope.js +1 -2
- package/dist/ops/grads/silu.js +1 -2
- package/dist/ops/grads/softmax16.js +6 -7
- package/dist/ops/grads/unpack16.js +1 -2
- package/dist/ops/grads/utils.js +1 -2
- package/dist/ops/matMul16.d.ts +1 -1
- package/dist/ops/matMul16.js +1 -2
- package/dist/ops/matMulGelu.js +3 -4
- package/dist/ops/matMulMul.js +2 -3
- package/dist/ops/mul16.js +1 -43
- package/dist/ops/mulDrop.js +2 -3
- package/dist/ops/normRMS.js +2 -3
- package/dist/ops/pack16.js +1 -2
- package/dist/ops/qkv.js +2 -3
- package/dist/ops/reshape16.js +11 -11
- package/dist/ops/rope.js +1 -2
- package/dist/ops/scatterSub.js +3 -4
- package/dist/ops/silu.js +1 -2
- package/dist/ops/slice16.js +5 -5
- package/dist/ops/softmax16.js +3 -4
- package/dist/ops/sub16.js +3 -4
- package/dist/ops/sum16.js +3 -3
- package/dist/ops/transpose16.js +16 -15
- package/dist/ops/unpack16.js +1 -2
- package/dist/ops/webgl/adamAdjust.js +8 -9
- package/dist/ops/webgl/adamMoments.js +2 -3
- package/dist/ops/webgl/appendCache.js +2 -3
- package/dist/ops/webgl/attentionMask.js +2 -3
- package/dist/ops/webgl/dropout16.js +2 -3
- package/dist/ops/webgl/fusedSoftmax.js +13 -13
- package/dist/ops/webgl/gatherSub.js +2 -3
- package/dist/ops/webgl/gelu.js +11 -12
- package/dist/ops/webgl/log.js +10 -10
- package/dist/ops/webgl/matMul16.js +31 -24
- package/dist/ops/webgl/matMulGelu.js +1 -2
- package/dist/ops/webgl/matMulMul.js +3 -4
- package/dist/ops/webgl/mulDropout.js +2 -3
- package/dist/ops/webgl/normRMS.js +11 -10
- package/dist/ops/webgl/qkv.js +2 -3
- package/dist/ops/webgl/rope.js +4 -5
- package/dist/ops/webgl/scatterSub.js +2 -3
- package/dist/ops/webgpu/adamAdjust.js +13 -14
- package/dist/ops/webgpu/adamMoments.js +13 -14
- package/dist/ops/webgpu/add16.js +3 -4
- package/dist/ops/webgpu/appendCache.js +20 -21
- package/dist/ops/webgpu/attentionMask.js +18 -19
- package/dist/ops/webgpu/attentionMask32_program.js +7 -8
- package/dist/ops/webgpu/clipScale.js +11 -12
- package/dist/ops/webgpu/concat16.js +17 -18
- package/dist/ops/webgpu/dropout16.js +6 -7
- package/dist/ops/webgpu/gatherSub.js +11 -12
- package/dist/ops/webgpu/gelu.js +10 -11
- package/dist/ops/webgpu/index.js +17 -17
- package/dist/ops/webgpu/matMul16.js +74 -63
- package/dist/ops/webgpu/matMul16_program.d.ts +2 -1
- package/dist/ops/webgpu/matMul16_program.js +29 -21
- package/dist/ops/webgpu/mul16.js +3 -4
- package/dist/ops/webgpu/norm2.js +9 -10
- package/dist/ops/webgpu/normRMS.js +9 -10
- package/dist/ops/webgpu/normRMS16_program.js +1 -2
- package/dist/ops/webgpu/normRMS32_program.js +1 -2
- package/dist/ops/webgpu/normRMSGrad.js +30 -30
- package/dist/ops/webgpu/pack16.js +2 -3
- package/dist/ops/webgpu/pack16_program.js +3 -4
- package/dist/ops/webgpu/qkv.js +10 -11
- package/dist/ops/webgpu/rope.js +26 -27
- package/dist/ops/webgpu/scatterSub.js +12 -13
- package/dist/ops/webgpu/silu.js +10 -11
- package/dist/ops/webgpu/slice16.js +17 -18
- package/dist/ops/webgpu/softmax16.js +9 -9
- package/dist/ops/webgpu/softmax16_program.js +9 -10
- package/dist/ops/webgpu/softmax16_subgroup_program.js +11 -12
- package/dist/ops/webgpu/softmax16grad.js +8 -9
- package/dist/ops/webgpu/sub16.js +3 -4
- package/dist/ops/webgpu/sum16.js +16 -15
- package/dist/ops/webgpu/transpose16.js +13 -12
- package/dist/ops/webgpu/transpose16_program.js +3 -4
- package/dist/ops/webgpu/transpose16_shared_program.js +17 -18
- package/dist/ops/webgpu/unpack16.js +8 -9
- package/dist/ops/webgpu/utils/binary_op.js +20 -21
- package/dist/ops/webgpu/utils/deviceInfo.js +1 -2
- package/dist/ops/webgpu/utils/reductions.js +21 -20
- package/dist/ops-Be5ACU5R.js +13 -0
- package/dist/ops-C1UpdEYM.js +509 -0
- package/dist/{pack16-BhuXNUS7.js → pack16-BHO4t1-M.js} +14 -17
- package/dist/pad-Dy-1IP3A.js +13 -0
- package/dist/patches/webgpu_backend.js +18 -19
- package/dist/patches/webgpu_base.js +2 -3
- package/dist/patches/webgpu_program.js +21 -22
- package/dist/{pdf-Bzuk68Vy.js → pdf-CbnQ75VG.js} +380 -701
- package/dist/{picomatch-BO4HbNfo.js → picomatch--TW6gyBJ.js} +229 -291
- package/dist/qkv-BQfNPucX.js +42 -0
- package/dist/rand_util-_vCY93Uw.js +44 -0
- package/dist/random_normal-DUIT8kyC.js +11 -0
- package/dist/range-CYvQC3fW.js +13 -0
- package/dist/relu-C4XULT8A.js +8 -0
- package/dist/reshape-DJb1jgMt.js +8 -0
- package/dist/resize_nearest_neighbor-DAqcTYUe.js +188 -0
- package/dist/{chunk-CWhphoD1.js → rolldown-runtime-CwxnZyOB.js} +4 -5
- package/dist/{rope-BPu_uooz.js → rope-JjBVufF_.js} +6 -8
- package/dist/scatterSub-BOnqk-uY.js +27 -0
- package/dist/scatter_nd_util-BepMCpLY.js +34 -0
- package/dist/seedrandom-SHEGFK6H.js +282 -0
- package/dist/selu_util-DeOTf-sc.js +27 -0
- package/dist/shared-BIDMUBCs.js +1864 -0
- package/dist/{shared-CfTzpULd.js → shared-CX_iPI5K.js} +2 -3
- package/dist/silu-DsAE2cJ5.js +23 -0
- package/dist/slice-Dlb1FlzG.js +13 -0
- package/dist/{slice_util-Dve4TkDn.js → slice_util-BVgPRoij.js} +3 -4
- package/dist/softmax-Dpav_dWw.js +10 -0
- package/dist/split-DYnT8chz.js +11 -0
- package/dist/squeeze-B3XYGAlg.js +9 -0
- package/dist/stack-Dbbt9mIk.js +10 -0
- package/dist/step-DA-5DNu9.js +348 -0
- package/dist/{stream-BpAwcvHz.js → stream-BBe2apn4.js} +68 -88
- package/dist/sum-C8qNbFNp.js +13 -0
- package/dist/tensor-ALxWZfmz.js +7 -0
- package/dist/tensor1d-BHgkkhTE.js +9 -0
- package/dist/tensor2d-ARItvqVn.js +10 -0
- package/dist/tensor4d-D1zRBipJ.js +10 -0
- package/dist/tfjs_backend-CsXOum0h.js +685 -0
- package/dist/tile-DfyQ0KX-.js +10 -0
- package/dist/tokenise-DbS2Ea-T.js +14 -0
- package/dist/tokenise.js +6 -15
- package/dist/tokeniser/BaseTokeniser.js +5 -9
- package/dist/tokeniser/CharTokeniser.js +1 -2
- package/dist/tokeniser/bpe.js +19 -20
- package/dist/topk-BrU2pkrR.js +19 -0
- package/dist/training/AdamW.js +35 -31
- package/dist/training/BasicTrainer.js +56 -56
- package/dist/training/DatasetBuilder.js +1 -2
- package/dist/training/Evaluator.js +4 -4
- package/dist/training/LRScheduler.js +1 -2
- package/dist/training/PreTrainer.js +7 -8
- package/dist/training/SFTTrainer.js +7 -8
- package/dist/training/configure.js +16 -15
- package/dist/training/factory.js +1 -2
- package/dist/training/loss.js +1 -2
- package/dist/training/orthoGrad.js +2 -3
- package/dist/training/prepareData.js +18 -17
- package/dist/training/sparseCrossEntropy.js +38 -32
- package/dist/training/tasks/TokenStore.js +21 -22
- package/dist/training/tasks/tokenStream.js +1 -2
- package/dist/training/validateOptions.js +1 -2
- package/dist/training/validation.js +1 -2
- package/dist/transpose-BC-M_OoT.js +34 -0
- package/dist/unsorted_segment_sum-BelC7R-q.js +408 -0
- package/dist/utilities/arrayClose.js +5 -4
- package/dist/utilities/arrayShape.js +1 -2
- package/dist/utilities/datasetID.js +1 -2
- package/dist/utilities/dummy.js +15 -15
- package/dist/utilities/float16.js +10 -10
- package/dist/utilities/maxHeap.js +1 -2
- package/dist/utilities/multinomialCPU.d.ts +1 -2
- package/dist/utilities/multinomialCPU.js +6 -8
- package/dist/utilities/packed.js +2 -3
- package/dist/utilities/parameters.js +3 -4
- package/dist/utilities/performance.js +2 -3
- package/dist/utilities/profile.js +3 -4
- package/dist/utilities/random.js +1 -2
- package/dist/utilities/safetensors.js +14 -14
- package/dist/utilities/sentences.js +16 -13
- package/dist/utilities/tokenParse.js +1 -2
- package/dist/utilities/tokens.js +5 -6
- package/dist/utilities/topP.d.ts +1 -0
- package/dist/utilities/topP.js +20 -13
- package/dist/utilities/waitForModel.js +1 -2
- package/dist/utilities/weights.js +4 -4
- package/dist/utilities/yielder.js +1 -2
- package/dist/{v4-BK7K-jy_.js → v4-YCkfo8OR.js} +4 -7
- package/dist/{webgpu-IAn9VotJ.js → webgpu-BHX-uBym.js} +156 -163
- package/dist/{webgpu_program-B0PokuRJ.js → webgpu_program-DvkFqRlR.js} +28 -29
- package/dist/{webgpu_util-DfODg6XI.js → webgpu_util-5QTyovaf.js} +2 -3
- package/dist/zeros-hxKGkRfl.js +12 -0
- package/package.json +3 -3
- package/dist/Reshape-CwxdaU8n.js +0 -17
- package/dist/dist-Da20xy8E.js +0 -6375
- package/dist/gelu-B6637MKa.js +0 -27
- package/dist/selu_util-B_AFEfoz.js +0 -24
- package/dist/shared-24EoeHJl.js +0 -1314
- package/dist/silu-B6bvCgJ7.js +0 -25
- package/dist/tfjs_backend-h5weiy1O.js +0 -614
package/dist/ops/transpose16.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forceFloat as
|
|
1
|
+
import { H as e, bt as t, xt as n } from "../dist-CMMLi-qO.js";
|
|
2
|
+
import { forceFloat as r, forcePacked as i } from "./grads/utils.js";
|
|
3
|
+
import { t as a } from "../transpose-BC-M_OoT.js";
|
|
4
|
+
import { c as o } from "../axis_util-rF9RnwKE.js";
|
|
3
5
|
import { isPackedTensor as s } from "../utilities/packed.js";
|
|
4
|
-
|
|
6
|
+
// lib/ops/transpose16.ts
|
|
5
7
|
var c = {
|
|
6
8
|
kernelName: "Transpose16",
|
|
7
|
-
gradFunc: (e, t,
|
|
9
|
+
gradFunc: (e, t, n) => {
|
|
8
10
|
if (Array.isArray(e)) throw Error("Transpose16 gradient does not support multiple outputs.");
|
|
9
|
-
let { perm:
|
|
10
|
-
return { x: () => u(e,
|
|
11
|
+
let { perm: r } = n, i = o(r);
|
|
12
|
+
return { x: () => u(e, i) };
|
|
11
13
|
}
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
t(c);
|
|
14
16
|
function l(e) {
|
|
15
|
-
let { inputs: t, attrs: n } = e, { x:
|
|
16
|
-
if (l && c[c.length - 1] !==
|
|
17
|
-
return l ?
|
|
17
|
+
let { inputs: t, attrs: n } = e, { x: o } = t, { perm: c } = n, l = s(o);
|
|
18
|
+
if (l && c[c.length - 1] !== o.shape.length - 1) throw Error("Transpose16 currently only supports the last axis being unchanged.");
|
|
19
|
+
return l ? i(a(r(o), c)) : a(o, c);
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
n({
|
|
20
22
|
kernelName: "Transpose16",
|
|
21
23
|
backendName: "webgl",
|
|
22
24
|
kernelFunc: l
|
|
23
|
-
}),
|
|
25
|
+
}), n({
|
|
24
26
|
kernelName: "Transpose16",
|
|
25
27
|
backendName: "cpu",
|
|
26
28
|
kernelFunc: l
|
|
27
29
|
});
|
|
28
|
-
function u(
|
|
29
|
-
return
|
|
30
|
+
function u(t, n) {
|
|
31
|
+
return n ??= t.shape.map((e, t) => t).reverse(), e().runKernel("Transpose16", { x: t }, { perm: n });
|
|
30
32
|
}
|
|
31
|
-
//#endregion
|
|
32
33
|
export { u as transpose16, c as transpose16GradConfig };
|
package/dist/ops/unpack16.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { e as unpack16 };
|
|
1
|
+
export { r as unpack16 } from "../pack16-BHO4t1-M.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t } from "../../
|
|
3
|
-
|
|
1
|
+
import { t as e } from "../../Reshape-CKxKPKqi.js";
|
|
2
|
+
import { xt as t } from "../../dist-CMMLi-qO.js";
|
|
3
|
+
// lib/ops/webgl/adamAdjust.ts
|
|
4
4
|
var n = class {
|
|
5
5
|
variableNames = ["moments", "value"];
|
|
6
6
|
outputShape;
|
|
@@ -49,12 +49,12 @@ var n = class {
|
|
|
49
49
|
`;
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
function r(
|
|
53
|
-
let { moments: r, value: i } =
|
|
52
|
+
function r(t) {
|
|
53
|
+
let { moments: r, value: i } = t.inputs, { beta1: a, beta2: o, learningRate: s, epsilon: c, weightDecay: l } = t.attrs, u = t.backend, d = e({
|
|
54
54
|
inputs: { x: r },
|
|
55
55
|
backend: u,
|
|
56
56
|
attrs: { shape: [-1] }
|
|
57
|
-
}), f =
|
|
57
|
+
}), f = e({
|
|
58
58
|
inputs: { x: i },
|
|
59
59
|
backend: u,
|
|
60
60
|
attrs: { shape: [-1] }
|
|
@@ -67,16 +67,15 @@ function r(e) {
|
|
|
67
67
|
l > 0 && m.push([l]);
|
|
68
68
|
let h = u.runWebGLProgram(p, [d, f], "float32", m);
|
|
69
69
|
u.disposeIntermediateTensorInfo(d), u.disposeIntermediateTensorInfo(f);
|
|
70
|
-
let g =
|
|
70
|
+
let g = e({
|
|
71
71
|
inputs: { x: h },
|
|
72
72
|
backend: u,
|
|
73
73
|
attrs: { shape: i.shape }
|
|
74
74
|
});
|
|
75
75
|
return u.disposeIntermediateTensorInfo(h), g;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
t({
|
|
78
78
|
kernelName: "AdamAdjust",
|
|
79
79
|
backendName: "webgl",
|
|
80
80
|
kernelFunc: r
|
|
81
81
|
});
|
|
82
|
-
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/adamMoments.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = ["moments", "gradient"];
|
|
5
5
|
outputShape;
|
|
@@ -41,4 +41,3 @@ e({
|
|
|
41
41
|
backendName: "webgl",
|
|
42
42
|
kernelFunc: n
|
|
43
43
|
});
|
|
44
|
-
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/appendCache.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = ["cache", "item"];
|
|
5
5
|
outputShape;
|
|
@@ -50,4 +50,3 @@ e({
|
|
|
50
50
|
backendName: "webgl",
|
|
51
51
|
kernelFunc: n
|
|
52
52
|
});
|
|
53
|
-
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/attentionMask.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = ["q", "k"];
|
|
5
5
|
outputShape;
|
|
@@ -61,4 +61,3 @@ e({
|
|
|
61
61
|
backendName: "webgl",
|
|
62
62
|
kernelFunc: n
|
|
63
63
|
});
|
|
64
|
-
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/dropout16.ts
|
|
3
3
|
function t(e) {
|
|
4
4
|
let { x: t } = e.inputs;
|
|
5
5
|
return t;
|
|
@@ -9,4 +9,3 @@ e({
|
|
|
9
9
|
backendName: "webgl",
|
|
10
10
|
kernelFunc: t
|
|
11
11
|
});
|
|
12
|
-
//#endregion
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { a as e, r as t, t as n } from "../../RealDiv-Cl8k3YTx.js";
|
|
2
|
+
import { a as r } from "../../axis_util-rF9RnwKE.js";
|
|
3
|
+
import { t as i } from "../../Reshape-CKxKPKqi.js";
|
|
4
|
+
import { Ui as a, xt as o } from "../../dist-CMMLi-qO.js";
|
|
5
|
+
// lib/ops/webgl/fusedSoftmax.ts
|
|
5
6
|
var s = class {
|
|
6
7
|
variableNames = ["logits", "maxLogits"];
|
|
7
8
|
outputShape;
|
|
@@ -24,26 +25,26 @@ var s = class {
|
|
|
24
25
|
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
|
}
|
|
26
27
|
};
|
|
27
|
-
function l(
|
|
28
|
-
let { inputs: l, attrs: u } =
|
|
28
|
+
function l(o) {
|
|
29
|
+
let { inputs: l, attrs: u } = o, { logits: d } = l, { dim: f, dropoutRate: p, seed: m } = u, h = o.backend;
|
|
29
30
|
if (!d) throw Error("Error in softmax: input logits is null");
|
|
30
|
-
let g =
|
|
31
|
+
let g = a([f], d.shape), _ = t({
|
|
31
32
|
inputs: { x: d },
|
|
32
33
|
backend: h,
|
|
33
34
|
attrs: {
|
|
34
35
|
reductionIndices: g,
|
|
35
36
|
keepDims: !1
|
|
36
37
|
}
|
|
37
|
-
}), v =
|
|
38
|
+
}), v = r(_.shape, g), y = new s(d.shape), b = h.runWebGLProgram(y, [d, _], "float32");
|
|
38
39
|
h.disposeIntermediateTensorInfo(_);
|
|
39
|
-
let x =
|
|
40
|
+
let x = e({
|
|
40
41
|
inputs: { x: b },
|
|
41
42
|
backend: h,
|
|
42
43
|
attrs: {
|
|
43
44
|
axis: g,
|
|
44
45
|
keepDims: !1
|
|
45
46
|
}
|
|
46
|
-
}), S =
|
|
47
|
+
}), S = i({
|
|
47
48
|
inputs: { x },
|
|
48
49
|
backend: h,
|
|
49
50
|
attrs: { shape: v }
|
|
@@ -52,7 +53,7 @@ function l(e) {
|
|
|
52
53
|
let e = new c(d.shape), t = h.runWebGLProgram(e, [b, S], "float32", [[p], [m ?? Math.random() * 1e4]]);
|
|
53
54
|
return h.disposeIntermediateTensorInfo(b), h.disposeIntermediateTensorInfo(x), h.disposeIntermediateTensorInfo(S), t;
|
|
54
55
|
}
|
|
55
|
-
let C =
|
|
56
|
+
let C = n({
|
|
56
57
|
inputs: {
|
|
57
58
|
a: b,
|
|
58
59
|
b: S
|
|
@@ -61,10 +62,9 @@ function l(e) {
|
|
|
61
62
|
});
|
|
62
63
|
return h.disposeIntermediateTensorInfo(b), h.disposeIntermediateTensorInfo(x), h.disposeIntermediateTensorInfo(S), C;
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
o({
|
|
65
66
|
kernelName: "FusedSoftmax",
|
|
66
67
|
backendName: "webgl",
|
|
67
68
|
kernelFunc: l
|
|
68
69
|
});
|
|
69
|
-
//#endregion
|
|
70
70
|
export { l as softmax };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/gatherSub.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = [
|
|
5
5
|
"labels",
|
|
@@ -25,4 +25,3 @@ e({
|
|
|
25
25
|
backendName: "webgl",
|
|
26
26
|
kernelFunc: n
|
|
27
27
|
});
|
|
28
|
-
//#endregion
|
package/dist/ops/webgl/gelu.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as t, s as n } from "../../kernel_funcs_utils-
|
|
3
|
-
|
|
4
|
-
var r = .7978845608028654, i = .044715, a =
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { i as t, s as n } from "../../kernel_funcs_utils-BYRpSfV_.js";
|
|
3
|
+
// lib/ops/webgl/gelu.ts
|
|
4
|
+
var r = .7978845608028654, i = .044715, a = n + `
|
|
5
5
|
float x3 = x * x * x;
|
|
6
6
|
float inner = x + ${i} * x3;
|
|
7
7
|
inner = ${r} * inner;
|
|
@@ -9,13 +9,13 @@ var r = .7978845608028654, i = .044715, a = t({ opSnippet: n + `
|
|
|
9
9
|
inner = 0.5 * (1.0 + inner);
|
|
10
10
|
inner = x * inner;
|
|
11
11
|
return inner;
|
|
12
|
-
|
|
12
|
+
`, o = t({ opSnippet: a });
|
|
13
13
|
e({
|
|
14
14
|
kernelName: "Gelu",
|
|
15
15
|
backendName: "webgl",
|
|
16
|
-
kernelFunc:
|
|
16
|
+
kernelFunc: o
|
|
17
17
|
});
|
|
18
|
-
var
|
|
18
|
+
var s = class {
|
|
19
19
|
variableNames = ["dy", "x"];
|
|
20
20
|
outputShape;
|
|
21
21
|
userCode;
|
|
@@ -35,14 +35,13 @@ var o = class {
|
|
|
35
35
|
}`;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
function
|
|
39
|
-
let { dy: t, x: n } = e.inputs, r = e.backend, i = new
|
|
38
|
+
function c(e) {
|
|
39
|
+
let { dy: t, x: n } = e.inputs, r = e.backend, i = new s(n.shape);
|
|
40
40
|
return r.runWebGLProgram(i, [t, n], "float32");
|
|
41
41
|
}
|
|
42
42
|
e({
|
|
43
43
|
kernelName: "GeluGrad",
|
|
44
44
|
backendName: "webgl",
|
|
45
|
-
kernelFunc:
|
|
45
|
+
kernelFunc: c
|
|
46
46
|
});
|
|
47
|
-
|
|
48
|
-
export { a as gelu };
|
|
47
|
+
export { o as gelu };
|
package/dist/ops/webgl/log.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as t, t as n } from "../../kernel_funcs_utils-
|
|
3
|
-
import { y as r } from "../../shared-
|
|
4
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { i as t, t as n } from "../../kernel_funcs_utils-BYRpSfV_.js";
|
|
3
|
+
import { y as r } from "../../shared-CX_iPI5K.js";
|
|
4
|
+
// lib/ops/webgl/log.ts
|
|
5
|
+
var i = n + "\n return x < 0.0 ? NAN : log(x);\n", a = t({
|
|
6
|
+
opSnippet: i,
|
|
7
|
+
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",
|
|
8
|
+
cpuKernelImpl: r
|
|
9
|
+
});
|
|
5
10
|
e({
|
|
6
11
|
kernelName: "Log",
|
|
7
12
|
backendName: "webgl",
|
|
8
|
-
kernelFunc:
|
|
9
|
-
opSnippet: n + "\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: r
|
|
12
|
-
})
|
|
13
|
+
kernelFunc: a
|
|
13
14
|
});
|
|
14
|
-
//#endregion
|
|
@@ -1,41 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isPackedTensor as e } from "../../utilities/packed.js";
|
|
2
|
+
import { t } from "../../reshape-DJb1jgMt.js";
|
|
3
|
+
import { t as n } from "../../mat_mul-R9_DWmIT.js";
|
|
4
|
+
import { t as r } from "../../transpose-BC-M_OoT.js";
|
|
5
|
+
import { t as i } from "../../relu-C4XULT8A.js";
|
|
6
|
+
import { O as a, b as o, v as s, xt as c } from "../../dist-CMMLi-qO.js";
|
|
3
7
|
import { matMulMul as l } from "../matMulMul.js";
|
|
4
8
|
import { matMulGelu as u } from "../matMulGelu.js";
|
|
5
|
-
|
|
6
|
-
function d(
|
|
7
|
-
let { A: d, B: f } =
|
|
9
|
+
// lib/ops/webgl/matMul16.ts
|
|
10
|
+
function d(c) {
|
|
11
|
+
let { A: d, B: f } = c.inputs, { transposeA: p, transposeB: m, scale: h, activation: g, scaleA: _, scaleB: v, forceOutputShape: y, perm: b } = c.attrs, x = !e(d), S = !e(f);
|
|
8
12
|
if (x && S) {
|
|
9
|
-
let e = _ === void 0 ? d :
|
|
13
|
+
let e = _ === void 0 ? d : a(d, o(_)), c = v === void 0 ? f : a(f, o(v)), x;
|
|
10
14
|
if (g === "gelu") x = u(e, c);
|
|
11
15
|
else if (g === "relu2") {
|
|
12
|
-
let t =
|
|
13
|
-
t.dispose(), x =
|
|
16
|
+
let t = n(e, c, p, m), r = i(t);
|
|
17
|
+
t.dispose(), x = s(r), r.dispose();
|
|
14
18
|
} else if (g === "relu") {
|
|
15
|
-
if (x =
|
|
16
|
-
let e =
|
|
19
|
+
if (x = i(n(e, c, p, m)), h !== void 0) {
|
|
20
|
+
let e = a(x, o(h));
|
|
17
21
|
x.dispose(), x = e;
|
|
18
22
|
}
|
|
19
|
-
} else x = h === void 0 ?
|
|
20
|
-
if (b)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
} else x = h === void 0 ? n(e, c, p, m) : l(e, c, o(h), p, m);
|
|
24
|
+
if (b) {
|
|
25
|
+
if (y) {
|
|
26
|
+
let e = t(x, y);
|
|
27
|
+
x.dispose();
|
|
28
|
+
let n = r(e, b);
|
|
29
|
+
return e.dispose(), n;
|
|
30
|
+
}
|
|
31
|
+
{
|
|
32
|
+
let e = r(x, b);
|
|
33
|
+
return x.dispose(), e;
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
|
-
|
|
30
|
-
let e =
|
|
36
|
+
if (y) {
|
|
37
|
+
let e = t(x, y);
|
|
31
38
|
return x.dispose(), e;
|
|
32
|
-
}
|
|
39
|
+
}
|
|
40
|
+
return x;
|
|
33
41
|
}
|
|
34
42
|
throw Error("Not implemented: matMul16 with packed inputs");
|
|
35
43
|
}
|
|
36
|
-
|
|
44
|
+
c({
|
|
37
45
|
kernelName: "MatMul16",
|
|
38
46
|
backendName: "webgl",
|
|
39
47
|
kernelFunc: d
|
|
40
48
|
});
|
|
41
|
-
//#endregion
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { n as MATMUL_SHARED_DIM_THRESHOLD, e as batchMatMulGeluImpl, t as batchMatMulKernel };
|
|
1
|
+
export { t as MATMUL_SHARED_DIM_THRESHOLD, n as batchMatMulGeluImpl, r as batchMatMulKernel } from "../../matMulGelu-ASUWlKqu.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as t } from "../../matMulGelu-
|
|
3
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { n as t } from "../../matMulGelu-ASUWlKqu.js";
|
|
3
|
+
// lib/ops/webgl/matMulMul.ts
|
|
4
4
|
var n = "\n return a * b;\n";
|
|
5
5
|
function r(e) {
|
|
6
6
|
let { inputs: r, backend: i, attrs: a } = e, { x: o, kernel: s, y: c } = r, { transposeA: l, transposeB: u } = a;
|
|
@@ -20,5 +20,4 @@ e({
|
|
|
20
20
|
backendName: "webgl",
|
|
21
21
|
kernelFunc: r
|
|
22
22
|
});
|
|
23
|
-
//#endregion
|
|
24
23
|
export { r as batchMatMulKernel };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/mulDropout.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = ["a", "b"];
|
|
5
5
|
outputShape;
|
|
@@ -29,4 +29,3 @@ e({
|
|
|
29
29
|
backendName: "webgl",
|
|
30
30
|
kernelFunc: n
|
|
31
31
|
});
|
|
32
|
-
//#endregion
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { H as e, xt as t } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { t as n } from "../../sum-C8qNbFNp.js";
|
|
3
|
+
// lib/ops/webgl/normRMS.ts
|
|
3
4
|
var r = class {
|
|
4
5
|
variableNames = ["x", "meanSquare"];
|
|
5
6
|
outputShape;
|
|
@@ -40,7 +41,7 @@ var a = {
|
|
|
40
41
|
backendName: "webgl",
|
|
41
42
|
kernelFunc: i
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
t(a), t(o);
|
|
44
45
|
var s = class {
|
|
45
46
|
variableNames = [
|
|
46
47
|
"x",
|
|
@@ -84,8 +85,8 @@ var s = class {
|
|
|
84
85
|
], this.userCode = "\n void main() {\n ivec3 coords = getOutputCoords();\n float x = getXAtOutCoords();\n float meanSquare = getMeanSquare(coords.x, coords.y, 0) + 1e-8;\n float dy = getDyAtOutCoords();\n float invRms = inversesqrt(meanSquare);\n float dGamma = dy * (x * invRms);\n setOutput(dGamma);\n }\n ";
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
|
-
function l(
|
|
88
|
-
let { dy: r, x: i, gamma: a } =
|
|
88
|
+
function l(t) {
|
|
89
|
+
let { dy: r, x: i, gamma: a } = t.inputs, o = t.backend, l = i.shape[0], u = i.shape[1], d = i.shape[2], f = a ? r.mul(a) : r, p = f.mul(i), m = p.sum(-1, !0);
|
|
89
90
|
p.dispose();
|
|
90
91
|
let h = i.square(), g = h.mean(-1, !0);
|
|
91
92
|
h.dispose();
|
|
@@ -96,19 +97,19 @@ function l(e) {
|
|
|
96
97
|
m
|
|
97
98
|
], "float32");
|
|
98
99
|
if (a && f.dispose(), m.dispose(), a) {
|
|
99
|
-
let
|
|
100
|
+
let t = new c(l, u, d), a = o.runWebGLProgram(t, [
|
|
100
101
|
i,
|
|
101
102
|
g,
|
|
102
103
|
r
|
|
103
104
|
], "float32");
|
|
104
105
|
g.dispose();
|
|
105
|
-
let s = n(
|
|
106
|
+
let s = n(e().makeTensorFromTensorInfo(a), [0, 1]);
|
|
106
107
|
return o.disposeIntermediateTensorInfo(a), [v, s];
|
|
107
|
-
}
|
|
108
|
+
}
|
|
109
|
+
return g.dispose(), [v];
|
|
108
110
|
}
|
|
109
|
-
|
|
111
|
+
t({
|
|
110
112
|
kernelName: "RMSNormGrad",
|
|
111
113
|
backendName: "webgl",
|
|
112
114
|
kernelFunc: l
|
|
113
115
|
});
|
|
114
|
-
//#endregion
|
package/dist/ops/webgl/qkv.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/qkv.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = ["x", "kernel"];
|
|
5
5
|
outputShape;
|
|
@@ -51,4 +51,3 @@ e({
|
|
|
51
51
|
backendName: "webgl",
|
|
52
52
|
kernelFunc: n
|
|
53
53
|
});
|
|
54
|
-
//#endregion
|
package/dist/ops/webgl/rope.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/rope.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = [
|
|
5
5
|
"x",
|
|
@@ -32,8 +32,8 @@ var t = class {
|
|
|
32
32
|
|
|
33
33
|
if (d < rotaryDim) {
|
|
34
34
|
int pairIdx = d / 2;
|
|
35
|
-
float cos = getCos(t + pastLen, pairIdx, 0);
|
|
36
|
-
float sin = getSin(t + pastLen, pairIdx, 0);
|
|
35
|
+
float cos = getCos(t + pastLen + b, pairIdx, 0);
|
|
36
|
+
float sin = getSin(t + pastLen + b, pairIdx, 0);
|
|
37
37
|
|
|
38
38
|
if (d % 2 == 0) {
|
|
39
39
|
// even index
|
|
@@ -71,4 +71,3 @@ e({
|
|
|
71
71
|
backendName: "webgl",
|
|
72
72
|
kernelFunc: n
|
|
73
73
|
});
|
|
74
|
-
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/ops/webgl/scatterSub.ts
|
|
3
3
|
var t = class {
|
|
4
4
|
variableNames = [
|
|
5
5
|
"labels",
|
|
@@ -25,4 +25,3 @@ e({
|
|
|
25
25
|
backendName: "webgl",
|
|
26
26
|
kernelFunc: n
|
|
27
27
|
});
|
|
28
|
-
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { s as e } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
+
import { c as t, i as n } from "../../webgpu_util-5QTyovaf.js";
|
|
3
|
+
import { Si as r, xt as i } from "../../dist-CMMLi-qO.js";
|
|
4
|
+
// lib/ops/webgpu/adamAdjust.ts
|
|
5
5
|
var a = class {
|
|
6
6
|
variableNames = ["moments", "value"];
|
|
7
7
|
outputShape;
|
|
@@ -18,12 +18,12 @@ var a = class {
|
|
|
18
18
|
outputComponent = 1;
|
|
19
19
|
variableComponents = [2, 1];
|
|
20
20
|
useWeightDecay;
|
|
21
|
-
constructor(e,
|
|
22
|
-
this.outputShape = e, this.dispatchLayout =
|
|
21
|
+
constructor(e, r) {
|
|
22
|
+
this.outputShape = e, this.dispatchLayout = t(this.outputShape), this.dispatch = n(this.dispatchLayout, this.outputShape, this.workgroupSize), this.useWeightDecay = r, r && (this.uniforms += ", weightDecay: f32");
|
|
23
23
|
}
|
|
24
24
|
getUserCode() {
|
|
25
25
|
return `
|
|
26
|
-
${
|
|
26
|
+
${e("index")} {
|
|
27
27
|
if (index < uniforms.size) {
|
|
28
28
|
let moments: vec2<f32> = moments[index];
|
|
29
29
|
let value: f32 = value[index];
|
|
@@ -43,10 +43,10 @@ var a = class {
|
|
|
43
43
|
`;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
function o(
|
|
47
|
-
let { moments:
|
|
48
|
-
|
|
49
|
-
let d = new a(
|
|
46
|
+
function o(e) {
|
|
47
|
+
let { moments: t, value: n } = e.inputs, { beta1: i, beta2: o, learningRate: s, epsilon: c, weightDecay: l } = e.attrs, u = e.backend;
|
|
48
|
+
r(t.shape, [...n.shape, 2], "Error in AdamAdjust: ");
|
|
49
|
+
let d = new a(n.shape, l > 0), f = [
|
|
50
50
|
{
|
|
51
51
|
type: "float32",
|
|
52
52
|
data: [1 / i]
|
|
@@ -67,11 +67,10 @@ function o(t) {
|
|
|
67
67
|
return l > 0 && f.push({
|
|
68
68
|
type: "float32",
|
|
69
69
|
data: [l]
|
|
70
|
-
}), u.runWebGPUProgram(d, [
|
|
70
|
+
}), u.runWebGPUProgram(d, [t, n], "float32", f);
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
i({
|
|
73
73
|
kernelName: "AdamAdjust",
|
|
74
74
|
backendName: "webgpu",
|
|
75
75
|
kernelFunc: o
|
|
76
76
|
});
|
|
77
|
-
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { s as e } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
+
import { c as t, i as n } from "../../webgpu_util-5QTyovaf.js";
|
|
3
|
+
import { Si as r, xt as i } from "../../dist-CMMLi-qO.js";
|
|
4
|
+
// lib/ops/webgpu/adamMoments.ts
|
|
5
5
|
var a = class {
|
|
6
6
|
variableNames = [
|
|
7
7
|
"moments",
|
|
@@ -26,7 +26,7 @@ var a = class {
|
|
|
26
26
|
1
|
|
27
27
|
];
|
|
28
28
|
constructor(e) {
|
|
29
|
-
this.outputShape = e, this.dispatchLayout =
|
|
29
|
+
this.outputShape = e, this.dispatchLayout = t(this.outputShape.slice(0, -1)), this.dispatch = n(this.dispatchLayout, this.outputShape.slice(0, -1), this.workgroupSize, [
|
|
30
30
|
1,
|
|
31
31
|
1,
|
|
32
32
|
1
|
|
@@ -34,7 +34,7 @@ var a = class {
|
|
|
34
34
|
}
|
|
35
35
|
getUserCode() {
|
|
36
36
|
return `
|
|
37
|
-
${
|
|
37
|
+
${e("index")} {
|
|
38
38
|
if (index < uniforms.size) {
|
|
39
39
|
let m: vec2<f32> = moments[index];
|
|
40
40
|
|
|
@@ -50,12 +50,12 @@ var a = class {
|
|
|
50
50
|
`;
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
function o(
|
|
54
|
-
let { moments:
|
|
55
|
-
if (
|
|
56
|
-
if (
|
|
53
|
+
function o(e) {
|
|
54
|
+
let { moments: t, gradient: n, scaling: i } = e.inputs, { beta1: o, beta2: s } = e.attrs, c = e.backend;
|
|
55
|
+
if (n.dtype !== "float32") throw Error(`Gradient must be float32, but got ${n.dtype}`);
|
|
56
|
+
if (r(t.shape, [...n.shape, 2], "Error in AdamMoments: "), o < 0 || o >= 1) throw Error(`Invalid beta1 value: ${o}. Must be in the range [0, 1).`);
|
|
57
57
|
if (s < 0 || s >= 1) throw Error(`Invalid beta2 value: ${s}. Must be in the range [0, 1).`);
|
|
58
|
-
let l = new a(
|
|
58
|
+
let l = new a(t.shape), u = [{
|
|
59
59
|
type: "float32",
|
|
60
60
|
data: [o]
|
|
61
61
|
}, {
|
|
@@ -63,14 +63,13 @@ function o(t) {
|
|
|
63
63
|
data: [s]
|
|
64
64
|
}];
|
|
65
65
|
return c.runWebGPUProgram(l, [
|
|
66
|
+
t,
|
|
66
67
|
n,
|
|
67
|
-
r,
|
|
68
68
|
i
|
|
69
69
|
], "float32", u);
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
i({
|
|
72
72
|
kernelName: "AdamMoments",
|
|
73
73
|
backendName: "webgpu",
|
|
74
74
|
kernelFunc: o
|
|
75
75
|
});
|
|
76
|
-
//#endregion
|