@genai-fi/nanogpt 0.3.1 → 0.4.0

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 +22 -22
  2. package/dist/MLP-KHhikThU.js +83 -0
  3. package/dist/NanoGPTModel.d.ts +2 -3
  4. package/dist/NanoGPTModel.js +79 -79
  5. package/dist/TeachableLLM.d.ts +4 -3
  6. package/dist/TeachableLLM.js +16 -13
  7. package/dist/Trainer.js +20 -13
  8. package/dist/axis_util-DeydwOoC.js +69 -0
  9. package/dist/{concat-BIZS_td9.js → concat-DS_qH7MI.js} +5 -5
  10. package/dist/config.js +7 -8
  11. package/dist/{gather-BPGW8RsB.js → gather-BUmJIS8n.js} +1 -1
  12. package/dist/{index-pWA4_lUh.js → index-XjBAhiFO.js} +1272 -1174
  13. package/dist/layers/BaseLayer.d.ts +14 -2
  14. package/dist/layers/BaseLayer.js +9 -9
  15. package/dist/layers/CausalSelfAttention.d.ts +4 -8
  16. package/dist/layers/CausalSelfAttention.js +108 -82
  17. package/dist/layers/MLP.d.ts +2 -3
  18. package/dist/layers/MLP.js +5 -62
  19. package/dist/layers/RMSNorm.d.ts +2 -2
  20. package/dist/layers/RMSNorm.js +11 -11
  21. package/dist/layers/RoPECache.js +3 -3
  22. package/dist/layers/TiedEmbedding.js +7 -6
  23. package/dist/layers/TransformerBlock.d.ts +2 -6
  24. package/dist/layers/TransformerBlock.js +9 -12
  25. package/dist/{sum-C7Mgy9Bw.js → log_sum_exp-DJPkVZZn.js} +32 -54
  26. package/dist/main.js +22 -19
  27. package/dist/{mat_mul-D7_a4KJn.js → mat_mul-CKwFEV1Q.js} +1 -1
  28. package/dist/max-DJvEiCAJ.js +25 -0
  29. package/dist/moments-CrWRPcR3.js +53 -0
  30. package/dist/norm-BzY929B_.js +86 -0
  31. package/dist/{ones-Cog-G2ag.js → ones-BO01zpJG.js} +2 -2
  32. package/dist/ops/appendCache.js +1 -1
  33. package/dist/ops/attentionMask.js +1 -1
  34. package/dist/ops/cpu/appendCache.js +2 -2
  35. package/dist/ops/cpu/attentionMask.js +2 -2
  36. package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
  37. package/dist/ops/cpu/fusedSoftmax.js +23 -0
  38. package/dist/ops/cpu/gatherSub.js +3 -3
  39. package/dist/ops/cpu/mulDropout.d.ts +1 -0
  40. package/dist/ops/cpu/mulDropout.js +17 -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 +27 -27
  44. package/dist/ops/fusedSoftmax.d.ts +2 -0
  45. package/dist/ops/fusedSoftmax.js +10 -0
  46. package/dist/ops/gatherSub.js +1 -1
  47. package/dist/ops/grads/attentionMask.js +1 -1
  48. package/dist/ops/grads/fusedSoftmax.d.ts +2 -0
  49. package/dist/ops/grads/fusedSoftmax.js +17 -0
  50. package/dist/ops/grads/qkv.js +1 -1
  51. package/dist/ops/grads/rope.js +1 -1
  52. package/dist/ops/mulDrop.d.ts +2 -0
  53. package/dist/ops/mulDrop.js +9 -0
  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.d.ts +11 -0
  60. package/dist/ops/webgl/fusedSoftmax.js +3930 -0
  61. package/dist/ops/webgl/gatherSub.js +1 -1
  62. package/dist/ops/webgl/mulDropout.d.ts +1 -0
  63. package/dist/ops/webgl/mulDropout.js +41 -0
  64. package/dist/ops/webgl/qkv.js +1 -1
  65. package/dist/ops/webgl/rope.js +1 -1
  66. package/dist/ops/webgl/scatterSub.js +1 -1
  67. package/dist/{random_width-oeUIlUZj.js → random_width-CMHmdbSu.js} +4212 -6630
  68. package/dist/{range-CcDl05lo.js → range-DQMNzBWs.js} +1 -1
  69. package/dist/{reshape-C8CR_Bad.js → reshape-DFzh97Sc.js} +1 -1
  70. package/dist/{sin-BJIrfnj7.js → sin-BYM-U4Ut.js} +1 -1
  71. package/dist/slice_util-CnVNPQI-.js +90 -0
  72. package/dist/softmax-4DOn6cPq.js +28 -0
  73. package/dist/{split-DZbvruEP.js → split-CkbeVdF8.js} +3 -3
  74. package/dist/{stack-BMm-efee.js → stack-DaIMO5iX.js} +1 -1
  75. package/dist/sum-C6u3xMi3.js +27 -0
  76. package/dist/{tensor-DJVbYhh1.js → tensor-Cu1fU7H7.js} +1 -1
  77. package/dist/{tensor2d-ZuQSh2D-.js → tensor2d-D0CKdG6B.js} +1 -1
  78. package/dist/tfjs_backend-Bzl2SrRo.js +2460 -0
  79. package/dist/training/AdamExt.js +1 -1
  80. package/dist/training/DatasetBuilder.js +3 -3
  81. package/dist/training/FullTrainer.js +41 -33
  82. package/dist/training/Trainer.d.ts +6 -1
  83. package/dist/training/Trainer.js +13 -12
  84. package/dist/training/sparseCrossEntropy.js +12 -11
  85. package/dist/utilities/dummy.js +8 -8
  86. package/dist/utilities/generate.js +11 -11
  87. package/dist/utilities/load.js +1 -1
  88. package/dist/utilities/profile.js +1 -1
  89. package/dist/utilities/weights.js +2 -2
  90. package/dist/{variable-Dl_ub3pk.js → variable-BS4AKqNU.js} +1 -1
  91. package/dist/{zeros-CCy9C3uU.js → zeros-CmJFiC84.js} +1 -1
  92. package/package.json +1 -1
  93. package/dist/exports_layers-tbTBcwMM.js +0 -25
  94. package/dist/layers/LayerNorm.d.ts +0 -13
  95. package/dist/layers/LayerNorm.js +0 -33
  96. package/dist/moments-DfcpfwKi.js +0 -132
  97. package/dist/softmax-Be_lsqUc.js +0 -105
  98. package/dist/training/LayerTrainer.d.ts +0 -29
  99. package/dist/training/LayerTrainer.js +0 -90
  100. package/dist/training/lwSchedule.d.ts +0 -7
  101. package/dist/training/lwSchedule.js +0 -162
@@ -1,4 +1,4 @@
1
- import { A as r, b as c, f as h, s as g, e as o } from "../index-pWA4_lUh.js";
1
+ import { A as r, b as c, f as h, s as g, e as o } from "../index-XjBAhiFO.js";
2
2
  class u extends r {
3
3
  constructor(t, e, s, a, i) {
4
4
  super(t, e, s, a), this.config = i, this.startLearningRate = t;
@@ -1,7 +1,7 @@
1
- import { a7 as $, a8 as m, a9 as M, a as R, aa as f, ab as v, ac as z, j as _, t as x } from "../index-pWA4_lUh.js";
1
+ import { a9 as $, aa as m, ab as M, a as R, ac as f, ad as v, ae as z, j as _, t as x } from "../index-XjBAhiFO.js";
2
2
  import { s as E } from "../index-C4L8Cm77.js";
3
- import { s as P } from "../stack-BMm-efee.js";
4
- import { t as D } from "../tensor-DJVbYhh1.js";
3
+ import { s as P } from "../stack-DaIMO5iX.js";
4
+ import { t as D } from "../tensor-Cu1fU7H7.js";
5
5
  import "../index-Tf7vU29b.js";
6
6
  /**
7
7
  * @license
@@ -1,69 +1,77 @@
1
- import { generateText as w } from "../utilities/generate.js";
2
- import x from "./Trainer.js";
3
- import g from "./Evaluator.js";
4
- import { a as h } from "../index-pWA4_lUh.js";
5
- const S = {
1
+ import { generateText as v } from "../utilities/generate.js";
2
+ import L from "./Trainer.js";
3
+ import x from "./Evaluator.js";
4
+ import { a as h } from "../index-XjBAhiFO.js";
5
+ const D = {
6
6
  desiredLoss: 0.01,
7
7
  logInterval: 1,
8
8
  maxSteps: 1e3
9
9
  };
10
- class D extends x {
10
+ class E extends L {
11
11
  constructor(r, i, o = 3e-4) {
12
12
  super(r, i, o);
13
13
  }
14
14
  // Train for multiple epochs using Dataset API - FIXED memory leaks
15
15
  async trainOnDataset(r, i, o) {
16
- const { desiredLoss: m, logInterval: u, onStep: n, prompt: l, maxSteps: d } = {
17
- ...S,
16
+ const { desiredLoss: u, logInterval: d, onStep: l, prompt: c, maxSteps: g } = {
17
+ ...D,
18
18
  ...i
19
- }, t = {
19
+ }, n = Date.now(), t = {
20
20
  step: 0,
21
21
  lastLoss: 1e6,
22
22
  totalSteps: 0,
23
23
  losses: [],
24
24
  validationLosses: [],
25
+ logStartTime: n,
26
+ trainingDuration: 0,
25
27
  ...this.lastState || {}
26
28
  };
27
- this.lastState = t, this.dummyPass(), this.model.trainable = !0;
28
- const f = Date.now();
29
- this.running = !0;
30
- const c = o ? new g(this.model, o) : void 0, v = await r.iterator();
29
+ this.lastState = t, this.dummyPass(), this.model.trainable = !0, this.running = !0, t.logStartTime = n;
30
+ const m = o ? new x(this.model, o) : void 0, S = await r.iterator();
31
31
  try {
32
- for (; this.running && !(t.lastLoss < m); ) {
33
- const e = await v.next();
34
- if (e.done) break;
35
- const p = e.value, L = this.trainBatch(t, p), a = {
32
+ for (; this.running && !(t.lastLoss < u); ) {
33
+ const a = await S.next();
34
+ if (a.done) break;
35
+ const p = a.value, f = this.trainBatch(t, p), s = {
36
36
  loss: t.lastLoss,
37
37
  step: t.step,
38
- time: Date.now() - f,
38
+ time: Date.now() - n,
39
39
  batchSize: p.xs.shape[0]
40
40
  };
41
- if (this.model.log.push(a), t.step % u === 0) {
42
- if (await L, c)
41
+ if (this.model.log.push(s), t.step % d === 0) {
42
+ await f;
43
+ const w = Date.now();
44
+ if (t.trainingDuration += w - t.logStartTime, m)
43
45
  try {
44
- const s = await c.evaluate(5);
45
- t.validationLosses.push(s), a.valLoss = s;
46
- } catch (s) {
47
- console.error("Validation error:", s);
46
+ const e = await m.evaluate(5);
47
+ t.validationLosses.push(e), s.valLoss = e;
48
+ } catch (e) {
49
+ console.error("Validation error:", e);
48
50
  }
49
- if (n) {
50
- if (l) {
51
- const s = await w(this.tokenizer, this.model, l, 100, {
51
+ if (l) {
52
+ if (c) {
53
+ const T = await v(this.tokenizer, this.model, c, 100, {
52
54
  temperature: 0.8
53
55
  });
54
- a.example = s;
56
+ s.example = T;
55
57
  }
56
- await n(a);
58
+ const e = {
59
+ duration: t.trainingDuration,
60
+ totalSamples: t.totalSteps * s.batchSize,
61
+ samplesPerSecond: t.totalSteps * s.batchSize / (t.trainingDuration / 1e3)
62
+ };
63
+ await l(s, e);
57
64
  }
65
+ t.logStartTime = Date.now();
58
66
  }
59
- t.step >= d && this.stop();
67
+ t.step >= g && this.stop();
60
68
  }
61
- } catch (e) {
62
- throw console.error("Training error:", e), h(), e;
69
+ } catch (a) {
70
+ throw console.error("Training error:", a), h(), a;
63
71
  }
64
72
  return h(), this.running = !1, { losses: t.losses, validationLosses: t.validationLosses };
65
73
  }
66
74
  }
67
75
  export {
68
- D as default
76
+ E as default
69
77
  };
@@ -12,6 +12,11 @@ export interface TrainingState {
12
12
  losses: number[];
13
13
  validationLosses: number[];
14
14
  }
15
+ export interface TrainingProgress {
16
+ duration: number;
17
+ totalSamples: number;
18
+ samplesPerSecond: number;
19
+ }
15
20
  export interface AdamConfig {
16
21
  learningRateFactor: number;
17
22
  beta1: number;
@@ -23,7 +28,7 @@ export interface TrainingOptions {
23
28
  logInterval: number;
24
29
  prompt?: string;
25
30
  maxSteps: number;
26
- onStep?: (log: TrainingLogEntry) => Promise<void> | void;
31
+ onStep?: (log: TrainingLogEntry, progress: TrainingProgress) => Promise<void> | void;
27
32
  }
28
33
  export default abstract class GPTTrainer {
29
34
  protected tokenizer: ITokeniser;
@@ -1,12 +1,13 @@
1
- import { DatasetBuilder as p } from "./DatasetBuilder.js";
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-pWA4_lUh.js";
4
- import { m as y, a as f, b as S, n as z } from "../moments-DfcpfwKi.js";
5
- import { m as b } from "../sum-C7Mgy9Bw.js";
6
- import { z as n } from "../zeros-CCy9C3uU.js";
7
- class M {
3
+ import { t as g, v as u, a as o } from "../index-XjBAhiFO.js";
4
+ import { m as y, n as f } from "../norm-BzY929B_.js";
5
+ import { m as S, a as z } from "../moments-CrWRPcR3.js";
6
+ import { m as b } from "../max-DJvEiCAJ.js";
7
+ import { z as n } from "../zeros-CmJFiC84.js";
8
+ class G {
8
9
  constructor(t, s, e = 1e-3) {
9
- this.tokenizer = s, this.model = t, this.learningRate = e, this.resetOptimizer(), this.datasetBuilder = new p(s, t.config.blockSize);
10
+ this.tokenizer = s, this.model = t, this.learningRate = e, this.resetOptimizer(), this.datasetBuilder = new d(s, t.config.gpt.blockSize);
10
11
  }
11
12
  model;
12
13
  optimizer;
@@ -45,21 +46,21 @@ class M {
45
46
  printGradients(t) {
46
47
  Object.keys(t).forEach((s) => {
47
48
  const e = t[s];
48
- console.log(`${s}:`), console.log(` Shape: ${e.shape}`), console.log(` Mean: ${y(e).dataSync()[0]}`), console.log(` Std: ${f(e).variance.sqrt().dataSync()[0]}`), console.log(` Min: ${S(e).dataSync()[0]}`), console.log(` Max: ${b(e).dataSync()[0]}`), console.log(` Norm: ${z(e).dataSync()[0]}`);
49
+ console.log(`${s}:`), console.log(` Shape: ${e.shape}`), console.log(` Mean: ${S(e).dataSync()[0]}`), console.log(` Std: ${z(e).variance.sqrt().dataSync()[0]}`), console.log(` Min: ${y(e).dataSync()[0]}`), console.log(` Max: ${b(e).dataSync()[0]}`), console.log(` Norm: ${f(e).dataSync()[0]}`);
49
50
  });
50
51
  }
51
52
  trainStep(t, s = !1, e = !1) {
52
53
  return g(() => {
53
54
  this.model.getProfiler()?.startMemory();
54
55
  const { xs: a, ys: r } = t, l = () => {
55
- const { loss: d, logits: m } = this.model.forward(a, r, !0);
56
- return m.dispose(), d;
56
+ const { loss: m, logits: p } = this.model.forward(a, r, !0);
57
+ return p.dispose(), m;
57
58
  }, { value: c, grads: i } = u(l);
58
59
  return s ? this.model.getProfiler()?.endMemory("Training") : (e && (console.log("-------"), this.printGradients(i), console.log("-------")), this.optimizer.applyGradients(i), this.model.getProfiler()?.endMemory("Training"), o(i)), c;
59
60
  });
60
61
  }
61
62
  dummyPass() {
62
- const t = n([1, this.model.config.blockSize], "int32"), s = n([1, this.model.config.blockSize], "int32");
63
+ const t = n([1, this.model.config.gpt.blockSize], "int32"), s = n([1, this.model.config.gpt.blockSize], "int32");
63
64
  try {
64
65
  const e = this.trainStep({ xs: t, ys: s }, !0);
65
66
  e.dataSync(), e.dispose();
@@ -94,5 +95,5 @@ class M {
94
95
  }
95
96
  }
96
97
  export {
97
- M as default
98
+ G as default
98
99
  };
@@ -1,26 +1,27 @@
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-pWA4_lUh.js";
4
- import { s as v, l as z } from "../softmax-Be_lsqUc.js";
5
- import { m as k } from "../sum-C7Mgy9Bw.js";
3
+ import { e as u, c as i, z as S, t as f, s as G } from "../index-XjBAhiFO.js";
4
+ import { s as v } from "../softmax-4DOn6cPq.js";
5
+ import { m as z } from "../max-DJvEiCAJ.js";
6
+ import { l as k } from "../log_sum_exp-DJPkVZZn.js";
6
7
  function F(a, s) {
7
8
  return f(() => {
8
- const e = a.shape[a.shape.length - 1], n = a.shape.slice(0, -1).reduce((d, c) => d * c, 1), p = a.shape.length > 2 ? a.reshape([n, e]) : a, o = s.shape.length > 1 ? s.reshape([n]).cast("int32") : s.cast("int32"), t = k(p, -1, !0), r = G(p, t), h = z(r, -1);
9
- return L(h, o, r);
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);
10
+ return L(h, n, r);
10
11
  });
11
12
  }
12
- function $() {
13
+ function j() {
13
14
  return u().backendName === "tensorflow" ? i((s, e, m) => {
14
- const n = s.shape.length > 2 ? s.reshape([-1, s.shape[s.shape.length - 1]]) : s, p = e.shape.length > 1 ? e.reshape([-1]).cast("int32") : e.cast("int32"), [o, t] = u().runKernel(
15
+ const o = s.shape.length > 2 ? s.reshape([-1, s.shape[s.shape.length - 1]]) : s, p = e.shape.length > 1 ? e.reshape([-1]).cast("int32") : e.cast("int32"), [n, t] = u().runKernel(
15
16
  "NativeSparseSoftmaxCrossEntropy",
16
- { logits: n, labels: p },
17
+ { logits: o, labels: p },
17
18
  {}
18
19
  );
19
- return m([t.reshape(s.shape)]), { value: o, gradFunc: (r, h) => [h[0], S(e)] };
20
+ return m([t.reshape(s.shape)]), { value: n, gradFunc: (r, h) => [h[0], S(e)] };
20
21
  }) : i(
21
22
  // @ts-expect-error Invalid params
22
23
  (s, e, m) => {
23
- const n = s.shape[s.shape.length - 1], o = s.shape.slice(0, -1).reduce((d, c) => d * c, 1), t = s.reshape([o, n]), r = e.reshape([o]).cast("int32"), h = F(t, r);
24
+ const o = s.shape[s.shape.length - 1], n = s.shape.slice(0, -1).reduce((d, c) => d * c, 1), t = s.reshape([n, o]), r = e.reshape([n]).cast("int32"), h = F(t, r);
24
25
  return m([t, r]), t.dispose(), r.dispose(), { value: h, gradFunc: (d, c) => f(() => {
25
26
  const l = c[0], b = c[1], x = v(l), C = y(x, b, d), E = S(e);
26
27
  return [C.reshape(s.shape), E];
@@ -29,6 +30,6 @@ function $() {
29
30
  );
30
31
  }
31
32
  export {
32
- $ as createSoftmaxCrossEntropyWithGrad,
33
+ j as createSoftmaxCrossEntropyWithGrad,
33
34
  F as sparseSoftmaxCrossEntropy
34
35
  };
@@ -1,14 +1,14 @@
1
- import "../index-pWA4_lUh.js";
2
- import { z as n } from "../zeros-CCy9C3uU.js";
3
- async function c(s) {
4
- const o = n([1, s.config.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
1
+ import "../index-XjBAhiFO.js";
2
+ import { z as n } from "../zeros-CmJFiC84.js";
3
+ async function a(s) {
4
+ const o = n([1, s.config.gpt.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
5
5
  await t.data(), t.dispose(), i && i.dispose(), o.dispose();
6
6
  }
7
- function f(s) {
8
- const o = n([1, s.config.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
7
+ function c(s) {
8
+ const o = n([1, s.config.gpt.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
9
9
  t.dispose(), i && i.dispose(), o.dispose();
10
10
  }
11
11
  export {
12
- f as dummyPass,
13
- c as dummyPassAsync
12
+ c as dummyPass,
13
+ a as dummyPassAsync
14
14
  };
@@ -1,20 +1,20 @@
1
- import { t as y } from "../index-pWA4_lUh.js";
2
- import { t as x } from "../tensor2d-ZuQSh2D-.js";
3
- import { c as g } from "../concat-BIZS_td9.js";
1
+ import { t as y } from "../index-XjBAhiFO.js";
2
+ import { t as x } from "../tensor2d-D0CKdG6B.js";
3
+ import { c as f } from "../concat-DS_qH7MI.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");
7
7
  if (a.length === 0)
8
8
  throw new Error("Prompt cannot be an empty string");
9
- const d = await o.tokenise([a], !0), s = r.config.useRope ? new Array(r.config.nLayer).fill(void 0) : void 0, p = y(() => {
10
- let e = x(d, [1, d[0].length], "int32"), t = e;
11
- for (let f = 0; f < c; f++) {
12
- const { output: n } = r.generate(e, s, T), l = e, m = t;
13
- t = g([t, n], 1), e = s ? n : g([e, n], 1), l.dispose(), m.dispose(), s || n.dispose();
9
+ const p = await o.tokenise([a], !0), s = r.config.gpt.useRope ? new Array(r.config.gpt.nLayer).fill(void 0) : void 0, d = y(() => {
10
+ let t = x(p, [1, p[0].length], "int32"), e = t;
11
+ for (let g = 0; g < c; g++) {
12
+ const { output: n } = r.generate(t, s, T), l = t, m = e;
13
+ e = f([e, n], 1), t = s ? n : f([t, n], 1), l.dispose(), m.dispose(), s || n.dispose();
14
14
  }
15
- return t;
16
- }), w = await p.array();
17
- p.dispose();
15
+ return e;
16
+ }), w = await d.array();
17
+ d.dispose();
18
18
  const i = w[0], u = i.indexOf(o.eosToken);
19
19
  return u !== -1 && i.splice(u), await o.decode(i);
20
20
  }
@@ -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-pWA4_lUh.js";
6
+ import { d as T } from "../index-XjBAhiFO.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-pWA4_lUh.js";
1
+ import { m as s } from "../index-XjBAhiFO.js";
2
2
  const m = 1024 * 1024;
3
3
  class i {
4
4
  log = /* @__PURE__ */ new Map();
@@ -1,5 +1,5 @@
1
- import "../index-pWA4_lUh.js";
2
- import { t as p } from "../tensor-DJVbYhh1.js";
1
+ import "../index-XjBAhiFO.js";
2
+ import { t as p } from "../tensor-Cu1fU7H7.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;
@@ -1,4 +1,4 @@
1
- import { E as i } from "./index-pWA4_lUh.js";
1
+ import { E as i } from "./index-XjBAhiFO.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { o as m, h as r, M as l, E as c, N as i, k as p, O as u, n as f } from "./index-pWA4_lUh.js";
1
+ import { o as m, h as r, U as l, E as c, V as i, k as p, W as u, n as f } from "./index-XjBAhiFO.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -1,25 +0,0 @@
1
- import { E as e, D as r, a as o } from "./random_width-oeUIlUZj.js";
2
- import "./index-pWA4_lUh.js";
3
- /**
4
- * @license
5
- * Copyright 2018 Google LLC
6
- *
7
- * Use of this source code is governed by an MIT-style
8
- * license that can be found in the LICENSE file or at
9
- * https://opensource.org/licenses/MIT.
10
- * =============================================================================
11
- */
12
- function s(n) {
13
- return new o(n);
14
- }
15
- function u(n) {
16
- return new r(n);
17
- }
18
- function d(n) {
19
- return new e(n);
20
- }
21
- export {
22
- u as a,
23
- s as d,
24
- d as e
25
- };
@@ -1,13 +0,0 @@
1
- import { default as TF } from '@tensorflow/tfjs';
2
- export default class LayerNorm {
3
- private gamma;
4
- private epsilon;
5
- private tf;
6
- constructor(tf: typeof TF, shape: number[], epsilon?: number, name?: string);
7
- get trainableWeights(): TF.Variable[];
8
- set trainable(value: boolean);
9
- getWeights(): TF.Tensor[];
10
- setWeights(weights: TF.Tensor[]): void;
11
- apply(x: TF.Tensor): TF.Tensor;
12
- dispose(): void;
13
- }
@@ -1,33 +0,0 @@
1
- class h {
2
- gamma;
3
- //private beta: TF.Variable;
4
- epsilon;
5
- tf;
6
- constructor(a, s, t = 1e-5, e = "") {
7
- this.tf = a, this.epsilon = t, this.gamma = a.variable(a.ones(s), !0, `${e}_gamma`, "float32");
8
- }
9
- get trainableWeights() {
10
- return [this.gamma];
11
- }
12
- set trainable(a) {
13
- this.gamma.trainable = a;
14
- }
15
- getWeights() {
16
- return [this.gamma];
17
- }
18
- setWeights(a) {
19
- this.gamma.assign(a[0]);
20
- }
21
- apply(a) {
22
- return this.tf.tidy(() => {
23
- const s = a.mean(-1, !0), t = a.sub(s), i = t.square().mean(-1, !0).add(this.epsilon).rsqrt();
24
- return t.mul(i).mul(this.gamma);
25
- });
26
- }
27
- dispose() {
28
- this.gamma.dispose();
29
- }
30
- }
31
- export {
32
- h as default
33
- };
@@ -1,132 +0,0 @@
1
- import { o as i, h as m, E as y, a2 as A, a0 as E, a3 as o, a4 as h, J as b, f as S, a5 as v, a6 as _, s as k, U as q } from "./index-pWA4_lUh.js";
2
- import { e as w, s as u, m as l } from "./sum-C7Mgy9Bw.js";
3
- import { r as c } from "./reshape-C8CR_Bad.js";
4
- /**
5
- * @license
6
- * Copyright 2020 Google Inc. 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 K(r, e = null, n = !1) {
21
- const t = { x: m(r, "x", "min") }, a = { axis: e, keepDims: n };
22
- return y.runKernel(A, t, a);
23
- }
24
- const d = /* @__PURE__ */ i({ min_: K });
25
- /**
26
- * @license
27
- * Copyright 2018 Google LLC. All Rights Reserved.
28
- * Licensed under the Apache License, Version 2.0 (the "License");
29
- * you may not use this file except in compliance with the License.
30
- * You may obtain a copy of the License at
31
- *
32
- * http://www.apache.org/licenses/LICENSE-2.0
33
- *
34
- * Unless required by applicable law or agreed to in writing, software
35
- * distributed under the License is distributed on an "AS IS" BASIS,
36
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
- * See the License for the specific language governing permissions and
38
- * limitations under the License.
39
- * =============================================================================
40
- */
41
- function M(r, e = "euclidean", n = null, s = !1) {
42
- r = m(r, "x", "norm");
43
- const t = $(r, e, n);
44
- let a = t.shape;
45
- if (s) {
46
- const f = E(n, r.shape);
47
- a = w(t.shape, f);
48
- }
49
- return c(t, a);
50
- }
51
- function $(r, e, n = null) {
52
- if (r.rank === 0)
53
- return o(r);
54
- if (r.rank !== 1 && n === null)
55
- return $(c(r, [-1]), e, n);
56
- if (r.rank === 1 || typeof n == "number" || Array.isArray(n) && n.length === 1) {
57
- if (e === 1)
58
- return u(o(r), n);
59
- if (e === 1 / 0)
60
- return l(o(r), n);
61
- if (e === -1 / 0)
62
- return d(o(r), n);
63
- if (e === "euclidean" || e === 2)
64
- return h(u(b(o(r), S(2, "int32")), n));
65
- throw new Error(`Error in norm: invalid ord value: ${e}`);
66
- }
67
- if (Array.isArray(n) && n.length === 2) {
68
- if (e === 1)
69
- return l(u(o(r), n[0]), n[1] - 1);
70
- if (e === 1 / 0)
71
- return l(u(o(r), n[1]), n[0]);
72
- if (e === -1 / 0)
73
- return d(u(o(r), n[1]), n[0]);
74
- if (e === "fro" || e === "euclidean")
75
- return h(u(v(r), n));
76
- throw new Error(`Error in norm: invalid ord value: ${e}`);
77
- }
78
- throw new Error(`Error in norm: invalid axis: ${n}`);
79
- }
80
- const J = /* @__PURE__ */ i({ norm_: M });
81
- /**
82
- * @license
83
- * Copyright 2020 Google Inc. All Rights Reserved.
84
- * Licensed under the Apache License, Version 2.0 (the "License");
85
- * you may not use this file except in compliance with the License.
86
- * You may obtain a copy of the License at
87
- *
88
- * http://www.apache.org/licenses/LICENSE-2.0
89
- *
90
- * Unless required by applicable law or agreed to in writing, software
91
- * distributed under the License is distributed on an "AS IS" BASIS,
92
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93
- * See the License for the specific language governing permissions and
94
- * limitations under the License.
95
- * =============================================================================
96
- */
97
- function T(r, e = null, n = !1) {
98
- const t = { x: m(r, "x", "mean") }, a = { axis: e, keepDims: n };
99
- return y.runKernel(_, t, a);
100
- }
101
- const p = /* @__PURE__ */ i({ mean_: T });
102
- /**
103
- * @license
104
- * Copyright 2020 Google LLC. All Rights Reserved.
105
- * Licensed under the Apache License, Version 2.0 (the "License");
106
- * you may not use this file except in compliance with the License.
107
- * You may obtain a copy of the License at
108
- *
109
- * http://www.apache.org/licenses/LICENSE-2.0
110
- *
111
- * Unless required by applicable law or agreed to in writing, software
112
- * distributed under the License is distributed on an "AS IS" BASIS,
113
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
- * See the License for the specific language governing permissions and
115
- * limitations under the License.
116
- * =============================================================================
117
- */
118
- function g(r, e = null, n = !1) {
119
- r = m(r, "x", "moments");
120
- const s = E(e, r.shape), t = p(r, s, n);
121
- let a = t.shape;
122
- n || (a = w(t.shape, s));
123
- const f = v(k(q(r, "float32"), c(t, a))), I = p(f, s, n);
124
- return { mean: t, variance: I };
125
- }
126
- const P = /* @__PURE__ */ i({ moments_: g });
127
- export {
128
- P as a,
129
- d as b,
130
- p as m,
131
- J as n
132
- };