@genai-fi/nanogpt 0.20.5 → 0.20.7
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 +1 -1
- package/dist/TeachableLLM.js +1 -1
- package/dist/Trainer.js +1 -1
- package/dist/checks/rope.js +5 -5
- package/dist/loader/load.js +1 -1
- package/dist/loader/loadHF.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/newZipLoad.js +1 -1
- package/dist/loader/oldZipLoad.js +1 -1
- package/dist/loader/save.js +1 -1
- package/dist/{main-PgJdpFTC.js → main-BTmbwF1h.js} +23 -21
- package/dist/main.js +1 -1
- package/dist/models/NanoGPTV1.js +1 -1
- package/dist/models/NanoGPTV2.js +1 -1
- package/dist/models/factory.js +1 -1
- package/dist/models/model.js +1 -1
- package/dist/ops/webgl/adamMoments.js +2 -2
- package/dist/ops/webgl/matMul16.js +7 -3
- package/dist/ops/webgpu/matMul16.js +7 -3
- package/dist/ops/webgpu/normRMS.js +1 -1
- package/dist/training/BasicTrainer.js +1 -1
- package/dist/training/validation.js +1 -1
- package/dist/utilities/arrayClose.d.ts +1 -0
- package/dist/utilities/arrayClose.js +13 -1
- package/package.json +1 -1
package/dist/Generator.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as e, s as t } from "./main-
|
|
1
|
+
import { c as e, s as t } from "./main-BTmbwF1h.js";
|
|
2
2
|
export { t as default, e as isConversation };
|
package/dist/TeachableLLM.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as e } from "./main-
|
|
1
|
+
import { i as e } from "./main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
package/dist/Trainer.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e } from "./main-
|
|
1
|
+
import { a as e } from "./main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
package/dist/checks/rope.js
CHANGED
|
@@ -19,11 +19,11 @@ async function i(i) {
|
|
|
19
19
|
useRope: !0
|
|
20
20
|
});
|
|
21
21
|
o.ensureRopeCache(120);
|
|
22
|
-
let s = t().runKernel("Rope", {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
let s = t().runKernel("Rope", { x: a }, {
|
|
23
|
+
pastLen: 20,
|
|
24
|
+
ropeCache: o,
|
|
25
|
+
negSin: !1
|
|
26
|
+
});
|
|
27
27
|
return Array.isArray(s) ? s.map((e) => e.array()) : s.array();
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
package/dist/loader/load.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { d as e, u as t } from "../main-
|
|
1
|
+
import { d as e, u as t } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { t as VERSION, e as loadModel };
|
package/dist/loader/loadHF.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { f as e } from "../main-
|
|
1
|
+
import { f as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { h as e, m as t } from "../main-
|
|
1
|
+
import { h as e, m as t } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { t as default, e as mapTransformersConfigToGPTConfig };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { p as e } from "../main-
|
|
1
|
+
import { p as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { g as e } from "../main-
|
|
1
|
+
import { g as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
package/dist/loader/save.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { l as e } from "../main-
|
|
1
|
+
import { l as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as saveModel };
|
|
@@ -12829,7 +12829,7 @@ var bS = class extends hc {
|
|
|
12829
12829
|
}
|
|
12830
12830
|
async tokenisePrompt(e, t, n) {
|
|
12831
12831
|
if (t) {
|
|
12832
|
-
let r = t.length > 0 && t[t.length - 1].role === "
|
|
12832
|
+
let r = t.length > 0 && t[t.length - 1].role === "text", i = [];
|
|
12833
12833
|
return i = n?.nonConversational ? r && n?.continuation ? [e.bosToken, ...e.encode(t[t.length - 1].content)] : e.encodeAsSequence(t, !0) : e.encodeConversation(t, !0), i.length > this.model.config.blockSize && (i = i.slice(-this.model.config.blockSize)), ce([i], [1, i.length], "int32");
|
|
12834
12834
|
} else {
|
|
12835
12835
|
let t = n?.nonConversational ? void 0 : e.getSpecialTokenIndex("<|assistant_start|>"), r = t === void 0 ? [e.bosToken] : [e.bosToken, t];
|
|
@@ -12947,32 +12947,32 @@ var bS = class extends hc {
|
|
|
12947
12947
|
multinomialRand: p
|
|
12948
12948
|
};
|
|
12949
12949
|
}
|
|
12950
|
-
async _generate(e) {
|
|
12951
|
-
let
|
|
12952
|
-
this.outputConversation.length === 0 || this.outputConversation[this.outputConversation.length - 1]._completed || this.outputConversation[this.outputConversation.length - 1].role !== "assistant" ? (this.outputConversation.push({
|
|
12953
|
-
role: "assistant",
|
|
12950
|
+
async _generate(e, t) {
|
|
12951
|
+
let n = !1;
|
|
12952
|
+
this.outputConversation.length === 0 || this.outputConversation[this.outputConversation.length - 1]._completed || this.outputConversation[this.outputConversation.length - 1].role !== "assistant" && e?.nonConversational !== !0 || this.outputConversation[this.outputConversation.length - 1].role !== "text" && e?.nonConversational === !0 ? (this.outputConversation.push({
|
|
12953
|
+
role: e?.nonConversational === !0 ? "text" : "assistant",
|
|
12954
12954
|
content: "",
|
|
12955
12955
|
_timestamp: Date.now()
|
|
12956
|
-
}),
|
|
12957
|
-
let
|
|
12958
|
-
for (let t = 0; t <
|
|
12959
|
-
let { output:
|
|
12956
|
+
}), n = !0, this.resetCache(!e?.noCache)) : (this.lastToken < 0 || t) && this.resetCache(!e?.noCache);
|
|
12957
|
+
let r = this.lastToken >= 0 && this.cache ? ce([this.lastToken], [1, 1], "int32") : await this.tokenisePrompt(this.actualTokeniser, t ? n ? this.outputConversation.slice(0, -1) : this.outputConversation : void 0, e), i = e?.maxLength ?? 1e3;
|
|
12958
|
+
for (let t = 0; t < i && this.active; t++) {
|
|
12959
|
+
let { output: n, probabilities: a, attention: o, loss: s, multinomialRand: c } = await this._generateToken(r, this.cache ? this.cache : void 0, {
|
|
12960
12960
|
...e,
|
|
12961
12961
|
usePadding: !this.cache
|
|
12962
12962
|
});
|
|
12963
|
-
if (this.lastMultinomialRand = c, s !== void 0 && (this.lastLoss = s), this.cache)
|
|
12963
|
+
if (this.lastMultinomialRand = c, s !== void 0 && (this.lastLoss = s), this.cache) r.dispose(), r = n;
|
|
12964
12964
|
else {
|
|
12965
|
-
let e =
|
|
12966
|
-
|
|
12965
|
+
let e = r;
|
|
12966
|
+
r = kt([r, n], 1), e.dispose();
|
|
12967
12967
|
}
|
|
12968
|
-
let l = await this.processResponse(this.actualTokeniser,
|
|
12969
|
-
if (this.cache ||
|
|
12968
|
+
let l = await this.processResponse(this.actualTokeniser, n, e?.allowSpecial ?? !1, o, a);
|
|
12969
|
+
if (this.cache || n.dispose(), l === null) {
|
|
12970
12970
|
this.outputConversation[this.outputConversation.length - 1]._completed = !0;
|
|
12971
12971
|
break;
|
|
12972
12972
|
}
|
|
12973
|
-
t ===
|
|
12973
|
+
t === i - 1 && i > 1 && (this.outputConversation[this.outputConversation.length - 1]._completed = !0), this.outputConversation[this.outputConversation.length - 1].content += l;
|
|
12974
12974
|
}
|
|
12975
|
-
return
|
|
12975
|
+
return r.dispose(), this.outputConversation;
|
|
12976
12976
|
}
|
|
12977
12977
|
resetCache(e) {
|
|
12978
12978
|
this.cache && (this.cache.forEach((e) => {
|
|
@@ -13036,7 +13036,7 @@ var bS = class extends hc {
|
|
|
13036
13036
|
}
|
|
13037
13037
|
async startJob(e, t) {
|
|
13038
13038
|
this.initialise(e, t), this.active = !0, this.model.metaData.generationSettings = t, t?.maxLength !== 1 && this.emit("start");
|
|
13039
|
-
let n = await this._generate(t);
|
|
13039
|
+
let n = await this._generate(t, !!e);
|
|
13040
13040
|
if (this.active = !1, this.startTime !== null) {
|
|
13041
13041
|
let e = Date.now(), n = e - this.startTime;
|
|
13042
13042
|
this.startTime = null, this.model.metaData.actionLog = this.model.metaData.actionLog || [], this.model.metaData.actionLog.push({
|
|
@@ -13163,13 +13163,15 @@ var DS = class e extends hc {
|
|
|
13163
13163
|
}
|
|
13164
13164
|
if (!n) throw Error("Tokeniser must be provided when initializing Trainer with a model");
|
|
13165
13165
|
if (!t) throw Error("Model must be provided when initializing Trainer");
|
|
13166
|
-
|
|
13166
|
+
this.options = i || {
|
|
13167
13167
|
batchSize: 32,
|
|
13168
13168
|
sftMode: "full"
|
|
13169
|
-
}
|
|
13170
|
-
|
|
13169
|
+
};
|
|
13170
|
+
let o = this.options.mixedPrecision && tc();
|
|
13171
|
+
if (this.options.lossScaling = o ? t.lossScaling : 1, r === "sft") {
|
|
13172
|
+
let e = new Ac(t, n, this.options, a);
|
|
13171
13173
|
this.trainer = e, e.loraName = i?.loraName;
|
|
13172
|
-
} else this.trainer = new kc(t, n,
|
|
13174
|
+
} else this.trainer = new kc(t, n, this.options, a);
|
|
13173
13175
|
this.trainingType = r || "pretraining", this.tokenizer = n;
|
|
13174
13176
|
}
|
|
13175
13177
|
get model() {
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, b as t, i as n, n as r, r as i, s as a, t as o, y as s } from "./main-
|
|
1
|
+
import { a as e, b as t, i as n, n as r, r as i, s as a, t as o, y as s } from "./main-BTmbwF1h.js";
|
|
2
2
|
import c from "./tokeniser/CharTokeniser.js";
|
|
3
3
|
import l from "./tokeniser/bpe.js";
|
|
4
4
|
import { AdamWOptimizer as u } from "./training/AdamW.js";
|
package/dist/models/NanoGPTV1.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { y as e } from "../main-
|
|
1
|
+
import { y as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
package/dist/models/NanoGPTV2.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { v as e } from "../main-
|
|
1
|
+
import { v as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
package/dist/models/factory.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as e } from "../main-
|
|
1
|
+
import { _ as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
package/dist/models/model.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { b as e } from "../main-
|
|
1
|
+
import { b as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as default };
|
|
@@ -19,8 +19,8 @@ var t = class {
|
|
|
19
19
|
float m = getMomentsAtOutCoords();
|
|
20
20
|
${n} coords = getOutputCoords();
|
|
21
21
|
|
|
22
|
-
// Add
|
|
23
|
-
float g =
|
|
22
|
+
// TODO: Add scaling
|
|
23
|
+
float g = getGradient(${i});
|
|
24
24
|
int which = ${r};
|
|
25
25
|
|
|
26
26
|
float beta = which == 0 ? beta1 : beta2;
|
|
@@ -7,12 +7,16 @@ function d(e) {
|
|
|
7
7
|
let { A: d, B: f } = e.inputs, { transposeA: p, transposeB: m, scale: h, activation: g, scaleA: _, scaleB: v, forceOutputShape: y, perm: b } = e.attrs, x = !c(d), S = !c(f);
|
|
8
8
|
if (x && S) {
|
|
9
9
|
let e = _ === void 0 ? d : t(d, n(_)), c = v === void 0 ? f : t(f, n(v)), x;
|
|
10
|
-
if (
|
|
11
|
-
else if (g === "gelu") x = u(e, c);
|
|
10
|
+
if (g === "gelu") x = u(e, c);
|
|
12
11
|
else if (g === "relu2") {
|
|
13
12
|
let t = i(e, c, p, m), n = o(t);
|
|
14
13
|
t.dispose(), x = a(n), n.dispose();
|
|
15
|
-
} else
|
|
14
|
+
} else if (g === "relu") {
|
|
15
|
+
if (x = o(i(e, c, p, m)), h !== void 0) {
|
|
16
|
+
let e = t(x, n(h));
|
|
17
|
+
x.dispose(), x = e;
|
|
18
|
+
}
|
|
19
|
+
} else x = h === void 0 ? i(e, c, p, m) : l(e, c, n(h), p, m);
|
|
16
20
|
if (b) if (y) {
|
|
17
21
|
let e = r(x, y);
|
|
18
22
|
x.dispose();
|
|
@@ -11,12 +11,16 @@ function h(e) {
|
|
|
11
11
|
let e = x === void 0 ? h : n(h, r(x)), t = S === void 0 ? g : n(g, r(S));
|
|
12
12
|
if (T) throw Error("Causal mask is not supported for unpacked MatMul16.");
|
|
13
13
|
let c;
|
|
14
|
-
if (
|
|
15
|
-
else if (b === "gelu") c = p(e, t);
|
|
14
|
+
if (b === "gelu") c = p(e, t);
|
|
16
15
|
else if (b === "relu2") {
|
|
17
16
|
let n = a(e, t, _, v), r = s(n);
|
|
18
17
|
n.dispose(), c = o(r), r.dispose();
|
|
19
|
-
} else
|
|
18
|
+
} else if (b === "relu") {
|
|
19
|
+
if (c = s(a(e, t, _, v)), y !== void 0) {
|
|
20
|
+
let e = n(c, r(y));
|
|
21
|
+
c.dispose(), c = e;
|
|
22
|
+
}
|
|
23
|
+
} else c = y === void 0 ? a(e, t, _, v) : f(e, t, r(y), _, v);
|
|
20
24
|
if (w) if (C) {
|
|
21
25
|
let e = i(c, C);
|
|
22
26
|
c.dispose();
|
|
@@ -7,7 +7,7 @@ import s from "./normRMS32_program.js";
|
|
|
7
7
|
import c from "./normRMS16_program.js";
|
|
8
8
|
//#region lib/ops/webgpu/normRMS.ts
|
|
9
9
|
function l(t) {
|
|
10
|
-
let { x: l, gamma: u } = t.inputs, d = t.backend, f = o(d), p = n(l), m = u ? n(u) : !1, h = p || m, g = !h ||
|
|
10
|
+
let { x: l, gamma: u } = t.inputs, d = t.backend, f = o(d), p = n(l), m = u ? n(u) : !1, h = p || m, g = !h || p ? l : r(l), _ = u && (!h || m ? u : r(u)), v = _ ? [g, _] : [g], y = i(v, -1), b = h ? new c(f, y, !!u) : new s(f, y, !!u);
|
|
11
11
|
if (_ && e(_.shape, [g.shape[g.shape.length - 1]], "Error in RMSNorm: "), l.shape.length !== 3) throw Error(`rmsNormGPU: input rank ${l.shape.length} not supported, only rank 3 is supported`);
|
|
12
12
|
if (y.inSize !== g.shape[g.shape.length - 1]) throw Error(`rmsNormGPU: reduction size ${y.inSize} does not match expected size ${g.shape[g.shape.length - 1]}`);
|
|
13
13
|
if (y.batchSize !== l.shape[0] * l.shape[1]) throw Error(`rmsNormGPU: batch size ${y.batchSize} does not match expected size ${l.shape[0] * l.shape[1]}`);
|
|
@@ -39,7 +39,7 @@ var f = {
|
|
|
39
39
|
this.tokenizer = t, this.model = e, this.optimizerConfig = {
|
|
40
40
|
...p,
|
|
41
41
|
...n,
|
|
42
|
-
lossScaling: e.lossScaling
|
|
42
|
+
lossScaling: n?.lossScaling ?? e.lossScaling
|
|
43
43
|
};
|
|
44
44
|
let i = r || new o(this.optimizerConfig);
|
|
45
45
|
r && r.updateConfig(this.optimizerConfig), this.optimizer = i;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { o as e } from "../main-
|
|
1
|
+
import { o as e } from "../main-BTmbwF1h.js";
|
|
2
2
|
export { e as createTrainValidationSplit };
|
|
@@ -12,5 +12,17 @@ function e(t, n) {
|
|
|
12
12
|
return r = Math.max(r, e), r;
|
|
13
13
|
} else return Infinity;
|
|
14
14
|
}
|
|
15
|
+
function t(e, t, n = .99) {
|
|
16
|
+
let r = [];
|
|
17
|
+
function i(e, t) {
|
|
18
|
+
if ((Array.isArray(e) || e instanceof Float32Array) && (Array.isArray(t) || t instanceof Float32Array)) {
|
|
19
|
+
if (e.length !== t.length) return !1;
|
|
20
|
+
for (let n = 0; n < e.length; n++) if (!i(e[n], t[n])) return !1;
|
|
21
|
+
return !0;
|
|
22
|
+
}
|
|
23
|
+
return typeof e == "number" && typeof t == "number" ? Number.isNaN(e) && Number.isNaN(t) ? (r.push(0), !0) : !Number.isFinite(e) || !Number.isFinite(t) ? e === t : (r.push(Math.abs(e - t)), !0) : !1;
|
|
24
|
+
}
|
|
25
|
+
return !i(e, t) || r.length === 0 ? Infinity : (r.sort((e, t) => e - t), r[Math.min(r.length - 1, Math.floor(n * r.length))]);
|
|
26
|
+
}
|
|
15
27
|
//#endregion
|
|
16
|
-
export { e as arraysClose };
|
|
28
|
+
export { e as arraysClose, t as arraysClosePercentile };
|