@genai-fi/nanogpt 0.2.12 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/Generator.js +30 -25
  2. package/dist/NanoGPTModel.d.ts +13 -14
  3. package/dist/NanoGPTModel.js +142 -70
  4. package/dist/TeachableLLM.d.ts +16 -7
  5. package/dist/TeachableLLM.js +81 -44
  6. package/dist/Trainer.js +8 -8
  7. package/dist/concat-BIZS_td9.js +33 -0
  8. package/dist/data/parquet.js +1 -1
  9. package/dist/exports_layers-tbTBcwMM.js +25 -0
  10. package/dist/{sum-D7fu15XL.js → gather-BPGW8RsB.js} +6 -8
  11. package/dist/index-C4L8Cm77.js +349 -0
  12. package/dist/{index-YPKosni4.js → index-pWA4_lUh.js} +1020 -782
  13. package/dist/layers/CausalSelfAttention.d.ts +11 -11
  14. package/dist/layers/CausalSelfAttention.js +71 -63
  15. package/dist/layers/MLP.d.ts +6 -7
  16. package/dist/layers/MLP.js +18 -16
  17. package/dist/layers/RMSNorm.d.ts +6 -7
  18. package/dist/layers/RMSNorm.js +15 -13
  19. package/dist/layers/RoPECache.d.ts +4 -5
  20. package/dist/layers/RoPECache.js +36 -12
  21. package/dist/layers/TiedEmbedding.d.ts +7 -8
  22. package/dist/layers/TiedEmbedding.js +16 -418
  23. package/dist/layers/TransformerBlock.d.ts +8 -9
  24. package/dist/layers/TransformerBlock.js +12 -12
  25. package/dist/main.d.ts +2 -0
  26. package/dist/main.js +35 -21
  27. package/dist/{mat_mul-Bu7bhLms.js → mat_mul-D7_a4KJn.js} +5 -5
  28. package/dist/moments-DfcpfwKi.js +132 -0
  29. package/dist/ones-Cog-G2ag.js +29 -0
  30. package/dist/ops/appendCache.d.ts +2 -0
  31. package/dist/ops/appendCache.js +9 -0
  32. package/dist/ops/attentionMask.d.ts +1 -1
  33. package/dist/ops/attentionMask.js +7 -85
  34. package/dist/ops/cpu/appendCache.d.ts +2 -0
  35. package/dist/ops/cpu/appendCache.js +28 -0
  36. package/dist/ops/cpu/attentionMask.js +18 -0
  37. package/dist/ops/cpu/gatherSub.d.ts +1 -0
  38. package/dist/ops/cpu/gatherSub.js +34 -0
  39. package/dist/ops/cpu/qkv.d.ts +5 -0
  40. package/dist/ops/cpu/qkv.js +38 -0
  41. package/dist/ops/cpu/rope.d.ts +6 -0
  42. package/dist/ops/cpu/rope.js +38 -0
  43. package/dist/ops/cpu/scatterSub.d.ts +1 -0
  44. package/dist/ops/cpu/scatterSub.js +70 -0
  45. package/dist/ops/gatherSub.d.ts +1 -1
  46. package/dist/ops/gatherSub.js +6 -63
  47. package/dist/ops/grads/attentionMask.d.ts +1 -0
  48. package/dist/ops/grads/attentionMask.js +21 -0
  49. package/dist/ops/grads/qkv.d.ts +1 -0
  50. package/dist/ops/grads/qkv.js +20 -0
  51. package/dist/ops/grads/rope.d.ts +1 -0
  52. package/dist/ops/grads/rope.js +14 -0
  53. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  54. package/dist/ops/qkv.d.ts +1 -6
  55. package/dist/ops/qkv.js +7 -124
  56. package/dist/ops/rope.d.ts +0 -5
  57. package/dist/ops/rope.js +7 -151
  58. package/dist/ops/scatterSub.d.ts +1 -1
  59. package/dist/ops/scatterSub.js +6 -147
  60. package/dist/ops/webgl/appendCache.d.ts +1 -0
  61. package/dist/ops/webgl/appendCache.js +43 -0
  62. package/dist/ops/webgl/attentionMask.d.ts +1 -0
  63. package/dist/ops/webgl/attentionMask.js +43 -0
  64. package/dist/ops/webgl/gatherSub.d.ts +1 -0
  65. package/dist/ops/webgl/gatherSub.js +27 -0
  66. package/dist/ops/webgl/qkv.d.ts +1 -0
  67. package/dist/ops/webgl/qkv.js +46 -0
  68. package/dist/ops/webgl/rope.d.ts +1 -0
  69. package/dist/ops/webgl/rope.js +56 -0
  70. package/dist/ops/webgl/scatterSub.d.ts +1 -0
  71. package/dist/ops/webgl/scatterSub.js +27 -0
  72. package/dist/{parquet-BRl5lE_I.js → parquet-C0Tlmv9c.js} +3045 -3048
  73. package/dist/random_width-oeUIlUZj.js +15487 -0
  74. package/dist/range-CcDl05lo.js +26 -0
  75. package/dist/{reshape-DmnmKT6r.js → reshape-C8CR_Bad.js} +3 -3
  76. package/dist/sin-BJIrfnj7.js +47 -0
  77. package/dist/softmax-Be_lsqUc.js +105 -0
  78. package/dist/{complex-CJ-qCcLB.js → split-DZbvruEP.js} +6 -8
  79. package/dist/stack-BMm-efee.js +27 -0
  80. package/dist/sum-C7Mgy9Bw.js +104 -0
  81. package/dist/tensor-DJVbYhh1.js +24 -0
  82. package/dist/tensor2d-ZuQSh2D-.js +30 -0
  83. package/dist/tokeniser/bpe.d.ts +17 -6
  84. package/dist/tokeniser/bpe.js +89 -61
  85. package/dist/training/AdamExt.js +1 -1
  86. package/dist/training/DatasetBuilder.d.ts +6 -6
  87. package/dist/training/DatasetBuilder.js +1262 -17
  88. package/dist/training/Evaluator.d.ts +3 -2
  89. package/dist/training/FullTrainer.d.ts +9 -8
  90. package/dist/training/FullTrainer.js +26 -25
  91. package/dist/training/LayerTrainer.d.ts +9 -8
  92. package/dist/training/LayerTrainer.js +34 -33
  93. package/dist/training/Trainer.d.ts +22 -21
  94. package/dist/training/Trainer.js +21 -18
  95. package/dist/training/sparseCrossEntropy.js +22 -166
  96. package/dist/utilities/dummy.js +10 -8
  97. package/dist/utilities/generate.js +14 -11
  98. package/dist/utilities/load.d.ts +1 -2
  99. package/dist/utilities/load.js +37 -35
  100. package/dist/utilities/profile.js +1 -1
  101. package/dist/utilities/save.js +14 -9
  102. package/dist/utilities/tokenParse.d.ts +1 -1
  103. package/dist/utilities/tokenParse.js +7 -61
  104. package/dist/utilities/weights.d.ts +3 -3
  105. package/dist/utilities/weights.js +21 -19
  106. package/dist/variable-Dl_ub3pk.js +23 -0
  107. package/dist/{stack-BtKpB0Ry.js → zeros-CCy9C3uU.js} +18 -16
  108. package/package.json +2 -1
  109. package/dist/assets/worker-BYeSPNkq.js +0 -1
  110. package/dist/tokeniser/NodeTokeniser.d.ts +0 -20
  111. package/dist/tokeniser/NodeTokeniser.js +0 -46
  112. package/dist/tokeniser/WebTokeniser.d.ts +0 -18
  113. package/dist/tokeniser/WebTokeniser.js +0 -96
  114. package/dist/tokeniser/worker.js +0 -53
  115. /package/dist/{tokeniser/worker.d.ts → ops/cpu/attentionMask.d.ts} +0 -0
@@ -1,96 +0,0 @@
1
- import { E as d } from "../index-Dwqa6Zy2.js";
2
- const t = new Worker(new URL(
3
- /* @vite-ignore */
4
- "/assets/worker-BYeSPNkq.js",
5
- import.meta.url
6
- ), {
7
- type: "module"
8
- });
9
- let r = 0;
10
- class m extends d {
11
- id;
12
- vocabSize = 0;
13
- handler;
14
- constructor() {
15
- super(), this.id = r++, this.handler = (e) => {
16
- e.data.type === "trainStatus" && e.data.id === this.id && (this.vocabSize = e.data.vocabSize, this.emit("trainStatus", e.data.progress, e.data.vocabSize));
17
- }, t.addEventListener("message", this.handler);
18
- }
19
- destroy() {
20
- this.handler && (t.removeEventListener("message", this.handler), this.handler = void 0);
21
- }
22
- post(e) {
23
- t.postMessage(e);
24
- }
25
- async train(e, n) {
26
- return new Promise((s) => {
27
- const i = (a) => {
28
- a.data.type === "trainResponse" && a.data.id === this.id && (t.removeEventListener("message", i), this.vocabSize = a.data.vocabSize, s(this.vocabSize));
29
- };
30
- t.addEventListener("message", i), this.post({
31
- type: "train",
32
- id: this.id,
33
- text: e,
34
- vocabSize: n
35
- });
36
- });
37
- }
38
- async tokenise(e, n) {
39
- return new Promise((s) => {
40
- const i = (a) => {
41
- a.data.type === "tokeniseResponse" && a.data.id === this.id && (t.removeEventListener("message", i), s(a.data.tokens));
42
- };
43
- t.addEventListener("message", i), this.post({
44
- type: "tokenise",
45
- id: this.id,
46
- text: e,
47
- numeric: n
48
- });
49
- });
50
- }
51
- async detokenise(e) {
52
- return new Promise((n) => {
53
- const s = (i) => {
54
- i.data.type === "detokeniseResponse" && i.data.id === this.id && (t.removeEventListener("message", s), n(i.data.text));
55
- };
56
- t.addEventListener("message", s), this.post({
57
- type: "detokenise",
58
- id: this.id,
59
- tokens: e
60
- });
61
- });
62
- }
63
- async encode(e) {
64
- return (await this.tokenise([e], !0))[0];
65
- }
66
- async decode(e) {
67
- return (await this.detokenise([e]))[0];
68
- }
69
- async getVocab() {
70
- return new Promise((e) => {
71
- const n = (s) => {
72
- s.data.type === "tokensResponse" && s.data.id === this.id && (t.removeEventListener("message", n), e(s.data.tokens));
73
- };
74
- t.addEventListener("message", n), this.post({
75
- type: "tokens",
76
- id: this.id
77
- });
78
- });
79
- }
80
- async createTrainingData(e, n = 5) {
81
- return new Promise((s) => {
82
- const i = (a) => {
83
- a.data.type === "buildTrainingDataResponse" && a.data.id === this.id && (t.removeEventListener("message", i), s(a.data.trainingData));
84
- };
85
- t.addEventListener("message", i), this.post({
86
- type: "buildTrainingData",
87
- id: this.id,
88
- text: e,
89
- windowSize: n
90
- });
91
- });
92
- }
93
- }
94
- export {
95
- m as default
96
- };
@@ -1,53 +0,0 @@
1
- import d from "./bpe.js";
2
- let e = new d();
3
- onmessage = async (s) => {
4
- if (s.data.type === "tokenise")
5
- if (s.data.numeric) {
6
- const t = e.tokenise(s.data.text, !0), a = {
7
- type: "tokeniseResponse",
8
- id: s.data.id,
9
- tokens: t,
10
- numeric: !0
11
- };
12
- postMessage(a);
13
- } else {
14
- const t = e.tokenise(s.data.text), a = {
15
- type: "tokeniseResponse",
16
- id: s.data.id,
17
- tokens: t,
18
- numeric: !1
19
- };
20
- postMessage(a);
21
- }
22
- else if (s.data.type === "detokenise") {
23
- const t = e.getVocab(), a = s.data.tokens.map((i) => i.map((n) => t[n]).join("")), o = {
24
- type: "detokeniseResponse",
25
- id: s.data.id,
26
- text: a
27
- };
28
- postMessage(o);
29
- } else if (s.data.type === "train") {
30
- e = new d(), e.train(s.data.text, s.data.vocabSize ?? 100, (a, o) => {
31
- const i = {
32
- type: "trainStatus",
33
- id: s.data.id,
34
- progress: a,
35
- vocabSize: o
36
- };
37
- postMessage(i);
38
- });
39
- const t = {
40
- type: "trainResponse",
41
- id: s.data.id,
42
- vocabSize: e.getVocab().length
43
- };
44
- postMessage(t);
45
- } else if (s.data.type === "tokens") {
46
- const t = e.getVocab(), a = {
47
- type: "tokensResponse",
48
- id: s.data.id,
49
- tokens: t
50
- };
51
- postMessage(a);
52
- }
53
- };