@genai-fi/nanogpt 0.2.10 → 0.2.12
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/TeachableLLM.js +8 -6
- package/dist/{complex-x7w5HPOS.js → complex-CJ-qCcLB.js} +1 -1
- package/dist/{index-CWQLouWz.js → index-YPKosni4.js} +52 -48
- package/dist/layers/CausalSelfAttention.d.ts +2 -0
- package/dist/layers/CausalSelfAttention.js +46 -56
- package/dist/layers/RoPECache.d.ts +4 -3
- package/dist/layers/RoPECache.js +17 -22
- package/dist/layers/TiedEmbedding.js +33 -32
- package/dist/main.js +18 -16
- package/dist/{mat_mul-4v7St11W.js → mat_mul-Bu7bhLms.js} +1 -1
- package/dist/ops/attentionMask.js +2 -2
- package/dist/ops/gatherSub.js +2 -2
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/qkv.d.ts +7 -0
- package/dist/ops/qkv.js +127 -0
- package/dist/ops/rope.d.ts +8 -0
- package/dist/ops/rope.js +154 -0
- package/dist/ops/scatterSub.js +10 -10
- package/dist/reshape-DmnmKT6r.js +25 -0
- package/dist/{stack-CTdK-itU.js → stack-BtKpB0Ry.js} +7 -7
- package/dist/sum-D7fu15XL.js +27 -0
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/sparseCrossEntropy.js +31 -30
- package/dist/utilities/profile.js +1 -1
- package/package.json +1 -1
- package/dist/sum-CnIf1YOh.js +0 -49
package/dist/main.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { default as
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import { estimateMemoryUsage as
|
|
1
|
+
import { default as s } from "./NanoGPTModel.js";
|
|
2
|
+
import { default as p } from "./TeachableLLM.js";
|
|
3
|
+
import { default as d } from "./tokeniser/CharTokeniser.js";
|
|
4
|
+
import { default as x } from "./utilities/waitForModel.js";
|
|
5
|
+
import { default as T } from "./data/textLoader.js";
|
|
6
|
+
import { estimateMemoryUsage as M, estimateParameterCount as C, estimateResources as c, estimateTrainingMemoryUsage as h, validateConfig as y } from "./utilities/parameters.js";
|
|
7
7
|
import "./ops/scatterSub.js";
|
|
8
8
|
import "./ops/gatherSub.js";
|
|
9
9
|
import "./ops/attentionMask.js";
|
|
10
|
+
import "./ops/qkv.js";
|
|
11
|
+
import "./ops/rope.js";
|
|
10
12
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
d as CharTokeniser,
|
|
14
|
+
s as NanoGPT,
|
|
15
|
+
p as TeachableLLM,
|
|
16
|
+
M as estimateMemoryUsage,
|
|
17
|
+
C as estimateParameterCount,
|
|
18
|
+
c as estimateResources,
|
|
19
|
+
h as estimateTrainingMemoryUsage,
|
|
20
|
+
T as loadTextData,
|
|
21
|
+
y as validateConfig,
|
|
22
|
+
x as waitForModel
|
|
21
23
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { engine as k } from "@tensorflow/tfjs";
|
|
2
|
-
import { r as m, c as d, s as p } from "../index-
|
|
3
|
-
import { m as f } from "../mat_mul-
|
|
2
|
+
import { r as m, c as d, s as p } from "../index-YPKosni4.js";
|
|
3
|
+
import { m as f } from "../mat_mul-Bu7bhLms.js";
|
|
4
4
|
class h {
|
|
5
5
|
variableNames = ["q", "k", "mask"];
|
|
6
6
|
outputShape;
|
package/dist/ops/gatherSub.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { engine as l } from "@tensorflow/tfjs";
|
|
2
|
-
import { o as g, d as i, E as b, G as d, r as c, b as h } from "../index-
|
|
3
|
-
import { r as p, s as f } from "../stack-
|
|
2
|
+
import { o as g, d as i, E as b, G as d, r as c, b as h } from "../index-YPKosni4.js";
|
|
3
|
+
import { r as p, s as f } from "../stack-BtKpB0Ry.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Tensor } from '@tensorflow/tfjs';
|
|
2
|
+
import { TensorInfo, NamedTensorInfoMap, NamedAttrMap } from '@tensorflow/tfjs-core';
|
|
3
|
+
export declare function qkvCPU(args: {
|
|
4
|
+
inputs: NamedTensorInfoMap;
|
|
5
|
+
attrs?: NamedAttrMap;
|
|
6
|
+
}): TensorInfo[];
|
|
7
|
+
export declare function qkv(x: Tensor, kernel: Tensor, heads: number): Tensor[];
|
package/dist/ops/qkv.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { engine as C } from "@tensorflow/tfjs";
|
|
2
|
+
import { o as N, d as V, E as Q, i as T, r as b, c as G } from "../index-YPKosni4.js";
|
|
3
|
+
import { r as x } from "../reshape-DmnmKT6r.js";
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2020 Google LLC. 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 M(r, e, o = 0) {
|
|
21
|
+
const t = { x: V(r, "x", "split") }, s = { numOrSizeSplits: e, axis: o };
|
|
22
|
+
return Q.runKernel(T, t, s);
|
|
23
|
+
}
|
|
24
|
+
const P = /* @__PURE__ */ N({ split_: M });
|
|
25
|
+
class S {
|
|
26
|
+
variableNames = ["x", "kernel"];
|
|
27
|
+
outputShape;
|
|
28
|
+
userCode;
|
|
29
|
+
// enableShapeUniforms = true;
|
|
30
|
+
customUniforms = [{ name: "mode", type: "int" }];
|
|
31
|
+
constructor(e, o, a, t) {
|
|
32
|
+
const s = t / o;
|
|
33
|
+
this.outputShape = [e, o, a, s], this.userCode = `
|
|
34
|
+
void main() {
|
|
35
|
+
ivec4 coords = getOutputCoords(); // [b, h, t, d]
|
|
36
|
+
int b = coords.x;
|
|
37
|
+
int h = coords.y;
|
|
38
|
+
int t = coords.z;
|
|
39
|
+
int d = coords.w;
|
|
40
|
+
|
|
41
|
+
// Compute output channel index in fused kernel
|
|
42
|
+
int out_offset = mode * ${o} * ${s} + h * ${s} + d;
|
|
43
|
+
|
|
44
|
+
float sum = 0.0;
|
|
45
|
+
for (int c = 0; c < ${t}; ++c) {
|
|
46
|
+
float xval = getX(b, t, c); // fetch from x
|
|
47
|
+
float kval = getKernel(c, out_offset); // fetch from kernel
|
|
48
|
+
sum += xval * kval;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setOutput(sum);
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function $(r) {
|
|
57
|
+
const { x: e, kernel: o } = r.inputs, { heads: a } = r.attrs, t = r.backend, s = e.shape[0], l = e.shape[1], d = e.shape[2], c = new S(s, a, l, d);
|
|
58
|
+
return [
|
|
59
|
+
t.runWebGLProgram(c, [e, o], "float32", [[0]]),
|
|
60
|
+
t.runWebGLProgram(c, [e, o], "float32", [[1]]),
|
|
61
|
+
t.runWebGLProgram(c, [e, o], "float32", [[2]])
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
const w = {
|
|
65
|
+
kernelName: "QKV",
|
|
66
|
+
backendName: "webgl",
|
|
67
|
+
kernelFunc: $
|
|
68
|
+
};
|
|
69
|
+
b(w);
|
|
70
|
+
function q(r) {
|
|
71
|
+
const { x: e, kernel: o } = r.inputs, { heads: a } = r.attrs, [t, s, l] = e.shape, d = x(e, [t * s, l]), c = d.dot(o);
|
|
72
|
+
d.dispose();
|
|
73
|
+
const n = x(c, [t, s, 3 * l]);
|
|
74
|
+
c.dispose();
|
|
75
|
+
const [p, m, k] = P(n, 3, -1);
|
|
76
|
+
n.dispose();
|
|
77
|
+
const f = l / a, v = x(p, [t, s, a, f]);
|
|
78
|
+
p.dispose();
|
|
79
|
+
const g = v.transpose([0, 2, 1, 3]);
|
|
80
|
+
v.dispose();
|
|
81
|
+
const u = x(m, [t, s, a, f]);
|
|
82
|
+
m.dispose();
|
|
83
|
+
const h = u.transpose([0, 2, 1, 3]);
|
|
84
|
+
u.dispose();
|
|
85
|
+
const i = x(k, [t, s, a, f]);
|
|
86
|
+
k.dispose();
|
|
87
|
+
const K = i.transpose([0, 2, 1, 3]);
|
|
88
|
+
return i.dispose(), [g, h, K];
|
|
89
|
+
}
|
|
90
|
+
const F = {
|
|
91
|
+
kernelName: "QKV",
|
|
92
|
+
backendName: "cpu",
|
|
93
|
+
kernelFunc: q
|
|
94
|
+
};
|
|
95
|
+
b(F);
|
|
96
|
+
const L = {
|
|
97
|
+
kernelName: "QKV",
|
|
98
|
+
backendName: "tensorflow",
|
|
99
|
+
kernelFunc: q
|
|
100
|
+
};
|
|
101
|
+
b(L);
|
|
102
|
+
function y(r, e, o) {
|
|
103
|
+
return C().runKernel("QKV", { x: r, kernel: e }, { heads: o });
|
|
104
|
+
}
|
|
105
|
+
const _ = {
|
|
106
|
+
kernelName: "QKV",
|
|
107
|
+
inputsToSave: ["x", "kernel"],
|
|
108
|
+
outputsToSave: [],
|
|
109
|
+
gradFunc: (r, e) => {
|
|
110
|
+
const [o, a, t] = r, [s, l] = e, [d, c, n] = s.shape, p = o.transpose([0, 2, 1, 3]).reshape([d * c, n]), m = a.transpose([0, 2, 1, 3]).reshape([d * c, n]), k = t.transpose([0, 2, 1, 3]).reshape([d * c, n]), f = l.slice([0, 0], [n, n]), v = l.slice([0, n], [n, n]), g = l.slice([0, 2 * n], [n, n]);
|
|
111
|
+
return {
|
|
112
|
+
x: () => {
|
|
113
|
+
const u = p.matMul(f, !1, !0), h = m.matMul(v, !1, !0), i = k.matMul(g, !1, !0);
|
|
114
|
+
return u.add(h).add(i).reshape([d, c, n]);
|
|
115
|
+
},
|
|
116
|
+
kernel: () => {
|
|
117
|
+
const u = s.reshape([d * c, n]), h = u.matMul(p, !0, !1), i = u.matMul(m, !0, !1), K = u.matMul(k, !0, !1);
|
|
118
|
+
return h.concat(i, 1).concat(K, 1);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
G(_);
|
|
124
|
+
export {
|
|
125
|
+
y as qkv,
|
|
126
|
+
q as qkvCPU
|
|
127
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as RoPECache } from '../layers/RoPECache';
|
|
2
|
+
import { Tensor } from '@tensorflow/tfjs';
|
|
3
|
+
import { TensorInfo, NamedTensorInfoMap, NamedAttrMap } from '@tensorflow/tfjs-core';
|
|
4
|
+
export declare function ropeCPU(args: {
|
|
5
|
+
inputs: NamedTensorInfoMap;
|
|
6
|
+
attrs?: NamedAttrMap;
|
|
7
|
+
}): TensorInfo;
|
|
8
|
+
export declare function rope(x: Tensor, cache: RoPECache, pastLength: number): Tensor;
|
package/dist/ops/rope.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { engine as D } from "@tensorflow/tfjs";
|
|
2
|
+
import { o as G, l as F, k as _, n as U, E as K, p as z, d as I, q as O, r as f, c as A } from "../index-YPKosni4.js";
|
|
3
|
+
import { r as T, s as B } from "../stack-BtKpB0Ry.js";
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2020 Google LLC. 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 W(o, t = 0) {
|
|
21
|
+
F(o.length >= 1, () => "Pass at least one tensor to concat");
|
|
22
|
+
const e = _(o, "tensors", "concat", "string_or_numeric");
|
|
23
|
+
if (e[0].dtype === "complex64" && e.forEach((r) => {
|
|
24
|
+
if (r.dtype !== "complex64")
|
|
25
|
+
throw new Error(`Cannot concatenate complex64 tensors with a tensor
|
|
26
|
+
with dtype ${r.dtype}. `);
|
|
27
|
+
}), e.length === 1)
|
|
28
|
+
return U(e[0]);
|
|
29
|
+
const n = e, s = { axis: t };
|
|
30
|
+
return K.runKernel(z, n, s);
|
|
31
|
+
}
|
|
32
|
+
const j = /* @__PURE__ */ G({ concat_: W });
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
36
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
37
|
+
* you may not use this file except in compliance with the License.
|
|
38
|
+
* You may obtain a copy of the License at
|
|
39
|
+
*
|
|
40
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
41
|
+
*
|
|
42
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
43
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
44
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
45
|
+
* See the License for the specific language governing permissions and
|
|
46
|
+
* limitations under the License.
|
|
47
|
+
* =============================================================================
|
|
48
|
+
*/
|
|
49
|
+
function H(o, t, e = 0, n = 0) {
|
|
50
|
+
const s = I(o, "x", "gather"), r = I(t, "indices", "gather", "int32"), c = { x: s, indices: r }, a = { axis: e, batchDims: n };
|
|
51
|
+
return K.runKernel(O, c, a);
|
|
52
|
+
}
|
|
53
|
+
const E = /* @__PURE__ */ G({ gather_: H });
|
|
54
|
+
class J {
|
|
55
|
+
variableNames = ["x", "sin", "cos"];
|
|
56
|
+
outputShape;
|
|
57
|
+
userCode;
|
|
58
|
+
// enableShapeUniforms = true;
|
|
59
|
+
customUniforms = [{ name: "pastLen", type: "int" }];
|
|
60
|
+
constructor(t, e, n, s) {
|
|
61
|
+
this.outputShape = [t, e, n, s], this.userCode = `
|
|
62
|
+
void main() {
|
|
63
|
+
ivec4 coords = getOutputCoords(); // [b, h, t, d]
|
|
64
|
+
int b = coords.x;
|
|
65
|
+
int h = coords.y;
|
|
66
|
+
int t = coords.z;
|
|
67
|
+
int d = coords.w;
|
|
68
|
+
|
|
69
|
+
int rotaryDim = ${s};
|
|
70
|
+
|
|
71
|
+
float outVal = 0.0;
|
|
72
|
+
|
|
73
|
+
if (d < rotaryDim) {
|
|
74
|
+
int pairIdx = d / 2;
|
|
75
|
+
float cos = getCos(t + pastLen, pairIdx, 0);
|
|
76
|
+
float sin = getSin(t + pastLen, pairIdx, 0);
|
|
77
|
+
|
|
78
|
+
if (d % 2 == 0) {
|
|
79
|
+
// even index
|
|
80
|
+
float even = getX(b, h, t, d);
|
|
81
|
+
float odd = getX(b, h, t, d + 1);
|
|
82
|
+
outVal = even * cos - odd * sin;
|
|
83
|
+
} else {
|
|
84
|
+
// odd index
|
|
85
|
+
float even = getX(b, h, t, d - 1);
|
|
86
|
+
float odd = getX(b, h, t, d);
|
|
87
|
+
outVal = even * sin + odd * cos;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
// pass through for non-rotary dims
|
|
91
|
+
outVal = getX(b, h, t, d);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setOutput(outVal);
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function M(o) {
|
|
100
|
+
const { x: t, sin: e, cos: n } = o.inputs, { pastLen: s } = o.attrs, r = o.backend, c = t.shape[0], a = t.shape[1], i = t.shape[2], d = t.shape[3], p = new J(c, a, i, d);
|
|
101
|
+
return r.runWebGLProgram(p, [t, e, n], "float32", [[s]]);
|
|
102
|
+
}
|
|
103
|
+
const Q = {
|
|
104
|
+
kernelName: "Rope",
|
|
105
|
+
backendName: "webgl",
|
|
106
|
+
kernelFunc: M
|
|
107
|
+
};
|
|
108
|
+
f(Q);
|
|
109
|
+
function V(o, t, e, n, s) {
|
|
110
|
+
const r = n.shape[3], c = e;
|
|
111
|
+
if (c > r) return n;
|
|
112
|
+
const a = n.shape[2], i = c / 2, d = t.slice([s, 0, 0], [a, i, 1]).reshape([1, 1, a, i]), p = o.slice([s, 0, 0], [a, i, 1]).reshape([1, 1, a, i]), u = n.shape[0], l = n.shape[1], g = T(0, c, 2, "int32"), x = T(1, c, 2, "int32"), $ = ((b) => {
|
|
113
|
+
const v = b.slice([0, 0, 0, 0], [u, l, a, c]), k = c < r ? b.slice([0, 0, 0, c], [u, l, a, r - c]) : null, h = E(v, g, 3), m = E(v, x, 3), C = h.mul(d), y = m.mul(p), R = C.sub(y), N = m.mul(d), S = h.mul(p), w = N.add(S);
|
|
114
|
+
h.dispose(), m.dispose(), d.dispose(), p.dispose(), C.dispose(), y.dispose(), N.dispose(), S.dispose();
|
|
115
|
+
const L = B([R, w], -1);
|
|
116
|
+
R.dispose(), w.dispose();
|
|
117
|
+
const P = L.reshape([u, l, a, c]);
|
|
118
|
+
return L.dispose(), k ? j([P, k], 3) : P;
|
|
119
|
+
})(n);
|
|
120
|
+
return g.dispose(), x.dispose(), $;
|
|
121
|
+
}
|
|
122
|
+
function X(o) {
|
|
123
|
+
const { x: t, sin: e, cos: n } = o.inputs, { pastLen: s } = o.attrs, r = t.shape[3];
|
|
124
|
+
return V(e, n, r, t, s);
|
|
125
|
+
}
|
|
126
|
+
const Y = {
|
|
127
|
+
kernelName: "Rope",
|
|
128
|
+
backendName: "cpu",
|
|
129
|
+
kernelFunc: X
|
|
130
|
+
};
|
|
131
|
+
f(Y);
|
|
132
|
+
const Z = {
|
|
133
|
+
kernelName: "Rope",
|
|
134
|
+
backendName: "tensorflow",
|
|
135
|
+
kernelFunc: X
|
|
136
|
+
};
|
|
137
|
+
f(Z);
|
|
138
|
+
function st(o, t, e) {
|
|
139
|
+
return t.ensureRopeCache(o.shape[1] + e), D().runKernel("Rope", { x: o, sin: t.getSin(), cos: t.getCos() }, { pastLen: e });
|
|
140
|
+
}
|
|
141
|
+
const q = {
|
|
142
|
+
kernelName: "Rope",
|
|
143
|
+
inputsToSave: ["x", "sin", "cos"],
|
|
144
|
+
outputsToSave: [],
|
|
145
|
+
gradFunc: (o, t) => {
|
|
146
|
+
const [e, n, s] = t, r = n.neg(), c = e.shape[3], i = V(r, s, c, o, 0);
|
|
147
|
+
return r.dispose(), { x: () => i };
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
A(q);
|
|
151
|
+
export {
|
|
152
|
+
st as rope,
|
|
153
|
+
X as ropeCPU
|
|
154
|
+
};
|
package/dist/ops/scatterSub.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { engine as $ } from "@tensorflow/tfjs";
|
|
2
|
-
import {
|
|
3
|
-
import { c as d } from "../complex-
|
|
4
|
-
import { r as v, s as T } from "../stack-
|
|
2
|
+
import { t as u, u as S, v as l, E as f, w as E, o as N, d as h, x as y, r as p, b as x, a as D } from "../index-YPKosni4.js";
|
|
3
|
+
import { c as d } from "../complex-CJ-qCcLB.js";
|
|
4
|
+
import { r as v, s as T } from "../stack-BtKpB0Ry.js";
|
|
5
5
|
/**
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -23,7 +23,7 @@ function i(e, t = "float32") {
|
|
|
23
23
|
const a = i(e, "float32"), o = i(e, "float32");
|
|
24
24
|
return d(a, o);
|
|
25
25
|
}
|
|
26
|
-
const r = S(
|
|
26
|
+
const r = S(l(e), t);
|
|
27
27
|
return f.makeTensor(r, e, t);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
@@ -47,7 +47,7 @@ function m(e, t = "float32") {
|
|
|
47
47
|
const a = m(e, "float32"), o = i(e, "float32");
|
|
48
48
|
return d(a, o);
|
|
49
49
|
}
|
|
50
|
-
const r = E(
|
|
50
|
+
const r = E(l(e), t);
|
|
51
51
|
return f.makeTensor(r, e, t);
|
|
52
52
|
}
|
|
53
53
|
function C(e, t, r) {
|
|
@@ -100,7 +100,7 @@ function O(e, t, r) {
|
|
|
100
100
|
*/
|
|
101
101
|
function z(e, t, r) {
|
|
102
102
|
u(r);
|
|
103
|
-
const a =
|
|
103
|
+
const a = h(e, "indices", "scatterND", "int32"), o = h(t, "updates", "scatterND");
|
|
104
104
|
O(o, a, r);
|
|
105
105
|
const s = { indices: a, updates: o }, n = { shape: r };
|
|
106
106
|
return f.runKernel(y, s, n);
|
|
@@ -131,17 +131,17 @@ const K = {
|
|
|
131
131
|
backendName: "webgl",
|
|
132
132
|
kernelFunc: P
|
|
133
133
|
};
|
|
134
|
-
|
|
134
|
+
p(K);
|
|
135
135
|
function A(e) {
|
|
136
|
-
const { logits: t, labels: r, dy: a } = e.inputs, o = r.shape[0], s = t.shape[1], n = v(0, o, 1, "int32"), c = T([n, r], 1), b = m([o]), g = I(c, b, [o, s]), k =
|
|
137
|
-
return
|
|
136
|
+
const { logits: t, labels: r, dy: a } = e.inputs, o = r.shape[0], s = t.shape[1], n = v(0, o, 1, "int32"), c = T([n, r], 1), b = m([o]), g = I(c, b, [o, s]), k = x(t, g), w = a.reshape([o, 1]);
|
|
137
|
+
return D(k, w);
|
|
138
138
|
}
|
|
139
139
|
const F = {
|
|
140
140
|
kernelName: "EfficientScatterSub",
|
|
141
141
|
backendName: "cpu",
|
|
142
142
|
kernelFunc: A
|
|
143
143
|
};
|
|
144
|
-
|
|
144
|
+
p(F);
|
|
145
145
|
function R(e, t, r) {
|
|
146
146
|
return $().runKernel("EfficientScatterSub", { logits: e, labels: t, dy: r }, {});
|
|
147
147
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { o, d as t, E as a, R as p } from "./index-YPKosni4.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 c(r, s) {
|
|
19
|
+
const e = { x: t(r, "x", "reshape", "string_or_numeric") }, n = { shape: s };
|
|
20
|
+
return a.runKernel(p, e, n);
|
|
21
|
+
}
|
|
22
|
+
const x = /* @__PURE__ */ o({ reshape_: c });
|
|
23
|
+
export {
|
|
24
|
+
x as r
|
|
25
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as e,
|
|
1
|
+
import { E as e, j as c, o as f, k as u, l as a, P as i } from "./index-YPKosni4.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -15,7 +15,7 @@ import { E as e, R as c, o as f, h as i, i as a, P as u } from "./index-CWQLouWz
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
* =============================================================================
|
|
17
17
|
*/
|
|
18
|
-
function
|
|
18
|
+
function g(n, s, t = 1, r = "float32") {
|
|
19
19
|
if (t === 0)
|
|
20
20
|
throw new Error("Cannot have a step of zero");
|
|
21
21
|
const o = { start: n, stop: s, step: t, dtype: r };
|
|
@@ -38,13 +38,13 @@ function l(n, s, t = 1, r = "float32") {
|
|
|
38
38
|
* =============================================================================
|
|
39
39
|
*/
|
|
40
40
|
function k(n, s = 0) {
|
|
41
|
-
const t =
|
|
41
|
+
const t = u(n, "tensors", "stack", "string_or_numeric");
|
|
42
42
|
a(t.length >= 1, () => "Pass at least one tensor to tf.stack"), t.length > 0 && a(s <= t[0].rank, () => "Axis must be <= rank of the tensor");
|
|
43
43
|
const r = t, o = { axis: s };
|
|
44
|
-
return e.runKernel(
|
|
44
|
+
return e.runKernel(i, r, o);
|
|
45
45
|
}
|
|
46
|
-
const
|
|
46
|
+
const h = /* @__PURE__ */ f({ stack_: k });
|
|
47
47
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
g as r,
|
|
49
|
+
h as s
|
|
50
50
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { o as e, d as u, h as c, E as l, S as m } from "./index-YPKosni4.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2018 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 i(t, o = null, n = !1) {
|
|
19
|
+
let s = u(t, "x", "sum");
|
|
20
|
+
s.dtype === "bool" && (s = c(s, "int32"));
|
|
21
|
+
const r = { x: s }, a = { axis: o, keepDims: n };
|
|
22
|
+
return l.runKernel(m, r, a);
|
|
23
|
+
}
|
|
24
|
+
const f = /* @__PURE__ */ e({ sum_: i });
|
|
25
|
+
export {
|
|
26
|
+
f as s
|
|
27
|
+
};
|
package/dist/training/AdamExt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as r, a as c, s as h, b as g, e as o } from "../index-
|
|
1
|
+
import { A as r, a as c, s as h, b as g, e as o } from "../index-YPKosni4.js";
|
|
2
2
|
class u extends r {
|
|
3
3
|
constructor(t, e, s, a, i) {
|
|
4
4
|
super(t, e, s, a), this.config = i, this.startLearningRate = t;
|