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