@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.
Files changed (121) hide show
  1. package/dist/Generator.js +7 -7
  2. package/dist/NanoGPTModel.js +70 -121
  3. package/dist/RealDiv-BYViZwhN.js +540 -0
  4. package/dist/Reshape-t7Kcikjk.js +127 -0
  5. package/dist/TeachableLLM.d.ts +2 -0
  6. package/dist/TeachableLLM.js +34 -27
  7. package/dist/{TiedEmbedding-BhxWO8QR.js → TiedEmbedding-9WeDwvjO.js} +12 -13
  8. package/dist/{axis_util-D17qZRQm.js → axis_util-Bu4h7XWV.js} +14 -12
  9. package/dist/{broadcast_to-BMQLjvt_.js → broadcast_to-DARN-DBD.js} +2 -2
  10. package/dist/{concat-DhZfF1GY.js → concat-5aPGqw3Z.js} +3 -3
  11. package/dist/{dataset-oilnemHf.js → dataset-pgqp-YfL.js} +3 -3
  12. package/dist/{dropout-CrMQPCeG.js → dropout-Bciw46HT.js} +7 -7
  13. package/dist/{gather-DZCMHZuN.js → gather-DjyCjmOD.js} +1 -1
  14. package/dist/gpgpu_math-CNslybmD.js +3115 -0
  15. package/dist/{index-bMBtI-WR.js → index-BAzbokzv.js} +846 -649
  16. package/dist/{kernel_funcs_utils-CNmjLWnB.js → kernel_funcs_utils-CUxJCg0g.js} +232 -138
  17. package/dist/layers/BaseLayer.js +2 -2
  18. package/dist/layers/CausalSelfAttention.js +6 -6
  19. package/dist/layers/MLP.js +5 -5
  20. package/dist/layers/RMSNorm.js +3 -3
  21. package/dist/layers/RoPECache.js +13 -33
  22. package/dist/layers/TiedEmbedding.js +6 -7
  23. package/dist/layers/TransformerBlock.js +1 -1
  24. package/dist/loader/load.d.ts +13 -0
  25. package/dist/loader/load.js +27 -0
  26. package/dist/loader/loadHF.d.ts +7 -0
  27. package/dist/loader/loadHF.js +22 -0
  28. package/dist/{utilities/load.d.ts → loader/loadTransformers.d.ts} +11 -11
  29. package/dist/loader/loadTransformers.js +28 -0
  30. package/dist/loader/newZipLoad.d.ts +8 -0
  31. package/dist/loader/newZipLoad.js +21 -0
  32. package/dist/loader/oldZipLoad.d.ts +7 -0
  33. package/dist/loader/oldZipLoad.js +76 -0
  34. package/dist/{log_sum_exp-BHdkCb4s.js → log_sum_exp-YEo2h3gb.js} +14 -14
  35. package/dist/main.js +23 -20
  36. package/dist/{mat_mul-BsrLfy81.js → mat_mul-7121rsJk.js} +1 -1
  37. package/dist/{max-DechV4Bc.js → max-DtlIuVeW.js} +1 -1
  38. package/dist/mulmat_packed_gpu-D4nKF7Je.js +71 -0
  39. package/dist/{norm-B9hWHZH1.js → norm-CzltS9Fz.js} +16 -16
  40. package/dist/{ones-g0K8jVwm.js → ones-BBlSRqn1.js} +2 -2
  41. package/dist/ops/appendCache.js +3 -3
  42. package/dist/ops/attentionMask.js +1 -1
  43. package/dist/ops/cpu/appendCache.js +2 -2
  44. package/dist/ops/cpu/attentionMask.js +6 -6
  45. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  46. package/dist/ops/cpu/gatherSub.js +9 -9
  47. package/dist/ops/cpu/gelu.js +1 -1
  48. package/dist/ops/cpu/matMulGelu.js +1 -1
  49. package/dist/ops/cpu/matMulMul.js +1 -1
  50. package/dist/ops/cpu/mulDropout.js +1 -1
  51. package/dist/ops/cpu/normRMS.js +1 -1
  52. package/dist/ops/cpu/qkv.js +3 -3
  53. package/dist/ops/cpu/rope.js +5 -5
  54. package/dist/ops/cpu/scatterSub.js +17 -48
  55. package/dist/ops/fusedSoftmax.js +1 -1
  56. package/dist/ops/gatherSub.js +1 -1
  57. package/dist/ops/gelu.js +1 -1
  58. package/dist/ops/grads/attentionMask.js +1 -1
  59. package/dist/ops/grads/fusedSoftmax.js +4 -4
  60. package/dist/ops/grads/gelu.js +1 -1
  61. package/dist/ops/grads/matMulGelu.js +1 -1
  62. package/dist/ops/grads/normRMS.js +1 -1
  63. package/dist/ops/grads/qkv.js +1 -1
  64. package/dist/ops/grads/rope.js +1 -1
  65. package/dist/ops/matMulGelu.js +1 -1
  66. package/dist/ops/matMulMul.js +1 -1
  67. package/dist/ops/mulDrop.js +1 -1
  68. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  69. package/dist/ops/normRMS.js +1 -1
  70. package/dist/ops/qkv.js +1 -1
  71. package/dist/ops/rope.js +8 -4
  72. package/dist/ops/scatterSub.js +1 -1
  73. package/dist/ops/webgl/appendCache.js +1 -1
  74. package/dist/ops/webgl/attentionMask.js +1 -1
  75. package/dist/ops/webgl/fusedSoftmax.js +29 -560
  76. package/dist/ops/webgl/gatherSub.js +1 -1
  77. package/dist/ops/webgl/gelu.js +2 -2
  78. package/dist/ops/webgl/log.js +3 -3
  79. package/dist/ops/webgl/matMulGelu.js +46 -113
  80. package/dist/ops/webgl/matMulMul.js +1 -1
  81. package/dist/ops/webgl/mulDropout.js +1 -1
  82. package/dist/ops/webgl/normRMS.js +2 -2
  83. package/dist/ops/webgl/qkv.js +1 -1
  84. package/dist/ops/webgl/rope.js +1 -1
  85. package/dist/ops/webgl/scatterSub.js +1 -1
  86. package/dist/{ops-Mv7Ta72x.js → ops-C0sQEcPw.js} +117 -109
  87. package/dist/{random_width-BBAWzDym.js → random_width-DWzaOgrn.js} +6925 -6291
  88. package/dist/{range-DMaG9A3G.js → range-DYsrnfiy.js} +1 -1
  89. package/dist/{gpgpu_math-Ctc31slO.js → reciprocal-CJQeasVa.js} +7 -5
  90. package/dist/register_all_kernels-BfFCQAqs.js +21397 -0
  91. package/dist/{reshape-T4yDEqoF.js → reshape-krWGKraP.js} +1 -1
  92. package/dist/scatter_nd_util-93ln7Hut.js +46 -0
  93. package/dist/selu_util-sntGesxr.js +740 -0
  94. package/dist/{shared-XNAoXhOa.js → shared-Ca6iDobD.js} +1462 -1089
  95. package/dist/{sin-EEhbrRO_.js → sin-D_h-qCSx.js} +1 -1
  96. package/dist/{softmax-B2_IKPDR.js → softmax-fsdtf6JC.js} +1 -1
  97. package/dist/{split-dcks18H1.js → split-eiktj-6L.js} +1 -1
  98. package/dist/{stack-lpJ5kYvE.js → stack-dfEEz2OY.js} +2 -2
  99. package/dist/{sum-CutF5lj2.js → sum-BE_Irnim.js} +1 -1
  100. package/dist/{tensor-C15NA2LA.js → tensor-Xyi595sG.js} +1 -1
  101. package/dist/{tensor2d-DZ_e5eKM.js → tensor2d-CPEkynbH.js} +1 -1
  102. package/dist/training/AdamExt.js +1 -1
  103. package/dist/training/DatasetBuilder.js +2 -2
  104. package/dist/training/FullTrainer.js +1 -1
  105. package/dist/training/Trainer.js +3 -3
  106. package/dist/training/sparseCrossEntropy.js +5 -5
  107. package/dist/utilities/dummy.d.ts +6 -0
  108. package/dist/utilities/dummy.js +31 -10
  109. package/dist/utilities/generate.js +3 -3
  110. package/dist/utilities/profile.d.ts +5 -0
  111. package/dist/utilities/profile.js +10 -7
  112. package/dist/utilities/safetensors.js +2 -2
  113. package/dist/utilities/save.js +1 -1
  114. package/dist/utilities/weights.js +2 -2
  115. package/dist/{variable-CdRKKp8x.js → variable-wSS22xj5.js} +1 -1
  116. package/dist/{zeros-CAbHfODe.js → zeros-YJDE7oRb.js} +4 -4
  117. package/package.json +2 -8
  118. package/dist/Reshape-CLOrdpve.js +0 -212
  119. package/dist/slice_util-Ddk0uxGJ.js +0 -49
  120. package/dist/tfjs_backend-BDb8r9qx.js +0 -1010
  121. package/dist/utilities/load.js +0 -99
@@ -1,5 +1,5 @@
1
- import { am as N, an as D, Q as P, q as E, U as v, N as w } from "./index-bMBtI-WR.js";
2
- import { u as g } from "./gpgpu_math-Ctc31slO.js";
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 B(t) {
20
- try {
21
- return t.map((e) => N(e));
22
- } catch (e) {
23
- throw new Error(`Failed to decode encoded string bytes into utf-8, error: ${e}`);
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 H(t) {
27
- return t.map((e) => D(e));
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
- function R(t) {
46
- if (t <= 1)
47
- return "int";
48
- if (t === 2)
49
- return "ivec2";
50
- if (t === 3)
51
- return "ivec3";
52
- if (t === 4)
53
- return "ivec4";
54
- if (t === 5)
55
- return "ivec5";
56
- if (t === 6)
57
- return "ivec6";
58
- throw Error(`GPU for rank ${t} is not yet supported`);
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
- function _(t, e) {
77
- return ["x", "y", "z", "w", "u", "v"].slice(0, e).map((a) => `${t}.${a}`);
78
- }
79
- function k(t, e) {
80
- return e === 1 ? [t] : _(t, e);
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
- class C {
99
- constructor(e, a, u) {
100
- this.variableNames = ["A", "B"], this.outputShape = P(a, u), this.enableShapeUniforms = g(this.outputShape.length), this.userCode = `
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
- class z {
130
- constructor(e, a, u, d = !1) {
131
- this.variableNames = ["A", "B"], this.supportsBroadcasting = !0, this.packedInputs = !0, this.packedOutput = !0, this.outputShape = P(a, u);
132
- const o = this.outputShape.length;
133
- this.enableShapeUniforms = g(o);
134
- let n = "";
135
- if (d)
136
- if (o === 0 || E(this.outputShape) === 1)
137
- n = `
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 (n = `
143
- ${R(o)} coords = getOutputCoords();
144
- `, o === 1)
145
- this.enableShapeUniforms ? n += `
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
- ` : n += `
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 s = k("coords", o);
156
- this.enableShapeUniforms ? n += `
215
+ const a = Z("coords", n);
216
+ this.enableShapeUniforms ? o += `
157
217
  bool nextRowOutOfBounds =
158
- (${s[o - 2]} + 1) >= outShape[${o} - 2];
218
+ (${a[n - 2]} + 1) >= outShape[${n} - 2];
159
219
  bool nextColOutOfBounds =
160
- (${s[o - 1]} + 1) >= outShape[${o} - 1];
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
- ` : n += `
224
+ ` : o += `
165
225
  bool nextRowOutOfBounds =
166
- (${s[o - 2]} + 1) >= ${this.outputShape[o - 2]};
226
+ (${a[n - 2]} + 1) >= ${this.outputShape[n - 2]};
167
227
  bool nextColOutOfBounds =
168
- (${s[o - 1]} + 1) >= ${this.outputShape[o - 1]};
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
- ${n}
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 A(t) {
208
- const { inputs: e, backend: a } = t, { x: u } = e;
209
- return a.incRef(u.dataId), { dataId: u.dataId, shape: u.shape, dtype: u.dtype };
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 G(t) {
228
- const { inputs: e, backend: a } = t, { real: u, imag: d } = e, o = a.makeTensorInfo(u.shape, "complex64"), n = a.texData.get(o.dataId), l = A({ inputs: { x: u }, backend: a }), s = A({ inputs: { x: d }, backend: a });
229
- return n.complexTensorInfos = { real: l, imag: s }, o;
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 2017 Google LLC. All Rights Reserved.
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
- class V {
248
- constructor(e, a) {
249
- this.variableNames = ["A"], this.outputShape = e, this.enableShapeUniforms = g(this.outputShape.length), this.userCode = `
250
- float unaryOperation(float x) {
251
- ${a}
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 K = "if (isnan(x)) return x;";
325
+ const me = {
326
+ kernelName: z,
327
+ backendName: "webgl",
328
+ kernelFunc: oe
329
+ };
264
330
  /**
265
331
  * @license
266
- * Copyright 2018 Google LLC. All Rights Reserved.
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
- class L {
281
- constructor(e, a) {
282
- this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = e, this.enableShapeUniforms = g(this.outputShape.length), this.userCode = `
283
- vec4 unaryOperation(vec4 x) {
284
- ${a}
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 Y = "if (isnan(x)) return x;";
313
- function q({ opSnippet: t, packedOpSnippet: e, cpuKernelImpl: a, dtype: u }) {
314
- return ({ inputs: d, backend: o }) => {
315
- const { x: n } = d, l = o, s = u || n.dtype;
316
- if (l.shouldExecuteOnCPU([n]) && a != null) {
317
- const c = l.texData.get(n.dataId), x = a(c.values, s);
318
- return l.makeTensorInfo(n.shape, s, x);
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 i = w().getBool("WEBGL_PACK_UNARY_OPERATIONS") && e != null;
321
- let r;
322
- return i ? r = new L(n.shape, e) : r = new V(n.shape, t), l.runWebGLProgram(r, [n], s);
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 Q({ opSnippet: t, packedOpSnippet: e, checkOutOfBounds: a = !1, supportsComplex: u = !1, cpuKernelImpl: d, dtype: o }) {
326
- return ({ inputs: n, backend: l }) => {
327
- const { a: s, b: i } = n, r = l;
328
- if (u && s.dtype === "complex64") {
329
- const h = r.texData.get(s.dataId), f = r.texData.get(i.dataId), [y, O] = [
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((S) => {
333
- const [p, m] = S, $ = {
395
+ ].map((C) => {
396
+ const [p, x] = C, $ = {
334
397
  dataId: p.dataId,
335
398
  dtype: p.dtype,
336
- shape: s.shape
337
- }, T = {
338
- dataId: m.dataId,
339
- dtype: m.dtype,
340
- shape: i.shape
341
- }, U = new C(t, s.shape, i.shape);
342
- return r.runWebGLProgram(U, [$, T], v(p.dtype, m.dtype));
343
- }), I = G({ inputs: { real: y, imag: O }, backend: r });
344
- return r.disposeIntermediateTensorInfo(y), r.disposeIntermediateTensorInfo(O), I;
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 c = o || v(s.dtype, i.dtype);
347
- if ((s.dtype === "string" || i.dtype === "string" || r.shouldExecuteOnCPU([s, i])) && d != null) {
348
- const h = r.texData.get(s.dataId).values, f = r.texData.get(i.dataId).values, y = s.dtype === "string" ? (
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
- B(h)
351
- ) : h, O = s.dtype === "string" ? (
413
+ v(h)
414
+ ) : h, m = a.dtype === "string" ? (
352
415
  // tslint:disable-next-line: no-any
353
- B(f)
354
- ) : f, [I, S] = d(s.shape, i.shape, y, O, c), p = r.makeTensorInfo(S, c), m = r.texData.get(p.dataId);
355
- return m.values = I, p;
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 x = w().getBool("WEBGL_PACK_BINARY_OPERATIONS") && e != null;
358
- let b;
359
- return x ? b = new z(e, s.shape, i.shape, a) : b = new C(t, s.shape, i.shape), r.runWebGLProgram(b, [s, i], c);
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
- K as C,
364
- _ as a,
365
- Q as b,
366
- H as c,
367
- Y as d,
368
- B as f,
369
- R as g,
370
- q as u
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
  };
@@ -1,5 +1,5 @@
1
- import { T as g, c as p, e as o, i as v } from "../index-bMBtI-WR.js";
2
- import { v as _ } from "../variable-CdRKKp8x.js";
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 { H as c, t as C } from "../index-bMBtI-WR.js";
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 "../tfjs_backend-BDb8r9qx.js";
9
- import { v as b } from "../variable-CdRKKp8x.js";
10
- import { r as k, d as L } from "../dropout-CrMQPCeG.js";
11
- import { r as N } from "../reshape-T4yDEqoF.js";
12
- import { m as R } from "../mat_mul-BsrLfy81.js";
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;
@@ -1,10 +1,10 @@
1
- import { t as l } from "../index-bMBtI-WR.js";
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-CdRKKp8x.js";
5
- import { r as h, d as f } from "../dropout-CrMQPCeG.js";
6
- import { r as d } from "../reshape-T4yDEqoF.js";
7
- import { m as c } from "../mat_mul-BsrLfy81.js";
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;
@@ -1,8 +1,8 @@
1
- import { t as s } from "../index-bMBtI-WR.js";
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-CdRKKp8x.js";
5
- import { o as m } from "../ones-g0K8jVwm.js";
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) {
@@ -1,36 +1,16 @@
1
- import { o as c, j as f, E as l, V as m, f as n, W as u, t as p, H as a } from "../index-bMBtI-WR.js";
2
- import { c as d, s as C } from "../sin-EEhbrRO_.js";
3
- import { r as h } from "../range-DMaG9A3G.js";
4
- /**
5
- * @license
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 s = this.config.nEmbed / this.config.nHead;
29
- if (this.rotaryDim = s, this.rotaryDim % 2 !== 0)
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 = h(0, this.rotaryDim, 2, "float32"), e = i.div(n(this.rotaryDim, "float32")), t = u(n(this.ropeBase, "float32"), e);
33
- this.ropeInvFreq = S(t), e.dispose(), t.dispose(), i.dispose(), this.config.useRope === !1 ? (this.ropeCos = null, this.ropeSin = null, this.ropeCacheLen = 0) : p(() => {
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
- p(() => {
26
+ n(() => {
47
27
  if (o <= this.ropeCacheLen) return;
48
28
  this.ropeCos && this.ropeCos.dispose(), this.ropeSin && this.ropeSin.dispose();
49
- const s = Math.max(o, this.ropeCacheLen + this.config.blockSize * 4), e = h(0, s, 1, "float32").expandDims(1).mul(this.ropeInvFreq.expandDims(0));
50
- this.ropeCos = a(d(e).expandDims(-1)), this.ropeSin = a(C(e).expandDims(-1)), this.ropeCacheLen = s;
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
- y as default
44
+ D as default
65
45
  };
@@ -1,10 +1,9 @@
1
- import "../random_width-BBAWzDym.js";
2
- import "../index-bMBtI-WR.js";
3
- import { T as f } from "../TiedEmbedding-BhxWO8QR.js";
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-CdRKKp8x.js";
7
- import "../gather-DZCMHZuN.js";
5
+ import "../variable-wSS22xj5.js";
6
+ import "../gather-DjyCjmOD.js";
8
7
  export {
9
- f as default
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-bMBtI-WR.js";
5
+ import { t as p } from "../index-BAzbokzv.js";
6
6
  class k extends d {
7
7
  ln1;
8
8
  attn;