@genai-fi/nanogpt 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/{DatasetBuilder-C0iJT29K.js → DatasetBuilder-DU1G1OKX.js} +20 -23
  2. package/dist/Generator.js +2 -2
  3. package/dist/TeachableLLM.d.ts +1 -2
  4. package/dist/TeachableLLM.js +1 -1
  5. package/dist/{Trainer-DBsyWJ4s.js → Trainer-Cr7csbTD.js} +1 -1
  6. package/dist/Trainer.d.ts +2 -2
  7. package/dist/Trainer.js +1 -1
  8. package/dist/data/stream.d.ts +6 -6
  9. package/dist/data/stream.js +1 -1
  10. package/dist/data/textLoader.js +1 -1
  11. package/dist/loader/load.js +2 -2
  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-BSaDGH7I.js → main-Dz72vadm.js} +1489 -1496
  18. package/dist/main.d.ts +2 -10
  19. package/dist/main.js +20 -20
  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-BjdpSNqB.js → stream-BpAwcvHz.js} +565 -561
  25. package/dist/tokeniser/CharTokeniser.js +18 -20
  26. package/dist/tokeniser/bpe.js +18 -22
  27. package/dist/training/DatasetBuilder.d.ts +4 -4
  28. package/dist/training/DatasetBuilder.js +1 -1
  29. package/dist/training/PreTrainer.js +1 -1
  30. package/dist/training/SFTTrainer.js +1 -1
  31. package/dist/training/tasks/TokenStore.d.ts +2 -1
  32. package/dist/training/tasks/TokenStore.js +8 -5
  33. package/dist/training/tasks/tokenStream.d.ts +16 -0
  34. package/dist/training/tasks/tokenStream.js +46 -0
  35. package/dist/training/validation.js +4 -2
  36. package/dist/utilities/random.d.ts +1 -0
  37. package/dist/utilities/random.js +19 -0
  38. package/package.json +1 -1
  39. package/dist/training/tasks/ConversationTask.d.ts +0 -17
  40. package/dist/training/tasks/ConversationTask.js +0 -29
  41. package/dist/training/tasks/PretrainingTask.d.ts +0 -17
  42. package/dist/training/tasks/PretrainingTask.js +0 -42
  43. package/dist/training/tasks/StartSentenceTask.d.ts +0 -18
  44. package/dist/training/tasks/StartSentenceTask.js +0 -45
  45. package/dist/training/tasks/Task.d.ts +0 -29
  46. package/dist/training/tasks/Task.js +0 -50
  47. package/dist/training/tasks/splitter.d.ts +0 -5
  48. package/dist/training/tasks/splitter.js +0 -18
@@ -58,17 +58,17 @@ function b(e) {
58
58
  return e != null && !ArrayBuffer.isView(e) && (Array.isArray(e) || typeof e == "object" && !(e instanceof f) && !(e instanceof Promise) && !t);
59
59
  }
60
60
  function x(e) {
61
- return e == null || S(e) || Array.isArray(e) || typeof e == "object" && e instanceof f || l(e);
61
+ return e == null || ee(e) || Array.isArray(e) || typeof e == "object" && e instanceof f || l(e);
62
62
  }
63
- function S(e) {
63
+ function ee(e) {
64
64
  return e === null || typeof e != "object" && typeof e != "function";
65
65
  }
66
66
  //#endregion
67
67
  //#region node_modules/@tensorflow/tfjs-data/dist/util/deep_clone.js
68
- function C(e) {
69
- return h(e, ee);
68
+ function S(e) {
69
+ return h(e, C);
70
70
  }
71
- function ee(e) {
71
+ function C(e) {
72
72
  return e instanceof f ? {
73
73
  value: e.clone(),
74
74
  recurse: !1
@@ -249,7 +249,7 @@ var O = class {
249
249
  };
250
250
  let e = this.items[this.trav];
251
251
  return this.trav++, {
252
- value: C(e),
252
+ value: S(e),
253
253
  done: !1
254
254
  };
255
255
  }
@@ -683,9 +683,9 @@ var ne = class {
683
683
  let { batchSize: n = 32, noShuffle: r = !1, ignoreIndex: i = 65535 } = t || {}, a = e.getTokenCount();
684
684
  if (a < this.blockSize + 1) throw Error(`Not enough tokens (${a}) for block size ${this.blockSize}`);
685
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)),
686
+ shuffledShards: new Uint16Array(e.getShardCount()),
687
+ shuffledIndexes: new Uint16Array(o),
688
+ lastShardIndexes: new Uint16Array(Math.ceil(e.getShardLength(e.getShardCount() - 1) / this.blockSize)),
689
689
  currentMask: null,
690
690
  nextMask: null,
691
691
  currentShard: null,
@@ -703,22 +703,19 @@ var ne = class {
703
703
  })), {
704
704
  dataset: Y(async function* () {
705
705
  for (;;) {
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;
706
+ let t = (c.shardIndex === c.shuffledShards.length - 1 ? c.lastShardIndexes : c.shuffledIndexes)[c.step] * this.blockSize, n = c.currentShard, a = c.currentMask, o = $(c, e, r);
707
+ if (!n) break;
708
+ t + this.blockSize + 1 > n.length && (t = n.length - this.blockSize - 1);
709
+ let s = new Int32Array(n.slice(t, t + this.blockSize)), l = new Int32Array(n.slice(t + 1, t + this.blockSize + 1));
710
+ if (a) {
711
+ let e = 0, n = a.slice(t + 1, t + this.blockSize + 1);
712
+ for (let t = 0; t < l.length; t++) n[t] === 0 && (l[t] = i, e++);
713
+ if (e === l.length) continue;
717
714
  }
718
715
  yield {
719
- xs: l,
720
- ys: u
721
- }, await s;
716
+ xs: s,
717
+ ys: l
718
+ }, await o;
722
719
  }
723
720
  }.bind(this)).batch(n).map((e) => {
724
721
  let t = e;
package/dist/Generator.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, o as t } from "./main-BSaDGH7I.js";
2
- export { e as default, t as isConversation };
1
+ import { a as e, i as t } from "./main-Dz72vadm.js";
2
+ export { t as default, e as isConversation };
@@ -7,7 +7,6 @@ import { default as Trainer, TrainingType } from './Trainer';
7
7
  import { ConversationStream } from './main';
8
8
  import { default as MemoryProfiler } from './utilities/profile';
9
9
  import { default as Model, ModelForwardAttributes } from './models/model';
10
- import { Task } from './training/tasks/Task';
11
10
  import { TrainingLogEntry, TrainingOptions } from './training/types';
12
11
  import { ModelMode, TransformersMetadata } from './loader/types';
13
12
  type TeachableLLMStatus = 'warmup' | 'awaitingTokens' | 'ready' | 'training' | 'loading' | 'busy' | 'error';
@@ -51,7 +50,7 @@ export default class TeachableLLM {
51
50
  set enableProfiler(value: boolean);
52
51
  getNumParams(): number;
53
52
  trainer(trainingType?: TrainingType, options?: TrainingOptions): Trainer;
54
- train(text: Task[], options?: TrainingOptions, trainingType?: TrainingType): Promise<void>;
53
+ train(text: ConversationStream[], options?: TrainingOptions, trainingType?: TrainingType): Promise<void>;
55
54
  trainTokeniser(text: ConversationStream[]): Promise<number>;
56
55
  generator(): IGenerator;
57
56
  generateText(prompt: Conversation[], options?: IGenerateOptions): Promise<Conversation[]>;
@@ -1,2 +1,2 @@
1
- import { i as e } from "./main-BSaDGH7I.js";
1
+ import { r as e } from "./main-Dz72vadm.js";
2
2
  export { e as default };
@@ -2,7 +2,7 @@ import { packingSupported as e } from "./utilities/packed.js";
2
2
  import { t } from "./eventemitter3-D_qV3Lof.js";
3
3
  import n from "./training/PreTrainer.js";
4
4
  import { TokenStore as r } from "./training/tasks/TokenStore.js";
5
- import { tokensFromTasks as i } from "./training/tasks/Task.js";
5
+ import { tokensFromStreams as i } from "./training/tasks/tokenStream.js";
6
6
  import { createTrainValidationDatasets as a, storeFromArray as o } from "./training/validation.js";
7
7
  import s from "./training/SFTTrainer.js";
8
8
  //#region node_modules/uuid/dist/stringify.js
package/dist/Trainer.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ITokeniser } from './tokeniser/type';
2
2
  import { default as EE } from 'eventemitter3';
3
3
  import { default as Model, ModelForwardAttributes } from './models/model';
4
- import { Task } from './training/tasks/Task';
5
4
  import { TrainingOptions, TrainingLogEntry } from './training/types';
6
5
  import { AdamWOptimizer } from './training/AdamW';
7
6
  import { DatasetMetadata } from './loader/types';
8
7
  import { TokenStore } from './training/tasks/TokenStore';
8
+ import { ConversationStream } from './data/stream';
9
9
  interface TrainingProgress {
10
10
  lastLog: TrainingLogEntry;
11
11
  progress: number;
@@ -34,7 +34,7 @@ export default class Trainer extends EE<'start' | 'stop' | 'log'> {
34
34
  dispose(): void;
35
35
  getTotalTokens(): number;
36
36
  setOptions(options: TrainingOptions): void;
37
- prepare(tasks?: Task[] | Uint16Array[] | TokenStore, validation?: Uint16Array[] | TokenStore, datasets?: DatasetMetadata[]): Promise<void>;
37
+ prepare(tasks?: ConversationStream[] | Uint16Array[] | TokenStore, validation?: Uint16Array[] | TokenStore, datasets?: DatasetMetadata[]): Promise<void>;
38
38
  private configureModel;
39
39
  train(): Promise<void>;
40
40
  step(options?: TrainingOptions): Promise<void>;
package/dist/Trainer.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./Trainer-DBsyWJ4s.js";
1
+ import { t as e } from "./Trainer-Cr7csbTD.js";
2
2
  export { e as default };
@@ -1,19 +1,19 @@
1
1
  import { Conversation } from '../../tokeniser/type';
2
- export interface ConversationCursor {
3
- next(): Promise<Conversation[] | null>;
4
- }
5
2
  export interface ConversationStream {
6
- cursor(): ConversationCursor;
3
+ begin(cb: (conv: Conversation[]) => void, yieldCb?: () => void): Promise<void>;
4
+ step(cb: (conv: Conversation[]) => void): Promise<() => Promise<boolean>>;
7
5
  }
8
6
  export declare class MemoryConversationStream implements ConversationStream {
9
7
  private conversations;
10
8
  constructor(conversations: Conversation[][]);
11
- cursor(): ConversationCursor;
9
+ step(cb: (conv: Conversation[]) => void): Promise<() => Promise<boolean>>;
10
+ begin(cb: (conv: Conversation[]) => void, yieldCb?: () => void): Promise<void>;
12
11
  }
13
12
  declare class JSONLFromReadableStream implements ConversationStream {
14
13
  private sourceFactory;
15
14
  constructor(sourceFactory: () => Promise<ReadableStream<Uint8Array>>);
16
- cursor(): ConversationCursor;
15
+ step(cb: (conv: Conversation[]) => void): Promise<() => Promise<boolean>>;
16
+ begin(cb: (conv: Conversation[]) => void, yieldCb?: () => void): Promise<void>;
17
17
  }
18
18
  export declare class JSONLConversationStream extends JSONLFromReadableStream {
19
19
  constructor(file: File);
@@ -1,2 +1,2 @@
1
- import { n as e, r as t, t as n } from "../stream-BjdpSNqB.js";
1
+ import { n as e, r as t, t as n } from "../stream-BpAwcvHz.js";
2
2
  export { n as JSONLConversationStream, e as MemoryConversationStream, t as ZipJSONLConversationStream };
@@ -1,7 +1,7 @@
1
1
  import { i as e, t } from "../chunk-CWhphoD1.js";
2
2
  import { loadPDF as n } from "./pdf.js";
3
3
  import { loadDOCX as r } from "./docx.js";
4
- import { n as i, r as a, t as o } from "../stream-BjdpSNqB.js";
4
+ import { n as i, r as a, t as o } from "../stream-BpAwcvHz.js";
5
5
  //#endregion
6
6
  //#region lib/data/textLoader.ts
7
7
  var s = /* @__PURE__ */ e((/* @__PURE__ */ t(((e, t) => {
@@ -1,2 +1,2 @@
1
- import { c as e, l as t } from "../main-BSaDGH7I.js";
2
- export { e as VERSION, t as loadModel };
1
+ import { c as e, s as t } from "../main-Dz72vadm.js";
2
+ export { t as VERSION, e as loadModel };
@@ -1,2 +1,2 @@
1
- import { u as e } from "../main-BSaDGH7I.js";
1
+ import { l as e } from "../main-Dz72vadm.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { f as e, p as t } from "../main-BSaDGH7I.js";
1
+ import { d as e, f as t } from "../main-Dz72vadm.js";
2
2
  export { e as default, t as mapTransformersConfigToGPTConfig };
@@ -1,2 +1,2 @@
1
- import { d as e } from "../main-BSaDGH7I.js";
1
+ import { u as e } from "../main-Dz72vadm.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { m as e } from "../main-BSaDGH7I.js";
1
+ import { p as e } from "../main-Dz72vadm.js";
2
2
  export { e as default };
@@ -1,2 +1,2 @@
1
- import { s as e } from "../main-BSaDGH7I.js";
1
+ import { o as e } from "../main-Dz72vadm.js";
2
2
  export { e as saveModel };