mindspore 1.10.0__cp37-none-any.whl → 2.0.0rc1__cp37-none-any.whl
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.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/Third_Party_Open_Source_Software_Notice +9064 -0
- mindspore/__init__.py +9 -4
- mindspore/_akg/akg/composite/build_module.py +11 -0
- mindspore/_akg/akg/config/repository_cuda.json +11 -0
- mindspore/_akg/akg/tvm/contrib/nvcc.py +4 -3
- mindspore/_c_dataengine.cpython-37m-aarch64-linux-gnu.so +0 -0
- mindspore/_c_expression.cpython-37m-aarch64-linux-gnu.so +0 -0
- mindspore/_c_mindrecord.cpython-37m-aarch64-linux-gnu.so +0 -0
- mindspore/_check_jit_forbidden_api.py +102 -0
- mindspore/_checkparam.py +1066 -1001
- mindspore/_extends/builtin_operations.py +32 -4
- mindspore/_extends/graph_kernel/model/graph_split.py +66 -222
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +12 -9
- mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +119 -26
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +50 -50
- mindspore/_extends/parallel_compile/akg_compiler/util.py +9 -6
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +4 -25
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +9 -4
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +1 -27
- mindspore/_extends/parse/__init__.py +5 -3
- mindspore/_extends/parse/namespace.py +17 -2
- mindspore/_extends/parse/parser.py +193 -34
- mindspore/_extends/parse/resources.py +7 -8
- mindspore/_extends/parse/standard_method.py +1780 -435
- mindspore/_extends/parse/trope.py +3 -1
- mindspore/_mindspore_offline_debug.cpython-37m-aarch64-linux-gnu.so +0 -0
- mindspore/amp.py +53 -58
- mindspore/bin/cache_admin +0 -0
- mindspore/bin/cache_server +0 -0
- mindspore/boost/adasum.py +3 -2
- mindspore/boost/boost.py +2 -2
- mindspore/boost/boost_cell_wrapper.py +46 -26
- mindspore/boost/dim_reduce.py +6 -5
- mindspore/boost/grad_accumulation.py +2 -1
- mindspore/boost/group_loss_scale_manager.py +1 -1
- mindspore/common/__init__.py +11 -10
- mindspore/common/_decorator.py +2 -0
- mindspore/common/_register_for_adapter.py +55 -0
- mindspore/common/_stub_tensor.py +201 -0
- mindspore/common/_utils.py +57 -0
- mindspore/common/api.py +582 -297
- mindspore/common/dtype.py +66 -18
- mindspore/common/dump.py +2 -2
- mindspore/common/initializer.py +38 -1
- mindspore/common/jit_config.py +25 -13
- mindspore/common/mutable.py +53 -24
- mindspore/common/parameter.py +60 -37
- mindspore/common/seed.py +8 -24
- mindspore/common/sparse_tensor.py +927 -0
- mindspore/common/tensor.py +1627 -3900
- mindspore/communication/__init__.py +10 -5
- mindspore/communication/_comm_helper.py +78 -214
- mindspore/communication/_hccl_management.py +2 -1
- mindspore/communication/management.py +136 -47
- mindspore/config/op_info.config +501 -1008
- mindspore/config/super_bar_config.json +512 -0
- mindspore/context.py +291 -56
- mindspore/dataset/__init__.py +12 -8
- mindspore/dataset/audio/__init__.py +9 -9
- mindspore/dataset/audio/transforms.py +1090 -228
- mindspore/dataset/audio/utils.py +87 -39
- mindspore/dataset/audio/validators.py +223 -1
- mindspore/dataset/callback/ds_callback.py +17 -15
- mindspore/dataset/core/config.py +246 -17
- mindspore/dataset/core/py_util_helpers.py +4 -3
- mindspore/dataset/core/validator_helpers.py +10 -10
- mindspore/{parallel/nn/layers.py → dataset/debug/__init__.py} +7 -8
- mindspore/dataset/debug/debug_hook.py +65 -0
- mindspore/dataset/debug/pre_defined_hook.py +67 -0
- mindspore/dataset/engine/__init__.py +7 -3
- mindspore/dataset/engine/cache_client.py +9 -9
- mindspore/dataset/engine/datasets.py +648 -477
- mindspore/dataset/engine/datasets_audio.py +165 -167
- mindspore/dataset/engine/datasets_standard_format.py +93 -67
- mindspore/dataset/engine/datasets_text.py +492 -342
- mindspore/dataset/engine/datasets_user_defined.py +85 -50
- mindspore/dataset/engine/datasets_vision.py +1224 -699
- mindspore/dataset/engine/graphdata.py +134 -69
- mindspore/dataset/engine/iterators.py +50 -9
- mindspore/dataset/engine/offload.py +52 -31
- mindspore/dataset/engine/samplers.py +27 -24
- mindspore/dataset/engine/serializer_deserializer.py +14 -15
- mindspore/dataset/engine/validators.py +213 -52
- mindspore/dataset/text/__init__.py +10 -8
- mindspore/dataset/text/transforms.py +152 -57
- mindspore/dataset/text/utils.py +98 -49
- mindspore/dataset/text/validators.py +25 -0
- mindspore/dataset/transforms/__init__.py +4 -2
- mindspore/dataset/transforms/c_transforms.py +11 -13
- mindspore/dataset/transforms/py_transforms.py +2 -2
- mindspore/dataset/transforms/py_transforms_util.py +10 -0
- mindspore/dataset/transforms/transforms.py +13 -15
- mindspore/dataset/transforms/validators.py +7 -7
- mindspore/dataset/utils/__init__.py +2 -1
- mindspore/dataset/utils/browse_dataset.py +13 -13
- mindspore/dataset/utils/line_reader.py +121 -0
- mindspore/dataset/vision/__init__.py +8 -7
- mindspore/dataset/vision/c_transforms.py +125 -126
- mindspore/dataset/vision/py_transforms.py +37 -37
- mindspore/dataset/vision/py_transforms_util.py +23 -20
- mindspore/dataset/vision/transforms.py +316 -315
- mindspore/dataset/vision/utils.py +313 -17
- mindspore/dataset/vision/validators.py +6 -6
- mindspore/default_config.py +0 -1
- mindspore/{compression → experimental}/__init__.py +6 -5
- mindspore/experimental/map_parameter.py +275 -0
- mindspore/include/OWNERS +0 -1
- mindspore/include/api/callback/callback.h +9 -13
- mindspore/include/api/callback/ckpt_saver.h +2 -2
- mindspore/include/api/callback/loss_monitor.h +2 -2
- mindspore/include/api/callback/lr_scheduler.h +5 -5
- mindspore/include/api/callback/time_monitor.h +2 -2
- mindspore/include/api/callback/train_accuracy.h +4 -6
- mindspore/include/api/cfg.h +19 -6
- mindspore/include/api/context.h +70 -9
- mindspore/include/api/delegate.h +8 -1
- mindspore/include/api/dual_abi_helper.h +8 -24
- mindspore/include/api/metrics/accuracy.h +2 -2
- mindspore/include/api/metrics/metrics.h +4 -3
- mindspore/include/api/model.h +9 -4
- mindspore/include/api/model_group.h +68 -0
- mindspore/include/api/model_parallel_runner.h +17 -17
- mindspore/include/api/net.h +12 -11
- mindspore/include/api/serialization.h +20 -4
- mindspore/include/api/status.h +7 -1
- mindspore/include/api/types.h +25 -21
- mindspore/include/api/visible.h +4 -0
- mindspore/include/c_api/model_c.h +5 -0
- mindspore/include/c_api/status_c.h +1 -1
- mindspore/include/dataset/config.h +1 -1
- mindspore/include/dataset/constants.h +14 -0
- mindspore/include/dataset/text.h +59 -0
- mindspore/include/dataset/vision.h +56 -117
- mindspore/include/dataset/vision_lite.h +102 -0
- mindspore/include/mindapi/base/type_id.h +42 -3
- mindspore/lib/libdnnl.so.2 +0 -0
- mindspore/lib/libicudata.so.69 +0 -0
- mindspore/lib/libicui18n.so.69 +0 -0
- mindspore/lib/libicuuc.so.69 +0 -0
- mindspore/lib/libmindspore.so +0 -0
- mindspore/lib/libmindspore_backend.so +0 -0
- mindspore/lib/libmindspore_common.so +0 -0
- mindspore/lib/libmindspore_core.so +0 -0
- mindspore/lib/libmindspore_glog.so.0 +0 -0
- mindspore/lib/libmindspore_gpr.so.15 +0 -0
- mindspore/lib/libmindspore_grpc++.so.1 +0 -0
- mindspore/lib/libmindspore_grpc.so.15 +0 -0
- mindspore/lib/libmindspore_shared_lib.so +0 -0
- mindspore/lib/libmpi_adapter.so +0 -0
- mindspore/lib/libmpi_collective.so +0 -0
- mindspore/lib/libnnacl.so +0 -0
- mindspore/lib/libopencv_core.so.4.5 +0 -0
- mindspore/lib/libopencv_imgcodecs.so.4.5 +0 -0
- mindspore/lib/libopencv_imgproc.so.4.5 +0 -0
- mindspore/lib/libps_cache.so +0 -0
- mindspore/lib/plugin/ascend/libakg.so +0 -0
- mindspore/lib/plugin/ascend/libascend_collective.so +0 -0
- mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
- mindspore/lib/plugin/ascend/libhccl_plugin.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_aicpu_kernels.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
- mindspore/lib/{libakg.so → plugin/cpu/libakg.so} +0 -0
- mindspore/lib/plugin/libmindspore_ascend.so.1 +0 -0
- mindspore/lib/plugin/libmindspore_ascend.so.2 +0 -0
- mindspore/log.py +28 -28
- mindspore/mindrecord/common/exceptions.py +2 -4
- mindspore/mindrecord/filereader.py +19 -1
- mindspore/mindrecord/filewriter.py +250 -88
- mindspore/mindrecord/mindpage.py +13 -13
- mindspore/mindrecord/shardheader.py +15 -15
- mindspore/mindrecord/shardreader.py +9 -0
- mindspore/mindrecord/shardwriter.py +29 -29
- mindspore/mindrecord/tools/cifar100_to_mr.py +9 -9
- mindspore/mindrecord/tools/cifar10_to_mr.py +9 -9
- mindspore/mindrecord/tools/csv_to_mr.py +4 -4
- mindspore/mindrecord/tools/imagenet_to_mr.py +70 -65
- mindspore/mindrecord/tools/mnist_to_mr.py +41 -41
- mindspore/mindrecord/tools/tfrecord_to_mr.py +6 -6
- mindspore/nn/__init__.py +1 -5
- mindspore/nn/cell.py +297 -234
- mindspore/nn/dynamic_lr.py +1 -1
- mindspore/nn/grad/cell_grad.py +17 -42
- mindspore/nn/layer/__init__.py +7 -4
- mindspore/nn/layer/activation.py +131 -88
- mindspore/nn/layer/basic.py +313 -613
- mindspore/nn/layer/channel_shuffle.py +103 -0
- mindspore/nn/layer/combined.py +1 -1
- mindspore/nn/layer/container.py +52 -6
- mindspore/nn/layer/conv.py +112 -43
- mindspore/nn/layer/dense.py +10 -9
- mindspore/nn/layer/embedding.py +36 -34
- mindspore/nn/layer/image.py +123 -27
- mindspore/nn/layer/math.py +108 -107
- mindspore/nn/layer/normalization.py +212 -366
- mindspore/nn/layer/padding.py +370 -42
- mindspore/nn/layer/pooling.py +1443 -219
- mindspore/nn/layer/rnn_cells.py +11 -16
- mindspore/nn/layer/rnns.py +38 -39
- mindspore/nn/layer/thor_layer.py +24 -25
- mindspore/nn/layer/timedistributed.py +5 -5
- mindspore/nn/layer/transformer.py +701 -0
- mindspore/nn/learning_rate_schedule.py +8 -8
- mindspore/nn/loss/__init__.py +9 -6
- mindspore/nn/loss/loss.py +678 -142
- mindspore/nn/metrics.py +53 -0
- mindspore/nn/optim/_dist_optimizer_registry.py +2 -2
- mindspore/nn/optim/ada_grad.py +8 -8
- mindspore/nn/optim/adadelta.py +2 -3
- mindspore/nn/optim/adafactor.py +18 -14
- mindspore/nn/optim/adam.py +429 -87
- mindspore/nn/optim/adamax.py +5 -6
- mindspore/nn/optim/adasum.py +10 -8
- mindspore/nn/optim/asgd.py +7 -7
- mindspore/nn/optim/ftrl.py +81 -11
- mindspore/nn/optim/lamb.py +7 -8
- mindspore/nn/optim/lars.py +4 -4
- mindspore/nn/optim/lazyadam.py +82 -7
- mindspore/nn/optim/momentum.py +8 -7
- mindspore/nn/optim/optimizer.py +19 -10
- mindspore/nn/optim/proximal_ada_grad.py +6 -5
- mindspore/nn/optim/rmsprop.py +3 -3
- mindspore/nn/optim/rprop.py +20 -16
- mindspore/nn/optim/sgd.py +21 -15
- mindspore/nn/optim/thor.py +23 -21
- mindspore/nn/probability/__init__.py +0 -2
- mindspore/nn/probability/bijector/bijector.py +7 -6
- mindspore/nn/probability/bijector/invert.py +4 -2
- mindspore/nn/probability/bijector/softplus.py +2 -2
- mindspore/nn/probability/bnn_layers/dense_variational.py +1 -1
- mindspore/nn/probability/bnn_layers/layer_distribution.py +2 -2
- mindspore/nn/probability/distribution/__init__.py +6 -0
- mindspore/nn/probability/distribution/_utils/custom_ops.py +3 -2
- mindspore/nn/probability/distribution/_utils/utils.py +11 -17
- mindspore/nn/probability/distribution/bernoulli.py +6 -6
- mindspore/nn/probability/distribution/beta.py +1 -1
- mindspore/nn/probability/distribution/categorical.py +9 -9
- mindspore/nn/probability/distribution/cauchy.py +8 -8
- mindspore/nn/probability/distribution/distribution.py +12 -6
- mindspore/nn/probability/distribution/exponential.py +5 -5
- mindspore/nn/probability/distribution/gamma.py +3 -3
- mindspore/nn/probability/distribution/geometric.py +6 -5
- mindspore/nn/probability/distribution/gumbel.py +5 -5
- mindspore/nn/probability/distribution/half_normal.py +133 -0
- mindspore/nn/probability/distribution/laplace.py +128 -0
- mindspore/nn/probability/distribution/log_normal.py +0 -1
- mindspore/nn/probability/distribution/logistic.py +4 -5
- mindspore/nn/probability/distribution/normal.py +11 -15
- mindspore/nn/probability/distribution/poisson.py +6 -2
- mindspore/nn/probability/distribution/student_t.py +150 -0
- mindspore/nn/probability/distribution/transformed_distribution.py +4 -4
- mindspore/nn/probability/distribution/uniform.py +5 -5
- mindspore/nn/reinforcement/_tensors_queue.py +3 -3
- mindspore/nn/reinforcement/tensor_array.py +2 -2
- mindspore/nn/sparse/sparse.py +8 -1
- mindspore/nn/wrap/cell_wrapper.py +55 -27
- mindspore/nn/wrap/grad_reducer.py +20 -11
- mindspore/nn/wrap/loss_scale.py +47 -30
- mindspore/numpy/array_creations.py +33 -22
- mindspore/numpy/array_ops.py +46 -42
- mindspore/numpy/logic_ops.py +6 -27
- mindspore/numpy/math_ops.py +26 -19
- mindspore/numpy/utils.py +1 -8
- mindspore/numpy/utils_const.py +112 -62
- mindspore/ops/__init__.py +6 -3
- mindspore/ops/_constants.py +0 -6
- mindspore/ops/_grad/__init__.py +2 -1
- mindspore/ops/_grad/grad_array_ops.py +209 -152
- mindspore/ops/_grad/grad_base.py +55 -17
- mindspore/ops/_grad/grad_clip_ops.py +11 -3
- mindspore/ops/_grad/grad_comm_ops.py +58 -47
- mindspore/ops/_grad/grad_implementations.py +21 -61
- mindspore/ops/_grad/grad_inner_ops.py +48 -6
- mindspore/ops/_grad/grad_math_ops.py +306 -161
- mindspore/ops/_grad/grad_nn_ops.py +192 -181
- mindspore/ops/_grad/grad_other_ops.py +1 -1
- mindspore/ops/_grad/grad_quant_ops.py +5 -5
- mindspore/ops/_grad/grad_sequence_ops.py +296 -0
- mindspore/ops/_grad/grad_sparse.py +15 -9
- mindspore/ops/_grad_experimental/__init__.py +1 -0
- mindspore/ops/_grad_experimental/grad_array_ops.py +441 -55
- mindspore/ops/_grad_experimental/grad_image_ops.py +25 -7
- mindspore/ops/_grad_experimental/grad_inner_ops.py +3 -44
- mindspore/ops/_grad_experimental/grad_linalg_ops.py +16 -21
- mindspore/ops/_grad_experimental/grad_math_ops.py +979 -49
- mindspore/ops/_grad_experimental/grad_nn_ops.py +78 -8
- mindspore/ops/_grad_experimental/grad_scalar_ops.py +112 -0
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +197 -13
- mindspore/ops/_op_impl/__init__.py +3 -3
- mindspore/ops/_op_impl/_custom_op/__init__.py +0 -1
- mindspore/ops/_op_impl/_custom_op/_basic.py +0 -1
- mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +4 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +5 -5
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +3 -3
- mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/correction_mul.py +3 -3
- mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +4 -8
- mindspore/ops/_op_impl/_custom_op/dsd_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/img2col_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +2 -2
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +2 -2
- mindspore/ops/_op_impl/_custom_op/matmul_dds_grad_impl.py +0 -1
- mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +0 -1
- mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +1 -1
- mindspore/ops/_op_impl/aicpu/__init__.py +238 -3
- mindspore/ops/_op_impl/aicpu/abs.py +36 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d.py +34 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d.py +39 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d_grad.py +39 -0
- mindspore/ops/_op_impl/aicpu/adaptive_max_pool_2d_grad.py +37 -0
- mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d.py +42 -0
- mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d_grad.py +152 -0
- mindspore/ops/_op_impl/aicpu/add.py +43 -0
- mindspore/ops/_op_impl/aicpu/addcdiv.py +0 -32
- mindspore/ops/_op_impl/aicpu/addcmul.py +0 -84
- mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/arg_max.py +75 -0
- mindspore/ops/_op_impl/aicpu/arg_min.py +75 -0
- mindspore/ops/_op_impl/aicpu/argmin_with_value.py +43 -0
- mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -0
- mindspore/ops/_op_impl/aicpu/batch_norm_grad_grad.py +49 -0
- mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
- mindspore/ops/_op_impl/aicpu/bessel_i0.py +31 -0
- mindspore/ops/_op_impl/aicpu/bias_add.py +44 -0
- mindspore/ops/_op_impl/aicpu/bias_add_grad.py +43 -0
- mindspore/ops/_op_impl/aicpu/bincount.py +33 -0
- mindspore/{nn/probability/infer/variational/__init__.py → ops/_op_impl/aicpu/cauchy.py} +17 -10
- mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
- mindspore/ops/_op_impl/aicpu/cholesky.py +1 -1
- mindspore/ops/_op_impl/{cpu/bias_add.py → aicpu/choleskygrad.py} +9 -7
- mindspore/ops/_op_impl/aicpu/combined_non_max_suppression.py +42 -0
- mindspore/ops/_op_impl/aicpu/concat_offset.py +42 -0
- mindspore/ops/_op_impl/aicpu/concat_offset_v1.py +31 -0
- mindspore/ops/_op_impl/aicpu/conj.py +11 -0
- mindspore/ops/_op_impl/aicpu/crop_and_resize_grad_image.py +38 -0
- mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +36 -0
- mindspore/ops/_op_impl/aicpu/deformable_offsets.py +38 -0
- mindspore/ops/_op_impl/aicpu/deformable_offsets_grad.py +2 -2
- mindspore/ops/_op_impl/aicpu/dense_to_sparse_set_operation.py +48 -0
- mindspore/ops/_op_impl/aicpu/diag.py +36 -0
- mindspore/ops/_op_impl/aicpu/diag_part.py +36 -0
- mindspore/ops/_op_impl/aicpu/diagonal.py +35 -0
- mindspore/ops/_op_impl/{cpu/bias_add_grad.py → aicpu/digamma.py} +9 -7
- mindspore/ops/_op_impl/aicpu/eig.py +35 -0
- mindspore/ops/_op_impl/aicpu/fft_with_size.py +41 -0
- mindspore/ops/_op_impl/aicpu/flatten.py +1 -0
- mindspore/ops/_op_impl/aicpu/fmax.py +36 -0
- mindspore/ops/_op_impl/aicpu/fmin.py +37 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_with_fixed_ksize.py +1 -1
- mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -0
- mindspore/ops/_op_impl/aicpu/glu.py +33 -0
- mindspore/ops/_op_impl/aicpu/glu_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/greater.py +41 -0
- mindspore/ops/_op_impl/aicpu/greater_equal.py +41 -0
- mindspore/ops/_op_impl/aicpu/index_put.py +50 -0
- mindspore/ops/_op_impl/{tbe/scatter_add_ds.py → aicpu/inplace_index_add.py} +17 -21
- mindspore/ops/_op_impl/aicpu/instance_norm_v2.py +41 -0
- mindspore/ops/_op_impl/aicpu/instance_norm_v2_grad.py +44 -0
- mindspore/ops/_op_impl/aicpu/layer_norm_grad_grad.py +47 -0
- mindspore/ops/_op_impl/aicpu/less.py +41 -0
- mindspore/ops/_op_impl/aicpu/less_equal.py +41 -0
- mindspore/ops/_op_impl/aicpu/lgamma.py +32 -0
- mindspore/ops/_op_impl/aicpu/log_normal_reverse.py +33 -0
- mindspore/ops/_op_impl/aicpu/logit.py +33 -0
- mindspore/ops/_op_impl/aicpu/logit_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/masked_fill.py +42 -0
- mindspore/ops/_op_impl/aicpu/masked_scatter.py +39 -0
- mindspore/ops/_op_impl/aicpu/matmul.py +39 -0
- mindspore/ops/_op_impl/aicpu/matrix_logarithm.py +31 -0
- mindspore/ops/_op_impl/aicpu/matrix_power.py +32 -0
- mindspore/ops/_op_impl/aicpu/matrix_solve_ls.py +36 -0
- mindspore/ops/_op_impl/aicpu/matrix_triangular_solve.py +36 -0
- mindspore/ops/_op_impl/aicpu/mirror_pad.py +2 -0
- mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +0 -4
- mindspore/ops/_op_impl/aicpu/mul.py +3 -1
- mindspore/ops/_op_impl/aicpu/multinomial.py +14 -6
- mindspore/ops/_op_impl/aicpu/multinomial_with_replacement.py +35 -0
- mindspore/ops/_op_impl/aicpu/nan_to_num.py +34 -0
- mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
- mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
- mindspore/ops/_op_impl/aicpu/ones_like.py +0 -2
- mindspore/ops/_op_impl/aicpu/polar.py +32 -0
- mindspore/ops/_op_impl/aicpu/polygamma.py +34 -0
- mindspore/ops/_op_impl/aicpu/qr.py +36 -0
- mindspore/ops/_op_impl/aicpu/quant_dtype_cast.py +40 -0
- mindspore/ops/_op_impl/aicpu/quantile.py +35 -0
- mindspore/ops/_op_impl/aicpu/ragged_tensor_to_sparse.py +73 -0
- mindspore/ops/_op_impl/aicpu/ragged_tensor_to_tensor.py +74 -0
- mindspore/ops/_op_impl/aicpu/random_shuffle.py +3 -0
- mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
- mindspore/ops/_op_impl/aicpu/range.py +36 -0
- mindspore/ops/_op_impl/aicpu/reciprocal.py +34 -0
- mindspore/ops/_op_impl/aicpu/reciprocal_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/reduce_sum.py +57 -0
- mindspore/ops/_op_impl/aicpu/resize_bicubic.py +2 -8
- mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +1 -1
- mindspore/ops/_op_impl/aicpu/resize_v2.py +68 -0
- mindspore/ops/_op_impl/aicpu/resize_v2_grad.py +68 -0
- mindspore/ops/_op_impl/aicpu/scatter_elements.py +4 -0
- mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +2 -0
- mindspore/ops/_op_impl/aicpu/search_sorted.py +12 -6
- mindspore/ops/_op_impl/aicpu/self_adjoint_eig.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_add.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_add_offset.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_addn.py +38 -0
- mindspore/ops/_op_impl/aicpu/slice_grad.py +76 -0
- mindspore/ops/_op_impl/aicpu/smooth_l1_loss.py +35 -0
- mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
- mindspore/ops/_op_impl/aicpu/sort.py +39 -0
- mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +0 -24
- mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
- mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows.py +63 -0
- mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows_grad.py +45 -0
- mindspore/ops/_op_impl/aicpu/sparse_matrix_mat_mul.py +56 -0
- mindspore/ops/_op_impl/{tbe/slice_ds.py → aicpu/sparse_segment_sum.py} +16 -24
- mindspore/ops/_op_impl/aicpu/sparse_segment_sum_with_num_segments.py +68 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice.py +63 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +61 -0
- mindspore/ops/_op_impl/aicpu/squared_difference.py +2 -0
- mindspore/ops/_op_impl/aicpu/strided_slice_v2.py +93 -0
- mindspore/ops/_op_impl/aicpu/strided_slice_v2_grad.py +66 -0
- mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
- mindspore/ops/_op_impl/{tbe/gather_v2.py → aicpu/tile.py} +24 -24
- mindspore/ops/_op_impl/aicpu/tridiagonal_solve.py +35 -0
- mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
- mindspore/ops/_op_impl/aicpu/triu_indices.py +34 -0
- mindspore/ops/_op_impl/aicpu/uniform.py +34 -0
- mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +1 -0
- mindspore/ops/_op_impl/aicpu/unique_consecutive.py +10 -2
- mindspore/ops/_op_impl/cpu/__init__.py +1 -2
- mindspore/ops/_op_impl/cpu/dynamic_shape.py +5 -1
- mindspore/ops/_op_impl/cpu/maximum_grad.py +2 -0
- mindspore/{compression/common/__init__.py → ops/_op_impl/cpu/pyexecute.py} +13 -8
- mindspore/ops/_op_impl/cpu/reduce_sum.py +8 -0
- mindspore/ops/_op_impl/cpu/sparse_slice.py +62 -0
- mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +60 -0
- mindspore/ops/_op_impl/cpu/tensor_shape.py +5 -1
- mindspore/ops/_op_impl/tbe/__init__.py +27 -608
- mindspore/ops/_op_impl/tbe/addcdiv_ds.py +42 -0
- mindspore/ops/_op_impl/tbe/addcmul_ds.py +44 -0
- mindspore/ops/_op_impl/tbe/assign_add_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/atomic_addr_clean.py +1 -1
- mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +1 -1
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -1
- mindspore/ops/_op_impl/tbe/batch_to_space.py +1 -1
- mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +1 -1
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +41 -0
- mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +1 -0
- mindspore/ops/_op_impl/tbe/bias_add_grad.py +2 -0
- mindspore/ops/_op_impl/tbe/bn_infer_grad.py +4 -2
- mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +40 -0
- mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -1
- mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -1
- mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +6 -4
- mindspore/ops/_op_impl/tbe/cast.py +0 -2
- mindspore/ops/_op_impl/tbe/cast_ds.py +3 -3
- mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -2
- mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -2
- mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/deformable_offsets.py +1 -0
- mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +1 -1
- mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +1 -1
- mindspore/ops/_op_impl/tbe/gather_nd.py +1 -0
- mindspore/ops/_op_impl/tbe/greater.py +2 -0
- mindspore/ops/_op_impl/tbe/{index_add.py → inplace_index_add.py} +3 -6
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -1
- mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +35 -0
- mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +35 -0
- mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -6
- mindspore/ops/_op_impl/tbe/{greater_ds.py → reduce_all_ds.py} +13 -16
- mindspore/ops/_op_impl/tbe/reduce_any_ds.py +39 -0
- mindspore/ops/_op_impl/tbe/roi_align_ds.py +44 -0
- mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +44 -0
- mindspore/ops/_op_impl/tbe/scatter_add.py +2 -0
- mindspore/ops/_op_impl/tbe/scatter_nd_add.py +2 -2
- mindspore/ops/_op_impl/tbe/slice.py +26 -15
- mindspore/ops/_op_impl/tbe/space_to_batch.py +1 -1
- mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +1 -1
- mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +1 -0
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +15 -5
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +1 -1
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +2 -0
- mindspore/ops/_primitive_cache.py +3 -2
- mindspore/ops/_register_for_op.py +11 -0
- mindspore/ops/_utils/__init__.py +1 -1
- mindspore/ops/_utils/utils.py +20 -41
- mindspore/ops/_vmap/__init__.py +2 -2
- mindspore/ops/_vmap/vmap_array_ops.py +170 -78
- mindspore/ops/_vmap/vmap_base.py +24 -10
- mindspore/ops/_vmap/vmap_convolution_ops.py +7 -10
- mindspore/ops/_vmap/vmap_grad_math_ops.py +4 -4
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +41 -9
- mindspore/ops/_vmap/vmap_image_ops.py +52 -0
- mindspore/ops/_vmap/vmap_math_ops.py +77 -6
- mindspore/ops/_vmap/vmap_nn_ops.py +78 -29
- mindspore/ops/_vmap/vmap_other_ops.py +3 -1
- mindspore/ops/_vmap/vmap_random_ops.py +55 -3
- mindspore/ops/_vmap/vmap_sparse_ops.py +1 -0
- mindspore/ops/bprop_mindir/AdaptiveAvgPool2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/AdaptiveMaxPool2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ApproximateEqual_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/Argmax_bprop.mindir +13 -12
- mindspore/ops/bprop_mindir/Argmin_bprop.mindir +14 -13
- mindspore/ops/bprop_mindir/AssignSub_bprop.mindir +17 -18
- mindspore/ops/bprop_mindir/Assign_bprop.mindir +16 -16
- mindspore/ops/bprop_mindir/AvgPool3D_bprop.mindir +150 -0
- mindspore/ops/bprop_mindir/AvgPool_bprop.mindir +66 -0
- mindspore/ops/bprop_mindir/BCEWithLogitsLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BNTrainingReduce_bprop.mindir +13 -12
- mindspore/ops/bprop_mindir/BatchNormGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BatchToSpaceND_bprop.mindir +28 -0
- mindspore/ops/bprop_mindir/BiasAddGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BinaryCrossEntropy_bprop.mindir +33 -0
- mindspore/ops/bprop_mindir/BroadcastTo_bprop.mindir +306 -0
- mindspore/ops/bprop_mindir/Broadcast_bprop.mindir +12 -8
- mindspore/ops/bprop_mindir/CTCLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Concat_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Conv2DBackpropFilter_bprop.mindir +240 -0
- mindspore/ops/bprop_mindir/Conv2DBackpropInput_bprop.mindir +247 -0
- mindspore/ops/bprop_mindir/Conv2DTranspose_bprop.mindir +247 -0
- mindspore/ops/bprop_mindir/Conv3DTranspose_bprop.mindir +315 -0
- mindspore/ops/bprop_mindir/Conv3D_bprop.mindir +278 -0
- mindspore/ops/bprop_mindir/DType_bprop.mindir +12 -12
- mindspore/ops/bprop_mindir/DeformableOffsets_bprop.mindir +58 -0
- mindspore/ops/bprop_mindir/Depend_bprop.mindir +12 -13
- mindspore/ops/bprop_mindir/DepthToSpace_bprop.mindir +23 -0
- mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +138 -0
- mindspore/ops/bprop_mindir/DiagPart_bprop.mindir +15 -0
- mindspore/ops/bprop_mindir/Dropout2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Dropout3D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DropoutDoMask_bprop.mindir +22 -24
- mindspore/ops/bprop_mindir/DropoutGenMask_bprop.mindir +16 -14
- mindspore/ops/bprop_mindir/DropoutGrad_bprop.mindir +27 -0
- mindspore/ops/bprop_mindir/Dropout_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DynamicGRUV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DynamicRNN_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DynamicShape_bprop.mindir +12 -12
- mindspore/ops/bprop_mindir/Elu_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Equal_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/ExpandDims_bprop.mindir +58 -0
- mindspore/ops/bprop_mindir/FastGeLU_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Flatten_bprop.mindir +54 -0
- mindspore/ops/bprop_mindir/FloorDiv_bprop.mindir +18 -15
- mindspore/ops/bprop_mindir/GatherD_bprop.mindir +26 -0
- mindspore/ops/bprop_mindir/GatherNd_bprop.mindir +57 -0
- mindspore/ops/bprop_mindir/Gather_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/GreaterEqual_bprop.mindir +17 -18
- mindspore/ops/bprop_mindir/Greater_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/HSigmoid_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/HSwish_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/IOU_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/InstanceNorm_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/IsFinite_bprop.mindir +13 -12
- mindspore/ops/bprop_mindir/IsInf_bprop.mindir +13 -10
- mindspore/ops/bprop_mindir/IsNan_bprop.mindir +14 -11
- mindspore/ops/bprop_mindir/KLDivLoss_bprop.mindir +126 -0
- mindspore/ops/bprop_mindir/L2Loss_bprop.mindir +15 -0
- mindspore/ops/bprop_mindir/L2Normalize_bprop.mindir +30 -0
- mindspore/ops/bprop_mindir/LRN_bprop.mindir +43 -0
- mindspore/ops/bprop_mindir/LayerNormGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/LessEqual_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/Less_bprop.mindir +17 -18
- mindspore/ops/bprop_mindir/LinSpace_bprop.mindir +22 -19
- mindspore/ops/bprop_mindir/Load_bprop.mindir +12 -13
- mindspore/ops/bprop_mindir/LogSoftmax_bprop.mindir +23 -0
- mindspore/ops/bprop_mindir/LogicalAnd_bprop.mindir +17 -18
- mindspore/ops/bprop_mindir/LogicalNot_bprop.mindir +14 -13
- mindspore/ops/bprop_mindir/MaskedSelect_bprop.mindir +21 -0
- mindspore/ops/bprop_mindir/MaxPool3DGradGrad_bprop.mindir +74 -0
- mindspore/ops/bprop_mindir/MaxPool3DGrad_bprop.mindir +74 -0
- mindspore/ops/bprop_mindir/MaxPool3D_bprop.mindir +75 -0
- mindspore/ops/bprop_mindir/MaxPoolGradGrad_bprop.mindir +65 -0
- mindspore/ops/bprop_mindir/MaxPoolWithArgmax_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Maximum_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Minimum_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/MirrorPad_bprop.mindir +27 -0
- mindspore/ops/bprop_mindir/Mish_bprop.mindir +35 -0
- mindspore/ops/bprop_mindir/MulNoNan_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/NLLLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/NonZero_bprop.mindir +14 -0
- mindspore/ops/bprop_mindir/NotEqual_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/OneHot_bprop.mindir +25 -23
- mindspore/ops/bprop_mindir/OnesLike_bprop.mindir +13 -13
- mindspore/ops/bprop_mindir/PReLU_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Pad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Padding_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/RNNTLoss_bprop.mindir +29 -0
- mindspore/ops/bprop_mindir/ROIAlign_bprop.mindir +82 -0
- mindspore/ops/bprop_mindir/Range_bprop.mindir +21 -19
- mindspore/ops/bprop_mindir/Rank_bprop.mindir +11 -11
- mindspore/ops/bprop_mindir/ReLU6_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/ReLUV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ReduceAll_bprop.mindir +18 -17
- mindspore/ops/bprop_mindir/ReduceAny_bprop.mindir +18 -17
- mindspore/ops/bprop_mindir/ReluGrad_bprop.mindir +19 -23
- mindspore/ops/bprop_mindir/Reshape_bprop.mindir +60 -0
- mindspore/ops/bprop_mindir/ResizeBilinear_bprop.mindir +29 -0
- mindspore/ops/bprop_mindir/ResizeNearestNeighbor_bprop.mindir +89 -0
- mindspore/ops/bprop_mindir/ReverseSequence_bprop.mindir +52 -0
- mindspore/ops/bprop_mindir/ReverseV2_bprop.mindir +22 -0
- mindspore/ops/bprop_mindir/Round_bprop.mindir +14 -13
- mindspore/ops/bprop_mindir/ScatterMax_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ScatterMin_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ScatterNdUpdate_bprop.mindir +22 -0
- mindspore/ops/bprop_mindir/ScatterNd_bprop.mindir +24 -0
- mindspore/ops/bprop_mindir/ScatterNonAliasingAdd_bprop.mindir +22 -0
- mindspore/ops/bprop_mindir/ScatterUpdate_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/SeLU_bprop.mindir +21 -0
- mindspore/ops/bprop_mindir/Select_bprop.mindir +30 -34
- mindspore/ops/bprop_mindir/Shape_bprop.mindir +12 -12
- mindspore/ops/bprop_mindir/SigmoidCrossEntropyWithLogits_bprop.mindir +21 -0
- mindspore/ops/bprop_mindir/SigmoidGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Sigmoid_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Sign_bprop.mindir +13 -12
- mindspore/ops/bprop_mindir/Slice_bprop.mindir +26 -0
- mindspore/ops/bprop_mindir/SmoothL1Loss_bprop.mindir +36 -0
- mindspore/ops/bprop_mindir/SoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Softplus_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Softsign_bprop.mindir +33 -0
- mindspore/ops/bprop_mindir/Sort_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/SpaceToBatchND_bprop.mindir +28 -0
- mindspore/ops/bprop_mindir/SpaceToDepth_bprop.mindir +23 -0
- mindspore/ops/bprop_mindir/SparseGatherV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Split_bprop.mindir +22 -0
- mindspore/ops/bprop_mindir/Squeeze_bprop.mindir +54 -0
- mindspore/ops/bprop_mindir/StridedSliceGrad_bprop.mindir +95 -0
- mindspore/ops/bprop_mindir/StridedSlice_bprop.mindir +98 -0
- mindspore/ops/bprop_mindir/Switch_bprop.mindir +28 -32
- mindspore/ops/bprop_mindir/TanhGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Tanh_bprop.mindir +66 -0
- mindspore/ops/bprop_mindir/TensorScatterAdd_bprop.mindir +22 -0
- mindspore/ops/bprop_mindir/TensorScatterUpdate_bprop.mindir +29 -0
- mindspore/ops/bprop_mindir/TensorShape_bprop.mindir +14 -0
- mindspore/ops/bprop_mindir/Tile_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TopK_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TransShape_bprop.mindir +23 -0
- mindspore/ops/bprop_mindir/TruncateDiv_bprop.mindir +18 -15
- mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +11 -13
- mindspore/ops/bprop_mindir/Unique_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Unstack_bprop.mindir +22 -0
- mindspore/ops/bprop_mindir/UpsampleNearest3D_bprop.mindir +32 -0
- mindspore/ops/bprop_mindir/UpsampleTrilinear3D_bprop.mindir +38 -0
- mindspore/ops/bprop_mindir/ZerosLike_bprop.mindir +13 -12
- mindspore/ops/bprop_mindir/__init__.py +1 -4
- mindspore/ops/bprop_mindir/generate_mindir.py +32 -20
- mindspore/ops/composite/__init__.py +12 -13
- mindspore/ops/composite/base.py +261 -254
- mindspore/ops/composite/env_ops.py +41 -0
- mindspore/ops/composite/math_ops.py +197 -156
- mindspore/ops/composite/multitype_ops/_compile_utils.py +428 -176
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +188 -87
- mindspore/ops/composite/multitype_ops/add_impl.py +23 -1
- mindspore/ops/composite/multitype_ops/div_impl.py +3 -3
- mindspore/ops/composite/multitype_ops/equal_impl.py +1 -0
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +1 -1
- mindspore/ops/composite/multitype_ops/getitem_impl.py +52 -5
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/greater_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/in_impl.py +15 -3
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +33 -2
- mindspore/ops/composite/multitype_ops/less_impl.py +33 -0
- mindspore/ops/composite/multitype_ops/logical_and_impl.py +2 -2
- mindspore/ops/composite/multitype_ops/logical_or_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/mod_impl.py +1 -1
- mindspore/ops/composite/multitype_ops/mul_impl.py +21 -7
- mindspore/ops/composite/multitype_ops/not_in_impl.py +15 -3
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -4
- mindspore/ops/composite/multitype_ops/pow_impl.py +1 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +62 -70
- mindspore/ops/composite/multitype_ops/sub_impl.py +3 -3
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +41 -4
- mindspore/ops/function/__init__.py +323 -8
- mindspore/ops/function/array_func.py +3511 -780
- mindspore/ops/function/clip_func.py +329 -0
- mindspore/ops/function/debug_func.py +6 -6
- mindspore/ops/function/grad/__init__.py +5 -1
- mindspore/ops/function/grad/grad_func.py +736 -65
- mindspore/ops/function/image_func.py +270 -0
- mindspore/ops/function/linalg_func.py +268 -8
- mindspore/ops/function/math_func.py +8032 -3164
- mindspore/ops/function/nn_func.py +5619 -1855
- mindspore/ops/function/other_func.py +115 -0
- mindspore/ops/function/parameter_func.py +11 -10
- mindspore/ops/function/random_func.py +939 -77
- mindspore/ops/function/sparse_func.py +249 -84
- mindspore/ops/function/sparse_unary_func.py +2303 -0
- mindspore/ops/function/spectral_func.py +146 -0
- mindspore/ops/function/vmap_func.py +114 -0
- mindspore/ops/functional.py +182 -254
- mindspore/ops/op_info_register.py +79 -34
- mindspore/ops/operations/__init__.py +210 -118
- mindspore/ops/operations/_csr_ops.py +7 -7
- mindspore/ops/operations/_embedding_cache_ops.py +25 -15
- mindspore/ops/operations/_grad_ops.py +447 -322
- mindspore/ops/operations/_inner_ops.py +547 -176
- mindspore/ops/operations/_map_tensor_ops.py +112 -0
- mindspore/ops/operations/_ms_kernel.py +29 -27
- mindspore/ops/operations/_ocr_ops.py +11 -11
- mindspore/ops/operations/_opaque_predicate_registry.py +41 -0
- mindspore/ops/operations/_quant_ops.py +186 -101
- mindspore/ops/operations/_rl_inner_ops.py +122 -61
- mindspore/ops/operations/_scalar_ops.py +466 -0
- mindspore/ops/operations/_sequence_ops.py +1047 -0
- mindspore/ops/operations/_tensor_array.py +10 -11
- mindspore/ops/operations/_thor_ops.py +4 -4
- mindspore/ops/operations/array_ops.py +1428 -1226
- mindspore/ops/operations/comm_ops.py +180 -117
- mindspore/ops/operations/control_ops.py +4 -2
- mindspore/ops/operations/custom_ops.py +185 -98
- mindspore/ops/operations/debug_ops.py +92 -54
- mindspore/ops/operations/image_ops.py +406 -211
- mindspore/ops/operations/inner_ops.py +42 -53
- mindspore/ops/operations/linalg_ops.py +32 -29
- mindspore/ops/operations/math_ops.py +2076 -897
- mindspore/ops/operations/nn_ops.py +1282 -1252
- mindspore/ops/operations/other_ops.py +124 -278
- mindspore/ops/operations/random_ops.py +345 -178
- mindspore/ops/operations/rl_ops.py +8 -9
- mindspore/ops/operations/sparse_ops.py +502 -157
- mindspore/ops/operations/spectral_ops.py +107 -0
- mindspore/ops/primitive.py +192 -15
- mindspore/ops/vm_impl_registry.py +23 -2
- mindspore/parallel/__init__.py +6 -1
- mindspore/parallel/_auto_parallel_context.py +199 -92
- mindspore/parallel/_cell_wrapper.py +4 -2
- mindspore/parallel/_cost_model_context.py +3 -0
- mindspore/parallel/_dp_allreduce_fusion.py +2 -1
- mindspore/parallel/_offload_context.py +185 -0
- mindspore/parallel/_parallel_serialization.py +167 -28
- mindspore/parallel/_ps_context.py +9 -5
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +9 -1
- mindspore/{nn/transformer → parallel/_transformer}/__init__.py +6 -6
- mindspore/{nn/transformer → parallel/_transformer}/layers.py +59 -37
- mindspore/{nn/transformer → parallel/_transformer}/loss.py +4 -7
- mindspore/{nn/transformer → parallel/_transformer}/moe.py +160 -35
- mindspore/{nn/transformer → parallel/_transformer}/op_parallel_config.py +3 -3
- mindspore/{nn/transformer → parallel/_transformer}/transformer.py +235 -196
- mindspore/parallel/_utils.py +47 -7
- mindspore/parallel/algo_parameter_config.py +5 -1
- mindspore/parallel/checkpoint_transform.py +329 -0
- mindspore/parallel/shard.py +229 -0
- mindspore/profiler/__init__.py +2 -1
- mindspore/profiler/common/util.py +4 -3
- mindspore/profiler/common/validator/validate_path.py +2 -2
- mindspore/profiler/envprofiling.py +249 -0
- mindspore/profiler/parser/aicpu_data_parser.py +38 -39
- mindspore/profiler/parser/ascend_timeline_generator.py +497 -0
- mindspore/profiler/parser/base_timeline_generator.py +471 -0
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +684 -0
- mindspore/profiler/parser/framework_parser.py +42 -16
- mindspore/profiler/parser/hccl_parser.py +158 -158
- mindspore/profiler/parser/hwts_log_parser.py +7 -6
- mindspore/profiler/parser/integrator.py +18 -1579
- mindspore/profiler/parser/minddata_analyzer.py +8 -8
- mindspore/profiler/parser/msadvisor_analyzer.py +14 -27
- mindspore/profiler/parser/msadvisor_parser.py +2 -4
- mindspore/profiler/parser/optime_parser.py +17 -18
- mindspore/profiler/parser/profiler_info.py +108 -0
- mindspore/profiler/parser/step_trace_parser.py +1 -1
- mindspore/profiler/profiling.py +396 -194
- mindspore/rewrite/__init__.py +6 -2
- mindspore/rewrite/api/node.py +51 -110
- mindspore/rewrite/api/node_type.py +10 -6
- mindspore/rewrite/api/pattern_engine.py +51 -7
- mindspore/rewrite/api/scoped_value.py +64 -53
- mindspore/rewrite/api/symbol_tree.py +108 -61
- mindspore/rewrite/api/tree_node_helper.py +2 -3
- mindspore/{compression/quant/__init__.py → rewrite/ast_creator_register.py} +20 -11
- mindspore/rewrite/ast_helpers/__init__.py +6 -3
- mindspore/rewrite/ast_helpers/ast_creator.py +115 -0
- mindspore/rewrite/ast_helpers/ast_finder.py +99 -1
- mindspore/rewrite/ast_helpers/ast_modifier.py +17 -4
- mindspore/rewrite/ast_helpers/ast_replacer.py +1 -1
- mindspore/rewrite/ast_transformers/__init__.py +0 -1
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +46 -5
- mindspore/rewrite/ast_transformers/remove_return_out_of_if.py +6 -3
- mindspore/rewrite/common/__init__.py +2 -0
- mindspore/rewrite/common/event.py +1 -1
- mindspore/rewrite/common/observable.py +1 -1
- mindspore/rewrite/common/observer.py +1 -1
- mindspore/rewrite/common/rewrite_elog.py +35 -0
- mindspore/rewrite/namer.py +2 -2
- mindspore/rewrite/namespace.py +14 -4
- mindspore/rewrite/node.py +161 -13
- mindspore/rewrite/parser.py +0 -1
- mindspore/rewrite/parser_register.py +0 -1
- mindspore/rewrite/parsers/arguments_parser.py +3 -2
- mindspore/rewrite/parsers/assign_parser.py +267 -67
- mindspore/rewrite/parsers/attribute_parser.py +56 -0
- mindspore/rewrite/parsers/class_def_parser.py +191 -108
- mindspore/rewrite/parsers/constant_parser.py +101 -0
- mindspore/rewrite/parsers/container_parser.py +88 -0
- mindspore/rewrite/parsers/for_parser.py +28 -15
- mindspore/rewrite/parsers/function_def_parser.py +21 -5
- mindspore/rewrite/parsers/if_parser.py +11 -28
- mindspore/rewrite/parsers/module_parser.py +9 -6
- mindspore/rewrite/parsers/return_parser.py +3 -2
- mindspore/rewrite/sparsify/__init__.py +0 -0
- mindspore/rewrite/sparsify/sparse_transformer.py +448 -0
- mindspore/rewrite/sparsify/sparsify.py +109 -0
- mindspore/rewrite/sparsify/utils.py +173 -0
- mindspore/rewrite/symbol_tree.py +322 -109
- mindspore/rewrite/symbol_tree_builder.py +45 -8
- mindspore/rewrite/symbol_tree_dumper.py +0 -1
- mindspore/rewrite/topological_manager.py +1 -2
- mindspore/run_check/_check_version.py +209 -112
- mindspore/run_check/run_check.py +2 -1
- mindspore/scipy/linalg.py +13 -117
- mindspore/scipy/ops.py +5 -71
- mindspore/scipy/ops_grad.py +1 -25
- mindspore/scipy/ops_wrapper.py +1 -1
- mindspore/scipy/optimize/_bfgs.py +1 -1
- mindspore/scipy/optimize/_lagrange.py +200 -0
- mindspore/scipy/optimize/line_search.py +3 -2
- mindspore/scipy/optimize/minimize.py +43 -6
- mindspore/scipy/sparse/__init__.py +2 -2
- mindspore/scipy/sparse/linalg.py +5 -465
- mindspore/scipy/utils.py +2 -1
- mindspore/scipy/utils_const.py +7 -1
- mindspore/train/__init__.py +6 -4
- mindspore/train/_utils.py +28 -5
- mindspore/train/amp.py +321 -50
- mindspore/train/callback/__init__.py +3 -1
- mindspore/train/callback/_backup_and_restore.py +120 -0
- mindspore/train/callback/_callback.py +8 -8
- mindspore/train/callback/_checkpoint.py +12 -9
- mindspore/train/callback/_early_stop.py +13 -7
- mindspore/train/callback/_history.py +8 -8
- mindspore/train/callback/_lambda_callback.py +6 -6
- mindspore/train/callback/_landscape.py +36 -38
- mindspore/train/callback/_loss_monitor.py +12 -6
- mindspore/train/callback/_lr_scheduler_callback.py +2 -4
- mindspore/train/callback/_on_request_exit.py +212 -0
- mindspore/train/callback/_reduce_lr_on_plateau.py +13 -7
- mindspore/train/callback/_summary_collector.py +27 -19
- mindspore/train/callback/_time_monitor.py +13 -7
- mindspore/train/checkpoint_pb2.py +68 -8
- mindspore/train/data_sink.py +122 -33
- mindspore/train/dataset_helper.py +28 -87
- mindspore/train/loss_scale_manager.py +4 -7
- mindspore/{nn → train}/metrics/__init__.py +20 -20
- mindspore/{nn → train}/metrics/accuracy.py +12 -10
- mindspore/{nn → train}/metrics/auc.py +4 -4
- mindspore/{nn → train}/metrics/bleu_score.py +4 -4
- mindspore/{nn → train}/metrics/confusion_matrix.py +10 -8
- mindspore/{nn → train}/metrics/cosine_similarity.py +4 -4
- mindspore/{nn → train}/metrics/dice.py +6 -5
- mindspore/{nn → train}/metrics/error.py +7 -5
- mindspore/{nn → train}/metrics/fbeta.py +9 -7
- mindspore/{nn → train}/metrics/hausdorff_distance.py +8 -6
- mindspore/{nn → train}/metrics/loss.py +4 -3
- mindspore/{nn → train}/metrics/mean_surface_distance.py +6 -5
- mindspore/{nn → train}/metrics/metric.py +6 -5
- mindspore/{nn → train}/metrics/occlusion_sensitivity.py +4 -3
- mindspore/{nn → train}/metrics/perplexity.py +5 -4
- mindspore/{nn → train}/metrics/precision.py +5 -4
- mindspore/{nn → train}/metrics/recall.py +5 -4
- mindspore/{nn → train}/metrics/roc.py +7 -6
- mindspore/{nn → train}/metrics/root_mean_square_surface_distance.py +6 -5
- mindspore/{nn → train}/metrics/topk.py +7 -5
- mindspore/train/mind_ir_pb2.py +339 -32
- mindspore/train/model.py +113 -84
- mindspore/train/serialization.py +547 -167
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/train/summary/summary_record.py +43 -12
- mindspore/train/train_thor/convert_utils.py +7 -1
- mindspore/train/train_thor/dataset_helper.py +3 -3
- mindspore/train/train_thor/model_thor.py +0 -4
- mindspore/version.py +1 -1
- {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/METADATA +4 -3
- {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/RECORD +899 -675
- mindspore/compression/common/constant.py +0 -124
- mindspore/compression/export/__init__.py +0 -19
- mindspore/compression/export/quant_export.py +0 -514
- mindspore/compression/quant/qat.py +0 -636
- mindspore/compression/quant/quant_utils.py +0 -462
- mindspore/compression/quant/quantizer.py +0 -68
- mindspore/nn/layer/quant.py +0 -1868
- mindspore/nn/layer/rnn_utils.py +0 -90
- mindspore/nn/probability/dpn/__init__.py +0 -22
- mindspore/nn/probability/dpn/vae/__init__.py +0 -25
- mindspore/nn/probability/dpn/vae/cvae.py +0 -138
- mindspore/nn/probability/dpn/vae/vae.py +0 -122
- mindspore/nn/probability/infer/__init__.py +0 -22
- mindspore/nn/probability/infer/variational/elbo.py +0 -70
- mindspore/nn/probability/infer/variational/svi.py +0 -84
- mindspore/nn/probability/toolbox/__init__.py +0 -22
- mindspore/nn/probability/toolbox/anomaly_detection.py +0 -99
- mindspore/nn/probability/toolbox/uncertainty_evaluation.py +0 -363
- mindspore/nn/probability/transforms/__init__.py +0 -22
- mindspore/nn/probability/transforms/transform_bnn.py +0 -262
- mindspore/nn/probability/zhusuan/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/framework/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/framework/bn.py +0 -95
- mindspore/nn/probability/zhusuan/variational/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/variational/elbo.py +0 -46
- mindspore/ops/_op_impl/tbe/bias_add_grad_ds.py +0 -52
- mindspore/ops/_op_impl/tbe/scatter_nd_add_ds.py +0 -43
- mindspore/ops/bprop_mindir/AssignAdd_bprop.mindir +0 -20
- mindspore/ops/bprop_mindir/Identity_bprop.mindir +0 -9
- mindspore/ops/bprop_mindir/LogicalOr_bprop.mindir +0 -20
- mindspore/ops/bprop_mindir/ReLU_bprop.mindir +0 -16
- mindspore/ops/bprop_mindir/UpdateState_bprop.mindir +0 -17
- mindspore/ops/bprop_mindir/stop_gradient_bprop.mindir +0 -12
- mindspore/ops/composite/array_ops.py +0 -210
- mindspore/ops/composite/clip_ops.py +0 -238
- mindspore/ops/composite/random_ops.py +0 -426
- mindspore/ops/composite/vmap_ops.py +0 -38
- mindspore/ops/operations/sponge_ops.py +0 -3531
- mindspore/ops/operations/sponge_update_ops.py +0 -2546
- mindspore/parallel/nn/__init__.py +0 -42
- mindspore/parallel/nn/loss.py +0 -22
- mindspore/parallel/nn/moe.py +0 -21
- mindspore/parallel/nn/op_parallel_config.py +0 -22
- mindspore/parallel/nn/transformer.py +0 -31
- mindspore/run_check/_check_deps_version.py +0 -84
- {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/entry_points.txt +0 -0
- {mindspore-1.10.0.dist-info → mindspore-2.0.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -18,6 +18,7 @@ from typing import NamedTuple
|
|
|
18
18
|
from ...common import Tensor
|
|
19
19
|
from ._bfgs import minimize_bfgs
|
|
20
20
|
from ._lbfgs import minimize_lbfgs
|
|
21
|
+
from ._lagrange import minimize_lagrange
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
class OptimizeResults(NamedTuple):
|
|
@@ -47,10 +48,25 @@ class OptimizeResults(NamedTuple):
|
|
|
47
48
|
nit: int
|
|
48
49
|
|
|
49
50
|
|
|
51
|
+
def lagrange_para_check(func, constraints, options, tol):
|
|
52
|
+
"""check the parameter of lagrange method."""
|
|
53
|
+
|
|
54
|
+
if not callable(func):
|
|
55
|
+
raise TypeError("'func' must be of type function, but got {}".format(type(func)))
|
|
56
|
+
if 'coincide_func' in options:
|
|
57
|
+
if not callable(options['coincide_fun']):
|
|
58
|
+
raise TypeError("'coincide_fun' must be of type function, but got {}".format(type(options['coincide_fun'])))
|
|
59
|
+
for constraint in constraints:
|
|
60
|
+
if not callable(constraint):
|
|
61
|
+
raise TypeError("'constraint' must be of type function, but got {}".format(type(constraint)))
|
|
62
|
+
if tol is not None:
|
|
63
|
+
if len(tol) != len(constraints):
|
|
64
|
+
raise ValueError("The len of tol must be same as the len of constraints")
|
|
65
|
+
|
|
66
|
+
|
|
50
67
|
def minimize(func, x0, args=(), method=None, jac=None, hess=None, hessp=None, bounds=None, constraints=(),
|
|
51
68
|
tol=None, callback=None, options=None):
|
|
52
|
-
r"""
|
|
53
|
-
Minimization of scalar function of one or more variables.
|
|
69
|
+
r"""Minimization of scalar function of one or more variables.
|
|
54
70
|
|
|
55
71
|
This API for this function matches SciPy with some minor deviations:
|
|
56
72
|
|
|
@@ -67,6 +83,7 @@ def minimize(func, x0, args=(), method=None, jac=None, hess=None, hessp=None, bo
|
|
|
67
83
|
multi-dimensional Tensor, but support for both is planned.
|
|
68
84
|
|
|
69
85
|
- `minimize` is not supported on Windows platform yet.
|
|
86
|
+
- `LAGRANGE` method is only supported on "GPU".
|
|
70
87
|
|
|
71
88
|
Args:
|
|
72
89
|
func (Callable): the objective function to be minimized, :math:`fun(x, *args) -> float`,
|
|
@@ -76,28 +93,42 @@ def minimize(func, x0, args=(), method=None, jac=None, hess=None, hessp=None, bo
|
|
|
76
93
|
x0 (Tensor): initial guess. Array of real elements of size :math:`(n,)`, where `n` is
|
|
77
94
|
the number of independent variables.
|
|
78
95
|
args (Tuple): extra arguments passed to the objective function. Default: ().
|
|
79
|
-
method (str): solver type. Should be one of `"BFGS"` and `"LBFGS"`.
|
|
96
|
+
method (str): solver type. Should be one of `"BFGS"` and `"LBFGS"`, `"LAGRANGE"`.
|
|
80
97
|
jac (Callable, optional): method for computing the gradient vector. Only for `"BFGS"` and `"LBFGS"`.
|
|
81
98
|
if it is None, the gradient will be estimated with gradient of ``func``.
|
|
82
99
|
if it is a callable, it should be a function that returns the gradient vector:
|
|
83
100
|
:math:`jac(x, *args) -> array\_like, shape (n,)`
|
|
84
|
-
where x is an array with shape (n,) and args is a tuple with the fixed parameters.
|
|
101
|
+
where x is an array with shape :math:`(n,)` and args is a tuple with the fixed parameters.
|
|
85
102
|
tol (float, optional): tolerance for termination. For detailed control, use solver-specific
|
|
86
103
|
options. Default: None.
|
|
104
|
+
constraints(Callable, optional): representing the inequality constrains, each function in constrains indicates
|
|
105
|
+
the function < 0 as an inequality constrain.
|
|
87
106
|
options (Mapping[str, Any], optional): a dictionary of solver options. All methods accept the following
|
|
88
107
|
generic options, Default: None.
|
|
89
108
|
|
|
90
109
|
- history_size (int): size of buffer used to help to update inv hessian, only used with method="LBFGS".
|
|
91
110
|
Default: 20.
|
|
92
|
-
|
|
93
111
|
- maxiter (int): Maximum number of iterations to perform. Depending on the
|
|
94
112
|
method each iteration may use several function evaluations.
|
|
95
113
|
|
|
114
|
+
The follow options are exclusive to Lagrange method:
|
|
115
|
+
|
|
116
|
+
- save_tol (list): list of saving tolerance, with the same length with 'constrains'.
|
|
117
|
+
- obj_weight (float): weight for objective function, usually between 1.0 - 100000.0.
|
|
118
|
+
- lower (Tensor): lower bound constrain for variables, must have same shape with x0.
|
|
119
|
+
- upper (Tensor): upper bound constrain for variables, must have same shape with x0.
|
|
120
|
+
- learning_rate (float): learning rate for each Adam step.
|
|
121
|
+
- coincide_func (Callable): sub-function representing the common parts between objective function
|
|
122
|
+
and constrains to avoid redundant computation.
|
|
123
|
+
- rounds (int): times to update Lagrange multipliers.
|
|
124
|
+
- steps (int): steps to apply Adam per round.
|
|
125
|
+
- log_sw (bool): whether to print the loss at each step.
|
|
126
|
+
|
|
96
127
|
Returns:
|
|
97
128
|
OptimizeResults, object holding optimization results.
|
|
98
129
|
|
|
99
130
|
Supported Platforms:
|
|
100
|
-
``
|
|
131
|
+
``GPU`` ``CPU``
|
|
101
132
|
|
|
102
133
|
Examples:
|
|
103
134
|
>>> import numpy as onp
|
|
@@ -156,4 +187,10 @@ def minimize(func, x0, args=(), method=None, jac=None, hess=None, hessp=None, bo
|
|
|
156
187
|
njev=results.ngev,
|
|
157
188
|
nit=results.k)
|
|
158
189
|
|
|
190
|
+
|
|
191
|
+
if method.lower() == 'lagrange':
|
|
192
|
+
lagrange_para_check(func, constraints, options, tol)
|
|
193
|
+
results = minimize_lagrange(func, x0, constraints, tol, **options)
|
|
194
|
+
return results
|
|
195
|
+
|
|
159
196
|
raise ValueError("Method {} not recognized".format(method))
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
# ============================================================================
|
|
15
15
|
"""Sparse submodule"""
|
|
16
16
|
from . import linalg
|
|
17
|
-
from .linalg import cg
|
|
17
|
+
from .linalg import cg
|
|
18
18
|
|
|
19
|
-
__all__ = ["cg"
|
|
19
|
+
__all__ = ["cg"]
|
mindspore/scipy/sparse/linalg.py
CHANGED
|
@@ -16,342 +16,11 @@
|
|
|
16
16
|
from ... import nn
|
|
17
17
|
from ... import numpy as mnp
|
|
18
18
|
from ...ops import functional as F
|
|
19
|
-
from ...
|
|
20
|
-
from ...common import Tensor, CSRTensor, COOTensor, dtype as mstype
|
|
19
|
+
from ...common import Tensor, CSRTensor
|
|
21
20
|
from ...ops.composite.multitype_ops.zeros_like_impl import zeros_like
|
|
22
|
-
from ..
|
|
23
|
-
from ..linalg import cho_factor, cho_solve
|
|
24
|
-
from ..utils import _to_tensor, _safe_normalize, _eps, _norm, _type_check, _value_check, \
|
|
21
|
+
from ..utils import _to_tensor, _norm, _type_check, _value_check, \
|
|
25
22
|
_sparse_check, _matvec
|
|
26
|
-
from ..utils_const import
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def gram_schmidt(Q, q):
|
|
30
|
-
"""Do Gram–Schmidt process to normalize vector v"""
|
|
31
|
-
h = mnp.dot(Q.T, q)
|
|
32
|
-
Qh = mnp.dot(Q, h)
|
|
33
|
-
q = q - Qh
|
|
34
|
-
return q, h
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def arnoldi_iteration(k, A, M, V, H):
|
|
38
|
-
"""Performs a single (the k'th) step of the Arnoldi process."""
|
|
39
|
-
v_ = V[..., k]
|
|
40
|
-
v = _matvec(M, _matvec(A, v_))
|
|
41
|
-
v, h = gram_schmidt(V, v)
|
|
42
|
-
_, v_norm_0 = _safe_normalize(v)
|
|
43
|
-
tol = _eps(v) * v_norm_0
|
|
44
|
-
unit_v, v_norm_1 = _safe_normalize(v, tol)
|
|
45
|
-
V[..., k + 1] = unit_v
|
|
46
|
-
h[k + 1] = v_norm_1
|
|
47
|
-
H[k, :] = h
|
|
48
|
-
breakdown = v_norm_1 == 0
|
|
49
|
-
return V, H, breakdown
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def rotate_vectors(H, i, cs, sn):
|
|
53
|
-
"""Rotate vectors."""
|
|
54
|
-
x1 = H[i]
|
|
55
|
-
y1 = H[i + 1]
|
|
56
|
-
x2 = cs * x1 - sn * y1
|
|
57
|
-
y2 = sn * x1 + cs * y1
|
|
58
|
-
H[i] = x2
|
|
59
|
-
H[i + 1] = y2
|
|
60
|
-
return H
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def _high_precision_cho_solve(a, b, data_type=mstype.float64):
|
|
64
|
-
"""As a core computing module of gmres, cholesky solver must explicitly cast to double precision."""
|
|
65
|
-
a = a.astype(mstype.float64)
|
|
66
|
-
b = b.astype(mstype.float64)
|
|
67
|
-
a_a = mnp.dot(a, a.T)
|
|
68
|
-
a_b = mnp.dot(a, b)
|
|
69
|
-
c, lower = cho_factor(a_a, lower=False)
|
|
70
|
-
factor = (c, lower)
|
|
71
|
-
y = cho_solve(factor, a_b)
|
|
72
|
-
return y.astype(data_type)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def _batch_gmres(A, b, x0, tol, restart, maxiter, M, atol):
|
|
76
|
-
"""
|
|
77
|
-
batched gmres: solve the least squares problem from scratch at the end of each GMRES iteration.
|
|
78
|
-
It does not allow for early termination, but has much less overhead on GPUs.
|
|
79
|
-
"""
|
|
80
|
-
# Constant tensor which avoids loop unrolling
|
|
81
|
-
const_int_zero = _to_tensor(0)
|
|
82
|
-
dtype = b.dtype
|
|
83
|
-
_, b_norm = _safe_normalize(b)
|
|
84
|
-
atol = mnp.maximum(tol * b_norm, _to_tensor(atol), dtype=dtype)
|
|
85
|
-
residual = _matvec(M, b - _matvec(A, x0))
|
|
86
|
-
unit_residual, residual_norm = _safe_normalize(residual)
|
|
87
|
-
k = const_int_zero
|
|
88
|
-
x = x0
|
|
89
|
-
while k < maxiter and residual_norm > atol:
|
|
90
|
-
pad_width = ((0, 0),) * unit_residual.ndim + ((0, restart),)
|
|
91
|
-
V = mnp.pad(unit_residual[..., None], pad_width=pad_width)
|
|
92
|
-
H = mnp.eye(restart, restart + 1, dtype=dtype)
|
|
93
|
-
k_iter = const_int_zero
|
|
94
|
-
breakdown = _to_tensor(False)
|
|
95
|
-
while k_iter < restart and mnp.logical_not(breakdown):
|
|
96
|
-
V, H, breakdown = arnoldi_iteration(k_iter, A, M, V, H)
|
|
97
|
-
k_iter += 1
|
|
98
|
-
beta_vec = mnp.zeros((restart + 1,), dtype=dtype)
|
|
99
|
-
beta_vec[0] = residual_norm
|
|
100
|
-
y = _high_precision_cho_solve(H, beta_vec, data_type=dtype)
|
|
101
|
-
dx = mnp.dot(V[..., :-1], y)
|
|
102
|
-
x = x + dx
|
|
103
|
-
residual = _matvec(M, b - _matvec(A, x))
|
|
104
|
-
unit_residual, residual_norm = _safe_normalize(residual)
|
|
105
|
-
k += 1
|
|
106
|
-
return x, F.select(residual_norm > atol, k, const_int_zero)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def _incremental_gmres(A, b, x0, tol, restart, maxiter, M, atol):
|
|
110
|
-
"""
|
|
111
|
-
incremental gmres: builds a QR decomposition for the Krylov subspace incrementally during
|
|
112
|
-
the GMRES process using Givens rotations. This improves numerical stability and gives a free estimate of
|
|
113
|
-
the residual norm that allows for early termination within a single "restart".
|
|
114
|
-
"""
|
|
115
|
-
const_int_zero = _to_tensor(0)
|
|
116
|
-
_, b_norm = _safe_normalize(b)
|
|
117
|
-
atol = mnp.maximum(tol * b_norm, atol)
|
|
118
|
-
|
|
119
|
-
Mb = _matvec(M, b)
|
|
120
|
-
_, Mb_norm = _safe_normalize(Mb)
|
|
121
|
-
ptol = Mb_norm * mnp.minimum(1.0, atol / b_norm)
|
|
122
|
-
|
|
123
|
-
r = _matvec(M, b - _matvec(A, x0))
|
|
124
|
-
r, r_norm = _safe_normalize(r)
|
|
125
|
-
|
|
126
|
-
iters = const_int_zero
|
|
127
|
-
while iters < maxiter and r_norm > atol:
|
|
128
|
-
V = mnp.pad(r[..., None], ((0, 0),) * r.ndim + ((0, restart),))
|
|
129
|
-
dtype = mnp.result_type(b)
|
|
130
|
-
# Use eye() to avoid constructing a singular matrix in case of early
|
|
131
|
-
# Termination
|
|
132
|
-
R = mnp.eye(restart, restart + 1, dtype=dtype)
|
|
133
|
-
givens = mnp.zeros((restart, 2), dtype=dtype)
|
|
134
|
-
beta_vec = mnp.zeros((restart + 1), dtype=dtype)
|
|
135
|
-
beta_vec[0] = r_norm
|
|
136
|
-
|
|
137
|
-
k = const_int_zero
|
|
138
|
-
err = r_norm
|
|
139
|
-
while mnp.logical_and(mnp.less(k, restart), mnp.less(ptol, err)):
|
|
140
|
-
V, R, _ = arnoldi_iteration(k, A, M, V, R)
|
|
141
|
-
# Givens rotation
|
|
142
|
-
row_k = R[k, :]
|
|
143
|
-
i = const_int_zero
|
|
144
|
-
while i < k:
|
|
145
|
-
row_k = rotate_vectors(row_k, i, givens[i, 0], givens[i, 1])
|
|
146
|
-
i += 1
|
|
147
|
-
|
|
148
|
-
if row_k[k + 1] == 0:
|
|
149
|
-
givens[k, 0] = 1
|
|
150
|
-
givens[k, 1] = 0
|
|
151
|
-
else:
|
|
152
|
-
increase = mnp.absolute(row_k[k]) < mnp.absolute(row_k[k + 1])
|
|
153
|
-
t = mnp.where(increase, -row_k[k] / row_k[k + 1], -row_k[k + 1] / row_k[k])
|
|
154
|
-
r = 1 / F.sqrt(1 + mnp.absolute(t) ** 2)
|
|
155
|
-
givens[k, 0] = mnp.where(increase, r * t, r)
|
|
156
|
-
givens[k, 1] = mnp.where(increase, r, r * t)
|
|
157
|
-
|
|
158
|
-
R[k, :] = rotate_vectors(row_k, k, givens[k, 0], givens[k, 1])
|
|
159
|
-
beta_vec = rotate_vectors(beta_vec, k, givens[k, 0], givens[k, 1])
|
|
160
|
-
err = mnp.absolute(beta_vec[k + 1])
|
|
161
|
-
k += 1
|
|
162
|
-
|
|
163
|
-
y = solve_triangular(R[:, :-1], beta_vec[:-1], trans='T', lower=True)
|
|
164
|
-
dx = mnp.dot(V[:, :-1], y)
|
|
165
|
-
|
|
166
|
-
x = x0 + dx
|
|
167
|
-
r = _matvec(M, b - _matvec(A, x))
|
|
168
|
-
r, r_norm = _safe_normalize(r)
|
|
169
|
-
x0 = x
|
|
170
|
-
iters += 1
|
|
171
|
-
return x0, F.select(r_norm > atol, iters, const_int_zero)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
class GMRES(nn.Cell):
|
|
175
|
-
"""
|
|
176
|
-
Given given A and b, GMRES solves the linear system:
|
|
177
|
-
|
|
178
|
-
.. math::
|
|
179
|
-
A x = b
|
|
180
|
-
"""
|
|
181
|
-
|
|
182
|
-
def __init__(self, A, M, solve_method):
|
|
183
|
-
super(GMRES, self).__init__()
|
|
184
|
-
self.A = A
|
|
185
|
-
self.M = M
|
|
186
|
-
self.solve_method = solve_method
|
|
187
|
-
|
|
188
|
-
def construct(self, b, x0, tol, restart, maxiter, atol):
|
|
189
|
-
# Constant tensor which avoids loop unrolling
|
|
190
|
-
x = x0
|
|
191
|
-
info = _to_tensor(0)
|
|
192
|
-
if self.solve_method == 'batched':
|
|
193
|
-
x, info = _batch_gmres(self.A, b, x0, tol, restart, maxiter, self.M, atol)
|
|
194
|
-
elif self.solve_method == "incremental":
|
|
195
|
-
x, info = _incremental_gmres(self.A, b, x0, tol, restart, maxiter, self.M, atol)
|
|
196
|
-
else:
|
|
197
|
-
_raise_value_error("solve_method should be in ('incremental' or 'batched'), but got ", self.solve_method,
|
|
198
|
-
".")
|
|
199
|
-
return x, info
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
class GMRESV2(nn.Cell):
|
|
203
|
-
"""
|
|
204
|
-
This is a new version of GMRES, which contains all parameters in a graph.
|
|
205
|
-
"""
|
|
206
|
-
|
|
207
|
-
def __init__(self, solve_method):
|
|
208
|
-
super(GMRESV2, self).__init__()
|
|
209
|
-
self.solve_method = solve_method
|
|
210
|
-
|
|
211
|
-
def transpose(self, a):
|
|
212
|
-
if isinstance(a, CSRTensor):
|
|
213
|
-
a_coo = a.to_coo()
|
|
214
|
-
row_indices = a_coo.indices[:, 0]
|
|
215
|
-
col_indices = a_coo.indices[:, 1]
|
|
216
|
-
coo_indices = P.Stack(1)([col_indices, row_indices])
|
|
217
|
-
a_t_coo = COOTensor(coo_indices, a_coo.values, a_coo.shape)
|
|
218
|
-
a_t_csr = a_t_coo.to_csr()
|
|
219
|
-
return a_t_csr
|
|
220
|
-
return a.T
|
|
221
|
-
|
|
222
|
-
def construct(self, A, b, x0, tol, restart, maxiter, M, atol):
|
|
223
|
-
x = x0
|
|
224
|
-
info = _to_tensor(0)
|
|
225
|
-
if self.solve_method == 'batched':
|
|
226
|
-
x, info = _batch_gmres(A, b, x0, tol, restart, maxiter, M, atol)
|
|
227
|
-
elif self.solve_method == "incremental":
|
|
228
|
-
x, info = _incremental_gmres(A, b, x0, tol, restart, maxiter, M, atol)
|
|
229
|
-
else:
|
|
230
|
-
_raise_value_error("solve_method should be in ('incremental' or 'batched'), but got ", self.solve_method,
|
|
231
|
-
".")
|
|
232
|
-
return x, info
|
|
233
|
-
|
|
234
|
-
def bprop(self, A, b, x0, tol, restart, maxiter, M, atol, out, dout):
|
|
235
|
-
"""
|
|
236
|
-
Derivatives of `gmres` are implemented via implicit differentiation with
|
|
237
|
-
another `gmres` solve, rather than by differentiating *through* the solver.
|
|
238
|
-
They will be accurate only if both solves converge.
|
|
239
|
-
"""
|
|
240
|
-
n = b.shape[0]
|
|
241
|
-
if not isinstance(M, (Tensor, CSRTensor)):
|
|
242
|
-
M = F.eye(n, n, b.dtype)
|
|
243
|
-
A_T = self.transpose(A)
|
|
244
|
-
grad_b, _ = self.construct(A_T, dout[0], x0, tol, restart, maxiter, M, atol)
|
|
245
|
-
if isinstance(A, CSRTensor):
|
|
246
|
-
grad_a_dense = -1 * F.reshape(grad_b, (n, 1)) * F.reshape(out[0], (1, n))
|
|
247
|
-
values = F.csr_gather(A.indptr, A.indices, grad_a_dense, A.shape)
|
|
248
|
-
grad_a = CSRTensor(A.indptr, A.indices, values, A.shape)
|
|
249
|
-
else:
|
|
250
|
-
grad_a = -1 * F.reshape(grad_b, (n, 1)) * F.reshape(out[0], (1, n))
|
|
251
|
-
return grad_a, grad_b, zeros_like(x0), zeros_like(tol), zeros_like(atol), zeros_like(maxiter), zeros_like(M)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
def gmres(A, b, x0=None, *, tol=1e-5, restart=20, maxiter=None,
|
|
255
|
-
M=None, callback=None, restrt=None, atol=0.0, callback_type=None, solve_method='batched'):
|
|
256
|
-
"""
|
|
257
|
-
Given given A and b, GMRES solves the linear system:
|
|
258
|
-
|
|
259
|
-
.. math::
|
|
260
|
-
A x = b
|
|
261
|
-
|
|
262
|
-
A is specified as a function performing A(vi) -> vf = A @ vi, and in principle
|
|
263
|
-
need not have any particular special properties, such as symmetry. However,
|
|
264
|
-
convergence is often slow for nearly symmetric operators.
|
|
265
|
-
|
|
266
|
-
Note:
|
|
267
|
-
- `gmres` is not supported on Windows platform yet.
|
|
268
|
-
|
|
269
|
-
Args:
|
|
270
|
-
A (Union[Tensor, function]): 2D Tensor or function that calculates the linear
|
|
271
|
-
map (matrix-vector product) :math:`Ax` when called like :math:`A(x)`.
|
|
272
|
-
As function, `A` must return Tensor with the same structure and shape as its input matrix.
|
|
273
|
-
b (Tensor): Right hand side of the linear system representing a single vector.
|
|
274
|
-
Can be stored as a Tensor.
|
|
275
|
-
x0 (Tensor, optional): Starting guess for the solution. Must have the same structure
|
|
276
|
-
as `b`. If this is unspecified, zeroes are used. Default: None.
|
|
277
|
-
tol (float, optional): Tolerances for convergence,
|
|
278
|
-
:math:`norm(residual) <= max(tol*norm(b), atol)`. We do not implement SciPy's
|
|
279
|
-
"legacy" behavior, so MindSpore's tolerance will differ from SciPy unless you
|
|
280
|
-
explicitly pass `atol` to SciPy's `gmres`. Default: 1e-5.
|
|
281
|
-
restart (integer, optional): Size of the Krylov subspace ("number of iterations")
|
|
282
|
-
built between restarts. GMRES works by approximating the true solution x as its
|
|
283
|
-
projection into a Krylov space of this dimension - this parameter
|
|
284
|
-
therefore bounds the maximum accuracy achievable from any guess
|
|
285
|
-
solution. Larger values increase both number of iterations and iteration
|
|
286
|
-
cost, but may be necessary for convergence. The algorithm terminates
|
|
287
|
-
early if convergence is achieved before the full subspace is built. Default: 20.
|
|
288
|
-
maxiter (int): Maximum number of times to rebuild the size-`restart`
|
|
289
|
-
Krylov space starting from the solution found at the last iteration. If GMRES
|
|
290
|
-
halts or is very slow, decreasing this parameter may help. Default: None.
|
|
291
|
-
M (Union[Tensor, function]): Preconditioner for A. The preconditioner should approximate the
|
|
292
|
-
inverse of A. Effective preconditioning dramatically improves the
|
|
293
|
-
rate of convergence, which implies that fewer iterations are needed
|
|
294
|
-
to reach a given error tolerance. Default: None.
|
|
295
|
-
callback (function): User-supplied function to call after each iteration. It is called as callback(args),
|
|
296
|
-
where args are selected by callback_type. Default: None.
|
|
297
|
-
restrt (int, optional): Deprecated, use restart instead. Default: None.
|
|
298
|
-
atol (float, optional): The same as `tol`. Default: 0.0.
|
|
299
|
-
callback_type (str, optional): Callback function argument requested:
|
|
300
|
-
Default: None.
|
|
301
|
-
|
|
302
|
-
- x: current iterate (ndarray), called on every restart
|
|
303
|
-
- pr_norm: relative (preconditioned) residual norm (float), called on every inner iteration
|
|
304
|
-
- legacy (default): same as pr_norm, but also changes the meaning of ‘maxiter’ to count inner
|
|
305
|
-
iterations instead of restart cycles.
|
|
306
|
-
|
|
307
|
-
solve_method (str): There are two kinds of solve methods,'incremental' or 'batched'. Default: "batched".
|
|
308
|
-
|
|
309
|
-
- incremental: builds a QR decomposition for the Krylov subspace incrementally during
|
|
310
|
-
the GMRES process using Givens rotations. This improves numerical stability and gives
|
|
311
|
-
a free estimate of the residual norm that allows for early termination within a single "restart".
|
|
312
|
-
- batched: solve the least squares problem from scratch at the end of each GMRES
|
|
313
|
-
iteration. It does not allow for early termination, but has much less overhead on GPUs.
|
|
314
|
-
|
|
315
|
-
Returns:
|
|
316
|
-
- Tensor, the converged solution. Has the same structure as `b`.
|
|
317
|
-
- Tensor, placeholder for convergence information: 0 : successful exit.
|
|
318
|
-
>0 : convergence to tolerance not achieved, number of iterations. <0 : illegal input or breakdown.
|
|
319
|
-
|
|
320
|
-
Supported Platforms:
|
|
321
|
-
``CPU`` ``GPU``
|
|
322
|
-
|
|
323
|
-
Examples:
|
|
324
|
-
>>> import numpy as onp
|
|
325
|
-
>>> import mindspore.numpy as mnp
|
|
326
|
-
>>> from mindspore.common import Tensor
|
|
327
|
-
>>> from mindspore.scipy.sparse.linalg import gmres
|
|
328
|
-
>>> A = Tensor(mnp.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]], dtype=mnp.float32))
|
|
329
|
-
>>> b = Tensor(mnp.array([2, 4, -1], dtype=mnp.float32))
|
|
330
|
-
>>> x, exitCode = gmres(A, b)
|
|
331
|
-
>>> print(exitCode) # 0 indicates successful convergence
|
|
332
|
-
0
|
|
333
|
-
>>> print(onp.allclose(mnp.dot(A,x).asnumpy(), b.asnumpy()))
|
|
334
|
-
True
|
|
335
|
-
"""
|
|
336
|
-
func_name = "gmres"
|
|
337
|
-
A, M, b, x0 = _sparse_check(func_name, A, M, b, x0)
|
|
338
|
-
size = b.size
|
|
339
|
-
if maxiter is None:
|
|
340
|
-
maxiter = 10 * size # copied from scipy
|
|
341
|
-
_type_check(func_name, tol, float, 'tol')
|
|
342
|
-
_type_check(func_name, restart, int, 'restart')
|
|
343
|
-
_type_check(func_name, maxiter, int, 'maxiter')
|
|
344
|
-
_type_check(func_name, solve_method, str, 'solve_method')
|
|
345
|
-
_value_check(func_name, callback, None, 'callback', op='is', fmt='todo')
|
|
346
|
-
_value_check(func_name, restrt, None, 'restrt', op='is', fmt='todo')
|
|
347
|
-
_value_check(func_name, callback_type, None, 'callback_type', op='is', fmt='todo')
|
|
348
|
-
if restart > size:
|
|
349
|
-
restart = size
|
|
350
|
-
if not is_within_graph(A):
|
|
351
|
-
x, info = GMRES(A, M, solve_method)(b, x0, tol, restart, maxiter, atol)
|
|
352
|
-
else:
|
|
353
|
-
x, info = GMRESV2(solve_method)(A, b, x0, tol, restart, maxiter, M, atol)
|
|
354
|
-
return x, info
|
|
23
|
+
from ..utils_const import is_within_graph
|
|
355
24
|
|
|
356
25
|
|
|
357
26
|
def _cg(A, b, x0, tol, atol, maxiter, M):
|
|
@@ -493,7 +162,7 @@ def cg(A, b, x0=None, *, tol=1e-5, atol=0.0, maxiter=None, M=None, callback=None
|
|
|
493
162
|
TypeError: If `A` and `b` don't have the same data types.
|
|
494
163
|
|
|
495
164
|
Supported Platforms:
|
|
496
|
-
``
|
|
165
|
+
``GPU`` ``CPU``
|
|
497
166
|
|
|
498
167
|
Examples:
|
|
499
168
|
>>> import numpy as onp
|
|
@@ -516,137 +185,8 @@ def cg(A, b, x0=None, *, tol=1e-5, atol=0.0, maxiter=None, M=None, callback=None
|
|
|
516
185
|
_type_check(func_name, maxiter, int, 'maxiter')
|
|
517
186
|
_value_check(func_name, callback, None, 'callback', op='is', fmt='todo')
|
|
518
187
|
|
|
519
|
-
if not is_within_graph(
|
|
188
|
+
if not is_within_graph(b):
|
|
520
189
|
x, info = CG(A, M)(b, x0, tol, atol, maxiter)
|
|
521
190
|
else:
|
|
522
191
|
x, info = CGv2()(A, b, x0, tol, atol, maxiter, M)
|
|
523
192
|
return x, info
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
class BiCGStab(nn.Cell):
|
|
527
|
-
"""Figure 2.10 from Barrett R, et al. 'Templates for the sulution of linear systems:
|
|
528
|
-
building blocks for iterative methods', 1994, pg. 24-25
|
|
529
|
-
"""
|
|
530
|
-
|
|
531
|
-
def __init__(self, A, M):
|
|
532
|
-
super(BiCGStab, self).__init__()
|
|
533
|
-
self.A = A
|
|
534
|
-
self.M = M
|
|
535
|
-
|
|
536
|
-
def construct(self, b, x0, tol, atol, maxiter):
|
|
537
|
-
# Constant tensors which avoid loop unrolling
|
|
538
|
-
const_int_zero = _to_tensor(0)
|
|
539
|
-
const_int_neg_one = _to_tensor(-1)
|
|
540
|
-
|
|
541
|
-
const_float_one = _to_tensor(1., dtype=b.dtype)
|
|
542
|
-
atol_ = mnp.maximum(atol, tol * _norm(b))
|
|
543
|
-
|
|
544
|
-
r = r_tilde = v = p = b - _matvec(self.A, x0)
|
|
545
|
-
rho = alpha = omega = const_float_one
|
|
546
|
-
k = const_int_zero
|
|
547
|
-
x = x0
|
|
548
|
-
while k < maxiter:
|
|
549
|
-
rho_ = mnp.dot(r_tilde, r)
|
|
550
|
-
if rho_ == 0. or omega == 0.:
|
|
551
|
-
k = const_int_neg_one
|
|
552
|
-
break
|
|
553
|
-
|
|
554
|
-
beta = rho_ / rho * (alpha / omega)
|
|
555
|
-
p = r + beta * (p - omega * v)
|
|
556
|
-
p_hat = _matvec(self.M, p)
|
|
557
|
-
v = _matvec(self.A, p_hat)
|
|
558
|
-
alpha = rho_ / mnp.dot(r_tilde, v)
|
|
559
|
-
s = r - alpha * v
|
|
560
|
-
x = x + alpha * p_hat
|
|
561
|
-
if _norm(s) <= atol_:
|
|
562
|
-
break
|
|
563
|
-
|
|
564
|
-
s_hat = _matvec(self.M, s)
|
|
565
|
-
t = _matvec(self.A, s_hat)
|
|
566
|
-
omega = mnp.dot(t, s) / mnp.dot(t, t)
|
|
567
|
-
x = x + omega * s_hat
|
|
568
|
-
r = s - omega * t
|
|
569
|
-
if _norm(r) <= atol_:
|
|
570
|
-
break
|
|
571
|
-
|
|
572
|
-
rho = rho_
|
|
573
|
-
k += 1
|
|
574
|
-
|
|
575
|
-
return x, F.select(k == const_int_neg_one or k >= maxiter, k, const_int_zero)
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
def bicgstab(A, b, x0=None, *, tol=1e-5, atol=0.0, maxiter=None, M=None):
|
|
579
|
-
"""Use Bi-Conjugate Gradient Stable iteration to solve :math:`Ax = b`.
|
|
580
|
-
|
|
581
|
-
The numerics of MindSpore's `bicgstab` should exact match SciPy's
|
|
582
|
-
`bicgstab` (up to numerical precision).
|
|
583
|
-
|
|
584
|
-
As with `cg`, derivatives of `bicgstab` are implemented via implicit
|
|
585
|
-
differentiation with another `bicgstab` solve, rather than by
|
|
586
|
-
differentiating *through* the solver. They will be accurate only if
|
|
587
|
-
both solves converge.
|
|
588
|
-
|
|
589
|
-
Note:
|
|
590
|
-
- `bicgstab` is not supported on Windows platform yet.
|
|
591
|
-
|
|
592
|
-
Args:
|
|
593
|
-
A (Union[Tensor, function]): 2D Tensor or function that calculates the linear
|
|
594
|
-
map (matrix-vector product) :math:`Ax` when called like :math:`A(x)`.
|
|
595
|
-
As function, `A` must return Tensor with the same structure and shape as its input matrix.
|
|
596
|
-
b (Tensor): Right hand side of the linear system representing a single vector. Can be
|
|
597
|
-
stored as a Tensor.
|
|
598
|
-
x0 (Tensor): Starting guess for the solution. Must have the same structure as `b`. Default: None.
|
|
599
|
-
tol (float, optional): Tolerances for convergence, :math:`norm(residual) <= max(tol*norm(b), atol)`.
|
|
600
|
-
We do not implement SciPy's "legacy" behavior, so MindSpore's tolerance will
|
|
601
|
-
differ from SciPy unless you explicitly pass `atol` to SciPy's `bicgstab`. Default: 1e-5.
|
|
602
|
-
atol (float, optional): The same as `tol`. Default: 0.0.
|
|
603
|
-
maxiter (int): Maximum number of iterations. Iteration will stop after maxiter
|
|
604
|
-
steps even if the specified tolerance has not been achieved. Default: None.
|
|
605
|
-
M (Union[Tensor, function]): Preconditioner for A. The preconditioner should approximate the
|
|
606
|
-
inverse of A. Effective preconditioning dramatically improves the
|
|
607
|
-
rate of convergence, which implies that fewer iterations are needed
|
|
608
|
-
to reach a given error tolerance. Default: None.
|
|
609
|
-
|
|
610
|
-
Returns:
|
|
611
|
-
- Tensor, the converged solution. Has the same structure as `b`.
|
|
612
|
-
- Tensor, placeholder for convergence information: 0 : successful exit.
|
|
613
|
-
>0 : convergence to tolerance not achieved, number of iterations. <0 : illegal input or breakdown.
|
|
614
|
-
|
|
615
|
-
Raises:
|
|
616
|
-
ValueError: If `x0` and `b` don't have the same structure.
|
|
617
|
-
TypeError: If `A`, `x0` and `b` don't have the same float types(`mstype.float32` or `mstype.float64`).
|
|
618
|
-
|
|
619
|
-
Supported Platforms:
|
|
620
|
-
``CPU`` ``GPU``
|
|
621
|
-
|
|
622
|
-
Examples:
|
|
623
|
-
>>> import numpy as onp
|
|
624
|
-
>>> from mindspore.common import Tensor
|
|
625
|
-
>>> from mindspore.scipy.sparse.linalg import bicgstab
|
|
626
|
-
>>> A = Tensor(onp.array([[1, 2], [2, 1]], dtype='float32'))
|
|
627
|
-
>>> b = Tensor(onp.array([1, -1], dtype='float32'))
|
|
628
|
-
>>> result, info = bicgstab(A, b)
|
|
629
|
-
>>> print(result)
|
|
630
|
-
[-1. 1.]
|
|
631
|
-
>>> print(info)
|
|
632
|
-
0
|
|
633
|
-
"""
|
|
634
|
-
if x0 is None:
|
|
635
|
-
x0 = mnp.zeros_like(b)
|
|
636
|
-
|
|
637
|
-
if maxiter is None:
|
|
638
|
-
maxiter = 10 * b.shape[0]
|
|
639
|
-
|
|
640
|
-
if M is None:
|
|
641
|
-
M = lambda x: x
|
|
642
|
-
|
|
643
|
-
if x0.shape != b.shape:
|
|
644
|
-
_raise_value_error(
|
|
645
|
-
'Input x0 and b must have matching shapes: ', x0.shape, ' vs ', b.shape)
|
|
646
|
-
|
|
647
|
-
if (F.dtype(b) not in (mstype.float32, mstype.float64)) or (F.dtype(b) != F.dtype(x0)) or (
|
|
648
|
-
F.dtype(b) != F.dtype(A)):
|
|
649
|
-
_raise_type_error('Input A, x0 and b must have same float types')
|
|
650
|
-
|
|
651
|
-
x, info = BiCGStab(A, M)(b, x0, tol, atol, maxiter)
|
|
652
|
-
return x, info
|
mindspore/scipy/utils.py
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
# ============================================================================
|
|
15
15
|
"""internal utility functions"""
|
|
16
|
+
from __future__ import division
|
|
16
17
|
from .. import ops
|
|
17
18
|
from .. import numpy as mnp
|
|
18
19
|
from ..numpy import where, zeros_like, dot, greater
|
|
@@ -156,7 +157,7 @@ def _solve_check(func_name, arg1, arg2, arg1_name='a', arg2_name='b', sparse=Fal
|
|
|
156
157
|
|
|
157
158
|
|
|
158
159
|
def _sparse_check(func_name, a, m, b, x0):
|
|
159
|
-
"""Used for cg
|
|
160
|
+
"""Used for cg method."""
|
|
160
161
|
|
|
161
162
|
def _check_right(arg, arg_name):
|
|
162
163
|
if arg is None:
|
mindspore/scipy/utils_const.py
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
from __future__ import absolute_import
|
|
17
17
|
from types import FunctionType
|
|
18
18
|
from collections.abc import Iterable
|
|
19
|
+
from mindspore.ops import functional as F
|
|
19
20
|
from .. import context
|
|
20
21
|
from ..ops.primitive import constexpr
|
|
21
22
|
from ..common import Tensor, CSRTensor
|
|
@@ -29,13 +30,18 @@ def _callable_const(x):
|
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
@constexpr
|
|
33
|
+
def is_pynative():
|
|
34
|
+
"""Returns true if the current mode is PYNATIVE mode."""
|
|
35
|
+
return context.get_context("mode") == context.PYNATIVE_MODE
|
|
36
|
+
|
|
37
|
+
|
|
32
38
|
def is_within_graph(x):
|
|
33
39
|
"""
|
|
34
40
|
Returns true if x is None. It's aim to check whether the call is within MindSpore graph.
|
|
35
41
|
Because in graph mode, x should be None in constexpr when x is a variable of MindSpore.
|
|
36
42
|
Note that always return true if the call is in pynative mode.
|
|
37
43
|
"""
|
|
38
|
-
return
|
|
44
|
+
return is_pynative() or not F.isconstant(x) or x is None
|
|
39
45
|
|
|
40
46
|
|
|
41
47
|
@constexpr
|
mindspore/train/__init__.py
CHANGED
|
@@ -26,19 +26,21 @@ from mindspore.train.amp import build_train_network
|
|
|
26
26
|
from mindspore.train.loss_scale_manager import LossScaleManager, FixedLossScaleManager, DynamicLossScaleManager
|
|
27
27
|
from mindspore.train.serialization import save_checkpoint, load_checkpoint, load_param_into_net, export, \
|
|
28
28
|
load, parse_print, build_searched_strategy, merge_sliced_parameter, load_distributed_checkpoint, \
|
|
29
|
-
async_ckpt_thread_status, restore_group_info_list, convert_model
|
|
29
|
+
async_ckpt_thread_status, restore_group_info_list, convert_model, obfuscate_model
|
|
30
30
|
from mindspore.train.callback import Callback, LossMonitor, TimeMonitor, ModelCheckpoint, SummaryCollector, \
|
|
31
31
|
CheckpointConfig, RunContext, LearningRateScheduler, SummaryLandscape, \
|
|
32
|
-
History, LambdaCallback, ReduceLROnPlateau, EarlyStopping
|
|
32
|
+
History, LambdaCallback, ReduceLROnPlateau, EarlyStopping, OnRequestExit, BackupAndRestore
|
|
33
33
|
from mindspore.train.summary import SummaryRecord
|
|
34
34
|
from mindspore.train.train_thor import ConvertNetUtils, ConvertModelUtils
|
|
35
|
+
from mindspore.train.metrics import *
|
|
35
36
|
from mindspore.train.data_sink import data_sink
|
|
36
37
|
|
|
37
|
-
__all__ = ["Model", "DatasetHelper", "
|
|
38
|
+
__all__ = ["Model", "DatasetHelper", "connect_network_with_dataset", "build_train_network", "LossScaleManager",
|
|
38
39
|
"FixedLossScaleManager", "DynamicLossScaleManager", "save_checkpoint", "load_checkpoint",
|
|
39
40
|
"load_param_into_net", "export", "load", "parse_print", "build_searched_strategy", "merge_sliced_parameter",
|
|
40
41
|
"load_distributed_checkpoint", "async_ckpt_thread_status", "restore_group_info_list", "convert_model",
|
|
41
|
-
"data_sink"]
|
|
42
|
+
"data_sink", "obfuscate_model"]
|
|
42
43
|
__all__.extend(callback.__all__)
|
|
43
44
|
__all__.extend(summary.__all__)
|
|
44
45
|
__all__.extend(train_thor.__all__)
|
|
46
|
+
__all__.extend(metrics.__all__)
|