@genai-fi/nanogpt 0.3.1 → 0.4.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 (101) hide show
  1. package/dist/Generator.js +22 -22
  2. package/dist/MLP-KHhikThU.js +83 -0
  3. package/dist/NanoGPTModel.d.ts +2 -3
  4. package/dist/NanoGPTModel.js +79 -79
  5. package/dist/TeachableLLM.d.ts +4 -3
  6. package/dist/TeachableLLM.js +16 -13
  7. package/dist/Trainer.js +20 -13
  8. package/dist/axis_util-DeydwOoC.js +69 -0
  9. package/dist/{concat-BIZS_td9.js → concat-DS_qH7MI.js} +5 -5
  10. package/dist/config.js +7 -8
  11. package/dist/{gather-BPGW8RsB.js → gather-BUmJIS8n.js} +1 -1
  12. package/dist/{index-pWA4_lUh.js → index-XjBAhiFO.js} +1272 -1174
  13. package/dist/layers/BaseLayer.d.ts +14 -2
  14. package/dist/layers/BaseLayer.js +9 -9
  15. package/dist/layers/CausalSelfAttention.d.ts +4 -8
  16. package/dist/layers/CausalSelfAttention.js +108 -82
  17. package/dist/layers/MLP.d.ts +2 -3
  18. package/dist/layers/MLP.js +5 -62
  19. package/dist/layers/RMSNorm.d.ts +2 -2
  20. package/dist/layers/RMSNorm.js +11 -11
  21. package/dist/layers/RoPECache.js +3 -3
  22. package/dist/layers/TiedEmbedding.js +7 -6
  23. package/dist/layers/TransformerBlock.d.ts +2 -6
  24. package/dist/layers/TransformerBlock.js +9 -12
  25. package/dist/{sum-C7Mgy9Bw.js → log_sum_exp-DJPkVZZn.js} +32 -54
  26. package/dist/main.js +22 -19
  27. package/dist/{mat_mul-D7_a4KJn.js → mat_mul-CKwFEV1Q.js} +1 -1
  28. package/dist/max-DJvEiCAJ.js +25 -0
  29. package/dist/moments-CrWRPcR3.js +53 -0
  30. package/dist/norm-BzY929B_.js +86 -0
  31. package/dist/{ones-Cog-G2ag.js → ones-BO01zpJG.js} +2 -2
  32. package/dist/ops/appendCache.js +1 -1
  33. package/dist/ops/attentionMask.js +1 -1
  34. package/dist/ops/cpu/appendCache.js +2 -2
  35. package/dist/ops/cpu/attentionMask.js +2 -2
  36. package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
  37. package/dist/ops/cpu/fusedSoftmax.js +23 -0
  38. package/dist/ops/cpu/gatherSub.js +3 -3
  39. package/dist/ops/cpu/mulDropout.d.ts +1 -0
  40. package/dist/ops/cpu/mulDropout.js +17 -0
  41. package/dist/ops/cpu/qkv.js +3 -3
  42. package/dist/ops/cpu/rope.js +5 -5
  43. package/dist/ops/cpu/scatterSub.js +27 -27
  44. package/dist/ops/fusedSoftmax.d.ts +2 -0
  45. package/dist/ops/fusedSoftmax.js +10 -0
  46. package/dist/ops/gatherSub.js +1 -1
  47. package/dist/ops/grads/attentionMask.js +1 -1
  48. package/dist/ops/grads/fusedSoftmax.d.ts +2 -0
  49. package/dist/ops/grads/fusedSoftmax.js +17 -0
  50. package/dist/ops/grads/qkv.js +1 -1
  51. package/dist/ops/grads/rope.js +1 -1
  52. package/dist/ops/mulDrop.d.ts +2 -0
  53. package/dist/ops/mulDrop.js +9 -0
  54. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  55. package/dist/ops/qkv.js +1 -1
  56. package/dist/ops/scatterSub.js +1 -1
  57. package/dist/ops/webgl/appendCache.js +1 -1
  58. package/dist/ops/webgl/attentionMask.js +1 -1
  59. package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
  60. package/dist/ops/webgl/fusedSoftmax.js +3930 -0
  61. package/dist/ops/webgl/gatherSub.js +1 -1
  62. package/dist/ops/webgl/mulDropout.d.ts +1 -0
  63. package/dist/ops/webgl/mulDropout.js +41 -0
  64. package/dist/ops/webgl/qkv.js +1 -1
  65. package/dist/ops/webgl/rope.js +1 -1
  66. package/dist/ops/webgl/scatterSub.js +1 -1
  67. package/dist/{random_width-oeUIlUZj.js → random_width-CMHmdbSu.js} +4212 -6630
  68. package/dist/{range-CcDl05lo.js → range-DQMNzBWs.js} +1 -1
  69. package/dist/{reshape-C8CR_Bad.js → reshape-DFzh97Sc.js} +1 -1
  70. package/dist/{sin-BJIrfnj7.js → sin-BYM-U4Ut.js} +1 -1
  71. package/dist/slice_util-CnVNPQI-.js +90 -0
  72. package/dist/softmax-4DOn6cPq.js +28 -0
  73. package/dist/{split-DZbvruEP.js → split-CkbeVdF8.js} +3 -3
  74. package/dist/{stack-BMm-efee.js → stack-DaIMO5iX.js} +1 -1
  75. package/dist/sum-C6u3xMi3.js +27 -0
  76. package/dist/{tensor-DJVbYhh1.js → tensor-Cu1fU7H7.js} +1 -1
  77. package/dist/{tensor2d-ZuQSh2D-.js → tensor2d-D0CKdG6B.js} +1 -1
  78. package/dist/tfjs_backend-Bzl2SrRo.js +2460 -0
  79. package/dist/training/AdamExt.js +1 -1
  80. package/dist/training/DatasetBuilder.js +3 -3
  81. package/dist/training/FullTrainer.js +41 -33
  82. package/dist/training/Trainer.d.ts +6 -1
  83. package/dist/training/Trainer.js +13 -12
  84. package/dist/training/sparseCrossEntropy.js +12 -11
  85. package/dist/utilities/dummy.js +8 -8
  86. package/dist/utilities/generate.js +11 -11
  87. package/dist/utilities/load.js +1 -1
  88. package/dist/utilities/profile.js +1 -1
  89. package/dist/utilities/weights.js +2 -2
  90. package/dist/{variable-Dl_ub3pk.js → variable-BS4AKqNU.js} +1 -1
  91. package/dist/{zeros-CCy9C3uU.js → zeros-CmJFiC84.js} +1 -1
  92. package/package.json +1 -1
  93. package/dist/exports_layers-tbTBcwMM.js +0 -25
  94. package/dist/layers/LayerNorm.d.ts +0 -13
  95. package/dist/layers/LayerNorm.js +0 -33
  96. package/dist/moments-DfcpfwKi.js +0 -132
  97. package/dist/softmax-Be_lsqUc.js +0 -105
  98. package/dist/training/LayerTrainer.d.ts +0 -29
  99. package/dist/training/LayerTrainer.js +0 -90
  100. package/dist/training/lwSchedule.d.ts +0 -7
  101. package/dist/training/lwSchedule.js +0 -162
@@ -1,7 +1,11 @@
1
- import { o as c, h as i, E as a, T as f, U as m, V as p } from "./index-pWA4_lUh.js";
1
+ import { o as r, h as p, E as u, a3 as h, a4 as E, Y as S, s as $, a5 as d } from "./index-XjBAhiFO.js";
2
+ import { e as K } from "./axis_util-DeydwOoC.js";
3
+ import { m as T } from "./max-DJvEiCAJ.js";
4
+ import { r as m } from "./reshape-DFzh97Sc.js";
5
+ import { s as _ } from "./sum-C6u3xMi3.js";
2
6
  /**
3
7
  * @license
4
- * Copyright 2017 Google LLC. All Rights Reserved.
8
+ * Copyright 2018 Google LLC. All Rights Reserved.
5
9
  * Licensed under the Apache License, Version 2.0 (the "License");
6
10
  * you may not use this file except in compliance with the License.
7
11
  * You may obtain a copy of the License at
@@ -15,44 +19,14 @@ import { o as c, h as i, E as a, T as f, U as m, V as p } from "./index-pWA4_lUh
15
19
  * limitations under the License.
16
20
  * =============================================================================
17
21
  */
18
- function d(e, n) {
19
- for (let t = 0; t < e.length; ++t)
20
- if (e[e.length - t - 1] !== n - 1 - t)
21
- return !1;
22
- return !0;
23
- }
24
- function x(e, n, t) {
25
- const s = e.length + n.length, r = [];
26
- let o = 0, l = 0;
27
- for (let u = 0; u < s; u++)
28
- t.indexOf(u) === -1 ? r.push(e[o++]) : r.push(n[l++]);
29
- return r;
30
- }
31
- function S(e, n) {
32
- const t = [], s = e.length;
33
- for (let o = 0; o < s; o++)
34
- n.indexOf(o) === -1 && t.push(e[o]);
35
- const r = n.map((o) => e[o]);
36
- return [t, r];
37
- }
38
- function A(e, n) {
39
- const t = n.map((s) => 1);
40
- return x(e, t, n);
41
- }
42
- function E(e, n) {
43
- if (d(e, n))
44
- return null;
45
- const t = [];
46
- for (let s = 0; s < n; ++s)
47
- e.indexOf(s) === -1 && t.push(s);
48
- return e.forEach((s) => t.push(s)), t;
49
- }
50
- function O(e) {
51
- return e.map((n, t) => [t, n]).sort((n, t) => n[1] - t[1]).map((n) => n[0]);
22
+ function b(s) {
23
+ const o = { x: p(s, "x", "exp") };
24
+ return u.runKernel(h, o);
52
25
  }
26
+ const N = /* @__PURE__ */ r({ exp_: b });
53
27
  /**
54
28
  * @license
55
- * Copyright 2020 Google LLC. All Rights Reserved.
29
+ * Copyright 2018 Google LLC. All Rights Reserved.
56
30
  * Licensed under the Apache License, Version 2.0 (the "License");
57
31
  * you may not use this file except in compliance with the License.
58
32
  * You may obtain a copy of the License at
@@ -66,14 +40,14 @@ function O(e) {
66
40
  * limitations under the License.
67
41
  * =============================================================================
68
42
  */
69
- function h(e, n = null, t = !1) {
70
- const r = { x: i(e, "x", "max") }, o = { reductionIndices: n, keepDims: t };
71
- return a.runKernel(f, r, o);
43
+ function v(s) {
44
+ const o = { x: p(s, "x", "log", "float32") };
45
+ return u.runKernel(E, o);
72
46
  }
73
- const T = /* @__PURE__ */ c({ max_: h });
47
+ const w = /* @__PURE__ */ r({ log_: v });
74
48
  /**
75
49
  * @license
76
- * Copyright 2018 Google LLC. All Rights Reserved.
50
+ * Copyright 2020 Google LLC. All Rights Reserved.
77
51
  * Licensed under the Apache License, Version 2.0 (the "License");
78
52
  * you may not use this file except in compliance with the License.
79
53
  * You may obtain a copy of the License at
@@ -87,18 +61,22 @@ const T = /* @__PURE__ */ c({ max_: h });
87
61
  * limitations under the License.
88
62
  * =============================================================================
89
63
  */
90
- function g(e, n = null, t = !1) {
91
- let s = i(e, "x", "sum");
92
- s.dtype === "bool" && (s = m(s, "int32"));
93
- const r = { x: s }, o = { axis: n, keepDims: t };
94
- return a.runKernel(p, r, o);
64
+ function A(s, n = null, o = !1) {
65
+ const a = p(s, "x", "logSumExp"), t = S(n, a.shape), x = T(
66
+ a,
67
+ t,
68
+ !0
69
+ /* keepDims */
70
+ ), i = $(a, x), l = N(i), f = _(l, t), c = w(f), e = d(m(x, c.shape), c);
71
+ if (o) {
72
+ const g = K(e.shape, t);
73
+ return m(e, g);
74
+ }
75
+ return e;
95
76
  }
96
- const b = /* @__PURE__ */ c({ sum_: g });
77
+ const P = /* @__PURE__ */ r({ logSumExp_: A });
97
78
  export {
98
- O as a,
99
- S as c,
100
- A as e,
101
- E as g,
102
- T as m,
103
- b as s
79
+ w as a,
80
+ N as e,
81
+ P as l
104
82
  };
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- import { default as P } from "./NanoGPTModel.js";
2
- import { default as h } from "./TeachableLLM.js";
3
- import { default as y } from "./tokeniser/CharTokeniser.js";
4
- import { default as U } from "./tokeniser/bpe.js";
5
- import { default as v } from "./utilities/waitForModel.js";
6
- import { default as B } from "./data/textLoader.js";
7
- import { estimateMemoryUsage as E, estimateParameterCount as F, estimateResources as G, estimateTrainingMemoryUsage as N, validateConfig as R } from "./utilities/parameters.js";
8
- import "./index-pWA4_lUh.js";
1
+ import { default as k } from "./NanoGPTModel.js";
2
+ import { default as L } from "./TeachableLLM.js";
3
+ import { default as b } from "./tokeniser/CharTokeniser.js";
4
+ import { default as w } from "./tokeniser/bpe.js";
5
+ import { default as D } from "./utilities/waitForModel.js";
6
+ import { default as F } from "./data/textLoader.js";
7
+ import { estimateMemoryUsage as N, estimateParameterCount as R, estimateResources as j, estimateTrainingMemoryUsage as q, validateConfig as z } from "./utilities/parameters.js";
8
+ import "./index-XjBAhiFO.js";
9
9
  import "./ops/cpu/scatterSub.js";
10
10
  import "./ops/webgl/scatterSub.js";
11
11
  import "./ops/cpu/gatherSub.js";
@@ -22,16 +22,19 @@ import "./ops/webgl/rope.js";
22
22
  import "./ops/grads/rope.js";
23
23
  import "./ops/cpu/appendCache.js";
24
24
  import "./ops/webgl/appendCache.js";
25
+ import "./ops/cpu/fusedSoftmax.js";
26
+ import "./ops/webgl/fusedSoftmax.js";
27
+ import "./ops/grads/fusedSoftmax.js";
25
28
  export {
26
- U as BPETokeniser,
27
- y as CharTokeniser,
28
- P as NanoGPT,
29
- h as TeachableLLM,
30
- E as estimateMemoryUsage,
31
- F as estimateParameterCount,
32
- G as estimateResources,
33
- N as estimateTrainingMemoryUsage,
34
- B as loadTextData,
35
- R as validateConfig,
36
- v as waitForModel
29
+ w as BPETokeniser,
30
+ b as CharTokeniser,
31
+ k as NanoGPT,
32
+ L as TeachableLLM,
33
+ N as estimateMemoryUsage,
34
+ R as estimateParameterCount,
35
+ j as estimateResources,
36
+ q as estimateTrainingMemoryUsage,
37
+ F as loadTextData,
38
+ z as validateConfig,
39
+ D as waitForModel
37
40
  };
@@ -1,4 +1,4 @@
1
- import { o as m, h as s, p as c, E as M, B as p } from "./index-pWA4_lUh.js";
1
+ import { o as m, h as s, p as c, E as M, B as p } from "./index-XjBAhiFO.js";
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -0,0 +1,25 @@
1
+ import { o as r, h as e, E as x, M as c } from "./index-XjBAhiFO.js";
2
+ /**
3
+ * @license
4
+ * Copyright 2020 Google LLC. All Rights Reserved.
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ * =============================================================================
17
+ */
18
+ function m(n, o = null, s = !1) {
19
+ const t = { x: e(n, "x", "max") }, a = { reductionIndices: o, keepDims: s };
20
+ return x.runKernel(c, t, a);
21
+ }
22
+ const l = /* @__PURE__ */ r({ max_: m });
23
+ export {
24
+ l as m
25
+ };
@@ -0,0 +1,53 @@
1
+ import { o as m, h as c, E as f, X as i, Y as l, Z as h, s as x, x as d } from "./index-XjBAhiFO.js";
2
+ import { e as v } from "./axis_util-DeydwOoC.js";
3
+ import { r as E } from "./reshape-DFzh97Sc.js";
4
+ /**
5
+ * @license
6
+ * Copyright 2020 Google Inc. All Rights Reserved.
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * =============================================================================
19
+ */
20
+ function S(a, t = null, e = !1) {
21
+ const s = { x: c(a, "x", "mean") }, o = { axis: t, keepDims: e };
22
+ return f.runKernel(i, s, o);
23
+ }
24
+ const r = /* @__PURE__ */ m({ mean_: S });
25
+ /**
26
+ * @license
27
+ * Copyright 2020 Google LLC. All Rights Reserved.
28
+ * Licensed under the Apache License, Version 2.0 (the "License");
29
+ * you may not use this file except in compliance with the License.
30
+ * You may obtain a copy of the License at
31
+ *
32
+ * http://www.apache.org/licenses/LICENSE-2.0
33
+ *
34
+ * Unless required by applicable law or agreed to in writing, software
35
+ * distributed under the License is distributed on an "AS IS" BASIS,
36
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
+ * See the License for the specific language governing permissions and
38
+ * limitations under the License.
39
+ * =============================================================================
40
+ */
41
+ function T(a, t = null, e = !1) {
42
+ a = c(a, "x", "moments");
43
+ const n = l(t, a.shape), s = r(a, n, e);
44
+ let o = s.shape;
45
+ e || (o = v(s.shape, n));
46
+ const p = h(x(d(a, "float32"), E(s, o))), u = r(p, n, e);
47
+ return { mean: s, variance: u };
48
+ }
49
+ const N = /* @__PURE__ */ m({ moments_: T });
50
+ export {
51
+ N as a,
52
+ r as m
53
+ };
@@ -0,0 +1,86 @@
1
+ import { o as l, h as c, E as y, _ as E, Y as w, $ as o, a0 as u, O as v, f as I, Z as $ } from "./index-XjBAhiFO.js";
2
+ import { e as A } from "./axis_util-DeydwOoC.js";
3
+ import { m as f } from "./max-DJvEiCAJ.js";
4
+ import { r as h } from "./reshape-DFzh97Sc.js";
5
+ import { s as t } from "./sum-C6u3xMi3.js";
6
+ /**
7
+ * @license
8
+ * Copyright 2020 Google Inc. All Rights Reserved.
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ * =============================================================================
21
+ */
22
+ function k(n, e = null, r = !1) {
23
+ const i = { x: c(n, "x", "min") }, a = { axis: e, keepDims: r };
24
+ return y.runKernel(E, i, a);
25
+ }
26
+ const s = /* @__PURE__ */ l({ min_: k });
27
+ /**
28
+ * @license
29
+ * Copyright 2018 Google LLC. All Rights Reserved.
30
+ * Licensed under the Apache License, Version 2.0 (the "License");
31
+ * you may not use this file except in compliance with the License.
32
+ * You may obtain a copy of the License at
33
+ *
34
+ * http://www.apache.org/licenses/LICENSE-2.0
35
+ *
36
+ * Unless required by applicable law or agreed to in writing, software
37
+ * distributed under the License is distributed on an "AS IS" BASIS,
38
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39
+ * See the License for the specific language governing permissions and
40
+ * limitations under the License.
41
+ * =============================================================================
42
+ */
43
+ function T(n, e = "euclidean", r = null, m = !1) {
44
+ n = c(n, "x", "norm");
45
+ const i = d(n, e, r);
46
+ let a = i.shape;
47
+ if (m) {
48
+ const p = w(r, n.shape);
49
+ a = A(i.shape, p);
50
+ }
51
+ return h(i, a);
52
+ }
53
+ function d(n, e, r = null) {
54
+ if (n.rank === 0)
55
+ return o(n);
56
+ if (n.rank !== 1 && r === null)
57
+ return d(h(n, [-1]), e, r);
58
+ if (n.rank === 1 || typeof r == "number" || Array.isArray(r) && r.length === 1) {
59
+ if (e === 1)
60
+ return t(o(n), r);
61
+ if (e === 1 / 0)
62
+ return f(o(n), r);
63
+ if (e === -1 / 0)
64
+ return s(o(n), r);
65
+ if (e === "euclidean" || e === 2)
66
+ return u(t(v(o(n), I(2, "int32")), r));
67
+ throw new Error(`Error in norm: invalid ord value: ${e}`);
68
+ }
69
+ if (Array.isArray(r) && r.length === 2) {
70
+ if (e === 1)
71
+ return f(t(o(n), r[0]), r[1] - 1);
72
+ if (e === 1 / 0)
73
+ return f(t(o(n), r[1]), r[0]);
74
+ if (e === -1 / 0)
75
+ return s(t(o(n), r[1]), r[0]);
76
+ if (e === "fro" || e === "euclidean")
77
+ return u(t($(n), r));
78
+ throw new Error(`Error in norm: invalid ord value: ${e}`);
79
+ }
80
+ throw new Error(`Error in norm: invalid axis: ${r}`);
81
+ }
82
+ const K = /* @__PURE__ */ l({ norm_: T });
83
+ export {
84
+ s as m,
85
+ K as n
86
+ };
@@ -1,5 +1,5 @@
1
- import { k as n, l as t, n as m, E as i } from "./index-pWA4_lUh.js";
2
- import { z as l, c } from "./zeros-CCy9C3uU.js";
1
+ import { k as n, l as t, n as m, E as i } from "./index-XjBAhiFO.js";
2
+ import { z as l, c } from "./zeros-CmJFiC84.js";
3
3
  /**
4
4
  * @license
5
5
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -1,4 +1,4 @@
1
- import { e as p } from "../index-pWA4_lUh.js";
1
+ import { e as p } from "../index-XjBAhiFO.js";
2
2
  import "./cpu/appendCache.js";
3
3
  import "./webgl/appendCache.js";
4
4
  function a(e, n, r) {
@@ -1,4 +1,4 @@
1
- import { e as o } from "../index-pWA4_lUh.js";
1
+ import { e as o } from "../index-XjBAhiFO.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 a, e as m } from "../../index-pWA4_lUh.js";
2
- import { c as d } from "../../concat-BIZS_td9.js";
1
+ import { r as a, e as m } from "../../index-XjBAhiFO.js";
2
+ import { c as d } from "../../concat-DS_qH7MI.js";
3
3
  function r(n) {
4
4
  const { cache: c, item: t } = n.inputs, { maxSize: o } = n.attrs, e = d([c, t], 2), s = e.shape[2];
5
5
  if (s > o) {
@@ -1,5 +1,5 @@
1
- import { r as s, f as i } from "../../index-pWA4_lUh.js";
2
- import { m as k } from "../../mat_mul-D7_a4KJn.js";
1
+ import { r as s, f as i } from "../../index-XjBAhiFO.js";
2
+ import { m as k } from "../../mat_mul-CKwFEV1Q.js";
3
3
  function a(t) {
4
4
  const { q: e, k: o, mask: r } = t.inputs, { divisor: c } = t.attrs, n = e.shape[2], m = k(e, o, !1, !0).mul(i(c)), l = r.slice([0, 0], [n, n]).expandDims(0).expandDims(0);
5
5
  return m.add(l);
@@ -0,0 +1,9 @@
1
+ import { SoftmaxAttrs, SoftmaxInputs, TensorInfo } from '@tensorflow/tfjs-core';
2
+ interface FusedSoftmaxAttrs extends SoftmaxAttrs {
3
+ dropoutRate?: number;
4
+ }
5
+ export declare function softmaxCPU(args: {
6
+ inputs: SoftmaxInputs;
7
+ attrs: FusedSoftmaxAttrs;
8
+ }): TensorInfo;
9
+ export {};
@@ -0,0 +1,23 @@
1
+ import { r as n } from "../../index-XjBAhiFO.js";
2
+ import { s as f } from "../../softmax-4DOn6cPq.js";
3
+ function r(t) {
4
+ const { inputs: s, attrs: i } = t, { logits: o } = s, { dim: a, dropoutRate: e } = i;
5
+ if (!o)
6
+ throw new Error("Error in softmax: input logits is null");
7
+ return e !== void 0 && e > 0 && console.warn("Dropout in fusedSoftmax not implemented for CPU backend, skipping dropout."), f(o, a);
8
+ }
9
+ const m = {
10
+ kernelName: "FusedSoftmax",
11
+ backendName: "cpu",
12
+ kernelFunc: r
13
+ };
14
+ n(m);
15
+ const l = {
16
+ kernelName: "FusedSoftmax",
17
+ backendName: "tensorflow",
18
+ kernelFunc: r
19
+ };
20
+ n(l);
21
+ export {
22
+ r as softmaxCPU
23
+ };
@@ -1,6 +1,6 @@
1
- import { o as u, h as c, E as g, H as h, r as m, s as p } from "../../index-pWA4_lUh.js";
2
- import { r as l } from "../../range-CcDl05lo.js";
3
- import { s as N } from "../../stack-BMm-efee.js";
1
+ import { o as u, h as c, E as g, L as h, r as m, s as p } from "../../index-XjBAhiFO.js";
2
+ import { r as l } from "../../range-DQMNzBWs.js";
3
+ import { s as N } from "../../stack-DaIMO5iX.js";
4
4
  /**
5
5
  * @license
6
6
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { r as e, b as u } from "../../index-XjBAhiFO.js";
2
+ function n(o) {
3
+ const { inputs: r } = o, { a: l, b: t } = r;
4
+ return console.warn("Using fallback mulDrop implementation without dropout."), u(l, t);
5
+ }
6
+ const a = {
7
+ kernelName: "MulDropout",
8
+ backendName: "cpu",
9
+ kernelFunc: n
10
+ };
11
+ e(a);
12
+ const c = {
13
+ kernelName: "MulDropout",
14
+ backendName: "tensorflow",
15
+ kernelFunc: n
16
+ };
17
+ e(c);
@@ -1,6 +1,6 @@
1
- import { r as q } from "../../index-pWA4_lUh.js";
2
- import { r as o } from "../../reshape-C8CR_Bad.js";
3
- import { s as x } from "../../split-DZbvruEP.js";
1
+ import { r as q } from "../../index-XjBAhiFO.js";
2
+ import { r as o } from "../../reshape-DFzh97Sc.js";
3
+ import { s as x } from "../../split-CkbeVdF8.js";
4
4
  function v(p) {
5
5
  const { x: c, kernel: K } = p.inputs, { heads: n } = p.attrs, [s, e, t] = c.shape, a = o(c, [s * e, t]), i = a.dot(K);
6
6
  a.dispose();
@@ -1,8 +1,8 @@
1
- import { r as S } from "../../index-pWA4_lUh.js";
2
- import { r as F } from "../../range-CcDl05lo.js";
3
- import { g as I } from "../../gather-BPGW8RsB.js";
4
- import { s as E } from "../../stack-BMm-efee.js";
5
- import { c as T } from "../../concat-BIZS_td9.js";
1
+ import { r as S } from "../../index-XjBAhiFO.js";
2
+ import { r as F } from "../../range-DQMNzBWs.js";
3
+ import { g as I } from "../../gather-BUmJIS8n.js";
4
+ import { s as E } from "../../stack-DaIMO5iX.js";
5
+ import { c as T } from "../../concat-DS_qH7MI.js";
6
6
  function U(t, c, p, o, r) {
7
7
  const n = o.shape[3], s = p;
8
8
  if (s > n) return o;
@@ -1,27 +1,27 @@
1
- import { o as l, k, h, E as g, Q as w, r as $, s as d, b as m } from "../../index-pWA4_lUh.js";
2
- import { r as b } from "../../range-CcDl05lo.js";
3
- import { s as E } from "../../stack-BMm-efee.js";
4
- import { o as D } from "../../ones-Cog-G2ag.js";
5
- function N(a, r, t) {
6
- const s = r.rank > 1 ? r.shape[r.rank - 1] : 1, e = r.rank > 1 ? r.rank - 1 : 1, o = `Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: ${t.shape}, indices.shape: ${r.shape}, shape: ${a}, sliceDim: ${s}, and batchDim: ${e}.`;
1
+ import { o as l, k, h, E as g, a2 as w, r as $, s as d, b as m } from "../../index-XjBAhiFO.js";
2
+ import { r as b } from "../../range-DQMNzBWs.js";
3
+ import { s as E } from "../../stack-DaIMO5iX.js";
4
+ import { o as D } from "../../ones-BO01zpJG.js";
5
+ function N(n, r, t) {
6
+ const s = r.rank > 1 ? r.shape[r.rank - 1] : 1, e = r.rank > 1 ? r.rank - 1 : 1, o = `Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: ${t.shape}, indices.shape: ${r.shape}, shape: ${n}, sliceDim: ${s}, and batchDim: ${e}.`;
7
7
  if (t.rank < e)
8
8
  throw new Error(o + ` update.rank < ${e}. `);
9
- if (a.length < s + (t.rank - e))
9
+ if (n.length < s + (t.rank - e))
10
10
  throw new Error(o + ` Output shape length < ${s + (t.rank - e)}`);
11
- if (t.rank !== e + a.length - s)
12
- throw new Error(o + ` update.rank != ${e + a.length - s}`);
13
- for (let n = 0; n < e; ++n)
14
- if (t.shape[n] !== r.shape[n])
15
- throw new Error(o + ` updates.shape[${n}] (${t.shape[n]}) != indices.shape[${n}] (${r.shape[n]}).`);
16
- for (let n = 0; n < t.rank - e; ++n)
17
- if (t.shape[n + e] !== a[n + s])
18
- throw new Error(o + ` updates.shape[${n + e}] (${t.shape[n + e]}) != shape[${n + e}] (${a[n + e]})`);
11
+ if (t.rank !== e + n.length - s)
12
+ throw new Error(o + ` update.rank != ${e + n.length - s}`);
13
+ for (let a = 0; a < e; ++a)
14
+ if (t.shape[a] !== r.shape[a])
15
+ throw new Error(o + ` updates.shape[${a}] (${t.shape[a]}) != indices.shape[${a}] (${r.shape[a]}).`);
16
+ for (let a = 0; a < t.rank - e; ++a)
17
+ if (t.shape[a + e] !== n[a + s])
18
+ throw new Error(o + ` updates.shape[${a + e}] (${t.shape[a + e]}) != shape[${a + e}] (${n[a + e]})`);
19
19
  }
20
- function S(a, r, t) {
20
+ function S(n, r, t) {
21
21
  if (r.rank < 1)
22
22
  throw new Error(`tf.scatterND() expects the indices to be rank 1 or higher, but the rank was ${r.rank}.`);
23
- if (a.rank < 1)
24
- throw new Error(`tf.scatterND() expects the updates to be rank 1 or higher, but the rank was ${a.rank}.`);
23
+ if (n.rank < 1)
24
+ throw new Error(`tf.scatterND() expects the updates to be rank 1 or higher, but the rank was ${n.rank}.`);
25
25
  if (r.dtype !== "int32")
26
26
  throw new Error(`The dtype of 'indices' should be int32, but got dtype: ${r.dtype}`);
27
27
  if (t.length < 1)
@@ -29,10 +29,10 @@ function S(a, r, t) {
29
29
  if (t.length === 0) {
30
30
  if (r.size === 0)
31
31
  throw new Error(`Indices specified for empty output. indices shape: ${r.shape}`);
32
- if (a.size === 0)
33
- throw new Error(`Updates specified for empty output. updates shape: ${a.shape}`);
32
+ if (n.size === 0)
33
+ throw new Error(`Updates specified for empty output. updates shape: ${n.shape}`);
34
34
  }
35
- N(t, r, a);
35
+ N(t, r, n);
36
36
  }
37
37
  /**
38
38
  * @license
@@ -50,16 +50,16 @@ function S(a, r, t) {
50
50
  * limitations under the License.
51
51
  * =============================================================================
52
52
  */
53
- function y(a, r, t) {
53
+ function y(n, r, t) {
54
54
  k(t);
55
- const s = h(a, "indices", "scatterND", "int32"), e = h(r, "updates", "scatterND");
55
+ const s = h(n, "indices", "scatterND", "int32"), e = h(r, "updates", "scatterND");
56
56
  S(e, s, t);
57
- const o = { indices: s, updates: e }, n = { shape: t };
58
- return g.runKernel(w, o, n);
57
+ const o = { indices: s, updates: e }, a = { shape: t };
58
+ return g.runKernel(w, o, a);
59
59
  }
60
60
  const v = /* @__PURE__ */ l({ scatterND_: y });
61
- function I(a) {
62
- const { logits: r, labels: t, dy: s } = a.inputs, e = t.shape[0], o = r.shape[1], n = b(0, e, 1, "int32"), i = E([n, t], 1), c = D([e]), p = v(i, c, [e, o]), f = d(r, p), u = s.reshape([e, 1]);
61
+ function I(n) {
62
+ const { logits: r, labels: t, dy: s } = n.inputs, e = t.shape[0], o = r.shape[1], a = b(0, e, 1, "int32"), i = E([a, t], 1), c = D([e]), p = v(i, c, [e, o]), f = d(r, p), u = s.reshape([e, 1]);
63
63
  return m(f, u);
64
64
  }
65
65
  const T = {
@@ -0,0 +1,2 @@
1
+ import { Tensor } from '@tensorflow/tfjs-core';
2
+ export declare function fusedSoftmax(logits: Tensor, dropoutRate: number, seed: number): Tensor;
@@ -0,0 +1,10 @@
1
+ import { e as t } from "../index-XjBAhiFO.js";
2
+ import "./cpu/fusedSoftmax.js";
3
+ import "./webgl/fusedSoftmax.js";
4
+ import "./grads/fusedSoftmax.js";
5
+ function p(r, e, o) {
6
+ return t().runKernel("FusedSoftmax", { logits: r }, { dim: -1, dropoutRate: e, seed: o });
7
+ }
8
+ export {
9
+ p as fusedSoftmax
10
+ };
@@ -1,4 +1,4 @@
1
- import { e as n } from "../index-pWA4_lUh.js";
1
+ import { e as n } from "../index-XjBAhiFO.js";
2
2
  import "./cpu/gatherSub.js";
3
3
  import "./webgl/gatherSub.js";
4
4
  function f(r, e, t) {
@@ -1,4 +1,4 @@
1
- import { g as i } from "../../index-pWA4_lUh.js";
1
+ import { g as i } from "../../index-XjBAhiFO.js";
2
2
  const u = {
3
3
  kernelName: "AttentionMask",
4
4
  inputsToSave: ["q", "k"],
@@ -0,0 +1,2 @@
1
+ import { GradConfig } from '@tensorflow/tfjs-core';
2
+ export declare const softmaxGradConfig: GradConfig;
@@ -0,0 +1,17 @@
1
+ import { g as p, b as m, s as d } from "../../index-XjBAhiFO.js";
2
+ import { mulDrop as c } from "../mulDrop.js";
3
+ import { s as f } from "../../sum-C6u3xMi3.js";
4
+ const g = {
5
+ kernelName: "FusedSoftmax",
6
+ outputsToSave: [!0],
7
+ gradFunc: (s, a, u) => {
8
+ const [o] = a, { dim: i, dropoutRate: t, seed: r } = u, n = !0, e = t && r ? c(s, o, t, r) : m(s, o);
9
+ return {
10
+ logits: () => d(e, m(f(e, [i], n), o))
11
+ };
12
+ }
13
+ };
14
+ p(g);
15
+ export {
16
+ g as softmaxGradConfig
17
+ };
@@ -1,4 +1,4 @@
1
- import { g as v } from "../../index-pWA4_lUh.js";
1
+ import { g as v } from "../../index-XjBAhiFO.js";
2
2
  const g = {
3
3
  kernelName: "QKV",
4
4
  inputsToSave: ["x", "kernel"],
@@ -1,4 +1,4 @@
1
- import { g as a, e as i } from "../../index-pWA4_lUh.js";
1
+ import { g as a, e as i } from "../../index-XjBAhiFO.js";
2
2
  function p(n, e, s, o) {
3
3
  return i().runKernel("Rope", { x: n, sin: e, cos: s }, { pastLen: o });
4
4
  }
@@ -0,0 +1,2 @@
1
+ import { Tensor } from '@tensorflow/tfjs-core';
2
+ export declare function mulDrop(a: Tensor, b: Tensor, dropoutRate: number, seed: number): Tensor;
@@ -0,0 +1,9 @@
1
+ import { e as t } from "../index-XjBAhiFO.js";
2
+ import "./cpu/mulDropout.js";
3
+ import "./webgl/mulDropout.js";
4
+ function m(r, o, e, n) {
5
+ return t().runKernel("MulDropout", { a: r, b: o }, { dropoutRate: e, seed: n });
6
+ }
7
+ export {
8
+ m as mulDrop
9
+ };