@genai-fi/nanogpt 1.0.3 → 1.0.4
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.
|
@@ -34,6 +34,7 @@ export default class Generator extends EE<'start' | 'stop' | 'tokens' | 'reset'>
|
|
|
34
34
|
private startTime;
|
|
35
35
|
private tokenCount;
|
|
36
36
|
constructor(model: Model<ModelForwardAttributes>, tokeniser: ITokeniser);
|
|
37
|
+
private shouldTerminate;
|
|
37
38
|
/** Generate logits and select a token. */
|
|
38
39
|
private _generateToken;
|
|
39
40
|
/** Generate multiple tokens in a loop and produce text */
|
|
@@ -40,6 +40,11 @@ var b = class extends e {
|
|
|
40
40
|
constructor(e, t) {
|
|
41
41
|
super(), this.model = e, this.tokeniser = t, this.actualTokeniser = t;
|
|
42
42
|
}
|
|
43
|
+
shouldTerminate(e, t) {
|
|
44
|
+
if (e) return !1;
|
|
45
|
+
let n = this.tokeniser.getSpecialTokenIndex("<|assistant_end|>");
|
|
46
|
+
return t === this.actualTokeniser.eosToken || t === n;
|
|
47
|
+
}
|
|
43
48
|
async _generateToken(e, t, n) {
|
|
44
49
|
let s = n?.temperature ?? 1, h = n?.topK, _ = n?.topP, v = n?.usePadding ?? !1, y = {
|
|
45
50
|
training: !1,
|
|
@@ -132,7 +137,7 @@ var b = class extends e {
|
|
|
132
137
|
S.dispose(), S = E;
|
|
133
138
|
let D = (await S.array())[0][0], O = this.actualTokeniser.decode([D]);
|
|
134
139
|
this.lastToken = D;
|
|
135
|
-
let k =
|
|
140
|
+
let k = this.shouldTerminate(n?.allowSpecial ?? !1, D), A = {
|
|
136
141
|
outputTensor: S,
|
|
137
142
|
token: D,
|
|
138
143
|
text: O,
|
package/dist/loader/types.d.ts
CHANGED
|
@@ -8,13 +8,14 @@ async function a(a, o, s, c, l, u, d) {
|
|
|
8
8
|
if (d && f) throw Error("Cannot specify datasets when using LoRA fine-tuning");
|
|
9
9
|
if (!d && !f) throw Error("Must specify datasets for non-LoRA training");
|
|
10
10
|
if (d) {
|
|
11
|
-
let e =
|
|
12
|
-
for (let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
let e = !1;
|
|
12
|
+
for (let t of d) t.conversational && (e = !0);
|
|
13
|
+
o.metaData.pretrainingData = d.map((e) => ({
|
|
14
|
+
id: e.id,
|
|
15
|
+
name: e.name,
|
|
16
|
+
conversational: e.conversational,
|
|
17
|
+
url: e.url
|
|
18
|
+
})), e ? o.metaData.mode = "conversational" : o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
|
|
18
19
|
} else o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
|
|
19
20
|
let p = a.maskedLoss ?? a.method.type === "supervised", m, h = u;
|
|
20
21
|
if (Array.isArray(c)) if (c[0] instanceof Uint16Array) m = c;
|