@genai-fi/nanogpt 0.4.2 → 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 (94) hide show
  1. package/dist/Generator.js +3 -3
  2. package/dist/NanoGPTModel.js +73 -76
  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 +44 -44
  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.d.ts +1 -1
  29. package/dist/ops/appendCache.js +10 -4
  30. package/dist/ops/attentionMask.js +1 -1
  31. package/dist/ops/cpu/appendCache.d.ts +1 -2
  32. package/dist/ops/cpu/appendCache.js +15 -20
  33. package/dist/ops/cpu/attentionMask.js +10 -10
  34. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  35. package/dist/ops/cpu/gatherSub.js +4 -4
  36. package/dist/ops/cpu/gelu.js +1 -1
  37. package/dist/ops/cpu/matMulGelu.d.ts +1 -0
  38. package/dist/ops/cpu/matMulGelu.js +40 -0
  39. package/dist/ops/cpu/mulDropout.js +1 -1
  40. package/dist/ops/cpu/qkv.js +3 -3
  41. package/dist/ops/cpu/rope.js +5 -5
  42. package/dist/ops/cpu/scatterSub.js +4 -4
  43. package/dist/ops/fusedSoftmax.js +1 -1
  44. package/dist/ops/gatherSub.js +1 -1
  45. package/dist/ops/gelu.js +2 -2
  46. package/dist/ops/grads/attentionMask.js +1 -1
  47. package/dist/ops/grads/fusedSoftmax.js +2 -2
  48. package/dist/ops/grads/gelu.js +24 -3
  49. package/dist/ops/grads/matMulGelu.d.ts +1 -0
  50. package/dist/ops/grads/matMulGelu.js +17 -0
  51. package/dist/ops/grads/qkv.js +1 -1
  52. package/dist/ops/grads/rope.js +1 -1
  53. package/dist/ops/matMulGelu.d.ts +3 -0
  54. package/dist/ops/matMulGelu.js +14 -0
  55. package/dist/ops/mulDrop.js +1 -1
  56. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  57. package/dist/ops/qkv.js +1 -1
  58. package/dist/ops/scatterSub.js +1 -1
  59. package/dist/ops/webgl/appendCache.js +14 -13
  60. package/dist/ops/webgl/attentionMask.js +1 -1
  61. package/dist/ops/webgl/fusedSoftmax.js +689 -895
  62. package/dist/ops/webgl/gatherSub.js +1 -1
  63. package/dist/ops/webgl/gelu.js +2 -2
  64. package/dist/ops/webgl/matMulGelu.d.ts +20 -0
  65. package/dist/ops/webgl/matMulGelu.js +166 -0
  66. package/dist/ops/webgl/mulDropout.js +1 -1
  67. package/dist/ops/webgl/qkv.js +1 -1
  68. package/dist/ops/webgl/rope.js +1 -1
  69. package/dist/ops/webgl/scatterSub.js +1 -1
  70. package/dist/{range-9AzeApCc.js → range-C_vpUjBu.js} +1 -1
  71. package/dist/{reshape-Boe4DuIO.js → reshape-z51Eu-re.js} +1 -1
  72. package/dist/{sin-KmhiDuMa.js → sin-H567uayl.js} +1 -1
  73. package/dist/{slice_util-19zDNNSn.js → slice_util-BdhYwFY_.js} +2 -2
  74. package/dist/{softmax-Cujsg4ay.js → softmax-Dsxflvdl.js} +1 -1
  75. package/dist/{split-DbcNm1-i.js → split-B_k_jwud.js} +1 -1
  76. package/dist/{stack-D1YjmgKN.js → stack-CmqSdsfs.js} +1 -1
  77. package/dist/{sum-R28pucR5.js → sum-DdkDf2MG.js} +1 -1
  78. package/dist/{tensor-BVeHdl7V.js → tensor-BGYi41cj.js} +1 -1
  79. package/dist/{tensor2d-DqFGNs_K.js → tensor2d-DUr_htjt.js} +1 -1
  80. package/dist/{tfjs_backend-Cug-PH75.js → tfjs_backend-DuKis_xG.js} +46 -46
  81. package/dist/training/AdamExt.js +1 -1
  82. package/dist/training/DatasetBuilder.js +18 -18
  83. package/dist/training/FullTrainer.js +1 -1
  84. package/dist/training/Trainer.js +5 -5
  85. package/dist/training/sparseCrossEntropy.js +4 -4
  86. package/dist/utilities/dummy.js +2 -2
  87. package/dist/utilities/generate.js +3 -3
  88. package/dist/utilities/load.js +1 -1
  89. package/dist/utilities/profile.js +1 -1
  90. package/dist/utilities/weights.js +2 -2
  91. package/dist/{variable-LJT9Ld63.js → variable-BJTZ3jOy.js} +1 -1
  92. package/dist/{zeros-dnQxFgAD.js → zeros-8xl-W2DC.js} +1 -1
  93. package/package.json +1 -1
  94. package/dist/gelu-CnCt17Lk.js +0 -26
@@ -1,6 +1,6 @@
1
- import { o as u, h as c, E as g, L as h, r as m, s as p } from "../../index-C4JCoBvj.js";
2
- import { r as l } from "../../range-9AzeApCc.js";
3
- import { s as N } from "../../stack-D1YjmgKN.js";
1
+ import { o as u, h as c, E as g, N as h, r as m, s as p } from "../../index--6vO-cOz.js";
2
+ import { r as N } from "../../range-C_vpUjBu.js";
3
+ import { s as l } from "../../stack-CmqSdsfs.js";
4
4
  /**
5
5
  * @license
6
6
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -23,7 +23,7 @@ function f(e, s) {
23
23
  }
24
24
  const b = /* @__PURE__ */ u({ gatherND_: f });
25
25
  function d(e) {
26
- const { values: s, labels: n, logits: r } = e.inputs, t = n.shape[0], o = l(0, t, 1, "int32"), a = N([o, n], 1), i = b(r, a);
26
+ const { values: s, labels: n, logits: r } = e.inputs, t = n.shape[0], o = N(0, t, 1, "int32"), a = l([o, n], 1), i = b(r, a);
27
27
  return p(s, i);
28
28
  }
29
29
  const k = {
@@ -1,4 +1,4 @@
1
- import { r as t, t as d } from "../../index-C4JCoBvj.js";
1
+ import { r as t, t as d } from "../../index--6vO-cOz.js";
2
2
  const o = 0.7978845608028654, c = 0.044715;
3
3
  function m(u) {
4
4
  const { inputs: l } = u, { x: e } = l, n = e;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { r as a, t as i } from "../../index--6vO-cOz.js";
2
+ const c = 0.7978845608028654, m = 0.044715;
3
+ function M(o) {
4
+ const { inputs: s } = o, { x: t, kernel: l } = s, e = t, u = l;
5
+ return i(() => {
6
+ const n = e.matMul(u), d = n.mul(n).mul(n), r = n.add(d.mul(m)).mul(c).tanh().add(1).mul(0.5);
7
+ return n.mul(r);
8
+ });
9
+ }
10
+ const b = {
11
+ kernelName: "MatMulGelu",
12
+ backendName: "cpu",
13
+ kernelFunc: M
14
+ };
15
+ a(b);
16
+ const w = {
17
+ kernelName: "MatMulGelu",
18
+ backendName: "tensorflow",
19
+ kernelFunc: M
20
+ };
21
+ a(w);
22
+ function f(o) {
23
+ const { dy: s, x: t, kernel: l } = o.inputs;
24
+ return i(() => {
25
+ const e = t.matMul(l), u = e.square(), n = u.mul(e), r = e.add(n.mul(m)).mul(c).tanh(), G = r.square().neg().add(1), g = u.mul(3 * m).add(1), p = r.add(1).mul(0.5), N = e.mul(G).mul(c).mul(g).mul(0.5), K = p.add(N), k = s.mul(K), h = k.matMul(l.transpose()), F = t.transpose().matMul(k);
26
+ return [h, F];
27
+ });
28
+ }
29
+ const x = {
30
+ kernelName: "MatMulGeluGrad",
31
+ backendName: "cpu",
32
+ kernelFunc: f
33
+ };
34
+ a(x);
35
+ const C = {
36
+ kernelName: "MatMulGeluGrad",
37
+ backendName: "tensorflow",
38
+ kernelFunc: f
39
+ };
40
+ a(C);
@@ -1,4 +1,4 @@
1
- import { r as e, b as u } from "../../index-C4JCoBvj.js";
1
+ import { r as e, b as u } from "../../index--6vO-cOz.js";
2
2
  function n(o) {
3
3
  const { inputs: r } = o, { a: l, b: t } = r;
4
4
  return console.warn("Using fallback mulDrop implementation without dropout."), u(l, t);
@@ -1,6 +1,6 @@
1
- import { r as q } from "../../index-C4JCoBvj.js";
2
- import { r as o } from "../../reshape-Boe4DuIO.js";
3
- import { s as x } from "../../split-DbcNm1-i.js";
1
+ import { r as q } from "../../index--6vO-cOz.js";
2
+ import { r as o } from "../../reshape-z51Eu-re.js";
3
+ import { s as x } from "../../split-B_k_jwud.js";
4
4
  function v(p) {
5
5
  const { x: c, kernel: K } = p.inputs, { heads: n } = p.attrs, [s, e, t] = c.shape, a = o(c, [s * e, t]), i = a.dot(K);
6
6
  a.dispose();
@@ -1,8 +1,8 @@
1
- import { r as S } from "../../index-C4JCoBvj.js";
2
- import { r as F } from "../../range-9AzeApCc.js";
3
- import { g as I } from "../../gather-ZYRWhmXR.js";
4
- import { s as E } from "../../stack-D1YjmgKN.js";
5
- import { c as T } from "../../concat-CuRsVY-K.js";
1
+ import { r as S } from "../../index--6vO-cOz.js";
2
+ import { r as F } from "../../range-C_vpUjBu.js";
3
+ import { g as I } from "../../gather-C5D8PxwA.js";
4
+ import { s as E } from "../../stack-CmqSdsfs.js";
5
+ import { c as T } from "../../concat-DvWM7HGZ.js";
6
6
  function U(t, c, p, o, r) {
7
7
  const n = o.shape[3], s = p;
8
8
  if (s > n) return o;
@@ -1,7 +1,7 @@
1
- import { o as l, k, h, E as g, a2 as w, r as $, s as d, b as m } from "../../index-C4JCoBvj.js";
2
- import { r as b } from "../../range-9AzeApCc.js";
3
- import { s as E } from "../../stack-D1YjmgKN.js";
4
- import { o as D } from "../../ones-Bf3YR48P.js";
1
+ import { o as l, k, h, E as g, a5 as w, r as $, s as d, b as m } from "../../index--6vO-cOz.js";
2
+ import { r as b } from "../../range-C_vpUjBu.js";
3
+ import { s as E } from "../../stack-CmqSdsfs.js";
4
+ import { o as D } from "../../ones-D6kB8bdY.js";
5
5
  function N(n, r, t) {
6
6
  const s = r.rank > 1 ? r.shape[r.rank - 1] : 1, e = r.rank > 1 ? r.rank - 1 : 1, o = `Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: ${t.shape}, indices.shape: ${r.shape}, shape: ${n}, sliceDim: ${s}, and batchDim: ${e}.`;
7
7
  if (t.rank < e)
@@ -1,4 +1,4 @@
1
- import { e as t } from "../index-C4JCoBvj.js";
1
+ import { e as t } from "../index--6vO-cOz.js";
2
2
  import "./cpu/fusedSoftmax.js";
3
3
  import "./webgl/fusedSoftmax.js";
4
4
  import "./grads/fusedSoftmax.js";
@@ -1,4 +1,4 @@
1
- import { e as n } from "../index-C4JCoBvj.js";
1
+ import { e as n } from "../index--6vO-cOz.js";
2
2
  import "./cpu/gatherSub.js";
3
3
  import "./webgl/gatherSub.js";
4
4
  function f(r, e, t) {
package/dist/ops/gelu.js CHANGED
@@ -1,7 +1,7 @@
1
- import "../index-C4JCoBvj.js";
1
+ import "../index--6vO-cOz.js";
2
2
  import "./cpu/gelu.js";
3
3
  import "./webgl/gelu.js";
4
- import { d as e, g as i } from "../gelu-CnCt17Lk.js";
4
+ import { d as e, g as i } from "./grads/gelu.js";
5
5
  export {
6
6
  e as dGelu,
7
7
  i as gelu
@@ -1,4 +1,4 @@
1
- import { g as i } from "../../index-C4JCoBvj.js";
1
+ import { g as i } from "../../index--6vO-cOz.js";
2
2
  const u = {
3
3
  kernelName: "AttentionMask",
4
4
  inputsToSave: ["q", "k"],
@@ -1,6 +1,6 @@
1
- import { g as p, b as m, s as d } from "../../index-C4JCoBvj.js";
1
+ import { g as p, b as m, s as d } from "../../index--6vO-cOz.js";
2
2
  import { mulDrop as c } from "../mulDrop.js";
3
- import { s as f } from "../../sum-R28pucR5.js";
3
+ import { s as f } from "../../sum-DdkDf2MG.js";
4
4
  const g = {
5
5
  kernelName: "FusedSoftmax",
6
6
  outputsToSave: [!0],
@@ -1,5 +1,26 @@
1
- import "../../index-C4JCoBvj.js";
2
- import { a as e } from "../../gelu-CnCt17Lk.js";
1
+ import { g as t, e as n } from "../../index--6vO-cOz.js";
2
+ import "../cpu/gelu.js";
3
+ import "../webgl/gelu.js";
4
+ const o = {
5
+ kernelName: "Gelu",
6
+ inputsToSave: ["x"],
7
+ outputsToSave: [],
8
+ gradFunc: (e, r) => {
9
+ const [u] = r;
10
+ return {
11
+ x: () => a(e, u)
12
+ };
13
+ }
14
+ };
15
+ t(o);
16
+ function g(e) {
17
+ return n().runKernel("Gelu", { x: e });
18
+ }
19
+ function a(e, r) {
20
+ return n().runKernel("GeluGrad", { dy: e, x: r });
21
+ }
3
22
  export {
4
- e as geluGradConfig
23
+ a as d,
24
+ g,
25
+ o as geluGradConfig
5
26
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { g as a, e as o } from "../../index--6vO-cOz.js";
2
+ function s(e, n, r) {
3
+ return o().runKernel("MatMulGeluGrad", { dy: e, x: n, kernel: r });
4
+ }
5
+ const d = {
6
+ kernelName: "MatMulGelu",
7
+ inputsToSave: ["x", "kernel"],
8
+ outputsToSave: [],
9
+ gradFunc: (e, n) => {
10
+ const [r, t] = n, [u, l] = s(e, r, t);
11
+ return {
12
+ x: () => u,
13
+ kernel: () => l
14
+ };
15
+ }
16
+ };
17
+ a(d);
@@ -1,4 +1,4 @@
1
- import { g as v } from "../../index-C4JCoBvj.js";
1
+ import { g as v } from "../../index--6vO-cOz.js";
2
2
  const g = {
3
3
  kernelName: "QKV",
4
4
  inputsToSave: ["x", "kernel"],
@@ -1,4 +1,4 @@
1
- import { g as a, e as i } from "../../index-C4JCoBvj.js";
1
+ import { g as a, e as i } from "../../index--6vO-cOz.js";
2
2
  function p(n, e, s, o) {
3
3
  return i().runKernel("Rope", { x: n, sin: e, cos: s }, { pastLen: o });
4
4
  }
@@ -0,0 +1,3 @@
1
+ import { Tensor } from '@tensorflow/tfjs-core';
2
+ export declare function matMulGelu(x: Tensor, kernel: Tensor): Tensor;
3
+ export declare function dMatMulGelu(dy: Tensor, x: Tensor, kernel: Tensor): Tensor;
@@ -0,0 +1,14 @@
1
+ import { e as u } from "../index--6vO-cOz.js";
2
+ import "./cpu/matMulGelu.js";
3
+ import "./webgl/matMulGelu.js";
4
+ import "./grads/matMulGelu.js";
5
+ function M(r, e) {
6
+ return u().runKernel("MatMulGelu", { x: r, kernel: e });
7
+ }
8
+ function a(r, e, t) {
9
+ return u().runKernel("MatMulGeluGrad", { dy: r, x: e, kernel: t });
10
+ }
11
+ export {
12
+ a as dMatMulGelu,
13
+ M as matMulGelu
14
+ };
@@ -1,4 +1,4 @@
1
- import { e as t } from "../index-C4JCoBvj.js";
1
+ import { e as t } from "../index--6vO-cOz.js";
2
2
  import "./cpu/mulDropout.js";
3
3
  import "./webgl/mulDropout.js";
4
4
  function m(r, o, e, n) {
@@ -1,4 +1,4 @@
1
- import { r as o } from "../../index-C4JCoBvj.js";
1
+ import { r as o } from "../../index--6vO-cOz.js";
2
2
  function r(e) {
3
3
  const { logits: t, labels: n } = e.inputs;
4
4
  return e.backend.executeMultipleOutputs("SparseSoftmaxCrossEntropyWithLogits", [], [t, n], 2);
package/dist/ops/qkv.js CHANGED
@@ -1,4 +1,4 @@
1
- import { e as o } from "../index-C4JCoBvj.js";
1
+ import { e as o } from "../index--6vO-cOz.js";
2
2
  import "./cpu/qkv.js";
3
3
  import "./webgl/qkv.js";
4
4
  import "./grads/qkv.js";
@@ -1,4 +1,4 @@
1
- import { e as i } from "../index-C4JCoBvj.js";
1
+ import { e as i } from "../index--6vO-cOz.js";
2
2
  import "./cpu/scatterSub.js";
3
3
  import "./webgl/scatterSub.js";
4
4
  function c(t, r, e) {
@@ -1,12 +1,12 @@
1
- import { r as h } from "../../index-C4JCoBvj.js";
1
+ import { r as p } from "../../index--6vO-cOz.js";
2
2
  class m {
3
3
  variableNames = ["cache", "item"];
4
4
  outputShape;
5
5
  userCode;
6
6
  customUniforms = [{ name: "cacheT", type: "int" }];
7
- constructor(t, a, o, s, n) {
8
- const c = Math.min(o + 1, n);
9
- this.outputShape = [t, a, c, s], this.userCode = `
7
+ constructor(t, a, n, o, c) {
8
+ const s = Math.min(n + 1, c);
9
+ this.outputShape = [t, a, s, o], this.userCode = `
10
10
  void main() {
11
11
  ivec4 coords = getOutputCoords(); // [b, h, t, d]
12
12
  int b = coords.x;
@@ -15,7 +15,7 @@ class m {
15
15
  int d = coords.w;
16
16
 
17
17
  int itemT = 1;
18
- int maxSize = ${n};
18
+ int maxSize = ${c};
19
19
  int totalT = cacheT + itemT;
20
20
  int start = totalT >= maxSize ? 1 : 0;
21
21
 
@@ -23,21 +23,22 @@ class m {
23
23
  float val = 0.0;
24
24
  if (srcT < cacheT) {
25
25
  val = getCache(b, h, srcT, d);
26
- } else {
26
+ } else if (srcT == cacheT) {
27
27
  val = getItem(b, h, 0, d);
28
- }
28
+ } else {
29
+ val = 0.0;}
29
30
  setOutput(val);
30
31
  }
31
32
  `;
32
33
  }
33
34
  }
34
- function p(e) {
35
- const { cache: t, item: a } = e.inputs, { maxSize: o } = e.attrs, s = e.backend, n = t.shape[0], c = t.shape[2], r = t.shape[1], i = new m(n, r, c, a.shape[3], o);
36
- return s.runWebGLProgram(i, [t, a], "float32", [[c]]);
35
+ function d(e) {
36
+ const { cache: t, item: a } = e.inputs, { maxSize: n, pastLen: o } = e.attrs, c = e.backend, s = t.shape[0], r = t.shape[2], i = t.shape[1], h = new m(s, i, r, a.shape[3], n);
37
+ return c.runWebGLProgram(h, [t, a], "float32", [[o]]);
37
38
  }
38
- const d = {
39
+ const l = {
39
40
  kernelName: "AppendCache",
40
41
  backendName: "webgl",
41
- kernelFunc: p
42
+ kernelFunc: d
42
43
  };
43
- h(d);
44
+ p(l);
@@ -1,4 +1,4 @@
1
- import { r as h } from "../../index-C4JCoBvj.js";
1
+ import { r as h } from "../../index--6vO-cOz.js";
2
2
  class l {
3
3
  variableNames = ["q", "k"];
4
4
  outputShape;