@genai-fi/nanogpt 0.17.1 → 0.17.3
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.d.ts +4 -0
- package/dist/Generator.js +28 -22
- package/dist/TeachableLLM.d.ts +2 -2
- package/package.json +1 -1
package/dist/Generator.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Conversation, ITokeniser } from './tokeniser/type';
|
|
2
2
|
import { default as EE } from 'eventemitter3';
|
|
3
3
|
import { default as Model, ModelForwardAttributes } from './models/model';
|
|
4
|
+
export interface GeneratorConversation extends Conversation {
|
|
5
|
+
_completed?: boolean;
|
|
6
|
+
_timestamp?: number;
|
|
7
|
+
}
|
|
4
8
|
export interface GenerateOptions {
|
|
5
9
|
temperature?: number;
|
|
6
10
|
topK?: number;
|
package/dist/Generator.js
CHANGED
|
@@ -11701,7 +11701,7 @@ class AS extends Ui {
|
|
|
11701
11701
|
if (e) {
|
|
11702
11702
|
const s = e.length > 0 && e[e.length - 1].role === "assistant";
|
|
11703
11703
|
let o = [];
|
|
11704
|
-
return n?.nonConversational ? s && n?.continuation ? o = t.encode(e[e.length - 1].content) : o = t.encodeAsSequence(e, !0) : o = t.encodeConversation(e, !0), o.length > this.model.config.blockSize && (o = o.slice(-this.model.config.blockSize)), Kt([o], [1, o.length], "int32");
|
|
11704
|
+
return n?.nonConversational ? s && n?.continuation ? o = [t.bosToken, ...t.encode(e[e.length - 1].content)] : o = t.encodeAsSequence(e, !0) : o = t.encodeConversation(e, !0), o.length > this.model.config.blockSize && (o = o.slice(-this.model.config.blockSize)), Kt([o], [1, o.length], "int32");
|
|
11705
11705
|
} else {
|
|
11706
11706
|
const s = n?.nonConversational ? void 0 : t.getSpecialTokenIndex("<|assistant_start|>"), o = s !== void 0 ? [t.bosToken, s] : [t.bosToken];
|
|
11707
11707
|
return Kt([o], [1, o.length], "int32");
|
|
@@ -11804,40 +11804,46 @@ class AS extends Ui {
|
|
|
11804
11804
|
}
|
|
11805
11805
|
/** Generate multiple tokens in a loop and produce text */
|
|
11806
11806
|
async _generate(t) {
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11810
|
-
|
|
11807
|
+
let e = !1;
|
|
11808
|
+
//this.lastToken < 0 ||
|
|
11809
|
+
this.outputConversation.length === 0 || this.outputConversation[this.outputConversation.length - 1]._completed || this.outputConversation[this.outputConversation.length - 1].role !== "assistant" ? (this.outputConversation.push({ role: "assistant", content: "", _timestamp: Date.now() }), e = !0, this.resetCache(!t?.noCache)) : this.lastToken < 0 && this.resetCache(!t?.noCache);
|
|
11810
|
+
let n = this.lastToken >= 0 && this.cache ? Kt([this.lastToken], [1, 1], "int32") : await this.tokenisePrompt(
|
|
11811
|
+
this.actualTokeniser,
|
|
11812
|
+
e ? this.outputConversation.slice(0, -1) : this.outputConversation,
|
|
11813
|
+
t
|
|
11814
|
+
);
|
|
11815
|
+
const s = t?.maxLength ?? 1e3;
|
|
11816
|
+
for (let o = 0; o < s && this.active; o++) {
|
|
11811
11817
|
const {
|
|
11812
|
-
output:
|
|
11813
|
-
probabilities:
|
|
11814
|
-
attention:
|
|
11815
|
-
loss:
|
|
11816
|
-
multinomialRand:
|
|
11817
|
-
} = await this._generateToken(
|
|
11818
|
+
output: r,
|
|
11819
|
+
probabilities: c,
|
|
11820
|
+
attention: i,
|
|
11821
|
+
loss: l,
|
|
11822
|
+
multinomialRand: u
|
|
11823
|
+
} = await this._generateToken(n, this.cache ? this.cache : void 0, {
|
|
11818
11824
|
...t,
|
|
11819
11825
|
usePadding: !this.cache
|
|
11820
11826
|
});
|
|
11821
|
-
if (this.lastMultinomialRand =
|
|
11822
|
-
|
|
11827
|
+
if (this.lastMultinomialRand = u, l !== void 0 && (this.lastLoss = l), this.cache)
|
|
11828
|
+
n.dispose(), n = r;
|
|
11823
11829
|
else {
|
|
11824
|
-
const
|
|
11825
|
-
|
|
11830
|
+
const d = n;
|
|
11831
|
+
n = Gd([n, r], 1), d.dispose();
|
|
11826
11832
|
}
|
|
11827
|
-
const
|
|
11833
|
+
const p = await this.processResponse(
|
|
11828
11834
|
this.actualTokeniser,
|
|
11829
|
-
|
|
11835
|
+
r,
|
|
11830
11836
|
t?.allowSpecial ?? !1,
|
|
11831
|
-
|
|
11832
|
-
|
|
11837
|
+
i,
|
|
11838
|
+
c
|
|
11833
11839
|
);
|
|
11834
|
-
if (this.cache ||
|
|
11840
|
+
if (this.cache || r.dispose(), p === null) {
|
|
11835
11841
|
this.outputConversation[this.outputConversation.length - 1]._completed = !0;
|
|
11836
11842
|
break;
|
|
11837
11843
|
}
|
|
11838
|
-
this.outputConversation[this.outputConversation.length - 1].content +=
|
|
11844
|
+
o === s - 1 && (this.outputConversation[this.outputConversation.length - 1]._completed = !0), this.outputConversation[this.outputConversation.length - 1].content += p;
|
|
11839
11845
|
}
|
|
11840
|
-
return
|
|
11846
|
+
return n.dispose(), this.outputConversation;
|
|
11841
11847
|
}
|
|
11842
11848
|
resetCache(t) {
|
|
11843
11849
|
this.cache && (this.cache.forEach((e) => {
|
package/dist/TeachableLLM.d.ts
CHANGED
|
@@ -65,11 +65,11 @@ export default class TeachableLLM {
|
|
|
65
65
|
on(event: 'phase', listener: (phase: ModelPhase) => void): void;
|
|
66
66
|
on(event: 'error', listener: (error: Error) => void): void;
|
|
67
67
|
on(event: 'trainStep', listener: (step: TrainingLogEntry) => void): void;
|
|
68
|
-
on(event: 'loaded', listener: () => void): void;
|
|
68
|
+
on(event: 'loaded' | 'changeLoRA', listener: () => void): void;
|
|
69
69
|
off(event: 'status', listener: (status: TeachableLLMStatus) => void): void;
|
|
70
70
|
off(event: 'phase', listener: (phase: ModelPhase) => void): void;
|
|
71
71
|
off(event: 'error', listener: (error: Error) => void): void;
|
|
72
72
|
off(event: 'trainStep', listener: (step: TrainingLogEntry) => void): void;
|
|
73
|
-
off(event: 'loaded', listener: () => void): void;
|
|
73
|
+
off(event: 'loaded' | 'changeLoRA', listener: () => void): void;
|
|
74
74
|
}
|
|
75
75
|
export {};
|