@genai-fi/nanogpt 0.2.8 → 0.2.10
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.
- package/dist/Generator.d.ts +2 -0
- package/dist/Generator.js +37 -32
- package/dist/NanoGPTModel.d.ts +4 -1
- package/dist/NanoGPTModel.js +33 -25
- package/dist/TeachableLLM.d.ts +4 -0
- package/dist/TeachableLLM.js +31 -16
- package/dist/{complex-CeoYJn2o.js → complex-x7w5HPOS.js} +6 -6
- package/dist/{index-DQfEAU9u.js → index-CWQLouWz.js} +312 -303
- package/dist/layers/BaseLayer.d.ts +8 -0
- package/dist/layers/BaseLayer.js +18 -0
- package/dist/layers/CausalSelfAttention.d.ts +2 -1
- package/dist/layers/CausalSelfAttention.js +10 -8
- package/dist/layers/MLP.d.ts +2 -1
- package/dist/layers/MLP.js +16 -14
- package/dist/layers/RMSNorm.d.ts +2 -1
- package/dist/layers/RMSNorm.js +13 -11
- package/dist/layers/TiedEmbedding.js +4 -4
- package/dist/layers/TransformerBlock.d.ts +4 -1
- package/dist/layers/TransformerBlock.js +9 -5
- package/dist/{mat_mul-CuHB58-H.js → mat_mul-4v7St11W.js} +5 -5
- package/dist/ops/attentionMask.js +47 -21
- package/dist/ops/gatherSub.js +2 -2
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/scatterSub.js +10 -10
- package/dist/{stack-C9cTkqpq.js → stack-CTdK-itU.js} +5 -5
- package/dist/{sum-B-O33dgG.js → sum-CnIf1YOh.js} +3 -3
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/Trainer.js +30 -29
- package/dist/training/sparseCrossEntropy.js +12 -12
- package/dist/utilities/profile.d.ts +10 -0
- package/dist/utilities/profile.js +29 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { gatherSub as w } from "../ops/gatherSub.js";
|
|
2
2
|
import { scatterSub as K } from "../ops/scatterSub.js";
|
|
3
|
-
import { o as l,
|
|
4
|
-
import { s as
|
|
3
|
+
import { o as l, d, E as f, M as _, u as z, L as I, v as N, b as E, w as M, x as T, e as m, y as g, z as $, D as S } from "../index-CWQLouWz.js";
|
|
4
|
+
import { s as D, r as b } from "../sum-CnIf1YOh.js";
|
|
5
5
|
/**
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
@@ -18,16 +18,16 @@ import { s as F, r as b } from "../sum-B-O33dgG.js";
|
|
|
18
18
|
* limitations under the License.
|
|
19
19
|
* =============================================================================
|
|
20
20
|
*/
|
|
21
|
-
function
|
|
21
|
+
function F(n, s, t) {
|
|
22
22
|
const a = n.length + s.length, e = [];
|
|
23
23
|
let r = 0, c = 0;
|
|
24
24
|
for (let o = 0; o < a; o++)
|
|
25
25
|
t.indexOf(o) === -1 ? e.push(n[r++]) : e.push(s[c++]);
|
|
26
26
|
return e;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function P(n, s) {
|
|
29
29
|
const t = s.map((a) => 1);
|
|
30
|
-
return
|
|
30
|
+
return F(n, t, s);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* @license
|
|
@@ -66,11 +66,11 @@ const L = /* @__PURE__ */ l({ max_: A });
|
|
|
66
66
|
* limitations under the License.
|
|
67
67
|
* =============================================================================
|
|
68
68
|
*/
|
|
69
|
-
function
|
|
69
|
+
function O(n) {
|
|
70
70
|
const t = { x: d(n, "x", "exp") };
|
|
71
71
|
return f.runKernel(z, t);
|
|
72
72
|
}
|
|
73
|
-
const
|
|
73
|
+
const W = /* @__PURE__ */ l({ exp_: O });
|
|
74
74
|
/**
|
|
75
75
|
* @license
|
|
76
76
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -87,11 +87,11 @@ const O = /* @__PURE__ */ l({ exp_: D });
|
|
|
87
87
|
* limitations under the License.
|
|
88
88
|
* =============================================================================
|
|
89
89
|
*/
|
|
90
|
-
function
|
|
90
|
+
function j(n) {
|
|
91
91
|
const t = { x: d(n, "x", "log", "float32") };
|
|
92
92
|
return f.runKernel(I, t);
|
|
93
93
|
}
|
|
94
|
-
const
|
|
94
|
+
const q = /* @__PURE__ */ l({ log_: j });
|
|
95
95
|
/**
|
|
96
96
|
* @license
|
|
97
97
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -114,9 +114,9 @@ function B(n, s = null, t = !1) {
|
|
|
114
114
|
e,
|
|
115
115
|
!0
|
|
116
116
|
/* keepDims */
|
|
117
|
-
), c = E(a, r), o =
|
|
117
|
+
), c = E(a, r), o = W(c), p = D(o, e), u = q(p), i = M(b(r, u.shape), u);
|
|
118
118
|
if (t) {
|
|
119
|
-
const h =
|
|
119
|
+
const h = P(i.shape, e);
|
|
120
120
|
return b(i, h);
|
|
121
121
|
}
|
|
122
122
|
return i;
|
|
@@ -165,7 +165,7 @@ function ss() {
|
|
|
165
165
|
(s, t, a) => {
|
|
166
166
|
const e = s.shape[s.shape.length - 1], c = s.shape.slice(0, -1).reduce((h, x) => h * x, 1), o = s.reshape([c, e]), p = t.reshape([c]).cast("int32"), u = R(o, p);
|
|
167
167
|
return a([o, p]), o.dispose(), p.dispose(), { value: u, gradFunc: (h, x) => $(() => {
|
|
168
|
-
const
|
|
168
|
+
const y = x[0], k = x[1], C = Q(y), G = K(C, k, h), v = S(t);
|
|
169
169
|
return [G.reshape(s.shape), v];
|
|
170
170
|
}) };
|
|
171
171
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { m as s } from "../index-CWQLouWz.js";
|
|
2
|
+
const m = 1024 * 1024;
|
|
3
|
+
class i {
|
|
4
|
+
log = /* @__PURE__ */ new Map();
|
|
5
|
+
maxMemory = 0;
|
|
6
|
+
maxLabel;
|
|
7
|
+
lastMemInfo = [];
|
|
8
|
+
peakMemory = 0;
|
|
9
|
+
startMemory() {
|
|
10
|
+
this.lastMemInfo.push(s());
|
|
11
|
+
}
|
|
12
|
+
endMemory(e) {
|
|
13
|
+
if (this.lastMemInfo.length === 0) {
|
|
14
|
+
console.warn("MemoryProfiler: endMemory called without matching startMemory");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const o = s(), t = o.numBytes - (this.lastMemInfo.pop()?.numBytes || 0);
|
|
18
|
+
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.numBytes);
|
|
19
|
+
}
|
|
20
|
+
printSummary() {
|
|
21
|
+
console.log("Memory Usage Summary:");
|
|
22
|
+
for (const [e, o] of this.log.entries())
|
|
23
|
+
console.log(`- ${e}: ${(o / m).toFixed(2)} MB`);
|
|
24
|
+
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`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
i as default
|
|
29
|
+
};
|