@genai-fi/nanogpt 1.5.0 → 1.6.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/dist/{DatasetBuilder-DU1G1OKX.js → DatasetBuilder-DRDW8tcM.js} +85 -86
- package/dist/Generator-8IK28IWR.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/webgpu/add16.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t } from "../../binary_op_util-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { t } from "../../binary_op_util-WY9YIl0q.js";
|
|
3
3
|
import { BinaryOpProgram as n } from "./utils/binary_op.js";
|
|
4
|
-
|
|
4
|
+
// lib/ops/webgpu/add16.ts
|
|
5
5
|
function r(e) {
|
|
6
6
|
let { a: r, b: i } = e.inputs, a = e.backend, o = new n(t.ADD, r.shape, i.shape);
|
|
7
7
|
return a.runWebGPUProgram(o, [r, i], "packedF16");
|
|
@@ -11,4 +11,3 @@ e({
|
|
|
11
11
|
backendName: "webgpu",
|
|
12
12
|
kernelFunc: r
|
|
13
13
|
});
|
|
14
|
-
//#endregion
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { isPackedTensor as e } from "../../utilities/packed.js";
|
|
2
|
+
import { s as t } from "../../webgpu_program-DvkFqRlR.js";
|
|
3
|
+
import { c as n, i as r } from "../../webgpu_util-5QTyovaf.js";
|
|
4
|
+
import { Si as i, xt as a } from "../../dist-CMMLi-qO.js";
|
|
5
|
+
// lib/ops/webgpu/appendCache.ts
|
|
6
6
|
var o = class {
|
|
7
7
|
variableNames = ["cache", "item"];
|
|
8
8
|
outputShape;
|
|
@@ -16,19 +16,19 @@ var o = class {
|
|
|
16
16
|
];
|
|
17
17
|
size = !0;
|
|
18
18
|
uniforms = "cacheT: i32";
|
|
19
|
-
constructor(e, t,
|
|
20
|
-
let s = Math.min(
|
|
19
|
+
constructor(e, t, i, a, o) {
|
|
20
|
+
let s = Math.min(i + 1, o);
|
|
21
21
|
this.shaderKey = `AppendCache_${s}`, this.outputShape = [
|
|
22
22
|
e,
|
|
23
23
|
t,
|
|
24
24
|
s,
|
|
25
25
|
a
|
|
26
|
-
], this.dispatchLayout =
|
|
26
|
+
], this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
27
27
|
}
|
|
28
28
|
getUserCode() {
|
|
29
29
|
let e = this.outputShape[2];
|
|
30
30
|
return `
|
|
31
|
-
${
|
|
31
|
+
${t("index")} {
|
|
32
32
|
if (index < uniforms.size) {
|
|
33
33
|
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
34
34
|
let b = coords[0];
|
|
@@ -68,19 +68,19 @@ var o = class {
|
|
|
68
68
|
];
|
|
69
69
|
size = !0;
|
|
70
70
|
uniforms = "cacheT: i32";
|
|
71
|
-
constructor(e, t,
|
|
72
|
-
let s = Math.min(
|
|
71
|
+
constructor(e, t, i, a, o) {
|
|
72
|
+
let s = Math.min(i + 1, o);
|
|
73
73
|
this.shaderKey = `AppendCache_${s}`, this.outputShape = [
|
|
74
74
|
e,
|
|
75
75
|
t,
|
|
76
76
|
s,
|
|
77
77
|
a
|
|
78
|
-
], this.dispatchLayout =
|
|
78
|
+
], this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
79
79
|
}
|
|
80
80
|
getUserCode() {
|
|
81
81
|
let e = this.outputShape[2];
|
|
82
82
|
return `
|
|
83
|
-
${
|
|
83
|
+
${t("index")} {
|
|
84
84
|
if (index < uniforms.size) {
|
|
85
85
|
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
86
86
|
let b = coords[0];
|
|
@@ -109,22 +109,21 @@ var o = class {
|
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
111
|
function c(t) {
|
|
112
|
-
let { cache:
|
|
113
|
-
if (
|
|
112
|
+
let { cache: n, item: r } = t.inputs, { maxSize: a, pastLen: c } = t.attrs, l = t.backend, u = e(n), d = n.shape[0], f = n.shape[2], p = n.shape[1];
|
|
113
|
+
if (i(r.shape, [
|
|
114
114
|
d,
|
|
115
115
|
p,
|
|
116
116
|
1,
|
|
117
|
-
|
|
117
|
+
r.shape[3]
|
|
118
118
|
], "Error in AppendCache: "), c < 0 || c > a) throw Error(`Invalid pastLen value: ${c}. Must be in the range [0, ${a}].`);
|
|
119
|
-
let m = u ? new s(d, p, f,
|
|
119
|
+
let m = u ? new s(d, p, f, r.shape[3], a) : new o(d, p, f, r.shape[3], a), h = [{
|
|
120
120
|
type: "int32",
|
|
121
121
|
data: [c]
|
|
122
|
-
}], g = u ? "packedF16" :
|
|
123
|
-
return l.runWebGPUProgram(m, [
|
|
122
|
+
}], g = u ? "packedF16" : n.dtype;
|
|
123
|
+
return l.runWebGPUProgram(m, [n, r], g, h);
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
a({
|
|
126
126
|
kernelName: "AppendCache",
|
|
127
127
|
backendName: "webgpu",
|
|
128
128
|
kernelFunc: c
|
|
129
129
|
});
|
|
130
|
-
//#endregion
|
|
@@ -1,42 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Si as e, xt as t } from "../../dist-CMMLi-qO.js";
|
|
2
2
|
import { isPackedTensor as n } from "../../utilities/packed.js";
|
|
3
|
-
import { t as r } from "../../matMul16-
|
|
3
|
+
import { t as r } from "../../matMul16-tE26fnhf.js";
|
|
4
4
|
import i from "./attentionMask32_program.js";
|
|
5
|
-
|
|
5
|
+
// lib/ops/webgpu/attentionMask.ts
|
|
6
6
|
function a(t) {
|
|
7
|
-
let { q: a, k: o } = t.inputs, { divisor:
|
|
7
|
+
let { q: a, k: o, mask: s } = t.inputs, { divisor: c, pastLen: l } = t.attrs, u = t.backend;
|
|
8
8
|
if (n(a) && n(o)) return r(a, o, !1, !0, {
|
|
9
9
|
causalMask: !0,
|
|
10
|
-
pastLen:
|
|
11
|
-
scale:
|
|
12
|
-
});
|
|
13
|
-
let
|
|
10
|
+
pastLen: l,
|
|
11
|
+
scale: c
|
|
12
|
+
}, s);
|
|
13
|
+
let d = a.shape[0], f = a.shape[2], p = o.shape[2], m = a.shape[1], h = a.shape[3];
|
|
14
14
|
if (e(o.shape, [
|
|
15
|
-
|
|
15
|
+
d,
|
|
16
|
+
m,
|
|
16
17
|
p,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let h = new i(u, p, d, f, m), g = [
|
|
18
|
+
h
|
|
19
|
+
], "Error in AttentionMask: "), c === 0) throw Error("Divisor must be non-zero in AttentionMask");
|
|
20
|
+
if (l < 0) throw Error("pastLen must be non-negative in AttentionMask");
|
|
21
|
+
let g = new i(d, m, f, p, h), _ = [
|
|
22
22
|
{
|
|
23
23
|
type: "float32",
|
|
24
|
-
data: [
|
|
24
|
+
data: [c]
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
type: "int32",
|
|
28
|
-
data: [
|
|
28
|
+
data: [l]
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
type: "float32",
|
|
32
32
|
data: [-Infinity]
|
|
33
33
|
}
|
|
34
|
-
],
|
|
35
|
-
return
|
|
34
|
+
], v = a.dtype;
|
|
35
|
+
return u.runWebGPUProgram(g, [a, o], v, _);
|
|
36
36
|
}
|
|
37
37
|
t({
|
|
38
38
|
kernelName: "AttentionMask",
|
|
39
39
|
backendName: "webgpu",
|
|
40
40
|
kernelFunc: a
|
|
41
41
|
});
|
|
42
|
-
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { s as e } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
+
import { c as t, i as n } from "../../webgpu_util-5QTyovaf.js";
|
|
3
|
+
// lib/ops/webgpu/attentionMask32_program.ts
|
|
4
4
|
var r = class {
|
|
5
5
|
variableNames = ["q", "k"];
|
|
6
6
|
outputShape;
|
|
@@ -18,17 +18,17 @@ var r = class {
|
|
|
18
18
|
nh;
|
|
19
19
|
T1;
|
|
20
20
|
T2;
|
|
21
|
-
constructor(
|
|
21
|
+
constructor(e, r, i, a, o) {
|
|
22
22
|
if (this.shaderKey = `AttentionMask_${o}`, this.outputShape = [
|
|
23
|
-
|
|
23
|
+
e,
|
|
24
24
|
r,
|
|
25
25
|
i,
|
|
26
26
|
a
|
|
27
|
-
], this.hs = o, this.nh = r, this.T1 = i, this.T2 = a, this.dispatchLayout =
|
|
27
|
+
], this.hs = o, this.nh = r, this.T1 = i, this.T2 = a, this.dispatchLayout = t(this.outputShape), this.dispatch = n(this.dispatchLayout, this.outputShape, this.workgroupSize), o % 4 != 0) throw Error("Head size must be a multiple of 4 for AttentionMaskProgram");
|
|
28
28
|
}
|
|
29
29
|
getUserCode() {
|
|
30
30
|
return `
|
|
31
|
-
${
|
|
31
|
+
${e("index")} {
|
|
32
32
|
|
|
33
33
|
let coords = getCoordsFromIndex(index);
|
|
34
34
|
let b = coords[0];
|
|
@@ -58,5 +58,4 @@ var r = class {
|
|
|
58
58
|
`;
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
//#endregion
|
|
62
61
|
export { r as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReduceProgram as e, reduce as t } from "./utils/reductions.js";
|
|
2
|
+
import { xt as n } from "../../dist-CMMLi-qO.js";
|
|
3
3
|
import r from "./utils/deviceInfo.js";
|
|
4
|
-
|
|
5
|
-
var i = class extends
|
|
4
|
+
// lib/ops/webgpu/clipScale.ts
|
|
5
|
+
var i = class extends e {
|
|
6
6
|
shaderKey = "clipscale";
|
|
7
7
|
constructor(e, t, n) {
|
|
8
8
|
super(e, t, {
|
|
@@ -19,27 +19,26 @@ var i = class extends t {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
function a(e) {
|
|
22
|
-
let { x:
|
|
23
|
-
if (
|
|
24
|
-
let l = r(s), u = 128, d = 1, f =
|
|
22
|
+
let { x: n } = e.inputs, { invLossScaling: a, clipNorm: o } = e.attrs, s = e.backend, c = [];
|
|
23
|
+
if (n.shape.length !== 1) throw Error(`ClipScaleProgram requires 1D input, but got shape ${n.shape}`);
|
|
24
|
+
let l = r(s), u = 128, d = 1, f = n.shape[0];
|
|
25
25
|
f <= 16 ? u = 16 : f <= 32 ? u = 32 : f <= 64 && (u = 64), f > 128 && (d = Math.ceil(f / 128));
|
|
26
|
-
let p =
|
|
26
|
+
let p = new i(l, {
|
|
27
27
|
inSize: u * d,
|
|
28
28
|
outSize: 2,
|
|
29
29
|
batchSize: 1,
|
|
30
30
|
windowSize: u
|
|
31
|
-
}, u), [
|
|
31
|
+
}, u), m = t(p, [n], s, [{
|
|
32
32
|
type: "float32",
|
|
33
33
|
data: [a]
|
|
34
34
|
}, {
|
|
35
35
|
type: "float32",
|
|
36
36
|
data: [o]
|
|
37
37
|
}]);
|
|
38
|
-
return c.forEach((e) => e.dispose()),
|
|
38
|
+
return c.forEach((e) => e.dispose()), m;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
n({
|
|
41
41
|
kernelName: "ClipScale",
|
|
42
42
|
backendName: "webgpu",
|
|
43
43
|
kernelFunc: a
|
|
44
44
|
});
|
|
45
|
-
//#endregion
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as r, t as i } from "../../concat_util-
|
|
3
|
-
import {
|
|
4
|
-
import { s } from "../../
|
|
5
|
-
import { t as c } from "../../Reshape-
|
|
6
|
-
|
|
1
|
+
import { Ui as e, qi as t, xt as n } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { n as r, t as i } from "../../concat_util-CY45Hf4F.js";
|
|
3
|
+
import { s as a } from "../../webgpu_program-DvkFqRlR.js";
|
|
4
|
+
import { c as o, i as s } from "../../webgpu_util-5QTyovaf.js";
|
|
5
|
+
import { t as c } from "../../Reshape-H5zZRgr9.js";
|
|
6
|
+
// lib/ops/webgpu/concat16.ts
|
|
7
7
|
var l = class {
|
|
8
8
|
outputShape;
|
|
9
9
|
shaderKey;
|
|
@@ -20,7 +20,7 @@ var l = class {
|
|
|
20
20
|
size = !0;
|
|
21
21
|
offsetLength;
|
|
22
22
|
constructor(e) {
|
|
23
|
-
this.outputShape = r(e, 1), this.variableNames = e.map((e, t) => `T${t}`), this.dispatchLayout =
|
|
23
|
+
this.outputShape = r(e, 1), this.variableNames = e.map((e, t) => `T${t}`), this.dispatchLayout = o(this.outputShape), this.dispatch = s(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
24
24
|
this.workPerThread,
|
|
25
25
|
1,
|
|
26
26
|
1
|
|
@@ -37,7 +37,7 @@ var l = class {
|
|
|
37
37
|
e.push(`else { result[getIndexFromCoords2D(coords, uniforms.outShape)] = T${t}[getIndexFromCoords2D(vec2<i32>(yR, yC - uniforms.offset${n}), uniforms.t${t}Shape)]; }`);
|
|
38
38
|
} else e.push("result[getIndexFromCoords2D(coords, uniforms.outShape)] = T0[getIndexFromCoords2D(vec2<i32>(yR, yC), uniforms.t0Shape)];");
|
|
39
39
|
return `
|
|
40
|
-
${
|
|
40
|
+
${a("index")} {
|
|
41
41
|
for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
|
|
42
42
|
let flatIndex = index * ${this.workPerThread} + i;
|
|
43
43
|
if(flatIndex < uniforms.size) {
|
|
@@ -84,28 +84,27 @@ function u(e, t, n) {
|
|
|
84
84
|
});
|
|
85
85
|
return n.disposeData(m.dataId), h;
|
|
86
86
|
}
|
|
87
|
-
function d(e,
|
|
88
|
-
let a = r(e.map((e) => e.shape),
|
|
87
|
+
function d(e, n, i) {
|
|
88
|
+
let a = r(e.map((e) => e.shape), n);
|
|
89
89
|
return {
|
|
90
90
|
tensors2D: e.map((e) => c({
|
|
91
91
|
inputs: { x: e },
|
|
92
92
|
backend: i,
|
|
93
|
-
attrs: { shape: [
|
|
93
|
+
attrs: { shape: [t(e.shape.slice(0, n)), t(e.shape.slice(n))] }
|
|
94
94
|
})),
|
|
95
95
|
outShape: a
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
-
function f(
|
|
99
|
-
let { inputs: a, backend: o, attrs: s } =
|
|
100
|
-
i(
|
|
101
|
-
let
|
|
102
|
-
return
|
|
98
|
+
function f(n) {
|
|
99
|
+
let { inputs: a, backend: o, attrs: s } = n, { axis: c } = s, l = e(c, a[0].shape)[0], d = a.map((e) => e.shape);
|
|
100
|
+
i(d, l);
|
|
101
|
+
let f = r(a.map((e) => e.shape), l);
|
|
102
|
+
return t(f) === 0 ? o.makeTensorInfo(f, a[0].dtype, []) : u(a.filter((e) => t(e.shape) > 0), l, o);
|
|
103
103
|
}
|
|
104
104
|
var p = {
|
|
105
105
|
kernelName: "Concat16",
|
|
106
106
|
backendName: "webgpu",
|
|
107
107
|
kernelFunc: f
|
|
108
108
|
};
|
|
109
|
-
|
|
110
|
-
//#endregion
|
|
109
|
+
n(p);
|
|
111
110
|
export { l as ConcatProgram, p as concatConfig };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as t, i as n } from "../../webgpu_util-
|
|
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 { xt as r } from "../../dist-CMMLi-qO.js";
|
|
4
|
+
// lib/ops/webgpu/dropout16.ts
|
|
5
5
|
var i = class {
|
|
6
6
|
variableNames = ["x"];
|
|
7
7
|
outputShape;
|
|
@@ -27,7 +27,7 @@ var i = class {
|
|
|
27
27
|
return vec2<f32>(fract(sin(uniforms.seed + x1) * 43758.5453123), fract(sin(uniforms.seed + x2) * 43758.5453123));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
${
|
|
30
|
+
${e("index")} {
|
|
31
31
|
if (index < uniforms.size) {
|
|
32
32
|
let coords = getCoordsFromIndex(index);
|
|
33
33
|
let values = unpack2x16float(u32(x[index]));
|
|
@@ -51,9 +51,8 @@ function a(e) {
|
|
|
51
51
|
}];
|
|
52
52
|
return a.runWebGPUProgram(o, [t], "packedF16", s);
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
r({
|
|
55
55
|
kernelName: "Dropout16",
|
|
56
56
|
backendName: "webgpu",
|
|
57
57
|
kernelFunc: a
|
|
58
58
|
});
|
|
59
|
-
//#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/gatherSub.ts
|
|
5
5
|
var a = class {
|
|
6
6
|
variableNames = [
|
|
7
7
|
"labels",
|
|
@@ -19,11 +19,11 @@ var a = class {
|
|
|
19
19
|
];
|
|
20
20
|
size = !0;
|
|
21
21
|
constructor(e) {
|
|
22
|
-
this.outputShape = [e], this.dispatchLayout =
|
|
22
|
+
this.outputShape = [e], this.dispatchLayout = t(this.outputShape), this.dispatch = n(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
23
23
|
}
|
|
24
24
|
getUserCode() {
|
|
25
25
|
return `
|
|
26
|
-
${
|
|
26
|
+
${e("index")} {
|
|
27
27
|
if (index < uniforms.size) {
|
|
28
28
|
let idx = i32(labels[index]);
|
|
29
29
|
let val = values[index];
|
|
@@ -34,19 +34,18 @@ var a = class {
|
|
|
34
34
|
`;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
function o(
|
|
38
|
-
let { logits:
|
|
39
|
-
|
|
37
|
+
function o(e) {
|
|
38
|
+
let { logits: t, labels: n, values: i } = e.inputs, o = e.backend, s = n.shape[0];
|
|
39
|
+
r(i.shape, [s], "Error in EfficientGatherSub: "), r(n.shape, [s], "Error in EfficientGatherSub: ");
|
|
40
40
|
let c = new a(s);
|
|
41
41
|
return o.runWebGPUProgram(c, [
|
|
42
|
-
r,
|
|
43
42
|
n,
|
|
43
|
+
t,
|
|
44
44
|
i
|
|
45
45
|
], "float32");
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
i({
|
|
48
48
|
kernelName: "EfficientGatherSub",
|
|
49
49
|
backendName: "webgpu",
|
|
50
50
|
kernelFunc: o
|
|
51
51
|
});
|
|
52
|
-
//#endregion
|
package/dist/ops/webgpu/gelu.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as n, i as r } from "../../webgpu_util-
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { s as t } from "../../webgpu_program-DvkFqRlR.js";
|
|
3
|
+
import { c as n, i as r } from "../../webgpu_util-5QTyovaf.js";
|
|
4
|
+
import { isPackedTensor as i } from "../../utilities/packed.js";
|
|
5
|
+
// lib/ops/webgpu/gelu.ts
|
|
6
6
|
var a = .7978845608028654, o = .044715, s = class {
|
|
7
7
|
outputShape;
|
|
8
8
|
shaderKey;
|
|
@@ -32,7 +32,7 @@ var a = .7978845608028654, o = .044715, s = class {
|
|
|
32
32
|
inner = 0.5 * (1.0 + inner);
|
|
33
33
|
return x * inner;
|
|
34
34
|
}
|
|
35
|
-
${
|
|
35
|
+
${t("index")} {
|
|
36
36
|
if (index < uniforms.size) {
|
|
37
37
|
let a = getAByOutputIndex(index);
|
|
38
38
|
setOutputAtIndex(index, unaryOperation(a));
|
|
@@ -81,7 +81,7 @@ var l = class {
|
|
|
81
81
|
let dgelu = 0.5 * (1.0 + t) + 0.5 * X * sech2 * du_dx;
|
|
82
82
|
return dy *dgelu;
|
|
83
83
|
}
|
|
84
|
-
${
|
|
84
|
+
${t("index")} {
|
|
85
85
|
if (index < uniforms.size) {
|
|
86
86
|
let X = unpack2x16float(u32(x[index]));
|
|
87
87
|
let DY = unpack2x16float(u32(dy[index]));
|
|
@@ -124,7 +124,7 @@ var l = class {
|
|
|
124
124
|
let dgelu = 0.5 * (1.0 + t) + 0.5 * X * sech2 * du_dx;
|
|
125
125
|
return dy *dgelu;
|
|
126
126
|
}
|
|
127
|
-
${
|
|
127
|
+
${t("index")} {
|
|
128
128
|
if (index < uniforms.size) {
|
|
129
129
|
let X = getXByOutputIndex(index);
|
|
130
130
|
let DY = getDyByOutputIndex(index);
|
|
@@ -135,13 +135,12 @@ var l = class {
|
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
137
|
function d(e) {
|
|
138
|
-
let { dy:
|
|
139
|
-
return
|
|
138
|
+
let { dy: t, x: n } = e.inputs, r = e.backend, a = i(t), o = a ? new l(n.shape) : new u(n.shape);
|
|
139
|
+
return r.runWebGPUProgram(o, [t, n], a ? "packedF16" : "float32");
|
|
140
140
|
}
|
|
141
141
|
e({
|
|
142
142
|
kernelName: "GeluGrad",
|
|
143
143
|
backendName: "webgpu",
|
|
144
144
|
kernelFunc: d
|
|
145
145
|
});
|
|
146
|
-
//#endregion
|
|
147
146
|
export { s as GeluProgram };
|
package/dist/ops/webgpu/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import "./unpack16.js";
|
|
2
|
-
import "./transpose16.js";
|
|
3
|
-
import "./sum16.js";
|
|
4
|
-
import "./sub16.js";
|
|
5
|
-
import "./softmax16grad.js";
|
|
6
|
-
import "./softmax16.js";
|
|
7
|
-
import "./slice16.js";
|
|
8
|
-
import "./silu.js";
|
|
9
|
-
import "./scatterSub.js";
|
|
10
|
-
import "./rope.js";
|
|
11
|
-
import "./qkv.js";
|
|
12
|
-
import "./pack16.js";
|
|
13
|
-
import "./normRMSGrad.js";
|
|
14
|
-
import "./normRMS.js";
|
|
15
|
-
import "./norm2.js";
|
|
16
|
-
import "./mul16.js";
|
|
17
|
-
import "./matMul16.js";
|
|
18
1
|
import "./attentionMask.js";
|
|
2
|
+
import "./normRMS.js";
|
|
3
|
+
import "./normRMSGrad.js";
|
|
4
|
+
import "./rope.js";
|
|
19
5
|
import "./appendCache.js";
|
|
6
|
+
import "./scatterSub.js";
|
|
20
7
|
import "./gatherSub.js";
|
|
8
|
+
import "./qkv.js";
|
|
21
9
|
import "./gelu.js";
|
|
22
10
|
import "./adamMoments.js";
|
|
23
11
|
import "./adamAdjust.js";
|
|
12
|
+
import "./pack16.js";
|
|
13
|
+
import "./unpack16.js";
|
|
14
|
+
import "./softmax16.js";
|
|
15
|
+
import "./matMul16.js";
|
|
16
|
+
import "./transpose16.js";
|
|
17
|
+
import "./sum16.js";
|
|
18
|
+
import "./slice16.js";
|
|
24
19
|
import "./add16.js";
|
|
25
20
|
import "./concat16.js";
|
|
21
|
+
import "./mul16.js";
|
|
22
|
+
import "./sub16.js";
|
|
23
|
+
import "./softmax16grad.js";
|
|
24
|
+
import "./norm2.js";
|
|
26
25
|
import "./clipScale.js";
|
|
27
26
|
import "./dropout16.js";
|
|
27
|
+
import "./silu.js";
|