@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.
Files changed (50) hide show
  1. package/dist/{DatasetBuilder-B9UGNQT5.js → DatasetBuilder-Ctb425Id.js} +111 -111
  2. package/dist/Generator.js +1 -1
  3. package/dist/TeachableLLM.d.ts +2 -1
  4. package/dist/TeachableLLM.js +1 -1
  5. package/dist/Trainer.d.ts +1 -1
  6. package/dist/Trainer.js +1 -1
  7. package/dist/data/stream.d.ts +24 -0
  8. package/dist/data/stream.js +2 -0
  9. package/dist/data/textLoader.d.ts +2 -2
  10. package/dist/data/textLoader.js +28 -67
  11. package/dist/loader/load.js +1 -1
  12. package/dist/loader/loadHF.js +1 -1
  13. package/dist/loader/loadTransformers.js +1 -1
  14. package/dist/loader/newZipLoad.js +1 -1
  15. package/dist/loader/oldZipLoad.js +1 -1
  16. package/dist/loader/save.js +1 -1
  17. package/dist/{main-DdsoTJAW.js → main-Bgc7_9kb.js} +18 -17
  18. package/dist/main.d.ts +3 -0
  19. package/dist/main.js +13 -11
  20. package/dist/models/NanoGPTV1.js +1 -1
  21. package/dist/models/NanoGPTV2.js +1 -1
  22. package/dist/models/factory.js +1 -1
  23. package/dist/models/model.js +1 -1
  24. package/dist/stream-DKl3GTDL.js +2287 -0
  25. package/dist/tokeniser/BaseTokeniser.d.ts +2 -1
  26. package/dist/tokeniser/CharTokeniser.d.ts +2 -2
  27. package/dist/tokeniser/CharTokeniser.js +7 -11
  28. package/dist/tokeniser/bpe.d.ts +2 -2
  29. package/dist/tokeniser/bpe.js +18 -27
  30. package/dist/tokeniser/type.d.ts +3 -2
  31. package/dist/training/DatasetBuilder.d.ts +1 -1
  32. package/dist/training/DatasetBuilder.js +1 -1
  33. package/dist/training/PreTrainer.js +1 -1
  34. package/dist/training/SFTTrainer.js +1 -1
  35. package/dist/training/tasks/ConversationTask.d.ts +9 -10
  36. package/dist/training/tasks/ConversationTask.js +15 -24
  37. package/dist/training/tasks/PretrainingTask.d.ts +4 -4
  38. package/dist/training/tasks/PretrainingTask.js +2 -2
  39. package/dist/training/tasks/StartSentenceTask.d.ts +4 -4
  40. package/dist/training/tasks/StartSentenceTask.js +3 -3
  41. package/dist/training/tasks/Task.d.ts +9 -11
  42. package/dist/training/tasks/Task.js +14 -27
  43. package/dist/training/tasks/splitter.d.ts +2 -2
  44. package/dist/training/tasks/splitter.js +11 -11
  45. package/dist/training/validation.d.ts +1 -1
  46. package/dist/training/validation.js +1 -1
  47. package/dist/utilities/tokens.d.ts +2 -0
  48. package/dist/utilities/tokens.js +40 -0
  49. package/dist/utilities/topP.js +6 -0
  50. 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 m = /* @__PURE__ */ e(u());
5
- function h(e, t) {
6
- return g(e, t);
5
+ var g = /* @__PURE__ */ e(u());
6
+ function ee(e, t) {
7
+ return _(e, t);
7
8
  }
8
- function g(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
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 (b(e)) {
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] = g(o, t, n, r);
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 _(e, t = y) {
27
- return v(e, t);
27
+ function v(e, t = b) {
28
+ return y(e, t);
28
29
  }
29
- function v(e, t, n = /* @__PURE__ */ new Set()) {
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 (b(r)) {
36
+ if (x(r)) {
36
37
  let i = Array.isArray(r) ? [] : {};
37
38
  n.add(r);
38
- for (let a in r) i[a] = v(e.map((e) => e[a]), t, n);
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 y(e) {
43
- return e === null ? null : b(e[0]) ? {
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 b(e) {
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
- } : b(e) ? {
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 T = class {
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
- }, E = class e extends T {
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
- E.INITIAL_CAPACITY = 32;
160
+ D.INITIAL_CAPACITY = 32;
160
161
  //#endregion
161
162
  //#region node_modules/@tensorflow/tfjs-data/dist/iterators/lazy_iterator.js
162
- function ee(e) {
163
- return new A(e);
163
+ function O(e) {
164
+ return new M(e);
164
165
  }
165
- function D(e) {
166
- return new j(e);
166
+ function k(e) {
167
+ return new N(e);
167
168
  }
168
- function O(e, t) {
169
- return new H(e, t);
169
+ function A(e, t) {
170
+ return new W(e, t);
170
171
  }
171
- var k = class {
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 R(this, e);
192
+ return new B(this, e);
192
193
  }
193
194
  filter(e) {
194
- return new I(this, e);
195
+ return new R(this, e);
195
196
  }
196
197
  map(e) {
197
- return new L(this, e);
198
+ return new z(this, e);
198
199
  }
199
200
  mapAsync(e) {
200
- return new z(this, e);
201
+ return new V(this, e);
201
202
  }
202
203
  serialMapAsync(e) {
203
- return new z(this, e).serial();
204
+ return new V(this, e).serial();
204
205
  }
205
206
  flatmap(e) {
206
- return new V(this, e);
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 F(this, e, t);
216
+ return new L(this, e, t);
216
217
  }
217
- columnMajorBatch(e, t = !0, n = y) {
218
- return this.rowMajorBatch(e, t).map((e) => _(e, n));
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 H(ee([this, e]), t);
222
+ return new W(O([this, e]), t);
222
223
  }
223
224
  take(e) {
224
- return e < 0 || e == null ? this : new P(this, e);
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 N(this, e);
228
+ return e < 0 || e == null ? this : new F(this, e);
228
229
  }
229
230
  prefetch(e) {
230
- return new W(this, e);
231
+ return new K(this, e);
231
232
  }
232
233
  shuffle(e, t) {
233
- return new G(this, e, t);
234
+ return new q(this, e, t);
234
235
  }
235
236
  serial() {
236
- return new M(this);
237
+ return new P(this);
237
238
  }
238
- }, A = class extends k {
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: C(e),
253
+ value: w(e),
253
254
  done: !1
254
255
  };
255
256
  }
256
- }, j = class extends k {
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
- }, M = class extends k {
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
- }, N = class extends k {
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
- }, P = class extends k {
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
- }, F = class extends k {
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
- }, I = class extends k {
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
- }, L = class extends k {
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
- }, R = class extends k {
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
- }, z = class extends k {
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
- }, B = class extends k {
435
+ }, H = class extends j {
435
436
  constructor() {
436
- super(), this.outputQueue = new E(), this.lastRead = Promise.resolve({
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
- }, V = class extends B {
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
- }, H = class extends k {
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
- }, U;
492
+ }, G;
492
493
  (function(e) {
493
494
  e[e.FAIL = 0] = "FAIL", e[e.SHORTEST = 1] = "SHORTEST", e[e.LONGEST = 2] = "LONGEST";
494
- })(U ||= {});
495
- var W = class extends k {
495
+ })(G ||= {});
496
+ var K = class extends j {
496
497
  constructor(e, t) {
497
- super(), this.upstream = e, this.bufferSize = t, this.buffer = new T(t);
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
- }, G = class extends W {
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 = m.alea(r || t().toString()), this.lastRead = Promise.resolve({
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
- }, K = class {
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), q(async () => (await n.iterator()).columnMajorBatch(e, t, J), i);
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, q(async () => (await t.iterator()).concatenate(await e.iterator()), n);
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, q(async () => (await t.iterator()).filter((t) => s(() => e(t))), n);
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 q(async () => (await t.iterator()).map((t) => s(() => e(t))), this.size);
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 q(async () => (await t.iterator()).mapAsync(e), this.size);
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 q(async () => (await t.iterator()).prefetch(e), this.size);
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, q(async () => O(D(async () => ({
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, q(async () => (await t.iterator()).skip(e), 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, 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 = m.alea(n || t().toString());
587
- return q(async () => {
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, q(async () => (await t.iterator()).take(e), n);
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
- K.MAX_BUFFER_SIZE = 1e4;
606
- function q(e, t = null) {
607
- return new class extends K {
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 J(e) {
617
+ function X(e) {
617
618
  if (e === null) return null;
618
619
  let t = e[0];
619
- return x(t) ? {
620
- value: Y(e),
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 Y(e) {
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 X(e) {
634
- return q(async () => {
634
+ function Q(e) {
635
+ return Y(async () => {
635
636
  let t = await e();
636
- return D(() => t.next());
637
+ return k(() => t.next());
637
638
  });
638
639
  }
639
640
  //#endregion
640
641
  //#region lib/training/DatasetBuilder.ts
641
- function Z(e, t) {
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 Q(e, t) {
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 te = class {
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
- if (e.length < this.blockSize + 1) throw Error(`Not enough tokens (${e.length}) for block size ${this.blockSize}`);
669
- let a = Math.ceil(e.length / this.blockSize), o = {
670
- shuffledIndexes: new Uint32Array(a),
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) o.shuffledIndexes = n;
673
+ if (n) c.shuffledIndexes = n;
674
674
  else {
675
- o.shuffledIndexes = new Uint32Array(a);
676
- for (let e = 0; e < a; e++) o.shuffledIndexes[e] = 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: X(function* () {
679
+ dataset: Q(function* () {
680
680
  for (;;) {
681
- let t = o.shuffledIndexes[o.step++] * this.blockSize;
682
- if (o.step >= o.shuffledIndexes.length && (o.step = 0, $(o.shuffledIndexes)), t + this.blockSize + 1 > e.length) continue;
683
- let n = new Int32Array(e.subarray(t, t + this.blockSize)), a = e.subarray(t + 1, t + this.blockSize + 1), s = new Int32Array(a);
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 n = 0; n < s.length; n++) r[t + 1 + n] === 0 && (s[n] = i, e++);
687
- if (e === s.length) continue;
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: s
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: o
701
+ state: c
702
702
  };
703
703
  }
704
704
  };
705
705
  //#endregion
706
- export { $ as i, Z as n, Q as r, te as t };
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-DdsoTJAW.js";
1
+ import { c as e, s as t } from "./main-Bgc7_9kb.js";
2
2
  export { t as default, e as isConversation };
@@ -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: Conversation[][]): Promise<number>;
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[]>;
@@ -1,2 +1,2 @@
1
- import { i as e } from "./main-DdsoTJAW.js";
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-DdsoTJAW.js";
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 {};
@@ -0,0 +1,2 @@
1
+ import { n as e, r as t, t as n } from "../stream-DKl3GTDL.js";
2
+ export { n as JSONLConversationStream, e as MemoryConversationStream, t as ZipJSONLConversationStream };
@@ -1,7 +1,7 @@
1
- import { Conversation } from '../tokeniser/type';
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, cb?: (progress: number) => void): Promise<Conversation[][]>;
7
+ export default function loadTextData(file: File, options?: DataOptions): Promise<ConversationStream>;