@genai-fi/nanogpt 0.5.1 → 0.5.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 (102) hide show
  1. package/dist/Generator.js +90 -41
  2. package/dist/NanoGPTModel.d.ts +1 -0
  3. package/dist/NanoGPTModel.js +86 -73
  4. package/dist/{Reshape-BE5rA4rT.js → Reshape-Bt_t7RNz.js} +4 -4
  5. package/dist/TeachableLLM.js +1 -1
  6. package/dist/TiedEmbedding-DORsPlNL.js +44 -0
  7. package/dist/{axis_util-97KkkyRQ.js → axis_util-CVbf1vmL.js} +3 -3
  8. package/dist/{broadcast_to-CMlkG8NS.js → broadcast_to-BBoMQXbL.js} +4 -4
  9. package/dist/{concat-Cxbo2sOz.js → concat-BRRtq4S2.js} +1 -1
  10. package/dist/dataset-ZHEPJmED.js +1226 -0
  11. package/dist/{dropout-kbDY39Ci.js → dropout-lQm_YyX3.js} +1 -1
  12. package/dist/{gather-Bxe1Qip8.js → gather-BWyutxwi.js} +3 -3
  13. package/dist/{gpgpu_math-C0zyxKFi.js → gpgpu_math-Df7gzJWH.js} +1 -1
  14. package/dist/{index-iNhkcAEQ.js → index-CnHyhpKc.js} +32 -32
  15. package/dist/{kernel_funcs_utils-C4eIk4fE.js → kernel_funcs_utils-Dqo82NH4.js} +25 -25
  16. package/dist/layers/BaseLayer.js +114 -3
  17. package/dist/layers/CausalSelfAttention.js +29 -28
  18. package/dist/layers/MLP.js +10 -9
  19. package/dist/layers/RMSNorm.js +12 -11
  20. package/dist/layers/RoPECache.js +3 -3
  21. package/dist/layers/TiedEmbedding.js +8 -6
  22. package/dist/layers/TransformerBlock.js +2 -2
  23. package/dist/{log_sum_exp-CkumwesB.js → log_sum_exp-CRH7Np9v.js} +12 -12
  24. package/dist/main.js +1 -1
  25. package/dist/{mat_mul-D0SifYfJ.js → mat_mul-DeGU1U_C.js} +3 -3
  26. package/dist/{max-CYaAjEEp.js → max-CcnEArWK.js} +3 -3
  27. package/dist/{moments-B06NlR_V.js → moments-DLTE6-1p.js} +4 -4
  28. package/dist/{norm-D3676xIo.js → norm-BpWsOapl.js} +5 -5
  29. package/dist/{ones-BIeFnPHR.js → ones-CDWGzVnm.js} +6 -6
  30. package/dist/ops/appendCache.js +3 -3
  31. package/dist/ops/attentionMask.js +1 -1
  32. package/dist/ops/cpu/appendCache.js +2 -2
  33. package/dist/ops/cpu/attentionMask.js +5 -5
  34. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  35. package/dist/ops/cpu/gatherSub.js +5 -5
  36. package/dist/ops/cpu/gelu.js +1 -1
  37. package/dist/ops/cpu/matMulGelu.js +1 -1
  38. package/dist/ops/cpu/matMulMul.js +1 -1
  39. package/dist/ops/cpu/mulDropout.js +1 -1
  40. package/dist/ops/cpu/normRMS.js +1 -1
  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 +27 -27
  44. package/dist/ops/fusedSoftmax.js +1 -1
  45. package/dist/ops/gatherSub.js +1 -1
  46. package/dist/ops/gelu.js +1 -1
  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 +1 -1
  50. package/dist/ops/grads/matMulGelu.js +1 -1
  51. package/dist/ops/grads/normRMS.js +1 -1
  52. package/dist/ops/grads/qkv.js +1 -1
  53. package/dist/ops/grads/rope.js +1 -1
  54. package/dist/ops/matMulGelu.js +1 -1
  55. package/dist/ops/matMulMul.js +1 -1
  56. package/dist/ops/mulDrop.js +1 -1
  57. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  58. package/dist/ops/normRMS.js +1 -1
  59. package/dist/ops/qkv.js +1 -1
  60. package/dist/ops/scatterSub.js +1 -1
  61. package/dist/ops/webgl/appendCache.js +1 -1
  62. package/dist/ops/webgl/attentionMask.js +1 -1
  63. package/dist/ops/webgl/fusedSoftmax.js +36 -36
  64. package/dist/ops/webgl/gatherSub.js +1 -1
  65. package/dist/ops/webgl/gelu.js +2 -2
  66. package/dist/ops/webgl/matMulGelu.js +22 -22
  67. package/dist/ops/webgl/matMulMul.js +1 -1
  68. package/dist/ops/webgl/mulDropout.js +1 -1
  69. package/dist/ops/webgl/normRMS.js +2 -2
  70. package/dist/ops/webgl/qkv.js +1 -1
  71. package/dist/ops/webgl/rope.js +1 -1
  72. package/dist/ops/webgl/scatterSub.js +1 -1
  73. package/dist/{ops-ObfXLHYQ.js → ops-DzQTmLIl.js} +60 -60
  74. package/dist/{TiedEmbedding-DsDRvLB0.js → random_width-DI2h9CMs.js} +1215 -1250
  75. package/dist/{range-BsFU-SNG.js → range-CkOJ7090.js} +1 -1
  76. package/dist/{reshape-DxTPgnwL.js → reshape-CTIbqjwm.js} +1 -1
  77. package/dist/{sin-BOX-JVAj.js → sin-HzioENy_.js} +5 -5
  78. package/dist/{slice_util-D-kaD4ZV.js → slice_util-n4wHKmex.js} +1 -1
  79. package/dist/{softmax-BjsptB07.js → softmax-DX6qXAbm.js} +2 -2
  80. package/dist/{split-BCbrzthj.js → split-CVwhL8Oe.js} +3 -3
  81. package/dist/{stack--cqr9Dgc.js → stack-S2-D2JAQ.js} +1 -1
  82. package/dist/{sum-B_92TaHD.js → sum-UdfvaNhB.js} +4 -4
  83. package/dist/{tensor-CfiPXsW4.js → tensor-IZex6Bwp.js} +1 -1
  84. package/dist/{tensor2d-tSxWdFMH.js → tensor2d-CqtBzOKq.js} +1 -1
  85. package/dist/{tfjs_backend-NucKez4s.js → tfjs_backend-DX9yVvwk.js} +41 -41
  86. package/dist/tokeniser/CharTokeniser.js +27 -27
  87. package/dist/tokeniser/bpe.d.ts +1 -0
  88. package/dist/tokeniser/bpe.js +38 -35
  89. package/dist/training/AdamExt.js +1 -1
  90. package/dist/training/DatasetBuilder.js +22 -1242
  91. package/dist/training/FullTrainer.js +1 -1
  92. package/dist/training/Trainer.js +5 -5
  93. package/dist/training/sparseCrossEntropy.js +4 -4
  94. package/dist/utilities/dummy.js +2 -2
  95. package/dist/utilities/generate.js +3 -3
  96. package/dist/utilities/load.js +1 -1
  97. package/dist/utilities/profile.js +1 -1
  98. package/dist/utilities/weights.js +2 -2
  99. package/dist/variable-BGvK-VN3.js +23 -0
  100. package/dist/{zeros-NMYTayy7.js → zeros-CYMicyqz.js} +3 -3
  101. package/package.json +1 -1
  102. package/dist/BaseLayer-BhrMN8JO.js +0 -135
@@ -1,7 +1,7 @@
1
1
  import { generateText as v } from "../utilities/generate.js";
2
2
  import L from "./Trainer.js";
3
3
  import x from "./Evaluator.js";
4
- import { a as h } from "../index-iNhkcAEQ.js";
4
+ import { a as h } from "../index-CnHyhpKc.js";
5
5
  const D = {
6
6
  desiredLoss: 0.01,
7
7
  logInterval: 1,
@@ -1,10 +1,10 @@
1
1
  import { DatasetBuilder as d } from "./DatasetBuilder.js";
2
2
  import h from "./AdamExt.js";
3
- import { t as g, v as u, a as o } from "../index-iNhkcAEQ.js";
4
- import { m as y, n as f } from "../norm-D3676xIo.js";
5
- import { m as S, a as z } from "../moments-B06NlR_V.js";
6
- import { m as b } from "../max-CYaAjEEp.js";
7
- import { z as n } from "../zeros-NMYTayy7.js";
3
+ import { t as g, v as u, a as o } from "../index-CnHyhpKc.js";
4
+ import { m as y, n as f } from "../norm-BpWsOapl.js";
5
+ import { m as S, a as z } from "../moments-DLTE6-1p.js";
6
+ import { m as b } from "../max-CcnEArWK.js";
7
+ import { z as n } from "../zeros-CYMicyqz.js";
8
8
  class G {
9
9
  constructor(t, s, e = 1e-3) {
10
10
  this.tokenizer = s, this.model = t, this.learningRate = e, this.resetOptimizer(), this.datasetBuilder = new d(s, t.config.gpt.blockSize);
@@ -1,9 +1,9 @@
1
1
  import { gatherSub as L } from "../ops/gatherSub.js";
2
2
  import { scatterSub as y } from "../ops/scatterSub.js";
3
- import { e as u, c as i, z as S, t as f, s as G } from "../index-iNhkcAEQ.js";
4
- import { s as v } from "../softmax-BjsptB07.js";
5
- import { m as z } from "../max-CYaAjEEp.js";
6
- import { l as k } from "../log_sum_exp-CkumwesB.js";
3
+ import { e as u, c as i, z as S, t as f, s as G } from "../index-CnHyhpKc.js";
4
+ import { s as v } from "../softmax-DX6qXAbm.js";
5
+ import { m as z } from "../max-CcnEArWK.js";
6
+ import { l as k } from "../log_sum_exp-CRH7Np9v.js";
7
7
  function F(a, s) {
8
8
  return f(() => {
9
9
  const e = a.shape[a.shape.length - 1], o = a.shape.slice(0, -1).reduce((d, c) => d * c, 1), p = a.shape.length > 2 ? a.reshape([o, e]) : a, n = s.shape.length > 1 ? s.reshape([o]).cast("int32") : s.cast("int32"), t = z(p, -1, !0), r = G(p, t), h = k(r, -1);
@@ -1,5 +1,5 @@
1
- import "../index-iNhkcAEQ.js";
2
- import { z as n } from "../zeros-NMYTayy7.js";
1
+ import "../index-CnHyhpKc.js";
2
+ import { z as n } from "../zeros-CYMicyqz.js";
3
3
  async function c(s) {
4
4
  const i = n([1, s.config.gpt.blockSize], "int32"), [t, o] = s.forward({ training: !1 }, i);
5
5
  await t.data(), t.dispose(), o && o.dispose(), i.dispose();
@@ -1,6 +1,6 @@
1
- import { t as y } from "../index-iNhkcAEQ.js";
2
- import { t as x } from "../tensor2d-tSxWdFMH.js";
3
- import { c as f } from "../concat-Cxbo2sOz.js";
1
+ import { t as y } from "../index-CnHyhpKc.js";
2
+ import { t as x } from "../tensor2d-CqtBzOKq.js";
3
+ import { c as f } from "../concat-BRRtq4S2.js";
4
4
  async function A(o, r, a, c, T) {
5
5
  if (c <= 0)
6
6
  throw new Error("Length must be a positive integer");
@@ -3,7 +3,7 @@ import { importWeights as b } from "./weights.js";
3
3
  import u from "../tokeniser/CharTokeniser.js";
4
4
  import F from "../NanoGPTModel.js";
5
5
  import { dummyPassAsync as j } from "./dummy.js";
6
- import { d as T } from "../index-iNhkcAEQ.js";
6
+ import { d as T } from "../index-CnHyhpKc.js";
7
7
  import E from "../tokeniser/bpe.js";
8
8
  async function A(t) {
9
9
  const o = await fetch(t);
@@ -1,4 +1,4 @@
1
- import { m as s } from "../index-iNhkcAEQ.js";
1
+ import { m as s } from "../index-CnHyhpKc.js";
2
2
  const m = 1024 * 1024;
3
3
  class i {
4
4
  log = /* @__PURE__ */ new Map();
@@ -1,5 +1,5 @@
1
- import "../index-iNhkcAEQ.js";
2
- import { t as p } from "../tensor-CfiPXsW4.js";
1
+ import "../index-CnHyhpKc.js";
2
+ import { t as p } from "../tensor-IZex6Bwp.js";
3
3
  function h(n) {
4
4
  const e = n.reduce((s, o) => s + o.length, 0), a = new Float32Array(e);
5
5
  let t = 0;
@@ -0,0 +1,23 @@
1
+ import { E as i } from "./index-CnHyhpKc.js";
2
+ /**
3
+ * @license
4
+ * Copyright 2018 Google LLC. All Rights Reserved.
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ * =============================================================================
17
+ */
18
+ function m(r, a = !0, e, t) {
19
+ return i.makeVariable(r, a, e, t);
20
+ }
21
+ export {
22
+ m as v
23
+ };
@@ -1,4 +1,4 @@
1
- import { o as l, i as r, X as m, E as c, Y as i, l as p, Z as u, p as f } from "./index-iNhkcAEQ.js";
1
+ import { o as m, j as r, X as l, E as c, Y as i, n as p, Z as u, q as f } from "./index-CnHyhpKc.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -17,11 +17,11 @@ import { o as l, i as r, X as m, E as c, Y as i, l as p, Z as u, p as f } from "
17
17
  */
18
18
  function x(a, e) {
19
19
  const o = r(a, "real", "complex"), s = r(e, "imag", "complex");
20
- m(o.shape, s.shape, `real and imag shapes, ${o.shape} and ${s.shape}, must match in call to tf.complex().`);
20
+ l(o.shape, s.shape, `real and imag shapes, ${o.shape} and ${s.shape}, must match in call to tf.complex().`);
21
21
  const n = { real: o, imag: s };
22
22
  return c.runKernel(i, n);
23
23
  }
24
- const g = /* @__PURE__ */ l({ complex_: x });
24
+ const g = /* @__PURE__ */ m({ complex_: x });
25
25
  /**
26
26
  * @license
27
27
  * Copyright 2018 Google LLC. All Rights Reserved.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -1,135 +0,0 @@
1
- import { E as p, V as v, c as _, e as o, W as V } from "./index-iNhkcAEQ.js";
2
- /**
3
- * @license
4
- * Copyright 2018 Google LLC. All Rights Reserved.
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- * =============================================================================
17
- */
18
- function E(l, t = !0, r, e) {
19
- return p.makeVariable(l, t, r, e);
20
- }
21
- class m {
22
- parent;
23
- config;
24
- _variables = /* @__PURE__ */ new Map();
25
- _trainable = !0;
26
- children = [];
27
- constructor(t, r) {
28
- this.config = t, this.parent = r, this.parent && this.parent.children.push(this);
29
- }
30
- getProfiler() {
31
- return this.config.layerConfig.profiler;
32
- }
33
- startMemory() {
34
- this.config.layerConfig.profiler?.startMemory();
35
- }
36
- endMemory(t) {
37
- this.config.layerConfig.profiler?.endMemory(t);
38
- }
39
- addVariable(t, r) {
40
- this._variables.set(t, r || null);
41
- }
42
- get variables() {
43
- const t = Array.from(this._variables.values()).filter((e) => e !== null), r = this.children.flatMap((e) => e.variables);
44
- return [...t, ...r];
45
- }
46
- get trainableVariables() {
47
- const t = Array.from(this._variables.values()).filter(
48
- (e) => e !== null && e.trainable
49
- ), r = this.children.flatMap((e) => e.trainableVariables);
50
- return [...t, ...r];
51
- }
52
- get trainable() {
53
- return this._trainable;
54
- }
55
- set trainable(t) {
56
- this._trainable = t, this._variables.forEach((r) => {
57
- r && (r.trainable = t);
58
- }), this.children.forEach((r) => {
59
- r.trainable = t;
60
- });
61
- }
62
- getVariable(t) {
63
- const r = this._variables.get(t);
64
- if (!r)
65
- throw new Error(`Variable ${t} not found`);
66
- return r;
67
- }
68
- hasVariable(t) {
69
- return this._variables.get(t) !== null;
70
- }
71
- setVariable(t, r) {
72
- if (!this._variables.has(t))
73
- throw new Error(`Variable ${t} not found`);
74
- this._variables.set(t, r);
75
- }
76
- saveWeights(t) {
77
- this._variables.forEach((r, e) => {
78
- r && t.set(e, [r.clone()]);
79
- }), this.children.forEach((r) => {
80
- r.saveWeights(t);
81
- });
82
- }
83
- loadWeights(t) {
84
- this._variables.forEach((r, e) => {
85
- const i = t.get(e)?.[0];
86
- if (!i)
87
- throw new Error(`Weights for ${e} not found`);
88
- r ? r.assign(i) : this._variables.set(e, E(i, this._trainable));
89
- }), this.children.forEach((r) => {
90
- r.loadWeights(t);
91
- });
92
- }
93
- dispose() {
94
- this._variables.forEach((t) => {
95
- t?.dispose();
96
- }), this._variables.clear();
97
- }
98
- build() {
99
- }
100
- dropout(t) {
101
- return t;
102
- }
103
- call(t, ...r) {
104
- this.build();
105
- const e = this.forward(t, ...r);
106
- if (t.training && e instanceof v) {
107
- const i = this.dropout(e);
108
- return i !== e && e.dispose(), i;
109
- } else
110
- return e;
111
- }
112
- callCheckpoint(t, ...r) {
113
- return this.build(), this.checkpointingFn(t, ...r);
114
- }
115
- checkpointingFn(t, ...r) {
116
- const e = this.trainableVariables, s = _((...a) => {
117
- const h = a[a.length - 1], n = a.slice(0, r.length), c = this.forward(t, ...n);
118
- return h(n), { value: c, gradFunc: (f, u) => {
119
- const b = o().state.activeTape;
120
- o().state.activeTape = [];
121
- const d = V((...g) => this.forward(t, ...g.slice(0, n.length)))([...u, ...e], f);
122
- return o().state.activeTape = b, d;
123
- } };
124
- })(...r, ...e);
125
- if (t.training) {
126
- const a = this.dropout(s);
127
- return a !== s && s.dispose(), a;
128
- } else
129
- return s;
130
- }
131
- }
132
- export {
133
- m as B,
134
- E as v
135
- };