@genai-fi/nanogpt 1.7.0 → 1.7.2

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.
@@ -2,20 +2,27 @@ import { Tensor } from '@tensorflow/tfjs-core';
2
2
  import type { Conversation, ITokeniser } from '../tokeniser/type.js';
3
3
  import { Dataset } from '@tensorflow/tfjs-data';
4
4
  import { TokenStore } from './tasks/TokenStore.js';
5
- export declare function flattenTokens(textData: Conversation[][], tokenizer: ITokeniser): Uint16Array;
5
+ export declare function flattenTokens(textData: Conversation[][], tokenizer: ITokeniser): Uint16Array<ArrayBuffer>;
6
6
  export declare function flattenTokensWithMask(textData: Conversation[][], tokenizer: ITokeniser): {
7
- tokens: Uint16Array;
8
- mask: Uint8Array;
7
+ tokens: Uint16Array<ArrayBuffer>;
8
+ mask: Uint8Array<ArrayBuffer>;
9
9
  };
10
10
  export declare function shuffle(array: Uint32Array | Uint16Array): Uint32Array | Uint16Array;
11
+ interface ShardData {
12
+ tokens: Uint16Array<ArrayBuffer>;
13
+ mask: Uint8Array<ArrayBuffer> | null;
14
+ }
15
+ interface PrefetchedShard {
16
+ shardId: number;
17
+ data: Promise<ShardData>;
18
+ }
11
19
  export interface DatasetState {
12
20
  shuffledShards: Uint16Array;
13
21
  shuffledIndexes: Uint16Array;
14
22
  lastShardIndexes: Uint16Array;
15
- currentShard: Uint16Array | null;
16
- nextShard: Uint16Array | null;
17
- currentMask: Uint8Array | null;
18
- nextMask: Uint8Array | null;
23
+ currentShard: Uint16Array<ArrayBuffer> | null;
24
+ nextShard: PrefetchedShard | null;
25
+ currentMask: Uint8Array<ArrayBuffer> | null;
19
26
  shardIndex: number;
20
27
  step: number;
21
28
  }
@@ -18,5 +18,5 @@ interface PrepareDataResult {
18
18
  totalTokens: number;
19
19
  }
20
20
  /** Take our training options, model, tokeniser, and tasks, and prepare the training and validation datasets in Tensorflow format. */
21
- export default function prepareData(options: TrainingOptions, model: Model<ModelForwardAttributes>, tokeniser: ITokeniser, tasks: ConversationStream[] | Uint16Array[] | TokenStore, datasetId: string, validation?: Uint16Array[] | TokenStore, datasets?: DatasetMetadata[]): Promise<PrepareDataResult>;
21
+ export default function prepareData(options: TrainingOptions, model: Model<ModelForwardAttributes>, tokeniser: ITokeniser, tasks: ConversationStream[] | Uint16Array<ArrayBuffer>[] | TokenStore, datasetId: string, validation?: Uint16Array<ArrayBuffer>[] | TokenStore, datasets?: DatasetMetadata[]): Promise<PrepareDataResult>;
22
22
  export {};
@@ -15,7 +15,7 @@ export declare class TokenStore {
15
15
  get shardSize(): number;
16
16
  hasMask(): boolean;
17
17
  getShardLength(index: number): number;
18
- slice(start: number, end: number): Promise<Uint16Array>;
18
+ slice(start: number, end: number): Promise<Uint16Array<ArrayBuffer>>;
19
19
  init(): Promise<void>;
20
20
  private writeManifest;
21
21
  private readManifest;
@@ -27,12 +27,12 @@ export declare class TokenStore {
27
27
  private readMaskFromOPFS;
28
28
  private touchLRU;
29
29
  private evictIfNeeded;
30
- getShard(index: number): Promise<Uint16Array>;
31
- getMask(index: number): Promise<Uint8Array | undefined>;
30
+ getShard(index: number): Promise<Uint16Array<ArrayBuffer>>;
31
+ getMask(index: number): Promise<Uint8Array<ArrayBuffer> | undefined>;
32
32
  getShardCount(): number;
33
33
  getTokenCount(): number;
34
34
  finish(): Promise<void>;
35
- appendShard(shard: Uint16Array, mask?: Uint8Array): void;
35
+ appendShard(shard: Uint16Array<ArrayBuffer>, mask?: Uint8Array<ArrayBuffer>): void;
36
36
  dispose(): Promise<void>;
37
37
  clear(): Promise<void>;
38
38
  }
@@ -73,8 +73,8 @@ export interface TrainingOptions extends Partial<AdamWOptimizerConfig> {
73
73
  debug?: boolean;
74
74
  }
75
75
  export interface TrainingContext {
76
- training_data: ConversationStream[] | Uint16Array[] | TokenStore;
77
- validation_data?: Uint16Array[] | TokenStore;
76
+ training_data: ConversationStream[] | Uint16Array<ArrayBuffer>[] | TokenStore;
77
+ validation_data?: Uint16Array<ArrayBuffer>[] | TokenStore;
78
78
  datasets?: DatasetMetadata[];
79
79
  onStep?: (log: TrainingLogEntry) => void;
80
80
  }
@@ -3,8 +3,8 @@ import { Tensor } from '@tensorflow/tfjs-core';
3
3
  import { Dataset } from '@tensorflow/tfjs-data';
4
4
  import { DatasetBuilder, DatasetState } from './DatasetBuilder.js';
5
5
  import { TokenStore } from './tasks/TokenStore.js';
6
- export declare function storeFromArray(tokens: Uint16Array[], tokenizer: ITokeniser): Promise<TokenStore>;
7
- export declare function createTrainValidationDatasets(trainingTokens: Uint16Array[] | TokenStore, validationTokens: Uint16Array[] | TokenStore, tokeniser: ITokeniser, datasetBuilder: DatasetBuilder, batchSize: number): Promise<{
6
+ export declare function storeFromArray(tokens: Uint16Array<ArrayBuffer>[], tokenizer: ITokeniser): Promise<TokenStore>;
7
+ export declare function createTrainValidationDatasets(trainingTokens: Uint16Array<ArrayBuffer>[] | TokenStore, validationTokens: Uint16Array<ArrayBuffer>[] | TokenStore, tokeniser: ITokeniser, datasetBuilder: DatasetBuilder, batchSize: number): Promise<{
8
8
  trainDataset: Dataset<{
9
9
  xs: Tensor;
10
10
  ys: Tensor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "type": "module",
5
5
  "main": "dist/nanogpt.js",
6
6
  "types": "dist/main.d.ts",