@genai-fi/nanogpt 0.20.7 → 0.22.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 (230) hide show
  1. package/dist/{BaseTokeniser-DSg9zcYq.js → BaseTokeniser-C9TSv4th.js} +1 -1
  2. package/dist/{DatasetBuilder-DgURD85T.js → DatasetBuilder-Ctb425Id.js} +117 -123
  3. package/dist/Generator.js +1 -1
  4. package/dist/{RealDiv-DBu0FQqT.js → RealDiv-CNsvC4AU.js} +6 -6
  5. package/dist/{Reshape-DqO3r8BC.js → Reshape-CwxdaU8n.js} +1 -1
  6. package/dist/{Reshape-CABOPB9d.js → Reshape-dnm9bO3B.js} +2 -2
  7. package/dist/TeachableLLM.d.ts +2 -1
  8. package/dist/TeachableLLM.js +1 -1
  9. package/dist/Trainer.d.ts +1 -1
  10. package/dist/Trainer.js +1 -1
  11. package/dist/backend.js +2 -2
  12. package/dist/{backend_util-Cg-roD1p.js → backend_util-DAV0I34P.js} +5 -5
  13. package/dist/checks/appendCache.js +1 -1
  14. package/dist/checks/attentionMask.js +1 -1
  15. package/dist/checks/gelu.js +1 -1
  16. package/dist/checks/matMulGelu.js +1 -1
  17. package/dist/checks/normRMS.js +1 -1
  18. package/dist/checks/normRMSGrad.js +1 -1
  19. package/dist/checks/packUnpack.js +1 -1
  20. package/dist/checks/qkv.js +1 -1
  21. package/dist/checks/rope.js +1 -1
  22. package/dist/{chunk-BPntVaq0.js → chunk-CWhphoD1.js} +5 -5
  23. package/dist/{concat_util-CWDZCBlA.js → concat_util-CWzvQQlK.js} +1 -1
  24. package/dist/data/docx.js +58 -59
  25. package/dist/data/pdf.js +1 -1
  26. package/dist/data/stream.d.ts +24 -0
  27. package/dist/data/stream.js +2 -0
  28. package/dist/data/textLoader.d.ts +2 -2
  29. package/dist/data/textLoader.js +29 -68
  30. package/dist/{dist-DVmq73nz.js → dist-9wGF4ci9.js} +10 -10
  31. package/dist/{dist-VEU5mfO0.js → dist-BqAU9-yi.js} +4 -4
  32. package/dist/{dist-BewPQWjc.js → dist-Da20xy8E.js} +1874 -3071
  33. package/dist/{gelu-Bf1HW1RY.js → gelu-B6637MKa.js} +1 -1
  34. package/dist/{gpgpu_math-DvLcCH6u.js → gpgpu_math-DBYEAAdI.js} +2 -2
  35. package/dist/{kernel_funcs_utils-HiXOOx3f.js → kernel_funcs_utils-D-mATnGR.js} +3 -3
  36. package/dist/layers/BaseLayer.js +1 -1
  37. package/dist/layers/CausalSelfAttention.js +4 -4
  38. package/dist/layers/LoRA.js +3 -3
  39. package/dist/layers/MLP.js +2 -2
  40. package/dist/layers/PositionEmbedding.js +2 -2
  41. package/dist/layers/RMSNorm.js +1 -1
  42. package/dist/layers/RoPECache.js +1 -1
  43. package/dist/layers/TiedEmbedding.js +3 -3
  44. package/dist/layers/TransformerBlock.js +1 -1
  45. package/dist/layers/WeightStore.js +3 -3
  46. package/dist/loader/load.js +1 -1
  47. package/dist/loader/loadHF.js +1 -1
  48. package/dist/loader/loadTransformers.js +1 -1
  49. package/dist/loader/loadZipMeta.js +1 -1
  50. package/dist/loader/newZipLoad.js +1 -1
  51. package/dist/loader/oldZipLoad.js +1 -1
  52. package/dist/loader/save.d.ts +1 -0
  53. package/dist/loader/save.js +1 -1
  54. package/dist/{main-BTmbwF1h.js → main-Bgc7_9kb.js} +2012 -2016
  55. package/dist/main.d.ts +3 -0
  56. package/dist/main.js +13 -11
  57. package/dist/{matMul16-BNfZSnNM.js → matMul16-DGtlziMn.js} +3 -3
  58. package/dist/{matMulGelu-CPTntosE.js → matMulGelu-BAIgQaRx.js} +3 -3
  59. package/dist/models/NanoGPTV1.js +1 -1
  60. package/dist/models/NanoGPTV2.js +1 -1
  61. package/dist/models/factory.js +1 -1
  62. package/dist/models/model.js +1 -1
  63. package/dist/ops/adamAdjust.js +1 -1
  64. package/dist/ops/adamMoments.js +1 -1
  65. package/dist/ops/add16.js +1 -1
  66. package/dist/ops/appendCache.js +1 -1
  67. package/dist/ops/attentionMask.js +1 -1
  68. package/dist/ops/concat16.js +1 -1
  69. package/dist/ops/cpu/adamAdjust.js +1 -1
  70. package/dist/ops/cpu/adamMoments.js +1 -1
  71. package/dist/ops/cpu/appendCache.js +1 -1
  72. package/dist/ops/cpu/attentionMask.js +1 -1
  73. package/dist/ops/cpu/fusedSoftmax.js +1 -1
  74. package/dist/ops/cpu/gatherSub.js +1 -1
  75. package/dist/ops/cpu/gelu.js +1 -1
  76. package/dist/ops/cpu/matMul16.js +1 -1
  77. package/dist/ops/cpu/matMulGelu.js +2 -2
  78. package/dist/ops/cpu/matMulMul.js +1 -1
  79. package/dist/ops/cpu/mulDropout.js +1 -1
  80. package/dist/ops/cpu/normRMS.js +1 -1
  81. package/dist/ops/cpu/qkv.js +1 -1
  82. package/dist/ops/cpu/rope.js +1 -1
  83. package/dist/ops/cpu/scatterSub.js +1 -1
  84. package/dist/ops/dot16.js +2 -2
  85. package/dist/ops/dropout.js +1 -1
  86. package/dist/ops/dropout16.js +1 -1
  87. package/dist/ops/gatherSub.js +1 -1
  88. package/dist/ops/gelu.js +1 -1
  89. package/dist/ops/globalNorm.js +1 -1
  90. package/dist/ops/grads/add16.js +1 -1
  91. package/dist/ops/grads/attentionMask.js +2 -2
  92. package/dist/ops/grads/gelu.js +1 -1
  93. package/dist/ops/grads/matMul16.js +1 -1
  94. package/dist/ops/grads/matMulGelu.js +1 -1
  95. package/dist/ops/grads/normRMS.js +1 -1
  96. package/dist/ops/grads/pack16.js +1 -1
  97. package/dist/ops/grads/qkv.js +2 -2
  98. package/dist/ops/grads/rope.js +1 -1
  99. package/dist/ops/grads/softmax16.js +1 -1
  100. package/dist/ops/grads/unpack16.js +1 -1
  101. package/dist/ops/matMul16.js +1 -1
  102. package/dist/ops/matMulGelu.js +2 -2
  103. package/dist/ops/matMulMul.js +1 -1
  104. package/dist/ops/mul16.js +1 -1
  105. package/dist/ops/mulDrop.js +1 -1
  106. package/dist/ops/normRMS.js +1 -1
  107. package/dist/ops/pack16.js +1 -1
  108. package/dist/ops/qkv.js +1 -1
  109. package/dist/ops/reshape16.js +1 -1
  110. package/dist/ops/rope.js +1 -1
  111. package/dist/ops/scatterSub.js +1 -1
  112. package/dist/ops/slice16.js +1 -1
  113. package/dist/ops/softmax16.js +1 -1
  114. package/dist/ops/sub16.js +1 -1
  115. package/dist/ops/sum16.js +1 -1
  116. package/dist/ops/transpose16.js +1 -1
  117. package/dist/ops/unpack16.js +1 -1
  118. package/dist/ops/webgl/adamAdjust.js +2 -2
  119. package/dist/ops/webgl/adamMoments.js +1 -1
  120. package/dist/ops/webgl/appendCache.js +1 -1
  121. package/dist/ops/webgl/attentionMask.js +1 -1
  122. package/dist/ops/webgl/dropout16.js +1 -1
  123. package/dist/ops/webgl/fusedSoftmax.js +3 -3
  124. package/dist/ops/webgl/gatherSub.js +1 -1
  125. package/dist/ops/webgl/gelu.js +2 -2
  126. package/dist/ops/webgl/log.js +3 -3
  127. package/dist/ops/webgl/matMul16.js +1 -1
  128. package/dist/ops/webgl/matMulGelu.js +1 -1
  129. package/dist/ops/webgl/matMulMul.js +2 -2
  130. package/dist/ops/webgl/mulDropout.js +1 -1
  131. package/dist/ops/webgl/normRMS.js +1 -1
  132. package/dist/ops/webgl/qkv.js +1 -1
  133. package/dist/ops/webgl/rope.js +1 -1
  134. package/dist/ops/webgl/scatterSub.js +1 -1
  135. package/dist/ops/webgpu/adamAdjust.js +3 -3
  136. package/dist/ops/webgpu/adamMoments.js +3 -3
  137. package/dist/ops/webgpu/add16.js +1 -1
  138. package/dist/ops/webgpu/appendCache.js +3 -3
  139. package/dist/ops/webgpu/attentionMask.js +2 -2
  140. package/dist/ops/webgpu/attentionMask32_program.js +2 -2
  141. package/dist/ops/webgpu/clipScale.js +1 -1
  142. package/dist/ops/webgpu/concat16.js +5 -5
  143. package/dist/ops/webgpu/dropout16.js +3 -3
  144. package/dist/ops/webgpu/gatherSub.js +3 -3
  145. package/dist/ops/webgpu/gelu.js +3 -3
  146. package/dist/ops/webgpu/matMul16.js +1 -1
  147. package/dist/ops/webgpu/matMul16_program.js +7 -7
  148. package/dist/ops/webgpu/mul16.js +1 -1
  149. package/dist/ops/webgpu/norm2.js +1 -1
  150. package/dist/ops/webgpu/normRMS.js +2 -2
  151. package/dist/ops/webgpu/normRMSGrad.js +4 -4
  152. package/dist/ops/webgpu/pack16.js +1 -1
  153. package/dist/ops/webgpu/pack16_program.js +2 -2
  154. package/dist/ops/webgpu/qkv.js +2 -2
  155. package/dist/ops/webgpu/rope.js +3 -3
  156. package/dist/ops/webgpu/scatterSub.js +3 -3
  157. package/dist/ops/webgpu/slice16.js +4 -4
  158. package/dist/ops/webgpu/softmax16.js +1 -1
  159. package/dist/ops/webgpu/softmax16_program.js +2 -2
  160. package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
  161. package/dist/ops/webgpu/softmax16grad.js +1 -1
  162. package/dist/ops/webgpu/sub16.js +1 -1
  163. package/dist/ops/webgpu/sum16.js +15 -15
  164. package/dist/ops/webgpu/transpose16.js +1 -1
  165. package/dist/ops/webgpu/transpose16_program.js +2 -2
  166. package/dist/ops/webgpu/transpose16_shared_program.js +3 -3
  167. package/dist/ops/webgpu/unpack16.js +3 -3
  168. package/dist/ops/webgpu/utils/binary_op.js +3 -3
  169. package/dist/ops/webgpu/utils/reductions.js +3 -3
  170. package/dist/{pack16-Ck-spx_F.js → pack16-BhuXNUS7.js} +1 -1
  171. package/dist/patches/webgpu_backend.js +3 -3
  172. package/dist/patches/webgpu_base.js +1 -1
  173. package/dist/patches/webgpu_program.js +4 -4
  174. package/dist/{pdf-UoDqCYzz.js → pdf-CdmW8ikl.js} +1159 -1160
  175. package/dist/{picomatch-3tUnMMbd.js → picomatch-BO4HbNfo.js} +125 -127
  176. package/dist/{rope-CbeGlsV8.js → rope-C8EAiSGY.js} +1 -1
  177. package/dist/{selu_util-zkAx5doH.js → selu_util-B_AFEfoz.js} +1 -1
  178. package/dist/{shared-D1coEFea.js → shared-24EoeHJl.js} +4 -4
  179. package/dist/{shared-DOgWaqvL.js → shared-CfTzpULd.js} +1 -1
  180. package/dist/{slice_util-Dgb3ANWI.js → slice_util-Dve4TkDn.js} +2 -2
  181. package/dist/stream-DKl3GTDL.js +2287 -0
  182. package/dist/{tfjs_backend-BjuQ5FqB.js → tfjs_backend-CydPRQTc.js} +2 -2
  183. package/dist/tokeniser/BaseTokeniser.d.ts +2 -1
  184. package/dist/tokeniser/BaseTokeniser.js +1 -1
  185. package/dist/tokeniser/CharTokeniser.d.ts +2 -2
  186. package/dist/tokeniser/CharTokeniser.js +8 -12
  187. package/dist/tokeniser/bpe.d.ts +2 -2
  188. package/dist/tokeniser/bpe.js +19 -28
  189. package/dist/tokeniser/type.d.ts +3 -2
  190. package/dist/training/AdamW.js +1 -1
  191. package/dist/training/BasicTrainer.js +1 -1
  192. package/dist/training/DatasetBuilder.d.ts +1 -2
  193. package/dist/training/DatasetBuilder.js +2 -2
  194. package/dist/training/Evaluator.js +1 -1
  195. package/dist/training/PreTrainer.js +1 -1
  196. package/dist/training/SFTTrainer.js +1 -1
  197. package/dist/training/loss.js +2 -2
  198. package/dist/training/orthoGrad.js +1 -1
  199. package/dist/training/sparseCrossEntropy.js +1 -1
  200. package/dist/training/tasks/ConversationTask.d.ts +9 -10
  201. package/dist/training/tasks/ConversationTask.js +15 -24
  202. package/dist/training/tasks/PretrainingTask.d.ts +4 -4
  203. package/dist/training/tasks/PretrainingTask.js +2 -2
  204. package/dist/training/tasks/StartSentenceTask.d.ts +4 -4
  205. package/dist/training/tasks/StartSentenceTask.js +3 -3
  206. package/dist/training/tasks/Task.d.ts +9 -11
  207. package/dist/training/tasks/Task.js +14 -27
  208. package/dist/training/tasks/splitter.d.ts +2 -2
  209. package/dist/training/tasks/splitter.js +11 -11
  210. package/dist/training/validation.d.ts +1 -1
  211. package/dist/training/validation.js +1 -1
  212. package/dist/utilities/dummy.js +1 -1
  213. package/dist/utilities/float16.d.ts +3 -0
  214. package/dist/utilities/float16.js +46 -0
  215. package/dist/utilities/multinomialCPU.js +1 -1
  216. package/dist/utilities/packed.js +1 -1
  217. package/dist/utilities/performance.js +1 -1
  218. package/dist/utilities/profile.js +1 -1
  219. package/dist/utilities/safetensors.d.ts +3 -1
  220. package/dist/utilities/safetensors.js +46 -36
  221. package/dist/utilities/sentences.js +1 -1
  222. package/dist/utilities/tokens.d.ts +2 -0
  223. package/dist/utilities/tokens.js +40 -0
  224. package/dist/utilities/topP.js +6 -0
  225. package/dist/utilities/weights.js +1 -1
  226. package/dist/{webgpu-Dt7BMzWz.js → webgpu-B19Tw8Nd.js} +3 -3
  227. package/dist/{webgpu_program-WOyIVMlZ.js → webgpu_program-B0PokuRJ.js} +1 -1
  228. package/dist/{webgpu_util-B_F3SShA.js → webgpu_util-DfODg6XI.js} +1 -1
  229. package/package.json +6 -5
  230. package/dist/dist-DXwIvKxl.js +0 -896
@@ -1,4 +1,4 @@
1
- import { a as e, t } from "./chunk-BPntVaq0.js";
1
+ import { i as e, t } from "./chunk-CWhphoD1.js";
2
2
  var n = (/* @__PURE__ */ e((/* @__PURE__ */ t(((e, t) => {
3
3
  var n = Object.prototype.hasOwnProperty, r = "~";
4
4
  function i() {}
@@ -1,12 +1,12 @@
1
- import { a as e } from "./chunk-BPntVaq0.js";
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 ee, ni as u, wi as d, yi as f } from "./dist-BewPQWjc.js";
3
- import { n as p } from "./dist-DXwIvKxl.js";
1
+ import { i as e } from "./chunk-CWhphoD1.js";
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
4
  //#region node_modules/@tensorflow/tfjs-data/dist/util/deep_map.js
5
- var m = /* @__PURE__ */ e(ee());
6
- function h(e, t) {
7
- return g(e, t);
5
+ var g = /* @__PURE__ */ e(u());
6
+ function ee(e, t) {
7
+ return _(e, t);
8
8
  }
9
- function g(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
9
+ function _(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
10
10
  if (e == null) return null;
11
11
  if (typeof Blob == "function" && e instanceof Blob) return e.slice();
12
12
  if (r.has(e)) throw Error("Circular references are not supported.");
@@ -14,34 +14,34 @@ function g(e, t, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set()) {
14
14
  let i = t(e);
15
15
  if (i.recurse && i.value !== null) throw Error("A deep map function may not return both a value and recurse=true.");
16
16
  if (!i.recurse) return n.set(e, i.value), i.value;
17
- if (b(e)) {
17
+ if (x(e)) {
18
18
  let i = Array.isArray(e) ? [] : {};
19
19
  r.add(e);
20
20
  for (let a in e) {
21
21
  let o = e[a];
22
- i[a] = g(o, t, n, r);
22
+ i[a] = _(o, t, n, r);
23
23
  }
24
24
  return r.delete(e), e.__proto__ && (i.__proto__ = e.__proto__), i;
25
25
  } else throw Error(`Can't recurse into non-iterable type: ${e}`);
26
26
  }
27
- function _(e, t = y) {
28
- return v(e, t);
27
+ function v(e, t = b) {
28
+ return y(e, t);
29
29
  }
30
- function v(e, t, n = /* @__PURE__ */ new Set()) {
30
+ function y(e, t, n = /* @__PURE__ */ new Set()) {
31
31
  let r = e[0];
32
32
  if (n.has(r)) throw Error("Circular references are not supported.");
33
33
  let i = t(e);
34
34
  if (i.recurse && i.value !== null) throw Error("A deep zip function may not return both a value and recurse=true.");
35
35
  if (!i.recurse) return i.value;
36
- if (b(r)) {
36
+ if (x(r)) {
37
37
  let i = Array.isArray(r) ? [] : {};
38
38
  n.add(r);
39
- for (let a in r) i[a] = v(e.map((e) => e[a]), t, n);
39
+ for (let a in r) i[a] = y(e.map((e) => e[a]), t, n);
40
40
  return n.delete(r), i;
41
41
  } else throw Error(`Can't recurse into non-iterable type: ${r}`);
42
42
  }
43
- function y(e) {
44
- return e === null ? null : b(e[0]) ? {
43
+ function b(e) {
44
+ return e === null ? null : x(e[0]) ? {
45
45
  value: null,
46
46
  recurse: !0
47
47
  } : {
@@ -49,31 +49,31 @@ function y(e) {
49
49
  recurse: !1
50
50
  };
51
51
  }
52
- function b(e) {
52
+ function x(e) {
53
53
  let t = !1;
54
54
  if (n().get("IS_BROWSER")) t = e instanceof TextDecoder;
55
55
  else {
56
56
  let { StringDecoder: n } = a();
57
57
  t = e instanceof n;
58
58
  }
59
- return e != null && !ArrayBuffer.isView(e) && (Array.isArray(e) || typeof e == "object" && !(e instanceof d) && !(e instanceof Promise) && !t);
60
- }
61
- function x(e) {
62
- return e == null || S(e) || Array.isArray(e) || typeof e == "object" && e instanceof d || l(e);
59
+ return e != null && !ArrayBuffer.isView(e) && (Array.isArray(e) || typeof e == "object" && !(e instanceof f) && !(e instanceof Promise) && !t);
63
60
  }
64
61
  function S(e) {
62
+ return e == null || C(e) || Array.isArray(e) || typeof e == "object" && e instanceof f || l(e);
63
+ }
64
+ function C(e) {
65
65
  return e === null || typeof e != "object" && typeof e != "function";
66
66
  }
67
67
  //#endregion
68
68
  //#region node_modules/@tensorflow/tfjs-data/dist/util/deep_clone.js
69
- function C(e) {
70
- return h(e, w);
71
- }
72
69
  function w(e) {
73
- return e instanceof d ? {
70
+ return ee(e, T);
71
+ }
72
+ function T(e) {
73
+ return e instanceof f ? {
74
74
  value: e.clone(),
75
75
  recurse: !1
76
- } : b(e) ? {
76
+ } : x(e) ? {
77
77
  value: null,
78
78
  recurse: !0
79
79
  } : {
@@ -83,7 +83,7 @@ function w(e) {
83
83
  }
84
84
  //#endregion
85
85
  //#region node_modules/@tensorflow/tfjs-data/dist/util/ring_buffer.js
86
- var T = class {
86
+ var E = class {
87
87
  constructor(e) {
88
88
  if (this.capacity = e, this.begin = 0, this.end = 0, e == null) throw RangeError("Can't create a ring buffer of unknown capacity.");
89
89
  if (e < 1) throw RangeError("Can't create ring buffer of capacity < 1.");
@@ -138,7 +138,7 @@ var T = class {
138
138
  let t = this.wrap(this.begin + e), n = this.get(t);
139
139
  return this.set(t, this.pop()), n;
140
140
  }
141
- }, E = class e extends T {
141
+ }, D = class e extends E {
142
142
  constructor() {
143
143
  super(e.INITIAL_CAPACITY);
144
144
  }
@@ -157,19 +157,19 @@ var T = class {
157
157
  this.data = t, this.capacity = e, this.doubledCapacity = 2 * this.capacity, this.begin = 0, this.end = n;
158
158
  }
159
159
  };
160
- E.INITIAL_CAPACITY = 32;
160
+ D.INITIAL_CAPACITY = 32;
161
161
  //#endregion
162
162
  //#region node_modules/@tensorflow/tfjs-data/dist/iterators/lazy_iterator.js
163
- function D(e) {
164
- return new j(e);
165
- }
166
163
  function O(e) {
167
164
  return new M(e);
168
165
  }
169
- function k(e, t) {
170
- return new U(e, t);
166
+ function k(e) {
167
+ return new N(e);
168
+ }
169
+ function A(e, t) {
170
+ return new W(e, t);
171
171
  }
172
- var A = class {
172
+ var j = class {
173
173
  async toArray() {
174
174
  let e = [], t = await this.next();
175
175
  for (; !t.done;) e.push(t.value), t = await this.next();
@@ -189,22 +189,22 @@ var A = class {
189
189
  for (; !t.done && n;) t = await this.next(), n = e(t.value);
190
190
  }
191
191
  handleErrors(e) {
192
- return new z(this, e);
192
+ return new B(this, e);
193
193
  }
194
194
  filter(e) {
195
- return new L(this, e);
195
+ return new R(this, e);
196
196
  }
197
197
  map(e) {
198
- return new R(this, e);
198
+ return new z(this, e);
199
199
  }
200
200
  mapAsync(e) {
201
- return new B(this, e);
201
+ return new V(this, e);
202
202
  }
203
203
  serialMapAsync(e) {
204
- return new B(this, e).serial();
204
+ return new V(this, e).serial();
205
205
  }
206
206
  flatmap(e) {
207
- return new H(this, e);
207
+ return new U(this, e);
208
208
  }
209
209
  async forEachAsync(e) {
210
210
  return this.map(e).resolveFully();
@@ -213,30 +213,30 @@ var A = class {
213
213
  return this.serialMapAsync(e).resolveWhile((e) => e === !0);
214
214
  }
215
215
  rowMajorBatch(e, t = !0) {
216
- return new I(this, e, t);
216
+ return new L(this, e, t);
217
217
  }
218
- columnMajorBatch(e, t = !0, n = y) {
219
- return this.rowMajorBatch(e, t).map((e) => _(e, n));
218
+ columnMajorBatch(e, t = !0, n = b) {
219
+ return this.rowMajorBatch(e, t).map((e) => v(e, n));
220
220
  }
221
221
  concatenate(e, t) {
222
- return new U(D([this, e]), t);
222
+ return new W(O([this, e]), t);
223
223
  }
224
224
  take(e) {
225
- return e < 0 || e == null ? this : new F(this, e);
225
+ return e < 0 || e == null ? this : new I(this, e);
226
226
  }
227
227
  skip(e) {
228
- return e < 0 || e == null ? this : new P(this, e);
228
+ return e < 0 || e == null ? this : new F(this, e);
229
229
  }
230
230
  prefetch(e) {
231
- return new G(this, e);
231
+ return new K(this, e);
232
232
  }
233
233
  shuffle(e, t) {
234
- return new K(this, e, t);
234
+ return new q(this, e, t);
235
235
  }
236
236
  serial() {
237
- return new N(this);
237
+ return new P(this);
238
238
  }
239
- }, j = class extends A {
239
+ }, M = class extends j {
240
240
  constructor(e) {
241
241
  super(), this.items = e, this.trav = 0;
242
242
  }
@@ -250,11 +250,11 @@ var A = class {
250
250
  };
251
251
  let e = this.items[this.trav];
252
252
  return this.trav++, {
253
- value: C(e),
253
+ value: w(e),
254
254
  done: !1
255
255
  };
256
256
  }
257
- }, M = class extends A {
257
+ }, N = class extends j {
258
258
  constructor(e) {
259
259
  super(), this.nextFn = e;
260
260
  }
@@ -268,7 +268,7 @@ var A = class {
268
268
  throw e.message = `Error thrown while iterating through a dataset: ${e.message}`, e;
269
269
  }
270
270
  }
271
- }, N = class extends A {
271
+ }, P = class extends j {
272
272
  constructor(e) {
273
273
  super(), this.upstream = e, this.lastRead = Promise.resolve({
274
274
  value: null,
@@ -284,7 +284,7 @@ var A = class {
284
284
  async serialNext() {
285
285
  return this.upstream.next();
286
286
  }
287
- }, P = class extends A {
287
+ }, F = class extends j {
288
288
  constructor(e, t) {
289
289
  super(), this.upstream = e, this.maxCount = t, this.count = 0, this.lastRead = Promise.resolve({
290
290
  value: null,
@@ -301,11 +301,11 @@ var A = class {
301
301
  for (; this.count++ < this.maxCount;) {
302
302
  let e = await this.upstream.next();
303
303
  if (e.done) return e;
304
- u(e.value);
304
+ d(e.value);
305
305
  }
306
306
  return this.upstream.next();
307
307
  }
308
- }, F = class extends A {
308
+ }, I = class extends j {
309
309
  constructor(e, t) {
310
310
  super(), this.upstream = e, this.maxCount = t, this.count = 0;
311
311
  }
@@ -318,7 +318,7 @@ var A = class {
318
318
  done: !0
319
319
  } : this.upstream.next();
320
320
  }
321
- }, I = class extends A {
321
+ }, L = class extends j {
322
322
  constructor(e, t, n = !0) {
323
323
  super(), this.upstream = e, this.batchSize = t, this.enableSmallLastBatch = n, this.lastRead = Promise.resolve({
324
324
  value: null,
@@ -349,7 +349,7 @@ var A = class {
349
349
  done: !1
350
350
  };
351
351
  }
352
- }, L = class extends A {
352
+ }, R = class extends j {
353
353
  constructor(e, t) {
354
354
  super(), this.upstream = e, this.predicate = t, this.lastRead = Promise.resolve({
355
355
  value: null,
@@ -366,10 +366,10 @@ var A = class {
366
366
  for (;;) {
367
367
  let e = await this.upstream.next();
368
368
  if (e.done || this.predicate(e.value)) return e;
369
- u(e.value);
369
+ d(e.value);
370
370
  }
371
371
  }
372
- }, R = class extends A {
372
+ }, z = class extends j {
373
373
  constructor(e, t) {
374
374
  super(), this.upstream = e, this.transform = t;
375
375
  }
@@ -382,14 +382,14 @@ var A = class {
382
382
  value: null,
383
383
  done: !0
384
384
  };
385
- let t = f(e.value), n = this.transform(e.value), r = f(n);
385
+ let t = p(e.value), n = this.transform(e.value), r = p(n);
386
386
  for (let e of t) o(e, r) || e.dispose();
387
387
  return {
388
388
  value: n,
389
389
  done: !1
390
390
  };
391
391
  }
392
- }, z = class extends A {
392
+ }, B = class extends j {
393
393
  constructor(e, t) {
394
394
  super(), this.upstream = e, this.handler = t, this.count = 0, this.lastRead = Promise.resolve({
395
395
  value: null,
@@ -412,7 +412,7 @@ var A = class {
412
412
  };
413
413
  }
414
414
  }
415
- }, B = class extends A {
415
+ }, V = class extends j {
416
416
  constructor(e, t) {
417
417
  super(), this.upstream = e, this.transform = t;
418
418
  }
@@ -425,16 +425,16 @@ var A = class {
425
425
  value: null,
426
426
  done: !0
427
427
  };
428
- let t = f(e.value), n = await this.transform(e.value), r = f(n);
428
+ let t = p(e.value), n = await this.transform(e.value), r = p(n);
429
429
  for (let e of t) o(e, r) || e.dispose();
430
430
  return {
431
431
  value: n,
432
432
  done: !1
433
433
  };
434
434
  }
435
- }, V = class extends A {
435
+ }, H = class extends j {
436
436
  constructor() {
437
- super(), this.outputQueue = new E(), this.lastRead = Promise.resolve({
437
+ super(), this.outputQueue = new D(), this.lastRead = Promise.resolve({
438
438
  value: null,
439
439
  done: !1
440
440
  });
@@ -452,7 +452,7 @@ var A = class {
452
452
  done: !1
453
453
  };
454
454
  }
455
- }, H = class extends V {
455
+ }, U = class extends H {
456
456
  constructor(e, t) {
457
457
  super(), this.upstream = e, this.transform = t;
458
458
  }
@@ -462,12 +462,12 @@ var A = class {
462
462
  async pump() {
463
463
  let e = await this.upstream.next();
464
464
  if (e.done) return !1;
465
- let t = f(e.value), n = this.transform(e.value), r = f(n);
465
+ let t = p(e.value), n = this.transform(e.value), r = p(n);
466
466
  this.outputQueue.pushAll(n);
467
467
  for (let e of t) o(e, r) || e.dispose();
468
468
  return !0;
469
469
  }
470
- }, U = class extends A {
470
+ }, W = class extends j {
471
471
  constructor(e, t) {
472
472
  super(), this.baseErrorHandler = t, this.lastRead = null, this.iterator = null, this.moreIterators = e;
473
473
  }
@@ -489,13 +489,13 @@ var A = class {
489
489
  let t = await this.iterator.next();
490
490
  return t.done ? (this.iterator = null, this.readFromChain(e)) : t;
491
491
  }
492
- }, W;
492
+ }, G;
493
493
  (function(e) {
494
494
  e[e.FAIL = 0] = "FAIL", e[e.SHORTEST = 1] = "SHORTEST", e[e.LONGEST = 2] = "LONGEST";
495
- })(W ||= {});
496
- var G = class extends A {
495
+ })(G ||= {});
496
+ var K = class extends j {
497
497
  constructor(e, t) {
498
- super(), this.upstream = e, this.bufferSize = t, this.buffer = new T(t);
498
+ super(), this.upstream = e, this.bufferSize = t, this.buffer = new E(t);
499
499
  }
500
500
  summary() {
501
501
  return `${this.upstream.summary()} -> Prefetch`;
@@ -509,9 +509,9 @@ var G = class extends A {
509
509
  next() {
510
510
  return this.refill(), this.buffer.shift();
511
511
  }
512
- }, K = class extends G {
512
+ }, q = class extends K {
513
513
  constructor(e, n, r) {
514
- super(e, n), this.upstream = e, this.windowSize = n, this.upstreamExhausted = !1, this.random = m.alea(r || t().toString()), this.lastRead = Promise.resolve({
514
+ super(e, n), this.upstream = e, this.windowSize = n, this.upstreamExhausted = !1, this.random = g.alea(r || t().toString()), this.lastRead = Promise.resolve({
515
515
  value: null,
516
516
  done: !1
517
517
  });
@@ -536,7 +536,7 @@ var G = class extends A {
536
536
  done: !0
537
537
  };
538
538
  }
539
- }, q = class {
539
+ }, J = class {
540
540
  constructor() {
541
541
  this.size = null;
542
542
  }
@@ -545,54 +545,54 @@ var G = class extends A {
545
545
  r(e > 0, () => `batchSize needs to be positive, but it is
546
546
  ${e}`);
547
547
  let i;
548
- return i = this.size === Infinity || this.size == null ? this.size : t ? Math.ceil(this.size / e) : Math.floor(this.size / e), J(async () => (await n.iterator()).columnMajorBatch(e, t, Y), 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);
549
549
  }
550
550
  concatenate(e) {
551
551
  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, J(async () => (await t.iterator()).concatenate(await e.iterator()), 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);
553
553
  }
554
554
  filter(e) {
555
555
  let t = this, n;
556
- return n = this.size === Infinity ? Infinity : null, J(async () => (await t.iterator()).filter((t) => s(() => e(t))), n);
556
+ return n = this.size === Infinity ? Infinity : null, Y(async () => (await t.iterator()).filter((t) => s(() => e(t))), n);
557
557
  }
558
558
  async forEachAsync(e) {
559
559
  return (await this.iterator()).forEachAsync(e);
560
560
  }
561
561
  map(e) {
562
562
  let t = this;
563
- return J(async () => (await t.iterator()).map((t) => s(() => e(t))), this.size);
563
+ return Y(async () => (await t.iterator()).map((t) => s(() => e(t))), this.size);
564
564
  }
565
565
  mapAsync(e) {
566
566
  let t = this;
567
- return J(async () => (await t.iterator()).mapAsync(e), this.size);
567
+ return Y(async () => (await t.iterator()).mapAsync(e), this.size);
568
568
  }
569
569
  prefetch(e) {
570
570
  if (e == null) throw RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");
571
571
  let t = this;
572
- return J(async () => (await t.iterator()).prefetch(e), this.size);
572
+ return Y(async () => (await t.iterator()).prefetch(e), this.size);
573
573
  }
574
574
  repeat(e) {
575
575
  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, J(async () => k(O(async () => ({
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 () => ({
577
577
  value: await t.iterator(),
578
578
  done: !1
579
579
  })).take(e)), n);
580
580
  }
581
581
  skip(e) {
582
582
  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, J(async () => (await t.iterator()).skip(e), 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);
584
584
  }
585
585
  shuffle(e, n, r = !0) {
586
586
  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 = m.alea(n || t().toString());
588
- return J(async () => {
587
+ let i = this, a = g.alea(n || t().toString());
588
+ return Y(async () => {
589
589
  let t = a.int32();
590
590
  return r && (t += a.int32()), (await i.iterator()).shuffle(e, t.toString());
591
591
  }, this.size);
592
592
  }
593
593
  take(e) {
594
594
  let t = this, n;
595
- return n = this.size != null && this.size > e ? e : this.size != null && this.size <= e ? this.size : null, J(async () => (await t.iterator()).take(e), 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);
596
596
  }
597
597
  async toArray() {
598
598
  if (this.size === Infinity) throw Error("Can not convert infinite data stream to array.");
@@ -603,9 +603,9 @@ var G = class extends A {
603
603
  return (await this.iterator()).toArrayForTest();
604
604
  }
605
605
  };
606
- q.MAX_BUFFER_SIZE = 1e4;
607
- function J(e, t = null) {
608
- return new class extends q {
606
+ J.MAX_BUFFER_SIZE = 1e4;
607
+ function Y(e, t = null) {
608
+ return new class extends J {
609
609
  constructor() {
610
610
  super(...arguments), this.size = t;
611
611
  }
@@ -614,43 +614,37 @@ function J(e, t = null) {
614
614
  }
615
615
  }();
616
616
  }
617
- function Y(e) {
617
+ function X(e) {
618
618
  if (e === null) return null;
619
619
  let t = e[0];
620
- return x(t) ? {
621
- value: X(e),
620
+ return S(t) ? {
621
+ value: Z(e),
622
622
  recurse: !1
623
623
  } : {
624
624
  value: null,
625
625
  recurse: !0
626
626
  };
627
627
  }
628
- function X(e) {
628
+ function Z(e) {
629
629
  if (e.length === 0) throw Error("Can't make a batch of zero elements.");
630
- return e[0] instanceof d ? i(e) : c(e);
630
+ return e[0] instanceof f ? i(e) : c(e);
631
631
  }
632
632
  //#endregion
633
- //#region node_modules/@tensorflow/tfjs-data/dist/iterators/string_iterator.js
634
- p();
635
- //#endregion
636
633
  //#region node_modules/@tensorflow/tfjs-data/dist/readers.js
637
- function Z(e) {
638
- return J(async () => {
634
+ function Q(e) {
635
+ return Y(async () => {
639
636
  let t = await e();
640
- return O(() => t.next());
637
+ return k(() => t.next());
641
638
  });
642
639
  }
643
640
  //#endregion
644
641
  //#region lib/training/DatasetBuilder.ts
645
- var Q = 8;
646
642
  function te(e, t) {
647
643
  let n = e.map((e) => t.encodeConversation(e)).flat();
648
644
  return new Uint16Array(n);
649
645
  }
650
646
  function ne(e, t) {
651
- let n = e.map((e) => t.encodeConversation(e, !1, !0));
652
- console.log("Tokenised Texts with Mask:", n);
653
- let r = n.map((e) => e.tokens).flat(), i = n.map((e) => e.mask).flat();
647
+ let n = e.map((e) => t.encodeConversation(e, !1, !0)), r = n.map((e) => e.tokens).flat(), i = n.map((e) => e.mask).flat();
654
648
  return {
655
649
  tokens: new Uint16Array(r),
656
650
  mask: new Uint8Array(i.map((e) => +!!e))
@@ -670,31 +664,31 @@ var re = class {
670
664
  this.tokenizer = e, this.blockSize = t;
671
665
  }
672
666
  async createTextDataset(e, t = 32, n, r, i = 65535) {
673
- if (e.length < this.blockSize + 1) throw Error(`Not enough tokens (${e.length}) for block size ${this.blockSize}`);
674
- let a = {
675
- shuffledIndexes: new Uint32Array(e.length),
667
+ let a = e.reduce((e, t) => e + t.length, 0);
668
+ 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 = {
670
+ shuffledIndexes: new Uint32Array(o),
676
671
  step: 0
677
672
  };
678
- if (n) a.shuffledIndexes = n;
673
+ if (n) c.shuffledIndexes = n;
679
674
  else {
680
- a.shuffledIndexes = new Uint32Array(e.length);
681
- for (let t = 0; t < e.length; t++) a.shuffledIndexes[t] = t;
682
- $(a.shuffledIndexes);
675
+ c.shuffledIndexes = new Uint32Array(o);
676
+ for (let e = 0; e < o; e++) c.shuffledIndexes[e] = e;
683
677
  }
684
678
  return {
685
- dataset: Z(function* () {
679
+ dataset: Q(function* () {
686
680
  for (;;) {
687
- let t = a.shuffledIndexes[a.step++];
688
- if (a.step >= a.shuffledIndexes.length && (a.step = 0, $(a.shuffledIndexes)), t + this.blockSize + 1 > e.length) continue;
689
- let n = new Int32Array(e.subarray(t, t + this.blockSize)), o = e.subarray(t + 1, t + this.blockSize + 1), s = new Int32Array(o);
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));
690
684
  if (r) {
691
- let e = 0;
692
- for (let n = 0; n < s.length; n++) r[t + 1 + n] === 0 && (s[n] = i, e++);
693
- if (e === s.length) continue;
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;
694
688
  }
695
689
  yield {
696
690
  xs: n,
697
- ys: s
691
+ ys: o
698
692
  };
699
693
  }
700
694
  }.bind(this)).batch(t).map((e) => {
@@ -704,9 +698,9 @@ var re = class {
704
698
  ys: t.ys.cast("int32")
705
699
  }));
706
700
  }).prefetch(2),
707
- state: a
701
+ state: c
708
702
  };
709
703
  }
710
704
  };
711
705
  //#endregion
712
- export { $ as a, ne as i, Q as n, te as r, re as t };
706
+ export { $ as i, te as n, ne as r, re as t };
package/dist/Generator.js CHANGED
@@ -1,2 +1,2 @@
1
- import { c as e, s as t } from "./main-BTmbwF1h.js";
1
+ import { c as e, s as t } from "./main-Bgc7_9kb.js";
2
2
  export { t as default, e as isConversation };
@@ -1,9 +1,9 @@
1
- import { Dn as e, En as t, Io as n, Ks as r, Ms as i, Si as a, Tn as o, nc as s, oc as c, wn as l, xn as u } from "./dist-BewPQWjc.js";
2
- import { L as d } from "./backend_util-Cg-roD1p.js";
3
- import { o as f } from "./gpgpu_math-DvLcCH6u.js";
4
- import { J as p, b as m } from "./shared-DOgWaqvL.js";
5
- import { S as h, n as g } from "./kernel_funcs_utils-HiXOOx3f.js";
6
- import { t as _ } from "./Reshape-CABOPB9d.js";
1
+ import { Dn as e, En as t, Io as n, Ks as r, Ms as i, Si as a, Tn as o, nc as s, oc as c, wn as l, xn as u } from "./dist-Da20xy8E.js";
2
+ import { L as d } from "./backend_util-DAV0I34P.js";
3
+ import { o as f } from "./gpgpu_math-DBYEAAdI.js";
4
+ import { J as p, b as m } from "./shared-CfTzpULd.js";
5
+ import { S as h, n as g } from "./kernel_funcs_utils-D-mATnGR.js";
6
+ import { t as _ } from "./Reshape-dnm9bO3B.js";
7
7
  //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/mean_gpu.js
8
8
  var v = class {
9
9
  constructor(e, t) {
@@ -1,4 +1,4 @@
1
- import { Bo as e, Gs as t, Ps as n, oc as r } from "./dist-BewPQWjc.js";
1
+ import { Bo as e, Gs as t, Ps as n, oc as r } from "./dist-Da20xy8E.js";
2
2
  //#region node_modules/@tensorflow/tfjs-backend-webgpu/dist/kernels/Reshape.js
3
3
  function i(e) {
4
4
  let { inputs: i, attrs: a } = e, { x: o } = i, { shape: s } = a, c = r(o.shape), l = t(s, c), u = r(l);
@@ -1,5 +1,5 @@
1
- import { Bo as e, Gs as t, Ps as n, oc as r } from "./dist-BewPQWjc.js";
2
- import { E as i, a, c as o, d as s, j as c, l, u, z as d } from "./gpgpu_math-DvLcCH6u.js";
1
+ import { Bo as e, Gs as t, Ps as n, oc as r } from "./dist-Da20xy8E.js";
2
+ import { E as i, a, c as o, d as s, j as c, l, u, z as d } from "./gpgpu_math-DBYEAAdI.js";
3
3
  //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/reshape_packed_gpu.js
4
4
  var f = class {
5
5
  constructor(e, t) {
@@ -4,6 +4,7 @@ import { SaveOptions } from './loader/save';
4
4
  import { LoadModelOptions } from './loader/load';
5
5
  import { IGenerateOptions, IGenerator } from './Generator';
6
6
  import { default as Trainer, TrainingType } from './Trainer';
7
+ import { ConversationStream } from './main';
7
8
  import { default as MemoryProfiler } from './utilities/profile';
8
9
  import { default as Model, ModelForwardAttributes } from './models/model';
9
10
  import { Task } from './training/tasks/Task';
@@ -51,7 +52,7 @@ export default class TeachableLLM {
51
52
  getNumParams(): number;
52
53
  trainer(trainingType?: TrainingType, options?: TrainingOptions): Trainer;
53
54
  train(text: Task[], options?: TrainingOptions, trainingType?: TrainingType): Promise<void>;
54
- trainTokeniser(text: Conversation[][]): Promise<number>;
55
+ trainTokeniser(text: ConversationStream[]): Promise<number>;
55
56
  generator(): IGenerator;
56
57
  generateText(prompt: Conversation[], options?: IGenerateOptions): Promise<Conversation[]>;
57
58
  generateText(options?: IGenerateOptions): Promise<Conversation[]>;
@@ -1,2 +1,2 @@
1
- import { i as e } from "./main-BTmbwF1h.js";
1
+ import { i as e } from "./main-Bgc7_9kb.js";
2
2
  export { e as default };
package/dist/Trainer.d.ts CHANGED
@@ -33,7 +33,7 @@ export default class Trainer extends EE<'start' | 'stop' | 'log'> {
33
33
  dispose(): void;
34
34
  getTotalTokens(): number;
35
35
  setOptions(options: TrainingOptions): void;
36
- prepare(tasks?: Task[] | Uint16Array, datasets?: DatasetMetadata[]): Promise<void>;
36
+ prepare(tasks?: Task[] | Uint16Array[], datasets?: DatasetMetadata[]): Promise<void>;
37
37
  private configureModel;
38
38
  train(): Promise<void>;
39
39
  step(options?: TrainingOptions): Promise<void>;
package/dist/Trainer.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e } from "./main-BTmbwF1h.js";
1
+ import { a as e } from "./main-Bgc7_9kb.js";
2
2
  export { e as default };