@genai-fi/nanogpt 0.3.2 → 0.4.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.
- package/dist/Generator.js +22 -22
- package/dist/MLP-KHhikThU.js +83 -0
- package/dist/NanoGPTModel.d.ts +2 -3
- package/dist/NanoGPTModel.js +79 -79
- package/dist/TeachableLLM.js +16 -13
- package/dist/axis_util-DeydwOoC.js +69 -0
- package/dist/{concat-BIZS_td9.js → concat-DS_qH7MI.js} +5 -5
- package/dist/config.js +7 -8
- package/dist/{gather-BPGW8RsB.js → gather-BUmJIS8n.js} +1 -1
- package/dist/{index-pWA4_lUh.js → index-XjBAhiFO.js} +1272 -1174
- package/dist/layers/BaseLayer.d.ts +14 -2
- package/dist/layers/BaseLayer.js +9 -9
- package/dist/layers/CausalSelfAttention.d.ts +4 -8
- package/dist/layers/CausalSelfAttention.js +106 -80
- package/dist/layers/MLP.d.ts +2 -3
- package/dist/layers/MLP.js +5 -62
- package/dist/layers/RMSNorm.d.ts +2 -2
- package/dist/layers/RMSNorm.js +11 -11
- package/dist/layers/RoPECache.js +3 -3
- package/dist/layers/TiedEmbedding.js +7 -6
- package/dist/layers/TransformerBlock.d.ts +2 -6
- package/dist/layers/TransformerBlock.js +9 -12
- package/dist/{sum-C7Mgy9Bw.js → log_sum_exp-DJPkVZZn.js} +32 -54
- package/dist/main.js +22 -19
- package/dist/{mat_mul-D7_a4KJn.js → mat_mul-CKwFEV1Q.js} +1 -1
- package/dist/max-DJvEiCAJ.js +25 -0
- package/dist/moments-CrWRPcR3.js +53 -0
- package/dist/norm-BzY929B_.js +86 -0
- package/dist/{ones-Cog-G2ag.js → ones-BO01zpJG.js} +2 -2
- package/dist/ops/appendCache.js +1 -1
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +2 -2
- package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
- package/dist/ops/cpu/fusedSoftmax.js +23 -0
- package/dist/ops/cpu/gatherSub.js +3 -3
- package/dist/ops/cpu/mulDropout.d.ts +1 -0
- package/dist/ops/cpu/mulDropout.js +17 -0
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +27 -27
- package/dist/ops/fusedSoftmax.d.ts +2 -0
- package/dist/ops/fusedSoftmax.js +10 -0
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.d.ts +2 -0
- package/dist/ops/grads/fusedSoftmax.js +17 -0
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/mulDrop.d.ts +2 -0
- package/dist/ops/mulDrop.js +9 -0
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
- package/dist/ops/webgl/fusedSoftmax.js +3930 -0
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/mulDropout.d.ts +1 -0
- package/dist/ops/webgl/mulDropout.js +41 -0
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/{random_width-oeUIlUZj.js → random_width-CMHmdbSu.js} +4212 -6630
- package/dist/{range-CcDl05lo.js → range-DQMNzBWs.js} +1 -1
- package/dist/{reshape-C8CR_Bad.js → reshape-DFzh97Sc.js} +1 -1
- package/dist/{sin-BJIrfnj7.js → sin-BYM-U4Ut.js} +1 -1
- package/dist/slice_util-CnVNPQI-.js +90 -0
- package/dist/softmax-4DOn6cPq.js +28 -0
- package/dist/{split-DZbvruEP.js → split-CkbeVdF8.js} +3 -3
- package/dist/{stack-BMm-efee.js → stack-DaIMO5iX.js} +1 -1
- package/dist/sum-C6u3xMi3.js +27 -0
- package/dist/{tensor-DJVbYhh1.js → tensor-Cu1fU7H7.js} +1 -1
- package/dist/{tensor2d-ZuQSh2D-.js → tensor2d-D0CKdG6B.js} +1 -1
- package/dist/tfjs_backend-Bzl2SrRo.js +2460 -0
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +3 -3
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +13 -12
- package/dist/training/sparseCrossEntropy.js +12 -11
- package/dist/utilities/dummy.js +8 -8
- package/dist/utilities/generate.js +11 -11
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-Dl_ub3pk.js → variable-BS4AKqNU.js} +1 -1
- package/dist/{zeros-CCy9C3uU.js → zeros-CmJFiC84.js} +1 -1
- package/package.json +1 -1
- package/dist/exports_layers-tbTBcwMM.js +0 -25
- package/dist/layers/LayerNorm.d.ts +0 -13
- package/dist/layers/LayerNorm.js +0 -33
- package/dist/moments-DfcpfwKi.js +0 -132
- package/dist/softmax-Be_lsqUc.js +0 -105
- package/dist/training/LayerTrainer.d.ts +0 -29
- package/dist/training/LayerTrainer.js +0 -95
- package/dist/training/lwSchedule.d.ts +0 -7
- package/dist/training/lwSchedule.js +0 -162
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { o as
|
|
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
|
|
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
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
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
|
|
70
|
-
const
|
|
71
|
-
return
|
|
43
|
+
function v(s) {
|
|
44
|
+
const o = { x: p(s, "x", "log", "float32") };
|
|
45
|
+
return u.runKernel(E, o);
|
|
72
46
|
}
|
|
73
|
-
const
|
|
47
|
+
const w = /* @__PURE__ */ r({ log_: v });
|
|
74
48
|
/**
|
|
75
49
|
* @license
|
|
76
|
-
* Copyright
|
|
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
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
77
|
+
const P = /* @__PURE__ */ r({ logSumExp_: A });
|
|
97
78
|
export {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
7
|
-
import { estimateMemoryUsage as
|
|
8
|
-
import "./index-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
};
|
|
@@ -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-
|
|
2
|
-
import { z as l, c } from "./zeros-
|
|
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.
|
package/dist/ops/appendCache.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as a, e as m } from "../../index-
|
|
2
|
-
import { c as d } from "../../concat-
|
|
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-
|
|
2
|
-
import { m as k } from "../../mat_mul-
|
|
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,
|
|
2
|
-
import { r as l } from "../../range-
|
|
3
|
-
import { s as N } from "../../stack-
|
|
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);
|
package/dist/ops/cpu/qkv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { r as q } from "../../index-
|
|
2
|
-
import { r as o } from "../../reshape-
|
|
3
|
-
import { s as x } from "../../split-
|
|
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();
|
package/dist/ops/cpu/rope.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { r as S } from "../../index-
|
|
2
|
-
import { r as F } from "../../range-
|
|
3
|
-
import { g as I } from "../../gather-
|
|
4
|
-
import { s as E } from "../../stack-
|
|
5
|
-
import { c as T } from "../../concat-
|
|
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,
|
|
2
|
-
import { r as b } from "../../range-
|
|
3
|
-
import { s as E } from "../../stack-
|
|
4
|
-
import { o as D } from "../../ones-
|
|
5
|
-
function N(
|
|
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: ${
|
|
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 (
|
|
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 +
|
|
12
|
-
throw new Error(o + ` update.rank != ${e +
|
|
13
|
-
for (let
|
|
14
|
-
if (t.shape[
|
|
15
|
-
throw new Error(o + ` updates.shape[${
|
|
16
|
-
for (let
|
|
17
|
-
if (t.shape[
|
|
18
|
-
throw new Error(o + ` updates.shape[${
|
|
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(
|
|
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 (
|
|
24
|
-
throw new Error(`tf.scatterND() expects the updates to be rank 1 or higher, but the rank was ${
|
|
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 (
|
|
33
|
-
throw new Error(`Updates specified for empty output. updates 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,
|
|
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(
|
|
53
|
+
function y(n, r, t) {
|
|
54
54
|
k(t);
|
|
55
|
-
const s = h(
|
|
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 },
|
|
58
|
-
return g.runKernel(w, o,
|
|
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(
|
|
62
|
-
const { logits: r, labels: t, dy: s } =
|
|
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,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
|
+
};
|
package/dist/ops/gatherSub.js
CHANGED
|
@@ -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
|
+
};
|
package/dist/ops/grads/qkv.js
CHANGED
package/dist/ops/grads/rope.js
CHANGED