@genai-fi/nanogpt 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Generator.js +22 -22
- package/dist/MLP-KHhikThU.js +83 -0
- package/dist/NanoGPTModel.d.ts +2 -3
- package/dist/NanoGPTModel.js +79 -79
- package/dist/TeachableLLM.js +16 -13
- package/dist/axis_util-DeydwOoC.js +69 -0
- package/dist/{concat-BIZS_td9.js → concat-DS_qH7MI.js} +5 -5
- package/dist/config.js +7 -8
- package/dist/{gather-BPGW8RsB.js → gather-BUmJIS8n.js} +1 -1
- package/dist/{index-pWA4_lUh.js → index-XjBAhiFO.js} +1272 -1174
- package/dist/layers/BaseLayer.d.ts +14 -2
- package/dist/layers/BaseLayer.js +9 -9
- package/dist/layers/CausalSelfAttention.d.ts +4 -8
- package/dist/layers/CausalSelfAttention.js +106 -80
- package/dist/layers/MLP.d.ts +2 -3
- package/dist/layers/MLP.js +5 -62
- package/dist/layers/RMSNorm.d.ts +2 -2
- package/dist/layers/RMSNorm.js +11 -11
- package/dist/layers/RoPECache.js +3 -3
- package/dist/layers/TiedEmbedding.js +7 -6
- package/dist/layers/TransformerBlock.d.ts +2 -6
- package/dist/layers/TransformerBlock.js +9 -12
- package/dist/{sum-C7Mgy9Bw.js → log_sum_exp-DJPkVZZn.js} +32 -54
- package/dist/main.js +22 -19
- package/dist/{mat_mul-D7_a4KJn.js → mat_mul-CKwFEV1Q.js} +1 -1
- package/dist/max-DJvEiCAJ.js +25 -0
- package/dist/moments-CrWRPcR3.js +53 -0
- package/dist/norm-BzY929B_.js +86 -0
- package/dist/{ones-Cog-G2ag.js → ones-BO01zpJG.js} +2 -2
- package/dist/ops/appendCache.js +1 -1
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +2 -2
- package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
- package/dist/ops/cpu/fusedSoftmax.js +23 -0
- package/dist/ops/cpu/gatherSub.js +3 -3
- package/dist/ops/cpu/mulDropout.d.ts +1 -0
- package/dist/ops/cpu/mulDropout.js +17 -0
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +27 -27
- package/dist/ops/fusedSoftmax.d.ts +2 -0
- package/dist/ops/fusedSoftmax.js +10 -0
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.d.ts +2 -0
- package/dist/ops/grads/fusedSoftmax.js +17 -0
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/mulDrop.d.ts +2 -0
- package/dist/ops/mulDrop.js +9 -0
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
- package/dist/ops/webgl/fusedSoftmax.js +3930 -0
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/mulDropout.d.ts +1 -0
- package/dist/ops/webgl/mulDropout.js +41 -0
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/{random_width-oeUIlUZj.js → random_width-CMHmdbSu.js} +4212 -6630
- package/dist/{range-CcDl05lo.js → range-DQMNzBWs.js} +1 -1
- package/dist/{reshape-C8CR_Bad.js → reshape-DFzh97Sc.js} +1 -1
- package/dist/{sin-BJIrfnj7.js → sin-BYM-U4Ut.js} +1 -1
- package/dist/slice_util-CnVNPQI-.js +90 -0
- package/dist/softmax-4DOn6cPq.js +28 -0
- package/dist/{split-DZbvruEP.js → split-CkbeVdF8.js} +3 -3
- package/dist/{stack-BMm-efee.js → stack-DaIMO5iX.js} +1 -1
- package/dist/sum-C6u3xMi3.js +27 -0
- package/dist/{tensor-DJVbYhh1.js → tensor-Cu1fU7H7.js} +1 -1
- package/dist/{tensor2d-ZuQSh2D-.js → tensor2d-D0CKdG6B.js} +1 -1
- package/dist/tfjs_backend-Bzl2SrRo.js +2460 -0
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +3 -3
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +13 -12
- package/dist/training/sparseCrossEntropy.js +12 -11
- package/dist/utilities/dummy.js +8 -8
- package/dist/utilities/generate.js +11 -11
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-Dl_ub3pk.js → variable-BS4AKqNU.js} +1 -1
- package/dist/{zeros-CCy9C3uU.js → zeros-CmJFiC84.js} +1 -1
- package/package.json +1 -1
- package/dist/exports_layers-tbTBcwMM.js +0 -25
- package/dist/layers/LayerNorm.d.ts +0 -13
- package/dist/layers/LayerNorm.js +0 -33
- package/dist/moments-DfcpfwKi.js +0 -132
- package/dist/softmax-Be_lsqUc.js +0 -105
- package/dist/training/LayerTrainer.d.ts +0 -29
- package/dist/training/LayerTrainer.js +0 -95
- package/dist/training/lwSchedule.d.ts +0 -7
- package/dist/training/lwSchedule.js +0 -162
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { g as Ot } from "./index-D5v913EJ.js";
|
|
2
2
|
import { p as Z } from "./index-xuotMAFm.js";
|
|
3
|
-
import { B as
|
|
3
|
+
import { B as mt } from "./index-Tf7vU29b.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -17,8 +17,8 @@ import { B as gt } from "./index-Tf7vU29b.js";
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
* =============================================================================
|
|
19
19
|
*/
|
|
20
|
-
const
|
|
21
|
-
class
|
|
20
|
+
const Me = 1e-7, Ne = 1e-4;
|
|
21
|
+
class Fe {
|
|
22
22
|
refCount(t) {
|
|
23
23
|
return v("refCount");
|
|
24
24
|
}
|
|
@@ -37,22 +37,22 @@ class ve {
|
|
|
37
37
|
readSync(t) {
|
|
38
38
|
return v("readSync");
|
|
39
39
|
}
|
|
40
|
-
readToGPU(t,
|
|
40
|
+
readToGPU(t, n) {
|
|
41
41
|
return v("readToGPU");
|
|
42
42
|
}
|
|
43
43
|
numDataIds() {
|
|
44
44
|
return v("numDataIds");
|
|
45
45
|
}
|
|
46
|
-
disposeData(t,
|
|
46
|
+
disposeData(t, n) {
|
|
47
47
|
return v("disposeData");
|
|
48
48
|
}
|
|
49
|
-
write(t,
|
|
49
|
+
write(t, n, s) {
|
|
50
50
|
return v("write");
|
|
51
51
|
}
|
|
52
|
-
move(t,
|
|
52
|
+
move(t, n, s, r, a) {
|
|
53
53
|
return v("move");
|
|
54
54
|
}
|
|
55
|
-
createTensorFromGPUData(t,
|
|
55
|
+
createTensorFromGPUData(t, n, s) {
|
|
56
56
|
return v("createTensorFromGPUData");
|
|
57
57
|
}
|
|
58
58
|
memory() {
|
|
@@ -64,14 +64,14 @@ class ve {
|
|
|
64
64
|
}
|
|
65
65
|
/** Returns the smallest representable number. */
|
|
66
66
|
epsilon() {
|
|
67
|
-
return this.floatPrecision() === 32 ?
|
|
67
|
+
return this.floatPrecision() === 32 ? Me : Ne;
|
|
68
68
|
}
|
|
69
69
|
dispose() {
|
|
70
70
|
return v("dispose");
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
function v(
|
|
74
|
-
throw new Error(`'${
|
|
73
|
+
function v(e) {
|
|
74
|
+
throw new Error(`'${e}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`);
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* @license
|
|
@@ -89,175 +89,227 @@ function v(n) {
|
|
|
89
89
|
* limitations under the License.
|
|
90
90
|
* =============================================================================
|
|
91
91
|
*/
|
|
92
|
-
function
|
|
93
|
-
let t =
|
|
92
|
+
function Ns(e) {
|
|
93
|
+
let t = e.length, n = 0;
|
|
94
94
|
for (; t > 0; )
|
|
95
|
-
|
|
95
|
+
n = Math.random() * t | 0, t--, Re(e, t, n);
|
|
96
96
|
}
|
|
97
|
-
function
|
|
98
|
-
const s =
|
|
99
|
-
|
|
97
|
+
function Re(e, t, n) {
|
|
98
|
+
const s = e[t];
|
|
99
|
+
e[t] = e[n], e[n] = s;
|
|
100
100
|
}
|
|
101
|
-
function y(
|
|
102
|
-
if (!
|
|
101
|
+
function y(e, t) {
|
|
102
|
+
if (!e)
|
|
103
103
|
throw new Error(typeof t == "string" ? t : t());
|
|
104
104
|
}
|
|
105
|
-
function
|
|
106
|
-
y(
|
|
105
|
+
function De(e, t, n = "") {
|
|
106
|
+
y(Rt(e, t), () => n + ` Shapes ${e} and ${t} must match`);
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
y(
|
|
108
|
+
function Fs(e) {
|
|
109
|
+
y(e != null, () => "The input to the tensor constructor must be a non-null value.");
|
|
110
110
|
}
|
|
111
|
-
function z(
|
|
112
|
-
if (
|
|
111
|
+
function z(e) {
|
|
112
|
+
if (e.length === 0)
|
|
113
113
|
return 1;
|
|
114
|
-
let t =
|
|
115
|
-
for (let
|
|
116
|
-
t *= n
|
|
114
|
+
let t = e[0];
|
|
115
|
+
for (let n = 1; n < e.length; n++)
|
|
116
|
+
t *= e[n];
|
|
117
117
|
return t;
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
if (
|
|
119
|
+
function Rt(e, t) {
|
|
120
|
+
if (e === t)
|
|
121
121
|
return !0;
|
|
122
|
-
if (
|
|
122
|
+
if (e == null || t == null || e.length !== t.length)
|
|
123
123
|
return !1;
|
|
124
|
-
for (let
|
|
125
|
-
if (n
|
|
124
|
+
for (let n = 0; n < e.length; n++)
|
|
125
|
+
if (e[n] !== t[n])
|
|
126
126
|
return !1;
|
|
127
127
|
return !0;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
function lt(
|
|
133
|
-
return t <=
|
|
129
|
+
function $e(e) {
|
|
130
|
+
return e % 1 === 0;
|
|
131
|
+
}
|
|
132
|
+
function lt(e, t) {
|
|
133
|
+
return t <= e.length ? e : e + " ".repeat(t - e.length);
|
|
134
|
+
}
|
|
135
|
+
function Rs(e, t) {
|
|
136
|
+
let n = 1, s = -1;
|
|
137
|
+
for (let a = 0; a < e.length; ++a)
|
|
138
|
+
if (e[a] >= 0)
|
|
139
|
+
n *= e[a];
|
|
140
|
+
else if (e[a] === -1) {
|
|
141
|
+
if (s !== -1)
|
|
142
|
+
throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${a}`);
|
|
143
|
+
s = a;
|
|
144
|
+
} else if (e[a] < 0)
|
|
145
|
+
throw Error(`Shapes can not be < 0. Found ${e[a]} at dim ${a}`);
|
|
146
|
+
if (s === -1) {
|
|
147
|
+
if (t > 0 && t !== n)
|
|
148
|
+
throw Error(`Size(${t}) must match the product of shape ${e}`);
|
|
149
|
+
return e;
|
|
150
|
+
}
|
|
151
|
+
if (n === 0)
|
|
152
|
+
throw Error(`Cannot infer the missing size in [${e}] when there are 0 elements`);
|
|
153
|
+
if (t % n !== 0)
|
|
154
|
+
throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${n}`);
|
|
155
|
+
const r = e.slice();
|
|
156
|
+
return r[s] = t / n, r;
|
|
134
157
|
}
|
|
135
|
-
function
|
|
136
|
-
const
|
|
137
|
-
return
|
|
158
|
+
function xe(e, t) {
|
|
159
|
+
const n = t.length;
|
|
160
|
+
return e = e == null ? t.map((s, r) => r) : [].concat(e), y(e.every((s) => s >= -n && s < n), () => `All values in axis param must be in range [-${n}, ${n}) but got axis ${e}`), y(e.every((s) => $e(s)), () => `All values in axis param must be integers but got axis ${e}`), e.map((s) => s < 0 ? n + s : s);
|
|
138
161
|
}
|
|
139
|
-
function
|
|
140
|
-
const
|
|
162
|
+
function Ds(e, t) {
|
|
163
|
+
const n = [], s = [], r = t != null && Array.isArray(t) && t.length === 0, a = t == null || r ? null : xe(t, e).sort();
|
|
141
164
|
let o = 0;
|
|
142
|
-
for (let i = 0; i <
|
|
165
|
+
for (let i = 0; i < e.length; ++i) {
|
|
143
166
|
if (a != null) {
|
|
144
|
-
if (a[o] === i &&
|
|
145
|
-
throw new Error(`Can't squeeze axis ${i} since its dim '${
|
|
146
|
-
(a[o] == null || a[o] > i) &&
|
|
167
|
+
if (a[o] === i && e[i] !== 1)
|
|
168
|
+
throw new Error(`Can't squeeze axis ${i} since its dim '${e[i]}' is not 1`);
|
|
169
|
+
(a[o] == null || a[o] > i) && e[i] === 1 && (n.push(e[i]), s.push(i)), a[o] <= i && o++;
|
|
147
170
|
}
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
return { newShape:
|
|
151
|
-
}
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
e[i] !== 1 && (n.push(e[i]), s.push(i));
|
|
172
|
+
}
|
|
173
|
+
return { newShape: n, keptDims: s };
|
|
174
|
+
}
|
|
175
|
+
function $s(e, t) {
|
|
176
|
+
return te(e, t);
|
|
177
|
+
}
|
|
178
|
+
function te(e, t) {
|
|
179
|
+
let n = null;
|
|
180
|
+
if (e == null || e === "float32")
|
|
181
|
+
n = new Float32Array(t);
|
|
182
|
+
else if (e === "int32")
|
|
183
|
+
n = new Int32Array(t);
|
|
184
|
+
else if (e === "bool")
|
|
185
|
+
n = new Uint8Array(t);
|
|
186
|
+
else if (e === "string")
|
|
187
|
+
n = new Array(t);
|
|
162
188
|
else
|
|
163
|
-
throw new Error(`Unknown data type ${
|
|
164
|
-
return
|
|
189
|
+
throw new Error(`Unknown data type ${e}`);
|
|
190
|
+
return n;
|
|
165
191
|
}
|
|
166
|
-
function
|
|
167
|
-
for (let
|
|
168
|
-
const s = n
|
|
192
|
+
function Ce(e, t) {
|
|
193
|
+
for (let n = 0; n < e.length; n++) {
|
|
194
|
+
const s = e[n];
|
|
169
195
|
if (isNaN(s) || !isFinite(s))
|
|
170
196
|
throw Error(`A tensor of type ${t} being uploaded contains ${s}.`);
|
|
171
197
|
}
|
|
172
198
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
199
|
+
function Pe(e) {
|
|
200
|
+
return e === "bool" || e === "complex64" || e === "float32" || e === "int32" || e === "string";
|
|
175
201
|
}
|
|
176
|
-
function
|
|
177
|
-
if (
|
|
202
|
+
function kt(e) {
|
|
203
|
+
if (e === "float32" || e === "int32")
|
|
178
204
|
return 4;
|
|
179
|
-
if (
|
|
205
|
+
if (e === "complex64")
|
|
180
206
|
return 8;
|
|
181
|
-
if (
|
|
207
|
+
if (e === "bool")
|
|
182
208
|
return 1;
|
|
183
|
-
throw new Error(`Unknown dtype ${
|
|
209
|
+
throw new Error(`Unknown dtype ${e}`);
|
|
184
210
|
}
|
|
185
|
-
function
|
|
186
|
-
if (
|
|
211
|
+
function Le(e) {
|
|
212
|
+
if (e == null)
|
|
187
213
|
return 0;
|
|
188
214
|
let t = 0;
|
|
189
|
-
return
|
|
215
|
+
return e.forEach((n) => t += n.length), t;
|
|
190
216
|
}
|
|
191
|
-
function Dt(
|
|
192
|
-
return typeof
|
|
217
|
+
function Dt(e) {
|
|
218
|
+
return typeof e == "string" || e instanceof String;
|
|
193
219
|
}
|
|
194
|
-
function
|
|
195
|
-
return typeof
|
|
220
|
+
function _e(e) {
|
|
221
|
+
return typeof e == "boolean";
|
|
196
222
|
}
|
|
197
|
-
function
|
|
198
|
-
return typeof
|
|
223
|
+
function Oe(e) {
|
|
224
|
+
return typeof e == "number";
|
|
199
225
|
}
|
|
200
|
-
function
|
|
201
|
-
return Array.isArray(
|
|
226
|
+
function pt(e) {
|
|
227
|
+
return Array.isArray(e) ? pt(e[0]) : e instanceof Float32Array ? "float32" : e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray ? "int32" : Oe(e) ? "float32" : Dt(e) ? "string" : _e(e) ? "bool" : "float32";
|
|
202
228
|
}
|
|
203
|
-
function
|
|
204
|
-
return !!(
|
|
229
|
+
function ht(e) {
|
|
230
|
+
return !!(e && e.constructor && e.call && e.apply);
|
|
205
231
|
}
|
|
206
|
-
function
|
|
207
|
-
|
|
232
|
+
function xs(e, t) {
|
|
233
|
+
for (let n = t; n < e; ++n)
|
|
234
|
+
if (e % n === 0)
|
|
235
|
+
return n;
|
|
236
|
+
return e;
|
|
237
|
+
}
|
|
238
|
+
function $t(e) {
|
|
239
|
+
const t = e.length;
|
|
208
240
|
if (t < 2)
|
|
209
241
|
return [];
|
|
210
|
-
const
|
|
211
|
-
|
|
242
|
+
const n = new Array(t - 1);
|
|
243
|
+
n[t - 2] = e[t - 1];
|
|
212
244
|
for (let s = t - 3; s >= 0; --s)
|
|
213
|
-
|
|
214
|
-
return
|
|
245
|
+
n[s] = n[s + 1] * e[s + 1];
|
|
246
|
+
return n;
|
|
215
247
|
}
|
|
216
|
-
function
|
|
248
|
+
function ee(e, t, n, s = !1) {
|
|
217
249
|
const r = new Array();
|
|
218
250
|
if (t.length === 1) {
|
|
219
251
|
const a = t[0] * (s ? 2 : 1);
|
|
220
252
|
for (let o = 0; o < a; o++)
|
|
221
|
-
r[o] = e
|
|
253
|
+
r[o] = n[e + o];
|
|
222
254
|
} else {
|
|
223
255
|
const a = t[0], o = t.slice(1), i = o.reduce((c, l) => c * l) * (s ? 2 : 1);
|
|
224
256
|
for (let c = 0; c < a; c++)
|
|
225
|
-
r[c] =
|
|
257
|
+
r[c] = ee(e + c * i, o, n, s);
|
|
226
258
|
}
|
|
227
259
|
return r;
|
|
228
260
|
}
|
|
229
|
-
function
|
|
230
|
-
if (
|
|
261
|
+
function Gt(e, t, n = !1) {
|
|
262
|
+
if (e.length === 0)
|
|
231
263
|
return t[0];
|
|
232
|
-
const s =
|
|
264
|
+
const s = e.reduce((r, a) => r * a) * (n ? 2 : 1);
|
|
233
265
|
if (s === 0)
|
|
234
266
|
return [];
|
|
235
267
|
if (s !== t.length)
|
|
236
|
-
throw new Error(`[${
|
|
237
|
-
return
|
|
268
|
+
throw new Error(`[${e}] does not match the input size ${t.length}${n ? " for a complex tensor" : ""}.`);
|
|
269
|
+
return ee(0, e, t, n);
|
|
238
270
|
}
|
|
239
|
-
function
|
|
240
|
-
const
|
|
241
|
-
for (let s = 0; s <
|
|
242
|
-
|
|
243
|
-
return
|
|
271
|
+
function Ge(e, t) {
|
|
272
|
+
const n = ne(e, t);
|
|
273
|
+
for (let s = 0; s < n.length; s++)
|
|
274
|
+
n[s] = 1;
|
|
275
|
+
return n;
|
|
244
276
|
}
|
|
245
|
-
function
|
|
277
|
+
function ne(e, t) {
|
|
246
278
|
if (t == null || t === "float32" || t === "complex64")
|
|
247
|
-
return new Float32Array(
|
|
279
|
+
return new Float32Array(e);
|
|
248
280
|
if (t === "int32")
|
|
249
|
-
return new Int32Array(
|
|
281
|
+
return new Int32Array(e);
|
|
250
282
|
if (t === "bool")
|
|
251
|
-
return new Uint8Array(
|
|
283
|
+
return new Uint8Array(e);
|
|
252
284
|
throw new Error(`Unknown data type ${t}`);
|
|
253
285
|
}
|
|
254
|
-
function xt(
|
|
255
|
-
|
|
256
|
-
y(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${
|
|
286
|
+
function xt(e) {
|
|
287
|
+
e.forEach((t) => {
|
|
288
|
+
y(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${e}].`);
|
|
257
289
|
});
|
|
258
290
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
291
|
+
function Cs(e, t, n) {
|
|
292
|
+
if (t === 0)
|
|
293
|
+
return 0;
|
|
294
|
+
if (t === 1)
|
|
295
|
+
return e[0];
|
|
296
|
+
let s = e[e.length - 1];
|
|
297
|
+
for (let r = 0; r < e.length - 1; ++r)
|
|
298
|
+
s += n[r] * e[r];
|
|
299
|
+
return s;
|
|
300
|
+
}
|
|
301
|
+
function Ps(e, t, n) {
|
|
302
|
+
if (t === 0)
|
|
303
|
+
return [];
|
|
304
|
+
if (t === 1)
|
|
305
|
+
return [e];
|
|
306
|
+
const s = new Array(t);
|
|
307
|
+
for (let r = 0; r < s.length - 1; ++r)
|
|
308
|
+
s[r] = Math.floor(e / n[r]), e -= s[r] * n[r];
|
|
309
|
+
return s[s.length - 1] = e, s;
|
|
310
|
+
}
|
|
311
|
+
function Ct(e) {
|
|
312
|
+
return e && e.then && typeof e.then == "function";
|
|
261
313
|
}
|
|
262
314
|
/**
|
|
263
315
|
* @license
|
|
@@ -276,16 +328,16 @@ function Ct(n) {
|
|
|
276
328
|
* =============================================================================
|
|
277
329
|
*/
|
|
278
330
|
const Ut = "tfjsflags";
|
|
279
|
-
class
|
|
331
|
+
class Ue {
|
|
280
332
|
// tslint:disable-next-line: no-any
|
|
281
333
|
constructor(t) {
|
|
282
|
-
this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams =
|
|
334
|
+
this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = ze, this.populateURLFlags();
|
|
283
335
|
}
|
|
284
|
-
setPlatform(t,
|
|
285
|
-
this.platform != null && (k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform =
|
|
336
|
+
setPlatform(t, n) {
|
|
337
|
+
this.platform != null && (k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform = n;
|
|
286
338
|
}
|
|
287
|
-
registerFlag(t,
|
|
288
|
-
if (this.flagRegistry[t] = { evaluationFn:
|
|
339
|
+
registerFlag(t, n, s) {
|
|
340
|
+
if (this.flagRegistry[t] = { evaluationFn: n, setHook: s }, this.urlFlags[t] != null) {
|
|
289
341
|
const r = this.urlFlags[t];
|
|
290
342
|
k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(`Setting feature override from URL ${t}: ${r}.`), this.set(t, r);
|
|
291
343
|
}
|
|
@@ -296,10 +348,10 @@ class Oe {
|
|
|
296
348
|
get(t) {
|
|
297
349
|
if (t in this.flags)
|
|
298
350
|
return this.flags[t];
|
|
299
|
-
const
|
|
300
|
-
if (Ct(
|
|
351
|
+
const n = this.evaluateFlag(t);
|
|
352
|
+
if (Ct(n))
|
|
301
353
|
throw new Error(`Flag ${t} cannot be synchronously evaluated. Please use getAsync() instead.`);
|
|
302
|
-
return this.flags[t] =
|
|
354
|
+
return this.flags[t] = n, this.flags[t];
|
|
303
355
|
}
|
|
304
356
|
getNumber(t) {
|
|
305
357
|
return this.get(t);
|
|
@@ -317,10 +369,10 @@ class Oe {
|
|
|
317
369
|
get features() {
|
|
318
370
|
return this.flags;
|
|
319
371
|
}
|
|
320
|
-
set(t,
|
|
372
|
+
set(t, n) {
|
|
321
373
|
if (this.flagRegistry[t] == null)
|
|
322
374
|
throw new Error(`Cannot set flag ${t} as it has not been registered.`);
|
|
323
|
-
this.flags[t] =
|
|
375
|
+
this.flags[t] = n, this.flagRegistry[t].setHook != null && this.flagRegistry[t].setHook(n);
|
|
324
376
|
}
|
|
325
377
|
evaluateFlag(t) {
|
|
326
378
|
if (this.flagRegistry[t] == null)
|
|
@@ -339,27 +391,27 @@ class Oe {
|
|
|
339
391
|
const t = this.getQueryParams(this.global.location.search);
|
|
340
392
|
Ut in t && t[Ut].split(",").forEach((s) => {
|
|
341
393
|
const [r, a] = s.split(":");
|
|
342
|
-
this.urlFlags[r] =
|
|
394
|
+
this.urlFlags[r] = We(r, a);
|
|
343
395
|
});
|
|
344
396
|
}
|
|
345
397
|
}
|
|
346
|
-
function
|
|
398
|
+
function ze(e) {
|
|
347
399
|
const t = {};
|
|
348
|
-
return
|
|
400
|
+
return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (n, ...s) => (Ve(t, s[0], s[1]), s.join("="))), t;
|
|
349
401
|
}
|
|
350
|
-
function
|
|
351
|
-
|
|
402
|
+
function Ve(e, t, n) {
|
|
403
|
+
e[decodeURIComponent(t)] = decodeURIComponent(n || "");
|
|
352
404
|
}
|
|
353
|
-
function
|
|
354
|
-
const
|
|
355
|
-
return
|
|
405
|
+
function We(e, t) {
|
|
406
|
+
const n = t.toLowerCase();
|
|
407
|
+
return n === "true" || n === "false" ? n === "true" : `${+n}` === n ? +n : t;
|
|
356
408
|
}
|
|
357
409
|
function k() {
|
|
358
|
-
return
|
|
410
|
+
return se;
|
|
359
411
|
}
|
|
360
|
-
let
|
|
361
|
-
function
|
|
362
|
-
|
|
412
|
+
let se = null;
|
|
413
|
+
function je(e) {
|
|
414
|
+
se = e;
|
|
363
415
|
}
|
|
364
416
|
/**
|
|
365
417
|
* @license
|
|
@@ -377,38 +429,38 @@ function ze(n) {
|
|
|
377
429
|
* limitations under the License.
|
|
378
430
|
* =============================================================================
|
|
379
431
|
*/
|
|
380
|
-
let
|
|
381
|
-
function
|
|
382
|
-
if (
|
|
383
|
-
let
|
|
432
|
+
let yt;
|
|
433
|
+
function re() {
|
|
434
|
+
if (yt == null) {
|
|
435
|
+
let e;
|
|
384
436
|
if (typeof window < "u")
|
|
385
|
-
|
|
437
|
+
e = window;
|
|
386
438
|
else if (typeof Ot < "u")
|
|
387
|
-
|
|
439
|
+
e = Ot;
|
|
388
440
|
else if (typeof Z < "u")
|
|
389
|
-
|
|
441
|
+
e = Z;
|
|
390
442
|
else if (typeof self < "u")
|
|
391
|
-
|
|
443
|
+
e = self;
|
|
392
444
|
else
|
|
393
445
|
throw new Error("Could not find a global object");
|
|
394
|
-
|
|
446
|
+
yt = e;
|
|
395
447
|
}
|
|
396
|
-
return
|
|
448
|
+
return yt;
|
|
397
449
|
}
|
|
398
|
-
function
|
|
399
|
-
const
|
|
400
|
-
return
|
|
450
|
+
function Ke() {
|
|
451
|
+
const e = re();
|
|
452
|
+
return e._tfGlobals == null && (e._tfGlobals = /* @__PURE__ */ new Map()), e._tfGlobals;
|
|
401
453
|
}
|
|
402
|
-
function Pt(
|
|
403
|
-
const
|
|
404
|
-
if (
|
|
405
|
-
return
|
|
454
|
+
function Pt(e, t) {
|
|
455
|
+
const n = Ke();
|
|
456
|
+
if (n.has(e))
|
|
457
|
+
return n.get(e);
|
|
406
458
|
{
|
|
407
459
|
const s = t();
|
|
408
|
-
return
|
|
460
|
+
return n.set(e, s), n.get(e);
|
|
409
461
|
}
|
|
410
462
|
}
|
|
411
|
-
const
|
|
463
|
+
const qe = "Abs", Ls = "Acos", _s = "Acosh", ae = "Add", Os = "AddN", Gs = "All", Us = "Any", zs = "ArgMax", Vs = "ArgMin", Ws = "Asin", js = "Asinh", Ks = "Atan", qs = "Atanh", Hs = "Atan2", Js = "AvgPool", Xs = "AvgPoolGrad", Ys = "AvgPool3D", Qs = "AvgPool3DGrad", Zs = "BatchMatMul", tr = "BatchToSpaceND", er = "Bincount", nr = "BroadcastTo", oe = "Cast", sr = "Ceil", rr = "ClipByValue", ar = "Complex", He = "ComplexAbs", or = "Concat", ir = "Conv2D", cr = "Conv2DBackpropFilter", lr = "Conv2DBackpropInput", ur = "Conv3D", hr = "Conv3DBackpropFilterV2", fr = "Conv3DBackpropInputV2", dr = "Cos", gr = "Cosh", mr = "Cumprod", pr = "Cumsum", yr = "CropAndResize", br = "DenseBincount", wr = "DepthwiseConv2dNative", Sr = "DepthwiseConv2dNativeBackpropFilter", kr = "DepthwiseConv2dNativeBackpropInput", Ir = "Dilation2D", Tr = "Dilation2DBackpropInput", Er = "Dilation2DBackpropFilter", Je = "RealDiv", Ar = "Einsum", Br = "Elu", vr = "EluGrad", Mr = "Erf", Nr = "Equal", Fr = "Exp", Rr = "ExpandDims", Dr = "Expm1", Xe = "Fill", $r = "FlipLeftRight", xr = "Floor", Ye = "FloorDiv", Cr = "FusedBatchNorm", Pr = "GatherV2", Lr = "GatherNd", _r = "Greater", Or = "GreaterEqual", ie = "Identity", Gr = "Imag", Ur = "IsFinite", zr = "IsInf", Vr = "IsNan", Wr = "LeakyRelu", jr = "Less", Kr = "LessEqual", qr = "Log", Hr = "Log1p", Jr = "LogicalAnd", Xr = "LogicalNot", Yr = "LogSoftmax", Qr = "LRN", Zr = "LRNGrad", ta = "Max", Qe = "Maximum", ea = "MaxPool", na = "MaxPoolGrad", sa = "MaxPool3D", ra = "MaxPool3DGrad", aa = "Mean", oa = "Min", ia = "Minimum", ca = "MirrorPad", la = "Mod", ua = "Multinomial", Ze = "Multiply", ha = "Neg", fa = "NotEqual", da = "NonMaxSuppressionV3", ga = "NonMaxSuppressionV4", ma = "NonMaxSuppressionV5", pa = "OnesLike", ya = "OneHot", ba = "Pack", wa = "PadV2", tn = "Pow", Sa = "Prelu", ka = "Prod", Ia = "Range", Ta = "Real", Ea = "Reciprocal", Aa = "Relu", Ba = "Reshape", va = "ResizeNearestNeighbor", Ma = "ResizeNearestNeighborGrad", Na = "ResizeBilinear", Fa = "ResizeBilinearGrad", Ra = "Relu6", Da = "Reverse", $a = "Round", xa = "Rsqrt", Ca = "ScatterNd", Pa = "Select", La = "Selu", _a = "Slice", Oa = "Sin", Ga = "Sinh", Ua = "Sign", za = "Sigmoid", Va = "Softplus", en = "Sqrt", Wa = "Sum", ja = "SpaceToBatchND", Ka = "SplitV", qa = "Softmax", Ha = "SquaredDifference", Ja = "Square", nn = "Sub", Xa = "Tan", Ya = "Tanh", Qa = "Tile", Za = "TopK", to = "Transform", eo = "Transpose", no = "Unpack", so = "UnsortedSegmentSum", sn = "ZerosLike", ro = "Step", ao = "RotateWithOffset", oo = "_FusedMatMul", io = "FusedConv2D";
|
|
412
464
|
/**
|
|
413
465
|
* @license
|
|
414
466
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -425,8 +477,8 @@ const We = "Abs", Rs = "Acos", Fs = "Acosh", se = "Add", Ds = "AddN", $s = "All"
|
|
|
425
477
|
* limitations under the License.
|
|
426
478
|
* =============================================================================
|
|
427
479
|
*/
|
|
428
|
-
function
|
|
429
|
-
k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(...
|
|
480
|
+
function O(...e) {
|
|
481
|
+
k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(...e);
|
|
430
482
|
}
|
|
431
483
|
/**
|
|
432
484
|
* @license
|
|
@@ -444,35 +496,35 @@ function _(...n) {
|
|
|
444
496
|
* limitations under the License.
|
|
445
497
|
* =============================================================================
|
|
446
498
|
*/
|
|
447
|
-
const
|
|
448
|
-
function
|
|
449
|
-
const
|
|
450
|
-
return
|
|
499
|
+
const ft = Pt("kernelRegistry", () => /* @__PURE__ */ new Map()), It = Pt("gradRegistry", () => /* @__PURE__ */ new Map());
|
|
500
|
+
function zt(e, t) {
|
|
501
|
+
const n = ce(e, t);
|
|
502
|
+
return ft.get(n);
|
|
451
503
|
}
|
|
452
|
-
function
|
|
453
|
-
return It.get(
|
|
504
|
+
function Vt(e) {
|
|
505
|
+
return It.get(e);
|
|
454
506
|
}
|
|
455
|
-
function
|
|
456
|
-
const t =
|
|
507
|
+
function Wt(e) {
|
|
508
|
+
const t = ft.entries(), n = [];
|
|
457
509
|
for (; ; ) {
|
|
458
510
|
const { done: s, value: r } = t.next();
|
|
459
511
|
if (s)
|
|
460
512
|
break;
|
|
461
513
|
const [a, o] = r, [i] = a.split("_");
|
|
462
|
-
i ===
|
|
514
|
+
i === e && n.push(o);
|
|
463
515
|
}
|
|
464
|
-
return
|
|
516
|
+
return n;
|
|
465
517
|
}
|
|
466
|
-
function
|
|
467
|
-
const { kernelName: t, backendName:
|
|
468
|
-
|
|
518
|
+
function co(e) {
|
|
519
|
+
const { kernelName: t, backendName: n } = e, s = ce(t, n);
|
|
520
|
+
ft.has(s) && O(`The kernel '${t}' for backend '${n}' is already registered`), ft.set(s, e);
|
|
469
521
|
}
|
|
470
|
-
function
|
|
471
|
-
const { kernelName: t } =
|
|
472
|
-
It.has(t) && k().getBool("DEBUG") &&
|
|
522
|
+
function lo(e) {
|
|
523
|
+
const { kernelName: t } = e;
|
|
524
|
+
It.has(t) && k().getBool("DEBUG") && O(`Overriding the gradient for '${t}'`), It.set(t, e);
|
|
473
525
|
}
|
|
474
|
-
function
|
|
475
|
-
return `${t}_${
|
|
526
|
+
function ce(e, t) {
|
|
527
|
+
return `${t}_${e}`;
|
|
476
528
|
}
|
|
477
529
|
/**
|
|
478
530
|
* @license
|
|
@@ -490,8 +542,8 @@ function oe(n, t) {
|
|
|
490
542
|
* limitations under the License.
|
|
491
543
|
* =============================================================================
|
|
492
544
|
*/
|
|
493
|
-
function
|
|
494
|
-
return
|
|
545
|
+
function le(e) {
|
|
546
|
+
return e instanceof Float32Array || e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray;
|
|
495
547
|
}
|
|
496
548
|
/**
|
|
497
549
|
* @license
|
|
@@ -509,50 +561,53 @@ function ie(n) {
|
|
|
509
561
|
* limitations under the License.
|
|
510
562
|
* =============================================================================
|
|
511
563
|
*/
|
|
512
|
-
function
|
|
513
|
-
return
|
|
564
|
+
function uo(e, t) {
|
|
565
|
+
return t === "string" ? ue(e) : Lt([e], t);
|
|
514
566
|
}
|
|
515
|
-
function
|
|
567
|
+
function rn(e, t) {
|
|
568
|
+
return e instanceof Float32Array && t === "float32" || e instanceof Int32Array && t === "int32" || e instanceof Uint8Array && t === "bool";
|
|
569
|
+
}
|
|
570
|
+
function Lt(e, t) {
|
|
516
571
|
if (t === "string")
|
|
517
572
|
throw new Error("Cannot convert a string[] to a TypedArray");
|
|
518
|
-
if (Array.isArray(
|
|
519
|
-
return
|
|
573
|
+
if (Array.isArray(e) && (e = ct(e)), k().getBool("DEBUG") && Ce(e, t), rn(e, t))
|
|
574
|
+
return e;
|
|
520
575
|
if (t == null || t === "float32" || t === "complex64")
|
|
521
|
-
return new Float32Array(
|
|
576
|
+
return new Float32Array(e);
|
|
522
577
|
if (t === "int32")
|
|
523
|
-
return new Int32Array(
|
|
578
|
+
return new Int32Array(e);
|
|
524
579
|
if (t === "bool") {
|
|
525
|
-
const
|
|
526
|
-
for (let s = 0; s <
|
|
527
|
-
Math.round(
|
|
528
|
-
return
|
|
580
|
+
const n = new Uint8Array(e.length);
|
|
581
|
+
for (let s = 0; s < n.length; ++s)
|
|
582
|
+
Math.round(e[s]) !== 0 && (n[s] = 1);
|
|
583
|
+
return n;
|
|
529
584
|
} else
|
|
530
585
|
throw new Error(`Unknown data type ${t}`);
|
|
531
586
|
}
|
|
532
587
|
function dt() {
|
|
533
588
|
return k().platform.now();
|
|
534
589
|
}
|
|
535
|
-
function
|
|
536
|
-
return t = t || "utf-8", k().platform.encode(
|
|
590
|
+
function ue(e, t = "utf-8") {
|
|
591
|
+
return t = t || "utf-8", k().platform.encode(e, t);
|
|
537
592
|
}
|
|
538
|
-
function
|
|
539
|
-
return t = t || "utf-8", k().platform.decode(
|
|
593
|
+
function jt(e, t = "utf-8") {
|
|
594
|
+
return t = t || "utf-8", k().platform.decode(e, t);
|
|
540
595
|
}
|
|
541
|
-
function
|
|
542
|
-
return k().platform.isTypedArray != null ? k().platform.isTypedArray(
|
|
596
|
+
function F(e) {
|
|
597
|
+
return k().platform.isTypedArray != null ? k().platform.isTypedArray(e) : le(e);
|
|
543
598
|
}
|
|
544
|
-
function ct(
|
|
545
|
-
if (t == null && (t = []), typeof
|
|
546
|
-
t.push(
|
|
547
|
-
else if (Array.isArray(
|
|
548
|
-
for (let s = 0; s <
|
|
549
|
-
ct(
|
|
599
|
+
function ct(e, t = [], n = !1) {
|
|
600
|
+
if (t == null && (t = []), typeof e == "boolean" || typeof e == "number" || typeof e == "string" || Ct(e) || e == null || F(e) && n)
|
|
601
|
+
t.push(e);
|
|
602
|
+
else if (Array.isArray(e) || F(e))
|
|
603
|
+
for (let s = 0; s < e.length; ++s)
|
|
604
|
+
ct(e[s], t, n);
|
|
550
605
|
else {
|
|
551
606
|
let s = -1;
|
|
552
|
-
for (const r of Object.keys(
|
|
607
|
+
for (const r of Object.keys(e))
|
|
553
608
|
/^([1-9]+[0-9]*|0)$/.test(r) && (s = Math.max(s, Number(r)));
|
|
554
609
|
for (let r = 0; r <= s; r++)
|
|
555
|
-
ct(
|
|
610
|
+
ct(e[r], t, n);
|
|
556
611
|
}
|
|
557
612
|
return t;
|
|
558
613
|
}
|
|
@@ -572,11 +627,11 @@ function ct(n, t = [], e = !1) {
|
|
|
572
627
|
* limitations under the License.
|
|
573
628
|
* =============================================================================
|
|
574
629
|
*/
|
|
575
|
-
class
|
|
576
|
-
constructor(t,
|
|
577
|
-
this.backendTimer = t, this.logger =
|
|
630
|
+
class an {
|
|
631
|
+
constructor(t, n) {
|
|
632
|
+
this.backendTimer = t, this.logger = n, n == null && (this.logger = new cn());
|
|
578
633
|
}
|
|
579
|
-
profileKernel(t,
|
|
634
|
+
profileKernel(t, n, s) {
|
|
580
635
|
let r;
|
|
581
636
|
const a = () => {
|
|
582
637
|
r = s();
|
|
@@ -595,48 +650,48 @@ class sn {
|
|
|
595
650
|
for (let l = 0; l < r.length; l++) {
|
|
596
651
|
const u = r[l];
|
|
597
652
|
u.data().then((h) => {
|
|
598
|
-
|
|
653
|
+
on(h, u.dtype, t);
|
|
599
654
|
});
|
|
600
655
|
}
|
|
601
656
|
return {
|
|
602
657
|
kernelName: t,
|
|
603
658
|
outputs: r,
|
|
604
|
-
inputs:
|
|
659
|
+
inputs: n,
|
|
605
660
|
timeMs: o.then((l) => l.kernelMs),
|
|
606
661
|
extraInfo: o.then((l) => l.getExtraProfileInfo != null ? l.getExtraProfileInfo() : "")
|
|
607
662
|
};
|
|
608
663
|
}
|
|
609
664
|
logKernelProfile(t) {
|
|
610
|
-
const { kernelName:
|
|
665
|
+
const { kernelName: n, outputs: s, timeMs: r, inputs: a, extraInfo: o } = t;
|
|
611
666
|
s.forEach((i) => {
|
|
612
667
|
Promise.all([i.data(), r, o]).then((c) => {
|
|
613
|
-
this.logger.logKernelProfile(
|
|
668
|
+
this.logger.logKernelProfile(n, i, c[0], c[1], a, c[2]);
|
|
614
669
|
});
|
|
615
670
|
});
|
|
616
671
|
}
|
|
617
672
|
}
|
|
618
|
-
function
|
|
673
|
+
function on(e, t, n) {
|
|
619
674
|
if (t !== "float32")
|
|
620
675
|
return !1;
|
|
621
|
-
for (let s = 0; s <
|
|
622
|
-
const r =
|
|
676
|
+
for (let s = 0; s < e.length; s++) {
|
|
677
|
+
const r = e[s];
|
|
623
678
|
if (isNaN(r) || !isFinite(r))
|
|
624
|
-
return console.warn(`Found ${r} in the result of '${
|
|
679
|
+
return console.warn(`Found ${r} in the result of '${n}'`), !0;
|
|
625
680
|
}
|
|
626
681
|
return !1;
|
|
627
682
|
}
|
|
628
|
-
class
|
|
629
|
-
logKernelProfile(t,
|
|
630
|
-
const i = typeof r == "number" ? lt(`${r}ms`, 9) : r.error, c = lt(t, 25), l =
|
|
631
|
-
let
|
|
683
|
+
class cn {
|
|
684
|
+
logKernelProfile(t, n, s, r, a, o) {
|
|
685
|
+
const i = typeof r == "number" ? lt(`${r}ms`, 9) : r.error, c = lt(t, 25), l = n.rank, u = n.size, h = lt(n.shape.toString(), 14);
|
|
686
|
+
let f = "";
|
|
632
687
|
for (const m in a) {
|
|
633
688
|
const p = a[m];
|
|
634
689
|
if (p != null) {
|
|
635
|
-
const
|
|
636
|
-
|
|
690
|
+
const d = p.shape || n.shape, w = d.length;
|
|
691
|
+
f += `${m}: ${w}D ${w > 0 ? d : ""} `;
|
|
637
692
|
}
|
|
638
693
|
}
|
|
639
|
-
console.log(`%c${c} %c${i} %c${l}D ${h} %c${u} %c${
|
|
694
|
+
console.log(`%c${c} %c${i} %c${l}D ${h} %c${u} %c${f} %c${o}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
|
|
640
695
|
}
|
|
641
696
|
}
|
|
642
697
|
/**
|
|
@@ -655,18 +710,18 @@ class an {
|
|
|
655
710
|
* limitations under the License.
|
|
656
711
|
* =============================================================================
|
|
657
712
|
*/
|
|
658
|
-
function
|
|
713
|
+
function ln(e, t, n) {
|
|
659
714
|
const s = {}, r = {};
|
|
660
715
|
for (let c = 0; c < t.length; c++)
|
|
661
716
|
s[t[c].id] = !0;
|
|
662
|
-
for (let c = 0; c <
|
|
663
|
-
const l =
|
|
717
|
+
for (let c = 0; c < e.length; c++) {
|
|
718
|
+
const l = e[c], u = l.inputs;
|
|
664
719
|
for (const h in u) {
|
|
665
|
-
const
|
|
720
|
+
const f = u[h];
|
|
666
721
|
let m = !1;
|
|
667
722
|
for (let p = 0; p < t.length; p++)
|
|
668
|
-
if (s[
|
|
669
|
-
l.outputs.forEach((
|
|
723
|
+
if (s[f.id]) {
|
|
724
|
+
l.outputs.forEach((d) => s[d.id] = !0), m = !0, r[l.id] = !0;
|
|
670
725
|
break;
|
|
671
726
|
}
|
|
672
727
|
if (m)
|
|
@@ -674,25 +729,25 @@ function on(n, t, e) {
|
|
|
674
729
|
}
|
|
675
730
|
}
|
|
676
731
|
const a = {};
|
|
677
|
-
a[
|
|
732
|
+
a[n.id] = !0;
|
|
678
733
|
const o = {};
|
|
679
|
-
for (let c =
|
|
680
|
-
const l =
|
|
734
|
+
for (let c = e.length - 1; c >= 0; c--) {
|
|
735
|
+
const l = e[c], u = l.inputs;
|
|
681
736
|
for (let h = 0; h < l.outputs.length; h++)
|
|
682
737
|
if (a[l.outputs[h].id]) {
|
|
683
|
-
for (const
|
|
684
|
-
a[u[
|
|
738
|
+
for (const f in u)
|
|
739
|
+
a[u[f].id] = !0, o[l.id] = !0;
|
|
685
740
|
break;
|
|
686
741
|
}
|
|
687
742
|
}
|
|
688
743
|
const i = [];
|
|
689
|
-
for (let c = 0; c <
|
|
690
|
-
const l =
|
|
744
|
+
for (let c = 0; c < e.length; c++) {
|
|
745
|
+
const l = e[c];
|
|
691
746
|
if (r[l.id] && o[l.id]) {
|
|
692
747
|
const u = {};
|
|
693
|
-
for (const
|
|
694
|
-
const m = l.inputs[
|
|
695
|
-
s[m.id] && (u[
|
|
748
|
+
for (const f in l.inputs) {
|
|
749
|
+
const m = l.inputs[f];
|
|
750
|
+
s[m.id] && (u[f] = m);
|
|
696
751
|
}
|
|
697
752
|
const h = Object.assign({}, l);
|
|
698
753
|
h.inputs = u, h.outputs = l.outputs, i.push(h);
|
|
@@ -700,11 +755,11 @@ function on(n, t, e) {
|
|
|
700
755
|
}
|
|
701
756
|
return i;
|
|
702
757
|
}
|
|
703
|
-
function
|
|
758
|
+
function un(e, t, n, s) {
|
|
704
759
|
for (let r = t.length - 1; r >= 0; r--) {
|
|
705
760
|
const a = t[r], o = [];
|
|
706
761
|
if (a.outputs.forEach((c) => {
|
|
707
|
-
const l =
|
|
762
|
+
const l = e[c.id];
|
|
708
763
|
l != null ? o.push(l) : o.push(null);
|
|
709
764
|
}), a.gradient == null)
|
|
710
765
|
throw new Error(`Cannot compute gradient: gradient function not found for ${a.kernelName}.`);
|
|
@@ -712,17 +767,17 @@ function cn(n, t, e, s) {
|
|
|
712
767
|
for (const c in a.inputs) {
|
|
713
768
|
if (!(c in i))
|
|
714
769
|
throw new Error(`Cannot backprop through input ${c}. Available gradients found: ${Object.keys(i)}.`);
|
|
715
|
-
const l =
|
|
770
|
+
const l = n(() => i[c]());
|
|
716
771
|
if (l.dtype !== "float32")
|
|
717
772
|
throw new Error(`Error in gradient for op ${a.kernelName}. The gradient of input ${c} must have 'float32' dtype, but has '${l.dtype}'`);
|
|
718
773
|
const u = a.inputs[c];
|
|
719
|
-
if (!
|
|
774
|
+
if (!Rt(l.shape, u.shape))
|
|
720
775
|
throw new Error(`Error in gradient for op ${a.kernelName}. The gradient of input '${c}' has shape '${l.shape}', which does not match the shape of the input '${u.shape}'`);
|
|
721
|
-
if (
|
|
722
|
-
|
|
776
|
+
if (e[u.id] == null)
|
|
777
|
+
e[u.id] = l;
|
|
723
778
|
else {
|
|
724
|
-
const h =
|
|
725
|
-
|
|
779
|
+
const h = e[u.id];
|
|
780
|
+
e[u.id] = s(h, l), h.dispose();
|
|
726
781
|
}
|
|
727
782
|
}
|
|
728
783
|
}
|
|
@@ -743,106 +798,106 @@ function cn(n, t, e, s) {
|
|
|
743
798
|
* limitations under the License.
|
|
744
799
|
* =============================================================================
|
|
745
800
|
*/
|
|
746
|
-
const
|
|
747
|
-
function
|
|
748
|
-
const r = $t(t), a =
|
|
749
|
-
return s && (c.push(` dtype: ${
|
|
801
|
+
const Kt = 20, at = 3, bt = 7;
|
|
802
|
+
function hn(e, t, n, s) {
|
|
803
|
+
const r = $t(t), a = fn(e, t, n, r), o = t.length, i = ut(e, t, n, r, a), c = ["Tensor"];
|
|
804
|
+
return s && (c.push(` dtype: ${n}`), c.push(` rank: ${o}`), c.push(` shape: [${t}]`), c.push(" values:")), c.push(i.map((l) => " " + l).join(`
|
|
750
805
|
`)), c.join(`
|
|
751
806
|
`);
|
|
752
807
|
}
|
|
753
|
-
function
|
|
754
|
-
const r = z(t), a = s[s.length - 1], o = new Array(a).fill(0), i = t.length, c =
|
|
808
|
+
function fn(e, t, n, s) {
|
|
809
|
+
const r = z(t), a = s[s.length - 1], o = new Array(a).fill(0), i = t.length, c = n === "complex64" ? it(e) : e;
|
|
755
810
|
if (i > 1)
|
|
756
811
|
for (let l = 0; l < r / a; l++) {
|
|
757
812
|
const u = l * a;
|
|
758
813
|
for (let h = 0; h < a; h++)
|
|
759
|
-
o[h] = Math.max(o[h], ot(c[u + h], 0,
|
|
814
|
+
o[h] = Math.max(o[h], ot(c[u + h], 0, n).length);
|
|
760
815
|
}
|
|
761
816
|
return o;
|
|
762
817
|
}
|
|
763
|
-
function ot(
|
|
818
|
+
function ot(e, t, n) {
|
|
764
819
|
let s;
|
|
765
|
-
return Array.isArray(
|
|
820
|
+
return Array.isArray(e) ? s = `${parseFloat(e[0].toFixed(bt))} + ${parseFloat(e[1].toFixed(bt))}j` : Dt(e) ? s = `'${e}'` : n === "bool" ? s = he(e) : s = parseFloat(e.toFixed(bt)).toString(), lt(s, t);
|
|
766
821
|
}
|
|
767
|
-
function
|
|
768
|
-
return
|
|
822
|
+
function he(e) {
|
|
823
|
+
return e === 0 ? "false" : "true";
|
|
769
824
|
}
|
|
770
|
-
function ut(
|
|
771
|
-
const o =
|
|
825
|
+
function ut(e, t, n, s, r, a = !0) {
|
|
826
|
+
const o = n === "complex64" ? 2 : 1, i = t[0], c = t.length;
|
|
772
827
|
if (c === 0) {
|
|
773
|
-
if (
|
|
774
|
-
const
|
|
775
|
-
return [ot(
|
|
828
|
+
if (n === "complex64") {
|
|
829
|
+
const d = it(e);
|
|
830
|
+
return [ot(d[0], 0, n)];
|
|
776
831
|
}
|
|
777
|
-
return
|
|
832
|
+
return n === "bool" ? [he(e[0])] : [e[0].toString()];
|
|
778
833
|
}
|
|
779
834
|
if (c === 1) {
|
|
780
|
-
if (i >
|
|
835
|
+
if (i > Kt) {
|
|
781
836
|
const w = at * o;
|
|
782
|
-
let I = Array.from(
|
|
783
|
-
return
|
|
784
|
-
"[" + I.map((J, X) => ot(J, r[X],
|
|
837
|
+
let I = Array.from(e.slice(0, w)), _ = Array.from(e.slice((i - at) * o, i * o));
|
|
838
|
+
return n === "complex64" && (I = it(I), _ = it(_)), [
|
|
839
|
+
"[" + I.map((J, X) => ot(J, r[X], n)).join(", ") + ", ..., " + _.map((J, X) => ot(J, r[i - at + X], n)).join(", ") + "]"
|
|
785
840
|
];
|
|
786
841
|
}
|
|
787
842
|
return [
|
|
788
|
-
"[" + (
|
|
843
|
+
"[" + (n === "complex64" ? it(e) : Array.from(e)).map((w, I) => ot(w, r[I], n)).join(", ") + "]"
|
|
789
844
|
];
|
|
790
845
|
}
|
|
791
|
-
const l = t.slice(1), u = s.slice(1), h = s[0] * o,
|
|
792
|
-
if (i >
|
|
793
|
-
for (let
|
|
794
|
-
const w =
|
|
795
|
-
|
|
796
|
-
|
|
846
|
+
const l = t.slice(1), u = s.slice(1), h = s[0] * o, f = [];
|
|
847
|
+
if (i > Kt) {
|
|
848
|
+
for (let d = 0; d < at; d++) {
|
|
849
|
+
const w = d * h, I = w + h;
|
|
850
|
+
f.push(...ut(
|
|
851
|
+
e.slice(w, I),
|
|
797
852
|
l,
|
|
798
|
-
|
|
853
|
+
n,
|
|
799
854
|
u,
|
|
800
855
|
r,
|
|
801
856
|
!1
|
|
802
857
|
/* isLast */
|
|
803
858
|
));
|
|
804
859
|
}
|
|
805
|
-
|
|
806
|
-
for (let
|
|
807
|
-
const w =
|
|
808
|
-
|
|
809
|
-
|
|
860
|
+
f.push("...");
|
|
861
|
+
for (let d = i - at; d < i; d++) {
|
|
862
|
+
const w = d * h, I = w + h;
|
|
863
|
+
f.push(...ut(
|
|
864
|
+
e.slice(w, I),
|
|
810
865
|
l,
|
|
811
|
-
|
|
866
|
+
n,
|
|
812
867
|
u,
|
|
813
868
|
r,
|
|
814
|
-
|
|
869
|
+
d === i - 1
|
|
815
870
|
/* isLast */
|
|
816
871
|
));
|
|
817
872
|
}
|
|
818
873
|
} else
|
|
819
|
-
for (let
|
|
820
|
-
const w =
|
|
821
|
-
|
|
822
|
-
|
|
874
|
+
for (let d = 0; d < i; d++) {
|
|
875
|
+
const w = d * h, I = w + h;
|
|
876
|
+
f.push(...ut(
|
|
877
|
+
e.slice(w, I),
|
|
823
878
|
l,
|
|
824
|
-
|
|
879
|
+
n,
|
|
825
880
|
u,
|
|
826
881
|
r,
|
|
827
|
-
|
|
882
|
+
d === i - 1
|
|
828
883
|
/* isLast */
|
|
829
884
|
));
|
|
830
885
|
}
|
|
831
886
|
const m = c === 2 ? "," : "";
|
|
832
|
-
|
|
833
|
-
for (let
|
|
834
|
-
d
|
|
887
|
+
f[0] = "[" + (i > 0 ? f[0] + m : "");
|
|
888
|
+
for (let d = 1; d < f.length - 1; d++)
|
|
889
|
+
f[d] = " " + f[d] + m;
|
|
835
890
|
let p = `,
|
|
836
891
|
`;
|
|
837
|
-
for (let
|
|
892
|
+
for (let d = 2; d < c; d++)
|
|
838
893
|
p += `
|
|
839
894
|
`;
|
|
840
|
-
return
|
|
895
|
+
return f[f.length - 1] = " " + f[f.length - 1] + "]" + (a ? "" : p), f;
|
|
841
896
|
}
|
|
842
|
-
function it(
|
|
897
|
+
function it(e) {
|
|
843
898
|
const t = [];
|
|
844
|
-
for (let
|
|
845
|
-
t.push([n
|
|
899
|
+
for (let n = 0; n < e.length; n += 2)
|
|
900
|
+
t.push([e[n], e[n + 1]]);
|
|
846
901
|
return t;
|
|
847
902
|
}
|
|
848
903
|
/**
|
|
@@ -861,15 +916,15 @@ function it(n) {
|
|
|
861
916
|
* limitations under the License.
|
|
862
917
|
* =============================================================================
|
|
863
918
|
*/
|
|
864
|
-
class
|
|
865
|
-
constructor(t,
|
|
866
|
-
if (this.dtype =
|
|
919
|
+
class dn {
|
|
920
|
+
constructor(t, n, s) {
|
|
921
|
+
if (this.dtype = n, this.shape = t.slice(), this.size = z(t), s != null) {
|
|
867
922
|
const r = s.length;
|
|
868
923
|
y(r === this.size, () => `Length of values '${r}' does not match the size inferred by the shape '${this.size}'.`);
|
|
869
924
|
}
|
|
870
|
-
if (
|
|
925
|
+
if (n === "complex64")
|
|
871
926
|
throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");
|
|
872
|
-
this.values = s ||
|
|
927
|
+
this.values = s || te(n, this.size), this.strides = $t(t);
|
|
873
928
|
}
|
|
874
929
|
/**
|
|
875
930
|
* Sets a value in the buffer at a given location.
|
|
@@ -879,9 +934,9 @@ class hn {
|
|
|
879
934
|
*
|
|
880
935
|
* @doc {heading: 'Tensors', subheading: 'Creation'}
|
|
881
936
|
*/
|
|
882
|
-
set(t, ...
|
|
883
|
-
|
|
884
|
-
const s = this.locToIndex(
|
|
937
|
+
set(t, ...n) {
|
|
938
|
+
n.length === 0 && (n = [0]), y(n.length === this.rank, () => `The number of provided coordinates (${n.length}) must match the rank (${this.rank})`);
|
|
939
|
+
const s = this.locToIndex(n);
|
|
885
940
|
this.values[s] = t;
|
|
886
941
|
}
|
|
887
942
|
/**
|
|
@@ -893,13 +948,13 @@ class hn {
|
|
|
893
948
|
*/
|
|
894
949
|
get(...t) {
|
|
895
950
|
t.length === 0 && (t = [0]);
|
|
896
|
-
let
|
|
951
|
+
let n = 0;
|
|
897
952
|
for (const r of t) {
|
|
898
|
-
if (r < 0 || r >= this.shape[
|
|
953
|
+
if (r < 0 || r >= this.shape[n]) {
|
|
899
954
|
const a = `Requested out of range element at ${t}. Buffer shape=${this.shape}`;
|
|
900
955
|
throw new Error(a);
|
|
901
956
|
}
|
|
902
|
-
|
|
957
|
+
n++;
|
|
903
958
|
}
|
|
904
959
|
let s = t[t.length - 1];
|
|
905
960
|
for (let r = 0; r < t.length - 1; ++r)
|
|
@@ -911,20 +966,20 @@ class hn {
|
|
|
911
966
|
return 0;
|
|
912
967
|
if (this.rank === 1)
|
|
913
968
|
return t[0];
|
|
914
|
-
let
|
|
969
|
+
let n = t[t.length - 1];
|
|
915
970
|
for (let s = 0; s < t.length - 1; ++s)
|
|
916
|
-
|
|
917
|
-
return
|
|
971
|
+
n += this.strides[s] * t[s];
|
|
972
|
+
return n;
|
|
918
973
|
}
|
|
919
974
|
indexToLoc(t) {
|
|
920
975
|
if (this.rank === 0)
|
|
921
976
|
return [];
|
|
922
977
|
if (this.rank === 1)
|
|
923
978
|
return [t];
|
|
924
|
-
const
|
|
925
|
-
for (let s = 0; s <
|
|
926
|
-
|
|
927
|
-
return
|
|
979
|
+
const n = new Array(this.shape.length);
|
|
980
|
+
for (let s = 0; s < n.length - 1; ++s)
|
|
981
|
+
n[s] = Math.floor(t / this.strides[s]), t -= n[s] * this.strides[s];
|
|
982
|
+
return n[n.length - 1] = t, n;
|
|
928
983
|
}
|
|
929
984
|
get rank() {
|
|
930
985
|
return this.shape.length;
|
|
@@ -935,19 +990,19 @@ class hn {
|
|
|
935
990
|
* @doc {heading: 'Tensors', subheading: 'Creation'}
|
|
936
991
|
*/
|
|
937
992
|
toTensor() {
|
|
938
|
-
return
|
|
993
|
+
return R().makeTensor(this.values, this.shape, this.dtype);
|
|
939
994
|
}
|
|
940
995
|
}
|
|
941
|
-
let
|
|
942
|
-
function
|
|
943
|
-
|
|
996
|
+
let R = null, Y = null;
|
|
997
|
+
function gn(e) {
|
|
998
|
+
R = e;
|
|
944
999
|
}
|
|
945
|
-
function
|
|
946
|
-
Y =
|
|
1000
|
+
function mn(e) {
|
|
1001
|
+
Y = e;
|
|
947
1002
|
}
|
|
948
1003
|
class D {
|
|
949
|
-
constructor(t,
|
|
950
|
-
this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype =
|
|
1004
|
+
constructor(t, n, s, r) {
|
|
1005
|
+
this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype = n || "float32", this.size = z(t), this.strides = $t(t), this.dataId = s, this.id = r, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
|
|
951
1006
|
}
|
|
952
1007
|
get rank() {
|
|
953
1008
|
return this.shape.length;
|
|
@@ -976,7 +1031,7 @@ class D {
|
|
|
976
1031
|
*/
|
|
977
1032
|
async array() {
|
|
978
1033
|
const t = await this.data();
|
|
979
|
-
return
|
|
1034
|
+
return Gt(this.shape, t, this.dtype === "complex64");
|
|
980
1035
|
}
|
|
981
1036
|
/**
|
|
982
1037
|
* Returns the tensor data as a nested array. The transfer of data is done
|
|
@@ -985,7 +1040,7 @@ class D {
|
|
|
985
1040
|
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
986
1041
|
*/
|
|
987
1042
|
arraySync() {
|
|
988
|
-
return
|
|
1043
|
+
return Gt(this.shape, this.dataSync(), this.dtype === "complex64");
|
|
989
1044
|
}
|
|
990
1045
|
/**
|
|
991
1046
|
* Asynchronously downloads the values from the `tf.Tensor`. Returns a
|
|
@@ -995,11 +1050,11 @@ class D {
|
|
|
995
1050
|
*/
|
|
996
1051
|
async data() {
|
|
997
1052
|
this.throwIfDisposed();
|
|
998
|
-
const t =
|
|
1053
|
+
const t = R().read(this.dataId);
|
|
999
1054
|
if (this.dtype === "string") {
|
|
1000
|
-
const
|
|
1055
|
+
const n = await t;
|
|
1001
1056
|
try {
|
|
1002
|
-
return
|
|
1057
|
+
return n.map((s) => jt(s));
|
|
1003
1058
|
} catch {
|
|
1004
1059
|
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
|
|
1005
1060
|
}
|
|
@@ -1041,7 +1096,7 @@ class D {
|
|
|
1041
1096
|
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1042
1097
|
*/
|
|
1043
1098
|
dataToGPU(t) {
|
|
1044
|
-
return this.throwIfDisposed(),
|
|
1099
|
+
return this.throwIfDisposed(), R().readToGPU(this.dataId, t);
|
|
1045
1100
|
}
|
|
1046
1101
|
/**
|
|
1047
1102
|
* Synchronously downloads the values from the `tf.Tensor`. This blocks the
|
|
@@ -1051,10 +1106,10 @@ class D {
|
|
|
1051
1106
|
*/
|
|
1052
1107
|
dataSync() {
|
|
1053
1108
|
this.throwIfDisposed();
|
|
1054
|
-
const t =
|
|
1109
|
+
const t = R().readSync(this.dataId);
|
|
1055
1110
|
if (this.dtype === "string")
|
|
1056
1111
|
try {
|
|
1057
|
-
return t.map((
|
|
1112
|
+
return t.map((n) => jt(n));
|
|
1058
1113
|
} catch {
|
|
1059
1114
|
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
|
|
1060
1115
|
}
|
|
@@ -1063,7 +1118,7 @@ class D {
|
|
|
1063
1118
|
/** Returns the underlying bytes of the tensor's data. */
|
|
1064
1119
|
async bytes() {
|
|
1065
1120
|
this.throwIfDisposed();
|
|
1066
|
-
const t = await
|
|
1121
|
+
const t = await R().read(this.dataId);
|
|
1067
1122
|
return this.dtype === "string" ? t : new Uint8Array(t.buffer);
|
|
1068
1123
|
}
|
|
1069
1124
|
/**
|
|
@@ -1072,7 +1127,7 @@ class D {
|
|
|
1072
1127
|
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1073
1128
|
*/
|
|
1074
1129
|
dispose() {
|
|
1075
|
-
this.isDisposed || (this.kerasMask && this.kerasMask.dispose(),
|
|
1130
|
+
this.isDisposed || (this.kerasMask && this.kerasMask.dispose(), R().disposeTensor(this), this.isDisposedInternal = !0);
|
|
1076
1131
|
}
|
|
1077
1132
|
get isDisposed() {
|
|
1078
1133
|
return this.isDisposedInternal;
|
|
@@ -1105,26 +1160,26 @@ class D {
|
|
|
1105
1160
|
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1106
1161
|
*/
|
|
1107
1162
|
toString(t = !1) {
|
|
1108
|
-
const
|
|
1109
|
-
return
|
|
1163
|
+
const n = this.dataSync();
|
|
1164
|
+
return hn(n, this.shape, this.dtype, t);
|
|
1110
1165
|
}
|
|
1111
1166
|
cast(t) {
|
|
1112
1167
|
return this.throwIfDisposed(), Y.cast(this, t);
|
|
1113
1168
|
}
|
|
1114
|
-
variable(t = !0,
|
|
1115
|
-
return this.throwIfDisposed(),
|
|
1169
|
+
variable(t = !0, n, s) {
|
|
1170
|
+
return this.throwIfDisposed(), R().makeVariable(this, t, n, s);
|
|
1116
1171
|
}
|
|
1117
1172
|
}
|
|
1118
1173
|
Object.defineProperty(D, Symbol.hasInstance, {
|
|
1119
|
-
value: (
|
|
1174
|
+
value: (e) => !!e && e.data != null && e.dataSync != null && e.throwIfDisposed != null
|
|
1120
1175
|
});
|
|
1121
|
-
function
|
|
1176
|
+
function fe() {
|
|
1122
1177
|
return Pt("Tensor", () => D);
|
|
1123
1178
|
}
|
|
1124
|
-
|
|
1125
|
-
class
|
|
1126
|
-
constructor(t,
|
|
1127
|
-
super(t.shape, t.dtype, t.dataId, r), this.trainable =
|
|
1179
|
+
fe();
|
|
1180
|
+
class gt extends D {
|
|
1181
|
+
constructor(t, n, s, r) {
|
|
1182
|
+
super(t.shape, t.dtype, t.dataId, r), this.trainable = n, this.name = s;
|
|
1128
1183
|
}
|
|
1129
1184
|
/**
|
|
1130
1185
|
* Assign a new `tf.Tensor` to this variable. The new `tf.Tensor` must have
|
|
@@ -1137,20 +1192,20 @@ class ft extends D {
|
|
|
1137
1192
|
assign(t) {
|
|
1138
1193
|
if (t.dtype !== this.dtype)
|
|
1139
1194
|
throw new Error(`dtype of the new value (${t.dtype}) and previous value (${this.dtype}) must match`);
|
|
1140
|
-
if (!
|
|
1195
|
+
if (!Rt(t.shape, this.shape))
|
|
1141
1196
|
throw new Error(`shape of the new value (${t.shape}) and previous value (${this.shape}) must match`);
|
|
1142
|
-
|
|
1197
|
+
R().disposeTensor(this), this.dataId = t.dataId, R().incRef(
|
|
1143
1198
|
this,
|
|
1144
1199
|
null
|
|
1145
1200
|
/* backend */
|
|
1146
1201
|
);
|
|
1147
1202
|
}
|
|
1148
1203
|
dispose() {
|
|
1149
|
-
|
|
1204
|
+
R().disposeVariable(this), this.isDisposedInternal = !0;
|
|
1150
1205
|
}
|
|
1151
1206
|
}
|
|
1152
|
-
Object.defineProperty(
|
|
1153
|
-
value: (
|
|
1207
|
+
Object.defineProperty(gt, Symbol.hasInstance, {
|
|
1208
|
+
value: (e) => e instanceof D && e.assign != null && e.assign instanceof Function
|
|
1154
1209
|
});
|
|
1155
1210
|
/**
|
|
1156
1211
|
* @license
|
|
@@ -1168,45 +1223,48 @@ Object.defineProperty(ft, Symbol.hasInstance, {
|
|
|
1168
1223
|
* limitations under the License.
|
|
1169
1224
|
* =============================================================================
|
|
1170
1225
|
*/
|
|
1171
|
-
var
|
|
1172
|
-
(function(
|
|
1173
|
-
|
|
1174
|
-
})(
|
|
1226
|
+
var qt;
|
|
1227
|
+
(function(e) {
|
|
1228
|
+
e.R0 = "R0", e.R1 = "R1", e.R2 = "R2", e.R3 = "R3", e.R4 = "R4", e.R5 = "R5", e.R6 = "R6";
|
|
1229
|
+
})(qt || (qt = {}));
|
|
1175
1230
|
var Tt;
|
|
1176
|
-
(function(
|
|
1177
|
-
|
|
1231
|
+
(function(e) {
|
|
1232
|
+
e.float32 = "float32", e.int32 = "int32", e.bool = "int32", e.complex64 = "complex64";
|
|
1178
1233
|
})(Tt || (Tt = {}));
|
|
1179
1234
|
var Et;
|
|
1180
|
-
(function(
|
|
1181
|
-
|
|
1235
|
+
(function(e) {
|
|
1236
|
+
e.float32 = "float32", e.int32 = "int32", e.bool = "bool", e.complex64 = "complex64";
|
|
1182
1237
|
})(Et || (Et = {}));
|
|
1183
1238
|
var At;
|
|
1184
|
-
(function(
|
|
1185
|
-
|
|
1239
|
+
(function(e) {
|
|
1240
|
+
e.float32 = "float32", e.int32 = "float32", e.bool = "float32", e.complex64 = "complex64";
|
|
1186
1241
|
})(At || (At = {}));
|
|
1187
1242
|
var Bt;
|
|
1188
|
-
(function(
|
|
1189
|
-
|
|
1243
|
+
(function(e) {
|
|
1244
|
+
e.float32 = "complex64", e.int32 = "complex64", e.bool = "complex64", e.complex64 = "complex64";
|
|
1190
1245
|
})(Bt || (Bt = {}));
|
|
1191
|
-
const
|
|
1246
|
+
const pn = {
|
|
1192
1247
|
float32: At,
|
|
1193
1248
|
int32: Tt,
|
|
1194
1249
|
bool: Et,
|
|
1195
1250
|
complex64: Bt
|
|
1196
1251
|
};
|
|
1197
|
-
function
|
|
1198
|
-
if (
|
|
1199
|
-
if (
|
|
1252
|
+
function de(e, t) {
|
|
1253
|
+
if (e === "string" || t === "string") {
|
|
1254
|
+
if (e === "string" && t === "string")
|
|
1200
1255
|
return "string";
|
|
1201
|
-
throw new Error(`Can not upcast ${
|
|
1256
|
+
throw new Error(`Can not upcast ${e} with ${t}`);
|
|
1202
1257
|
}
|
|
1203
|
-
return
|
|
1258
|
+
return pn[e][t];
|
|
1259
|
+
}
|
|
1260
|
+
function ho(e) {
|
|
1261
|
+
return de(e, "int32");
|
|
1204
1262
|
}
|
|
1205
|
-
function
|
|
1206
|
-
return
|
|
1263
|
+
function ge(e) {
|
|
1264
|
+
return e != null && typeof e == "object" && "texture" in e && e.texture instanceof WebGLTexture;
|
|
1207
1265
|
}
|
|
1208
|
-
function
|
|
1209
|
-
return typeof GPUBuffer < "u" &&
|
|
1266
|
+
function me(e) {
|
|
1267
|
+
return typeof GPUBuffer < "u" && e != null && typeof e == "object" && "buffer" in e && e.buffer instanceof GPUBuffer;
|
|
1210
1268
|
}
|
|
1211
1269
|
/**
|
|
1212
1270
|
* @license
|
|
@@ -1224,36 +1282,36 @@ function de(n) {
|
|
|
1224
1282
|
* limitations under the License.
|
|
1225
1283
|
* =============================================================================
|
|
1226
1284
|
*/
|
|
1227
|
-
function q(
|
|
1228
|
-
if (
|
|
1229
|
-
return [
|
|
1230
|
-
const
|
|
1231
|
-
return [
|
|
1285
|
+
function q(e, t) {
|
|
1286
|
+
if (e.dtype === t.dtype)
|
|
1287
|
+
return [e, t];
|
|
1288
|
+
const n = de(e.dtype, t.dtype);
|
|
1289
|
+
return [e.cast(n), t.cast(n)];
|
|
1232
1290
|
}
|
|
1233
|
-
function
|
|
1234
|
-
return t.some((
|
|
1291
|
+
function fo(e, t) {
|
|
1292
|
+
return t.some((n) => n.id === e.id);
|
|
1235
1293
|
}
|
|
1236
|
-
function
|
|
1294
|
+
function pe(e) {
|
|
1237
1295
|
const t = [];
|
|
1238
|
-
return
|
|
1296
|
+
return ye(e, t, /* @__PURE__ */ new Set()), t;
|
|
1239
1297
|
}
|
|
1240
|
-
function
|
|
1241
|
-
if (
|
|
1298
|
+
function ye(e, t, n) {
|
|
1299
|
+
if (e == null)
|
|
1242
1300
|
return;
|
|
1243
|
-
if (
|
|
1244
|
-
t.push(
|
|
1301
|
+
if (e instanceof D) {
|
|
1302
|
+
t.push(e);
|
|
1245
1303
|
return;
|
|
1246
1304
|
}
|
|
1247
|
-
if (!
|
|
1305
|
+
if (!yn(e))
|
|
1248
1306
|
return;
|
|
1249
|
-
const s =
|
|
1307
|
+
const s = e;
|
|
1250
1308
|
for (const r in s) {
|
|
1251
1309
|
const a = s[r];
|
|
1252
|
-
|
|
1310
|
+
n.has(a) || (n.add(a), ye(a, t, n));
|
|
1253
1311
|
}
|
|
1254
1312
|
}
|
|
1255
|
-
function
|
|
1256
|
-
return Array.isArray(
|
|
1313
|
+
function yn(e) {
|
|
1314
|
+
return Array.isArray(e) || typeof e == "object";
|
|
1257
1315
|
}
|
|
1258
1316
|
/**
|
|
1259
1317
|
* @license
|
|
@@ -1271,10 +1329,10 @@ function pn(n) {
|
|
|
1271
1329
|
* limitations under the License.
|
|
1272
1330
|
* =============================================================================
|
|
1273
1331
|
*/
|
|
1274
|
-
function
|
|
1275
|
-
return
|
|
1332
|
+
function wt(e) {
|
|
1333
|
+
return e.kernelName != null;
|
|
1276
1334
|
}
|
|
1277
|
-
class
|
|
1335
|
+
class Ht {
|
|
1278
1336
|
constructor() {
|
|
1279
1337
|
this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = /* @__PURE__ */ new WeakMap(), this.profiling = !1, this.activeProfile = {
|
|
1280
1338
|
newBytes: 0,
|
|
@@ -1294,7 +1352,7 @@ class qt {
|
|
|
1294
1352
|
}
|
|
1295
1353
|
class et {
|
|
1296
1354
|
constructor(t) {
|
|
1297
|
-
this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new
|
|
1355
|
+
this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new Ht();
|
|
1298
1356
|
}
|
|
1299
1357
|
async ready() {
|
|
1300
1358
|
if (this.pendingBackendInit != null)
|
|
@@ -1303,8 +1361,8 @@ class et {
|
|
|
1303
1361
|
if (this.backendInstance != null)
|
|
1304
1362
|
return;
|
|
1305
1363
|
const t = this.getSortedBackends();
|
|
1306
|
-
for (let
|
|
1307
|
-
const s = t[
|
|
1364
|
+
for (let n = 0; n < t.length; n++) {
|
|
1365
|
+
const s = t[n];
|
|
1308
1366
|
if (await this.initializeBackend(s).success) {
|
|
1309
1367
|
await this.setBackend(s);
|
|
1310
1368
|
return;
|
|
@@ -1316,8 +1374,8 @@ class et {
|
|
|
1316
1374
|
if (this.pendingBackendInit != null)
|
|
1317
1375
|
throw new Error(`Backend '${this.backendName}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);
|
|
1318
1376
|
if (this.backendInstance == null) {
|
|
1319
|
-
const { name: t, asyncInit:
|
|
1320
|
-
if (
|
|
1377
|
+
const { name: t, asyncInit: n } = this.initializeBackendsAndReturnBest();
|
|
1378
|
+
if (n)
|
|
1321
1379
|
throw new Error(`The highest priority backend '${t}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);
|
|
1322
1380
|
this.setBackend(t);
|
|
1323
1381
|
}
|
|
@@ -1329,8 +1387,8 @@ class et {
|
|
|
1329
1387
|
findBackend(t) {
|
|
1330
1388
|
if (!(t in this.registry))
|
|
1331
1389
|
if (t in this.registryFactory) {
|
|
1332
|
-
const { asyncInit:
|
|
1333
|
-
if (
|
|
1390
|
+
const { asyncInit: n } = this.initializeBackend(t);
|
|
1391
|
+
if (n)
|
|
1334
1392
|
return null;
|
|
1335
1393
|
} else
|
|
1336
1394
|
return null;
|
|
@@ -1339,27 +1397,27 @@ class et {
|
|
|
1339
1397
|
findBackendFactory(t) {
|
|
1340
1398
|
return t in this.registryFactory ? this.registryFactory[t].factory : null;
|
|
1341
1399
|
}
|
|
1342
|
-
registerBackend(t,
|
|
1343
|
-
return t in this.registryFactory ? (
|
|
1400
|
+
registerBackend(t, n, s = 1) {
|
|
1401
|
+
return t in this.registryFactory ? (O(`${t} backend was already registered. Reusing existing backend factory.`), !1) : (this.registryFactory[t] = { factory: n, priority: s }, !0);
|
|
1344
1402
|
}
|
|
1345
1403
|
async setBackend(t) {
|
|
1346
1404
|
if (this.registryFactory[t] == null)
|
|
1347
1405
|
throw new Error(`Backend name '${t}' not found in registry`);
|
|
1348
1406
|
if (this.backendName = t, this.registry[t] == null) {
|
|
1349
1407
|
this.backendInstance = null;
|
|
1350
|
-
const { success:
|
|
1351
|
-
if (!(s ? await
|
|
1408
|
+
const { success: n, asyncInit: s } = this.initializeBackend(t);
|
|
1409
|
+
if (!(s ? await n : n))
|
|
1352
1410
|
return !1;
|
|
1353
1411
|
}
|
|
1354
|
-
return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new
|
|
1412
|
+
return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new an(this.backendInstance), !0;
|
|
1355
1413
|
}
|
|
1356
1414
|
setupRegisteredKernels() {
|
|
1357
|
-
|
|
1358
|
-
|
|
1415
|
+
Wt(this.backendName).forEach((n) => {
|
|
1416
|
+
n.setupFunc != null && n.setupFunc(this.backendInstance);
|
|
1359
1417
|
});
|
|
1360
1418
|
}
|
|
1361
1419
|
disposeRegisteredKernels(t) {
|
|
1362
|
-
|
|
1420
|
+
Wt(t).forEach((s) => {
|
|
1363
1421
|
s.disposeFunc != null && s.disposeFunc(this.registry[t]);
|
|
1364
1422
|
});
|
|
1365
1423
|
}
|
|
@@ -1370,18 +1428,18 @@ class et {
|
|
|
1370
1428
|
* there is no backend in the factory registry.
|
|
1371
1429
|
*/
|
|
1372
1430
|
initializeBackend(t) {
|
|
1373
|
-
const
|
|
1374
|
-
if (
|
|
1431
|
+
const n = this.registryFactory[t];
|
|
1432
|
+
if (n == null)
|
|
1375
1433
|
throw new Error(`Cannot initialize backend ${t}, no registration found.`);
|
|
1376
1434
|
try {
|
|
1377
|
-
const s =
|
|
1378
|
-
if (s && !(s instanceof
|
|
1379
|
-
const r = ++this.pendingBackendInitId, a = s.then((o) => r < this.pendingBackendInitId ? !1 : (this.registry[t] = o, this.pendingBackendInit = null, !0)).catch((o) => (r < this.pendingBackendInitId || (this.pendingBackendInit = null,
|
|
1435
|
+
const s = n.factory();
|
|
1436
|
+
if (s && !(s instanceof Fe) && typeof s.then == "function") {
|
|
1437
|
+
const r = ++this.pendingBackendInitId, a = s.then((o) => r < this.pendingBackendInitId ? !1 : (this.registry[t] = o, this.pendingBackendInit = null, !0)).catch((o) => (r < this.pendingBackendInitId || (this.pendingBackendInit = null, O(`Initialization of backend ${t} failed`), O(o.stack || o.message)), !1));
|
|
1380
1438
|
return this.pendingBackendInit = a, { success: a, asyncInit: !0 };
|
|
1381
1439
|
} else
|
|
1382
1440
|
return this.registry[t] = s, { success: !0, asyncInit: !1 };
|
|
1383
1441
|
} catch (s) {
|
|
1384
|
-
return
|
|
1442
|
+
return O(`Initialization of backend ${t} failed`), O(s.stack || s.message), { success: !1, asyncInit: !1 };
|
|
1385
1443
|
}
|
|
1386
1444
|
}
|
|
1387
1445
|
removeBackend(t) {
|
|
@@ -1392,44 +1450,44 @@ class et {
|
|
|
1392
1450
|
getSortedBackends() {
|
|
1393
1451
|
if (Object.keys(this.registryFactory).length === 0)
|
|
1394
1452
|
throw new Error("No backend found in registry.");
|
|
1395
|
-
return Object.keys(this.registryFactory).sort((t,
|
|
1453
|
+
return Object.keys(this.registryFactory).sort((t, n) => this.registryFactory[n].priority - this.registryFactory[t].priority);
|
|
1396
1454
|
}
|
|
1397
1455
|
initializeBackendsAndReturnBest() {
|
|
1398
1456
|
const t = this.getSortedBackends();
|
|
1399
|
-
for (let
|
|
1400
|
-
const s = t[
|
|
1457
|
+
for (let n = 0; n < t.length; n++) {
|
|
1458
|
+
const s = t[n], { success: r, asyncInit: a } = this.initializeBackend(s);
|
|
1401
1459
|
if (a || r)
|
|
1402
1460
|
return { name: s, asyncInit: a };
|
|
1403
1461
|
}
|
|
1404
1462
|
throw new Error("Could not initialize any backends, all backend initializations failed.");
|
|
1405
1463
|
}
|
|
1406
|
-
moveData(t,
|
|
1407
|
-
const s = this.state.tensorInfo.get(
|
|
1408
|
-
r.disposeData(
|
|
1464
|
+
moveData(t, n) {
|
|
1465
|
+
const s = this.state.tensorInfo.get(n), r = s.backend, a = this.readSync(n), o = r.refCount(n);
|
|
1466
|
+
r.disposeData(n, !0), s.backend = t, t.move(n, a, s.shape, s.dtype, o), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++;
|
|
1409
1467
|
}
|
|
1410
|
-
tidy(t,
|
|
1468
|
+
tidy(t, n) {
|
|
1411
1469
|
let s = null;
|
|
1412
|
-
if (
|
|
1470
|
+
if (n == null) {
|
|
1413
1471
|
if (typeof t != "function")
|
|
1414
1472
|
throw new Error("Please provide a function to tidy()");
|
|
1415
|
-
|
|
1473
|
+
n = t;
|
|
1416
1474
|
} else {
|
|
1417
1475
|
if (typeof t != "string" && !(t instanceof String))
|
|
1418
1476
|
throw new Error("When calling with two arguments, the first argument to tidy() must be a string");
|
|
1419
|
-
if (typeof
|
|
1477
|
+
if (typeof n != "function")
|
|
1420
1478
|
throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");
|
|
1421
1479
|
s = t;
|
|
1422
1480
|
}
|
|
1423
1481
|
let r;
|
|
1424
|
-
return this.scopedRun(() => this.startScope(s), () => this.endScope(r), () => (r =
|
|
1482
|
+
return this.scopedRun(() => this.startScope(s), () => this.endScope(r), () => (r = n(), r instanceof Promise && console.error("Cannot return a Promise inside of tidy."), r));
|
|
1425
1483
|
}
|
|
1426
|
-
scopedRun(t,
|
|
1484
|
+
scopedRun(t, n, s) {
|
|
1427
1485
|
t();
|
|
1428
1486
|
try {
|
|
1429
1487
|
const r = s();
|
|
1430
|
-
return
|
|
1488
|
+
return n(), r;
|
|
1431
1489
|
} catch (r) {
|
|
1432
|
-
throw
|
|
1490
|
+
throw n(), r;
|
|
1433
1491
|
}
|
|
1434
1492
|
}
|
|
1435
1493
|
nextTensorId() {
|
|
@@ -1445,18 +1503,18 @@ class et {
|
|
|
1445
1503
|
* execution.
|
|
1446
1504
|
*/
|
|
1447
1505
|
clone(t) {
|
|
1448
|
-
const
|
|
1506
|
+
const n = g.runKernel(ie, { x: t }), s = { x: t }, r = (o) => ({
|
|
1449
1507
|
x: () => {
|
|
1450
1508
|
const i = "float32", c = { x: o }, l = { dtype: i };
|
|
1451
1509
|
return g.runKernel(
|
|
1452
|
-
|
|
1510
|
+
oe,
|
|
1453
1511
|
c,
|
|
1454
1512
|
// tslint:disable-next-line: no-unnecessary-type-assertion
|
|
1455
1513
|
l
|
|
1456
1514
|
);
|
|
1457
1515
|
}
|
|
1458
1516
|
}), a = [];
|
|
1459
|
-
return this.addTapeNode(this.state.activeScope.name, s, [
|
|
1517
|
+
return this.addTapeNode(this.state.activeScope.name, s, [n], r, a, {}), n;
|
|
1460
1518
|
}
|
|
1461
1519
|
/**
|
|
1462
1520
|
* Execute a kernel with the given name and return the output tensor.
|
|
@@ -1471,21 +1529,21 @@ class et {
|
|
|
1471
1529
|
* for the backprop computation. These are booleans since the output
|
|
1472
1530
|
* tensors are not visible to the user.
|
|
1473
1531
|
*/
|
|
1474
|
-
runKernel(t,
|
|
1475
|
-
if (this.backendName == null && this.backend, !(
|
|
1532
|
+
runKernel(t, n, s) {
|
|
1533
|
+
if (this.backendName == null && this.backend, !(zt(t, this.backendName) != null))
|
|
1476
1534
|
throw new Error(`Kernel '${t}' not registered for backend '${this.backendName}'`);
|
|
1477
|
-
return this.runKernelFunc({ kernelName: t, inputs:
|
|
1535
|
+
return this.runKernelFunc({ kernelName: t, inputs: n, attrs: s });
|
|
1478
1536
|
}
|
|
1479
1537
|
shouldCheckForMemLeaks() {
|
|
1480
1538
|
return this.ENV.getBool("IS_TEST");
|
|
1481
1539
|
}
|
|
1482
|
-
checkKernelForMemLeak(t,
|
|
1540
|
+
checkKernelForMemLeak(t, n, s) {
|
|
1483
1541
|
const r = this.backend.numDataIds();
|
|
1484
1542
|
let a = 0;
|
|
1485
1543
|
s.forEach((c) => {
|
|
1486
1544
|
a += c.dtype === "complex64" ? 3 : 1;
|
|
1487
1545
|
});
|
|
1488
|
-
const o = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], i = r -
|
|
1546
|
+
const o = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], i = r - n - a - o;
|
|
1489
1547
|
if (i > 0)
|
|
1490
1548
|
throw new Error(`Backend '${this.backendName}' has an internal memory leak (${i} data ids) after running '${t}'`);
|
|
1491
1549
|
}
|
|
@@ -1495,60 +1553,60 @@ class et {
|
|
|
1495
1553
|
* Use `runKernel` to execute kernels from outside of engine.
|
|
1496
1554
|
*/
|
|
1497
1555
|
runKernelFunc(t) {
|
|
1498
|
-
let
|
|
1556
|
+
let n, s = [];
|
|
1499
1557
|
const r = this.isTapeOn(), a = this.state.numBytes, o = this.state.numTensors;
|
|
1500
1558
|
this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0);
|
|
1501
1559
|
let i;
|
|
1502
1560
|
this.backendName == null && this.backend;
|
|
1503
1561
|
let c;
|
|
1504
|
-
const l =
|
|
1505
|
-
if (
|
|
1506
|
-
const { kernelName: p, inputs:
|
|
1562
|
+
const l = wt(t) ? t.kernelName : this.state.activeScope != null ? this.state.activeScope.name : "";
|
|
1563
|
+
if (wt(t)) {
|
|
1564
|
+
const { kernelName: p, inputs: d, attrs: w } = t;
|
|
1507
1565
|
this.backendName == null && this.backend;
|
|
1508
|
-
const I =
|
|
1566
|
+
const I = zt(p, this.backendName);
|
|
1509
1567
|
y(I != null, () => `Cannot find registered kernel '${p}' for backend '${this.backendName}'`), i = () => {
|
|
1510
|
-
const
|
|
1511
|
-
c = I.kernelFunc({ inputs:
|
|
1568
|
+
const _ = this.backend.numDataIds();
|
|
1569
|
+
c = I.kernelFunc({ inputs: d, attrs: w, backend: this.backend });
|
|
1512
1570
|
const J = Array.isArray(c) ? c : [c];
|
|
1513
|
-
this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(p,
|
|
1571
|
+
this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(p, _, J);
|
|
1514
1572
|
const X = J.map((rt) => rt.rank != null ? rt : this.makeTensorFromTensorInfo(rt));
|
|
1515
1573
|
if (r) {
|
|
1516
|
-
const rt = this.getTensorsForGradient(p,
|
|
1574
|
+
const rt = this.getTensorsForGradient(p, d, X);
|
|
1517
1575
|
s = this.saveTensorsForBackwardMode(rt);
|
|
1518
1576
|
}
|
|
1519
1577
|
return X;
|
|
1520
1578
|
};
|
|
1521
1579
|
} else {
|
|
1522
|
-
const { forwardFunc: p } = t,
|
|
1580
|
+
const { forwardFunc: p } = t, d = (w) => {
|
|
1523
1581
|
r && (s = w.map((I) => this.keep(this.clone(I))));
|
|
1524
1582
|
};
|
|
1525
1583
|
i = () => {
|
|
1526
1584
|
const w = this.backend.numDataIds();
|
|
1527
|
-
c = this.tidy(() => p(this.backend,
|
|
1585
|
+
c = this.tidy(() => p(this.backend, d));
|
|
1528
1586
|
const I = Array.isArray(c) ? c : [c];
|
|
1529
1587
|
return this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(l, w, I), I;
|
|
1530
1588
|
};
|
|
1531
1589
|
}
|
|
1532
|
-
const { inputs: u, attrs: h } = t,
|
|
1590
|
+
const { inputs: u, attrs: h } = t, f = wt(t) ? null : t.backwardsFunc;
|
|
1533
1591
|
let m;
|
|
1534
1592
|
return this.scopedRun(
|
|
1535
1593
|
// Stop recording to a tape when running a kernel.
|
|
1536
1594
|
() => this.state.kernelDepth++,
|
|
1537
1595
|
() => this.state.kernelDepth--,
|
|
1538
1596
|
() => {
|
|
1539
|
-
!this.ENV.getBool("DEBUG") && !this.state.profiling ?
|
|
1597
|
+
!this.ENV.getBool("DEBUG") && !this.state.profiling ? n = i() : (m = this.profiler.profileKernel(l, u, () => i()), this.ENV.getBool("DEBUG") && this.profiler.logKernelProfile(m), n = m.outputs);
|
|
1540
1598
|
}
|
|
1541
|
-
), r && this.addTapeNode(l, u,
|
|
1599
|
+
), r && this.addTapeNode(l, u, n, f, s, h), this.state.profiling && this.state.activeProfile.kernels.push({
|
|
1542
1600
|
name: l,
|
|
1543
1601
|
bytesAdded: this.state.numBytes - a,
|
|
1544
1602
|
totalBytesSnapshot: this.state.numBytes,
|
|
1545
1603
|
tensorsAdded: this.state.numTensors - o,
|
|
1546
1604
|
totalTensorsSnapshot: this.state.numTensors,
|
|
1547
1605
|
inputShapes: Object.keys(u).map((p) => u[p] != null ? u[p].shape : null),
|
|
1548
|
-
outputShapes:
|
|
1606
|
+
outputShapes: n.map((p) => p.shape),
|
|
1549
1607
|
kernelTimeMs: m.timeMs,
|
|
1550
1608
|
extraInfo: m.extraInfo
|
|
1551
|
-
}), Array.isArray(c) ?
|
|
1609
|
+
}), Array.isArray(c) ? n : n[0];
|
|
1552
1610
|
}
|
|
1553
1611
|
/**
|
|
1554
1612
|
* Saves tensors used in forward mode for use in backward mode.
|
|
@@ -1565,12 +1623,12 @@ class et {
|
|
|
1565
1623
|
* @param inputs a map of input tensors.
|
|
1566
1624
|
* @param outputs an array of output tensors from forward mode of kernel.
|
|
1567
1625
|
*/
|
|
1568
|
-
getTensorsForGradient(t,
|
|
1569
|
-
const r =
|
|
1626
|
+
getTensorsForGradient(t, n, s) {
|
|
1627
|
+
const r = Vt(t);
|
|
1570
1628
|
if (r != null) {
|
|
1571
1629
|
const a = r.inputsToSave || [], o = r.outputsToSave || [];
|
|
1572
1630
|
let i;
|
|
1573
|
-
r.saveAllInputs ? (y(Array.isArray(
|
|
1631
|
+
r.saveAllInputs ? (y(Array.isArray(n), () => "saveAllInputs is true, expected inputs to be an array."), i = Object.keys(n).map((l) => n[l])) : i = a.map((l) => n[l]);
|
|
1574
1632
|
const c = s.filter((l, u) => o[u]);
|
|
1575
1633
|
return i.concat(c);
|
|
1576
1634
|
}
|
|
@@ -1581,15 +1639,15 @@ class et {
|
|
|
1581
1639
|
* tensor with the provided shape, dtype and values. It always
|
|
1582
1640
|
* creates a new data id and writes the values to the underlying backend.
|
|
1583
1641
|
*/
|
|
1584
|
-
makeTensor(t,
|
|
1642
|
+
makeTensor(t, n, s, r) {
|
|
1585
1643
|
if (t == null)
|
|
1586
1644
|
throw new Error("Values passed to engine.makeTensor() are null");
|
|
1587
1645
|
s = s || "float32", r = r || this.backend;
|
|
1588
1646
|
let a = t;
|
|
1589
|
-
s === "string" && Dt(t[0]) && (a = t.map((c) =>
|
|
1590
|
-
const o = r.write(a,
|
|
1647
|
+
s === "string" && Dt(t[0]) && (a = t.map((c) => ue(c)));
|
|
1648
|
+
const o = r.write(a, n, s), i = new D(n, s, o, this.nextTensorId());
|
|
1591
1649
|
if (this.trackTensor(i, r), s === "string") {
|
|
1592
|
-
const c = this.state.tensorInfo.get(o), l =
|
|
1650
|
+
const c = this.state.tensorInfo.get(o), l = Le(a);
|
|
1593
1651
|
this.state.numBytes += l - c.bytes, c.bytes = l;
|
|
1594
1652
|
}
|
|
1595
1653
|
return i;
|
|
@@ -1600,9 +1658,9 @@ class et {
|
|
|
1600
1658
|
* a new data id, only increments the ref count used in memory tracking.
|
|
1601
1659
|
* @deprecated
|
|
1602
1660
|
*/
|
|
1603
|
-
makeTensorFromDataId(t,
|
|
1661
|
+
makeTensorFromDataId(t, n, s, r) {
|
|
1604
1662
|
s = s || "float32";
|
|
1605
|
-
const a = { dataId: t, shape:
|
|
1663
|
+
const a = { dataId: t, shape: n, dtype: s };
|
|
1606
1664
|
return this.makeTensorFromTensorInfo(a, r);
|
|
1607
1665
|
}
|
|
1608
1666
|
/**
|
|
@@ -1610,52 +1668,52 @@ class et {
|
|
|
1610
1668
|
* around an existing data id in TensorInfo. It doesn't create a new data id,
|
|
1611
1669
|
* only increments the ref count used in memory tracking.
|
|
1612
1670
|
*/
|
|
1613
|
-
makeTensorFromTensorInfo(t,
|
|
1671
|
+
makeTensorFromTensorInfo(t, n) {
|
|
1614
1672
|
const { dataId: s, shape: r, dtype: a } = t, o = new D(r, a, s, this.nextTensorId());
|
|
1615
|
-
return this.trackTensor(o,
|
|
1673
|
+
return this.trackTensor(o, n), o;
|
|
1616
1674
|
}
|
|
1617
|
-
makeVariable(t,
|
|
1675
|
+
makeVariable(t, n = !0, s, r) {
|
|
1618
1676
|
s = s || this.nextVariableId().toString(), r != null && r !== t.dtype && (t = t.cast(r));
|
|
1619
|
-
const a = new
|
|
1677
|
+
const a = new gt(t, n, s, this.nextTensorId());
|
|
1620
1678
|
if (this.state.registeredVariables[a.name] != null)
|
|
1621
1679
|
throw new Error(`Variable with name ${a.name} was already registered`);
|
|
1622
1680
|
return this.state.registeredVariables[a.name] = a, this.incRef(a, this.backend), a;
|
|
1623
1681
|
}
|
|
1624
|
-
trackTensor(t,
|
|
1682
|
+
trackTensor(t, n) {
|
|
1625
1683
|
this.state.numTensors++, t.dtype === "string" && this.state.numStringTensors++;
|
|
1626
1684
|
let s = 0;
|
|
1627
|
-
t.dtype !== "complex64" && t.dtype !== "string" && (s = t.size *
|
|
1628
|
-
backend:
|
|
1685
|
+
t.dtype !== "complex64" && t.dtype !== "string" && (s = t.size * kt(t.dtype)), this.state.numBytes += s, this.state.tensorInfo.has(t.dataId) || (this.state.numDataBuffers++, this.state.tensorInfo.set(t.dataId, {
|
|
1686
|
+
backend: n || this.backend,
|
|
1629
1687
|
dtype: t.dtype,
|
|
1630
1688
|
shape: t.shape,
|
|
1631
1689
|
bytes: s
|
|
1632
|
-
})), t instanceof
|
|
1690
|
+
})), t instanceof gt || this.track(t);
|
|
1633
1691
|
}
|
|
1634
1692
|
// Track the tensor by dataId and increase the refCount for the dataId in the
|
|
1635
1693
|
// backend.
|
|
1636
1694
|
// TODO(pyu10055): This is currently used by makeVariable method, to increase
|
|
1637
1695
|
// refCount on the backend for the dataId. It can potentially be replaced with
|
|
1638
1696
|
// Identity op indead of calling backend directly.
|
|
1639
|
-
incRef(t,
|
|
1640
|
-
this.trackTensor(t,
|
|
1697
|
+
incRef(t, n) {
|
|
1698
|
+
this.trackTensor(t, n), this.backend.incRef(t.dataId);
|
|
1641
1699
|
}
|
|
1642
|
-
removeDataId(t,
|
|
1643
|
-
this.state.tensorInfo.has(t) && this.state.tensorInfo.get(t).backend ===
|
|
1700
|
+
removeDataId(t, n) {
|
|
1701
|
+
this.state.tensorInfo.has(t) && this.state.tensorInfo.get(t).backend === n && (this.state.tensorInfo.delete(t), this.state.numDataBuffers--);
|
|
1644
1702
|
}
|
|
1645
1703
|
disposeTensor(t) {
|
|
1646
1704
|
if (!this.state.tensorInfo.has(t.dataId))
|
|
1647
1705
|
return;
|
|
1648
|
-
const
|
|
1649
|
-
if (this.state.numTensors--, t.dtype === "string" && (this.state.numStringTensors--, this.state.numBytes -=
|
|
1650
|
-
const s = t.size *
|
|
1706
|
+
const n = this.state.tensorInfo.get(t.dataId);
|
|
1707
|
+
if (this.state.numTensors--, t.dtype === "string" && (this.state.numStringTensors--, this.state.numBytes -= n.bytes), t.dtype !== "complex64" && t.dtype !== "string") {
|
|
1708
|
+
const s = t.size * kt(t.dtype);
|
|
1651
1709
|
this.state.numBytes -= s;
|
|
1652
1710
|
}
|
|
1653
|
-
|
|
1711
|
+
n.backend.disposeData(t.dataId) && this.removeDataId(t.dataId, n.backend);
|
|
1654
1712
|
}
|
|
1655
1713
|
disposeVariables() {
|
|
1656
1714
|
for (const t in this.state.registeredVariables) {
|
|
1657
|
-
const
|
|
1658
|
-
this.disposeVariable(
|
|
1715
|
+
const n = this.state.registeredVariables[t];
|
|
1716
|
+
this.disposeVariable(n);
|
|
1659
1717
|
}
|
|
1660
1718
|
}
|
|
1661
1719
|
disposeVariable(t) {
|
|
@@ -1667,8 +1725,8 @@ class et {
|
|
|
1667
1725
|
}
|
|
1668
1726
|
async profile(t) {
|
|
1669
1727
|
this.state.profiling = !0;
|
|
1670
|
-
const
|
|
1671
|
-
this.state.activeProfile.kernels = [], this.state.activeProfile.result = await t(), this.state.profiling = !1, this.state.activeProfile.peakBytes = Math.max(...this.state.activeProfile.kernels.map((r) => r.totalBytesSnapshot)), this.state.activeProfile.newBytes = this.state.numBytes -
|
|
1728
|
+
const n = this.state.numBytes, s = this.state.numTensors;
|
|
1729
|
+
this.state.activeProfile.kernels = [], this.state.activeProfile.result = await t(), this.state.profiling = !1, this.state.activeProfile.peakBytes = Math.max(...this.state.activeProfile.kernels.map((r) => r.totalBytesSnapshot)), this.state.activeProfile.newBytes = this.state.numBytes - n, this.state.activeProfile.newTensors = this.state.numTensors - s;
|
|
1672
1730
|
for (const r of this.state.activeProfile.kernels)
|
|
1673
1731
|
r.kernelTimeMs = await r.kernelTimeMs, r.extraInfo = await r.extraInfo;
|
|
1674
1732
|
return this.state.activeProfile;
|
|
@@ -1676,12 +1734,12 @@ class et {
|
|
|
1676
1734
|
isTapeOn() {
|
|
1677
1735
|
return this.state.gradientDepth > 0 && this.state.kernelDepth === 0;
|
|
1678
1736
|
}
|
|
1679
|
-
addTapeNode(t,
|
|
1680
|
-
const i = { id: this.state.nextTapeNodeId++, kernelName: t, inputs:
|
|
1737
|
+
addTapeNode(t, n, s, r, a, o) {
|
|
1738
|
+
const i = { id: this.state.nextTapeNodeId++, kernelName: t, inputs: n, outputs: s, saved: a }, c = Vt(t);
|
|
1681
1739
|
c != null && (r = c.gradFunc), r != null && (i.gradient = (l) => (l = l.map((u, h) => {
|
|
1682
1740
|
if (u == null) {
|
|
1683
|
-
const
|
|
1684
|
-
return this.makeTensor(m,
|
|
1741
|
+
const f = s[h], m = ne(f.size, f.dtype);
|
|
1742
|
+
return this.makeTensor(m, f.shape, f.dtype);
|
|
1685
1743
|
}
|
|
1686
1744
|
return u;
|
|
1687
1745
|
}), r(l.length > 1 ? l : l[0], a, o))), this.state.activeTape.push(i);
|
|
@@ -1700,25 +1758,25 @@ class et {
|
|
|
1700
1758
|
* as scope() without the need for a function closure.
|
|
1701
1759
|
*/
|
|
1702
1760
|
startScope(t) {
|
|
1703
|
-
const
|
|
1761
|
+
const n = {
|
|
1704
1762
|
track: [],
|
|
1705
1763
|
name: "unnamed scope",
|
|
1706
1764
|
id: this.state.nextScopeId++
|
|
1707
1765
|
};
|
|
1708
|
-
t && (
|
|
1766
|
+
t && (n.name = t), this.state.scopeStack.push(n), this.state.activeScope = n;
|
|
1709
1767
|
}
|
|
1710
1768
|
/**
|
|
1711
1769
|
* End a scope. Use this with startScope() to achieve the same functionality
|
|
1712
1770
|
* as scope() without the need for a function closure.
|
|
1713
1771
|
*/
|
|
1714
1772
|
endScope(t) {
|
|
1715
|
-
const
|
|
1773
|
+
const n = pe(t), s = new Set(n.map((a) => a.id));
|
|
1716
1774
|
for (let a = 0; a < this.state.activeScope.track.length; a++) {
|
|
1717
1775
|
const o = this.state.activeScope.track[a];
|
|
1718
1776
|
!o.kept && !s.has(o.id) && o.dispose();
|
|
1719
1777
|
}
|
|
1720
1778
|
const r = this.state.scopeStack.pop();
|
|
1721
|
-
this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1],
|
|
1779
|
+
this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], n.forEach((a) => {
|
|
1722
1780
|
!a.kept && a.scopeId === r.id && this.track(a);
|
|
1723
1781
|
});
|
|
1724
1782
|
}
|
|
@@ -1728,25 +1786,25 @@ class et {
|
|
|
1728
1786
|
* was not a function of that `x`. It also takes optional dy to multiply the
|
|
1729
1787
|
* gradient, which defaults to `1`.
|
|
1730
1788
|
*/
|
|
1731
|
-
gradients(t,
|
|
1732
|
-
if (y(
|
|
1789
|
+
gradients(t, n, s, r = !1) {
|
|
1790
|
+
if (y(n.length > 0, () => "gradients() received an empty list of xs."), s != null && s.dtype !== "float32")
|
|
1733
1791
|
throw new Error(`dy must have 'float32' dtype, but has '${s.dtype}'`);
|
|
1734
1792
|
const a = this.scopedRun(() => this.startTape(), () => this.endTape(), () => this.tidy("forward", t));
|
|
1735
1793
|
y(a instanceof D, () => "The result y returned by f() must be a tensor.");
|
|
1736
|
-
const o =
|
|
1737
|
-
if (!r && o.length === 0 &&
|
|
1794
|
+
const o = ln(this.state.activeTape, n, a);
|
|
1795
|
+
if (!r && o.length === 0 && n.length > 0)
|
|
1738
1796
|
throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");
|
|
1739
1797
|
return this.tidy("backward", () => {
|
|
1740
1798
|
const i = {};
|
|
1741
|
-
i[a.id] = s ??
|
|
1799
|
+
i[a.id] = s ?? bn(a.shape), un(
|
|
1742
1800
|
i,
|
|
1743
1801
|
o,
|
|
1744
1802
|
// Pass the tidy function to avoid circular dep with `tape.ts`.
|
|
1745
1803
|
(l) => this.tidy(l),
|
|
1746
1804
|
// Pass an add function to avoide a circular dep with `tape.ts`.
|
|
1747
|
-
|
|
1805
|
+
wn
|
|
1748
1806
|
);
|
|
1749
|
-
const c =
|
|
1807
|
+
const c = n.map((l) => i[l.id]);
|
|
1750
1808
|
return this.state.gradientDepth === 0 && (this.state.activeTape.forEach((l) => {
|
|
1751
1809
|
for (const u of l.saved)
|
|
1752
1810
|
u.dispose();
|
|
@@ -1754,19 +1812,19 @@ class et {
|
|
|
1754
1812
|
});
|
|
1755
1813
|
}
|
|
1756
1814
|
customGrad(t) {
|
|
1757
|
-
return y(
|
|
1758
|
-
y(
|
|
1815
|
+
return y(ht(t), () => "The f passed in customGrad(f) must be a function."), (...n) => {
|
|
1816
|
+
y(n.every((i) => i instanceof D), () => "The args passed in customGrad(f)(x1, x2,...) must all be tensors");
|
|
1759
1817
|
let s;
|
|
1760
1818
|
const r = {};
|
|
1761
|
-
|
|
1819
|
+
n.forEach((i, c) => {
|
|
1762
1820
|
r[c] = i;
|
|
1763
1821
|
});
|
|
1764
|
-
const a = (i, c) => (s = t(...
|
|
1822
|
+
const a = (i, c) => (s = t(...n, c), y(s.value instanceof D, () => "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"), y(ht(s.gradFunc), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."), s.value), o = (i, c) => {
|
|
1765
1823
|
const l = s.gradFunc(i, c), u = Array.isArray(l) ? l : [l];
|
|
1766
|
-
y(u.length ===
|
|
1824
|
+
y(u.length === n.length, () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."), y(u.every((f) => f instanceof D), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.");
|
|
1767
1825
|
const h = {};
|
|
1768
|
-
return u.forEach((
|
|
1769
|
-
h[m] = () =>
|
|
1826
|
+
return u.forEach((f, m) => {
|
|
1827
|
+
h[m] = () => f;
|
|
1770
1828
|
}), h;
|
|
1771
1829
|
};
|
|
1772
1830
|
return this.runKernelFunc({
|
|
@@ -1782,12 +1840,12 @@ class et {
|
|
|
1782
1840
|
read(t) {
|
|
1783
1841
|
return this.state.tensorInfo.get(t).backend.read(t);
|
|
1784
1842
|
}
|
|
1785
|
-
readToGPU(t,
|
|
1786
|
-
return this.state.tensorInfo.get(t).backend.readToGPU(t,
|
|
1843
|
+
readToGPU(t, n) {
|
|
1844
|
+
return this.state.tensorInfo.get(t).backend.readToGPU(t, n);
|
|
1787
1845
|
}
|
|
1788
1846
|
async time(t) {
|
|
1789
|
-
const
|
|
1790
|
-
return s.wallMs = dt() -
|
|
1847
|
+
const n = dt(), s = await this.backend.time(t);
|
|
1848
|
+
return s.wallMs = dt() - n, s;
|
|
1791
1849
|
}
|
|
1792
1850
|
/**
|
|
1793
1851
|
* Tracks a Tensor in the current scope to be automatically cleaned up
|
|
@@ -1806,7 +1864,7 @@ class et {
|
|
|
1806
1864
|
* registered backend factories.
|
|
1807
1865
|
*/
|
|
1808
1866
|
reset() {
|
|
1809
|
-
this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new
|
|
1867
|
+
this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new Ht();
|
|
1810
1868
|
for (const t in this.registry)
|
|
1811
1869
|
this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t];
|
|
1812
1870
|
this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null;
|
|
@@ -1814,22 +1872,22 @@ class et {
|
|
|
1814
1872
|
}
|
|
1815
1873
|
et.nextTensorId = 0;
|
|
1816
1874
|
et.nextVariableId = 0;
|
|
1817
|
-
function
|
|
1818
|
-
const t =
|
|
1819
|
-
return g.makeTensor(t,
|
|
1875
|
+
function bn(e) {
|
|
1876
|
+
const t = Ge(z(e), "float32");
|
|
1877
|
+
return g.makeTensor(t, e, "float32");
|
|
1820
1878
|
}
|
|
1821
|
-
function
|
|
1822
|
-
const
|
|
1823
|
-
if (
|
|
1824
|
-
const t = new
|
|
1825
|
-
|
|
1879
|
+
function be() {
|
|
1880
|
+
const e = re();
|
|
1881
|
+
if (e._tfengine == null) {
|
|
1882
|
+
const t = new Ue(e);
|
|
1883
|
+
e._tfengine = new et(t);
|
|
1826
1884
|
}
|
|
1827
|
-
return
|
|
1885
|
+
return je(e._tfengine.ENV), gn(() => e._tfengine), e._tfengine;
|
|
1828
1886
|
}
|
|
1829
|
-
const g =
|
|
1830
|
-
function
|
|
1831
|
-
const
|
|
1832
|
-
return g.runKernel(
|
|
1887
|
+
const g = be();
|
|
1888
|
+
function wn(e, t) {
|
|
1889
|
+
const n = { a: e, b: t };
|
|
1890
|
+
return g.runKernel(ae, n);
|
|
1833
1891
|
}
|
|
1834
1892
|
/**
|
|
1835
1893
|
* @license
|
|
@@ -1847,15 +1905,15 @@ function bn(n, t) {
|
|
|
1847
1905
|
* limitations under the License.
|
|
1848
1906
|
* =============================================================================
|
|
1849
1907
|
*/
|
|
1850
|
-
function
|
|
1908
|
+
function Sn() {
|
|
1851
1909
|
return typeof window < "u" && window.document != null || //@ts-ignore
|
|
1852
1910
|
typeof WorkerGlobalScope < "u";
|
|
1853
1911
|
}
|
|
1854
1912
|
const B = k();
|
|
1855
|
-
B.registerFlag("DEBUG", () => !1, (
|
|
1856
|
-
|
|
1913
|
+
B.registerFlag("DEBUG", () => !1, (e) => {
|
|
1914
|
+
e && console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.");
|
|
1857
1915
|
});
|
|
1858
|
-
B.registerFlag("IS_BROWSER", () =>
|
|
1916
|
+
B.registerFlag("IS_BROWSER", () => Sn());
|
|
1859
1917
|
B.registerFlag("IS_NODE", () => typeof Z < "u" && typeof Z.versions < "u" && typeof Z.versions.node < "u");
|
|
1860
1918
|
B.registerFlag("IS_CHROME", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor));
|
|
1861
1919
|
B.registerFlag("IS_SAFARI", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Safari/.test(navigator.userAgent) && /Apple/.test(navigator.vendor));
|
|
@@ -1883,57 +1941,57 @@ B.registerFlag("USE_SETTIMEOUTCUSTOM", () => !1);
|
|
|
1883
1941
|
* limitations under the License.
|
|
1884
1942
|
* =============================================================================
|
|
1885
1943
|
*/
|
|
1886
|
-
function
|
|
1887
|
-
let
|
|
1888
|
-
if (
|
|
1889
|
-
return t === "string" ? [] : [
|
|
1890
|
-
if (
|
|
1891
|
-
const r =
|
|
1892
|
-
return [
|
|
1893
|
-
} else if (
|
|
1894
|
-
return [
|
|
1895
|
-
if (!Array.isArray(
|
|
1944
|
+
function kn(e, t) {
|
|
1945
|
+
let n = e;
|
|
1946
|
+
if (F(e))
|
|
1947
|
+
return t === "string" ? [] : [e.length];
|
|
1948
|
+
if (ge(e)) {
|
|
1949
|
+
const r = e.channels || "RGBA";
|
|
1950
|
+
return [e.height, e.width * r.length];
|
|
1951
|
+
} else if (me(e))
|
|
1952
|
+
return [e.buffer.size / (t == null ? 4 : kt(t))];
|
|
1953
|
+
if (!Array.isArray(e))
|
|
1896
1954
|
return [];
|
|
1897
1955
|
const s = [];
|
|
1898
|
-
for (; Array.isArray(
|
|
1899
|
-
s.push(
|
|
1900
|
-
return Array.isArray(
|
|
1956
|
+
for (; Array.isArray(n) || F(n) && t !== "string"; )
|
|
1957
|
+
s.push(n.length), n = n[0];
|
|
1958
|
+
return Array.isArray(e) && k().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && we(e, s, []), s;
|
|
1901
1959
|
}
|
|
1902
|
-
function
|
|
1903
|
-
if (
|
|
1904
|
-
y(t.length === 0, () => `Element arr[${
|
|
1960
|
+
function we(e, t, n) {
|
|
1961
|
+
if (n = n || [], !Array.isArray(e) && !F(e)) {
|
|
1962
|
+
y(t.length === 0, () => `Element arr[${n.join("][")}] is a primitive, but should be an array/TypedArray of ${t[0]} elements`);
|
|
1905
1963
|
return;
|
|
1906
1964
|
}
|
|
1907
|
-
y(t.length > 0, () => `Element arr[${
|
|
1965
|
+
y(t.length > 0, () => `Element arr[${n.join("][")}] should be a primitive, but is an array of ${e.length} elements`), y(e.length === t[0], () => `Element arr[${n.join("][")}] should have ${t[0]} elements, but has ${e.length} elements`);
|
|
1908
1966
|
const s = t.slice(1);
|
|
1909
|
-
for (let r = 0; r <
|
|
1910
|
-
|
|
1967
|
+
for (let r = 0; r < e.length; ++r)
|
|
1968
|
+
we(e[r], s, n.concat(r));
|
|
1911
1969
|
}
|
|
1912
|
-
function
|
|
1913
|
-
if (
|
|
1914
|
-
if (
|
|
1970
|
+
function Jt(e, t, n, s) {
|
|
1971
|
+
if (e !== "string_or_numeric") {
|
|
1972
|
+
if (e == null)
|
|
1915
1973
|
throw new Error("Expected dtype cannot be null.");
|
|
1916
|
-
if (
|
|
1917
|
-
throw new Error(`Argument '${
|
|
1974
|
+
if (e !== "numeric" && e !== t || e === "numeric" && t === "string")
|
|
1975
|
+
throw new Error(`Argument '${n}' passed to '${s}' must be ${e} tensor, but got ${t} tensor`);
|
|
1918
1976
|
}
|
|
1919
1977
|
}
|
|
1920
|
-
function T(
|
|
1921
|
-
if (
|
|
1922
|
-
return
|
|
1923
|
-
let r =
|
|
1924
|
-
if (r !== "string" && ["bool", "int32", "float32"].indexOf(s) >= 0 && (r = s),
|
|
1925
|
-
const c =
|
|
1926
|
-
throw new Error(`Argument '${t}' passed to '${
|
|
1978
|
+
function T(e, t, n, s = "numeric") {
|
|
1979
|
+
if (e instanceof fe())
|
|
1980
|
+
return Jt(s, e.dtype, t, n), e;
|
|
1981
|
+
let r = pt(e);
|
|
1982
|
+
if (r !== "string" && ["bool", "int32", "float32"].indexOf(s) >= 0 && (r = s), Jt(s, r, t, n), e == null || !F(e) && !Array.isArray(e) && typeof e != "number" && typeof e != "boolean" && typeof e != "string") {
|
|
1983
|
+
const c = e == null ? "null" : e.constructor.name;
|
|
1984
|
+
throw new Error(`Argument '${t}' passed to '${n}' must be a Tensor or TensorLike, but got '${c}'`);
|
|
1927
1985
|
}
|
|
1928
|
-
const a =
|
|
1929
|
-
!
|
|
1930
|
-
const i = r !== "string" ?
|
|
1986
|
+
const a = kn(e, r);
|
|
1987
|
+
!F(e) && !Array.isArray(e) && (e = [e]);
|
|
1988
|
+
const i = r !== "string" ? Lt(e, r) : ct(e, [], !0);
|
|
1931
1989
|
return g.makeTensor(i, a, r);
|
|
1932
1990
|
}
|
|
1933
|
-
function
|
|
1934
|
-
if (!Array.isArray(
|
|
1935
|
-
throw new Error(`Argument ${t} passed to ${
|
|
1936
|
-
return
|
|
1991
|
+
function In(e, t, n, s = "numeric") {
|
|
1992
|
+
if (!Array.isArray(e))
|
|
1993
|
+
throw new Error(`Argument ${t} passed to ${n} must be a \`Tensor[]\` or \`TensorLike[]\``);
|
|
1994
|
+
return e.map((a, o) => T(a, `${t}[${o}]`, n, s));
|
|
1937
1995
|
}
|
|
1938
1996
|
/**
|
|
1939
1997
|
* @license
|
|
@@ -1951,16 +2009,16 @@ function ro(n, t, e, s = "numeric") {
|
|
|
1951
2009
|
* limitations under the License.
|
|
1952
2010
|
* =============================================================================
|
|
1953
2011
|
*/
|
|
1954
|
-
const
|
|
1955
|
-
function N(
|
|
1956
|
-
const t = Object.keys(
|
|
2012
|
+
const Tn = "__op";
|
|
2013
|
+
function N(e) {
|
|
2014
|
+
const t = Object.keys(e);
|
|
1957
2015
|
if (t.length !== 1)
|
|
1958
2016
|
throw new Error(`Please provide an object with a single key (operation name) mapping to a function. Got an object with ${t.length} keys.`);
|
|
1959
|
-
let
|
|
1960
|
-
const s = n
|
|
1961
|
-
|
|
2017
|
+
let n = t[0];
|
|
2018
|
+
const s = e[n];
|
|
2019
|
+
n.endsWith("_") && (n = n.substring(0, n.length - 1)), n = n + Tn;
|
|
1962
2020
|
const r = (...a) => {
|
|
1963
|
-
g.startScope(
|
|
2021
|
+
g.startScope(n);
|
|
1964
2022
|
try {
|
|
1965
2023
|
const o = s(...a);
|
|
1966
2024
|
return Ct(o) && console.error("Cannot return a Promise inside of tidy."), g.endScope(o), o;
|
|
@@ -1968,7 +2026,7 @@ function N(n) {
|
|
|
1968
2026
|
throw g.endScope(null), o;
|
|
1969
2027
|
}
|
|
1970
2028
|
};
|
|
1971
|
-
return Object.defineProperty(r, "name", { value:
|
|
2029
|
+
return Object.defineProperty(r, "name", { value: n, configurable: !0 }), r;
|
|
1972
2030
|
}
|
|
1973
2031
|
/**
|
|
1974
2032
|
* @license
|
|
@@ -1986,28 +2044,28 @@ function N(n) {
|
|
|
1986
2044
|
* limitations under the License.
|
|
1987
2045
|
* =============================================================================
|
|
1988
2046
|
*/
|
|
1989
|
-
function
|
|
2047
|
+
function En(e, t, n, s) {
|
|
1990
2048
|
if (s == null)
|
|
1991
|
-
s =
|
|
2049
|
+
s = pt(e);
|
|
1992
2050
|
else if (s === "complex64")
|
|
1993
2051
|
throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");
|
|
1994
|
-
if (
|
|
2052
|
+
if (me(e) || ge(e)) {
|
|
1995
2053
|
if (s !== "float32" && s !== "int32")
|
|
1996
2054
|
throw new Error(`Creating tensor from GPU data only supports 'float32'|'int32' dtype, while the dtype is ${s}.`);
|
|
1997
|
-
return g.backend.createTensorFromGPUData(
|
|
2055
|
+
return g.backend.createTensorFromGPUData(e, t || n, s);
|
|
1998
2056
|
}
|
|
1999
|
-
if (!
|
|
2057
|
+
if (!F(e) && !Array.isArray(e) && typeof e != "number" && typeof e != "boolean" && typeof e != "string")
|
|
2000
2058
|
throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");
|
|
2001
2059
|
if (t != null) {
|
|
2002
2060
|
xt(t);
|
|
2003
|
-
const r = z(t), a = z(
|
|
2061
|
+
const r = z(t), a = z(n);
|
|
2004
2062
|
y(r === a, () => `Based on the provided shape, [${t}], the tensor should have ${r} values but has ${a}`);
|
|
2005
|
-
for (let o = 0; o <
|
|
2006
|
-
const i =
|
|
2007
|
-
y(
|
|
2063
|
+
for (let o = 0; o < n.length; ++o) {
|
|
2064
|
+
const i = n[o], c = o === n.length - 1 ? i !== z(t.slice(o)) : !0;
|
|
2065
|
+
y(n[o] === t[o] || !c, () => `Error creating a new Tensor. Inferred shape (${n}) does not match the provided shape (${t}). `);
|
|
2008
2066
|
}
|
|
2009
2067
|
}
|
|
2010
|
-
return !
|
|
2068
|
+
return !F(e) && !Array.isArray(e) && (e = [e]), t = t || n, e = s !== "string" ? Lt(e, s) : ct(e, [], !0), g.makeTensor(e, t, s);
|
|
2011
2069
|
}
|
|
2012
2070
|
class st {
|
|
2013
2071
|
/**
|
|
@@ -2021,31 +2079,31 @@ class st {
|
|
|
2021
2079
|
return new st(t).slice();
|
|
2022
2080
|
}
|
|
2023
2081
|
constructor(t) {
|
|
2024
|
-
if (this.shards = [], this.previousShardIndex = 0, t == null || (t instanceof Array || (t = [t]), t = t.map((s) =>
|
|
2082
|
+
if (this.shards = [], this.previousShardIndex = 0, t == null || (t instanceof Array || (t = [t]), t = t.map((s) => F(s) ? s.buffer : s), t.length === 0))
|
|
2025
2083
|
return;
|
|
2026
2084
|
this.bufferUniformSize = t[0].byteLength;
|
|
2027
|
-
let
|
|
2085
|
+
let n = 0;
|
|
2028
2086
|
for (let s = 0; s < t.length; s++) {
|
|
2029
2087
|
const r = t[s];
|
|
2030
2088
|
s !== t.length - 1 && r.byteLength !== this.bufferUniformSize && (this.bufferUniformSize = void 0);
|
|
2031
|
-
const a =
|
|
2032
|
-
this.shards.push({ buffer: r, start:
|
|
2089
|
+
const a = n + r.byteLength;
|
|
2090
|
+
this.shards.push({ buffer: r, start: n, end: a }), n = a;
|
|
2033
2091
|
}
|
|
2034
2092
|
this.shards.length === 0 && (this.byteLength = 0), this.byteLength = this.shards[this.shards.length - 1].end;
|
|
2035
2093
|
}
|
|
2036
|
-
slice(t = 0,
|
|
2094
|
+
slice(t = 0, n = this.byteLength) {
|
|
2037
2095
|
if (this.shards.length === 0)
|
|
2038
2096
|
return new ArrayBuffer(0);
|
|
2039
|
-
if (t = isNaN(Number(t)) ? 0 : t,
|
|
2097
|
+
if (t = isNaN(Number(t)) ? 0 : t, n = isNaN(Number(n)) ? 0 : n, t = Math.max(0, t), n = Math.min(this.byteLength, n), n <= t)
|
|
2040
2098
|
return new ArrayBuffer(0);
|
|
2041
2099
|
const s = this.findShardForByte(t);
|
|
2042
2100
|
if (s === -1)
|
|
2043
2101
|
throw new Error(`Could not find start shard for byte ${t}`);
|
|
2044
|
-
const r =
|
|
2102
|
+
const r = n - t, a = new ArrayBuffer(r), o = new Uint8Array(a);
|
|
2045
2103
|
let i = 0;
|
|
2046
2104
|
for (let c = s; c < this.shards.length; c++) {
|
|
2047
|
-
const l = this.shards[c], h = t + i - l.start,
|
|
2048
|
-
if (o.set(
|
|
2105
|
+
const l = this.shards[c], h = t + i - l.start, f = i, p = Math.min(n, l.end) - l.start, d = new Uint8Array(l.buffer, h, p - h);
|
|
2106
|
+
if (o.set(d, f), i += d.length, n < l.end)
|
|
2049
2107
|
break;
|
|
2050
2108
|
}
|
|
2051
2109
|
return a;
|
|
@@ -2058,22 +2116,22 @@ class st {
|
|
|
2058
2116
|
return -1;
|
|
2059
2117
|
if (this.bufferUniformSize != null)
|
|
2060
2118
|
return this.previousShardIndex = Math.floor(t / this.bufferUniformSize), this.previousShardIndex;
|
|
2061
|
-
function
|
|
2119
|
+
function n(r) {
|
|
2062
2120
|
return t < r.start ? -1 : t >= r.end ? 1 : 0;
|
|
2063
2121
|
}
|
|
2064
|
-
if (
|
|
2122
|
+
if (n(this.shards[this.previousShardIndex]) === 0)
|
|
2065
2123
|
return this.previousShardIndex;
|
|
2066
|
-
const s =
|
|
2124
|
+
const s = An(this.shards, n);
|
|
2067
2125
|
return s === -1 ? -1 : (this.previousShardIndex = s, this.previousShardIndex);
|
|
2068
2126
|
}
|
|
2069
2127
|
}
|
|
2070
|
-
function
|
|
2071
|
-
let
|
|
2072
|
-
for (;
|
|
2073
|
-
const r = Math.floor((s -
|
|
2128
|
+
function An(e, t) {
|
|
2129
|
+
let n = 0, s = e.length;
|
|
2130
|
+
for (; n <= s; ) {
|
|
2131
|
+
const r = Math.floor((s - n) / 2) + n, a = t(e[r]);
|
|
2074
2132
|
if (a === 0)
|
|
2075
2133
|
return r;
|
|
2076
|
-
a < 0 ? s = r :
|
|
2134
|
+
a < 0 ? s = r : n = r + 1;
|
|
2077
2135
|
}
|
|
2078
2136
|
return -1;
|
|
2079
2137
|
}
|
|
@@ -2093,103 +2151,103 @@ function Tn(n, t) {
|
|
|
2093
2151
|
* limitations under the License.
|
|
2094
2152
|
* =============================================================================
|
|
2095
2153
|
*/
|
|
2096
|
-
function
|
|
2154
|
+
function go() {
|
|
2097
2155
|
g.disposeVariables();
|
|
2098
2156
|
}
|
|
2099
|
-
function
|
|
2157
|
+
function mo() {
|
|
2100
2158
|
return g;
|
|
2101
2159
|
}
|
|
2102
|
-
function
|
|
2160
|
+
function po() {
|
|
2103
2161
|
return g.memory();
|
|
2104
2162
|
}
|
|
2105
|
-
function E(
|
|
2106
|
-
return g.tidy(
|
|
2163
|
+
function E(e, t) {
|
|
2164
|
+
return g.tidy(e, t);
|
|
2107
2165
|
}
|
|
2108
|
-
function M(
|
|
2109
|
-
|
|
2166
|
+
function M(e) {
|
|
2167
|
+
pe(e).forEach((n) => n.dispose());
|
|
2110
2168
|
}
|
|
2111
|
-
function
|
|
2112
|
-
return g.keep(
|
|
2169
|
+
function Bn(e) {
|
|
2170
|
+
return g.keep(e);
|
|
2113
2171
|
}
|
|
2114
|
-
function
|
|
2172
|
+
function yo() {
|
|
2115
2173
|
return g.backend;
|
|
2116
2174
|
}
|
|
2117
|
-
const
|
|
2118
|
-
async function
|
|
2119
|
-
const
|
|
2175
|
+
const Xt = 4;
|
|
2176
|
+
async function bo(e, t) {
|
|
2177
|
+
const n = [], s = [], r = Array.isArray(e) ? e.map((o) => o.name) : Object.keys(e);
|
|
2120
2178
|
for (let o = 0; o < r.length; ++o) {
|
|
2121
|
-
const i = r[o], c = Array.isArray(
|
|
2179
|
+
const i = r[o], c = Array.isArray(e) ? e[o].tensor : e[i];
|
|
2122
2180
|
if (c.dtype !== "float32" && c.dtype !== "int32" && c.dtype !== "bool" && c.dtype !== "string" && c.dtype !== "complex64")
|
|
2123
2181
|
throw new Error(`Unsupported dtype in weight '${i}': ${c.dtype}`);
|
|
2124
2182
|
const l = { name: i, shape: c.shape, dtype: c.dtype };
|
|
2125
2183
|
if (c.dtype === "string") {
|
|
2126
2184
|
const u = new Promise(async (h) => {
|
|
2127
|
-
const
|
|
2128
|
-
let
|
|
2129
|
-
for (let w = 0; w <
|
|
2130
|
-
const I =
|
|
2131
|
-
p.set(
|
|
2185
|
+
const f = await c.bytes(), m = f.reduce((w, I) => w + I.length, 0) + Xt * f.length, p = new Uint8Array(m);
|
|
2186
|
+
let d = 0;
|
|
2187
|
+
for (let w = 0; w < f.length; w++) {
|
|
2188
|
+
const I = f[w], _ = new Uint8Array(new Uint32Array([I.length]).buffer);
|
|
2189
|
+
p.set(_, d), d += Xt, p.set(I, d), d += I.length;
|
|
2132
2190
|
}
|
|
2133
2191
|
h(p);
|
|
2134
2192
|
});
|
|
2135
2193
|
s.push(u);
|
|
2136
2194
|
} else
|
|
2137
2195
|
s.push(c.data());
|
|
2138
|
-
t != null && (l.group = t),
|
|
2196
|
+
t != null && (l.group = t), n.push(l);
|
|
2139
2197
|
}
|
|
2140
2198
|
const a = await Promise.all(s);
|
|
2141
|
-
return { data:
|
|
2199
|
+
return { data: vn(a), specs: n };
|
|
2142
2200
|
}
|
|
2143
|
-
function
|
|
2144
|
-
if (
|
|
2145
|
-
throw new Error(`Invalid input value: ${JSON.stringify(
|
|
2201
|
+
function vn(e) {
|
|
2202
|
+
if (e === null)
|
|
2203
|
+
throw new Error(`Invalid input value: ${JSON.stringify(e)}`);
|
|
2146
2204
|
let t = 0;
|
|
2147
|
-
const
|
|
2148
|
-
|
|
2149
|
-
if (t += a.byteLength,
|
|
2205
|
+
const n = [];
|
|
2206
|
+
e.forEach((a) => {
|
|
2207
|
+
if (t += a.byteLength, n.push(a.byteLength === a.buffer.byteLength ? a : new a.constructor(a)), !(a instanceof Float32Array || a instanceof Int32Array || a instanceof Uint8Array))
|
|
2150
2208
|
throw new Error(`Unsupported TypedArray subtype: ${a.constructor.name}`);
|
|
2151
2209
|
});
|
|
2152
2210
|
const s = new Uint8Array(t);
|
|
2153
2211
|
let r = 0;
|
|
2154
|
-
return
|
|
2212
|
+
return n.forEach((a) => {
|
|
2155
2213
|
s.set(new Uint8Array(a.buffer), r), r += a.byteLength;
|
|
2156
2214
|
}), s.buffer;
|
|
2157
2215
|
}
|
|
2158
|
-
const
|
|
2159
|
-
function
|
|
2160
|
-
return
|
|
2216
|
+
const _t = typeof mt < "u" && (typeof Blob > "u" || typeof atob > "u" || typeof btoa > "u");
|
|
2217
|
+
function Yt(e) {
|
|
2218
|
+
return _t ? mt.byteLength(e, "utf8") : new Blob([e]).size;
|
|
2161
2219
|
}
|
|
2162
|
-
function
|
|
2163
|
-
if (
|
|
2164
|
-
return
|
|
2165
|
-
const t = new Uint8Array(
|
|
2166
|
-
let
|
|
2220
|
+
function Mn(e) {
|
|
2221
|
+
if (_t)
|
|
2222
|
+
return mt.from(e).toString("base64");
|
|
2223
|
+
const t = new Uint8Array(e);
|
|
2224
|
+
let n = "";
|
|
2167
2225
|
for (let s = 0, r = t.length; s < r; s++)
|
|
2168
|
-
|
|
2169
|
-
return btoa(
|
|
2226
|
+
n += String.fromCharCode(t[s]);
|
|
2227
|
+
return btoa(n);
|
|
2170
2228
|
}
|
|
2171
|
-
function
|
|
2172
|
-
if (
|
|
2173
|
-
const s =
|
|
2229
|
+
function Nn(e) {
|
|
2230
|
+
if (_t) {
|
|
2231
|
+
const s = mt.from(e, "base64");
|
|
2174
2232
|
return s.buffer.slice(s.byteOffset, s.byteOffset + s.byteLength);
|
|
2175
2233
|
}
|
|
2176
|
-
const t = atob(
|
|
2234
|
+
const t = atob(e), n = new Uint8Array(t.length);
|
|
2177
2235
|
for (let s = 0; s < t.length; ++s)
|
|
2178
|
-
|
|
2179
|
-
return
|
|
2236
|
+
n.set([t.charCodeAt(s)], s);
|
|
2237
|
+
return n.buffer;
|
|
2180
2238
|
}
|
|
2181
|
-
function
|
|
2182
|
-
return st.join(
|
|
2239
|
+
function wo(e) {
|
|
2240
|
+
return st.join(e);
|
|
2183
2241
|
}
|
|
2184
|
-
function
|
|
2185
|
-
if (
|
|
2242
|
+
function Se(e) {
|
|
2243
|
+
if (e.modelTopology instanceof ArrayBuffer)
|
|
2186
2244
|
throw new Error("Expected JSON model topology, received ArrayBuffer.");
|
|
2187
2245
|
return {
|
|
2188
2246
|
dateSaved: /* @__PURE__ */ new Date(),
|
|
2189
2247
|
modelTopologyType: "JSON",
|
|
2190
|
-
modelTopologyBytes:
|
|
2191
|
-
weightSpecsBytes:
|
|
2192
|
-
weightDataBytes:
|
|
2248
|
+
modelTopologyBytes: e.modelTopology == null ? 0 : Yt(JSON.stringify(e.modelTopology)),
|
|
2249
|
+
weightSpecsBytes: e.weightSpecs == null ? 0 : Yt(JSON.stringify(e.weightSpecs)),
|
|
2250
|
+
weightDataBytes: e.weightData == null ? 0 : new st(e.weightData).byteLength
|
|
2193
2251
|
};
|
|
2194
2252
|
}
|
|
2195
2253
|
/**
|
|
@@ -2252,18 +2310,18 @@ class A {
|
|
|
2252
2310
|
* @returns All valid handlers for `url`, given the currently registered
|
|
2253
2311
|
* handler routers.
|
|
2254
2312
|
*/
|
|
2255
|
-
static getLoadHandlers(t,
|
|
2256
|
-
return A.getHandlers(t, "load",
|
|
2313
|
+
static getLoadHandlers(t, n) {
|
|
2314
|
+
return A.getHandlers(t, "load", n);
|
|
2257
2315
|
}
|
|
2258
|
-
static getHandlers(t,
|
|
2316
|
+
static getHandlers(t, n, s) {
|
|
2259
2317
|
const r = [];
|
|
2260
|
-
return (
|
|
2318
|
+
return (n === "load" ? A.getInstance().loadRouters : A.getInstance().saveRouters).forEach((o) => {
|
|
2261
2319
|
const i = o(t, s);
|
|
2262
2320
|
i !== null && r.push(i);
|
|
2263
2321
|
}), r;
|
|
2264
2322
|
}
|
|
2265
2323
|
}
|
|
2266
|
-
const
|
|
2324
|
+
const So = (e) => A.getSaveHandlers(e);
|
|
2267
2325
|
/**
|
|
2268
2326
|
* @license
|
|
2269
2327
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -2280,22 +2338,22 @@ const ho = (n) => A.getSaveHandlers(n);
|
|
|
2280
2338
|
* limitations under the License.
|
|
2281
2339
|
* =============================================================================
|
|
2282
2340
|
*/
|
|
2283
|
-
const vt = "tensorflowjs", Mt = 1,
|
|
2284
|
-
function
|
|
2341
|
+
const vt = "tensorflowjs", Mt = 1, U = "models_store", L = "model_info_store";
|
|
2342
|
+
function ke() {
|
|
2285
2343
|
if (!k().getBool("IS_BROWSER"))
|
|
2286
2344
|
throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");
|
|
2287
|
-
const
|
|
2345
|
+
const e = typeof window > "u" ? self : window, t = e.indexedDB || e.mozIndexedDB || e.webkitIndexedDB || e.msIndexedDB || e.shimIndexedDB;
|
|
2288
2346
|
if (t == null)
|
|
2289
2347
|
throw new Error("The current browser does not appear to support IndexedDB.");
|
|
2290
2348
|
return t;
|
|
2291
2349
|
}
|
|
2292
|
-
function Nt(
|
|
2293
|
-
const t =
|
|
2294
|
-
t.createObjectStore(
|
|
2350
|
+
function Nt(e) {
|
|
2351
|
+
const t = e.result;
|
|
2352
|
+
t.createObjectStore(U, { keyPath: "modelPath" }), t.createObjectStore(L, { keyPath: "modelPath" });
|
|
2295
2353
|
}
|
|
2296
2354
|
class W {
|
|
2297
2355
|
constructor(t) {
|
|
2298
|
-
if (this.indexedDB =
|
|
2356
|
+
if (this.indexedDB = ke(), t == null || !t)
|
|
2299
2357
|
throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");
|
|
2300
2358
|
this.modelPath = t;
|
|
2301
2359
|
}
|
|
@@ -2321,36 +2379,36 @@ class W {
|
|
|
2321
2379
|
* @returns A `Promise` of `SaveResult`, if the action is put, or a `Promise`
|
|
2322
2380
|
* of `ModelArtifacts`, if the action is get.
|
|
2323
2381
|
*/
|
|
2324
|
-
databaseAction(t,
|
|
2382
|
+
databaseAction(t, n) {
|
|
2325
2383
|
return new Promise((s, r) => {
|
|
2326
2384
|
const a = this.indexedDB.open(vt, Mt);
|
|
2327
2385
|
a.onupgradeneeded = () => Nt(a), a.onsuccess = () => {
|
|
2328
2386
|
const o = a.result;
|
|
2329
|
-
if (
|
|
2330
|
-
const i = o.transaction(
|
|
2387
|
+
if (n == null) {
|
|
2388
|
+
const i = o.transaction(U, "readonly"), l = i.objectStore(U).get(this.modelPath);
|
|
2331
2389
|
l.onsuccess = () => {
|
|
2332
2390
|
if (l.result == null)
|
|
2333
2391
|
return o.close(), r(new Error(`Cannot find model with path '${this.modelPath}' in IndexedDB.`));
|
|
2334
2392
|
s(l.result.modelArtifacts);
|
|
2335
2393
|
}, l.onerror = (u) => (o.close(), r(l.error)), i.oncomplete = () => o.close();
|
|
2336
2394
|
} else {
|
|
2337
|
-
|
|
2338
|
-
const i =
|
|
2395
|
+
n.weightData = st.join(n.weightData);
|
|
2396
|
+
const i = Se(n), c = o.transaction(L, "readwrite");
|
|
2339
2397
|
let l = c.objectStore(L), u;
|
|
2340
2398
|
try {
|
|
2341
2399
|
u = l.put({ modelPath: this.modelPath, modelArtifactsInfo: i });
|
|
2342
|
-
} catch (
|
|
2343
|
-
return r(
|
|
2400
|
+
} catch (f) {
|
|
2401
|
+
return r(f);
|
|
2344
2402
|
}
|
|
2345
2403
|
let h;
|
|
2346
2404
|
u.onsuccess = () => {
|
|
2347
|
-
h = o.transaction(
|
|
2348
|
-
const
|
|
2405
|
+
h = o.transaction(U, "readwrite");
|
|
2406
|
+
const f = h.objectStore(U);
|
|
2349
2407
|
let m;
|
|
2350
2408
|
try {
|
|
2351
|
-
m =
|
|
2409
|
+
m = f.put({
|
|
2352
2410
|
modelPath: this.modelPath,
|
|
2353
|
-
modelArtifacts:
|
|
2411
|
+
modelArtifacts: n,
|
|
2354
2412
|
modelArtifactsInfo: i
|
|
2355
2413
|
});
|
|
2356
2414
|
} catch (p) {
|
|
@@ -2358,10 +2416,10 @@ class W {
|
|
|
2358
2416
|
}
|
|
2359
2417
|
m.onsuccess = () => s({ modelArtifactsInfo: i }), m.onerror = (p) => {
|
|
2360
2418
|
l = c.objectStore(L);
|
|
2361
|
-
const
|
|
2362
|
-
|
|
2419
|
+
const d = l.delete(this.modelPath);
|
|
2420
|
+
d.onsuccess = () => (o.close(), r(m.error)), d.onerror = (w) => (o.close(), r(m.error));
|
|
2363
2421
|
};
|
|
2364
|
-
}, u.onerror = (
|
|
2422
|
+
}, u.onerror = (f) => (o.close(), r(u.error)), c.oncomplete = () => {
|
|
2365
2423
|
h == null ? o.close() : h.oncomplete = () => o.close();
|
|
2366
2424
|
};
|
|
2367
2425
|
}
|
|
@@ -2370,21 +2428,21 @@ class W {
|
|
|
2370
2428
|
}
|
|
2371
2429
|
}
|
|
2372
2430
|
W.URL_SCHEME = "indexeddb://";
|
|
2373
|
-
const
|
|
2374
|
-
A.registerSaveRouter(
|
|
2375
|
-
A.registerLoadRouter(
|
|
2376
|
-
function
|
|
2377
|
-
return new W(
|
|
2431
|
+
const Ie = (e) => k().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(W.URL_SCHEME) ? Fn(e.slice(W.URL_SCHEME.length)) : null;
|
|
2432
|
+
A.registerSaveRouter(Ie);
|
|
2433
|
+
A.registerLoadRouter(Ie);
|
|
2434
|
+
function Fn(e) {
|
|
2435
|
+
return new W(e);
|
|
2378
2436
|
}
|
|
2379
|
-
function
|
|
2380
|
-
return
|
|
2437
|
+
function Rn(e) {
|
|
2438
|
+
return e.startsWith(W.URL_SCHEME) ? e.slice(W.URL_SCHEME.length) : e;
|
|
2381
2439
|
}
|
|
2382
|
-
class
|
|
2440
|
+
class Dn {
|
|
2383
2441
|
constructor() {
|
|
2384
|
-
this.indexedDB =
|
|
2442
|
+
this.indexedDB = ke();
|
|
2385
2443
|
}
|
|
2386
2444
|
async listModels() {
|
|
2387
|
-
return new Promise((t,
|
|
2445
|
+
return new Promise((t, n) => {
|
|
2388
2446
|
const s = this.indexedDB.open(vt, Mt);
|
|
2389
2447
|
s.onupgradeneeded = () => Nt(s), s.onsuccess = () => {
|
|
2390
2448
|
const r = s.result, a = r.transaction(L, "readonly"), i = a.objectStore(L).getAll();
|
|
@@ -2393,12 +2451,12 @@ class Rn {
|
|
|
2393
2451
|
for (const l of i.result)
|
|
2394
2452
|
c[l.modelPath] = l.modelArtifactsInfo;
|
|
2395
2453
|
t(c);
|
|
2396
|
-
}, i.onerror = (c) => (r.close(),
|
|
2397
|
-
}, s.onerror = (r) =>
|
|
2454
|
+
}, i.onerror = (c) => (r.close(), n(i.error)), a.oncomplete = () => r.close();
|
|
2455
|
+
}, s.onerror = (r) => n(s.error);
|
|
2398
2456
|
});
|
|
2399
2457
|
}
|
|
2400
2458
|
async removeModel(t) {
|
|
2401
|
-
return t =
|
|
2459
|
+
return t = Rn(t), new Promise((n, s) => {
|
|
2402
2460
|
const r = this.indexedDB.open(vt, Mt);
|
|
2403
2461
|
r.onupgradeneeded = () => Nt(r), r.onsuccess = () => {
|
|
2404
2462
|
const a = r.result, o = a.transaction(L, "readwrite"), i = o.objectStore(L), c = i.get(t);
|
|
@@ -2408,11 +2466,11 @@ class Rn {
|
|
|
2408
2466
|
return a.close(), s(new Error(`Cannot find model with path '${t}' in IndexedDB.`));
|
|
2409
2467
|
{
|
|
2410
2468
|
const u = i.delete(t), h = () => {
|
|
2411
|
-
l = a.transaction(
|
|
2412
|
-
const m = l.objectStore(
|
|
2413
|
-
m.onsuccess = () =>
|
|
2469
|
+
l = a.transaction(U, "readwrite");
|
|
2470
|
+
const m = l.objectStore(U).delete(t);
|
|
2471
|
+
m.onsuccess = () => n(c.result.modelArtifactsInfo), m.onerror = (p) => s(c.error);
|
|
2414
2472
|
};
|
|
2415
|
-
u.onsuccess = h, u.onerror = (
|
|
2473
|
+
u.onsuccess = h, u.onerror = (f) => (h(), a.close(), s(c.error));
|
|
2416
2474
|
}
|
|
2417
2475
|
}, c.onerror = (u) => (a.close(), s(c.error)), o.oncomplete = () => {
|
|
2418
2476
|
l == null ? a.close() : l.oncomplete = () => a.close();
|
|
@@ -2437,28 +2495,28 @@ class Rn {
|
|
|
2437
2495
|
* limitations under the License.
|
|
2438
2496
|
* =============================================================================
|
|
2439
2497
|
*/
|
|
2440
|
-
const P = "/", Q = "tensorflowjs_models",
|
|
2441
|
-
function
|
|
2498
|
+
const P = "/", Q = "tensorflowjs_models", Te = "info", $n = "model_topology", xn = "weight_specs", Cn = "weight_data", Pn = "model_metadata";
|
|
2499
|
+
function Ee(e) {
|
|
2442
2500
|
return {
|
|
2443
|
-
info: [Q,
|
|
2444
|
-
topology: [Q,
|
|
2445
|
-
weightSpecs: [Q,
|
|
2446
|
-
weightData: [Q,
|
|
2447
|
-
modelMetadata: [Q,
|
|
2501
|
+
info: [Q, e, Te].join(P),
|
|
2502
|
+
topology: [Q, e, $n].join(P),
|
|
2503
|
+
weightSpecs: [Q, e, xn].join(P),
|
|
2504
|
+
weightData: [Q, e, Cn].join(P),
|
|
2505
|
+
modelMetadata: [Q, e, Pn].join(P)
|
|
2448
2506
|
};
|
|
2449
2507
|
}
|
|
2450
|
-
function
|
|
2451
|
-
for (const t of Object.values(
|
|
2508
|
+
function Ae(e) {
|
|
2509
|
+
for (const t of Object.values(e))
|
|
2452
2510
|
window.localStorage.removeItem(t);
|
|
2453
2511
|
}
|
|
2454
|
-
function
|
|
2455
|
-
const t =
|
|
2512
|
+
function Ln(e) {
|
|
2513
|
+
const t = e.split(P);
|
|
2456
2514
|
if (t.length < 3)
|
|
2457
|
-
throw new Error(`Invalid key format: ${
|
|
2515
|
+
throw new Error(`Invalid key format: ${e}`);
|
|
2458
2516
|
return t.slice(1, t.length - 1).join(P);
|
|
2459
2517
|
}
|
|
2460
|
-
function
|
|
2461
|
-
return
|
|
2518
|
+
function _n(e) {
|
|
2519
|
+
return e.startsWith(j.URL_SCHEME) ? e.slice(j.URL_SCHEME.length) : e;
|
|
2462
2520
|
}
|
|
2463
2521
|
class j {
|
|
2464
2522
|
constructor(t) {
|
|
@@ -2466,7 +2524,7 @@ class j {
|
|
|
2466
2524
|
throw new Error("The current environment does not support local storage.");
|
|
2467
2525
|
if (this.LS = window.localStorage, t == null || !t)
|
|
2468
2526
|
throw new Error("For local storage, modelPath must not be null, undefined or empty.");
|
|
2469
|
-
this.modelPath = t, this.keys =
|
|
2527
|
+
this.modelPath = t, this.keys = Ee(this.modelPath);
|
|
2470
2528
|
}
|
|
2471
2529
|
/**
|
|
2472
2530
|
* Save model artifacts to browser local storage.
|
|
@@ -2481,9 +2539,9 @@ class j {
|
|
|
2481
2539
|
if (t.modelTopology instanceof ArrayBuffer)
|
|
2482
2540
|
throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
|
|
2483
2541
|
{
|
|
2484
|
-
const
|
|
2542
|
+
const n = JSON.stringify(t.modelTopology), s = JSON.stringify(t.weightSpecs), r = Se(t), a = st.join(t.weightData);
|
|
2485
2543
|
try {
|
|
2486
|
-
this.LS.setItem(this.keys.info, JSON.stringify(r)), this.LS.setItem(this.keys.topology,
|
|
2544
|
+
this.LS.setItem(this.keys.info, JSON.stringify(r)), this.LS.setItem(this.keys.topology, n), this.LS.setItem(this.keys.weightSpecs, s), this.LS.setItem(this.keys.weightData, Mn(a));
|
|
2487
2545
|
const o = {
|
|
2488
2546
|
format: t.format,
|
|
2489
2547
|
generatedBy: t.generatedBy,
|
|
@@ -2496,7 +2554,7 @@ class j {
|
|
|
2496
2554
|
};
|
|
2497
2555
|
return this.LS.setItem(this.keys.modelMetadata, JSON.stringify(o)), { modelArtifactsInfo: r };
|
|
2498
2556
|
} catch {
|
|
2499
|
-
throw
|
|
2557
|
+
throw Ae(this.keys), new Error(`Failed to save model '${this.modelPath}' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=${r.modelTopologyBytes}, weightSpecsBytes=${r.weightSpecsBytes}, weightDataBytes=${r.weightDataBytes}.`);
|
|
2500
2558
|
}
|
|
2501
2559
|
}
|
|
2502
2560
|
}
|
|
@@ -2514,54 +2572,54 @@ class j {
|
|
|
2514
2572
|
throw new Error(`In local storage, there is no model with name '${this.modelPath}'`);
|
|
2515
2573
|
if (t.modelTopologyType !== "JSON")
|
|
2516
2574
|
throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");
|
|
2517
|
-
const
|
|
2575
|
+
const n = {}, s = JSON.parse(this.LS.getItem(this.keys.topology));
|
|
2518
2576
|
if (s == null)
|
|
2519
2577
|
throw new Error(`In local storage, the topology of model '${this.modelPath}' is missing.`);
|
|
2520
|
-
|
|
2578
|
+
n.modelTopology = s;
|
|
2521
2579
|
const r = JSON.parse(this.LS.getItem(this.keys.weightSpecs));
|
|
2522
2580
|
if (r == null)
|
|
2523
2581
|
throw new Error(`In local storage, the weight specs of model '${this.modelPath}' are missing.`);
|
|
2524
|
-
|
|
2582
|
+
n.weightSpecs = r;
|
|
2525
2583
|
const a = this.LS.getItem(this.keys.modelMetadata);
|
|
2526
2584
|
if (a != null) {
|
|
2527
2585
|
const i = JSON.parse(a);
|
|
2528
|
-
|
|
2586
|
+
n.format = i.format, n.generatedBy = i.generatedBy, n.convertedBy = i.convertedBy, i.signature != null && (n.signature = i.signature), i.userDefinedMetadata != null && (n.userDefinedMetadata = i.userDefinedMetadata), i.modelInitializer != null && (n.modelInitializer = i.modelInitializer), i.initializerSignature != null && (n.initializerSignature = i.initializerSignature), i.trainingConfig != null && (n.trainingConfig = i.trainingConfig);
|
|
2529
2587
|
}
|
|
2530
2588
|
const o = this.LS.getItem(this.keys.weightData);
|
|
2531
2589
|
if (o == null)
|
|
2532
2590
|
throw new Error(`In local storage, the binary weight values of model '${this.modelPath}' are missing.`);
|
|
2533
|
-
return
|
|
2591
|
+
return n.weightData = Nn(o), n;
|
|
2534
2592
|
}
|
|
2535
2593
|
}
|
|
2536
2594
|
j.URL_SCHEME = "localstorage://";
|
|
2537
|
-
const
|
|
2538
|
-
A.registerSaveRouter(
|
|
2539
|
-
A.registerLoadRouter(
|
|
2540
|
-
function
|
|
2541
|
-
return new j(
|
|
2595
|
+
const Be = (e) => k().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(j.URL_SCHEME) ? On(e.slice(j.URL_SCHEME.length)) : null;
|
|
2596
|
+
A.registerSaveRouter(Be);
|
|
2597
|
+
A.registerLoadRouter(Be);
|
|
2598
|
+
function On(e) {
|
|
2599
|
+
return new j(e);
|
|
2542
2600
|
}
|
|
2543
|
-
class
|
|
2601
|
+
class Gn {
|
|
2544
2602
|
constructor() {
|
|
2545
2603
|
y(k().getBool("IS_BROWSER"), () => "Current environment is not a web browser"), y(typeof window > "u" || typeof window.localStorage < "u", () => "Current browser does not appear to support localStorage"), this.LS = window.localStorage;
|
|
2546
2604
|
}
|
|
2547
2605
|
async listModels() {
|
|
2548
|
-
const t = {},
|
|
2606
|
+
const t = {}, n = Q + P, s = P + Te;
|
|
2549
2607
|
for (let r = 0; r < this.LS.length; ++r) {
|
|
2550
2608
|
const a = this.LS.key(r);
|
|
2551
|
-
if (a.startsWith(
|
|
2552
|
-
const o =
|
|
2609
|
+
if (a.startsWith(n) && a.endsWith(s)) {
|
|
2610
|
+
const o = Ln(a);
|
|
2553
2611
|
t[o] = JSON.parse(this.LS.getItem(a));
|
|
2554
2612
|
}
|
|
2555
2613
|
}
|
|
2556
2614
|
return t;
|
|
2557
2615
|
}
|
|
2558
2616
|
async removeModel(t) {
|
|
2559
|
-
t =
|
|
2560
|
-
const
|
|
2561
|
-
if (this.LS.getItem(
|
|
2617
|
+
t = _n(t);
|
|
2618
|
+
const n = Ee(t);
|
|
2619
|
+
if (this.LS.getItem(n.info) == null)
|
|
2562
2620
|
throw new Error(`Cannot find model at path '${t}'`);
|
|
2563
|
-
const s = JSON.parse(this.LS.getItem(
|
|
2564
|
-
return
|
|
2621
|
+
const s = JSON.parse(this.LS.getItem(n.info));
|
|
2622
|
+
return Ae(n), s;
|
|
2565
2623
|
}
|
|
2566
2624
|
}
|
|
2567
2625
|
/**
|
|
@@ -2580,7 +2638,7 @@ class On {
|
|
|
2580
2638
|
* limitations under the License.
|
|
2581
2639
|
* =============================================================================
|
|
2582
2640
|
*/
|
|
2583
|
-
const
|
|
2641
|
+
const Qt = "://";
|
|
2584
2642
|
class $ {
|
|
2585
2643
|
constructor() {
|
|
2586
2644
|
this.managers = {};
|
|
@@ -2594,16 +2652,16 @@ class $ {
|
|
|
2594
2652
|
* @param saveRouter A function that maps a URL-like string onto an instance
|
|
2595
2653
|
* of `IOHandler` with the `save` method defined or `null`.
|
|
2596
2654
|
*/
|
|
2597
|
-
static registerManager(t,
|
|
2598
|
-
y(t != null, () => "scheme must not be undefined or null."), t.endsWith(
|
|
2655
|
+
static registerManager(t, n) {
|
|
2656
|
+
y(t != null, () => "scheme must not be undefined or null."), t.endsWith(Qt) && (t = t.slice(0, t.indexOf(Qt))), y(t.length > 0, () => "scheme must not be an empty string.");
|
|
2599
2657
|
const s = $.getInstance();
|
|
2600
|
-
y(s.managers[t] == null, () => `A model store manager is already registered for scheme '${t}'.`), s.managers[t] =
|
|
2658
|
+
y(s.managers[t] == null, () => `A model store manager is already registered for scheme '${t}'.`), s.managers[t] = n;
|
|
2601
2659
|
}
|
|
2602
2660
|
static getManager(t) {
|
|
2603
|
-
const
|
|
2604
|
-
if (
|
|
2661
|
+
const n = $.getInstance().managers[t];
|
|
2662
|
+
if (n == null)
|
|
2605
2663
|
throw new Error(`Cannot find model manager for scheme '${t}'`);
|
|
2606
|
-
return
|
|
2664
|
+
return n;
|
|
2607
2665
|
}
|
|
2608
2666
|
static getSchemes() {
|
|
2609
2667
|
return Object.keys($.getInstance().managers);
|
|
@@ -2625,36 +2683,36 @@ class $ {
|
|
|
2625
2683
|
* limitations under the License.
|
|
2626
2684
|
* =============================================================================
|
|
2627
2685
|
*/
|
|
2628
|
-
class
|
|
2686
|
+
class Un {
|
|
2629
2687
|
constructor() {
|
|
2630
2688
|
this.messageName = "setTimeoutCustom", this.functionRefs = [], this.handledMessageCount = 0, this.hasEventListener = !1;
|
|
2631
2689
|
}
|
|
2632
|
-
fetch(t,
|
|
2633
|
-
return fetch(t,
|
|
2690
|
+
fetch(t, n) {
|
|
2691
|
+
return fetch(t, n);
|
|
2634
2692
|
}
|
|
2635
2693
|
now() {
|
|
2636
2694
|
return performance.now();
|
|
2637
2695
|
}
|
|
2638
|
-
encode(t,
|
|
2639
|
-
if (
|
|
2640
|
-
throw new Error(`Browser's encoder only supports utf-8, but got ${
|
|
2696
|
+
encode(t, n) {
|
|
2697
|
+
if (n !== "utf-8" && n !== "utf8")
|
|
2698
|
+
throw new Error(`Browser's encoder only supports utf-8, but got ${n}`);
|
|
2641
2699
|
return this.textEncoder == null && (this.textEncoder = new TextEncoder()), this.textEncoder.encode(t);
|
|
2642
2700
|
}
|
|
2643
|
-
decode(t,
|
|
2644
|
-
return new TextDecoder(
|
|
2701
|
+
decode(t, n) {
|
|
2702
|
+
return new TextDecoder(n).decode(t);
|
|
2645
2703
|
}
|
|
2646
2704
|
// If the setTimeout nesting level is greater than 5 and timeout is less
|
|
2647
2705
|
// than 4ms, timeout will be clamped to 4ms, which hurts the perf.
|
|
2648
2706
|
// Interleaving window.postMessage and setTimeout will trick the browser and
|
|
2649
2707
|
// avoid the clamp.
|
|
2650
|
-
setTimeoutCustom(t,
|
|
2708
|
+
setTimeoutCustom(t, n) {
|
|
2651
2709
|
if (typeof window > "u" || !k().getBool("USE_SETTIMEOUTCUSTOM")) {
|
|
2652
|
-
setTimeout(t,
|
|
2710
|
+
setTimeout(t, n);
|
|
2653
2711
|
return;
|
|
2654
2712
|
}
|
|
2655
2713
|
this.functionRefs.push(t), setTimeout(() => {
|
|
2656
2714
|
window.postMessage({ name: this.messageName, index: this.functionRefs.length - 1 }, "*");
|
|
2657
|
-
},
|
|
2715
|
+
}, n), this.hasEventListener || (this.hasEventListener = !0, window.addEventListener("message", (s) => {
|
|
2658
2716
|
if (s.source === window && s.data.name === this.messageName) {
|
|
2659
2717
|
s.stopPropagation();
|
|
2660
2718
|
const r = this.functionRefs[s.data.index];
|
|
@@ -2663,49 +2721,49 @@ class _n {
|
|
|
2663
2721
|
}, !0));
|
|
2664
2722
|
}
|
|
2665
2723
|
isTypedArray(t) {
|
|
2666
|
-
return
|
|
2724
|
+
return le(t);
|
|
2667
2725
|
}
|
|
2668
2726
|
}
|
|
2669
2727
|
if (k().get("IS_BROWSER")) {
|
|
2670
|
-
k().setPlatform("browser", new
|
|
2728
|
+
k().setPlatform("browser", new Un());
|
|
2671
2729
|
try {
|
|
2672
|
-
$.registerManager(j.URL_SCHEME, new
|
|
2730
|
+
$.registerManager(j.URL_SCHEME, new Gn());
|
|
2673
2731
|
} catch {
|
|
2674
2732
|
}
|
|
2675
2733
|
try {
|
|
2676
|
-
$.registerManager(W.URL_SCHEME, new
|
|
2734
|
+
$.registerManager(W.URL_SCHEME, new Dn());
|
|
2677
2735
|
} catch {
|
|
2678
2736
|
}
|
|
2679
2737
|
}
|
|
2680
|
-
const
|
|
2738
|
+
const zn = {
|
|
2681
2739
|
// tslint:disable-next-line:no-require-imports
|
|
2682
2740
|
importFetch: () => require("node-fetch")
|
|
2683
2741
|
};
|
|
2684
|
-
let
|
|
2685
|
-
class
|
|
2742
|
+
let St;
|
|
2743
|
+
class Vn {
|
|
2686
2744
|
constructor() {
|
|
2687
2745
|
this.util = require("util"), this.textEncoder = new this.util.TextEncoder();
|
|
2688
2746
|
}
|
|
2689
|
-
fetch(t,
|
|
2690
|
-
return k().global.fetch != null ? k().global.fetch(t,
|
|
2747
|
+
fetch(t, n) {
|
|
2748
|
+
return k().global.fetch != null ? k().global.fetch(t, n) : (St == null && (St = zn.importFetch()), St(t, n));
|
|
2691
2749
|
}
|
|
2692
2750
|
now() {
|
|
2693
2751
|
const t = Z.hrtime();
|
|
2694
2752
|
return t[0] * 1e3 + t[1] / 1e6;
|
|
2695
2753
|
}
|
|
2696
|
-
encode(t,
|
|
2697
|
-
if (
|
|
2698
|
-
throw new Error(`Node built-in encoder only supports utf-8, but got ${
|
|
2754
|
+
encode(t, n) {
|
|
2755
|
+
if (n !== "utf-8" && n !== "utf8")
|
|
2756
|
+
throw new Error(`Node built-in encoder only supports utf-8, but got ${n}`);
|
|
2699
2757
|
return this.textEncoder.encode(t);
|
|
2700
2758
|
}
|
|
2701
|
-
decode(t,
|
|
2702
|
-
return t.length === 0 ? "" : new this.util.TextDecoder(
|
|
2759
|
+
decode(t, n) {
|
|
2760
|
+
return t.length === 0 ? "" : new this.util.TextDecoder(n).decode(t);
|
|
2703
2761
|
}
|
|
2704
2762
|
isTypedArray(t) {
|
|
2705
2763
|
return this.util.types.isFloat32Array(t) || this.util.types.isInt32Array(t) || this.util.types.isUint8Array(t) || this.util.types.isUint8ClampedArray(t);
|
|
2706
2764
|
}
|
|
2707
2765
|
}
|
|
2708
|
-
k().get("IS_NODE") && !k().get("IS_BROWSER") && k().setPlatform("node", new
|
|
2766
|
+
k().get("IS_NODE") && !k().get("IS_BROWSER") && k().setPlatform("node", new Vn());
|
|
2709
2767
|
/**
|
|
2710
2768
|
* @license
|
|
2711
2769
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
@@ -2722,8 +2780,8 @@ k().get("IS_NODE") && !k().get("IS_BROWSER") && k().setPlatform("node", new Gn()
|
|
|
2722
2780
|
* limitations under the License.
|
|
2723
2781
|
* =============================================================================
|
|
2724
2782
|
*/
|
|
2725
|
-
function
|
|
2726
|
-
return t = t || "float32", xt(
|
|
2783
|
+
function Wn(e, t = "float32", n) {
|
|
2784
|
+
return t = t || "float32", xt(e), new dn(e, t, n);
|
|
2727
2785
|
}
|
|
2728
2786
|
/**
|
|
2729
2787
|
* @license
|
|
@@ -2741,16 +2799,16 @@ function zn(n, t = "float32", e) {
|
|
|
2741
2799
|
* limitations under the License.
|
|
2742
2800
|
* =============================================================================
|
|
2743
2801
|
*/
|
|
2744
|
-
function
|
|
2745
|
-
const
|
|
2746
|
-
if (
|
|
2802
|
+
function jn(e, t) {
|
|
2803
|
+
const n = T(e, "x", "cast");
|
|
2804
|
+
if (!Pe(t))
|
|
2747
2805
|
throw new Error(`Failed to cast to unknown dtype ${t}`);
|
|
2748
|
-
if (t === "string" &&
|
|
2806
|
+
if (t === "string" && n.dtype !== "string" || t !== "string" && n.dtype === "string")
|
|
2749
2807
|
throw new Error("Only strings can be casted to strings");
|
|
2750
|
-
const s = { x:
|
|
2751
|
-
return g.runKernel(
|
|
2808
|
+
const s = { x: n }, r = { dtype: t };
|
|
2809
|
+
return g.runKernel(oe, s, r);
|
|
2752
2810
|
}
|
|
2753
|
-
const
|
|
2811
|
+
const Ft = /* @__PURE__ */ N({ cast_: jn });
|
|
2754
2812
|
/**
|
|
2755
2813
|
* @license
|
|
2756
2814
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2767,11 +2825,11 @@ const Rt = /* @__PURE__ */ N({ cast_: Vn });
|
|
|
2767
2825
|
* limitations under the License.
|
|
2768
2826
|
* =============================================================================
|
|
2769
2827
|
*/
|
|
2770
|
-
function
|
|
2771
|
-
const
|
|
2772
|
-
return g.runKernel(
|
|
2828
|
+
function Kn(e) {
|
|
2829
|
+
const n = { x: T(e, "x", "clone", "string_or_numeric") };
|
|
2830
|
+
return g.runKernel(ie, n);
|
|
2773
2831
|
}
|
|
2774
|
-
const
|
|
2832
|
+
const qn = /* @__PURE__ */ N({ clone_: Kn });
|
|
2775
2833
|
/**
|
|
2776
2834
|
* @license
|
|
2777
2835
|
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
@@ -2788,8 +2846,8 @@ const jn = /* @__PURE__ */ N({ clone_: Wn });
|
|
|
2788
2846
|
* limitations under the License.
|
|
2789
2847
|
* =============================================================================
|
|
2790
2848
|
*/
|
|
2791
|
-
function
|
|
2792
|
-
console.log(
|
|
2849
|
+
function Hn(e, t = !1) {
|
|
2850
|
+
console.log(e.toString(t));
|
|
2793
2851
|
}
|
|
2794
2852
|
/**
|
|
2795
2853
|
* @license
|
|
@@ -2807,14 +2865,14 @@ function Kn(n, t = !1) {
|
|
|
2807
2865
|
* limitations under the License.
|
|
2808
2866
|
* =============================================================================
|
|
2809
2867
|
*/
|
|
2810
|
-
|
|
2811
|
-
const
|
|
2812
|
-
buffer:
|
|
2813
|
-
cast:
|
|
2814
|
-
clone:
|
|
2815
|
-
print:
|
|
2868
|
+
be();
|
|
2869
|
+
const Jn = {
|
|
2870
|
+
buffer: Wn,
|
|
2871
|
+
cast: Ft,
|
|
2872
|
+
clone: qn,
|
|
2873
|
+
print: Hn
|
|
2816
2874
|
};
|
|
2817
|
-
|
|
2875
|
+
mn(Jn);
|
|
2818
2876
|
/**
|
|
2819
2877
|
* @license
|
|
2820
2878
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2831,13 +2889,13 @@ fn(qn);
|
|
|
2831
2889
|
* limitations under the License.
|
|
2832
2890
|
* =============================================================================
|
|
2833
2891
|
*/
|
|
2834
|
-
function
|
|
2835
|
-
let
|
|
2836
|
-
[
|
|
2837
|
-
const r = { a:
|
|
2838
|
-
return g.runKernel(
|
|
2892
|
+
function Xn(e, t) {
|
|
2893
|
+
let n = T(e, "a", "add"), s = T(t, "b", "add");
|
|
2894
|
+
[n, s] = q(n, s);
|
|
2895
|
+
const r = { a: n, b: s };
|
|
2896
|
+
return g.runKernel(ae, r);
|
|
2839
2897
|
}
|
|
2840
|
-
const S = /* @__PURE__ */ N({ add_:
|
|
2898
|
+
const S = /* @__PURE__ */ N({ add_: Xn });
|
|
2841
2899
|
/**
|
|
2842
2900
|
* @license
|
|
2843
2901
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2854,13 +2912,13 @@ const S = /* @__PURE__ */ N({ add_: Hn });
|
|
|
2854
2912
|
* limitations under the License.
|
|
2855
2913
|
* =============================================================================
|
|
2856
2914
|
*/
|
|
2857
|
-
function
|
|
2858
|
-
let
|
|
2859
|
-
[
|
|
2860
|
-
const r = { a:
|
|
2861
|
-
return g.runKernel(
|
|
2915
|
+
function Yn(e, t) {
|
|
2916
|
+
let n = T(e, "a", "floorDiv"), s = T(t, "b", "floorDiv");
|
|
2917
|
+
[n, s] = q(n, s);
|
|
2918
|
+
const r = { a: n, b: s };
|
|
2919
|
+
return g.runKernel(Ye, r);
|
|
2862
2920
|
}
|
|
2863
|
-
const
|
|
2921
|
+
const Qn = /* @__PURE__ */ N({ floorDiv_: Yn });
|
|
2864
2922
|
/**
|
|
2865
2923
|
* @license
|
|
2866
2924
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2877,14 +2935,14 @@ const Xn = /* @__PURE__ */ N({ floorDiv_: Jn });
|
|
|
2877
2935
|
* limitations under the License.
|
|
2878
2936
|
* =============================================================================
|
|
2879
2937
|
*/
|
|
2880
|
-
function
|
|
2881
|
-
let
|
|
2882
|
-
if ([
|
|
2883
|
-
return
|
|
2884
|
-
const r = { a:
|
|
2885
|
-
return g.runKernel(
|
|
2886
|
-
}
|
|
2887
|
-
const x = /* @__PURE__ */ N({ div_:
|
|
2938
|
+
function Zn(e, t) {
|
|
2939
|
+
let n = T(e, "a", "div"), s = T(t, "b", "div");
|
|
2940
|
+
if ([n, s] = q(n, s), n.dtype === "int32" && s.dtype === "int32")
|
|
2941
|
+
return Qn(n, s);
|
|
2942
|
+
const r = { a: n, b: s }, a = {};
|
|
2943
|
+
return g.runKernel(Je, r, a);
|
|
2944
|
+
}
|
|
2945
|
+
const x = /* @__PURE__ */ N({ div_: Zn });
|
|
2888
2946
|
/**
|
|
2889
2947
|
* @license
|
|
2890
2948
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2901,13 +2959,13 @@ const x = /* @__PURE__ */ N({ div_: Yn });
|
|
|
2901
2959
|
* limitations under the License.
|
|
2902
2960
|
* =============================================================================
|
|
2903
2961
|
*/
|
|
2904
|
-
function
|
|
2905
|
-
let
|
|
2906
|
-
[
|
|
2907
|
-
const r = { a:
|
|
2908
|
-
return g.runKernel(
|
|
2962
|
+
function ts(e, t) {
|
|
2963
|
+
let n = T(e, "a", "mul"), s = T(t, "b", "mul");
|
|
2964
|
+
[n, s] = q(n, s);
|
|
2965
|
+
const r = { a: n, b: s };
|
|
2966
|
+
return g.runKernel(Ze, r);
|
|
2909
2967
|
}
|
|
2910
|
-
const b = /* @__PURE__ */ N({ mul_:
|
|
2968
|
+
const b = /* @__PURE__ */ N({ mul_: ts });
|
|
2911
2969
|
/**
|
|
2912
2970
|
* @license
|
|
2913
2971
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -2924,17 +2982,17 @@ const b = /* @__PURE__ */ N({ mul_: Qn });
|
|
|
2924
2982
|
* limitations under the License.
|
|
2925
2983
|
* =============================================================================
|
|
2926
2984
|
*/
|
|
2927
|
-
function
|
|
2928
|
-
const t = T(
|
|
2985
|
+
function es(e) {
|
|
2986
|
+
const t = T(e, "x", "abs");
|
|
2929
2987
|
if (t.dtype === "complex64") {
|
|
2930
|
-
const
|
|
2931
|
-
return g.runKernel(
|
|
2988
|
+
const n = { x: t };
|
|
2989
|
+
return g.runKernel(He, n);
|
|
2932
2990
|
} else {
|
|
2933
|
-
const
|
|
2934
|
-
return g.runKernel(
|
|
2991
|
+
const n = { x: t };
|
|
2992
|
+
return g.runKernel(qe, n);
|
|
2935
2993
|
}
|
|
2936
2994
|
}
|
|
2937
|
-
const
|
|
2995
|
+
const ns = /* @__PURE__ */ N({ abs_: es });
|
|
2938
2996
|
/**
|
|
2939
2997
|
* @license
|
|
2940
2998
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2951,10 +3009,10 @@ const ts = /* @__PURE__ */ N({ abs_: Zn });
|
|
|
2951
3009
|
* limitations under the License.
|
|
2952
3010
|
* =============================================================================
|
|
2953
3011
|
*/
|
|
2954
|
-
function
|
|
2955
|
-
xt(
|
|
2956
|
-
const s = { shape:
|
|
2957
|
-
return g.runKernel(
|
|
3012
|
+
function ss(e, t, n) {
|
|
3013
|
+
xt(e), n = n || pt(t);
|
|
3014
|
+
const s = { shape: e, value: t, dtype: n };
|
|
3015
|
+
return g.runKernel(Xe, {}, s);
|
|
2958
3016
|
}
|
|
2959
3017
|
/**
|
|
2960
3018
|
* @license
|
|
@@ -2972,29 +3030,37 @@ function es(n, t, e) {
|
|
|
2972
3030
|
* limitations under the License.
|
|
2973
3031
|
* =============================================================================
|
|
2974
3032
|
*/
|
|
2975
|
-
function
|
|
2976
|
-
const e = [];
|
|
3033
|
+
function ko(e, t) {
|
|
3034
|
+
const n = e.length, s = [];
|
|
3035
|
+
for (let r = 0; r < n; r++) {
|
|
3036
|
+
const a = n - 1 - r, o = e[a] || 1;
|
|
3037
|
+
(t[t.length - 1 - r] || 1) > 1 && o === 1 && s.unshift(a);
|
|
3038
|
+
}
|
|
3039
|
+
return s;
|
|
3040
|
+
}
|
|
3041
|
+
function Io(e, t) {
|
|
3042
|
+
const n = [];
|
|
2977
3043
|
for (let s = 0; s < t.length; s++) {
|
|
2978
|
-
const r =
|
|
2979
|
-
(r == null || r === 1 && o > 1) &&
|
|
3044
|
+
const r = e[e.length - s - 1], a = t.length - s - 1, o = t[a];
|
|
3045
|
+
(r == null || r === 1 && o > 1) && n.unshift(a);
|
|
2980
3046
|
}
|
|
2981
|
-
return
|
|
3047
|
+
return n;
|
|
2982
3048
|
}
|
|
2983
|
-
function
|
|
2984
|
-
const
|
|
2985
|
-
for (let r = 0; r <
|
|
2986
|
-
let a =
|
|
3049
|
+
function rs(e, t) {
|
|
3050
|
+
const n = Math.max(e.length, t.length), s = new Array(n);
|
|
3051
|
+
for (let r = 0; r < n; r++) {
|
|
3052
|
+
let a = e[e.length - r - 1];
|
|
2987
3053
|
a == null && (a = 1);
|
|
2988
3054
|
let o = t[t.length - r - 1];
|
|
2989
3055
|
if (o == null && (o = 1), a === 1)
|
|
2990
|
-
s[
|
|
3056
|
+
s[n - r - 1] = o;
|
|
2991
3057
|
else if (o === 1)
|
|
2992
|
-
s[
|
|
3058
|
+
s[n - r - 1] = a;
|
|
2993
3059
|
else if (a !== o) {
|
|
2994
|
-
const i = `Operands could not be broadcast together with shapes ${
|
|
3060
|
+
const i = `Operands could not be broadcast together with shapes ${e} and ${t}.`;
|
|
2995
3061
|
throw Error(i);
|
|
2996
3062
|
} else
|
|
2997
|
-
s[
|
|
3063
|
+
s[n - r - 1] = a;
|
|
2998
3064
|
}
|
|
2999
3065
|
return s;
|
|
3000
3066
|
}
|
|
@@ -3014,11 +3080,11 @@ function ns(n, t) {
|
|
|
3014
3080
|
* limitations under the License.
|
|
3015
3081
|
* =============================================================================
|
|
3016
3082
|
*/
|
|
3017
|
-
function
|
|
3018
|
-
const
|
|
3019
|
-
return g.runKernel(
|
|
3083
|
+
function as(e) {
|
|
3084
|
+
const n = { x: T(e, "x", "zerosLike") };
|
|
3085
|
+
return g.runKernel(sn, n);
|
|
3020
3086
|
}
|
|
3021
|
-
const C = /* @__PURE__ */ N({ zerosLike_:
|
|
3087
|
+
const C = /* @__PURE__ */ N({ zerosLike_: as });
|
|
3022
3088
|
/**
|
|
3023
3089
|
* @license
|
|
3024
3090
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -3035,13 +3101,13 @@ const C = /* @__PURE__ */ N({ zerosLike_: ss });
|
|
|
3035
3101
|
* limitations under the License.
|
|
3036
3102
|
* =============================================================================
|
|
3037
3103
|
*/
|
|
3038
|
-
function
|
|
3039
|
-
let
|
|
3040
|
-
[
|
|
3041
|
-
const r = { a:
|
|
3042
|
-
return g.runKernel(
|
|
3104
|
+
function os(e, t) {
|
|
3105
|
+
let n = T(e, "base", "pow"), s = T(t, "exp", "pow");
|
|
3106
|
+
[n, s] = q(n, s);
|
|
3107
|
+
const r = { a: n, b: s };
|
|
3108
|
+
return g.runKernel(tn, r);
|
|
3043
3109
|
}
|
|
3044
|
-
const
|
|
3110
|
+
const Zt = /* @__PURE__ */ N({ pow_: os });
|
|
3045
3111
|
/**
|
|
3046
3112
|
* @license
|
|
3047
3113
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -3058,12 +3124,12 @@ const Qt = /* @__PURE__ */ N({ pow_: rs });
|
|
|
3058
3124
|
* limitations under the License.
|
|
3059
3125
|
* =============================================================================
|
|
3060
3126
|
*/
|
|
3061
|
-
function K(
|
|
3062
|
-
if ((
|
|
3127
|
+
function K(e, t) {
|
|
3128
|
+
if ((F(e) && t !== "string" || Array.isArray(e)) && t !== "complex64")
|
|
3063
3129
|
throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");
|
|
3064
|
-
if (t === "string" &&
|
|
3130
|
+
if (t === "string" && F(e) && !(e instanceof Uint8Array))
|
|
3065
3131
|
throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");
|
|
3066
|
-
return
|
|
3132
|
+
return En(e, [], [], t);
|
|
3067
3133
|
}
|
|
3068
3134
|
/**
|
|
3069
3135
|
* @license
|
|
@@ -3081,11 +3147,11 @@ function K(n, t) {
|
|
|
3081
3147
|
* limitations under the License.
|
|
3082
3148
|
* =============================================================================
|
|
3083
3149
|
*/
|
|
3084
|
-
function
|
|
3085
|
-
const
|
|
3086
|
-
return g.runKernel(
|
|
3150
|
+
function is(e) {
|
|
3151
|
+
const n = { x: T(e, "x", "sqrt", "float32") };
|
|
3152
|
+
return g.runKernel(en, n);
|
|
3087
3153
|
}
|
|
3088
|
-
const nt = /* @__PURE__ */ N({ sqrt_:
|
|
3154
|
+
const nt = /* @__PURE__ */ N({ sqrt_: is });
|
|
3089
3155
|
/**
|
|
3090
3156
|
* @license
|
|
3091
3157
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -3102,11 +3168,11 @@ const nt = /* @__PURE__ */ N({ sqrt_: as });
|
|
|
3102
3168
|
* limitations under the License.
|
|
3103
3169
|
* =============================================================================
|
|
3104
3170
|
*/
|
|
3105
|
-
function
|
|
3106
|
-
const t = T(
|
|
3107
|
-
return g.runKernel("Square", { x: t },
|
|
3171
|
+
function cs(e) {
|
|
3172
|
+
const t = T(e, "x", "square"), n = {};
|
|
3173
|
+
return g.runKernel("Square", { x: t }, n);
|
|
3108
3174
|
}
|
|
3109
|
-
const V = /* @__PURE__ */ N({ square_:
|
|
3175
|
+
const V = /* @__PURE__ */ N({ square_: cs });
|
|
3110
3176
|
/**
|
|
3111
3177
|
* @license
|
|
3112
3178
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -3123,25 +3189,40 @@ const V = /* @__PURE__ */ N({ square_: os });
|
|
|
3123
3189
|
* limitations under the License.
|
|
3124
3190
|
* =============================================================================
|
|
3125
3191
|
*/
|
|
3126
|
-
function
|
|
3127
|
-
y(
|
|
3128
|
-
|
|
3129
|
-
|
|
3192
|
+
function To(e) {
|
|
3193
|
+
return y(ht(e), () => "The f passed in grads(f) must be a function"), (t, n) => {
|
|
3194
|
+
y(Array.isArray(t), () => "The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s");
|
|
3195
|
+
const s = In(t, "args", "tf.grads", "string_or_numeric"), r = n != null ? T(n, "dy", "tf.grads") : null;
|
|
3196
|
+
return g.tidy(() => {
|
|
3197
|
+
const { value: a, grads: o } = g.gradients(() => e(...s), s, r);
|
|
3198
|
+
return r != null && De(a.shape, r.shape, "The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), us(o), o;
|
|
3199
|
+
});
|
|
3200
|
+
};
|
|
3201
|
+
}
|
|
3202
|
+
function ls(e, t) {
|
|
3203
|
+
y(ht(e), () => "The f passed in variableGrads(f) must be a function"), y(t == null || Array.isArray(t) && t.every((l) => l instanceof gt), () => "The varList passed in variableGrads(f, varList) must be an array of variables");
|
|
3204
|
+
const n = t != null;
|
|
3205
|
+
if (!n) {
|
|
3130
3206
|
t = [];
|
|
3131
3207
|
for (const l in g.registeredVariables)
|
|
3132
3208
|
t.push(g.registeredVariables[l]);
|
|
3133
3209
|
}
|
|
3134
|
-
const s =
|
|
3210
|
+
const s = n ? t.filter((l) => !l.trainable) : null, r = t.length;
|
|
3135
3211
|
t = t.filter((l) => l.trainable), y(t.length > 0, () => `variableGrads() expects at least one of the input variables to be trainable, but none of the ${r} variables is trainable.`);
|
|
3136
|
-
const a = !0, { value: o, grads: i } = g.gradients(
|
|
3212
|
+
const a = !0, { value: o, grads: i } = g.gradients(e, t, null, a);
|
|
3137
3213
|
y(i.some((l) => l != null), () => "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."), y(o.rank === 0, () => `The f passed in variableGrads(f) must return a scalar, but it returned a rank-${o.rank} tensor`);
|
|
3138
3214
|
const c = {};
|
|
3139
3215
|
return t.forEach((l, u) => {
|
|
3140
3216
|
i[u] != null && (c[l.name] = i[u]);
|
|
3141
3217
|
}), s?.forEach((l) => c[l.name] = null), { value: o, grads: c };
|
|
3142
3218
|
}
|
|
3143
|
-
function
|
|
3144
|
-
return g.customGrad(
|
|
3219
|
+
function Eo(e) {
|
|
3220
|
+
return g.customGrad(e);
|
|
3221
|
+
}
|
|
3222
|
+
function us(e) {
|
|
3223
|
+
if (e.filter((n) => n == null).length > 0)
|
|
3224
|
+
throw new Error(`Cannot compute gradient of y=f(x) with respect to x. Make sure that
|
|
3225
|
+
the f you passed encloses all operations that lead from x to y.`);
|
|
3145
3226
|
}
|
|
3146
3227
|
/**
|
|
3147
3228
|
* @license
|
|
@@ -3159,13 +3240,13 @@ function go(n) {
|
|
|
3159
3240
|
* limitations under the License.
|
|
3160
3241
|
* =============================================================================
|
|
3161
3242
|
*/
|
|
3162
|
-
function
|
|
3163
|
-
let
|
|
3164
|
-
[
|
|
3165
|
-
const r = { a:
|
|
3166
|
-
return g.runKernel(
|
|
3243
|
+
function hs(e, t) {
|
|
3244
|
+
let n = T(e, "a", "sub"), s = T(t, "b", "sub");
|
|
3245
|
+
[n, s] = q(n, s);
|
|
3246
|
+
const r = { a: n, b: s };
|
|
3247
|
+
return g.runKernel(nn, r);
|
|
3167
3248
|
}
|
|
3168
|
-
const tt = /* @__PURE__ */ N({ sub_:
|
|
3249
|
+
const tt = /* @__PURE__ */ N({ sub_: hs });
|
|
3169
3250
|
/**
|
|
3170
3251
|
* @license
|
|
3171
3252
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -3182,13 +3263,13 @@ const tt = /* @__PURE__ */ N({ sub_: cs });
|
|
|
3182
3263
|
* limitations under the License.
|
|
3183
3264
|
* =============================================================================
|
|
3184
3265
|
*/
|
|
3185
|
-
function
|
|
3186
|
-
let
|
|
3187
|
-
[
|
|
3188
|
-
const r = { a:
|
|
3189
|
-
return g.runKernel(
|
|
3266
|
+
function fs(e, t) {
|
|
3267
|
+
let n = T(e, "a", "maximum"), s = T(t, "b", "maximum");
|
|
3268
|
+
[n, s] = q(n, s), n.dtype === "bool" && (n = Ft(n, "int32"), s = Ft(s, "int32")), rs(n.shape, s.shape);
|
|
3269
|
+
const r = { a: n, b: s };
|
|
3270
|
+
return g.runKernel(Qe, r);
|
|
3190
3271
|
}
|
|
3191
|
-
const
|
|
3272
|
+
const ds = /* @__PURE__ */ N({ maximum_: fs });
|
|
3192
3273
|
/**
|
|
3193
3274
|
* @license
|
|
3194
3275
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -3205,8 +3286,8 @@ const us = /* @__PURE__ */ N({ maximum_: ls });
|
|
|
3205
3286
|
* limitations under the License.
|
|
3206
3287
|
* =============================================================================
|
|
3207
3288
|
*/
|
|
3208
|
-
const
|
|
3209
|
-
class
|
|
3289
|
+
const gs = /* @__PURE__ */ new Map(), ms = /* @__PURE__ */ new Map();
|
|
3290
|
+
class ps {
|
|
3210
3291
|
/**
|
|
3211
3292
|
* Return the class name for this class to use in serialization contexts.
|
|
3212
3293
|
*
|
|
@@ -3230,11 +3311,11 @@ class fs {
|
|
|
3230
3311
|
* @param config The Configuration for the object.
|
|
3231
3312
|
*/
|
|
3232
3313
|
/** @nocollapse */
|
|
3233
|
-
static fromConfig(t,
|
|
3234
|
-
return new t(
|
|
3314
|
+
static fromConfig(t, n) {
|
|
3315
|
+
return new t(n);
|
|
3235
3316
|
}
|
|
3236
3317
|
}
|
|
3237
|
-
class
|
|
3318
|
+
class G {
|
|
3238
3319
|
constructor() {
|
|
3239
3320
|
this.classNameMap = {};
|
|
3240
3321
|
}
|
|
@@ -3242,19 +3323,19 @@ class U {
|
|
|
3242
3323
|
* Returns the singleton instance of the map.
|
|
3243
3324
|
*/
|
|
3244
3325
|
static getMap() {
|
|
3245
|
-
return
|
|
3326
|
+
return G.instance == null && (G.instance = new G()), G.instance;
|
|
3246
3327
|
}
|
|
3247
3328
|
/**
|
|
3248
3329
|
* Registers the class as serializable.
|
|
3249
3330
|
*/
|
|
3250
3331
|
static register(t) {
|
|
3251
|
-
|
|
3332
|
+
G.getMap().classNameMap[t.className] = [t, t.fromConfig];
|
|
3252
3333
|
}
|
|
3253
3334
|
}
|
|
3254
|
-
function
|
|
3255
|
-
y(
|
|
3256
|
-
const s =
|
|
3257
|
-
return
|
|
3335
|
+
function ys(e, t, n) {
|
|
3336
|
+
y(e.className != null, () => "Class being registered does not have the static className property defined."), y(typeof e.className == "string", () => "className is required to be a string, but got type " + typeof e.className), y(e.className.length > 0, () => "Class being registered has an empty-string as its className, which is disallowed."), typeof t > "u" && (t = "Custom"), typeof n > "u" && (n = e.className);
|
|
3337
|
+
const s = n, r = t + ">" + s;
|
|
3338
|
+
return G.register(e), gs.set(r, e), ms.set(e, r), e;
|
|
3258
3339
|
}
|
|
3259
3340
|
/**
|
|
3260
3341
|
* @license
|
|
@@ -3272,7 +3353,7 @@ function gs(n, t, e) {
|
|
|
3272
3353
|
* limitations under the License.
|
|
3273
3354
|
* =============================================================================
|
|
3274
3355
|
*/
|
|
3275
|
-
class H extends
|
|
3356
|
+
class H extends ps {
|
|
3276
3357
|
/**
|
|
3277
3358
|
* Executes `f()` and minimizes the scalar output of `f()` by computing
|
|
3278
3359
|
* gradients of y with respect to the list of trainable variables provided by
|
|
@@ -3287,14 +3368,14 @@ class H extends fs {
|
|
|
3287
3368
|
*
|
|
3288
3369
|
* @doc {heading: 'Training', subheading: 'Optimizers'}
|
|
3289
3370
|
*/
|
|
3290
|
-
minimize(t,
|
|
3371
|
+
minimize(t, n = !1, s) {
|
|
3291
3372
|
const { value: r, grads: a } = this.computeGradients(t, s);
|
|
3292
3373
|
if (s != null) {
|
|
3293
3374
|
const o = s.map((i) => ({ name: i.name, tensor: a[i.name] }));
|
|
3294
3375
|
this.applyGradients(o);
|
|
3295
3376
|
} else
|
|
3296
3377
|
this.applyGradients(a);
|
|
3297
|
-
return M(a),
|
|
3378
|
+
return M(a), n ? r : (r.dispose(), null);
|
|
3298
3379
|
}
|
|
3299
3380
|
/**
|
|
3300
3381
|
* The number of iterations that this optimizer instance has been invoked for.
|
|
@@ -3318,8 +3399,8 @@ class H extends fs {
|
|
|
3318
3399
|
*
|
|
3319
3400
|
* @doc {heading: 'Training', subheading: 'Optimizers'}
|
|
3320
3401
|
*/
|
|
3321
|
-
computeGradients(t,
|
|
3322
|
-
return
|
|
3402
|
+
computeGradients(t, n) {
|
|
3403
|
+
return ls(t, n);
|
|
3323
3404
|
}
|
|
3324
3405
|
/**
|
|
3325
3406
|
* Dispose the variables (if any) owned by this optimizer instance.
|
|
@@ -3352,7 +3433,7 @@ class H extends fs {
|
|
|
3352
3433
|
}
|
|
3353
3434
|
}
|
|
3354
3435
|
Object.defineProperty(H, Symbol.hasInstance, {
|
|
3355
|
-
value: (
|
|
3436
|
+
value: (e) => e.minimize != null && e.computeGradients != null && e.applyGradients != null
|
|
3356
3437
|
});
|
|
3357
3438
|
/**
|
|
3358
3439
|
* @license
|
|
@@ -3370,13 +3451,13 @@ Object.defineProperty(H, Symbol.hasInstance, {
|
|
|
3370
3451
|
* limitations under the License.
|
|
3371
3452
|
* =============================================================================
|
|
3372
3453
|
*/
|
|
3373
|
-
class
|
|
3454
|
+
class bs extends H {
|
|
3374
3455
|
/** @nocollapse */
|
|
3375
3456
|
static get className() {
|
|
3376
3457
|
return "Adadelta";
|
|
3377
3458
|
}
|
|
3378
|
-
constructor(t,
|
|
3379
|
-
super(), this.learningRate = t, this.rho =
|
|
3459
|
+
constructor(t, n, s = null) {
|
|
3460
|
+
super(), this.learningRate = t, this.rho = n, this.epsilon = s, this.accumulatedGrads = [], this.accumulatedUpdates = [], s == null && (this.epsilon = g.backend.epsilon());
|
|
3380
3461
|
}
|
|
3381
3462
|
applyGradients(t) {
|
|
3382
3463
|
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
@@ -3393,8 +3474,8 @@ class ms extends H {
|
|
|
3393
3474
|
return;
|
|
3394
3475
|
const c = this.accumulatedGrads[r].variable, l = this.accumulatedUpdates[r].variable;
|
|
3395
3476
|
E(() => {
|
|
3396
|
-
const u = S(b(c, this.rho), b(V(i), 1 - this.rho)), h = b(x(nt(S(l, this.epsilon)), nt(S(c, this.epsilon))), i),
|
|
3397
|
-
c.assign(u), l.assign(
|
|
3477
|
+
const u = S(b(c, this.rho), b(V(i), 1 - this.rho)), h = b(x(nt(S(l, this.epsilon)), nt(S(c, this.epsilon))), i), f = S(b(l, this.rho), b(V(h), 1 - this.rho));
|
|
3478
|
+
c.assign(u), l.assign(f);
|
|
3398
3479
|
const m = S(b(h, -this.learningRate), a);
|
|
3399
3480
|
a.assign(m);
|
|
3400
3481
|
});
|
|
@@ -3405,15 +3486,15 @@ class ms extends H {
|
|
|
3405
3486
|
}
|
|
3406
3487
|
async getWeights() {
|
|
3407
3488
|
const t = [...this.accumulatedGrads, ...this.accumulatedUpdates];
|
|
3408
|
-
return [await this.saveIterations()].concat(t.map((
|
|
3489
|
+
return [await this.saveIterations()].concat(t.map((n) => ({ name: n.originalName, tensor: n.variable })));
|
|
3409
3490
|
}
|
|
3410
3491
|
async setWeights(t) {
|
|
3411
3492
|
t = await this.extractIterations(t);
|
|
3412
|
-
const
|
|
3413
|
-
this.accumulatedGrads = t.slice(0,
|
|
3493
|
+
const n = t.length / 2, s = !1;
|
|
3494
|
+
this.accumulatedGrads = t.slice(0, n).map((r) => ({
|
|
3414
3495
|
originalName: r.name,
|
|
3415
3496
|
variable: r.tensor.variable(s)
|
|
3416
|
-
})), this.accumulatedUpdates = t.slice(
|
|
3497
|
+
})), this.accumulatedUpdates = t.slice(n, n * 2).map((r) => ({
|
|
3417
3498
|
originalName: r.name,
|
|
3418
3499
|
variable: r.tensor.variable(s)
|
|
3419
3500
|
}));
|
|
@@ -3426,8 +3507,8 @@ class ms extends H {
|
|
|
3426
3507
|
};
|
|
3427
3508
|
}
|
|
3428
3509
|
/** @nocollapse */
|
|
3429
|
-
static fromConfig(t,
|
|
3430
|
-
return new t(
|
|
3510
|
+
static fromConfig(t, n) {
|
|
3511
|
+
return new t(n.learningRate, n.rho, n.epsilon);
|
|
3431
3512
|
}
|
|
3432
3513
|
}
|
|
3433
3514
|
/**
|
|
@@ -3446,20 +3527,20 @@ class ms extends H {
|
|
|
3446
3527
|
* limitations under the License.
|
|
3447
3528
|
* =============================================================================
|
|
3448
3529
|
*/
|
|
3449
|
-
class
|
|
3530
|
+
class ws extends H {
|
|
3450
3531
|
/** @nocollapse */
|
|
3451
3532
|
static get className() {
|
|
3452
3533
|
return "Adagrad";
|
|
3453
3534
|
}
|
|
3454
|
-
constructor(t,
|
|
3455
|
-
super(), this.learningRate = t, this.initialAccumulatorValue =
|
|
3535
|
+
constructor(t, n = 0.1) {
|
|
3536
|
+
super(), this.learningRate = t, this.initialAccumulatorValue = n, this.accumulatedGrads = [];
|
|
3456
3537
|
}
|
|
3457
3538
|
applyGradients(t) {
|
|
3458
3539
|
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
3459
3540
|
const a = g.registeredVariables[s];
|
|
3460
3541
|
this.accumulatedGrads[r] == null && (this.accumulatedGrads[r] = {
|
|
3461
3542
|
originalName: `${s}/accumulator`,
|
|
3462
|
-
variable: E(() =>
|
|
3543
|
+
variable: E(() => ss(a.shape, this.initialAccumulatorValue).variable(!1))
|
|
3463
3544
|
});
|
|
3464
3545
|
const o = Array.isArray(t) ? t[r].tensor : t[s];
|
|
3465
3546
|
if (o == null)
|
|
@@ -3481,8 +3562,8 @@ class ps extends H {
|
|
|
3481
3562
|
}
|
|
3482
3563
|
async setWeights(t) {
|
|
3483
3564
|
t = await this.extractIterations(t);
|
|
3484
|
-
const
|
|
3485
|
-
this.accumulatedGrads = t.map((s) => ({ originalName: s.name, variable: s.tensor.variable(
|
|
3565
|
+
const n = !1;
|
|
3566
|
+
this.accumulatedGrads = t.map((s) => ({ originalName: s.name, variable: s.tensor.variable(n) }));
|
|
3486
3567
|
}
|
|
3487
3568
|
getConfig() {
|
|
3488
3569
|
return {
|
|
@@ -3491,8 +3572,8 @@ class ps extends H {
|
|
|
3491
3572
|
};
|
|
3492
3573
|
}
|
|
3493
3574
|
/** @nocollapse */
|
|
3494
|
-
static fromConfig(t,
|
|
3495
|
-
return new t(
|
|
3575
|
+
static fromConfig(t, n) {
|
|
3576
|
+
return new t(n.learningRate, n.initialAccumulatorValue);
|
|
3496
3577
|
}
|
|
3497
3578
|
}
|
|
3498
3579
|
/**
|
|
@@ -3511,21 +3592,21 @@ class ps extends H {
|
|
|
3511
3592
|
* limitations under the License.
|
|
3512
3593
|
* =============================================================================
|
|
3513
3594
|
*/
|
|
3514
|
-
class
|
|
3595
|
+
class Ss extends H {
|
|
3515
3596
|
/** @nocollapse */
|
|
3516
3597
|
static get className() {
|
|
3517
3598
|
return "Adam";
|
|
3518
3599
|
}
|
|
3519
|
-
constructor(t,
|
|
3520
|
-
super(), this.learningRate = t, this.beta1 =
|
|
3521
|
-
this.accBeta1 = K(
|
|
3600
|
+
constructor(t, n, s, r = null) {
|
|
3601
|
+
super(), this.learningRate = t, this.beta1 = n, this.beta2 = s, this.epsilon = r, this.accumulatedFirstMoment = [], this.accumulatedSecondMoment = [], E(() => {
|
|
3602
|
+
this.accBeta1 = K(n).variable(), this.accBeta2 = K(s).variable();
|
|
3522
3603
|
}), r == null && (this.epsilon = g.backend.epsilon());
|
|
3523
3604
|
}
|
|
3524
3605
|
applyGradients(t) {
|
|
3525
|
-
const
|
|
3606
|
+
const n = Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t);
|
|
3526
3607
|
E(() => {
|
|
3527
3608
|
const s = tt(1, this.accBeta1), r = tt(1, this.accBeta2);
|
|
3528
|
-
|
|
3609
|
+
n.forEach((a, o) => {
|
|
3529
3610
|
const i = g.registeredVariables[a], c = !1;
|
|
3530
3611
|
this.accumulatedFirstMoment[o] == null && (this.accumulatedFirstMoment[o] = {
|
|
3531
3612
|
originalName: `${a}/m`,
|
|
@@ -3537,9 +3618,9 @@ class ys extends H {
|
|
|
3537
3618
|
const l = Array.isArray(t) ? t[o].tensor : t[a];
|
|
3538
3619
|
if (l == null)
|
|
3539
3620
|
return;
|
|
3540
|
-
const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedSecondMoment[o].variable,
|
|
3541
|
-
u.assign(
|
|
3542
|
-
const w = S(b(x(p, S(nt(
|
|
3621
|
+
const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedSecondMoment[o].variable, f = S(b(u, this.beta1), b(l, 1 - this.beta1)), m = S(b(h, this.beta2), b(V(l), 1 - this.beta2)), p = x(f, s), d = x(m, r);
|
|
3622
|
+
u.assign(f), h.assign(m);
|
|
3623
|
+
const w = S(b(x(p, S(nt(d), this.epsilon)), -this.learningRate), i);
|
|
3543
3624
|
i.assign(w);
|
|
3544
3625
|
}), this.accBeta1.assign(b(this.accBeta1, this.beta1)), this.accBeta2.assign(b(this.accBeta2, this.beta2));
|
|
3545
3626
|
}), this.incrementIterations();
|
|
@@ -3549,17 +3630,17 @@ class ys extends H {
|
|
|
3549
3630
|
}
|
|
3550
3631
|
async getWeights() {
|
|
3551
3632
|
const t = [...this.accumulatedFirstMoment, ...this.accumulatedSecondMoment];
|
|
3552
|
-
return [await this.saveIterations()].concat(t.map((
|
|
3633
|
+
return [await this.saveIterations()].concat(t.map((n) => ({ name: n.originalName, tensor: n.variable })));
|
|
3553
3634
|
}
|
|
3554
3635
|
async setWeights(t) {
|
|
3555
3636
|
t = await this.extractIterations(t), E(() => {
|
|
3556
|
-
this.accBeta1.assign(
|
|
3637
|
+
this.accBeta1.assign(Zt(this.beta1, this.iterations_ + 1)), this.accBeta2.assign(Zt(this.beta2, this.iterations_ + 1));
|
|
3557
3638
|
});
|
|
3558
|
-
const
|
|
3559
|
-
this.accumulatedFirstMoment = t.slice(0,
|
|
3639
|
+
const n = t.length / 2, s = !1;
|
|
3640
|
+
this.accumulatedFirstMoment = t.slice(0, n).map((r) => ({
|
|
3560
3641
|
originalName: r.name,
|
|
3561
3642
|
variable: r.tensor.variable(s)
|
|
3562
|
-
})), this.accumulatedSecondMoment = t.slice(
|
|
3643
|
+
})), this.accumulatedSecondMoment = t.slice(n, n * 2).map((r) => ({
|
|
3563
3644
|
originalName: r.name,
|
|
3564
3645
|
variable: r.tensor.variable(s)
|
|
3565
3646
|
}));
|
|
@@ -3573,8 +3654,8 @@ class ys extends H {
|
|
|
3573
3654
|
};
|
|
3574
3655
|
}
|
|
3575
3656
|
/** @nocollapse */
|
|
3576
|
-
static fromConfig(t,
|
|
3577
|
-
return new t(
|
|
3657
|
+
static fromConfig(t, n) {
|
|
3658
|
+
return new t(n.learningRate, n.beta1, n.beta2, n.epsilon);
|
|
3578
3659
|
}
|
|
3579
3660
|
}
|
|
3580
3661
|
/**
|
|
@@ -3593,21 +3674,21 @@ class ys extends H {
|
|
|
3593
3674
|
* limitations under the License.
|
|
3594
3675
|
* =============================================================================
|
|
3595
3676
|
*/
|
|
3596
|
-
class
|
|
3677
|
+
class ks extends H {
|
|
3597
3678
|
/** @nocollapse */
|
|
3598
3679
|
static get className() {
|
|
3599
3680
|
return "Adamax";
|
|
3600
3681
|
}
|
|
3601
|
-
constructor(t,
|
|
3602
|
-
super(), this.learningRate = t, this.beta1 =
|
|
3603
|
-
this.iteration = K(0).variable(), this.accBeta1 = K(
|
|
3682
|
+
constructor(t, n, s, r = null, a = 0) {
|
|
3683
|
+
super(), this.learningRate = t, this.beta1 = n, this.beta2 = s, this.epsilon = r, this.decay = a, this.accumulatedFirstMoment = [], this.accumulatedWeightedInfNorm = [], E(() => {
|
|
3684
|
+
this.iteration = K(0).variable(), this.accBeta1 = K(n).variable();
|
|
3604
3685
|
}), r == null && (this.epsilon = g.backend.epsilon());
|
|
3605
3686
|
}
|
|
3606
3687
|
applyGradients(t) {
|
|
3607
|
-
const
|
|
3688
|
+
const n = Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t);
|
|
3608
3689
|
E(() => {
|
|
3609
3690
|
const s = tt(1, this.accBeta1), r = x(-this.learningRate, S(b(this.iteration, this.decay), 1));
|
|
3610
|
-
|
|
3691
|
+
n.forEach((a, o) => {
|
|
3611
3692
|
const i = g.registeredVariables[a], c = !1;
|
|
3612
3693
|
this.accumulatedFirstMoment[o] == null && (this.accumulatedFirstMoment[o] = {
|
|
3613
3694
|
originalName: `${a}/m`,
|
|
@@ -3619,9 +3700,9 @@ class bs extends H {
|
|
|
3619
3700
|
const l = Array.isArray(t) ? t[o].tensor : t[a];
|
|
3620
3701
|
if (l == null)
|
|
3621
3702
|
return;
|
|
3622
|
-
const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedWeightedInfNorm[o].variable,
|
|
3623
|
-
u.assign(
|
|
3624
|
-
const w = S(b(x(r, s), x(
|
|
3703
|
+
const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedWeightedInfNorm[o].variable, f = S(b(u, this.beta1), b(l, 1 - this.beta1)), m = b(h, this.beta2), p = ns(l), d = ds(m, p);
|
|
3704
|
+
u.assign(f), h.assign(d);
|
|
3705
|
+
const w = S(b(x(r, s), x(f, S(d, this.epsilon))), i);
|
|
3625
3706
|
i.assign(w);
|
|
3626
3707
|
}), this.iteration.assign(S(this.iteration, 1)), this.accBeta1.assign(b(this.accBeta1, this.beta1));
|
|
3627
3708
|
}), this.incrementIterations();
|
|
@@ -3645,8 +3726,8 @@ class bs extends H {
|
|
|
3645
3726
|
};
|
|
3646
3727
|
}
|
|
3647
3728
|
/** @nocollapse */
|
|
3648
|
-
static fromConfig(t,
|
|
3649
|
-
return new t(
|
|
3729
|
+
static fromConfig(t, n) {
|
|
3730
|
+
return new t(n.learningRate, n.beta1, n.beta2, n.epsilon, n.decay);
|
|
3650
3731
|
}
|
|
3651
3732
|
}
|
|
3652
3733
|
/**
|
|
@@ -3665,7 +3746,7 @@ class bs extends H {
|
|
|
3665
3746
|
* limitations under the License.
|
|
3666
3747
|
* =============================================================================
|
|
3667
3748
|
*/
|
|
3668
|
-
class
|
|
3749
|
+
class ve extends H {
|
|
3669
3750
|
/** @nocollapse */
|
|
3670
3751
|
static get className() {
|
|
3671
3752
|
return "SGD";
|
|
@@ -3689,7 +3770,7 @@ class Ee extends H {
|
|
|
3689
3770
|
* Sets the learning rate of the optimizer.
|
|
3690
3771
|
*/
|
|
3691
3772
|
setLearningRate(t) {
|
|
3692
|
-
this.learningRate = t, this.c != null && this.c.dispose(), this.c =
|
|
3773
|
+
this.learningRate = t, this.c != null && this.c.dispose(), this.c = Bn(K(-t));
|
|
3693
3774
|
}
|
|
3694
3775
|
dispose() {
|
|
3695
3776
|
this.c.dispose();
|
|
@@ -3705,8 +3786,8 @@ class Ee extends H {
|
|
|
3705
3786
|
return { learningRate: this.learningRate };
|
|
3706
3787
|
}
|
|
3707
3788
|
/** @nocollapse */
|
|
3708
|
-
static fromConfig(t,
|
|
3709
|
-
return new t(
|
|
3789
|
+
static fromConfig(t, n) {
|
|
3790
|
+
return new t(n.learningRate);
|
|
3710
3791
|
}
|
|
3711
3792
|
}
|
|
3712
3793
|
/**
|
|
@@ -3725,14 +3806,14 @@ class Ee extends H {
|
|
|
3725
3806
|
* limitations under the License.
|
|
3726
3807
|
* =============================================================================
|
|
3727
3808
|
*/
|
|
3728
|
-
class
|
|
3809
|
+
class Is extends ve {
|
|
3729
3810
|
/** @nocollapse */
|
|
3730
3811
|
// Name matters for Python compatibility.
|
|
3731
3812
|
static get className() {
|
|
3732
3813
|
return "Momentum";
|
|
3733
3814
|
}
|
|
3734
|
-
constructor(t,
|
|
3735
|
-
super(t), this.learningRate = t, this.momentum =
|
|
3815
|
+
constructor(t, n, s = !1) {
|
|
3816
|
+
super(t), this.learningRate = t, this.momentum = n, this.useNesterov = s, this.accumulations = [], this.m = K(this.momentum);
|
|
3736
3817
|
}
|
|
3737
3818
|
applyGradients(t) {
|
|
3738
3819
|
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
@@ -3765,8 +3846,8 @@ class ws extends Ee {
|
|
|
3765
3846
|
}
|
|
3766
3847
|
async setWeights(t) {
|
|
3767
3848
|
t = await this.extractIterations(t);
|
|
3768
|
-
const
|
|
3769
|
-
this.accumulations = t.map((s) => ({ originalName: s.name, variable: s.tensor.variable(
|
|
3849
|
+
const n = !1;
|
|
3850
|
+
this.accumulations = t.map((s) => ({ originalName: s.name, variable: s.tensor.variable(n) }));
|
|
3770
3851
|
}
|
|
3771
3852
|
getConfig() {
|
|
3772
3853
|
return {
|
|
@@ -3776,8 +3857,8 @@ class ws extends Ee {
|
|
|
3776
3857
|
};
|
|
3777
3858
|
}
|
|
3778
3859
|
/** @nocollapse */
|
|
3779
|
-
static fromConfig(t,
|
|
3780
|
-
return new t(
|
|
3860
|
+
static fromConfig(t, n) {
|
|
3861
|
+
return new t(n.learningRate, n.momentum, n.useNesterov);
|
|
3781
3862
|
}
|
|
3782
3863
|
}
|
|
3783
3864
|
/**
|
|
@@ -3796,13 +3877,13 @@ class ws extends Ee {
|
|
|
3796
3877
|
* limitations under the License.
|
|
3797
3878
|
* =============================================================================
|
|
3798
3879
|
*/
|
|
3799
|
-
class
|
|
3880
|
+
class Ts extends H {
|
|
3800
3881
|
/** @nocollapse */
|
|
3801
3882
|
static get className() {
|
|
3802
3883
|
return "RMSProp";
|
|
3803
3884
|
}
|
|
3804
|
-
constructor(t,
|
|
3805
|
-
if (super(), this.learningRate = t, this.decay =
|
|
3885
|
+
constructor(t, n = 0.9, s = 0, r = null, a = !1) {
|
|
3886
|
+
if (super(), this.learningRate = t, this.decay = n, this.momentum = s, this.epsilon = r, this.accumulatedMeanSquares = [], this.accumulatedMoments = [], this.accumulatedMeanGrads = [], this.centered = a, r == null && (this.epsilon = g.backend.epsilon()), t == null)
|
|
3806
3887
|
throw new Error("learningRate for RMSPropOptimizer must be defined.");
|
|
3807
3888
|
}
|
|
3808
3889
|
applyGradients(t) {
|
|
@@ -3825,14 +3906,14 @@ class Ss extends H {
|
|
|
3825
3906
|
E(() => {
|
|
3826
3907
|
const u = S(b(c, this.decay), b(V(i), 1 - this.decay));
|
|
3827
3908
|
if (this.centered) {
|
|
3828
|
-
const h = this.accumulatedMeanGrads[r].variable,
|
|
3829
|
-
c.assign(u), h.assign(
|
|
3830
|
-
const
|
|
3831
|
-
a.assign(
|
|
3909
|
+
const h = this.accumulatedMeanGrads[r].variable, f = S(b(h, this.decay), b(i, 1 - this.decay)), m = x(b(i, this.learningRate), nt(tt(u, S(V(f), this.epsilon)))), p = S(b(l, this.momentum), m);
|
|
3910
|
+
c.assign(u), h.assign(f), l.assign(p);
|
|
3911
|
+
const d = tt(a, p);
|
|
3912
|
+
a.assign(d);
|
|
3832
3913
|
} else {
|
|
3833
|
-
const h = S(b(c, this.decay), b(V(i), 1 - this.decay)),
|
|
3834
|
-
c.assign(h), l.assign(
|
|
3835
|
-
const m = tt(a,
|
|
3914
|
+
const h = S(b(c, this.decay), b(V(i), 1 - this.decay)), f = S(b(l, this.momentum), x(b(i, this.learningRate), nt(S(h, this.epsilon))));
|
|
3915
|
+
c.assign(h), l.assign(f);
|
|
3916
|
+
const m = tt(a, f);
|
|
3836
3917
|
a.assign(m);
|
|
3837
3918
|
}
|
|
3838
3919
|
});
|
|
@@ -3843,18 +3924,18 @@ class Ss extends H {
|
|
|
3843
3924
|
}
|
|
3844
3925
|
async getWeights() {
|
|
3845
3926
|
const t = [...this.accumulatedMeanSquares, ...this.accumulatedMoments];
|
|
3846
|
-
return this.centered && t.push(...this.accumulatedMeanGrads), [await this.saveIterations()].concat(t.map((
|
|
3927
|
+
return this.centered && t.push(...this.accumulatedMeanGrads), [await this.saveIterations()].concat(t.map((n) => ({ name: n.originalName, tensor: n.variable })));
|
|
3847
3928
|
}
|
|
3848
3929
|
async setWeights(t) {
|
|
3849
3930
|
t = await this.extractIterations(t);
|
|
3850
|
-
const
|
|
3851
|
-
this.accumulatedMeanSquares = t.slice(0,
|
|
3931
|
+
const n = this.centered ? t.length / 3 : t.length / 2, s = !1;
|
|
3932
|
+
this.accumulatedMeanSquares = t.slice(0, n).map((r) => ({
|
|
3852
3933
|
originalName: r.name,
|
|
3853
3934
|
variable: r.tensor.variable(s)
|
|
3854
|
-
})), this.accumulatedMoments = t.slice(
|
|
3935
|
+
})), this.accumulatedMoments = t.slice(n, n * 2).map((r) => ({
|
|
3855
3936
|
originalName: r.name,
|
|
3856
3937
|
variable: r.tensor.variable(s)
|
|
3857
|
-
})), this.centered && (this.accumulatedMeanGrads = t.slice(
|
|
3938
|
+
})), this.centered && (this.accumulatedMeanGrads = t.slice(n * 2, n * 3).map((r) => ({
|
|
3858
3939
|
originalName: r.name,
|
|
3859
3940
|
variable: r.tensor.variable(s)
|
|
3860
3941
|
})));
|
|
@@ -3869,8 +3950,8 @@ class Ss extends H {
|
|
|
3869
3950
|
};
|
|
3870
3951
|
}
|
|
3871
3952
|
/** @nocollapse */
|
|
3872
|
-
static fromConfig(t,
|
|
3873
|
-
return new t(
|
|
3953
|
+
static fromConfig(t, n) {
|
|
3954
|
+
return new t(n.learningRate, n.decay, n.momentum, n.epsilon, n.centered);
|
|
3874
3955
|
}
|
|
3875
3956
|
}
|
|
3876
3957
|
/**
|
|
@@ -3889,18 +3970,18 @@ class Ss extends H {
|
|
|
3889
3970
|
* limitations under the License.
|
|
3890
3971
|
* =============================================================================
|
|
3891
3972
|
*/
|
|
3892
|
-
const
|
|
3893
|
-
ms,
|
|
3894
|
-
ps,
|
|
3895
|
-
ys,
|
|
3973
|
+
const Es = [
|
|
3896
3974
|
bs,
|
|
3897
3975
|
ws,
|
|
3898
3976
|
Ss,
|
|
3899
|
-
|
|
3977
|
+
ks,
|
|
3978
|
+
Is,
|
|
3979
|
+
Ts,
|
|
3980
|
+
ve
|
|
3900
3981
|
];
|
|
3901
|
-
function
|
|
3902
|
-
for (const
|
|
3903
|
-
|
|
3982
|
+
function As() {
|
|
3983
|
+
for (const e of Es)
|
|
3984
|
+
ys(e);
|
|
3904
3985
|
}
|
|
3905
3986
|
/**
|
|
3906
3987
|
* @license
|
|
@@ -3918,220 +3999,237 @@ function Is() {
|
|
|
3918
3999
|
* limitations under the License.
|
|
3919
4000
|
* =============================================================================
|
|
3920
4001
|
*/
|
|
3921
|
-
|
|
4002
|
+
As();
|
|
3922
4003
|
export {
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
4004
|
+
ns as $,
|
|
4005
|
+
Ss as A,
|
|
4006
|
+
Zs as B,
|
|
4007
|
+
or as C,
|
|
4008
|
+
ss as D,
|
|
3928
4009
|
g as E,
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
4010
|
+
Bn as F,
|
|
4011
|
+
Pr as G,
|
|
4012
|
+
To as H,
|
|
4013
|
+
Fs as I,
|
|
4014
|
+
kn as J,
|
|
4015
|
+
En as K,
|
|
4016
|
+
Lr as L,
|
|
4017
|
+
ta as M,
|
|
4018
|
+
Ea as N,
|
|
4019
|
+
Zt as O,
|
|
4020
|
+
ba as P,
|
|
4021
|
+
dr as Q,
|
|
4022
|
+
Ia as R,
|
|
4023
|
+
qa as S,
|
|
4024
|
+
Oa as T,
|
|
4025
|
+
De as U,
|
|
4026
|
+
ar as V,
|
|
4027
|
+
ne as W,
|
|
4028
|
+
aa as X,
|
|
4029
|
+
xe as Y,
|
|
4030
|
+
V as Z,
|
|
4031
|
+
oa as _,
|
|
3951
4032
|
M as a,
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4033
|
+
ko as a$,
|
|
4034
|
+
nt as a0,
|
|
4035
|
+
Qa as a1,
|
|
4036
|
+
Ca as a2,
|
|
4037
|
+
Fr as a3,
|
|
4038
|
+
qr as a4,
|
|
4039
|
+
S as a5,
|
|
4040
|
+
la as a6,
|
|
4041
|
+
ua as a7,
|
|
4042
|
+
Za as a8,
|
|
4043
|
+
F as a9,
|
|
4044
|
+
Ta as aA,
|
|
4045
|
+
Aa as aB,
|
|
4046
|
+
Ra as aC,
|
|
4047
|
+
$a as aD,
|
|
4048
|
+
Ds as aE,
|
|
4049
|
+
ro as aF,
|
|
4050
|
+
no as aG,
|
|
4051
|
+
eo as aH,
|
|
4052
|
+
Rt as aI,
|
|
4053
|
+
x as aJ,
|
|
4054
|
+
Io as aK,
|
|
4055
|
+
oo as aL,
|
|
4056
|
+
yr as aM,
|
|
4057
|
+
$r as aN,
|
|
4058
|
+
ao as aO,
|
|
4059
|
+
da as aP,
|
|
4060
|
+
ma as aQ,
|
|
4061
|
+
ga as aR,
|
|
4062
|
+
Na as aS,
|
|
4063
|
+
va as aT,
|
|
4064
|
+
to as aU,
|
|
4065
|
+
yo as aV,
|
|
4066
|
+
xs as aW,
|
|
4067
|
+
jt as aX,
|
|
4068
|
+
ue as aY,
|
|
4069
|
+
$t as aZ,
|
|
4070
|
+
$s as a_,
|
|
4071
|
+
D as aa,
|
|
4072
|
+
k as ab,
|
|
4073
|
+
pe as ac,
|
|
4074
|
+
fo as ad,
|
|
4075
|
+
dt as ae,
|
|
4076
|
+
za as af,
|
|
4077
|
+
_a as ag,
|
|
4078
|
+
er as ah,
|
|
4079
|
+
rr as ai,
|
|
4080
|
+
rs as aj,
|
|
4081
|
+
Pa as ak,
|
|
4082
|
+
Ar as al,
|
|
4083
|
+
Br as am,
|
|
4084
|
+
Rr as an,
|
|
4085
|
+
Wn as ao,
|
|
4086
|
+
xr as ap,
|
|
4087
|
+
_r as aq,
|
|
4088
|
+
Or as ar,
|
|
4089
|
+
Gr as as,
|
|
4090
|
+
Wr as at,
|
|
4091
|
+
jr as au,
|
|
4092
|
+
Kr as av,
|
|
4093
|
+
ha as aw,
|
|
4094
|
+
Jr as ax,
|
|
4095
|
+
ia as ay,
|
|
4096
|
+
Sa as az,
|
|
4016
4097
|
b,
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
$
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4098
|
+
Vs as b$,
|
|
4099
|
+
Ps as b0,
|
|
4100
|
+
Cs as b1,
|
|
4101
|
+
Lt as b2,
|
|
4102
|
+
te as b3,
|
|
4103
|
+
uo as b4,
|
|
4104
|
+
de as b5,
|
|
4105
|
+
dn as b6,
|
|
4106
|
+
Re as b7,
|
|
4107
|
+
$e as b8,
|
|
4108
|
+
Rs as b9,
|
|
4109
|
+
ya as bA,
|
|
4110
|
+
pa as bB,
|
|
4111
|
+
wa as bC,
|
|
4112
|
+
ja as bD,
|
|
4113
|
+
Da as bE,
|
|
4114
|
+
xa as bF,
|
|
4115
|
+
La as bG,
|
|
4116
|
+
Ga as bH,
|
|
4117
|
+
so as bI,
|
|
4118
|
+
cr as bJ,
|
|
4119
|
+
io as bK,
|
|
4120
|
+
Sr as bL,
|
|
4121
|
+
kr as bM,
|
|
4122
|
+
ve as bN,
|
|
4123
|
+
Is as bO,
|
|
4124
|
+
Ts as bP,
|
|
4125
|
+
bs as bQ,
|
|
4126
|
+
ks as bR,
|
|
4127
|
+
ws as bS,
|
|
4128
|
+
ys as bT,
|
|
4129
|
+
ps as bU,
|
|
4130
|
+
G as bV,
|
|
4131
|
+
qe as bW,
|
|
4132
|
+
Ls as bX,
|
|
4133
|
+
_s as bY,
|
|
4134
|
+
ae as bZ,
|
|
4135
|
+
Os as b_,
|
|
4136
|
+
ho as ba,
|
|
4137
|
+
Gs as bb,
|
|
4138
|
+
Us as bc,
|
|
4139
|
+
zs as bd,
|
|
4140
|
+
Js as be,
|
|
4141
|
+
Ys as bf,
|
|
4142
|
+
Ya as bg,
|
|
4143
|
+
tr as bh,
|
|
4144
|
+
Cr as bi,
|
|
4145
|
+
ir as bj,
|
|
4146
|
+
lr as bk,
|
|
4147
|
+
ur as bl,
|
|
4148
|
+
fr as bm,
|
|
4149
|
+
gr as bn,
|
|
4150
|
+
mr as bo,
|
|
4151
|
+
pr as bp,
|
|
4152
|
+
br as bq,
|
|
4153
|
+
wr as br,
|
|
4154
|
+
Nr as bs,
|
|
4155
|
+
Mr as bt,
|
|
4156
|
+
Hr as bu,
|
|
4157
|
+
Va as bv,
|
|
4158
|
+
Xr as bw,
|
|
4159
|
+
ea as bx,
|
|
4160
|
+
sa as by,
|
|
4161
|
+
fa as bz,
|
|
4162
|
+
Eo as c,
|
|
4163
|
+
Ws as c0,
|
|
4164
|
+
js as c1,
|
|
4165
|
+
Hs as c2,
|
|
4166
|
+
Ks as c3,
|
|
4167
|
+
qs as c4,
|
|
4168
|
+
Qs as c5,
|
|
4169
|
+
Xs as c6,
|
|
4170
|
+
nr as c7,
|
|
4171
|
+
oe as c8,
|
|
4172
|
+
sr as c9,
|
|
4173
|
+
en as cA,
|
|
4174
|
+
Ja as cB,
|
|
4175
|
+
Ha as cC,
|
|
4176
|
+
nn as cD,
|
|
4177
|
+
Xa as cE,
|
|
4178
|
+
ds as cF,
|
|
4179
|
+
sn as cG,
|
|
4180
|
+
Oe as cH,
|
|
4181
|
+
H as cI,
|
|
4182
|
+
Ns as cJ,
|
|
4183
|
+
So as cK,
|
|
4184
|
+
bo as cL,
|
|
4185
|
+
wo as cM,
|
|
4186
|
+
He as ca,
|
|
4187
|
+
hr as cb,
|
|
4188
|
+
Ir as cc,
|
|
4189
|
+
Er as cd,
|
|
4190
|
+
Tr as ce,
|
|
4191
|
+
vr as cf,
|
|
4192
|
+
Dr as cg,
|
|
4193
|
+
Ye as ch,
|
|
4194
|
+
ie as ci,
|
|
4195
|
+
Ur as cj,
|
|
4196
|
+
zr as ck,
|
|
4197
|
+
Vr as cl,
|
|
4198
|
+
Yr as cm,
|
|
4199
|
+
Zr as cn,
|
|
4200
|
+
Qr as co,
|
|
4201
|
+
Qe as cp,
|
|
4202
|
+
ra as cq,
|
|
4203
|
+
na as cr,
|
|
4204
|
+
ca as cs,
|
|
4205
|
+
Ze as ct,
|
|
4206
|
+
tn as cu,
|
|
4207
|
+
ka as cv,
|
|
4208
|
+
Je as cw,
|
|
4209
|
+
Fa as cx,
|
|
4210
|
+
Ma as cy,
|
|
4211
|
+
Ua as cz,
|
|
4212
|
+
go as d,
|
|
4213
|
+
mo as e,
|
|
4116
4214
|
K as f,
|
|
4117
|
-
|
|
4215
|
+
lo as g,
|
|
4118
4216
|
T as h,
|
|
4119
|
-
|
|
4217
|
+
In as i,
|
|
4120
4218
|
y as j,
|
|
4121
4219
|
xt as k,
|
|
4122
|
-
|
|
4123
|
-
|
|
4220
|
+
Ge as l,
|
|
4221
|
+
po as m,
|
|
4124
4222
|
z as n,
|
|
4125
4223
|
N as o,
|
|
4126
4224
|
q as p,
|
|
4127
|
-
|
|
4128
|
-
|
|
4225
|
+
Ba as q,
|
|
4226
|
+
co as r,
|
|
4129
4227
|
tt as s,
|
|
4130
4228
|
E as t,
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4229
|
+
Ka as u,
|
|
4230
|
+
ls as v,
|
|
4231
|
+
qn as w,
|
|
4232
|
+
Ft as x,
|
|
4233
|
+
Wa as y,
|
|
4136
4234
|
C as z
|
|
4137
4235
|
};
|