@genai-fi/nanogpt 1.1.2 → 1.1.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/training/BasicTrainer.js +14 -12
- package/package.json +1 -1
|
@@ -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:
|
|
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 =
|
|
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,
|
|
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
|
|
234
|
-
if (
|
|
235
|
-
let n = e.value, r =
|
|
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
|
|
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
|
|
243
|
-
|
|
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
|
|
251
|
+
let _ = Date.now();
|
|
250
252
|
return this.model.metaData.actionLog.push({
|
|
251
253
|
action: "pretrain",
|
|
252
|
-
timestamp:
|
|
253
|
-
duration:
|
|
254
|
+
timestamp: _,
|
|
255
|
+
duration: _ - d,
|
|
254
256
|
tokensProcessed: this.tokensProcessed,
|
|
255
257
|
options: t
|
|
256
258
|
}), {
|