@genai-fi/nanogpt 0.21.0 → 0.23.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 (55) hide show
  1. package/dist/{DatasetBuilder-B9UGNQT5.js → DatasetBuilder-C0iJT29K.js} +122 -93
  2. package/dist/Generator.js +2 -2
  3. package/dist/TeachableLLM.d.ts +2 -1
  4. package/dist/TeachableLLM.js +1 -1
  5. package/dist/Trainer-DBsyWJ4s.js +228 -0
  6. package/dist/Trainer.d.ts +2 -1
  7. package/dist/Trainer.js +1 -1
  8. package/dist/data/stream.d.ts +24 -0
  9. package/dist/data/stream.js +2 -0
  10. package/dist/data/textLoader.d.ts +2 -2
  11. package/dist/data/textLoader.js +28 -67
  12. package/dist/{BaseTokeniser-C9TSv4th.js → eventemitter3-D_qV3Lof.js} +2 -132
  13. package/dist/loader/load.js +2 -2
  14. package/dist/loader/loadHF.js +1 -1
  15. package/dist/loader/loadTransformers.js +2 -2
  16. package/dist/loader/newZipLoad.js +1 -1
  17. package/dist/loader/oldZipLoad.js +1 -1
  18. package/dist/loader/save.js +1 -1
  19. package/dist/{main-DdsoTJAW.js → main-BSaDGH7I.js} +2686 -2912
  20. package/dist/main.d.ts +4 -0
  21. package/dist/main.js +20 -16
  22. package/dist/models/NanoGPTV1.js +1 -1
  23. package/dist/models/NanoGPTV2.js +1 -1
  24. package/dist/models/factory.js +1 -1
  25. package/dist/models/model.js +1 -1
  26. package/dist/stream-BjdpSNqB.js +2296 -0
  27. package/dist/tokeniser/BaseTokeniser.d.ts +2 -1
  28. package/dist/tokeniser/BaseTokeniser.js +135 -2
  29. package/dist/tokeniser/CharTokeniser.d.ts +2 -2
  30. package/dist/tokeniser/CharTokeniser.js +10 -14
  31. package/dist/tokeniser/bpe.d.ts +2 -2
  32. package/dist/tokeniser/bpe.js +23 -32
  33. package/dist/tokeniser/type.d.ts +3 -2
  34. package/dist/training/DatasetBuilder.d.ts +17 -1
  35. package/dist/training/DatasetBuilder.js +2 -2
  36. package/dist/training/PreTrainer.js +1 -1
  37. package/dist/training/SFTTrainer.js +1 -1
  38. package/dist/training/tasks/ConversationTask.d.ts +9 -10
  39. package/dist/training/tasks/ConversationTask.js +15 -24
  40. package/dist/training/tasks/PretrainingTask.d.ts +4 -4
  41. package/dist/training/tasks/PretrainingTask.js +2 -2
  42. package/dist/training/tasks/StartSentenceTask.d.ts +4 -4
  43. package/dist/training/tasks/StartSentenceTask.js +3 -3
  44. package/dist/training/tasks/Task.d.ts +19 -12
  45. package/dist/training/tasks/Task.js +25 -30
  46. package/dist/training/tasks/TokenStore.d.ts +46 -0
  47. package/dist/training/tasks/TokenStore.js +215 -0
  48. package/dist/training/tasks/splitter.d.ts +2 -2
  49. package/dist/training/tasks/splitter.js +11 -11
  50. package/dist/training/validation.d.ts +4 -2
  51. package/dist/training/validation.js +21 -2
  52. package/dist/utilities/tokens.d.ts +2 -0
  53. package/dist/utilities/tokens.js +40 -0
  54. package/dist/utilities/topP.js +6 -0
  55. package/package.json +2 -1
@@ -66,9 +66,9 @@ function S(e) {
66
66
  //#endregion
67
67
  //#region node_modules/@tensorflow/tfjs-data/dist/util/deep_clone.js
68
68
  function C(e) {
69
- return h(e, w);
69
+ return h(e, ee);
70
70
  }
71
- function w(e) {
71
+ function ee(e) {
72
72
  return e instanceof f ? {
73
73
  value: e.clone(),
74
74
  recurse: !1
@@ -82,7 +82,7 @@ function w(e) {
82
82
  }
83
83
  //#endregion
84
84
  //#region node_modules/@tensorflow/tfjs-data/dist/util/ring_buffer.js
85
- var T = class {
85
+ var w = class {
86
86
  constructor(e) {
87
87
  if (this.capacity = e, this.begin = 0, this.end = 0, e == null) throw RangeError("Can't create a ring buffer of unknown capacity.");
88
88
  if (e < 1) throw RangeError("Can't create ring buffer of capacity < 1.");
@@ -137,7 +137,7 @@ var T = class {
137
137
  let t = this.wrap(this.begin + e), n = this.get(t);
138
138
  return this.set(t, this.pop()), n;
139
139
  }
140
- }, E = class e extends T {
140
+ }, T = class e extends w {
141
141
  constructor() {
142
142
  super(e.INITIAL_CAPACITY);
143
143
  }
@@ -156,19 +156,19 @@ var T = class {
156
156
  this.data = t, this.capacity = e, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = n;
157
157
  }
158
158
  };
159
- E.INITIAL_CAPACITY = 32;
159
+ T.INITIAL_CAPACITY = 32;
160
160
  //#endregion
161
161
  //#region node_modules/@tensorflow/tfjs-data/dist/iterators/lazy_iterator.js
162
- function ee(e) {
163
- return new A(e);
162
+ function E(e) {
163
+ return new k(e);
164
164
  }
165
165
  function D(e) {
166
- return new j(e);
166
+ return new A(e);
167
167
  }
168
- function O(e, t) {
169
- return new H(e, t);
168
+ function te(e, t) {
169
+ return new V(e, t);
170
170
  }
171
- var k = class {
171
+ var O = class {
172
172
  async toArray() {
173
173
  let e = [], t = await this.next();
174
174
  for (; !t.done;) e.push(t.value), t = await this.next();
@@ -188,22 +188,22 @@ var k = class {
188
188
  for (; !t.done && n;) t = await this.next(), n = e(t.value);
189
189
  }
190
190
  handleErrors(e) {
191
- return new R(this, e);
191
+ return new L(this, e);
192
192
  }
193
193
  filter(e) {
194
- return new I(this, e);
194
+ return new F(this, e);
195
195
  }
196
196
  map(e) {
197
- return new L(this, e);
197
+ return new I(this, e);
198
198
  }
199
199
  mapAsync(e) {
200
- return new z(this, e);
200
+ return new R(this, e);
201
201
  }
202
202
  serialMapAsync(e) {
203
- return new z(this, e).serial();
203
+ return new R(this, e).serial();
204
204
  }
205
205
  flatmap(e) {
206
- return new V(this, e);
206
+ return new B(this, e);
207
207
  }
208
208
  async forEachAsync(e) {
209
209
  return this.map(e).resolveFully();
@@ -212,30 +212,30 @@ var k = class {
212
212
  return this.serialMapAsync(e).resolveWhile((e) => e === !0);
213
213
  }
214
214
  rowMajorBatch(e, t = !0) {
215
- return new F(this, e, t);
215
+ return new P(this, e, t);
216
216
  }
217
217
  columnMajorBatch(e, t = !0, n = y) {
218
218
  return this.rowMajorBatch(e, t).map((e) => _(e, n));
219
219
  }
220
220
  concatenate(e, t) {
221
- return new H(ee([this, e]), t);
221
+ return new V(E([this, e]), t);
222
222
  }
223
223
  take(e) {
224
- return e < 0 || e == null ? this : new P(this, e);
224
+ return e < 0 || e == null ? this : new N(this, e);
225
225
  }
226
226
  skip(e) {
227
- return e < 0 || e == null ? this : new N(this, e);
227
+ return e < 0 || e == null ? this : new M(this, e);
228
228
  }
229
229
  prefetch(e) {
230
- return new W(this, e);
230
+ return new U(this, e);
231
231
  }
232
232
  shuffle(e, t) {
233
- return new G(this, e, t);
233
+ return new W(this, e, t);
234
234
  }
235
235
  serial() {
236
- return new M(this);
236
+ return new j(this);
237
237
  }
238
- }, A = class extends k {
238
+ }, k = class extends O {
239
239
  constructor(e) {
240
240
  super(), this.items = e, this.trav = 0;
241
241
  }
@@ -253,7 +253,7 @@ var k = class {
253
253
  done: !1
254
254
  };
255
255
  }
256
- }, j = class extends k {
256
+ }, A = class extends O {
257
257
  constructor(e) {
258
258
  super(), this.nextFn = e;
259
259
  }
@@ -267,7 +267,7 @@ var k = class {
267
267
  throw e.message = `Error thrown while iterating through a dataset: ${e.message}`, e;
268
268
  }
269
269
  }
270
- }, M = class extends k {
270
+ }, j = class extends O {
271
271
  constructor(e) {
272
272
  super(), this.upstream = e, this.lastRead = Promise.resolve({
273
273
  value: null,
@@ -283,7 +283,7 @@ var k = class {
283
283
  async serialNext() {
284
284
  return this.upstream.next();
285
285
  }
286
- }, N = class extends k {
286
+ }, M = class extends O {
287
287
  constructor(e, t) {
288
288
  super(), this.upstream = e, this.maxCount = t, this.count = 0, this.lastRead = Promise.resolve({
289
289
  value: null,
@@ -304,7 +304,7 @@ var k = class {
304
304
  }
305
305
  return this.upstream.next();
306
306
  }
307
- }, P = class extends k {
307
+ }, N = class extends O {
308
308
  constructor(e, t) {
309
309
  super(), this.upstream = e, this.maxCount = t, this.count = 0;
310
310
  }
@@ -317,7 +317,7 @@ var k = class {
317
317
  done: !0
318
318
  } : this.upstream.next();
319
319
  }
320
- }, F = class extends k {
320
+ }, P = class extends O {
321
321
  constructor(e, t, n = !0) {
322
322
  super(), this.upstream = e, this.batchSize = t, this.enableSmallLastBatch = n, this.lastRead = Promise.resolve({
323
323
  value: null,
@@ -348,7 +348,7 @@ var k = class {
348
348
  done: !1
349
349
  };
350
350
  }
351
- }, I = class extends k {
351
+ }, F = class extends O {
352
352
  constructor(e, t) {
353
353
  super(), this.upstream = e, this.predicate = t, this.lastRead = Promise.resolve({
354
354
  value: null,
@@ -368,7 +368,7 @@ var k = class {
368
368
  d(e.value);
369
369
  }
370
370
  }
371
- }, L = class extends k {
371
+ }, I = class extends O {
372
372
  constructor(e, t) {
373
373
  super(), this.upstream = e, this.transform = t;
374
374
  }
@@ -388,7 +388,7 @@ var k = class {
388
388
  done: !1
389
389
  };
390
390
  }
391
- }, R = class extends k {
391
+ }, L = class extends O {
392
392
  constructor(e, t) {
393
393
  super(), this.upstream = e, this.handler = t, this.count = 0, this.lastRead = Promise.resolve({
394
394
  value: null,
@@ -411,7 +411,7 @@ var k = class {
411
411
  };
412
412
  }
413
413
  }
414
- }, z = class extends k {
414
+ }, R = class extends O {
415
415
  constructor(e, t) {
416
416
  super(), this.upstream = e, this.transform = t;
417
417
  }
@@ -431,9 +431,9 @@ var k = class {
431
431
  done: !1
432
432
  };
433
433
  }
434
- }, B = class extends k {
434
+ }, z = class extends O {
435
435
  constructor() {
436
- super(), this.outputQueue = new E(), this.lastRead = Promise.resolve({
436
+ super(), this.outputQueue = new T(), this.lastRead = Promise.resolve({
437
437
  value: null,
438
438
  done: !1
439
439
  });
@@ -451,7 +451,7 @@ var k = class {
451
451
  done: !1
452
452
  };
453
453
  }
454
- }, V = class extends B {
454
+ }, B = class extends z {
455
455
  constructor(e, t) {
456
456
  super(), this.upstream = e, this.transform = t;
457
457
  }
@@ -466,7 +466,7 @@ var k = class {
466
466
  for (let e of t) o(e, r) || e.dispose();
467
467
  return !0;
468
468
  }
469
- }, H = class extends k {
469
+ }, V = class extends O {
470
470
  constructor(e, t) {
471
471
  super(), this.baseErrorHandler = t, this.lastRead = null, this.iterator = null, this.moreIterators = e;
472
472
  }
@@ -488,13 +488,13 @@ var k = class {
488
488
  let t = await this.iterator.next();
489
489
  return t.done ? (this.iterator = null, this.readFromChain(e)) : t;
490
490
  }
491
- }, U;
491
+ }, H;
492
492
  (function(e) {
493
493
  e[e.FAIL = 0] = "FAIL", e[e.SHORTEST = 1] = "SHORTEST", e[e.LONGEST = 2] = "LONGEST";
494
- })(U ||= {});
495
- var W = class extends k {
494
+ })(H ||= {});
495
+ var U = class extends O {
496
496
  constructor(e, t) {
497
- super(), this.upstream = e, this.bufferSize = t, this.buffer = new T(t);
497
+ super(), this.upstream = e, this.bufferSize = t, this.buffer = new w(t);
498
498
  }
499
499
  summary() {
500
500
  return `${this.upstream.summary()} -> Prefetch`;
@@ -508,7 +508,7 @@ var W = class extends k {
508
508
  next() {
509
509
  return this.refill(), this.buffer.shift();
510
510
  }
511
- }, G = class extends W {
511
+ }, W = class extends U {
512
512
  constructor(e, n, r) {
513
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
514
  value: null,
@@ -535,7 +535,7 @@ var W = class extends k {
535
535
  done: !0
536
536
  };
537
537
  }
538
- }, K = class {
538
+ }, G = class {
539
539
  constructor() {
540
540
  this.size = null;
541
541
  }
@@ -544,54 +544,54 @@ var W = class extends k {
544
544
  r(e > 0, () => `batchSize needs to be positive, but it is
545
545
  ${e}`);
546
546
  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);
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);
548
548
  }
549
549
  concatenate(e) {
550
550
  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);
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);
552
552
  }
553
553
  filter(e) {
554
554
  let t = this, n;
555
- return n = this.size === Infinity ? Infinity : null, q(async () => (await t.iterator()).filter((t) => s(() => e(t))), n);
555
+ return n = this.size === Infinity ? Infinity : null, K(async () => (await t.iterator()).filter((t) => s(() => e(t))), n);
556
556
  }
557
557
  async forEachAsync(e) {
558
558
  return (await this.iterator()).forEachAsync(e);
559
559
  }
560
560
  map(e) {
561
561
  let t = this;
562
- return q(async () => (await t.iterator()).map((t) => s(() => e(t))), this.size);
562
+ return K(async () => (await t.iterator()).map((t) => s(() => e(t))), this.size);
563
563
  }
564
564
  mapAsync(e) {
565
565
  let t = this;
566
- return q(async () => (await t.iterator()).mapAsync(e), this.size);
566
+ return K(async () => (await t.iterator()).mapAsync(e), this.size);
567
567
  }
568
568
  prefetch(e) {
569
569
  if (e == null) throw RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
570
570
  let t = this;
571
- return q(async () => (await t.iterator()).prefetch(e), this.size);
571
+ return K(async () => (await t.iterator()).prefetch(e), this.size);
572
572
  }
573
573
  repeat(e) {
574
574
  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 () => ({
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 () => ({
576
576
  value: await t.iterator(),
577
577
  done: !1
578
578
  })).take(e)), n);
579
579
  }
580
580
  skip(e) {
581
581
  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);
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);
583
583
  }
584
584
  shuffle(e, n, r = !0) {
585
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)`);
586
586
  let i = this, a = m.alea(n || t().toString());
587
- return q(async () => {
587
+ return K(async () => {
588
588
  let t = a.int32();
589
589
  return r && (t += a.int32()), (await i.iterator()).shuffle(e, t.toString());
590
590
  }, this.size);
591
591
  }
592
592
  take(e) {
593
593
  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);
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);
595
595
  }
596
596
  async toArray() {
597
597
  if (this.size === Infinity) throw Error("Can not convert infinite data stream to array.");
@@ -602,9 +602,9 @@ var W = class extends k {
602
602
  return (await this.iterator()).toArrayForTest();
603
603
  }
604
604
  };
605
- K.MAX_BUFFER_SIZE = 1e4;
606
- function q(e, t = null) {
607
- return new class extends K {
605
+ G.MAX_BUFFER_SIZE = 1e4;
606
+ function K(e, t = null) {
607
+ return new class extends G {
608
608
  constructor() {
609
609
  super(...arguments), this.size = t;
610
610
  }
@@ -613,94 +613,123 @@ function q(e, t = null) {
613
613
  }
614
614
  }();
615
615
  }
616
- function J(e) {
616
+ function q(e) {
617
617
  if (e === null) return null;
618
618
  let t = e[0];
619
619
  return x(t) ? {
620
- value: Y(e),
620
+ value: J(e),
621
621
  recurse: !1
622
622
  } : {
623
623
  value: null,
624
624
  recurse: !0
625
625
  };
626
626
  }
627
- function Y(e) {
627
+ function J(e) {
628
628
  if (e.length === 0) throw Error("Can't make a batch of zero elements.");
629
629
  return e[0] instanceof f ? i(e) : c(e);
630
630
  }
631
631
  //#endregion
632
632
  //#region node_modules/@tensorflow/tfjs-data/dist/readers.js
633
- function X(e) {
634
- return q(async () => {
633
+ function Y(e) {
634
+ return K(async () => {
635
635
  let t = await e();
636
636
  return D(() => t.next());
637
637
  });
638
638
  }
639
639
  //#endregion
640
640
  //#region lib/training/DatasetBuilder.ts
641
- function Z(e, t) {
641
+ function X(e, t) {
642
642
  let n = e.map((e) => t.encodeConversation(e)).flat();
643
643
  return new Uint16Array(n);
644
644
  }
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();
645
+ function Z(e, t) {
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();
649
647
  return {
650
648
  tokens: new Uint16Array(r),
651
649
  mask: new Uint8Array(i.map((e) => +!!e))
652
650
  };
653
651
  }
654
- function $(e) {
652
+ function Q(e) {
655
653
  for (let t = e.length - 1; t > 0; t--) {
656
654
  let n = Math.floor(Math.random() * (t + 1));
657
655
  [e[t], e[n]] = [e[n], e[t]];
658
656
  }
659
657
  return e;
660
658
  }
661
- var te = class {
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 {
662
677
  tokenizer;
663
678
  blockSize;
664
679
  constructor(e, t = 128) {
665
680
  this.tokenizer = e, this.blockSize = t;
666
681
  }
667
- 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),
682
+ async createTextDataset(e, t) {
683
+ let { batchSize: n = 32, noShuffle: r = !1, ignoreIndex: i = 65535 } = t || {}, a = e.getTokenCount();
684
+ if (a < this.blockSize + 1) throw Error(`Not enough tokens (${a}) for block size ${this.blockSize}`);
685
+ let o = Math.ceil(e.shardSize / this.blockSize), c = {
686
+ shuffledShards: new Uint32Array(e.getShardCount()),
687
+ shuffledIndexes: new Uint32Array(o),
688
+ lastShardIndexes: new Uint32Array(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
- if (n) o.shuffledIndexes = n;
674
- else {
675
- o.shuffledIndexes = new Uint32Array(a);
676
- for (let e = 0; e < a; e++) o.shuffledIndexes[e] = e;
677
- }
678
- return {
679
- dataset: X(function* () {
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 = 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);
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;
706
+ let t = (c.shardIndex === c.shuffledShards.length - 1 ? c.lastShardIndexes : c.shuffledIndexes)[c.step], n = t * this.blockSize, a = c.currentShard, o = c.currentMask, s = $(c, e, r);
707
+ if (!a) break;
708
+ if (n + this.blockSize + 1 > a.length) {
709
+ console.warn("Index out of bounds for current shard, moving to next shard", t, n, a.length);
710
+ continue;
711
+ }
712
+ let l = new Int32Array(a.slice(n, n + this.blockSize)), u = new Int32Array(a.slice(n + 1, n + this.blockSize + 1));
713
+ if (o) {
714
+ let e = 0, t = o.slice(n + 1, n + this.blockSize + 1);
715
+ for (let n = 0; n < u.length; n++) t[n] === 0 && (u[n] = i, e++);
716
+ if (e === u.length) continue;
688
717
  }
689
718
  yield {
690
- xs: n,
691
- ys: s
692
- };
719
+ xs: l,
720
+ ys: u
721
+ }, await s;
693
722
  }
694
- }.bind(this)).batch(t).map((e) => {
723
+ }.bind(this)).batch(n).map((e) => {
695
724
  let t = e;
696
725
  return s(() => ({
697
726
  xs: t.xs.cast("int32"),
698
727
  ys: t.ys.cast("int32")
699
728
  }));
700
729
  }).prefetch(2),
701
- state: o
730
+ state: c
702
731
  };
703
732
  }
704
733
  };
705
734
  //#endregion
706
- export { $ as i, Z as n, Q as r, te as t };
735
+ 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 { c as e, s as t } from "./main-DdsoTJAW.js";
2
- export { t as default, e as isConversation };
1
+ import { a as e, o as t } from "./main-BSaDGH7I.js";
2
+ export { e as default, t 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-BSaDGH7I.js";
2
2
  export { e as default };