@genai-fi/nanogpt 1.2.5 → 1.3.0
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/api/training.js
CHANGED
|
@@ -108,7 +108,7 @@ var o = class {
|
|
|
108
108
|
return s.trainer.log = t, s.trainer.resumeFromLog(t[t.length - 1]), this._jobs.set(s.id, s), s;
|
|
109
109
|
}
|
|
110
110
|
launchJob(e) {
|
|
111
|
-
e.trainDataset && (this.setState(e, "running"), e.trainer.trainOnDataset(e.trainDataset, e.options, e.validationDataset, (t) => {
|
|
111
|
+
e.trainDataset && (this.setState(e, "running"), e.trainer.prepareToTrain(e.options), e.trainer.trainOnDataset(e.trainDataset, e.options, e.validationDataset, (t) => {
|
|
112
112
|
e.history = e.trainer.log, e.progress = t.totalTokens / e.totalTokens, e.remaining = Math.max(0, (e.totalTokens - t.totalTokens) / t.totalTokens * t.duration), e.breakOnLog.size > 0 && e.state === "running" && (this.setState(e, "pausing"), e.trainer.stop()), this.ee.emit("progress", e);
|
|
113
113
|
}).then(() => {
|
|
114
114
|
e.state === "running" ? this.setState(e, "completed") : e.state === "pausing" ? this.setState(e, "paused") : e.state === "cancelling" && this.setState(e, "cancelled");
|
|
@@ -45,6 +45,13 @@ export default class BasicTrainer {
|
|
|
45
45
|
dispose(): void;
|
|
46
46
|
private createEmptyState;
|
|
47
47
|
private performLogging;
|
|
48
|
+
/** A sync function to ensure the trainer is prepared and the state is initialized before training.
|
|
49
|
+
* It should be called before invoking trainOnDataset.
|
|
50
|
+
*/
|
|
51
|
+
prepareToTrain(options: Partial<TrainingOptions>): {
|
|
52
|
+
losses: number[];
|
|
53
|
+
validationLosses: number[];
|
|
54
|
+
} | undefined;
|
|
48
55
|
trainOnDataset(dataset: Dataset<{
|
|
49
56
|
xs: Tensor;
|
|
50
57
|
ys: Tensor;
|
|
@@ -211,22 +211,31 @@ var p = {
|
|
|
211
211
|
}
|
|
212
212
|
this.log.push(p), r && r(p), a.logStartTime = Date.now();
|
|
213
213
|
}
|
|
214
|
-
|
|
215
|
-
let {
|
|
214
|
+
prepareToTrain(e) {
|
|
215
|
+
let { maxEpochs: t = Infinity } = {
|
|
216
216
|
...p,
|
|
217
|
-
...
|
|
217
|
+
...e
|
|
218
218
|
};
|
|
219
219
|
this.log.length > 0 && this.resumeFromLog(this.log[this.log.length - 1]);
|
|
220
|
-
let
|
|
221
|
-
|
|
222
|
-
let
|
|
223
|
-
if (this.lastState =
|
|
224
|
-
losses:
|
|
225
|
-
validationLosses:
|
|
220
|
+
let n = t * (e?.epochSteps || 1e3);
|
|
221
|
+
e.metrics && this.setMetrics(e.metrics);
|
|
222
|
+
let r = this.createEmptyState();
|
|
223
|
+
if (this.lastState = r, r.step >= n) return {
|
|
224
|
+
losses: r.losses,
|
|
225
|
+
validationLosses: r.validationLosses
|
|
226
226
|
};
|
|
227
|
+
this.running = !0;
|
|
228
|
+
}
|
|
229
|
+
async trainOnDataset(e, t, n, i) {
|
|
230
|
+
let { logInterval: a = 40, maxEpochs: o = Infinity } = {
|
|
231
|
+
...p,
|
|
232
|
+
...t
|
|
233
|
+
}, c = o * (t?.epochSteps || 1e3);
|
|
227
234
|
await this.dummyPass(), t?.metrics?.includes("memoryUsage") && (this.model.getProfiler() || this.model.setProfiler(new s()));
|
|
235
|
+
let l = this.lastState;
|
|
236
|
+
if (!l) throw Error("Trainer state has not been initialized. Call prepareToTrain() first.");
|
|
228
237
|
let d = Date.now();
|
|
229
|
-
|
|
238
|
+
l.logStartTime = d;
|
|
230
239
|
let f = d, m = n ? new u(this.model, n, this.maskedLoss) : void 0, h = await e.iterator(), g = h.next();
|
|
231
240
|
try {
|
|
232
241
|
for (; this.running;) {
|