@genai-fi/nanogpt 0.4.1 → 0.4.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 (87) hide show
  1. package/dist/Generator.js +3 -3
  2. package/dist/NanoGPTModel.js +83 -70
  3. package/dist/TeachableLLM.js +1 -1
  4. package/dist/{random_width-CMHmdbSu.js → TiedEmbedding-CnJ1bx4q.js} +760 -719
  5. package/dist/{axis_util-DeydwOoC.js → axis_util-BgTGy5w8.js} +1 -1
  6. package/dist/{concat-DS_qH7MI.js → concat-CuRsVY-K.js} +1 -1
  7. package/dist/dropout-DfDdklfL.js +193 -0
  8. package/dist/{gather-BUmJIS8n.js → gather-ZYRWhmXR.js} +1 -1
  9. package/dist/gelu-CnCt17Lk.js +26 -0
  10. package/dist/{index-XjBAhiFO.js → index-C4JCoBvj.js} +61 -61
  11. package/dist/kernel_funcs_utils-CAd1h9X1.js +388 -0
  12. package/dist/layers/CausalSelfAttention.js +71 -70
  13. package/dist/layers/MLP.d.ts +3 -1
  14. package/dist/layers/MLP.js +93 -5
  15. package/dist/layers/RMSNorm.js +3 -3
  16. package/dist/layers/RoPECache.js +3 -3
  17. package/dist/layers/TiedEmbedding.js +6 -46
  18. package/dist/layers/TransformerBlock.js +2 -2
  19. package/dist/{log_sum_exp-DJPkVZZn.js → log_sum_exp-BswFnwOb.js} +5 -5
  20. package/dist/main.js +1 -1
  21. package/dist/{mat_mul-CKwFEV1Q.js → mat_mul-415y5Qn2.js} +1 -1
  22. package/dist/{max-DJvEiCAJ.js → max-CP_9O2Yd.js} +1 -1
  23. package/dist/{moments-CrWRPcR3.js → moments-CjeIaVdp.js} +3 -3
  24. package/dist/{norm-BzY929B_.js → norm-CZM380I3.js} +5 -5
  25. package/dist/{ones-BO01zpJG.js → ones-Bf3YR48P.js} +2 -2
  26. package/dist/ops/appendCache.js +1 -1
  27. package/dist/ops/attentionMask.d.ts +1 -1
  28. package/dist/ops/attentionMask.js +4 -4
  29. package/dist/ops/cpu/appendCache.js +2 -2
  30. package/dist/ops/cpu/attentionMask.js +13 -9
  31. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  32. package/dist/ops/cpu/gatherSub.js +3 -3
  33. package/dist/ops/cpu/gelu.d.ts +1 -0
  34. package/dist/ops/cpu/gelu.js +40 -0
  35. package/dist/ops/cpu/mulDropout.js +1 -1
  36. package/dist/ops/cpu/qkv.js +3 -3
  37. package/dist/ops/cpu/rope.js +5 -5
  38. package/dist/ops/cpu/scatterSub.js +4 -4
  39. package/dist/ops/fusedSoftmax.js +1 -1
  40. package/dist/ops/gatherSub.js +1 -1
  41. package/dist/ops/gelu.d.ts +3 -0
  42. package/dist/ops/gelu.js +8 -0
  43. package/dist/ops/grads/attentionMask.js +1 -1
  44. package/dist/ops/grads/fusedSoftmax.js +2 -2
  45. package/dist/ops/grads/gelu.d.ts +2 -0
  46. package/dist/ops/grads/gelu.js +5 -0
  47. package/dist/ops/grads/qkv.js +1 -1
  48. package/dist/ops/grads/rope.js +1 -1
  49. package/dist/ops/mulDrop.js +1 -1
  50. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  51. package/dist/ops/qkv.js +1 -1
  52. package/dist/ops/scatterSub.js +1 -1
  53. package/dist/ops/webgl/appendCache.js +1 -1
  54. package/dist/ops/webgl/attentionMask.js +19 -18
  55. package/dist/ops/webgl/fusedSoftmax.js +483 -782
  56. package/dist/ops/webgl/gatherSub.js +1 -1
  57. package/dist/ops/webgl/gelu.d.ts +2 -0
  58. package/dist/ops/webgl/gelu.js +50 -0
  59. package/dist/ops/webgl/mulDropout.js +1 -1
  60. package/dist/ops/webgl/qkv.js +1 -1
  61. package/dist/ops/webgl/rope.js +1 -1
  62. package/dist/ops/webgl/scatterSub.js +1 -1
  63. package/dist/{range-DQMNzBWs.js → range-9AzeApCc.js} +1 -1
  64. package/dist/{reshape-DFzh97Sc.js → reshape-Boe4DuIO.js} +1 -1
  65. package/dist/{sin-BYM-U4Ut.js → sin-KmhiDuMa.js} +1 -1
  66. package/dist/{slice_util-CnVNPQI-.js → slice_util-19zDNNSn.js} +2 -2
  67. package/dist/{softmax-4DOn6cPq.js → softmax-Cujsg4ay.js} +1 -1
  68. package/dist/{split-CkbeVdF8.js → split-DbcNm1-i.js} +1 -1
  69. package/dist/{stack-DaIMO5iX.js → stack-D1YjmgKN.js} +1 -1
  70. package/dist/{sum-C6u3xMi3.js → sum-R28pucR5.js} +1 -1
  71. package/dist/{tensor-Cu1fU7H7.js → tensor-BVeHdl7V.js} +1 -1
  72. package/dist/{tensor2d-D0CKdG6B.js → tensor2d-DqFGNs_K.js} +1 -1
  73. package/dist/{tfjs_backend-Bzl2SrRo.js → tfjs_backend-Cug-PH75.js} +826 -1015
  74. package/dist/training/AdamExt.js +1 -1
  75. package/dist/training/DatasetBuilder.js +3 -3
  76. package/dist/training/FullTrainer.js +1 -1
  77. package/dist/training/Trainer.js +5 -5
  78. package/dist/training/sparseCrossEntropy.js +4 -4
  79. package/dist/utilities/dummy.js +2 -2
  80. package/dist/utilities/generate.js +3 -3
  81. package/dist/utilities/load.js +1 -1
  82. package/dist/utilities/profile.js +1 -1
  83. package/dist/utilities/weights.js +2 -2
  84. package/dist/{variable-BS4AKqNU.js → variable-LJT9Ld63.js} +1 -1
  85. package/dist/{zeros-CmJFiC84.js → zeros-dnQxFgAD.js} +1 -1
  86. package/package.json +1 -1
  87. package/dist/MLP-KHhikThU.js +0 -83
@@ -1,4 +1,4 @@
1
- import { j as c } from "./index-XjBAhiFO.js";
1
+ import { j as c } from "./index-C4JCoBvj.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2017 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { o as s, j as a, i, w as p, E as l, C as f } from "./index-XjBAhiFO.js";
1
+ import { o as s, j as a, i, w as p, E as l, C as f } from "./index-C4JCoBvj.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -0,0 +1,193 @@
1
+ import { o as l, h, E as m, a9 as p, k as c, aa as d, ab as g, j as u, ac as V, ad as v, a5 as N, b } from "./index-C4JCoBvj.js";
2
+ import { s as f } from "./index-C4L8Cm77.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 w(r) {
20
+ const e = { x: h(r, "x", "floor", "float32") };
21
+ return m.runKernel(p, e);
22
+ }
23
+ const x = /* @__PURE__ */ l({ floor_: w });
24
+ /**
25
+ * @license
26
+ * Copyright 2018 Google LLC. All Rights Reserved.
27
+ * Licensed under the Apache License, Version 2.0 (the "License");
28
+ * you may not use this file except in compliance with the License.
29
+ * You may obtain a copy of the License at
30
+ *
31
+ * http://www.apache.org/licenses/LICENSE-2.0
32
+ *
33
+ * Unless required by applicable law or agreed to in writing, software
34
+ * distributed under the License is distributed on an "AS IS" BASIS,
35
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
+ * See the License for the specific language governing permissions and
37
+ * limitations under the License.
38
+ * =============================================================================
39
+ */
40
+ class T {
41
+ constructor(t, e, s, n, o) {
42
+ this.mean = t, this.stdDev = e, this.dtype = s, this.nextVal = NaN, this.truncated = n, this.truncated && (this.upper = this.mean + this.stdDev * 2, this.lower = this.mean - this.stdDev * 2);
43
+ const a = o || Math.random();
44
+ this.random = f.alea(a.toString());
45
+ }
46
+ /** Returns next sample from a Gaussian distribution. */
47
+ nextValue() {
48
+ if (!isNaN(this.nextVal)) {
49
+ const n = this.nextVal;
50
+ return this.nextVal = NaN, n;
51
+ }
52
+ let t, e, s = !1;
53
+ for (; !s; ) {
54
+ let n, o, a;
55
+ do
56
+ n = 2 * this.random() - 1, o = 2 * this.random() - 1, a = n * n + o * o;
57
+ while (a >= 1 || a === 0);
58
+ const i = Math.sqrt(-2 * Math.log(a) / a);
59
+ t = this.mean + this.stdDev * n * i, e = this.mean + this.stdDev * o * i, (!this.truncated || this.isValidTruncated(t)) && (s = !0);
60
+ }
61
+ return (!this.truncated || this.isValidTruncated(e)) && (this.nextVal = this.convertValue(e)), this.convertValue(t);
62
+ }
63
+ /** Handles proper rounding for non-floating-point numbers. */
64
+ convertValue(t) {
65
+ return this.dtype == null || this.dtype === "float32" ? t : Math.round(t);
66
+ }
67
+ /** Returns true if less than 2-standard-deviations from the mean. */
68
+ isValidTruncated(t) {
69
+ return t <= this.upper && t >= this.lower;
70
+ }
71
+ }
72
+ class $ {
73
+ constructor(t = 0, e = 1, s, n) {
74
+ if (this.canReturnFloat = () => this.dtype == null || this.dtype === "float32", this.min = t, this.range = e - t, this.dtype = s, n == null && (n = Math.random()), typeof n == "number" && (n = n.toString()), !this.canReturnFloat() && this.range <= 1)
75
+ throw new Error(`The difference between ${t} - ${e} <= 1 and dtype is not float`);
76
+ this.random = f.alea(n);
77
+ }
78
+ convertValue(t) {
79
+ return this.canReturnFloat() ? t : Math.round(t);
80
+ }
81
+ nextValue() {
82
+ return this.convertValue(this.min + this.range * this.random());
83
+ }
84
+ }
85
+ /**
86
+ * @license
87
+ * Copyright 2020 Google LLC. All Rights Reserved.
88
+ * Licensed under the Apache License, Version 2.0 (the "License");
89
+ * you may not use this file except in compliance with the License.
90
+ * You may obtain a copy of the License at
91
+ *
92
+ * http://www.apache.org/licenses/LICENSE-2.0
93
+ *
94
+ * Unless required by applicable law or agreed to in writing, software
95
+ * distributed under the License is distributed on an "AS IS" BASIS,
96
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
97
+ * See the License for the specific language governing permissions and
98
+ * limitations under the License.
99
+ * =============================================================================
100
+ */
101
+ function y(r, t = 0, e = 1, s, n) {
102
+ if (c(r), s != null && s === "bool")
103
+ throw new Error(`Unsupported data type ${s}`);
104
+ const o = new T(t, e, s, !1, n), a = d(r, s);
105
+ for (let i = 0; i < a.values.length; i++)
106
+ a.values[i] = o.nextValue();
107
+ return a.toTensor();
108
+ }
109
+ const _ = /* @__PURE__ */ l({ randomNormal_: y });
110
+ /**
111
+ * @license
112
+ * Copyright 2020 Google LLC. All Rights Reserved.
113
+ * Licensed under the Apache License, Version 2.0 (the "License");
114
+ * you may not use this file except in compliance with the License.
115
+ * You may obtain a copy of the License at
116
+ *
117
+ * http://www.apache.org/licenses/LICENSE-2.0
118
+ *
119
+ * Unless required by applicable law or agreed to in writing, software
120
+ * distributed under the License is distributed on an "AS IS" BASIS,
121
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122
+ * See the License for the specific language governing permissions and
123
+ * limitations under the License.
124
+ * =============================================================================
125
+ */
126
+ function M(r, t = 0, e = 1, s = "float32", n) {
127
+ c(r);
128
+ const o = d(r, s), a = new $(t, e, null, n);
129
+ for (let i = 0; i < o.values.length; i++)
130
+ o.values[i] = a.nextValue();
131
+ return o.toTensor();
132
+ }
133
+ const D = /* @__PURE__ */ l({ randomUniform_: M });
134
+ /**
135
+ * @license
136
+ * Copyright 2019 Google LLC. All Rights Reserved.
137
+ * Licensed under the Apache License, Version 2.0 (the "License");
138
+ * you may not use this file except in compliance with the License.
139
+ * You may obtain a copy of the License at
140
+ *
141
+ * http://www.apache.org/licenses/LICENSE-2.0
142
+ *
143
+ * Unless required by applicable law or agreed to in writing, software
144
+ * distributed under the License is distributed on an "AS IS" BASIS,
145
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
146
+ * See the License for the specific language governing permissions and
147
+ * limitations under the License.
148
+ * =============================================================================
149
+ */
150
+ function E(r, t) {
151
+ if (t == null)
152
+ return r.shape.slice();
153
+ if (g(r.shape, t))
154
+ return t;
155
+ if (r.shape.length === t.length) {
156
+ const e = [];
157
+ for (let s = 0; s < r.shape.length; s++)
158
+ t[s] == null && r.shape[s] != null ? e.push(r.shape[s]) : e.push(t[s]);
159
+ return e;
160
+ }
161
+ return t;
162
+ }
163
+ /**
164
+ * @license
165
+ * Copyright 2018 Google LLC. All Rights Reserved.
166
+ * Licensed under the Apache License, Version 2.0 (the "License");
167
+ * you may not use this file except in compliance with the License.
168
+ * You may obtain a copy of the License at
169
+ *
170
+ * http://www.apache.org/licenses/LICENSE-2.0
171
+ *
172
+ * Unless required by applicable law or agreed to in writing, software
173
+ * distributed under the License is distributed on an "AS IS" BASIS,
174
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
+ * See the License for the specific language governing permissions and
176
+ * limitations under the License.
177
+ * =============================================================================
178
+ */
179
+ function R(r, t, e, s) {
180
+ const n = h(r, "x", "dropout");
181
+ if (u(n.dtype === "float32", () => `x has to be a floating point tensor since it's going to be scaled, but got a ${n.dtype} tensor instead.`), u(t >= 0 && t < 1, () => `rate must be a float in the range [0, 1), but got ${t}.`), t === 0)
182
+ return r instanceof V ? n.clone() : n;
183
+ const o = E(n, e), a = 1 - t, i = v(x(N(D(o, 0, 1, "float32", s), a)), a);
184
+ return b(n, i);
185
+ }
186
+ const G = /* @__PURE__ */ l({ dropout_: R });
187
+ export {
188
+ T as M,
189
+ D as a,
190
+ G as d,
191
+ x as f,
192
+ _ as r
193
+ };
@@ -1,4 +1,4 @@
1
- import { o as h, h as t, E as g, G as p } from "./index-XjBAhiFO.js";
1
+ import { o as h, h as t, E as g, G as p } from "./index-C4JCoBvj.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -0,0 +1,26 @@
1
+ import { g as t, e as n } from "./index-C4JCoBvj.js";
2
+ import "./ops/cpu/gelu.js";
3
+ import "./ops/webgl/gelu.js";
4
+ const a = {
5
+ kernelName: "Gelu",
6
+ inputsToSave: ["x"],
7
+ outputsToSave: [],
8
+ gradFunc: (e, r) => {
9
+ const [u] = r;
10
+ return {
11
+ x: () => o(e, u)
12
+ };
13
+ }
14
+ };
15
+ t(a);
16
+ function g(e) {
17
+ return n().runKernel("Gelu", { x: e });
18
+ }
19
+ function o(e, r) {
20
+ return n().runKernel("GeluGrad", { dy: e, x: r });
21
+ }
22
+ export {
23
+ a,
24
+ o as d,
25
+ g
26
+ };
@@ -4030,7 +4030,7 @@ export {
4030
4030
  V as Z,
4031
4031
  oa as _,
4032
4032
  M as a,
4033
- ko as a$,
4033
+ $s as a$,
4034
4034
  nt as a0,
4035
4035
  Qa as a1,
4036
4036
  Ca as a2,
@@ -4040,68 +4040,68 @@ export {
4040
4040
  la as a6,
4041
4041
  ua as a7,
4042
4042
  Za as a8,
4043
- F as a9,
4044
- Ta as aA,
4045
- Aa as aB,
4046
- Ra as aC,
4047
- $a as aD,
4048
- Ds as aE,
4049
- ro as aF,
4050
- no as aG,
4051
- eo as aH,
4052
- Rt as aI,
4053
- x as aJ,
4054
- Io as aK,
4055
- oo as aL,
4056
- yr as aM,
4057
- $r as aN,
4058
- ao as aO,
4059
- da as aP,
4060
- ma as aQ,
4061
- ga as aR,
4062
- Na as aS,
4063
- va as aT,
4064
- to as aU,
4065
- yo as aV,
4066
- xs as aW,
4067
- jt as aX,
4068
- ue as aY,
4069
- $t as aZ,
4070
- $s as a_,
4071
- D as aa,
4072
- k as ab,
4073
- pe as ac,
4074
- fo as ad,
4075
- dt as ae,
4076
- za as af,
4077
- _a as ag,
4078
- er as ah,
4079
- rr as ai,
4080
- rs as aj,
4081
- Pa as ak,
4082
- Ar as al,
4083
- Br as am,
4084
- Rr as an,
4085
- Wn as ao,
4086
- xr as ap,
4087
- _r as aq,
4088
- Or as ar,
4089
- Gr as as,
4090
- Wr as at,
4091
- jr as au,
4092
- Kr as av,
4093
- ha as aw,
4094
- Jr as ax,
4095
- ia as ay,
4096
- Sa as az,
4043
+ xr as a9,
4044
+ Kr as aA,
4045
+ ha as aB,
4046
+ Jr as aC,
4047
+ ia as aD,
4048
+ Sa as aE,
4049
+ Ta as aF,
4050
+ Aa as aG,
4051
+ Ra as aH,
4052
+ $a as aI,
4053
+ Ds as aJ,
4054
+ ro as aK,
4055
+ no as aL,
4056
+ eo as aM,
4057
+ Io as aN,
4058
+ oo as aO,
4059
+ yr as aP,
4060
+ $r as aQ,
4061
+ ao as aR,
4062
+ da as aS,
4063
+ ma as aT,
4064
+ ga as aU,
4065
+ Na as aV,
4066
+ va as aW,
4067
+ to as aX,
4068
+ yo as aY,
4069
+ xs as aZ,
4070
+ $t as a_,
4071
+ Wn as aa,
4072
+ Rt as ab,
4073
+ D as ac,
4074
+ x as ad,
4075
+ F as ae,
4076
+ k as af,
4077
+ pe as ag,
4078
+ fo as ah,
4079
+ dt as ai,
4080
+ jt as aj,
4081
+ ue as ak,
4082
+ rs as al,
4083
+ de as am,
4084
+ za as an,
4085
+ _a as ao,
4086
+ er as ap,
4087
+ rr as aq,
4088
+ Pa as ar,
4089
+ Ar as as,
4090
+ Br as at,
4091
+ Rr as au,
4092
+ _r as av,
4093
+ Or as aw,
4094
+ Gr as ax,
4095
+ Wr as ay,
4096
+ jr as az,
4097
4097
  b,
4098
4098
  Vs as b$,
4099
- Ps as b0,
4100
- Cs as b1,
4101
- Lt as b2,
4102
- te as b3,
4103
- uo as b4,
4104
- de as b5,
4099
+ ko as b0,
4100
+ Ps as b1,
4101
+ Cs as b2,
4102
+ Lt as b3,
4103
+ te as b4,
4104
+ uo as b5,
4105
4105
  dn as b6,
4106
4106
  Re as b7,
4107
4107
  $e as b8,