@genai-fi/nanogpt 1.1.2 → 1.1.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.
@@ -56,13 +56,16 @@ var r = class {
56
56
  role: t.nonConversational ? "text" : "user",
57
57
  content: t.input
58
58
  }], s) : i.generate(s);
59
- if (t.background) return c.then(() => {
60
- o.done = !0, this._hookedResponses.delete(e), this._resumeWaiters.delete(e), a && i.off("tokens", a), this.ee.emit("done", e), this._processNextJob();
61
- }), {
62
- output: null,
63
- id: e,
64
- done: !1
65
- };
59
+ if (t.background) {
60
+ let t = {
61
+ output: null,
62
+ id: e,
63
+ done: !1
64
+ };
65
+ return c.then((n) => {
66
+ o.done = !0, t.done = !0, t.output = n, this._hookedResponses.delete(e), this._resumeWaiters.delete(e), a && i.off("tokens", a), this.ee.emit("done", e), this._processNextJob();
67
+ }), t;
68
+ }
66
69
  let l = await c;
67
70
  return a && i.off("tokens", a), o.done = !0, this._hookedResponses.delete(e), this._resumeWaiters.delete(e), this.ee.emit("done", e), this._processNextJob(), {
68
71
  output: l,
@@ -7,7 +7,7 @@ import { createTensorStatistics as d } from "../checks/weights.js";
7
7
  import f from "./configure.js";
8
8
  //#region lib/training/BasicTrainer.ts
9
9
  var p = {
10
- logInterval: 1,
10
+ logInterval: 200,
11
11
  maxEpochs: 100,
12
12
  method: { type: "pretraining" },
13
13
  batchSize: 32
@@ -212,7 +212,7 @@ var p = {
212
212
  this.log.push(p), r && r(p), a.logStartTime = Date.now();
213
213
  }
214
214
  async trainOnDataset(e, t, n, i) {
215
- let { logInterval: a = 10, maxEpochs: o = Infinity } = {
215
+ let { logInterval: a = 40, maxEpochs: o = Infinity } = {
216
216
  ...p,
217
217
  ...t
218
218
  };
@@ -227,30 +227,32 @@ var p = {
227
227
  await this.dummyPass(), t?.metrics?.includes("memoryUsage") && (this.model.getProfiler() || this.model.setProfiler(new s()));
228
228
  let d = Date.now();
229
229
  this.running = !0, l.logStartTime = d;
230
- let f = n ? new u(this.model, n, this.maskedLoss) : void 0, m = await e.iterator(), h = m.next();
230
+ let f = d, m = n ? new u(this.model, n, this.maskedLoss) : void 0, h = await e.iterator(), g = h.next();
231
231
  try {
232
232
  for (; this.running;) {
233
- let e = await h;
234
- if (h = m.next(), e.done) break;
235
- let n = e.value, r = l.step % a === 0, o = (t?.metrics?.includes("gradientStatistics") || !1) && r, s = this.trainStep(l, n, !1, o);
233
+ let e = await g;
234
+ if (g = h.next(), e.done) break;
235
+ let n = e.value, r = Date.now(), o = r - f >= a;
236
+ o && (f = r);
237
+ let s = (t?.metrics?.includes("gradientStatistics") || !1) && o, u = this.trainStep(l, n, !1, s);
236
238
  if (t.debug) {
237
- let e = (await s.data())[0];
239
+ let e = (await u.data())[0];
238
240
  if (isNaN(e) || !isFinite(e)) throw console.error("Invalid loss value:", e), console.error("Batch xs:", await n.xs.array()), console.error("Batch ys:", await n.ys.array()), console.error("State:", l), Error("Loss is NaN or Infinity");
239
241
  console.log(`Step ${l.step}: Loss = ${e}`);
240
242
  }
241
243
  n.xs.dispose(), n.ys.dispose(), l.step++, l.totalSteps++;
242
- let u = l.step >= c;
243
- r || u ? await this.performLogging(s, n.xs.shape[0], f, i) : (l.gradientNorm &&= (l.gradientNorm.dispose(), void 0), l.accuracy &&= (l.accuracy.dispose(), void 0)), s.dispose(), u && this.stop();
244
+ let d = l.step >= c;
245
+ o || d ? await this.performLogging(u, n.xs.shape[0], m, i) : (l.gradientNorm &&= (l.gradientNorm.dispose(), void 0), l.accuracy &&= (l.accuracy.dispose(), void 0)), u.dispose(), d && this.stop();
244
246
  }
245
247
  } catch (e) {
246
248
  throw console.error("Training error:", e), r(), e;
247
249
  }
248
250
  r(), this.running = !1, this.model.metaData.actionLog = this.model.metaData.actionLog || [];
249
- let g = Date.now();
251
+ let _ = Date.now();
250
252
  return this.model.metaData.actionLog.push({
251
253
  action: "pretrain",
252
- timestamp: g,
253
- duration: g - d,
254
+ timestamp: _,
255
+ duration: _ - d,
254
256
  tokensProcessed: this.tokensProcessed,
255
257
  options: t
256
258
  }), {
@@ -5,17 +5,16 @@ import { createTrainValidationDatasets as r, storeFromArray as i } from "./valid
5
5
  //#region lib/training/prepareData.ts
6
6
  async function a(a, o, s, c, l, u, d) {
7
7
  let f = a.loraName || a.loraConfig;
8
- if (d && f) throw Error("Cannot specify datasets when using LoRA fine-tuning");
9
8
  if (!d && !f) throw Error("Must specify datasets for non-LoRA training");
10
9
  if (d) {
11
10
  let e = !1;
12
11
  for (let t of d) t.conversational && (e = !0);
13
- o.metaData.pretrainingData = d.map((e) => ({
12
+ f || (o.metaData.pretrainingData = d.map((e) => ({
14
13
  id: e.id,
15
14
  name: e.name,
16
15
  conversational: e.conversational,
17
16
  url: e.url
18
- })), e ? o.metaData.mode = "conversational" : o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
17
+ }))), e ? o.metaData.mode = "conversational" : o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
19
18
  } else o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
20
19
  let p = a.maskedLoss ?? a.method.type === "supervised", m, h = u;
21
20
  if (Array.isArray(c)) if (c[0] instanceof Uint16Array) m = c;
@@ -27,6 +26,7 @@ async function a(a, o, s, c, l, u, d) {
27
26
  m = e.trainingTokens, u || (h = e.validationTokens);
28
27
  }
29
28
  else m = c;
29
+ console.log("Training tokens", m);
30
30
  let g = m instanceof e ? m.getTokenCount() : m.reduce((e, t) => e + t.length, 0);
31
31
  a.epochSteps = Math.max(1, Math.floor(g / ((a?.batchSize || 32) * o.config.blockSize)));
32
32
  let _ = new n(s, o.config.blockSize);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",