@genai-fi/nanogpt 0.4.3 → 0.4.5
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 +8 -8
- package/dist/Reshape-CiAY8ltP.js +212 -0
- package/dist/TeachableLLM.js +14 -5
- 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 +47 -46
- package/dist/layers/MLP.js +31 -33
- package/dist/layers/RMSNorm.d.ts +1 -2
- package/dist/layers/RMSNorm.js +10 -10
- package/dist/layers/RoPECache.js +3 -3
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +2 -2
- package/dist/{log_sum_exp-BswFnwOb.js → log_sum_exp-CiEy1aUe.js} +7 -7
- package/dist/main.js +28 -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.js +3 -3
- 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.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/normRMS.d.ts +1 -0
- package/dist/ops/cpu/normRMS.js +39 -0
- 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/normRMS.d.ts +2 -0
- package/dist/ops/grads/normRMS.js +20 -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/normRMS.d.ts +2 -0
- package/dist/ops/normRMS.js +10 -0
- 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.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 +21 -0
- package/dist/ops/webgl/matMulGelu.js +168 -0
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.d.ts +1 -0
- package/dist/ops/webgl/normRMS.js +78 -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/{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
|
@@ -3,15 +3,15 @@ import T from "./BaseLayer.js";
|
|
|
3
3
|
import { qkv as y } from "../ops/qkv.js";
|
|
4
4
|
import { rope as w } from "../ops/rope.js";
|
|
5
5
|
import { appendCache as E } from "../ops/appendCache.js";
|
|
6
|
-
import { D as z, F as S, t as $, c as L, e as j, H as O } from "../index-
|
|
6
|
+
import { D as z, F as S, t as $, c as L, e as j, H as O } from "../index--6vO-cOz.js";
|
|
7
7
|
import { fusedSoftmax as _ } from "../ops/fusedSoftmax.js";
|
|
8
|
-
import { l as W, w as M, d as x } from "../tfjs_backend-
|
|
9
|
-
import { o as
|
|
10
|
-
import { v as
|
|
11
|
-
import { z as
|
|
12
|
-
import { r as C, d as I } from "../dropout-
|
|
13
|
-
import { r as
|
|
14
|
-
import { m as
|
|
8
|
+
import { l as W, w as M, d as x } from "../tfjs_backend-DuKis_xG.js";
|
|
9
|
+
import { o as q } from "../ones-D6kB8bdY.js";
|
|
10
|
+
import { v as b } from "../variable-BJTZ3jOy.js";
|
|
11
|
+
import { z as B } from "../zeros-8xl-W2DC.js";
|
|
12
|
+
import { r as C, d as I } from "../dropout-DFEXTPV0.js";
|
|
13
|
+
import { r as F } from "../reshape-z51Eu-re.js";
|
|
14
|
+
import { m as H } from "../mat_mul-BEHRPMh0.js";
|
|
15
15
|
class nt extends T {
|
|
16
16
|
cAttn = null;
|
|
17
17
|
cProj = null;
|
|
@@ -23,16 +23,16 @@ class nt extends T {
|
|
|
23
23
|
units;
|
|
24
24
|
projUnits;
|
|
25
25
|
constructor(t, s) {
|
|
26
|
-
super(s), this.index = t, this.units = s.gpt.nEmbed * 3, this.projUnits = s.gpt.nEmbed, this.bias = W.bandPart(
|
|
27
|
-
const
|
|
28
|
-
this.maskInf = M(this.bias,
|
|
26
|
+
super(s), this.index = t, this.units = s.gpt.nEmbed * 3, this.projUnits = s.gpt.nEmbed, this.bias = W.bandPart(q([s.gpt.blockSize, s.gpt.blockSize]), -1, 0).cast("bool"), this.divisor = 1 / Math.sqrt(s.gpt.nEmbed / s.gpt.nHead);
|
|
27
|
+
const e = B([s.gpt.blockSize, s.gpt.blockSize]), o = z([s.gpt.blockSize, s.gpt.blockSize], Number.NEGATIVE_INFINITY);
|
|
28
|
+
this.maskInf = M(this.bias, e, o);
|
|
29
29
|
}
|
|
30
30
|
build() {
|
|
31
|
-
this.cAttn === null && (this.cAttn =
|
|
31
|
+
this.cAttn === null && (this.cAttn = b(
|
|
32
32
|
C([this.config.gpt.nEmbed, this.units], 0, 0.02),
|
|
33
33
|
!0
|
|
34
34
|
//`block_${this.index}_attn_cAttn_kernel`
|
|
35
|
-
)), this.cProj === null && (this.cProj =
|
|
35
|
+
)), this.cProj === null && (this.cProj = b(
|
|
36
36
|
C([this.projUnits, this.config.gpt.nEmbed], 0, 0.02),
|
|
37
37
|
!0
|
|
38
38
|
//`block_${this.index}_attn_cProj_kernel`
|
|
@@ -53,57 +53,58 @@ class nt extends T {
|
|
|
53
53
|
t.set(`block_${this.index}_cAttn`, this.cAttn ? [this.cAttn.clone()] : []), t.set(`block_${this.index}_cProj`, this.cProj ? [this.cProj.clone()] : []);
|
|
54
54
|
}
|
|
55
55
|
loadWeights(t) {
|
|
56
|
-
const s = t.get(`block_${this.index}_cAttn`)?.[0],
|
|
56
|
+
const s = t.get(`block_${this.index}_cAttn`)?.[0], e = t.get(`block_${this.index}_cProj`)?.[0];
|
|
57
57
|
if (!s) throw new Error(`Weights for block_${this.index}_cAttn not found`);
|
|
58
|
-
if (!
|
|
59
|
-
this.cAttn ? this.cAttn.assign(s) : this.cAttn =
|
|
58
|
+
if (!e) throw new Error(`Weights for block_${this.index}_cProj not found`);
|
|
59
|
+
this.cAttn ? this.cAttn.assign(s) : this.cAttn = b(s, !0), this.cProj ? this.cProj.assign(e) : this.cProj = b(e, !0);
|
|
60
60
|
}
|
|
61
|
-
getAttentionScores(t, s,
|
|
61
|
+
getAttentionScores(t, s, e, o) {
|
|
62
62
|
const i = P(t, s, this.divisor, this.maskInf);
|
|
63
|
-
return _(i,
|
|
63
|
+
return _(i, e ? this.config.gpt.dropout : 0, o);
|
|
64
64
|
}
|
|
65
65
|
// Attention with optional past. If pastLen > 0 and T_cur == 1, no mask needed.
|
|
66
|
-
getAttentionScoresWithPast(t, s,
|
|
67
|
-
const
|
|
68
|
-
return _(
|
|
66
|
+
getAttentionScoresWithPast(t, s, e) {
|
|
67
|
+
const o = P(t, s, this.divisor, void 0, e);
|
|
68
|
+
return _(o, 0, 0);
|
|
69
69
|
}
|
|
70
70
|
getQKV(t) {
|
|
71
71
|
return y(t, this.cAttn, this.config.gpt.nHead);
|
|
72
72
|
}
|
|
73
73
|
getOutputProjection(t) {
|
|
74
|
-
const s = t.shape[0],
|
|
74
|
+
const s = t.shape[0], e = t.shape[2], o = this.config.gpt.nEmbed, i = t.transpose([0, 2, 1, 3]), n = F(i, [s, e, o]);
|
|
75
75
|
return x(n, this.cProj);
|
|
76
76
|
}
|
|
77
|
-
updateCache(t, s,
|
|
78
|
-
const i = this.config.gpt.blockSize, n = t.shape[2], r =
|
|
79
|
-
|
|
77
|
+
updateCache(t, s, e, o) {
|
|
78
|
+
const i = this.config.gpt.blockSize, n = t.shape[2], r = o?.length || 0, a = e ? t : E(t, i, r, o?.k);
|
|
79
|
+
e || (t.dispose(), o?.k.dispose());
|
|
80
|
+
const p = e ? s : E(s, i, r, o?.v);
|
|
81
|
+
return e || (s.dispose(), o?.v.dispose()), {
|
|
80
82
|
k: S(a),
|
|
81
83
|
v: S(p),
|
|
82
84
|
length: Math.min(r + n, i),
|
|
83
|
-
cumulativeLength:
|
|
85
|
+
cumulativeLength: o ? o.cumulativeLength + n : n
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
|
-
forward(t, s = !1,
|
|
88
|
+
forward(t, s = !1, e, o = !1, i) {
|
|
87
89
|
return $(() => {
|
|
88
90
|
this.startMemory();
|
|
89
|
-
const [n, r, a] = this.getQKV(t), p = i ? i.cumulativeLength : 0, c = this.config.layerConfig.ropeCache, u = c ? w(n, c, p) : n,
|
|
91
|
+
const [n, r, a] = this.getQKV(t), p = i ? i.cumulativeLength : 0, c = this.config.layerConfig.ropeCache, u = c ? w(n, c, p) : n, A = c ? w(r, c, p) : r;
|
|
90
92
|
c && (n.dispose(), r.dispose());
|
|
91
|
-
const
|
|
92
|
-
i && (f.dispose(), a.dispose());
|
|
93
|
+
const f = i ? i.length : 0, d = this.updateCache(A, a, s, i), l = d.k, g = d.v;
|
|
93
94
|
let h;
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const k = this.getOutputProjection(
|
|
98
|
-
|
|
99
|
-
const v =
|
|
95
|
+
f > 0 ? h = this.getAttentionScoresWithPast(u, l, f) : h = this.getAttentionScores(u, l, s, e), u.dispose(), s && l.dispose();
|
|
96
|
+
const m = H(h, g);
|
|
97
|
+
o || h.dispose(), s && g.dispose();
|
|
98
|
+
const k = this.getOutputProjection(m);
|
|
99
|
+
m.dispose();
|
|
100
|
+
const v = o ? h.mean(1) : void 0;
|
|
100
101
|
return this.endMemory("CausalSelfAttention"), { output: k, attention: v, presentKV: s ? void 0 : d };
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
|
-
call(t, s = !1,
|
|
104
|
-
if (
|
|
104
|
+
call(t, s = !1, e = !1, o) {
|
|
105
|
+
if (o && !this.config.gpt.useRope)
|
|
105
106
|
throw new Error("Cannot use pastKV without RoPE enabled");
|
|
106
|
-
if (s &&
|
|
107
|
+
if (s && o)
|
|
107
108
|
throw new Error("Cannot use pastKV during training");
|
|
108
109
|
if (t.shape.length !== 3)
|
|
109
110
|
throw new Error(`Input tensor must be rank 3 [B, T, C], got shape ${t.shape}`);
|
|
@@ -115,15 +116,15 @@ class nt extends T {
|
|
|
115
116
|
const r = L(
|
|
116
117
|
// @ts-expect-error Invalid params
|
|
117
118
|
(a, p, c, u) => {
|
|
118
|
-
const
|
|
119
|
+
const A = this.forward(a, !0, i);
|
|
119
120
|
u([a]);
|
|
120
|
-
const
|
|
121
|
-
const [
|
|
121
|
+
const f = (d, l) => {
|
|
122
|
+
const [g] = l, h = j().state.activeTape;
|
|
122
123
|
j().state.activeTape = [];
|
|
123
|
-
const
|
|
124
|
-
return j().state.activeTape = h,
|
|
124
|
+
const m = O((k, v, R) => this.forward(k, !0, i).output)([g, p, c], d);
|
|
125
|
+
return j().state.activeTape = h, m;
|
|
125
126
|
};
|
|
126
|
-
return { value:
|
|
127
|
+
return { value: A.output, gradFunc: f };
|
|
127
128
|
}
|
|
128
129
|
)(t, this.cAttn, this.cProj);
|
|
129
130
|
if (this.config.gpt.dropout > 0) {
|
|
@@ -132,7 +133,7 @@ class nt extends T {
|
|
|
132
133
|
} else
|
|
133
134
|
return { output: r };
|
|
134
135
|
} else {
|
|
135
|
-
const n = this.forward(t, s, i,
|
|
136
|
+
const n = this.forward(t, s, i, e, o);
|
|
136
137
|
if (this.config.gpt.dropout > 0) {
|
|
137
138
|
const r = I(n.output, this.config.gpt.dropout);
|
|
138
139
|
return n.output.dispose(), { output: r, attention: n.attention, presentKV: n.presentKV };
|
package/dist/layers/MLP.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { v as
|
|
5
|
-
import { r as
|
|
6
|
-
import { r as
|
|
7
|
-
import { m as
|
|
8
|
-
class
|
|
1
|
+
import { t as F, c as _, e as h, H as M } from "../index--6vO-cOz.js";
|
|
2
|
+
import v from "./BaseLayer.js";
|
|
3
|
+
import { matMulGelu as x } from "../ops/matMulGelu.js";
|
|
4
|
+
import { v as c } from "../variable-BJTZ3jOy.js";
|
|
5
|
+
import { r as d, d as u } from "../dropout-DFEXTPV0.js";
|
|
6
|
+
import { r as p } from "../reshape-z51Eu-re.js";
|
|
7
|
+
import { m as L } from "../mat_mul-BEHRPMh0.js";
|
|
8
|
+
class G extends v {
|
|
9
9
|
cFc = null;
|
|
10
10
|
cProj = null;
|
|
11
11
|
index;
|
|
@@ -15,12 +15,12 @@ class V extends x {
|
|
|
15
15
|
super(s), this.index = t, this.hiddenUnits = s.gpt.mlpFactor * s.gpt.nEmbed;
|
|
16
16
|
}
|
|
17
17
|
build() {
|
|
18
|
-
this.cFc === null && (this.cFc =
|
|
19
|
-
|
|
18
|
+
this.cFc === null && (this.cFc = c(
|
|
19
|
+
d([this.config.gpt.nEmbed, this.hiddenUnits], 0, 0.02),
|
|
20
20
|
!0
|
|
21
21
|
//`block_${this.index}_attn_cAttn_kernel`
|
|
22
|
-
)), this.cProj === null && (this.cProj =
|
|
23
|
-
|
|
22
|
+
)), this.cProj === null && (this.cProj = c(
|
|
23
|
+
d(
|
|
24
24
|
[this.hiddenUnits, this.config.gpt.nEmbed],
|
|
25
25
|
0,
|
|
26
26
|
0.02 / Math.sqrt(2 * this.config.gpt.nLayer)
|
|
@@ -45,43 +45,41 @@ class V extends x {
|
|
|
45
45
|
const s = t.get(`block_${this.index}_mlpOut`)?.[0], i = t.get(`block_${this.index}_mlpHidden`)?.[0];
|
|
46
46
|
if (!s || !i)
|
|
47
47
|
throw new Error(`Weights for block ${this.index} not found`);
|
|
48
|
-
this.cFc ? this.cFc.assign(i) : this.cFc =
|
|
48
|
+
this.cFc ? this.cFc.assign(i) : this.cFc = c(i, !0), this.cProj ? this.cProj.assign(s) : this.cProj = c(s, !0);
|
|
49
49
|
}
|
|
50
50
|
forward(t) {
|
|
51
|
-
return
|
|
51
|
+
return F(() => {
|
|
52
52
|
this.startMemory();
|
|
53
|
-
const [s, i,
|
|
53
|
+
const [s, i, r] = t.shape, o = p(t, [s * i, r]), e = x(o, this.cFc), n = L(e, this.cProj);
|
|
54
54
|
e.dispose();
|
|
55
|
-
const a =
|
|
56
|
-
|
|
57
|
-
const h = l(a, [s, i, o]);
|
|
58
|
-
return this.endMemory("MLP"), h;
|
|
55
|
+
const a = p(n, [s, i, r]);
|
|
56
|
+
return this.endMemory("MLP"), a;
|
|
59
57
|
});
|
|
60
58
|
}
|
|
61
59
|
call(t, s = !1) {
|
|
62
60
|
if (this.build(), s && this.config.layerConfig.checkpointMLP) {
|
|
63
|
-
const
|
|
61
|
+
const r = _(
|
|
64
62
|
// @ts-expect-error Invalid params
|
|
65
|
-
(
|
|
66
|
-
const
|
|
67
|
-
return a([
|
|
68
|
-
const [
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
return
|
|
63
|
+
(o, e, n, a) => {
|
|
64
|
+
const l = this.forward(o);
|
|
65
|
+
return a([o]), { value: l, gradFunc: (f, g) => {
|
|
66
|
+
const [m] = g, b = h().state.activeTape;
|
|
67
|
+
h().state.activeTape = [];
|
|
68
|
+
const P = M((j, w, T) => this.forward(j))([m, e, n], f);
|
|
69
|
+
return h().state.activeTape = b, P;
|
|
72
70
|
} };
|
|
73
71
|
}
|
|
74
72
|
)(t, this.cFc, this.cProj);
|
|
75
73
|
if (this.config.gpt.dropout > 0) {
|
|
76
|
-
const
|
|
77
|
-
return
|
|
74
|
+
const o = u(r, this.config.gpt.dropout);
|
|
75
|
+
return r.dispose(), o;
|
|
78
76
|
}
|
|
79
|
-
return
|
|
77
|
+
return r;
|
|
80
78
|
} else {
|
|
81
79
|
const i = this.forward(t);
|
|
82
80
|
if (s && this.config.gpt.dropout > 0) {
|
|
83
|
-
const
|
|
84
|
-
return i.dispose(),
|
|
81
|
+
const r = u(i, this.config.gpt.dropout);
|
|
82
|
+
return i.dispose(), r;
|
|
85
83
|
}
|
|
86
84
|
return i;
|
|
87
85
|
}
|
|
@@ -91,5 +89,5 @@ class V extends x {
|
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
export {
|
|
94
|
-
|
|
92
|
+
G as default
|
|
95
93
|
};
|
package/dist/layers/RMSNorm.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { Tensor, Variable } from '@tensorflow/tfjs-core';
|
|
|
2
2
|
import { default as BaseLayer, GPTLayerConfig } from './BaseLayer';
|
|
3
3
|
export default class RMSNorm extends BaseLayer {
|
|
4
4
|
private gamma;
|
|
5
|
-
|
|
6
|
-
constructor(config: GPTLayerConfig, epsilon?: number, name?: string);
|
|
5
|
+
constructor(config: GPTLayerConfig, name?: string);
|
|
7
6
|
get trainableWeights(): Variable[];
|
|
8
7
|
set trainable(value: boolean);
|
|
9
8
|
getWeights(): Tensor[];
|
package/dist/layers/RMSNorm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as r } from "../index-
|
|
1
|
+
import { t as r } from "../index--6vO-cOz.js";
|
|
2
2
|
import m from "./BaseLayer.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { normRMS as s } from "../ops/normRMS.js";
|
|
4
|
+
import { v as e } from "../variable-BJTZ3jOy.js";
|
|
5
|
+
import { o as i } from "../ones-D6kB8bdY.js";
|
|
6
|
+
class u extends m {
|
|
6
7
|
gamma;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
super(t), this.epsilon = s, this.gamma = i(o([t.gpt.nEmbed]), !0, `${a}_gamma`, "float32");
|
|
8
|
+
constructor(t, a = "") {
|
|
9
|
+
super(t), this.gamma = e(i([t.gpt.nEmbed]), !0, `${a}_gamma`, "float32");
|
|
10
10
|
}
|
|
11
11
|
get trainableWeights() {
|
|
12
12
|
return [this.gamma];
|
|
@@ -23,8 +23,8 @@ class d extends m {
|
|
|
23
23
|
apply(t) {
|
|
24
24
|
return r(() => {
|
|
25
25
|
this.startMemory();
|
|
26
|
-
const a = t
|
|
27
|
-
return this.endMemory("RMSNorm"),
|
|
26
|
+
const a = s(t, this.gamma);
|
|
27
|
+
return this.endMemory("RMSNorm"), a;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
dispose() {
|
|
@@ -32,5 +32,5 @@ class d extends m {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
export {
|
|
35
|
-
|
|
35
|
+
u as default
|
|
36
36
|
};
|
package/dist/layers/RoPECache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as h, h as c, E as f,
|
|
2
|
-
import { c as d, s as C } from "../sin-
|
|
3
|
-
import { r as a } from "../range-
|
|
1
|
+
import { o as h, h as c, E as f, T as l, f as n, U as m, t as u, F as p } from "../index--6vO-cOz.js";
|
|
2
|
+
import { c as d, s as C } from "../sin-H567uayl.js";
|
|
3
|
+
import { r as a } from "../range-C_vpUjBu.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { T as a } from "../TiedEmbedding-
|
|
2
|
-
import "../index-
|
|
3
|
-
import "../tfjs_backend-
|
|
4
|
-
import "../variable-
|
|
5
|
-
import "../gather-
|
|
1
|
+
import { T as a } from "../TiedEmbedding-DznFwzcB.js";
|
|
2
|
+
import "../index--6vO-cOz.js";
|
|
3
|
+
import "../tfjs_backend-DuKis_xG.js";
|
|
4
|
+
import "../variable-BJTZ3jOy.js";
|
|
5
|
+
import "../gather-C5D8PxwA.js";
|
|
6
6
|
export {
|
|
7
7
|
a as default
|
|
8
8
|
};
|
|
@@ -2,7 +2,7 @@ import h from "./CausalSelfAttention.js";
|
|
|
2
2
|
import o from "./MLP.js";
|
|
3
3
|
import a from "./RMSNorm.js";
|
|
4
4
|
import p from "./BaseLayer.js";
|
|
5
|
-
import { t as d } from "../index-
|
|
5
|
+
import { t as d } from "../index--6vO-cOz.js";
|
|
6
6
|
class W extends p {
|
|
7
7
|
ln1;
|
|
8
8
|
attn;
|
|
@@ -12,7 +12,7 @@ class W extends p {
|
|
|
12
12
|
_trainable = !0;
|
|
13
13
|
skipped = !1;
|
|
14
14
|
constructor(t, s) {
|
|
15
|
-
super(s), this.index = t, this.ln1 = new a(s,
|
|
15
|
+
super(s), this.index = t, this.ln1 = new a(s, `block_${this.index}_rms1`), this.attn = new h(this.index, s), this.ln2 = new a(s, `block_${this.index}_rms2`), this.mlp = new o(this.index, s);
|
|
16
16
|
}
|
|
17
17
|
get variables() {
|
|
18
18
|
return [
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as r, h as p, E as u,
|
|
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, h as p, E as u, a6 as h, a7 as E, $, s as S, a8 as d } from "./index--6vO-cOz.js";
|
|
2
|
+
import { e as K } from "./axis_util-QP0LdI1v.js";
|
|
3
|
+
import { m as T } from "./max-BUShNgfh.js";
|
|
4
|
+
import { r as m } from "./reshape-z51Eu-re.js";
|
|
5
|
+
import { s as _ } from "./sum-DdkDf2MG.js";
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
8
8
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -62,12 +62,12 @@ const w = /* @__PURE__ */ r({ log_: v });
|
|
|
62
62
|
* =============================================================================
|
|
63
63
|
*/
|
|
64
64
|
function A(s, n = null, o = !1) {
|
|
65
|
-
const a = p(s, "x", "logSumExp"), t =
|
|
65
|
+
const a = p(s, "x", "logSumExp"), t = $(n, a.shape), x = T(
|
|
66
66
|
a,
|
|
67
67
|
t,
|
|
68
68
|
!0
|
|
69
69
|
/* keepDims */
|
|
70
|
-
), i =
|
|
70
|
+
), i = S(a, 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
|
@@ -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 E } from "./NanoGPTModel.js";
|
|
2
|
+
import { default as G } from "./TeachableLLM.js";
|
|
3
|
+
import { default as R } from "./tokeniser/CharTokeniser.js";
|
|
4
|
+
import { default as q } from "./tokeniser/bpe.js";
|
|
5
|
+
import { default as A } from "./utilities/waitForModel.js";
|
|
6
|
+
import { default as I } from "./data/textLoader.js";
|
|
7
|
+
import { estimateMemoryUsage as K, estimateParameterCount as O, estimateResources as Q, estimateTrainingMemoryUsage as S, validateConfig as V } from "./utilities/parameters.js";
|
|
8
|
+
import "./index--6vO-cOz.js";
|
|
9
9
|
import "./ops/cpu/scatterSub.js";
|
|
10
10
|
import "./ops/webgl/scatterSub.js";
|
|
11
11
|
import "./ops/cpu/gatherSub.js";
|
|
@@ -25,16 +25,25 @@ import "./ops/webgl/appendCache.js";
|
|
|
25
25
|
import "./ops/cpu/fusedSoftmax.js";
|
|
26
26
|
import "./ops/webgl/fusedSoftmax.js";
|
|
27
27
|
import "./ops/grads/fusedSoftmax.js";
|
|
28
|
+
import "./ops/cpu/matMulGelu.js";
|
|
29
|
+
import "./ops/webgl/matMulGelu.js";
|
|
30
|
+
import "./ops/grads/matMulGelu.js";
|
|
31
|
+
import "./ops/cpu/gelu.js";
|
|
32
|
+
import "./ops/webgl/gelu.js";
|
|
33
|
+
import "./ops/grads/gelu.js";
|
|
34
|
+
import "./ops/cpu/normRMS.js";
|
|
35
|
+
import "./ops/webgl/normRMS.js";
|
|
36
|
+
import "./ops/grads/normRMS.js";
|
|
28
37
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
q as BPETokeniser,
|
|
39
|
+
R as CharTokeniser,
|
|
40
|
+
E as NanoGPT,
|
|
41
|
+
G as TeachableLLM,
|
|
42
|
+
K as estimateMemoryUsage,
|
|
43
|
+
O as estimateParameterCount,
|
|
44
|
+
Q as estimateResources,
|
|
45
|
+
S as estimateTrainingMemoryUsage,
|
|
46
|
+
I as loadTextData,
|
|
47
|
+
V as validateConfig,
|
|
48
|
+
A as waitForModel
|
|
40
49
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as m, h as c, E as f,
|
|
2
|
-
import { e as v } from "./axis_util-
|
|
3
|
-
import { r as E } from "./reshape-
|
|
1
|
+
import { o as m, h as c, E as f, _ as i, $ as l, a0 as h, s as x, x as d } from "./index--6vO-cOz.js";
|
|
2
|
+
import { e as v } from "./axis_util-QP0LdI1v.js";
|
|
3
|
+
import { r as E } from "./reshape-z51Eu-re.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
@@ -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 K = /* @__PURE__ */ m({ moments_: T });
|
|
50
50
|
export {
|
|
51
|
-
|
|
51
|
+
K as a,
|
|
52
52
|
r as m
|
|
53
53
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as l, h as c, E as y,
|
|
2
|
-
import { e as A } from "./axis_util-
|
|
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, h as c, E as y, a1 as E, $ as w, a2 as o, a3 as u, U as v, f as I, a0 as $ } from "./index--6vO-cOz.js";
|
|
2
|
+
import { e as A } from "./axis_util-QP0LdI1v.js";
|
|
3
|
+
import { m as f } from "./max-BUShNgfh.js";
|
|
4
|
+
import { r as h } from "./reshape-z51Eu-re.js";
|
|
5
|
+
import { s as t } from "./sum-DdkDf2MG.js";
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
8
8
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
@@ -20,8 +20,8 @@ import { s as t } from "./sum-R28pucR5.js";
|
|
|
20
20
|
* =============================================================================
|
|
21
21
|
*/
|
|
22
22
|
function k(n, e = null, r = !1) {
|
|
23
|
-
const
|
|
24
|
-
return y.runKernel(E,
|
|
23
|
+
const a = { x: c(n, "x", "min") }, i = { axis: e, keepDims: r };
|
|
24
|
+
return y.runKernel(E, a, i);
|
|
25
25
|
}
|
|
26
26
|
const s = /* @__PURE__ */ l({ min_: k });
|
|
27
27
|
/**
|
|
@@ -42,13 +42,13 @@ const s = /* @__PURE__ */ l({ min_: k });
|
|
|
42
42
|
*/
|
|
43
43
|
function T(n, e = "euclidean", r = null, m = !1) {
|
|
44
44
|
n = c(n, "x", "norm");
|
|
45
|
-
const
|
|
46
|
-
let
|
|
45
|
+
const a = d(n, e, r);
|
|
46
|
+
let i = a.shape;
|
|
47
47
|
if (m) {
|
|
48
48
|
const p = w(r, n.shape);
|
|
49
|
-
|
|
49
|
+
i = A(a.shape, p);
|
|
50
50
|
}
|
|
51
|
-
return h(
|
|
51
|
+
return h(a, i);
|
|
52
52
|
}
|
|
53
53
|
function d(n, e, r = null) {
|
|
54
54
|
if (n.rank === 0)
|
|
@@ -79,8 +79,8 @@ function d(n, e, r = null) {
|
|
|
79
79
|
}
|
|
80
80
|
throw new Error(`Error in norm: invalid axis: ${r}`);
|
|
81
81
|
}
|
|
82
|
-
const
|
|
82
|
+
const N = /* @__PURE__ */ l({ norm_: T });
|
|
83
83
|
export {
|
|
84
84
|
s as m,
|
|
85
|
-
|
|
85
|
+
N as n
|
|
86
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--6vO-cOz.js";
|
|
2
|
+
import { z as l, c } from "./zeros-8xl-W2DC.js";
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
package/dist/ops/appendCache.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { e as a } from "../index-
|
|
1
|
+
import { e as a } from "../index--6vO-cOz.js";
|
|
2
2
|
import "./cpu/appendCache.js";
|
|
3
3
|
import "./webgl/appendCache.js";
|
|
4
|
-
import { z as s } from "../zeros-
|
|
5
|
-
import { c } from "../concat-
|
|
4
|
+
import { z as s } from "../zeros-8xl-W2DC.js";
|
|
5
|
+
import { c } from "../concat-DvWM7HGZ.js";
|
|
6
6
|
function i(r, p, n, o) {
|
|
7
7
|
if (!o) {
|
|
8
8
|
const e = r.shape[2];
|
|
@@ -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--6vO-cOz.js";
|
|
2
|
+
import { c as h } from "../../concat-DvWM7HGZ.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,5 +1,5 @@
|
|
|
1
|
-
import { r as o, f as k } from "../../index-
|
|
2
|
-
import { m as d } from "../../mat_mul-
|
|
1
|
+
import { r as o, f as k } from "../../index--6vO-cOz.js";
|
|
2
|
+
import { m as d } from "../../mat_mul-BEHRPMh0.js";
|
|
3
3
|
function r(t) {
|
|
4
4
|
const { q: e, k: n, mask: s } = t.inputs, { divisor: c } = t.attrs, m = e.shape[2], i = n.shape[2], a = d(e, n, !1, !0).mul(k(c));
|
|
5
5
|
if (s) {
|
|
@@ -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--6vO-cOz.js";
|
|
2
|
+
import { s as f } from "../../softmax-Dsxflvdl.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, 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 {};
|