@genai-fi/nanogpt 0.4.5 → 0.5.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.
- package/dist/BaseLayer-BhrMN8JO.js +135 -0
- package/dist/Generator.js +44 -41
- package/dist/NanoGPTModel.d.ts +12 -16
- package/dist/NanoGPTModel.js +128 -138
- package/dist/{Reshape-CiAY8ltP.js → Reshape-BE5rA4rT.js} +8 -8
- package/dist/TeachableLLM.js +1 -1
- package/dist/{TiedEmbedding-DznFwzcB.js → TiedEmbedding-DsDRvLB0.js} +751 -768
- package/dist/{axis_util-QP0LdI1v.js → axis_util-97KkkyRQ.js} +1 -1
- package/dist/broadcast_to-CMlkG8NS.js +44 -0
- package/dist/{concat-DvWM7HGZ.js → concat-Cxbo2sOz.js} +3 -3
- package/dist/{dropout-DFEXTPV0.js → dropout-kbDY39Ci.js} +1 -1
- package/dist/{gather-C5D8PxwA.js → gather-Bxe1Qip8.js} +4 -4
- package/dist/{gpgpu_math-CUzjlO9A.js → gpgpu_math-C0zyxKFi.js} +1 -1
- package/dist/{index--6vO-cOz.js → index-iNhkcAEQ.js} +82 -82
- package/dist/{kernel_funcs_utils-C6YBCuOt.js → kernel_funcs_utils-C4eIk4fE.js} +20 -20
- package/dist/layers/BaseLayer.d.ts +28 -4
- package/dist/layers/BaseLayer.js +3 -16
- package/dist/layers/CausalSelfAttention.d.ts +22 -24
- package/dist/layers/CausalSelfAttention.js +73 -128
- package/dist/layers/MLP.d.ts +8 -15
- package/dist/layers/MLP.js +43 -81
- package/dist/layers/RMSNorm.d.ts +5 -10
- package/dist/layers/RMSNorm.js +13 -29
- package/dist/layers/RoPECache.js +14 -12
- package/dist/layers/TiedEmbedding.d.ts +6 -16
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.d.ts +12 -16
- package/dist/layers/TransformerBlock.js +20 -41
- package/dist/{log_sum_exp-CiEy1aUe.js → log_sum_exp-CkumwesB.js} +11 -11
- package/dist/main.js +1 -1
- package/dist/{mat_mul-BEHRPMh0.js → mat_mul-D0SifYfJ.js} +3 -3
- package/dist/{max-BUShNgfh.js → max-CYaAjEEp.js} +3 -3
- package/dist/{moments-DYOHXoRV.js → moments-B06NlR_V.js} +6 -6
- package/dist/{norm-DSva3hI3.js → norm-D3676xIo.js} +7 -7
- package/dist/{ones-D6kB8bdY.js → ones-BIeFnPHR.js} +2 -2
- package/dist/ops/appendCache.js +4 -4
- package/dist/ops/attentionMask.d.ts +1 -1
- package/dist/ops/attentionMask.js +4 -4
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +14 -15
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +5 -5
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.js +1 -1
- package/dist/ops/cpu/matMulMul.d.ts +1 -0
- package/dist/ops/cpu/matMulMul.js +17 -0
- package/dist/ops/cpu/mulDropout.js +1 -1
- package/dist/ops/cpu/normRMS.js +1 -1
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +8 -8
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +1 -1
- package/dist/ops/grads/attentionMask.js +13 -9
- package/dist/ops/grads/fusedSoftmax.js +12 -9
- package/dist/ops/grads/gelu.js +1 -1
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/normRMS.js +1 -1
- package/dist/ops/grads/qkv.js +19 -9
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.d.ts +2 -0
- package/dist/ops/matMulMul.js +9 -0
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/normRMS.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 +13 -12
- package/dist/ops/webgl/fusedSoftmax.js +43 -40
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/matMulGelu.js +17 -17
- package/dist/ops/webgl/matMulMul.d.ts +14 -0
- package/dist/ops/webgl/matMulMul.js +28 -0
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.js +29 -21
- 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/ops-ObfXLHYQ.js +1269 -0
- package/dist/{range-C_vpUjBu.js → range-BsFU-SNG.js} +1 -1
- package/dist/{reshape-z51Eu-re.js → reshape-DxTPgnwL.js} +3 -3
- package/dist/{sin-H567uayl.js → sin-BOX-JVAj.js} +5 -5
- package/dist/slice_util-D-kaD4ZV.js +49 -0
- package/dist/{softmax-Dsxflvdl.js → softmax-BjsptB07.js} +2 -2
- package/dist/{split-B_k_jwud.js → split-BCbrzthj.js} +4 -4
- package/dist/{stack-CmqSdsfs.js → stack--cqr9Dgc.js} +2 -2
- package/dist/{sum-DdkDf2MG.js → sum-B_92TaHD.js} +5 -5
- package/dist/{tensor-BGYi41cj.js → tensor-CfiPXsW4.js} +1 -1
- package/dist/{tensor2d-DUr_htjt.js → tensor2d-tSxWdFMH.js} +1 -1
- package/dist/tfjs_backend-NucKez4s.js +1010 -0
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +44 -44
- package/dist/training/Evaluator.js +6 -6
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +7 -7
- package/dist/training/sparseCrossEntropy.js +4 -4
- package/dist/utilities/dummy.js +10 -10
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/save.js +10 -8
- package/dist/utilities/weights.js +2 -2
- package/dist/{zeros-8xl-W2DC.js → zeros-NMYTayy7.js} +3 -3
- package/package.json +1 -1
- package/dist/slice_util-BdhYwFY_.js +0 -90
- package/dist/tfjs_backend-DuKis_xG.js +0 -2271
- package/dist/variable-BJTZ3jOy.js +0 -23
|
@@ -1,53 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { t as
|
|
6
|
-
class
|
|
1
|
+
import l from "./CausalSelfAttention.js";
|
|
2
|
+
import r from "./MLP.js";
|
|
3
|
+
import o from "./RMSNorm.js";
|
|
4
|
+
import { B as d } from "../BaseLayer-BhrMN8JO.js";
|
|
5
|
+
import { t as p } from "../index-iNhkcAEQ.js";
|
|
6
|
+
class k extends d {
|
|
7
7
|
ln1;
|
|
8
8
|
attn;
|
|
9
9
|
ln2;
|
|
10
10
|
mlp;
|
|
11
11
|
index;
|
|
12
|
-
_trainable = !0;
|
|
13
12
|
skipped = !1;
|
|
14
|
-
constructor(t, s) {
|
|
15
|
-
super(s), this.index = t, this.ln1 = new
|
|
16
|
-
}
|
|
17
|
-
get variables() {
|
|
18
|
-
return [
|
|
19
|
-
...this.ln1.trainableWeights.map((t) => t),
|
|
20
|
-
...this.attn.variables,
|
|
21
|
-
...this.ln2.trainableWeights.map((t) => t),
|
|
22
|
-
...this.mlp.variables
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
get trainable() {
|
|
26
|
-
return this._trainable;
|
|
27
|
-
}
|
|
28
|
-
set trainable(t) {
|
|
29
|
-
this._trainable = t, this.ln1.trainable = t, this.ln2.trainable = t, this.attn.trainable = t, this.mlp.trainable = t;
|
|
30
|
-
}
|
|
31
|
-
saveWeights(t) {
|
|
32
|
-
this.attn.saveWeights(t), this.mlp.saveWeights(t), t.set(`block_${this.index}_rms1`, this.ln1.getWeights()), t.set(`block_${this.index}_rms2`, this.ln2.getWeights());
|
|
33
|
-
}
|
|
34
|
-
loadWeights(t) {
|
|
35
|
-
this.attn.loadWeights(t), this.mlp.loadWeights(t), this.ln1.setWeights(t.get(`block_${this.index}_rms1`) || []), this.ln2.setWeights(t.get(`block_${this.index}_rms2`) || []);
|
|
13
|
+
constructor(t, s, i) {
|
|
14
|
+
super(s, i), this.index = t, this.ln1 = new o(s, `block_${this.index}_rms1`, this), this.attn = new l(this.index, s, this), this.ln2 = new o(s, `block_${this.index}_rms2`, this), this.mlp = new r(this.index, s, this);
|
|
36
15
|
}
|
|
37
16
|
getMLPOutput(t, s) {
|
|
38
|
-
const i = this.ln2.
|
|
39
|
-
|
|
17
|
+
const i = this.ln2.call({ training: s }, t), e = this.mlp.call({ training: s }, i);
|
|
18
|
+
i.dispose();
|
|
19
|
+
const n = t.add(e);
|
|
20
|
+
return t.dispose(), e.dispose(), n;
|
|
40
21
|
}
|
|
41
|
-
|
|
42
|
-
return
|
|
22
|
+
forward(t, s) {
|
|
23
|
+
return p(() => {
|
|
43
24
|
if (this.skipped)
|
|
44
|
-
return
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
cache: n.presentKV
|
|
50
|
-
};
|
|
25
|
+
return s;
|
|
26
|
+
const i = this.ln1.call(t, s), e = this.attn.call(t, i);
|
|
27
|
+
i.dispose();
|
|
28
|
+
const n = s.add(e);
|
|
29
|
+
return e.dispose(), this.getMLPOutput(n, t.training);
|
|
51
30
|
});
|
|
52
31
|
}
|
|
53
32
|
dispose() {
|
|
@@ -55,5 +34,5 @@ class W extends p {
|
|
|
55
34
|
}
|
|
56
35
|
}
|
|
57
36
|
export {
|
|
58
|
-
|
|
37
|
+
k as default
|
|
59
38
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as r,
|
|
2
|
-
import { e as K } from "./axis_util-
|
|
3
|
-
import { m as T } from "./max-
|
|
4
|
-
import { r as m } from "./reshape-
|
|
5
|
-
import { s as _ } from "./sum-
|
|
1
|
+
import { o as r, i as p, E as u, a7 as E, a8 as h, a1 as S, s as $, a9 as d } from "./index-iNhkcAEQ.js";
|
|
2
|
+
import { e as K } from "./axis_util-97KkkyRQ.js";
|
|
3
|
+
import { m as T } from "./max-CYaAjEEp.js";
|
|
4
|
+
import { r as m } from "./reshape-DxTPgnwL.js";
|
|
5
|
+
import { s as _ } from "./sum-B_92TaHD.js";
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
8
8
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -21,7 +21,7 @@ import { s as _ } from "./sum-DdkDf2MG.js";
|
|
|
21
21
|
*/
|
|
22
22
|
function b(s) {
|
|
23
23
|
const o = { x: p(s, "x", "exp") };
|
|
24
|
-
return u.runKernel(
|
|
24
|
+
return u.runKernel(E, o);
|
|
25
25
|
}
|
|
26
26
|
const N = /* @__PURE__ */ r({ exp_: b });
|
|
27
27
|
/**
|
|
@@ -42,7 +42,7 @@ const N = /* @__PURE__ */ r({ exp_: b });
|
|
|
42
42
|
*/
|
|
43
43
|
function v(s) {
|
|
44
44
|
const o = { x: p(s, "x", "log", "float32") };
|
|
45
|
-
return u.runKernel(
|
|
45
|
+
return u.runKernel(h, o);
|
|
46
46
|
}
|
|
47
47
|
const w = /* @__PURE__ */ r({ log_: v });
|
|
48
48
|
/**
|
|
@@ -61,13 +61,13 @@ const w = /* @__PURE__ */ r({ log_: v });
|
|
|
61
61
|
* limitations under the License.
|
|
62
62
|
* =============================================================================
|
|
63
63
|
*/
|
|
64
|
-
function A(s,
|
|
65
|
-
const
|
|
66
|
-
|
|
64
|
+
function A(s, a = null, o = !1) {
|
|
65
|
+
const n = p(s, "x", "logSumExp"), t = S(a, n.shape), x = T(
|
|
66
|
+
n,
|
|
67
67
|
t,
|
|
68
68
|
!0
|
|
69
69
|
/* keepDims */
|
|
70
|
-
), i =
|
|
70
|
+
), i = $(n, x), l = N(i), f = _(l, t), c = w(f), e = d(m(x, c.shape), c);
|
|
71
71
|
if (o) {
|
|
72
72
|
const g = K(e.shape, t);
|
|
73
73
|
return m(e, g);
|
package/dist/main.js
CHANGED
|
@@ -5,7 +5,7 @@ import { default as q } from "./tokeniser/bpe.js";
|
|
|
5
5
|
import { default as A } from "./utilities/waitForModel.js";
|
|
6
6
|
import { default as I } from "./data/textLoader.js";
|
|
7
7
|
import { estimateMemoryUsage as K, estimateParameterCount as O, estimateResources as Q, estimateTrainingMemoryUsage as S, validateConfig as V } from "./utilities/parameters.js";
|
|
8
|
-
import "./index
|
|
8
|
+
import "./index-iNhkcAEQ.js";
|
|
9
9
|
import "./ops/cpu/scatterSub.js";
|
|
10
10
|
import "./ops/webgl/scatterSub.js";
|
|
11
11
|
import "./ops/cpu/gatherSub.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as m,
|
|
1
|
+
import { o as m, i as s, q as c, E as M, B as p } from "./index-iNhkcAEQ.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -21,7 +21,7 @@ function f(e, o, n = !1, l = !1) {
|
|
|
21
21
|
const r = { a, b: t }, u = { transposeA: n, transposeB: l };
|
|
22
22
|
return M.runKernel(p, r, u);
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const b = /* @__PURE__ */ m({ matMul_: f });
|
|
25
25
|
export {
|
|
26
|
-
|
|
26
|
+
b as m
|
|
27
27
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as r,
|
|
1
|
+
import { o as r, i as e, E as x, M as c } from "./index-iNhkcAEQ.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -15,11 +15,11 @@ import { o as r, h as e, E as x, M as c } from "./index--6vO-cOz.js";
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
* =============================================================================
|
|
17
17
|
*/
|
|
18
|
-
function
|
|
18
|
+
function i(n, o = null, s = !1) {
|
|
19
19
|
const t = { x: e(n, "x", "max") }, a = { reductionIndices: o, keepDims: s };
|
|
20
20
|
return x.runKernel(c, t, a);
|
|
21
21
|
}
|
|
22
|
-
const l = /* @__PURE__ */ r({ max_:
|
|
22
|
+
const l = /* @__PURE__ */ r({ max_: i });
|
|
23
23
|
export {
|
|
24
24
|
l as m
|
|
25
25
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as m,
|
|
2
|
-
import { e as v } from "./axis_util-
|
|
3
|
-
import { r as E } from "./reshape-
|
|
1
|
+
import { o as m, i as c, E as i, a0 as f, a1 as l, a2 as h, s as x, y as d } from "./index-iNhkcAEQ.js";
|
|
2
|
+
import { e as v } from "./axis_util-97KkkyRQ.js";
|
|
3
|
+
import { r as E } from "./reshape-DxTPgnwL.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
@@ -19,7 +19,7 @@ import { r as E } from "./reshape-z51Eu-re.js";
|
|
|
19
19
|
*/
|
|
20
20
|
function S(a, t = null, e = !1) {
|
|
21
21
|
const s = { x: c(a, "x", "mean") }, o = { axis: t, keepDims: e };
|
|
22
|
-
return
|
|
22
|
+
return i.runKernel(f, s, o);
|
|
23
23
|
}
|
|
24
24
|
const r = /* @__PURE__ */ m({ mean_: S });
|
|
25
25
|
/**
|
|
@@ -46,8 +46,8 @@ function T(a, t = null, e = !1) {
|
|
|
46
46
|
const p = h(x(d(a, "float32"), E(s, o))), u = r(p, n, e);
|
|
47
47
|
return { mean: s, variance: u };
|
|
48
48
|
}
|
|
49
|
-
const
|
|
49
|
+
const N = /* @__PURE__ */ m({ moments_: T });
|
|
50
50
|
export {
|
|
51
|
-
|
|
51
|
+
N as a,
|
|
52
52
|
r as m
|
|
53
53
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as l,
|
|
2
|
-
import { e as
|
|
3
|
-
import { m as f } from "./max-
|
|
4
|
-
import { r as h } from "./reshape-
|
|
5
|
-
import { s as t } from "./sum-
|
|
1
|
+
import { o as l, i as c, E as y, a3 as E, a1 as w, a4 as o, a5 as u, U as v, f as I, a2 as A } from "./index-iNhkcAEQ.js";
|
|
2
|
+
import { e as $ } from "./axis_util-97KkkyRQ.js";
|
|
3
|
+
import { m as f } from "./max-CYaAjEEp.js";
|
|
4
|
+
import { r as h } from "./reshape-DxTPgnwL.js";
|
|
5
|
+
import { s as t } from "./sum-B_92TaHD.js";
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
8
8
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
@@ -46,7 +46,7 @@ function T(n, e = "euclidean", r = null, m = !1) {
|
|
|
46
46
|
let i = a.shape;
|
|
47
47
|
if (m) {
|
|
48
48
|
const p = w(r, n.shape);
|
|
49
|
-
i =
|
|
49
|
+
i = $(a.shape, p);
|
|
50
50
|
}
|
|
51
51
|
return h(a, i);
|
|
52
52
|
}
|
|
@@ -74,7 +74,7 @@ function d(n, e, r = null) {
|
|
|
74
74
|
if (e === -1 / 0)
|
|
75
75
|
return s(t(o(n), r[1]), r[0]);
|
|
76
76
|
if (e === "fro" || e === "euclidean")
|
|
77
|
-
return u(t(
|
|
77
|
+
return u(t(A(n), r));
|
|
78
78
|
throw new Error(`Error in norm: invalid ord value: ${e}`);
|
|
79
79
|
}
|
|
80
80
|
throw new Error(`Error in norm: invalid axis: ${r}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z as l, c } from "./zeros-
|
|
1
|
+
import { l as n, n as t, p as m, E as i } from "./index-iNhkcAEQ.js";
|
|
2
|
+
import { z as l, c } from "./zeros-NMYTayy7.js";
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
package/dist/ops/appendCache.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { e as a } from "../index
|
|
1
|
+
import { e as a } from "../index-iNhkcAEQ.js";
|
|
2
2
|
import "./cpu/appendCache.js";
|
|
3
3
|
import "./webgl/appendCache.js";
|
|
4
|
-
import {
|
|
5
|
-
import { c } from "../
|
|
4
|
+
import { c as s } from "../concat-Cxbo2sOz.js";
|
|
5
|
+
import { z as c } from "../zeros-NMYTayy7.js";
|
|
6
6
|
function i(r, p, n, o) {
|
|
7
7
|
if (!o) {
|
|
8
8
|
const e = r.shape[2];
|
|
9
|
-
return
|
|
9
|
+
return s([r, c([r.shape[0], r.shape[1], p - e, r.shape[3]])], 2);
|
|
10
10
|
}
|
|
11
11
|
return a().runKernel("AppendCache", { cache: o, item: r }, { maxSize: p, pastLen: n });
|
|
12
12
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Tensor } from '@tensorflow/tfjs-core';
|
|
2
|
-
export declare function attentionMask(q: Tensor, k: Tensor, divisor: number,
|
|
2
|
+
export declare function attentionMask(q: Tensor, k: Tensor, divisor: number, pastLen?: number): Tensor;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { e as
|
|
1
|
+
import { e as o } from "../index-iNhkcAEQ.js";
|
|
2
2
|
import "./cpu/attentionMask.js";
|
|
3
3
|
import "./webgl/attentionMask.js";
|
|
4
4
|
import "./grads/attentionMask.js";
|
|
5
|
-
function
|
|
6
|
-
return
|
|
5
|
+
function s(t, n, e, r) {
|
|
6
|
+
return o().runKernel("AttentionMask", { q: t, k: n }, { divisor: e, pastLen: r || 0 });
|
|
7
7
|
}
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
s as attentionMask
|
|
10
10
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as d } from "../../index
|
|
2
|
-
import { c as h } from "../../concat-
|
|
1
|
+
import { r as d } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
import { c as h } from "../../concat-Cxbo2sOz.js";
|
|
3
3
|
function u(p) {
|
|
4
4
|
const { cache: n, item: s } = p.inputs, { maxSize: r, pastLen: c } = p.attrs, t = n.shape[0], o = n.shape[1], a = n.shape[3], e = s.shape[2];
|
|
5
5
|
if (c + e <= r) {
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { r as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return a;
|
|
1
|
+
import { r as a, g as p, f as u } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
import { l as N, w as b } from "../../ops-ObfXLHYQ.js";
|
|
3
|
+
import { o as g } from "../../ones-BIeFnPHR.js";
|
|
4
|
+
import { z as A } from "../../zeros-NMYTayy7.js";
|
|
5
|
+
import { m as I } from "../../mat_mul-D0SifYfJ.js";
|
|
6
|
+
function o(n) {
|
|
7
|
+
const { q: s, k: e } = n.inputs, { divisor: r } = n.attrs, c = s.shape[2], t = e.shape[2], m = N.bandPart(g([t, t]), -1, 0).cast("bool"), l = A([t, t]), i = p([t, t], Number.NEGATIVE_INFINITY), f = b(m, l, i), k = I(s, e, !1, !0).mul(u(r)), d = f.slice([0, 0], [c, t]).expandDims(0).expandDims(0);
|
|
8
|
+
return k.add(d);
|
|
10
9
|
}
|
|
11
|
-
const
|
|
10
|
+
const w = {
|
|
12
11
|
kernelName: "AttentionMask",
|
|
13
12
|
backendName: "cpu",
|
|
14
|
-
kernelFunc:
|
|
13
|
+
kernelFunc: o
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
const
|
|
15
|
+
a(w);
|
|
16
|
+
const M = {
|
|
18
17
|
kernelName: "AttentionMask",
|
|
19
18
|
backendName: "tensorflow",
|
|
20
|
-
kernelFunc:
|
|
19
|
+
kernelFunc: o
|
|
21
20
|
};
|
|
22
|
-
|
|
21
|
+
a(M);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as n } from "../../index
|
|
2
|
-
import { s as f } from "../../softmax-
|
|
1
|
+
import { r as n } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
import { s as f } from "../../softmax-BjsptB07.js";
|
|
3
3
|
function r(t) {
|
|
4
4
|
const { inputs: s, attrs: i } = t, { logits: o } = s, { dim: a, dropoutRate: e } = i;
|
|
5
5
|
if (!o)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as u,
|
|
2
|
-
import { r as
|
|
3
|
-
import { s as
|
|
1
|
+
import { o as u, i as c, E as g, L as h, r as m, s as p } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
import { r as l } from "../../range-BsFU-SNG.js";
|
|
3
|
+
import { s as N } from "../../stack--cqr9Dgc.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -23,8 +23,8 @@ function f(e, s) {
|
|
|
23
23
|
}
|
|
24
24
|
const b = /* @__PURE__ */ u({ gatherND_: f });
|
|
25
25
|
function d(e) {
|
|
26
|
-
const { values: s, labels: n, logits: r } = e.inputs, t = n.shape[0],
|
|
27
|
-
return p(s,
|
|
26
|
+
const { values: s, labels: n, logits: r } = e.inputs, t = n.shape[0], i = l(0, t, 1, "int32"), o = N([i, n], 1), a = b(r, o);
|
|
27
|
+
return p(s, a);
|
|
28
28
|
}
|
|
29
29
|
const k = {
|
|
30
30
|
kernelName: "EfficientGatherSub",
|
package/dist/ops/cpu/gelu.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { r as n, t as M } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
function e(t) {
|
|
3
|
+
const { inputs: r, attrs: o } = t, { transposeA: s, transposeB: l } = o, { x: c, kernel: u, y: a } = r, m = c, i = u, k = a;
|
|
4
|
+
return M(() => m.matMul(i, s, l).mul(k));
|
|
5
|
+
}
|
|
6
|
+
const f = {
|
|
7
|
+
kernelName: "MatMulMul",
|
|
8
|
+
backendName: "cpu",
|
|
9
|
+
kernelFunc: e
|
|
10
|
+
};
|
|
11
|
+
n(f);
|
|
12
|
+
const p = {
|
|
13
|
+
kernelName: "MatMulMul",
|
|
14
|
+
backendName: "tensorflow",
|
|
15
|
+
kernelFunc: e
|
|
16
|
+
};
|
|
17
|
+
n(p);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as e, b as u } from "../../index
|
|
1
|
+
import { r as e, b as u } from "../../index-iNhkcAEQ.js";
|
|
2
2
|
function n(o) {
|
|
3
3
|
const { inputs: r } = o, { a: l, b: t } = r;
|
|
4
4
|
return console.warn("Using fallback mulDrop implementation without dropout."), u(l, t);
|
package/dist/ops/cpu/normRMS.js
CHANGED
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-iNhkcAEQ.js";
|
|
2
|
+
import { r as o } from "../../reshape-DxTPgnwL.js";
|
|
3
|
+
import { s as x } from "../../split-BCbrzthj.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-iNhkcAEQ.js";
|
|
2
|
+
import { r as F } from "../../range-BsFU-SNG.js";
|
|
3
|
+
import { g as I } from "../../gather-Bxe1Qip8.js";
|
|
4
|
+
import { s as E } from "../../stack--cqr9Dgc.js";
|
|
5
|
+
import { c as T } from "../../concat-Cxbo2sOz.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,7 +1,7 @@
|
|
|
1
|
-
import { o as l,
|
|
2
|
-
import { r as b } from "../../range-
|
|
3
|
-
import { s as E } from "../../stack
|
|
4
|
-
import { o as D } from "../../ones-
|
|
1
|
+
import { o as l, l as g, i, E as k, a6 as w, r as $, s as d, b as m } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
import { r as b } from "../../range-BsFU-SNG.js";
|
|
3
|
+
import { s as E } from "../../stack--cqr9Dgc.js";
|
|
4
|
+
import { o as D } from "../../ones-BIeFnPHR.js";
|
|
5
5
|
function N(n, r, t) {
|
|
6
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)
|
|
@@ -51,15 +51,15 @@ function S(n, r, t) {
|
|
|
51
51
|
* =============================================================================
|
|
52
52
|
*/
|
|
53
53
|
function y(n, r, t) {
|
|
54
|
-
|
|
55
|
-
const s =
|
|
54
|
+
g(t);
|
|
55
|
+
const s = i(n, "indices", "scatterND", "int32"), e = i(r, "updates", "scatterND");
|
|
56
56
|
S(e, s, t);
|
|
57
57
|
const o = { indices: s, updates: e }, a = { shape: t };
|
|
58
|
-
return
|
|
58
|
+
return k.runKernel(w, o, a);
|
|
59
59
|
}
|
|
60
60
|
const v = /* @__PURE__ */ l({ scatterND_: y });
|
|
61
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"),
|
|
62
|
+
const { logits: r, labels: t, dy: s } = n.inputs, e = t.shape[0], o = r.shape[1], a = b(0, e, 1, "int32"), h = E([a, t], 1), c = D([e]), p = v(h, c, [e, o]), f = d(r, p), u = s.reshape([e, 1]);
|
|
63
63
|
return m(f, u);
|
|
64
64
|
}
|
|
65
65
|
const T = {
|
package/dist/ops/fusedSoftmax.js
CHANGED
package/dist/ops/gatherSub.js
CHANGED
package/dist/ops/gelu.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { h as l, f as a } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
import { matMulMul as i } from "../matMulMul.js";
|
|
3
|
+
const m = {
|
|
3
4
|
kernelName: "AttentionMask",
|
|
4
5
|
inputsToSave: ["q", "k"],
|
|
5
6
|
outputsToSave: [],
|
|
6
|
-
gradFunc: (t,
|
|
7
|
+
gradFunc: (t, u, c) => {
|
|
7
8
|
if (Array.isArray(t))
|
|
8
9
|
throw new Error("Expected dy to be a single Tensor");
|
|
9
|
-
const [
|
|
10
|
+
const [e, o] = u, { divisor: n } = c;
|
|
10
11
|
return {
|
|
11
|
-
q: () => t
|
|
12
|
-
k: () =>
|
|
12
|
+
q: () => i(t, o, a(n)),
|
|
13
|
+
k: () => {
|
|
14
|
+
const s = e.transpose([0, 1, 3, 2]), r = i(s, t, a(n));
|
|
15
|
+
return s.dispose(), r.transpose([0, 1, 3, 2]);
|
|
16
|
+
},
|
|
13
17
|
mask: () => t,
|
|
14
18
|
divisor: () => {
|
|
15
|
-
const
|
|
16
|
-
return
|
|
19
|
+
const s = e.matMul(o, !1, !0), r = t.mul(s);
|
|
20
|
+
return s.dispose(), r.sum();
|
|
17
21
|
}
|
|
18
22
|
};
|
|
19
23
|
}
|
|
20
24
|
};
|
|
21
|
-
|
|
25
|
+
l(m);
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { mulDrop as
|
|
3
|
-
import { s as
|
|
4
|
-
const
|
|
1
|
+
import { h as d, b as u, s as f } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
import { mulDrop as l } from "../mulDrop.js";
|
|
3
|
+
import { s as g } from "../../sum-B_92TaHD.js";
|
|
4
|
+
const T = {
|
|
5
5
|
kernelName: "FusedSoftmax",
|
|
6
6
|
outputsToSave: [!0],
|
|
7
|
-
gradFunc: (
|
|
8
|
-
const [
|
|
7
|
+
gradFunc: (o, i, n) => {
|
|
8
|
+
const [s] = i, { dim: a, dropoutRate: t, seed: e } = n, p = !0, r = t && e ? l(o, s, t, e) : u(o, s);
|
|
9
9
|
return {
|
|
10
|
-
logits: () =>
|
|
10
|
+
logits: () => {
|
|
11
|
+
const m = g(r, [a], p), c = u(m, s);
|
|
12
|
+
return m.dispose(), f(r, c);
|
|
13
|
+
}
|
|
11
14
|
};
|
|
12
15
|
}
|
|
13
16
|
};
|
|
14
|
-
|
|
17
|
+
d(T);
|
|
15
18
|
export {
|
|
16
|
-
|
|
19
|
+
T as softmaxGradConfig
|
|
17
20
|
};
|
package/dist/ops/grads/gelu.js
CHANGED
package/dist/ops/grads/qkv.js
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
1
|
+
import { h as Q } from "../../index-iNhkcAEQ.js";
|
|
2
|
+
const V = {
|
|
3
3
|
kernelName: "QKV",
|
|
4
4
|
inputsToSave: ["x", "kernel"],
|
|
5
5
|
outputsToSave: [],
|
|
6
|
-
gradFunc: (
|
|
7
|
-
const [
|
|
6
|
+
gradFunc: (x, K) => {
|
|
7
|
+
const [f, h, M] = x, [p, l] = K, [t, n, e] = p.shape, i = f.transpose([0, 2, 1, 3]).reshape([t * n, e]), u = h.transpose([0, 2, 1, 3]).reshape([t * n, e]), k = M.transpose([0, 2, 1, 3]).reshape([t * n, e]);
|
|
8
8
|
return {
|
|
9
9
|
x: () => {
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const s = l.slice([0, 0], [e, e]), o = i.matMul(s, !1, !0);
|
|
11
|
+
s.dispose();
|
|
12
|
+
const d = l.slice([0, e], [e, e]), r = u.matMul(d, !1, !0);
|
|
13
|
+
d.dispose();
|
|
14
|
+
const a = o.add(r);
|
|
15
|
+
o.dispose(), r.dispose();
|
|
16
|
+
const c = l.slice([0, 2 * e], [e, e]), m = k.matMul(c, !1, !0);
|
|
17
|
+
c.dispose();
|
|
18
|
+
const v = a.add(m).reshape([t, n, e]);
|
|
19
|
+
return a.dispose(), m.dispose(), v;
|
|
12
20
|
},
|
|
13
21
|
kernel: () => {
|
|
14
|
-
const
|
|
15
|
-
|
|
22
|
+
const s = p.reshape([t * n, e]), o = s.matMul(i, !0, !1), d = s.matMul(u, !0, !1), r = o.concat(d, 1);
|
|
23
|
+
o.dispose(), d.dispose();
|
|
24
|
+
const a = s.matMul(k, !0, !1), c = r.concat(a, 1);
|
|
25
|
+
return r.dispose(), a.dispose(), s.dispose(), c;
|
|
16
26
|
}
|
|
17
27
|
};
|
|
18
28
|
}
|
|
19
29
|
};
|
|
20
|
-
|
|
30
|
+
Q(V);
|