@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.
- package/dist/Generator.js +22 -22
- package/dist/MLP-KHhikThU.js +83 -0
- package/dist/NanoGPTModel.d.ts +2 -3
- package/dist/NanoGPTModel.js +79 -79
- package/dist/TeachableLLM.d.ts +4 -3
- package/dist/TeachableLLM.js +16 -13
- package/dist/Trainer.js +20 -13
- package/dist/axis_util-DeydwOoC.js +69 -0
- package/dist/{concat-BIZS_td9.js → concat-DS_qH7MI.js} +5 -5
- package/dist/config.js +7 -8
- package/dist/{gather-BPGW8RsB.js → gather-BUmJIS8n.js} +1 -1
- package/dist/{index-pWA4_lUh.js → index-XjBAhiFO.js} +1272 -1174
- package/dist/layers/BaseLayer.d.ts +14 -2
- package/dist/layers/BaseLayer.js +9 -9
- package/dist/layers/CausalSelfAttention.d.ts +4 -8
- package/dist/layers/CausalSelfAttention.js +108 -82
- package/dist/layers/MLP.d.ts +2 -3
- package/dist/layers/MLP.js +5 -62
- package/dist/layers/RMSNorm.d.ts +2 -2
- package/dist/layers/RMSNorm.js +11 -11
- package/dist/layers/RoPECache.js +3 -3
- package/dist/layers/TiedEmbedding.js +7 -6
- package/dist/layers/TransformerBlock.d.ts +2 -6
- package/dist/layers/TransformerBlock.js +9 -12
- package/dist/{sum-C7Mgy9Bw.js → log_sum_exp-DJPkVZZn.js} +32 -54
- package/dist/main.js +22 -19
- package/dist/{mat_mul-D7_a4KJn.js → mat_mul-CKwFEV1Q.js} +1 -1
- package/dist/max-DJvEiCAJ.js +25 -0
- package/dist/moments-CrWRPcR3.js +53 -0
- package/dist/norm-BzY929B_.js +86 -0
- package/dist/{ones-Cog-G2ag.js → ones-BO01zpJG.js} +2 -2
- package/dist/ops/appendCache.js +1 -1
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +2 -2
- package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
- package/dist/ops/cpu/fusedSoftmax.js +23 -0
- package/dist/ops/cpu/gatherSub.js +3 -3
- package/dist/ops/cpu/mulDropout.d.ts +1 -0
- package/dist/ops/cpu/mulDropout.js +17 -0
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +27 -27
- package/dist/ops/fusedSoftmax.d.ts +2 -0
- package/dist/ops/fusedSoftmax.js +10 -0
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.d.ts +2 -0
- package/dist/ops/grads/fusedSoftmax.js +17 -0
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/mulDrop.d.ts +2 -0
- package/dist/ops/mulDrop.js +9 -0
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
- package/dist/ops/webgl/fusedSoftmax.js +3930 -0
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/mulDropout.d.ts +1 -0
- package/dist/ops/webgl/mulDropout.js +41 -0
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/{random_width-oeUIlUZj.js → random_width-CMHmdbSu.js} +4212 -6630
- package/dist/{range-CcDl05lo.js → range-DQMNzBWs.js} +1 -1
- package/dist/{reshape-C8CR_Bad.js → reshape-DFzh97Sc.js} +1 -1
- package/dist/{sin-BJIrfnj7.js → sin-BYM-U4Ut.js} +1 -1
- package/dist/slice_util-CnVNPQI-.js +90 -0
- package/dist/softmax-4DOn6cPq.js +28 -0
- package/dist/{split-DZbvruEP.js → split-CkbeVdF8.js} +3 -3
- package/dist/{stack-BMm-efee.js → stack-DaIMO5iX.js} +1 -1
- package/dist/sum-C6u3xMi3.js +27 -0
- package/dist/{tensor-DJVbYhh1.js → tensor-Cu1fU7H7.js} +1 -1
- package/dist/{tensor2d-ZuQSh2D-.js → tensor2d-D0CKdG6B.js} +1 -1
- package/dist/tfjs_backend-Bzl2SrRo.js +2460 -0
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +3 -3
- package/dist/training/FullTrainer.js +41 -33
- package/dist/training/Trainer.d.ts +6 -1
- package/dist/training/Trainer.js +13 -12
- package/dist/training/sparseCrossEntropy.js +12 -11
- package/dist/utilities/dummy.js +8 -8
- package/dist/utilities/generate.js +11 -11
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-Dl_ub3pk.js → variable-BS4AKqNU.js} +1 -1
- package/dist/{zeros-CCy9C3uU.js → zeros-CmJFiC84.js} +1 -1
- package/package.json +1 -1
- package/dist/exports_layers-tbTBcwMM.js +0 -25
- package/dist/layers/LayerNorm.d.ts +0 -13
- package/dist/layers/LayerNorm.js +0 -33
- package/dist/moments-DfcpfwKi.js +0 -132
- package/dist/softmax-Be_lsqUc.js +0 -105
- package/dist/training/LayerTrainer.d.ts +0 -29
- package/dist/training/LayerTrainer.js +0 -90
- package/dist/training/lwSchedule.d.ts +0 -7
- package/dist/training/lwSchedule.js +0 -162
package/dist/training/AdamExt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as r, b as c, f as h, s as g, e as o } from "../index-
|
|
1
|
+
import { A as r, b as c, f as h, s as g, e as o } from "../index-XjBAhiFO.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,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a9 as $, aa as m, ab as M, a as R, ac as f, ad as v, ae as z, j as _, t as x } from "../index-XjBAhiFO.js";
|
|
2
2
|
import { s as E } from "../index-C4L8Cm77.js";
|
|
3
|
-
import { s as P } from "../stack-
|
|
4
|
-
import { t as D } from "../tensor-
|
|
3
|
+
import { s as P } from "../stack-DaIMO5iX.js";
|
|
4
|
+
import { t as D } from "../tensor-Cu1fU7H7.js";
|
|
5
5
|
import "../index-Tf7vU29b.js";
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
@@ -1,69 +1,77 @@
|
|
|
1
|
-
import { generateText as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { a as h } from "../index-
|
|
5
|
-
const
|
|
1
|
+
import { generateText as v } from "../utilities/generate.js";
|
|
2
|
+
import L from "./Trainer.js";
|
|
3
|
+
import x from "./Evaluator.js";
|
|
4
|
+
import { a as h } from "../index-XjBAhiFO.js";
|
|
5
|
+
const D = {
|
|
6
6
|
desiredLoss: 0.01,
|
|
7
7
|
logInterval: 1,
|
|
8
8
|
maxSteps: 1e3
|
|
9
9
|
};
|
|
10
|
-
class
|
|
10
|
+
class E extends L {
|
|
11
11
|
constructor(r, i, o = 3e-4) {
|
|
12
12
|
super(r, i, o);
|
|
13
13
|
}
|
|
14
14
|
// Train for multiple epochs using Dataset API - FIXED memory leaks
|
|
15
15
|
async trainOnDataset(r, i, o) {
|
|
16
|
-
const { desiredLoss:
|
|
17
|
-
...
|
|
16
|
+
const { desiredLoss: u, logInterval: d, onStep: l, prompt: c, maxSteps: g } = {
|
|
17
|
+
...D,
|
|
18
18
|
...i
|
|
19
|
-
}, t = {
|
|
19
|
+
}, n = Date.now(), t = {
|
|
20
20
|
step: 0,
|
|
21
21
|
lastLoss: 1e6,
|
|
22
22
|
totalSteps: 0,
|
|
23
23
|
losses: [],
|
|
24
24
|
validationLosses: [],
|
|
25
|
+
logStartTime: n,
|
|
26
|
+
trainingDuration: 0,
|
|
25
27
|
...this.lastState || {}
|
|
26
28
|
};
|
|
27
|
-
this.lastState = t, this.dummyPass(), this.model.trainable = !0;
|
|
28
|
-
const
|
|
29
|
-
this.running = !0;
|
|
30
|
-
const c = o ? new g(this.model, o) : void 0, v = await r.iterator();
|
|
29
|
+
this.lastState = t, this.dummyPass(), this.model.trainable = !0, this.running = !0, t.logStartTime = n;
|
|
30
|
+
const m = o ? new x(this.model, o) : void 0, S = await r.iterator();
|
|
31
31
|
try {
|
|
32
|
-
for (; this.running && !(t.lastLoss <
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const p =
|
|
32
|
+
for (; this.running && !(t.lastLoss < u); ) {
|
|
33
|
+
const a = await S.next();
|
|
34
|
+
if (a.done) break;
|
|
35
|
+
const p = a.value, f = this.trainBatch(t, p), s = {
|
|
36
36
|
loss: t.lastLoss,
|
|
37
37
|
step: t.step,
|
|
38
|
-
time: Date.now() -
|
|
38
|
+
time: Date.now() - n,
|
|
39
39
|
batchSize: p.xs.shape[0]
|
|
40
40
|
};
|
|
41
|
-
if (this.model.log.push(
|
|
42
|
-
|
|
41
|
+
if (this.model.log.push(s), t.step % d === 0) {
|
|
42
|
+
await f;
|
|
43
|
+
const w = Date.now();
|
|
44
|
+
if (t.trainingDuration += w - t.logStartTime, m)
|
|
43
45
|
try {
|
|
44
|
-
const
|
|
45
|
-
t.validationLosses.push(
|
|
46
|
-
} catch (
|
|
47
|
-
console.error("Validation error:",
|
|
46
|
+
const e = await m.evaluate(5);
|
|
47
|
+
t.validationLosses.push(e), s.valLoss = e;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error("Validation error:", e);
|
|
48
50
|
}
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
51
|
-
const
|
|
51
|
+
if (l) {
|
|
52
|
+
if (c) {
|
|
53
|
+
const T = await v(this.tokenizer, this.model, c, 100, {
|
|
52
54
|
temperature: 0.8
|
|
53
55
|
});
|
|
54
|
-
|
|
56
|
+
s.example = T;
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
const e = {
|
|
59
|
+
duration: t.trainingDuration,
|
|
60
|
+
totalSamples: t.totalSteps * s.batchSize,
|
|
61
|
+
samplesPerSecond: t.totalSteps * s.batchSize / (t.trainingDuration / 1e3)
|
|
62
|
+
};
|
|
63
|
+
await l(s, e);
|
|
57
64
|
}
|
|
65
|
+
t.logStartTime = Date.now();
|
|
58
66
|
}
|
|
59
|
-
t.step >=
|
|
67
|
+
t.step >= g && this.stop();
|
|
60
68
|
}
|
|
61
|
-
} catch (
|
|
62
|
-
throw console.error("Training error:",
|
|
69
|
+
} catch (a) {
|
|
70
|
+
throw console.error("Training error:", a), h(), a;
|
|
63
71
|
}
|
|
64
72
|
return h(), this.running = !1, { losses: t.losses, validationLosses: t.validationLosses };
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
export {
|
|
68
|
-
|
|
76
|
+
E as default
|
|
69
77
|
};
|
|
@@ -12,6 +12,11 @@ export interface TrainingState {
|
|
|
12
12
|
losses: number[];
|
|
13
13
|
validationLosses: number[];
|
|
14
14
|
}
|
|
15
|
+
export interface TrainingProgress {
|
|
16
|
+
duration: number;
|
|
17
|
+
totalSamples: number;
|
|
18
|
+
samplesPerSecond: number;
|
|
19
|
+
}
|
|
15
20
|
export interface AdamConfig {
|
|
16
21
|
learningRateFactor: number;
|
|
17
22
|
beta1: number;
|
|
@@ -23,7 +28,7 @@ export interface TrainingOptions {
|
|
|
23
28
|
logInterval: number;
|
|
24
29
|
prompt?: string;
|
|
25
30
|
maxSteps: number;
|
|
26
|
-
onStep?: (log: TrainingLogEntry) => Promise<void> | void;
|
|
31
|
+
onStep?: (log: TrainingLogEntry, progress: TrainingProgress) => Promise<void> | void;
|
|
27
32
|
}
|
|
28
33
|
export default abstract class GPTTrainer {
|
|
29
34
|
protected tokenizer: ITokeniser;
|
package/dist/training/Trainer.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { DatasetBuilder as
|
|
1
|
+
import { DatasetBuilder as d } from "./DatasetBuilder.js";
|
|
2
2
|
import h from "./AdamExt.js";
|
|
3
|
-
import { t as g, v as u, a as o } from "../index-
|
|
4
|
-
import { m as y,
|
|
5
|
-
import { m as
|
|
6
|
-
import {
|
|
7
|
-
|
|
3
|
+
import { t as g, v as u, a as o } from "../index-XjBAhiFO.js";
|
|
4
|
+
import { m as y, n as f } from "../norm-BzY929B_.js";
|
|
5
|
+
import { m as S, a as z } from "../moments-CrWRPcR3.js";
|
|
6
|
+
import { m as b } from "../max-DJvEiCAJ.js";
|
|
7
|
+
import { z as n } from "../zeros-CmJFiC84.js";
|
|
8
|
+
class G {
|
|
8
9
|
constructor(t, s, e = 1e-3) {
|
|
9
|
-
this.tokenizer = s, this.model = t, this.learningRate = e, this.resetOptimizer(), this.datasetBuilder = new
|
|
10
|
+
this.tokenizer = s, this.model = t, this.learningRate = e, this.resetOptimizer(), this.datasetBuilder = new d(s, t.config.gpt.blockSize);
|
|
10
11
|
}
|
|
11
12
|
model;
|
|
12
13
|
optimizer;
|
|
@@ -45,21 +46,21 @@ class M {
|
|
|
45
46
|
printGradients(t) {
|
|
46
47
|
Object.keys(t).forEach((s) => {
|
|
47
48
|
const e = t[s];
|
|
48
|
-
console.log(`${s}:`), console.log(` Shape: ${e.shape}`), console.log(` Mean: ${
|
|
49
|
+
console.log(`${s}:`), console.log(` Shape: ${e.shape}`), console.log(` Mean: ${S(e).dataSync()[0]}`), console.log(` Std: ${z(e).variance.sqrt().dataSync()[0]}`), console.log(` Min: ${y(e).dataSync()[0]}`), console.log(` Max: ${b(e).dataSync()[0]}`), console.log(` Norm: ${f(e).dataSync()[0]}`);
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
52
|
trainStep(t, s = !1, e = !1) {
|
|
52
53
|
return g(() => {
|
|
53
54
|
this.model.getProfiler()?.startMemory();
|
|
54
55
|
const { xs: a, ys: r } = t, l = () => {
|
|
55
|
-
const { loss:
|
|
56
|
-
return
|
|
56
|
+
const { loss: m, logits: p } = this.model.forward(a, r, !0);
|
|
57
|
+
return p.dispose(), m;
|
|
57
58
|
}, { value: c, grads: i } = u(l);
|
|
58
59
|
return s ? this.model.getProfiler()?.endMemory("Training") : (e && (console.log("-------"), this.printGradients(i), console.log("-------")), this.optimizer.applyGradients(i), this.model.getProfiler()?.endMemory("Training"), o(i)), c;
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
dummyPass() {
|
|
62
|
-
const t = n([1, this.model.config.blockSize], "int32"), s = n([1, this.model.config.blockSize], "int32");
|
|
63
|
+
const t = n([1, this.model.config.gpt.blockSize], "int32"), s = n([1, this.model.config.gpt.blockSize], "int32");
|
|
63
64
|
try {
|
|
64
65
|
const e = this.trainStep({ xs: t, ys: s }, !0);
|
|
65
66
|
e.dataSync(), e.dispose();
|
|
@@ -94,5 +95,5 @@ class M {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
export {
|
|
97
|
-
|
|
98
|
+
G as default
|
|
98
99
|
};
|
|
@@ -1,26 +1,27 @@
|
|
|
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-
|
|
4
|
-
import { s as v
|
|
5
|
-
import { m as
|
|
3
|
+
import { e as u, c as i, z as S, t as f, s as G } from "../index-XjBAhiFO.js";
|
|
4
|
+
import { s as v } from "../softmax-4DOn6cPq.js";
|
|
5
|
+
import { m as z } from "../max-DJvEiCAJ.js";
|
|
6
|
+
import { l as k } from "../log_sum_exp-DJPkVZZn.js";
|
|
6
7
|
function F(a, s) {
|
|
7
8
|
return f(() => {
|
|
8
|
-
const e = a.shape[a.shape.length - 1],
|
|
9
|
-
return L(h,
|
|
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);
|
|
10
|
+
return L(h, n, r);
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function j() {
|
|
13
14
|
return u().backendName === "tensorflow" ? i((s, e, m) => {
|
|
14
|
-
const
|
|
15
|
+
const o = s.shape.length > 2 ? s.reshape([-1, s.shape[s.shape.length - 1]]) : s, p = e.shape.length > 1 ? e.reshape([-1]).cast("int32") : e.cast("int32"), [n, t] = u().runKernel(
|
|
15
16
|
"NativeSparseSoftmaxCrossEntropy",
|
|
16
|
-
{ logits:
|
|
17
|
+
{ logits: o, labels: p },
|
|
17
18
|
{}
|
|
18
19
|
);
|
|
19
|
-
return m([t.reshape(s.shape)]), { value:
|
|
20
|
+
return m([t.reshape(s.shape)]), { value: n, gradFunc: (r, h) => [h[0], S(e)] };
|
|
20
21
|
}) : i(
|
|
21
22
|
// @ts-expect-error Invalid params
|
|
22
23
|
(s, e, m) => {
|
|
23
|
-
const
|
|
24
|
+
const o = s.shape[s.shape.length - 1], n = s.shape.slice(0, -1).reduce((d, c) => d * c, 1), t = s.reshape([n, o]), r = e.reshape([n]).cast("int32"), h = F(t, r);
|
|
24
25
|
return m([t, r]), t.dispose(), r.dispose(), { value: h, gradFunc: (d, c) => f(() => {
|
|
25
26
|
const l = c[0], b = c[1], x = v(l), C = y(x, b, d), E = S(e);
|
|
26
27
|
return [C.reshape(s.shape), E];
|
|
@@ -29,6 +30,6 @@ function $() {
|
|
|
29
30
|
);
|
|
30
31
|
}
|
|
31
32
|
export {
|
|
32
|
-
|
|
33
|
+
j as createSoftmaxCrossEntropyWithGrad,
|
|
33
34
|
F as sparseSoftmaxCrossEntropy
|
|
34
35
|
};
|
package/dist/utilities/dummy.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import { z as n } from "../zeros-
|
|
3
|
-
async function
|
|
4
|
-
const o = n([1, s.config.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
|
|
1
|
+
import "../index-XjBAhiFO.js";
|
|
2
|
+
import { z as n } from "../zeros-CmJFiC84.js";
|
|
3
|
+
async function a(s) {
|
|
4
|
+
const o = n([1, s.config.gpt.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
|
|
5
5
|
await t.data(), t.dispose(), i && i.dispose(), o.dispose();
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
const o = n([1, s.config.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
|
|
7
|
+
function c(s) {
|
|
8
|
+
const o = n([1, s.config.gpt.blockSize], "int32"), { logits: t, loss: i } = s.forward(o, void 0, !1);
|
|
9
9
|
t.dispose(), i && i.dispose(), o.dispose();
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
c as dummyPass,
|
|
13
|
+
a as dummyPassAsync
|
|
14
14
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { t as y } from "../index-
|
|
2
|
-
import { t as x } from "../tensor2d-
|
|
3
|
-
import { c as
|
|
1
|
+
import { t as y } from "../index-XjBAhiFO.js";
|
|
2
|
+
import { t as x } from "../tensor2d-D0CKdG6B.js";
|
|
3
|
+
import { c as f } from "../concat-DS_qH7MI.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");
|
|
7
7
|
if (a.length === 0)
|
|
8
8
|
throw new Error("Prompt cannot be an empty string");
|
|
9
|
-
const
|
|
10
|
-
let
|
|
11
|
-
for (let
|
|
12
|
-
const { output: n } = r.generate(
|
|
13
|
-
|
|
9
|
+
const p = await o.tokenise([a], !0), s = r.config.gpt.useRope ? new Array(r.config.gpt.nLayer).fill(void 0) : void 0, d = y(() => {
|
|
10
|
+
let t = x(p, [1, p[0].length], "int32"), e = t;
|
|
11
|
+
for (let g = 0; g < c; g++) {
|
|
12
|
+
const { output: n } = r.generate(t, s, T), l = t, m = e;
|
|
13
|
+
e = f([e, n], 1), t = s ? n : f([t, n], 1), l.dispose(), m.dispose(), s || n.dispose();
|
|
14
14
|
}
|
|
15
|
-
return
|
|
16
|
-
}), w = await
|
|
17
|
-
|
|
15
|
+
return e;
|
|
16
|
+
}), w = await d.array();
|
|
17
|
+
d.dispose();
|
|
18
18
|
const i = w[0], u = i.indexOf(o.eosToken);
|
|
19
19
|
return u !== -1 && i.splice(u), await o.decode(i);
|
|
20
20
|
}
|
package/dist/utilities/load.js
CHANGED
|
@@ -3,7 +3,7 @@ import { importWeights as b } from "./weights.js";
|
|
|
3
3
|
import u from "../tokeniser/CharTokeniser.js";
|
|
4
4
|
import F from "../NanoGPTModel.js";
|
|
5
5
|
import { dummyPassAsync as j } from "./dummy.js";
|
|
6
|
-
import { d as T } from "../index-
|
|
6
|
+
import { d as T } from "../index-XjBAhiFO.js";
|
|
7
7
|
import E from "../tokeniser/bpe.js";
|
|
8
8
|
async function A(t) {
|
|
9
9
|
const o = await fetch(t);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import { t as p } from "../tensor-
|
|
1
|
+
import "../index-XjBAhiFO.js";
|
|
2
|
+
import { t as p } from "../tensor-Cu1fU7H7.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 { o as m, h as r,
|
|
1
|
+
import { o as m, h as r, U as l, E as c, V as i, k as p, W as u, n as f } from "./index-XjBAhiFO.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { E as e, D as r, a as o } from "./random_width-oeUIlUZj.js";
|
|
2
|
-
import "./index-pWA4_lUh.js";
|
|
3
|
-
/**
|
|
4
|
-
* @license
|
|
5
|
-
* Copyright 2018 Google LLC
|
|
6
|
-
*
|
|
7
|
-
* Use of this source code is governed by an MIT-style
|
|
8
|
-
* license that can be found in the LICENSE file or at
|
|
9
|
-
* https://opensource.org/licenses/MIT.
|
|
10
|
-
* =============================================================================
|
|
11
|
-
*/
|
|
12
|
-
function s(n) {
|
|
13
|
-
return new o(n);
|
|
14
|
-
}
|
|
15
|
-
function u(n) {
|
|
16
|
-
return new r(n);
|
|
17
|
-
}
|
|
18
|
-
function d(n) {
|
|
19
|
-
return new e(n);
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
u as a,
|
|
23
|
-
s as d,
|
|
24
|
-
d as e
|
|
25
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { default as TF } from '@tensorflow/tfjs';
|
|
2
|
-
export default class LayerNorm {
|
|
3
|
-
private gamma;
|
|
4
|
-
private epsilon;
|
|
5
|
-
private tf;
|
|
6
|
-
constructor(tf: typeof TF, shape: number[], epsilon?: number, name?: string);
|
|
7
|
-
get trainableWeights(): TF.Variable[];
|
|
8
|
-
set trainable(value: boolean);
|
|
9
|
-
getWeights(): TF.Tensor[];
|
|
10
|
-
setWeights(weights: TF.Tensor[]): void;
|
|
11
|
-
apply(x: TF.Tensor): TF.Tensor;
|
|
12
|
-
dispose(): void;
|
|
13
|
-
}
|
package/dist/layers/LayerNorm.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
class h {
|
|
2
|
-
gamma;
|
|
3
|
-
//private beta: TF.Variable;
|
|
4
|
-
epsilon;
|
|
5
|
-
tf;
|
|
6
|
-
constructor(a, s, t = 1e-5, e = "") {
|
|
7
|
-
this.tf = a, this.epsilon = t, this.gamma = a.variable(a.ones(s), !0, `${e}_gamma`, "float32");
|
|
8
|
-
}
|
|
9
|
-
get trainableWeights() {
|
|
10
|
-
return [this.gamma];
|
|
11
|
-
}
|
|
12
|
-
set trainable(a) {
|
|
13
|
-
this.gamma.trainable = a;
|
|
14
|
-
}
|
|
15
|
-
getWeights() {
|
|
16
|
-
return [this.gamma];
|
|
17
|
-
}
|
|
18
|
-
setWeights(a) {
|
|
19
|
-
this.gamma.assign(a[0]);
|
|
20
|
-
}
|
|
21
|
-
apply(a) {
|
|
22
|
-
return this.tf.tidy(() => {
|
|
23
|
-
const s = a.mean(-1, !0), t = a.sub(s), i = t.square().mean(-1, !0).add(this.epsilon).rsqrt();
|
|
24
|
-
return t.mul(i).mul(this.gamma);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
dispose() {
|
|
28
|
-
this.gamma.dispose();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
h as default
|
|
33
|
-
};
|
package/dist/moments-DfcpfwKi.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { o as i, h as m, E as y, a2 as A, a0 as E, a3 as o, a4 as h, J as b, f as S, a5 as v, a6 as _, s as k, U as q } from "./index-pWA4_lUh.js";
|
|
2
|
-
import { e as w, s as u, m as l } from "./sum-C7Mgy9Bw.js";
|
|
3
|
-
import { r as c } from "./reshape-C8CR_Bad.js";
|
|
4
|
-
/**
|
|
5
|
-
* @license
|
|
6
|
-
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
* =============================================================================
|
|
19
|
-
*/
|
|
20
|
-
function K(r, e = null, n = !1) {
|
|
21
|
-
const t = { x: m(r, "x", "min") }, a = { axis: e, keepDims: n };
|
|
22
|
-
return y.runKernel(A, t, a);
|
|
23
|
-
}
|
|
24
|
-
const d = /* @__PURE__ */ i({ min_: K });
|
|
25
|
-
/**
|
|
26
|
-
* @license
|
|
27
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
28
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
29
|
-
* you may not use this file except in compliance with the License.
|
|
30
|
-
* You may obtain a copy of the License at
|
|
31
|
-
*
|
|
32
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
-
*
|
|
34
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
35
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
36
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
37
|
-
* See the License for the specific language governing permissions and
|
|
38
|
-
* limitations under the License.
|
|
39
|
-
* =============================================================================
|
|
40
|
-
*/
|
|
41
|
-
function M(r, e = "euclidean", n = null, s = !1) {
|
|
42
|
-
r = m(r, "x", "norm");
|
|
43
|
-
const t = $(r, e, n);
|
|
44
|
-
let a = t.shape;
|
|
45
|
-
if (s) {
|
|
46
|
-
const f = E(n, r.shape);
|
|
47
|
-
a = w(t.shape, f);
|
|
48
|
-
}
|
|
49
|
-
return c(t, a);
|
|
50
|
-
}
|
|
51
|
-
function $(r, e, n = null) {
|
|
52
|
-
if (r.rank === 0)
|
|
53
|
-
return o(r);
|
|
54
|
-
if (r.rank !== 1 && n === null)
|
|
55
|
-
return $(c(r, [-1]), e, n);
|
|
56
|
-
if (r.rank === 1 || typeof n == "number" || Array.isArray(n) && n.length === 1) {
|
|
57
|
-
if (e === 1)
|
|
58
|
-
return u(o(r), n);
|
|
59
|
-
if (e === 1 / 0)
|
|
60
|
-
return l(o(r), n);
|
|
61
|
-
if (e === -1 / 0)
|
|
62
|
-
return d(o(r), n);
|
|
63
|
-
if (e === "euclidean" || e === 2)
|
|
64
|
-
return h(u(b(o(r), S(2, "int32")), n));
|
|
65
|
-
throw new Error(`Error in norm: invalid ord value: ${e}`);
|
|
66
|
-
}
|
|
67
|
-
if (Array.isArray(n) && n.length === 2) {
|
|
68
|
-
if (e === 1)
|
|
69
|
-
return l(u(o(r), n[0]), n[1] - 1);
|
|
70
|
-
if (e === 1 / 0)
|
|
71
|
-
return l(u(o(r), n[1]), n[0]);
|
|
72
|
-
if (e === -1 / 0)
|
|
73
|
-
return d(u(o(r), n[1]), n[0]);
|
|
74
|
-
if (e === "fro" || e === "euclidean")
|
|
75
|
-
return h(u(v(r), n));
|
|
76
|
-
throw new Error(`Error in norm: invalid ord value: ${e}`);
|
|
77
|
-
}
|
|
78
|
-
throw new Error(`Error in norm: invalid axis: ${n}`);
|
|
79
|
-
}
|
|
80
|
-
const J = /* @__PURE__ */ i({ norm_: M });
|
|
81
|
-
/**
|
|
82
|
-
* @license
|
|
83
|
-
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
84
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
85
|
-
* you may not use this file except in compliance with the License.
|
|
86
|
-
* You may obtain a copy of the License at
|
|
87
|
-
*
|
|
88
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
89
|
-
*
|
|
90
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
91
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
92
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
93
|
-
* See the License for the specific language governing permissions and
|
|
94
|
-
* limitations under the License.
|
|
95
|
-
* =============================================================================
|
|
96
|
-
*/
|
|
97
|
-
function T(r, e = null, n = !1) {
|
|
98
|
-
const t = { x: m(r, "x", "mean") }, a = { axis: e, keepDims: n };
|
|
99
|
-
return y.runKernel(_, t, a);
|
|
100
|
-
}
|
|
101
|
-
const p = /* @__PURE__ */ i({ mean_: T });
|
|
102
|
-
/**
|
|
103
|
-
* @license
|
|
104
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
105
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
-
* you may not use this file except in compliance with the License.
|
|
107
|
-
* You may obtain a copy of the License at
|
|
108
|
-
*
|
|
109
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
-
*
|
|
111
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
112
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
-
* See the License for the specific language governing permissions and
|
|
115
|
-
* limitations under the License.
|
|
116
|
-
* =============================================================================
|
|
117
|
-
*/
|
|
118
|
-
function g(r, e = null, n = !1) {
|
|
119
|
-
r = m(r, "x", "moments");
|
|
120
|
-
const s = E(e, r.shape), t = p(r, s, n);
|
|
121
|
-
let a = t.shape;
|
|
122
|
-
n || (a = w(t.shape, s));
|
|
123
|
-
const f = v(k(q(r, "float32"), c(t, a))), I = p(f, s, n);
|
|
124
|
-
return { mean: t, variance: I };
|
|
125
|
-
}
|
|
126
|
-
const P = /* @__PURE__ */ i({ moments_: g });
|
|
127
|
-
export {
|
|
128
|
-
P as a,
|
|
129
|
-
d as b,
|
|
130
|
-
p as m,
|
|
131
|
-
J as n
|
|
132
|
-
};
|