@genai-fi/nanogpt 0.6.0 → 0.6.1

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 (110) hide show
  1. package/dist/Generator.js +7 -7
  2. package/dist/NanoGPTModel.js +70 -121
  3. package/dist/RealDiv-7xu-pkZN.js +540 -0
  4. package/dist/Reshape-BYC1oUku.js +127 -0
  5. package/dist/TeachableLLM.d.ts +2 -0
  6. package/dist/TeachableLLM.js +34 -27
  7. package/dist/{TiedEmbedding-BhxWO8QR.js → TiedEmbedding-C1HBot-5.js} +12 -13
  8. package/dist/{axis_util-D17qZRQm.js → axis_util-CCNL7jea.js} +14 -12
  9. package/dist/{broadcast_to-BMQLjvt_.js → broadcast_to-CddAF879.js} +2 -2
  10. package/dist/{concat-DhZfF1GY.js → concat-XOK9ANZu.js} +7 -7
  11. package/dist/{dataset-oilnemHf.js → dataset-BFFipD1c.js} +5 -5
  12. package/dist/{dropout-CrMQPCeG.js → dropout-xlKRoJyU.js} +9 -9
  13. package/dist/{gather-DZCMHZuN.js → gather-DKtUaTtA.js} +1 -1
  14. package/dist/gpgpu_math-B_ycgZ4W.js +3115 -0
  15. package/dist/{index-bMBtI-WR.js → index-CamYe_M8.js} +843 -646
  16. package/dist/{kernel_funcs_utils-CNmjLWnB.js → kernel_funcs_utils-D5MS0JFg.js} +232 -138
  17. package/dist/layers/BaseLayer.js +2 -2
  18. package/dist/layers/CausalSelfAttention.js +6 -6
  19. package/dist/layers/MLP.js +5 -5
  20. package/dist/layers/RMSNorm.js +3 -3
  21. package/dist/layers/RoPECache.js +13 -33
  22. package/dist/layers/TiedEmbedding.js +6 -7
  23. package/dist/layers/TransformerBlock.js +1 -1
  24. package/dist/{log_sum_exp-BHdkCb4s.js → log_sum_exp-CV_5-TTu.js} +15 -15
  25. package/dist/main.js +23 -20
  26. package/dist/{mat_mul-BsrLfy81.js → mat_mul-CAbRFWUj.js} +4 -4
  27. package/dist/{max-DechV4Bc.js → max-JBBv7aUf.js} +3 -3
  28. package/dist/mulmat_packed_gpu-DW4doKL_.js +71 -0
  29. package/dist/{norm-B9hWHZH1.js → norm-B9dQTFYn.js} +12 -12
  30. package/dist/{ones-g0K8jVwm.js → ones-CMHNqMr6.js} +2 -2
  31. package/dist/ops/appendCache.js +3 -3
  32. package/dist/ops/attentionMask.js +1 -1
  33. package/dist/ops/cpu/appendCache.js +2 -2
  34. package/dist/ops/cpu/attentionMask.js +5 -5
  35. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  36. package/dist/ops/cpu/gatherSub.js +5 -5
  37. package/dist/ops/cpu/gelu.js +1 -1
  38. package/dist/ops/cpu/matMulGelu.js +1 -1
  39. package/dist/ops/cpu/matMulMul.js +1 -1
  40. package/dist/ops/cpu/mulDropout.js +1 -1
  41. package/dist/ops/cpu/normRMS.js +1 -1
  42. package/dist/ops/cpu/qkv.js +3 -3
  43. package/dist/ops/cpu/rope.js +5 -5
  44. package/dist/ops/cpu/scatterSub.js +18 -49
  45. package/dist/ops/fusedSoftmax.js +1 -1
  46. package/dist/ops/gatherSub.js +1 -1
  47. package/dist/ops/gelu.js +1 -1
  48. package/dist/ops/grads/attentionMask.js +1 -1
  49. package/dist/ops/grads/fusedSoftmax.js +2 -2
  50. package/dist/ops/grads/gelu.js +1 -1
  51. package/dist/ops/grads/matMulGelu.js +1 -1
  52. package/dist/ops/grads/normRMS.js +1 -1
  53. package/dist/ops/grads/qkv.js +1 -1
  54. package/dist/ops/grads/rope.js +1 -1
  55. package/dist/ops/matMulGelu.js +1 -1
  56. package/dist/ops/matMulMul.js +1 -1
  57. package/dist/ops/mulDrop.js +1 -1
  58. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  59. package/dist/ops/normRMS.js +1 -1
  60. package/dist/ops/qkv.js +1 -1
  61. package/dist/ops/rope.js +8 -4
  62. package/dist/ops/scatterSub.js +1 -1
  63. package/dist/ops/webgl/appendCache.js +1 -1
  64. package/dist/ops/webgl/attentionMask.js +1 -1
  65. package/dist/ops/webgl/fusedSoftmax.js +29 -560
  66. package/dist/ops/webgl/gatherSub.js +1 -1
  67. package/dist/ops/webgl/gelu.js +2 -2
  68. package/dist/ops/webgl/log.js +3 -3
  69. package/dist/ops/webgl/matMulGelu.js +48 -115
  70. package/dist/ops/webgl/matMulMul.js +1 -1
  71. package/dist/ops/webgl/mulDropout.js +1 -1
  72. package/dist/ops/webgl/normRMS.js +2 -2
  73. package/dist/ops/webgl/qkv.js +1 -1
  74. package/dist/ops/webgl/rope.js +1 -1
  75. package/dist/ops/webgl/scatterSub.js +1 -1
  76. package/dist/{ops-Mv7Ta72x.js → ops-DqtYemmV.js} +143 -135
  77. package/dist/{random_width-BBAWzDym.js → random_width-CLMQG5Jn.js} +6925 -6291
  78. package/dist/{range-DMaG9A3G.js → range-DqYjKnuG.js} +1 -1
  79. package/dist/{gpgpu_math-Ctc31slO.js → reciprocal-z49filta.js} +7 -5
  80. package/dist/register_all_kernels-COt6wLD0.js +21397 -0
  81. package/dist/{reshape-T4yDEqoF.js → reshape-C45vIIRU.js} +1 -1
  82. package/dist/scatter_nd_util-qgtnviTE.js +46 -0
  83. package/dist/selu_util-4QV_GXTB.js +740 -0
  84. package/dist/{shared-XNAoXhOa.js → shared-ByfrGA97.js} +1462 -1089
  85. package/dist/{sin-EEhbrRO_.js → sin-9JBrfVaB.js} +1 -1
  86. package/dist/{softmax-B2_IKPDR.js → softmax-DvMvui-_.js} +1 -1
  87. package/dist/{split-dcks18H1.js → split-DxrHrPFK.js} +4 -4
  88. package/dist/{stack-lpJ5kYvE.js → stack-DgaoDmnF.js} +1 -1
  89. package/dist/{sum-CutF5lj2.js → sum-BpcpxNEh.js} +3 -3
  90. package/dist/{tensor-C15NA2LA.js → tensor-CDz5x1mP.js} +1 -1
  91. package/dist/{tensor2d-DZ_e5eKM.js → tensor2d-jO8JY5Jd.js} +1 -1
  92. package/dist/training/AdamExt.js +1 -1
  93. package/dist/training/DatasetBuilder.js +2 -2
  94. package/dist/training/FullTrainer.js +1 -1
  95. package/dist/training/Trainer.js +3 -3
  96. package/dist/training/sparseCrossEntropy.js +4 -4
  97. package/dist/utilities/dummy.d.ts +6 -0
  98. package/dist/utilities/dummy.js +31 -10
  99. package/dist/utilities/generate.js +3 -3
  100. package/dist/utilities/load.js +1 -1
  101. package/dist/utilities/profile.d.ts +5 -0
  102. package/dist/utilities/profile.js +10 -7
  103. package/dist/utilities/safetensors.js +2 -2
  104. package/dist/utilities/weights.js +2 -2
  105. package/dist/{variable-CdRKKp8x.js → variable-CLVXjN7F.js} +1 -1
  106. package/dist/{zeros-CAbHfODe.js → zeros-DUkkVccu.js} +8 -8
  107. package/package.json +3 -9
  108. package/dist/Reshape-CLOrdpve.js +0 -212
  109. package/dist/slice_util-Ddk0uxGJ.js +0 -49
  110. package/dist/tfjs_backend-BDb8r9qx.js +0 -1010
@@ -1,4 +1,4 @@
1
- import { o, j as t, E as c, _ as a, $ as e } from "./index-bMBtI-WR.js";
1
+ import { q as o, w as t, E as c, a0 as a, a1 as e } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { o as r, j as f, E as e, S as i } from "./index-bMBtI-WR.js";
1
+ import { q as r, w as f, E as e, S as i } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { o as p, j as i, E as a, x as c } from "./index-bMBtI-WR.js";
1
+ import { q as p, w as i, E as a, H as c } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -15,9 +15,9 @@ import { o as p, j as i, E as a, x as c } from "./index-bMBtI-WR.js";
15
15
  * limitations under the License.
16
16
  * =============================================================================
17
17
  */
18
- function e(t, s, o = 0) {
19
- const n = { x: i(t, "x", "split") }, r = { numOrSizeSplits: s, axis: o };
20
- return a.runKernel(c, n, r);
18
+ function e(t, s, n = 0) {
19
+ const o = { x: i(t, "x", "split") }, r = { numOrSizeSplits: s, axis: n };
20
+ return a.runKernel(c, o, r);
21
21
  }
22
22
  const u = /* @__PURE__ */ p({ split_: e });
23
23
  export {
@@ -1,4 +1,4 @@
1
- import { o as e, k as c, l as n, E as k, P as i } from "./index-bMBtI-WR.js";
1
+ import { q as e, x as c, k as n, E as k, P as i } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { o as e, j as u, D as c, E as l, F as m } from "./index-bMBtI-WR.js";
1
+ import { q as e, w as u, N as c, E as l, O as m } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -15,10 +15,10 @@ import { o as e, j as u, D as c, E as l, F as m } from "./index-bMBtI-WR.js";
15
15
  * limitations under the License.
16
16
  * =============================================================================
17
17
  */
18
- function i(t, o = null, n = !1) {
18
+ function i(t, n = null, o = !1) {
19
19
  let s = u(t, "x", "sum");
20
20
  s.dtype === "bool" && (s = c(s, "int32"));
21
- const r = { x: s }, a = { axis: o, keepDims: n };
21
+ const r = { x: s }, a = { axis: n, keepDims: o };
22
22
  return l.runKernel(m, r, a);
23
23
  }
24
24
  const f = /* @__PURE__ */ e({ sum_: i });
@@ -1,4 +1,4 @@
1
- import { J as t, K as a } from "./index-bMBtI-WR.js";
1
+ import { Q as t, U as a } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { I as t, J as s, K as a } from "./index-bMBtI-WR.js";
1
+ import { V as t, Q as s, U as a } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { A as r, b as c, f as h, s as g, e as o } from "../index-bMBtI-WR.js";
1
+ import { A as r, b as c, f as h, s as g, e as o } from "../index-CamYe_M8.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,5 +1,5 @@
1
- import { t as u } from "../index-bMBtI-WR.js";
2
- import { d as z, i as f } from "../dataset-oilnemHf.js";
1
+ import { t as u } from "../index-CamYe_M8.js";
2
+ import { d as z, i as f } from "../dataset-BFFipD1c.js";
3
3
  import "../index-Tf7vU29b.js";
4
4
  /**
5
5
  * @license
@@ -1,7 +1,7 @@
1
1
  import { generateText as T } 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-bMBtI-WR.js";
4
+ import { a as h } from "../index-CamYe_M8.js";
5
5
  import y from "../utilities/profile.js";
6
6
  const D = {
7
7
  desiredLoss: 0.01,
@@ -1,8 +1,8 @@
1
1
  import { DatasetBuilder as g, flattenTokens as m, PAGE_FACTOR as u } from "./DatasetBuilder.js";
2
2
  import f from "./AdamExt.js";
3
- import { t as y, v as z, a as c } from "../index-bMBtI-WR.js";
4
- import { n as S } from "../norm-B9hWHZH1.js";
5
- import { z as p } from "../zeros-CAbHfODe.js";
3
+ import { t as y, v as z, a as c } from "../index-CamYe_M8.js";
4
+ import { n as S } from "../norm-B9dQTFYn.js";
5
+ import { z as p } from "../zeros-DUkkVccu.js";
6
6
  class R {
7
7
  constructor(t, e, s = 1e-3) {
8
8
  this.tokenizer = e, this.model = t, this.learningRate = s, this.resetOptimizer(), this.datasetBuilder = new g(e, 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-bMBtI-WR.js";
4
- import { s as v } from "../softmax-B2_IKPDR.js";
5
- import { m as z } from "../max-DechV4Bc.js";
6
- import { l as k } from "../log_sum_exp-BHdkCb4s.js";
3
+ import { e as u, c as i, z as S, t as f, s as G } from "../index-CamYe_M8.js";
4
+ import { s as v } from "../softmax-DvMvui-_.js";
5
+ import { m as z } from "../max-JBBv7aUf.js";
6
+ import { l as k } from "../log_sum_exp-CV_5-TTu.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,3 +1,9 @@
1
1
  import { default as NanoGPT } from '../NanoGPTModel';
2
2
  export declare function dummyPassAsync(model: NanoGPT): Promise<void>;
3
+ export interface MemoryRequirements {
4
+ perBatch: number;
5
+ tapeSize: number;
6
+ gradients: number;
7
+ }
8
+ export declare function dummyPassTrainAsync(model: NanoGPT): Promise<MemoryRequirements>;
3
9
  export declare function dummyPass(model: NanoGPT): void;
@@ -1,14 +1,35 @@
1
- import "../index-bMBtI-WR.js";
2
- import { z as n } from "../zeros-CAbHfODe.js";
3
- async function c(s) {
4
- const i = n([1, s.config.gpt.blockSize], "int32"), [t, o] = s.forward({ training: !1 }, i);
5
- await t.data(), t.dispose(), o && o.dispose(), i.dispose();
1
+ import { m as f, v as S, e as w } from "../index-CamYe_M8.js";
2
+ import { z as i } from "../zeros-DUkkVccu.js";
3
+ async function P(s) {
4
+ const t = i([1, s.config.gpt.blockSize], "int32"), [e, n] = s.forward({ training: !1 }, t);
5
+ await e.data(), e.dispose(), n && n.dispose(), t.dispose();
6
6
  }
7
- function d(s) {
8
- const i = n([1, s.config.gpt.blockSize], "int32"), [t, o] = s.forward({ training: !1 }, i);
9
- t.dispose(), o && o.dispose(), i.dispose();
7
+ async function v(s) {
8
+ const t = f(), e = t.numBytesInGPUAllocated ?? t.numBytes;
9
+ await P(s);
10
+ const n = i([1, s.config.gpt.blockSize], "int32"), r = i([1, s.config.gpt.blockSize], "int32"), o = {
11
+ perBatch: 0,
12
+ tapeSize: 0,
13
+ gradients: s.getNumParams() * 4
14
+ }, g = () => {
15
+ const [a, l] = s.forward({ training: !0 }, n, r), d = w().state.activeTape;
16
+ let u = 0;
17
+ if (d)
18
+ for (const z of d)
19
+ u += z.saved?.reduce((B, I) => B + I.size * 4, 0) || 0;
20
+ return o.tapeSize = u, a.dispose(), l;
21
+ }, { value: c, grads: m } = S(g), p = f(), y = p.numBytesInGPUAllocated ?? p.numBytes;
22
+ o.perBatch = y - e - o.gradients, console.log("Dummy training memory requirements:", o), await c.data(), c.dispose();
23
+ for (const a in m)
24
+ m[a].dispose();
25
+ return n.dispose(), r.dispose(), o;
26
+ }
27
+ function A(s) {
28
+ const t = i([1, s.config.gpt.blockSize], "int32"), [e, n] = s.forward({ training: !1 }, t);
29
+ e.dispose(), n && n.dispose(), t.dispose();
10
30
  }
11
31
  export {
12
- d as dummyPass,
13
- c as dummyPassAsync
32
+ A as dummyPass,
33
+ P as dummyPassAsync,
34
+ v as dummyPassTrainAsync
14
35
  };
@@ -1,6 +1,6 @@
1
- import { t as y } from "../index-bMBtI-WR.js";
2
- import { t as x } from "../tensor2d-DZ_e5eKM.js";
3
- import { c as f } from "../concat-DhZfF1GY.js";
1
+ import { t as y } from "../index-CamYe_M8.js";
2
+ import { t as x } from "../tensor2d-jO8JY5Jd.js";
3
+ import { c as f } from "../concat-XOK9ANZu.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 F } from "./weights.js";
3
3
  import h from "../tokeniser/CharTokeniser.js";
4
4
  import b from "../NanoGPTModel.js";
5
5
  import { dummyPassAsync as u } from "./dummy.js";
6
- import { d as k } from "../index-bMBtI-WR.js";
6
+ import { d as k } from "../index-CamYe_M8.js";
7
7
  import j from "../tokeniser/bpe.js";
8
8
  import { load_safetensors as N } from "./safetensors.js";
9
9
  const I = 2;
@@ -1,3 +1,7 @@
1
+ import { MemoryInfo } from '@tensorflow/tfjs-core';
2
+ export interface ExtendedMemoryInfo extends MemoryInfo {
3
+ numBytesInGPUAllocated?: number;
4
+ }
1
5
  export default class MemoryProfiler {
2
6
  private log;
3
7
  private maxMemory;
@@ -6,6 +10,7 @@ export default class MemoryProfiler {
6
10
  private peakMemory;
7
11
  startMemory(): void;
8
12
  getPeakMemory(): number;
13
+ getMaxMemory(): number;
9
14
  endMemory(label: string): void;
10
15
  printSummary(): void;
11
16
  }
@@ -1,4 +1,4 @@
1
- import { m as s } from "../index-bMBtI-WR.js";
1
+ import { m as a } from "../index-CamYe_M8.js";
2
2
  const m = 1024 * 1024;
3
3
  class l {
4
4
  log = /* @__PURE__ */ new Map();
@@ -7,23 +7,26 @@ class l {
7
7
  lastMemInfo = [];
8
8
  peakMemory = 0;
9
9
  startMemory() {
10
- this.lastMemInfo.push(s());
10
+ this.lastMemInfo.push(a());
11
11
  }
12
12
  getPeakMemory() {
13
13
  return this.peakMemory;
14
14
  }
15
- endMemory(e) {
15
+ getMaxMemory() {
16
+ return this.maxMemory;
17
+ }
18
+ endMemory(o) {
16
19
  if (this.lastMemInfo.length === 0) {
17
20
  console.warn("MemoryProfiler: endMemory called without matching startMemory");
18
21
  return;
19
22
  }
20
- const o = s(), t = o.numBytes - (this.lastMemInfo.pop()?.numBytes || 0);
21
- this.log.set(e, Math.max(this.log.get(e) || 0, t)), t > this.maxMemory && (this.maxMemory = t, this.maxLabel = e), this.peakMemory = Math.max(this.peakMemory, o.numBytesInGPUAllocated || o.numBytes);
23
+ const e = a(), s = this.lastMemInfo.pop(), t = (e.numBytesInGPUAllocated ?? e.numBytes) - (s?.numBytes ?? s?.numBytesInGPUAllocated ?? 0);
24
+ this.log.set(o, Math.max(this.log.get(o) || 0, t)), t > this.maxMemory && (this.maxMemory = t, this.maxLabel = o), this.peakMemory = Math.max(this.peakMemory, e.numBytesInGPUAllocated ?? e.numBytes);
22
25
  }
23
26
  printSummary() {
24
27
  console.log("Memory Usage Summary:");
25
- for (const [e, o] of this.log.entries())
26
- console.log(`- ${e}: ${(o / m).toFixed(2)} MB`);
28
+ for (const [o, e] of this.log.entries())
29
+ console.log(`- ${o}: ${(e / m).toFixed(2)} MB`);
27
30
  this.maxLabel && console.log(`Peak Memory Usage: ${(this.maxMemory / m).toFixed(2)} MB at "${this.maxLabel}"`), console.log(`Overall Peak Memory Usage: ${(this.peakMemory / m).toFixed(2)} MB`);
28
31
  }
29
32
  }
@@ -1,5 +1,5 @@
1
- import "../index-bMBtI-WR.js";
2
- import { t as y } from "../tensor-C15NA2LA.js";
1
+ import "../index-CamYe_M8.js";
2
+ import { t as y } from "../tensor-CDz5x1mP.js";
3
3
  function l(t) {
4
4
  if (t === "float32") return "F32";
5
5
  if (t === "int32") return "I32";
@@ -1,5 +1,5 @@
1
- import "../index-bMBtI-WR.js";
2
- import { t as p } from "../tensor-C15NA2LA.js";
1
+ import "../index-CamYe_M8.js";
2
+ import { t as p } from "../tensor-CDz5x1mP.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-bMBtI-WR.js";
1
+ import { E as i } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
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-bMBtI-WR.js";
1
+ import { q as m, w as r, Z as l, E as c, _ as i, y as p, $ as u, i as f } from "./index-CamYe_M8.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -16,9 +16,9 @@ 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 "
16
16
  * =============================================================================
17
17
  */
18
18
  function x(a, e) {
19
- const o = r(a, "real", "complex"), s = r(e, "imag", "complex");
20
- l(o.shape, s.shape, `real and imag shapes, ${o.shape} and ${s.shape}, must match in call to tf.complex().`);
21
- const n = { real: o, imag: s };
19
+ const s = r(a, "real", "complex"), o = r(e, "imag", "complex");
20
+ l(s.shape, o.shape, `real and imag shapes, ${s.shape} and ${o.shape}, must match in call to tf.complex().`);
21
+ const n = { real: s, imag: o };
22
22
  return c.runKernel(i, n);
23
23
  }
24
24
  const g = /* @__PURE__ */ m({ complex_: x });
@@ -40,11 +40,11 @@ const g = /* @__PURE__ */ m({ complex_: x });
40
40
  */
41
41
  function t(a, e = "float32") {
42
42
  if (p(a), e === "complex64") {
43
- const s = t(a, "float32"), n = t(a, "float32");
44
- return g(s, n);
43
+ const o = t(a, "float32"), n = t(a, "float32");
44
+ return g(o, n);
45
45
  }
46
- const o = u(f(a), e);
47
- return c.makeTensor(o, a, e);
46
+ const s = u(f(a), e);
47
+ return c.makeTensor(s, a, e);
48
48
  }
49
49
  export {
50
50
  g as c,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -24,18 +24,11 @@
24
24
  "test:gl": "playwright test",
25
25
  "ci:test": "vitest --coverage --reporter=junit --outputFile=junit.xml",
26
26
  "coverage": "vitest run --coverage",
27
- "train": "tsx scripts/train.ts",
28
- "generate": "tsx scripts/generate.ts",
29
- "evaluate": "tsx scripts/evaluate.ts",
30
27
  "debug": "tsx scripts/debug.ts"
31
28
  },
32
- "peerDependencies": {
33
- "@tensorflow/tfjs": "^4.22.0"
34
- },
35
29
  "devDependencies": {
36
30
  "@eslint/js": "^9.32.0",
37
31
  "@playwright/test": "^1.55.0",
38
- "@tensorflow/tfjs-node-gpu": "^4.22.0",
39
32
  "@types/node": "^22.13.14",
40
33
  "@types/papaparse": "^5.3.16",
41
34
  "@types/yargs": "^17.0.33",
@@ -59,6 +52,7 @@
59
52
  "eventemitter3": "^5.0.1",
60
53
  "jszip": "^3.10.1",
61
54
  "papaparse": "^5.5.3",
62
- "pdfjs-dist": "^5.4.149"
55
+ "pdfjs-dist": "^5.4.149",
56
+ "@tensorflow/tfjs": "^4.22.0"
63
57
  }
64
58
  }
@@ -1,212 +0,0 @@
1
- import { ac as f, ad as g, q as p, ae as C, l as x } from "./index-bMBtI-WR.js";
2
- import { u as I } from "./gpgpu_math-Ctc31slO.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
- };
@@ -1,49 +0,0 @@
1
- import { l as s } from "./index-bMBtI-WR.js";
2
- /**
3
- * @license
4
- * Copyright 2021 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 u(r, n, t) {
19
- let l = t.length;
20
- for (let e = 0; e < t.length; e++)
21
- if (t[e] > 1) {
22
- l = e;
23
- break;
24
- }
25
- for (let e = l + 1; e < t.length; e++)
26
- if (n[e] > 0 || t[e] !== r[e])
27
- return !1;
28
- return !0;
29
- }
30
- function c(r, n) {
31
- let t = r.length > 0 ? r[r.length - 1] : 1;
32
- for (let l = 0; l < r.length - 1; l++)
33
- t += r[l] * n[l];
34
- return t;
35
- }
36
- function h(r, n, t) {
37
- let l;
38
- const e = r.shape.length;
39
- typeof n == "number" ? l = [n, ...new Array(e - 1).fill(0)] : n.length < e ? l = n.concat(new Array(e - n.length).fill(0)) : l = n.slice(), l.forEach((a) => {
40
- s(a !== -1, () => "slice() does not support negative begin indexing.");
41
- });
42
- let f;
43
- return t == null ? f = new Array(e).fill(-1) : typeof t == "number" ? f = [t, ...new Array(e - 1).fill(-1)] : t.length < e ? f = t.concat(new Array(e - t.length).fill(-1)) : f = t, f = f.map((a, o) => a >= 0 ? a : (s(a === -1, () => `Negative size values should be exactly -1 but got ${a} for the slice() size at index ${o}.`), r.shape[o] - l[o])), [l, f];
44
- }
45
- export {
46
- c,
47
- u as i,
48
- h as p
49
- };