@genai-fi/nanogpt 0.22.0 → 0.24.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/{DatasetBuilder-Ctb425Id.js → DatasetBuilder-DU1G1OKX.js} +143 -117
- package/dist/Generator.js +1 -1
- package/dist/TeachableLLM.d.ts +1 -2
- package/dist/TeachableLLM.js +1 -1
- package/dist/Trainer-Cr7csbTD.js +228 -0
- package/dist/Trainer.d.ts +3 -2
- package/dist/Trainer.js +1 -1
- package/dist/data/stream.d.ts +6 -6
- package/dist/data/stream.js +1 -1
- package/dist/data/textLoader.js +1 -1
- package/dist/{BaseTokeniser-C9TSv4th.js → eventemitter3-D_qV3Lof.js} +2 -132
- package/dist/loader/load.js +1 -1
- package/dist/loader/loadHF.js +1 -1
- package/dist/loader/loadTransformers.js +2 -2
- package/dist/loader/newZipLoad.js +1 -1
- package/dist/loader/oldZipLoad.js +1 -1
- package/dist/loader/save.js +1 -1
- package/dist/{main-Bgc7_9kb.js → main-Dz72vadm.js} +2742 -2976
- package/dist/main.d.ts +3 -10
- package/dist/main.js +12 -10
- package/dist/models/NanoGPTV1.js +1 -1
- package/dist/models/NanoGPTV2.js +1 -1
- package/dist/models/factory.js +1 -1
- package/dist/models/model.js +1 -1
- package/dist/{stream-DKl3GTDL.js → stream-BpAwcvHz.js} +563 -550
- package/dist/tokeniser/BaseTokeniser.js +135 -2
- package/dist/tokeniser/CharTokeniser.js +17 -19
- package/dist/tokeniser/bpe.js +16 -20
- package/dist/training/DatasetBuilder.d.ts +19 -3
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/PreTrainer.js +1 -1
- package/dist/training/SFTTrainer.js +1 -1
- package/dist/training/tasks/TokenStore.d.ts +47 -0
- package/dist/training/tasks/TokenStore.js +218 -0
- package/dist/training/tasks/tokenStream.d.ts +16 -0
- package/dist/training/tasks/tokenStream.js +46 -0
- package/dist/training/validation.d.ts +4 -2
- package/dist/training/validation.js +23 -2
- package/dist/utilities/random.d.ts +1 -0
- package/dist/utilities/random.js +19 -0
- package/package.json +1 -1
- package/dist/training/tasks/ConversationTask.d.ts +0 -17
- package/dist/training/tasks/ConversationTask.js +0 -29
- package/dist/training/tasks/PretrainingTask.d.ts +0 -17
- package/dist/training/tasks/PretrainingTask.js +0 -42
- package/dist/training/tasks/StartSentenceTask.d.ts +0 -18
- package/dist/training/tasks/StartSentenceTask.js +0 -45
- package/dist/training/tasks/Task.d.ts +0 -20
- package/dist/training/tasks/Task.js +0 -42
- package/dist/training/tasks/splitter.d.ts +0 -5
- package/dist/training/tasks/splitter.js +0 -18
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { i as e } from "./chunk-CWhphoD1.js";
|
|
2
2
|
import { Mi as t, Ms as n, Ps as r, V as i, Zr as a, bi as o, di as s, fi as c, ji as l, mt as u, ni as d, wi as f, yi as p } from "./dist-Da20xy8E.js";
|
|
3
|
-
import { sliceUint16Shards as m, sliceUint8Shards as h } from "./utilities/tokens.js";
|
|
4
3
|
//#region node_modules/@tensorflow/tfjs-data/dist/util/deep_map.js
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
return
|
|
4
|
+
var m = /* @__PURE__ */ e(u());
|
|
5
|
+
function h(e, t) {
|
|
6
|
+
return g(e, t);
|
|
8
7
|
}
|
|
9
|
-
function
|
|
8
|
+
function g(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
|
|
10
9
|
if (e == null) return null;
|
|
11
10
|
if (typeof Blob == "function" && e instanceof Blob) return e.slice();
|
|
12
11
|
if (r.has(e)) throw Error("Circular references are not supported.");
|
|
@@ -14,34 +13,34 @@ function _(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
|
|
|
14
13
|
let i = t(e);
|
|
15
14
|
if (i.recurse && i.value !== null) throw Error("A deep map function may not return both a value and recurse=true.");
|
|
16
15
|
if (!i.recurse) return n.set(e, i.value), i.value;
|
|
17
|
-
if (
|
|
16
|
+
if (b(e)) {
|
|
18
17
|
let i = Array.isArray(e) ? [] : {};
|
|
19
18
|
r.add(e);
|
|
20
19
|
for (let a in e) {
|
|
21
20
|
let o = e[a];
|
|
22
|
-
i[a] =
|
|
21
|
+
i[a] = g(o, t, n, r);
|
|
23
22
|
}
|
|
24
23
|
return r.delete(e), e.__proto__ && (i.__proto__ = e.__proto__), i;
|
|
25
24
|
} else throw Error(`Can't recurse into non-iterable type: ${e}`);
|
|
26
25
|
}
|
|
27
|
-
function
|
|
28
|
-
return
|
|
26
|
+
function _(e, t = y) {
|
|
27
|
+
return v(e, t);
|
|
29
28
|
}
|
|
30
|
-
function
|
|
29
|
+
function v(e, t, n = /* @__PURE__ */ new Set()) {
|
|
31
30
|
let r = e[0];
|
|
32
31
|
if (n.has(r)) throw Error("Circular references are not supported.");
|
|
33
32
|
let i = t(e);
|
|
34
33
|
if (i.recurse && i.value !== null) throw Error("A deep zip function may not return both a value and recurse=true.");
|
|
35
34
|
if (!i.recurse) return i.value;
|
|
36
|
-
if (
|
|
35
|
+
if (b(r)) {
|
|
37
36
|
let i = Array.isArray(r) ? [] : {};
|
|
38
37
|
n.add(r);
|
|
39
|
-
for (let a in r) i[a] =
|
|
38
|
+
for (let a in r) i[a] = v(e.map((e) => e[a]), t, n);
|
|
40
39
|
return n.delete(r), i;
|
|
41
40
|
} else throw Error(`Can't recurse into non-iterable type: ${r}`);
|
|
42
41
|
}
|
|
43
|
-
function
|
|
44
|
-
return e === null ? null :
|
|
42
|
+
function y(e) {
|
|
43
|
+
return e === null ? null : b(e[0]) ? {
|
|
45
44
|
value: null,
|
|
46
45
|
recurse: !0
|
|
47
46
|
} : {
|
|
@@ -49,7 +48,7 @@ function b(e) {
|
|
|
49
48
|
recurse: !1
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
|
-
function
|
|
51
|
+
function b(e) {
|
|
53
52
|
let t = !1;
|
|
54
53
|
if (n().get("IS_BROWSER")) t = e instanceof TextDecoder;
|
|
55
54
|
else {
|
|
@@ -58,22 +57,22 @@ function x(e) {
|
|
|
58
57
|
}
|
|
59
58
|
return e != null && !ArrayBuffer.isView(e) && (Array.isArray(e) || typeof e == "object" && !(e instanceof f) && !(e instanceof Promise) && !t);
|
|
60
59
|
}
|
|
61
|
-
function
|
|
62
|
-
return e == null ||
|
|
60
|
+
function x(e) {
|
|
61
|
+
return e == null || ee(e) || Array.isArray(e) || typeof e == "object" && e instanceof f || l(e);
|
|
63
62
|
}
|
|
64
|
-
function
|
|
63
|
+
function ee(e) {
|
|
65
64
|
return e === null || typeof e != "object" && typeof e != "function";
|
|
66
65
|
}
|
|
67
66
|
//#endregion
|
|
68
67
|
//#region node_modules/@tensorflow/tfjs-data/dist/util/deep_clone.js
|
|
69
|
-
function
|
|
70
|
-
return
|
|
68
|
+
function S(e) {
|
|
69
|
+
return h(e, C);
|
|
71
70
|
}
|
|
72
|
-
function
|
|
71
|
+
function C(e) {
|
|
73
72
|
return e instanceof f ? {
|
|
74
73
|
value: e.clone(),
|
|
75
74
|
recurse: !1
|
|
76
|
-
} :
|
|
75
|
+
} : b(e) ? {
|
|
77
76
|
value: null,
|
|
78
77
|
recurse: !0
|
|
79
78
|
} : {
|
|
@@ -83,7 +82,7 @@ function T(e) {
|
|
|
83
82
|
}
|
|
84
83
|
//#endregion
|
|
85
84
|
//#region node_modules/@tensorflow/tfjs-data/dist/util/ring_buffer.js
|
|
86
|
-
var
|
|
85
|
+
var w = class {
|
|
87
86
|
constructor(e) {
|
|
88
87
|
if (this.capacity = e, this.begin = 0, this.end = 0, e == null) throw RangeError("Can't create a ring buffer of unknown capacity.");
|
|
89
88
|
if (e < 1) throw RangeError("Can't create ring buffer of capacity < 1.");
|
|
@@ -138,7 +137,7 @@ var E = class {
|
|
|
138
137
|
let t = this.wrap(this.begin + e), n = this.get(t);
|
|
139
138
|
return this.set(t, this.pop()), n;
|
|
140
139
|
}
|
|
141
|
-
},
|
|
140
|
+
}, T = class e extends w {
|
|
142
141
|
constructor() {
|
|
143
142
|
super(e.INITIAL_CAPACITY);
|
|
144
143
|
}
|
|
@@ -157,19 +156,19 @@ var E = class {
|
|
|
157
156
|
this.data = t, this.capacity = e, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = n;
|
|
158
157
|
}
|
|
159
158
|
};
|
|
160
|
-
|
|
159
|
+
T.INITIAL_CAPACITY = 32;
|
|
161
160
|
//#endregion
|
|
162
161
|
//#region node_modules/@tensorflow/tfjs-data/dist/iterators/lazy_iterator.js
|
|
163
|
-
function
|
|
164
|
-
return new
|
|
162
|
+
function E(e) {
|
|
163
|
+
return new k(e);
|
|
165
164
|
}
|
|
166
|
-
function
|
|
167
|
-
return new
|
|
165
|
+
function D(e) {
|
|
166
|
+
return new A(e);
|
|
168
167
|
}
|
|
169
|
-
function
|
|
170
|
-
return new
|
|
168
|
+
function te(e, t) {
|
|
169
|
+
return new V(e, t);
|
|
171
170
|
}
|
|
172
|
-
var
|
|
171
|
+
var O = class {
|
|
173
172
|
async toArray() {
|
|
174
173
|
let e = [], t = await this.next();
|
|
175
174
|
for (; !t.done;) e.push(t.value), t = await this.next();
|
|
@@ -189,22 +188,22 @@ var j = class {
|
|
|
189
188
|
for (; !t.done && n;) t = await this.next(), n = e(t.value);
|
|
190
189
|
}
|
|
191
190
|
handleErrors(e) {
|
|
192
|
-
return new
|
|
191
|
+
return new L(this, e);
|
|
193
192
|
}
|
|
194
193
|
filter(e) {
|
|
195
|
-
return new
|
|
194
|
+
return new F(this, e);
|
|
196
195
|
}
|
|
197
196
|
map(e) {
|
|
198
|
-
return new
|
|
197
|
+
return new I(this, e);
|
|
199
198
|
}
|
|
200
199
|
mapAsync(e) {
|
|
201
|
-
return new
|
|
200
|
+
return new R(this, e);
|
|
202
201
|
}
|
|
203
202
|
serialMapAsync(e) {
|
|
204
|
-
return new
|
|
203
|
+
return new R(this, e).serial();
|
|
205
204
|
}
|
|
206
205
|
flatmap(e) {
|
|
207
|
-
return new
|
|
206
|
+
return new B(this, e);
|
|
208
207
|
}
|
|
209
208
|
async forEachAsync(e) {
|
|
210
209
|
return this.map(e).resolveFully();
|
|
@@ -213,30 +212,30 @@ var j = class {
|
|
|
213
212
|
return this.serialMapAsync(e).resolveWhile((e) => e === !0);
|
|
214
213
|
}
|
|
215
214
|
rowMajorBatch(e, t = !0) {
|
|
216
|
-
return new
|
|
215
|
+
return new P(this, e, t);
|
|
217
216
|
}
|
|
218
|
-
columnMajorBatch(e, t = !0, n =
|
|
219
|
-
return this.rowMajorBatch(e, t).map((e) =>
|
|
217
|
+
columnMajorBatch(e, t = !0, n = y) {
|
|
218
|
+
return this.rowMajorBatch(e, t).map((e) => _(e, n));
|
|
220
219
|
}
|
|
221
220
|
concatenate(e, t) {
|
|
222
|
-
return new
|
|
221
|
+
return new V(E([this, e]), t);
|
|
223
222
|
}
|
|
224
223
|
take(e) {
|
|
225
|
-
return e < 0 || e == null ? this : new
|
|
224
|
+
return e < 0 || e == null ? this : new N(this, e);
|
|
226
225
|
}
|
|
227
226
|
skip(e) {
|
|
228
|
-
return e < 0 || e == null ? this : new
|
|
227
|
+
return e < 0 || e == null ? this : new M(this, e);
|
|
229
228
|
}
|
|
230
229
|
prefetch(e) {
|
|
231
|
-
return new
|
|
230
|
+
return new U(this, e);
|
|
232
231
|
}
|
|
233
232
|
shuffle(e, t) {
|
|
234
|
-
return new
|
|
233
|
+
return new W(this, e, t);
|
|
235
234
|
}
|
|
236
235
|
serial() {
|
|
237
|
-
return new
|
|
236
|
+
return new j(this);
|
|
238
237
|
}
|
|
239
|
-
},
|
|
238
|
+
}, k = class extends O {
|
|
240
239
|
constructor(e) {
|
|
241
240
|
super(), this.items = e, this.trav = 0;
|
|
242
241
|
}
|
|
@@ -250,11 +249,11 @@ var j = class {
|
|
|
250
249
|
};
|
|
251
250
|
let e = this.items[this.trav];
|
|
252
251
|
return this.trav++, {
|
|
253
|
-
value:
|
|
252
|
+
value: S(e),
|
|
254
253
|
done: !1
|
|
255
254
|
};
|
|
256
255
|
}
|
|
257
|
-
},
|
|
256
|
+
}, A = class extends O {
|
|
258
257
|
constructor(e) {
|
|
259
258
|
super(), this.nextFn = e;
|
|
260
259
|
}
|
|
@@ -268,7 +267,7 @@ var j = class {
|
|
|
268
267
|
throw e.message = `Error thrown while iterating through a dataset: ${e.message}`, e;
|
|
269
268
|
}
|
|
270
269
|
}
|
|
271
|
-
},
|
|
270
|
+
}, j = class extends O {
|
|
272
271
|
constructor(e) {
|
|
273
272
|
super(), this.upstream = e, this.lastRead = Promise.resolve({
|
|
274
273
|
value: null,
|
|
@@ -284,7 +283,7 @@ var j = class {
|
|
|
284
283
|
async serialNext() {
|
|
285
284
|
return this.upstream.next();
|
|
286
285
|
}
|
|
287
|
-
},
|
|
286
|
+
}, M = class extends O {
|
|
288
287
|
constructor(e, t) {
|
|
289
288
|
super(), this.upstream = e, this.maxCount = t, this.count = 0, this.lastRead = Promise.resolve({
|
|
290
289
|
value: null,
|
|
@@ -305,7 +304,7 @@ var j = class {
|
|
|
305
304
|
}
|
|
306
305
|
return this.upstream.next();
|
|
307
306
|
}
|
|
308
|
-
},
|
|
307
|
+
}, N = class extends O {
|
|
309
308
|
constructor(e, t) {
|
|
310
309
|
super(), this.upstream = e, this.maxCount = t, this.count = 0;
|
|
311
310
|
}
|
|
@@ -318,7 +317,7 @@ var j = class {
|
|
|
318
317
|
done: !0
|
|
319
318
|
} : this.upstream.next();
|
|
320
319
|
}
|
|
321
|
-
},
|
|
320
|
+
}, P = class extends O {
|
|
322
321
|
constructor(e, t, n = !0) {
|
|
323
322
|
super(), this.upstream = e, this.batchSize = t, this.enableSmallLastBatch = n, this.lastRead = Promise.resolve({
|
|
324
323
|
value: null,
|
|
@@ -349,7 +348,7 @@ var j = class {
|
|
|
349
348
|
done: !1
|
|
350
349
|
};
|
|
351
350
|
}
|
|
352
|
-
},
|
|
351
|
+
}, F = class extends O {
|
|
353
352
|
constructor(e, t) {
|
|
354
353
|
super(), this.upstream = e, this.predicate = t, this.lastRead = Promise.resolve({
|
|
355
354
|
value: null,
|
|
@@ -369,7 +368,7 @@ var j = class {
|
|
|
369
368
|
d(e.value);
|
|
370
369
|
}
|
|
371
370
|
}
|
|
372
|
-
},
|
|
371
|
+
}, I = class extends O {
|
|
373
372
|
constructor(e, t) {
|
|
374
373
|
super(), this.upstream = e, this.transform = t;
|
|
375
374
|
}
|
|
@@ -389,7 +388,7 @@ var j = class {
|
|
|
389
388
|
done: !1
|
|
390
389
|
};
|
|
391
390
|
}
|
|
392
|
-
},
|
|
391
|
+
}, L = class extends O {
|
|
393
392
|
constructor(e, t) {
|
|
394
393
|
super(), this.upstream = e, this.handler = t, this.count = 0, this.lastRead = Promise.resolve({
|
|
395
394
|
value: null,
|
|
@@ -412,7 +411,7 @@ var j = class {
|
|
|
412
411
|
};
|
|
413
412
|
}
|
|
414
413
|
}
|
|
415
|
-
},
|
|
414
|
+
}, R = class extends O {
|
|
416
415
|
constructor(e, t) {
|
|
417
416
|
super(), this.upstream = e, this.transform = t;
|
|
418
417
|
}
|
|
@@ -432,9 +431,9 @@ var j = class {
|
|
|
432
431
|
done: !1
|
|
433
432
|
};
|
|
434
433
|
}
|
|
435
|
-
},
|
|
434
|
+
}, z = class extends O {
|
|
436
435
|
constructor() {
|
|
437
|
-
super(), this.outputQueue = new
|
|
436
|
+
super(), this.outputQueue = new T(), this.lastRead = Promise.resolve({
|
|
438
437
|
value: null,
|
|
439
438
|
done: !1
|
|
440
439
|
});
|
|
@@ -452,7 +451,7 @@ var j = class {
|
|
|
452
451
|
done: !1
|
|
453
452
|
};
|
|
454
453
|
}
|
|
455
|
-
},
|
|
454
|
+
}, B = class extends z {
|
|
456
455
|
constructor(e, t) {
|
|
457
456
|
super(), this.upstream = e, this.transform = t;
|
|
458
457
|
}
|
|
@@ -467,7 +466,7 @@ var j = class {
|
|
|
467
466
|
for (let e of t) o(e, r) || e.dispose();
|
|
468
467
|
return !0;
|
|
469
468
|
}
|
|
470
|
-
},
|
|
469
|
+
}, V = class extends O {
|
|
471
470
|
constructor(e, t) {
|
|
472
471
|
super(), this.baseErrorHandler = t, this.lastRead = null, this.iterator = null, this.moreIterators = e;
|
|
473
472
|
}
|
|
@@ -489,13 +488,13 @@ var j = class {
|
|
|
489
488
|
let t = await this.iterator.next();
|
|
490
489
|
return t.done ? (this.iterator = null, this.readFromChain(e)) : t;
|
|
491
490
|
}
|
|
492
|
-
},
|
|
491
|
+
}, H;
|
|
493
492
|
(function(e) {
|
|
494
493
|
e[e.FAIL = 0] = "FAIL", e[e.SHORTEST = 1] = "SHORTEST", e[e.LONGEST = 2] = "LONGEST";
|
|
495
|
-
})(
|
|
496
|
-
var
|
|
494
|
+
})(H ||= {});
|
|
495
|
+
var U = class extends O {
|
|
497
496
|
constructor(e, t) {
|
|
498
|
-
super(), this.upstream = e, this.bufferSize = t, this.buffer = new
|
|
497
|
+
super(), this.upstream = e, this.bufferSize = t, this.buffer = new w(t);
|
|
499
498
|
}
|
|
500
499
|
summary() {
|
|
501
500
|
return `${this.upstream.summary()} -> Prefetch`;
|
|
@@ -509,9 +508,9 @@ var K = class extends j {
|
|
|
509
508
|
next() {
|
|
510
509
|
return this.refill(), this.buffer.shift();
|
|
511
510
|
}
|
|
512
|
-
},
|
|
511
|
+
}, W = class extends U {
|
|
513
512
|
constructor(e, n, r) {
|
|
514
|
-
super(e, n), this.upstream = e, this.windowSize = n, this.upstreamExhausted = !1, this.random =
|
|
513
|
+
super(e, n), this.upstream = e, this.windowSize = n, this.upstreamExhausted = !1, this.random = m.alea(r || t().toString()), this.lastRead = Promise.resolve({
|
|
515
514
|
value: null,
|
|
516
515
|
done: !1
|
|
517
516
|
});
|
|
@@ -536,7 +535,7 @@ var K = class extends j {
|
|
|
536
535
|
done: !0
|
|
537
536
|
};
|
|
538
537
|
}
|
|
539
|
-
},
|
|
538
|
+
}, G = class {
|
|
540
539
|
constructor() {
|
|
541
540
|
this.size = null;
|
|
542
541
|
}
|
|
@@ -545,54 +544,54 @@ var K = class extends j {
|
|
|
545
544
|
r(e > 0, () => `batchSize needs to be positive, but it is
|
|
546
545
|
${e}`);
|
|
547
546
|
let i;
|
|
548
|
-
return i = this.size === Infinity || this.size == null ? this.size : t ? Math.ceil(this.size / e) : Math.floor(this.size / e),
|
|
547
|
+
return i = this.size === Infinity || this.size == null ? this.size : t ? Math.ceil(this.size / e) : Math.floor(this.size / e), K(async () => (await n.iterator()).columnMajorBatch(e, t, q), i);
|
|
549
548
|
}
|
|
550
549
|
concatenate(e) {
|
|
551
550
|
let t = this, n;
|
|
552
|
-
return n = this.size === Infinity || e.size === Infinity ? Infinity : this.size != null && e.size != null ? this.size + e.size : null,
|
|
551
|
+
return n = this.size === Infinity || e.size === Infinity ? Infinity : this.size != null && e.size != null ? this.size + e.size : null, K(async () => (await t.iterator()).concatenate(await e.iterator()), n);
|
|
553
552
|
}
|
|
554
553
|
filter(e) {
|
|
555
554
|
let t = this, n;
|
|
556
|
-
return n = this.size === Infinity ? Infinity : null,
|
|
555
|
+
return n = this.size === Infinity ? Infinity : null, K(async () => (await t.iterator()).filter((t) => s(() => e(t))), n);
|
|
557
556
|
}
|
|
558
557
|
async forEachAsync(e) {
|
|
559
558
|
return (await this.iterator()).forEachAsync(e);
|
|
560
559
|
}
|
|
561
560
|
map(e) {
|
|
562
561
|
let t = this;
|
|
563
|
-
return
|
|
562
|
+
return K(async () => (await t.iterator()).map((t) => s(() => e(t))), this.size);
|
|
564
563
|
}
|
|
565
564
|
mapAsync(e) {
|
|
566
565
|
let t = this;
|
|
567
|
-
return
|
|
566
|
+
return K(async () => (await t.iterator()).mapAsync(e), this.size);
|
|
568
567
|
}
|
|
569
568
|
prefetch(e) {
|
|
570
569
|
if (e == null) throw RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
|
|
571
570
|
let t = this;
|
|
572
|
-
return
|
|
571
|
+
return K(async () => (await t.iterator()).prefetch(e), this.size);
|
|
573
572
|
}
|
|
574
573
|
repeat(e) {
|
|
575
574
|
let t = this, n;
|
|
576
|
-
return n = this.size != null && e > 0 ? this.size * e : e === 0 ? 0 : this.size != null && (e === void 0 || e < 0) ? Infinity : null,
|
|
575
|
+
return n = this.size != null && e > 0 ? this.size * e : e === 0 ? 0 : this.size != null && (e === void 0 || e < 0) ? Infinity : null, K(async () => te(D(async () => ({
|
|
577
576
|
value: await t.iterator(),
|
|
578
577
|
done: !1
|
|
579
578
|
})).take(e)), n);
|
|
580
579
|
}
|
|
581
580
|
skip(e) {
|
|
582
581
|
let t = this, n;
|
|
583
|
-
return n = this.size != null && e >= 0 && this.size >= e ? this.size - e : this.size != null && (this.size < e || e === void 0 || e < 0) ? 0 : null,
|
|
582
|
+
return n = this.size != null && e >= 0 && this.size >= e ? this.size - e : this.size != null && (this.size < e || e === void 0 || e < 0) ? 0 : null, K(async () => (await t.iterator()).skip(e), n);
|
|
584
583
|
}
|
|
585
584
|
shuffle(e, n, r = !0) {
|
|
586
585
|
if (e == null || e < 0) throw this.size == null ? RangeError("`Dataset.shuffle()` requires bufferSize to be specified.") : RangeError(`\`Dataset.shuffle()\` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for \`tf.Tensor\`s), consider setting bufferSize to the dataset size (${this.size} elements)`);
|
|
587
|
-
let i = this, a =
|
|
588
|
-
return
|
|
586
|
+
let i = this, a = m.alea(n || t().toString());
|
|
587
|
+
return K(async () => {
|
|
589
588
|
let t = a.int32();
|
|
590
589
|
return r && (t += a.int32()), (await i.iterator()).shuffle(e, t.toString());
|
|
591
590
|
}, this.size);
|
|
592
591
|
}
|
|
593
592
|
take(e) {
|
|
594
593
|
let t = this, n;
|
|
595
|
-
return n = this.size != null && this.size > e ? e : this.size != null && this.size <= e ? this.size : null,
|
|
594
|
+
return n = this.size != null && this.size > e ? e : this.size != null && this.size <= e ? this.size : null, K(async () => (await t.iterator()).take(e), n);
|
|
596
595
|
}
|
|
597
596
|
async toArray() {
|
|
598
597
|
if (this.size === Infinity) throw Error("Can not convert infinite data stream to array.");
|
|
@@ -603,9 +602,9 @@ var K = class extends j {
|
|
|
603
602
|
return (await this.iterator()).toArrayForTest();
|
|
604
603
|
}
|
|
605
604
|
};
|
|
606
|
-
|
|
607
|
-
function
|
|
608
|
-
return new class extends
|
|
605
|
+
G.MAX_BUFFER_SIZE = 1e4;
|
|
606
|
+
function K(e, t = null) {
|
|
607
|
+
return new class extends G {
|
|
609
608
|
constructor() {
|
|
610
609
|
super(...arguments), this.size = t;
|
|
611
610
|
}
|
|
@@ -614,84 +613,111 @@ function Y(e, t = null) {
|
|
|
614
613
|
}
|
|
615
614
|
}();
|
|
616
615
|
}
|
|
617
|
-
function
|
|
616
|
+
function q(e) {
|
|
618
617
|
if (e === null) return null;
|
|
619
618
|
let t = e[0];
|
|
620
|
-
return
|
|
621
|
-
value:
|
|
619
|
+
return x(t) ? {
|
|
620
|
+
value: J(e),
|
|
622
621
|
recurse: !1
|
|
623
622
|
} : {
|
|
624
623
|
value: null,
|
|
625
624
|
recurse: !0
|
|
626
625
|
};
|
|
627
626
|
}
|
|
628
|
-
function
|
|
627
|
+
function J(e) {
|
|
629
628
|
if (e.length === 0) throw Error("Can't make a batch of zero elements.");
|
|
630
629
|
return e[0] instanceof f ? i(e) : c(e);
|
|
631
630
|
}
|
|
632
631
|
//#endregion
|
|
633
632
|
//#region node_modules/@tensorflow/tfjs-data/dist/readers.js
|
|
634
|
-
function
|
|
635
|
-
return
|
|
633
|
+
function Y(e) {
|
|
634
|
+
return K(async () => {
|
|
636
635
|
let t = await e();
|
|
637
|
-
return
|
|
636
|
+
return D(() => t.next());
|
|
638
637
|
});
|
|
639
638
|
}
|
|
640
639
|
//#endregion
|
|
641
640
|
//#region lib/training/DatasetBuilder.ts
|
|
642
|
-
function
|
|
641
|
+
function X(e, t) {
|
|
643
642
|
let n = e.map((e) => t.encodeConversation(e)).flat();
|
|
644
643
|
return new Uint16Array(n);
|
|
645
644
|
}
|
|
646
|
-
function
|
|
645
|
+
function Z(e, t) {
|
|
647
646
|
let n = e.map((e) => t.encodeConversation(e, !1, !0)), r = n.map((e) => e.tokens).flat(), i = n.map((e) => e.mask).flat();
|
|
648
647
|
return {
|
|
649
648
|
tokens: new Uint16Array(r),
|
|
650
649
|
mask: new Uint8Array(i.map((e) => +!!e))
|
|
651
650
|
};
|
|
652
651
|
}
|
|
653
|
-
function
|
|
652
|
+
function Q(e) {
|
|
654
653
|
for (let t = e.length - 1; t > 0; t--) {
|
|
655
654
|
let n = Math.floor(Math.random() * (t + 1));
|
|
656
655
|
[e[t], e[n]] = [e[n], e[t]];
|
|
657
656
|
}
|
|
658
657
|
return e;
|
|
659
658
|
}
|
|
660
|
-
|
|
659
|
+
async function $(e, t, n) {
|
|
660
|
+
e.step += 1;
|
|
661
|
+
let r = e.shardIndex === e.shuffledShards.length - 1 ? e.lastShardIndexes : e.shuffledIndexes;
|
|
662
|
+
if (e.step >= r.length) {
|
|
663
|
+
e.step = 0, e.shardIndex += 1, e.shardIndex >= e.shuffledShards.length && (e.shardIndex = 0, n || (Q(e.shuffledShards), Q(e.shuffledIndexes), Q(e.lastShardIndexes))), e.nextShard ? (e.currentShard = e.nextShard, e.nextShard = null) : e.currentShard = await t.getShard(e.shuffledShards[e.shardIndex]);
|
|
664
|
+
let r = (e.shardIndex + 1) % e.shuffledShards.length;
|
|
665
|
+
if (t.getShard(e.shuffledShards[r]).then((t) => {
|
|
666
|
+
e.nextShard = t;
|
|
667
|
+
}), t.hasMask()) {
|
|
668
|
+
e.nextMask ? (e.currentMask = e.nextMask, e.nextMask = null) : e.currentMask = await t.getMask(e.shuffledShards[e.shardIndex]) ?? null;
|
|
669
|
+
let n = (e.shardIndex + 1) % e.shuffledShards.length;
|
|
670
|
+
t.getMask(e.shuffledShards[n]).then((t) => {
|
|
671
|
+
e.nextMask = t ?? null;
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
var ne = class {
|
|
661
677
|
tokenizer;
|
|
662
678
|
blockSize;
|
|
663
679
|
constructor(e, t = 128) {
|
|
664
680
|
this.tokenizer = e, this.blockSize = t;
|
|
665
681
|
}
|
|
666
|
-
async createTextDataset(e, t
|
|
667
|
-
let
|
|
682
|
+
async createTextDataset(e, t) {
|
|
683
|
+
let { batchSize: n = 32, noShuffle: r = !1, ignoreIndex: i = 65535 } = t || {}, a = e.getTokenCount();
|
|
668
684
|
if (a < this.blockSize + 1) throw Error(`Not enough tokens (${a}) for block size ${this.blockSize}`);
|
|
669
|
-
let o = Math.ceil(
|
|
670
|
-
|
|
685
|
+
let o = Math.ceil(e.shardSize / this.blockSize), c = {
|
|
686
|
+
shuffledShards: new Uint16Array(e.getShardCount()),
|
|
687
|
+
shuffledIndexes: new Uint16Array(o),
|
|
688
|
+
lastShardIndexes: new Uint16Array(Math.ceil(e.getShardLength(e.getShardCount() - 1) / this.blockSize)),
|
|
689
|
+
currentMask: null,
|
|
690
|
+
nextMask: null,
|
|
691
|
+
currentShard: null,
|
|
692
|
+
nextShard: null,
|
|
693
|
+
shardIndex: 0,
|
|
671
694
|
step: 0
|
|
672
695
|
};
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
696
|
+
for (let e = 0; e < c.shuffledShards.length; e++) c.shuffledShards[e] = e;
|
|
697
|
+
for (let e = 0; e < c.shuffledIndexes.length; e++) c.shuffledIndexes[e] = e;
|
|
698
|
+
for (let e = 0; e < c.lastShardIndexes.length; e++) c.lastShardIndexes[e] = e;
|
|
699
|
+
return t?.shuffleFirst && (Q(c.shuffledShards), Q(c.shuffledIndexes), Q(c.lastShardIndexes)), c.currentShard = await e.getShard(c.shuffledShards[c.shardIndex]), c.shardIndex + 1 < c.shuffledShards.length && e.getShard(c.shuffledShards[c.shardIndex + 1]).then((e) => {
|
|
700
|
+
c.nextShard = e;
|
|
701
|
+
}), e.hasMask() && (c.currentMask = await e.getMask(c.shuffledShards[c.shardIndex]) ?? null, c.shardIndex + 1 < c.shuffledShards.length && e.getMask(c.shuffledShards[c.shardIndex + 1]).then((e) => {
|
|
702
|
+
c.nextMask = e ?? null;
|
|
703
|
+
})), {
|
|
704
|
+
dataset: Y(async function* () {
|
|
680
705
|
for (;;) {
|
|
681
|
-
let t = c.shuffledIndexes[c.step
|
|
682
|
-
if (
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
706
|
+
let t = (c.shardIndex === c.shuffledShards.length - 1 ? c.lastShardIndexes : c.shuffledIndexes)[c.step] * this.blockSize, n = c.currentShard, a = c.currentMask, o = $(c, e, r);
|
|
707
|
+
if (!n) break;
|
|
708
|
+
t + this.blockSize + 1 > n.length && (t = n.length - this.blockSize - 1);
|
|
709
|
+
let s = new Int32Array(n.slice(t, t + this.blockSize)), l = new Int32Array(n.slice(t + 1, t + this.blockSize + 1));
|
|
710
|
+
if (a) {
|
|
711
|
+
let e = 0, n = a.slice(t + 1, t + this.blockSize + 1);
|
|
712
|
+
for (let t = 0; t < l.length; t++) n[t] === 0 && (l[t] = i, e++);
|
|
713
|
+
if (e === l.length) continue;
|
|
688
714
|
}
|
|
689
715
|
yield {
|
|
690
|
-
xs:
|
|
691
|
-
ys:
|
|
692
|
-
};
|
|
716
|
+
xs: s,
|
|
717
|
+
ys: l
|
|
718
|
+
}, await o;
|
|
693
719
|
}
|
|
694
|
-
}.bind(this)).batch(
|
|
720
|
+
}.bind(this)).batch(n).map((e) => {
|
|
695
721
|
let t = e;
|
|
696
722
|
return s(() => ({
|
|
697
723
|
xs: t.xs.cast("int32"),
|
|
@@ -703,4 +729,4 @@ var re = class {
|
|
|
703
729
|
}
|
|
704
730
|
};
|
|
705
731
|
//#endregion
|
|
706
|
-
export { $ as i,
|
|
732
|
+
export { Q as a, $ as i, X as n, Z as r, ne as t };
|
package/dist/Generator.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as e, i as t } from "./main-Dz72vadm.js";
|
|
2
2
|
export { t as default, e as isConversation };
|
package/dist/TeachableLLM.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { default as Trainer, TrainingType } from './Trainer';
|
|
|
7
7
|
import { ConversationStream } from './main';
|
|
8
8
|
import { default as MemoryProfiler } from './utilities/profile';
|
|
9
9
|
import { default as Model, ModelForwardAttributes } from './models/model';
|
|
10
|
-
import { Task } from './training/tasks/Task';
|
|
11
10
|
import { TrainingLogEntry, TrainingOptions } from './training/types';
|
|
12
11
|
import { ModelMode, TransformersMetadata } from './loader/types';
|
|
13
12
|
type TeachableLLMStatus = 'warmup' | 'awaitingTokens' | 'ready' | 'training' | 'loading' | 'busy' | 'error';
|
|
@@ -51,7 +50,7 @@ export default class TeachableLLM {
|
|
|
51
50
|
set enableProfiler(value: boolean);
|
|
52
51
|
getNumParams(): number;
|
|
53
52
|
trainer(trainingType?: TrainingType, options?: TrainingOptions): Trainer;
|
|
54
|
-
train(text:
|
|
53
|
+
train(text: ConversationStream[], options?: TrainingOptions, trainingType?: TrainingType): Promise<void>;
|
|
55
54
|
trainTokeniser(text: ConversationStream[]): Promise<number>;
|
|
56
55
|
generator(): IGenerator;
|
|
57
56
|
generateText(prompt: Conversation[], options?: IGenerateOptions): Promise<Conversation[]>;
|
package/dist/TeachableLLM.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as e } from "./main-Dz72vadm.js";
|
|
2
2
|
export { e as default };
|