@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
@@ -0,0 +1,69 @@
1
+ import { j as c } from "./index-XjBAhiFO.js";
2
+ /**
3
+ * @license
4
+ * Copyright 2017 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 i(e, n) {
19
+ for (let t = 0; t < e.length; ++t)
20
+ if (e[e.length - t - 1] !== n - 1 - t)
21
+ return !1;
22
+ return !0;
23
+ }
24
+ function p(e, n, t) {
25
+ const r = e.length + n.length, s = [];
26
+ let o = 0, f = 0;
27
+ for (let u = 0; u < r; u++)
28
+ t.indexOf(u) === -1 ? s.push(e[o++]) : s.push(n[f++]);
29
+ return s;
30
+ }
31
+ function a(e, n) {
32
+ const t = [], r = e.length;
33
+ for (let o = 0; o < r; o++)
34
+ n.indexOf(o) === -1 && t.push(e[o]);
35
+ const s = n.map((o) => e[o]);
36
+ return [t, s];
37
+ }
38
+ function m(e, n) {
39
+ const t = n.map((r) => 1);
40
+ return p(e, t, n);
41
+ }
42
+ function d(e, n, t) {
43
+ c(i(n, t), () => `${e} supports only inner-most axes for now. Got axes ${n} and rank-${t} input.`);
44
+ }
45
+ function h(e, n) {
46
+ if (i(e, n))
47
+ return null;
48
+ const t = [];
49
+ for (let r = 0; r < n; ++r)
50
+ e.indexOf(r) === -1 && t.push(r);
51
+ return e.forEach((r) => t.push(r)), t;
52
+ }
53
+ function g(e) {
54
+ return e.map((n, t) => [t, n]).sort((n, t) => n[1] - t[1]).map((n) => n[0]);
55
+ }
56
+ function x(e, n) {
57
+ const t = [];
58
+ for (let r = n - e; r < n; ++r)
59
+ t.push(r);
60
+ return t;
61
+ }
62
+ export {
63
+ x as a,
64
+ d as b,
65
+ a as c,
66
+ g as d,
67
+ m as e,
68
+ h as g
69
+ };
@@ -1,4 +1,4 @@
1
- import { o as s, j as a, i, u as p, E as l, C as u } from "./index-pWA4_lUh.js";
1
+ import { o as s, j as a, i, w as p, E as l, C as f } from "./index-XjBAhiFO.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -15,7 +15,7 @@ import { o as s, j as a, i, u as p, E as l, C as u } from "./index-pWA4_lUh.js";
15
15
  * limitations under the License.
16
16
  * =============================================================================
17
17
  */
18
- function f(o, e = 0) {
18
+ function h(o, e = 0) {
19
19
  a(o.length >= 1, () => "Pass at least one tensor to concat");
20
20
  const t = i(o, "tensors", "concat", "string_or_numeric");
21
21
  if (t[0].dtype === "complex64" && t.forEach((n) => {
@@ -25,9 +25,9 @@ function f(o, e = 0) {
25
25
  }), t.length === 1)
26
26
  return p(t[0]);
27
27
  const r = t, c = { axis: e };
28
- return l.runKernel(u, r, c);
28
+ return l.runKernel(f, r, c);
29
29
  }
30
- const m = /* @__PURE__ */ s({ concat_: f });
30
+ const u = /* @__PURE__ */ s({ concat_: h });
31
31
  export {
32
- m as c
32
+ u as c
33
33
  };
package/dist/config.js CHANGED
@@ -1,20 +1,19 @@
1
1
  const e = {
2
- vocabSize: 50304,
3
- // GPT-2 vocab size
4
- blockSize: 1024,
2
+ vocabSize: 2e3,
3
+ blockSize: 128,
5
4
  // Maximum sequence length
6
- nLayer: 12,
5
+ nLayer: 6,
7
6
  // Number of transformer layers
8
- nHead: 12,
7
+ nHead: 4,
9
8
  // Number of attention heads
10
- nEmbed: 768,
9
+ nEmbed: 256,
11
10
  // Embedding dimension
12
- dropout: 0,
11
+ dropout: 0.1,
13
12
  // Dropout probability
14
13
  biasInLinear: !1,
15
14
  biasInLayerNorm: !1,
16
15
  mlpFactor: 4,
17
- useRope: !1
16
+ useRope: !0
18
17
  // Use Rotary Position Embeddings
19
18
  };
20
19
  export {
@@ -1,4 +1,4 @@
1
- import { o as h, h as t, E as g, G as p } from "./index-pWA4_lUh.js";
1
+ import { o as h, h as t, E as g, G as p } from "./index-XjBAhiFO.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.