@genai-fi/nanogpt 0.24.0 → 1.0.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/README.md +78 -281
- package/dist/{RealDiv-CNsvC4AU.js → RealDiv-CSnvtN2E.js} +20 -20
- package/dist/{Reshape-dnm9bO3B.js → Reshape-BlylqwWy.js} +12 -12
- package/dist/TeachableLLM.d.ts +10 -14
- package/dist/TeachableLLM.js +201 -2
- package/dist/api/responses.d.ts +81 -0
- package/dist/api/responses.js +169 -0
- package/dist/api/training.d.ts +70 -0
- package/dist/api/training.js +205 -0
- package/dist/data/docx.js +9 -3036
- package/dist/data/stream.d.ts +2 -2
- package/dist/data/textLoader.d.ts +1 -1
- package/dist/data/textLoader.js +1 -1
- package/dist/data.d.ts +3 -0
- package/dist/data.js +12 -0
- package/dist/{dist-BqAU9-yi.js → dist-CwK5S7Ls.js} +2168 -2168
- package/dist/{gpgpu_math-DBYEAAdI.js → gpgpu_math-20tPK8LM.js} +458 -458
- package/dist/{Generator.d.ts → inference/Generator.d.ts} +16 -44
- package/dist/inference/Generator.js +271 -0
- package/dist/inference/tokenisePrompt.d.ts +4 -0
- package/dist/inference/tokenisePrompt.js +13 -0
- package/dist/inference/types.d.ts +44 -8
- package/dist/inference/utilities.d.ts +9 -0
- package/dist/inference/utilities.js +20 -0
- package/dist/jszip.min-DKa1Rjyn.js +3033 -0
- package/dist/{kernel_funcs_utils-D-mATnGR.js → kernel_funcs_utils-ql8Y8qPn.js} +96 -93
- package/dist/layers/MLP.d.ts +1 -1
- package/dist/layers/PositionEmbedding.d.ts +2 -1
- package/dist/layers/PositionEmbedding.js +1 -1
- package/dist/layers/RMSNorm.d.ts +1 -1
- package/dist/layers/TiedEmbedding.js +1 -1
- package/dist/layers.d.ts +4 -0
- package/dist/layers.js +14 -0
- package/dist/loader/load.js +58 -2
- package/dist/loader/loadHF.d.ts +1 -1
- package/dist/loader/loadHF.js +17 -2
- package/dist/loader/loadTransformers.js +46 -2
- package/dist/loader/newZipLoad.js +25 -2
- package/dist/loader/oldZipLoad.d.ts +1 -1
- package/dist/loader/oldZipLoad.js +37 -2
- package/dist/loader/save.js +75 -2
- package/dist/loader/types.d.ts +3 -3
- package/dist/main.d.ts +34 -35
- package/dist/main.js +12327 -20
- package/dist/{matMulGelu-BAIgQaRx.js → matMulGelu-CBoqTZM7.js} +2 -2
- package/dist/models/NanoGPTV1.js +95 -2
- package/dist/models/NanoGPTV2.js +86 -2
- package/dist/models/factory.js +13 -2
- package/dist/models/model.js +76 -2
- package/dist/models.d.ts +4 -0
- package/dist/models.js +14 -0
- package/dist/ops/dot16.js +1 -1
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/webgl/adamAdjust.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +2 -2
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +5 -5
- package/dist/ops/webgl/matMulGelu.js +1 -1
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/{tfjs_backend-CydPRQTc.js → tfjs_backend-h5weiy1O.js} +36 -36
- package/dist/tokenise.d.ts +4 -0
- package/dist/tokenise.js +15 -0
- package/dist/training/BasicTrainer.d.ts +5 -10
- package/dist/training/BasicTrainer.js +80 -88
- package/dist/training/configure.d.ts +3 -0
- package/dist/training/configure.js +32 -0
- package/dist/training/factory.d.ts +6 -0
- package/dist/training/factory.js +8 -0
- package/dist/training/prepareData.d.ts +22 -0
- package/dist/training/prepareData.js +49 -0
- package/dist/training/tasks/tokenStream.d.ts +2 -1
- package/dist/training/types.d.ts +14 -1
- package/dist/training/validateOptions.d.ts +2 -0
- package/dist/training/validateOptions.js +19 -0
- package/dist/utilities/arrayShape.d.ts +1 -0
- package/dist/utilities/arrayShape.js +8 -0
- package/dist/utilities/waitForModel.d.ts +1 -1
- package/dist/v4-BK7K-jy_.js +30 -0
- package/package.json +8 -2
- package/dist/Generator.js +0 -2
- package/dist/Trainer-Cr7csbTD.js +0 -228
- package/dist/Trainer.d.ts +0 -45
- package/dist/Trainer.js +0 -2
- package/dist/main-Dz72vadm.js +0 -13267
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ci as e, Ii as t, In as n, Ps as r, di as i, gr as a, ii as o, oc as s } from "./dist-Da20xy8E.js";
|
|
2
|
-
import { a as c } from "./gpgpu_math-
|
|
3
|
-
import { t as l } from "./Reshape-
|
|
2
|
+
import { a as c } from "./gpgpu_math-20tPK8LM.js";
|
|
3
|
+
import { t as l } from "./Reshape-BlylqwWy.js";
|
|
4
4
|
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/mulmat_packed_gpu.js
|
|
5
5
|
var u = class {
|
|
6
6
|
constructor(e, t, n, r = !1, i = !1, a = !1, o = null, s = !1, l = !1) {
|
package/dist/models/NanoGPTV1.js
CHANGED
|
@@ -1,2 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { di as e, oi as t } from "../dist-Da20xy8E.js";
|
|
2
|
+
import { packingSupported as n } from "../utilities/packed.js";
|
|
3
|
+
import { r, t as i } from "../pack16-BhuXNUS7.js";
|
|
4
|
+
import a from "../layers/RMSNorm.js";
|
|
5
|
+
import o from "../layers/TransformerBlock.js";
|
|
6
|
+
import s from "../layers/TiedEmbedding.js";
|
|
7
|
+
import c from "../layers/RoPECache.js";
|
|
8
|
+
import l from "./model.js";
|
|
9
|
+
import u from "../layers/PositionEmbedding.js";
|
|
10
|
+
//#region lib/models/NanoGPTV1.ts
|
|
11
|
+
var d = {
|
|
12
|
+
modelType: "GenAI_NanoGPT_v1",
|
|
13
|
+
vocabSize: 2e3,
|
|
14
|
+
blockSize: 128,
|
|
15
|
+
nLayer: 6,
|
|
16
|
+
nHead: 4,
|
|
17
|
+
nEmbed: 256,
|
|
18
|
+
mlpFactor: 4,
|
|
19
|
+
useRope: !0
|
|
20
|
+
}, f = class extends l {
|
|
21
|
+
wte;
|
|
22
|
+
wpe;
|
|
23
|
+
blocks;
|
|
24
|
+
lnF;
|
|
25
|
+
ropeCache;
|
|
26
|
+
constructor(e = {}) {
|
|
27
|
+
super({
|
|
28
|
+
...d,
|
|
29
|
+
...e
|
|
30
|
+
});
|
|
31
|
+
let t = {
|
|
32
|
+
activation: "gelu",
|
|
33
|
+
hiddenFactor: this.config.mlpFactor,
|
|
34
|
+
useGamma: !0,
|
|
35
|
+
useQKNorm: !1
|
|
36
|
+
};
|
|
37
|
+
this.wte = new s(this.config, "token_embedding", this), this.config.useRope === !1 ? this.wpe = new u(this.config, "positional_embedding", this) : this.ropeCache = new c(this.config), this.blocks = [];
|
|
38
|
+
for (let e = 0; e < this.config.nLayer; e++) this.blocks.push(new o(e, this.config, t, this));
|
|
39
|
+
this.lnF = new a(this.config, t, "final_rms_norm", this);
|
|
40
|
+
}
|
|
41
|
+
getClassName() {
|
|
42
|
+
return "GenAI_NanoGPT_v1";
|
|
43
|
+
}
|
|
44
|
+
inputPhase(t, n) {
|
|
45
|
+
return e(() => {
|
|
46
|
+
let e = this.wte.embed(t);
|
|
47
|
+
if (this.config.useRope === !1) {
|
|
48
|
+
let t = this.wpe.call(n, e);
|
|
49
|
+
if (Array.isArray(t)) throw Error("PositionEmbedding output should not be an array");
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
return e;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
forward(a, o) {
|
|
56
|
+
return this.validateInput(o), a.ropeCache = this.ropeCache, a.outputEmbeddings && (a.embeddings = []), e(() => {
|
|
57
|
+
this.startMemory();
|
|
58
|
+
let e = this.inputPhase(o, a);
|
|
59
|
+
if (a.cache && a.cache.length !== this.blocks.length) throw console.error("Cache", a.cache), Error(`Cache length ${a.cache.length} does not match number of blocks ${this.blocks.length}`);
|
|
60
|
+
let s = a.mixedPrecision === !0 && n(), c = s ? i(e) : e;
|
|
61
|
+
s && e !== c && e.dispose();
|
|
62
|
+
for (let e = 0; e < this.blocks.length; e++) {
|
|
63
|
+
let n = this.blocks[e], r = Math.random() * 1e9, i = {
|
|
64
|
+
...a,
|
|
65
|
+
seed: r,
|
|
66
|
+
pastKV: a.cache ? a.cache[e] : void 0,
|
|
67
|
+
mixedPrecision: s
|
|
68
|
+
}, o = a.checkpointing && a.training ? n.callCheckpoint(i, c) : n.call(i, c);
|
|
69
|
+
a.outputEmbeddings ? (t(c), a.embeddings.push({
|
|
70
|
+
name: `block_output_${e}`,
|
|
71
|
+
tensor: c
|
|
72
|
+
})) : c.dispose(), c = o;
|
|
73
|
+
}
|
|
74
|
+
if (e = this.lnF.call({
|
|
75
|
+
...a,
|
|
76
|
+
mixedPrecision: s
|
|
77
|
+
}, c), c.dispose(), a.skipLogits) return this.endMemory("Forward"), e;
|
|
78
|
+
let l = this.wte.project(e);
|
|
79
|
+
a.outputEmbeddings ? (t(e), a.embeddings.push({
|
|
80
|
+
name: "final_norm_output",
|
|
81
|
+
tensor: e
|
|
82
|
+
})) : e.dispose();
|
|
83
|
+
let u = s ? r(l) : l;
|
|
84
|
+
return s && l !== u && l.dispose(), u;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
project(t) {
|
|
88
|
+
return e(() => this.wte.project(t));
|
|
89
|
+
}
|
|
90
|
+
dispose() {
|
|
91
|
+
this.weightStore.dispose(), this.wte.dispose(), this.wpe && this.wpe.dispose(), this.blocks.forEach((e) => e.dispose()), this.lnF.dispose();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
export { f as default };
|
package/dist/models/NanoGPTV2.js
CHANGED
|
@@ -1,2 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { di as e, oi as t } from "../dist-Da20xy8E.js";
|
|
2
|
+
import { packingSupported as n } from "../utilities/packed.js";
|
|
3
|
+
import { r, t as i } from "../pack16-BhuXNUS7.js";
|
|
4
|
+
import a from "../layers/RMSNorm.js";
|
|
5
|
+
import o from "../layers/TransformerBlock.js";
|
|
6
|
+
import s from "../layers/TiedEmbedding.js";
|
|
7
|
+
import c from "../layers/RoPECache.js";
|
|
8
|
+
import l from "./model.js";
|
|
9
|
+
//#region lib/models/NanoGPTV2.ts
|
|
10
|
+
var u = {
|
|
11
|
+
modelType: "GenAI_NanoGPT_v2",
|
|
12
|
+
vocabSize: 2e3,
|
|
13
|
+
blockSize: 128,
|
|
14
|
+
nLayer: 6,
|
|
15
|
+
nHead: 4,
|
|
16
|
+
nEmbed: 256,
|
|
17
|
+
mlpFactor: 4
|
|
18
|
+
}, d = class extends l {
|
|
19
|
+
wte;
|
|
20
|
+
wpe;
|
|
21
|
+
blocks;
|
|
22
|
+
lnF;
|
|
23
|
+
ropeCache;
|
|
24
|
+
constructor(e = {}) {
|
|
25
|
+
super({
|
|
26
|
+
...u,
|
|
27
|
+
...e
|
|
28
|
+
});
|
|
29
|
+
let t = {
|
|
30
|
+
activation: "relu2",
|
|
31
|
+
hiddenFactor: this.config.mlpFactor,
|
|
32
|
+
useGamma: !1,
|
|
33
|
+
useQKNorm: !0
|
|
34
|
+
};
|
|
35
|
+
this.wte = new s(this.config, "token_embedding", this), this.ropeCache = new c(this.config), this.blocks = [];
|
|
36
|
+
for (let e = 0; e < this.config.nLayer; e++) this.blocks.push(new o(e, this.config, t, this));
|
|
37
|
+
this.lnF = new a(this.config, t, "final_rms_norm", this);
|
|
38
|
+
}
|
|
39
|
+
getClassName() {
|
|
40
|
+
return "GenAI_NanoGPT_v2";
|
|
41
|
+
}
|
|
42
|
+
inputPhase(t) {
|
|
43
|
+
return e(() => this.wte.embed(t));
|
|
44
|
+
}
|
|
45
|
+
forward(a, o) {
|
|
46
|
+
return this.validateInput(o), a.ropeCache = this.ropeCache, a.outputEmbeddings && (a.embeddings = []), e(() => {
|
|
47
|
+
this.startMemory();
|
|
48
|
+
let e = this.inputPhase(o);
|
|
49
|
+
if (a.cache && a.cache.length !== this.blocks.length) throw console.error("Cache", a.cache), Error(`Cache length ${a.cache.length} does not match number of blocks ${this.blocks.length}`);
|
|
50
|
+
let s = a.mixedPrecision === !0 && n(), c = s ? i(e) : e;
|
|
51
|
+
s && e !== c && e.dispose();
|
|
52
|
+
for (let e = 0; e < this.blocks.length; e++) {
|
|
53
|
+
if (a.layerDrop && Math.random() < a.layerDrop * (e / this.blocks.length)) continue;
|
|
54
|
+
let n = this.blocks[e], r = Math.random() * 1e9, i = {
|
|
55
|
+
...a,
|
|
56
|
+
seed: r,
|
|
57
|
+
pastKV: a.cache ? a.cache[e] : void 0,
|
|
58
|
+
mixedPrecision: s
|
|
59
|
+
}, o = a.checkpointing && a.training ? n.callCheckpoint(i, c) : n.call(i, c);
|
|
60
|
+
a.outputEmbeddings ? (t(c), a.embeddings.push({
|
|
61
|
+
name: `block_output_${e}`,
|
|
62
|
+
tensor: c
|
|
63
|
+
})) : c.dispose(), c = o;
|
|
64
|
+
}
|
|
65
|
+
if (e = this.lnF.call({
|
|
66
|
+
...a,
|
|
67
|
+
mixedPrecision: s
|
|
68
|
+
}, c), c.dispose(), a.skipLogits) return this.endMemory("Forward"), e;
|
|
69
|
+
let l = this.wte.project(e);
|
|
70
|
+
a.outputEmbeddings ? (t(e), a.embeddings.push({
|
|
71
|
+
name: "final_norm_output",
|
|
72
|
+
tensor: e
|
|
73
|
+
})) : e.dispose();
|
|
74
|
+
let u = s ? r(l) : l;
|
|
75
|
+
return s && l !== u && l.dispose(), u;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
project(t) {
|
|
79
|
+
return e(() => this.wte.project(t));
|
|
80
|
+
}
|
|
81
|
+
dispose() {
|
|
82
|
+
this.weightStore.dispose(), this.wte.dispose(), this.wpe && this.wpe.dispose(), this.blocks.forEach((e) => e.dispose()), this.lnF.dispose();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
86
|
+
export { d as default };
|
package/dist/models/factory.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import e from "./NanoGPTV1.js";
|
|
2
|
+
import t from "./NanoGPTV2.js";
|
|
3
|
+
//#region lib/models/factory.ts
|
|
4
|
+
function n(n) {
|
|
5
|
+
let r = n.modelType || "GenAI_NanoGPT_v1";
|
|
6
|
+
switch (r) {
|
|
7
|
+
case "GenAI_NanoGPT_v1": return new e(n);
|
|
8
|
+
case "GenAI_NanoGPT_v2": return new t(n);
|
|
9
|
+
default: throw Error(`Unsupported model type: ${r}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { n as default };
|
package/dist/models/model.js
CHANGED
|
@@ -1,2 +1,76 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import e from "../layers/BaseLayer.js";
|
|
2
|
+
import { estimateParameterCount as t } from "../utilities/parameters.js";
|
|
3
|
+
import n from "../layers/LoRA.js";
|
|
4
|
+
//#region lib/models/model.ts
|
|
5
|
+
var r = class extends e {
|
|
6
|
+
lossScaling = 128;
|
|
7
|
+
trainingState = null;
|
|
8
|
+
metaData = {
|
|
9
|
+
version: 2,
|
|
10
|
+
application: "@genai-fi/nanogpt"
|
|
11
|
+
};
|
|
12
|
+
loraLayer;
|
|
13
|
+
loraMap = /* @__PURE__ */ new Map();
|
|
14
|
+
constructor(e) {
|
|
15
|
+
super(e), e.loraConfig && e.loraConfig.forEach((e, t) => {
|
|
16
|
+
this.createLoRA(t, e);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
createLoRA(e, t) {
|
|
20
|
+
if (this.loraMap.has(e)) return;
|
|
21
|
+
let r = new n(e, this.weightStore, t.alpha, t.rank, t.variables);
|
|
22
|
+
this.loraMap.set(e, r), this.config.loraConfig = this.config.loraConfig || /* @__PURE__ */ new Map(), this.config.loraConfig.set(e, t);
|
|
23
|
+
}
|
|
24
|
+
deleteLoRA(e) {
|
|
25
|
+
let t = this.loraMap.get(e);
|
|
26
|
+
if (!t) throw Error(`No LoRA with name ${e} exists.`);
|
|
27
|
+
this.loraLayer === t && this.detachLoRA(), t.dispose(), this.loraMap.delete(e), this.config.loraConfig && this.config.loraConfig.delete(e);
|
|
28
|
+
}
|
|
29
|
+
renameLoRA(e, t) {
|
|
30
|
+
if (!this.loraMap.has(e)) throw Error(`No LoRA with name ${e} exists.`);
|
|
31
|
+
if (this.loraMap.has(t)) throw Error(`LoRA with name ${t} already exists.`);
|
|
32
|
+
let n = this.loraMap.get(e);
|
|
33
|
+
this.loraMap.set(t, n), this.loraMap.delete(e), this.config.loraConfig && (this.config.loraConfig.delete(e), this.config.loraConfig.set(t, {
|
|
34
|
+
rank: n.rank,
|
|
35
|
+
alpha: n.alpha,
|
|
36
|
+
variables: Array.from(n.variables)
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
mergeLoRA(e) {
|
|
40
|
+
let t = this.loraMap.get(e);
|
|
41
|
+
if (!t) throw Error(`No LoRA with name ${e} exists.`);
|
|
42
|
+
t.merge(), this.deleteLoRA(e);
|
|
43
|
+
}
|
|
44
|
+
attachLoRA(e) {
|
|
45
|
+
if (this.loraLayer) {
|
|
46
|
+
if (this.loraLayer.name === e) return;
|
|
47
|
+
this.detachLoRA();
|
|
48
|
+
}
|
|
49
|
+
let t = this.loraMap.get(e);
|
|
50
|
+
if (!t) throw Error(`No LoRA with name ${e} exists.`);
|
|
51
|
+
t.attach(), this.loraLayer = t, this.config.loraName = e;
|
|
52
|
+
}
|
|
53
|
+
detachLoRA() {
|
|
54
|
+
if (!this.loraLayer) throw Error("No LoRA layer is attached to this model.");
|
|
55
|
+
this.loraLayer.detach(), this.loraLayer = void 0, this.config.loraName = void 0;
|
|
56
|
+
}
|
|
57
|
+
hasLoRA(e) {
|
|
58
|
+
return e ? this.loraMap.has(e) : !!this.loraLayer;
|
|
59
|
+
}
|
|
60
|
+
listLoRAs() {
|
|
61
|
+
return Array.from(this.loraMap.keys());
|
|
62
|
+
}
|
|
63
|
+
get lora() {
|
|
64
|
+
return this.loraLayer || null;
|
|
65
|
+
}
|
|
66
|
+
getNumParams() {
|
|
67
|
+
return t(this.config);
|
|
68
|
+
}
|
|
69
|
+
validateInput(e) {
|
|
70
|
+
if (e.shape.length !== 2) throw Error(`Invalid input shape: expected [batch_size, sequence_length], got ${e.shape}`);
|
|
71
|
+
if (e.shape[1] > this.config.blockSize) throw Error(`Input sequence length ${e.shape[1]} isn't block size ${this.config.blockSize}`);
|
|
72
|
+
if (e.dtype !== "int32") throw Error(`Input tensor must be of type int32, got ${e.dtype}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
export { r as default };
|
package/dist/models.d.ts
ADDED
package/dist/models.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { n as e } from "./chunk-CWhphoD1.js";
|
|
2
|
+
import t from "./models/model.js";
|
|
3
|
+
import n from "./models/NanoGPTV1.js";
|
|
4
|
+
import r from "./models/NanoGPTV2.js";
|
|
5
|
+
import i from "./utilities/waitForModel.js";
|
|
6
|
+
//#region lib/models.ts
|
|
7
|
+
var a = /* @__PURE__ */ e({
|
|
8
|
+
Model: () => t,
|
|
9
|
+
NanoGPTV1: () => n,
|
|
10
|
+
NanoGPTV2: () => r,
|
|
11
|
+
waitForModel: () => i
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { t as Model, n as NanoGPTV1, r as NanoGPTV2, a as t, i as waitForModel };
|
package/dist/ops/dot16.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as e } from "../tfjs_backend-
|
|
1
|
+
import { o as e } from "../tfjs_backend-h5weiy1O.js";
|
|
2
2
|
import { isPackedTensor as t } from "../utilities/packed.js";
|
|
3
3
|
import { transpose16 as n } from "./transpose16.js";
|
|
4
4
|
import { reshape16 as r } from "./reshape16.js";
|
package/dist/ops/matMulGelu.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ii as e, Tn as t, nc as n } from "../../dist-Da20xy8E.js";
|
|
2
|
-
import { t as r } from "../../Reshape-
|
|
3
|
-
import { a as i, r as a, t as o } from "../../RealDiv-
|
|
2
|
+
import { t as r } from "../../Reshape-BlylqwWy.js";
|
|
3
|
+
import { a as i, r as a, t as o } from "../../RealDiv-CSnvtN2E.js";
|
|
4
4
|
//#region lib/ops/webgl/fusedSoftmax.ts
|
|
5
5
|
var s = class {
|
|
6
6
|
variableNames = ["logits", "maxLogits"];
|
package/dist/ops/webgl/gelu.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ii as e } from "../../dist-Da20xy8E.js";
|
|
2
|
-
import {
|
|
2
|
+
import { i as t, s as n } from "../../kernel_funcs_utils-ql8Y8qPn.js";
|
|
3
3
|
//#region lib/ops/webgl/gelu.ts
|
|
4
|
-
var r = .7978845608028654, i = .044715, a =
|
|
4
|
+
var r = .7978845608028654, i = .044715, a = t({ opSnippet: n + `
|
|
5
5
|
float x3 = x * x * x;
|
|
6
6
|
float inner = x + ${i} * x3;
|
|
7
7
|
inner = ${r} * inner;
|
package/dist/ops/webgl/log.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Ii as e } from "../../dist-Da20xy8E.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { i as t, t as n } from "../../kernel_funcs_utils-ql8Y8qPn.js";
|
|
3
|
+
import { y as r } from "../../shared-CfTzpULd.js";
|
|
4
4
|
//#region lib/ops/webgl/log.ts
|
|
5
5
|
e({
|
|
6
6
|
kernelName: "Log",
|
|
7
7
|
backendName: "webgl",
|
|
8
|
-
kernelFunc:
|
|
9
|
-
opSnippet:
|
|
8
|
+
kernelFunc: t({
|
|
9
|
+
opSnippet: n + "\n return x < 0.0 ? NAN : log(x);\n",
|
|
10
10
|
packedOpSnippet: "\n vec4 result = log(x);\n bvec4 isNaN = isnan(x);\n result.r = isNaN.r ? x.r : (x.r < 0.0 ? NAN : result.r);\n result.g = isNaN.g ? x.g : (x.g < 0.0 ? NAN : result.g);\n result.b = isNaN.b ? x.b : (x.b < 0.0 ? NAN : result.b);\n result.a = isNaN.a ? x.a : (x.a < 0.0 ? NAN : result.a);\n return result;\n",
|
|
11
|
-
cpuKernelImpl:
|
|
11
|
+
cpuKernelImpl: r
|
|
12
12
|
})
|
|
13
13
|
});
|
|
14
14
|
//#endregion
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as e, r as t, t as n } from "../../matMulGelu-
|
|
1
|
+
import { n as e, r as t, t as n } from "../../matMulGelu-CBoqTZM7.js";
|
|
2
2
|
export { n as MATMUL_SHARED_DIM_THRESHOLD, e as batchMatMulGeluImpl, t as batchMatMulKernel };
|
|
@@ -74,11 +74,20 @@ function ie({ a: e, b: t, transposeA: n = !1, transposeB: i = !1, bias: a, activ
|
|
|
74
74
|
};
|
|
75
75
|
})(D, k, A);
|
|
76
76
|
}
|
|
77
|
-
var L = /* @__PURE__ */ k({ fusedMatMul_: ie }), ae =
|
|
77
|
+
var L = /* @__PURE__ */ k({ fusedMatMul_: ie }), ae = ["channelsFirst", "channelsLast"], oe = ["nearest", "bilinear"], se = [
|
|
78
|
+
"valid",
|
|
79
|
+
"same",
|
|
80
|
+
"causal"
|
|
81
|
+
], ce = ["max", "avg"], le = [
|
|
82
|
+
"sum",
|
|
83
|
+
"mul",
|
|
84
|
+
"concat",
|
|
85
|
+
"ave"
|
|
86
|
+
], ue = class e extends Error {
|
|
78
87
|
constructor(t) {
|
|
79
88
|
super(t), Object.setPrototypeOf(this, e.prototype);
|
|
80
89
|
}
|
|
81
|
-
},
|
|
90
|
+
}, de = class e extends Error {
|
|
82
91
|
constructor(t) {
|
|
83
92
|
super(t), Object.setPrototypeOf(this, e.prototype);
|
|
84
93
|
}
|
|
@@ -90,14 +99,14 @@ var L = /* @__PURE__ */ k({ fusedMatMul_: ie }), ae = class e extends Error {
|
|
|
90
99
|
constructor(t) {
|
|
91
100
|
super(t), Object.setPrototypeOf(this, e.prototype);
|
|
92
101
|
}
|
|
93
|
-
},
|
|
102
|
+
}, fe = class e extends Error {
|
|
94
103
|
constructor(t) {
|
|
95
104
|
super(t), Object.setPrototypeOf(this, e.prototype);
|
|
96
105
|
}
|
|
97
106
|
};
|
|
98
107
|
//#endregion
|
|
99
108
|
//#region node_modules/@tensorflow/tfjs-layers/dist/utils/generic_utils.js
|
|
100
|
-
function
|
|
109
|
+
function pe(e, t) {
|
|
101
110
|
if (Array.isArray(e)) {
|
|
102
111
|
let n = [];
|
|
103
112
|
for (let r = 0; r < t; r++) n = n.concat(e);
|
|
@@ -108,28 +117,28 @@ function ce(e, t) {
|
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
function B(e, t) {
|
|
111
|
-
if (!e) throw new
|
|
120
|
+
if (!e) throw new fe(t);
|
|
112
121
|
}
|
|
113
|
-
function
|
|
122
|
+
function me(e, t) {
|
|
114
123
|
let n = 0;
|
|
115
124
|
for (let r of e) r === t && n++;
|
|
116
125
|
return n;
|
|
117
126
|
}
|
|
118
|
-
function
|
|
127
|
+
function he(e) {
|
|
119
128
|
return e.length === 1 ? e[0] : e;
|
|
120
129
|
}
|
|
121
|
-
function
|
|
130
|
+
function ge(e) {
|
|
122
131
|
return Array.isArray(e) ? e : [e];
|
|
123
132
|
}
|
|
124
|
-
function
|
|
133
|
+
function _e(e) {
|
|
125
134
|
let t = e.replace(/(.)([A-Z][a-z0-9]+)/g, "$1_$2").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
126
135
|
return t[0] === "_" ? "private" + t : t;
|
|
127
136
|
}
|
|
128
|
-
function
|
|
137
|
+
function ve(e) {
|
|
129
138
|
return e.length <= 1 || e.indexOf("_") === -1 ? e : e.replace(/[_]+(\w|$)/g, (e, t) => t.toUpperCase());
|
|
130
139
|
}
|
|
131
140
|
var V = {};
|
|
132
|
-
function
|
|
141
|
+
function ye(e) {
|
|
133
142
|
if (e == null) return null;
|
|
134
143
|
let t = {};
|
|
135
144
|
return t.className = e.getClassName(), t.config = e.getConfig(), t;
|
|
@@ -144,7 +153,7 @@ function H(e) {
|
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
|
-
function
|
|
156
|
+
function be(e, t = {}, n = {}, r = "object", i = !1) {
|
|
148
157
|
if (typeof e == "string") {
|
|
149
158
|
let i = e, a;
|
|
150
159
|
if (i in n) a = n[i];
|
|
@@ -175,19 +184,19 @@ function he(e, t = {}, n = {}, r = "object", i = !1) {
|
|
|
175
184
|
}
|
|
176
185
|
}
|
|
177
186
|
}
|
|
178
|
-
function
|
|
187
|
+
function xe(e, t) {
|
|
179
188
|
return e < t ? -1 : +(e > t);
|
|
180
189
|
}
|
|
181
|
-
function
|
|
182
|
-
return -1 *
|
|
190
|
+
function Se(e, t) {
|
|
191
|
+
return -1 * xe(e, t);
|
|
183
192
|
}
|
|
184
|
-
function
|
|
193
|
+
function Ce(e) {
|
|
185
194
|
if (e == null) return e;
|
|
186
195
|
let t = [];
|
|
187
196
|
for (let n of e) t.indexOf(n) === -1 && t.push(n);
|
|
188
197
|
return t;
|
|
189
198
|
}
|
|
190
|
-
function
|
|
199
|
+
function we(e) {
|
|
191
200
|
if (e == null) throw new R(`Invalid value in obj: ${JSON.stringify(e)}`);
|
|
192
201
|
for (let t in e) if (e.hasOwnProperty(t)) return !1;
|
|
193
202
|
return !0;
|
|
@@ -195,7 +204,7 @@ function ye(e) {
|
|
|
195
204
|
function U(e, t, n) {
|
|
196
205
|
if (n != null && e.indexOf(n) < 0) throw new R(`${n} is not a valid ${t}. Valid values are ${e} or null/undefined.`);
|
|
197
206
|
}
|
|
198
|
-
function
|
|
207
|
+
function Te(e, t, n = 0, r = Infinity) {
|
|
199
208
|
return B(n >= 0), B(r >= n), Array.isArray(e) && e.length >= n && e.length <= r && e.every((e) => typeof e === t);
|
|
200
209
|
}
|
|
201
210
|
function W(e, t) {
|
|
@@ -204,39 +213,30 @@ function W(e, t) {
|
|
|
204
213
|
function G(e) {
|
|
205
214
|
return e === null ? "null" : Array.isArray(e) ? "[" + e.map((e) => G(e)).join(",") + "]" : typeof e == "string" ? `"${e}"` : `${e}`;
|
|
206
215
|
}
|
|
207
|
-
function
|
|
216
|
+
function Ee(e, t, n) {
|
|
208
217
|
let r = n == null ? a() : n(), i;
|
|
209
218
|
return (...o) => {
|
|
210
219
|
let s = n == null ? a() : n();
|
|
211
220
|
return s - r < t ? i : (r = s, i = e(...o), i);
|
|
212
221
|
};
|
|
213
222
|
}
|
|
214
|
-
function
|
|
223
|
+
function De(e) {
|
|
215
224
|
return e === "relu" ? "relu" : e === "linear" ? "linear" : e === "elu" ? "elu" : null;
|
|
216
225
|
}
|
|
217
226
|
//#endregion
|
|
218
|
-
//#region node_modules/@tensorflow/tfjs-layers/dist/
|
|
219
|
-
var
|
|
220
|
-
"valid",
|
|
221
|
-
"same",
|
|
222
|
-
"causal"
|
|
223
|
-
], Ee = ["max", "avg"], De = [
|
|
224
|
-
"sum",
|
|
225
|
-
"mul",
|
|
226
|
-
"concat",
|
|
227
|
-
"ave"
|
|
228
|
-
], K = /* @__PURE__ */ new Map();
|
|
227
|
+
//#region node_modules/@tensorflow/tfjs-layers/dist/common.js
|
|
228
|
+
var K = /* @__PURE__ */ new Map();
|
|
229
229
|
function q(e) {
|
|
230
|
-
U(
|
|
230
|
+
U(ae, "DataFormat", e);
|
|
231
231
|
}
|
|
232
232
|
function Oe(e) {
|
|
233
|
-
U(
|
|
233
|
+
U(oe, "InterpolationFormat", e);
|
|
234
234
|
}
|
|
235
235
|
function ke(e) {
|
|
236
|
-
U(
|
|
236
|
+
U(se, "PaddingMode", e);
|
|
237
237
|
}
|
|
238
238
|
function Ae(e) {
|
|
239
|
-
U(
|
|
239
|
+
U(ce, "PoolMode", e);
|
|
240
240
|
}
|
|
241
241
|
var J = [], je = "/";
|
|
242
242
|
function Me(e, t) {
|
|
@@ -611,4 +611,4 @@ function ct(e, t, n = !1) {
|
|
|
611
611
|
return n ? e() : t();
|
|
612
612
|
}
|
|
613
613
|
//#endregion
|
|
614
|
-
export {
|
|
614
|
+
export { z as $, ke as A, Ee as B, Y as C, Ve as D, ze as E, B as F, Se as G, we as H, W as I, ve as J, ye as K, Te as L, Pe as M, Fe as N, q as O, Me as P, ue as Q, U as R, X as S, Be as T, De as U, be as V, pe as W, _e as X, ge as Y, Ce as Z, Z as _, Xe as a, Qe as b, it as c, tt as d, de as et, st as f, Ye as g, Ke as h, Ze as i, Ae as j, Oe as k, Ge as l, $e as m, rt as n, le as nt, et as o, ct as p, he as q, We as r, ot as s, Je as t, R as tt, qe as u, at as v, Re as w, Ue as x, nt as y, me as z };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as CharTokeniser } from './tokeniser/CharTokeniser';
|
|
2
|
+
export { default as BPETokeniser } from './tokeniser/bpe';
|
|
3
|
+
export { tokensFromStreams } from './training/tasks/tokenStream';
|
|
4
|
+
export { TokenStore, createTokenStore } from './training/tasks/TokenStore';
|
package/dist/tokenise.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { n as e } from "./chunk-CWhphoD1.js";
|
|
2
|
+
import t from "./tokeniser/CharTokeniser.js";
|
|
3
|
+
import n from "./tokeniser/bpe.js";
|
|
4
|
+
import { TokenStore as r, createTokenStore as i } from "./training/tasks/TokenStore.js";
|
|
5
|
+
import { tokensFromStreams as a } from "./training/tasks/tokenStream.js";
|
|
6
|
+
//#region lib/tokenise.ts
|
|
7
|
+
var o = /* @__PURE__ */ e({
|
|
8
|
+
BPETokeniser: () => n,
|
|
9
|
+
CharTokeniser: () => t,
|
|
10
|
+
TokenStore: () => r,
|
|
11
|
+
createTokenStore: () => i,
|
|
12
|
+
tokensFromStreams: () => a
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
export { n as BPETokeniser, t as CharTokeniser, r as TokenStore, i as createTokenStore, o as t, a as tokensFromStreams };
|
|
@@ -8,6 +8,7 @@ export default class BasicTrainer {
|
|
|
8
8
|
tokenizer: ITokeniser;
|
|
9
9
|
model: Model<ModelForwardAttributes>;
|
|
10
10
|
optimizer: AdamWOptimizer;
|
|
11
|
+
log: TrainingLogEntry[];
|
|
11
12
|
protected running: boolean;
|
|
12
13
|
protected lastState?: TrainingState;
|
|
13
14
|
protected _gradientCheckpointing: boolean;
|
|
@@ -18,6 +19,7 @@ export default class BasicTrainer {
|
|
|
18
19
|
protected _labelSmoothing: number;
|
|
19
20
|
protected _layerDrop: number;
|
|
20
21
|
protected _dropout: number;
|
|
22
|
+
protected _tokensProcessed: number;
|
|
21
23
|
constructor(model: Model<ModelForwardAttributes>, tokenizer: ITokeniser, optConfig?: Partial<AdamWOptimizerConfig>, optimizer?: AdamWOptimizer);
|
|
22
24
|
setLossMasking(): void;
|
|
23
25
|
setGradientCheckpointing(enabled: boolean): void;
|
|
@@ -27,9 +29,11 @@ export default class BasicTrainer {
|
|
|
27
29
|
setLayerDrop(layerDrop: number): void;
|
|
28
30
|
setLearningRate(learningRate: number): void;
|
|
29
31
|
setMetrics(metrics: TrainingMetrics[]): void;
|
|
32
|
+
configure(options: TrainingOptions): void;
|
|
30
33
|
reset(): void;
|
|
31
34
|
stop(): void;
|
|
32
35
|
get isRunning(): boolean;
|
|
36
|
+
get tokensProcessed(): number;
|
|
33
37
|
getOptimizer(): AdamWOptimizer;
|
|
34
38
|
updateOptimizer(config?: Partial<AdamWOptimizerConfig>): void;
|
|
35
39
|
resumeFromLog(log: TrainingLogEntry): void;
|
|
@@ -40,15 +44,6 @@ export default class BasicTrainer {
|
|
|
40
44
|
private dummyPass;
|
|
41
45
|
dispose(): void;
|
|
42
46
|
private createEmptyState;
|
|
43
|
-
stepDataset(dataset: Dataset<{
|
|
44
|
-
xs: Tensor;
|
|
45
|
-
ys: Tensor;
|
|
46
|
-
}>, options: Partial<TrainingOptions>, validationDataset?: Dataset<{
|
|
47
|
-
xs: Tensor;
|
|
48
|
-
ys: Tensor;
|
|
49
|
-
}>): Promise<{
|
|
50
|
-
log: TrainingLogEntry;
|
|
51
|
-
}>;
|
|
52
47
|
private performLogging;
|
|
53
48
|
trainOnDataset(dataset: Dataset<{
|
|
54
49
|
xs: Tensor;
|
|
@@ -56,7 +51,7 @@ export default class BasicTrainer {
|
|
|
56
51
|
}>, options: Partial<TrainingOptions>, validationDataset?: Dataset<{
|
|
57
52
|
xs: Tensor;
|
|
58
53
|
ys: Tensor;
|
|
59
|
-
}
|
|
54
|
+
}>, onStep?: (log: TrainingLogEntry) => void): Promise<{
|
|
60
55
|
losses: number[];
|
|
61
56
|
validationLosses: number[];
|
|
62
57
|
}>;
|