@genai-fi/nanogpt 0.20.7 → 0.21.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 (206) hide show
  1. package/dist/{BaseTokeniser-DSg9zcYq.js → BaseTokeniser-C9TSv4th.js} +1 -1
  2. package/dist/{DatasetBuilder-DgURD85T.js → DatasetBuilder-B9UGNQT5.js} +82 -88
  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.js +1 -1
  8. package/dist/Trainer.js +1 -1
  9. package/dist/backend.js +2 -2
  10. package/dist/{backend_util-Cg-roD1p.js → backend_util-DAV0I34P.js} +5 -5
  11. package/dist/checks/appendCache.js +1 -1
  12. package/dist/checks/attentionMask.js +1 -1
  13. package/dist/checks/gelu.js +1 -1
  14. package/dist/checks/matMulGelu.js +1 -1
  15. package/dist/checks/normRMS.js +1 -1
  16. package/dist/checks/normRMSGrad.js +1 -1
  17. package/dist/checks/packUnpack.js +1 -1
  18. package/dist/checks/qkv.js +1 -1
  19. package/dist/checks/rope.js +1 -1
  20. package/dist/{chunk-BPntVaq0.js → chunk-CWhphoD1.js} +5 -5
  21. package/dist/{concat_util-CWDZCBlA.js → concat_util-CWzvQQlK.js} +1 -1
  22. package/dist/data/docx.js +58 -59
  23. package/dist/data/pdf.js +1 -1
  24. package/dist/data/textLoader.js +1 -1
  25. package/dist/{dist-DVmq73nz.js → dist-9wGF4ci9.js} +10 -10
  26. package/dist/{dist-VEU5mfO0.js → dist-BqAU9-yi.js} +4 -4
  27. package/dist/{dist-BewPQWjc.js → dist-Da20xy8E.js} +1874 -3071
  28. package/dist/{gelu-Bf1HW1RY.js → gelu-B6637MKa.js} +1 -1
  29. package/dist/{gpgpu_math-DvLcCH6u.js → gpgpu_math-DBYEAAdI.js} +2 -2
  30. package/dist/{kernel_funcs_utils-HiXOOx3f.js → kernel_funcs_utils-D-mATnGR.js} +3 -3
  31. package/dist/layers/BaseLayer.js +1 -1
  32. package/dist/layers/CausalSelfAttention.js +4 -4
  33. package/dist/layers/LoRA.js +3 -3
  34. package/dist/layers/MLP.js +2 -2
  35. package/dist/layers/PositionEmbedding.js +2 -2
  36. package/dist/layers/RMSNorm.js +1 -1
  37. package/dist/layers/RoPECache.js +1 -1
  38. package/dist/layers/TiedEmbedding.js +3 -3
  39. package/dist/layers/TransformerBlock.js +1 -1
  40. package/dist/layers/WeightStore.js +3 -3
  41. package/dist/loader/load.js +1 -1
  42. package/dist/loader/loadHF.js +1 -1
  43. package/dist/loader/loadTransformers.js +1 -1
  44. package/dist/loader/loadZipMeta.js +1 -1
  45. package/dist/loader/newZipLoad.js +1 -1
  46. package/dist/loader/oldZipLoad.js +1 -1
  47. package/dist/loader/save.d.ts +1 -0
  48. package/dist/loader/save.js +1 -1
  49. package/dist/{main-BTmbwF1h.js → main-DdsoTJAW.js} +2009 -2014
  50. package/dist/main.js +1 -1
  51. package/dist/{matMul16-BNfZSnNM.js → matMul16-DGtlziMn.js} +3 -3
  52. package/dist/{matMulGelu-CPTntosE.js → matMulGelu-BAIgQaRx.js} +3 -3
  53. package/dist/models/NanoGPTV1.js +1 -1
  54. package/dist/models/NanoGPTV2.js +1 -1
  55. package/dist/models/factory.js +1 -1
  56. package/dist/models/model.js +1 -1
  57. package/dist/ops/adamAdjust.js +1 -1
  58. package/dist/ops/adamMoments.js +1 -1
  59. package/dist/ops/add16.js +1 -1
  60. package/dist/ops/appendCache.js +1 -1
  61. package/dist/ops/attentionMask.js +1 -1
  62. package/dist/ops/concat16.js +1 -1
  63. package/dist/ops/cpu/adamAdjust.js +1 -1
  64. package/dist/ops/cpu/adamMoments.js +1 -1
  65. package/dist/ops/cpu/appendCache.js +1 -1
  66. package/dist/ops/cpu/attentionMask.js +1 -1
  67. package/dist/ops/cpu/fusedSoftmax.js +1 -1
  68. package/dist/ops/cpu/gatherSub.js +1 -1
  69. package/dist/ops/cpu/gelu.js +1 -1
  70. package/dist/ops/cpu/matMul16.js +1 -1
  71. package/dist/ops/cpu/matMulGelu.js +2 -2
  72. package/dist/ops/cpu/matMulMul.js +1 -1
  73. package/dist/ops/cpu/mulDropout.js +1 -1
  74. package/dist/ops/cpu/normRMS.js +1 -1
  75. package/dist/ops/cpu/qkv.js +1 -1
  76. package/dist/ops/cpu/rope.js +1 -1
  77. package/dist/ops/cpu/scatterSub.js +1 -1
  78. package/dist/ops/dot16.js +2 -2
  79. package/dist/ops/dropout.js +1 -1
  80. package/dist/ops/dropout16.js +1 -1
  81. package/dist/ops/gatherSub.js +1 -1
  82. package/dist/ops/gelu.js +1 -1
  83. package/dist/ops/globalNorm.js +1 -1
  84. package/dist/ops/grads/add16.js +1 -1
  85. package/dist/ops/grads/attentionMask.js +2 -2
  86. package/dist/ops/grads/gelu.js +1 -1
  87. package/dist/ops/grads/matMul16.js +1 -1
  88. package/dist/ops/grads/matMulGelu.js +1 -1
  89. package/dist/ops/grads/normRMS.js +1 -1
  90. package/dist/ops/grads/pack16.js +1 -1
  91. package/dist/ops/grads/qkv.js +2 -2
  92. package/dist/ops/grads/rope.js +1 -1
  93. package/dist/ops/grads/softmax16.js +1 -1
  94. package/dist/ops/grads/unpack16.js +1 -1
  95. package/dist/ops/matMul16.js +1 -1
  96. package/dist/ops/matMulGelu.js +2 -2
  97. package/dist/ops/matMulMul.js +1 -1
  98. package/dist/ops/mul16.js +1 -1
  99. package/dist/ops/mulDrop.js +1 -1
  100. package/dist/ops/normRMS.js +1 -1
  101. package/dist/ops/pack16.js +1 -1
  102. package/dist/ops/qkv.js +1 -1
  103. package/dist/ops/reshape16.js +1 -1
  104. package/dist/ops/rope.js +1 -1
  105. package/dist/ops/scatterSub.js +1 -1
  106. package/dist/ops/slice16.js +1 -1
  107. package/dist/ops/softmax16.js +1 -1
  108. package/dist/ops/sub16.js +1 -1
  109. package/dist/ops/sum16.js +1 -1
  110. package/dist/ops/transpose16.js +1 -1
  111. package/dist/ops/unpack16.js +1 -1
  112. package/dist/ops/webgl/adamAdjust.js +2 -2
  113. package/dist/ops/webgl/adamMoments.js +1 -1
  114. package/dist/ops/webgl/appendCache.js +1 -1
  115. package/dist/ops/webgl/attentionMask.js +1 -1
  116. package/dist/ops/webgl/dropout16.js +1 -1
  117. package/dist/ops/webgl/fusedSoftmax.js +3 -3
  118. package/dist/ops/webgl/gatherSub.js +1 -1
  119. package/dist/ops/webgl/gelu.js +2 -2
  120. package/dist/ops/webgl/log.js +3 -3
  121. package/dist/ops/webgl/matMul16.js +1 -1
  122. package/dist/ops/webgl/matMulGelu.js +1 -1
  123. package/dist/ops/webgl/matMulMul.js +2 -2
  124. package/dist/ops/webgl/mulDropout.js +1 -1
  125. package/dist/ops/webgl/normRMS.js +1 -1
  126. package/dist/ops/webgl/qkv.js +1 -1
  127. package/dist/ops/webgl/rope.js +1 -1
  128. package/dist/ops/webgl/scatterSub.js +1 -1
  129. package/dist/ops/webgpu/adamAdjust.js +3 -3
  130. package/dist/ops/webgpu/adamMoments.js +3 -3
  131. package/dist/ops/webgpu/add16.js +1 -1
  132. package/dist/ops/webgpu/appendCache.js +3 -3
  133. package/dist/ops/webgpu/attentionMask.js +2 -2
  134. package/dist/ops/webgpu/attentionMask32_program.js +2 -2
  135. package/dist/ops/webgpu/clipScale.js +1 -1
  136. package/dist/ops/webgpu/concat16.js +5 -5
  137. package/dist/ops/webgpu/dropout16.js +3 -3
  138. package/dist/ops/webgpu/gatherSub.js +3 -3
  139. package/dist/ops/webgpu/gelu.js +3 -3
  140. package/dist/ops/webgpu/matMul16.js +1 -1
  141. package/dist/ops/webgpu/matMul16_program.js +7 -7
  142. package/dist/ops/webgpu/mul16.js +1 -1
  143. package/dist/ops/webgpu/norm2.js +1 -1
  144. package/dist/ops/webgpu/normRMS.js +2 -2
  145. package/dist/ops/webgpu/normRMSGrad.js +4 -4
  146. package/dist/ops/webgpu/pack16.js +1 -1
  147. package/dist/ops/webgpu/pack16_program.js +2 -2
  148. package/dist/ops/webgpu/qkv.js +2 -2
  149. package/dist/ops/webgpu/rope.js +3 -3
  150. package/dist/ops/webgpu/scatterSub.js +3 -3
  151. package/dist/ops/webgpu/slice16.js +4 -4
  152. package/dist/ops/webgpu/softmax16.js +1 -1
  153. package/dist/ops/webgpu/softmax16_program.js +2 -2
  154. package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
  155. package/dist/ops/webgpu/softmax16grad.js +1 -1
  156. package/dist/ops/webgpu/sub16.js +1 -1
  157. package/dist/ops/webgpu/sum16.js +15 -15
  158. package/dist/ops/webgpu/transpose16.js +1 -1
  159. package/dist/ops/webgpu/transpose16_program.js +2 -2
  160. package/dist/ops/webgpu/transpose16_shared_program.js +3 -3
  161. package/dist/ops/webgpu/unpack16.js +3 -3
  162. package/dist/ops/webgpu/utils/binary_op.js +3 -3
  163. package/dist/ops/webgpu/utils/reductions.js +3 -3
  164. package/dist/{pack16-Ck-spx_F.js → pack16-BhuXNUS7.js} +1 -1
  165. package/dist/patches/webgpu_backend.js +3 -3
  166. package/dist/patches/webgpu_base.js +1 -1
  167. package/dist/patches/webgpu_program.js +4 -4
  168. package/dist/{pdf-UoDqCYzz.js → pdf-CdmW8ikl.js} +1159 -1160
  169. package/dist/{picomatch-3tUnMMbd.js → picomatch-BO4HbNfo.js} +125 -127
  170. package/dist/{rope-CbeGlsV8.js → rope-C8EAiSGY.js} +1 -1
  171. package/dist/{selu_util-zkAx5doH.js → selu_util-B_AFEfoz.js} +1 -1
  172. package/dist/{shared-D1coEFea.js → shared-24EoeHJl.js} +4 -4
  173. package/dist/{shared-DOgWaqvL.js → shared-CfTzpULd.js} +1 -1
  174. package/dist/{slice_util-Dgb3ANWI.js → slice_util-Dve4TkDn.js} +2 -2
  175. package/dist/{tfjs_backend-BjuQ5FqB.js → tfjs_backend-CydPRQTc.js} +2 -2
  176. package/dist/tokeniser/BaseTokeniser.js +1 -1
  177. package/dist/tokeniser/CharTokeniser.js +1 -1
  178. package/dist/tokeniser/bpe.js +1 -1
  179. package/dist/training/AdamW.js +1 -1
  180. package/dist/training/BasicTrainer.js +1 -1
  181. package/dist/training/DatasetBuilder.d.ts +0 -1
  182. package/dist/training/DatasetBuilder.js +2 -2
  183. package/dist/training/Evaluator.js +1 -1
  184. package/dist/training/PreTrainer.js +1 -1
  185. package/dist/training/SFTTrainer.js +1 -1
  186. package/dist/training/loss.js +2 -2
  187. package/dist/training/orthoGrad.js +1 -1
  188. package/dist/training/sparseCrossEntropy.js +1 -1
  189. package/dist/training/tasks/ConversationTask.js +1 -1
  190. package/dist/training/validation.js +1 -1
  191. package/dist/utilities/dummy.js +1 -1
  192. package/dist/utilities/float16.d.ts +3 -0
  193. package/dist/utilities/float16.js +46 -0
  194. package/dist/utilities/multinomialCPU.js +1 -1
  195. package/dist/utilities/packed.js +1 -1
  196. package/dist/utilities/performance.js +1 -1
  197. package/dist/utilities/profile.js +1 -1
  198. package/dist/utilities/safetensors.d.ts +3 -1
  199. package/dist/utilities/safetensors.js +46 -36
  200. package/dist/utilities/sentences.js +1 -1
  201. package/dist/utilities/weights.js +1 -1
  202. package/dist/{webgpu-Dt7BMzWz.js → webgpu-B19Tw8Nd.js} +3 -3
  203. package/dist/{webgpu_program-WOyIVMlZ.js → webgpu_program-B0PokuRJ.js} +1 -1
  204. package/dist/{webgpu_util-B_F3SShA.js → webgpu_util-DfODg6XI.js} +1 -1
  205. package/package.json +5 -5
  206. package/dist/dist-DXwIvKxl.js +0 -896
@@ -1,4 +1,4 @@
1
- import { t as e } from "./shared-D1coEFea.js";
1
+ import { t as e } from "./shared-24EoeHJl.js";
2
2
  //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/kernel_utils/shared.js
3
3
  var { addImpl: t, bincountImpl: n, bincountReduceImpl: r, bitwiseAndImpl: i, castImpl: a, ceilImpl: o, concatImpl: s, equalImpl: c, expImpl: l, expm1Impl: u, floorImpl: d, gatherNdImpl: f, gatherV2Impl: p, greaterImpl: m, greaterEqualImpl: h, lessImpl: g, lessEqualImpl: _, linSpaceImpl: v, logImpl: y, maxImpl: b, maximumImpl: x, minimumImpl: S, multiplyImpl: C, negImpl: w, notEqualImpl: T, prodImpl: E, raggedGatherImpl: D, raggedRangeImpl: O, raggedTensorToTensorImpl: k, rangeImpl: A, rsqrtImpl: j, scatterImpl: M, sigmoidImpl: N, simpleAbsImpl: P, sliceImpl: F, sparseFillEmptyRowsImpl: I, sparseReshapeImpl: L, sparseSegmentReductionImpl: R, sqrtImpl: z, staticRegexReplaceImpl: B, stridedSliceImpl: V, stringNGramsImpl: H, stringSplitImpl: U, stringToHashBucketFastImpl: W, subImpl: G, tileImpl: K, topKImpl: q, transposeImpl: J, uniqueImpl: Y } = e;
4
4
  //#endregion
@@ -1,5 +1,5 @@
1
- import { r as e } from "./chunk-BPntVaq0.js";
2
- import { Ls as t, Ps as n } from "./dist-BewPQWjc.js";
1
+ import { n as e } from "./chunk-CWhphoD1.js";
2
+ import { Ls as t, Ps as n } from "./dist-Da20xy8E.js";
3
3
  //#region node_modules/@tensorflow/tfjs-core/dist/ops/slice_util.js
4
4
  var r = /* @__PURE__ */ e({
5
5
  assertParamsValid: () => o,
@@ -1,5 +1,5 @@
1
- import { $ as e, An as t, Gr as n, In as r, L as i, Mi as a, Ps as o, Q as s, Ur as c, Wr as l, Wt as u, X as d, Yr as f, Z as p, _i as m, _r as h, an as g, b as _, br as v, cn as y, di as b, er as x, gr as S, ir as C, js as w, mi as T, mr as E, nr as D, oc as O, pi as k, pt as A, qr as j, rr as M, ti as N, tr as P, w as F, xi as I } from "./dist-BewPQWjc.js";
2
- import { a as ee, i as te, o as ne, r as re } from "./selu_util-zkAx5doH.js";
1
+ import { $ as e, An as t, Gr as n, In as r, L as i, Mi as a, Ps as o, Q as s, Ur as c, Wr as l, Wt as u, X as d, Yr as f, Z as p, _i as m, _r as h, an as g, b as _, br as v, cn as y, di as b, er as x, gr as S, ir as C, js as w, mi as T, mr as E, nr as D, oc as O, pi as k, pt as A, qr as j, rr as M, ti as N, tr as P, w as F, xi as I } from "./dist-Da20xy8E.js";
2
+ import { a as ee, i as te, o as ne, r as re } from "./selu_util-B_AFEfoz.js";
3
3
  //#region node_modules/@tensorflow/tfjs-core/dist/ops/fused/mat_mul.js
4
4
  function ie({ a: e, b: t, transposeA: n = !1, transposeB: i = !1, bias: a, activation: s = "linear", preluActivationWeights: c, leakyreluAlpha: l = .2 }) {
5
5
  if (ne(m.state.gradientDepth, s) === !1) {
@@ -1,2 +1,2 @@
1
- import { n as e, t } from "../BaseTokeniser-DSg9zcYq.js";
1
+ import { n as e, t } from "../BaseTokeniser-C9TSv4th.js";
2
2
  export { e as SPECIALS, t as default };
@@ -1,5 +1,5 @@
1
1
  import { yieldIfNeeded as e } from "../utilities/yielder.js";
2
- import { n as t, t as n } from "../BaseTokeniser-DSg9zcYq.js";
2
+ import { n as t, t as n } from "../BaseTokeniser-C9TSv4th.js";
3
3
  //#region lib/tokeniser/CharTokeniser.ts
4
4
  var r = ["<eos>", "<unk>"], i = class extends n {
5
5
  vocabSize = 0;
@@ -1,5 +1,5 @@
1
1
  import { yieldIfNeeded as e } from "../utilities/yielder.js";
2
- import { n as t, t as n } from "../BaseTokeniser-DSg9zcYq.js";
2
+ import { n as t, t as n } from "../BaseTokeniser-C9TSv4th.js";
3
3
  import r from "../utilities/tokenParse.js";
4
4
  //#region lib/tokeniser/bpe.ts
5
5
  function i(e, t) {
@@ -1,4 +1,4 @@
1
- import { _n as e, c as t, di as n, ii as r, kt as i, ni as a } from "../dist-BewPQWjc.js";
1
+ import { _n as e, c as t, di as n, ii as r, kt as i, ni as a } from "../dist-Da20xy8E.js";
2
2
  import { load_safetensors as o, save_safetensors as s } from "../utilities/safetensors.js";
3
3
  import { adamAdjust as c } from "../ops/adamAdjust.js";
4
4
  import { adamMoments as l } from "../ops/adamMoments.js";
@@ -1,4 +1,4 @@
1
- import { _n as e, di as t, kt as n, ni as r, oi as i, qt as a } from "../dist-BewPQWjc.js";
1
+ import { _n as e, di as t, kt as n, ni as r, oi as i, qt as a } from "../dist-Da20xy8E.js";
2
2
  import { AdamWOptimizer as o } from "./AdamW.js";
3
3
  import { calculateAccuracy as s, calculateLoss as c } from "./loss.js";
4
4
  import l from "./Evaluator.js";
@@ -1,7 +1,6 @@
1
1
  import { Tensor } from '@tensorflow/tfjs-core';
2
2
  import { Conversation, ITokeniser } from '../tokeniser/type';
3
3
  import { Dataset } from '@tensorflow/tfjs-data';
4
- export declare const PAGE_FACTOR = 8;
5
4
  export declare function flattenTokens(textData: Conversation[][], tokenizer: ITokeniser): Uint16Array;
6
5
  export declare function flattenTokensWithMask(textData: Conversation[][], tokenizer: ITokeniser): {
7
6
  tokens: Uint16Array;
@@ -1,2 +1,2 @@
1
- import { a as e, i as t, n, r, t as i } from "../DatasetBuilder-DgURD85T.js";
2
- export { i as DatasetBuilder, n as PAGE_FACTOR, r as flattenTokens, t as flattenTokensWithMask, e as shuffle };
1
+ import { i as e, n as t, r as n, t as r } from "../DatasetBuilder-B9UGNQT5.js";
2
+ export { r as DatasetBuilder, t as flattenTokens, n as flattenTokensWithMask, e as shuffle };
@@ -1,4 +1,4 @@
1
- import { di as e } from "../dist-BewPQWjc.js";
1
+ import { di as e } from "../dist-Da20xy8E.js";
2
2
  import { calculateAccuracy as t, calculateLoss as n } from "./loss.js";
3
3
  //#region lib/training/Evaluator.ts
4
4
  var r = class {
@@ -1,4 +1,4 @@
1
- import { t as e } from "../DatasetBuilder-DgURD85T.js";
1
+ import { t as e } from "../DatasetBuilder-B9UGNQT5.js";
2
2
  import t from "./BasicTrainer.js";
3
3
  //#region lib/training/PreTrainer.ts
4
4
  var n = {
@@ -1,4 +1,4 @@
1
- import { t as e } from "../DatasetBuilder-DgURD85T.js";
1
+ import { t as e } from "../DatasetBuilder-B9UGNQT5.js";
2
2
  import t from "./BasicTrainer.js";
3
3
  //#region lib/training/SFTTrainer.ts
4
4
  var n = {
@@ -4,7 +4,7 @@ function t(t, n, r, i, a) {
4
4
  try {
5
5
  return e(r, i, a && a > 0 ? a : void 0)(t, n);
6
6
  } catch (e) {
7
- throw console.error("Error computing loss:", e), Error(`Loss computation failed: ${e}`);
7
+ throw console.error("Error computing loss:", e), Error("Loss computation failed", { cause: e });
8
8
  }
9
9
  }
10
10
  function n(e, t) {
@@ -12,7 +12,7 @@ function n(e, t) {
12
12
  let n = e.argMax(-1), r = n.equal(t).cast("float32"), i = r.mean();
13
13
  return n.dispose(), r.dispose(), i;
14
14
  } catch (e) {
15
- throw console.error("Error computing accuracy:", e), Error(`Accuracy computation failed: ${e}`);
15
+ throw console.error("Error computing accuracy:", e), Error("Accuracy computation failed.", { cause: e });
16
16
  }
17
17
  }
18
18
  //#endregion
@@ -1,4 +1,4 @@
1
- import { di as e } from "../dist-BewPQWjc.js";
1
+ import { di as e } from "../dist-Da20xy8E.js";
2
2
  //#region lib/training/orthoGrad.ts
3
3
  function t(t, n, r) {
4
4
  return e(() => {
@@ -1,4 +1,4 @@
1
- import { At as e, Bt as t, Gr as n, Nn as r, Pn as i, Rt as a, St as o, Wr as s, Wt as c, Y as l, _n as u, bn as d, di as f, mn as p, qr as m } from "../dist-BewPQWjc.js";
1
+ import { At as e, Bt as t, Gr as n, Nn as r, Pn as i, Rt as a, St as o, Wr as s, Wt as c, Y as l, _n as u, bn as d, di as f, mn as p, qr as m } from "../dist-Da20xy8E.js";
2
2
  import { gatherSub as h } from "../ops/gatherSub.js";
3
3
  import { scatterSub as g } from "../ops/scatterSub.js";
4
4
  //#region lib/training/sparseCrossEntropy.ts
@@ -1,4 +1,4 @@
1
- import { a as e } from "../../DatasetBuilder-DgURD85T.js";
1
+ import { i as e } from "../../DatasetBuilder-B9UGNQT5.js";
2
2
  import { Task as t } from "./Task.js";
3
3
  //#region lib/training/tasks/ConversationTask.ts
4
4
  var n = class extends t {
@@ -1,2 +1,2 @@
1
- import { o as e } from "../main-BTmbwF1h.js";
1
+ import { o as e } from "../main-DdsoTJAW.js";
2
2
  export { e as createTrainValidationSplit };
@@ -1,4 +1,4 @@
1
- import { ii as e, kt as t, qt as n, si as r } from "../dist-BewPQWjc.js";
1
+ import { ii as e, kt as t, qt as n, si as r } from "../dist-Da20xy8E.js";
2
2
  //#region lib/utilities/dummy.ts
3
3
  async function i(e) {
4
4
  let n = t([1, e.config.blockSize], "int32"), r = e.forward({ training: !1 }, n);
@@ -0,0 +1,3 @@
1
+ export declare function toFloat16Array(float32arr: Float32Array): Uint16Array;
2
+ export declare function loadFloat16FromBuffer(buffer: ArrayBuffer, byteOffset: number, length: number): Float32Array;
3
+ export declare function manualFloat16Array(float32arr: Float32Array): Uint16Array;
@@ -0,0 +1,46 @@
1
+ //#region lib/utilities/float16.ts
2
+ function e(e) {
3
+ if (typeof Float16Array < "u") {
4
+ let t = new Float16Array(e);
5
+ return new Uint16Array(t.buffer);
6
+ }
7
+ return i(e);
8
+ }
9
+ function t(e, t, r) {
10
+ if (typeof Float16Array < "u") {
11
+ let n = new Float16Array(e, t, r);
12
+ return new Float32Array(n);
13
+ }
14
+ return n(e, t, r);
15
+ }
16
+ function n(e, t, n) {
17
+ let i = new Uint16Array(e, t, n), a = new Float32Array(n);
18
+ for (let e = 0; e < n; e++) a[e] = r(i[e]);
19
+ return a;
20
+ }
21
+ function r(e) {
22
+ let t = e & 32768 ? -1 : 1, n = e >>> 10 & 31, r = e & 1023;
23
+ return n === 0 ? t * r * 2 ** -24 : n === 31 ? r ? NaN : t * Infinity : t * (1 + r / 1024) * 2 ** (n - 15);
24
+ }
25
+ function i(e) {
26
+ let t = new Uint16Array(e.length), n = new Float32Array(1), r = new Uint32Array(n.buffer);
27
+ for (let i = 0; i < e.length; i++) {
28
+ n[0] = e[i];
29
+ let a = r[0], o = a >>> 16 & 32768, s = (a >>> 23 & 255) - 127 + 15, c = a & 8388607;
30
+ if ((a >>> 23 & 255) == 255) t[i] = o | 31744 | (c ? 512 : 0);
31
+ else if (s >= 31) t[i] = o | 31744;
32
+ else if (s <= 0) if (s < -10) t[i] = o;
33
+ else {
34
+ c |= 8388608;
35
+ let e = 14 - s, n = c >>> e;
36
+ c >>> e - 1 & 1 && (c & (1 << e - 1) - 1 || n & 1) && n++, t[i] = o | n;
37
+ }
38
+ else {
39
+ let e = s << 10 | c >>> 13;
40
+ c & 4096 && (c & 4095 || e & 1) && (e++, (e & 31744) == 31744 && (e = o | 31744)), t[i] = o | e;
41
+ }
42
+ }
43
+ return t;
44
+ }
45
+ //#endregion
46
+ export { t as loadFloat16FromBuffer, i as manualFloat16Array, e as toFloat16Array };
@@ -1,4 +1,4 @@
1
- import { I as e } from "../dist-BewPQWjc.js";
1
+ import { I as e } from "../dist-Da20xy8E.js";
2
2
  //#region lib/utilities/multinomialCPU.ts
3
3
  function t(t, n) {
4
4
  let r = 0, i = n ?? Math.random();
@@ -1,4 +1,4 @@
1
- import { ii as e } from "../dist-BewPQWjc.js";
1
+ import { ii as e } from "../dist-Da20xy8E.js";
2
2
  //#region lib/utilities/packed.ts
3
3
  function t() {
4
4
  return e().backendName === "webgpu";
@@ -1,4 +1,4 @@
1
- import { di as e } from "../dist-BewPQWjc.js";
1
+ import { di as e } from "../dist-Da20xy8E.js";
2
2
  //#region lib/utilities/performance.ts
3
3
  async function t(t, n = 10, r = !1) {
4
4
  for (let n = 0; n < 100; n++) {
@@ -1,4 +1,4 @@
1
- import { si as e } from "../dist-BewPQWjc.js";
1
+ import { si as e } from "../dist-Da20xy8E.js";
2
2
  //#region lib/utilities/profile.ts
3
3
  var t = 1024 * 1024, n = class {
4
4
  log = /* @__PURE__ */ new Map();
@@ -1,3 +1,5 @@
1
1
  import { Tensor } from '@tensorflow/tfjs-core';
2
- export declare function save_safetensors(tensors: Record<string, Tensor>): Promise<ArrayBuffer>;
2
+ type Quantization = 'none' | 'F16';
3
+ export declare function save_safetensors(tensors: Record<string, Tensor>, quantize?: Quantization): Promise<ArrayBuffer>;
3
4
  export declare function load_safetensors(buffer: ArrayBuffer): Promise<Record<string, Tensor>>;
5
+ export {};
@@ -1,53 +1,63 @@
1
- import { fi as e } from "../dist-BewPQWjc.js";
1
+ import { fi as e } from "../dist-Da20xy8E.js";
2
+ import { loadFloat16FromBuffer as t, toFloat16Array as n } from "./float16.js";
2
3
  //#region lib/utilities/safetensors.ts
3
- function t(e) {
4
+ function r(e, t = "none") {
5
+ if (t === "F16" && e === "float32") return "F16";
4
6
  if (e === "float32") return "F32";
5
7
  if (e === "int32") return "I32";
6
8
  throw Error(`Unsupported dtype: ${e}`);
7
9
  }
8
- function n(e) {
10
+ function i(e) {
9
11
  if (e === "F32") return "float32";
10
12
  if (e === "I32") return "int32";
13
+ if (e === "F16") return "float32";
11
14
  throw Error(`Unsupported dtype: ${e}`);
12
15
  }
13
- async function r(e) {
14
- let n = {}, r = 0;
15
- for (let [i, a] of Object.entries(e)) n[i] = {
16
- dtype: t(a.dtype),
17
- shape: a.shape,
18
- data_offsets: [r, r + a.size * 4]
19
- }, r += a.size * 4;
20
- let i = JSON.stringify(n), a = new TextEncoder().encode(i);
21
- if (a.length % 4 != 0) {
22
- let e = 4 - a.length % 4, t = new Uint8Array(a.length + e);
23
- t.set(a);
24
- for (let e = a.length; e < t.length; e++) t[e] = 32;
25
- a = t;
16
+ async function a(e, t = "none") {
17
+ let i = {}, a = 0;
18
+ for (let [n, o] of Object.entries(e)) {
19
+ let e = r(o.dtype, t), s = e === "F16" ? 2 : 4;
20
+ i[n] = {
21
+ dtype: e,
22
+ shape: o.shape,
23
+ data_offsets: [a, a + o.size * s]
24
+ }, a += o.size * s;
26
25
  }
27
- let o = a.length, s = 8 + o + r, c = new ArrayBuffer(s);
28
- new DataView(c).setUint32(0, o, !0), new Uint8Array(c, 8, o).set(a);
29
- let l = 8 + o;
30
- for (let t of Object.values(e)) {
31
- if (t.size === 0) continue;
32
- let e = await t.data();
33
- if (t.dtype === "float32") new Float32Array(c, l, t.size).set(e), l += t.size * 4;
34
- else if (t.dtype === "int32") new Int32Array(c, l, t.size).set(e), l += t.size * 4;
35
- else throw Error(`Unsupported dtype: ${t.dtype}`);
26
+ let o = JSON.stringify(i), s = new TextEncoder().encode(o);
27
+ if (s.length % 4 != 0) {
28
+ let e = 4 - s.length % 4, t = new Uint8Array(s.length + e);
29
+ t.set(s);
30
+ for (let e = s.length; e < t.length; e++) t[e] = 32;
31
+ s = t;
36
32
  }
37
- return c;
33
+ let c = s.length, l = 8 + c + a, u = new ArrayBuffer(l), d = new DataView(u);
34
+ d.setUint32(0, c, !0), d.setUint32(4, 0, !0), new Uint8Array(u, 8, c).set(s);
35
+ let f = 8 + c;
36
+ for (let r of Object.values(e)) {
37
+ if (r.size === 0) continue;
38
+ let e = await r.data();
39
+ if (r.dtype === "float32") if (t === "F16") {
40
+ let t = n(e);
41
+ new Uint16Array(u, f, r.size).set(t), f += r.size * 2;
42
+ } else new Float32Array(u, f, r.size).set(e), f += r.size * 4;
43
+ else if (r.dtype === "int32") new Int32Array(u, f, r.size).set(e), f += r.size * 4;
44
+ else throw Error(`Unsupported dtype: ${r.dtype}`);
45
+ }
46
+ return u;
38
47
  }
39
- async function i(t) {
40
- let r = new DataView(t).getUint32(0, !0), i = new Uint8Array(t, 8, r), a = JSON.parse(new TextDecoder().decode(i)), o = {};
41
- for (let [i, s] of Object.entries(a)) {
42
- if (s.data_offsets[0] === s.data_offsets[1]) {
43
- o[i] = e([], s.shape, n(s.dtype));
48
+ async function o(n) {
49
+ let r = new DataView(n).getUint32(0, !0), a = new Uint8Array(n, 8, r), o = JSON.parse(new TextDecoder().decode(a)), s = {};
50
+ for (let [a, c] of Object.entries(o)) if (a !== "__metadata__") {
51
+ if (c.data_offsets[0] === c.data_offsets[1]) {
52
+ s[a] = e([], c.shape, i(c.dtype));
44
53
  continue;
45
54
  }
46
- if (s.dtype === "F32") o[i] = e(new Float32Array(t, s.data_offsets[0] + 8 + r, (s.data_offsets[1] - s.data_offsets[0]) / 4), s.shape, n(s.dtype));
47
- else if (s.dtype === "I32") o[i] = e(new Int32Array(t, s.data_offsets[0] + 8 + r, (s.data_offsets[1] - s.data_offsets[0]) / 4), s.shape, n(s.dtype));
48
- else throw Error(`Unsupported dtype: ${s.dtype}`);
55
+ if (c.dtype === "F16") s[a] = e(t(n, c.data_offsets[0] + 8 + r, (c.data_offsets[1] - c.data_offsets[0]) / 2), c.shape, i(c.dtype));
56
+ else if (c.dtype === "F32") s[a] = e(new Float32Array(n, c.data_offsets[0] + 8 + r, (c.data_offsets[1] - c.data_offsets[0]) / 4), c.shape, i(c.dtype));
57
+ else if (c.dtype === "I32") s[a] = e(new Int32Array(n, c.data_offsets[0] + 8 + r, (c.data_offsets[1] - c.data_offsets[0]) / 4), c.shape, i(c.dtype));
58
+ else throw Error(`Unsupported dtype: ${c.dtype}`);
49
59
  }
50
- return o;
60
+ return s;
51
61
  }
52
62
  //#endregion
53
- export { i as load_safetensors, r as save_safetensors };
63
+ export { o as load_safetensors, a as save_safetensors };
@@ -1,4 +1,4 @@
1
- import { I as e, Wr as t, _r as n, mn as r, un as i } from "../dist-BewPQWjc.js";
1
+ import { I as e, Wr as t, _r as n, mn as r, un as i } from "../dist-Da20xy8E.js";
2
2
  //#region lib/utilities/sentences.ts
3
3
  var a = 16;
4
4
  function o(e, n) {
@@ -1,4 +1,4 @@
1
- import { fi as e } from "../dist-BewPQWjc.js";
1
+ import { fi as e } from "../dist-Da20xy8E.js";
2
2
  //#region lib/utilities/weights.ts
3
3
  function t(e) {
4
4
  let t = e.reduce((e, t) => e + t.length, 0), n = new Float32Array(t), r = 0;
@@ -1,7 +1,7 @@
1
- import { Ai as e, Ms as t, Oi as n, Ps as r, Rs as i, Vs as a, Xr as o, Ys as s, fc as c, ii as l, ki as u, lc as d, oc as f, pc as p, zs as m } from "./dist-BewPQWjc.js";
1
+ import { Ai as e, Ms as t, Oi as n, Ps as r, Rs as i, Vs as a, Xr as o, Ys as s, fc as c, ii as l, ki as u, lc as d, oc as f, pc as p, zs as m } from "./dist-Da20xy8E.js";
2
2
  import { s as h } from "./complex_util-CkazZsaH.js";
3
- import { l as g, n as _, t as v } from "./webgpu_program-WOyIVMlZ.js";
4
- import { l as y, t as b } from "./webgpu_util-B_F3SShA.js";
3
+ import { l as g, n as _, t as v } from "./webgpu_program-B0PokuRJ.js";
4
+ import { l as y, t as b } from "./webgpu_util-DfODg6XI.js";
5
5
  //#region node_modules/@tensorflow/tfjs-backend-webgpu/dist/flags_webgpu.js
6
6
  var x = t();
7
7
  x.registerFlag("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE", () => 15), x.registerFlag("WEBGPU_CPU_FORWARD", () => !0), x.registerFlag("WEBGPU_MATMUL_PROGRAM_TYPE", () => -1), x.registerFlag("WEBGPU_USE_NAIVE_CONV2D_TRANSPOSE", () => !0), x.registerFlag("WEBGPU_USE_LOW_POWER_GPU", () => !1), x.registerFlag("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD", () => 1e3), x.registerFlag("WEBGPU_USE_PROFILE_TOOL", () => !1), x.registerFlag("WEBGPU_IMPORT_EXTERNAL_TEXTURE", () => !0), x.registerFlag("WEBGPU_USE_NAIVE_CONV2D_DEBUG", () => !1), x.registerFlag("WEBGPU_THRESHOLD_TO_INCREASE_WORKGROUPS_FOR_MATMUL", () => -1), x.registerFlag("WEBGPU_CONV_SEPARATE_IM2COL_SHADER", () => !1), x.registerFlag("WEBGPU_PRINT_SHADER", () => ""), x.registerFlag("WEBGPU_ENGINE_COMPILE_ONLY", () => !1);
@@ -1,4 +1,4 @@
1
- import { Ln as e, Ms as t, Ns as n, Ps as r, Rs as i } from "./dist-BewPQWjc.js";
1
+ import { Ln as e, Ms as t, Ns as n, Ps as r, Rs as i } from "./dist-Da20xy8E.js";
2
2
  //#region node_modules/@tensorflow/tfjs-backend-webgpu/dist/shader_util.js
3
3
  function a(e, t) {
4
4
  if (Math.max(...e) > 5) throw Error("Cannot symbolically compute strides for rank > 6 tensor.");
@@ -1,4 +1,4 @@
1
- import { Ps as e } from "./dist-BewPQWjc.js";
1
+ import { Ps as e } from "./dist-Da20xy8E.js";
2
2
  //#region node_modules/@tensorflow/tfjs-backend-webgpu/dist/webgpu_util.js
3
3
  var t = (e) => {
4
4
  let t = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "0.20.7",
3
+ "version": "0.21.0",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -20,14 +20,14 @@
20
20
  "build:script": "tsc -p scripts/tsconfig.json",
21
21
  "preview": "vite preview",
22
22
  "lint": "eslint",
23
- "test": "vitest",
23
+ "test": "vitest --execArgv=\"--js-float16array\"",
24
24
  "test:gl": "playwright test",
25
25
  "ci:test": "vitest --coverage --reporter=junit --outputFile=junit.xml",
26
26
  "coverage": "vitest run --coverage",
27
27
  "postinstall": "patch-package"
28
28
  },
29
29
  "devDependencies": {
30
- "@eslint/js": "^9.32.0",
30
+ "@eslint/js": "^10.0.1",
31
31
  "@playwright/test": "^1.55.0",
32
32
  "@types/node": "^22.13.14",
33
33
  "@types/papaparse": "^5.3.16",
@@ -36,15 +36,15 @@
36
36
  "@vitest/coverage-v8": "^4.1.9",
37
37
  "chalk": "^5.4.1",
38
38
  "dayjs": "^1.11.13",
39
- "eslint": "^9.32.0",
39
+ "eslint": "^10.8.0",
40
40
  "glob": "^11.0.3",
41
+ "globals": "^17.8.0",
41
42
  "jsdom": "^27.4.0",
42
43
  "tsx": "^4.20.3",
43
44
  "typescript": "^6.0.3",
44
45
  "typescript-eslint": "^8.61.1",
45
46
  "vite": "^8.0.16",
46
47
  "vite-plugin-dts": "^5.0.2",
47
- "vite-plugin-node-polyfills": "^0.28.0",
48
48
  "vitest": "^4.1.9",
49
49
  "webgpu": "^0.4.0",
50
50
  "yargs": "^18.0.0"