@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 = !n?.allowSpecial && this.tokeniser.isSpecialToken(D), A = {
140
+ let k = this.shouldTerminate(n?.allowSpecial ?? !1, D), A = {
136
141
  outputTensor: S,
137
142
  token: D,
138
143
  text: O,
@@ -36,6 +36,7 @@ export interface DatasetMetadata {
36
36
  id: string;
37
37
  name: string;
38
38
  conversational: boolean;
39
+ url?: string;
39
40
  }
40
41
  export interface ActionLogEntry {
41
42
  action: 'pretrain' | 'generate' | 'finetune';
@@ -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 = o.metaData.pretrainingData || [], t = [...e], n = !1;
12
- for (let r of d) e.some((e) => e.id === r.id) || t.push({
13
- id: r.id,
14
- name: r.name,
15
- conversational: r.conversational
16
- }), r.conversational && (n = !0);
17
- o.metaData.pretrainingData = t, n ? o.metaData.mode = "conversational" : o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",