@genai-fi/nanogpt 0.3.2 → 0.4.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.
- 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.js +16 -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 +106 -80
- 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 +1 -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 -95
- 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,7 +1,7 @@
|
|
|
1
1
|
import { generateText as v } 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-
|
|
4
|
+
import { a as h } from "../index-XjBAhiFO.js";
|
|
5
5
|
const D = {
|
|
6
6
|
desiredLoss: 0.01,
|
|
7
7
|
logInterval: 1,
|
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
|
-
};
|
package/dist/softmax-Be_lsqUc.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { o as r, h as e, E as c, _ as $, $ as h, a0 as E, s as S, Z as _, a1 as d } from "./index-pWA4_lUh.js";
|
|
2
|
-
import { m as k, s as w, e as K } from "./sum-C7Mgy9Bw.js";
|
|
3
|
-
import { r as l } from "./reshape-C8CR_Bad.js";
|
|
4
|
-
/**
|
|
5
|
-
* @license
|
|
6
|
-
* Copyright 2018 Google LLC. 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 T(n) {
|
|
21
|
-
const s = { x: e(n, "x", "exp") };
|
|
22
|
-
return c.runKernel($, s);
|
|
23
|
-
}
|
|
24
|
-
const b = /* @__PURE__ */ r({ exp_: T });
|
|
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 L(n) {
|
|
42
|
-
const s = { x: e(n, "x", "log", "float32") };
|
|
43
|
-
return c.runKernel(h, s);
|
|
44
|
-
}
|
|
45
|
-
const N = /* @__PURE__ */ r({ log_: L });
|
|
46
|
-
/**
|
|
47
|
-
* @license
|
|
48
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
49
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
50
|
-
* you may not use this file except in compliance with the License.
|
|
51
|
-
* You may obtain a copy of the License at
|
|
52
|
-
*
|
|
53
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
54
|
-
*
|
|
55
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
56
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
57
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
58
|
-
* See the License for the specific language governing permissions and
|
|
59
|
-
* limitations under the License.
|
|
60
|
-
* =============================================================================
|
|
61
|
-
*/
|
|
62
|
-
function v(n, o = null, s = !1) {
|
|
63
|
-
const t = e(n, "x", "logSumExp"), a = E(o, t.shape), p = k(
|
|
64
|
-
t,
|
|
65
|
-
a,
|
|
66
|
-
!0
|
|
67
|
-
/* keepDims */
|
|
68
|
-
), i = S(t, p), f = b(i), m = w(f, a), u = N(m), x = _(l(p, u.shape), u);
|
|
69
|
-
if (s) {
|
|
70
|
-
const g = K(x.shape, a);
|
|
71
|
-
return l(x, g);
|
|
72
|
-
}
|
|
73
|
-
return x;
|
|
74
|
-
}
|
|
75
|
-
const I = /* @__PURE__ */ r({ logSumExp_: v });
|
|
76
|
-
/**
|
|
77
|
-
* @license
|
|
78
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
79
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
80
|
-
* you may not use this file except in compliance with the License.
|
|
81
|
-
* You may obtain a copy of the License at
|
|
82
|
-
*
|
|
83
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
84
|
-
*
|
|
85
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
86
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
87
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
88
|
-
* See the License for the specific language governing permissions and
|
|
89
|
-
* limitations under the License.
|
|
90
|
-
* =============================================================================
|
|
91
|
-
*/
|
|
92
|
-
function y(n, o = -1) {
|
|
93
|
-
const s = e(n, "logits", "softmax", "float32");
|
|
94
|
-
if (o === -1 && (o = s.rank - 1), o !== s.rank - 1)
|
|
95
|
-
throw Error(`Softmax along a non-last dimension is not yet supported. Logits was rank ${s.rank} and dim was ${o}`);
|
|
96
|
-
const t = { logits: s }, a = { dim: o };
|
|
97
|
-
return c.runKernel(d, t, a);
|
|
98
|
-
}
|
|
99
|
-
const M = /* @__PURE__ */ r({ softmax_: y });
|
|
100
|
-
export {
|
|
101
|
-
N as a,
|
|
102
|
-
b as e,
|
|
103
|
-
I as l,
|
|
104
|
-
M as s
|
|
105
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ITokeniser } from '../tokeniser/type';
|
|
2
|
-
import { default as NanoGPT } from '../NanoGPTModel';
|
|
3
|
-
import { default as GPTTrainer, TrainingOptions } from './Trainer';
|
|
4
|
-
import { Tensor } from '@tensorflow/tfjs-core';
|
|
5
|
-
import { Dataset } from '@tensorflow/tfjs-data';
|
|
6
|
-
interface LayerTrainingOptions extends TrainingOptions {
|
|
7
|
-
stepsPerLayer: number;
|
|
8
|
-
maxPasses: number;
|
|
9
|
-
onLayerChange?: (layer: number, pass: number, valLoss?: number) => Promise<void> | void;
|
|
10
|
-
onPassComplete?: (pass: number) => Promise<void> | void;
|
|
11
|
-
}
|
|
12
|
-
export default class LayerTrainer extends GPTTrainer {
|
|
13
|
-
private trainingPattern;
|
|
14
|
-
private startPass;
|
|
15
|
-
private startLayer;
|
|
16
|
-
constructor(model: NanoGPT, tokenizer: ITokeniser, learningRate?: number);
|
|
17
|
-
private applyTrainingPattern;
|
|
18
|
-
trainOnDataset(dataset: Dataset<{
|
|
19
|
-
xs: Tensor;
|
|
20
|
-
ys: Tensor;
|
|
21
|
-
}>, options: Partial<LayerTrainingOptions>, validationDataset?: Dataset<{
|
|
22
|
-
xs: Tensor;
|
|
23
|
-
ys: Tensor;
|
|
24
|
-
}>): Promise<{
|
|
25
|
-
losses: number[];
|
|
26
|
-
validationLosses: number[];
|
|
27
|
-
}>;
|
|
28
|
-
}
|
|
29
|
-
export {};
|