@genai-fi/nanogpt 0.6.0 → 0.6.2
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 +7 -7
- package/dist/NanoGPTModel.js +70 -121
- package/dist/RealDiv-BYViZwhN.js +540 -0
- package/dist/Reshape-t7Kcikjk.js +127 -0
- package/dist/TeachableLLM.d.ts +2 -0
- package/dist/TeachableLLM.js +34 -27
- package/dist/{TiedEmbedding-BhxWO8QR.js → TiedEmbedding-9WeDwvjO.js} +12 -13
- package/dist/{axis_util-D17qZRQm.js → axis_util-Bu4h7XWV.js} +14 -12
- package/dist/{broadcast_to-BMQLjvt_.js → broadcast_to-DARN-DBD.js} +2 -2
- package/dist/{concat-DhZfF1GY.js → concat-5aPGqw3Z.js} +3 -3
- package/dist/{dataset-oilnemHf.js → dataset-pgqp-YfL.js} +3 -3
- package/dist/{dropout-CrMQPCeG.js → dropout-Bciw46HT.js} +7 -7
- package/dist/{gather-DZCMHZuN.js → gather-DjyCjmOD.js} +1 -1
- package/dist/gpgpu_math-CNslybmD.js +3115 -0
- package/dist/{index-bMBtI-WR.js → index-BAzbokzv.js} +846 -649
- package/dist/{kernel_funcs_utils-CNmjLWnB.js → kernel_funcs_utils-CUxJCg0g.js} +232 -138
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/MLP.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +13 -33
- package/dist/layers/TiedEmbedding.js +6 -7
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/load.d.ts +13 -0
- package/dist/loader/load.js +27 -0
- package/dist/loader/loadHF.d.ts +7 -0
- package/dist/loader/loadHF.js +22 -0
- package/dist/{utilities/load.d.ts → loader/loadTransformers.d.ts} +11 -11
- package/dist/loader/loadTransformers.js +28 -0
- package/dist/loader/newZipLoad.d.ts +8 -0
- package/dist/loader/newZipLoad.js +21 -0
- package/dist/loader/oldZipLoad.d.ts +7 -0
- package/dist/loader/oldZipLoad.js +76 -0
- package/dist/{log_sum_exp-BHdkCb4s.js → log_sum_exp-YEo2h3gb.js} +14 -14
- package/dist/main.js +23 -20
- package/dist/{mat_mul-BsrLfy81.js → mat_mul-7121rsJk.js} +1 -1
- package/dist/{max-DechV4Bc.js → max-DtlIuVeW.js} +1 -1
- package/dist/mulmat_packed_gpu-D4nKF7Je.js +71 -0
- package/dist/{norm-B9hWHZH1.js → norm-CzltS9Fz.js} +16 -16
- package/dist/{ones-g0K8jVwm.js → ones-BBlSRqn1.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 +6 -6
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +9 -9
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.js +1 -1
- package/dist/ops/cpu/matMulMul.js +1 -1
- package/dist/ops/cpu/mulDropout.js +1 -1
- package/dist/ops/cpu/normRMS.js +1 -1
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +17 -48
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +1 -1
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +4 -4
- package/dist/ops/grads/gelu.js +1 -1
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/normRMS.js +1 -1
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/rope.js +8 -4
- 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 +29 -560
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +3 -3
- package/dist/ops/webgl/matMulGelu.js +46 -113
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.js +2 -2
- 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/{ops-Mv7Ta72x.js → ops-C0sQEcPw.js} +117 -109
- package/dist/{random_width-BBAWzDym.js → random_width-DWzaOgrn.js} +6925 -6291
- package/dist/{range-DMaG9A3G.js → range-DYsrnfiy.js} +1 -1
- package/dist/{gpgpu_math-Ctc31slO.js → reciprocal-CJQeasVa.js} +7 -5
- package/dist/register_all_kernels-BfFCQAqs.js +21397 -0
- package/dist/{reshape-T4yDEqoF.js → reshape-krWGKraP.js} +1 -1
- package/dist/scatter_nd_util-93ln7Hut.js +46 -0
- package/dist/selu_util-sntGesxr.js +740 -0
- package/dist/{shared-XNAoXhOa.js → shared-Ca6iDobD.js} +1462 -1089
- package/dist/{sin-EEhbrRO_.js → sin-D_h-qCSx.js} +1 -1
- package/dist/{softmax-B2_IKPDR.js → softmax-fsdtf6JC.js} +1 -1
- package/dist/{split-dcks18H1.js → split-eiktj-6L.js} +1 -1
- package/dist/{stack-lpJ5kYvE.js → stack-dfEEz2OY.js} +2 -2
- package/dist/{sum-CutF5lj2.js → sum-BE_Irnim.js} +1 -1
- package/dist/{tensor-C15NA2LA.js → tensor-Xyi595sG.js} +1 -1
- package/dist/{tensor2d-DZ_e5eKM.js → tensor2d-CPEkynbH.js} +1 -1
- 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 +3 -3
- package/dist/training/sparseCrossEntropy.js +5 -5
- package/dist/utilities/dummy.d.ts +6 -0
- package/dist/utilities/dummy.js +31 -10
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/profile.d.ts +5 -0
- package/dist/utilities/profile.js +10 -7
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/save.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-CdRKKp8x.js → variable-wSS22xj5.js} +1 -1
- package/dist/{zeros-CAbHfODe.js → zeros-YJDE7oRb.js} +4 -4
- package/package.json +2 -8
- package/dist/Reshape-CLOrdpve.js +0 -212
- package/dist/slice_util-Ddk0uxGJ.js +0 -49
- package/dist/tfjs_backend-BDb8r9qx.js +0 -1010
- package/dist/utilities/load.js +0 -99
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { u as
|
|
1
|
+
import { h as B, g as G, ak as K, _ as W, al as z, am as V, ac as N, an as F, u as S } from "./index-BAzbokzv.js";
|
|
2
|
+
import { u as O, f as Y, h as v } from "./gpgpu_math-CNslybmD.js";
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -16,15 +16,19 @@ import { u as g } from "./gpgpu_math-Ctc31slO.js";
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
* =============================================================================
|
|
18
18
|
*/
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
function H(t, e) {
|
|
20
|
+
return ["x", "y", "z", "w", "u", "v"].slice(0, e).map((s) => `${t}.${s}`);
|
|
21
|
+
}
|
|
22
|
+
function Z(t, e) {
|
|
23
|
+
return e === 1 ? [t] : H(t, e);
|
|
25
24
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
25
|
+
function ie(t, e) {
|
|
26
|
+
if (t === 1)
|
|
27
|
+
return "rc";
|
|
28
|
+
let s = "";
|
|
29
|
+
for (let r = 0; r < t; r++)
|
|
30
|
+
s += e[r], r < t - 1 && (s += ",");
|
|
31
|
+
return s;
|
|
28
32
|
}
|
|
29
33
|
/**
|
|
30
34
|
* @license
|
|
@@ -42,21 +46,27 @@ function H(t) {
|
|
|
42
46
|
* limitations under the License.
|
|
43
47
|
* =============================================================================
|
|
44
48
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
class q {
|
|
50
|
+
constructor(e, s) {
|
|
51
|
+
this.variableNames = ["A"], this.outputShape = e, this.enableShapeUniforms = O(this.outputShape.length), this.userCode = `
|
|
52
|
+
float unaryOperation(float x) {
|
|
53
|
+
${s}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void main() {
|
|
57
|
+
float x = getAAtOutCoords();
|
|
58
|
+
float y = unaryOperation(x);
|
|
59
|
+
|
|
60
|
+
setOutput(y);
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
59
64
|
}
|
|
65
|
+
const T = "if (isnan(x)) return x;", M = "return x;", pe = "return abs(x);", j = "return (x >= 0.0) ? x : (exp(x) - 1.0);", J = T + `
|
|
66
|
+
return (x < 0.0) ? 0.0 : x;
|
|
67
|
+
`, Q = T + `
|
|
68
|
+
return (x < 0.0) ? 0.0 : min(6.0, x);
|
|
69
|
+
`, de = "return x;", X = "return 1.0 / (1.0 + exp(-1.0 * x));";
|
|
60
70
|
/**
|
|
61
71
|
* @license
|
|
62
72
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -73,11 +83,51 @@ function R(t) {
|
|
|
73
83
|
* limitations under the License.
|
|
74
84
|
* =============================================================================
|
|
75
85
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
const ee = "return x;", te = `
|
|
87
|
+
vec4 result;
|
|
88
|
+
|
|
89
|
+
result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);
|
|
90
|
+
result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);
|
|
91
|
+
result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);
|
|
92
|
+
result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
`, se = `
|
|
96
|
+
vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));
|
|
97
|
+
bvec4 isNaN = isnan(x);
|
|
98
|
+
|
|
99
|
+
result.r = isNaN.r ? x.r : result.r;
|
|
100
|
+
result.g = isNaN.g ? x.g : result.g;
|
|
101
|
+
result.b = isNaN.b ? x.b : result.b;
|
|
102
|
+
result.a = isNaN.a ? x.a : result.a;
|
|
103
|
+
|
|
104
|
+
return result;
|
|
105
|
+
`, ae = `
|
|
106
|
+
vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));
|
|
107
|
+
bvec4 isNaN = isnan(x);
|
|
108
|
+
|
|
109
|
+
result.r = isNaN.r ? x.r : result.r;
|
|
110
|
+
result.g = isNaN.g ? x.g : result.g;
|
|
111
|
+
result.b = isNaN.b ? x.b : result.b;
|
|
112
|
+
result.a = isNaN.a ? x.a : result.a;
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
`, re = "return 1.0 / (1.0 + exp(-1.0 * x));";
|
|
116
|
+
class ne {
|
|
117
|
+
constructor(e, s) {
|
|
118
|
+
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e, this.enableShapeUniforms = O(this.outputShape.length), this.userCode = `
|
|
119
|
+
vec4 unaryOperation(vec4 x) {
|
|
120
|
+
${s}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
void main() {
|
|
124
|
+
vec4 x = getAAtOutCoords();
|
|
125
|
+
vec4 y = unaryOperation(x);
|
|
126
|
+
|
|
127
|
+
setOutput(y);
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
}
|
|
81
131
|
}
|
|
82
132
|
/**
|
|
83
133
|
* @license
|
|
@@ -95,9 +145,13 @@ function k(t, e) {
|
|
|
95
145
|
* limitations under the License.
|
|
96
146
|
* =============================================================================
|
|
97
147
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
148
|
+
const he = `
|
|
149
|
+
if (isnan(a)) return a;
|
|
150
|
+
if (isnan(b)) return b;
|
|
151
|
+
`;
|
|
152
|
+
class b {
|
|
153
|
+
constructor(e, s, r) {
|
|
154
|
+
this.variableNames = ["A", "B"], this.outputShape = B(s, r), this.enableShapeUniforms = O(this.outputShape.length), this.userCode = `
|
|
101
155
|
float binaryOperation(float a, float b) {
|
|
102
156
|
${e}
|
|
103
157
|
}
|
|
@@ -126,46 +180,52 @@ class C {
|
|
|
126
180
|
* limitations under the License.
|
|
127
181
|
* =============================================================================
|
|
128
182
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
183
|
+
const fe = `
|
|
184
|
+
result.r = isNaN.r ? NAN : result.r;
|
|
185
|
+
result.g = isNaN.g ? NAN : result.g;
|
|
186
|
+
result.b = isNaN.b ? NAN : result.b;
|
|
187
|
+
result.a = isNaN.a ? NAN : result.a;
|
|
188
|
+
`;
|
|
189
|
+
class E {
|
|
190
|
+
constructor(e, s, r, u = !1) {
|
|
191
|
+
this.variableNames = ["A", "B"], this.supportsBroadcasting = !0, this.packedInputs = !0, this.packedOutput = !0, this.outputShape = B(s, r);
|
|
192
|
+
const n = this.outputShape.length;
|
|
193
|
+
this.enableShapeUniforms = O(n);
|
|
194
|
+
let o = "";
|
|
195
|
+
if (u)
|
|
196
|
+
if (n === 0 || G(this.outputShape) === 1)
|
|
197
|
+
o = `
|
|
138
198
|
result.y = 0.;
|
|
139
199
|
result.z = 0.;
|
|
140
200
|
result.w = 0.;
|
|
141
201
|
`;
|
|
142
|
-
else if (
|
|
143
|
-
${
|
|
144
|
-
`,
|
|
145
|
-
this.enableShapeUniforms ?
|
|
202
|
+
else if (o = `
|
|
203
|
+
${Y(n)} coords = getOutputCoords();
|
|
204
|
+
`, n === 1)
|
|
205
|
+
this.enableShapeUniforms ? o += `
|
|
146
206
|
result.y = (coords + 1) >= outShape ? 0. : result.y;
|
|
147
207
|
result.z = 0.;
|
|
148
208
|
result.w = 0.;
|
|
149
|
-
` :
|
|
209
|
+
` : o += `
|
|
150
210
|
result.y = (coords + 1) >= ${this.outputShape[0]} ? 0. : result.y;
|
|
151
211
|
result.z = 0.;
|
|
152
212
|
result.w = 0.;
|
|
153
213
|
`;
|
|
154
214
|
else {
|
|
155
|
-
const
|
|
156
|
-
this.enableShapeUniforms ?
|
|
215
|
+
const a = Z("coords", n);
|
|
216
|
+
this.enableShapeUniforms ? o += `
|
|
157
217
|
bool nextRowOutOfBounds =
|
|
158
|
-
(${
|
|
218
|
+
(${a[n - 2]} + 1) >= outShape[${n} - 2];
|
|
159
219
|
bool nextColOutOfBounds =
|
|
160
|
-
(${
|
|
220
|
+
(${a[n - 1]} + 1) >= outShape[${n} - 1];
|
|
161
221
|
result.y = nextColOutOfBounds ? 0. : result.y;
|
|
162
222
|
result.z = nextRowOutOfBounds ? 0. : result.z;
|
|
163
223
|
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
|
|
164
|
-
` :
|
|
224
|
+
` : o += `
|
|
165
225
|
bool nextRowOutOfBounds =
|
|
166
|
-
(${
|
|
226
|
+
(${a[n - 2]} + 1) >= ${this.outputShape[n - 2]};
|
|
167
227
|
bool nextColOutOfBounds =
|
|
168
|
-
(${
|
|
228
|
+
(${a[n - 1]} + 1) >= ${this.outputShape[n - 1]};
|
|
169
229
|
result.y = nextColOutOfBounds ? 0. : result.y;
|
|
170
230
|
result.z = nextRowOutOfBounds ? 0. : result.z;
|
|
171
231
|
result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;
|
|
@@ -181,7 +241,7 @@ class z {
|
|
|
181
241
|
vec4 b = getBAtOutCoords();
|
|
182
242
|
|
|
183
243
|
vec4 result = binaryOperation(a, b);
|
|
184
|
-
${
|
|
244
|
+
${o}
|
|
185
245
|
|
|
186
246
|
setOutput(result);
|
|
187
247
|
}
|
|
@@ -204,10 +264,15 @@ class z {
|
|
|
204
264
|
* limitations under the License.
|
|
205
265
|
* =============================================================================
|
|
206
266
|
*/
|
|
207
|
-
function
|
|
208
|
-
const { inputs: e, backend:
|
|
209
|
-
return
|
|
267
|
+
function P(t) {
|
|
268
|
+
const { inputs: e, backend: s } = t, { x: r } = e;
|
|
269
|
+
return s.incRef(r.dataId), { dataId: r.dataId, shape: r.shape, dtype: r.dtype };
|
|
210
270
|
}
|
|
271
|
+
const xe = {
|
|
272
|
+
kernelName: K,
|
|
273
|
+
backendName: "webgl",
|
|
274
|
+
kernelFunc: P
|
|
275
|
+
};
|
|
211
276
|
/**
|
|
212
277
|
* @license
|
|
213
278
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -224,13 +289,18 @@ function A(t) {
|
|
|
224
289
|
* limitations under the License.
|
|
225
290
|
* =============================================================================
|
|
226
291
|
*/
|
|
227
|
-
function
|
|
228
|
-
const { inputs: e, backend:
|
|
229
|
-
return
|
|
292
|
+
function L(t) {
|
|
293
|
+
const { inputs: e, backend: s } = t, { real: r, imag: u } = e, n = s.makeTensorInfo(r.shape, "complex64"), o = s.texData.get(n.dataId), i = P({ inputs: { x: r }, backend: s }), a = P({ inputs: { x: u }, backend: s });
|
|
294
|
+
return o.complexTensorInfos = { real: i, imag: a }, n;
|
|
230
295
|
}
|
|
296
|
+
const ge = {
|
|
297
|
+
kernelName: W,
|
|
298
|
+
backendName: "webgl",
|
|
299
|
+
kernelFunc: L
|
|
300
|
+
};
|
|
231
301
|
/**
|
|
232
302
|
* @license
|
|
233
|
-
* Copyright
|
|
303
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
234
304
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
235
305
|
* you may not use this file except in compliance with the License.
|
|
236
306
|
* You may obtain a copy of the License at
|
|
@@ -244,26 +314,22 @@ function G(t) {
|
|
|
244
314
|
* limitations under the License.
|
|
245
315
|
* =============================================================================
|
|
246
316
|
*/
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
void main() {
|
|
255
|
-
float x = getAAtOutCoords();
|
|
256
|
-
float y = unaryOperation(x);
|
|
257
|
-
|
|
258
|
-
setOutput(y);
|
|
259
|
-
}
|
|
260
|
-
`;
|
|
261
|
-
}
|
|
317
|
+
const w = "return (a < 0.) ? b * a : a;", k = `
|
|
318
|
+
vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
|
|
319
|
+
return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
|
|
320
|
+
`;
|
|
321
|
+
function oe(t) {
|
|
322
|
+
const { inputs: e, backend: s, attrs: r } = t, { x: u } = e, { alpha: n } = r, o = s.makeTensorInfo([], "float32", V(n, "float32")), i = N().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new E(k, u.shape, o.shape) : new b(w, u.shape, o.shape), a = s.runWebGLProgram(i, [u, o], "float32");
|
|
323
|
+
return s.disposeIntermediateTensorInfo(o), a;
|
|
262
324
|
}
|
|
263
|
-
const
|
|
325
|
+
const me = {
|
|
326
|
+
kernelName: z,
|
|
327
|
+
backendName: "webgl",
|
|
328
|
+
kernelFunc: oe
|
|
329
|
+
};
|
|
264
330
|
/**
|
|
265
331
|
* @license
|
|
266
|
-
* Copyright
|
|
332
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
267
333
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
268
334
|
* you may not use this file except in compliance with the License.
|
|
269
335
|
* You may obtain a copy of the License at
|
|
@@ -277,22 +343,19 @@ const K = "if (isnan(x)) return x;";
|
|
|
277
343
|
* limitations under the License.
|
|
278
344
|
* =============================================================================
|
|
279
345
|
*/
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
void main() {
|
|
288
|
-
vec4 x = getAAtOutCoords();
|
|
289
|
-
vec4 y = unaryOperation(x);
|
|
290
|
-
|
|
291
|
-
setOutput(y);
|
|
292
|
-
}
|
|
293
|
-
`;
|
|
294
|
-
}
|
|
346
|
+
const R = "return (a < 0.) ? b * a : a;", U = `
|
|
347
|
+
vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));
|
|
348
|
+
return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);
|
|
349
|
+
`;
|
|
350
|
+
function ue(t) {
|
|
351
|
+
const { inputs: e, backend: s } = t, { x: r, alpha: u } = e, n = N().getBool("WEBGL_PACK_BINARY_OPERATIONS") ? new E(U, r.shape, u.shape) : new b(R, r.shape, u.shape);
|
|
352
|
+
return s.runWebGLProgram(n, [r, u], "float32");
|
|
295
353
|
}
|
|
354
|
+
const be = {
|
|
355
|
+
kernelName: F,
|
|
356
|
+
backendName: "webgl",
|
|
357
|
+
kernelFunc: ue
|
|
358
|
+
};
|
|
296
359
|
/**
|
|
297
360
|
* @license
|
|
298
361
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -309,63 +372,94 @@ class L {
|
|
|
309
372
|
* limitations under the License.
|
|
310
373
|
* =============================================================================
|
|
311
374
|
*/
|
|
312
|
-
const
|
|
313
|
-
function
|
|
314
|
-
return ({ inputs:
|
|
315
|
-
const { x:
|
|
316
|
-
if (
|
|
317
|
-
const
|
|
318
|
-
return
|
|
375
|
+
const Ne = "if (isnan(x)) return x;";
|
|
376
|
+
function Oe({ opSnippet: t, packedOpSnippet: e, cpuKernelImpl: s, dtype: r }) {
|
|
377
|
+
return ({ inputs: u, backend: n }) => {
|
|
378
|
+
const { x: o } = u, i = n, a = r || o.dtype;
|
|
379
|
+
if (i.shouldExecuteOnCPU([o]) && s != null) {
|
|
380
|
+
const d = i.texData.get(o.dataId), y = s(d.values, a);
|
|
381
|
+
return i.makeTensorInfo(o.shape, a, y);
|
|
319
382
|
}
|
|
320
|
-
const
|
|
321
|
-
let
|
|
322
|
-
return
|
|
383
|
+
const c = N().getBool("WEBGL_PACK_UNARY_OPERATIONS") && e != null;
|
|
384
|
+
let l;
|
|
385
|
+
return c ? l = new ne(o.shape, e) : l = new q(o.shape, t), i.runWebGLProgram(l, [o], a);
|
|
323
386
|
};
|
|
324
387
|
}
|
|
325
|
-
function
|
|
326
|
-
return ({ inputs:
|
|
327
|
-
const { a
|
|
328
|
-
if (
|
|
329
|
-
const h =
|
|
388
|
+
function ye({ opSnippet: t, packedOpSnippet: e, checkOutOfBounds: s = !1, supportsComplex: r = !1, cpuKernelImpl: u, dtype: n }) {
|
|
389
|
+
return ({ inputs: o, backend: i }) => {
|
|
390
|
+
const { a, b: c } = o, l = i;
|
|
391
|
+
if (r && a.dtype === "complex64") {
|
|
392
|
+
const h = l.texData.get(a.dataId), f = l.texData.get(c.dataId), [g, m] = [
|
|
330
393
|
[h.complexTensorInfos.real, f.complexTensorInfos.real],
|
|
331
394
|
[h.complexTensorInfos.imag, f.complexTensorInfos.imag]
|
|
332
|
-
].map((
|
|
333
|
-
const [p,
|
|
395
|
+
].map((C) => {
|
|
396
|
+
const [p, x] = C, $ = {
|
|
334
397
|
dataId: p.dataId,
|
|
335
398
|
dtype: p.dtype,
|
|
336
|
-
shape:
|
|
337
|
-
},
|
|
338
|
-
dataId:
|
|
339
|
-
dtype:
|
|
340
|
-
shape:
|
|
341
|
-
},
|
|
342
|
-
return
|
|
343
|
-
}),
|
|
344
|
-
return
|
|
399
|
+
shape: a.shape
|
|
400
|
+
}, _ = {
|
|
401
|
+
dataId: x.dataId,
|
|
402
|
+
dtype: x.dtype,
|
|
403
|
+
shape: c.shape
|
|
404
|
+
}, D = new b(t, a.shape, c.shape);
|
|
405
|
+
return l.runWebGLProgram(D, [$, _], S(p.dtype, x.dtype));
|
|
406
|
+
}), A = L({ inputs: { real: g, imag: m }, backend: l });
|
|
407
|
+
return l.disposeIntermediateTensorInfo(g), l.disposeIntermediateTensorInfo(m), A;
|
|
345
408
|
}
|
|
346
|
-
const
|
|
347
|
-
if ((
|
|
348
|
-
const h =
|
|
409
|
+
const d = n || S(a.dtype, c.dtype);
|
|
410
|
+
if ((a.dtype === "string" || c.dtype === "string" || l.shouldExecuteOnCPU([a, c])) && u != null) {
|
|
411
|
+
const h = l.texData.get(a.dataId).values, f = l.texData.get(c.dataId).values, g = a.dtype === "string" ? (
|
|
349
412
|
// tslint:disable-next-line: no-any
|
|
350
|
-
|
|
351
|
-
) : h,
|
|
413
|
+
v(h)
|
|
414
|
+
) : h, m = a.dtype === "string" ? (
|
|
352
415
|
// tslint:disable-next-line: no-any
|
|
353
|
-
|
|
354
|
-
) : f, [
|
|
355
|
-
return
|
|
416
|
+
v(f)
|
|
417
|
+
) : f, [A, C] = u(a.shape, c.shape, g, m, d), p = l.makeTensorInfo(C, d), x = l.texData.get(p.dataId);
|
|
418
|
+
return x.values = A, p;
|
|
356
419
|
}
|
|
357
|
-
const
|
|
358
|
-
let
|
|
359
|
-
return
|
|
420
|
+
const y = N().getBool("WEBGL_PACK_BINARY_OPERATIONS") && e != null;
|
|
421
|
+
let I;
|
|
422
|
+
return y ? I = new E(e, a.shape, c.shape, s) : I = new b(t, a.shape, c.shape), l.runWebGLProgram(I, [a, c], d);
|
|
360
423
|
};
|
|
361
424
|
}
|
|
425
|
+
function Ie(t, e = !1) {
|
|
426
|
+
if (t === "linear")
|
|
427
|
+
return e ? ee : M;
|
|
428
|
+
if (t === "relu")
|
|
429
|
+
return e ? se : J;
|
|
430
|
+
if (t === "elu")
|
|
431
|
+
return e ? te : j;
|
|
432
|
+
if (t === "relu6")
|
|
433
|
+
return e ? ae : Q;
|
|
434
|
+
if (t === "prelu")
|
|
435
|
+
return e ? U : R;
|
|
436
|
+
if (t === "leakyrelu")
|
|
437
|
+
return e ? k : w;
|
|
438
|
+
if (t === "sigmoid")
|
|
439
|
+
return e ? re : X;
|
|
440
|
+
throw new Error(`Activation ${t} has not been implemented for the WebGL backend.`);
|
|
441
|
+
}
|
|
362
442
|
export {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
443
|
+
pe as A,
|
|
444
|
+
E as B,
|
|
445
|
+
T as C,
|
|
446
|
+
ne as U,
|
|
447
|
+
Z as a,
|
|
448
|
+
ye as b,
|
|
449
|
+
ie as c,
|
|
450
|
+
de as d,
|
|
451
|
+
q as e,
|
|
452
|
+
L as f,
|
|
453
|
+
H as g,
|
|
454
|
+
b as h,
|
|
455
|
+
P as i,
|
|
456
|
+
he as j,
|
|
457
|
+
fe as k,
|
|
458
|
+
Ne as l,
|
|
459
|
+
Ie as m,
|
|
460
|
+
ge as n,
|
|
461
|
+
xe as o,
|
|
462
|
+
me as p,
|
|
463
|
+
be as q,
|
|
464
|
+
Oe as u
|
|
371
465
|
};
|
package/dist/layers/BaseLayer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as g,
|
|
2
|
-
import { v as _ } from "../variable-
|
|
1
|
+
import { T as g, l as p, e as o, n as v } from "../index-BAzbokzv.js";
|
|
2
|
+
import { v as _ } from "../variable-wSS22xj5.js";
|
|
3
3
|
class M {
|
|
4
4
|
parent;
|
|
5
5
|
config;
|
|
@@ -3,13 +3,13 @@ import O from "./BaseLayer.js";
|
|
|
3
3
|
import { qkv as P } from "../ops/qkv.js";
|
|
4
4
|
import { rope as v } from "../ops/rope.js";
|
|
5
5
|
import { appendCache as V } from "../ops/appendCache.js";
|
|
6
|
-
import {
|
|
6
|
+
import { k as c, t as C } from "../index-BAzbokzv.js";
|
|
7
7
|
import { fusedSoftmax as T } from "../ops/fusedSoftmax.js";
|
|
8
|
-
import { d as y } from "../
|
|
9
|
-
import { v as b } from "../variable-
|
|
10
|
-
import { r as k, d as L } from "../dropout-
|
|
11
|
-
import { r as N } from "../reshape-
|
|
12
|
-
import { m as R } from "../mat_mul-
|
|
8
|
+
import { d as y } from "../random_width-DWzaOgrn.js";
|
|
9
|
+
import { v as b } from "../variable-wSS22xj5.js";
|
|
10
|
+
import { r as k, d as L } from "../dropout-Bciw46HT.js";
|
|
11
|
+
import { r as N } from "../reshape-krWGKraP.js";
|
|
12
|
+
import { m as R } from "../mat_mul-7121rsJk.js";
|
|
13
13
|
class $ extends O {
|
|
14
14
|
divisor;
|
|
15
15
|
index;
|
package/dist/layers/MLP.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as l } from "../index-
|
|
1
|
+
import { t as l } from "../index-BAzbokzv.js";
|
|
2
2
|
import u from "./BaseLayer.js";
|
|
3
3
|
import { matMulGelu as M } from "../ops/matMulGelu.js";
|
|
4
|
-
import { v as o } from "../variable-
|
|
5
|
-
import { r as h, d as f } from "../dropout-
|
|
6
|
-
import { r as d } from "../reshape-
|
|
7
|
-
import { m as c } from "../mat_mul-
|
|
4
|
+
import { v as o } from "../variable-wSS22xj5.js";
|
|
5
|
+
import { r as h, d as f } from "../dropout-Bciw46HT.js";
|
|
6
|
+
import { r as d } from "../reshape-krWGKraP.js";
|
|
7
|
+
import { m as c } from "../mat_mul-7121rsJk.js";
|
|
8
8
|
class V extends u {
|
|
9
9
|
index;
|
|
10
10
|
hiddenUnits;
|
package/dist/layers/RMSNorm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as s } from "../index-
|
|
1
|
+
import { t as s } from "../index-BAzbokzv.js";
|
|
2
2
|
import e from "./BaseLayer.js";
|
|
3
3
|
import { normRMS as a } from "../ops/normRMS.js";
|
|
4
|
-
import { v as i } from "../variable-
|
|
5
|
-
import { o as m } from "../ones-
|
|
4
|
+
import { v as i } from "../variable-wSS22xj5.js";
|
|
5
|
+
import { o as m } from "../ones-BBlSRqn1.js";
|
|
6
6
|
class f extends e {
|
|
7
7
|
GAMMA;
|
|
8
8
|
constructor(r, t = "", o) {
|
package/dist/layers/RoPECache.js
CHANGED
|
@@ -1,36 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
* =============================================================================
|
|
19
|
-
*/
|
|
20
|
-
function x(r) {
|
|
21
|
-
const s = { x: f(r, "x", "reciprocal") };
|
|
22
|
-
return l.runKernel(m, s);
|
|
23
|
-
}
|
|
24
|
-
const S = /* @__PURE__ */ c({ reciprocal_: x });
|
|
25
|
-
class y {
|
|
1
|
+
import { s as t, j as h, t as n, k as p } from "../index-BAzbokzv.js";
|
|
2
|
+
import { r as c } from "../reciprocal-CJQeasVa.js";
|
|
3
|
+
import { c as f, s as m } from "../sin-D_h-qCSx.js";
|
|
4
|
+
import { r as a } from "../range-DYsrnfiy.js";
|
|
5
|
+
class D {
|
|
26
6
|
constructor(o) {
|
|
27
7
|
this.config = o;
|
|
28
|
-
const
|
|
29
|
-
if (this.rotaryDim =
|
|
8
|
+
const e = this.config.nEmbed / this.config.nHead;
|
|
9
|
+
if (this.rotaryDim = e, this.rotaryDim % 2 !== 0)
|
|
30
10
|
throw new Error("rotaryDim must be even");
|
|
31
11
|
this.ropeBase = 1e4;
|
|
32
|
-
const i =
|
|
33
|
-
this.ropeInvFreq =
|
|
12
|
+
const i = a(0, this.rotaryDim, 2, "float32"), s = i.div(t(this.rotaryDim, "float32")), r = h(t(this.ropeBase, "float32"), s);
|
|
13
|
+
this.ropeInvFreq = c(r), s.dispose(), r.dispose(), i.dispose(), this.config.useRope === !1 ? (this.ropeCos = null, this.ropeSin = null, this.ropeCacheLen = 0) : n(() => {
|
|
34
14
|
this.ensureRopeCache(this.config.blockSize * 4);
|
|
35
15
|
});
|
|
36
16
|
}
|
|
@@ -43,11 +23,11 @@ class y {
|
|
|
43
23
|
// [cacheLen, rotaryDim/2]
|
|
44
24
|
ropeCacheLen = 0;
|
|
45
25
|
ensureRopeCache(o) {
|
|
46
|
-
|
|
26
|
+
n(() => {
|
|
47
27
|
if (o <= this.ropeCacheLen) return;
|
|
48
28
|
this.ropeCos && this.ropeCos.dispose(), this.ropeSin && this.ropeSin.dispose();
|
|
49
|
-
const
|
|
50
|
-
this.ropeCos =
|
|
29
|
+
const e = Math.max(o, this.ropeCacheLen + this.config.blockSize * 4), s = a(0, e, 1, "float32").expandDims(1).mul(this.ropeInvFreq.expandDims(0));
|
|
30
|
+
this.ropeCos = p(f(s).expandDims(-1)), this.ropeSin = p(m(s).expandDims(-1)), this.ropeCacheLen = e;
|
|
51
31
|
});
|
|
52
32
|
}
|
|
53
33
|
getCos() {
|
|
@@ -61,5 +41,5 @@ class y {
|
|
|
61
41
|
}
|
|
62
42
|
}
|
|
63
43
|
export {
|
|
64
|
-
|
|
44
|
+
D as default
|
|
65
45
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "../random_width-
|
|
2
|
-
import "../index-
|
|
3
|
-
import { T as
|
|
4
|
-
import "../tfjs_backend-BDb8r9qx.js";
|
|
1
|
+
import "../random_width-DWzaOgrn.js";
|
|
2
|
+
import "../index-BAzbokzv.js";
|
|
3
|
+
import { T as e } from "../TiedEmbedding-9WeDwvjO.js";
|
|
5
4
|
import "./BaseLayer.js";
|
|
6
|
-
import "../variable-
|
|
7
|
-
import "../gather-
|
|
5
|
+
import "../variable-wSS22xj5.js";
|
|
6
|
+
import "../gather-DjyCjmOD.js";
|
|
8
7
|
export {
|
|
9
|
-
|
|
8
|
+
e as default
|
|
10
9
|
};
|
|
@@ -2,7 +2,7 @@ import l from "./CausalSelfAttention.js";
|
|
|
2
2
|
import r from "./MLP.js";
|
|
3
3
|
import o from "./RMSNorm.js";
|
|
4
4
|
import d from "./BaseLayer.js";
|
|
5
|
-
import { t as p } from "../index-
|
|
5
|
+
import { t as p } from "../index-BAzbokzv.js";
|
|
6
6
|
class k extends d {
|
|
7
7
|
ln1;
|
|
8
8
|
attn;
|