@genai-fi/nanogpt 0.6.0 → 0.6.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.
Files changed (121) hide show
  1. package/dist/Generator.js +7 -7
  2. package/dist/NanoGPTModel.js +70 -121
  3. package/dist/RealDiv-BYViZwhN.js +540 -0
  4. package/dist/Reshape-t7Kcikjk.js +127 -0
  5. package/dist/TeachableLLM.d.ts +2 -0
  6. package/dist/TeachableLLM.js +34 -27
  7. package/dist/{TiedEmbedding-BhxWO8QR.js → TiedEmbedding-9WeDwvjO.js} +12 -13
  8. package/dist/{axis_util-D17qZRQm.js → axis_util-Bu4h7XWV.js} +14 -12
  9. package/dist/{broadcast_to-BMQLjvt_.js → broadcast_to-DARN-DBD.js} +2 -2
  10. package/dist/{concat-DhZfF1GY.js → concat-5aPGqw3Z.js} +3 -3
  11. package/dist/{dataset-oilnemHf.js → dataset-pgqp-YfL.js} +3 -3
  12. package/dist/{dropout-CrMQPCeG.js → dropout-Bciw46HT.js} +7 -7
  13. package/dist/{gather-DZCMHZuN.js → gather-DjyCjmOD.js} +1 -1
  14. package/dist/gpgpu_math-CNslybmD.js +3115 -0
  15. package/dist/{index-bMBtI-WR.js → index-BAzbokzv.js} +846 -649
  16. package/dist/{kernel_funcs_utils-CNmjLWnB.js → kernel_funcs_utils-CUxJCg0g.js} +232 -138
  17. package/dist/layers/BaseLayer.js +2 -2
  18. package/dist/layers/CausalSelfAttention.js +6 -6
  19. package/dist/layers/MLP.js +5 -5
  20. package/dist/layers/RMSNorm.js +3 -3
  21. package/dist/layers/RoPECache.js +13 -33
  22. package/dist/layers/TiedEmbedding.js +6 -7
  23. package/dist/layers/TransformerBlock.js +1 -1
  24. package/dist/loader/load.d.ts +13 -0
  25. package/dist/loader/load.js +27 -0
  26. package/dist/loader/loadHF.d.ts +7 -0
  27. package/dist/loader/loadHF.js +22 -0
  28. package/dist/{utilities/load.d.ts → loader/loadTransformers.d.ts} +11 -11
  29. package/dist/loader/loadTransformers.js +28 -0
  30. package/dist/loader/newZipLoad.d.ts +8 -0
  31. package/dist/loader/newZipLoad.js +21 -0
  32. package/dist/loader/oldZipLoad.d.ts +7 -0
  33. package/dist/loader/oldZipLoad.js +76 -0
  34. package/dist/{log_sum_exp-BHdkCb4s.js → log_sum_exp-YEo2h3gb.js} +14 -14
  35. package/dist/main.js +23 -20
  36. package/dist/{mat_mul-BsrLfy81.js → mat_mul-7121rsJk.js} +1 -1
  37. package/dist/{max-DechV4Bc.js → max-DtlIuVeW.js} +1 -1
  38. package/dist/mulmat_packed_gpu-D4nKF7Je.js +71 -0
  39. package/dist/{norm-B9hWHZH1.js → norm-CzltS9Fz.js} +16 -16
  40. package/dist/{ones-g0K8jVwm.js → ones-BBlSRqn1.js} +2 -2
  41. package/dist/ops/appendCache.js +3 -3
  42. package/dist/ops/attentionMask.js +1 -1
  43. package/dist/ops/cpu/appendCache.js +2 -2
  44. package/dist/ops/cpu/attentionMask.js +6 -6
  45. package/dist/ops/cpu/fusedSoftmax.js +2 -2
  46. package/dist/ops/cpu/gatherSub.js +9 -9
  47. package/dist/ops/cpu/gelu.js +1 -1
  48. package/dist/ops/cpu/matMulGelu.js +1 -1
  49. package/dist/ops/cpu/matMulMul.js +1 -1
  50. package/dist/ops/cpu/mulDropout.js +1 -1
  51. package/dist/ops/cpu/normRMS.js +1 -1
  52. package/dist/ops/cpu/qkv.js +3 -3
  53. package/dist/ops/cpu/rope.js +5 -5
  54. package/dist/ops/cpu/scatterSub.js +17 -48
  55. package/dist/ops/fusedSoftmax.js +1 -1
  56. package/dist/ops/gatherSub.js +1 -1
  57. package/dist/ops/gelu.js +1 -1
  58. package/dist/ops/grads/attentionMask.js +1 -1
  59. package/dist/ops/grads/fusedSoftmax.js +4 -4
  60. package/dist/ops/grads/gelu.js +1 -1
  61. package/dist/ops/grads/matMulGelu.js +1 -1
  62. package/dist/ops/grads/normRMS.js +1 -1
  63. package/dist/ops/grads/qkv.js +1 -1
  64. package/dist/ops/grads/rope.js +1 -1
  65. package/dist/ops/matMulGelu.js +1 -1
  66. package/dist/ops/matMulMul.js +1 -1
  67. package/dist/ops/mulDrop.js +1 -1
  68. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  69. package/dist/ops/normRMS.js +1 -1
  70. package/dist/ops/qkv.js +1 -1
  71. package/dist/ops/rope.js +8 -4
  72. package/dist/ops/scatterSub.js +1 -1
  73. package/dist/ops/webgl/appendCache.js +1 -1
  74. package/dist/ops/webgl/attentionMask.js +1 -1
  75. package/dist/ops/webgl/fusedSoftmax.js +29 -560
  76. package/dist/ops/webgl/gatherSub.js +1 -1
  77. package/dist/ops/webgl/gelu.js +2 -2
  78. package/dist/ops/webgl/log.js +3 -3
  79. package/dist/ops/webgl/matMulGelu.js +46 -113
  80. package/dist/ops/webgl/matMulMul.js +1 -1
  81. package/dist/ops/webgl/mulDropout.js +1 -1
  82. package/dist/ops/webgl/normRMS.js +2 -2
  83. package/dist/ops/webgl/qkv.js +1 -1
  84. package/dist/ops/webgl/rope.js +1 -1
  85. package/dist/ops/webgl/scatterSub.js +1 -1
  86. package/dist/{ops-Mv7Ta72x.js → ops-C0sQEcPw.js} +117 -109
  87. package/dist/{random_width-BBAWzDym.js → random_width-DWzaOgrn.js} +6925 -6291
  88. package/dist/{range-DMaG9A3G.js → range-DYsrnfiy.js} +1 -1
  89. package/dist/{gpgpu_math-Ctc31slO.js → reciprocal-CJQeasVa.js} +7 -5
  90. package/dist/register_all_kernels-BfFCQAqs.js +21397 -0
  91. package/dist/{reshape-T4yDEqoF.js → reshape-krWGKraP.js} +1 -1
  92. package/dist/scatter_nd_util-93ln7Hut.js +46 -0
  93. package/dist/selu_util-sntGesxr.js +740 -0
  94. package/dist/{shared-XNAoXhOa.js → shared-Ca6iDobD.js} +1462 -1089
  95. package/dist/{sin-EEhbrRO_.js → sin-D_h-qCSx.js} +1 -1
  96. package/dist/{softmax-B2_IKPDR.js → softmax-fsdtf6JC.js} +1 -1
  97. package/dist/{split-dcks18H1.js → split-eiktj-6L.js} +1 -1
  98. package/dist/{stack-lpJ5kYvE.js → stack-dfEEz2OY.js} +2 -2
  99. package/dist/{sum-CutF5lj2.js → sum-BE_Irnim.js} +1 -1
  100. package/dist/{tensor-C15NA2LA.js → tensor-Xyi595sG.js} +1 -1
  101. package/dist/{tensor2d-DZ_e5eKM.js → tensor2d-CPEkynbH.js} +1 -1
  102. package/dist/training/AdamExt.js +1 -1
  103. package/dist/training/DatasetBuilder.js +2 -2
  104. package/dist/training/FullTrainer.js +1 -1
  105. package/dist/training/Trainer.js +3 -3
  106. package/dist/training/sparseCrossEntropy.js +5 -5
  107. package/dist/utilities/dummy.d.ts +6 -0
  108. package/dist/utilities/dummy.js +31 -10
  109. package/dist/utilities/generate.js +3 -3
  110. package/dist/utilities/profile.d.ts +5 -0
  111. package/dist/utilities/profile.js +10 -7
  112. package/dist/utilities/safetensors.js +2 -2
  113. package/dist/utilities/save.js +1 -1
  114. package/dist/utilities/weights.js +2 -2
  115. package/dist/{variable-CdRKKp8x.js → variable-wSS22xj5.js} +1 -1
  116. package/dist/{zeros-CAbHfODe.js → zeros-YJDE7oRb.js} +4 -4
  117. package/package.json +2 -8
  118. package/dist/Reshape-CLOrdpve.js +0 -212
  119. package/dist/slice_util-Ddk0uxGJ.js +0 -49
  120. package/dist/tfjs_backend-BDb8r9qx.js +0 -1010
  121. package/dist/utilities/load.js +0 -99
@@ -0,0 +1,13 @@
1
+ import { default as NanoGPT } from '../NanoGPTModel';
2
+ import { ITokeniser } from '../tokeniser/type';
3
+ export declare const VERSION = 2;
4
+ export interface Metadata {
5
+ version: string;
6
+ application: string;
7
+ name?: string;
8
+ }
9
+ export declare function loadModel(data: Blob | Buffer | string): Promise<{
10
+ model: NanoGPT;
11
+ tokeniser: ITokeniser;
12
+ name?: string;
13
+ }>;
@@ -0,0 +1,27 @@
1
+ import { j as o } from "../jszip.min-CjP2V1VV.js";
2
+ import i from "./oldZipLoad.js";
3
+ import s from "./newZipLoad.js";
4
+ import n from "./loadHF.js";
5
+ const u = 2;
6
+ async function f(t) {
7
+ const e = await fetch(t);
8
+ if (!e.ok)
9
+ throw new Error(`Failed to fetch ${t}: ${e.statusText}`);
10
+ return e.arrayBuffer();
11
+ }
12
+ async function m(t) {
13
+ if (typeof t == "string")
14
+ if (t.startsWith("http://") || t.startsWith("https://")) {
15
+ const e = await f(t), r = await o.loadAsync(e);
16
+ return r.file("manifest.json") ? i(r) : s(r);
17
+ } else
18
+ return n(t);
19
+ else {
20
+ const e = await o.loadAsync(t);
21
+ return e.file("manifest.json") ? i(e) : s(e);
22
+ }
23
+ }
24
+ export {
25
+ u as VERSION,
26
+ m as loadModel
27
+ };
@@ -0,0 +1,7 @@
1
+ import { default as NanoGPT } from '../NanoGPTModel';
2
+ import { ITokeniser } from '../main';
3
+ export default function loadHuggingFace(name: string): Promise<{
4
+ model: NanoGPT;
5
+ tokeniser: ITokeniser;
6
+ name?: string;
7
+ }>;
@@ -0,0 +1,22 @@
1
+ import w from "./loadTransformers.js";
2
+ async function u(t) {
3
+ const r = `https://huggingface.co/${t}/resolve/main/config.json`, a = `https://huggingface.co/${t}/resolve/main/tokeniser.json`, i = `https://huggingface.co/${t}/resolve/main/meta.json`, c = `https://huggingface.co/${t}/resolve/main/model.safetensors`, [o, e, s, n] = await Promise.all([
4
+ fetch(r),
5
+ fetch(a),
6
+ fetch(i),
7
+ fetch(c)
8
+ ]);
9
+ if (!o.ok)
10
+ throw new Error(`Failed to fetch config from ${r}: ${o.statusText}`);
11
+ if (!e.ok)
12
+ throw new Error(`Failed to fetch tokeniser from ${a}: ${e.statusText}`);
13
+ if (!s.ok)
14
+ throw new Error(`Failed to fetch meta from ${i}: ${s.statusText}`);
15
+ if (!n.ok)
16
+ throw new Error(`Failed to fetch weights from ${c}: ${n.statusText}`);
17
+ const f = await o.json(), g = await e.json(), h = await s.json(), l = await n.arrayBuffer();
18
+ return w(f, g, h, l);
19
+ }
20
+ export {
21
+ u as default
22
+ };
@@ -1,7 +1,5 @@
1
- import { default as zip } from 'jszip';
2
- import { default as NanoGPT } from '../NanoGPTModel';
3
1
  import { ITokeniser } from '../tokeniser/type';
4
- export declare const VERSION = 2;
2
+ import { default as NanoGPT } from '../NanoGPTModel';
5
3
  export interface TransformersConfig {
6
4
  model_type: string;
7
5
  vocab_size: number;
@@ -15,16 +13,18 @@ export interface TransformersConfig {
15
13
  mlpFactor: number;
16
14
  useRope: boolean;
17
15
  }
18
- export interface Metadata {
19
- version: string;
20
- application: string;
16
+ export interface TransformersTokeniser {
17
+ type: 'char' | 'bpe';
18
+ vocab: string[];
19
+ merges: [string, string][];
20
+ }
21
+ export interface TransformersMetadata {
21
22
  name?: string;
23
+ version: number;
24
+ application: string;
25
+ [key: string]: unknown;
22
26
  }
23
- export declare function loadOldModel(zipFile: zip): Promise<{
24
- model: NanoGPT;
25
- tokeniser: ITokeniser;
26
- }>;
27
- export declare function loadModel(data: Blob | Buffer | string): Promise<{
27
+ export default function loadTransformers(config: TransformersConfig, tokeniser: TransformersTokeniser, metadata: TransformersMetadata, weightData: ArrayBuffer): Promise<{
28
28
  model: NanoGPT;
29
29
  tokeniser: ITokeniser;
30
30
  name?: string;
@@ -0,0 +1,28 @@
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 { U as y } from "../index-BAzbokzv.js";
6
+ import { dummyPassAsync as h } from "../utilities/dummy.js";
7
+ async function L(e, a, r, t) {
8
+ const n = {
9
+ vocabSize: e.vocab_size,
10
+ blockSize: e.block_size,
11
+ nLayer: e.num_hidden_layers,
12
+ nHead: e.num_attention_heads,
13
+ nEmbed: e.hidden_size,
14
+ dropout: e.dropout,
15
+ biasInLinear: e.biasInLinear,
16
+ biasInLayerNorm: e.biasInLayerNorm,
17
+ mlpFactor: e.mlpFactor,
18
+ 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
+ for (const [p, d] of Object.entries(i))
21
+ s.set(p, [d]);
22
+ y();
23
+ const o = new b(n);
24
+ return await h(o), o.loadWeights(s), { model: o, tokeniser: m, name: r.name };
25
+ }
26
+ export {
27
+ L as default
28
+ };
@@ -0,0 +1,8 @@
1
+ import { ITokeniser } from '../main';
2
+ import { default as NanoGPT } from '../NanoGPTModel';
3
+ import { default as zip } from 'jszip';
4
+ export default function loadZipFile(zipFile: zip): Promise<{
5
+ model: NanoGPT;
6
+ tokeniser: ITokeniser;
7
+ name?: string;
8
+ }>;
@@ -0,0 +1,21 @@
1
+ import c from "./loadTransformers.js";
2
+ async function g(r) {
3
+ const e = await r.file("config.json")?.async("string");
4
+ if (!e)
5
+ throw new Error("Config file not found in the zip archive");
6
+ const t = JSON.parse(e), n = await r.file("tokeniser.json")?.async("string");
7
+ if (!n)
8
+ throw new Error("Tokeniser file not found in the zip archive");
9
+ const i = JSON.parse(n), s = await r.file("model.safetensors").async("arraybuffer"), o = await r.file("meta.json")?.async("string");
10
+ let a = { version: 0, application: "" };
11
+ if (o)
12
+ try {
13
+ a = JSON.parse(o);
14
+ } catch (f) {
15
+ console.error("Error parsing meta file:", f);
16
+ }
17
+ return c(t, i, a, s);
18
+ }
19
+ export {
20
+ g as default
21
+ };
@@ -0,0 +1,7 @@
1
+ import { default as zip } from 'jszip';
2
+ import { ITokeniser } from '../main';
3
+ import { default as NanoGPT } from '../NanoGPTModel';
4
+ export default function loadOldModel(zipFile: zip): Promise<{
5
+ model: NanoGPT;
6
+ tokeniser: ITokeniser;
7
+ }>;
@@ -0,0 +1,76 @@
1
+ import d from "../NanoGPTModel.js";
2
+ import "../jszip.min-CjP2V1VV.js";
3
+ import h from "../tokeniser/CharTokeniser.js";
4
+ import { U as k } from "../index-BAzbokzv.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-pgqp-YfL.js";
10
+ import "../index-Tf7vU29b.js";
11
+ import "../papaparse.min-C8l2Kvo1.js";
12
+ import "../ops/cpu/scatterSub.js";
13
+ import "../ops/webgl/scatterSub.js";
14
+ import "../ops/cpu/gatherSub.js";
15
+ import "../ops/webgl/gatherSub.js";
16
+ import "../ops/cpu/attentionMask.js";
17
+ import "../ops/webgl/attentionMask.js";
18
+ import "../ops/grads/attentionMask.js";
19
+ import "../ops/cpu/qkv.js";
20
+ import "../ops/webgl/qkv.js";
21
+ import "../ops/grads/qkv.js";
22
+ import "../random_width-DWzaOgrn.js";
23
+ import "../register_all_kernels-BfFCQAqs.js";
24
+ import "../ops/cpu/rope.js";
25
+ import "../ops/webgl/rope.js";
26
+ import "../ops/grads/rope.js";
27
+ import "../ops/cpu/appendCache.js";
28
+ import "../ops/webgl/appendCache.js";
29
+ import "../ops/cpu/fusedSoftmax.js";
30
+ import "../ops/webgl/fusedSoftmax.js";
31
+ import "../ops/grads/fusedSoftmax.js";
32
+ import "../ops/cpu/matMulGelu.js";
33
+ import "../ops/webgl/matMulGelu.js";
34
+ import "../ops/grads/matMulGelu.js";
35
+ import "../ops/cpu/gelu.js";
36
+ import "../ops/webgl/gelu.js";
37
+ import "../ops/grads/gelu.js";
38
+ import "../ops/cpu/normRMS.js";
39
+ import "../ops/webgl/normRMS.js";
40
+ import "../ops/grads/normRMS.js";
41
+ import "../ops/webgl/log.js";
42
+ import { importWeights as O } from "../utilities/weights.js";
43
+ async function ft(o) {
44
+ const n = /* @__PURE__ */ new Map(), s = await o.file("manifest.json")?.async("string");
45
+ if (!s)
46
+ throw new Error("Manifest file not found in the zip archive");
47
+ const m = JSON.parse(s);
48
+ for (const [t, r] of Object.entries(m.weightSpec))
49
+ n.set(t, { spec: r, data: new Float32Array() });
50
+ const p = await o.file("tokeniser.json")?.async("string");
51
+ if (!p)
52
+ throw new Error("Tokeniser file not found in the zip archive");
53
+ const i = JSON.parse(p), l = (i.type ?? "char") === "char" ? new h(i.vocab) : new b(i.vocab, i.merges), c = /* @__PURE__ */ new Map();
54
+ for (const t of Object.keys(o.files))
55
+ if (t.endsWith(".bin")) {
56
+ const r = t.replace(".bin", ""), w = await o.file(t).async("arraybuffer"), g = new Float32Array(w), a = n.get(r) || { spec: [], data: new Float32Array() };
57
+ a.data = g, n.set(r, a);
58
+ const y = await O(a);
59
+ c.set(r, y);
60
+ }
61
+ k();
62
+ const e = new d(m.config);
63
+ await u(e), e.loadWeights(c);
64
+ const f = await o.file("log.json")?.async("string");
65
+ if (f)
66
+ try {
67
+ const t = JSON.parse(f);
68
+ e.log = t;
69
+ } catch (t) {
70
+ throw console.error("Error parsing training log:", t), new Error(`Failed to parse training log: ${t}`);
71
+ }
72
+ return { model: e, tokeniser: l };
73
+ }
74
+ export {
75
+ ft as default
76
+ };
@@ -1,8 +1,8 @@
1
- import { o as r, j as p, E as u, a6 as E, a7 as h, a1 as S, s as $, a8 as d } from "./index-bMBtI-WR.js";
2
- import { e as K } from "./axis_util-D17qZRQm.js";
3
- import { m as T } from "./max-DechV4Bc.js";
4
- import { r as m } from "./reshape-T4yDEqoF.js";
5
- import { s as _ } from "./sum-CutF5lj2.js";
1
+ import { o as r, q as p, E as u, a8 as E, a9 as h, p as S, b as $, a7 as d } from "./index-BAzbokzv.js";
2
+ import { e as b } from "./axis_util-Bu4h7XWV.js";
3
+ import { m as K } from "./max-DtlIuVeW.js";
4
+ import { r as m } from "./reshape-krWGKraP.js";
5
+ import { s as T } from "./sum-BE_Irnim.js";
6
6
  /**
7
7
  * @license
8
8
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -19,11 +19,11 @@ import { s as _ } from "./sum-CutF5lj2.js";
19
19
  * limitations under the License.
20
20
  * =============================================================================
21
21
  */
22
- function b(s) {
22
+ function _(s) {
23
23
  const o = { x: p(s, "x", "exp") };
24
24
  return u.runKernel(E, o);
25
25
  }
26
- const N = /* @__PURE__ */ r({ exp_: b });
26
+ const N = /* @__PURE__ */ r({ exp_: _ });
27
27
  /**
28
28
  * @license
29
29
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -40,11 +40,11 @@ const N = /* @__PURE__ */ r({ exp_: b });
40
40
  * limitations under the License.
41
41
  * =============================================================================
42
42
  */
43
- function j(s) {
43
+ function q(s) {
44
44
  const o = { x: p(s, "x", "log", "float32") };
45
45
  return u.runKernel(h, o);
46
46
  }
47
- const v = /* @__PURE__ */ r({ log_: j });
47
+ const v = /* @__PURE__ */ r({ log_: q });
48
48
  /**
49
49
  * @license
50
50
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -61,15 +61,15 @@ const v = /* @__PURE__ */ r({ log_: j });
61
61
  * limitations under the License.
62
62
  * =============================================================================
63
63
  */
64
- function w(s, a = null, o = !1) {
65
- const n = p(s, "x", "logSumExp"), t = S(a, n.shape), x = T(
66
- n,
64
+ function w(s, n = null, o = !1) {
65
+ const a = p(s, "x", "logSumExp"), t = S(n, a.shape), x = K(
66
+ a,
67
67
  t,
68
68
  !0
69
69
  /* keepDims */
70
- ), i = $(n, x), l = N(i), f = _(l, t), c = v(f), e = d(m(x, c.shape), c);
70
+ ), i = $(a, x), l = N(i), f = T(l, t), c = v(f), e = d(m(x, c.shape), c);
71
71
  if (o) {
72
- const g = K(e.shape, t);
72
+ const g = b(e.shape, t);
73
73
  return m(e, g);
74
74
  }
75
75
  return e;
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- import { default as F } from "./NanoGPTModel.js";
2
- import { default as N } from "./TeachableLLM.js";
3
- import { default as j } from "./tokeniser/CharTokeniser.js";
4
- import { default as z } from "./tokeniser/bpe.js";
5
- import { default as H } from "./utilities/waitForModel.js";
6
- import { default as J } from "./data/textLoader.js";
7
- import { estimateMemoryUsage as O, estimateParameterCount as Q, estimateResources as S, estimateTrainingMemoryUsage as V, validateConfig as W } from "./utilities/parameters.js";
8
- import "./index-bMBtI-WR.js";
1
+ import { default as R } from "./NanoGPTModel.js";
2
+ import { default as q } from "./TeachableLLM.js";
3
+ import { default as A } from "./tokeniser/CharTokeniser.js";
4
+ import { default as I } from "./tokeniser/bpe.js";
5
+ import { default as K } from "./utilities/waitForModel.js";
6
+ import { default as Q } from "./data/textLoader.js";
7
+ import { estimateMemoryUsage as V, estimateParameterCount as W, estimateResources as X, estimateTrainingMemoryUsage as Y, validateConfig as Z } from "./utilities/parameters.js";
8
+ import "./index-BAzbokzv.js";
9
9
  import "./ops/cpu/scatterSub.js";
10
10
  import "./ops/webgl/scatterSub.js";
11
11
  import "./ops/cpu/gatherSub.js";
@@ -16,7 +16,10 @@ import "./ops/grads/attentionMask.js";
16
16
  import "./ops/cpu/qkv.js";
17
17
  import "./ops/webgl/qkv.js";
18
18
  import "./ops/grads/qkv.js";
19
- import "@tensorflow/tfjs";
19
+ import "./random_width-DWzaOgrn.js";
20
+ import "./register_all_kernels-BfFCQAqs.js";
21
+ import "./index-Tf7vU29b.js";
22
+ import "./dataset-pgqp-YfL.js";
20
23
  import "./ops/cpu/rope.js";
21
24
  import "./ops/webgl/rope.js";
22
25
  import "./ops/grads/rope.js";
@@ -36,15 +39,15 @@ import "./ops/webgl/normRMS.js";
36
39
  import "./ops/grads/normRMS.js";
37
40
  import "./ops/webgl/log.js";
38
41
  export {
39
- z as BPETokeniser,
40
- j as CharTokeniser,
41
- F as NanoGPT,
42
- N as TeachableLLM,
43
- O as estimateMemoryUsage,
44
- Q as estimateParameterCount,
45
- S as estimateResources,
46
- V as estimateTrainingMemoryUsage,
47
- J as loadTextData,
48
- W as validateConfig,
49
- H as waitForModel
42
+ I as BPETokeniser,
43
+ A as CharTokeniser,
44
+ R as NanoGPT,
45
+ q as TeachableLLM,
46
+ V as estimateMemoryUsage,
47
+ W as estimateParameterCount,
48
+ X as estimateResources,
49
+ Y as estimateTrainingMemoryUsage,
50
+ Q as loadTextData,
51
+ Z as validateConfig,
52
+ K as waitForModel
50
53
  };
@@ -1,4 +1,4 @@
1
- import { o as m, j as s, u as c, E as M, B as p } from "./index-bMBtI-WR.js";
1
+ import { o as m, q as s, B as c, E as M, C as p } from "./index-BAzbokzv.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { o as r, j as e, E as x, M as c } from "./index-bMBtI-WR.js";
1
+ import { o as r, q as e, E as x, M as c } from "./index-BAzbokzv.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -0,0 +1,71 @@
1
+ import { u as z } from "./gpgpu_math-CNslybmD.js";
2
+ /**
3
+ * @license
4
+ * Copyright 2018 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
+ class g {
19
+ constructor(e, s, v, a = !1, r = !1, c = !1, t = null, o = !1, l = !1) {
20
+ this.variableNames = ["matrixA", "matrixB"], this.packedInputs = !0, this.packedOutput = !0, this.outputShape = v, this.enableShapeUniforms = z(this.outputShape.length);
21
+ const m = a ? e[1] : e[2], u = Math.ceil(m / 2), b = a ? "i * 2, rc.y" : "rc.y, i * 2", x = r ? "rc.z, i * 2" : "i * 2, rc.z", n = a ? ["a.xxyy", "a.zzww"] : ["a.xxzz", "a.yyww"], p = r ? ["b.xzxz", "b.ywyw"] : ["b.xyxy", "b.zwzw"];
22
+ let i = "", h = "";
23
+ t && (o ? i = `vec4 activation(vec4 a) {
24
+ vec4 b = getPreluActivationWeightsAtOutCoords();
25
+ ${t}
26
+ }` : l ? i = `vec4 activation(vec4 a) {
27
+ vec4 b = getLeakyreluAlphaAtOutCoords();
28
+ ${t}
29
+ }` : i = `vec4 activation(vec4 x) {
30
+ ${t}
31
+ }`, h = "result = activation(result);");
32
+ const $ = c ? "result += getBiasAtOutCoords();" : "";
33
+ c && this.variableNames.push("bias"), o && this.variableNames.push("preluActivationWeights"), l && this.variableNames.push("leakyreluAlpha");
34
+ let d = "rc.x", f = "rc.x";
35
+ e[0] < s[0] ? d = `imod(rc.x, ${e[0]})` : s[0] < e[0] && (f = `imod(rc.x, ${s[0]})`), this.userCode = `
36
+ ${i}
37
+ // Don't use uniform for sharedDimensionPacked for performance.
38
+ const float sharedDimension = ${u}.0;
39
+
40
+ vec4 dot2x2ARowBCol(ivec3 rc) {
41
+ vec4 result = vec4(0);
42
+ int batchA = ${d};
43
+ int batchB = ${f};
44
+ for (int i = 0; i < ${u}; i++) {
45
+ vec4 a = getMatrixA(batchA, ${b});
46
+ vec4 b = getMatrixB(batchB, ${x});
47
+
48
+ // These swizzled products need to be separately added.
49
+ // See: https://github.com/tensorflow/tfjs/issues/1735
50
+ result += (${n[0]} * ${p[0]});
51
+ result += (${n[1]} * ${p[1]});
52
+ }
53
+ return result;
54
+ }
55
+
56
+ void main() {
57
+ ivec3 rc = getOutputCoords();
58
+ vec4 result = dot2x2ARowBCol(rc);
59
+
60
+ ${$}
61
+
62
+ ${h}
63
+
64
+ setOutput(result);
65
+ }
66
+ `;
67
+ }
68
+ }
69
+ export {
70
+ g as M
71
+ };
@@ -1,8 +1,8 @@
1
- import { o as l, j as c, E as y, a0 as E, a1 as w, a2 as o, a3 as u, W as v, f as I, a4 as A } from "./index-bMBtI-WR.js";
2
- import { e as $ } from "./axis_util-D17qZRQm.js";
3
- import { m as f } from "./max-DechV4Bc.js";
4
- import { r as h } from "./reshape-T4yDEqoF.js";
5
- import { s as t } from "./sum-CutF5lj2.js";
1
+ import { o as l, q as c, E as y, a2 as E, p as w, a3 as o, a4 as u, j as v, s as I, a5 as A } from "./index-BAzbokzv.js";
2
+ import { e as $ } from "./axis_util-Bu4h7XWV.js";
3
+ import { m } from "./max-DtlIuVeW.js";
4
+ import { r as h } from "./reshape-krWGKraP.js";
5
+ import { s as t } from "./sum-BE_Irnim.js";
6
6
  /**
7
7
  * @license
8
8
  * Copyright 2020 Google Inc. All Rights Reserved.
@@ -40,26 +40,26 @@ const s = /* @__PURE__ */ l({ min_: k });
40
40
  * limitations under the License.
41
41
  * =============================================================================
42
42
  */
43
- function T(n, e = "euclidean", r = null, m = !1) {
43
+ function q(n, e = "euclidean", r = null, f = !1) {
44
44
  n = c(n, "x", "norm");
45
- const a = d(n, e, r);
45
+ const a = p(n, e, r);
46
46
  let i = a.shape;
47
- if (m) {
48
- const p = w(r, n.shape);
49
- i = $(a.shape, p);
47
+ if (f) {
48
+ const d = w(r, n.shape);
49
+ i = $(a.shape, d);
50
50
  }
51
51
  return h(a, i);
52
52
  }
53
- function d(n, e, r = null) {
53
+ function p(n, e, r = null) {
54
54
  if (n.rank === 0)
55
55
  return o(n);
56
56
  if (n.rank !== 1 && r === null)
57
- return d(h(n, [-1]), e, r);
57
+ return p(h(n, [-1]), e, r);
58
58
  if (n.rank === 1 || typeof r == "number" || Array.isArray(r) && r.length === 1) {
59
59
  if (e === 1)
60
60
  return t(o(n), r);
61
61
  if (e === 1 / 0)
62
- return f(o(n), r);
62
+ return m(o(n), r);
63
63
  if (e === -1 / 0)
64
64
  return s(o(n), r);
65
65
  if (e === "euclidean" || e === 2)
@@ -68,9 +68,9 @@ function d(n, e, r = null) {
68
68
  }
69
69
  if (Array.isArray(r) && r.length === 2) {
70
70
  if (e === 1)
71
- return f(t(o(n), r[0]), r[1] - 1);
71
+ return m(t(o(n), r[0]), r[1] - 1);
72
72
  if (e === 1 / 0)
73
- return f(t(o(n), r[1]), r[0]);
73
+ return m(t(o(n), r[1]), r[0]);
74
74
  if (e === -1 / 0)
75
75
  return s(t(o(n), r[1]), r[0]);
76
76
  if (e === "fro" || e === "euclidean")
@@ -79,7 +79,7 @@ function d(n, e, r = null) {
79
79
  }
80
80
  throw new Error(`Error in norm: invalid axis: ${r}`);
81
81
  }
82
- const N = /* @__PURE__ */ l({ norm_: T });
82
+ const N = /* @__PURE__ */ l({ norm_: q });
83
83
  export {
84
84
  s as m,
85
85
  N as n
@@ -1,5 +1,5 @@
1
- import { n, p as t, q as m, E as i } from "./index-bMBtI-WR.js";
2
- import { z as c, c as f } from "./zeros-CAbHfODe.js";
1
+ import { x as n, y as t, g as m, E as i } from "./index-BAzbokzv.js";
2
+ import { z as c, c as f } from "./zeros-YJDE7oRb.js";
3
3
  /**
4
4
  * @license
5
5
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,8 +1,8 @@
1
- import { e as a } from "../index-bMBtI-WR.js";
1
+ import { e as a } from "../index-BAzbokzv.js";
2
2
  import "./cpu/appendCache.js";
3
3
  import "./webgl/appendCache.js";
4
- import { c as s } from "../concat-DhZfF1GY.js";
5
- import { z as c } from "../zeros-CAbHfODe.js";
4
+ import { c as s } from "../concat-5aPGqw3Z.js";
5
+ import { z as c } from "../zeros-YJDE7oRb.js";
6
6
  function i(r, p, n, o) {
7
7
  if (!o) {
8
8
  const e = r.shape[2];
@@ -1,4 +1,4 @@
1
- import { e as o } from "../index-bMBtI-WR.js";
1
+ import { e as o } from "../index-BAzbokzv.js";
2
2
  import "./cpu/attentionMask.js";
3
3
  import "./webgl/attentionMask.js";
4
4
  import "./grads/attentionMask.js";
@@ -1,5 +1,5 @@
1
- import { r as d } from "../../index-bMBtI-WR.js";
2
- import { c as h } from "../../concat-DhZfF1GY.js";
1
+ import { r as d } from "../../index-BAzbokzv.js";
2
+ import { c as h } from "../../concat-5aPGqw3Z.js";
3
3
  function u(p) {
4
4
  const { cache: n, item: s } = p.inputs, { maxSize: r, pastLen: c } = p.attrs, t = n.shape[0], o = n.shape[1], a = n.shape[3], e = s.shape[2];
5
5
  if (c + e <= r) {
@@ -1,10 +1,10 @@
1
- import { r as a, g as p, f as u } from "../../index-bMBtI-WR.js";
2
- import { l as N, w as b } from "../../ops-Mv7Ta72x.js";
3
- import { o as g } from "../../ones-g0K8jVwm.js";
4
- import { z as A } from "../../zeros-CAbHfODe.js";
5
- import { m as I } from "../../mat_mul-BsrLfy81.js";
1
+ import { r as a, f as p, s as u } from "../../index-BAzbokzv.js";
2
+ import { l as N, w as b } from "../../ops-C0sQEcPw.js";
3
+ import { o as A } from "../../ones-BBlSRqn1.js";
4
+ import { z as I } from "../../zeros-YJDE7oRb.js";
5
+ import { m as g } from "../../mat_mul-7121rsJk.js";
6
6
  function o(n) {
7
- const { q: s, k: e } = n.inputs, { divisor: r } = n.attrs, c = s.shape[2], t = e.shape[2], m = N.bandPart(g([t, t]), -1, 0).cast("bool"), l = A([t, t]), i = p([t, t], Number.NEGATIVE_INFINITY), f = b(m, l, i), k = I(s, e, !1, !0).mul(u(r)), d = f.slice([0, 0], [c, t]).expandDims(0).expandDims(0);
7
+ const { q: s, k: e } = n.inputs, { divisor: r } = n.attrs, c = s.shape[2], t = e.shape[2], m = N.bandPart(A([t, t]), -1, 0).cast("bool"), l = I([t, t]), i = p([t, t], Number.NEGATIVE_INFINITY), f = b(m, l, i), k = g(s, e, !1, !0).mul(u(r)), d = f.slice([0, 0], [c, t]).expandDims(0).expandDims(0);
8
8
  return k.add(d);
9
9
  }
10
10
  const w = {
@@ -1,5 +1,5 @@
1
- import { r as n } from "../../index-bMBtI-WR.js";
2
- import { s as f } from "../../softmax-B2_IKPDR.js";
1
+ import { r as n } from "../../index-BAzbokzv.js";
2
+ import { s as f } from "../../softmax-fsdtf6JC.js";
3
3
  function r(t) {
4
4
  const { inputs: s, attrs: i } = t, { logits: o } = s, { dim: a, dropoutRate: e } = i;
5
5
  if (!o)
@@ -1,6 +1,6 @@
1
- import { o as u, j as c, E as g, O as h, r as m, s as p } from "../../index-bMBtI-WR.js";
2
- import { r as l } from "../../range-DMaG9A3G.js";
3
- import { s as N } from "../../stack-lpJ5kYvE.js";
1
+ import { o as u, q as c, E as g, Y as h, r as m, b as p } from "../../index-BAzbokzv.js";
2
+ import { r as l } from "../../range-DYsrnfiy.js";
3
+ import { s as N } from "../../stack-dfEEz2OY.js";
4
4
  /**
5
5
  * @license
6
6
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -17,14 +17,14 @@ import { s as N } from "../../stack-lpJ5kYvE.js";
17
17
  * limitations under the License.
18
18
  * =============================================================================
19
19
  */
20
- function f(e, s) {
21
- const n = c(s, "indices", "gatherND", "int32"), t = { params: c(e, "x", "gatherND", "string_or_numeric"), indices: n };
22
- return g.runKernel(h, t);
20
+ function b(e, t) {
21
+ const n = c(t, "indices", "gatherND", "int32"), s = { params: c(e, "x", "gatherND", "string_or_numeric"), indices: n };
22
+ return g.runKernel(h, s);
23
23
  }
24
- const b = /* @__PURE__ */ u({ gatherND_: f });
24
+ const f = /* @__PURE__ */ u({ gatherND_: b });
25
25
  function d(e) {
26
- const { values: s, labels: n, logits: r } = e.inputs, t = n.shape[0], o = l(0, t, 1, "int32"), a = N([o, n], 1), i = b(r, a);
27
- return p(s, i);
26
+ const { values: t, labels: n, logits: r } = e.inputs, s = n.shape[0], o = l(0, s, 1, "int32"), a = N([o, n], 1), i = f(r, a);
27
+ return p(t, i);
28
28
  }
29
29
  const k = {
30
30
  kernelName: "EfficientGatherSub",
@@ -1,4 +1,4 @@
1
- import { r as t, t as d } from "../../index-bMBtI-WR.js";
1
+ import { r as t, t as d } from "../../index-BAzbokzv.js";
2
2
  const o = 0.7978845608028654, c = 0.044715;
3
3
  function m(u) {
4
4
  const { inputs: l } = u, { x: e } = l, n = e;
@@ -1,4 +1,4 @@
1
- import { r as a, t as i } from "../../index-bMBtI-WR.js";
1
+ import { r as a, t as i } from "../../index-BAzbokzv.js";
2
2
  const c = 0.7978845608028654, m = 0.044715;
3
3
  function M(o) {
4
4
  const { inputs: s } = o, { x: t, kernel: l } = s, e = t, u = l;