@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.
Files changed (101) hide show
  1. package/dist/Generator.js +3 -3
  2. package/dist/NanoGPTModel.js +8 -8
  3. package/dist/Reshape-CiAY8ltP.js +212 -0
  4. package/dist/TeachableLLM.js +14 -5
  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 +47 -46
  16. package/dist/layers/MLP.js +31 -33
  17. package/dist/layers/RMSNorm.d.ts +1 -2
  18. package/dist/layers/RMSNorm.js +10 -10
  19. package/dist/layers/RoPECache.js +3 -3
  20. package/dist/layers/TiedEmbedding.js +5 -5
  21. package/dist/layers/TransformerBlock.js +2 -2
  22. package/dist/{log_sum_exp-BswFnwOb.js → log_sum_exp-CiEy1aUe.js} +7 -7
  23. package/dist/main.js +28 -19
  24. package/dist/{mat_mul-415y5Qn2.js → mat_mul-BEHRPMh0.js} +1 -1
  25. package/dist/{max-CP_9O2Yd.js → max-BUShNgfh.js} +1 -1
  26. package/dist/{moments-CjeIaVdp.js → moments-DYOHXoRV.js} +5 -5
  27. package/dist/{norm-CZM380I3.js → norm-DSva3hI3.js} +13 -13
  28. package/dist/{ones-Bf3YR48P.js → ones-D6kB8bdY.js} +2 -2
  29. package/dist/ops/appendCache.js +3 -3
  30. package/dist/ops/attentionMask.js +1 -1
  31. package/dist/ops/cpu/appendCache.js +2 -2
  32. package/dist/ops/cpu/attentionMask.js +2 -2
  33. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  34. package/dist/ops/cpu/gatherSub.js +4 -4
  35. package/dist/ops/cpu/gelu.js +1 -1
  36. package/dist/ops/cpu/matMulGelu.d.ts +1 -0
  37. package/dist/ops/cpu/matMulGelu.js +40 -0
  38. package/dist/ops/cpu/mulDropout.js +1 -1
  39. package/dist/ops/cpu/normRMS.d.ts +1 -0
  40. package/dist/ops/cpu/normRMS.js +39 -0
  41. package/dist/ops/cpu/qkv.js +3 -3
  42. package/dist/ops/cpu/rope.js +5 -5
  43. package/dist/ops/cpu/scatterSub.js +4 -4
  44. package/dist/ops/fusedSoftmax.js +1 -1
  45. package/dist/ops/gatherSub.js +1 -1
  46. package/dist/ops/gelu.js +2 -2
  47. package/dist/ops/grads/attentionMask.js +1 -1
  48. package/dist/ops/grads/fusedSoftmax.js +2 -2
  49. package/dist/ops/grads/gelu.js +24 -3
  50. package/dist/ops/grads/matMulGelu.d.ts +1 -0
  51. package/dist/ops/grads/matMulGelu.js +17 -0
  52. package/dist/ops/grads/normRMS.d.ts +2 -0
  53. package/dist/ops/grads/normRMS.js +20 -0
  54. package/dist/ops/grads/qkv.js +1 -1
  55. package/dist/ops/grads/rope.js +1 -1
  56. package/dist/ops/matMulGelu.d.ts +3 -0
  57. package/dist/ops/matMulGelu.js +14 -0
  58. package/dist/ops/mulDrop.js +1 -1
  59. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  60. package/dist/ops/normRMS.d.ts +2 -0
  61. package/dist/ops/normRMS.js +10 -0
  62. package/dist/ops/qkv.js +1 -1
  63. package/dist/ops/scatterSub.js +1 -1
  64. package/dist/ops/webgl/appendCache.js +1 -1
  65. package/dist/ops/webgl/attentionMask.js +1 -1
  66. package/dist/ops/webgl/fusedSoftmax.js +689 -895
  67. package/dist/ops/webgl/gatherSub.js +1 -1
  68. package/dist/ops/webgl/gelu.js +2 -2
  69. package/dist/ops/webgl/matMulGelu.d.ts +21 -0
  70. package/dist/ops/webgl/matMulGelu.js +168 -0
  71. package/dist/ops/webgl/mulDropout.js +1 -1
  72. package/dist/ops/webgl/normRMS.d.ts +1 -0
  73. package/dist/ops/webgl/normRMS.js +78 -0
  74. package/dist/ops/webgl/qkv.js +1 -1
  75. package/dist/ops/webgl/rope.js +1 -1
  76. package/dist/ops/webgl/scatterSub.js +1 -1
  77. package/dist/{range-9AzeApCc.js → range-C_vpUjBu.js} +1 -1
  78. package/dist/{reshape-Boe4DuIO.js → reshape-z51Eu-re.js} +1 -1
  79. package/dist/{sin-KmhiDuMa.js → sin-H567uayl.js} +1 -1
  80. package/dist/{slice_util-19zDNNSn.js → slice_util-BdhYwFY_.js} +2 -2
  81. package/dist/{softmax-Cujsg4ay.js → softmax-Dsxflvdl.js} +1 -1
  82. package/dist/{split-DbcNm1-i.js → split-B_k_jwud.js} +1 -1
  83. package/dist/{stack-D1YjmgKN.js → stack-CmqSdsfs.js} +1 -1
  84. package/dist/{sum-R28pucR5.js → sum-DdkDf2MG.js} +1 -1
  85. package/dist/{tensor-BVeHdl7V.js → tensor-BGYi41cj.js} +1 -1
  86. package/dist/{tensor2d-DqFGNs_K.js → tensor2d-DUr_htjt.js} +1 -1
  87. package/dist/{tfjs_backend-Cug-PH75.js → tfjs_backend-DuKis_xG.js} +46 -46
  88. package/dist/training/AdamExt.js +1 -1
  89. package/dist/training/DatasetBuilder.js +18 -18
  90. package/dist/training/FullTrainer.js +1 -1
  91. package/dist/training/Trainer.js +5 -5
  92. package/dist/training/sparseCrossEntropy.js +4 -4
  93. package/dist/utilities/dummy.js +2 -2
  94. package/dist/utilities/generate.js +3 -3
  95. package/dist/utilities/load.js +1 -1
  96. package/dist/utilities/profile.js +1 -1
  97. package/dist/utilities/weights.js +2 -2
  98. package/dist/{variable-LJT9Ld63.js → variable-BJTZ3jOy.js} +1 -1
  99. package/dist/{zeros-dnQxFgAD.js → zeros-8xl-W2DC.js} +1 -1
  100. package/package.json +1 -1
  101. 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.
@@ -132,7 +132,7 @@ class wt extends B {
132
132
  }) : (this.ropeCache = new K(this.config.gpt), this.config.layerConfig.ropeCache = this.ropeCache), this.drop = st({ rate: this.config.gpt.dropout }), this.blocks = [];
133
133
  for (let e = 0; e < this.config.gpt.nLayer; e++)
134
134
  this.blocks.push(new W(e, this.config));
135
- this.lnF = new N(this.config, 1e-8, "final_rms_norm");
135
+ this.lnF = new N(this.config, "final_rms_norm");
136
136
  }
137
137
  get checkpointing() {
138
138
  return this.config.layerConfig.checkpointAttention === !0 || this.config.layerConfig.checkpointMLP === !0;
@@ -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
+ };
@@ -3,15 +3,15 @@ import l from "./NanoGPTModel.js";
3
3
  import { saveModel as d } from "./utilities/save.js";
4
4
  import { loadModel as f } from "./utilities/load.js";
5
5
  import u from "./Generator.js";
6
- import _ from "./Trainer.js";
7
- import { E as p } from "./index-Dwqa6Zy2.js";
6
+ import p from "./Trainer.js";
7
+ import { E as _ } from "./index-Dwqa6Zy2.js";
8
8
  import { dummyPassAsync as m } from "./utilities/dummy.js";
9
9
  import c from "./tokeniser/CharTokeniser.js";
10
10
  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,9 +31,18 @@ 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";
40
+ import "./ops/cpu/normRMS.js";
41
+ import "./ops/webgl/normRMS.js";
42
+ import "./ops/grads/normRMS.js";
34
43
  import w from "./utilities/profile.js";
35
44
  class a {
36
- ee = new p();
45
+ ee = new _();
37
46
  _config;
38
47
  _model;
39
48
  _tokeniser;
@@ -120,7 +129,7 @@ class a {
120
129
  trainer() {
121
130
  if (!this._model || !this._tokeniser)
122
131
  throw new Error("Model or tokeniser is not initialized.");
123
- const t = new _(this._model, this._tokeniser);
132
+ const t = new p(this._model, this._tokeniser);
124
133
  return t.on("start", () => this.setStatus("training")), t.on("stop", () => this.setStatus("ready")), t.on("log", async (e) => {
125
134
  const i = this.ee.listeners("trainStep");
126
135
  for (const o of i)