@genai-fi/nanogpt 0.10.2 → 0.10.3
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/Generator.js +11761 -171
- package/dist/{RealDiv-zz7FpkKX.js → RealDiv-KAPDe8zB.js} +23 -25
- package/dist/Reshape-BYkmUnAv.js +14 -0
- package/dist/{Reshape-CHdUjC72.js → Reshape-Zt6eb7yh.js} +18 -20
- package/dist/TeachableLLM.js +10 -11
- package/dist/{axis_util-BsIr9ZNu.js → axis_util-BaG7mf5A.js} +3 -3
- package/dist/backend.js +2 -2
- package/dist/{backend_util-B1XRLuq9.js → backend_util-RCe-rHaj.js} +72 -73
- package/dist/{backend_webgpu-CqpfEImu.js → backend_webgpu-DE3ACOLx.js} +45 -47
- package/dist/broadcast_to-B3eYlZm7.js +28 -0
- package/dist/checks/appendCache.js +2 -2
- package/dist/checks/attentionMask.js +3 -3
- package/dist/checks/gelu.js +2 -2
- package/dist/checks/matMulGelu.js +7 -11
- package/dist/checks/normRMS.js +9 -9
- package/dist/checks/normRMSGrad.js +3 -3
- package/dist/checks/packUnpack.js +2 -2
- package/dist/checks/qkv.js +12 -13
- package/dist/checks/rope.js +2 -2
- package/dist/clip_by_value-BnO7-a88.js +12 -0
- package/dist/complex-DjxcVmoX.js +11 -0
- package/dist/concat-BV8bt5H-.js +17 -0
- package/dist/{concat_util-iBYIyuQe.js → concat_util-DpW8mL_l.js} +1 -1
- package/dist/{dataset-D2P7rHAw.js → dataset-BcwmTGYc.js} +137 -139
- package/dist/dropout-BcvN9JYi.js +92 -0
- package/dist/expand_dims-DT4tEPwA.js +11 -0
- package/dist/{exports_initializers-CZSUJoVE.js → exports_initializers-Hta_rEnm.js} +1 -1
- package/dist/floor-D5QdR_le.js +9 -0
- package/dist/gather-D3JcZUaI.js +9 -0
- package/dist/{gelu-Bmhopi0J.js → gelu-CjNPL4OH.js} +10 -11
- package/dist/{gpgpu_math-DsCcikas.js → gpgpu_math-DAOmgtXR.js} +841 -1015
- package/dist/{index-DRyE072i.js → index-BwexR4lA.js} +262 -263
- package/dist/index-DOvlwCh-.js +3520 -0
- package/dist/{kernel_funcs_utils-CWfOAPGO.js → kernel_funcs_utils-CCzYdUZg.js} +130 -132
- package/dist/layers/BaseLayer.js +15 -16
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/MLP.js +4 -4
- package/dist/layers/PositionEmbedding.js +7 -7
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +9 -9
- package/dist/layers/TiedEmbedding.js +6 -6
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +13 -14
- package/dist/log_sum_exp-ngO0-4pK.js +39 -0
- package/dist/main.js +49 -50
- package/dist/{matMul16-fEAJ4smh.js → matMul16-BWRSOCWB.js} +14 -15
- package/dist/matMulGelu-CzfgT6Wq.js +163 -0
- package/dist/mat_mul-SjpJRLyL.js +11 -0
- package/dist/mod-AnXEvvpo.js +11 -0
- package/dist/models/NanoGPTV1.js +2 -2
- package/dist/models/model.js +13 -14
- package/dist/ones-D2rT0xk2.js +14 -0
- package/dist/ops/adamAdjust.js +1 -1
- package/dist/ops/adamMoments.js +1 -1
- package/dist/ops/add16.js +1 -1
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/concat16.js +2 -2
- package/dist/ops/cpu/adamAdjust.js +13 -14
- package/dist/ops/cpu/adamMoments.js +6 -7
- package/dist/ops/cpu/appendCache.js +7 -8
- package/dist/ops/cpu/attentionMask.js +7 -7
- package/dist/ops/cpu/fusedSoftmax.js +10 -11
- package/dist/ops/cpu/gatherSub.js +9 -10
- package/dist/ops/cpu/gelu.js +9 -10
- package/dist/ops/cpu/matMul16.js +6 -7
- package/dist/ops/cpu/matMulGelu.js +5 -6
- package/dist/ops/cpu/matMulMul.js +3 -4
- package/dist/ops/cpu/mulDropout.js +3 -4
- package/dist/ops/cpu/normRMS.js +10 -11
- package/dist/ops/cpu/qkv.js +8 -9
- package/dist/ops/cpu/rope.js +5 -6
- package/dist/ops/cpu/scatterSub.js +17 -19
- package/dist/ops/dot16.js +2 -2
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/add16.js +11 -12
- package/dist/ops/grads/attentionMask.js +5 -6
- package/dist/ops/grads/gelu.js +3 -4
- package/dist/ops/grads/matMul16.js +4 -5
- package/dist/ops/grads/matMulGelu.js +9 -10
- package/dist/ops/grads/normRMS.js +7 -8
- package/dist/ops/grads/pack16.js +4 -5
- package/dist/ops/grads/qkv.js +17 -19
- package/dist/ops/grads/rope.js +3 -5
- package/dist/ops/grads/softmax16.js +3 -4
- package/dist/ops/grads/unpack16.js +3 -4
- package/dist/ops/grads/utils.d.ts +1 -0
- package/dist/ops/grads/utils.js +8 -4
- package/dist/ops/matMul16.js +3 -3
- package/dist/ops/matMulGelu.js +2 -2
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mul16.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/pack16.js +3 -4
- package/dist/ops/qkv.js +4 -8
- package/dist/ops/reshape16.js +14 -16
- package/dist/ops/rope.d.ts +1 -1
- package/dist/ops/rope.js +3 -8
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/slice16.js +2 -2
- package/dist/ops/softmax16.js +5 -8
- package/dist/ops/sub16.js +1 -1
- package/dist/ops/sum16.js +2 -2
- package/dist/ops/transpose16.js +23 -24
- package/dist/ops/unpack16.js +2 -2
- package/dist/ops/webgl/adamAdjust.js +2 -3
- package/dist/ops/webgl/adamMoments.js +1 -2
- package/dist/ops/webgl/appendCache.js +1 -2
- package/dist/ops/webgl/attentionMask.js +4 -5
- package/dist/ops/webgl/fusedSoftmax.js +4 -6
- package/dist/ops/webgl/gatherSub.js +6 -7
- package/dist/ops/webgl/gelu.js +2 -3
- package/dist/ops/webgl/log.js +11 -12
- package/dist/ops/webgl/matMul16.js +10 -11
- package/dist/ops/webgl/matMulGelu.js +7 -111
- package/dist/ops/webgl/matMulMul.js +9 -10
- package/dist/ops/webgl/mulDropout.js +8 -9
- package/dist/ops/webgl/normRMS.js +2 -3
- package/dist/ops/webgl/qkv.js +5 -6
- package/dist/ops/webgl/rope.js +7 -8
- package/dist/ops/webgl/scatterSub.js +5 -6
- package/dist/ops/webgpu/adamAdjust.js +10 -12
- package/dist/ops/webgpu/adamMoments.js +8 -10
- package/dist/ops/webgpu/add16.js +8 -9
- package/dist/ops/webgpu/appendCache.js +23 -25
- package/dist/ops/webgpu/attentionMask.js +8 -10
- package/dist/ops/webgpu/attentionMask32_program.js +2 -2
- package/dist/ops/webgpu/concat16.js +12 -14
- package/dist/ops/webgpu/gatherSub.js +11 -13
- package/dist/ops/webgpu/gelu.js +28 -29
- package/dist/ops/webgpu/matMul16.js +26 -28
- package/dist/ops/webgpu/matMul16_program.js +4 -5
- package/dist/ops/webgpu/mul16.js +9 -10
- package/dist/ops/webgpu/normRMS.js +15 -17
- package/dist/ops/webgpu/normRMSGrad.js +21 -28
- package/dist/ops/webgpu/pack16.js +12 -13
- package/dist/ops/webgpu/pack16_program.js +2 -2
- package/dist/ops/webgpu/qkv.js +16 -18
- package/dist/ops/webgpu/rope.js +25 -27
- package/dist/ops/webgpu/scatterSub.js +7 -9
- package/dist/ops/webgpu/slice16.js +21 -23
- package/dist/ops/webgpu/softmax16.js +17 -19
- package/dist/ops/webgpu/softmax16_program.js +2 -2
- package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
- package/dist/ops/webgpu/softmax16grad.js +7 -8
- package/dist/ops/webgpu/sub16.js +7 -8
- package/dist/ops/webgpu/sum16.js +18 -20
- package/dist/ops/webgpu/transpose16.js +19 -20
- package/dist/ops/webgpu/transpose16_program.js +2 -2
- package/dist/ops/webgpu/transpose16_shared_program.js +11 -12
- package/dist/ops/webgpu/unpack16.js +3 -4
- package/dist/ops/webgpu/utils/binary_op.js +7 -8
- package/dist/ops/webgpu/utils/reductions.js +14 -22
- package/dist/ops-B5yanEdW.js +476 -0
- package/dist/pack16-nQ6JaLo-.js +39 -0
- package/dist/patches/webgpu_backend.js +19 -20
- package/dist/patches/webgpu_base.js +1 -1
- package/dist/patches/webgpu_program.js +21 -22
- package/dist/{random_width-BVV9HveY.js → random_width-or-CEftb.js} +2506 -2761
- package/dist/range-BklejeeW.js +10 -0
- package/dist/relu-CP0ZcxWO.js +9 -0
- package/dist/reshape-ByE68wS9.js +9 -0
- package/dist/resize_nearest_neighbor-B19mCEg2.js +175 -0
- package/dist/rope-Ir4mTyD1.js +24 -0
- package/dist/{scatter_nd_util-C7zXRT_h.js → scatter_nd_util-lvSiX8q4.js} +1 -1
- package/dist/selu_util-kbhpTdYD.js +44 -0
- package/dist/{shared-CHhxz-O5.js → shared-DT1TkE6w.js} +1 -1
- package/dist/{shared-D2NP_CpY.js → shared-dntlHIDQ.js} +343 -345
- package/dist/slice-BfEGSH82.js +12 -0
- package/dist/{slice_util-DyjSAD0u.js → slice_util-uTKwiEpW.js} +1 -1
- package/dist/{softmax-C9JQEtnO.js → softmax-CA5jFsLR.js} +4 -5
- package/dist/split-CVLc0w--.js +9 -0
- package/dist/squeeze-C7Z2srUo.js +10 -0
- package/dist/stack-Cf4n9h0N.js +11 -0
- package/dist/step-CINUs5QB.js +261 -0
- package/dist/sum-DWAtNGez.js +11 -0
- package/dist/tensor-DJoc7gJU.js +8 -0
- package/dist/tensor1d-D11P_7Dp.js +11 -0
- package/dist/{tensor2d-CSB4KOb0.js → tensor2d-Bs9wZRc7.js} +6 -7
- package/dist/{tensor4d-D7bLqGqz.js → tensor4d-BARPdTaS.js} +6 -7
- package/dist/{tfjs_backend-CNkSTL0c.js → tfjs_backend-y1cvNhLA.js} +255 -264
- package/dist/tile-mbfagpsB.js +11 -0
- package/dist/training/Adam.js +2 -2
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +2 -2
- package/dist/training/sparseCrossEntropy.js +5 -5
- package/dist/transpose-ClWiBS_b.js +36 -0
- package/dist/unsorted_segment_sum-BDDhB_E6.js +277 -0
- package/dist/utilities/dummy.js +3 -3
- package/dist/utilities/multinomialCPU.js +2 -2
- package/dist/utilities/packed.d.ts +1 -4
- package/dist/utilities/packed.js +10 -745
- package/dist/utilities/performance.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/sentences.js +5 -5
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-DzfrwYuP.js → variable-WawDEaAb.js} +1 -1
- package/dist/{webgpu_program-DzaQiqel.js → webgpu_program-DuOXPQol.js} +178 -172
- package/dist/{webgpu_util-0_ubCEHJ.js → webgpu_util-RxEF33Rj.js} +34 -35
- package/dist/zeros-KnWaWf-X.js +13 -0
- package/dist/zeros_like-DvE73F4e.js +721 -0
- package/package.json +4 -2
- package/dist/Reshape-CDVLyVfz.js +0 -16
- package/dist/broadcast_to-B0ChcDaz.js +0 -30
- package/dist/complex-BBiRlsVq.js +0 -13
- package/dist/concat-DmBLPVGC.js +0 -19
- package/dist/dropout-B1x1kYMa.js +0 -99
- package/dist/expand_dims-ouvfxQ1n.js +0 -13
- package/dist/gather-CH9sdacz.js +0 -10
- package/dist/index-D6Q1lPZO.js +0 -2157
- package/dist/log_sum_exp-D3ftBNY5.js +0 -41
- package/dist/mat_mul-C59XWcJd.js +0 -12
- package/dist/mod-DESSvHIU.js +0 -12
- package/dist/mulmat_packed_gpu-Coh6qbJk.js +0 -55
- package/dist/ones-jU9jlQvM.js +0 -15
- package/dist/ops-BFDtP6th.js +0 -645
- package/dist/pack16-CmVZs6af.js +0 -41
- package/dist/patches/PackedTensor.d.ts +0 -12
- package/dist/patches/PackedTensor.js +0 -11
- package/dist/patches/engine.d.ts +0 -261
- package/dist/patches/engine.js +0 -12
- package/dist/patches/tape.d.ts +0 -12
- package/dist/patches/tape.js +0 -5
- package/dist/range-ZZZD60Fx.js +0 -11
- package/dist/reciprocal-CrYlsAGD.js +0 -10
- package/dist/register_all_kernels-nvj2k7OC.js +0 -12307
- package/dist/relu-BYDneVPn.js +0 -10
- package/dist/reshape-CaPQzFvz.js +0 -10
- package/dist/rope-s4W2XO9B.js +0 -32
- package/dist/selu_util-BGPXmd4B.js +0 -303
- package/dist/sin-Djs4aQiu.js +0 -16
- package/dist/slice-DvovR5wq.js +0 -13
- package/dist/split-DBck65sX.js +0 -10
- package/dist/squeeze-C00Ipm_7.js +0 -11
- package/dist/stack-ChnHwRpX.js +0 -13
- package/dist/sum-ywRJj3Zr.js +0 -12
- package/dist/tensor-0r5yOo2R.js +0 -8
- package/dist/tensor-CzmOBsdf.js +0 -909
- package/dist/tensor1d-BlUT89BP.js +0 -12
- package/dist/tensor_util-DfwaWayG.js +0 -523
- package/dist/tile-CR074jmp.js +0 -13
- package/dist/transpose-DH4gmHvu.js +0 -38
- package/dist/zeros-DBFVbpv5.js +0 -14
package/dist/ops/webgpu/gelu.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "../../index-
|
|
2
|
-
import { e as s } from "../../webgpu_program-
|
|
3
|
-
import { f as
|
|
1
|
+
import { p as d } from "../../index-DOvlwCh-.js";
|
|
2
|
+
import { e as s } from "../../webgpu_program-DuOXPQol.js";
|
|
3
|
+
import { f as n, c as o } from "../../webgpu_util-RxEF33Rj.js";
|
|
4
4
|
import { isPackedTensor as l } from "../../utilities/packed.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class x {
|
|
5
|
+
const u = 0.7978845608028654, r = 0.044715;
|
|
6
|
+
class c {
|
|
8
7
|
outputShape;
|
|
9
8
|
shaderKey;
|
|
10
9
|
dispatchLayout;
|
|
@@ -13,7 +12,7 @@ class x {
|
|
|
13
12
|
workgroupSize;
|
|
14
13
|
size = !0;
|
|
15
14
|
constructor(e) {
|
|
16
|
-
this.workgroupSize = [128, 1, 1], this.outputShape = e, this.dispatchLayout =
|
|
15
|
+
this.workgroupSize = [128, 1, 1], this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = o(this.dispatchLayout, this.outputShape, this.workgroupSize), this.shaderKey = "unary_gelu";
|
|
17
16
|
}
|
|
18
17
|
getUserCode() {
|
|
19
18
|
return `
|
|
@@ -23,8 +22,8 @@ class x {
|
|
|
23
22
|
}
|
|
24
23
|
fn unaryOperation(x : f32) -> f32 {
|
|
25
24
|
let x3 = x * x * x;
|
|
26
|
-
var inner = fma(${
|
|
27
|
-
inner = ${
|
|
25
|
+
var inner = fma(${r}, x3, x);
|
|
26
|
+
inner = ${u} * inner;
|
|
28
27
|
inner = tanhComplete(inner);
|
|
29
28
|
inner = 0.5 * (1.0 + inner);
|
|
30
29
|
return x * inner;
|
|
@@ -38,17 +37,17 @@ class x {
|
|
|
38
37
|
`;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
function
|
|
42
|
-
const { x: e } = t.inputs, a = t.backend, i = new
|
|
40
|
+
function x(t) {
|
|
41
|
+
const { x: e } = t.inputs, a = t.backend, i = new c(e.shape);
|
|
43
42
|
return a.runWebGPUProgram(i, [e], "float32");
|
|
44
43
|
}
|
|
45
|
-
const
|
|
44
|
+
const g = {
|
|
46
45
|
kernelName: "Gelu",
|
|
47
46
|
backendName: "webgpu",
|
|
48
|
-
kernelFunc:
|
|
47
|
+
kernelFunc: x
|
|
49
48
|
};
|
|
50
|
-
|
|
51
|
-
class
|
|
49
|
+
d(g);
|
|
50
|
+
class f {
|
|
52
51
|
// Inputs: dy, x
|
|
53
52
|
variableNames = ["dy", "x"];
|
|
54
53
|
outputShape;
|
|
@@ -58,7 +57,7 @@ class m {
|
|
|
58
57
|
workgroupSize = [128, 1, 1];
|
|
59
58
|
size = !0;
|
|
60
59
|
constructor(e) {
|
|
61
|
-
this.outputShape = e, this.dispatchLayout =
|
|
60
|
+
this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = o(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
62
61
|
}
|
|
63
62
|
getUserCode() {
|
|
64
63
|
return `
|
|
@@ -69,10 +68,10 @@ class m {
|
|
|
69
68
|
fn activationGrad(dy: f32, X: f32) -> f32 {
|
|
70
69
|
let x2 = X * X;
|
|
71
70
|
let x3 = x2 * X;
|
|
72
|
-
let u = ${
|
|
71
|
+
let u = ${u} * (X + ${r} * x3);
|
|
73
72
|
let t = tanhComplete(u);
|
|
74
73
|
let sech2 = 1.0 - t * t;
|
|
75
|
-
let du_dx = ${
|
|
74
|
+
let du_dx = ${u} * (1.0 + 3.0 * ${r} * x2);
|
|
76
75
|
let dgelu = 0.5 * (1.0 + t) + 0.5 * X * sech2 * du_dx;
|
|
77
76
|
return dy *dgelu;
|
|
78
77
|
}
|
|
@@ -89,7 +88,7 @@ class m {
|
|
|
89
88
|
}`;
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
|
-
class
|
|
91
|
+
class m {
|
|
93
92
|
// Inputs: dy, x
|
|
94
93
|
variableNames = ["dy", "x"];
|
|
95
94
|
outputShape;
|
|
@@ -99,7 +98,7 @@ class y {
|
|
|
99
98
|
workgroupSize = [128, 1, 1];
|
|
100
99
|
size = !0;
|
|
101
100
|
constructor(e) {
|
|
102
|
-
this.outputShape = e, this.dispatchLayout =
|
|
101
|
+
this.outputShape = e, this.dispatchLayout = n(this.outputShape), this.dispatch = o(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
103
102
|
}
|
|
104
103
|
getUserCode() {
|
|
105
104
|
return `
|
|
@@ -110,10 +109,10 @@ class y {
|
|
|
110
109
|
fn activationGrad(dy: f32, X: f32) -> f32 {
|
|
111
110
|
let x2 = X * X;
|
|
112
111
|
let x3 = x2 * X;
|
|
113
|
-
let u = ${
|
|
112
|
+
let u = ${u} * (X + ${r} * x3);
|
|
114
113
|
let t = tanhComplete(u);
|
|
115
114
|
let sech2 = 1.0 - t * t;
|
|
116
|
-
let du_dx = ${
|
|
115
|
+
let du_dx = ${u} * (1.0 + 3.0 * ${r} * x2);
|
|
117
116
|
let dgelu = 0.5 * (1.0 + t) + 0.5 * X * sech2 * du_dx;
|
|
118
117
|
return dy *dgelu;
|
|
119
118
|
}
|
|
@@ -127,16 +126,16 @@ class y {
|
|
|
127
126
|
}`;
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
|
-
function
|
|
131
|
-
const { dy: e, x: a } = t.inputs, i = t.backend,
|
|
132
|
-
return
|
|
129
|
+
function y(t) {
|
|
130
|
+
const { dy: e, x: a } = t.inputs, i = t.backend, p = l(e), h = p ? new f(a.shape) : new m(a.shape);
|
|
131
|
+
return i.runWebGPUProgram(h, [e, a], p ? "packedF16" : "float32");
|
|
133
132
|
}
|
|
134
|
-
const
|
|
133
|
+
const b = {
|
|
135
134
|
kernelName: "GeluGrad",
|
|
136
135
|
backendName: "webgpu",
|
|
137
|
-
kernelFunc:
|
|
136
|
+
kernelFunc: y
|
|
138
137
|
};
|
|
139
|
-
|
|
138
|
+
d(b);
|
|
140
139
|
export {
|
|
141
|
-
|
|
140
|
+
c as GeluProgram
|
|
142
141
|
};
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
import { m as
|
|
1
|
+
import { p as Q, m as P, b as B, h as y, a3 as V } from "../../index-DOvlwCh-.js";
|
|
2
2
|
import { isPackedTensor as R } from "../../utilities/packed.js";
|
|
3
3
|
import { reshape16 as U } from "../reshape16.js";
|
|
4
|
-
import { matMulMul as
|
|
5
|
-
import { matMulGelu as
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { t as C } from "../../transpose-DH4gmHvu.js";
|
|
11
|
-
import { s as E } from "../../tensor-CzmOBsdf.js";
|
|
4
|
+
import { matMulMul as X } from "../matMulMul.js";
|
|
5
|
+
import { matMulGelu as Y } from "../matMulGelu.js";
|
|
6
|
+
import Z from "./matMul16_program.js";
|
|
7
|
+
import { m as _ } from "../../mat_mul-SjpJRLyL.js";
|
|
8
|
+
import { r as x } from "../../reshape-ByE68wS9.js";
|
|
9
|
+
import { t as C } from "../../transpose-ClWiBS_b.js";
|
|
12
10
|
function $(p) {
|
|
13
|
-
const { A: e, B: s } = p.inputs, { transposeA: d, transposeB: f, scale: i, activation: k, scaleA: c, scaleB: u, forceOutputShape: o, perm:
|
|
11
|
+
const { A: e, B: s } = p.inputs, { transposeA: d, transposeB: f, scale: i, activation: k, scaleA: c, scaleB: u, forceOutputShape: o, perm: h, causalMask: g, pastLen: E } = p.attrs, F = p.backend, S = !R(e), M = !R(s);
|
|
14
12
|
if (S && M) {
|
|
15
|
-
const A = c !== void 0 ?
|
|
13
|
+
const A = c !== void 0 ? P(e, B(c)) : e, b = u !== void 0 ? P(s, B(u)) : s;
|
|
16
14
|
if (g)
|
|
17
15
|
throw new Error("Causal mask is not supported for unpacked MatMul16.");
|
|
18
16
|
let a;
|
|
19
|
-
if (i !== void 0 ? a =
|
|
17
|
+
if (i !== void 0 ? a = X(A, b, B(i), d, f) : k === "gelu" ? a = Y(A, b) : a = _(A, b, d, f), h)
|
|
20
18
|
if (o) {
|
|
21
|
-
const
|
|
19
|
+
const r = x(a, o);
|
|
22
20
|
a.dispose();
|
|
23
|
-
const J = C(
|
|
24
|
-
return
|
|
21
|
+
const J = C(r, h);
|
|
22
|
+
return r.dispose(), J;
|
|
25
23
|
} else {
|
|
26
|
-
const
|
|
27
|
-
return a.dispose(),
|
|
24
|
+
const r = C(a, h);
|
|
25
|
+
return a.dispose(), r;
|
|
28
26
|
}
|
|
29
27
|
else if (o) {
|
|
30
|
-
const
|
|
31
|
-
return a.dispose(),
|
|
28
|
+
const r = x(a, o);
|
|
29
|
+
return a.dispose(), r;
|
|
32
30
|
} else
|
|
33
31
|
return a;
|
|
34
32
|
}
|
|
@@ -36,23 +34,23 @@ function $(p) {
|
|
|
36
34
|
throw new Error("When using mixed precision, A must be packed if B is packed.");
|
|
37
35
|
if (!S && M)
|
|
38
36
|
throw new Error("When using mixed precision, B must be packed if A is packed.");
|
|
39
|
-
const
|
|
40
|
-
i !== void 0 && (t.useScale(),
|
|
37
|
+
const l = e.shape.length, m = s.shape.length, W = e.shape.slice(0, -2), z = s.shape.slice(0, -2), v = y(W), w = y(z), I = V(e.shape.slice(0, -2), s.shape.slice(0, -2)), N = Math.max(v, w), K = e.shape[l - 2], L = s.shape[m - 2], T = e.shape[l - 1] * 2, j = s.shape[m - 1] * 2, D = U(e, [v, e.shape[l - 2], e.shape[l - 1]]), G = U(s, [w, s.shape[m - 2], s.shape[m - 1]]), t = new Z(N, K, L, T, j, d, f), n = [];
|
|
38
|
+
i !== void 0 && (t.useScale(), n.push({ type: "float32", data: [i] })), c !== void 0 && (t.useScaleA(), n.push({ type: "float32", data: [c] })), u !== void 0 && (t.useScaleB(), n.push({ type: "float32", data: [u] })), k !== void 0 && t.useActivation(k), g && (t.useCausalMask(), n.push({ type: "int32", data: [E || 0] }));
|
|
41
39
|
const O = t.outputShape.length;
|
|
42
40
|
o && (p.attrs.originalShape = t.outputShape);
|
|
43
|
-
const
|
|
44
|
-
t.setOutputShape(
|
|
45
|
-
const
|
|
41
|
+
const q = o ?? I.concat([t.outputShape[O - 2], t.outputShape[O - 1]]);
|
|
42
|
+
t.setOutputShape(q, h);
|
|
43
|
+
const H = F.runWebGPUProgram(
|
|
46
44
|
t,
|
|
47
45
|
[D, G],
|
|
48
|
-
"
|
|
49
|
-
|
|
46
|
+
"packedF16",
|
|
47
|
+
n.length > 0 ? n : void 0
|
|
50
48
|
);
|
|
51
|
-
return
|
|
49
|
+
return D.dispose(), G.dispose(), H;
|
|
52
50
|
}
|
|
53
51
|
const ee = {
|
|
54
52
|
kernelName: "MatMul16",
|
|
55
53
|
backendName: "webgpu",
|
|
56
54
|
kernelFunc: $
|
|
57
55
|
};
|
|
58
|
-
|
|
56
|
+
Q(ee);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "../../index-
|
|
2
|
-
import { e as h } from "../../webgpu_program-
|
|
3
|
-
|
|
4
|
-
class A {
|
|
1
|
+
import { h as f } from "../../index-DOvlwCh-.js";
|
|
2
|
+
import { e as h } from "../../webgpu_program-DuOXPQol.js";
|
|
3
|
+
class B {
|
|
5
4
|
variableNames = ["A", "B"];
|
|
6
5
|
outputShape;
|
|
7
6
|
shaderKey = "MatMul16TB";
|
|
@@ -332,5 +331,5 @@ class A {
|
|
|
332
331
|
}
|
|
333
332
|
}
|
|
334
333
|
export {
|
|
335
|
-
|
|
334
|
+
B as default
|
|
336
335
|
};
|
package/dist/ops/webgpu/mul16.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import "../../index-
|
|
2
|
-
import { BinaryOpProgram as
|
|
3
|
-
import { B as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return o.packed = !0, o;
|
|
1
|
+
import { p as t } from "../../index-DOvlwCh-.js";
|
|
2
|
+
import { BinaryOpProgram as p } from "./utils/binary_op.js";
|
|
3
|
+
import { B as m } from "../../binary_op_util-pKXltfxI.js";
|
|
4
|
+
function s(e) {
|
|
5
|
+
const { a: r, b: n } = e.inputs, o = e.backend, a = new p(m.MUL, r.shape, n.shape);
|
|
6
|
+
return o.runWebGPUProgram(a, [r, n], "packedF16");
|
|
8
7
|
}
|
|
9
|
-
const
|
|
8
|
+
const c = {
|
|
10
9
|
kernelName: "Mul16",
|
|
11
10
|
backendName: "webgpu",
|
|
12
|
-
kernelFunc:
|
|
11
|
+
kernelFunc: s
|
|
13
12
|
};
|
|
14
|
-
c
|
|
13
|
+
t(c);
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import "../../index-
|
|
2
|
-
import { createReduceInfo as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import S from "./normRMS16_program.js";
|
|
1
|
+
import { p as g, ab as l } from "../../index-DOvlwCh-.js";
|
|
2
|
+
import { createReduceInfo as w, reduce as S } from "./utils/reductions.js";
|
|
3
|
+
import { isPackedTensor as d } from "../../utilities/packed.js";
|
|
4
|
+
import { p as f } from "../../pack16-nQ6JaLo-.js";
|
|
5
|
+
import b from "./normRMS16_program.js";
|
|
7
6
|
import z from "./normRMS32_program.js";
|
|
8
7
|
import N from "./utils/deviceInfo.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (w(p.shape, [r.shape[r.shape.length - 1]], "Error in RMSNorm: "), e.shape.length !== 3)
|
|
8
|
+
function P(c) {
|
|
9
|
+
const { x: e, gamma: s } = c.inputs, m = c.backend, i = N(m), t = d(e), a = d(s), n = t || a, r = !n || t ? e : f(e), p = !n || a ? s : f(s), h = [r, p], o = w(h, -1), u = n ? new b(i, o) : new z(i, o);
|
|
10
|
+
if (l(p.shape, [r.shape[r.shape.length - 1]], "Error in RMSNorm: "), e.shape.length !== 3)
|
|
13
11
|
throw new Error(`rmsNormGPU: input rank ${e.shape.length} not supported, only rank 3 is supported`);
|
|
14
|
-
if (
|
|
12
|
+
if (o.inSize !== r.shape[r.shape.length - 1])
|
|
15
13
|
throw new Error(
|
|
16
|
-
`rmsNormGPU: reduction size ${
|
|
14
|
+
`rmsNormGPU: reduction size ${o.inSize} does not match expected size ${r.shape[r.shape.length - 1]}`
|
|
17
15
|
);
|
|
18
|
-
if (
|
|
16
|
+
if (o.batchSize !== e.shape[0] * e.shape[1])
|
|
19
17
|
throw new Error(
|
|
20
|
-
`rmsNormGPU: batch size ${
|
|
18
|
+
`rmsNormGPU: batch size ${o.batchSize} does not match expected size ${e.shape[0] * e.shape[1]}`
|
|
21
19
|
);
|
|
22
|
-
const
|
|
23
|
-
return
|
|
20
|
+
const k = S(u, h, m);
|
|
21
|
+
return n && !t && r.dispose(), n && !a && p.dispose(), k;
|
|
24
22
|
}
|
|
25
23
|
const G = {
|
|
26
24
|
kernelName: "RMSNorm",
|
|
27
25
|
backendName: "webgpu",
|
|
28
26
|
kernelFunc: P
|
|
29
27
|
};
|
|
30
|
-
|
|
28
|
+
g(G);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createReduceInfo as
|
|
3
|
-
import { f as
|
|
4
|
-
import { e as
|
|
5
|
-
import {
|
|
6
|
-
import { p as k, u as M } from "../../pack16-CmVZs6af.js";
|
|
1
|
+
import { p as _, ab as y, e as D } from "../../index-DOvlwCh-.js";
|
|
2
|
+
import { createReduceInfo as X } from "./utils/reductions.js";
|
|
3
|
+
import { f as $ } from "../../webgpu_util-RxEF33Rj.js";
|
|
4
|
+
import { e as M } from "../../webgpu_program-DuOXPQol.js";
|
|
5
|
+
import { p as k, u as R } from "../../pack16-nQ6JaLo-.js";
|
|
7
6
|
import { isPackedTensor as h } from "../../utilities/packed.js";
|
|
8
|
-
import { reshape16 as
|
|
9
|
-
import { sum16 as
|
|
10
|
-
import { slice16 as
|
|
11
|
-
import { r as P } from "../../tensor_util-DfwaWayG.js";
|
|
7
|
+
import { reshape16 as L } from "../reshape16.js";
|
|
8
|
+
import { sum16 as P } from "../sum16.js";
|
|
9
|
+
import { slice16 as z } from "../slice16.js";
|
|
12
10
|
class N {
|
|
13
11
|
outputShape;
|
|
14
12
|
shaderKey = "RMSNormGrad";
|
|
@@ -23,7 +21,7 @@ class N {
|
|
|
23
21
|
packed = !1;
|
|
24
22
|
outputComponent;
|
|
25
23
|
constructor(a, e = 4, o = !1) {
|
|
26
|
-
if (this.packed = o, this.shaderKey = `RMSNormGrad_${e}`, this.rowsPerWorkgroup = e, this.inputShape = [a.batchSize, a.inSize], this.outputShape = [a.batchSize + a.batchSize / this.rowsPerWorkgroup, a.inSize], this.dispatchLayout =
|
|
24
|
+
if (this.packed = o, this.shaderKey = `RMSNormGrad_${e}`, this.rowsPerWorkgroup = e, this.inputShape = [a.batchSize, a.inSize], this.outputShape = [a.batchSize + a.batchSize / this.rowsPerWorkgroup, a.inSize], this.dispatchLayout = $(this.outputShape), this.dispatch = [a.batchSize / this.rowsPerWorkgroup, 1, 1], a.batchSize % this.rowsPerWorkgroup !== 0)
|
|
27
25
|
throw new Error(
|
|
28
26
|
`RMSNormGradProgram: batch size ${a.batchSize} must be divisible by rowsPerWorkgroup ${this.rowsPerWorkgroup}`
|
|
29
27
|
);
|
|
@@ -87,7 +85,7 @@ class N {
|
|
|
87
85
|
|
|
88
86
|
${o}
|
|
89
87
|
|
|
90
|
-
${
|
|
88
|
+
${M("index")} {
|
|
91
89
|
// One workgroup per row (batch).
|
|
92
90
|
let Length = uniforms.reduceSize;
|
|
93
91
|
let BatchSize = uniforms.batchSize;
|
|
@@ -145,10 +143,10 @@ class N {
|
|
|
145
143
|
}
|
|
146
144
|
function W(p) {
|
|
147
145
|
const { dy: a, x: e, gamma: o } = p.inputs, n = 4;
|
|
148
|
-
|
|
146
|
+
y(e.shape, a.shape, "Error in RMSNormGrad dy: ");
|
|
149
147
|
const s = h(e), i = h(o), u = h(a), r = s || i || u, m = !r || s ? e : k(e), c = !r || i ? o : k(o), d = !r || u ? a : k(a);
|
|
150
|
-
|
|
151
|
-
const
|
|
148
|
+
y(c.shape, [m.shape[m.shape.length - 1]], "Error in RMSNormGrad gamma: ");
|
|
149
|
+
const w = p.backend, t = X([m, c, d], -1), f = new N(t, n, r), G = [
|
|
152
150
|
{ type: "int32", data: [f.inputShape[1]] },
|
|
153
151
|
// Reduce size
|
|
154
152
|
{ type: "int32", data: [f.inputShape[0]] }
|
|
@@ -156,27 +154,22 @@ function W(p) {
|
|
|
156
154
|
];
|
|
157
155
|
if (t.inSize > 1024)
|
|
158
156
|
throw new Error(`rmsNormGradGPU: inSize ${t.inSize} exceeds max of 1024`);
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
r ? "int32" : "float32",
|
|
163
|
-
v
|
|
164
|
-
);
|
|
165
|
-
x.packed = r, r && !s && m.dispose(), r && !i && c.dispose(), r && !u && d.dispose();
|
|
166
|
-
const l = _().makeTensorFromTensorInfo(x), S = w(l, [0, 0], [t.batchSize, t.inSize]), g = w(
|
|
157
|
+
const v = w.runWebGPUProgram(f, [m, c, d], r ? "packedF16" : "float32", G);
|
|
158
|
+
r && !s && m.dispose(), r && !i && c.dispose(), r && !u && d.dispose();
|
|
159
|
+
const l = D().makeTensorFromTensorInfo(v), x = z(l, [0, 0], [t.batchSize, t.inSize]), S = z(
|
|
167
160
|
l,
|
|
168
161
|
[t.batchSize, 0],
|
|
169
162
|
[t.batchSize / n, t.inSize]
|
|
170
163
|
);
|
|
171
164
|
l.dispose();
|
|
172
|
-
const b =
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
return
|
|
165
|
+
const b = L(x, e.shape);
|
|
166
|
+
x.dispose();
|
|
167
|
+
const g = P(S, [0]);
|
|
168
|
+
return S.dispose(), [b, !r || i ? g : R(g)];
|
|
176
169
|
}
|
|
177
170
|
const Y = {
|
|
178
171
|
kernelName: "RMSNormGrad",
|
|
179
172
|
backendName: "webgpu",
|
|
180
173
|
kernelFunc: W
|
|
181
174
|
};
|
|
182
|
-
|
|
175
|
+
_(Y);
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import "../../index-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (e.shape[e.shape.length - 1] % 2 !== 0)
|
|
1
|
+
import { p as i } from "../../index-DOvlwCh-.js";
|
|
2
|
+
import p from "./pack16_program.js";
|
|
3
|
+
function m(e) {
|
|
4
|
+
const { x: n } = e.inputs, { scaling: a, padding: r } = e.attrs, s = e.backend;
|
|
5
|
+
if (n.shape[n.shape.length - 1] % 2 !== 0)
|
|
7
6
|
throw new Error("Last dimension of input tensor must be even to use Pack16.");
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
o &&
|
|
11
|
-
const
|
|
12
|
-
return
|
|
7
|
+
e.attrs && (e.attrs.originalShape = n.shape);
|
|
8
|
+
const t = new p(n.shape, r), o = a !== 1;
|
|
9
|
+
o && t.useScaling();
|
|
10
|
+
const c = [{ type: "float32", data: [a] }];
|
|
11
|
+
return s.runWebGPUProgram(t, [n], "packedF16", o ? c : void 0);
|
|
13
12
|
}
|
|
14
|
-
const
|
|
13
|
+
const k = {
|
|
15
14
|
kernelName: "Pack16",
|
|
16
15
|
backendName: "webgpu",
|
|
17
16
|
kernelFunc: m
|
|
18
17
|
};
|
|
19
|
-
|
|
18
|
+
i(k);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as o, c as a } from "../../webgpu_util-
|
|
2
|
-
import { e as s } from "../../webgpu_program-
|
|
1
|
+
import { f as o, c as a } from "../../webgpu_util-RxEF33Rj.js";
|
|
2
|
+
import { e as s } from "../../webgpu_program-DuOXPQol.js";
|
|
3
3
|
class h {
|
|
4
4
|
outputShape;
|
|
5
5
|
shaderKey = "Pack16";
|
package/dist/ops/webgpu/qkv.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import "../../index-
|
|
2
|
-
import {
|
|
3
|
-
import { b as f } from "../../matMul16-fEAJ4smh.js";
|
|
1
|
+
import { p as h, ab as l } from "../../index-DOvlwCh-.js";
|
|
2
|
+
import { b as f } from "../../matMul16-BWRSOCWB.js";
|
|
4
3
|
import { slice16 as a } from "../slice16.js";
|
|
5
|
-
import { isPackedTensor as
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (h(c.shape, [m ? s * 2 : s, 3 * s], "Error in QKV: "), s % e !== 0)
|
|
4
|
+
import { isPackedTensor as u } from "../../utilities/packed.js";
|
|
5
|
+
function b(i) {
|
|
6
|
+
const { x: n, kernel: c } = i.inputs, { heads: e } = i.attrs, r = n.shape[0], t = n.shape[1], s = n.shape[2], p = u(n);
|
|
7
|
+
if (l(c.shape, [p ? s * 2 : s, 3 * s], "Error in QKV: "), s % e !== 0)
|
|
10
8
|
throw new Error(`Channel dimension ${s} must be divisible by number of heads ${e} in QKV.`);
|
|
11
|
-
const o = f(
|
|
12
|
-
forceOutputShape: [
|
|
9
|
+
const o = f(n, c, !1, !1, {
|
|
10
|
+
forceOutputShape: [r, t, 3 * e, s / e],
|
|
13
11
|
perm: [0, 2, 1, 3]
|
|
14
|
-
}),
|
|
15
|
-
a(o, [0, 0, 0, 0], [
|
|
16
|
-
a(o, [0, e, 0, 0], [
|
|
17
|
-
a(o, [0, 2 * e, 0, 0], [
|
|
12
|
+
}), m = [
|
|
13
|
+
a(o, [0, 0, 0, 0], [r, e, t, s / e]),
|
|
14
|
+
a(o, [0, e, 0, 0], [r, e, t, s / e]),
|
|
15
|
+
a(o, [0, 2 * e, 0, 0], [r, e, t, s / e])
|
|
18
16
|
];
|
|
19
|
-
return o.dispose(),
|
|
17
|
+
return o.dispose(), m;
|
|
20
18
|
}
|
|
21
|
-
const
|
|
19
|
+
const k = {
|
|
22
20
|
kernelName: "QKV",
|
|
23
21
|
backendName: "webgpu",
|
|
24
|
-
kernelFunc:
|
|
22
|
+
kernelFunc: b
|
|
25
23
|
};
|
|
26
|
-
|
|
24
|
+
h(k);
|
package/dist/ops/webgpu/rope.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { isPackedTensor as
|
|
2
|
-
import { e as
|
|
3
|
-
import { f as
|
|
4
|
-
import "../../index-
|
|
5
|
-
|
|
6
|
-
import { r as v } from "../../tensor_util-DfwaWayG.js";
|
|
7
|
-
class k {
|
|
1
|
+
import { isPackedTensor as y } from "../../utilities/packed.js";
|
|
2
|
+
import { e as c } from "../../webgpu_program-DuOXPQol.js";
|
|
3
|
+
import { f as x, c as l } from "../../webgpu_util-RxEF33Rj.js";
|
|
4
|
+
import { p as w, ab as b } from "../../index-DOvlwCh-.js";
|
|
5
|
+
class v {
|
|
8
6
|
variableNames = ["x", "sin", "cos"];
|
|
9
7
|
outputShape;
|
|
10
8
|
shaderKey = "Rope";
|
|
@@ -13,13 +11,13 @@ class k {
|
|
|
13
11
|
workgroupSize = [64, 1, 1];
|
|
14
12
|
size = !0;
|
|
15
13
|
uniforms = "pastLen: i32";
|
|
16
|
-
constructor(e,
|
|
17
|
-
this.shaderKey = `Rope_${t}`, this.outputShape = [e,
|
|
14
|
+
constructor(e, o, a, t) {
|
|
15
|
+
this.shaderKey = `Rope_${t}`, this.outputShape = [e, o, a, t], this.dispatchLayout = x(this.outputShape), this.dispatch = l(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
18
16
|
}
|
|
19
17
|
getUserCode() {
|
|
20
18
|
const e = this.outputShape[3];
|
|
21
19
|
return `
|
|
22
|
-
${
|
|
20
|
+
${c("index")} {
|
|
23
21
|
if (index < uniforms.size) {
|
|
24
22
|
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
25
23
|
let b = coords[0];
|
|
@@ -64,7 +62,7 @@ class k {
|
|
|
64
62
|
`;
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
|
-
class
|
|
65
|
+
class k {
|
|
68
66
|
variableNames = ["x", "sin", "cos"];
|
|
69
67
|
outputShape;
|
|
70
68
|
shaderKey = "Rope";
|
|
@@ -73,12 +71,12 @@ class L {
|
|
|
73
71
|
workgroupSize = [64, 1, 1];
|
|
74
72
|
size = !0;
|
|
75
73
|
uniforms = "pastLen: i32";
|
|
76
|
-
constructor(e,
|
|
77
|
-
this.shaderKey = `Rope_${t}`, this.outputShape = [e,
|
|
74
|
+
constructor(e, o, a, t) {
|
|
75
|
+
this.shaderKey = `Rope_${t}`, this.outputShape = [e, o, a, t / 2], this.dispatchLayout = x(this.outputShape), this.dispatch = l(this.dispatchLayout, this.outputShape, this.workgroupSize);
|
|
78
76
|
}
|
|
79
77
|
getUserCode() {
|
|
80
78
|
return `
|
|
81
|
-
${
|
|
79
|
+
${c("index")} {
|
|
82
80
|
if (index < uniforms.size) {
|
|
83
81
|
let coords = getCoordsFromIndex(index); // [b, h, t, d]
|
|
84
82
|
let b = coords[0];
|
|
@@ -116,22 +114,22 @@ class L {
|
|
|
116
114
|
`;
|
|
117
115
|
}
|
|
118
116
|
}
|
|
119
|
-
function
|
|
120
|
-
const { x: e } = i.inputs, { pastLen:
|
|
121
|
-
if (b(
|
|
117
|
+
function L(i) {
|
|
118
|
+
const { x: e } = i.inputs, { pastLen: o, negSin: a, ropeCache: t } = i.attrs, m = i.backend, d = y(e), p = e.shape[0], h = e.shape[1], r = e.shape[2], n = d ? e.shape[3] * 2 : e.shape[3], s = a ? t.getNegSin() : t.getSin(), u = t.getCos();
|
|
119
|
+
if (b(s.shape, u.shape, "Error in Rope: "), s.shape[0] < r + o)
|
|
122
120
|
throw new Error(
|
|
123
|
-
`Sin tensor shape ${
|
|
121
|
+
`Sin tensor shape ${s.shape} is not compatible with seqLength ${r} and pastLen ${o}.`
|
|
124
122
|
);
|
|
125
|
-
if (
|
|
126
|
-
throw new Error(`Sin tensor shape ${
|
|
127
|
-
if (
|
|
128
|
-
throw new Error(`Sin tensor must be 3-dimensional, but got shape ${
|
|
129
|
-
const
|
|
130
|
-
return
|
|
123
|
+
if (s.shape[1] * 2 < n)
|
|
124
|
+
throw new Error(`Sin tensor shape ${s.shape} is not compatible with feature dimension ${n}.`);
|
|
125
|
+
if (s.shape.length !== 3)
|
|
126
|
+
throw new Error(`Sin tensor must be 3-dimensional, but got shape ${s.shape}.`);
|
|
127
|
+
const f = d ? new k(p, h, r, n) : new v(p, h, r, n), S = [{ type: "int32", data: [o] }], g = d ? "packedF16" : e.dtype;
|
|
128
|
+
return m.runWebGPUProgram(f, [e, s, u], g, S);
|
|
131
129
|
}
|
|
132
|
-
const
|
|
130
|
+
const P = {
|
|
133
131
|
kernelName: "Rope",
|
|
134
132
|
backendName: "webgpu",
|
|
135
|
-
kernelFunc:
|
|
133
|
+
kernelFunc: L
|
|
136
134
|
};
|
|
137
|
-
|
|
135
|
+
w(P);
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { e as p } from "../../webgpu_program-
|
|
2
|
-
import { f as u, c as d } from "../../webgpu_util-
|
|
3
|
-
import "../../index-
|
|
4
|
-
import { j as s } from "../../tensor-CzmOBsdf.js";
|
|
5
|
-
import { r as h } from "../../tensor_util-DfwaWayG.js";
|
|
1
|
+
import { e as p } from "../../webgpu_program-DuOXPQol.js";
|
|
2
|
+
import { f as u, c as d } from "../../webgpu_util-RxEF33Rj.js";
|
|
3
|
+
import { p as h, ab as o } from "../../index-DOvlwCh-.js";
|
|
6
4
|
class b {
|
|
7
5
|
variableNames = ["labels", "softmaxProbs", "dy"];
|
|
8
6
|
outputShape;
|
|
@@ -28,11 +26,11 @@ class b {
|
|
|
28
26
|
`;
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
|
-
function f(
|
|
32
|
-
const { logits: t, labels: e, dy:
|
|
33
|
-
s
|
|
29
|
+
function f(a) {
|
|
30
|
+
const { logits: t, labels: e, dy: s } = a.inputs, c = a.backend, r = e.shape[0], i = t.shape[1];
|
|
31
|
+
o(s.shape, [r], "Error in EfficientScatterSub dy: "), o(t.shape, [r, i], "Error in EfficientScatterSub logits: "), o(e.shape, [r], "Error in EfficientScatterSub labels: ");
|
|
34
32
|
const n = new b(r, i);
|
|
35
|
-
return c.runWebGPUProgram(n, [e, t,
|
|
33
|
+
return c.runWebGPUProgram(n, [e, t, s], "float32");
|
|
36
34
|
}
|
|
37
35
|
const l = {
|
|
38
36
|
kernelName: "EfficientScatterSub",
|