@genai-fi/nanogpt 0.4.3 → 0.4.5
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 +3 -3
- package/dist/NanoGPTModel.js +8 -8
- package/dist/Reshape-CiAY8ltP.js +212 -0
- package/dist/TeachableLLM.js +14 -5
- package/dist/{TiedEmbedding-CnJ1bx4q.js → TiedEmbedding-DznFwzcB.js} +244 -244
- package/dist/{axis_util-BgTGy5w8.js → axis_util-QP0LdI1v.js} +1 -1
- package/dist/{concat-CuRsVY-K.js → concat-DvWM7HGZ.js} +1 -1
- package/dist/data/parquet.js +9 -6
- package/dist/data/textLoader.js +6 -5
- package/dist/{dropout-DfDdklfL.js → dropout-DFEXTPV0.js} +4 -4
- package/dist/{gather-ZYRWhmXR.js → gather-C5D8PxwA.js} +1 -1
- package/dist/gpgpu_math-CUzjlO9A.js +23 -0
- package/dist/{index-C4JCoBvj.js → index--6vO-cOz.js} +87 -87
- package/dist/{kernel_funcs_utils-CAd1h9X1.js → kernel_funcs_utils-C6YBCuOt.js} +72 -91
- package/dist/layers/CausalSelfAttention.js +47 -46
- package/dist/layers/MLP.js +31 -33
- package/dist/layers/RMSNorm.d.ts +1 -2
- package/dist/layers/RMSNorm.js +10 -10
- package/dist/layers/RoPECache.js +3 -3
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +2 -2
- package/dist/{log_sum_exp-BswFnwOb.js → log_sum_exp-CiEy1aUe.js} +7 -7
- package/dist/main.js +28 -19
- package/dist/{mat_mul-415y5Qn2.js → mat_mul-BEHRPMh0.js} +1 -1
- package/dist/{max-CP_9O2Yd.js → max-BUShNgfh.js} +1 -1
- package/dist/{moments-CjeIaVdp.js → moments-DYOHXoRV.js} +5 -5
- package/dist/{norm-CZM380I3.js → norm-DSva3hI3.js} +13 -13
- package/dist/{ones-Bf3YR48P.js → ones-D6kB8bdY.js} +2 -2
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +2 -2
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +4 -4
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.d.ts +1 -0
- package/dist/ops/cpu/matMulGelu.js +40 -0
- package/dist/ops/cpu/mulDropout.js +1 -1
- package/dist/ops/cpu/normRMS.d.ts +1 -0
- package/dist/ops/cpu/normRMS.js +39 -0
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +4 -4
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +24 -3
- package/dist/ops/grads/matMulGelu.d.ts +1 -0
- package/dist/ops/grads/matMulGelu.js +17 -0
- package/dist/ops/grads/normRMS.d.ts +2 -0
- package/dist/ops/grads/normRMS.js +20 -0
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.d.ts +3 -0
- package/dist/ops/matMulGelu.js +14 -0
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/normRMS.d.ts +2 -0
- package/dist/ops/normRMS.js +10 -0
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +689 -895
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/matMulGelu.d.ts +21 -0
- package/dist/ops/webgl/matMulGelu.js +168 -0
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.d.ts +1 -0
- package/dist/ops/webgl/normRMS.js +78 -0
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/{range-9AzeApCc.js → range-C_vpUjBu.js} +1 -1
- package/dist/{reshape-Boe4DuIO.js → reshape-z51Eu-re.js} +1 -1
- package/dist/{sin-KmhiDuMa.js → sin-H567uayl.js} +1 -1
- package/dist/{slice_util-19zDNNSn.js → slice_util-BdhYwFY_.js} +2 -2
- package/dist/{softmax-Cujsg4ay.js → softmax-Dsxflvdl.js} +1 -1
- package/dist/{split-DbcNm1-i.js → split-B_k_jwud.js} +1 -1
- package/dist/{stack-D1YjmgKN.js → stack-CmqSdsfs.js} +1 -1
- package/dist/{sum-R28pucR5.js → sum-DdkDf2MG.js} +1 -1
- package/dist/{tensor-BVeHdl7V.js → tensor-BGYi41cj.js} +1 -1
- package/dist/{tensor2d-DqFGNs_K.js → tensor2d-DUr_htjt.js} +1 -1
- package/dist/{tfjs_backend-Cug-PH75.js → tfjs_backend-DuKis_xG.js} +46 -46
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +18 -18
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +5 -5
- package/dist/training/sparseCrossEntropy.js +4 -4
- package/dist/utilities/dummy.js +2 -2
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-LJT9Ld63.js → variable-BJTZ3jOy.js} +1 -1
- package/dist/{zeros-dnQxFgAD.js → zeros-8xl-W2DC.js} +1 -1
- package/package.json +1 -1
- package/dist/gelu-CnCt17Lk.js +0 -26
package/dist/ops/webgl/gelu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as a } from "../../index-
|
|
2
|
-
import { u as s, C as x } from "../../kernel_funcs_utils-
|
|
1
|
+
import { r as a } from "../../index--6vO-cOz.js";
|
|
2
|
+
import { u as s, C as x } from "../../kernel_funcs_utils-C6YBCuOt.js";
|
|
3
3
|
const t = 0.7978845608028654, r = 0.044715, c = x + `
|
|
4
4
|
float x3 = x * x * x;
|
|
5
5
|
float inner = x + ${r} * x3;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TensorInfo } from '@tensorflow/tfjs-core';
|
|
2
|
+
import { MathBackendWebGL } from '@tensorflow/tfjs-backend-webgl';
|
|
3
|
+
export declare const MATMUL_SHARED_DIM_THRESHOLD = 1000;
|
|
4
|
+
type BatchMatMulConfig = {
|
|
5
|
+
a: TensorInfo;
|
|
6
|
+
b: TensorInfo;
|
|
7
|
+
transposeA: boolean;
|
|
8
|
+
transposeB: boolean;
|
|
9
|
+
backend: MathBackendWebGL;
|
|
10
|
+
activationSnippet?: string;
|
|
11
|
+
multiplier?: TensorInfo;
|
|
12
|
+
};
|
|
13
|
+
export declare function batchMatMulGeluImpl({ a, b, transposeA, transposeB, backend, activationSnippet, multiplier, }: BatchMatMulConfig): TensorInfo;
|
|
14
|
+
export declare function batchMatMulKernel(args: {
|
|
15
|
+
inputs: {
|
|
16
|
+
x: TensorInfo;
|
|
17
|
+
kernel: TensorInfo;
|
|
18
|
+
};
|
|
19
|
+
backend: MathBackendWebGL;
|
|
20
|
+
}): TensorInfo;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { r as C, t as R, e as I, n as G, O as L, j as F, Q as U } from "../../index--6vO-cOz.js";
|
|
2
|
+
import { r as S } from "../../Reshape-CiAY8ltP.js";
|
|
3
|
+
import { u as H } from "../../gpgpu_math-CUzjlO9A.js";
|
|
4
|
+
import { m as B } from "../../mat_mul-BEHRPMh0.js";
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
* =============================================================================
|
|
20
|
+
*/
|
|
21
|
+
class W {
|
|
22
|
+
constructor(e, s, n, a = !1, c = !1, o = !1, r = null, u = !1, l = !1) {
|
|
23
|
+
this.variableNames = ["matrixA", "matrixB"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = n, this.enableShapeUniforms = H(this.outputShape.length);
|
|
24
|
+
const h = a ? e[1] : e[2], p = Math.ceil(h / 2), d = a ? "i * 2, rc.y" : "rc.y, i * 2", $ = c ? "rc.z, i * 2" : "i * 2, rc.z", x = a ? ["a.xxyy", "a.zzww"] : ["a.xxzz", "a.yyww"], m = c ? ["b.xzxz", "b.ywyw"] : ["b.xyxy", "b.zwzw"];
|
|
25
|
+
let i = "", b = "";
|
|
26
|
+
r && (u ? i = `vec4 activation(vec4 a) {
|
|
27
|
+
vec4 b = getPreluActivationWeightsAtOutCoords();
|
|
28
|
+
${r}
|
|
29
|
+
}` : l ? i = `vec4 activation(vec4 a) {
|
|
30
|
+
vec4 b = getLeakyreluAlphaAtOutCoords();
|
|
31
|
+
${r}
|
|
32
|
+
}` : i = `vec4 activation(vec4 x) {
|
|
33
|
+
${r}
|
|
34
|
+
}`, b = "result = activation(result);");
|
|
35
|
+
const M = o ? "result += getBiasAtOutCoords();" : "";
|
|
36
|
+
o && this.variableNames.push("bias"), u && this.variableNames.push("preluActivationWeights"), l && this.variableNames.push("leakyreluAlpha");
|
|
37
|
+
let f = "rc.x", v = "rc.x";
|
|
38
|
+
e[0] < s[0] ? f = `imod(rc.x, ${e[0]})` : s[0] < e[0] && (v = `imod(rc.x, ${s[0]})`), this.userCode = `
|
|
39
|
+
${i}
|
|
40
|
+
// Don't use uniform for sharedDimensionPacked for performance.
|
|
41
|
+
const float sharedDimension = ${p}.0;
|
|
42
|
+
|
|
43
|
+
vec4 dot2x2ARowBCol(ivec3 rc) {
|
|
44
|
+
vec4 result = vec4(0);
|
|
45
|
+
int batchA = ${f};
|
|
46
|
+
int batchB = ${v};
|
|
47
|
+
for (int i = 0; i < ${p}; i++) {
|
|
48
|
+
vec4 a = getMatrixA(batchA, ${d});
|
|
49
|
+
vec4 b = getMatrixB(batchB, ${$});
|
|
50
|
+
|
|
51
|
+
// These swizzled products need to be separately added.
|
|
52
|
+
// See: https://github.com/tensorflow/tfjs/issues/1735
|
|
53
|
+
result += (${x[0]} * ${m[0]});
|
|
54
|
+
result += (${x[1]} * ${m[1]});
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void main() {
|
|
60
|
+
ivec3 rc = getOutputCoords();
|
|
61
|
+
vec4 result = dot2x2ARowBCol(rc);
|
|
62
|
+
|
|
63
|
+
${M}
|
|
64
|
+
|
|
65
|
+
${b}
|
|
66
|
+
|
|
67
|
+
setOutput(result);
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const g = 0.7978845608028654, w = 0.044715, j = `
|
|
73
|
+
vec4 x3 = x * x * x;
|
|
74
|
+
vec4 inner = x + ${w} * x3;
|
|
75
|
+
inner = ${g} * inner;
|
|
76
|
+
inner = tanh(inner);
|
|
77
|
+
inner = 0.5 * (1.0 + inner);
|
|
78
|
+
vec4 result = x * inner;
|
|
79
|
+
return result;
|
|
80
|
+
`, q = `
|
|
81
|
+
vec4 a2 = a * a;
|
|
82
|
+
vec4 a3 = a2 * a;
|
|
83
|
+
vec4 u = ${g} * (a + ${w} * a3);
|
|
84
|
+
vec4 t = tanh(u);
|
|
85
|
+
vec4 sech2 = 1.0 - t * t;
|
|
86
|
+
vec4 du_dx = ${g} * (1.0 + 3.0 * ${w} * a2);
|
|
87
|
+
vec4 dgelu = 0.5 * (1.0 + t) + 0.5 * a * sech2 * du_dx;
|
|
88
|
+
return dgelu * b;
|
|
89
|
+
`, se = 1e3;
|
|
90
|
+
function O({
|
|
91
|
+
a: t,
|
|
92
|
+
b: e,
|
|
93
|
+
transposeA: s,
|
|
94
|
+
transposeB: n,
|
|
95
|
+
backend: a,
|
|
96
|
+
activationSnippet: c,
|
|
97
|
+
multiplier: o
|
|
98
|
+
}) {
|
|
99
|
+
const r = t.shape.length, u = e.shape.length, l = s ? t.shape[r - 2] : t.shape[r - 1], h = n ? e.shape[u - 1] : e.shape[u - 2], p = s ? t.shape[r - 1] : t.shape[r - 2], d = n ? e.shape[u - 2] : e.shape[u - 1], $ = t.shape.slice(0, -2), x = e.shape.slice(0, -2), m = G($), i = G(x), M = L(t.shape.slice(0, -2), e.shape.slice(0, -2)).concat([p, d]);
|
|
100
|
+
F(
|
|
101
|
+
l === h,
|
|
102
|
+
() => `Error in matMul: inner shapes (${l}) and (${h}) of Tensors with shapes ${t.shape} and ${e.shape} and transposeA=${s} and transposeB=${n} must match.`
|
|
103
|
+
);
|
|
104
|
+
const f = s ? [m, l, p] : [m, p, l], v = n ? [i, d, h] : [i, h, d], A = S({ inputs: { x: t }, backend: a, attrs: { shape: f } }), y = S({ inputs: { x: e }, backend: a, attrs: { shape: v } }), D = [A, y], E = Math.max(m, i), N = c, T = U(t.dtype, e.dtype), _ = new W(
|
|
105
|
+
f,
|
|
106
|
+
v,
|
|
107
|
+
[E, p, d],
|
|
108
|
+
s,
|
|
109
|
+
n,
|
|
110
|
+
!1,
|
|
111
|
+
N,
|
|
112
|
+
!!o,
|
|
113
|
+
!1
|
|
114
|
+
), k = [A, y];
|
|
115
|
+
o && k.push(o);
|
|
116
|
+
const z = a.runWebGLProgram(_, k, T), K = S({ inputs: { x: z }, backend: a, attrs: { shape: M } });
|
|
117
|
+
D.push(z);
|
|
118
|
+
for (const P of D)
|
|
119
|
+
a.disposeIntermediateTensorInfo(P);
|
|
120
|
+
return K;
|
|
121
|
+
}
|
|
122
|
+
function Q(t) {
|
|
123
|
+
const { inputs: e, backend: s } = t, { x: n, kernel: a } = e;
|
|
124
|
+
if (n === void 0 || a === void 0)
|
|
125
|
+
throw new Error("BatchMatMul requires two input tensors.");
|
|
126
|
+
return O({
|
|
127
|
+
a: n,
|
|
128
|
+
b: a,
|
|
129
|
+
transposeA: !1,
|
|
130
|
+
transposeB: !1,
|
|
131
|
+
backend: s,
|
|
132
|
+
activationSnippet: j
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const J = {
|
|
136
|
+
kernelName: "MatMulGelu",
|
|
137
|
+
backendName: "webgl",
|
|
138
|
+
kernelFunc: Q
|
|
139
|
+
};
|
|
140
|
+
C(J);
|
|
141
|
+
function V(t) {
|
|
142
|
+
const { dy: e, x: s, kernel: n } = t.inputs, a = t.backend;
|
|
143
|
+
return R(() => {
|
|
144
|
+
const c = I().makeTensorFromTensorInfo(
|
|
145
|
+
O({
|
|
146
|
+
a: s,
|
|
147
|
+
b: n,
|
|
148
|
+
transposeA: !1,
|
|
149
|
+
transposeB: !1,
|
|
150
|
+
backend: a,
|
|
151
|
+
activationSnippet: q,
|
|
152
|
+
multiplier: e
|
|
153
|
+
})
|
|
154
|
+
), o = B(c, n, !1, !0), r = B(s, c, !0, !1);
|
|
155
|
+
return [o, r];
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const X = {
|
|
159
|
+
kernelName: "MatMulGeluGrad",
|
|
160
|
+
backendName: "webgl",
|
|
161
|
+
kernelFunc: V
|
|
162
|
+
};
|
|
163
|
+
C(X);
|
|
164
|
+
export {
|
|
165
|
+
se as MATMUL_SHARED_DIM_THRESHOLD,
|
|
166
|
+
O as batchMatMulGeluImpl,
|
|
167
|
+
Q as batchMatMulKernel
|
|
168
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { r as c, e as h } from "../../index--6vO-cOz.js";
|
|
2
|
+
import { s as q } from "../../sum-DdkDf2MG.js";
|
|
3
|
+
class G {
|
|
4
|
+
variableNames = ["x", "meanSquare", "gamma"];
|
|
5
|
+
outputShape;
|
|
6
|
+
userCode;
|
|
7
|
+
constructor(e, a, o) {
|
|
8
|
+
this.outputShape = [e, a, o], this.userCode = `
|
|
9
|
+
void main() {
|
|
10
|
+
ivec3 coords = getOutputCoords();
|
|
11
|
+
float x = getXAtOutCoords();
|
|
12
|
+
float meanSquare = getMeanSquare(coords.x, coords.y, 0);
|
|
13
|
+
float gamma = getGammaAtOutCoords();
|
|
14
|
+
float invRms = inversesqrt(meanSquare + 1e-8);
|
|
15
|
+
float normalized = x * invRms;
|
|
16
|
+
float outVal = normalized * gamma;
|
|
17
|
+
setOutput(outVal);
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function v(t) {
|
|
23
|
+
const { x: e, gamma: a } = t.inputs, o = t.backend, r = e.shape[0], s = e.shape[1], n = e.shape[2], m = e.square().mean(-1, !0), u = new G(r, s, n);
|
|
24
|
+
return o.runWebGLProgram(u, [e, m, a], "float32");
|
|
25
|
+
}
|
|
26
|
+
const x = {
|
|
27
|
+
kernelName: "RMSNorm",
|
|
28
|
+
backendName: "webgl",
|
|
29
|
+
kernelFunc: v
|
|
30
|
+
};
|
|
31
|
+
c(x);
|
|
32
|
+
class y {
|
|
33
|
+
variableNames = ["x", "meanSquare", "dyGamma", "dyXMean"];
|
|
34
|
+
outputShape;
|
|
35
|
+
userCode;
|
|
36
|
+
constructor(e, a, o) {
|
|
37
|
+
this.outputShape = [e, a, o], this.userCode = `
|
|
38
|
+
void main() {
|
|
39
|
+
ivec3 coords = getOutputCoords();
|
|
40
|
+
float x = getXAtOutCoords();
|
|
41
|
+
float meanSquare = getMeanSquare(coords.x, coords.y, 0) + 1e-8;
|
|
42
|
+
float dyGamma = getDyGammaAtOutCoords();
|
|
43
|
+
float dyXMean = getDyXMean(coords.x, coords.y, 0) / ${o}.0;
|
|
44
|
+
float invRms = inversesqrt(meanSquare);
|
|
45
|
+
float dx = dyGamma * invRms - x * dyXMean * invRms / meanSquare;
|
|
46
|
+
setOutput(dx);
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class C {
|
|
52
|
+
variableNames = ["x", "meanSquare", "dy"];
|
|
53
|
+
outputShape;
|
|
54
|
+
userCode;
|
|
55
|
+
constructor(e, a, o) {
|
|
56
|
+
this.outputShape = [e, a, o], this.userCode = `
|
|
57
|
+
void main() {
|
|
58
|
+
ivec3 coords = getOutputCoords();
|
|
59
|
+
float x = getXAtOutCoords();
|
|
60
|
+
float meanSquare = getMeanSquare(coords.x, coords.y, 0) + 1e-8;
|
|
61
|
+
float dy = getDyAtOutCoords();
|
|
62
|
+
float invRms = inversesqrt(meanSquare);
|
|
63
|
+
float dGamma = dy * (x * invRms);
|
|
64
|
+
setOutput(dGamma);
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function b(t) {
|
|
70
|
+
const { dy: e, x: a, gamma: o } = t.inputs, r = t.backend, s = a.shape[0], n = a.shape[1], m = a.shape[2], u = a.square().mean(-1, !0), d = e.mul(o), l = d.mul(a).sum(-1, !0), i = new y(s, n, m), g = r.runWebGLProgram(i, [a, u, d, l], "float32"), p = new C(s, n, m), S = r.runWebGLProgram(p, [a, u, e], "float32"), f = q(h().makeTensorFromTensorInfo(S), [0, 1]);
|
|
71
|
+
return [g, f];
|
|
72
|
+
}
|
|
73
|
+
const N = {
|
|
74
|
+
kernelName: "RMSNormGrad",
|
|
75
|
+
backendName: "webgl",
|
|
76
|
+
kernelFunc: b
|
|
77
|
+
};
|
|
78
|
+
c(N);
|
package/dist/ops/webgl/qkv.js
CHANGED
package/dist/ops/webgl/rope.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as u, h as p, k as g, w as m, E as w,
|
|
2
|
-
import { r as y } from "./reshape-
|
|
1
|
+
import { o as u, h as p, k as g, w as m, E as w, a4 as x, j as i } from "./index--6vO-cOz.js";
|
|
2
|
+
import { r as y } from "./reshape-z51Eu-re.js";
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { o as f, h as l, E as d,
|
|
2
|
-
import { r as $ } from "./reshape-
|
|
3
|
-
import { s as Ce } from "./split-
|
|
4
|
-
import { s as G } from "./sum-
|
|
5
|
-
import { b as me } from "./slice_util-
|
|
6
|
-
import { r as ue } from "./range-
|
|
7
|
-
import { t as Wn } from "./tensor-
|
|
8
|
-
import { s as le } from "./stack-
|
|
9
|
-
import { c as Jn, z as Yn } from "./zeros-
|
|
10
|
-
import { n as ve } from "./norm-
|
|
11
|
-
import { c as V } from "./concat-
|
|
12
|
-
import { m as y } from "./mat_mul-
|
|
13
|
-
import { t as ge } from "./tensor2d-
|
|
14
|
-
import { r as Un, d as
|
|
15
|
-
import { g as
|
|
1
|
+
import { o as f, h as l, E as d, ap as nn, aq as tn, j as p, ar as sn, D as Ve, as as rn, O as P, at as on, au as an, av as cn, aw as un, a4 as ln, ag as pn, p as Y, ax as fn, ay as hn, az as dn, aA as mn, aB as gn, aC as $n, aD as bn, aE as kn, x as C, aF as xn, aG as wn, aH as An, aI as yn, aJ as _n, aK as In, aL as En, aM as Sn, I as Tn, J as Nn, K as Dn, aN as Mn, t as K, aO as he, b as I, aP as On, a8 as U, n as Me, c as Oe, aQ as Be, aR as Bn, aS as Pn, aT as Kn, aU as Rn, aV as qn, aW as jn, f as Fn, aX as Gn, aY as Ln, ai as L, s as q, aZ as Vn, w as de, a as Cn, am as Pe, a_ as vn, a2 as zn } from "./index--6vO-cOz.js";
|
|
2
|
+
import { r as $ } from "./reshape-z51Eu-re.js";
|
|
3
|
+
import { s as Ce } from "./split-B_k_jwud.js";
|
|
4
|
+
import { s as G } from "./sum-DdkDf2MG.js";
|
|
5
|
+
import { b as me } from "./slice_util-BdhYwFY_.js";
|
|
6
|
+
import { r as ue } from "./range-C_vpUjBu.js";
|
|
7
|
+
import { t as Wn } from "./tensor-BGYi41cj.js";
|
|
8
|
+
import { s as le } from "./stack-CmqSdsfs.js";
|
|
9
|
+
import { c as Jn, z as Yn } from "./zeros-8xl-W2DC.js";
|
|
10
|
+
import { n as ve } from "./norm-DSva3hI3.js";
|
|
11
|
+
import { c as V } from "./concat-DvWM7HGZ.js";
|
|
12
|
+
import { m as y } from "./mat_mul-BEHRPMh0.js";
|
|
13
|
+
import { t as ge } from "./tensor2d-DUr_htjt.js";
|
|
14
|
+
import { r as Un, d as Zn } from "./dropout-DFEXTPV0.js";
|
|
15
|
+
import { g as Xn } from "./gather-C5D8PxwA.js";
|
|
16
16
|
/**
|
|
17
17
|
* @license
|
|
18
18
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -708,7 +708,7 @@ function Ut(e, n = 0) {
|
|
|
708
708
|
const s = { x: l(e, "x", "step") }, r = { alpha: n };
|
|
709
709
|
return d.runKernel(Sn, s, r);
|
|
710
710
|
}
|
|
711
|
-
const
|
|
711
|
+
const Zt = /* @__PURE__ */ f({ step_: Ut });
|
|
712
712
|
/**
|
|
713
713
|
* @license
|
|
714
714
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -748,13 +748,13 @@ function B(e, n) {
|
|
|
748
748
|
* limitations under the License.
|
|
749
749
|
* =============================================================================
|
|
750
750
|
*/
|
|
751
|
-
function
|
|
751
|
+
function Xt(e, n = 0) {
|
|
752
752
|
const t = l(e, "x", "unstack", "string_or_numeric");
|
|
753
753
|
p(n >= -t.shape.length && n < t.shape.length, () => `Axis = ${n} is not in [-${t.shape.length}, ${t.shape.length})`);
|
|
754
754
|
const s = { value: t }, r = { axis: n };
|
|
755
755
|
return d.runKernel(Mn, s, r);
|
|
756
756
|
}
|
|
757
|
-
const Ye = /* @__PURE__ */ f({ unstack_:
|
|
757
|
+
const Ye = /* @__PURE__ */ f({ unstack_: Xt });
|
|
758
758
|
/**
|
|
759
759
|
* @license
|
|
760
760
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -804,7 +804,7 @@ function Qt(e, n, t) {
|
|
|
804
804
|
if (t == null || t === "linear")
|
|
805
805
|
return e;
|
|
806
806
|
if (t === "relu")
|
|
807
|
-
return I(e,
|
|
807
|
+
return I(e, Zt(n));
|
|
808
808
|
throw new Error(`Cannot compute gradient for fused activation ${t}.`);
|
|
809
809
|
}
|
|
810
810
|
function es(e, n) {
|
|
@@ -862,13 +862,13 @@ function ss({ a: e, b: n, transposeA: t = !1, transposeB: s = !1, bias: r, activ
|
|
|
862
862
|
a != null && (te = l(a, "prelu weights", "fused matMul"));
|
|
863
863
|
const v = (z, se) => {
|
|
864
864
|
const [j, F, W, ce] = se, R = Qt($(z, W.shape), W, o);
|
|
865
|
-
let
|
|
866
|
-
if (!t && !s ? (
|
|
865
|
+
let X, H;
|
|
866
|
+
if (!t && !s ? (X = y(R, F, !1, !0), H = y(j, R, !0, !1)) : !t && s ? (X = y(R, F, !1, !1), H = y(R, j, !0, !1)) : t && !s ? (X = y(F, R, !1, !0), H = y(j, R, !1, !1)) : (X = y(F, R, !0, !0), H = y(R, j, !0, !0)), r != null) {
|
|
867
867
|
const en = es(ce, R);
|
|
868
|
-
return [
|
|
868
|
+
return [X, H, en];
|
|
869
869
|
} else
|
|
870
|
-
return [
|
|
871
|
-
},
|
|
870
|
+
return [X, H];
|
|
871
|
+
}, Z = {
|
|
872
872
|
a: M,
|
|
873
873
|
b: O,
|
|
874
874
|
bias: N,
|
|
@@ -877,13 +877,13 @@ function ss({ a: e, b: n, transposeA: t = !1, transposeB: s = !1, bias: r, activ
|
|
|
877
877
|
return r == null ? Oe((se, j, F) => {
|
|
878
878
|
const W = (
|
|
879
879
|
// tslint:disable-next-line: no-unnecessary-type-assertion
|
|
880
|
-
d.runKernel(Be,
|
|
880
|
+
d.runKernel(Be, Z, De)
|
|
881
881
|
);
|
|
882
882
|
return F([se, j, W]), { value: $(W, T), gradFunc: v };
|
|
883
883
|
})(M, O) : Oe((se, j, F, W) => {
|
|
884
884
|
const ce = (
|
|
885
885
|
// tslint:disable-next-line: no-unnecessary-type-assertion
|
|
886
|
-
d.runKernel(Be,
|
|
886
|
+
d.runKernel(Be, Z, De)
|
|
887
887
|
);
|
|
888
888
|
return W([se, j, ce, F]), { value: $(ce, T), gradFunc: v };
|
|
889
889
|
})(M, O, N);
|
|
@@ -1575,15 +1575,15 @@ function Fe(e, n = !1) {
|
|
|
1575
1575
|
if (c === 0)
|
|
1576
1576
|
o = q(M, y(O, y(N, M)));
|
|
1577
1577
|
else {
|
|
1578
|
-
const
|
|
1579
|
-
o = V([_(o, [0, 0], [c, s]),
|
|
1578
|
+
const Z = q(M, y(O, y(N, M)));
|
|
1579
|
+
o = V([_(o, [0, 0], [c, s]), Z], 0);
|
|
1580
1580
|
}
|
|
1581
1581
|
const te = xe(O), v = _(r, [0, c], [t, r.shape[1] - c]);
|
|
1582
1582
|
if (c === 0)
|
|
1583
1583
|
r = q(v, y(y(v, i), te));
|
|
1584
1584
|
else {
|
|
1585
|
-
const
|
|
1586
|
-
r = V([_(r, [0, 0], [t, c]),
|
|
1585
|
+
const Z = q(v, y(y(v, i), te));
|
|
1586
|
+
r = V([_(r, [0, 0], [t, c]), Z], 1);
|
|
1587
1587
|
}
|
|
1588
1588
|
return [i, o, r];
|
|
1589
1589
|
}), Cn([m, h, b]);
|
|
@@ -1638,7 +1638,7 @@ const Ar = {
|
|
|
1638
1638
|
* https://opensource.org/licenses/MIT.
|
|
1639
1639
|
* =============================================================================
|
|
1640
1640
|
*/
|
|
1641
|
-
const
|
|
1641
|
+
const Zs = ["channelsFirst", "channelsLast"], Xs = ["nearest", "bilinear"], Hs = ["valid", "same", "causal"], Qs = ["max", "avg"], _r = ["sum", "mul", "concat", "ave"];
|
|
1642
1642
|
/**
|
|
1643
1643
|
* @license
|
|
1644
1644
|
* Copyright 2018 Google LLC
|
|
@@ -1653,9 +1653,9 @@ class Ue extends Error {
|
|
|
1653
1653
|
super(n), Object.setPrototypeOf(this, Ue.prototype);
|
|
1654
1654
|
}
|
|
1655
1655
|
}
|
|
1656
|
-
class
|
|
1656
|
+
class Ze extends Error {
|
|
1657
1657
|
constructor(n) {
|
|
1658
|
-
super(n), Object.setPrototypeOf(this,
|
|
1658
|
+
super(n), Object.setPrototypeOf(this, Ze.prototype);
|
|
1659
1659
|
}
|
|
1660
1660
|
}
|
|
1661
1661
|
class A extends Error {
|
|
@@ -1812,10 +1812,10 @@ function Rr(e, n, t = 0, s = 1 / 0) {
|
|
|
1812
1812
|
return Ge(t >= 0), Ge(s >= t), Array.isArray(e) && e.length >= t && e.length <= s && e.every((r) => typeof r === n);
|
|
1813
1813
|
}
|
|
1814
1814
|
function nr(e, n) {
|
|
1815
|
-
Array.isArray(e) ? (p(e.length > 0, () => `${n} is unexpectedly an empty array.`), e.forEach((t, s) => nr(t, `element ${s + 1} of ${n}`))) : p(Number.isInteger(e) && e > 0, () => `Expected ${n} to be a positive integer, but got ${
|
|
1815
|
+
Array.isArray(e) ? (p(e.length > 0, () => `${n} is unexpectedly an empty array.`), e.forEach((t, s) => nr(t, `element ${s + 1} of ${n}`))) : p(Number.isInteger(e) && e > 0, () => `Expected ${n} to be a positive integer, but got ${Xe(e)}.`);
|
|
1816
1816
|
}
|
|
1817
|
-
function
|
|
1818
|
-
return e === null ? "null" : Array.isArray(e) ? "[" + e.map((n) =>
|
|
1817
|
+
function Xe(e) {
|
|
1818
|
+
return e === null ? "null" : Array.isArray(e) ? "[" + e.map((n) => Xe(n)).join(",") + "]" : typeof e == "string" ? `"${e}"` : `${e}`;
|
|
1819
1819
|
}
|
|
1820
1820
|
function qr(e, n, t) {
|
|
1821
1821
|
let s = t != null ? t() : Pe(), r;
|
|
@@ -1838,10 +1838,10 @@ function jr(e) {
|
|
|
1838
1838
|
*/
|
|
1839
1839
|
const Q = /* @__PURE__ */ new Map();
|
|
1840
1840
|
function tr(e) {
|
|
1841
|
-
fe(
|
|
1841
|
+
fe(Zs, "DataFormat", e);
|
|
1842
1842
|
}
|
|
1843
1843
|
function Fr(e) {
|
|
1844
|
-
fe(
|
|
1844
|
+
fe(Xs, "InterpolationFormat", e);
|
|
1845
1845
|
}
|
|
1846
1846
|
function Gr(e) {
|
|
1847
1847
|
fe(Hs, "PaddingMode", e);
|
|
@@ -1954,14 +1954,14 @@ function Ae() {
|
|
|
1954
1954
|
* https://opensource.org/licenses/MIT.
|
|
1955
1955
|
* =============================================================================
|
|
1956
1956
|
*/
|
|
1957
|
-
function
|
|
1957
|
+
function Zr(e, n) {
|
|
1958
1958
|
return C(e, n);
|
|
1959
1959
|
}
|
|
1960
1960
|
function or(e, n = -1) {
|
|
1961
1961
|
const t = e.shape.slice();
|
|
1962
1962
|
return n < 0 && (n = t.length + n + 1), t.splice(n, 0, 1), $(e, t);
|
|
1963
1963
|
}
|
|
1964
|
-
function
|
|
1964
|
+
function Xr(e, n) {
|
|
1965
1965
|
return K(() => {
|
|
1966
1966
|
if (e.shape.length !== 2)
|
|
1967
1967
|
throw new A(`repeat() expects a rank-2 tensor, but received a rank-${e.shape.length} tensor.`);
|
|
@@ -2131,7 +2131,7 @@ function ro(e, n, t, s) {
|
|
|
2131
2131
|
}
|
|
2132
2132
|
}
|
|
2133
2133
|
function oo(e, n, t) {
|
|
2134
|
-
return K(() => (Array.isArray(n) ? n = B(n, "int32") : n = C(n, "int32"),
|
|
2134
|
+
return K(() => (Array.isArray(n) ? n = B(n, "int32") : n = C(n, "int32"), Xn(e, n, t)));
|
|
2135
2135
|
}
|
|
2136
2136
|
function ao(e) {
|
|
2137
2137
|
return I(e, e);
|
|
@@ -2171,7 +2171,7 @@ function uo(e) {
|
|
|
2171
2171
|
return K(() => L(e, U(zn(e), 1)));
|
|
2172
2172
|
}
|
|
2173
2173
|
function lo(e, n, t, s) {
|
|
2174
|
-
return K(() =>
|
|
2174
|
+
return K(() => Zn(e, n, t, s));
|
|
2175
2175
|
}
|
|
2176
2176
|
function po(e) {
|
|
2177
2177
|
return K(() => {
|
|
@@ -2200,8 +2200,8 @@ export {
|
|
|
2200
2200
|
ie as N,
|
|
2201
2201
|
ao as O,
|
|
2202
2202
|
Ge as P,
|
|
2203
|
-
|
|
2204
|
-
|
|
2203
|
+
Zr as Q,
|
|
2204
|
+
Ze as R,
|
|
2205
2205
|
Yt as S,
|
|
2206
2206
|
Dr as T,
|
|
2207
2207
|
Pr as U,
|
|
@@ -2240,7 +2240,7 @@ export {
|
|
|
2240
2240
|
lo as ap,
|
|
2241
2241
|
no as aq,
|
|
2242
2242
|
Qr as ar,
|
|
2243
|
-
|
|
2243
|
+
Xr as as,
|
|
2244
2244
|
Lr as at,
|
|
2245
2245
|
_r as au,
|
|
2246
2246
|
es as b,
|
|
@@ -2258,7 +2258,7 @@ export {
|
|
|
2258
2258
|
Sr as n,
|
|
2259
2259
|
Tr as o,
|
|
2260
2260
|
Vr as p,
|
|
2261
|
-
|
|
2261
|
+
Zt as q,
|
|
2262
2262
|
so as r,
|
|
2263
2263
|
ts as s,
|
|
2264
2264
|
Nr as t,
|
package/dist/training/AdamExt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as r, b as c, f as h, s as g, e as o } from "../index-
|
|
1
|
+
import { A as r, b as c, f as h, s as g, e as o } from "../index--6vO-cOz.js";
|
|
2
2
|
class u extends r {
|
|
3
3
|
constructor(t, e, s, a, i) {
|
|
4
4
|
super(t, e, s, a), this.config = i, this.startLearningRate = t;
|