@genai-fi/nanogpt 0.4.3 → 0.4.4

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 (92) hide show
  1. package/dist/Generator.js +3 -3
  2. package/dist/NanoGPTModel.js +7 -7
  3. package/dist/Reshape-CiAY8ltP.js +212 -0
  4. package/dist/TeachableLLM.js +7 -1
  5. package/dist/{TiedEmbedding-CnJ1bx4q.js → TiedEmbedding-DznFwzcB.js} +244 -244
  6. package/dist/{axis_util-BgTGy5w8.js → axis_util-QP0LdI1v.js} +1 -1
  7. package/dist/{concat-CuRsVY-K.js → concat-DvWM7HGZ.js} +1 -1
  8. package/dist/data/parquet.js +9 -6
  9. package/dist/data/textLoader.js +6 -5
  10. package/dist/{dropout-DfDdklfL.js → dropout-DFEXTPV0.js} +4 -4
  11. package/dist/{gather-ZYRWhmXR.js → gather-C5D8PxwA.js} +1 -1
  12. package/dist/gpgpu_math-CUzjlO9A.js +23 -0
  13. package/dist/{index-C4JCoBvj.js → index--6vO-cOz.js} +87 -87
  14. package/dist/{kernel_funcs_utils-CAd1h9X1.js → kernel_funcs_utils-C6YBCuOt.js} +72 -91
  15. package/dist/layers/CausalSelfAttention.js +8 -8
  16. package/dist/layers/MLP.js +31 -33
  17. package/dist/layers/RMSNorm.js +3 -3
  18. package/dist/layers/RoPECache.js +3 -3
  19. package/dist/layers/TiedEmbedding.js +5 -5
  20. package/dist/layers/TransformerBlock.js +1 -1
  21. package/dist/{log_sum_exp-BswFnwOb.js → log_sum_exp-CiEy1aUe.js} +7 -7
  22. package/dist/main.js +25 -19
  23. package/dist/{mat_mul-415y5Qn2.js → mat_mul-BEHRPMh0.js} +1 -1
  24. package/dist/{max-CP_9O2Yd.js → max-BUShNgfh.js} +1 -1
  25. package/dist/{moments-CjeIaVdp.js → moments-DYOHXoRV.js} +5 -5
  26. package/dist/{norm-CZM380I3.js → norm-DSva3hI3.js} +13 -13
  27. package/dist/{ones-Bf3YR48P.js → ones-D6kB8bdY.js} +2 -2
  28. package/dist/ops/appendCache.js +3 -3
  29. package/dist/ops/attentionMask.js +1 -1
  30. package/dist/ops/cpu/appendCache.js +2 -2
  31. package/dist/ops/cpu/attentionMask.js +2 -2
  32. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  33. package/dist/ops/cpu/gatherSub.js +4 -4
  34. package/dist/ops/cpu/gelu.js +1 -1
  35. package/dist/ops/cpu/matMulGelu.d.ts +1 -0
  36. package/dist/ops/cpu/matMulGelu.js +40 -0
  37. package/dist/ops/cpu/mulDropout.js +1 -1
  38. package/dist/ops/cpu/qkv.js +3 -3
  39. package/dist/ops/cpu/rope.js +5 -5
  40. package/dist/ops/cpu/scatterSub.js +4 -4
  41. package/dist/ops/fusedSoftmax.js +1 -1
  42. package/dist/ops/gatherSub.js +1 -1
  43. package/dist/ops/gelu.js +2 -2
  44. package/dist/ops/grads/attentionMask.js +1 -1
  45. package/dist/ops/grads/fusedSoftmax.js +2 -2
  46. package/dist/ops/grads/gelu.js +24 -3
  47. package/dist/ops/grads/matMulGelu.d.ts +1 -0
  48. package/dist/ops/grads/matMulGelu.js +17 -0
  49. package/dist/ops/grads/qkv.js +1 -1
  50. package/dist/ops/grads/rope.js +1 -1
  51. package/dist/ops/matMulGelu.d.ts +3 -0
  52. package/dist/ops/matMulGelu.js +14 -0
  53. package/dist/ops/mulDrop.js +1 -1
  54. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  55. package/dist/ops/qkv.js +1 -1
  56. package/dist/ops/scatterSub.js +1 -1
  57. package/dist/ops/webgl/appendCache.js +1 -1
  58. package/dist/ops/webgl/attentionMask.js +1 -1
  59. package/dist/ops/webgl/fusedSoftmax.js +689 -895
  60. package/dist/ops/webgl/gatherSub.js +1 -1
  61. package/dist/ops/webgl/gelu.js +2 -2
  62. package/dist/ops/webgl/matMulGelu.d.ts +20 -0
  63. package/dist/ops/webgl/matMulGelu.js +166 -0
  64. package/dist/ops/webgl/mulDropout.js +1 -1
  65. package/dist/ops/webgl/qkv.js +1 -1
  66. package/dist/ops/webgl/rope.js +1 -1
  67. package/dist/ops/webgl/scatterSub.js +1 -1
  68. package/dist/{range-9AzeApCc.js → range-C_vpUjBu.js} +1 -1
  69. package/dist/{reshape-Boe4DuIO.js → reshape-z51Eu-re.js} +1 -1
  70. package/dist/{sin-KmhiDuMa.js → sin-H567uayl.js} +1 -1
  71. package/dist/{slice_util-19zDNNSn.js → slice_util-BdhYwFY_.js} +2 -2
  72. package/dist/{softmax-Cujsg4ay.js → softmax-Dsxflvdl.js} +1 -1
  73. package/dist/{split-DbcNm1-i.js → split-B_k_jwud.js} +1 -1
  74. package/dist/{stack-D1YjmgKN.js → stack-CmqSdsfs.js} +1 -1
  75. package/dist/{sum-R28pucR5.js → sum-DdkDf2MG.js} +1 -1
  76. package/dist/{tensor-BVeHdl7V.js → tensor-BGYi41cj.js} +1 -1
  77. package/dist/{tensor2d-DqFGNs_K.js → tensor2d-DUr_htjt.js} +1 -1
  78. package/dist/{tfjs_backend-Cug-PH75.js → tfjs_backend-DuKis_xG.js} +46 -46
  79. package/dist/training/AdamExt.js +1 -1
  80. package/dist/training/DatasetBuilder.js +18 -18
  81. package/dist/training/FullTrainer.js +1 -1
  82. package/dist/training/Trainer.js +5 -5
  83. package/dist/training/sparseCrossEntropy.js +4 -4
  84. package/dist/utilities/dummy.js +2 -2
  85. package/dist/utilities/generate.js +3 -3
  86. package/dist/utilities/load.js +1 -1
  87. package/dist/utilities/profile.js +1 -1
  88. package/dist/utilities/weights.js +2 -2
  89. package/dist/{variable-LJT9Ld63.js → variable-BJTZ3jOy.js} +1 -1
  90. package/dist/{zeros-dnQxFgAD.js → zeros-8xl-W2DC.js} +1 -1
  91. package/package.json +1 -1
  92. package/dist/gelu-CnCt17Lk.js +0 -26
package/dist/Generator.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { E as u } from "./index-Dwqa6Zy2.js";
2
- import "./index-C4JCoBvj.js";
3
- import { t as d } from "./tensor2d-DqFGNs_K.js";
4
- import { c as p } from "./concat-CuRsVY-K.js";
2
+ import "./index--6vO-cOz.js";
3
+ import { t as d } from "./tensor2d-DUr_htjt.js";
4
+ import { c as p } from "./concat-DvWM7HGZ.js";
5
5
  class w extends u {
6
6
  constructor(s, e) {
7
7
  super(), this.model = s, this.tokeniser = e;
@@ -1,17 +1,17 @@
1
1
  import { defaultConfig as x } from "./config.js";
2
2
  import W from "./layers/TransformerBlock.js";
3
- import { E as F, D as P, T as q, r as T, p as D } from "./TiedEmbedding-CnJ1bx4q.js";
3
+ import { E as F, D as P, T as q, r as T, p as D } from "./TiedEmbedding-DznFwzcB.js";
4
4
  import K from "./layers/RoPECache.js";
5
5
  import N from "./layers/RMSNorm.js";
6
6
  import { estimateParameterCount as R } from "./utilities/parameters.js";
7
7
  import { createSoftmaxCrossEntropyWithGrad as A } from "./training/sparseCrossEntropy.js";
8
8
  import B from "./layers/BaseLayer.js";
9
- import { o as $, h as E, p as G, E as v, a6 as O, a7 as j, a8 as Q, t as w, a5 as V, f as C } from "./index-C4JCoBvj.js";
10
- import { r as _ } from "./reshape-Boe4DuIO.js";
11
- import { r as X } from "./range-9AzeApCc.js";
12
- import { e as H } from "./tfjs_backend-Cug-PH75.js";
13
- import { g as J } from "./gather-ZYRWhmXR.js";
14
- import { s as U } from "./softmax-Cujsg4ay.js";
9
+ import { o as $, h as E, p as G, E as v, a9 as O, aa as j, ab as Q, t as w, a8 as V, f as C } from "./index--6vO-cOz.js";
10
+ import { r as _ } from "./reshape-z51Eu-re.js";
11
+ import { r as X } from "./range-C_vpUjBu.js";
12
+ import { e as H } from "./tfjs_backend-DuKis_xG.js";
13
+ import { g as J } from "./gather-C5D8PxwA.js";
14
+ import { s as U } from "./softmax-Dsxflvdl.js";
15
15
  /**
16
16
  * @license
17
17
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -0,0 +1,212 @@
1
+ import { ac as f, ad as g, n as p, ae as C, j as x } from "./index--6vO-cOz.js";
2
+ import { u as I } from "./gpgpu_math-CUzjlO9A.js";
3
+ /**
4
+ * @license
5
+ * Copyright 2018 Google LLC. All Rights Reserved.
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ * =============================================================================
18
+ */
19
+ function R(t, e, o = "index") {
20
+ const s = f(e);
21
+ return s.map((n, r) => {
22
+ const i = `int ${t[r]} = ${o} / ${n}`, u = r === s.length - 1 ? `int ${t[r + 1]} = ${o} - ${t[r]} * ${n}` : `index -= ${t[r]} * ${n}`;
23
+ return `${i}; ${u};`;
24
+ }).join("");
25
+ }
26
+ function y(t, e) {
27
+ const o = t.length, s = t.map((r) => `${e}[${r}]`), n = new Array(o - 1);
28
+ n[o - 2] = s[o - 1];
29
+ for (let r = o - 3; r >= 0; --r)
30
+ n[r] = `(${n[r + 1]} * ${s[r + 1]})`;
31
+ return n;
32
+ }
33
+ function S(t, e, o = "index") {
34
+ const s = t.map((r, i) => i), n = y(s, e);
35
+ return n.map((r, i) => {
36
+ const u = `int ${t[i]} = ${o} / ${n[i]}`, a = i === n.length - 1 ? `int ${t[i + 1]} = ${o} - ${t[i]} * ${n[i]}` : `index -= ${t[i]} * ${n[i]}`;
37
+ return `${u}; ${a};`;
38
+ }).join("");
39
+ }
40
+ function F(t) {
41
+ const e = f(t).map((o) => o.toString());
42
+ return `
43
+ int getFlatIndex(ivec3 coords) {
44
+ return coords.x * ${e[0]} + coords.y * ${e[1]} + coords.z;
45
+ }
46
+ `;
47
+ }
48
+ function v() {
49
+ return `
50
+ int getFlatIndex(ivec3 coords) {
51
+ return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
52
+ }
53
+ `;
54
+ }
55
+ /**
56
+ * @license
57
+ * Copyright 2017 Google LLC. All Rights Reserved.
58
+ * Licensed under the Apache License, Version 2.0 (the "License");
59
+ * you may not use this file except in compliance with the License.
60
+ * You may obtain a copy of the License at
61
+ *
62
+ * http://www.apache.org/licenses/LICENSE-2.0
63
+ *
64
+ * Unless required by applicable law or agreed to in writing, software
65
+ * distributed under the License is distributed on an "AS IS" BASIS,
66
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67
+ * See the License for the specific language governing permissions and
68
+ * limitations under the License.
69
+ * =============================================================================
70
+ */
71
+ function h(t, e = 2) {
72
+ return p(t.slice(0, t.length - e));
73
+ }
74
+ function m(t) {
75
+ if (t.length === 0)
76
+ throw Error("Cannot get rows and columns of an empty shape array.");
77
+ return [
78
+ t.length > 1 ? t[t.length - 2] : 1,
79
+ t[t.length - 1]
80
+ ];
81
+ }
82
+ function d(t) {
83
+ return t % 2 === 0;
84
+ }
85
+ function $(t, e) {
86
+ if (t = t.slice(-2), e = e.slice(-2), g(t, e) || !t.length || !e.length || t[0] === 0 || t[1] === 0 || e[0] === 0 || e[1] === 0)
87
+ return !0;
88
+ if (t.length !== e.length) {
89
+ const o = t[t.length - 1], s = e[e.length - 1];
90
+ if (o === s || d(o) && d(s) && (t[0] === 1 || e[0] === 1))
91
+ return !0;
92
+ }
93
+ return t[1] === e[1] && d(t[0]) && d(e[0]);
94
+ }
95
+ /**
96
+ * @license
97
+ * Copyright 2018 Google LLC. All Rights Reserved.
98
+ * Licensed under the Apache License, Version 2.0 (the "License");
99
+ * you may not use this file except in compliance with the License.
100
+ * You may obtain a copy of the License at
101
+ *
102
+ * http://www.apache.org/licenses/LICENSE-2.0
103
+ *
104
+ * Unless required by applicable law or agreed to in writing, software
105
+ * distributed under the License is distributed on an "AS IS" BASIS,
106
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
107
+ * See the License for the specific language governing permissions and
108
+ * limitations under the License.
109
+ * =============================================================================
110
+ */
111
+ class b {
112
+ constructor(e, o) {
113
+ this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "inputShape", type: "ivec3" }], this.outputShape = e, this.enableShapeUniforms = I(this.outputShape.length);
114
+ let s = "";
115
+ for (let n = 0; n < 4; n++) {
116
+ let r = "thisRC = rc;";
117
+ n % 2 === 1 && (r += "thisRC.z += 1;"), n > 1 && (r += "thisRC.y += 1;"), s += `
118
+ ${r}
119
+ ${n > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : ""}
120
+ int flatIndex = getFlatIndex(thisRC);
121
+
122
+ ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
123
+ vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));
124
+
125
+ result[${n}] =
126
+ getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
127
+ ${n > 0 ? "}" : ""}
128
+ `;
129
+ }
130
+ this.userCode = `
131
+ ${w(o, this.enableShapeUniforms)}
132
+ ${this.enableShapeUniforms ? v() : F(e)}
133
+
134
+ void main() {
135
+ ivec3 rc = getOutputCoords();
136
+
137
+ vec4 result = vec4(0.);
138
+
139
+ ivec3 thisRC;
140
+ int rows = ${this.enableShapeUniforms ? "outShape[1]" : e[1]};
141
+ int cols = ${this.enableShapeUniforms ? "outShape[2]" : e[2]};
142
+
143
+ ${s}
144
+
145
+ setOutput(result);
146
+ }
147
+ `;
148
+ }
149
+ }
150
+ function w(t, e) {
151
+ return `
152
+ ivec3 inputCoordsFromReshapedOutCoords(int index) {
153
+ ${e ? S(["r", "c", "d"], "inputShape") : R(["r", "c", "d"], t)}
154
+ return ivec3(r, c, d);
155
+ }
156
+ `;
157
+ }
158
+ /**
159
+ * @license
160
+ * Copyright 2020 Google LLC. All Rights Reserved.
161
+ * Licensed under the Apache License, Version 2.0 (the "License");
162
+ * you may not use this file except in compliance with the License.
163
+ * You may obtain a copy of the License at
164
+ *
165
+ * http://www.apache.org/licenses/LICENSE-2.0
166
+ *
167
+ * Unless required by applicable law or agreed to in writing, software
168
+ * distributed under the License is distributed on an "AS IS" BASIS,
169
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170
+ * See the License for the specific language governing permissions and
171
+ * limitations under the License.
172
+ * =============================================================================
173
+ */
174
+ function D(t, e, o) {
175
+ const s = [
176
+ h(t.shape),
177
+ ...m(t.shape)
178
+ ], n = {
179
+ dtype: t.dtype,
180
+ shape: s,
181
+ dataId: t.dataId
182
+ }, r = [
183
+ h(e),
184
+ ...m(e)
185
+ ], i = new b(r, s), u = !0, a = [s], c = o.runWebGLProgram(i, [n], t.dtype, a, u);
186
+ return { dataId: c.dataId, shape: e, dtype: c.dtype };
187
+ }
188
+ /**
189
+ * @license
190
+ * Copyright 2020 Google LLC. All Rights Reserved.
191
+ * Licensed under the Apache License, Version 2.0 (the "License");
192
+ * you may not use this file except in compliance with the License.
193
+ * You may obtain a copy of the License at
194
+ *
195
+ * http://www.apache.org/licenses/LICENSE-2.0
196
+ *
197
+ * Unless required by applicable law or agreed to in writing, software
198
+ * distributed under the License is distributed on an "AS IS" BASIS,
199
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ * See the License for the specific language governing permissions and
201
+ * limitations under the License.
202
+ * =============================================================================
203
+ */
204
+ function k(t) {
205
+ const { inputs: e, backend: o, attrs: s } = t, { x: n } = e, { shape: r } = s, i = o, u = p(n.shape), a = C(r, u), c = p(a);
206
+ x(u === c, () => `The new shape (${a}) has ${c} elements and the old shape (${n.shape}) has ${u} elements. The new shape and old shape must have the same number of elements.`);
207
+ const l = i.texData.get(n.dataId);
208
+ return l.isPacked && !$(n.shape, a) && !(l.texture !== null && $(l.shape, a)) ? D(n, a, i) : (i.incRef(n.dataId), { dataId: n.dataId, shape: a, dtype: n.dtype });
209
+ }
210
+ export {
211
+ k as r
212
+ };
@@ -11,7 +11,7 @@ import g from "./tokeniser/bpe.js";
11
11
  import "./papaparse.min-C8l2Kvo1.js";
12
12
  import "./index-Tf7vU29b.js";
13
13
  import "./jszip.min-CjP2V1VV.js";
14
- import "./index-C4JCoBvj.js";
14
+ import "./index--6vO-cOz.js";
15
15
  import "./ops/cpu/scatterSub.js";
16
16
  import "./ops/webgl/scatterSub.js";
17
17
  import "./ops/cpu/gatherSub.js";
@@ -31,6 +31,12 @@ import "./ops/webgl/appendCache.js";
31
31
  import "./ops/cpu/fusedSoftmax.js";
32
32
  import "./ops/webgl/fusedSoftmax.js";
33
33
  import "./ops/grads/fusedSoftmax.js";
34
+ import "./ops/cpu/matMulGelu.js";
35
+ import "./ops/webgl/matMulGelu.js";
36
+ import "./ops/grads/matMulGelu.js";
37
+ import "./ops/cpu/gelu.js";
38
+ import "./ops/webgl/gelu.js";
39
+ import "./ops/grads/gelu.js";
34
40
  import w from "./utilities/profile.js";
35
41
  class a {
36
42
  ee = new p();