@genai-fi/nanogpt 1.4.1 → 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.d.ts +1 -0
- package/dist/api/beamer.js +19 -10
- 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.d.ts +14 -2
- package/dist/inference/Beamer.js +170 -105
- package/dist/inference/Generator.js +1 -259
- package/dist/inference/tokenisePrompt.d.ts +2 -1
- package/dist/inference/tokenisePrompt.js +15 -11
- package/dist/inference/types.d.ts +7 -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/{CausalSelfAttention.d.ts → GQA.d.ts} +8 -3
- package/dist/layers/GQA.js +102 -0
- package/dist/layers/HeadLayer.d.ts +12 -0
- package/dist/layers/HeadLayer.js +28 -0
- package/dist/layers/LoRA.js +17 -20
- package/dist/layers/MHA.d.ts +43 -0
- package/dist/layers/MHA.js +102 -0
- package/dist/layers/MLP.d.ts +5 -1
- package/dist/layers/MLP.js +33 -20
- package/dist/layers/PositionEmbedding.js +14 -13
- package/dist/layers/RMSNorm.d.ts +2 -0
- package/dist/layers/RMSNorm.js +16 -11
- package/dist/layers/RoPECache.js +1 -337
- package/dist/layers/TiedEmbedding.js +15 -14
- package/dist/layers/TransformerBlock.d.ts +4 -10
- package/dist/layers/TransformerBlock.js +29 -30
- package/dist/layers/WeightStore.js +4 -5
- package/dist/layers-CFqEip3s.js +13 -0
- package/dist/layers.d.ts +1 -1
- package/dist/layers.js +4 -12
- package/dist/loader/load.js +27 -24
- package/dist/loader/loadHF.js +3 -3
- package/dist/loader/loadTransformers.js +22 -7
- 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 +31 -17
- package/dist/loader/types.d.ts +8 -2
- package/dist/main.js +3281 -3463
- package/dist/matMul16-tE26fnhf.js +87 -0
- package/dist/{matMulGelu-CBoqTZM7.js → matMulGelu-ASUWlKqu.js} +33 -33
- package/dist/mat_mul-R9_DWmIT.js +16 -0
- package/dist/models/Llama.d.ts +16 -0
- package/dist/models/Llama.js +88 -0
- package/dist/models/NanoGPTV1.js +53 -54
- package/dist/models/NanoGPTV2.js +48 -49
- package/dist/models/Qwen3.d.ts +16 -0
- package/dist/models/Qwen3.js +88 -0
- package/dist/models/config.d.ts +18 -1
- package/dist/models/config.js +3 -8
- package/dist/models/factory.js +14 -11
- 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 +14 -14
- 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.d.ts +2 -0
- package/dist/ops/grads/silu.js +1 -0
- 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 +2 -2
- 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.d.ts +1 -1
- package/dist/ops/normRMS.js +10 -11
- 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.d.ts +1 -1
- package/dist/ops/rope.js +1 -2
- package/dist/ops/scatterSub.js +3 -4
- package/dist/ops/silu.d.ts +3 -0
- package/dist/ops/silu.js +1 -0
- 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 +10 -9
- 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 -16
- package/dist/ops/webgpu/matMul16.js +74 -57
- package/dist/ops/webgpu/matMul16_program.d.ts +4 -3
- package/dist/ops/webgpu/matMul16_program.js +30 -22
- package/dist/ops/webgpu/mul16.js +3 -4
- package/dist/ops/webgpu/norm2.js +9 -10
- package/dist/ops/webgpu/normRMS.js +13 -14
- package/dist/ops/webgpu/normRMS16_program.d.ts +2 -1
- package/dist/ops/webgpu/normRMS16_program.js +5 -5
- package/dist/ops/webgpu/normRMS32_program.d.ts +2 -1
- package/dist/ops/webgpu/normRMS32_program.js +5 -5
- 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 +113 -49
- package/dist/ops/webgpu/scatterSub.js +12 -13
- package/dist/ops/webgpu/silu.d.ts +14 -0
- package/dist/ops/webgpu/silu.js +117 -0
- 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-JjBVufF_.js +24 -0
- 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 +8 -5
- 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.d.ts +16 -0
- package/dist/utilities/maxHeap.js +54 -0
- 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 +34 -19
- 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/layers/CausalSelfAttention.js +0 -99
- package/dist/matMul16-DGtlziMn.js +0 -81
- package/dist/rope-C8EAiSGY.js +0 -25
- package/dist/selu_util-B_AFEfoz.js +0 -24
- package/dist/shared-24EoeHJl.js +0 -1314
- package/dist/tfjs_backend-h5weiy1O.js +0 -614
package/dist/ops/webgpu/rope.js
CHANGED
|
@@ -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/rope.ts
|
|
6
6
|
var o = class {
|
|
7
7
|
variableNames = [
|
|
8
8
|
"x",
|
|
@@ -20,18 +20,19 @@ var o = class {
|
|
|
20
20
|
];
|
|
21
21
|
size = !0;
|
|
22
22
|
uniforms = "pastLen: i32";
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
interleaved;
|
|
24
|
+
constructor(e, t, i, a, o = !0) {
|
|
25
|
+
this.shaderKey = `Rope_${a}_${o ? "interleaved" : "split"}`, this.outputShape = [
|
|
25
26
|
e,
|
|
26
27
|
t,
|
|
27
|
-
|
|
28
|
+
i,
|
|
28
29
|
a
|
|
29
|
-
], this.dispatchLayout =
|
|
30
|
+
], this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize), this.interleaved = o;
|
|
30
31
|
}
|
|
31
32
|
getUserCode() {
|
|
32
33
|
let e = this.outputShape[3];
|
|
33
34
|
return `
|
|
34
|
-
${
|
|
35
|
+
${t("index")} {
|
|
35
36
|
if (index < uniforms.size) {
|
|
36
37
|
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
37
38
|
let b = coords[0];
|
|
@@ -49,19 +50,19 @@ var o = class {
|
|
|
49
50
|
d;
|
|
50
51
|
|
|
51
52
|
if (d < rotaryDim) {
|
|
52
|
-
let
|
|
53
|
+
let half = rotaryDim / 2;
|
|
54
|
+
let idx = (t + uniforms.pastLen + b) * uniforms.cosShape[1] +
|
|
55
|
+
${this.interleaved ? "d / 2" : "d % half"};
|
|
53
56
|
let cos = cos[idx];
|
|
54
57
|
let sin = sin[idx];
|
|
55
58
|
|
|
56
59
|
let ownX = x[xIdx] * cos;
|
|
57
60
|
var evenOdd = 0.0;
|
|
58
61
|
|
|
59
|
-
if (d % 2 == 0) {
|
|
60
|
-
|
|
61
|
-
evenOdd = -x[xIdx + 1];
|
|
62
|
+
if (${this.interleaved ? "d % 2 == 0" : "d < half"}) {
|
|
63
|
+
evenOdd = -x[${this.interleaved ? "xIdx + 1" : "xIdx + half"}];
|
|
62
64
|
} else {
|
|
63
|
-
|
|
64
|
-
evenOdd = x[xIdx - 1];
|
|
65
|
+
evenOdd = x[${this.interleaved ? "xIdx - 1" : "xIdx - half"}];
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
outVal = fma(evenOdd, sin, ownX);
|
|
@@ -92,17 +93,17 @@ var o = class {
|
|
|
92
93
|
];
|
|
93
94
|
size = !0;
|
|
94
95
|
uniforms = "pastLen: i32";
|
|
95
|
-
constructor(e, t,
|
|
96
|
-
this.shaderKey = `Rope_${a}`, this.outputShape = [
|
|
96
|
+
constructor(e, t, i, a) {
|
|
97
|
+
this.shaderKey = `Rope_${a}_interleaved_packed`, this.outputShape = [
|
|
97
98
|
e,
|
|
98
99
|
t,
|
|
99
|
-
|
|
100
|
+
i,
|
|
100
101
|
a / 2
|
|
101
|
-
], this.dispatchLayout =
|
|
102
|
+
], this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
102
103
|
}
|
|
103
104
|
getUserCode() {
|
|
104
105
|
return `
|
|
105
|
-
${
|
|
106
|
+
${t("index")} {
|
|
106
107
|
if (index < uniforms.size) {
|
|
107
108
|
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
108
109
|
let b = coords[0];
|
|
@@ -117,21 +118,14 @@ var o = class {
|
|
|
117
118
|
t * uniforms.outShapeStrides[2] +
|
|
118
119
|
d;
|
|
119
120
|
|
|
120
|
-
let idx = (t + uniforms.pastLen) * uniforms.cosShape[1] + d;
|
|
121
|
-
let cos = cos[idx];
|
|
122
|
-
let sin = sin[idx];
|
|
123
|
-
|
|
124
121
|
let xPair = unpack2x16float(u32(x[xIdx]));
|
|
125
|
-
let
|
|
126
|
-
|
|
127
|
-
let
|
|
128
|
-
-xPair.y,
|
|
129
|
-
xPair.x
|
|
130
|
-
);
|
|
122
|
+
let idx = (t + uniforms.pastLen + b) * uniforms.cosShape[1] + d;
|
|
123
|
+
let cosVal = cos[idx];
|
|
124
|
+
let sinVal = sin[idx];
|
|
131
125
|
|
|
132
126
|
outVal = vec2<f32>(
|
|
133
|
-
fma(
|
|
134
|
-
fma(
|
|
127
|
+
fma(-xPair.y, sinVal, xPair.x * cosVal),
|
|
128
|
+
fma(xPair.x, sinVal, xPair.y * cosVal)
|
|
135
129
|
);
|
|
136
130
|
|
|
137
131
|
result[index] = i32(pack2x16float(outVal));
|
|
@@ -139,25 +133,95 @@ var o = class {
|
|
|
139
133
|
}
|
|
140
134
|
`;
|
|
141
135
|
}
|
|
136
|
+
}, c = class {
|
|
137
|
+
variableNames = [
|
|
138
|
+
"x",
|
|
139
|
+
"sin",
|
|
140
|
+
"cos"
|
|
141
|
+
];
|
|
142
|
+
outputShape;
|
|
143
|
+
shaderKey = "Rope";
|
|
144
|
+
dispatchLayout;
|
|
145
|
+
dispatch;
|
|
146
|
+
workPerThread = 2;
|
|
147
|
+
workgroupSize = [
|
|
148
|
+
64,
|
|
149
|
+
1,
|
|
150
|
+
1
|
|
151
|
+
];
|
|
152
|
+
size = !0;
|
|
153
|
+
uniforms = "pastLen: i32";
|
|
154
|
+
constructor(e, t, i, a) {
|
|
155
|
+
this.shaderKey = `Rope_${a}_split_packed`, this.outputShape = [
|
|
156
|
+
e,
|
|
157
|
+
t,
|
|
158
|
+
i,
|
|
159
|
+
a / 2
|
|
160
|
+
], this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
161
|
+
this.workPerThread,
|
|
162
|
+
1,
|
|
163
|
+
1
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
getUserCode() {
|
|
167
|
+
return `
|
|
168
|
+
${t("index")} {
|
|
169
|
+
let halfPacked = uniforms.outShape[3] / 2;
|
|
170
|
+
for (var i = 0; i < ${this.workPerThread}; i = i + 1) {
|
|
171
|
+
let flatIndex = index * ${this.workPerThread} + i;
|
|
172
|
+
if (flatIndex < uniforms.size) {
|
|
173
|
+
let coords = getCoordsFromIndex(flatIndex); // [b, h, t, dPacked]
|
|
174
|
+
let d = coords[3];
|
|
175
|
+
|
|
176
|
+
if (d < halfPacked) {
|
|
177
|
+
let t = coords[2];
|
|
178
|
+
let xLow = unpack2x16float(u32(x[flatIndex]));
|
|
179
|
+
let xHigh = unpack2x16float(u32(x[flatIndex + halfPacked]));
|
|
180
|
+
|
|
181
|
+
let scalar0 = d * 2;
|
|
182
|
+
let scalar1 = scalar0 + 1;
|
|
183
|
+
let cacheOffset = (t + uniforms.pastLen + coords[0]) * uniforms.cosShape[1];
|
|
184
|
+
|
|
185
|
+
let cos0 = cos[cacheOffset + scalar0];
|
|
186
|
+
let sin0 = sin[cacheOffset + scalar0];
|
|
187
|
+
let cos1 = cos[cacheOffset + scalar1];
|
|
188
|
+
let sin1 = sin[cacheOffset + scalar1];
|
|
189
|
+
|
|
190
|
+
let outLow = vec2<f32>(
|
|
191
|
+
fma(-xHigh.x, sin0, xLow.x * cos0),
|
|
192
|
+
fma(-xHigh.y, sin1, xLow.y * cos1)
|
|
193
|
+
);
|
|
194
|
+
let outHigh = vec2<f32>(
|
|
195
|
+
fma(xLow.x, sin0, xHigh.x * cos0),
|
|
196
|
+
fma(xLow.y, sin1, xHigh.y * cos1)
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
result[flatIndex] = i32(pack2x16float(outLow));
|
|
200
|
+
result[flatIndex + halfPacked] = i32(pack2x16float(outHigh));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
142
207
|
};
|
|
143
|
-
function
|
|
144
|
-
let { x:
|
|
145
|
-
if (
|
|
146
|
-
if (
|
|
147
|
-
if (
|
|
148
|
-
let
|
|
208
|
+
function l(t) {
|
|
209
|
+
let { x: n } = t.inputs, { pastLen: r, negSin: a, ropeCache: l, interleaved: u } = t.attrs, d = t.backend, f = e(n), p = n.shape[0], m = n.shape[1], h = n.shape[2], g = f ? n.shape[3] * 2 : n.shape[3], _ = a ? l.getNegSin() : l.getSin(), v = l.getCos();
|
|
210
|
+
if (i(_.shape, v.shape, "Error in Rope: "), _.shape[0] < h + r) throw Error(`Sin tensor shape ${_.shape} is not compatible with seqLength ${h} and pastLen ${r}.`);
|
|
211
|
+
if (_.shape[1] * 2 < g) throw Error(`Sin tensor shape ${_.shape} is not compatible with feature dimension ${g}.`);
|
|
212
|
+
if (_.shape.length !== 3) throw Error(`Sin tensor must be 3-dimensional, but got shape ${_.shape}.`);
|
|
213
|
+
let y = f ? u ? new s(p, m, h, g) : new c(p, m, h, g) : new o(p, m, h, g, u), b = [{
|
|
149
214
|
type: "int32",
|
|
150
|
-
data: [
|
|
151
|
-
}],
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
],
|
|
215
|
+
data: [r]
|
|
216
|
+
}], x = f ? "packedF16" : n.dtype;
|
|
217
|
+
return d.runWebGPUProgram(y, [
|
|
218
|
+
n,
|
|
219
|
+
_,
|
|
220
|
+
v
|
|
221
|
+
], x, b);
|
|
157
222
|
}
|
|
158
|
-
|
|
223
|
+
a({
|
|
159
224
|
kernelName: "Rope",
|
|
160
225
|
backendName: "webgpu",
|
|
161
|
-
kernelFunc:
|
|
226
|
+
kernelFunc: l
|
|
162
227
|
});
|
|
163
|
-
//#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/scatterSub.ts
|
|
5
5
|
var a = class {
|
|
6
6
|
variableNames = [
|
|
7
7
|
"labels",
|
|
@@ -18,12 +18,12 @@ var a = class {
|
|
|
18
18
|
1
|
|
19
19
|
];
|
|
20
20
|
size = !0;
|
|
21
|
-
constructor(e,
|
|
22
|
-
this.outputShape = [e,
|
|
21
|
+
constructor(e, r) {
|
|
22
|
+
this.outputShape = [e, r], 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 coords = getCoordsFromIndex(index); // [batch, depth]
|
|
29
29
|
let idx = i32(labels[coords[0]]);
|
|
@@ -35,19 +35,18 @@ var a = class {
|
|
|
35
35
|
`;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
function o(
|
|
39
|
-
let { logits:
|
|
40
|
-
|
|
38
|
+
function o(e) {
|
|
39
|
+
let { logits: t, labels: n, dy: i } = e.inputs, o = e.backend, s = n.shape[0], c = t.shape[1];
|
|
40
|
+
r(i.shape, [s], "Error in EfficientScatterSub dy: "), r(t.shape, [s, c], "Error in EfficientScatterSub logits: "), r(n.shape, [s], "Error in EfficientScatterSub labels: ");
|
|
41
41
|
let l = new a(s, c);
|
|
42
42
|
return o.runWebGPUProgram(l, [
|
|
43
|
-
r,
|
|
44
43
|
n,
|
|
44
|
+
t,
|
|
45
45
|
i
|
|
46
46
|
], "float32");
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
i({
|
|
49
49
|
kernelName: "EfficientScatterSub",
|
|
50
50
|
backendName: "webgpu",
|
|
51
51
|
kernelFunc: o
|
|
52
52
|
});
|
|
53
|
-
//#endregion
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WebGPUProgram } from '@tensorflow/tfjs-backend-webgpu';
|
|
2
|
+
export declare class SiluProgram implements WebGPUProgram {
|
|
3
|
+
outputShape: number[];
|
|
4
|
+
shaderKey: string;
|
|
5
|
+
dispatchLayout: {
|
|
6
|
+
x: number[];
|
|
7
|
+
};
|
|
8
|
+
dispatch: [number, number, number];
|
|
9
|
+
variableNames: string[];
|
|
10
|
+
workgroupSize: [number, number, number];
|
|
11
|
+
size: boolean;
|
|
12
|
+
constructor(outputShape: number[]);
|
|
13
|
+
getUserCode(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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/silu.ts
|
|
6
|
+
var a = class {
|
|
7
|
+
outputShape;
|
|
8
|
+
shaderKey;
|
|
9
|
+
dispatchLayout;
|
|
10
|
+
dispatch;
|
|
11
|
+
variableNames = ["A"];
|
|
12
|
+
workgroupSize;
|
|
13
|
+
size = !0;
|
|
14
|
+
constructor(e) {
|
|
15
|
+
this.workgroupSize = [
|
|
16
|
+
128,
|
|
17
|
+
1,
|
|
18
|
+
1
|
|
19
|
+
], this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize), this.shaderKey = "unary_silu";
|
|
20
|
+
}
|
|
21
|
+
getUserCode() {
|
|
22
|
+
return `
|
|
23
|
+
fn unaryOperation(x : f32) -> f32 {
|
|
24
|
+
return x / (1.0 + exp(-x));
|
|
25
|
+
}
|
|
26
|
+
${t("index")} {
|
|
27
|
+
if (index < uniforms.size) {
|
|
28
|
+
let a = getAByOutputIndex(index);
|
|
29
|
+
setOutputAtIndex(index, unaryOperation(a));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
function o(e) {
|
|
36
|
+
let { x: t } = e.inputs, n = e.backend, r = new a(t.shape);
|
|
37
|
+
return n.runWebGPUProgram(r, [t], "float32");
|
|
38
|
+
}
|
|
39
|
+
e({
|
|
40
|
+
kernelName: "Silu",
|
|
41
|
+
backendName: "webgpu",
|
|
42
|
+
kernelFunc: o
|
|
43
|
+
});
|
|
44
|
+
var s = class {
|
|
45
|
+
variableNames = ["dy", "x"];
|
|
46
|
+
outputShape;
|
|
47
|
+
shaderKey = "SiluGrad16";
|
|
48
|
+
dispatchLayout;
|
|
49
|
+
dispatch;
|
|
50
|
+
workgroupSize = [
|
|
51
|
+
128,
|
|
52
|
+
1,
|
|
53
|
+
1
|
|
54
|
+
];
|
|
55
|
+
size = !0;
|
|
56
|
+
constructor(e) {
|
|
57
|
+
this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
58
|
+
}
|
|
59
|
+
getUserCode() {
|
|
60
|
+
return `
|
|
61
|
+
fn activationGrad(dy: f32, X: f32) -> f32 {
|
|
62
|
+
let sigmoid = 1.0 / (1.0 + exp(-X));
|
|
63
|
+
return dy * (sigmoid + X * sigmoid * (1.0 - sigmoid));
|
|
64
|
+
}
|
|
65
|
+
${t("index")} {
|
|
66
|
+
if (index < uniforms.size) {
|
|
67
|
+
let X = unpack2x16float(u32(x[index]));
|
|
68
|
+
let DY = unpack2x16float(u32(dy[index]));
|
|
69
|
+
let dsilu = vec2<f32>(
|
|
70
|
+
activationGrad(DY.x, X.x),
|
|
71
|
+
activationGrad(DY.y, X.y)
|
|
72
|
+
);
|
|
73
|
+
result[index] = i32(pack2x16float(dsilu));
|
|
74
|
+
}
|
|
75
|
+
}`;
|
|
76
|
+
}
|
|
77
|
+
}, c = class {
|
|
78
|
+
variableNames = ["dy", "x"];
|
|
79
|
+
outputShape;
|
|
80
|
+
shaderKey = "SiluGrad32";
|
|
81
|
+
dispatchLayout;
|
|
82
|
+
dispatch;
|
|
83
|
+
workgroupSize = [
|
|
84
|
+
128,
|
|
85
|
+
1,
|
|
86
|
+
1
|
|
87
|
+
];
|
|
88
|
+
size = !0;
|
|
89
|
+
constructor(e) {
|
|
90
|
+
this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
91
|
+
}
|
|
92
|
+
getUserCode() {
|
|
93
|
+
return `
|
|
94
|
+
fn activationGrad(dy: f32, X: f32) -> f32 {
|
|
95
|
+
let sigmoid = 1.0 / (1.0 + exp(-X));
|
|
96
|
+
return dy * (sigmoid + X * sigmoid * (1.0 - sigmoid));
|
|
97
|
+
}
|
|
98
|
+
${t("index")} {
|
|
99
|
+
if (index < uniforms.size) {
|
|
100
|
+
let X = getXByOutputIndex(index);
|
|
101
|
+
let DY = getDyByOutputIndex(index);
|
|
102
|
+
let dsilu = activationGrad(DY, X);
|
|
103
|
+
setOutputAtIndex(index, dsilu);
|
|
104
|
+
}
|
|
105
|
+
}`;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function l(e) {
|
|
109
|
+
let { dy: t, x: n } = e.inputs, r = e.backend, a = i(t), o = a ? new s(n.shape) : new c(n.shape);
|
|
110
|
+
return r.runWebGPUProgram(o, [t, n], a ? "packedF16" : "float32");
|
|
111
|
+
}
|
|
112
|
+
e({
|
|
113
|
+
kernelName: "SiluGrad",
|
|
114
|
+
backendName: "webgpu",
|
|
115
|
+
kernelFunc: l
|
|
116
|
+
});
|
|
117
|
+
export { a as SiluProgram };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import { c as
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { i as e, o as t, s as n } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
+
import { a as r, t as i } from "../../slice_util-BVgPRoij.js";
|
|
3
|
+
import { c as a, i as o } from "../../webgpu_util-5QTyovaf.js";
|
|
4
|
+
import { qi as s, xt as c } from "../../dist-CMMLi-qO.js";
|
|
5
|
+
// lib/ops/webgpu/slice16.ts
|
|
6
6
|
function l(e) {
|
|
7
7
|
switch (e) {
|
|
8
8
|
case 1: return "1D";
|
|
@@ -28,21 +28,21 @@ var u = class {
|
|
|
28
28
|
];
|
|
29
29
|
start;
|
|
30
30
|
size = !0;
|
|
31
|
-
constructor(
|
|
32
|
-
this.outputShape =
|
|
31
|
+
constructor(t, n) {
|
|
32
|
+
this.outputShape = n, this.rank = n.length, this.dispatchLayout = a(this.outputShape), this.dispatch = o(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
33
33
|
this.workPerThread,
|
|
34
34
|
1,
|
|
35
35
|
1
|
|
36
|
-
]), this.start =
|
|
36
|
+
]), this.start = t, this.uniforms = `start : ${e(t.length)}, `, this.shaderKey = "slice";
|
|
37
37
|
}
|
|
38
38
|
getUserCode() {
|
|
39
|
-
let
|
|
40
|
-
return
|
|
41
|
-
${
|
|
39
|
+
let r = e(this.rank), i;
|
|
40
|
+
return i = this.start.length === 1 ? this.outputShape.map(() => "sourceLoc = uniforms.start + coords;") : this.outputShape.map((e, n) => `sourceLoc.${d[n]} = uniforms.start.${t(n)} + coords.${d[n]};`), `
|
|
41
|
+
${n("index")} {
|
|
42
42
|
if (index < uniforms.size) {
|
|
43
|
-
var sourceLoc : ${
|
|
43
|
+
var sourceLoc : ${r};
|
|
44
44
|
let coords = getCoordsFromIndex(index);
|
|
45
|
-
${
|
|
45
|
+
${i.join("\n")}
|
|
46
46
|
result[index] = source[getIndexFromCoords${l(this.rank)}(sourceLoc, uniforms.sourceShape)];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -57,18 +57,17 @@ var u = class {
|
|
|
57
57
|
"v"
|
|
58
58
|
];
|
|
59
59
|
function f(e) {
|
|
60
|
-
let { inputs:
|
|
61
|
-
if (
|
|
60
|
+
let { inputs: t, backend: n, attrs: a } = e, { x: o } = t, { begin: c, size: l } = a, [d, f] = r(o, c, l);
|
|
61
|
+
if (i(o, d, f), s(f) === 0) return n.makeTensorInfo(f, o.dtype, []);
|
|
62
62
|
let p = new u(d, f), m = [{
|
|
63
63
|
type: "int32",
|
|
64
64
|
data: d
|
|
65
65
|
}];
|
|
66
|
-
return
|
|
66
|
+
return n.runWebGPUProgram(p, [o], o.dtype, m);
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
c({
|
|
69
69
|
kernelName: "Slice16",
|
|
70
70
|
backendName: "webgpu",
|
|
71
71
|
kernelFunc: f
|
|
72
72
|
});
|
|
73
|
-
//#endregion
|
|
74
73
|
export { f as slice };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as e, qi as t, xt as n } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { t as r } from "../../reshape-DJb1jgMt.js";
|
|
2
3
|
import { reshape16 as i } from "../reshape16.js";
|
|
3
|
-
import a from "./
|
|
4
|
+
import a from "./softmax16_program.js";
|
|
4
5
|
import o from "./softmax16_subgroup_program.js";
|
|
5
|
-
import s from "./
|
|
6
|
-
|
|
7
|
-
function c(
|
|
8
|
-
let { inputs: c, backend: l, attrs: u } =
|
|
6
|
+
import s from "./utils/deviceInfo.js";
|
|
7
|
+
// lib/ops/webgpu/softmax16.ts
|
|
8
|
+
function c(n) {
|
|
9
|
+
let { inputs: c, backend: l, attrs: u } = n, { logits: d } = c, { dim: f } = u, p = l.subgroupMinSize, m = l.subgroupMaxSize, h = s(l).subgroupsSupported, g = r(d, [t(d.shape) / d.shape[f], d.shape[f]]), _ = h ? new o(g.shape, p, m) : new a(g.shape), v = l.runWebGPUProgram(_, [g], "packedF16");
|
|
9
10
|
g.dispose();
|
|
10
|
-
let y =
|
|
11
|
+
let y = e().makeTensorFromTensorInfo(v), b = i(y, d.shape);
|
|
11
12
|
return y.dispose(), b;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
n({
|
|
14
15
|
kernelName: "Softmax16",
|
|
15
16
|
backendName: "webgpu",
|
|
16
17
|
kernelFunc: c
|
|
17
18
|
});
|
|
18
|
-
//#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 } from "../../webgpu_util-5QTyovaf.js";
|
|
3
|
+
// lib/ops/webgpu/softmax16_program.ts
|
|
4
4
|
var n = class {
|
|
5
5
|
variableNames = ["logits"];
|
|
6
6
|
outputShape;
|
|
@@ -8,20 +8,20 @@ var n = class {
|
|
|
8
8
|
dispatchLayout;
|
|
9
9
|
dispatch;
|
|
10
10
|
workgroupSize;
|
|
11
|
-
constructor(
|
|
12
|
-
this.outputShape =
|
|
11
|
+
constructor(e) {
|
|
12
|
+
this.outputShape = e, this.dispatchLayout = t(this.outputShape), this.dispatch = [
|
|
13
13
|
this.outputShape[0],
|
|
14
14
|
1,
|
|
15
15
|
1
|
|
16
|
-
], this.outputShape[1] >= 4096 ?
|
|
16
|
+
], this.workgroupSize = this.outputShape[1] >= 4096 ? [
|
|
17
17
|
256,
|
|
18
18
|
1,
|
|
19
19
|
1
|
|
20
|
-
] : this.outputShape[1] < 64 ?
|
|
20
|
+
] : this.outputShape[1] < 64 ? [
|
|
21
21
|
32,
|
|
22
22
|
1,
|
|
23
23
|
1
|
|
24
|
-
] :
|
|
24
|
+
] : [
|
|
25
25
|
64,
|
|
26
26
|
1,
|
|
27
27
|
1
|
|
@@ -31,7 +31,7 @@ var n = class {
|
|
|
31
31
|
return `
|
|
32
32
|
var<workgroup> buf : array<f32, ${this.workgroupSize[0]}>;
|
|
33
33
|
const blockSize = ${this.workgroupSize[0]};
|
|
34
|
-
${
|
|
34
|
+
${e("index")} {
|
|
35
35
|
let row = index / blockSize;
|
|
36
36
|
let tid = i32(localId.x);
|
|
37
37
|
let cols = uniforms.outShape[1];
|
|
@@ -85,5 +85,4 @@ var n = class {
|
|
|
85
85
|
`;
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
|
-
//#endregion
|
|
89
88
|
export { n as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { s as e } from "../../webgpu_program-DvkFqRlR.js";
|
|
2
|
+
import { c as t } from "../../webgpu_util-5QTyovaf.js";
|
|
3
|
+
// lib/ops/webgpu/softmax16_subgroup_program.ts
|
|
4
4
|
var n = class {
|
|
5
5
|
variableNames = ["logits"];
|
|
6
6
|
outputShape;
|
|
@@ -12,8 +12,8 @@ var n = class {
|
|
|
12
12
|
maxSubgroupSize;
|
|
13
13
|
subgroups = !0;
|
|
14
14
|
subgroupBuiltins = !1;
|
|
15
|
-
constructor(
|
|
16
|
-
this.minSubgroupSize = n, this.maxSubgroupSize = r, this.outputShape =
|
|
15
|
+
constructor(e, n, r) {
|
|
16
|
+
this.minSubgroupSize = n, this.maxSubgroupSize = r, this.outputShape = e, this.dispatchLayout = t(this.outputShape), this.dispatch = [
|
|
17
17
|
this.outputShape[0],
|
|
18
18
|
1,
|
|
19
19
|
1
|
|
@@ -28,11 +28,11 @@ var n = class {
|
|
|
28
28
|
]), this.shaderKey = "softmax16subgroup";
|
|
29
29
|
}
|
|
30
30
|
getUserCode() {
|
|
31
|
-
let
|
|
31
|
+
let t = this.maxSubgroupSize !== this.minSubgroupSize;
|
|
32
32
|
return `
|
|
33
|
-
${
|
|
33
|
+
${t ? `var<workgroup> bestValues : array<f32, ${this.workgroupSize[0]}>;` : ""}
|
|
34
34
|
const blockSize = ${this.workgroupSize[0]};
|
|
35
|
-
${
|
|
35
|
+
${e("index")} {
|
|
36
36
|
let row = index / blockSize;
|
|
37
37
|
let tid = i32(localId.x);
|
|
38
38
|
let cols = uniforms.outShape[1];
|
|
@@ -45,7 +45,7 @@ var n = class {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
threadMax = subgroupMax(threadMax);
|
|
48
|
-
${
|
|
48
|
+
${t ? "\n let lane = localId.x % subgroupSize;\n if (lane == 0) {\n bestValues[localId.x / subgroupSize] = threadMax;\n }\n workgroupBarrier();\n let numSubgroups = blockSize / subgroupSize;\n threadMax = select(-3.402823e+38f, bestValues[lane], lane < numSubgroups);\n threadMax = subgroupMax(threadMax);\n workgroupBarrier(); \n " : ""}
|
|
49
49
|
|
|
50
50
|
var threadSum = 0.0f;
|
|
51
51
|
for (var col = tid; col < cols; col += blockSize) {
|
|
@@ -55,9 +55,9 @@ var n = class {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
threadSum = subgroupAdd(threadSum);
|
|
58
|
-
${
|
|
58
|
+
${t ? "\n if (lane == 0) {\n bestValues[localId.x / subgroupSize] = threadSum;\n }\n workgroupBarrier();\n threadSum = select(0.0f, bestValues[lane], lane < numSubgroups);\n threadSum = subgroupAdd(threadSum); \n " : ""}
|
|
59
59
|
|
|
60
|
-
for (var col = tid; col < cols; col += ${
|
|
60
|
+
for (var col = tid; col < cols; col += ${t ? "i32(subgroupSize)" : "blockSize"}) {
|
|
61
61
|
let value = unpack2x16float(u32(logits[rowIdx + col]));
|
|
62
62
|
let valuePair: vec2<f32> = exp(value - threadMax) / threadSum;
|
|
63
63
|
result[rowIdx + col] = i32(pack2x16float(valuePair));
|
|
@@ -66,5 +66,4 @@ var n = class {
|
|
|
66
66
|
`;
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
-
//#endregion
|
|
70
69
|
export { n as default };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { xt as e } from "../../dist-CMMLi-qO.js";
|
|
2
|
+
import { ReduceProgram as t, createReduceInfo as n, reduce as r } from "./utils/reductions.js";
|
|
3
|
+
import { isPackedTensor as i } from "../../utilities/packed.js";
|
|
4
4
|
import a from "./utils/deviceInfo.js";
|
|
5
|
-
|
|
6
|
-
var o = class extends
|
|
5
|
+
// lib/ops/webgpu/softmax16grad.ts
|
|
6
|
+
var o = class extends t {
|
|
7
7
|
constructor(e, t) {
|
|
8
8
|
super(e, t, {
|
|
9
9
|
reductionOp: "sum",
|
|
@@ -18,14 +18,13 @@ var o = class extends n {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
function s(e) {
|
|
21
|
-
let { dy:
|
|
21
|
+
let { dy: t, softmaxOutput: s } = e.inputs, c = e.backend, l = a(c), u = i(t), d = i(s);
|
|
22
22
|
if (!(u && d)) throw Error("softmaxGradGPU: dy and softmaxOutput must be packed tensors");
|
|
23
|
-
let f = [
|
|
24
|
-
return
|
|
23
|
+
let f = [t, s], p = new o(l, n(f, -1));
|
|
24
|
+
return r(p, f, c);
|
|
25
25
|
}
|
|
26
26
|
e({
|
|
27
27
|
kernelName: "Softmax16Grad",
|
|
28
28
|
backendName: "webgpu",
|
|
29
29
|
kernelFunc: s
|
|
30
30
|
});
|
|
31
|
-
//#endregion
|