@genai-fi/nanogpt 0.4.2 → 0.4.4
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 +3 -3
- package/dist/NanoGPTModel.js +73 -76
- package/dist/Reshape-CiAY8ltP.js +212 -0
- package/dist/TeachableLLM.js +7 -1
- package/dist/{TiedEmbedding-CnJ1bx4q.js → TiedEmbedding-DznFwzcB.js} +244 -244
- package/dist/{axis_util-BgTGy5w8.js → axis_util-QP0LdI1v.js} +1 -1
- package/dist/{concat-CuRsVY-K.js → concat-DvWM7HGZ.js} +1 -1
- package/dist/data/parquet.js +9 -6
- package/dist/data/textLoader.js +6 -5
- package/dist/{dropout-DfDdklfL.js → dropout-DFEXTPV0.js} +4 -4
- package/dist/{gather-ZYRWhmXR.js → gather-C5D8PxwA.js} +1 -1
- package/dist/gpgpu_math-CUzjlO9A.js +23 -0
- package/dist/{index-C4JCoBvj.js → index--6vO-cOz.js} +87 -87
- package/dist/{kernel_funcs_utils-CAd1h9X1.js → kernel_funcs_utils-C6YBCuOt.js} +72 -91
- package/dist/layers/CausalSelfAttention.js +44 -44
- package/dist/layers/MLP.js +31 -33
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +3 -3
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/{log_sum_exp-BswFnwOb.js → log_sum_exp-CiEy1aUe.js} +7 -7
- package/dist/main.js +25 -19
- package/dist/{mat_mul-415y5Qn2.js → mat_mul-BEHRPMh0.js} +1 -1
- package/dist/{max-CP_9O2Yd.js → max-BUShNgfh.js} +1 -1
- package/dist/{moments-CjeIaVdp.js → moments-DYOHXoRV.js} +5 -5
- package/dist/{norm-CZM380I3.js → norm-DSva3hI3.js} +13 -13
- package/dist/{ones-Bf3YR48P.js → ones-D6kB8bdY.js} +2 -2
- package/dist/ops/appendCache.d.ts +1 -1
- package/dist/ops/appendCache.js +10 -4
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.d.ts +1 -2
- package/dist/ops/cpu/appendCache.js +15 -20
- package/dist/ops/cpu/attentionMask.js +10 -10
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +4 -4
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.d.ts +1 -0
- package/dist/ops/cpu/matMulGelu.js +40 -0
- package/dist/ops/cpu/mulDropout.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 +4 -4
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +24 -3
- package/dist/ops/grads/matMulGelu.d.ts +1 -0
- package/dist/ops/grads/matMulGelu.js +17 -0
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.d.ts +3 -0
- package/dist/ops/matMulGelu.js +14 -0
- package/dist/ops/mulDrop.js +1 -1
- 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 +14 -13
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +689 -895
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/matMulGelu.d.ts +20 -0
- package/dist/ops/webgl/matMulGelu.js +166 -0
- package/dist/ops/webgl/mulDropout.js +1 -1
- 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/{range-9AzeApCc.js → range-C_vpUjBu.js} +1 -1
- package/dist/{reshape-Boe4DuIO.js → reshape-z51Eu-re.js} +1 -1
- package/dist/{sin-KmhiDuMa.js → sin-H567uayl.js} +1 -1
- package/dist/{slice_util-19zDNNSn.js → slice_util-BdhYwFY_.js} +2 -2
- package/dist/{softmax-Cujsg4ay.js → softmax-Dsxflvdl.js} +1 -1
- package/dist/{split-DbcNm1-i.js → split-B_k_jwud.js} +1 -1
- package/dist/{stack-D1YjmgKN.js → stack-CmqSdsfs.js} +1 -1
- package/dist/{sum-R28pucR5.js → sum-DdkDf2MG.js} +1 -1
- package/dist/{tensor-BVeHdl7V.js → tensor-BGYi41cj.js} +1 -1
- package/dist/{tensor2d-DqFGNs_K.js → tensor2d-DUr_htjt.js} +1 -1
- package/dist/{tfjs_backend-Cug-PH75.js → tfjs_backend-DuKis_xG.js} +46 -46
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +18 -18
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +5 -5
- package/dist/training/sparseCrossEntropy.js +4 -4
- package/dist/utilities/dummy.js +2 -2
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-LJT9Ld63.js → variable-BJTZ3jOy.js} +1 -1
- package/dist/{zeros-dnQxFgAD.js → zeros-8xl-W2DC.js} +1 -1
- package/package.json +1 -1
- package/dist/gelu-CnCt17Lk.js +0 -26
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as u, h as c, E as g,
|
|
2
|
-
import { r as
|
|
3
|
-
import { s as
|
|
1
|
+
import { o as u, h as c, E as g, N as h, r as m, s as p } from "../../index--6vO-cOz.js";
|
|
2
|
+
import { r as N } from "../../range-C_vpUjBu.js";
|
|
3
|
+
import { s as l } from "../../stack-CmqSdsfs.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -23,7 +23,7 @@ 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], o =
|
|
26
|
+
const { values: s, labels: n, logits: r } = e.inputs, t = n.shape[0], o = N(0, t, 1, "int32"), a = l([o, n], 1), i = b(r, a);
|
|
27
27
|
return p(s, i);
|
|
28
28
|
}
|
|
29
29
|
const k = {
|
package/dist/ops/cpu/gelu.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { r as a, t as i } from "../../index--6vO-cOz.js";
|
|
2
|
+
const c = 0.7978845608028654, m = 0.044715;
|
|
3
|
+
function M(o) {
|
|
4
|
+
const { inputs: s } = o, { x: t, kernel: l } = s, e = t, u = l;
|
|
5
|
+
return i(() => {
|
|
6
|
+
const n = e.matMul(u), d = n.mul(n).mul(n), r = n.add(d.mul(m)).mul(c).tanh().add(1).mul(0.5);
|
|
7
|
+
return n.mul(r);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
const b = {
|
|
11
|
+
kernelName: "MatMulGelu",
|
|
12
|
+
backendName: "cpu",
|
|
13
|
+
kernelFunc: M
|
|
14
|
+
};
|
|
15
|
+
a(b);
|
|
16
|
+
const w = {
|
|
17
|
+
kernelName: "MatMulGelu",
|
|
18
|
+
backendName: "tensorflow",
|
|
19
|
+
kernelFunc: M
|
|
20
|
+
};
|
|
21
|
+
a(w);
|
|
22
|
+
function f(o) {
|
|
23
|
+
const { dy: s, x: t, kernel: l } = o.inputs;
|
|
24
|
+
return i(() => {
|
|
25
|
+
const e = t.matMul(l), u = e.square(), n = u.mul(e), r = e.add(n.mul(m)).mul(c).tanh(), G = r.square().neg().add(1), g = u.mul(3 * m).add(1), p = r.add(1).mul(0.5), N = e.mul(G).mul(c).mul(g).mul(0.5), K = p.add(N), k = s.mul(K), h = k.matMul(l.transpose()), F = t.transpose().matMul(k);
|
|
26
|
+
return [h, F];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const x = {
|
|
30
|
+
kernelName: "MatMulGeluGrad",
|
|
31
|
+
backendName: "cpu",
|
|
32
|
+
kernelFunc: f
|
|
33
|
+
};
|
|
34
|
+
a(x);
|
|
35
|
+
const C = {
|
|
36
|
+
kernelName: "MatMulGeluGrad",
|
|
37
|
+
backendName: "tensorflow",
|
|
38
|
+
kernelFunc: f
|
|
39
|
+
};
|
|
40
|
+
a(C);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as e, b as u } from "../../index-
|
|
1
|
+
import { r as e, b as u } from "../../index--6vO-cOz.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/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--6vO-cOz.js";
|
|
2
|
+
import { r as o } from "../../reshape-z51Eu-re.js";
|
|
3
|
+
import { s as x } from "../../split-B_k_jwud.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--6vO-cOz.js";
|
|
2
|
+
import { r as F } from "../../range-C_vpUjBu.js";
|
|
3
|
+
import { g as I } from "../../gather-C5D8PxwA.js";
|
|
4
|
+
import { s as E } from "../../stack-CmqSdsfs.js";
|
|
5
|
+
import { c as T } from "../../concat-DvWM7HGZ.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, 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-
|
|
1
|
+
import { o as l, k, h, E as g, a5 as w, r as $, s as d, b as m } from "../../index--6vO-cOz.js";
|
|
2
|
+
import { r as b } from "../../range-C_vpUjBu.js";
|
|
3
|
+
import { s as E } from "../../stack-CmqSdsfs.js";
|
|
4
|
+
import { o as D } from "../../ones-D6kB8bdY.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)
|
package/dist/ops/fusedSoftmax.js
CHANGED
package/dist/ops/gatherSub.js
CHANGED
package/dist/ops/gelu.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as p, b as m, s as d } from "../../index-
|
|
1
|
+
import { g as p, b as m, s as d } from "../../index--6vO-cOz.js";
|
|
2
2
|
import { mulDrop as c } from "../mulDrop.js";
|
|
3
|
-
import { s as f } from "../../sum-
|
|
3
|
+
import { s as f } from "../../sum-DdkDf2MG.js";
|
|
4
4
|
const g = {
|
|
5
5
|
kernelName: "FusedSoftmax",
|
|
6
6
|
outputsToSave: [!0],
|
package/dist/ops/grads/gelu.js
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
import "../../index-
|
|
2
|
-
import
|
|
1
|
+
import { g as t, e as n } from "../../index--6vO-cOz.js";
|
|
2
|
+
import "../cpu/gelu.js";
|
|
3
|
+
import "../webgl/gelu.js";
|
|
4
|
+
const o = {
|
|
5
|
+
kernelName: "Gelu",
|
|
6
|
+
inputsToSave: ["x"],
|
|
7
|
+
outputsToSave: [],
|
|
8
|
+
gradFunc: (e, r) => {
|
|
9
|
+
const [u] = r;
|
|
10
|
+
return {
|
|
11
|
+
x: () => a(e, u)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
t(o);
|
|
16
|
+
function g(e) {
|
|
17
|
+
return n().runKernel("Gelu", { x: e });
|
|
18
|
+
}
|
|
19
|
+
function a(e, r) {
|
|
20
|
+
return n().runKernel("GeluGrad", { dy: e, x: r });
|
|
21
|
+
}
|
|
3
22
|
export {
|
|
4
|
-
|
|
23
|
+
a as d,
|
|
24
|
+
g,
|
|
25
|
+
o as geluGradConfig
|
|
5
26
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { g as a, e as o } from "../../index--6vO-cOz.js";
|
|
2
|
+
function s(e, n, r) {
|
|
3
|
+
return o().runKernel("MatMulGeluGrad", { dy: e, x: n, kernel: r });
|
|
4
|
+
}
|
|
5
|
+
const d = {
|
|
6
|
+
kernelName: "MatMulGelu",
|
|
7
|
+
inputsToSave: ["x", "kernel"],
|
|
8
|
+
outputsToSave: [],
|
|
9
|
+
gradFunc: (e, n) => {
|
|
10
|
+
const [r, t] = n, [u, l] = s(e, r, t);
|
|
11
|
+
return {
|
|
12
|
+
x: () => u,
|
|
13
|
+
kernel: () => l
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
a(d);
|
package/dist/ops/grads/qkv.js
CHANGED
package/dist/ops/grads/rope.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { e as u } from "../index--6vO-cOz.js";
|
|
2
|
+
import "./cpu/matMulGelu.js";
|
|
3
|
+
import "./webgl/matMulGelu.js";
|
|
4
|
+
import "./grads/matMulGelu.js";
|
|
5
|
+
function M(r, e) {
|
|
6
|
+
return u().runKernel("MatMulGelu", { x: r, kernel: e });
|
|
7
|
+
}
|
|
8
|
+
function a(r, e, t) {
|
|
9
|
+
return u().runKernel("MatMulGeluGrad", { dy: r, x: e, kernel: t });
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
a as dMatMulGelu,
|
|
13
|
+
M as matMulGelu
|
|
14
|
+
};
|
package/dist/ops/mulDrop.js
CHANGED
package/dist/ops/qkv.js
CHANGED
package/dist/ops/scatterSub.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { r as
|
|
1
|
+
import { r as p } from "../../index--6vO-cOz.js";
|
|
2
2
|
class m {
|
|
3
3
|
variableNames = ["cache", "item"];
|
|
4
4
|
outputShape;
|
|
5
5
|
userCode;
|
|
6
6
|
customUniforms = [{ name: "cacheT", type: "int" }];
|
|
7
|
-
constructor(t, a,
|
|
8
|
-
const
|
|
9
|
-
this.outputShape = [t, a,
|
|
7
|
+
constructor(t, a, n, o, c) {
|
|
8
|
+
const s = Math.min(n + 1, c);
|
|
9
|
+
this.outputShape = [t, a, s, o], this.userCode = `
|
|
10
10
|
void main() {
|
|
11
11
|
ivec4 coords = getOutputCoords(); // [b, h, t, d]
|
|
12
12
|
int b = coords.x;
|
|
@@ -15,7 +15,7 @@ class m {
|
|
|
15
15
|
int d = coords.w;
|
|
16
16
|
|
|
17
17
|
int itemT = 1;
|
|
18
|
-
int maxSize = ${
|
|
18
|
+
int maxSize = ${c};
|
|
19
19
|
int totalT = cacheT + itemT;
|
|
20
20
|
int start = totalT >= maxSize ? 1 : 0;
|
|
21
21
|
|
|
@@ -23,21 +23,22 @@ class m {
|
|
|
23
23
|
float val = 0.0;
|
|
24
24
|
if (srcT < cacheT) {
|
|
25
25
|
val = getCache(b, h, srcT, d);
|
|
26
|
-
} else {
|
|
26
|
+
} else if (srcT == cacheT) {
|
|
27
27
|
val = getItem(b, h, 0, d);
|
|
28
|
-
}
|
|
28
|
+
} else {
|
|
29
|
+
val = 0.0;}
|
|
29
30
|
setOutput(val);
|
|
30
31
|
}
|
|
31
32
|
`;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
function
|
|
35
|
-
const { cache: t, item: a } = e.inputs, { maxSize: o } = e.attrs,
|
|
36
|
-
return
|
|
35
|
+
function d(e) {
|
|
36
|
+
const { cache: t, item: a } = e.inputs, { maxSize: n, pastLen: o } = e.attrs, c = e.backend, s = t.shape[0], r = t.shape[2], i = t.shape[1], h = new m(s, i, r, a.shape[3], n);
|
|
37
|
+
return c.runWebGLProgram(h, [t, a], "float32", [[o]]);
|
|
37
38
|
}
|
|
38
|
-
const
|
|
39
|
+
const l = {
|
|
39
40
|
kernelName: "AppendCache",
|
|
40
41
|
backendName: "webgl",
|
|
41
|
-
kernelFunc:
|
|
42
|
+
kernelFunc: d
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
p(l);
|