@genai-fi/nanogpt 0.9.1 → 0.10.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/README.md +352 -14
- package/dist/Generator.js +69 -78
- package/dist/{RealDiv-D4EzDsC0.js → RealDiv-DgA3z9oO.js} +32 -206
- package/dist/Reshape-CF6odzV4.js +16 -0
- package/dist/Reshape-_kILl6tK.js +81 -0
- package/dist/TeachableLLM.js +28 -22
- package/dist/Trainer.d.ts +2 -0
- package/dist/Trainer.js +3 -2
- package/dist/{axis_util-TbGYJ208.js → axis_util-BvHEw88j.js} +7 -23
- package/dist/backend.d.ts +2 -1
- package/dist/backend.js +10 -4
- package/dist/backend_util-D-rUb2ty.js +474 -0
- package/dist/backend_webgpu-B0u2ndUn.js +547 -0
- package/dist/binary_op_util-pKXltfxI.js +192 -0
- package/dist/broadcast_to-CwF7XIeu.js +30 -0
- package/dist/checks/appendCache.js +2 -2
- package/dist/checks/attentionMask.js +3 -3
- package/dist/checks/check.d.ts +1 -1
- package/dist/checks/check.js +8 -8
- package/dist/checks/gelu.js +2 -2
- package/dist/checks/index.d.ts +2 -0
- package/dist/checks/index.js +7 -5
- package/dist/checks/matMulGelu.js +6 -6
- package/dist/checks/normRMS.js +7 -7
- package/dist/checks/normRMSGrad.js +3 -3
- package/dist/checks/packUnpack.d.ts +1 -0
- package/dist/checks/packUnpack.js +18 -0
- package/dist/checks/qkv.js +12 -27
- package/dist/checks/rope.js +2 -2
- package/dist/checks/weights.js +18 -16
- package/dist/complex-CSlYz-2T.js +13 -0
- package/dist/complex_util-Yc1A_gV1.js +55 -0
- package/dist/concat-BHlIJeyT.js +19 -0
- package/dist/concat_util-DcJk7YHS.js +22 -0
- package/dist/data/docx.js +1 -1
- package/dist/data/parquet.js +2 -2
- package/dist/data/pdf.js +1 -1
- package/dist/data/textLoader.js +1 -1
- package/dist/{dataset-DlZtKmBq.js → dataset-0xP8GjwI.js} +136 -236
- package/dist/dropout-C1pM3f11.js +99 -0
- package/dist/expand_dims-BPG4fwBP.js +13 -0
- package/dist/exports_initializers-xuidcwI4.js +7 -0
- package/dist/gather-DykLGqmW.js +10 -0
- package/dist/{gelu-Bp_-935b.js → gelu-CNLFZWea.js} +11 -10
- package/dist/{gpgpu_math-CDaYiyE_.js → gpgpu_math-DDVJCn6-.js} +90 -265
- package/dist/{index-C4L8Cm77.js → index-CieiGp4Y.js} +14 -14
- package/dist/index-CjOj7j-u.js +7308 -0
- package/dist/{index-Tf7vU29b.js → index-Cp39cXWe.js} +3 -10
- package/dist/{index-Dwqa6Zy2.js → index-DvYrXKkX.js} +2 -2
- package/dist/index-ZyQhjEPo.js +2157 -0
- package/dist/{jszip.min-CjP2V1VV.js → jszip.min-Bz5-11Bk.js} +56 -57
- package/dist/kernel_funcs_utils-Dg_-E44D.js +308 -0
- package/dist/layers/BaseLayer.d.ts +1 -0
- package/dist/layers/BaseLayer.js +7 -6
- package/dist/layers/CausalSelfAttention.d.ts +0 -1
- package/dist/layers/CausalSelfAttention.js +56 -55
- package/dist/layers/MLP.js +15 -16
- package/dist/layers/PositionEmbedding.js +5 -14
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.d.ts +2 -0
- package/dist/layers/RoPECache.js +22 -17
- package/dist/layers/TiedEmbedding.js +22 -17
- package/dist/layers/TransformerBlock.js +21 -20
- package/dist/loader/load.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +39 -33
- package/dist/loader/save.js +1 -1
- package/dist/log_sum_exp-DWI-76TI.js +41 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.js +63 -52
- package/dist/matMul16--R5hOwDG.js +77 -0
- package/dist/mat_mul-DeAh4uTH.js +12 -0
- package/dist/mod-Gt1rMB4n.js +12 -0
- package/dist/models/NanoGPTV1.js +40 -31
- package/dist/models/model.d.ts +2 -0
- package/dist/models/model.js +37 -29
- package/dist/{mulmat_packed_gpu-BT60jmzP.js → mulmat_packed_gpu-BMFhLwta.js} +1 -17
- package/dist/{non_max_suppression_impl-CsEgBuMA.js → non_max_suppression_impl-B2W7YjZB.js} +0 -32
- package/dist/ones-CAMiP4I2.js +15 -0
- package/dist/ops/adamAdjust.js +1 -1
- package/dist/ops/adamMoments.d.ts +1 -1
- package/dist/ops/adamMoments.js +4 -4
- package/dist/ops/add16.d.ts +2 -0
- package/dist/ops/add16.js +9 -0
- package/dist/ops/appendCache.js +16 -9
- package/dist/ops/attentionMask.js +4 -4
- package/dist/ops/concat16.d.ts +2 -0
- package/dist/ops/concat16.js +9 -0
- package/dist/ops/cpu/adamAdjust.js +14 -13
- package/dist/ops/cpu/adamMoments.js +10 -9
- package/dist/ops/cpu/appendCache.js +9 -8
- package/dist/ops/cpu/attentionMask.js +15 -14
- package/dist/ops/cpu/fusedSoftmax.js +13 -12
- package/dist/ops/cpu/gatherSub.js +9 -24
- package/dist/ops/cpu/gelu.js +13 -12
- package/dist/ops/cpu/matMul16.d.ts +1 -0
- package/dist/ops/cpu/matMul16.js +16 -0
- package/dist/ops/cpu/matMulGelu.js +18 -16
- package/dist/ops/cpu/matMulMul.js +8 -7
- package/dist/ops/cpu/mulDropout.js +4 -3
- package/dist/ops/cpu/normRMS.js +11 -10
- package/dist/ops/cpu/qkv.js +17 -13
- package/dist/ops/cpu/rope.js +23 -22
- package/dist/ops/cpu/scatterSub.js +16 -30
- package/dist/ops/dot16.d.ts +2 -0
- package/dist/ops/dot16.js +42 -0
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/add16.d.ts +1 -0
- package/dist/ops/grads/add16.js +27 -0
- package/dist/ops/grads/attentionMask.js +12 -19
- package/dist/ops/grads/gelu.js +4 -3
- package/dist/ops/grads/matMul16.d.ts +2 -0
- package/dist/ops/grads/matMul16.js +9 -0
- package/dist/ops/grads/matMulGelu.js +8 -7
- package/dist/ops/grads/normRMS.js +8 -7
- package/dist/ops/grads/{fusedSoftmax.d.ts → pack16.d.ts} +1 -1
- package/dist/ops/grads/pack16.js +7 -0
- package/dist/ops/grads/qkv.d.ts +3 -1
- package/dist/ops/grads/qkv.js +28 -22
- package/dist/ops/grads/rope.d.ts +2 -1
- package/dist/ops/grads/rope.js +6 -13
- package/dist/ops/grads/softmax16.d.ts +2 -0
- package/dist/ops/grads/softmax16.js +26 -0
- package/dist/ops/grads/unpack16.d.ts +2 -0
- package/dist/ops/grads/unpack16.js +6 -0
- package/dist/ops/grads/utils.d.ts +3 -0
- package/dist/ops/grads/utils.js +10 -0
- package/dist/ops/matMul16.d.ts +15 -0
- package/dist/ops/matMul16.js +13 -0
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mul16.d.ts +2 -0
- package/dist/ops/mul16.js +8 -0
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/pack16.d.ts +2 -0
- package/dist/ops/pack16.js +6 -0
- package/dist/ops/qkv.d.ts +1 -1
- package/dist/ops/qkv.js +8 -4
- package/dist/ops/reshape16.d.ts +2 -0
- package/dist/ops/reshape16.js +43 -0
- package/dist/ops/rope.d.ts +1 -1
- package/dist/ops/rope.js +8 -10
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/slice16.d.ts +2 -0
- package/dist/ops/slice16.js +9 -0
- package/dist/ops/softmax16.d.ts +2 -0
- package/dist/ops/softmax16.js +12 -0
- package/dist/ops/sub16.d.ts +2 -0
- package/dist/ops/sub16.js +8 -0
- package/dist/ops/sum16.d.ts +2 -0
- package/dist/ops/sum16.js +13 -0
- package/dist/ops/transpose16.d.ts +3 -0
- package/dist/ops/transpose16.js +41 -0
- package/dist/ops/unpack16.d.ts +2 -0
- package/dist/ops/unpack16.js +6 -0
- package/dist/ops/webgl/adamAdjust.js +3 -2
- package/dist/ops/webgl/adamMoments.js +2 -1
- package/dist/ops/webgl/appendCache.js +2 -1
- package/dist/ops/webgl/attentionMask.js +5 -4
- package/dist/ops/webgl/fusedSoftmax.js +6 -4
- package/dist/ops/webgl/gatherSub.js +7 -6
- package/dist/ops/webgl/gelu.js +3 -2
- package/dist/ops/webgl/log.js +12 -27
- package/dist/ops/webgl/matMul16.d.ts +1 -0
- package/dist/ops/webgl/matMul16.js +37 -0
- package/dist/ops/webgl/matMulGelu.js +17 -15
- package/dist/ops/webgl/matMulMul.js +13 -12
- package/dist/ops/webgl/mulDropout.js +9 -8
- package/dist/ops/webgl/normRMS.js +8 -7
- package/dist/ops/webgl/qkv.js +6 -5
- package/dist/ops/webgl/rope.js +11 -10
- package/dist/ops/webgl/scatterSub.js +6 -5
- package/dist/ops/webgpu/adamAdjust.js +12 -10
- package/dist/ops/webgpu/adamMoments.js +27 -22
- package/dist/ops/webgpu/add16.d.ts +1 -0
- package/dist/ops/webgpu/add16.js +14 -0
- package/dist/ops/webgpu/appendCache.js +64 -17
- package/dist/ops/webgpu/attentionMask.js +19 -62
- package/dist/ops/webgpu/attentionMask32_program.d.ts +19 -0
- package/dist/ops/webgpu/attentionMask32_program.js +54 -0
- package/dist/ops/webgpu/concat16.d.ts +19 -0
- package/dist/ops/webgpu/concat16.js +128 -0
- package/dist/ops/webgpu/gatherSub.js +9 -7
- package/dist/ops/webgpu/gelu.js +78 -31
- package/dist/ops/webgpu/index.js +12 -0
- package/dist/ops/webgpu/matMul16.d.ts +1 -0
- package/dist/ops/webgpu/matMul16.js +58 -0
- package/dist/ops/webgpu/matMul16_program.d.ts +42 -0
- package/dist/ops/webgpu/matMul16_program.js +336 -0
- package/dist/ops/webgpu/mul16.d.ts +1 -0
- package/dist/ops/webgpu/mul16.js +14 -0
- package/dist/ops/webgpu/normRMS.js +21 -40
- package/dist/ops/webgpu/normRMS16_program.d.ts +9 -0
- package/dist/ops/webgpu/normRMS16_program.js +24 -0
- package/dist/ops/webgpu/normRMS32_program.d.ts +9 -0
- package/dist/ops/webgpu/normRMS32_program.js +24 -0
- package/dist/ops/webgpu/normRMSGrad.js +113 -64
- package/dist/ops/webgpu/pack16.d.ts +1 -0
- package/dist/ops/webgpu/pack16.js +19 -0
- package/dist/ops/webgpu/pack16_program.d.ts +19 -0
- package/dist/ops/webgpu/pack16_program.js +92 -0
- package/dist/ops/webgpu/qkv.js +20 -55
- package/dist/ops/webgpu/rope.js +77 -22
- package/dist/ops/webgpu/scatterSub.js +9 -7
- package/dist/ops/webgpu/slice16.d.ts +7 -0
- package/dist/ops/webgpu/slice16.js +71 -0
- package/dist/{variable-Bm2OFwGI.js → ops/webgpu/softmax16.d.ts} +2 -8
- package/dist/ops/webgpu/softmax16.js +23 -0
- package/dist/ops/webgpu/softmax16_program.d.ts +13 -0
- package/dist/ops/webgpu/softmax16_program.js +73 -0
- package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +17 -0
- package/dist/ops/webgpu/softmax16_subgroup_program.js +75 -0
- package/dist/ops/webgpu/softmax16grad.d.ts +1 -0
- package/dist/ops/webgpu/softmax16grad.js +38 -0
- package/dist/ops/webgpu/sub16.d.ts +1 -0
- package/dist/ops/webgpu/sub16.js +14 -0
- package/dist/ops/webgpu/sum16.d.ts +1 -0
- package/dist/ops/webgpu/sum16.js +40 -0
- package/dist/ops/webgpu/transpose16.d.ts +1 -0
- package/dist/ops/webgpu/transpose16.js +35 -0
- package/dist/ops/webgpu/transpose16_program.d.ts +16 -0
- package/dist/ops/webgpu/transpose16_program.js +50 -0
- package/dist/ops/webgpu/transpose16_shared_program.d.ts +15 -0
- package/dist/ops/webgpu/transpose16_shared_program.js +71 -0
- package/dist/ops/webgpu/unpack16.d.ts +1 -0
- package/dist/ops/webgpu/unpack16.js +49 -0
- package/dist/ops/webgpu/utils/binary_op.d.ts +19 -0
- package/dist/ops/webgpu/utils/binary_op.js +79 -0
- package/dist/ops/webgpu/utils/deviceInfo.d.ts +7 -0
- package/dist/ops/webgpu/utils/deviceInfo.js +11 -0
- package/dist/ops/webgpu/utils/reductions.d.ts +32 -4
- package/dist/ops/webgpu/utils/reductions.js +236 -45
- package/dist/ops-CNI3TwqM.js +645 -0
- package/dist/pack16-CFUqumar.js +41 -0
- package/dist/{papaparse.min-C8l2Kvo1.js → papaparse.min-C0cScC2i.js} +2 -8
- package/dist/{parquet-C0Tlmv9c.js → parquet-BE8MU_ge.js} +201 -278
- package/dist/patches/PackedTensor.d.ts +12 -0
- package/dist/patches/PackedTensor.js +11 -0
- package/dist/patches/engine.d.ts +261 -0
- package/dist/patches/engine.js +10 -0
- package/dist/patches/tape.d.ts +12 -0
- package/dist/patches/tape.js +5 -0
- package/dist/patches/webgpu_backend.d.ts +18 -0
- package/dist/patches/webgpu_backend.js +57 -0
- package/dist/{tensor-CZr4dh61.js → patches/webgpu_base.d.ts} +5 -8
- package/dist/patches/webgpu_base.js +34 -0
- package/dist/patches/webgpu_program.d.ts +36 -0
- package/dist/patches/webgpu_program.js +401 -0
- package/dist/{pdf-kJD-f258.js → pdf-NIhmP3sq.js} +424 -428
- package/dist/random_width-DY6Kk2Dl.js +10051 -0
- package/dist/range-BMS52eQi.js +11 -0
- package/dist/reciprocal-CTmshQ9J.js +10 -0
- package/dist/{register_all_kernels-DIGpEwcf.js → register_all_kernels-Bwu1PTuU.js} +719 -9766
- package/dist/relu-yZ2-7WxU.js +10 -0
- package/dist/reshape-DevtBWtf.js +10 -0
- package/dist/rope-B5UUMsPi.js +32 -0
- package/dist/{scatter_nd_util-BQdz--Gn.js → scatter_nd_util-5EL-8VAQ.js} +1 -1
- package/dist/selu_util-D1w6yyTO.js +303 -0
- package/dist/{shared-DuP7ue-R.js → shared-BRksrJb3.js} +1 -17
- package/dist/shared-BuAXb4CI.js +2145 -0
- package/dist/sin-BGfy2HZo.js +16 -0
- package/dist/slice-D_gkkqZK.js +13 -0
- package/dist/slice_util-DtEldBfK.js +261 -0
- package/dist/softmax-ZHVebtR1.js +13 -0
- package/dist/split-DrfihRpZ.js +10 -0
- package/dist/squeeze-DZEpeblb.js +11 -0
- package/dist/stack-yOIAalTq.js +13 -0
- package/dist/sum-_fzj5ZTB.js +12 -0
- package/dist/tensor-DdQUJZlz.js +909 -0
- package/dist/tensor-f35l8Odg.js +8 -0
- package/dist/tensor1d-CeZuc-Rv.js +12 -0
- package/dist/tensor2d-G4Ys2GxX.js +15 -0
- package/dist/tensor4d-B8roDgtc.js +15 -0
- package/dist/tensor_util-DV-FP5Q3.js +523 -0
- package/dist/tfjs_backend-kNyO5L2d.js +653 -0
- package/dist/tile-BzyEiF-F.js +13 -0
- package/dist/tokeniser/CharTokeniser.js +1 -1
- package/dist/tokeniser/bpe.js +1 -1
- package/dist/training/Adam.d.ts +2 -1
- package/dist/training/Adam.js +12 -28
- package/dist/training/AdamExt.d.ts +1 -0
- package/dist/training/AdamExt.js +2 -2
- package/dist/training/DatasetBuilder.js +3 -20
- package/dist/training/FullTrainer.js +55 -48
- package/dist/training/Trainer.d.ts +11 -6
- package/dist/training/Trainer.js +51 -39
- package/dist/training/sparseCrossEntropy.js +3 -3
- package/dist/transpose-DKELTqhe.js +38 -0
- package/dist/utilities/arrayClose.js +7 -7
- package/dist/utilities/dummy.js +35 -27
- package/dist/utilities/multinomialCPU.js +2 -2
- package/dist/utilities/packed.d.ts +7 -0
- package/dist/utilities/packed.js +716 -0
- package/dist/utilities/performance.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/sentences.d.ts +5 -0
- package/dist/utilities/sentences.js +41 -0
- package/dist/utilities/weights.js +2 -2
- package/dist/variable-Bhn5bHYv.js +7 -0
- package/dist/{webgpu_program-DkQJOJSd.js → webgpu_program-Cigz-7RF.js} +15 -44
- package/dist/webgpu_util-BBCnKm2X.js +65 -0
- package/dist/zeros-2gldETuK.js +14 -0
- package/package.json +4 -3
- package/dist/Reshape-Bowtk9BP.js +0 -127
- package/dist/Reshape-DUqYftGC.js +0 -30
- package/dist/backend_util-CJIiDoV1.js +0 -749
- package/dist/broadcast_to-DzlNweb8.js +0 -44
- package/dist/concat-B912vBbo.js +0 -33
- package/dist/dropout-C-csYCLj.js +0 -193
- package/dist/exports_initializers-B8iZMgQ0.js +0 -16
- package/dist/gather-Dnpgw-YQ.js +0 -25
- package/dist/index-BzFyqcy-.js +0 -4457
- package/dist/index-C1rx_Ajs.js +0 -12076
- package/dist/kernel_funcs_utils-DKLK0Mg3.js +0 -466
- package/dist/log_sum_exp-DO6z8tSE.js +0 -103
- package/dist/mat_mul-DzjTFx-u.js +0 -27
- package/dist/mod-Dobti4j4.js +0 -27
- package/dist/ones-tIJeHlq-.js +0 -29
- package/dist/ops/fusedSoftmax.d.ts +0 -2
- package/dist/ops/fusedSoftmax.js +0 -10
- package/dist/ops/grads/fusedSoftmax.js +0 -22
- package/dist/ops-LuCMAnmM.js +0 -1525
- package/dist/random_width-CXVRloNK.js +0 -13670
- package/dist/range-CWcz7xFA.js +0 -26
- package/dist/reciprocal-C4rNcM-S.js +0 -25
- package/dist/relu-BjCh_SYb.js +0 -25
- package/dist/reshape-CnIwVG1c.js +0 -25
- package/dist/selu_util-OtRzVwW5.js +0 -719
- package/dist/shared-DmRsFyaJ.js +0 -3134
- package/dist/sin-gpDNRxE0.js +0 -47
- package/dist/slice-d0Vo9XTN.js +0 -28
- package/dist/softmax-D7Jj3p_P.js +0 -28
- package/dist/split-DK2k5eHf.js +0 -25
- package/dist/stack-DFatutCx.js +0 -27
- package/dist/sum-CJ0ULhmt.js +0 -27
- package/dist/tensor1d-vML0r3q6.js +0 -27
- package/dist/tensor2d-D76QGjF3.js +0 -30
- package/dist/tensor4d-Df1WlVDY.js +0 -30
- package/dist/webgpu_util-pLEV9tks.js +0 -80
- package/dist/zeros-Bj5rMYA7.js +0 -52
package/dist/index-BzFyqcy-.js
DELETED
|
@@ -1,4457 +0,0 @@
|
|
|
1
|
-
import { g as Gt } from "./index-D5v913EJ.js";
|
|
2
|
-
import { p as Q } from "./index-xuotMAFm.js";
|
|
3
|
-
import { B as pt } from "./index-Tf7vU29b.js";
|
|
4
|
-
/**
|
|
5
|
-
* @license
|
|
6
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
* =============================================================================
|
|
19
|
-
*/
|
|
20
|
-
const Fe = 1e-7, Re = 1e-4;
|
|
21
|
-
class Rs {
|
|
22
|
-
constructor(t, n) {
|
|
23
|
-
this.backend = t, this.dataMover = n, this.data = /* @__PURE__ */ new WeakMap(), this.dataIdsCount = 0;
|
|
24
|
-
}
|
|
25
|
-
get(t) {
|
|
26
|
-
return this.data.has(t) || this.dataMover.moveData(this.backend, t), this.data.get(t);
|
|
27
|
-
}
|
|
28
|
-
set(t, n) {
|
|
29
|
-
this.dataIdsCount++, this.data.set(t, n);
|
|
30
|
-
}
|
|
31
|
-
has(t) {
|
|
32
|
-
return this.data.has(t);
|
|
33
|
-
}
|
|
34
|
-
delete(t) {
|
|
35
|
-
return this.dataIdsCount--, this.data.delete(t);
|
|
36
|
-
}
|
|
37
|
-
numDataIds() {
|
|
38
|
-
return this.dataIdsCount;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
class xe {
|
|
42
|
-
refCount(t) {
|
|
43
|
-
return B("refCount");
|
|
44
|
-
}
|
|
45
|
-
incRef(t) {
|
|
46
|
-
return B("incRef");
|
|
47
|
-
}
|
|
48
|
-
timerAvailable() {
|
|
49
|
-
return !0;
|
|
50
|
-
}
|
|
51
|
-
time(t) {
|
|
52
|
-
return B("time");
|
|
53
|
-
}
|
|
54
|
-
read(t) {
|
|
55
|
-
return B("read");
|
|
56
|
-
}
|
|
57
|
-
readSync(t) {
|
|
58
|
-
return B("readSync");
|
|
59
|
-
}
|
|
60
|
-
readToGPU(t, n) {
|
|
61
|
-
return B("readToGPU");
|
|
62
|
-
}
|
|
63
|
-
numDataIds() {
|
|
64
|
-
return B("numDataIds");
|
|
65
|
-
}
|
|
66
|
-
disposeData(t, n) {
|
|
67
|
-
return B("disposeData");
|
|
68
|
-
}
|
|
69
|
-
write(t, n, s) {
|
|
70
|
-
return B("write");
|
|
71
|
-
}
|
|
72
|
-
move(t, n, s, r, a) {
|
|
73
|
-
return B("move");
|
|
74
|
-
}
|
|
75
|
-
createTensorFromGPUData(t, n, s) {
|
|
76
|
-
return B("createTensorFromGPUData");
|
|
77
|
-
}
|
|
78
|
-
memory() {
|
|
79
|
-
return B("memory");
|
|
80
|
-
}
|
|
81
|
-
/** Returns the highest precision for floats in bits (e.g. 16 or 32) */
|
|
82
|
-
floatPrecision() {
|
|
83
|
-
return B("floatPrecision");
|
|
84
|
-
}
|
|
85
|
-
/** Returns the smallest representable number. */
|
|
86
|
-
epsilon() {
|
|
87
|
-
return this.floatPrecision() === 32 ? Fe : Re;
|
|
88
|
-
}
|
|
89
|
-
dispose() {
|
|
90
|
-
return B("dispose");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function B(e) {
|
|
94
|
-
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`);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* @license
|
|
98
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
99
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
100
|
-
* you may not use this file except in compliance with the License.
|
|
101
|
-
* You may obtain a copy of the License at
|
|
102
|
-
*
|
|
103
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
104
|
-
*
|
|
105
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
106
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
107
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
108
|
-
* See the License for the specific language governing permissions and
|
|
109
|
-
* limitations under the License.
|
|
110
|
-
* =============================================================================
|
|
111
|
-
*/
|
|
112
|
-
function xs(e) {
|
|
113
|
-
let t = e.length, n = 0;
|
|
114
|
-
for (; t > 0; )
|
|
115
|
-
n = Math.random() * t | 0, t--, Ne(e, t, n);
|
|
116
|
-
}
|
|
117
|
-
function Ns(e, t, n) {
|
|
118
|
-
return Math.max(e, Math.min(t, n));
|
|
119
|
-
}
|
|
120
|
-
function $s(e) {
|
|
121
|
-
return e % 2 === 0 ? e : e + 1;
|
|
122
|
-
}
|
|
123
|
-
function Ne(e, t, n) {
|
|
124
|
-
const s = e[t];
|
|
125
|
-
e[t] = e[n], e[n] = s;
|
|
126
|
-
}
|
|
127
|
-
function Cs(e) {
|
|
128
|
-
let t = 0;
|
|
129
|
-
for (let n = 0; n < e.length; n++)
|
|
130
|
-
t += e[n];
|
|
131
|
-
return t;
|
|
132
|
-
}
|
|
133
|
-
function p(e, t) {
|
|
134
|
-
if (!e)
|
|
135
|
-
throw new Error(typeof t == "string" ? t : t());
|
|
136
|
-
}
|
|
137
|
-
function te(e, t, n = "") {
|
|
138
|
-
p(xt(e, t), () => n + ` Shapes ${e} and ${t} must match`);
|
|
139
|
-
}
|
|
140
|
-
function Ps(e) {
|
|
141
|
-
p(e != null, () => "The input to the tensor constructor must be a non-null value.");
|
|
142
|
-
}
|
|
143
|
-
function z(e) {
|
|
144
|
-
if (e.length === 0)
|
|
145
|
-
return 1;
|
|
146
|
-
let t = e[0];
|
|
147
|
-
for (let n = 1; n < e.length; n++)
|
|
148
|
-
t *= e[n];
|
|
149
|
-
return t;
|
|
150
|
-
}
|
|
151
|
-
function Ls(e) {
|
|
152
|
-
return e.length === 0;
|
|
153
|
-
}
|
|
154
|
-
function xt(e, t) {
|
|
155
|
-
if (e === t)
|
|
156
|
-
return !0;
|
|
157
|
-
if (e == null || t == null || e.length !== t.length)
|
|
158
|
-
return !1;
|
|
159
|
-
for (let n = 0; n < e.length; n++)
|
|
160
|
-
if (e[n] !== t[n])
|
|
161
|
-
return !1;
|
|
162
|
-
return !0;
|
|
163
|
-
}
|
|
164
|
-
function $e(e) {
|
|
165
|
-
return e % 1 === 0;
|
|
166
|
-
}
|
|
167
|
-
function _s(e) {
|
|
168
|
-
const t = Math.ceil(Math.sqrt(e));
|
|
169
|
-
return [t, Math.ceil(e / t)];
|
|
170
|
-
}
|
|
171
|
-
function ht(e, t) {
|
|
172
|
-
return t <= e.length ? e : e + " ".repeat(t - e.length);
|
|
173
|
-
}
|
|
174
|
-
function Os(e, t = (r) => 0, n, s) {
|
|
175
|
-
return new Promise((r, a) => {
|
|
176
|
-
let o = 0;
|
|
177
|
-
const i = () => {
|
|
178
|
-
if (e()) {
|
|
179
|
-
r();
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
o++;
|
|
183
|
-
const c = t(o);
|
|
184
|
-
if (n != null && o >= n) {
|
|
185
|
-
a();
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
s != null ? s(i, c) : setTimeout(i, c);
|
|
189
|
-
};
|
|
190
|
-
i();
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
function Gs(e, t) {
|
|
194
|
-
let n = 1, s = -1;
|
|
195
|
-
for (let a = 0; a < e.length; ++a)
|
|
196
|
-
if (e[a] >= 0)
|
|
197
|
-
n *= e[a];
|
|
198
|
-
else if (e[a] === -1) {
|
|
199
|
-
if (s !== -1)
|
|
200
|
-
throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${a}`);
|
|
201
|
-
s = a;
|
|
202
|
-
} else if (e[a] < 0)
|
|
203
|
-
throw Error(`Shapes can not be < 0. Found ${e[a]} at dim ${a}`);
|
|
204
|
-
if (s === -1) {
|
|
205
|
-
if (t > 0 && t !== n)
|
|
206
|
-
throw Error(`Size(${t}) must match the product of shape ${e}`);
|
|
207
|
-
return e;
|
|
208
|
-
}
|
|
209
|
-
if (n === 0)
|
|
210
|
-
throw Error(`Cannot infer the missing size in [${e}] when there are 0 elements`);
|
|
211
|
-
if (t % n !== 0)
|
|
212
|
-
throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${n}`);
|
|
213
|
-
const r = e.slice();
|
|
214
|
-
return r[s] = t / n, r;
|
|
215
|
-
}
|
|
216
|
-
function Ce(e, t) {
|
|
217
|
-
const n = t.length;
|
|
218
|
-
return e = e == null ? t.map((s, r) => r) : [].concat(e), p(e.every((s) => s >= -n && s < n), () => `All values in axis param must be in range [-${n}, ${n}) but got axis ${e}`), p(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);
|
|
219
|
-
}
|
|
220
|
-
function Us(e, t) {
|
|
221
|
-
const n = [], s = [], r = t != null && Array.isArray(t) && t.length === 0, a = t == null || r ? null : Ce(t, e).sort();
|
|
222
|
-
let o = 0;
|
|
223
|
-
for (let i = 0; i < e.length; ++i) {
|
|
224
|
-
if (a != null) {
|
|
225
|
-
if (a[o] === i && e[i] !== 1)
|
|
226
|
-
throw new Error(`Can't squeeze axis ${i} since its dim '${e[i]}' is not 1`);
|
|
227
|
-
(a[o] == null || a[o] > i) && e[i] === 1 && (n.push(e[i]), s.push(i)), a[o] <= i && o++;
|
|
228
|
-
}
|
|
229
|
-
e[i] !== 1 && (n.push(e[i]), s.push(i));
|
|
230
|
-
}
|
|
231
|
-
return { newShape: n, keptDims: s };
|
|
232
|
-
}
|
|
233
|
-
function zs(e, t) {
|
|
234
|
-
return ee(e, t);
|
|
235
|
-
}
|
|
236
|
-
function ee(e, t) {
|
|
237
|
-
let n = null;
|
|
238
|
-
if (e == null || e === "float32")
|
|
239
|
-
n = new Float32Array(t);
|
|
240
|
-
else if (e === "int32")
|
|
241
|
-
n = new Int32Array(t);
|
|
242
|
-
else if (e === "bool")
|
|
243
|
-
n = new Uint8Array(t);
|
|
244
|
-
else if (e === "string")
|
|
245
|
-
n = new Array(t);
|
|
246
|
-
else
|
|
247
|
-
throw new Error(`Unknown data type ${e}`);
|
|
248
|
-
return n;
|
|
249
|
-
}
|
|
250
|
-
function Pe(e, t) {
|
|
251
|
-
for (let n = 0; n < e.length; n++) {
|
|
252
|
-
const s = e[n];
|
|
253
|
-
if (isNaN(s) || !isFinite(s))
|
|
254
|
-
throw Error(`A tensor of type ${t} being uploaded contains ${s}.`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function Le(e) {
|
|
258
|
-
return e === "bool" || e === "complex64" || e === "float32" || e === "int32" || e === "string";
|
|
259
|
-
}
|
|
260
|
-
function Vs(e, t) {
|
|
261
|
-
return !(t === "complex64" || t === "float32" && e !== "complex64" || t === "int32" && e !== "float32" && e !== "complex64" || t === "bool" && e === "bool");
|
|
262
|
-
}
|
|
263
|
-
function It(e) {
|
|
264
|
-
if (e === "float32" || e === "int32")
|
|
265
|
-
return 4;
|
|
266
|
-
if (e === "complex64")
|
|
267
|
-
return 8;
|
|
268
|
-
if (e === "bool")
|
|
269
|
-
return 1;
|
|
270
|
-
throw new Error(`Unknown dtype ${e}`);
|
|
271
|
-
}
|
|
272
|
-
function _e(e) {
|
|
273
|
-
if (e == null)
|
|
274
|
-
return 0;
|
|
275
|
-
let t = 0;
|
|
276
|
-
return e.forEach((n) => t += n.length), t;
|
|
277
|
-
}
|
|
278
|
-
function Nt(e) {
|
|
279
|
-
return typeof e == "string" || e instanceof String;
|
|
280
|
-
}
|
|
281
|
-
function Oe(e) {
|
|
282
|
-
return typeof e == "boolean";
|
|
283
|
-
}
|
|
284
|
-
function Ge(e) {
|
|
285
|
-
return typeof e == "number";
|
|
286
|
-
}
|
|
287
|
-
function yt(e) {
|
|
288
|
-
return Array.isArray(e) ? yt(e[0]) : e instanceof Float32Array ? "float32" : e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray ? "int32" : Ge(e) ? "float32" : Nt(e) ? "string" : Oe(e) ? "bool" : "float32";
|
|
289
|
-
}
|
|
290
|
-
function lt(e) {
|
|
291
|
-
return !!(e && e.constructor && e.call && e.apply);
|
|
292
|
-
}
|
|
293
|
-
function Ws(e, t) {
|
|
294
|
-
for (let n = t; n < e; ++n)
|
|
295
|
-
if (e % n === 0)
|
|
296
|
-
return n;
|
|
297
|
-
return e;
|
|
298
|
-
}
|
|
299
|
-
function $t(e) {
|
|
300
|
-
const t = e.length;
|
|
301
|
-
if (t < 2)
|
|
302
|
-
return [];
|
|
303
|
-
const n = new Array(t - 1);
|
|
304
|
-
n[t - 2] = e[t - 1];
|
|
305
|
-
for (let s = t - 3; s >= 0; --s)
|
|
306
|
-
n[s] = n[s + 1] * e[s + 1];
|
|
307
|
-
return n;
|
|
308
|
-
}
|
|
309
|
-
function ne(e, t, n, s = !1) {
|
|
310
|
-
const r = new Array();
|
|
311
|
-
if (t.length === 1) {
|
|
312
|
-
const a = t[0] * (s ? 2 : 1);
|
|
313
|
-
for (let o = 0; o < a; o++)
|
|
314
|
-
r[o] = n[e + o];
|
|
315
|
-
} else {
|
|
316
|
-
const a = t[0], o = t.slice(1), i = o.reduce((c, l) => c * l) * (s ? 2 : 1);
|
|
317
|
-
for (let c = 0; c < a; c++)
|
|
318
|
-
r[c] = ne(e + c * i, o, n, s);
|
|
319
|
-
}
|
|
320
|
-
return r;
|
|
321
|
-
}
|
|
322
|
-
function ct(e, t, n = !1) {
|
|
323
|
-
if (e.length === 0)
|
|
324
|
-
return t[0];
|
|
325
|
-
const s = e.reduce((r, a) => r * a) * (n ? 2 : 1);
|
|
326
|
-
if (s === 0)
|
|
327
|
-
return [];
|
|
328
|
-
if (s !== t.length)
|
|
329
|
-
throw new Error(`[${e}] does not match the input size ${t.length}${n ? " for a complex tensor" : ""}.`);
|
|
330
|
-
return ne(0, e, t, n);
|
|
331
|
-
}
|
|
332
|
-
function js(e, t) {
|
|
333
|
-
if (Array.isArray(e))
|
|
334
|
-
return e;
|
|
335
|
-
if (t === "float32")
|
|
336
|
-
return e instanceof Float32Array ? e : new Float32Array(e);
|
|
337
|
-
if (t === "int32")
|
|
338
|
-
return e instanceof Int32Array ? e : new Int32Array(e);
|
|
339
|
-
if (t === "bool" || t === "string")
|
|
340
|
-
return Uint8Array.from(new Int32Array(e));
|
|
341
|
-
throw new Error(`Unknown dtype ${t}`);
|
|
342
|
-
}
|
|
343
|
-
function Ue(e, t) {
|
|
344
|
-
const n = se(e, t);
|
|
345
|
-
for (let s = 0; s < n.length; s++)
|
|
346
|
-
n[s] = 1;
|
|
347
|
-
return n;
|
|
348
|
-
}
|
|
349
|
-
function se(e, t) {
|
|
350
|
-
if (t == null || t === "float32" || t === "complex64")
|
|
351
|
-
return new Float32Array(e);
|
|
352
|
-
if (t === "int32")
|
|
353
|
-
return new Int32Array(e);
|
|
354
|
-
if (t === "bool")
|
|
355
|
-
return new Uint8Array(e);
|
|
356
|
-
throw new Error(`Unknown data type ${t}`);
|
|
357
|
-
}
|
|
358
|
-
function qs(e, t) {
|
|
359
|
-
const n = e.reduce((s, r) => s * r, 1);
|
|
360
|
-
if (t == null || t === "float32")
|
|
361
|
-
return ct(e, new Float32Array(n));
|
|
362
|
-
if (t === "int32")
|
|
363
|
-
return ct(e, new Int32Array(n));
|
|
364
|
-
if (t === "bool")
|
|
365
|
-
return ct(e, new Uint8Array(n));
|
|
366
|
-
throw new Error(`Unknown data type ${t}`);
|
|
367
|
-
}
|
|
368
|
-
function Ct(e) {
|
|
369
|
-
e.forEach((t) => {
|
|
370
|
-
p(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${e}].`);
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
function Ks(e, t, n) {
|
|
374
|
-
if (t === 0)
|
|
375
|
-
return 0;
|
|
376
|
-
if (t === 1)
|
|
377
|
-
return e[0];
|
|
378
|
-
let s = e[e.length - 1];
|
|
379
|
-
for (let r = 0; r < e.length - 1; ++r)
|
|
380
|
-
s += n[r] * e[r];
|
|
381
|
-
return s;
|
|
382
|
-
}
|
|
383
|
-
function Hs(e, t, n) {
|
|
384
|
-
if (t === 0)
|
|
385
|
-
return [];
|
|
386
|
-
if (t === 1)
|
|
387
|
-
return [e];
|
|
388
|
-
const s = new Array(t);
|
|
389
|
-
for (let r = 0; r < s.length - 1; ++r)
|
|
390
|
-
s[r] = Math.floor(e / n[r]), e -= s[r] * n[r];
|
|
391
|
-
return s[s.length - 1] = e, s;
|
|
392
|
-
}
|
|
393
|
-
function Pt(e) {
|
|
394
|
-
return e && e.then && typeof e.then == "function";
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* @license
|
|
398
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
399
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
400
|
-
* you may not use this file except in compliance with the License.
|
|
401
|
-
* You may obtain a copy of the License at
|
|
402
|
-
*
|
|
403
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
404
|
-
*
|
|
405
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
406
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
407
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
408
|
-
* See the License for the specific language governing permissions and
|
|
409
|
-
* limitations under the License.
|
|
410
|
-
* =============================================================================
|
|
411
|
-
*/
|
|
412
|
-
const Ut = "tfjsflags";
|
|
413
|
-
class ze {
|
|
414
|
-
// tslint:disable-next-line: no-any
|
|
415
|
-
constructor(t) {
|
|
416
|
-
this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = Ve, this.populateURLFlags();
|
|
417
|
-
}
|
|
418
|
-
setPlatform(t, n) {
|
|
419
|
-
this.platform != null && (S().getBool("IS_TEST") || S().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform = n;
|
|
420
|
-
}
|
|
421
|
-
registerFlag(t, n, s) {
|
|
422
|
-
if (this.flagRegistry[t] = { evaluationFn: n, setHook: s }, this.urlFlags[t] != null) {
|
|
423
|
-
const r = this.urlFlags[t];
|
|
424
|
-
S().getBool("IS_TEST") || S().getBool("PROD") || console.warn(`Setting feature override from URL ${t}: ${r}.`), this.set(t, r);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
async getAsync(t) {
|
|
428
|
-
return t in this.flags ? this.flags[t] : (this.flags[t] = await this.evaluateFlag(t), this.flags[t]);
|
|
429
|
-
}
|
|
430
|
-
get(t) {
|
|
431
|
-
if (t in this.flags)
|
|
432
|
-
return this.flags[t];
|
|
433
|
-
const n = this.evaluateFlag(t);
|
|
434
|
-
if (Pt(n))
|
|
435
|
-
throw new Error(`Flag ${t} cannot be synchronously evaluated. Please use getAsync() instead.`);
|
|
436
|
-
return this.flags[t] = n, this.flags[t];
|
|
437
|
-
}
|
|
438
|
-
getNumber(t) {
|
|
439
|
-
return this.get(t);
|
|
440
|
-
}
|
|
441
|
-
getBool(t) {
|
|
442
|
-
return this.get(t);
|
|
443
|
-
}
|
|
444
|
-
getString(t) {
|
|
445
|
-
return this.get(t);
|
|
446
|
-
}
|
|
447
|
-
getFlags() {
|
|
448
|
-
return this.flags;
|
|
449
|
-
}
|
|
450
|
-
// For backwards compatibility.
|
|
451
|
-
get features() {
|
|
452
|
-
return this.flags;
|
|
453
|
-
}
|
|
454
|
-
set(t, n) {
|
|
455
|
-
if (this.flagRegistry[t] == null)
|
|
456
|
-
throw new Error(`Cannot set flag ${t} as it has not been registered.`);
|
|
457
|
-
this.flags[t] = n, this.flagRegistry[t].setHook != null && this.flagRegistry[t].setHook(n);
|
|
458
|
-
}
|
|
459
|
-
evaluateFlag(t) {
|
|
460
|
-
if (this.flagRegistry[t] == null)
|
|
461
|
-
throw new Error(`Cannot evaluate flag '${t}': no evaluation function found.`);
|
|
462
|
-
return this.flagRegistry[t].evaluationFn();
|
|
463
|
-
}
|
|
464
|
-
setFlags(t) {
|
|
465
|
-
this.flags = Object.assign({}, t);
|
|
466
|
-
}
|
|
467
|
-
reset() {
|
|
468
|
-
this.flags = {}, this.urlFlags = {}, this.populateURLFlags();
|
|
469
|
-
}
|
|
470
|
-
populateURLFlags() {
|
|
471
|
-
if (typeof this.global > "u" || typeof this.global.location > "u" || typeof this.global.location.search > "u")
|
|
472
|
-
return;
|
|
473
|
-
const t = this.getQueryParams(this.global.location.search);
|
|
474
|
-
Ut in t && t[Ut].split(",").forEach((s) => {
|
|
475
|
-
const [r, a] = s.split(":");
|
|
476
|
-
this.urlFlags[r] = je(r, a);
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
function Ve(e) {
|
|
481
|
-
const t = {};
|
|
482
|
-
return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (n, ...s) => (We(t, s[0], s[1]), s.join("="))), t;
|
|
483
|
-
}
|
|
484
|
-
function We(e, t, n) {
|
|
485
|
-
e[decodeURIComponent(t)] = decodeURIComponent(n || "");
|
|
486
|
-
}
|
|
487
|
-
function je(e, t) {
|
|
488
|
-
const n = t.toLowerCase();
|
|
489
|
-
return n === "true" || n === "false" ? n === "true" : `${+n}` === n ? +n : t;
|
|
490
|
-
}
|
|
491
|
-
function S() {
|
|
492
|
-
return re;
|
|
493
|
-
}
|
|
494
|
-
let re = null;
|
|
495
|
-
function qe(e) {
|
|
496
|
-
re = e;
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* @license
|
|
500
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
501
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
502
|
-
* you may not use this file except in compliance with the License.
|
|
503
|
-
* You may obtain a copy of the License at
|
|
504
|
-
*
|
|
505
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
506
|
-
*
|
|
507
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
508
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
509
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
510
|
-
* See the License for the specific language governing permissions and
|
|
511
|
-
* limitations under the License.
|
|
512
|
-
* =============================================================================
|
|
513
|
-
*/
|
|
514
|
-
let bt;
|
|
515
|
-
function ae() {
|
|
516
|
-
if (bt == null) {
|
|
517
|
-
let e;
|
|
518
|
-
if (typeof window < "u")
|
|
519
|
-
e = window;
|
|
520
|
-
else if (typeof Gt < "u")
|
|
521
|
-
e = Gt;
|
|
522
|
-
else if (typeof Q < "u")
|
|
523
|
-
e = Q;
|
|
524
|
-
else if (typeof self < "u")
|
|
525
|
-
e = self;
|
|
526
|
-
else
|
|
527
|
-
throw new Error("Could not find a global object");
|
|
528
|
-
bt = e;
|
|
529
|
-
}
|
|
530
|
-
return bt;
|
|
531
|
-
}
|
|
532
|
-
function Ke() {
|
|
533
|
-
const e = ae();
|
|
534
|
-
return e._tfGlobals == null && (e._tfGlobals = /* @__PURE__ */ new Map()), e._tfGlobals;
|
|
535
|
-
}
|
|
536
|
-
function Lt(e, t) {
|
|
537
|
-
const n = Ke();
|
|
538
|
-
if (n.has(e))
|
|
539
|
-
return n.get(e);
|
|
540
|
-
{
|
|
541
|
-
const s = t();
|
|
542
|
-
return n.set(e, s), n.get(e);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
const He = "Abs", Xs = "Acos", Js = "Acosh", oe = "Add", Ys = "AddN", Zs = "All", Qs = "Any", tr = "ArgMax", er = "ArgMin", nr = "Asin", sr = "Asinh", rr = "Atan", ar = "Atanh", or = "Atan2", ir = "AvgPool", cr = "AvgPoolGrad", lr = "AvgPool3D", ur = "AvgPool3DGrad", hr = "BatchMatMul", dr = "BatchToSpaceND", fr = "Bincount", gr = "BitwiseAnd", mr = "BroadcastTo", pr = "BroadcastArgs", ie = "Cast", yr = "Ceil", br = "ClipByValue", wr = "Complex", Xe = "ComplexAbs", Sr = "Concat", kr = "Conv2D", Ir = "Conv2DBackpropFilter", Tr = "Conv2DBackpropInput", Ar = "Conv3D", Er = "Conv3DBackpropFilterV2", vr = "Conv3DBackpropInputV2", Br = "Cos", Mr = "Cosh", Dr = "Cumprod", Fr = "Cumsum", Rr = "CropAndResize", xr = "DenseBincount", Nr = "DepthToSpace", $r = "DepthwiseConv2dNative", Cr = "DepthwiseConv2dNativeBackpropFilter", Pr = "DepthwiseConv2dNativeBackpropInput", Lr = "Diag", _r = "Dilation2D", Or = "Dilation2DBackpropInput", Gr = "Dilation2DBackpropFilter", Ur = "Draw", Je = "RealDiv", zr = "Einsum", Vr = "Elu", Wr = "EluGrad", jr = "Erf", qr = "Equal", Kr = "Exp", Hr = "ExpandDims", Xr = "Expm1", Jr = "FFT", Ye = "Fill", Yr = "FlipLeftRight", Zr = "Floor", Ze = "FloorDiv", Qr = "FusedBatchNorm", ta = "GatherV2", ea = "GatherNd", na = "Greater", sa = "GreaterEqual", ce = "Identity", ra = "IFFT", aa = "Imag", oa = "IsFinite", ia = "IsInf", ca = "IsNan", la = "LeakyRelu", ua = "Less", ha = "LessEqual", da = "LinSpace", fa = "Log", ga = "Log1p", ma = "LogicalAnd", pa = "LogicalNot", ya = "LogicalOr", ba = "LogSoftmax", wa = "LRN", Sa = "LRNGrad", ka = "Max", Qe = "Maximum", Ia = "MaxPool", Ta = "MaxPoolGrad", Aa = "MaxPool3D", Ea = "MaxPool3DGrad", va = "MaxPoolWithArgmax", Ba = "Mean", Ma = "Min", Da = "Minimum", Fa = "MirrorPad", Ra = "Mod", xa = "Multinomial", tn = "Multiply", Na = "Neg", $a = "NotEqual", Ca = "NonMaxSuppressionV3", Pa = "NonMaxSuppressionV4", La = "NonMaxSuppressionV5", _a = "OnesLike", Oa = "OneHot", Ga = "Pack", Ua = "PadV2", en = "Pow", za = "Prelu", Va = "Prod", Wa = "RaggedGather", ja = "RaggedRange", qa = "RaggedTensorToTensor", Ka = "Range", Ha = "Real", Xa = "Reciprocal", Ja = "Relu", Ya = "Reshape", Za = "ResizeNearestNeighbor", Qa = "ResizeNearestNeighborGrad", to = "ResizeBilinear", eo = "ResizeBilinearGrad", no = "Relu6", so = "Reverse", ro = "Round", ao = "Rsqrt", oo = "ScatterNd", io = "TensorScatterUpdate", co = "SearchSorted", lo = "Select", uo = "Selu", ho = "Slice", fo = "Sin", go = "Sinh", mo = "Sign", po = "Sigmoid", yo = "Softplus", nn = "Sqrt", bo = "Sum", wo = "SpaceToBatchND", So = "SplitV", ko = "Softmax", Io = "SparseFillEmptyRows", To = "SparseReshape", Ao = "SparseSegmentMean", Eo = "SparseSegmentSum", vo = "SparseToDense", Bo = "SquaredDifference", Mo = "Square", Do = "StaticRegexReplace", Fo = "StridedSlice", Ro = "StringNGrams", xo = "StringSplit", No = "StringToHashBucketFast", sn = "Sub", $o = "Tan", Co = "Tanh", Po = "Tile", Lo = "TopK", _o = "Transform", Oo = "Transpose", Go = "Unique", Uo = "Unpack", zo = "UnsortedSegmentSum", rn = "ZerosLike", Vo = "Step", Wo = "FromPixels", jo = "RotateWithOffset", qo = "_FusedMatMul", Ko = "FusedConv2D", Ho = "FusedDepthwiseConv2D";
|
|
546
|
-
/**
|
|
547
|
-
* @license
|
|
548
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
549
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
550
|
-
* you may not use this file except in compliance with the License.
|
|
551
|
-
* You may obtain a copy of the License at
|
|
552
|
-
*
|
|
553
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
554
|
-
*
|
|
555
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
556
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
557
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
558
|
-
* See the License for the specific language governing permissions and
|
|
559
|
-
* limitations under the License.
|
|
560
|
-
* =============================================================================
|
|
561
|
-
*/
|
|
562
|
-
function O(...e) {
|
|
563
|
-
S().getBool("IS_TEST") || S().getBool("PROD") || console.warn(...e);
|
|
564
|
-
}
|
|
565
|
-
function Xo(...e) {
|
|
566
|
-
S().getBool("IS_TEST") || S().getBool("PROD") || console.log(...e);
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* @license
|
|
570
|
-
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
571
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
572
|
-
* you may not use this file except in compliance with the License.
|
|
573
|
-
* You may obtain a copy of the License at
|
|
574
|
-
*
|
|
575
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
576
|
-
*
|
|
577
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
578
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
579
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
580
|
-
* See the License for the specific language governing permissions and
|
|
581
|
-
* limitations under the License.
|
|
582
|
-
* =============================================================================
|
|
583
|
-
*/
|
|
584
|
-
const ft = Lt("kernelRegistry", () => /* @__PURE__ */ new Map()), Tt = Lt("gradRegistry", () => /* @__PURE__ */ new Map());
|
|
585
|
-
function zt(e, t) {
|
|
586
|
-
const n = le(e, t);
|
|
587
|
-
return ft.get(n);
|
|
588
|
-
}
|
|
589
|
-
function Vt(e) {
|
|
590
|
-
return Tt.get(e);
|
|
591
|
-
}
|
|
592
|
-
function Wt(e) {
|
|
593
|
-
const t = ft.entries(), n = [];
|
|
594
|
-
for (; ; ) {
|
|
595
|
-
const { done: s, value: r } = t.next();
|
|
596
|
-
if (s)
|
|
597
|
-
break;
|
|
598
|
-
const [a, o] = r, [i] = a.split("_");
|
|
599
|
-
i === e && n.push(o);
|
|
600
|
-
}
|
|
601
|
-
return n;
|
|
602
|
-
}
|
|
603
|
-
function Jo(e) {
|
|
604
|
-
const { kernelName: t, backendName: n } = e, s = le(t, n);
|
|
605
|
-
ft.has(s) && O(`The kernel '${t}' for backend '${n}' is already registered`), ft.set(s, e);
|
|
606
|
-
}
|
|
607
|
-
function Yo(e) {
|
|
608
|
-
const { kernelName: t } = e;
|
|
609
|
-
Tt.has(t) && S().getBool("DEBUG") && O(`Overriding the gradient for '${t}'`), Tt.set(t, e);
|
|
610
|
-
}
|
|
611
|
-
function le(e, t) {
|
|
612
|
-
return `${t}_${e}`;
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* @license
|
|
616
|
-
* Copyright 2023 Google LLC.
|
|
617
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
618
|
-
* you may not use this file except in compliance with the License.
|
|
619
|
-
* You may obtain a copy of the License at
|
|
620
|
-
*
|
|
621
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
622
|
-
*
|
|
623
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
624
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
625
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
626
|
-
* See the License for the specific language governing permissions and
|
|
627
|
-
* limitations under the License.
|
|
628
|
-
* =============================================================================
|
|
629
|
-
*/
|
|
630
|
-
function ue(e) {
|
|
631
|
-
return e instanceof Float32Array || e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray;
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* @license
|
|
635
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
636
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
637
|
-
* you may not use this file except in compliance with the License.
|
|
638
|
-
* You may obtain a copy of the License at
|
|
639
|
-
*
|
|
640
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
641
|
-
*
|
|
642
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
643
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
644
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
645
|
-
* See the License for the specific language governing permissions and
|
|
646
|
-
* limitations under the License.
|
|
647
|
-
* =============================================================================
|
|
648
|
-
*/
|
|
649
|
-
function Zo(e, t) {
|
|
650
|
-
return t === "string" ? he(e) : _t([e], t);
|
|
651
|
-
}
|
|
652
|
-
function an(e, t) {
|
|
653
|
-
return e instanceof Float32Array && t === "float32" || e instanceof Int32Array && t === "int32" || e instanceof Uint8Array && t === "bool";
|
|
654
|
-
}
|
|
655
|
-
function _t(e, t) {
|
|
656
|
-
if (t === "string")
|
|
657
|
-
throw new Error("Cannot convert a string[] to a TypedArray");
|
|
658
|
-
if (Array.isArray(e) && (e = ut(e)), S().getBool("DEBUG") && Pe(e, t), an(e, t))
|
|
659
|
-
return e;
|
|
660
|
-
if (t == null || t === "float32" || t === "complex64")
|
|
661
|
-
return new Float32Array(e);
|
|
662
|
-
if (t === "int32")
|
|
663
|
-
return new Int32Array(e);
|
|
664
|
-
if (t === "bool") {
|
|
665
|
-
const n = new Uint8Array(e.length);
|
|
666
|
-
for (let s = 0; s < n.length; ++s)
|
|
667
|
-
Math.round(e[s]) !== 0 && (n[s] = 1);
|
|
668
|
-
return n;
|
|
669
|
-
} else
|
|
670
|
-
throw new Error(`Unknown data type ${t}`);
|
|
671
|
-
}
|
|
672
|
-
function gt() {
|
|
673
|
-
return S().platform.now();
|
|
674
|
-
}
|
|
675
|
-
function he(e, t = "utf-8") {
|
|
676
|
-
return t = t || "utf-8", S().platform.encode(e, t);
|
|
677
|
-
}
|
|
678
|
-
function jt(e, t = "utf-8") {
|
|
679
|
-
return t = t || "utf-8", S().platform.decode(e, t);
|
|
680
|
-
}
|
|
681
|
-
function R(e) {
|
|
682
|
-
return S().platform.isTypedArray != null ? S().platform.isTypedArray(e) : ue(e);
|
|
683
|
-
}
|
|
684
|
-
function ut(e, t = [], n = !1) {
|
|
685
|
-
if (t == null && (t = []), typeof e == "boolean" || typeof e == "number" || typeof e == "string" || Pt(e) || e == null || R(e) && n)
|
|
686
|
-
t.push(e);
|
|
687
|
-
else if (Array.isArray(e) || R(e))
|
|
688
|
-
for (let s = 0; s < e.length; ++s)
|
|
689
|
-
ut(e[s], t, n);
|
|
690
|
-
else {
|
|
691
|
-
let s = -1;
|
|
692
|
-
for (const r of Object.keys(e))
|
|
693
|
-
/^([1-9]+[0-9]*|0)$/.test(r) && (s = Math.max(s, Number(r)));
|
|
694
|
-
for (let r = 0; r <= s; r++)
|
|
695
|
-
ut(e[r], t, n);
|
|
696
|
-
}
|
|
697
|
-
return t;
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* @license
|
|
701
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
702
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
703
|
-
* you may not use this file except in compliance with the License.
|
|
704
|
-
* You may obtain a copy of the License at
|
|
705
|
-
*
|
|
706
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
707
|
-
*
|
|
708
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
709
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
710
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
711
|
-
* See the License for the specific language governing permissions and
|
|
712
|
-
* limitations under the License.
|
|
713
|
-
* =============================================================================
|
|
714
|
-
*/
|
|
715
|
-
class on {
|
|
716
|
-
constructor(t, n) {
|
|
717
|
-
this.backendTimer = t, this.logger = n, n == null && (this.logger = new ln());
|
|
718
|
-
}
|
|
719
|
-
profileKernel(t, n, s) {
|
|
720
|
-
let r;
|
|
721
|
-
const a = () => {
|
|
722
|
-
r = s();
|
|
723
|
-
};
|
|
724
|
-
let o;
|
|
725
|
-
const i = gt();
|
|
726
|
-
if (this.backendTimer.timerAvailable())
|
|
727
|
-
o = this.backendTimer.time(a);
|
|
728
|
-
else {
|
|
729
|
-
a();
|
|
730
|
-
for (const l of r)
|
|
731
|
-
l.dataSync();
|
|
732
|
-
o = Promise.resolve({ kernelMs: gt() - i });
|
|
733
|
-
}
|
|
734
|
-
if (S().getBool("CHECK_COMPUTATION_FOR_ERRORS"))
|
|
735
|
-
for (let l = 0; l < r.length; l++) {
|
|
736
|
-
const u = r[l];
|
|
737
|
-
u.data().then((h) => {
|
|
738
|
-
cn(h, u.dtype, t);
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
return {
|
|
742
|
-
kernelName: t,
|
|
743
|
-
outputs: r,
|
|
744
|
-
inputs: n,
|
|
745
|
-
timeMs: o.then((l) => l.kernelMs),
|
|
746
|
-
extraInfo: o.then((l) => l.getExtraProfileInfo != null ? l.getExtraProfileInfo() : "")
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
logKernelProfile(t) {
|
|
750
|
-
const { kernelName: n, outputs: s, timeMs: r, inputs: a, extraInfo: o } = t;
|
|
751
|
-
s.forEach((i) => {
|
|
752
|
-
Promise.all([i.data(), r, o]).then((c) => {
|
|
753
|
-
this.logger.logKernelProfile(n, i, c[0], c[1], a, c[2]);
|
|
754
|
-
});
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
function cn(e, t, n) {
|
|
759
|
-
if (t !== "float32")
|
|
760
|
-
return !1;
|
|
761
|
-
for (let s = 0; s < e.length; s++) {
|
|
762
|
-
const r = e[s];
|
|
763
|
-
if (isNaN(r) || !isFinite(r))
|
|
764
|
-
return console.warn(`Found ${r} in the result of '${n}'`), !0;
|
|
765
|
-
}
|
|
766
|
-
return !1;
|
|
767
|
-
}
|
|
768
|
-
class ln {
|
|
769
|
-
logKernelProfile(t, n, s, r, a, o) {
|
|
770
|
-
const i = typeof r == "number" ? ht(`${r}ms`, 9) : r.error, c = ht(t, 25), l = n.rank, u = n.size, h = ht(n.shape.toString(), 14);
|
|
771
|
-
let d = "";
|
|
772
|
-
for (const m in a) {
|
|
773
|
-
const y = a[m];
|
|
774
|
-
if (y != null) {
|
|
775
|
-
const g = y.shape || n.shape, w = g.length;
|
|
776
|
-
d += `${m}: ${w}D ${w > 0 ? g : ""} `;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
console.log(`%c${c} %c${i} %c${l}D ${h} %c${u} %c${d} %c${o}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* @license
|
|
784
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
785
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
786
|
-
* you may not use this file except in compliance with the License.
|
|
787
|
-
* You may obtain a copy of the License at
|
|
788
|
-
*
|
|
789
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
790
|
-
*
|
|
791
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
792
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
793
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
794
|
-
* See the License for the specific language governing permissions and
|
|
795
|
-
* limitations under the License.
|
|
796
|
-
* =============================================================================
|
|
797
|
-
*/
|
|
798
|
-
function un(e, t, n) {
|
|
799
|
-
const s = {}, r = {};
|
|
800
|
-
for (let c = 0; c < t.length; c++)
|
|
801
|
-
s[t[c].id] = !0;
|
|
802
|
-
for (let c = 0; c < e.length; c++) {
|
|
803
|
-
const l = e[c], u = l.inputs;
|
|
804
|
-
for (const h in u) {
|
|
805
|
-
const d = u[h];
|
|
806
|
-
let m = !1;
|
|
807
|
-
for (let y = 0; y < t.length; y++)
|
|
808
|
-
if (s[d.id]) {
|
|
809
|
-
l.outputs.forEach((g) => s[g.id] = !0), m = !0, r[l.id] = !0;
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
if (m)
|
|
813
|
-
break;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
const a = {};
|
|
817
|
-
a[n.id] = !0;
|
|
818
|
-
const o = {};
|
|
819
|
-
for (let c = e.length - 1; c >= 0; c--) {
|
|
820
|
-
const l = e[c], u = l.inputs;
|
|
821
|
-
for (let h = 0; h < l.outputs.length; h++)
|
|
822
|
-
if (a[l.outputs[h].id]) {
|
|
823
|
-
for (const d in u)
|
|
824
|
-
a[u[d].id] = !0, o[l.id] = !0;
|
|
825
|
-
break;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
const i = [];
|
|
829
|
-
for (let c = 0; c < e.length; c++) {
|
|
830
|
-
const l = e[c];
|
|
831
|
-
if (r[l.id] && o[l.id]) {
|
|
832
|
-
const u = {};
|
|
833
|
-
for (const d in l.inputs) {
|
|
834
|
-
const m = l.inputs[d];
|
|
835
|
-
s[m.id] && (u[d] = m);
|
|
836
|
-
}
|
|
837
|
-
const h = Object.assign({}, l);
|
|
838
|
-
h.inputs = u, h.outputs = l.outputs, i.push(h);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
return i;
|
|
842
|
-
}
|
|
843
|
-
function hn(e, t, n, s) {
|
|
844
|
-
for (let r = t.length - 1; r >= 0; r--) {
|
|
845
|
-
const a = t[r], o = [];
|
|
846
|
-
if (a.outputs.forEach((c) => {
|
|
847
|
-
const l = e[c.id];
|
|
848
|
-
l != null ? o.push(l) : o.push(null);
|
|
849
|
-
}), a.gradient == null)
|
|
850
|
-
throw new Error(`Cannot compute gradient: gradient function not found for ${a.kernelName}.`);
|
|
851
|
-
const i = a.gradient(o);
|
|
852
|
-
for (const c in a.inputs) {
|
|
853
|
-
if (!(c in i))
|
|
854
|
-
throw new Error(`Cannot backprop through input ${c}. Available gradients found: ${Object.keys(i)}.`);
|
|
855
|
-
const l = n(() => i[c]());
|
|
856
|
-
if (l.dtype !== "float32")
|
|
857
|
-
throw new Error(`Error in gradient for op ${a.kernelName}. The gradient of input ${c} must have 'float32' dtype, but has '${l.dtype}'`);
|
|
858
|
-
const u = a.inputs[c];
|
|
859
|
-
if (!xt(l.shape, u.shape))
|
|
860
|
-
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}'`);
|
|
861
|
-
if (e[u.id] == null)
|
|
862
|
-
e[u.id] = l;
|
|
863
|
-
else {
|
|
864
|
-
const h = e[u.id];
|
|
865
|
-
e[u.id] = s(h, l), h.dispose();
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* @license
|
|
872
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
873
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
874
|
-
* you may not use this file except in compliance with the License.
|
|
875
|
-
* You may obtain a copy of the License at
|
|
876
|
-
*
|
|
877
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
878
|
-
*
|
|
879
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
880
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
881
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
882
|
-
* See the License for the specific language governing permissions and
|
|
883
|
-
* limitations under the License.
|
|
884
|
-
* =============================================================================
|
|
885
|
-
*/
|
|
886
|
-
const qt = 20, at = 3, wt = 7;
|
|
887
|
-
function dn(e, t, n, s) {
|
|
888
|
-
const r = $t(t), a = fn(e, t, n, r), o = t.length, i = dt(e, t, n, r, a), c = ["Tensor"];
|
|
889
|
-
return s && (c.push(` dtype: ${n}`), c.push(` rank: ${o}`), c.push(` shape: [${t}]`), c.push(" values:")), c.push(i.map((l) => " " + l).join(`
|
|
890
|
-
`)), c.join(`
|
|
891
|
-
`);
|
|
892
|
-
}
|
|
893
|
-
function fn(e, t, n, s) {
|
|
894
|
-
const r = z(t), a = s[s.length - 1], o = new Array(a).fill(0), i = t.length, c = n === "complex64" ? it(e) : e;
|
|
895
|
-
if (i > 1)
|
|
896
|
-
for (let l = 0; l < r / a; l++) {
|
|
897
|
-
const u = l * a;
|
|
898
|
-
for (let h = 0; h < a; h++)
|
|
899
|
-
o[h] = Math.max(o[h], ot(c[u + h], 0, n).length);
|
|
900
|
-
}
|
|
901
|
-
return o;
|
|
902
|
-
}
|
|
903
|
-
function ot(e, t, n) {
|
|
904
|
-
let s;
|
|
905
|
-
return Array.isArray(e) ? s = `${parseFloat(e[0].toFixed(wt))} + ${parseFloat(e[1].toFixed(wt))}j` : Nt(e) ? s = `'${e}'` : n === "bool" ? s = de(e) : s = parseFloat(e.toFixed(wt)).toString(), ht(s, t);
|
|
906
|
-
}
|
|
907
|
-
function de(e) {
|
|
908
|
-
return e === 0 ? "false" : "true";
|
|
909
|
-
}
|
|
910
|
-
function dt(e, t, n, s, r, a = !0) {
|
|
911
|
-
const o = n === "complex64" ? 2 : 1, i = t[0], c = t.length;
|
|
912
|
-
if (c === 0) {
|
|
913
|
-
if (n === "complex64") {
|
|
914
|
-
const g = it(e);
|
|
915
|
-
return [ot(g[0], 0, n)];
|
|
916
|
-
}
|
|
917
|
-
return n === "bool" ? [de(e[0])] : [e[0].toString()];
|
|
918
|
-
}
|
|
919
|
-
if (c === 1) {
|
|
920
|
-
if (i > qt) {
|
|
921
|
-
const w = at * o;
|
|
922
|
-
let I = Array.from(e.slice(0, w)), _ = Array.from(e.slice((i - at) * o, i * o));
|
|
923
|
-
return n === "complex64" && (I = it(I), _ = it(_)), [
|
|
924
|
-
"[" + I.map((X, J) => ot(X, r[J], n)).join(", ") + ", ..., " + _.map((X, J) => ot(X, r[i - at + J], n)).join(", ") + "]"
|
|
925
|
-
];
|
|
926
|
-
}
|
|
927
|
-
return [
|
|
928
|
-
"[" + (n === "complex64" ? it(e) : Array.from(e)).map((w, I) => ot(w, r[I], n)).join(", ") + "]"
|
|
929
|
-
];
|
|
930
|
-
}
|
|
931
|
-
const l = t.slice(1), u = s.slice(1), h = s[0] * o, d = [];
|
|
932
|
-
if (i > qt) {
|
|
933
|
-
for (let g = 0; g < at; g++) {
|
|
934
|
-
const w = g * h, I = w + h;
|
|
935
|
-
d.push(...dt(
|
|
936
|
-
e.slice(w, I),
|
|
937
|
-
l,
|
|
938
|
-
n,
|
|
939
|
-
u,
|
|
940
|
-
r,
|
|
941
|
-
!1
|
|
942
|
-
/* isLast */
|
|
943
|
-
));
|
|
944
|
-
}
|
|
945
|
-
d.push("...");
|
|
946
|
-
for (let g = i - at; g < i; g++) {
|
|
947
|
-
const w = g * h, I = w + h;
|
|
948
|
-
d.push(...dt(
|
|
949
|
-
e.slice(w, I),
|
|
950
|
-
l,
|
|
951
|
-
n,
|
|
952
|
-
u,
|
|
953
|
-
r,
|
|
954
|
-
g === i - 1
|
|
955
|
-
/* isLast */
|
|
956
|
-
));
|
|
957
|
-
}
|
|
958
|
-
} else
|
|
959
|
-
for (let g = 0; g < i; g++) {
|
|
960
|
-
const w = g * h, I = w + h;
|
|
961
|
-
d.push(...dt(
|
|
962
|
-
e.slice(w, I),
|
|
963
|
-
l,
|
|
964
|
-
n,
|
|
965
|
-
u,
|
|
966
|
-
r,
|
|
967
|
-
g === i - 1
|
|
968
|
-
/* isLast */
|
|
969
|
-
));
|
|
970
|
-
}
|
|
971
|
-
const m = c === 2 ? "," : "";
|
|
972
|
-
d[0] = "[" + (i > 0 ? d[0] + m : "");
|
|
973
|
-
for (let g = 1; g < d.length - 1; g++)
|
|
974
|
-
d[g] = " " + d[g] + m;
|
|
975
|
-
let y = `,
|
|
976
|
-
`;
|
|
977
|
-
for (let g = 2; g < c; g++)
|
|
978
|
-
y += `
|
|
979
|
-
`;
|
|
980
|
-
return d[d.length - 1] = " " + d[d.length - 1] + "]" + (a ? "" : y), d;
|
|
981
|
-
}
|
|
982
|
-
function it(e) {
|
|
983
|
-
const t = [];
|
|
984
|
-
for (let n = 0; n < e.length; n += 2)
|
|
985
|
-
t.push([e[n], e[n + 1]]);
|
|
986
|
-
return t;
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* @license
|
|
990
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
991
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
992
|
-
* you may not use this file except in compliance with the License.
|
|
993
|
-
* You may obtain a copy of the License at
|
|
994
|
-
*
|
|
995
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
996
|
-
*
|
|
997
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
998
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
999
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1000
|
-
* See the License for the specific language governing permissions and
|
|
1001
|
-
* limitations under the License.
|
|
1002
|
-
* =============================================================================
|
|
1003
|
-
*/
|
|
1004
|
-
class gn {
|
|
1005
|
-
constructor(t, n, s) {
|
|
1006
|
-
if (this.dtype = n, this.shape = t.slice(), this.size = z(t), s != null) {
|
|
1007
|
-
const r = s.length;
|
|
1008
|
-
p(r === this.size, () => `Length of values '${r}' does not match the size inferred by the shape '${this.size}'.`);
|
|
1009
|
-
}
|
|
1010
|
-
if (n === "complex64")
|
|
1011
|
-
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).");
|
|
1012
|
-
this.values = s || ee(n, this.size), this.strides = $t(t);
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* Sets a value in the buffer at a given location.
|
|
1016
|
-
*
|
|
1017
|
-
* @param value The value to set.
|
|
1018
|
-
* @param locs The location indices.
|
|
1019
|
-
*
|
|
1020
|
-
* @doc {heading: 'Tensors', subheading: 'Creation'}
|
|
1021
|
-
*/
|
|
1022
|
-
set(t, ...n) {
|
|
1023
|
-
n.length === 0 && (n = [0]), p(n.length === this.rank, () => `The number of provided coordinates (${n.length}) must match the rank (${this.rank})`);
|
|
1024
|
-
const s = this.locToIndex(n);
|
|
1025
|
-
this.values[s] = t;
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* Returns the value in the buffer at the provided location.
|
|
1029
|
-
*
|
|
1030
|
-
* @param locs The location indices.
|
|
1031
|
-
*
|
|
1032
|
-
* @doc {heading: 'Tensors', subheading: 'Creation'}
|
|
1033
|
-
*/
|
|
1034
|
-
get(...t) {
|
|
1035
|
-
t.length === 0 && (t = [0]);
|
|
1036
|
-
let n = 0;
|
|
1037
|
-
for (const r of t) {
|
|
1038
|
-
if (r < 0 || r >= this.shape[n]) {
|
|
1039
|
-
const a = `Requested out of range element at ${t}. Buffer shape=${this.shape}`;
|
|
1040
|
-
throw new Error(a);
|
|
1041
|
-
}
|
|
1042
|
-
n++;
|
|
1043
|
-
}
|
|
1044
|
-
let s = t[t.length - 1];
|
|
1045
|
-
for (let r = 0; r < t.length - 1; ++r)
|
|
1046
|
-
s += this.strides[r] * t[r];
|
|
1047
|
-
return this.values[s];
|
|
1048
|
-
}
|
|
1049
|
-
locToIndex(t) {
|
|
1050
|
-
if (this.rank === 0)
|
|
1051
|
-
return 0;
|
|
1052
|
-
if (this.rank === 1)
|
|
1053
|
-
return t[0];
|
|
1054
|
-
let n = t[t.length - 1];
|
|
1055
|
-
for (let s = 0; s < t.length - 1; ++s)
|
|
1056
|
-
n += this.strides[s] * t[s];
|
|
1057
|
-
return n;
|
|
1058
|
-
}
|
|
1059
|
-
indexToLoc(t) {
|
|
1060
|
-
if (this.rank === 0)
|
|
1061
|
-
return [];
|
|
1062
|
-
if (this.rank === 1)
|
|
1063
|
-
return [t];
|
|
1064
|
-
const n = new Array(this.shape.length);
|
|
1065
|
-
for (let s = 0; s < n.length - 1; ++s)
|
|
1066
|
-
n[s] = Math.floor(t / this.strides[s]), t -= n[s] * this.strides[s];
|
|
1067
|
-
return n[n.length - 1] = t, n;
|
|
1068
|
-
}
|
|
1069
|
-
get rank() {
|
|
1070
|
-
return this.shape.length;
|
|
1071
|
-
}
|
|
1072
|
-
/**
|
|
1073
|
-
* Creates an immutable `tf.Tensor` object from the buffer.
|
|
1074
|
-
*
|
|
1075
|
-
* @doc {heading: 'Tensors', subheading: 'Creation'}
|
|
1076
|
-
*/
|
|
1077
|
-
toTensor() {
|
|
1078
|
-
return x().makeTensor(this.values, this.shape, this.dtype);
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
let x = null, Y = null;
|
|
1082
|
-
function mn(e) {
|
|
1083
|
-
x = e;
|
|
1084
|
-
}
|
|
1085
|
-
function pn(e) {
|
|
1086
|
-
Y = e;
|
|
1087
|
-
}
|
|
1088
|
-
class M {
|
|
1089
|
-
constructor(t, n, s, r) {
|
|
1090
|
-
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";
|
|
1091
|
-
}
|
|
1092
|
-
get rank() {
|
|
1093
|
-
return this.shape.length;
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Returns a promise of `tf.TensorBuffer` that holds the underlying data.
|
|
1097
|
-
*
|
|
1098
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1099
|
-
*/
|
|
1100
|
-
async buffer() {
|
|
1101
|
-
const t = await this.data();
|
|
1102
|
-
return Y.buffer(this.shape, this.dtype, t);
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Returns a `tf.TensorBuffer` that holds the underlying data.
|
|
1106
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1107
|
-
*/
|
|
1108
|
-
bufferSync() {
|
|
1109
|
-
return Y.buffer(this.shape, this.dtype, this.dataSync());
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Returns the tensor data as a nested array. The transfer of data is done
|
|
1113
|
-
* asynchronously.
|
|
1114
|
-
*
|
|
1115
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1116
|
-
*/
|
|
1117
|
-
async array() {
|
|
1118
|
-
const t = await this.data();
|
|
1119
|
-
return ct(this.shape, t, this.dtype === "complex64");
|
|
1120
|
-
}
|
|
1121
|
-
/**
|
|
1122
|
-
* Returns the tensor data as a nested array. The transfer of data is done
|
|
1123
|
-
* synchronously.
|
|
1124
|
-
*
|
|
1125
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1126
|
-
*/
|
|
1127
|
-
arraySync() {
|
|
1128
|
-
return ct(this.shape, this.dataSync(), this.dtype === "complex64");
|
|
1129
|
-
}
|
|
1130
|
-
/**
|
|
1131
|
-
* Asynchronously downloads the values from the `tf.Tensor`. Returns a
|
|
1132
|
-
* promise of `TypedArray` that resolves when the computation has finished.
|
|
1133
|
-
*
|
|
1134
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1135
|
-
*/
|
|
1136
|
-
async data() {
|
|
1137
|
-
this.throwIfDisposed();
|
|
1138
|
-
const t = x().read(this.dataId);
|
|
1139
|
-
if (this.dtype === "string") {
|
|
1140
|
-
const n = await t;
|
|
1141
|
-
try {
|
|
1142
|
-
return n.map((s) => jt(s));
|
|
1143
|
-
} catch {
|
|
1144
|
-
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
return t;
|
|
1148
|
-
}
|
|
1149
|
-
/**
|
|
1150
|
-
* Copy the tensor's data to a new GPU resource. Comparing to the `dataSync()`
|
|
1151
|
-
* and `data()`, this method prevents data from being downloaded to CPU.
|
|
1152
|
-
*
|
|
1153
|
-
* For WebGL backend, the data will be stored on a densely packed texture.
|
|
1154
|
-
* This means that the texture will use the RGBA channels to store value.
|
|
1155
|
-
*
|
|
1156
|
-
* For WebGPU backend, the data will be stored on a buffer. There is no
|
|
1157
|
-
* parameter, so can not use a user-defined size to create the buffer.
|
|
1158
|
-
*
|
|
1159
|
-
* @param options:
|
|
1160
|
-
* For WebGL,
|
|
1161
|
-
* - customTexShape: Optional. If set, will use the user defined
|
|
1162
|
-
* texture shape to create the texture.
|
|
1163
|
-
*
|
|
1164
|
-
* @returns For WebGL backend, a GPUData contains the new texture and
|
|
1165
|
-
* its information.
|
|
1166
|
-
* {
|
|
1167
|
-
* tensorRef: The tensor that is associated with this texture,
|
|
1168
|
-
* texture: WebGLTexture,
|
|
1169
|
-
* texShape: [number, number] // [height, width]
|
|
1170
|
-
* }
|
|
1171
|
-
*
|
|
1172
|
-
* For WebGPU backend, a GPUData contains the new buffer.
|
|
1173
|
-
* {
|
|
1174
|
-
* tensorRef: The tensor that is associated with this buffer,
|
|
1175
|
-
* buffer: GPUBuffer,
|
|
1176
|
-
* }
|
|
1177
|
-
*
|
|
1178
|
-
* Remember to dispose the GPUData after it is used by
|
|
1179
|
-
* `res.tensorRef.dispose()`.
|
|
1180
|
-
*
|
|
1181
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1182
|
-
*/
|
|
1183
|
-
dataToGPU(t) {
|
|
1184
|
-
return this.throwIfDisposed(), x().readToGPU(this.dataId, t);
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* Synchronously downloads the values from the `tf.Tensor`. This blocks the
|
|
1188
|
-
* UI thread until the values are ready, which can cause performance issues.
|
|
1189
|
-
*
|
|
1190
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1191
|
-
*/
|
|
1192
|
-
dataSync() {
|
|
1193
|
-
this.throwIfDisposed();
|
|
1194
|
-
const t = x().readSync(this.dataId);
|
|
1195
|
-
if (this.dtype === "string")
|
|
1196
|
-
try {
|
|
1197
|
-
return t.map((n) => jt(n));
|
|
1198
|
-
} catch {
|
|
1199
|
-
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
|
|
1200
|
-
}
|
|
1201
|
-
return t;
|
|
1202
|
-
}
|
|
1203
|
-
/** Returns the underlying bytes of the tensor's data. */
|
|
1204
|
-
async bytes() {
|
|
1205
|
-
this.throwIfDisposed();
|
|
1206
|
-
const t = await x().read(this.dataId);
|
|
1207
|
-
return this.dtype === "string" ? t : new Uint8Array(t.buffer);
|
|
1208
|
-
}
|
|
1209
|
-
/**
|
|
1210
|
-
* Disposes `tf.Tensor` from memory.
|
|
1211
|
-
*
|
|
1212
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1213
|
-
*/
|
|
1214
|
-
dispose() {
|
|
1215
|
-
this.isDisposed || (this.kerasMask && this.kerasMask.dispose(), x().disposeTensor(this), this.isDisposedInternal = !0);
|
|
1216
|
-
}
|
|
1217
|
-
get isDisposed() {
|
|
1218
|
-
return this.isDisposedInternal;
|
|
1219
|
-
}
|
|
1220
|
-
throwIfDisposed() {
|
|
1221
|
-
if (this.isDisposed)
|
|
1222
|
-
throw new Error("Tensor is disposed.");
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
* Prints the `tf.Tensor`. See `tf.print` for details.
|
|
1226
|
-
*
|
|
1227
|
-
* @param verbose Whether to print verbose information about the tensor,
|
|
1228
|
-
* including dtype and size.
|
|
1229
|
-
*
|
|
1230
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1231
|
-
*/
|
|
1232
|
-
print(t = !1) {
|
|
1233
|
-
return Y.print(this, t);
|
|
1234
|
-
}
|
|
1235
|
-
/**
|
|
1236
|
-
* Returns a copy of the tensor. See `tf.clone` for details.
|
|
1237
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1238
|
-
*/
|
|
1239
|
-
clone() {
|
|
1240
|
-
return this.throwIfDisposed(), Y.clone(this);
|
|
1241
|
-
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Returns a human-readable description of the tensor. Useful for logging.
|
|
1244
|
-
*
|
|
1245
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1246
|
-
*/
|
|
1247
|
-
toString(t = !1) {
|
|
1248
|
-
const n = this.dataSync();
|
|
1249
|
-
return dn(n, this.shape, this.dtype, t);
|
|
1250
|
-
}
|
|
1251
|
-
cast(t) {
|
|
1252
|
-
return this.throwIfDisposed(), Y.cast(this, t);
|
|
1253
|
-
}
|
|
1254
|
-
variable(t = !0, n, s) {
|
|
1255
|
-
return this.throwIfDisposed(), x().makeVariable(this, t, n, s);
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
Object.defineProperty(M, Symbol.hasInstance, {
|
|
1259
|
-
value: (e) => !!e && e.data != null && e.dataSync != null && e.throwIfDisposed != null
|
|
1260
|
-
});
|
|
1261
|
-
function fe() {
|
|
1262
|
-
return Lt("Tensor", () => M);
|
|
1263
|
-
}
|
|
1264
|
-
fe();
|
|
1265
|
-
class mt extends M {
|
|
1266
|
-
constructor(t, n, s, r) {
|
|
1267
|
-
super(t.shape, t.dtype, t.dataId, r), this.trainable = n, this.name = s;
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Assign a new `tf.Tensor` to this variable. The new `tf.Tensor` must have
|
|
1271
|
-
* the same shape and dtype as the old `tf.Tensor`.
|
|
1272
|
-
*
|
|
1273
|
-
* @param newValue New tensor to be assigned to this variable.
|
|
1274
|
-
*
|
|
1275
|
-
* @doc {heading: 'Tensors', subheading: 'Classes'}
|
|
1276
|
-
*/
|
|
1277
|
-
assign(t) {
|
|
1278
|
-
if (t.dtype !== this.dtype)
|
|
1279
|
-
throw new Error(`dtype of the new value (${t.dtype}) and previous value (${this.dtype}) must match`);
|
|
1280
|
-
if (!xt(t.shape, this.shape))
|
|
1281
|
-
throw new Error(`shape of the new value (${t.shape}) and previous value (${this.shape}) must match`);
|
|
1282
|
-
x().disposeTensor(this), this.dataId = t.dataId, x().incRef(
|
|
1283
|
-
this,
|
|
1284
|
-
null
|
|
1285
|
-
/* backend */
|
|
1286
|
-
);
|
|
1287
|
-
}
|
|
1288
|
-
dispose() {
|
|
1289
|
-
x().disposeVariable(this), this.isDisposedInternal = !0;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
Object.defineProperty(mt, Symbol.hasInstance, {
|
|
1293
|
-
value: (e) => e instanceof M && e.assign != null && e.assign instanceof Function
|
|
1294
|
-
});
|
|
1295
|
-
/**
|
|
1296
|
-
* @license
|
|
1297
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
1298
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1299
|
-
* you may not use this file except in compliance with the License.
|
|
1300
|
-
* You may obtain a copy of the License at
|
|
1301
|
-
*
|
|
1302
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1303
|
-
*
|
|
1304
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1305
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1306
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1307
|
-
* See the License for the specific language governing permissions and
|
|
1308
|
-
* limitations under the License.
|
|
1309
|
-
* =============================================================================
|
|
1310
|
-
*/
|
|
1311
|
-
var Kt;
|
|
1312
|
-
(function(e) {
|
|
1313
|
-
e.R0 = "R0", e.R1 = "R1", e.R2 = "R2", e.R3 = "R3", e.R4 = "R4", e.R5 = "R5", e.R6 = "R6";
|
|
1314
|
-
})(Kt || (Kt = {}));
|
|
1315
|
-
var At;
|
|
1316
|
-
(function(e) {
|
|
1317
|
-
e.float32 = "float32", e.int32 = "int32", e.bool = "int32", e.complex64 = "complex64";
|
|
1318
|
-
})(At || (At = {}));
|
|
1319
|
-
var Et;
|
|
1320
|
-
(function(e) {
|
|
1321
|
-
e.float32 = "float32", e.int32 = "int32", e.bool = "bool", e.complex64 = "complex64";
|
|
1322
|
-
})(Et || (Et = {}));
|
|
1323
|
-
var vt;
|
|
1324
|
-
(function(e) {
|
|
1325
|
-
e.float32 = "float32", e.int32 = "float32", e.bool = "float32", e.complex64 = "complex64";
|
|
1326
|
-
})(vt || (vt = {}));
|
|
1327
|
-
var Bt;
|
|
1328
|
-
(function(e) {
|
|
1329
|
-
e.float32 = "complex64", e.int32 = "complex64", e.bool = "complex64", e.complex64 = "complex64";
|
|
1330
|
-
})(Bt || (Bt = {}));
|
|
1331
|
-
const yn = {
|
|
1332
|
-
float32: vt,
|
|
1333
|
-
int32: At,
|
|
1334
|
-
bool: Et,
|
|
1335
|
-
complex64: Bt
|
|
1336
|
-
};
|
|
1337
|
-
function ge(e, t) {
|
|
1338
|
-
if (e === "string" || t === "string") {
|
|
1339
|
-
if (e === "string" && t === "string")
|
|
1340
|
-
return "string";
|
|
1341
|
-
throw new Error(`Can not upcast ${e} with ${t}`);
|
|
1342
|
-
}
|
|
1343
|
-
return yn[e][t];
|
|
1344
|
-
}
|
|
1345
|
-
function Qo(e) {
|
|
1346
|
-
return ge(e, "int32");
|
|
1347
|
-
}
|
|
1348
|
-
function me(e) {
|
|
1349
|
-
return e != null && typeof e == "object" && "texture" in e && e.texture instanceof WebGLTexture;
|
|
1350
|
-
}
|
|
1351
|
-
function pe(e) {
|
|
1352
|
-
return typeof GPUBuffer < "u" && e != null && typeof e == "object" && "buffer" in e && e.buffer instanceof GPUBuffer;
|
|
1353
|
-
}
|
|
1354
|
-
/**
|
|
1355
|
-
* @license
|
|
1356
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
1357
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1358
|
-
* you may not use this file except in compliance with the License.
|
|
1359
|
-
* You may obtain a copy of the License at
|
|
1360
|
-
*
|
|
1361
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1362
|
-
*
|
|
1363
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1364
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1365
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1366
|
-
* See the License for the specific language governing permissions and
|
|
1367
|
-
* limitations under the License.
|
|
1368
|
-
* =============================================================================
|
|
1369
|
-
*/
|
|
1370
|
-
function K(e, t) {
|
|
1371
|
-
if (e.dtype === t.dtype)
|
|
1372
|
-
return [e, t];
|
|
1373
|
-
const n = ge(e.dtype, t.dtype);
|
|
1374
|
-
return [e.cast(n), t.cast(n)];
|
|
1375
|
-
}
|
|
1376
|
-
function ti(e, t) {
|
|
1377
|
-
return t.some((n) => n.id === e.id);
|
|
1378
|
-
}
|
|
1379
|
-
function ye(e) {
|
|
1380
|
-
const t = [];
|
|
1381
|
-
return be(e, t, /* @__PURE__ */ new Set()), t;
|
|
1382
|
-
}
|
|
1383
|
-
function be(e, t, n) {
|
|
1384
|
-
if (e == null)
|
|
1385
|
-
return;
|
|
1386
|
-
if (e instanceof M) {
|
|
1387
|
-
t.push(e);
|
|
1388
|
-
return;
|
|
1389
|
-
}
|
|
1390
|
-
if (!bn(e))
|
|
1391
|
-
return;
|
|
1392
|
-
const s = e;
|
|
1393
|
-
for (const r in s) {
|
|
1394
|
-
const a = s[r];
|
|
1395
|
-
n.has(a) || (n.add(a), be(a, t, n));
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
function bn(e) {
|
|
1399
|
-
return Array.isArray(e) || typeof e == "object";
|
|
1400
|
-
}
|
|
1401
|
-
/**
|
|
1402
|
-
* @license
|
|
1403
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
1404
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1405
|
-
* you may not use this file except in compliance with the License.
|
|
1406
|
-
* You may obtain a copy of the License at
|
|
1407
|
-
*
|
|
1408
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1409
|
-
*
|
|
1410
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1411
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1412
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1413
|
-
* See the License for the specific language governing permissions and
|
|
1414
|
-
* limitations under the License.
|
|
1415
|
-
* =============================================================================
|
|
1416
|
-
*/
|
|
1417
|
-
function St(e) {
|
|
1418
|
-
return e.kernelName != null;
|
|
1419
|
-
}
|
|
1420
|
-
class Ht {
|
|
1421
|
-
constructor() {
|
|
1422
|
-
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 = {
|
|
1423
|
-
newBytes: 0,
|
|
1424
|
-
newTensors: 0,
|
|
1425
|
-
peakBytes: 0,
|
|
1426
|
-
kernels: [],
|
|
1427
|
-
result: null,
|
|
1428
|
-
get kernelNames() {
|
|
1429
|
-
return Array.from(new Set(this.kernels.map((t) => t.name)));
|
|
1430
|
-
}
|
|
1431
|
-
};
|
|
1432
|
-
}
|
|
1433
|
-
dispose() {
|
|
1434
|
-
for (const t in this.registeredVariables)
|
|
1435
|
-
this.registeredVariables[t].dispose();
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
class et {
|
|
1439
|
-
constructor(t) {
|
|
1440
|
-
this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new Ht();
|
|
1441
|
-
}
|
|
1442
|
-
async ready() {
|
|
1443
|
-
if (this.pendingBackendInit != null)
|
|
1444
|
-
return this.pendingBackendInit.then(() => {
|
|
1445
|
-
});
|
|
1446
|
-
if (this.backendInstance != null)
|
|
1447
|
-
return;
|
|
1448
|
-
const t = this.getSortedBackends();
|
|
1449
|
-
for (let n = 0; n < t.length; n++) {
|
|
1450
|
-
const s = t[n];
|
|
1451
|
-
if (await this.initializeBackend(s).success) {
|
|
1452
|
-
await this.setBackend(s);
|
|
1453
|
-
return;
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
throw new Error("Could not initialize any backends, all backend initializations failed.");
|
|
1457
|
-
}
|
|
1458
|
-
get backend() {
|
|
1459
|
-
if (this.pendingBackendInit != null)
|
|
1460
|
-
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`);
|
|
1461
|
-
if (this.backendInstance == null) {
|
|
1462
|
-
const { name: t, asyncInit: n } = this.initializeBackendsAndReturnBest();
|
|
1463
|
-
if (n)
|
|
1464
|
-
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`);
|
|
1465
|
-
this.setBackend(t);
|
|
1466
|
-
}
|
|
1467
|
-
return this.backendInstance;
|
|
1468
|
-
}
|
|
1469
|
-
backendNames() {
|
|
1470
|
-
return Object.keys(this.registryFactory);
|
|
1471
|
-
}
|
|
1472
|
-
findBackend(t) {
|
|
1473
|
-
if (!(t in this.registry))
|
|
1474
|
-
if (t in this.registryFactory) {
|
|
1475
|
-
const { asyncInit: n } = this.initializeBackend(t);
|
|
1476
|
-
if (n)
|
|
1477
|
-
return null;
|
|
1478
|
-
} else
|
|
1479
|
-
return null;
|
|
1480
|
-
return this.registry[t];
|
|
1481
|
-
}
|
|
1482
|
-
findBackendFactory(t) {
|
|
1483
|
-
return t in this.registryFactory ? this.registryFactory[t].factory : null;
|
|
1484
|
-
}
|
|
1485
|
-
registerBackend(t, n, s = 1) {
|
|
1486
|
-
return t in this.registryFactory ? (O(`${t} backend was already registered. Reusing existing backend factory.`), !1) : (this.registryFactory[t] = { factory: n, priority: s }, !0);
|
|
1487
|
-
}
|
|
1488
|
-
async setBackend(t) {
|
|
1489
|
-
if (this.registryFactory[t] == null)
|
|
1490
|
-
throw new Error(`Backend name '${t}' not found in registry`);
|
|
1491
|
-
if (this.backendName = t, this.registry[t] == null) {
|
|
1492
|
-
this.backendInstance = null;
|
|
1493
|
-
const { success: n, asyncInit: s } = this.initializeBackend(t);
|
|
1494
|
-
if (!(s ? await n : n))
|
|
1495
|
-
return !1;
|
|
1496
|
-
}
|
|
1497
|
-
return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new on(this.backendInstance), !0;
|
|
1498
|
-
}
|
|
1499
|
-
setupRegisteredKernels() {
|
|
1500
|
-
Wt(this.backendName).forEach((n) => {
|
|
1501
|
-
n.setupFunc != null && n.setupFunc(this.backendInstance);
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
disposeRegisteredKernels(t) {
|
|
1505
|
-
Wt(t).forEach((s) => {
|
|
1506
|
-
s.disposeFunc != null && s.disposeFunc(this.registry[t]);
|
|
1507
|
-
});
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Initializes a backend by looking up the backend name in the factory
|
|
1511
|
-
* registry and calling the factory method. Returns a boolean representing
|
|
1512
|
-
* whether the initialization of the backend succeeded. Throws an error if
|
|
1513
|
-
* there is no backend in the factory registry.
|
|
1514
|
-
*/
|
|
1515
|
-
initializeBackend(t) {
|
|
1516
|
-
const n = this.registryFactory[t];
|
|
1517
|
-
if (n == null)
|
|
1518
|
-
throw new Error(`Cannot initialize backend ${t}, no registration found.`);
|
|
1519
|
-
try {
|
|
1520
|
-
const s = n.factory();
|
|
1521
|
-
if (s && !(s instanceof xe) && typeof s.then == "function") {
|
|
1522
|
-
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));
|
|
1523
|
-
return this.pendingBackendInit = a, { success: a, asyncInit: !0 };
|
|
1524
|
-
} else
|
|
1525
|
-
return this.registry[t] = s, { success: !0, asyncInit: !1 };
|
|
1526
|
-
} catch (s) {
|
|
1527
|
-
return O(`Initialization of backend ${t} failed`), O(s.stack || s.message), { success: !1, asyncInit: !1 };
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
removeBackend(t) {
|
|
1531
|
-
if (!(t in this.registryFactory))
|
|
1532
|
-
throw new Error(`${t} backend not found in registry`);
|
|
1533
|
-
this.backendName === t && this.pendingBackendInit != null && this.pendingBackendInitId++, t in this.registry && (this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t]), delete this.registryFactory[t], this.backendName === t && (this.pendingBackendInit = null, this.backendName = null, this.backendInstance = null);
|
|
1534
|
-
}
|
|
1535
|
-
getSortedBackends() {
|
|
1536
|
-
if (Object.keys(this.registryFactory).length === 0)
|
|
1537
|
-
throw new Error("No backend found in registry.");
|
|
1538
|
-
return Object.keys(this.registryFactory).sort((t, n) => this.registryFactory[n].priority - this.registryFactory[t].priority);
|
|
1539
|
-
}
|
|
1540
|
-
initializeBackendsAndReturnBest() {
|
|
1541
|
-
const t = this.getSortedBackends();
|
|
1542
|
-
for (let n = 0; n < t.length; n++) {
|
|
1543
|
-
const s = t[n], { success: r, asyncInit: a } = this.initializeBackend(s);
|
|
1544
|
-
if (a || r)
|
|
1545
|
-
return { name: s, asyncInit: a };
|
|
1546
|
-
}
|
|
1547
|
-
throw new Error("Could not initialize any backends, all backend initializations failed.");
|
|
1548
|
-
}
|
|
1549
|
-
moveData(t, n) {
|
|
1550
|
-
const s = this.state.tensorInfo.get(n), r = s.backend, a = this.readSync(n), o = r.refCount(n);
|
|
1551
|
-
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]++;
|
|
1552
|
-
}
|
|
1553
|
-
tidy(t, n) {
|
|
1554
|
-
let s = null;
|
|
1555
|
-
if (n == null) {
|
|
1556
|
-
if (typeof t != "function")
|
|
1557
|
-
throw new Error("Please provide a function to tidy()");
|
|
1558
|
-
n = t;
|
|
1559
|
-
} else {
|
|
1560
|
-
if (typeof t != "string" && !(t instanceof String))
|
|
1561
|
-
throw new Error("When calling with two arguments, the first argument to tidy() must be a string");
|
|
1562
|
-
if (typeof n != "function")
|
|
1563
|
-
throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");
|
|
1564
|
-
s = t;
|
|
1565
|
-
}
|
|
1566
|
-
let r;
|
|
1567
|
-
return this.scopedRun(() => this.startScope(s), () => this.endScope(r), () => (r = n(), r instanceof Promise && console.error("Cannot return a Promise inside of tidy."), r));
|
|
1568
|
-
}
|
|
1569
|
-
scopedRun(t, n, s) {
|
|
1570
|
-
t();
|
|
1571
|
-
try {
|
|
1572
|
-
const r = s();
|
|
1573
|
-
return n(), r;
|
|
1574
|
-
} catch (r) {
|
|
1575
|
-
throw n(), r;
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
nextTensorId() {
|
|
1579
|
-
return et.nextTensorId++;
|
|
1580
|
-
}
|
|
1581
|
-
nextVariableId() {
|
|
1582
|
-
return et.nextVariableId++;
|
|
1583
|
-
}
|
|
1584
|
-
/**
|
|
1585
|
-
* This method is called instead of the public-facing tensor.clone() when
|
|
1586
|
-
* saving a tensor for backwards pass. It makes sure to add the clone
|
|
1587
|
-
* operation to the tape regardless of being called inside a kernel
|
|
1588
|
-
* execution.
|
|
1589
|
-
*/
|
|
1590
|
-
clone(t) {
|
|
1591
|
-
const n = f.runKernel(ce, { x: t }), s = { x: t }, r = (o) => ({
|
|
1592
|
-
x: () => {
|
|
1593
|
-
const i = "float32", c = { x: o }, l = { dtype: i };
|
|
1594
|
-
return f.runKernel(
|
|
1595
|
-
ie,
|
|
1596
|
-
c,
|
|
1597
|
-
// tslint:disable-next-line: no-unnecessary-type-assertion
|
|
1598
|
-
l
|
|
1599
|
-
);
|
|
1600
|
-
}
|
|
1601
|
-
}), a = [];
|
|
1602
|
-
return this.addTapeNode(this.state.activeScope.name, s, [n], r, a, {}), n;
|
|
1603
|
-
}
|
|
1604
|
-
/**
|
|
1605
|
-
* Execute a kernel with the given name and return the output tensor.
|
|
1606
|
-
*
|
|
1607
|
-
* @param kernelName The name of the kernel to execute.
|
|
1608
|
-
* @param inputs A map of input names to tensors.
|
|
1609
|
-
* @param attrs A map of attribute names to their values. An attribute is a
|
|
1610
|
-
* primitive (non-tensor) input to the kernel.
|
|
1611
|
-
* @param inputsToSave A list of tensors, inputs to save for the backprop
|
|
1612
|
-
* computation.
|
|
1613
|
-
* @param outputsToSave A list of booleans, specifying which output to save
|
|
1614
|
-
* for the backprop computation. These are booleans since the output
|
|
1615
|
-
* tensors are not visible to the user.
|
|
1616
|
-
*/
|
|
1617
|
-
runKernel(t, n, s) {
|
|
1618
|
-
if (this.backendName == null && this.backend, !(zt(t, this.backendName) != null))
|
|
1619
|
-
throw new Error(`Kernel '${t}' not registered for backend '${this.backendName}'`);
|
|
1620
|
-
return this.runKernelFunc({ kernelName: t, inputs: n, attrs: s });
|
|
1621
|
-
}
|
|
1622
|
-
shouldCheckForMemLeaks() {
|
|
1623
|
-
return this.ENV.getBool("IS_TEST");
|
|
1624
|
-
}
|
|
1625
|
-
checkKernelForMemLeak(t, n, s) {
|
|
1626
|
-
const r = this.backend.numDataIds();
|
|
1627
|
-
let a = 0;
|
|
1628
|
-
s.forEach((c) => {
|
|
1629
|
-
a += c.dtype === "complex64" ? 3 : 1;
|
|
1630
|
-
});
|
|
1631
|
-
const o = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], i = r - n - a - o;
|
|
1632
|
-
if (i > 0)
|
|
1633
|
-
throw new Error(`Backend '${this.backendName}' has an internal memory leak (${i} data ids) after running '${t}'`);
|
|
1634
|
-
}
|
|
1635
|
-
/**
|
|
1636
|
-
* Internal helper method to execute a kernel Func
|
|
1637
|
-
*
|
|
1638
|
-
* Use `runKernel` to execute kernels from outside of engine.
|
|
1639
|
-
*/
|
|
1640
|
-
runKernelFunc(t) {
|
|
1641
|
-
let n, s = [];
|
|
1642
|
-
const r = this.isTapeOn(), a = this.state.numBytes, o = this.state.numTensors;
|
|
1643
|
-
this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0);
|
|
1644
|
-
let i;
|
|
1645
|
-
this.backendName == null && this.backend;
|
|
1646
|
-
let c;
|
|
1647
|
-
const l = St(t) ? t.kernelName : this.state.activeScope != null ? this.state.activeScope.name : "";
|
|
1648
|
-
if (St(t)) {
|
|
1649
|
-
const { kernelName: y, inputs: g, attrs: w } = t;
|
|
1650
|
-
this.backendName == null && this.backend;
|
|
1651
|
-
const I = zt(y, this.backendName);
|
|
1652
|
-
p(I != null, () => `Cannot find registered kernel '${y}' for backend '${this.backendName}'`), i = () => {
|
|
1653
|
-
const _ = this.backend.numDataIds();
|
|
1654
|
-
c = I.kernelFunc({ inputs: g, attrs: w, backend: this.backend });
|
|
1655
|
-
const X = Array.isArray(c) ? c : [c];
|
|
1656
|
-
this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(y, _, X);
|
|
1657
|
-
const J = X.map((rt) => rt.rank != null ? rt : this.makeTensorFromTensorInfo(rt));
|
|
1658
|
-
if (r) {
|
|
1659
|
-
const rt = this.getTensorsForGradient(y, g, J);
|
|
1660
|
-
s = this.saveTensorsForBackwardMode(rt);
|
|
1661
|
-
}
|
|
1662
|
-
return J;
|
|
1663
|
-
};
|
|
1664
|
-
} else {
|
|
1665
|
-
const { forwardFunc: y } = t, g = (w) => {
|
|
1666
|
-
r && (s = w.map((I) => this.keep(this.clone(I))));
|
|
1667
|
-
};
|
|
1668
|
-
i = () => {
|
|
1669
|
-
const w = this.backend.numDataIds();
|
|
1670
|
-
c = this.tidy(() => y(this.backend, g));
|
|
1671
|
-
const I = Array.isArray(c) ? c : [c];
|
|
1672
|
-
return this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(l, w, I), I;
|
|
1673
|
-
};
|
|
1674
|
-
}
|
|
1675
|
-
const { inputs: u, attrs: h } = t, d = St(t) ? null : t.backwardsFunc;
|
|
1676
|
-
let m;
|
|
1677
|
-
return this.scopedRun(
|
|
1678
|
-
// Stop recording to a tape when running a kernel.
|
|
1679
|
-
() => this.state.kernelDepth++,
|
|
1680
|
-
() => this.state.kernelDepth--,
|
|
1681
|
-
() => {
|
|
1682
|
-
!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);
|
|
1683
|
-
}
|
|
1684
|
-
), r && this.addTapeNode(l, u, n, d, s, h), this.state.profiling && this.state.activeProfile.kernels.push({
|
|
1685
|
-
name: l,
|
|
1686
|
-
bytesAdded: this.state.numBytes - a,
|
|
1687
|
-
totalBytesSnapshot: this.state.numBytes,
|
|
1688
|
-
tensorsAdded: this.state.numTensors - o,
|
|
1689
|
-
totalTensorsSnapshot: this.state.numTensors,
|
|
1690
|
-
inputShapes: Object.keys(u).map((y) => u[y] != null ? u[y].shape : null),
|
|
1691
|
-
outputShapes: n.map((y) => y.shape),
|
|
1692
|
-
kernelTimeMs: m.timeMs,
|
|
1693
|
-
extraInfo: m.extraInfo
|
|
1694
|
-
}), Array.isArray(c) ? n : n[0];
|
|
1695
|
-
}
|
|
1696
|
-
/**
|
|
1697
|
-
* Saves tensors used in forward mode for use in backward mode.
|
|
1698
|
-
*
|
|
1699
|
-
* @param tensors the list of tensors to save.
|
|
1700
|
-
*/
|
|
1701
|
-
saveTensorsForBackwardMode(t) {
|
|
1702
|
-
return t.map((s) => this.keep(this.clone(s)));
|
|
1703
|
-
}
|
|
1704
|
-
/**
|
|
1705
|
-
* Returns a list of tensors to save for a given gradient calculation.
|
|
1706
|
-
*
|
|
1707
|
-
* @param kernelName name of kernel to look up gradient for.
|
|
1708
|
-
* @param inputs a map of input tensors.
|
|
1709
|
-
* @param outputs an array of output tensors from forward mode of kernel.
|
|
1710
|
-
*/
|
|
1711
|
-
getTensorsForGradient(t, n, s) {
|
|
1712
|
-
const r = Vt(t);
|
|
1713
|
-
if (r != null) {
|
|
1714
|
-
const a = r.inputsToSave || [], o = r.outputsToSave || [];
|
|
1715
|
-
let i;
|
|
1716
|
-
r.saveAllInputs ? (p(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]);
|
|
1717
|
-
const c = s.filter((l, u) => o[u]);
|
|
1718
|
-
return i.concat(c);
|
|
1719
|
-
}
|
|
1720
|
-
return [];
|
|
1721
|
-
}
|
|
1722
|
-
/**
|
|
1723
|
-
* Internal method used by public APIs for tensor creation. Makes a new
|
|
1724
|
-
* tensor with the provided shape, dtype and values. It always
|
|
1725
|
-
* creates a new data id and writes the values to the underlying backend.
|
|
1726
|
-
*/
|
|
1727
|
-
makeTensor(t, n, s, r) {
|
|
1728
|
-
if (t == null)
|
|
1729
|
-
throw new Error("Values passed to engine.makeTensor() are null");
|
|
1730
|
-
s = s || "float32", r = r || this.backend;
|
|
1731
|
-
let a = t;
|
|
1732
|
-
s === "string" && Nt(t[0]) && (a = t.map((c) => he(c)));
|
|
1733
|
-
const o = r.write(a, n, s), i = new M(n, s, o, this.nextTensorId());
|
|
1734
|
-
if (this.trackTensor(i, r), s === "string") {
|
|
1735
|
-
const c = this.state.tensorInfo.get(o), l = _e(a);
|
|
1736
|
-
this.state.numBytes += l - c.bytes, c.bytes = l;
|
|
1737
|
-
}
|
|
1738
|
-
return i;
|
|
1739
|
-
}
|
|
1740
|
-
/**
|
|
1741
|
-
* Internal method used by backends. Makes a new tensor
|
|
1742
|
-
* that is a wrapper around an existing data id. It doesn't create
|
|
1743
|
-
* a new data id, only increments the ref count used in memory tracking.
|
|
1744
|
-
* @deprecated
|
|
1745
|
-
*/
|
|
1746
|
-
makeTensorFromDataId(t, n, s, r) {
|
|
1747
|
-
s = s || "float32";
|
|
1748
|
-
const a = { dataId: t, shape: n, dtype: s };
|
|
1749
|
-
return this.makeTensorFromTensorInfo(a, r);
|
|
1750
|
-
}
|
|
1751
|
-
/**
|
|
1752
|
-
* Internal method used by backends. Makes a new tensor that is a wrapper
|
|
1753
|
-
* around an existing data id in TensorInfo. It doesn't create a new data id,
|
|
1754
|
-
* only increments the ref count used in memory tracking.
|
|
1755
|
-
*/
|
|
1756
|
-
makeTensorFromTensorInfo(t, n) {
|
|
1757
|
-
const { dataId: s, shape: r, dtype: a } = t, o = new M(r, a, s, this.nextTensorId());
|
|
1758
|
-
return this.trackTensor(o, n), o;
|
|
1759
|
-
}
|
|
1760
|
-
makeVariable(t, n = !0, s, r) {
|
|
1761
|
-
s = s || this.nextVariableId().toString(), r != null && r !== t.dtype && (t = t.cast(r));
|
|
1762
|
-
const a = new mt(t, n, s, this.nextTensorId());
|
|
1763
|
-
if (this.state.registeredVariables[a.name] != null)
|
|
1764
|
-
throw new Error(`Variable with name ${a.name} was already registered`);
|
|
1765
|
-
return this.state.registeredVariables[a.name] = a, this.incRef(a, this.backend), a;
|
|
1766
|
-
}
|
|
1767
|
-
trackTensor(t, n) {
|
|
1768
|
-
this.state.numTensors++, t.dtype === "string" && this.state.numStringTensors++;
|
|
1769
|
-
let s = 0;
|
|
1770
|
-
t.dtype !== "complex64" && t.dtype !== "string" && (s = t.size * It(t.dtype)), this.state.numBytes += s, this.state.tensorInfo.has(t.dataId) || (this.state.numDataBuffers++, this.state.tensorInfo.set(t.dataId, {
|
|
1771
|
-
backend: n || this.backend,
|
|
1772
|
-
dtype: t.dtype,
|
|
1773
|
-
shape: t.shape,
|
|
1774
|
-
bytes: s
|
|
1775
|
-
})), t instanceof mt || this.track(t);
|
|
1776
|
-
}
|
|
1777
|
-
// Track the tensor by dataId and increase the refCount for the dataId in the
|
|
1778
|
-
// backend.
|
|
1779
|
-
// TODO(pyu10055): This is currently used by makeVariable method, to increase
|
|
1780
|
-
// refCount on the backend for the dataId. It can potentially be replaced with
|
|
1781
|
-
// Identity op indead of calling backend directly.
|
|
1782
|
-
incRef(t, n) {
|
|
1783
|
-
this.trackTensor(t, n), this.backend.incRef(t.dataId);
|
|
1784
|
-
}
|
|
1785
|
-
removeDataId(t, n) {
|
|
1786
|
-
this.state.tensorInfo.has(t) && this.state.tensorInfo.get(t).backend === n && (this.state.tensorInfo.delete(t), this.state.numDataBuffers--);
|
|
1787
|
-
}
|
|
1788
|
-
disposeTensor(t) {
|
|
1789
|
-
if (!this.state.tensorInfo.has(t.dataId))
|
|
1790
|
-
return;
|
|
1791
|
-
const n = this.state.tensorInfo.get(t.dataId);
|
|
1792
|
-
if (this.state.numTensors--, t.dtype === "string" && (this.state.numStringTensors--, this.state.numBytes -= n.bytes), t.dtype !== "complex64" && t.dtype !== "string") {
|
|
1793
|
-
const s = t.size * It(t.dtype);
|
|
1794
|
-
this.state.numBytes -= s;
|
|
1795
|
-
}
|
|
1796
|
-
n.backend.disposeData(t.dataId) && this.removeDataId(t.dataId, n.backend);
|
|
1797
|
-
}
|
|
1798
|
-
disposeVariables() {
|
|
1799
|
-
for (const t in this.state.registeredVariables) {
|
|
1800
|
-
const n = this.state.registeredVariables[t];
|
|
1801
|
-
this.disposeVariable(n);
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
disposeVariable(t) {
|
|
1805
|
-
this.disposeTensor(t), this.state.registeredVariables[t.name] != null && delete this.state.registeredVariables[t.name];
|
|
1806
|
-
}
|
|
1807
|
-
memory() {
|
|
1808
|
-
const t = this.backend.memory();
|
|
1809
|
-
return t.numTensors = this.state.numTensors, t.numDataBuffers = this.state.numDataBuffers, t.numBytes = this.state.numBytes, this.state.numStringTensors > 0 && (t.unreliable = !0, t.reasons == null && (t.reasons = []), t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")), t;
|
|
1810
|
-
}
|
|
1811
|
-
async profile(t) {
|
|
1812
|
-
this.state.profiling = !0;
|
|
1813
|
-
const n = this.state.numBytes, s = this.state.numTensors;
|
|
1814
|
-
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;
|
|
1815
|
-
for (const r of this.state.activeProfile.kernels)
|
|
1816
|
-
r.kernelTimeMs = await r.kernelTimeMs, r.extraInfo = await r.extraInfo;
|
|
1817
|
-
return this.state.activeProfile;
|
|
1818
|
-
}
|
|
1819
|
-
isTapeOn() {
|
|
1820
|
-
return this.state.gradientDepth > 0 && this.state.kernelDepth === 0;
|
|
1821
|
-
}
|
|
1822
|
-
addTapeNode(t, n, s, r, a, o) {
|
|
1823
|
-
const i = { id: this.state.nextTapeNodeId++, kernelName: t, inputs: n, outputs: s, saved: a }, c = Vt(t);
|
|
1824
|
-
c != null && (r = c.gradFunc), r != null && (i.gradient = (l) => (l = l.map((u, h) => {
|
|
1825
|
-
if (u == null) {
|
|
1826
|
-
const d = s[h], m = se(d.size, d.dtype);
|
|
1827
|
-
return this.makeTensor(m, d.shape, d.dtype);
|
|
1828
|
-
}
|
|
1829
|
-
return u;
|
|
1830
|
-
}), r(l.length > 1 ? l : l[0], a, o))), this.state.activeTape.push(i);
|
|
1831
|
-
}
|
|
1832
|
-
keep(t) {
|
|
1833
|
-
return t.kept = !0, t;
|
|
1834
|
-
}
|
|
1835
|
-
startTape() {
|
|
1836
|
-
this.state.gradientDepth === 0 && (this.state.activeTape = []), this.state.gradientDepth++;
|
|
1837
|
-
}
|
|
1838
|
-
endTape() {
|
|
1839
|
-
this.state.gradientDepth--;
|
|
1840
|
-
}
|
|
1841
|
-
/**
|
|
1842
|
-
* Start a scope. Use this with endScope() to achieve the same functionality
|
|
1843
|
-
* as scope() without the need for a function closure.
|
|
1844
|
-
*/
|
|
1845
|
-
startScope(t) {
|
|
1846
|
-
const n = {
|
|
1847
|
-
track: [],
|
|
1848
|
-
name: "unnamed scope",
|
|
1849
|
-
id: this.state.nextScopeId++
|
|
1850
|
-
};
|
|
1851
|
-
t && (n.name = t), this.state.scopeStack.push(n), this.state.activeScope = n;
|
|
1852
|
-
}
|
|
1853
|
-
/**
|
|
1854
|
-
* End a scope. Use this with startScope() to achieve the same functionality
|
|
1855
|
-
* as scope() without the need for a function closure.
|
|
1856
|
-
*/
|
|
1857
|
-
endScope(t) {
|
|
1858
|
-
const n = ye(t), s = new Set(n.map((a) => a.id));
|
|
1859
|
-
for (let a = 0; a < this.state.activeScope.track.length; a++) {
|
|
1860
|
-
const o = this.state.activeScope.track[a];
|
|
1861
|
-
!o.kept && !s.has(o.id) && o.dispose();
|
|
1862
|
-
}
|
|
1863
|
-
const r = this.state.scopeStack.pop();
|
|
1864
|
-
this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], n.forEach((a) => {
|
|
1865
|
-
!a.kept && a.scopeId === r.id && this.track(a);
|
|
1866
|
-
});
|
|
1867
|
-
}
|
|
1868
|
-
/**
|
|
1869
|
-
* Returns gradients of `f` with respect to each of the `xs`. The gradients
|
|
1870
|
-
* returned are of the same length as `xs`, but some might be null if `f`
|
|
1871
|
-
* was not a function of that `x`. It also takes optional dy to multiply the
|
|
1872
|
-
* gradient, which defaults to `1`.
|
|
1873
|
-
*/
|
|
1874
|
-
gradients(t, n, s, r = !1) {
|
|
1875
|
-
if (p(n.length > 0, () => "gradients() received an empty list of xs."), s != null && s.dtype !== "float32")
|
|
1876
|
-
throw new Error(`dy must have 'float32' dtype, but has '${s.dtype}'`);
|
|
1877
|
-
const a = this.scopedRun(() => this.startTape(), () => this.endTape(), () => this.tidy("forward", t));
|
|
1878
|
-
p(a instanceof M, () => "The result y returned by f() must be a tensor.");
|
|
1879
|
-
const o = un(this.state.activeTape, n, a);
|
|
1880
|
-
if (!r && o.length === 0 && n.length > 0)
|
|
1881
|
-
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.");
|
|
1882
|
-
return this.tidy("backward", () => {
|
|
1883
|
-
const i = {};
|
|
1884
|
-
i[a.id] = s ?? wn(a.shape), hn(
|
|
1885
|
-
i,
|
|
1886
|
-
o,
|
|
1887
|
-
// Pass the tidy function to avoid circular dep with `tape.ts`.
|
|
1888
|
-
(l) => this.tidy(l),
|
|
1889
|
-
// Pass an add function to avoide a circular dep with `tape.ts`.
|
|
1890
|
-
Sn
|
|
1891
|
-
);
|
|
1892
|
-
const c = n.map((l) => i[l.id]);
|
|
1893
|
-
return this.state.gradientDepth === 0 && (this.state.activeTape.forEach((l) => {
|
|
1894
|
-
for (const u of l.saved)
|
|
1895
|
-
u.dispose();
|
|
1896
|
-
}), this.state.activeTape = null), { value: a, grads: c };
|
|
1897
|
-
});
|
|
1898
|
-
}
|
|
1899
|
-
customGrad(t) {
|
|
1900
|
-
return p(lt(t), () => "The f passed in customGrad(f) must be a function."), (...n) => {
|
|
1901
|
-
p(n.every((i) => i instanceof M), () => "The args passed in customGrad(f)(x1, x2,...) must all be tensors");
|
|
1902
|
-
let s;
|
|
1903
|
-
const r = {};
|
|
1904
|
-
n.forEach((i, c) => {
|
|
1905
|
-
r[c] = i;
|
|
1906
|
-
});
|
|
1907
|
-
const a = (i, c) => (s = t(...n, c), p(s.value instanceof M, () => "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"), p(lt(s.gradFunc), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."), s.value), o = (i, c) => {
|
|
1908
|
-
const l = s.gradFunc(i, c), u = Array.isArray(l) ? l : [l];
|
|
1909
|
-
p(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(...)."), p(u.every((d) => d instanceof M), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.");
|
|
1910
|
-
const h = {};
|
|
1911
|
-
return u.forEach((d, m) => {
|
|
1912
|
-
h[m] = () => d;
|
|
1913
|
-
}), h;
|
|
1914
|
-
};
|
|
1915
|
-
return this.runKernelFunc({
|
|
1916
|
-
forwardFunc: a,
|
|
1917
|
-
backwardsFunc: o,
|
|
1918
|
-
inputs: r
|
|
1919
|
-
});
|
|
1920
|
-
};
|
|
1921
|
-
}
|
|
1922
|
-
readSync(t) {
|
|
1923
|
-
return this.state.tensorInfo.get(t).backend.readSync(t);
|
|
1924
|
-
}
|
|
1925
|
-
read(t) {
|
|
1926
|
-
return this.state.tensorInfo.get(t).backend.read(t);
|
|
1927
|
-
}
|
|
1928
|
-
readToGPU(t, n) {
|
|
1929
|
-
return this.state.tensorInfo.get(t).backend.readToGPU(t, n);
|
|
1930
|
-
}
|
|
1931
|
-
async time(t) {
|
|
1932
|
-
const n = gt(), s = await this.backend.time(t);
|
|
1933
|
-
return s.wallMs = gt() - n, s;
|
|
1934
|
-
}
|
|
1935
|
-
/**
|
|
1936
|
-
* Tracks a Tensor in the current scope to be automatically cleaned up
|
|
1937
|
-
* when the current scope ends, and returns the value.
|
|
1938
|
-
*
|
|
1939
|
-
* @param result The Tensor to track in the current scope.
|
|
1940
|
-
*/
|
|
1941
|
-
track(t) {
|
|
1942
|
-
return this.state.activeScope != null && (t.scopeId = this.state.activeScope.id, this.state.activeScope.track.push(t)), t;
|
|
1943
|
-
}
|
|
1944
|
-
get registeredVariables() {
|
|
1945
|
-
return this.state.registeredVariables;
|
|
1946
|
-
}
|
|
1947
|
-
/**
|
|
1948
|
-
* Resets the engine state. Removes all backends but does not remove
|
|
1949
|
-
* registered backend factories.
|
|
1950
|
-
*/
|
|
1951
|
-
reset() {
|
|
1952
|
-
this.pendingBackendInitId++, this.state.dispose(), this.ENV.reset(), this.state = new Ht();
|
|
1953
|
-
for (const t in this.registry)
|
|
1954
|
-
this.disposeRegisteredKernels(t), this.registry[t].dispose(), delete this.registry[t];
|
|
1955
|
-
this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null;
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
et.nextTensorId = 0;
|
|
1959
|
-
et.nextVariableId = 0;
|
|
1960
|
-
function wn(e) {
|
|
1961
|
-
const t = Ue(z(e), "float32");
|
|
1962
|
-
return f.makeTensor(t, e, "float32");
|
|
1963
|
-
}
|
|
1964
|
-
function we() {
|
|
1965
|
-
const e = ae();
|
|
1966
|
-
if (e._tfengine == null) {
|
|
1967
|
-
const t = new ze(e);
|
|
1968
|
-
e._tfengine = new et(t);
|
|
1969
|
-
}
|
|
1970
|
-
return qe(e._tfengine.ENV), mn(() => e._tfengine), e._tfengine;
|
|
1971
|
-
}
|
|
1972
|
-
const f = we();
|
|
1973
|
-
function Sn(e, t) {
|
|
1974
|
-
const n = { a: e, b: t };
|
|
1975
|
-
return f.runKernel(oe, n);
|
|
1976
|
-
}
|
|
1977
|
-
/**
|
|
1978
|
-
* @license
|
|
1979
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
1980
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1981
|
-
* you may not use this file except in compliance with the License.
|
|
1982
|
-
* You may obtain a copy of the License at
|
|
1983
|
-
*
|
|
1984
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1985
|
-
*
|
|
1986
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1987
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1988
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1989
|
-
* See the License for the specific language governing permissions and
|
|
1990
|
-
* limitations under the License.
|
|
1991
|
-
* =============================================================================
|
|
1992
|
-
*/
|
|
1993
|
-
function kn() {
|
|
1994
|
-
return typeof navigator < "u" && navigator != null;
|
|
1995
|
-
}
|
|
1996
|
-
function ei(e) {
|
|
1997
|
-
if (e || kn()) {
|
|
1998
|
-
if (e || (e = navigator), e.product === "ReactNative")
|
|
1999
|
-
return !0;
|
|
2000
|
-
const t = e.userAgent || e.vendor || // tslint:disable-next-line:no-any
|
|
2001
|
-
(typeof window < "u" ? window.opera : "");
|
|
2002
|
-
if (!t) {
|
|
2003
|
-
const n = e;
|
|
2004
|
-
return n.userAgentData && n.userAgentData.mobile;
|
|
2005
|
-
}
|
|
2006
|
-
return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t) || // tslint:disable-next-line:max-line-length
|
|
2007
|
-
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0, 4));
|
|
2008
|
-
}
|
|
2009
|
-
return !1;
|
|
2010
|
-
}
|
|
2011
|
-
function In() {
|
|
2012
|
-
return typeof window < "u" && window.document != null || //@ts-ignore
|
|
2013
|
-
typeof WorkerGlobalScope < "u";
|
|
2014
|
-
}
|
|
2015
|
-
const v = S();
|
|
2016
|
-
v.registerFlag("DEBUG", () => !1, (e) => {
|
|
2017
|
-
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.");
|
|
2018
|
-
});
|
|
2019
|
-
v.registerFlag("IS_BROWSER", () => In());
|
|
2020
|
-
v.registerFlag("IS_NODE", () => typeof Q < "u" && typeof Q.versions < "u" && typeof Q.versions.node < "u");
|
|
2021
|
-
v.registerFlag("IS_CHROME", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor));
|
|
2022
|
-
v.registerFlag("IS_SAFARI", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Safari/.test(navigator.userAgent) && /Apple/.test(navigator.vendor));
|
|
2023
|
-
v.registerFlag("PROD", () => !1);
|
|
2024
|
-
v.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY", () => v.getBool("DEBUG"));
|
|
2025
|
-
v.registerFlag("DEPRECATION_WARNINGS_ENABLED", () => !0);
|
|
2026
|
-
v.registerFlag("IS_TEST", () => !1);
|
|
2027
|
-
v.registerFlag("CHECK_COMPUTATION_FOR_ERRORS", () => v.getBool("DEBUG"));
|
|
2028
|
-
v.registerFlag("WRAP_TO_IMAGEBITMAP", () => !1);
|
|
2029
|
-
v.registerFlag("CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU", () => !1);
|
|
2030
|
-
v.registerFlag("USE_SETTIMEOUTCUSTOM", () => !1);
|
|
2031
|
-
/**
|
|
2032
|
-
* @license
|
|
2033
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2034
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2035
|
-
* you may not use this file except in compliance with the License.
|
|
2036
|
-
* You may obtain a copy of the License at
|
|
2037
|
-
*
|
|
2038
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2039
|
-
*
|
|
2040
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2041
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2042
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2043
|
-
* See the License for the specific language governing permissions and
|
|
2044
|
-
* limitations under the License.
|
|
2045
|
-
* =============================================================================
|
|
2046
|
-
*/
|
|
2047
|
-
function Tn(e, t) {
|
|
2048
|
-
let n = e;
|
|
2049
|
-
if (R(e))
|
|
2050
|
-
return t === "string" ? [] : [e.length];
|
|
2051
|
-
if (me(e)) {
|
|
2052
|
-
const r = e.channels || "RGBA";
|
|
2053
|
-
return [e.height, e.width * r.length];
|
|
2054
|
-
} else if (pe(e))
|
|
2055
|
-
return [e.buffer.size / (t == null ? 4 : It(t))];
|
|
2056
|
-
if (!Array.isArray(e))
|
|
2057
|
-
return [];
|
|
2058
|
-
const s = [];
|
|
2059
|
-
for (; Array.isArray(n) || R(n) && t !== "string"; )
|
|
2060
|
-
s.push(n.length), n = n[0];
|
|
2061
|
-
return Array.isArray(e) && S().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && Se(e, s, []), s;
|
|
2062
|
-
}
|
|
2063
|
-
function Se(e, t, n) {
|
|
2064
|
-
if (n = n || [], !Array.isArray(e) && !R(e)) {
|
|
2065
|
-
p(t.length === 0, () => `Element arr[${n.join("][")}] is a primitive, but should be an array/TypedArray of ${t[0]} elements`);
|
|
2066
|
-
return;
|
|
2067
|
-
}
|
|
2068
|
-
p(t.length > 0, () => `Element arr[${n.join("][")}] should be a primitive, but is an array of ${e.length} elements`), p(e.length === t[0], () => `Element arr[${n.join("][")}] should have ${t[0]} elements, but has ${e.length} elements`);
|
|
2069
|
-
const s = t.slice(1);
|
|
2070
|
-
for (let r = 0; r < e.length; ++r)
|
|
2071
|
-
Se(e[r], s, n.concat(r));
|
|
2072
|
-
}
|
|
2073
|
-
function Xt(e, t, n, s) {
|
|
2074
|
-
if (e !== "string_or_numeric") {
|
|
2075
|
-
if (e == null)
|
|
2076
|
-
throw new Error("Expected dtype cannot be null.");
|
|
2077
|
-
if (e !== "numeric" && e !== t || e === "numeric" && t === "string")
|
|
2078
|
-
throw new Error(`Argument '${n}' passed to '${s}' must be ${e} tensor, but got ${t} tensor`);
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
function T(e, t, n, s = "numeric") {
|
|
2082
|
-
if (e instanceof fe())
|
|
2083
|
-
return Xt(s, e.dtype, t, n), e;
|
|
2084
|
-
let r = yt(e);
|
|
2085
|
-
if (r !== "string" && ["bool", "int32", "float32"].indexOf(s) >= 0 && (r = s), Xt(s, r, t, n), e == null || !R(e) && !Array.isArray(e) && typeof e != "number" && typeof e != "boolean" && typeof e != "string") {
|
|
2086
|
-
const c = e == null ? "null" : e.constructor.name;
|
|
2087
|
-
throw new Error(`Argument '${t}' passed to '${n}' must be a Tensor or TensorLike, but got '${c}'`);
|
|
2088
|
-
}
|
|
2089
|
-
const a = Tn(e, r);
|
|
2090
|
-
!R(e) && !Array.isArray(e) && (e = [e]);
|
|
2091
|
-
const i = r !== "string" ? _t(e, r) : ut(e, [], !0);
|
|
2092
|
-
return f.makeTensor(i, a, r);
|
|
2093
|
-
}
|
|
2094
|
-
function An(e, t, n, s = "numeric") {
|
|
2095
|
-
if (!Array.isArray(e))
|
|
2096
|
-
throw new Error(`Argument ${t} passed to ${n} must be a \`Tensor[]\` or \`TensorLike[]\``);
|
|
2097
|
-
return e.map((a, o) => T(a, `${t}[${o}]`, n, s));
|
|
2098
|
-
}
|
|
2099
|
-
/**
|
|
2100
|
-
* @license
|
|
2101
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2102
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2103
|
-
* you may not use this file except in compliance with the License.
|
|
2104
|
-
* You may obtain a copy of the License at
|
|
2105
|
-
*
|
|
2106
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2107
|
-
*
|
|
2108
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2109
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2110
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2111
|
-
* See the License for the specific language governing permissions and
|
|
2112
|
-
* limitations under the License.
|
|
2113
|
-
* =============================================================================
|
|
2114
|
-
*/
|
|
2115
|
-
const En = "__op";
|
|
2116
|
-
function F(e) {
|
|
2117
|
-
const t = Object.keys(e);
|
|
2118
|
-
if (t.length !== 1)
|
|
2119
|
-
throw new Error(`Please provide an object with a single key (operation name) mapping to a function. Got an object with ${t.length} keys.`);
|
|
2120
|
-
let n = t[0];
|
|
2121
|
-
const s = e[n];
|
|
2122
|
-
n.endsWith("_") && (n = n.substring(0, n.length - 1)), n = n + En;
|
|
2123
|
-
const r = (...a) => {
|
|
2124
|
-
f.startScope(n);
|
|
2125
|
-
try {
|
|
2126
|
-
const o = s(...a);
|
|
2127
|
-
return Pt(o) && console.error("Cannot return a Promise inside of tidy."), f.endScope(o), o;
|
|
2128
|
-
} catch (o) {
|
|
2129
|
-
throw f.endScope(null), o;
|
|
2130
|
-
}
|
|
2131
|
-
};
|
|
2132
|
-
return Object.defineProperty(r, "name", { value: n, configurable: !0 }), r;
|
|
2133
|
-
}
|
|
2134
|
-
/**
|
|
2135
|
-
* @license
|
|
2136
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2137
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2138
|
-
* you may not use this file except in compliance with the License.
|
|
2139
|
-
* You may obtain a copy of the License at
|
|
2140
|
-
*
|
|
2141
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2142
|
-
*
|
|
2143
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2144
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2145
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2146
|
-
* See the License for the specific language governing permissions and
|
|
2147
|
-
* limitations under the License.
|
|
2148
|
-
* =============================================================================
|
|
2149
|
-
*/
|
|
2150
|
-
function vn(e, t, n, s) {
|
|
2151
|
-
if (s == null)
|
|
2152
|
-
s = yt(e);
|
|
2153
|
-
else if (s === "complex64")
|
|
2154
|
-
throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");
|
|
2155
|
-
if (pe(e) || me(e)) {
|
|
2156
|
-
if (s !== "float32" && s !== "int32")
|
|
2157
|
-
throw new Error(`Creating tensor from GPU data only supports 'float32'|'int32' dtype, while the dtype is ${s}.`);
|
|
2158
|
-
return f.backend.createTensorFromGPUData(e, t || n, s);
|
|
2159
|
-
}
|
|
2160
|
-
if (!R(e) && !Array.isArray(e) && typeof e != "number" && typeof e != "boolean" && typeof e != "string")
|
|
2161
|
-
throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");
|
|
2162
|
-
if (t != null) {
|
|
2163
|
-
Ct(t);
|
|
2164
|
-
const r = z(t), a = z(n);
|
|
2165
|
-
p(r === a, () => `Based on the provided shape, [${t}], the tensor should have ${r} values but has ${a}`);
|
|
2166
|
-
for (let o = 0; o < n.length; ++o) {
|
|
2167
|
-
const i = n[o], c = o === n.length - 1 ? i !== z(t.slice(o)) : !0;
|
|
2168
|
-
p(n[o] === t[o] || !c, () => `Error creating a new Tensor. Inferred shape (${n}) does not match the provided shape (${t}). `);
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
return !R(e) && !Array.isArray(e) && (e = [e]), t = t || n, e = s !== "string" ? _t(e, s) : ut(e, [], !0), f.makeTensor(e, t, s);
|
|
2172
|
-
}
|
|
2173
|
-
class st {
|
|
2174
|
-
/**
|
|
2175
|
-
* Concatenate a number of ArrayBuffers into one.
|
|
2176
|
-
*
|
|
2177
|
-
* @param buffers An array of ArrayBuffers to concatenate, or a single
|
|
2178
|
-
* ArrayBuffer.
|
|
2179
|
-
* @returns Result of concatenating `buffers` in order.
|
|
2180
|
-
*/
|
|
2181
|
-
static join(t) {
|
|
2182
|
-
return new st(t).slice();
|
|
2183
|
-
}
|
|
2184
|
-
constructor(t) {
|
|
2185
|
-
if (this.shards = [], this.previousShardIndex = 0, t == null || (t instanceof Array || (t = [t]), t = t.map((s) => R(s) ? s.buffer : s), t.length === 0))
|
|
2186
|
-
return;
|
|
2187
|
-
this.bufferUniformSize = t[0].byteLength;
|
|
2188
|
-
let n = 0;
|
|
2189
|
-
for (let s = 0; s < t.length; s++) {
|
|
2190
|
-
const r = t[s];
|
|
2191
|
-
s !== t.length - 1 && r.byteLength !== this.bufferUniformSize && (this.bufferUniformSize = void 0);
|
|
2192
|
-
const a = n + r.byteLength;
|
|
2193
|
-
this.shards.push({ buffer: r, start: n, end: a }), n = a;
|
|
2194
|
-
}
|
|
2195
|
-
this.shards.length === 0 && (this.byteLength = 0), this.byteLength = this.shards[this.shards.length - 1].end;
|
|
2196
|
-
}
|
|
2197
|
-
slice(t = 0, n = this.byteLength) {
|
|
2198
|
-
if (this.shards.length === 0)
|
|
2199
|
-
return new ArrayBuffer(0);
|
|
2200
|
-
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)
|
|
2201
|
-
return new ArrayBuffer(0);
|
|
2202
|
-
const s = this.findShardForByte(t);
|
|
2203
|
-
if (s === -1)
|
|
2204
|
-
throw new Error(`Could not find start shard for byte ${t}`);
|
|
2205
|
-
const r = n - t, a = new ArrayBuffer(r), o = new Uint8Array(a);
|
|
2206
|
-
let i = 0;
|
|
2207
|
-
for (let c = s; c < this.shards.length; c++) {
|
|
2208
|
-
const l = this.shards[c], h = t + i - l.start, d = i, y = Math.min(n, l.end) - l.start, g = new Uint8Array(l.buffer, h, y - h);
|
|
2209
|
-
if (o.set(g, d), i += g.length, n < l.end)
|
|
2210
|
-
break;
|
|
2211
|
-
}
|
|
2212
|
-
return a;
|
|
2213
|
-
}
|
|
2214
|
-
/**
|
|
2215
|
-
* Get the index of the shard that contains the byte at `byteIndex`.
|
|
2216
|
-
*/
|
|
2217
|
-
findShardForByte(t) {
|
|
2218
|
-
if (this.shards.length === 0 || t < 0 || t >= this.byteLength)
|
|
2219
|
-
return -1;
|
|
2220
|
-
if (this.bufferUniformSize != null)
|
|
2221
|
-
return this.previousShardIndex = Math.floor(t / this.bufferUniformSize), this.previousShardIndex;
|
|
2222
|
-
function n(r) {
|
|
2223
|
-
return t < r.start ? -1 : t >= r.end ? 1 : 0;
|
|
2224
|
-
}
|
|
2225
|
-
if (n(this.shards[this.previousShardIndex]) === 0)
|
|
2226
|
-
return this.previousShardIndex;
|
|
2227
|
-
const s = Bn(this.shards, n);
|
|
2228
|
-
return s === -1 ? -1 : (this.previousShardIndex = s, this.previousShardIndex);
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
function Bn(e, t) {
|
|
2232
|
-
let n = 0, s = e.length;
|
|
2233
|
-
for (; n <= s; ) {
|
|
2234
|
-
const r = Math.floor((s - n) / 2) + n, a = t(e[r]);
|
|
2235
|
-
if (a === 0)
|
|
2236
|
-
return r;
|
|
2237
|
-
a < 0 ? s = r : n = r + 1;
|
|
2238
|
-
}
|
|
2239
|
-
return -1;
|
|
2240
|
-
}
|
|
2241
|
-
/**
|
|
2242
|
-
* @license
|
|
2243
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2244
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2245
|
-
* you may not use this file except in compliance with the License.
|
|
2246
|
-
* You may obtain a copy of the License at
|
|
2247
|
-
*
|
|
2248
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2249
|
-
*
|
|
2250
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2251
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2252
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2253
|
-
* See the License for the specific language governing permissions and
|
|
2254
|
-
* limitations under the License.
|
|
2255
|
-
* =============================================================================
|
|
2256
|
-
*/
|
|
2257
|
-
function ni() {
|
|
2258
|
-
f.disposeVariables();
|
|
2259
|
-
}
|
|
2260
|
-
function si() {
|
|
2261
|
-
return f;
|
|
2262
|
-
}
|
|
2263
|
-
function ri() {
|
|
2264
|
-
return f.memory();
|
|
2265
|
-
}
|
|
2266
|
-
function A(e, t) {
|
|
2267
|
-
return f.tidy(e, t);
|
|
2268
|
-
}
|
|
2269
|
-
function D(e) {
|
|
2270
|
-
ye(e).forEach((n) => n.dispose());
|
|
2271
|
-
}
|
|
2272
|
-
function Mn(e) {
|
|
2273
|
-
return f.keep(e);
|
|
2274
|
-
}
|
|
2275
|
-
function ai(e) {
|
|
2276
|
-
return f.setBackend(e);
|
|
2277
|
-
}
|
|
2278
|
-
function oi() {
|
|
2279
|
-
return f.ready();
|
|
2280
|
-
}
|
|
2281
|
-
function ii() {
|
|
2282
|
-
return f.backendName;
|
|
2283
|
-
}
|
|
2284
|
-
function ci(e, t, n = 1) {
|
|
2285
|
-
return f.registerBackend(e, t, n);
|
|
2286
|
-
}
|
|
2287
|
-
function li() {
|
|
2288
|
-
return f.backend;
|
|
2289
|
-
}
|
|
2290
|
-
const Jt = 4;
|
|
2291
|
-
async function ui(e, t) {
|
|
2292
|
-
const n = [], s = [], r = Array.isArray(e) ? e.map((o) => o.name) : Object.keys(e);
|
|
2293
|
-
for (let o = 0; o < r.length; ++o) {
|
|
2294
|
-
const i = r[o], c = Array.isArray(e) ? e[o].tensor : e[i];
|
|
2295
|
-
if (c.dtype !== "float32" && c.dtype !== "int32" && c.dtype !== "bool" && c.dtype !== "string" && c.dtype !== "complex64")
|
|
2296
|
-
throw new Error(`Unsupported dtype in weight '${i}': ${c.dtype}`);
|
|
2297
|
-
const l = { name: i, shape: c.shape, dtype: c.dtype };
|
|
2298
|
-
if (c.dtype === "string") {
|
|
2299
|
-
const u = new Promise(async (h) => {
|
|
2300
|
-
const d = await c.bytes(), m = d.reduce((w, I) => w + I.length, 0) + Jt * d.length, y = new Uint8Array(m);
|
|
2301
|
-
let g = 0;
|
|
2302
|
-
for (let w = 0; w < d.length; w++) {
|
|
2303
|
-
const I = d[w], _ = new Uint8Array(new Uint32Array([I.length]).buffer);
|
|
2304
|
-
y.set(_, g), g += Jt, y.set(I, g), g += I.length;
|
|
2305
|
-
}
|
|
2306
|
-
h(y);
|
|
2307
|
-
});
|
|
2308
|
-
s.push(u);
|
|
2309
|
-
} else
|
|
2310
|
-
s.push(c.data());
|
|
2311
|
-
t != null && (l.group = t), n.push(l);
|
|
2312
|
-
}
|
|
2313
|
-
const a = await Promise.all(s);
|
|
2314
|
-
return { data: Dn(a), specs: n };
|
|
2315
|
-
}
|
|
2316
|
-
function Dn(e) {
|
|
2317
|
-
if (e === null)
|
|
2318
|
-
throw new Error(`Invalid input value: ${JSON.stringify(e)}`);
|
|
2319
|
-
let t = 0;
|
|
2320
|
-
const n = [];
|
|
2321
|
-
e.forEach((a) => {
|
|
2322
|
-
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))
|
|
2323
|
-
throw new Error(`Unsupported TypedArray subtype: ${a.constructor.name}`);
|
|
2324
|
-
});
|
|
2325
|
-
const s = new Uint8Array(t);
|
|
2326
|
-
let r = 0;
|
|
2327
|
-
return n.forEach((a) => {
|
|
2328
|
-
s.set(new Uint8Array(a.buffer), r), r += a.byteLength;
|
|
2329
|
-
}), s.buffer;
|
|
2330
|
-
}
|
|
2331
|
-
const Ot = typeof pt < "u" && (typeof Blob > "u" || typeof atob > "u" || typeof btoa > "u");
|
|
2332
|
-
function Yt(e) {
|
|
2333
|
-
return Ot ? pt.byteLength(e, "utf8") : new Blob([e]).size;
|
|
2334
|
-
}
|
|
2335
|
-
function Fn(e) {
|
|
2336
|
-
if (Ot)
|
|
2337
|
-
return pt.from(e).toString("base64");
|
|
2338
|
-
const t = new Uint8Array(e);
|
|
2339
|
-
let n = "";
|
|
2340
|
-
for (let s = 0, r = t.length; s < r; s++)
|
|
2341
|
-
n += String.fromCharCode(t[s]);
|
|
2342
|
-
return btoa(n);
|
|
2343
|
-
}
|
|
2344
|
-
function Rn(e) {
|
|
2345
|
-
if (Ot) {
|
|
2346
|
-
const s = pt.from(e, "base64");
|
|
2347
|
-
return s.buffer.slice(s.byteOffset, s.byteOffset + s.byteLength);
|
|
2348
|
-
}
|
|
2349
|
-
const t = atob(e), n = new Uint8Array(t.length);
|
|
2350
|
-
for (let s = 0; s < t.length; ++s)
|
|
2351
|
-
n.set([t.charCodeAt(s)], s);
|
|
2352
|
-
return n.buffer;
|
|
2353
|
-
}
|
|
2354
|
-
function hi(e) {
|
|
2355
|
-
return st.join(e);
|
|
2356
|
-
}
|
|
2357
|
-
function di(e, t) {
|
|
2358
|
-
const n = {
|
|
2359
|
-
modelTopology: e.modelTopology,
|
|
2360
|
-
format: e.format,
|
|
2361
|
-
generatedBy: e.generatedBy,
|
|
2362
|
-
convertedBy: e.convertedBy,
|
|
2363
|
-
weightsManifest: t
|
|
2364
|
-
};
|
|
2365
|
-
return e.signature != null && (n.signature = e.signature), e.userDefinedMetadata != null && (n.userDefinedMetadata = e.userDefinedMetadata), e.modelInitializer != null && (n.modelInitializer = e.modelInitializer), e.initializerSignature != null && (n.initializerSignature = e.initializerSignature), e.trainingConfig != null && (n.trainingConfig = e.trainingConfig), n;
|
|
2366
|
-
}
|
|
2367
|
-
function xn(e, t, n) {
|
|
2368
|
-
const s = {
|
|
2369
|
-
modelTopology: e.modelTopology,
|
|
2370
|
-
format: e.format,
|
|
2371
|
-
generatedBy: e.generatedBy,
|
|
2372
|
-
convertedBy: e.convertedBy
|
|
2373
|
-
};
|
|
2374
|
-
if (e.trainingConfig != null && (s.trainingConfig = e.trainingConfig), e.weightsManifest != null) {
|
|
2375
|
-
if (!t)
|
|
2376
|
-
throw new Error("modelJSON has weightsManifest but weightSpecs is null");
|
|
2377
|
-
if (!n)
|
|
2378
|
-
throw new Error("modelJSON has weightsManifest but weightData is null");
|
|
2379
|
-
s.weightSpecs = t, s.weightData = n;
|
|
2380
|
-
}
|
|
2381
|
-
return e.signature != null && (s.signature = e.signature), e.userDefinedMetadata != null && (s.userDefinedMetadata = e.userDefinedMetadata), e.modelInitializer != null && (s.modelInitializer = e.modelInitializer), e.initializerSignature != null && (s.initializerSignature = e.initializerSignature), s;
|
|
2382
|
-
}
|
|
2383
|
-
async function fi(e, t) {
|
|
2384
|
-
let n, s;
|
|
2385
|
-
return e.weightsManifest != null && ([n, s] = await t(e.weightsManifest)), xn(e, n, s);
|
|
2386
|
-
}
|
|
2387
|
-
function ke(e) {
|
|
2388
|
-
if (e.modelTopology instanceof ArrayBuffer)
|
|
2389
|
-
throw new Error("Expected JSON model topology, received ArrayBuffer.");
|
|
2390
|
-
return {
|
|
2391
|
-
dateSaved: /* @__PURE__ */ new Date(),
|
|
2392
|
-
modelTopologyType: "JSON",
|
|
2393
|
-
modelTopologyBytes: e.modelTopology == null ? 0 : Yt(JSON.stringify(e.modelTopology)),
|
|
2394
|
-
weightSpecsBytes: e.weightSpecs == null ? 0 : Yt(JSON.stringify(e.weightSpecs)),
|
|
2395
|
-
weightDataBytes: e.weightData == null ? 0 : new st(e.weightData).byteLength
|
|
2396
|
-
};
|
|
2397
|
-
}
|
|
2398
|
-
function gi(e) {
|
|
2399
|
-
const t = [];
|
|
2400
|
-
for (const n of e)
|
|
2401
|
-
t.push(...n.weights);
|
|
2402
|
-
return t;
|
|
2403
|
-
}
|
|
2404
|
-
/**
|
|
2405
|
-
* @license
|
|
2406
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2407
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2408
|
-
* you may not use this file except in compliance with the License.
|
|
2409
|
-
* You may obtain a copy of the License at
|
|
2410
|
-
*
|
|
2411
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2412
|
-
*
|
|
2413
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2414
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2415
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2416
|
-
* See the License for the specific language governing permissions and
|
|
2417
|
-
* limitations under the License.
|
|
2418
|
-
* =============================================================================
|
|
2419
|
-
*/
|
|
2420
|
-
class E {
|
|
2421
|
-
constructor() {
|
|
2422
|
-
this.saveRouters = [], this.loadRouters = [];
|
|
2423
|
-
}
|
|
2424
|
-
static getInstance() {
|
|
2425
|
-
return E.instance == null && (E.instance = new E()), E.instance;
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* Register a save-handler router.
|
|
2429
|
-
*
|
|
2430
|
-
* @param saveRouter A function that maps a URL-like string onto an instance
|
|
2431
|
-
* of `IOHandler` with the `save` method defined or `null`.
|
|
2432
|
-
*/
|
|
2433
|
-
static registerSaveRouter(t) {
|
|
2434
|
-
E.getInstance().saveRouters.push(t);
|
|
2435
|
-
}
|
|
2436
|
-
/**
|
|
2437
|
-
* Register a load-handler router.
|
|
2438
|
-
*
|
|
2439
|
-
* @param loadRouter A function that maps a URL-like string onto an instance
|
|
2440
|
-
* of `IOHandler` with the `load` method defined or `null`.
|
|
2441
|
-
*/
|
|
2442
|
-
static registerLoadRouter(t) {
|
|
2443
|
-
E.getInstance().loadRouters.push(t);
|
|
2444
|
-
}
|
|
2445
|
-
/**
|
|
2446
|
-
* Look up IOHandler for saving, given a URL-like string.
|
|
2447
|
-
*
|
|
2448
|
-
* @param url
|
|
2449
|
-
* @returns If only one match is found, an instance of IOHandler with the
|
|
2450
|
-
* `save` method defined. If no match is found, `null`.
|
|
2451
|
-
* @throws Error, if more than one match is found.
|
|
2452
|
-
*/
|
|
2453
|
-
static getSaveHandlers(t) {
|
|
2454
|
-
return E.getHandlers(t, "save");
|
|
2455
|
-
}
|
|
2456
|
-
/**
|
|
2457
|
-
* Look up IOHandler for loading, given a URL-like string.
|
|
2458
|
-
*
|
|
2459
|
-
* @param url
|
|
2460
|
-
* @param loadOptions Optional, custom load options.
|
|
2461
|
-
* @returns All valid handlers for `url`, given the currently registered
|
|
2462
|
-
* handler routers.
|
|
2463
|
-
*/
|
|
2464
|
-
static getLoadHandlers(t, n) {
|
|
2465
|
-
return E.getHandlers(t, "load", n);
|
|
2466
|
-
}
|
|
2467
|
-
static getHandlers(t, n, s) {
|
|
2468
|
-
const r = [];
|
|
2469
|
-
return (n === "load" ? E.getInstance().loadRouters : E.getInstance().saveRouters).forEach((o) => {
|
|
2470
|
-
const i = o(t, s);
|
|
2471
|
-
i !== null && r.push(i);
|
|
2472
|
-
}), r;
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
const mi = (e) => E.getSaveHandlers(e);
|
|
2476
|
-
/**
|
|
2477
|
-
* @license
|
|
2478
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2479
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2480
|
-
* you may not use this file except in compliance with the License.
|
|
2481
|
-
* You may obtain a copy of the License at
|
|
2482
|
-
*
|
|
2483
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2484
|
-
*
|
|
2485
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2486
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2487
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2488
|
-
* See the License for the specific language governing permissions and
|
|
2489
|
-
* limitations under the License.
|
|
2490
|
-
* =============================================================================
|
|
2491
|
-
*/
|
|
2492
|
-
const Mt = "tensorflowjs", Dt = 1, U = "models_store", L = "model_info_store";
|
|
2493
|
-
function Ie() {
|
|
2494
|
-
if (!S().getBool("IS_BROWSER"))
|
|
2495
|
-
throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");
|
|
2496
|
-
const e = typeof window > "u" ? self : window, t = e.indexedDB || e.mozIndexedDB || e.webkitIndexedDB || e.msIndexedDB || e.shimIndexedDB;
|
|
2497
|
-
if (t == null)
|
|
2498
|
-
throw new Error("The current browser does not appear to support IndexedDB.");
|
|
2499
|
-
return t;
|
|
2500
|
-
}
|
|
2501
|
-
function Ft(e) {
|
|
2502
|
-
const t = e.result;
|
|
2503
|
-
t.createObjectStore(U, { keyPath: "modelPath" }), t.createObjectStore(L, { keyPath: "modelPath" });
|
|
2504
|
-
}
|
|
2505
|
-
class W {
|
|
2506
|
-
constructor(t) {
|
|
2507
|
-
if (this.indexedDB = Ie(), t == null || !t)
|
|
2508
|
-
throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");
|
|
2509
|
-
this.modelPath = t;
|
|
2510
|
-
}
|
|
2511
|
-
async save(t) {
|
|
2512
|
-
if (t.modelTopology instanceof ArrayBuffer)
|
|
2513
|
-
throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
|
|
2514
|
-
return this.databaseAction(this.modelPath, t);
|
|
2515
|
-
}
|
|
2516
|
-
async load() {
|
|
2517
|
-
return this.databaseAction(this.modelPath);
|
|
2518
|
-
}
|
|
2519
|
-
/**
|
|
2520
|
-
* Perform database action to put model artifacts into or read model artifacts
|
|
2521
|
-
* from IndexedDB object store.
|
|
2522
|
-
*
|
|
2523
|
-
* Whether the action is put or get depends on whether `modelArtifacts` is
|
|
2524
|
-
* specified. If it is specified, the action will be put; otherwise the action
|
|
2525
|
-
* will be get.
|
|
2526
|
-
*
|
|
2527
|
-
* @param modelPath A unique string path for the model.
|
|
2528
|
-
* @param modelArtifacts If specified, it will be the model artifacts to be
|
|
2529
|
-
* stored in IndexedDB.
|
|
2530
|
-
* @returns A `Promise` of `SaveResult`, if the action is put, or a `Promise`
|
|
2531
|
-
* of `ModelArtifacts`, if the action is get.
|
|
2532
|
-
*/
|
|
2533
|
-
databaseAction(t, n) {
|
|
2534
|
-
return new Promise((s, r) => {
|
|
2535
|
-
const a = this.indexedDB.open(Mt, Dt);
|
|
2536
|
-
a.onupgradeneeded = () => Ft(a), a.onsuccess = () => {
|
|
2537
|
-
const o = a.result;
|
|
2538
|
-
if (n == null) {
|
|
2539
|
-
const i = o.transaction(U, "readonly"), l = i.objectStore(U).get(this.modelPath);
|
|
2540
|
-
l.onsuccess = () => {
|
|
2541
|
-
if (l.result == null)
|
|
2542
|
-
return o.close(), r(new Error(`Cannot find model with path '${this.modelPath}' in IndexedDB.`));
|
|
2543
|
-
s(l.result.modelArtifacts);
|
|
2544
|
-
}, l.onerror = (u) => (o.close(), r(l.error)), i.oncomplete = () => o.close();
|
|
2545
|
-
} else {
|
|
2546
|
-
n.weightData = st.join(n.weightData);
|
|
2547
|
-
const i = ke(n), c = o.transaction(L, "readwrite");
|
|
2548
|
-
let l = c.objectStore(L), u;
|
|
2549
|
-
try {
|
|
2550
|
-
u = l.put({ modelPath: this.modelPath, modelArtifactsInfo: i });
|
|
2551
|
-
} catch (d) {
|
|
2552
|
-
return r(d);
|
|
2553
|
-
}
|
|
2554
|
-
let h;
|
|
2555
|
-
u.onsuccess = () => {
|
|
2556
|
-
h = o.transaction(U, "readwrite");
|
|
2557
|
-
const d = h.objectStore(U);
|
|
2558
|
-
let m;
|
|
2559
|
-
try {
|
|
2560
|
-
m = d.put({
|
|
2561
|
-
modelPath: this.modelPath,
|
|
2562
|
-
modelArtifacts: n,
|
|
2563
|
-
modelArtifactsInfo: i
|
|
2564
|
-
});
|
|
2565
|
-
} catch (y) {
|
|
2566
|
-
return r(y);
|
|
2567
|
-
}
|
|
2568
|
-
m.onsuccess = () => s({ modelArtifactsInfo: i }), m.onerror = (y) => {
|
|
2569
|
-
l = c.objectStore(L);
|
|
2570
|
-
const g = l.delete(this.modelPath);
|
|
2571
|
-
g.onsuccess = () => (o.close(), r(m.error)), g.onerror = (w) => (o.close(), r(m.error));
|
|
2572
|
-
};
|
|
2573
|
-
}, u.onerror = (d) => (o.close(), r(u.error)), c.oncomplete = () => {
|
|
2574
|
-
h == null ? o.close() : h.oncomplete = () => o.close();
|
|
2575
|
-
};
|
|
2576
|
-
}
|
|
2577
|
-
}, a.onerror = (o) => r(a.error);
|
|
2578
|
-
});
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
W.URL_SCHEME = "indexeddb://";
|
|
2582
|
-
const Te = (e) => S().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(W.URL_SCHEME) ? Nn(e.slice(W.URL_SCHEME.length)) : null;
|
|
2583
|
-
E.registerSaveRouter(Te);
|
|
2584
|
-
E.registerLoadRouter(Te);
|
|
2585
|
-
function Nn(e) {
|
|
2586
|
-
return new W(e);
|
|
2587
|
-
}
|
|
2588
|
-
function $n(e) {
|
|
2589
|
-
return e.startsWith(W.URL_SCHEME) ? e.slice(W.URL_SCHEME.length) : e;
|
|
2590
|
-
}
|
|
2591
|
-
class Cn {
|
|
2592
|
-
constructor() {
|
|
2593
|
-
this.indexedDB = Ie();
|
|
2594
|
-
}
|
|
2595
|
-
async listModels() {
|
|
2596
|
-
return new Promise((t, n) => {
|
|
2597
|
-
const s = this.indexedDB.open(Mt, Dt);
|
|
2598
|
-
s.onupgradeneeded = () => Ft(s), s.onsuccess = () => {
|
|
2599
|
-
const r = s.result, a = r.transaction(L, "readonly"), i = a.objectStore(L).getAll();
|
|
2600
|
-
i.onsuccess = () => {
|
|
2601
|
-
const c = {};
|
|
2602
|
-
for (const l of i.result)
|
|
2603
|
-
c[l.modelPath] = l.modelArtifactsInfo;
|
|
2604
|
-
t(c);
|
|
2605
|
-
}, i.onerror = (c) => (r.close(), n(i.error)), a.oncomplete = () => r.close();
|
|
2606
|
-
}, s.onerror = (r) => n(s.error);
|
|
2607
|
-
});
|
|
2608
|
-
}
|
|
2609
|
-
async removeModel(t) {
|
|
2610
|
-
return t = $n(t), new Promise((n, s) => {
|
|
2611
|
-
const r = this.indexedDB.open(Mt, Dt);
|
|
2612
|
-
r.onupgradeneeded = () => Ft(r), r.onsuccess = () => {
|
|
2613
|
-
const a = r.result, o = a.transaction(L, "readwrite"), i = o.objectStore(L), c = i.get(t);
|
|
2614
|
-
let l;
|
|
2615
|
-
c.onsuccess = () => {
|
|
2616
|
-
if (c.result == null)
|
|
2617
|
-
return a.close(), s(new Error(`Cannot find model with path '${t}' in IndexedDB.`));
|
|
2618
|
-
{
|
|
2619
|
-
const u = i.delete(t), h = () => {
|
|
2620
|
-
l = a.transaction(U, "readwrite");
|
|
2621
|
-
const m = l.objectStore(U).delete(t);
|
|
2622
|
-
m.onsuccess = () => n(c.result.modelArtifactsInfo), m.onerror = (y) => s(c.error);
|
|
2623
|
-
};
|
|
2624
|
-
u.onsuccess = h, u.onerror = (d) => (h(), a.close(), s(c.error));
|
|
2625
|
-
}
|
|
2626
|
-
}, c.onerror = (u) => (a.close(), s(c.error)), o.oncomplete = () => {
|
|
2627
|
-
l == null ? a.close() : l.oncomplete = () => a.close();
|
|
2628
|
-
};
|
|
2629
|
-
}, r.onerror = (a) => s(r.error);
|
|
2630
|
-
});
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
/**
|
|
2634
|
-
* @license
|
|
2635
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2636
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2637
|
-
* you may not use this file except in compliance with the License.
|
|
2638
|
-
* You may obtain a copy of the License at
|
|
2639
|
-
*
|
|
2640
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2641
|
-
*
|
|
2642
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2643
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2644
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2645
|
-
* See the License for the specific language governing permissions and
|
|
2646
|
-
* limitations under the License.
|
|
2647
|
-
* =============================================================================
|
|
2648
|
-
*/
|
|
2649
|
-
const P = "/", Z = "tensorflowjs_models", Ae = "info", Pn = "model_topology", Ln = "weight_specs", _n = "weight_data", On = "model_metadata";
|
|
2650
|
-
function Ee(e) {
|
|
2651
|
-
return {
|
|
2652
|
-
info: [Z, e, Ae].join(P),
|
|
2653
|
-
topology: [Z, e, Pn].join(P),
|
|
2654
|
-
weightSpecs: [Z, e, Ln].join(P),
|
|
2655
|
-
weightData: [Z, e, _n].join(P),
|
|
2656
|
-
modelMetadata: [Z, e, On].join(P)
|
|
2657
|
-
};
|
|
2658
|
-
}
|
|
2659
|
-
function ve(e) {
|
|
2660
|
-
for (const t of Object.values(e))
|
|
2661
|
-
window.localStorage.removeItem(t);
|
|
2662
|
-
}
|
|
2663
|
-
function Gn(e) {
|
|
2664
|
-
const t = e.split(P);
|
|
2665
|
-
if (t.length < 3)
|
|
2666
|
-
throw new Error(`Invalid key format: ${e}`);
|
|
2667
|
-
return t.slice(1, t.length - 1).join(P);
|
|
2668
|
-
}
|
|
2669
|
-
function Un(e) {
|
|
2670
|
-
return e.startsWith(j.URL_SCHEME) ? e.slice(j.URL_SCHEME.length) : e;
|
|
2671
|
-
}
|
|
2672
|
-
class j {
|
|
2673
|
-
constructor(t) {
|
|
2674
|
-
if (!S().getBool("IS_BROWSER") || typeof window > "u" || typeof window.localStorage > "u")
|
|
2675
|
-
throw new Error("The current environment does not support local storage.");
|
|
2676
|
-
if (this.LS = window.localStorage, t == null || !t)
|
|
2677
|
-
throw new Error("For local storage, modelPath must not be null, undefined or empty.");
|
|
2678
|
-
this.modelPath = t, this.keys = Ee(this.modelPath);
|
|
2679
|
-
}
|
|
2680
|
-
/**
|
|
2681
|
-
* Save model artifacts to browser local storage.
|
|
2682
|
-
*
|
|
2683
|
-
* See the documentation to `browserLocalStorage` for details on the saved
|
|
2684
|
-
* artifacts.
|
|
2685
|
-
*
|
|
2686
|
-
* @param modelArtifacts The model artifacts to be stored.
|
|
2687
|
-
* @returns An instance of SaveResult.
|
|
2688
|
-
*/
|
|
2689
|
-
async save(t) {
|
|
2690
|
-
if (t.modelTopology instanceof ArrayBuffer)
|
|
2691
|
-
throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
|
|
2692
|
-
{
|
|
2693
|
-
const n = JSON.stringify(t.modelTopology), s = JSON.stringify(t.weightSpecs), r = ke(t), a = st.join(t.weightData);
|
|
2694
|
-
try {
|
|
2695
|
-
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, Fn(a));
|
|
2696
|
-
const o = {
|
|
2697
|
-
format: t.format,
|
|
2698
|
-
generatedBy: t.generatedBy,
|
|
2699
|
-
convertedBy: t.convertedBy,
|
|
2700
|
-
signature: t.signature != null ? t.signature : void 0,
|
|
2701
|
-
userDefinedMetadata: t.userDefinedMetadata != null ? t.userDefinedMetadata : void 0,
|
|
2702
|
-
modelInitializer: t.modelInitializer != null ? t.modelInitializer : void 0,
|
|
2703
|
-
initializerSignature: t.initializerSignature != null ? t.initializerSignature : void 0,
|
|
2704
|
-
trainingConfig: t.trainingConfig != null ? t.trainingConfig : void 0
|
|
2705
|
-
};
|
|
2706
|
-
return this.LS.setItem(this.keys.modelMetadata, JSON.stringify(o)), { modelArtifactsInfo: r };
|
|
2707
|
-
} catch {
|
|
2708
|
-
throw ve(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}.`);
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
/**
|
|
2713
|
-
* Load a model from local storage.
|
|
2714
|
-
*
|
|
2715
|
-
* See the documentation to `browserLocalStorage` for details on the saved
|
|
2716
|
-
* artifacts.
|
|
2717
|
-
*
|
|
2718
|
-
* @returns The loaded model (if loading succeeds).
|
|
2719
|
-
*/
|
|
2720
|
-
async load() {
|
|
2721
|
-
const t = JSON.parse(this.LS.getItem(this.keys.info));
|
|
2722
|
-
if (t == null)
|
|
2723
|
-
throw new Error(`In local storage, there is no model with name '${this.modelPath}'`);
|
|
2724
|
-
if (t.modelTopologyType !== "JSON")
|
|
2725
|
-
throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");
|
|
2726
|
-
const n = {}, s = JSON.parse(this.LS.getItem(this.keys.topology));
|
|
2727
|
-
if (s == null)
|
|
2728
|
-
throw new Error(`In local storage, the topology of model '${this.modelPath}' is missing.`);
|
|
2729
|
-
n.modelTopology = s;
|
|
2730
|
-
const r = JSON.parse(this.LS.getItem(this.keys.weightSpecs));
|
|
2731
|
-
if (r == null)
|
|
2732
|
-
throw new Error(`In local storage, the weight specs of model '${this.modelPath}' are missing.`);
|
|
2733
|
-
n.weightSpecs = r;
|
|
2734
|
-
const a = this.LS.getItem(this.keys.modelMetadata);
|
|
2735
|
-
if (a != null) {
|
|
2736
|
-
const i = JSON.parse(a);
|
|
2737
|
-
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);
|
|
2738
|
-
}
|
|
2739
|
-
const o = this.LS.getItem(this.keys.weightData);
|
|
2740
|
-
if (o == null)
|
|
2741
|
-
throw new Error(`In local storage, the binary weight values of model '${this.modelPath}' are missing.`);
|
|
2742
|
-
return n.weightData = Rn(o), n;
|
|
2743
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
j.URL_SCHEME = "localstorage://";
|
|
2746
|
-
const Be = (e) => S().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(j.URL_SCHEME) ? zn(e.slice(j.URL_SCHEME.length)) : null;
|
|
2747
|
-
E.registerSaveRouter(Be);
|
|
2748
|
-
E.registerLoadRouter(Be);
|
|
2749
|
-
function zn(e) {
|
|
2750
|
-
return new j(e);
|
|
2751
|
-
}
|
|
2752
|
-
class Vn {
|
|
2753
|
-
constructor() {
|
|
2754
|
-
p(S().getBool("IS_BROWSER"), () => "Current environment is not a web browser"), p(typeof window > "u" || typeof window.localStorage < "u", () => "Current browser does not appear to support localStorage"), this.LS = window.localStorage;
|
|
2755
|
-
}
|
|
2756
|
-
async listModels() {
|
|
2757
|
-
const t = {}, n = Z + P, s = P + Ae;
|
|
2758
|
-
for (let r = 0; r < this.LS.length; ++r) {
|
|
2759
|
-
const a = this.LS.key(r);
|
|
2760
|
-
if (a.startsWith(n) && a.endsWith(s)) {
|
|
2761
|
-
const o = Gn(a);
|
|
2762
|
-
t[o] = JSON.parse(this.LS.getItem(a));
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
|
-
return t;
|
|
2766
|
-
}
|
|
2767
|
-
async removeModel(t) {
|
|
2768
|
-
t = Un(t);
|
|
2769
|
-
const n = Ee(t);
|
|
2770
|
-
if (this.LS.getItem(n.info) == null)
|
|
2771
|
-
throw new Error(`Cannot find model at path '${t}'`);
|
|
2772
|
-
const s = JSON.parse(this.LS.getItem(n.info));
|
|
2773
|
-
return ve(n), s;
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
/**
|
|
2777
|
-
* @license
|
|
2778
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2779
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2780
|
-
* you may not use this file except in compliance with the License.
|
|
2781
|
-
* You may obtain a copy of the License at
|
|
2782
|
-
*
|
|
2783
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2784
|
-
*
|
|
2785
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2786
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2787
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2788
|
-
* See the License for the specific language governing permissions and
|
|
2789
|
-
* limitations under the License.
|
|
2790
|
-
* =============================================================================
|
|
2791
|
-
*/
|
|
2792
|
-
const Zt = "://";
|
|
2793
|
-
class N {
|
|
2794
|
-
constructor() {
|
|
2795
|
-
this.managers = {};
|
|
2796
|
-
}
|
|
2797
|
-
static getInstance() {
|
|
2798
|
-
return N.instance == null && (N.instance = new N()), N.instance;
|
|
2799
|
-
}
|
|
2800
|
-
/**
|
|
2801
|
-
* Register a save-handler router.
|
|
2802
|
-
*
|
|
2803
|
-
* @param saveRouter A function that maps a URL-like string onto an instance
|
|
2804
|
-
* of `IOHandler` with the `save` method defined or `null`.
|
|
2805
|
-
*/
|
|
2806
|
-
static registerManager(t, n) {
|
|
2807
|
-
p(t != null, () => "scheme must not be undefined or null."), t.endsWith(Zt) && (t = t.slice(0, t.indexOf(Zt))), p(t.length > 0, () => "scheme must not be an empty string.");
|
|
2808
|
-
const s = N.getInstance();
|
|
2809
|
-
p(s.managers[t] == null, () => `A model store manager is already registered for scheme '${t}'.`), s.managers[t] = n;
|
|
2810
|
-
}
|
|
2811
|
-
static getManager(t) {
|
|
2812
|
-
const n = N.getInstance().managers[t];
|
|
2813
|
-
if (n == null)
|
|
2814
|
-
throw new Error(`Cannot find model manager for scheme '${t}'`);
|
|
2815
|
-
return n;
|
|
2816
|
-
}
|
|
2817
|
-
static getSchemes() {
|
|
2818
|
-
return Object.keys(N.getInstance().managers);
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
/**
|
|
2822
|
-
* @license
|
|
2823
|
-
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
2824
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2825
|
-
* you may not use this file except in compliance with the License.
|
|
2826
|
-
* You may obtain a copy of the License at
|
|
2827
|
-
*
|
|
2828
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2829
|
-
*
|
|
2830
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2831
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2832
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2833
|
-
* See the License for the specific language governing permissions and
|
|
2834
|
-
* limitations under the License.
|
|
2835
|
-
* =============================================================================
|
|
2836
|
-
*/
|
|
2837
|
-
class Wn {
|
|
2838
|
-
constructor() {
|
|
2839
|
-
this.messageName = "setTimeoutCustom", this.functionRefs = [], this.handledMessageCount = 0, this.hasEventListener = !1;
|
|
2840
|
-
}
|
|
2841
|
-
fetch(t, n) {
|
|
2842
|
-
return fetch(t, n);
|
|
2843
|
-
}
|
|
2844
|
-
now() {
|
|
2845
|
-
return performance.now();
|
|
2846
|
-
}
|
|
2847
|
-
encode(t, n) {
|
|
2848
|
-
if (n !== "utf-8" && n !== "utf8")
|
|
2849
|
-
throw new Error(`Browser's encoder only supports utf-8, but got ${n}`);
|
|
2850
|
-
return this.textEncoder == null && (this.textEncoder = new TextEncoder()), this.textEncoder.encode(t);
|
|
2851
|
-
}
|
|
2852
|
-
decode(t, n) {
|
|
2853
|
-
return new TextDecoder(n).decode(t);
|
|
2854
|
-
}
|
|
2855
|
-
// If the setTimeout nesting level is greater than 5 and timeout is less
|
|
2856
|
-
// than 4ms, timeout will be clamped to 4ms, which hurts the perf.
|
|
2857
|
-
// Interleaving window.postMessage and setTimeout will trick the browser and
|
|
2858
|
-
// avoid the clamp.
|
|
2859
|
-
setTimeoutCustom(t, n) {
|
|
2860
|
-
if (typeof window > "u" || !S().getBool("USE_SETTIMEOUTCUSTOM")) {
|
|
2861
|
-
setTimeout(t, n);
|
|
2862
|
-
return;
|
|
2863
|
-
}
|
|
2864
|
-
this.functionRefs.push(t), setTimeout(() => {
|
|
2865
|
-
window.postMessage({ name: this.messageName, index: this.functionRefs.length - 1 }, "*");
|
|
2866
|
-
}, n), this.hasEventListener || (this.hasEventListener = !0, window.addEventListener("message", (s) => {
|
|
2867
|
-
if (s.source === window && s.data.name === this.messageName) {
|
|
2868
|
-
s.stopPropagation();
|
|
2869
|
-
const r = this.functionRefs[s.data.index];
|
|
2870
|
-
r(), this.handledMessageCount++, this.handledMessageCount === this.functionRefs.length && (this.functionRefs = [], this.handledMessageCount = 0);
|
|
2871
|
-
}
|
|
2872
|
-
}, !0));
|
|
2873
|
-
}
|
|
2874
|
-
isTypedArray(t) {
|
|
2875
|
-
return ue(t);
|
|
2876
|
-
}
|
|
2877
|
-
}
|
|
2878
|
-
if (S().get("IS_BROWSER")) {
|
|
2879
|
-
S().setPlatform("browser", new Wn());
|
|
2880
|
-
try {
|
|
2881
|
-
N.registerManager(j.URL_SCHEME, new Vn());
|
|
2882
|
-
} catch {
|
|
2883
|
-
}
|
|
2884
|
-
try {
|
|
2885
|
-
N.registerManager(W.URL_SCHEME, new Cn());
|
|
2886
|
-
} catch {
|
|
2887
|
-
}
|
|
2888
|
-
}
|
|
2889
|
-
const jn = {
|
|
2890
|
-
// tslint:disable-next-line:no-require-imports
|
|
2891
|
-
importFetch: () => require("node-fetch")
|
|
2892
|
-
};
|
|
2893
|
-
let kt;
|
|
2894
|
-
class qn {
|
|
2895
|
-
constructor() {
|
|
2896
|
-
this.util = require("util"), this.textEncoder = new this.util.TextEncoder();
|
|
2897
|
-
}
|
|
2898
|
-
fetch(t, n) {
|
|
2899
|
-
return S().global.fetch != null ? S().global.fetch(t, n) : (kt == null && (kt = jn.importFetch()), kt(t, n));
|
|
2900
|
-
}
|
|
2901
|
-
now() {
|
|
2902
|
-
const t = Q.hrtime();
|
|
2903
|
-
return t[0] * 1e3 + t[1] / 1e6;
|
|
2904
|
-
}
|
|
2905
|
-
encode(t, n) {
|
|
2906
|
-
if (n !== "utf-8" && n !== "utf8")
|
|
2907
|
-
throw new Error(`Node built-in encoder only supports utf-8, but got ${n}`);
|
|
2908
|
-
return this.textEncoder.encode(t);
|
|
2909
|
-
}
|
|
2910
|
-
decode(t, n) {
|
|
2911
|
-
return t.length === 0 ? "" : new this.util.TextDecoder(n).decode(t);
|
|
2912
|
-
}
|
|
2913
|
-
isTypedArray(t) {
|
|
2914
|
-
return this.util.types.isFloat32Array(t) || this.util.types.isInt32Array(t) || this.util.types.isUint8Array(t) || this.util.types.isUint8ClampedArray(t);
|
|
2915
|
-
}
|
|
2916
|
-
}
|
|
2917
|
-
S().get("IS_NODE") && !S().get("IS_BROWSER") && S().setPlatform("node", new qn());
|
|
2918
|
-
/**
|
|
2919
|
-
* @license
|
|
2920
|
-
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
2921
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2922
|
-
* you may not use this file except in compliance with the License.
|
|
2923
|
-
* You may obtain a copy of the License at
|
|
2924
|
-
*
|
|
2925
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2926
|
-
*
|
|
2927
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2928
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2929
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2930
|
-
* See the License for the specific language governing permissions and
|
|
2931
|
-
* limitations under the License.
|
|
2932
|
-
* =============================================================================
|
|
2933
|
-
*/
|
|
2934
|
-
function Kn(e, t = "float32", n) {
|
|
2935
|
-
return t = t || "float32", Ct(e), new gn(e, t, n);
|
|
2936
|
-
}
|
|
2937
|
-
/**
|
|
2938
|
-
* @license
|
|
2939
|
-
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
2940
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2941
|
-
* you may not use this file except in compliance with the License.
|
|
2942
|
-
* You may obtain a copy of the License at
|
|
2943
|
-
*
|
|
2944
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2945
|
-
*
|
|
2946
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2947
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2948
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2949
|
-
* See the License for the specific language governing permissions and
|
|
2950
|
-
* limitations under the License.
|
|
2951
|
-
* =============================================================================
|
|
2952
|
-
*/
|
|
2953
|
-
function Hn(e, t) {
|
|
2954
|
-
const n = T(e, "x", "cast");
|
|
2955
|
-
if (!Le(t))
|
|
2956
|
-
throw new Error(`Failed to cast to unknown dtype ${t}`);
|
|
2957
|
-
if (t === "string" && n.dtype !== "string" || t !== "string" && n.dtype === "string")
|
|
2958
|
-
throw new Error("Only strings can be casted to strings");
|
|
2959
|
-
const s = { x: n }, r = { dtype: t };
|
|
2960
|
-
return f.runKernel(ie, s, r);
|
|
2961
|
-
}
|
|
2962
|
-
const Rt = /* @__PURE__ */ F({ cast_: Hn });
|
|
2963
|
-
/**
|
|
2964
|
-
* @license
|
|
2965
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2966
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2967
|
-
* you may not use this file except in compliance with the License.
|
|
2968
|
-
* You may obtain a copy of the License at
|
|
2969
|
-
*
|
|
2970
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2971
|
-
*
|
|
2972
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2973
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2974
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2975
|
-
* See the License for the specific language governing permissions and
|
|
2976
|
-
* limitations under the License.
|
|
2977
|
-
* =============================================================================
|
|
2978
|
-
*/
|
|
2979
|
-
function Xn(e) {
|
|
2980
|
-
const n = { x: T(e, "x", "clone", "string_or_numeric") };
|
|
2981
|
-
return f.runKernel(ce, n);
|
|
2982
|
-
}
|
|
2983
|
-
const Jn = /* @__PURE__ */ F({ clone_: Xn });
|
|
2984
|
-
/**
|
|
2985
|
-
* @license
|
|
2986
|
-
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
2987
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2988
|
-
* you may not use this file except in compliance with the License.
|
|
2989
|
-
* You may obtain a copy of the License at
|
|
2990
|
-
*
|
|
2991
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2992
|
-
*
|
|
2993
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2994
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2995
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2996
|
-
* See the License for the specific language governing permissions and
|
|
2997
|
-
* limitations under the License.
|
|
2998
|
-
* =============================================================================
|
|
2999
|
-
*/
|
|
3000
|
-
function Yn(e, t = !1) {
|
|
3001
|
-
console.log(e.toString(t));
|
|
3002
|
-
}
|
|
3003
|
-
/**
|
|
3004
|
-
* @license
|
|
3005
|
-
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
3006
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3007
|
-
* you may not use this file except in compliance with the License.
|
|
3008
|
-
* You may obtain a copy of the License at
|
|
3009
|
-
*
|
|
3010
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3011
|
-
*
|
|
3012
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3013
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3014
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3015
|
-
* See the License for the specific language governing permissions and
|
|
3016
|
-
* limitations under the License.
|
|
3017
|
-
* =============================================================================
|
|
3018
|
-
*/
|
|
3019
|
-
we();
|
|
3020
|
-
const Zn = {
|
|
3021
|
-
buffer: Kn,
|
|
3022
|
-
cast: Rt,
|
|
3023
|
-
clone: Jn,
|
|
3024
|
-
print: Yn
|
|
3025
|
-
};
|
|
3026
|
-
pn(Zn);
|
|
3027
|
-
/**
|
|
3028
|
-
* @license
|
|
3029
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3030
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3031
|
-
* you may not use this file except in compliance with the License.
|
|
3032
|
-
* You may obtain a copy of the License at
|
|
3033
|
-
*
|
|
3034
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3035
|
-
*
|
|
3036
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3037
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3038
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3039
|
-
* See the License for the specific language governing permissions and
|
|
3040
|
-
* limitations under the License.
|
|
3041
|
-
* =============================================================================
|
|
3042
|
-
*/
|
|
3043
|
-
function Qn(e, t) {
|
|
3044
|
-
let n = T(e, "a", "add"), s = T(t, "b", "add");
|
|
3045
|
-
[n, s] = K(n, s);
|
|
3046
|
-
const r = { a: n, b: s };
|
|
3047
|
-
return f.runKernel(oe, r);
|
|
3048
|
-
}
|
|
3049
|
-
const k = /* @__PURE__ */ F({ add_: Qn });
|
|
3050
|
-
/**
|
|
3051
|
-
* @license
|
|
3052
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3053
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3054
|
-
* you may not use this file except in compliance with the License.
|
|
3055
|
-
* You may obtain a copy of the License at
|
|
3056
|
-
*
|
|
3057
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3058
|
-
*
|
|
3059
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3060
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3061
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3062
|
-
* See the License for the specific language governing permissions and
|
|
3063
|
-
* limitations under the License.
|
|
3064
|
-
* =============================================================================
|
|
3065
|
-
*/
|
|
3066
|
-
function ts(e, t) {
|
|
3067
|
-
let n = T(e, "a", "floorDiv"), s = T(t, "b", "floorDiv");
|
|
3068
|
-
[n, s] = K(n, s);
|
|
3069
|
-
const r = { a: n, b: s };
|
|
3070
|
-
return f.runKernel(Ze, r);
|
|
3071
|
-
}
|
|
3072
|
-
const es = /* @__PURE__ */ F({ floorDiv_: ts });
|
|
3073
|
-
/**
|
|
3074
|
-
* @license
|
|
3075
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3076
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3077
|
-
* you may not use this file except in compliance with the License.
|
|
3078
|
-
* You may obtain a copy of the License at
|
|
3079
|
-
*
|
|
3080
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3081
|
-
*
|
|
3082
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3083
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3084
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3085
|
-
* See the License for the specific language governing permissions and
|
|
3086
|
-
* limitations under the License.
|
|
3087
|
-
* =============================================================================
|
|
3088
|
-
*/
|
|
3089
|
-
function ns(e, t) {
|
|
3090
|
-
let n = T(e, "a", "div"), s = T(t, "b", "div");
|
|
3091
|
-
if ([n, s] = K(n, s), n.dtype === "int32" && s.dtype === "int32")
|
|
3092
|
-
return es(n, s);
|
|
3093
|
-
const r = { a: n, b: s }, a = {};
|
|
3094
|
-
return f.runKernel(Je, r, a);
|
|
3095
|
-
}
|
|
3096
|
-
const $ = /* @__PURE__ */ F({ div_: ns });
|
|
3097
|
-
/**
|
|
3098
|
-
* @license
|
|
3099
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3100
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3101
|
-
* you may not use this file except in compliance with the License.
|
|
3102
|
-
* You may obtain a copy of the License at
|
|
3103
|
-
*
|
|
3104
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3105
|
-
*
|
|
3106
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3107
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3108
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3109
|
-
* See the License for the specific language governing permissions and
|
|
3110
|
-
* limitations under the License.
|
|
3111
|
-
* =============================================================================
|
|
3112
|
-
*/
|
|
3113
|
-
function ss(e, t) {
|
|
3114
|
-
let n = T(e, "a", "mul"), s = T(t, "b", "mul");
|
|
3115
|
-
[n, s] = K(n, s);
|
|
3116
|
-
const r = { a: n, b: s };
|
|
3117
|
-
return f.runKernel(tn, r);
|
|
3118
|
-
}
|
|
3119
|
-
const b = /* @__PURE__ */ F({ mul_: ss });
|
|
3120
|
-
/**
|
|
3121
|
-
* @license
|
|
3122
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3123
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3124
|
-
* you may not use this file except in compliance with the License.
|
|
3125
|
-
* You may obtain a copy of the License at
|
|
3126
|
-
*
|
|
3127
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3128
|
-
*
|
|
3129
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3130
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3131
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3132
|
-
* See the License for the specific language governing permissions and
|
|
3133
|
-
* limitations under the License.
|
|
3134
|
-
* =============================================================================
|
|
3135
|
-
*/
|
|
3136
|
-
function rs(e) {
|
|
3137
|
-
const t = T(e, "x", "abs");
|
|
3138
|
-
if (t.dtype === "complex64") {
|
|
3139
|
-
const n = { x: t };
|
|
3140
|
-
return f.runKernel(Xe, n);
|
|
3141
|
-
} else {
|
|
3142
|
-
const n = { x: t };
|
|
3143
|
-
return f.runKernel(He, n);
|
|
3144
|
-
}
|
|
3145
|
-
}
|
|
3146
|
-
const as = /* @__PURE__ */ F({ abs_: rs });
|
|
3147
|
-
/**
|
|
3148
|
-
* @license
|
|
3149
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3150
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3151
|
-
* you may not use this file except in compliance with the License.
|
|
3152
|
-
* You may obtain a copy of the License at
|
|
3153
|
-
*
|
|
3154
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3155
|
-
*
|
|
3156
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3157
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3158
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3159
|
-
* See the License for the specific language governing permissions and
|
|
3160
|
-
* limitations under the License.
|
|
3161
|
-
* =============================================================================
|
|
3162
|
-
*/
|
|
3163
|
-
function os(e, t, n) {
|
|
3164
|
-
Ct(e), n = n || yt(t);
|
|
3165
|
-
const s = { shape: e, value: t, dtype: n };
|
|
3166
|
-
return f.runKernel(Ye, {}, s);
|
|
3167
|
-
}
|
|
3168
|
-
/**
|
|
3169
|
-
* @license
|
|
3170
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
3171
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3172
|
-
* you may not use this file except in compliance with the License.
|
|
3173
|
-
* You may obtain a copy of the License at
|
|
3174
|
-
*
|
|
3175
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3176
|
-
*
|
|
3177
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3178
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3179
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3180
|
-
* See the License for the specific language governing permissions and
|
|
3181
|
-
* limitations under the License.
|
|
3182
|
-
* =============================================================================
|
|
3183
|
-
*/
|
|
3184
|
-
function pi(e, t) {
|
|
3185
|
-
const n = e.length, s = [];
|
|
3186
|
-
for (let r = 0; r < n; r++) {
|
|
3187
|
-
const a = n - 1 - r, o = e[a] || 1;
|
|
3188
|
-
(t[t.length - 1 - r] || 1) > 1 && o === 1 && s.unshift(a);
|
|
3189
|
-
}
|
|
3190
|
-
return s;
|
|
3191
|
-
}
|
|
3192
|
-
function yi(e, t) {
|
|
3193
|
-
const n = [];
|
|
3194
|
-
for (let s = 0; s < t.length; s++) {
|
|
3195
|
-
const r = e[e.length - s - 1], a = t.length - s - 1, o = t[a];
|
|
3196
|
-
(r == null || r === 1 && o > 1) && n.unshift(a);
|
|
3197
|
-
}
|
|
3198
|
-
return n;
|
|
3199
|
-
}
|
|
3200
|
-
function is(e, t) {
|
|
3201
|
-
const n = Math.max(e.length, t.length), s = new Array(n);
|
|
3202
|
-
for (let r = 0; r < n; r++) {
|
|
3203
|
-
let a = e[e.length - r - 1];
|
|
3204
|
-
a == null && (a = 1);
|
|
3205
|
-
let o = t[t.length - r - 1];
|
|
3206
|
-
if (o == null && (o = 1), a === 1)
|
|
3207
|
-
s[n - r - 1] = o;
|
|
3208
|
-
else if (o === 1)
|
|
3209
|
-
s[n - r - 1] = a;
|
|
3210
|
-
else if (a !== o) {
|
|
3211
|
-
const i = `Operands could not be broadcast together with shapes ${e} and ${t}.`;
|
|
3212
|
-
throw Error(i);
|
|
3213
|
-
} else
|
|
3214
|
-
s[n - r - 1] = a;
|
|
3215
|
-
}
|
|
3216
|
-
return s;
|
|
3217
|
-
}
|
|
3218
|
-
/**
|
|
3219
|
-
* @license
|
|
3220
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3221
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3222
|
-
* you may not use this file except in compliance with the License.
|
|
3223
|
-
* You may obtain a copy of the License at
|
|
3224
|
-
*
|
|
3225
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3226
|
-
*
|
|
3227
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3228
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3229
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3230
|
-
* See the License for the specific language governing permissions and
|
|
3231
|
-
* limitations under the License.
|
|
3232
|
-
* =============================================================================
|
|
3233
|
-
*/
|
|
3234
|
-
function cs(e) {
|
|
3235
|
-
const n = { x: T(e, "x", "zerosLike") };
|
|
3236
|
-
return f.runKernel(rn, n);
|
|
3237
|
-
}
|
|
3238
|
-
const C = /* @__PURE__ */ F({ zerosLike_: cs });
|
|
3239
|
-
/**
|
|
3240
|
-
* @license
|
|
3241
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3242
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3243
|
-
* you may not use this file except in compliance with the License.
|
|
3244
|
-
* You may obtain a copy of the License at
|
|
3245
|
-
*
|
|
3246
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3247
|
-
*
|
|
3248
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3249
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3250
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3251
|
-
* See the License for the specific language governing permissions and
|
|
3252
|
-
* limitations under the License.
|
|
3253
|
-
* =============================================================================
|
|
3254
|
-
*/
|
|
3255
|
-
function ls(e, t) {
|
|
3256
|
-
let n = T(e, "base", "pow"), s = T(t, "exp", "pow");
|
|
3257
|
-
[n, s] = K(n, s);
|
|
3258
|
-
const r = { a: n, b: s };
|
|
3259
|
-
return f.runKernel(en, r);
|
|
3260
|
-
}
|
|
3261
|
-
const Qt = /* @__PURE__ */ F({ pow_: ls });
|
|
3262
|
-
/**
|
|
3263
|
-
* @license
|
|
3264
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3265
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3266
|
-
* you may not use this file except in compliance with the License.
|
|
3267
|
-
* You may obtain a copy of the License at
|
|
3268
|
-
*
|
|
3269
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3270
|
-
*
|
|
3271
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3272
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3273
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3274
|
-
* See the License for the specific language governing permissions and
|
|
3275
|
-
* limitations under the License.
|
|
3276
|
-
* =============================================================================
|
|
3277
|
-
*/
|
|
3278
|
-
function q(e, t) {
|
|
3279
|
-
if ((R(e) && t !== "string" || Array.isArray(e)) && t !== "complex64")
|
|
3280
|
-
throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");
|
|
3281
|
-
if (t === "string" && R(e) && !(e instanceof Uint8Array))
|
|
3282
|
-
throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");
|
|
3283
|
-
return vn(e, [], [], t);
|
|
3284
|
-
}
|
|
3285
|
-
/**
|
|
3286
|
-
* @license
|
|
3287
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3288
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3289
|
-
* you may not use this file except in compliance with the License.
|
|
3290
|
-
* You may obtain a copy of the License at
|
|
3291
|
-
*
|
|
3292
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3293
|
-
*
|
|
3294
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3295
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3296
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3297
|
-
* See the License for the specific language governing permissions and
|
|
3298
|
-
* limitations under the License.
|
|
3299
|
-
* =============================================================================
|
|
3300
|
-
*/
|
|
3301
|
-
function us(e) {
|
|
3302
|
-
const n = { x: T(e, "x", "sqrt", "float32") };
|
|
3303
|
-
return f.runKernel(nn, n);
|
|
3304
|
-
}
|
|
3305
|
-
const nt = /* @__PURE__ */ F({ sqrt_: us });
|
|
3306
|
-
/**
|
|
3307
|
-
* @license
|
|
3308
|
-
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
3309
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3310
|
-
* you may not use this file except in compliance with the License.
|
|
3311
|
-
* You may obtain a copy of the License at
|
|
3312
|
-
*
|
|
3313
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3314
|
-
*
|
|
3315
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3316
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3317
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3318
|
-
* See the License for the specific language governing permissions and
|
|
3319
|
-
* limitations under the License.
|
|
3320
|
-
* =============================================================================
|
|
3321
|
-
*/
|
|
3322
|
-
function hs(e) {
|
|
3323
|
-
const t = T(e, "x", "square"), n = {};
|
|
3324
|
-
return f.runKernel("Square", { x: t }, n);
|
|
3325
|
-
}
|
|
3326
|
-
const V = /* @__PURE__ */ F({ square_: hs });
|
|
3327
|
-
/**
|
|
3328
|
-
* @license
|
|
3329
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3330
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3331
|
-
* you may not use this file except in compliance with the License.
|
|
3332
|
-
* You may obtain a copy of the License at
|
|
3333
|
-
*
|
|
3334
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3335
|
-
*
|
|
3336
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3337
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3338
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3339
|
-
* See the License for the specific language governing permissions and
|
|
3340
|
-
* limitations under the License.
|
|
3341
|
-
* =============================================================================
|
|
3342
|
-
*/
|
|
3343
|
-
function bi(e) {
|
|
3344
|
-
return p(lt(e), () => "The f passed in grads(f) must be a function"), (t, n) => {
|
|
3345
|
-
p(Array.isArray(t), () => "The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s");
|
|
3346
|
-
const s = An(t, "args", "tf.grads", "string_or_numeric"), r = n != null ? T(n, "dy", "tf.grads") : null;
|
|
3347
|
-
return f.tidy(() => {
|
|
3348
|
-
const { value: a, grads: o } = f.gradients(() => e(...s), s, r);
|
|
3349
|
-
return r != null && te(a.shape, r.shape, "The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), Me(o), o;
|
|
3350
|
-
});
|
|
3351
|
-
};
|
|
3352
|
-
}
|
|
3353
|
-
function wi(e) {
|
|
3354
|
-
return p(lt(e), () => "The f passed in valueAndGrads(f) must be a function"), (t, n) => {
|
|
3355
|
-
p(Array.isArray(t) && t.every((r) => r instanceof M), () => "The args passed in valueAndGrads(f)(args) must be array of tensors"), p(n == null || n instanceof M, () => "The dy passed in valueAndGrads(f)(args, dy) must be a tensor");
|
|
3356
|
-
const s = f.gradients(() => e(...t), t, n);
|
|
3357
|
-
return n != null && te(s.value.shape, n.shape, "The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"), Me(s.grads), s;
|
|
3358
|
-
};
|
|
3359
|
-
}
|
|
3360
|
-
function ds(e, t) {
|
|
3361
|
-
p(lt(e), () => "The f passed in variableGrads(f) must be a function"), p(t == null || Array.isArray(t) && t.every((l) => l instanceof mt), () => "The varList passed in variableGrads(f, varList) must be an array of variables");
|
|
3362
|
-
const n = t != null;
|
|
3363
|
-
if (!n) {
|
|
3364
|
-
t = [];
|
|
3365
|
-
for (const l in f.registeredVariables)
|
|
3366
|
-
t.push(f.registeredVariables[l]);
|
|
3367
|
-
}
|
|
3368
|
-
const s = n ? t.filter((l) => !l.trainable) : null, r = t.length;
|
|
3369
|
-
t = t.filter((l) => l.trainable), p(t.length > 0, () => `variableGrads() expects at least one of the input variables to be trainable, but none of the ${r} variables is trainable.`);
|
|
3370
|
-
const a = !0, { value: o, grads: i } = f.gradients(e, t, null, a);
|
|
3371
|
-
p(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()."), p(o.rank === 0, () => `The f passed in variableGrads(f) must return a scalar, but it returned a rank-${o.rank} tensor`);
|
|
3372
|
-
const c = {};
|
|
3373
|
-
return t.forEach((l, u) => {
|
|
3374
|
-
i[u] != null && (c[l.name] = i[u]);
|
|
3375
|
-
}), s?.forEach((l) => c[l.name] = null), { value: o, grads: c };
|
|
3376
|
-
}
|
|
3377
|
-
function Si(e) {
|
|
3378
|
-
return f.customGrad(e);
|
|
3379
|
-
}
|
|
3380
|
-
function Me(e) {
|
|
3381
|
-
if (e.filter((n) => n == null).length > 0)
|
|
3382
|
-
throw new Error(`Cannot compute gradient of y=f(x) with respect to x. Make sure that
|
|
3383
|
-
the f you passed encloses all operations that lead from x to y.`);
|
|
3384
|
-
}
|
|
3385
|
-
/**
|
|
3386
|
-
* @license
|
|
3387
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3388
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3389
|
-
* you may not use this file except in compliance with the License.
|
|
3390
|
-
* You may obtain a copy of the License at
|
|
3391
|
-
*
|
|
3392
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3393
|
-
*
|
|
3394
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3395
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3396
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3397
|
-
* See the License for the specific language governing permissions and
|
|
3398
|
-
* limitations under the License.
|
|
3399
|
-
* =============================================================================
|
|
3400
|
-
*/
|
|
3401
|
-
function fs(e, t) {
|
|
3402
|
-
let n = T(e, "a", "sub"), s = T(t, "b", "sub");
|
|
3403
|
-
[n, s] = K(n, s);
|
|
3404
|
-
const r = { a: n, b: s };
|
|
3405
|
-
return f.runKernel(sn, r);
|
|
3406
|
-
}
|
|
3407
|
-
const tt = /* @__PURE__ */ F({ sub_: fs });
|
|
3408
|
-
/**
|
|
3409
|
-
* @license
|
|
3410
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3411
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3412
|
-
* you may not use this file except in compliance with the License.
|
|
3413
|
-
* You may obtain a copy of the License at
|
|
3414
|
-
*
|
|
3415
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3416
|
-
*
|
|
3417
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3418
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3419
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3420
|
-
* See the License for the specific language governing permissions and
|
|
3421
|
-
* limitations under the License.
|
|
3422
|
-
* =============================================================================
|
|
3423
|
-
*/
|
|
3424
|
-
function gs(e, t) {
|
|
3425
|
-
let n = T(e, "a", "maximum"), s = T(t, "b", "maximum");
|
|
3426
|
-
[n, s] = K(n, s), n.dtype === "bool" && (n = Rt(n, "int32"), s = Rt(s, "int32")), is(n.shape, s.shape);
|
|
3427
|
-
const r = { a: n, b: s };
|
|
3428
|
-
return f.runKernel(Qe, r);
|
|
3429
|
-
}
|
|
3430
|
-
const ms = /* @__PURE__ */ F({ maximum_: gs });
|
|
3431
|
-
/**
|
|
3432
|
-
* @license
|
|
3433
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3434
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3435
|
-
* you may not use this file except in compliance with the License.
|
|
3436
|
-
* You may obtain a copy of the License at
|
|
3437
|
-
*
|
|
3438
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3439
|
-
*
|
|
3440
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3441
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3442
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3443
|
-
* See the License for the specific language governing permissions and
|
|
3444
|
-
* limitations under the License.
|
|
3445
|
-
* =============================================================================
|
|
3446
|
-
*/
|
|
3447
|
-
const ps = /* @__PURE__ */ new Map(), ys = /* @__PURE__ */ new Map();
|
|
3448
|
-
class bs {
|
|
3449
|
-
/**
|
|
3450
|
-
* Return the class name for this class to use in serialization contexts.
|
|
3451
|
-
*
|
|
3452
|
-
* Generally speaking this will be the same thing that constructor.name
|
|
3453
|
-
* would have returned. However, the class name needs to be robust
|
|
3454
|
-
* against minification for serialization/deserialization to work properly.
|
|
3455
|
-
*
|
|
3456
|
-
* There's also places such as initializers.VarianceScaling, where
|
|
3457
|
-
* implementation details between different languages led to different
|
|
3458
|
-
* class hierarchies and a non-leaf node is used for serialization purposes.
|
|
3459
|
-
*/
|
|
3460
|
-
getClassName() {
|
|
3461
|
-
return this.constructor.className;
|
|
3462
|
-
}
|
|
3463
|
-
/**
|
|
3464
|
-
* Creates an instance of T from a ConfigDict.
|
|
3465
|
-
*
|
|
3466
|
-
* This works for most descendants of serializable. A few need to
|
|
3467
|
-
* provide special handling.
|
|
3468
|
-
* @param cls A Constructor for the class to instantiate.
|
|
3469
|
-
* @param config The Configuration for the object.
|
|
3470
|
-
*/
|
|
3471
|
-
/** @nocollapse */
|
|
3472
|
-
static fromConfig(t, n) {
|
|
3473
|
-
return new t(n);
|
|
3474
|
-
}
|
|
3475
|
-
}
|
|
3476
|
-
class G {
|
|
3477
|
-
constructor() {
|
|
3478
|
-
this.classNameMap = {};
|
|
3479
|
-
}
|
|
3480
|
-
/**
|
|
3481
|
-
* Returns the singleton instance of the map.
|
|
3482
|
-
*/
|
|
3483
|
-
static getMap() {
|
|
3484
|
-
return G.instance == null && (G.instance = new G()), G.instance;
|
|
3485
|
-
}
|
|
3486
|
-
/**
|
|
3487
|
-
* Registers the class as serializable.
|
|
3488
|
-
*/
|
|
3489
|
-
static register(t) {
|
|
3490
|
-
G.getMap().classNameMap[t.className] = [t, t.fromConfig];
|
|
3491
|
-
}
|
|
3492
|
-
}
|
|
3493
|
-
function ws(e, t, n) {
|
|
3494
|
-
p(e.className != null, () => "Class being registered does not have the static className property defined."), p(typeof e.className == "string", () => "className is required to be a string, but got type " + typeof e.className), p(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);
|
|
3495
|
-
const s = n, r = t + ">" + s;
|
|
3496
|
-
return G.register(e), ps.set(r, e), ys.set(e, r), e;
|
|
3497
|
-
}
|
|
3498
|
-
/**
|
|
3499
|
-
* @license
|
|
3500
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3501
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3502
|
-
* you may not use this file except in compliance with the License.
|
|
3503
|
-
* You may obtain a copy of the License at
|
|
3504
|
-
*
|
|
3505
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3506
|
-
*
|
|
3507
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3508
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3509
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3510
|
-
* See the License for the specific language governing permissions and
|
|
3511
|
-
* limitations under the License.
|
|
3512
|
-
* =============================================================================
|
|
3513
|
-
*/
|
|
3514
|
-
class H extends bs {
|
|
3515
|
-
/**
|
|
3516
|
-
* Executes `f()` and minimizes the scalar output of `f()` by computing
|
|
3517
|
-
* gradients of y with respect to the list of trainable variables provided by
|
|
3518
|
-
* `varList`. If no list is provided, it defaults to all trainable variables.
|
|
3519
|
-
*
|
|
3520
|
-
* @param f The function to execute and whose output to minimize.
|
|
3521
|
-
* @param returnCost Whether to return the scalar cost value produced by
|
|
3522
|
-
* executing `f()`.
|
|
3523
|
-
* @param varList An optional list of variables to update. If specified, only
|
|
3524
|
-
* the trainable variables in varList will be updated by minimize. Defaults to
|
|
3525
|
-
* all trainable variables.
|
|
3526
|
-
*
|
|
3527
|
-
* @doc {heading: 'Training', subheading: 'Optimizers'}
|
|
3528
|
-
*/
|
|
3529
|
-
minimize(t, n = !1, s) {
|
|
3530
|
-
const { value: r, grads: a } = this.computeGradients(t, s);
|
|
3531
|
-
if (s != null) {
|
|
3532
|
-
const o = s.map((i) => ({ name: i.name, tensor: a[i.name] }));
|
|
3533
|
-
this.applyGradients(o);
|
|
3534
|
-
} else
|
|
3535
|
-
this.applyGradients(a);
|
|
3536
|
-
return D(a), n ? r : (r.dispose(), null);
|
|
3537
|
-
}
|
|
3538
|
-
/**
|
|
3539
|
-
* The number of iterations that this optimizer instance has been invoked for.
|
|
3540
|
-
*/
|
|
3541
|
-
get iterations() {
|
|
3542
|
-
return this.iterations_ == null && (this.iterations_ = 0), this.iterations_;
|
|
3543
|
-
}
|
|
3544
|
-
incrementIterations() {
|
|
3545
|
-
this.iterations_ = this.iterations + 1;
|
|
3546
|
-
}
|
|
3547
|
-
/**
|
|
3548
|
-
* Executes f() and computes the gradient of the scalar output of f() with
|
|
3549
|
-
* respect to the list of trainable variables provided by `varList`. If no
|
|
3550
|
-
* list is provided, it defaults to all trainable variables.
|
|
3551
|
-
*
|
|
3552
|
-
* @param f The function to execute and whose output to use for computing
|
|
3553
|
-
* gradients with respect to variables.
|
|
3554
|
-
* @param varList An optional list of variables to compute gradients with
|
|
3555
|
-
* respect to. If specified, only the trainable variables in varList will have
|
|
3556
|
-
* gradients computed with respect to. Defaults to all trainable variables.
|
|
3557
|
-
*
|
|
3558
|
-
* @doc {heading: 'Training', subheading: 'Optimizers'}
|
|
3559
|
-
*/
|
|
3560
|
-
computeGradients(t, n) {
|
|
3561
|
-
return ds(t, n);
|
|
3562
|
-
}
|
|
3563
|
-
/**
|
|
3564
|
-
* Dispose the variables (if any) owned by this optimizer instance.
|
|
3565
|
-
*/
|
|
3566
|
-
dispose() {
|
|
3567
|
-
this.iterations_ != null && D(this.iterations_);
|
|
3568
|
-
}
|
|
3569
|
-
async saveIterations() {
|
|
3570
|
-
return this.iterations_ == null && (this.iterations_ = 0), {
|
|
3571
|
-
name: "iter",
|
|
3572
|
-
// TODO(cais): Use 'int64' type when available.
|
|
3573
|
-
tensor: q(this.iterations_, "int32")
|
|
3574
|
-
};
|
|
3575
|
-
}
|
|
3576
|
-
async getWeights() {
|
|
3577
|
-
throw new Error("getWeights() is not implemented for this optimizer yet.");
|
|
3578
|
-
}
|
|
3579
|
-
async setWeights(t) {
|
|
3580
|
-
throw new Error(`setWeights() is not implemented for this optimizer class ${this.getClassName()}`);
|
|
3581
|
-
}
|
|
3582
|
-
/**
|
|
3583
|
-
* Extract the first element of the weight values and set it
|
|
3584
|
-
* as the iterations counter variable of this instance of optimizer.
|
|
3585
|
-
*
|
|
3586
|
-
* @param weightValues
|
|
3587
|
-
* @returns Weight values with the first element consumed and excluded.
|
|
3588
|
-
*/
|
|
3589
|
-
async extractIterations(t) {
|
|
3590
|
-
return this.iterations_ = (await t[0].tensor.data())[0], t.slice(1);
|
|
3591
|
-
}
|
|
3592
|
-
}
|
|
3593
|
-
Object.defineProperty(H, Symbol.hasInstance, {
|
|
3594
|
-
value: (e) => e.minimize != null && e.computeGradients != null && e.applyGradients != null
|
|
3595
|
-
});
|
|
3596
|
-
/**
|
|
3597
|
-
* @license
|
|
3598
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3599
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3600
|
-
* you may not use this file except in compliance with the License.
|
|
3601
|
-
* You may obtain a copy of the License at
|
|
3602
|
-
*
|
|
3603
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3604
|
-
*
|
|
3605
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3606
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3607
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3608
|
-
* See the License for the specific language governing permissions and
|
|
3609
|
-
* limitations under the License.
|
|
3610
|
-
* =============================================================================
|
|
3611
|
-
*/
|
|
3612
|
-
class Ss extends H {
|
|
3613
|
-
/** @nocollapse */
|
|
3614
|
-
static get className() {
|
|
3615
|
-
return "Adadelta";
|
|
3616
|
-
}
|
|
3617
|
-
constructor(t, n, s = null) {
|
|
3618
|
-
super(), this.learningRate = t, this.rho = n, this.epsilon = s, this.accumulatedGrads = [], this.accumulatedUpdates = [], s == null && (this.epsilon = f.backend.epsilon());
|
|
3619
|
-
}
|
|
3620
|
-
applyGradients(t) {
|
|
3621
|
-
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
3622
|
-
const a = f.registeredVariables[s], o = !1;
|
|
3623
|
-
this.accumulatedGrads[r] == null && (this.accumulatedGrads[r] = {
|
|
3624
|
-
originalName: `${s}/accum_grad`,
|
|
3625
|
-
variable: A(() => C(a).variable(o))
|
|
3626
|
-
}), this.accumulatedUpdates[r] == null && (this.accumulatedUpdates[r] = {
|
|
3627
|
-
originalName: `${s}/accum_var`,
|
|
3628
|
-
variable: A(() => C(a).variable(o))
|
|
3629
|
-
});
|
|
3630
|
-
const i = Array.isArray(t) ? t[r].tensor : t[s];
|
|
3631
|
-
if (i == null)
|
|
3632
|
-
return;
|
|
3633
|
-
const c = this.accumulatedGrads[r].variable, l = this.accumulatedUpdates[r].variable;
|
|
3634
|
-
A(() => {
|
|
3635
|
-
const u = k(b(c, this.rho), b(V(i), 1 - this.rho)), h = b($(nt(k(l, this.epsilon)), nt(k(c, this.epsilon))), i), d = k(b(l, this.rho), b(V(h), 1 - this.rho));
|
|
3636
|
-
c.assign(u), l.assign(d);
|
|
3637
|
-
const m = k(b(h, -this.learningRate), a);
|
|
3638
|
-
a.assign(m);
|
|
3639
|
-
});
|
|
3640
|
-
}), this.incrementIterations();
|
|
3641
|
-
}
|
|
3642
|
-
dispose() {
|
|
3643
|
-
this.accumulatedUpdates != null && (D(this.accumulatedGrads.map((t) => t.variable)), D(this.accumulatedUpdates.map((t) => t.variable)));
|
|
3644
|
-
}
|
|
3645
|
-
async getWeights() {
|
|
3646
|
-
const t = [...this.accumulatedGrads, ...this.accumulatedUpdates];
|
|
3647
|
-
return [await this.saveIterations()].concat(t.map((n) => ({ name: n.originalName, tensor: n.variable })));
|
|
3648
|
-
}
|
|
3649
|
-
async setWeights(t) {
|
|
3650
|
-
t = await this.extractIterations(t);
|
|
3651
|
-
const n = t.length / 2, s = !1;
|
|
3652
|
-
this.accumulatedGrads = t.slice(0, n).map((r) => ({
|
|
3653
|
-
originalName: r.name,
|
|
3654
|
-
variable: r.tensor.variable(s)
|
|
3655
|
-
})), this.accumulatedUpdates = t.slice(n, n * 2).map((r) => ({
|
|
3656
|
-
originalName: r.name,
|
|
3657
|
-
variable: r.tensor.variable(s)
|
|
3658
|
-
}));
|
|
3659
|
-
}
|
|
3660
|
-
getConfig() {
|
|
3661
|
-
return {
|
|
3662
|
-
learningRate: this.learningRate,
|
|
3663
|
-
rho: this.rho,
|
|
3664
|
-
epsilon: this.epsilon
|
|
3665
|
-
};
|
|
3666
|
-
}
|
|
3667
|
-
/** @nocollapse */
|
|
3668
|
-
static fromConfig(t, n) {
|
|
3669
|
-
return new t(n.learningRate, n.rho, n.epsilon);
|
|
3670
|
-
}
|
|
3671
|
-
}
|
|
3672
|
-
/**
|
|
3673
|
-
* @license
|
|
3674
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3675
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3676
|
-
* you may not use this file except in compliance with the License.
|
|
3677
|
-
* You may obtain a copy of the License at
|
|
3678
|
-
*
|
|
3679
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3680
|
-
*
|
|
3681
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3682
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3683
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3684
|
-
* See the License for the specific language governing permissions and
|
|
3685
|
-
* limitations under the License.
|
|
3686
|
-
* =============================================================================
|
|
3687
|
-
*/
|
|
3688
|
-
class ks extends H {
|
|
3689
|
-
/** @nocollapse */
|
|
3690
|
-
static get className() {
|
|
3691
|
-
return "Adagrad";
|
|
3692
|
-
}
|
|
3693
|
-
constructor(t, n = 0.1) {
|
|
3694
|
-
super(), this.learningRate = t, this.initialAccumulatorValue = n, this.accumulatedGrads = [];
|
|
3695
|
-
}
|
|
3696
|
-
applyGradients(t) {
|
|
3697
|
-
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
3698
|
-
const a = f.registeredVariables[s];
|
|
3699
|
-
this.accumulatedGrads[r] == null && (this.accumulatedGrads[r] = {
|
|
3700
|
-
originalName: `${s}/accumulator`,
|
|
3701
|
-
variable: A(() => os(a.shape, this.initialAccumulatorValue).variable(!1))
|
|
3702
|
-
});
|
|
3703
|
-
const o = Array.isArray(t) ? t[r].tensor : t[s];
|
|
3704
|
-
if (o == null)
|
|
3705
|
-
return;
|
|
3706
|
-
const i = this.accumulatedGrads[r].variable;
|
|
3707
|
-
A(() => {
|
|
3708
|
-
const c = k(i, V(o));
|
|
3709
|
-
i.assign(c);
|
|
3710
|
-
const l = k(b($(o, nt(k(c, f.backend.epsilon()))), -this.learningRate), a);
|
|
3711
|
-
a.assign(l);
|
|
3712
|
-
});
|
|
3713
|
-
}), this.incrementIterations();
|
|
3714
|
-
}
|
|
3715
|
-
dispose() {
|
|
3716
|
-
this.accumulatedGrads != null && D(this.accumulatedGrads.map((t) => t.variable));
|
|
3717
|
-
}
|
|
3718
|
-
async getWeights() {
|
|
3719
|
-
return [await this.saveIterations()].concat(this.accumulatedGrads.map((t) => ({ name: t.originalName, tensor: t.variable })));
|
|
3720
|
-
}
|
|
3721
|
-
async setWeights(t) {
|
|
3722
|
-
t = await this.extractIterations(t);
|
|
3723
|
-
const n = !1;
|
|
3724
|
-
this.accumulatedGrads = t.map((s) => ({ originalName: s.name, variable: s.tensor.variable(n) }));
|
|
3725
|
-
}
|
|
3726
|
-
getConfig() {
|
|
3727
|
-
return {
|
|
3728
|
-
learningRate: this.learningRate,
|
|
3729
|
-
initialAccumulatorValue: this.initialAccumulatorValue
|
|
3730
|
-
};
|
|
3731
|
-
}
|
|
3732
|
-
/** @nocollapse */
|
|
3733
|
-
static fromConfig(t, n) {
|
|
3734
|
-
return new t(n.learningRate, n.initialAccumulatorValue);
|
|
3735
|
-
}
|
|
3736
|
-
}
|
|
3737
|
-
/**
|
|
3738
|
-
* @license
|
|
3739
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3740
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3741
|
-
* you may not use this file except in compliance with the License.
|
|
3742
|
-
* You may obtain a copy of the License at
|
|
3743
|
-
*
|
|
3744
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3745
|
-
*
|
|
3746
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3747
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3748
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3749
|
-
* See the License for the specific language governing permissions and
|
|
3750
|
-
* limitations under the License.
|
|
3751
|
-
* =============================================================================
|
|
3752
|
-
*/
|
|
3753
|
-
class Is extends H {
|
|
3754
|
-
/** @nocollapse */
|
|
3755
|
-
static get className() {
|
|
3756
|
-
return "Adam";
|
|
3757
|
-
}
|
|
3758
|
-
constructor(t, n, s, r = null) {
|
|
3759
|
-
super(), this.learningRate = t, this.beta1 = n, this.beta2 = s, this.epsilon = r, this.accumulatedFirstMoment = [], this.accumulatedSecondMoment = [], A(() => {
|
|
3760
|
-
this.accBeta1 = q(n).variable(), this.accBeta2 = q(s).variable();
|
|
3761
|
-
}), r == null && (this.epsilon = f.backend.epsilon());
|
|
3762
|
-
}
|
|
3763
|
-
applyGradients(t) {
|
|
3764
|
-
const n = Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t);
|
|
3765
|
-
A(() => {
|
|
3766
|
-
const s = tt(1, this.accBeta1), r = tt(1, this.accBeta2);
|
|
3767
|
-
n.forEach((a, o) => {
|
|
3768
|
-
const i = f.registeredVariables[a], c = !1;
|
|
3769
|
-
this.accumulatedFirstMoment[o] == null && (this.accumulatedFirstMoment[o] = {
|
|
3770
|
-
originalName: `${a}/m`,
|
|
3771
|
-
variable: A(() => C(i).variable(c))
|
|
3772
|
-
}), this.accumulatedSecondMoment[o] == null && (this.accumulatedSecondMoment[o] = {
|
|
3773
|
-
originalName: `${a}/v`,
|
|
3774
|
-
variable: A(() => C(i).variable(c))
|
|
3775
|
-
});
|
|
3776
|
-
const l = Array.isArray(t) ? t[o].tensor : t[a];
|
|
3777
|
-
if (l == null)
|
|
3778
|
-
return;
|
|
3779
|
-
const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedSecondMoment[o].variable, d = k(b(u, this.beta1), b(l, 1 - this.beta1)), m = k(b(h, this.beta2), b(V(l), 1 - this.beta2)), y = $(d, s), g = $(m, r);
|
|
3780
|
-
u.assign(d), h.assign(m);
|
|
3781
|
-
const w = k(b($(y, k(nt(g), this.epsilon)), -this.learningRate), i);
|
|
3782
|
-
i.assign(w);
|
|
3783
|
-
}), this.accBeta1.assign(b(this.accBeta1, this.beta1)), this.accBeta2.assign(b(this.accBeta2, this.beta2));
|
|
3784
|
-
}), this.incrementIterations();
|
|
3785
|
-
}
|
|
3786
|
-
dispose() {
|
|
3787
|
-
this.accBeta1.dispose(), this.accBeta2.dispose(), this.accumulatedFirstMoment != null && D(this.accumulatedFirstMoment.map((t) => t.variable)), this.accumulatedSecondMoment != null && D(this.accumulatedSecondMoment.map((t) => t.variable));
|
|
3788
|
-
}
|
|
3789
|
-
async getWeights() {
|
|
3790
|
-
const t = [...this.accumulatedFirstMoment, ...this.accumulatedSecondMoment];
|
|
3791
|
-
return [await this.saveIterations()].concat(t.map((n) => ({ name: n.originalName, tensor: n.variable })));
|
|
3792
|
-
}
|
|
3793
|
-
async setWeights(t) {
|
|
3794
|
-
t = await this.extractIterations(t), A(() => {
|
|
3795
|
-
this.accBeta1.assign(Qt(this.beta1, this.iterations_ + 1)), this.accBeta2.assign(Qt(this.beta2, this.iterations_ + 1));
|
|
3796
|
-
});
|
|
3797
|
-
const n = t.length / 2, s = !1;
|
|
3798
|
-
this.accumulatedFirstMoment = t.slice(0, n).map((r) => ({
|
|
3799
|
-
originalName: r.name,
|
|
3800
|
-
variable: r.tensor.variable(s)
|
|
3801
|
-
})), this.accumulatedSecondMoment = t.slice(n, n * 2).map((r) => ({
|
|
3802
|
-
originalName: r.name,
|
|
3803
|
-
variable: r.tensor.variable(s)
|
|
3804
|
-
}));
|
|
3805
|
-
}
|
|
3806
|
-
getConfig() {
|
|
3807
|
-
return {
|
|
3808
|
-
learningRate: this.learningRate,
|
|
3809
|
-
beta1: this.beta1,
|
|
3810
|
-
beta2: this.beta2,
|
|
3811
|
-
epsilon: this.epsilon
|
|
3812
|
-
};
|
|
3813
|
-
}
|
|
3814
|
-
/** @nocollapse */
|
|
3815
|
-
static fromConfig(t, n) {
|
|
3816
|
-
return new t(n.learningRate, n.beta1, n.beta2, n.epsilon);
|
|
3817
|
-
}
|
|
3818
|
-
}
|
|
3819
|
-
/**
|
|
3820
|
-
* @license
|
|
3821
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3822
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3823
|
-
* you may not use this file except in compliance with the License.
|
|
3824
|
-
* You may obtain a copy of the License at
|
|
3825
|
-
*
|
|
3826
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3827
|
-
*
|
|
3828
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3829
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3830
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3831
|
-
* See the License for the specific language governing permissions and
|
|
3832
|
-
* limitations under the License.
|
|
3833
|
-
* =============================================================================
|
|
3834
|
-
*/
|
|
3835
|
-
class Ts extends H {
|
|
3836
|
-
/** @nocollapse */
|
|
3837
|
-
static get className() {
|
|
3838
|
-
return "Adamax";
|
|
3839
|
-
}
|
|
3840
|
-
constructor(t, n, s, r = null, a = 0) {
|
|
3841
|
-
super(), this.learningRate = t, this.beta1 = n, this.beta2 = s, this.epsilon = r, this.decay = a, this.accumulatedFirstMoment = [], this.accumulatedWeightedInfNorm = [], A(() => {
|
|
3842
|
-
this.iteration = q(0).variable(), this.accBeta1 = q(n).variable();
|
|
3843
|
-
}), r == null && (this.epsilon = f.backend.epsilon());
|
|
3844
|
-
}
|
|
3845
|
-
applyGradients(t) {
|
|
3846
|
-
const n = Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t);
|
|
3847
|
-
A(() => {
|
|
3848
|
-
const s = tt(1, this.accBeta1), r = $(-this.learningRate, k(b(this.iteration, this.decay), 1));
|
|
3849
|
-
n.forEach((a, o) => {
|
|
3850
|
-
const i = f.registeredVariables[a], c = !1;
|
|
3851
|
-
this.accumulatedFirstMoment[o] == null && (this.accumulatedFirstMoment[o] = {
|
|
3852
|
-
originalName: `${a}/m`,
|
|
3853
|
-
variable: C(i).variable(c)
|
|
3854
|
-
}), this.accumulatedWeightedInfNorm[o] == null && (this.accumulatedWeightedInfNorm[o] = {
|
|
3855
|
-
originalName: `${a}/v`,
|
|
3856
|
-
variable: C(i).variable(c)
|
|
3857
|
-
});
|
|
3858
|
-
const l = Array.isArray(t) ? t[o].tensor : t[a];
|
|
3859
|
-
if (l == null)
|
|
3860
|
-
return;
|
|
3861
|
-
const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedWeightedInfNorm[o].variable, d = k(b(u, this.beta1), b(l, 1 - this.beta1)), m = b(h, this.beta2), y = as(l), g = ms(m, y);
|
|
3862
|
-
u.assign(d), h.assign(g);
|
|
3863
|
-
const w = k(b($(r, s), $(d, k(g, this.epsilon))), i);
|
|
3864
|
-
i.assign(w);
|
|
3865
|
-
}), this.iteration.assign(k(this.iteration, 1)), this.accBeta1.assign(b(this.accBeta1, this.beta1));
|
|
3866
|
-
}), this.incrementIterations();
|
|
3867
|
-
}
|
|
3868
|
-
dispose() {
|
|
3869
|
-
this.accBeta1.dispose(), this.iteration.dispose(), this.accumulatedFirstMoment != null && D(this.accumulatedFirstMoment.map((t) => t.variable)), this.accumulatedWeightedInfNorm != null && D(this.accumulatedWeightedInfNorm.map((t) => t.variable));
|
|
3870
|
-
}
|
|
3871
|
-
async getWeights() {
|
|
3872
|
-
throw new Error("getWeights() is not implemented for Adamax yet.");
|
|
3873
|
-
}
|
|
3874
|
-
async setWeights(t) {
|
|
3875
|
-
throw new Error("setWeights() is not implemented for Adamax yet.");
|
|
3876
|
-
}
|
|
3877
|
-
getConfig() {
|
|
3878
|
-
return {
|
|
3879
|
-
learningRate: this.learningRate,
|
|
3880
|
-
beta1: this.beta1,
|
|
3881
|
-
beta2: this.beta2,
|
|
3882
|
-
epsilon: this.epsilon,
|
|
3883
|
-
decay: this.decay
|
|
3884
|
-
};
|
|
3885
|
-
}
|
|
3886
|
-
/** @nocollapse */
|
|
3887
|
-
static fromConfig(t, n) {
|
|
3888
|
-
return new t(n.learningRate, n.beta1, n.beta2, n.epsilon, n.decay);
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
/**
|
|
3892
|
-
* @license
|
|
3893
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3894
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3895
|
-
* you may not use this file except in compliance with the License.
|
|
3896
|
-
* You may obtain a copy of the License at
|
|
3897
|
-
*
|
|
3898
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3899
|
-
*
|
|
3900
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3901
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3902
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3903
|
-
* See the License for the specific language governing permissions and
|
|
3904
|
-
* limitations under the License.
|
|
3905
|
-
* =============================================================================
|
|
3906
|
-
*/
|
|
3907
|
-
class De extends H {
|
|
3908
|
-
/** @nocollapse */
|
|
3909
|
-
static get className() {
|
|
3910
|
-
return "SGD";
|
|
3911
|
-
}
|
|
3912
|
-
constructor(t) {
|
|
3913
|
-
super(), this.learningRate = t, this.setLearningRate(t);
|
|
3914
|
-
}
|
|
3915
|
-
applyGradients(t) {
|
|
3916
|
-
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
3917
|
-
const a = Array.isArray(t) ? t[r].tensor : t[s];
|
|
3918
|
-
if (a == null)
|
|
3919
|
-
return;
|
|
3920
|
-
const o = f.registeredVariables[s];
|
|
3921
|
-
A(() => {
|
|
3922
|
-
const i = k(b(this.c, a), o);
|
|
3923
|
-
o.assign(i);
|
|
3924
|
-
});
|
|
3925
|
-
}), this.incrementIterations();
|
|
3926
|
-
}
|
|
3927
|
-
/**
|
|
3928
|
-
* Sets the learning rate of the optimizer.
|
|
3929
|
-
*/
|
|
3930
|
-
setLearningRate(t) {
|
|
3931
|
-
this.learningRate = t, this.c != null && this.c.dispose(), this.c = Mn(q(-t));
|
|
3932
|
-
}
|
|
3933
|
-
dispose() {
|
|
3934
|
-
this.c.dispose();
|
|
3935
|
-
}
|
|
3936
|
-
async getWeights() {
|
|
3937
|
-
return [await this.saveIterations()];
|
|
3938
|
-
}
|
|
3939
|
-
async setWeights(t) {
|
|
3940
|
-
if (t = await this.extractIterations(t), t.length !== 0)
|
|
3941
|
-
throw new Error("SGD optimizer does not have settable weights.");
|
|
3942
|
-
}
|
|
3943
|
-
getConfig() {
|
|
3944
|
-
return { learningRate: this.learningRate };
|
|
3945
|
-
}
|
|
3946
|
-
/** @nocollapse */
|
|
3947
|
-
static fromConfig(t, n) {
|
|
3948
|
-
return new t(n.learningRate);
|
|
3949
|
-
}
|
|
3950
|
-
}
|
|
3951
|
-
/**
|
|
3952
|
-
* @license
|
|
3953
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3954
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3955
|
-
* you may not use this file except in compliance with the License.
|
|
3956
|
-
* You may obtain a copy of the License at
|
|
3957
|
-
*
|
|
3958
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3959
|
-
*
|
|
3960
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3961
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3962
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3963
|
-
* See the License for the specific language governing permissions and
|
|
3964
|
-
* limitations under the License.
|
|
3965
|
-
* =============================================================================
|
|
3966
|
-
*/
|
|
3967
|
-
class As extends De {
|
|
3968
|
-
/** @nocollapse */
|
|
3969
|
-
// Name matters for Python compatibility.
|
|
3970
|
-
static get className() {
|
|
3971
|
-
return "Momentum";
|
|
3972
|
-
}
|
|
3973
|
-
constructor(t, n, s = !1) {
|
|
3974
|
-
super(t), this.learningRate = t, this.momentum = n, this.useNesterov = s, this.accumulations = [], this.m = q(this.momentum);
|
|
3975
|
-
}
|
|
3976
|
-
applyGradients(t) {
|
|
3977
|
-
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
3978
|
-
const a = f.registeredVariables[s];
|
|
3979
|
-
this.accumulations[r] == null && (this.accumulations[r] = {
|
|
3980
|
-
originalName: `${s}/momentum`,
|
|
3981
|
-
variable: A(() => C(a).variable(!1))
|
|
3982
|
-
});
|
|
3983
|
-
const o = this.accumulations[r].variable, i = Array.isArray(t) ? t[r].tensor : t[s];
|
|
3984
|
-
i != null && A(() => {
|
|
3985
|
-
let c;
|
|
3986
|
-
const l = k(b(this.m, o), i);
|
|
3987
|
-
this.useNesterov ? c = k(b(this.c, k(i, b(l, this.m))), a) : c = k(b(this.c, l), a), o.assign(l), a.assign(c);
|
|
3988
|
-
});
|
|
3989
|
-
}), this.incrementIterations();
|
|
3990
|
-
}
|
|
3991
|
-
dispose() {
|
|
3992
|
-
this.m.dispose(), this.accumulations != null && D(this.accumulations.map((t) => t.variable));
|
|
3993
|
-
}
|
|
3994
|
-
/**
|
|
3995
|
-
* Sets the momentum of the optimizer.
|
|
3996
|
-
*
|
|
3997
|
-
* @param momentum
|
|
3998
|
-
*/
|
|
3999
|
-
setMomentum(t) {
|
|
4000
|
-
this.momentum = t;
|
|
4001
|
-
}
|
|
4002
|
-
async getWeights() {
|
|
4003
|
-
return [await this.saveIterations()].concat(this.accumulations.map((t) => ({ name: t.originalName, tensor: t.variable })));
|
|
4004
|
-
}
|
|
4005
|
-
async setWeights(t) {
|
|
4006
|
-
t = await this.extractIterations(t);
|
|
4007
|
-
const n = !1;
|
|
4008
|
-
this.accumulations = t.map((s) => ({ originalName: s.name, variable: s.tensor.variable(n) }));
|
|
4009
|
-
}
|
|
4010
|
-
getConfig() {
|
|
4011
|
-
return {
|
|
4012
|
-
learningRate: this.learningRate,
|
|
4013
|
-
momentum: this.momentum,
|
|
4014
|
-
useNesterov: this.useNesterov
|
|
4015
|
-
};
|
|
4016
|
-
}
|
|
4017
|
-
/** @nocollapse */
|
|
4018
|
-
static fromConfig(t, n) {
|
|
4019
|
-
return new t(n.learningRate, n.momentum, n.useNesterov);
|
|
4020
|
-
}
|
|
4021
|
-
}
|
|
4022
|
-
/**
|
|
4023
|
-
* @license
|
|
4024
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
4025
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4026
|
-
* you may not use this file except in compliance with the License.
|
|
4027
|
-
* You may obtain a copy of the License at
|
|
4028
|
-
*
|
|
4029
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4030
|
-
*
|
|
4031
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4032
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4033
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4034
|
-
* See the License for the specific language governing permissions and
|
|
4035
|
-
* limitations under the License.
|
|
4036
|
-
* =============================================================================
|
|
4037
|
-
*/
|
|
4038
|
-
class Es extends H {
|
|
4039
|
-
/** @nocollapse */
|
|
4040
|
-
static get className() {
|
|
4041
|
-
return "RMSProp";
|
|
4042
|
-
}
|
|
4043
|
-
constructor(t, n = 0.9, s = 0, r = null, a = !1) {
|
|
4044
|
-
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 = f.backend.epsilon()), t == null)
|
|
4045
|
-
throw new Error("learningRate for RMSPropOptimizer must be defined.");
|
|
4046
|
-
}
|
|
4047
|
-
applyGradients(t) {
|
|
4048
|
-
(Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
|
|
4049
|
-
const a = f.registeredVariables[s], o = !1;
|
|
4050
|
-
this.accumulatedMeanSquares[r] == null && (this.accumulatedMeanSquares[r] = {
|
|
4051
|
-
originalName: `${s}/rms`,
|
|
4052
|
-
variable: A(() => C(a).variable(o))
|
|
4053
|
-
}), this.accumulatedMoments[r] == null && (this.accumulatedMoments[r] = {
|
|
4054
|
-
originalName: `${s}/momentum`,
|
|
4055
|
-
variable: A(() => C(a).variable(o))
|
|
4056
|
-
}), this.accumulatedMeanGrads[r] == null && this.centered && (this.accumulatedMeanGrads[r] = {
|
|
4057
|
-
originalName: `${s}/mg`,
|
|
4058
|
-
variable: A(() => C(a).variable(o))
|
|
4059
|
-
});
|
|
4060
|
-
const i = Array.isArray(t) ? t[r].tensor : t[s];
|
|
4061
|
-
if (i == null)
|
|
4062
|
-
return;
|
|
4063
|
-
const c = this.accumulatedMeanSquares[r].variable, l = this.accumulatedMoments[r].variable;
|
|
4064
|
-
A(() => {
|
|
4065
|
-
const u = k(b(c, this.decay), b(V(i), 1 - this.decay));
|
|
4066
|
-
if (this.centered) {
|
|
4067
|
-
const h = this.accumulatedMeanGrads[r].variable, d = k(b(h, this.decay), b(i, 1 - this.decay)), m = $(b(i, this.learningRate), nt(tt(u, k(V(d), this.epsilon)))), y = k(b(l, this.momentum), m);
|
|
4068
|
-
c.assign(u), h.assign(d), l.assign(y);
|
|
4069
|
-
const g = tt(a, y);
|
|
4070
|
-
a.assign(g);
|
|
4071
|
-
} else {
|
|
4072
|
-
const h = k(b(c, this.decay), b(V(i), 1 - this.decay)), d = k(b(l, this.momentum), $(b(i, this.learningRate), nt(k(h, this.epsilon))));
|
|
4073
|
-
c.assign(h), l.assign(d);
|
|
4074
|
-
const m = tt(a, d);
|
|
4075
|
-
a.assign(m);
|
|
4076
|
-
}
|
|
4077
|
-
});
|
|
4078
|
-
}), this.incrementIterations();
|
|
4079
|
-
}
|
|
4080
|
-
dispose() {
|
|
4081
|
-
this.accumulatedMeanSquares != null && D(this.accumulatedMeanSquares.map((t) => t.variable)), this.accumulatedMeanGrads != null && this.centered && D(this.accumulatedMeanGrads.map((t) => t.variable)), this.accumulatedMoments != null && D(this.accumulatedMoments.map((t) => t.variable));
|
|
4082
|
-
}
|
|
4083
|
-
async getWeights() {
|
|
4084
|
-
const t = [...this.accumulatedMeanSquares, ...this.accumulatedMoments];
|
|
4085
|
-
return this.centered && t.push(...this.accumulatedMeanGrads), [await this.saveIterations()].concat(t.map((n) => ({ name: n.originalName, tensor: n.variable })));
|
|
4086
|
-
}
|
|
4087
|
-
async setWeights(t) {
|
|
4088
|
-
t = await this.extractIterations(t);
|
|
4089
|
-
const n = this.centered ? t.length / 3 : t.length / 2, s = !1;
|
|
4090
|
-
this.accumulatedMeanSquares = t.slice(0, n).map((r) => ({
|
|
4091
|
-
originalName: r.name,
|
|
4092
|
-
variable: r.tensor.variable(s)
|
|
4093
|
-
})), this.accumulatedMoments = t.slice(n, n * 2).map((r) => ({
|
|
4094
|
-
originalName: r.name,
|
|
4095
|
-
variable: r.tensor.variable(s)
|
|
4096
|
-
})), this.centered && (this.accumulatedMeanGrads = t.slice(n * 2, n * 3).map((r) => ({
|
|
4097
|
-
originalName: r.name,
|
|
4098
|
-
variable: r.tensor.variable(s)
|
|
4099
|
-
})));
|
|
4100
|
-
}
|
|
4101
|
-
getConfig() {
|
|
4102
|
-
return {
|
|
4103
|
-
learningRate: this.learningRate,
|
|
4104
|
-
decay: this.decay,
|
|
4105
|
-
momentum: this.momentum,
|
|
4106
|
-
epsilon: this.epsilon,
|
|
4107
|
-
centered: this.centered
|
|
4108
|
-
};
|
|
4109
|
-
}
|
|
4110
|
-
/** @nocollapse */
|
|
4111
|
-
static fromConfig(t, n) {
|
|
4112
|
-
return new t(n.learningRate, n.decay, n.momentum, n.epsilon, n.centered);
|
|
4113
|
-
}
|
|
4114
|
-
}
|
|
4115
|
-
/**
|
|
4116
|
-
* @license
|
|
4117
|
-
* Copyright 2022 Google LLC.
|
|
4118
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4119
|
-
* you may not use this file except in compliance with the License.
|
|
4120
|
-
* You may obtain a copy of the License at
|
|
4121
|
-
*
|
|
4122
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4123
|
-
*
|
|
4124
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4125
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4126
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4127
|
-
* See the License for the specific language governing permissions and
|
|
4128
|
-
* limitations under the License.
|
|
4129
|
-
* =============================================================================
|
|
4130
|
-
*/
|
|
4131
|
-
const vs = [
|
|
4132
|
-
Ss,
|
|
4133
|
-
ks,
|
|
4134
|
-
Is,
|
|
4135
|
-
Ts,
|
|
4136
|
-
As,
|
|
4137
|
-
Es,
|
|
4138
|
-
De
|
|
4139
|
-
];
|
|
4140
|
-
function Bs() {
|
|
4141
|
-
for (const e of vs)
|
|
4142
|
-
ws(e);
|
|
4143
|
-
}
|
|
4144
|
-
/**
|
|
4145
|
-
* @license
|
|
4146
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
4147
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4148
|
-
* you may not use this file except in compliance with the License.
|
|
4149
|
-
* You may obtain a copy of the License at
|
|
4150
|
-
*
|
|
4151
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4152
|
-
*
|
|
4153
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
4154
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4155
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4156
|
-
* See the License for the specific language governing permissions and
|
|
4157
|
-
* limitations under the License.
|
|
4158
|
-
* =============================================================================
|
|
4159
|
-
*/
|
|
4160
|
-
Bs();
|
|
4161
|
-
export {
|
|
4162
|
-
ho as $,
|
|
4163
|
-
C as A,
|
|
4164
|
-
Ps as B,
|
|
4165
|
-
Tn as C,
|
|
4166
|
-
vn as D,
|
|
4167
|
-
F as E,
|
|
4168
|
-
T as F,
|
|
4169
|
-
f as G,
|
|
4170
|
-
ta as H,
|
|
4171
|
-
An as I,
|
|
4172
|
-
Jn as J,
|
|
4173
|
-
Sr as K,
|
|
4174
|
-
bi as L,
|
|
4175
|
-
Ct as M,
|
|
4176
|
-
Ue as N,
|
|
4177
|
-
H as O,
|
|
4178
|
-
Ga as P,
|
|
4179
|
-
K as Q,
|
|
4180
|
-
Ka as R,
|
|
4181
|
-
ko as S,
|
|
4182
|
-
M as T,
|
|
4183
|
-
hr as U,
|
|
4184
|
-
Ya as V,
|
|
4185
|
-
So as W,
|
|
4186
|
-
Po as X,
|
|
4187
|
-
Ra as Y,
|
|
4188
|
-
Xa as Z,
|
|
4189
|
-
Ja as _,
|
|
4190
|
-
b as a,
|
|
4191
|
-
aa as a$,
|
|
4192
|
-
Rt as a0,
|
|
4193
|
-
bo as a1,
|
|
4194
|
-
ni as a2,
|
|
4195
|
-
$t as a3,
|
|
4196
|
-
te as a4,
|
|
4197
|
-
Gs as a5,
|
|
4198
|
-
xa as a6,
|
|
4199
|
-
oo as a7,
|
|
4200
|
-
ea as a8,
|
|
4201
|
-
Sn as a9,
|
|
4202
|
-
Zo as aA,
|
|
4203
|
-
Qo as aB,
|
|
4204
|
-
Je as aC,
|
|
4205
|
-
E as aD,
|
|
4206
|
-
st as aE,
|
|
4207
|
-
di as aF,
|
|
4208
|
-
ke as aG,
|
|
4209
|
-
fi as aH,
|
|
4210
|
-
gi as aI,
|
|
4211
|
-
Us as aJ,
|
|
4212
|
-
_s as aK,
|
|
4213
|
-
$s as aL,
|
|
4214
|
-
ht as aM,
|
|
4215
|
-
Ws as aN,
|
|
4216
|
-
jt as aO,
|
|
4217
|
-
he as aP,
|
|
4218
|
-
Xo as aQ,
|
|
4219
|
-
O as aR,
|
|
4220
|
-
fr as aS,
|
|
4221
|
-
lo as aT,
|
|
4222
|
-
zr as aU,
|
|
4223
|
-
Ma as aV,
|
|
4224
|
-
as as aW,
|
|
4225
|
-
V as aX,
|
|
4226
|
-
Hr as aY,
|
|
4227
|
-
na as aZ,
|
|
4228
|
-
sa as a_,
|
|
4229
|
-
wr as aa,
|
|
4230
|
-
se as ab,
|
|
4231
|
-
Br as ac,
|
|
4232
|
-
fo as ad,
|
|
4233
|
-
pi as ae,
|
|
4234
|
-
xt as af,
|
|
4235
|
-
S as ag,
|
|
4236
|
-
ka as ah,
|
|
4237
|
-
Kr as ai,
|
|
4238
|
-
fa as aj,
|
|
4239
|
-
R as ak,
|
|
4240
|
-
ye as al,
|
|
4241
|
-
ti as am,
|
|
4242
|
-
gt as an,
|
|
4243
|
-
Zr as ao,
|
|
4244
|
-
Kn as ap,
|
|
4245
|
-
$e as aq,
|
|
4246
|
-
po as ar,
|
|
4247
|
-
Vr as as,
|
|
4248
|
-
la as at,
|
|
4249
|
-
za as au,
|
|
4250
|
-
no as av,
|
|
4251
|
-
Vo as aw,
|
|
4252
|
-
yi as ax,
|
|
4253
|
-
Ns as ay,
|
|
4254
|
-
ce as az,
|
|
4255
|
-
q as b,
|
|
4256
|
-
jr as b$,
|
|
4257
|
-
ua as b0,
|
|
4258
|
-
ha as b1,
|
|
4259
|
-
ga as b2,
|
|
4260
|
-
Na as b3,
|
|
4261
|
-
ma as b4,
|
|
4262
|
-
Ba as b5,
|
|
4263
|
-
Da as b6,
|
|
4264
|
-
$a as b7,
|
|
4265
|
-
Ha as b8,
|
|
4266
|
-
ro as b9,
|
|
4267
|
-
Qe as bA,
|
|
4268
|
-
tn as bB,
|
|
4269
|
-
Va as bC,
|
|
4270
|
-
ao as bD,
|
|
4271
|
-
gn as bE,
|
|
4272
|
-
nn as bF,
|
|
4273
|
-
Do as bG,
|
|
4274
|
-
sn as bH,
|
|
4275
|
-
Ne as bI,
|
|
4276
|
-
Zs as bJ,
|
|
4277
|
-
Qs as bK,
|
|
4278
|
-
tr as bL,
|
|
4279
|
-
ir as bM,
|
|
4280
|
-
lr as bN,
|
|
4281
|
-
Co as bO,
|
|
4282
|
-
dr as bP,
|
|
4283
|
-
Qr as bQ,
|
|
4284
|
-
br as bR,
|
|
4285
|
-
kr as bS,
|
|
4286
|
-
Tr as bT,
|
|
4287
|
-
Ar as bU,
|
|
4288
|
-
vr as bV,
|
|
4289
|
-
Mr as bW,
|
|
4290
|
-
Dr as bX,
|
|
4291
|
-
Fr as bY,
|
|
4292
|
-
xr as bZ,
|
|
4293
|
-
$r as b_,
|
|
4294
|
-
Bo as ba,
|
|
4295
|
-
Uo as bb,
|
|
4296
|
-
Oo as bc,
|
|
4297
|
-
Rr as bd,
|
|
4298
|
-
Yr as be,
|
|
4299
|
-
jo as bf,
|
|
4300
|
-
Ca as bg,
|
|
4301
|
-
La as bh,
|
|
4302
|
-
Pa as bi,
|
|
4303
|
-
to as bj,
|
|
4304
|
-
Za as bk,
|
|
4305
|
-
_o as bl,
|
|
4306
|
-
He as bm,
|
|
4307
|
-
zs as bn,
|
|
4308
|
-
Hs as bo,
|
|
4309
|
-
Ks as bp,
|
|
4310
|
-
ie as bq,
|
|
4311
|
-
Vs as br,
|
|
4312
|
-
_t as bs,
|
|
4313
|
-
oe as bt,
|
|
4314
|
-
gr as bu,
|
|
4315
|
-
ee as bv,
|
|
4316
|
-
yr as bw,
|
|
4317
|
-
qr as bx,
|
|
4318
|
-
Xr as by,
|
|
4319
|
-
Ze as bz,
|
|
4320
|
-
tt as c,
|
|
4321
|
-
Ge as c$,
|
|
4322
|
-
yo as c0,
|
|
4323
|
-
pa as c1,
|
|
4324
|
-
Ia as c2,
|
|
4325
|
-
Aa as c3,
|
|
4326
|
-
Oa as c4,
|
|
4327
|
-
_a as c5,
|
|
4328
|
-
Ua as c6,
|
|
4329
|
-
wo as c7,
|
|
4330
|
-
so as c8,
|
|
4331
|
-
uo as c9,
|
|
4332
|
-
Xe as cA,
|
|
4333
|
-
Er as cB,
|
|
4334
|
-
_r as cC,
|
|
4335
|
-
Gr as cD,
|
|
4336
|
-
Or as cE,
|
|
4337
|
-
Wr as cF,
|
|
4338
|
-
oa as cG,
|
|
4339
|
-
ia as cH,
|
|
4340
|
-
ca as cI,
|
|
4341
|
-
ba as cJ,
|
|
4342
|
-
Sa as cK,
|
|
4343
|
-
wa as cL,
|
|
4344
|
-
Ea as cM,
|
|
4345
|
-
Ta as cN,
|
|
4346
|
-
Fa as cO,
|
|
4347
|
-
en as cP,
|
|
4348
|
-
eo as cQ,
|
|
4349
|
-
Qa as cR,
|
|
4350
|
-
mo as cS,
|
|
4351
|
-
Mo as cT,
|
|
4352
|
-
$o as cU,
|
|
4353
|
-
ms as cV,
|
|
4354
|
-
rn as cW,
|
|
4355
|
-
li as cX,
|
|
4356
|
-
ws as cY,
|
|
4357
|
-
bs as cZ,
|
|
4358
|
-
G as c_,
|
|
4359
|
-
go as ca,
|
|
4360
|
-
zo as cb,
|
|
4361
|
-
Ir as cc,
|
|
4362
|
-
Ko as cd,
|
|
4363
|
-
Cr as ce,
|
|
4364
|
-
Pr as cf,
|
|
4365
|
-
qo as cg,
|
|
4366
|
-
De as ch,
|
|
4367
|
-
As as ci,
|
|
4368
|
-
Es as cj,
|
|
4369
|
-
Is as ck,
|
|
4370
|
-
Ss as cl,
|
|
4371
|
-
Ts as cm,
|
|
4372
|
-
ks as cn,
|
|
4373
|
-
Xs as co,
|
|
4374
|
-
Js as cp,
|
|
4375
|
-
Ys as cq,
|
|
4376
|
-
er as cr,
|
|
4377
|
-
nr as cs,
|
|
4378
|
-
sr as ct,
|
|
4379
|
-
or as cu,
|
|
4380
|
-
rr as cv,
|
|
4381
|
-
ar as cw,
|
|
4382
|
-
ur as cx,
|
|
4383
|
-
cr as cy,
|
|
4384
|
-
mr as cz,
|
|
4385
|
-
D as d,
|
|
4386
|
-
xs as d0,
|
|
4387
|
-
mi as d1,
|
|
4388
|
-
ui as d2,
|
|
4389
|
-
hi as d3,
|
|
4390
|
-
xe as d4,
|
|
4391
|
-
Rs as d5,
|
|
4392
|
-
js as d6,
|
|
4393
|
-
ut as d7,
|
|
4394
|
-
Cs as d8,
|
|
4395
|
-
Nt as d9,
|
|
4396
|
-
es as dA,
|
|
4397
|
-
ct as dB,
|
|
4398
|
-
qs as dC,
|
|
4399
|
-
Wa as dD,
|
|
4400
|
-
ja as dE,
|
|
4401
|
-
qa as dF,
|
|
4402
|
-
Io as dG,
|
|
4403
|
-
To as dH,
|
|
4404
|
-
xo as dI,
|
|
4405
|
-
No as dJ,
|
|
4406
|
-
ei as dK,
|
|
4407
|
-
Os as dL,
|
|
4408
|
-
It as dM,
|
|
4409
|
-
In as dN,
|
|
4410
|
-
ci as da,
|
|
4411
|
-
Ye as db,
|
|
4412
|
-
yt as dc,
|
|
4413
|
-
Ls as dd,
|
|
4414
|
-
pr as de,
|
|
4415
|
-
Nr as df,
|
|
4416
|
-
Lr as dg,
|
|
4417
|
-
Ur as dh,
|
|
4418
|
-
Jr as di,
|
|
4419
|
-
Wo as dj,
|
|
4420
|
-
Ho as dk,
|
|
4421
|
-
ra as dl,
|
|
4422
|
-
da as dm,
|
|
4423
|
-
ya as dn,
|
|
4424
|
-
va as dp,
|
|
4425
|
-
co as dq,
|
|
4426
|
-
Ao as dr,
|
|
4427
|
-
Eo as ds,
|
|
4428
|
-
vo as dt,
|
|
4429
|
-
Fo as du,
|
|
4430
|
-
Ro as dv,
|
|
4431
|
-
io as dw,
|
|
4432
|
-
Lo as dx,
|
|
4433
|
-
Go as dy,
|
|
4434
|
-
fe as dz,
|
|
4435
|
-
si as e,
|
|
4436
|
-
Jo as f,
|
|
4437
|
-
ii as g,
|
|
4438
|
-
os as h,
|
|
4439
|
-
Yo as i,
|
|
4440
|
-
z as j,
|
|
4441
|
-
Mn as k,
|
|
4442
|
-
is as l,
|
|
4443
|
-
ri as m,
|
|
4444
|
-
p as n,
|
|
4445
|
-
$ as o,
|
|
4446
|
-
Ce as p,
|
|
4447
|
-
k as q,
|
|
4448
|
-
oi as r,
|
|
4449
|
-
ai as s,
|
|
4450
|
-
A as t,
|
|
4451
|
-
ge as u,
|
|
4452
|
-
ds as v,
|
|
4453
|
-
nt as w,
|
|
4454
|
-
Qt as x,
|
|
4455
|
-
wi as y,
|
|
4456
|
-
Si as z
|
|
4457
|
-
};
|