@genai-fi/nanogpt 0.7.3 → 0.8.1

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 (197) hide show
  1. package/dist/Generator.d.ts +25 -2
  2. package/dist/Generator.js +152 -49
  3. package/dist/{RealDiv-Dy0p8Bvo.js → RealDiv-D_q39E3A.js} +13 -13
  4. package/dist/{Reshape-DvudQDvJ.js → Reshape-41YpQqEo.js} +1 -1
  5. package/dist/{Reshape-DH5srBP0.js → Reshape-Bh_jzKzV.js} +5 -5
  6. package/dist/TeachableLLM.d.ts +6 -6
  7. package/dist/TeachableLLM.js +33 -31
  8. package/dist/Trainer.d.ts +13 -2
  9. package/dist/Trainer.js +21 -12
  10. package/dist/{axis_util-BzbKo31C.js → axis_util-Did9235A.js} +3 -3
  11. package/dist/backend.js +2 -2
  12. package/dist/{backend_util-TE7aTPhZ.js → backend_util-yC3YH1jo.js} +58 -58
  13. package/dist/{broadcast_to-CdbwV-Dj.js → broadcast_to-CUvOdOT5.js} +2 -2
  14. package/dist/checks/appendCache.d.ts +1 -0
  15. package/dist/checks/appendCache.js +22 -0
  16. package/dist/checks/attentionMask.d.ts +1 -0
  17. package/dist/checks/attentionMask.js +37 -0
  18. package/dist/checks/check.d.ts +9 -0
  19. package/dist/checks/check.js +20 -0
  20. package/dist/checks/gelu.d.ts +1 -0
  21. package/dist/checks/gelu.js +18 -0
  22. package/dist/checks/index.d.ts +19 -0
  23. package/dist/checks/index.js +21 -0
  24. package/dist/checks/normRMS.d.ts +1 -0
  25. package/dist/checks/normRMS.js +16 -0
  26. package/dist/checks/normRMSGrad.d.ts +1 -0
  27. package/dist/checks/normRMSGrad.js +12 -0
  28. package/dist/checks/qkv.d.ts +1 -0
  29. package/dist/checks/qkv.js +25 -0
  30. package/dist/checks/rope.d.ts +1 -0
  31. package/dist/checks/rope.js +21 -0
  32. package/dist/{concat-CsxrgovM.js → concat-pHiVqR3L.js} +1 -1
  33. package/dist/{dataset-CtdBYwjo.js → dataset-DPPl-iLT.js} +9 -9
  34. package/dist/{dropout-DYs5QFGQ.js → dropout-CcKSfOYE.js} +18 -18
  35. package/dist/exports_initializers-DKk7-bsx.js +16 -0
  36. package/dist/{gather-CMMy2KEG.js → gather-CPg6ZlQA.js} +1 -1
  37. package/dist/{gelu-C-dPj6Ku.js → gelu-BkcmEEyD.js} +1 -1
  38. package/dist/{gpgpu_math-DGNLNL4I.js → gpgpu_math-D_ODOLix.js} +26 -26
  39. package/dist/{index-BoWRt-10.js → index-DdmHGZjq.js} +659 -650
  40. package/dist/{index-CLthM0TO.js → index-evZ57wr4.js} +185 -185
  41. package/dist/{kernel_funcs_utils-BYKWV8Aa.js → kernel_funcs_utils-CDfFpUab.js} +21 -21
  42. package/dist/layers/BaseLayer.d.ts +8 -13
  43. package/dist/layers/BaseLayer.js +25 -13
  44. package/dist/layers/CausalSelfAttention.d.ts +3 -2
  45. package/dist/layers/CausalSelfAttention.js +28 -28
  46. package/dist/layers/MLP.d.ts +3 -2
  47. package/dist/layers/MLP.js +16 -20
  48. package/dist/layers/PositionEmbedding.d.ts +9 -0
  49. package/dist/layers/PositionEmbedding.js +45 -0
  50. package/dist/layers/RMSNorm.d.ts +3 -2
  51. package/dist/layers/RMSNorm.js +6 -6
  52. package/dist/layers/RoPECache.d.ts +1 -1
  53. package/dist/layers/RoPECache.js +4 -4
  54. package/dist/layers/TiedEmbedding.d.ts +3 -2
  55. package/dist/layers/TiedEmbedding.js +29 -7
  56. package/dist/layers/TransformerBlock.d.ts +3 -2
  57. package/dist/layers/TransformerBlock.js +1 -1
  58. package/dist/loader/load.d.ts +2 -2
  59. package/dist/loader/loadHF.d.ts +2 -2
  60. package/dist/loader/loadTransformers.d.ts +4 -2
  61. package/dist/loader/loadTransformers.js +10 -9
  62. package/dist/loader/newZipLoad.d.ts +2 -2
  63. package/dist/loader/oldZipLoad.d.ts +2 -2
  64. package/dist/loader/oldZipLoad.js +44 -51
  65. package/dist/loader/save.d.ts +8 -0
  66. package/dist/loader/save.js +62 -0
  67. package/dist/{log_sum_exp-DbjkV734.js → log_sum_exp-C8yFJfZz.js} +45 -24
  68. package/dist/main.d.ts +6 -4
  69. package/dist/main.js +24 -18
  70. package/dist/{mat_mul-8m8pfdcx.js → mat_mul-Dpy2mMRu.js} +1 -1
  71. package/dist/mod-CbibJi3D.js +27 -0
  72. package/dist/models/NanoGPTV1.d.ts +15 -0
  73. package/dist/models/NanoGPTV1.js +71 -0
  74. package/dist/{config.d.ts → models/config.d.ts} +1 -0
  75. package/dist/{config.js → models/config.js} +1 -0
  76. package/dist/models/factory.d.ts +3 -0
  77. package/dist/models/factory.js +14 -0
  78. package/dist/models/model.d.ts +26 -0
  79. package/dist/models/model.js +70 -0
  80. package/dist/{mulmat_packed_gpu-VSekgsNv.js → mulmat_packed_gpu-q_Gmwyld.js} +1 -1
  81. package/dist/{ones-Dj0SDhHf.js → ones-BAqVh-eA.js} +2 -2
  82. package/dist/ops/adamAdjust.js +1 -1
  83. package/dist/ops/adamMoments.js +1 -1
  84. package/dist/ops/appendCache.js +3 -3
  85. package/dist/ops/attentionMask.js +1 -1
  86. package/dist/ops/cpu/adamAdjust.js +9 -9
  87. package/dist/ops/cpu/adamMoments.js +2 -2
  88. package/dist/ops/cpu/appendCache.js +2 -2
  89. package/dist/ops/cpu/attentionMask.js +5 -5
  90. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  91. package/dist/ops/cpu/gatherSub.js +5 -5
  92. package/dist/ops/cpu/gelu.js +1 -1
  93. package/dist/ops/cpu/matMulGelu.js +2 -2
  94. package/dist/ops/cpu/matMulMul.js +1 -1
  95. package/dist/ops/cpu/mulDropout.js +1 -1
  96. package/dist/ops/cpu/normRMS.js +1 -1
  97. package/dist/ops/cpu/qkv.js +3 -3
  98. package/dist/ops/cpu/rope.js +5 -5
  99. package/dist/ops/cpu/scatterSub.js +7 -7
  100. package/dist/ops/fusedSoftmax.js +1 -1
  101. package/dist/ops/gatherSub.js +1 -1
  102. package/dist/ops/gelu.js +2 -2
  103. package/dist/ops/grads/attentionMask.js +1 -1
  104. package/dist/ops/grads/fusedSoftmax.js +2 -2
  105. package/dist/ops/grads/gelu.js +2 -2
  106. package/dist/ops/grads/matMulGelu.js +1 -1
  107. package/dist/ops/grads/normRMS.js +1 -1
  108. package/dist/ops/grads/qkv.js +1 -1
  109. package/dist/ops/grads/rope.js +1 -1
  110. package/dist/ops/matMulGelu.js +1 -1
  111. package/dist/ops/matMulMul.js +1 -1
  112. package/dist/ops/mulDrop.js +1 -1
  113. package/dist/ops/normRMS.js +1 -1
  114. package/dist/ops/qkv.js +1 -1
  115. package/dist/ops/rope.js +4 -4
  116. package/dist/ops/scatterSub.js +1 -1
  117. package/dist/ops/webgl/adamAdjust.js +2 -2
  118. package/dist/ops/webgl/adamMoments.js +1 -1
  119. package/dist/ops/webgl/appendCache.js +1 -1
  120. package/dist/ops/webgl/attentionMask.js +1 -1
  121. package/dist/ops/webgl/fusedSoftmax.js +4 -4
  122. package/dist/ops/webgl/gatherSub.js +1 -1
  123. package/dist/ops/webgl/gelu.js +2 -2
  124. package/dist/ops/webgl/log.js +3 -3
  125. package/dist/ops/webgl/matMulGelu.js +10 -10
  126. package/dist/ops/webgl/matMulMul.js +1 -1
  127. package/dist/ops/webgl/mulDropout.js +1 -1
  128. package/dist/ops/webgl/normRMS.js +2 -2
  129. package/dist/ops/webgl/qkv.js +1 -1
  130. package/dist/ops/webgl/rope.js +1 -1
  131. package/dist/ops/webgl/scatterSub.js +1 -1
  132. package/dist/ops/webgpu/adamAdjust.js +3 -3
  133. package/dist/ops/webgpu/adamMoments.js +3 -3
  134. package/dist/ops/webgpu/appendCache.js +3 -3
  135. package/dist/ops/webgpu/attentionMask.js +3 -3
  136. package/dist/ops/webgpu/gatherSub.js +3 -3
  137. package/dist/ops/webgpu/gelu.js +3 -3
  138. package/dist/ops/webgpu/normRMS.js +2 -2
  139. package/dist/ops/webgpu/normRMSGrad.js +5 -5
  140. package/dist/ops/webgpu/qkv.js +3 -3
  141. package/dist/ops/webgpu/rope.js +3 -3
  142. package/dist/ops/webgpu/scatterSub.js +3 -3
  143. package/dist/ops/webgpu/utils/reductions.js +4 -4
  144. package/dist/ops-542ai2vG.js +1525 -0
  145. package/dist/{random_width-sZORGo5k.js → random_width-DKGeiFuR.js} +1471 -1538
  146. package/dist/{range-CRuAh-gd.js → range-BcUvLuf5.js} +1 -1
  147. package/dist/{reciprocal-BvGAyKyu.js → reciprocal-DhDWSKiD.js} +1 -1
  148. package/dist/{register_all_kernels-BwDSRN-f.js → register_all_kernels-Do9VvZmo.js} +2488 -2534
  149. package/dist/{max-Ddnnb5xe.js → relu-B1AXs7p5.js} +6 -6
  150. package/dist/{reshape-CdBq1WJ6.js → reshape-WeJkT3ja.js} +1 -1
  151. package/dist/{scatter_nd_util-DUstGbU1.js → scatter_nd_util-B7yDhiQr.js} +1 -1
  152. package/dist/{selu_util-BJEXVvjX.js → selu_util-BgUO9gHY.js} +125 -146
  153. package/dist/{shared-wS99K7_n.js → shared-CZiWmQCI.js} +1 -1
  154. package/dist/{shared-B8ztnyEk.js → shared-V6D_md-c.js} +72 -72
  155. package/dist/{sin-BeA3tsEd.js → sin-CPxad7Am.js} +1 -1
  156. package/dist/{slice-BiOsknYS.js → slice-B7jXtPnp.js} +1 -1
  157. package/dist/{softmax-Bv_6lyMX.js → softmax-BfsyI4As.js} +1 -1
  158. package/dist/{split-B-dikLRw.js → split-BPxr8_8m.js} +1 -1
  159. package/dist/{stack-B17UN2nn.js → stack-BNwLzE43.js} +1 -1
  160. package/dist/{sum-66ew2byf.js → sum-ByFINZgi.js} +3 -3
  161. package/dist/{tensor-JwS7ZYY6.js → tensor-DbqgIV9B.js} +1 -1
  162. package/dist/tensor1d-CtJq5BOv.js +27 -0
  163. package/dist/{tensor2d-wxPAnDQy.js → tensor2d-CObBWBkW.js} +1 -1
  164. package/dist/tensor3d-BOukqWwr.js +30 -0
  165. package/dist/tensor4d-DLtk7Nxh.js +30 -0
  166. package/dist/training/Adam.js +2 -2
  167. package/dist/training/AdamExt.js +1 -1
  168. package/dist/training/DatasetBuilder.js +2 -2
  169. package/dist/training/Evaluator.d.ts +2 -2
  170. package/dist/training/FullTrainer.d.ts +3 -3
  171. package/dist/training/FullTrainer.js +61 -69
  172. package/dist/training/Trainer.d.ts +15 -3
  173. package/dist/training/Trainer.js +39 -47
  174. package/dist/training/sparseCrossEntropy.js +12 -13
  175. package/dist/utilities/arrayClose.d.ts +1 -1
  176. package/dist/utilities/arrayClose.js +16 -7
  177. package/dist/utilities/dummy.d.ts +4 -4
  178. package/dist/utilities/dummy.js +13 -13
  179. package/dist/utilities/multinomialCPU.js +2 -2
  180. package/dist/utilities/parameters.d.ts +1 -1
  181. package/dist/utilities/performance.js +1 -1
  182. package/dist/utilities/profile.js +1 -1
  183. package/dist/utilities/safetensors.js +2 -2
  184. package/dist/utilities/weights.js +2 -2
  185. package/dist/{variable-BuddVFLa.js → variable-DPFOJyRG.js} +1 -1
  186. package/dist/{webgpu_program-PFzf1hAQ.js → webgpu_program-Dhk9R5aG.js} +1 -1
  187. package/dist/{webgpu_util-D____QpY.js → webgpu_util-BqGnZg8t.js} +27 -27
  188. package/dist/{zeros--BdLQ3oG.js → zeros-Dnwix0p4.js} +1 -1
  189. package/package.json +2 -3
  190. package/dist/NanoGPTModel.d.ts +0 -52
  191. package/dist/NanoGPTModel.js +0 -203
  192. package/dist/TiedEmbedding-BxOerUmB.js +0 -43
  193. package/dist/ops-BFGCx8Ri.js +0 -1202
  194. package/dist/utilities/generate.d.ts +0 -3
  195. package/dist/utilities/generate.js +0 -22
  196. package/dist/utilities/save.d.ts +0 -9
  197. package/dist/utilities/save.js +0 -61
@@ -1,6 +1,7 @@
1
1
  import { AttentionScores, KVCache } from './CausalSelfAttention';
2
- import { default as BaseLayer, ForwardAttributes, GPTLayerConfig } from './BaseLayer';
2
+ import { default as BaseLayer, ForwardAttributes } from './BaseLayer';
3
3
  import { Tensor } from '@tensorflow/tfjs-core';
4
+ import { GPTConfig } from '../models/config';
4
5
  interface BlockAttributes extends ForwardAttributes {
5
6
  pastKV?: KVCache;
6
7
  seed?: number;
@@ -13,7 +14,7 @@ export default class Block extends BaseLayer<BlockAttributes> {
13
14
  private mlp;
14
15
  private index;
15
16
  skipped: boolean;
16
- constructor(index: number, config: GPTLayerConfig, parent?: BaseLayer);
17
+ constructor(index: number, config: GPTConfig, parent?: BaseLayer);
17
18
  private getMLPOutput;
18
19
  forward(attrs: BlockAttributes, x: Tensor): Tensor;
19
20
  dispose(): void;
@@ -2,7 +2,7 @@ import l from "./CausalSelfAttention.js";
2
2
  import r from "./MLP.js";
3
3
  import o from "./RMSNorm.js";
4
4
  import d from "./BaseLayer.js";
5
- import { t as p } from "../index-BoWRt-10.js";
5
+ import { t as p } from "../index-DdmHGZjq.js";
6
6
  class k extends d {
7
7
  ln1;
8
8
  attn;
@@ -1,5 +1,5 @@
1
- import { default as NanoGPT } from '../NanoGPTModel';
2
1
  import { ITokeniser } from '../tokeniser/type';
2
+ import { default as Model, ModelForwardAttributes } from '../models/model';
3
3
  export declare const VERSION = 2;
4
4
  export interface Metadata {
5
5
  version: string;
@@ -7,7 +7,7 @@ export interface Metadata {
7
7
  name?: string;
8
8
  }
9
9
  export declare function loadModel(data: Blob | Buffer | string): Promise<{
10
- model: NanoGPT;
10
+ model: Model<ModelForwardAttributes>;
11
11
  tokeniser: ITokeniser;
12
12
  name?: string;
13
13
  }>;
@@ -1,7 +1,7 @@
1
- import { default as NanoGPT } from '../NanoGPTModel';
2
1
  import { ITokeniser } from '../main';
2
+ import { default as Model, ModelForwardAttributes } from '../models/model';
3
3
  export default function loadHuggingFace(name: string): Promise<{
4
- model: NanoGPT;
4
+ model: Model<ModelForwardAttributes>;
5
5
  tokeniser: ITokeniser;
6
6
  name?: string;
7
7
  }>;
@@ -1,5 +1,6 @@
1
1
  import { ITokeniser } from '../tokeniser/type';
2
- import { default as NanoGPT } from '../NanoGPTModel';
2
+ import { default as Model, ModelForwardAttributes } from '../models/model';
3
+ import { TrainingState } from '../training/Trainer';
3
4
  export interface TransformersConfig {
4
5
  model_type: string;
5
6
  vocab_size: number;
@@ -22,10 +23,11 @@ export interface TransformersMetadata {
22
23
  name?: string;
23
24
  version: number;
24
25
  application: string;
26
+ training?: TrainingState;
25
27
  [key: string]: unknown;
26
28
  }
27
29
  export default function loadTransformers(config: TransformersConfig, tokeniser: TransformersTokeniser, metadata: TransformersMetadata, weightData: ArrayBuffer): Promise<{
28
- model: NanoGPT;
30
+ model: Model<ModelForwardAttributes>;
29
31
  tokeniser: ITokeniser;
30
32
  name?: string;
31
33
  }>;
@@ -1,11 +1,12 @@
1
- import b from "../NanoGPTModel.js";
2
- import c from "../tokeniser/CharTokeniser.js";
3
- import l from "../tokeniser/bpe.js";
4
- import { load_safetensors as u } from "../utilities/safetensors.js";
5
- import { a0 as y } from "../index-BoWRt-10.js";
6
- import { dummyPassAsync as h } from "../utilities/dummy.js";
1
+ import l from "../tokeniser/CharTokeniser.js";
2
+ import c from "../tokeniser/bpe.js";
3
+ import { load_safetensors as b } from "../utilities/safetensors.js";
4
+ import { a2 as y } from "../index-DdmHGZjq.js";
5
+ import { dummyPassAsync as u } from "../utilities/dummy.js";
6
+ import _ from "../models/factory.js";
7
7
  async function L(e, a, r, t) {
8
8
  const n = {
9
+ modelType: e.model_type || "GenAI_NanoGPT_v1",
9
10
  vocabSize: e.vocab_size,
10
11
  blockSize: e.block_size,
11
12
  nLayer: e.num_hidden_layers,
@@ -16,12 +17,12 @@ async function L(e, a, r, t) {
16
17
  biasInLayerNorm: e.biasInLayerNorm,
17
18
  mlpFactor: e.mlpFactor,
18
19
  useRope: e.useRope
19
- }, m = (a.type ?? "char") === "char" ? new c(a.vocab) : new l(a.vocab, a.merges), i = await u(t), s = /* @__PURE__ */ new Map();
20
+ }, m = (a.type ?? "char") === "char" ? new l(a.vocab) : new c(a.vocab, a.merges), i = await b(t), s = /* @__PURE__ */ new Map();
20
21
  for (const [p, d] of Object.entries(i))
21
22
  s.set(p, [d]);
22
23
  y();
23
- const o = new b(n);
24
- return await h(o), o.loadWeights(s), { model: o, tokeniser: m, name: r.name };
24
+ const o = _(n);
25
+ return await u(o), o.loadWeights(s), { model: o, tokeniser: m, name: r.name };
25
26
  }
26
27
  export {
27
28
  L as default
@@ -1,8 +1,8 @@
1
1
  import { ITokeniser } from '../main';
2
- import { default as NanoGPT } from '../NanoGPTModel';
3
2
  import { default as zip } from 'jszip';
3
+ import { default as Model, ModelForwardAttributes } from '../models/model';
4
4
  export default function loadZipFile(zipFile: zip): Promise<{
5
- model: NanoGPT;
5
+ model: Model<ModelForwardAttributes>;
6
6
  tokeniser: ITokeniser;
7
7
  name?: string;
8
8
  }>;
@@ -1,7 +1,7 @@
1
1
  import { default as zip } from 'jszip';
2
2
  import { ITokeniser } from '../main';
3
- import { default as NanoGPT } from '../NanoGPTModel';
3
+ import { default as Model, ModelForwardAttributes } from '../models/model';
4
4
  export default function loadOldModel(zipFile: zip): Promise<{
5
- model: NanoGPT;
5
+ model: Model<ModelForwardAttributes>;
6
6
  tokeniser: ITokeniser;
7
7
  }>;
@@ -1,30 +1,14 @@
1
- import d from "../NanoGPTModel.js";
2
- import "../jszip.min-CjP2V1VV.js";
3
- import h from "../tokeniser/CharTokeniser.js";
4
- import { a0 as k } from "../index-BoWRt-10.js";
5
- import b from "../tokeniser/bpe.js";
6
- import { dummyPassAsync as u } from "../utilities/dummy.js";
7
- import "../Generator.js";
8
- import "../index-Dwqa6Zy2.js";
9
- import "../dataset-CtdBYwjo.js";
10
- import "../index-Tf7vU29b.js";
11
- import "../ops/cpu/adamAdjust.js";
12
- import "../ops/webgl/adamAdjust.js";
13
- import "../ops/cpu/adamMoments.js";
14
- import "../ops/webgl/adamMoments.js";
15
- import "../papaparse.min-C8l2Kvo1.js";
16
- import "../ops/cpu/scatterSub.js";
17
- import "../ops/webgl/scatterSub.js";
18
- import "../ops/cpu/gatherSub.js";
19
- import "../ops/webgl/gatherSub.js";
1
+ import { a2 as y } from "../index-DdmHGZjq.js";
20
2
  import "../ops/cpu/attentionMask.js";
21
3
  import "../ops/webgl/attentionMask.js";
22
4
  import "../ops/grads/attentionMask.js";
23
5
  import "../ops/cpu/qkv.js";
24
6
  import "../ops/webgl/qkv.js";
25
7
  import "../ops/grads/qkv.js";
26
- import "../random_width-sZORGo5k.js";
27
- import "../register_all_kernels-BwDSRN-f.js";
8
+ import "../random_width-DKGeiFuR.js";
9
+ import "../register_all_kernels-Do9VvZmo.js";
10
+ import "../index-Tf7vU29b.js";
11
+ import "../dataset-DPPl-iLT.js";
28
12
  import "../ops/cpu/rope.js";
29
13
  import "../ops/webgl/rope.js";
30
14
  import "../ops/grads/rope.js";
@@ -36,45 +20,54 @@ import "../ops/grads/fusedSoftmax.js";
36
20
  import "../ops/cpu/matMulGelu.js";
37
21
  import "../ops/webgl/matMulGelu.js";
38
22
  import "../ops/grads/matMulGelu.js";
39
- import "../ops/cpu/gelu.js";
40
- import "../ops/webgl/gelu.js";
41
- import "../gelu-C-dPj6Ku.js";
42
23
  import "../ops/cpu/normRMS.js";
43
24
  import "../ops/webgl/normRMS.js";
44
25
  import "../ops/grads/normRMS.js";
26
+ import "../ops/cpu/gatherSub.js";
27
+ import "../ops/webgl/gatherSub.js";
28
+ import "../ops/cpu/scatterSub.js";
29
+ import "../ops/webgl/scatterSub.js";
30
+ import "../jszip.min-CjP2V1VV.js";
31
+ import h from "../tokeniser/CharTokeniser.js";
32
+ import k from "../tokeniser/bpe.js";
33
+ import { dummyPassAsync as g } from "../utilities/dummy.js";
34
+ import b from "../models/factory.js";
35
+ import "../Generator.js";
36
+ import "../index-Dwqa6Zy2.js";
37
+ import "../ops/cpu/adamAdjust.js";
38
+ import "../ops/webgl/adamAdjust.js";
39
+ import "../ops/cpu/adamMoments.js";
40
+ import "../ops/webgl/adamMoments.js";
41
+ import "../papaparse.min-C8l2Kvo1.js";
42
+ import "../ops/cpu/gelu.js";
43
+ import "../ops/webgl/gelu.js";
44
+ import "../gelu-BkcmEEyD.js";
45
45
  import "../ops/webgl/log.js";
46
- import { importWeights as O } from "../utilities/weights.js";
47
- async function yt(o) {
48
- const n = /* @__PURE__ */ new Map(), s = await o.file("manifest.json")?.async("string");
49
- if (!s)
46
+ import "../checks/normRMS.js";
47
+ import "../checks/normRMSGrad.js";
48
+ import { importWeights as u } from "../utilities/weights.js";
49
+ async function ht(r) {
50
+ const e = /* @__PURE__ */ new Map(), a = await r.file("manifest.json")?.async("string");
51
+ if (!a)
50
52
  throw new Error("Manifest file not found in the zip archive");
51
- const m = JSON.parse(s);
52
- for (const [t, r] of Object.entries(m.weightSpec))
53
- n.set(t, { spec: r, data: new Float32Array() });
54
- const p = await o.file("tokeniser.json")?.async("string");
53
+ const m = JSON.parse(a);
54
+ for (const [t, o] of Object.entries(m.weightSpec))
55
+ e.set(t, { spec: o, data: new Float32Array() });
56
+ const p = await r.file("tokeniser.json")?.async("string");
55
57
  if (!p)
56
58
  throw new Error("Tokeniser file not found in the zip archive");
57
- const i = JSON.parse(p), l = (i.type ?? "char") === "char" ? new h(i.vocab) : new b(i.vocab, i.merges), c = /* @__PURE__ */ new Map();
58
- for (const t of Object.keys(o.files))
59
+ const i = JSON.parse(p), f = (i.type ?? "char") === "char" ? new h(i.vocab) : new k(i.vocab, i.merges), c = /* @__PURE__ */ new Map();
60
+ for (const t of Object.keys(r.files))
59
61
  if (t.endsWith(".bin")) {
60
- const r = t.replace(".bin", ""), w = await o.file(t).async("arraybuffer"), g = new Float32Array(w), a = n.get(r) || { spec: [], data: new Float32Array() };
61
- a.data = g, n.set(r, a);
62
- const y = await O(a);
63
- c.set(r, y);
64
- }
65
- k();
66
- const e = new d(m.config);
67
- await u(e), e.loadWeights(c);
68
- const f = await o.file("log.json")?.async("string");
69
- if (f)
70
- try {
71
- const t = JSON.parse(f);
72
- e.log = t;
73
- } catch (t) {
74
- throw console.error("Error parsing training log:", t), new Error(`Failed to parse training log: ${t}`);
62
+ const o = t.replace(".bin", ""), l = await r.file(t).async("arraybuffer"), w = new Float32Array(l), s = e.get(o) || { spec: [], data: new Float32Array() };
63
+ s.data = w, e.set(o, s);
64
+ const d = await u(s);
65
+ c.set(o, d);
75
66
  }
76
- return { model: e, tokeniser: l };
67
+ y();
68
+ const n = b(m.config);
69
+ return await g(n), n.loadWeights(c), { model: n, tokeniser: f };
77
70
  }
78
71
  export {
79
- yt as default
72
+ ht as default
80
73
  };
@@ -0,0 +1,8 @@
1
+ import { ITokeniser } from '../tokeniser/type';
2
+ import { default as Model, ModelForwardAttributes } from '../models/model';
3
+ export interface SaveOptions {
4
+ name?: string;
5
+ metadata?: Record<string, unknown>;
6
+ files?: Record<string, unknown>;
7
+ }
8
+ export declare function saveModel(model: Model<ModelForwardAttributes>, tokeniser: ITokeniser, options?: SaveOptions): Promise<Blob>;
@@ -0,0 +1,62 @@
1
+ import { j as g } from "../jszip.min-CjP2V1VV.js";
2
+ import b from "../tokeniser/CharTokeniser.js";
3
+ import { save_safetensors as p } from "../utilities/safetensors.js";
4
+ import { VERSION as y } from "./load.js";
5
+ async function v(e, n, a) {
6
+ const o = /* @__PURE__ */ new Map();
7
+ e.saveWeights(o);
8
+ const i = new g(), r = {};
9
+ o.forEach((t, s) => {
10
+ t.length === 1 && (r[s] = t[0]);
11
+ });
12
+ const f = await p(r);
13
+ i.file("model.safetensors", f, { binary: !0 });
14
+ const c = {
15
+ model_type: e.config.modelType || e.getClassName(),
16
+ vocab_size: n.getVocab().length,
17
+ hidden_size: e.config.nEmbed,
18
+ num_hidden_layers: e.config.nLayer,
19
+ num_attention_heads: e.config.nHead,
20
+ block_size: e.config.blockSize,
21
+ dropout: e.config.dropout,
22
+ biasInLinear: e.config.biasInLinear,
23
+ biasInLayerNorm: e.config.biasInLayerNorm,
24
+ mlpFactor: e.config.mlpFactor,
25
+ useRope: e.config.useRope
26
+ };
27
+ if (i.file("config.json", JSON.stringify(c, void 0, 4), {
28
+ binary: !1
29
+ }), i.file(
30
+ "meta.json",
31
+ JSON.stringify(
32
+ {
33
+ version: y,
34
+ application: "@genai-fi/nanogpt",
35
+ meta: a?.metadata,
36
+ name: a?.name,
37
+ training: e.trainingState || void 0
38
+ },
39
+ void 0,
40
+ 4
41
+ ),
42
+ {
43
+ binary: !1
44
+ }
45
+ ), i.file(
46
+ "tokeniser.json",
47
+ JSON.stringify({
48
+ type: n instanceof b ? "char" : "bpe",
49
+ vocab: n.getVocab(),
50
+ merges: await n.getMerges()
51
+ }),
52
+ {
53
+ binary: !1
54
+ }
55
+ ), a?.files)
56
+ for (const [t, s] of Object.entries(a.files))
57
+ i.file(t, JSON.stringify(s), { binary: !1 });
58
+ return i.generateAsync({ type: "blob" });
59
+ }
60
+ export {
61
+ v as saveModel
62
+ };
@@ -1,8 +1,28 @@
1
- import { B as r, C as p, E as u, ae as E, af as h, p as S, c as $, o as d } from "./index-BoWRt-10.js";
2
- import { e as K } from "./axis_util-BzbKo31C.js";
3
- import { m as T } from "./max-Ddnnb5xe.js";
4
- import { r as m } from "./reshape-CdBq1WJ6.js";
5
- import { s as _ } from "./sum-66ew2byf.js";
1
+ import { C as r, D as x, E as p, ah as h, ai as E, aj as $, p as d, c as S, q as K } from "./index-DdmHGZjq.js";
2
+ import { e as _ } from "./axis_util-Did9235A.js";
3
+ import { r as m } from "./reshape-WeJkT3ja.js";
4
+ import { s as T } from "./sum-ByFINZgi.js";
5
+ /**
6
+ * @license
7
+ * Copyright 2020 Google LLC. All Rights Reserved.
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ * =============================================================================
20
+ */
21
+ function b(s, o = null, n = !1) {
22
+ const t = { x: x(s, "x", "max") }, e = { reductionIndices: o, keepDims: n };
23
+ return p.runKernel(h, t, e);
24
+ }
25
+ const D = /* @__PURE__ */ r({ max_: b });
6
26
  /**
7
27
  * @license
8
28
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -19,11 +39,11 @@ import { s as _ } from "./sum-66ew2byf.js";
19
39
  * limitations under the License.
20
40
  * =============================================================================
21
41
  */
22
- function b(s) {
23
- const o = { x: p(s, "x", "exp") };
24
- return u.runKernel(E, o);
42
+ function I(s) {
43
+ const n = { x: x(s, "x", "exp") };
44
+ return p.runKernel(E, n);
25
45
  }
26
- const N = /* @__PURE__ */ r({ exp_: b });
46
+ const M = /* @__PURE__ */ r({ exp_: I });
27
47
  /**
28
48
  * @license
29
49
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -40,11 +60,11 @@ const N = /* @__PURE__ */ r({ exp_: b });
40
60
  * limitations under the License.
41
61
  * =============================================================================
42
62
  */
43
- function v(s) {
44
- const o = { x: p(s, "x", "log", "float32") };
45
- return u.runKernel(h, o);
63
+ function N(s) {
64
+ const n = { x: x(s, "x", "log", "float32") };
65
+ return p.runKernel($, n);
46
66
  }
47
- const w = /* @__PURE__ */ r({ log_: v });
67
+ const j = /* @__PURE__ */ r({ log_: N });
48
68
  /**
49
69
  * @license
50
70
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -61,22 +81,23 @@ const w = /* @__PURE__ */ r({ log_: v });
61
81
  * limitations under the License.
62
82
  * =============================================================================
63
83
  */
64
- function A(s, n = null, o = !1) {
65
- const a = p(s, "x", "logSumExp"), t = S(n, a.shape), x = T(
84
+ function q(s, o = null, n = !1) {
85
+ const a = x(s, "x", "logSumExp"), t = d(o, a.shape), e = D(
66
86
  a,
67
87
  t,
68
88
  !0
69
89
  /* keepDims */
70
- ), i = $(a, x), l = N(i), f = _(l, t), c = w(f), e = d(m(x, c.shape), c);
71
- if (o) {
72
- const g = K(e.shape, t);
73
- return m(e, g);
90
+ ), i = S(a, e), l = M(i), f = T(l, t), u = j(f), c = K(m(e, u.shape), u);
91
+ if (n) {
92
+ const g = _(c.shape, t);
93
+ return m(c, g);
74
94
  }
75
- return e;
95
+ return c;
76
96
  }
77
- const L = /* @__PURE__ */ r({ logSumExp_: A });
97
+ const G = /* @__PURE__ */ r({ logSumExp_: q });
78
98
  export {
79
- w as a,
80
- N as e,
81
- L as l
99
+ j as a,
100
+ M as e,
101
+ G as l,
102
+ D as m
82
103
  };
package/dist/main.d.ts CHANGED
@@ -2,18 +2,19 @@ import { default as CausalSelfAttention } from './layers/CausalSelfAttention';
2
2
  import { default as MLP } from './layers/MLP';
3
3
  import { default as TransformerBlock } from './layers/TransformerBlock';
4
4
  import { default as RoPECache } from './layers/RoPECache';
5
- export { default as NanoGPT } from './NanoGPTModel';
5
+ export { default as NanoGPT } from './models/NanoGPTV1';
6
6
  export { default as TeachableLLM } from './TeachableLLM';
7
7
  export { default as CharTokeniser } from './tokeniser/CharTokeniser';
8
8
  export { default as BPETokeniser } from './tokeniser/bpe';
9
9
  export { default as waitForModel } from './utilities/waitForModel';
10
10
  export { default as loadTextData } from './data/textLoader';
11
+ export { default as Generator } from './Generator';
11
12
  export type { ITrainerOptions } from './Trainer';
12
13
  export type { IGenerateOptions } from './Generator';
13
- export type { TrainingLogEntry } from './NanoGPTModel';
14
+ export { type ModelForwardAttributes, default as Model } from './models/model';
14
15
  export type { ITokeniser } from './tokeniser/type';
15
- export type { TrainingProgress } from './training/Trainer';
16
- export type { GPTConfig } from './config';
16
+ export type { TrainingProgress, TrainingLogEntry } from './training/Trainer';
17
+ export type { GPTConfig } from './models/config';
17
18
  export { estimateParameterCount, estimateMemoryUsage, estimateTrainingMemoryUsage, estimateResources, validateConfig, } from './utilities/parameters';
18
19
  export { selectBackend } from './backend';
19
20
  export { default as performanceTest } from './utilities/performance';
@@ -24,3 +25,4 @@ export declare const layers: {
24
25
  RoPECache: typeof RoPECache;
25
26
  };
26
27
  export { default as AdamExt } from './training/AdamExt';
28
+ export { default as checks } from './checks';
package/dist/main.js CHANGED
@@ -1,11 +1,13 @@
1
- import { default as W } from "./NanoGPTModel.js";
1
+ import { default as W } from "./models/NanoGPTV1.js";
2
2
  import { default as Y } from "./TeachableLLM.js";
3
3
  import { default as _ } from "./tokeniser/CharTokeniser.js";
4
4
  import { default as oo } from "./tokeniser/bpe.js";
5
5
  import { default as to } from "./utilities/waitForModel.js";
6
6
  import { default as eo } from "./data/textLoader.js";
7
- import { estimateMemoryUsage as po, estimateParameterCount as ao, estimateResources as fo, estimateTrainingMemoryUsage as so, validateConfig as lo } from "./utilities/parameters.js";
8
- import "./index-BoWRt-10.js";
7
+ import { default as io } from "./Generator.js";
8
+ import { default as fo } from "./models/model.js";
9
+ import { estimateMemoryUsage as lo, estimateParameterCount as xo, estimateResources as no, estimateTrainingMemoryUsage as uo, validateConfig as co } from "./utilities/parameters.js";
10
+ import "./index-DdmHGZjq.js";
9
11
  import "./ops/cpu/scatterSub.js";
10
12
  import "./ops/webgl/scatterSub.js";
11
13
  import "./ops/cpu/gatherSub.js";
@@ -16,10 +18,10 @@ import "./ops/grads/attentionMask.js";
16
18
  import "./ops/cpu/qkv.js";
17
19
  import "./ops/webgl/qkv.js";
18
20
  import "./ops/grads/qkv.js";
19
- import "./random_width-sZORGo5k.js";
20
- import "./register_all_kernels-BwDSRN-f.js";
21
+ import "./random_width-DKGeiFuR.js";
22
+ import "./register_all_kernels-Do9VvZmo.js";
21
23
  import "./index-Tf7vU29b.js";
22
- import "./dataset-CtdBYwjo.js";
24
+ import "./dataset-DPPl-iLT.js";
23
25
  import "./ops/cpu/rope.js";
24
26
  import "./ops/webgl/rope.js";
25
27
  import "./ops/grads/rope.js";
@@ -33,7 +35,7 @@ import "./ops/webgl/matMulGelu.js";
33
35
  import "./ops/grads/matMulGelu.js";
34
36
  import "./ops/cpu/gelu.js";
35
37
  import "./ops/webgl/gelu.js";
36
- import "./gelu-C-dPj6Ku.js";
38
+ import "./gelu-BkcmEEyD.js";
37
39
  import "./ops/cpu/normRMS.js";
38
40
  import "./ops/webgl/normRMS.js";
39
41
  import "./ops/grads/normRMS.js";
@@ -42,13 +44,14 @@ import "./ops/cpu/adamMoments.js";
42
44
  import "./ops/webgl/adamMoments.js";
43
45
  import "./ops/cpu/adamAdjust.js";
44
46
  import "./ops/webgl/adamAdjust.js";
45
- import { selectBackend as xo } from "./backend.js";
46
- import { default as co } from "./utilities/performance.js";
47
+ import { selectBackend as ko } from "./backend.js";
48
+ import { default as Co } from "./utilities/performance.js";
47
49
  import o from "./layers/CausalSelfAttention.js";
48
50
  import r from "./layers/MLP.js";
49
51
  import t from "./layers/TransformerBlock.js";
50
52
  import m from "./layers/RoPECache.js";
51
- import { default as ko } from "./training/AdamExt.js";
53
+ import { default as go } from "./training/AdamExt.js";
54
+ import { default as Bo } from "./checks/index.js";
52
55
  const O = {
53
56
  CausalSelfAttention: o,
54
57
  MLP: r,
@@ -56,19 +59,22 @@ const O = {
56
59
  RoPECache: m
57
60
  };
58
61
  export {
59
- ko as AdamExt,
62
+ go as AdamExt,
60
63
  oo as BPETokeniser,
61
64
  _ as CharTokeniser,
65
+ io as Generator,
66
+ fo as Model,
62
67
  W as NanoGPT,
63
68
  Y as TeachableLLM,
64
- po as estimateMemoryUsage,
65
- ao as estimateParameterCount,
66
- fo as estimateResources,
67
- so as estimateTrainingMemoryUsage,
69
+ Bo as checks,
70
+ lo as estimateMemoryUsage,
71
+ xo as estimateParameterCount,
72
+ no as estimateResources,
73
+ uo as estimateTrainingMemoryUsage,
68
74
  O as layers,
69
75
  eo as loadTextData,
70
- co as performanceTest,
71
- xo as selectBackend,
72
- lo as validateConfig,
76
+ Co as performanceTest,
77
+ ko as selectBackend,
78
+ co as validateConfig,
73
79
  to as waitForModel
74
80
  };
@@ -1,4 +1,4 @@
1
- import { B as m, C as s, I as c, E as M, J as p } from "./index-BoWRt-10.js";
1
+ import { C as m, D as s, Q as c, E as M, U as p } from "./index-DdmHGZjq.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -0,0 +1,27 @@
1
+ import { C as r, D as s, Q as m, E as c, Y as d } from "./index-DdmHGZjq.js";
2
+ /**
3
+ * @license
4
+ * Copyright 2020 Google LLC. All Rights Reserved.
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ * =============================================================================
17
+ */
18
+ function p(t, e) {
19
+ let o = s(t, "a", "mod"), a = s(e, "b", "mod");
20
+ [o, a] = m(o, a);
21
+ const n = { a: o, b: a };
22
+ return c.runKernel(d, n);
23
+ }
24
+ const b = /* @__PURE__ */ r({ mod_: p });
25
+ export {
26
+ b as m
27
+ };
@@ -0,0 +1,15 @@
1
+ import { GPTConfig } from './config';
2
+ import { Tensor } from '@tensorflow/tfjs-core';
3
+ import { default as Model, ModelForwardAttributes } from './model';
4
+ export default class NanoGPT extends Model<ModelForwardAttributes> {
5
+ private wte;
6
+ private wpe?;
7
+ private blocks;
8
+ private lnF;
9
+ private ropeCache?;
10
+ constructor(config?: Partial<GPTConfig>);
11
+ getClassName(): string;
12
+ private inputPhase;
13
+ forward(attrs: ModelForwardAttributes, idx: Tensor, targets?: Tensor): Tensor[];
14
+ dispose(): void;
15
+ }