@genai-fi/nanogpt 0.22.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 (38) hide show
  1. package/dist/{DatasetBuilder-Ctb425Id.js → DatasetBuilder-C0iJT29K.js} +145 -116
  2. package/dist/Generator.js +2 -2
  3. package/dist/TeachableLLM.js +1 -1
  4. package/dist/Trainer-DBsyWJ4s.js +228 -0
  5. package/dist/Trainer.d.ts +2 -1
  6. package/dist/Trainer.js +1 -1
  7. package/dist/data/stream.js +1 -1
  8. package/dist/data/textLoader.js +1 -1
  9. package/dist/{BaseTokeniser-C9TSv4th.js → eventemitter3-D_qV3Lof.js} +2 -132
  10. package/dist/loader/load.js +2 -2
  11. package/dist/loader/loadHF.js +1 -1
  12. package/dist/loader/loadTransformers.js +2 -2
  13. package/dist/loader/newZipLoad.js +1 -1
  14. package/dist/loader/oldZipLoad.js +1 -1
  15. package/dist/loader/save.js +1 -1
  16. package/dist/{main-Bgc7_9kb.js → main-BSaDGH7I.js} +2686 -2913
  17. package/dist/main.d.ts +1 -0
  18. package/dist/main.js +20 -18
  19. package/dist/models/NanoGPTV1.js +1 -1
  20. package/dist/models/NanoGPTV2.js +1 -1
  21. package/dist/models/factory.js +1 -1
  22. package/dist/models/model.js +1 -1
  23. package/dist/{stream-DKl3GTDL.js → stream-BjdpSNqB.js} +31 -22
  24. package/dist/tokeniser/BaseTokeniser.js +135 -2
  25. package/dist/tokeniser/CharTokeniser.js +3 -3
  26. package/dist/tokeniser/bpe.js +8 -8
  27. package/dist/training/DatasetBuilder.d.ts +17 -1
  28. package/dist/training/DatasetBuilder.js +2 -2
  29. package/dist/training/PreTrainer.js +1 -1
  30. package/dist/training/SFTTrainer.js +1 -1
  31. package/dist/training/tasks/Task.d.ts +13 -4
  32. package/dist/training/tasks/Task.js +22 -14
  33. package/dist/training/tasks/TokenStore.d.ts +46 -0
  34. package/dist/training/tasks/TokenStore.js +215 -0
  35. package/dist/training/tasks/splitter.js +1 -1
  36. package/dist/training/validation.d.ts +4 -2
  37. package/dist/training/validation.js +21 -2
  38. package/package.json +1 -1
@@ -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 g = /* @__PURE__ */ e(u());
6
- function ee(e, t) {
7
- return _(e, t);
4
+ var m = /* @__PURE__ */ e(u());
5
+ function h(e, t) {
6
+ return g(e, t);
8
7
  }
9
- function _(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
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 (x(e)) {
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] = _(o, t, n, r);
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 v(e, t = b) {
28
- return y(e, t);
26
+ function _(e, t = y) {
27
+ return v(e, t);
29
28
  }
30
- function y(e, t, n = /* @__PURE__ */ new Set()) {
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 (x(r)) {
35
+ if (b(r)) {
37
36
  let i = Array.isArray(r) ? [] : {};
38
37
  n.add(r);
39
- for (let a in r) i[a] = y(e.map((e) => e[a]), t, n);
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 b(e) {
44
- return e === null ? null : x(e[0]) ? {
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 x(e) {
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 S(e) {
62
- return e == null || C(e) || Array.isArray(e) || typeof e == "object" && e instanceof f || l(e);
60
+ function x(e) {
61
+ return e == null || S(e) || Array.isArray(e) || typeof e == "object" && e instanceof f || l(e);
63
62
  }
64
- function C(e) {
63
+ function S(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 w(e) {
70
- return ee(e, T);
68
+ function C(e) {
69
+ return h(e, ee);
71
70
  }
72
- function T(e) {
71
+ function ee(e) {
73
72
  return e instanceof f ? {
74
73
  value: e.clone(),
75
74
  recurse: !1
76
- } : x(e) ? {
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 E = class {
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
- }, D = class e extends E {
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
- D.INITIAL_CAPACITY = 32;
159
+ T.INITIAL_CAPACITY = 32;
161
160
  //#endregion
162
161
  //#region node_modules/@tensorflow/tfjs-data/dist/iterators/lazy_iterator.js
163
- function O(e) {
164
- return new M(e);
162
+ function E(e) {
163
+ return new k(e);
165
164
  }
166
- function k(e) {
167
- return new N(e);
165
+ function D(e) {
166
+ return new A(e);
168
167
  }
169
- function A(e, t) {
170
- return new W(e, t);
168
+ function te(e, t) {
169
+ return new V(e, t);
171
170
  }
172
- var j = class {
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 B(this, e);
191
+ return new L(this, e);
193
192
  }
194
193
  filter(e) {
195
- return new R(this, e);
194
+ return new F(this, e);
196
195
  }
197
196
  map(e) {
198
- return new z(this, e);
197
+ return new I(this, e);
199
198
  }
200
199
  mapAsync(e) {
201
- return new V(this, e);
200
+ return new R(this, e);
202
201
  }
203
202
  serialMapAsync(e) {
204
- return new V(this, e).serial();
203
+ return new R(this, e).serial();
205
204
  }
206
205
  flatmap(e) {
207
- return new U(this, e);
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 L(this, e, t);
215
+ return new P(this, e, t);
217
216
  }
218
- columnMajorBatch(e, t = !0, n = b) {
219
- return this.rowMajorBatch(e, t).map((e) => v(e, n));
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 W(O([this, e]), t);
221
+ return new V(E([this, e]), t);
223
222
  }
224
223
  take(e) {
225
- return e < 0 || e == null ? this : new I(this, e);
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 F(this, e);
227
+ return e < 0 || e == null ? this : new M(this, e);
229
228
  }
230
229
  prefetch(e) {
231
- return new K(this, e);
230
+ return new U(this, e);
232
231
  }
233
232
  shuffle(e, t) {
234
- return new q(this, e, t);
233
+ return new W(this, e, t);
235
234
  }
236
235
  serial() {
237
- return new P(this);
236
+ return new j(this);
238
237
  }
239
- }, M = class extends j {
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: w(e),
252
+ value: C(e),
254
253
  done: !1
255
254
  };
256
255
  }
257
- }, N = class extends j {
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
- }, P = class extends j {
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
- }, F = class extends j {
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
- }, I = class extends j {
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
- }, L = class extends j {
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
- }, R = class extends j {
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
- }, z = class extends j {
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
- }, B = class extends j {
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
- }, V = class extends j {
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
- }, H = class extends j {
434
+ }, z = class extends O {
436
435
  constructor() {
437
- super(), this.outputQueue = new D(), this.lastRead = Promise.resolve({
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
- }, U = class extends H {
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
- }, W = class extends j {
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
- }, G;
491
+ }, H;
493
492
  (function(e) {
494
493
  e[e.FAIL = 0] = "FAIL", e[e.SHORTEST = 1] = "SHORTEST", e[e.LONGEST = 2] = "LONGEST";
495
- })(G ||= {});
496
- var K = class extends j {
494
+ })(H ||= {});
495
+ var U = class extends O {
497
496
  constructor(e, t) {
498
- super(), this.upstream = e, this.bufferSize = t, this.buffer = new E(t);
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
- }, q = class extends K {
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 = g.alea(r || t().toString()), this.lastRead = Promise.resolve({
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
- }, J = class {
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), Y(async () => (await n.iterator()).columnMajorBatch(e, t, X), 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);
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, Y(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);
553
552
  }
554
553
  filter(e) {
555
554
  let t = this, n;
556
- return n = this.size === Infinity ? Infinity : null, Y(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);
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 Y(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);
564
563
  }
565
564
  mapAsync(e) {
566
565
  let t = this;
567
- return Y(async () => (await t.iterator()).mapAsync(e), this.size);
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 Y(async () => (await t.iterator()).prefetch(e), this.size);
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, Y(async () => A(k(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 () => ({
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, Y(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);
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 = g.alea(n || t().toString());
588
- return Y(async () => {
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, Y(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);
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
- J.MAX_BUFFER_SIZE = 1e4;
607
- function Y(e, t = null) {
608
- return new class extends J {
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,114 @@ function Y(e, t = null) {
614
613
  }
615
614
  }();
616
615
  }
617
- function X(e) {
616
+ function q(e) {
618
617
  if (e === null) return null;
619
618
  let t = e[0];
620
- return S(t) ? {
621
- value: Z(e),
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 Z(e) {
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 Q(e) {
635
- return Y(async () => {
633
+ function Y(e) {
634
+ return K(async () => {
636
635
  let t = await e();
637
- return k(() => t.next());
636
+ return D(() => t.next());
638
637
  });
639
638
  }
640
639
  //#endregion
641
640
  //#region lib/training/DatasetBuilder.ts
642
- function te(e, t) {
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 ne(e, t) {
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 $(e) {
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
- var re = 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 {
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 = 32, n, r, i = 65535) {
667
- let a = e.reduce((e, t) => e + t.length, 0);
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(a / this.blockSize), c = {
685
+ let o = Math.ceil(e.shardSize / this.blockSize), c = {
686
+ shuffledShards: new Uint32Array(e.getShardCount()),
670
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) c.shuffledIndexes = n;
674
- else {
675
- c.shuffledIndexes = new Uint32Array(o);
676
- for (let e = 0; e < o; e++) c.shuffledIndexes[e] = e;
677
- }
678
- return {
679
- dataset: Q(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 = 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
- if (r) {
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;
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: o
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"),
@@ -703,4 +732,4 @@ var re = class {
703
732
  }
704
733
  };
705
734
  //#endregion
706
- export { $ as i, te as n, ne as r, re 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-Bgc7_9kb.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 };
@@ -1,2 +1,2 @@
1
- import { i as e } from "./main-Bgc7_9kb.js";
1
+ import { i as e } from "./main-BSaDGH7I.js";
2
2
  export { e as default };