@genai-fi/nanogpt 0.20.4 → 0.20.6

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 CHANGED
@@ -1,2 +1,2 @@
1
- import { c as e, s as t } from "./main-BqRjvJ8B.js";
1
+ import { c as e, s as t } from "./main-C0YUnw98.js";
2
2
  export { t as default, e as isConversation };
@@ -1,2 +1,2 @@
1
- import { i as e } from "./main-BqRjvJ8B.js";
1
+ import { i as e } from "./main-C0YUnw98.js";
2
2
  export { e as default };
package/dist/Trainer.d.ts CHANGED
@@ -27,6 +27,7 @@ export default class Trainer extends EE<'start' | 'stop' | 'log'> {
27
27
  constructor(trainer: Trainer, options?: TrainingOptions);
28
28
  get model(): Model<ModelForwardAttributes>;
29
29
  get optimizer(): AdamWOptimizer;
30
+ get isTraining(): boolean;
30
31
  stop(): void;
31
32
  reset(): void;
32
33
  dispose(): void;
package/dist/Trainer.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e } from "./main-BqRjvJ8B.js";
1
+ import { a as e } from "./main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { d as e, u as t } from "../main-BqRjvJ8B.js";
1
+ import { d as e, u as t } from "../main-C0YUnw98.js";
2
2
  export { t as VERSION, e as loadModel };
@@ -1,2 +1,2 @@
1
- import { f as e } from "../main-BqRjvJ8B.js";
1
+ import { f as e } from "../main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { h as e, m as t } from "../main-BqRjvJ8B.js";
1
+ import { h as e, m as t } from "../main-C0YUnw98.js";
2
2
  export { t as default, e as mapTransformersConfigToGPTConfig };
@@ -1,2 +1,2 @@
1
- import { p as e } from "../main-BqRjvJ8B.js";
1
+ import { p as e } from "../main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { g as e } from "../main-BqRjvJ8B.js";
1
+ import { g as e } from "../main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { l as e } from "../main-BqRjvJ8B.js";
1
+ import { l as e } from "../main-C0YUnw98.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 === "assistant", i = [];
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 t = !1;
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
- }), t = !0, this.resetCache(!e?.noCache)) : this.lastToken < 0 && this.resetCache(!e?.noCache);
12957
- let n = this.lastToken >= 0 && this.cache ? ce([this.lastToken], [1, 1], "int32") : await this.tokenisePrompt(this.actualTokeniser, t ? this.outputConversation.slice(0, -1) : this.outputConversation, e), r = e?.maxLength ?? 1e3;
12958
- for (let t = 0; t < r && this.active; t++) {
12959
- let { output: i, probabilities: a, attention: o, loss: s, multinomialRand: c } = await this._generateToken(n, this.cache ? this.cache : void 0, {
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) n.dispose(), n = i;
12963
+ if (this.lastMultinomialRand = c, s !== void 0 && (this.lastLoss = s), this.cache) r.dispose(), r = n;
12964
12964
  else {
12965
- let e = n;
12966
- n = kt([n, i], 1), e.dispose();
12965
+ let e = r;
12966
+ r = kt([r, n], 1), e.dispose();
12967
12967
  }
12968
- let l = await this.processResponse(this.actualTokeniser, i, e?.allowSpecial ?? !1, o, a);
12969
- if (this.cache || i.dispose(), l === null) {
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 === r - 1 && r > 1 && (this.outputConversation[this.outputConversation.length - 1]._completed = !0), this.outputConversation[this.outputConversation.length - 1].content += l;
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 n.dispose(), this.outputConversation;
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({
@@ -13178,6 +13178,9 @@ var DS = class e extends hc {
13178
13178
  get optimizer() {
13179
13179
  return this.trainer.optimizer;
13180
13180
  }
13181
+ get isTraining() {
13182
+ return this.trainer.isRunning;
13183
+ }
13181
13184
  stop() {
13182
13185
  this.trainer.stop();
13183
13186
  }
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-BqRjvJ8B.js";
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-C0YUnw98.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";
@@ -1,2 +1,2 @@
1
- import { y as e } from "../main-BqRjvJ8B.js";
1
+ import { y as e } from "../main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { v as e } from "../main-BqRjvJ8B.js";
1
+ import { v as e } from "../main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { _ as e } from "../main-BqRjvJ8B.js";
1
+ import { _ as e } from "../main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { b as e } from "../main-BqRjvJ8B.js";
1
+ import { b as e } from "../main-C0YUnw98.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { o as e } from "../main-BqRjvJ8B.js";
1
+ import { o as e } from "../main-C0YUnw98.js";
2
2
  export { e as createTrainValidationSplit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "0.20.4",
3
+ "version": "0.20.6",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",