mindspore 2.1.0__cp39-cp39-win_amd64.whl → 2.2.10__cp39-cp39-win_amd64.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/Microsoft.VisualStudio.Telemetry.dll +0 -0
- mindspore/Newtonsoft.Json.dll +0 -0
- mindspore/__init__.py +4 -1
- mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
- mindspore/_check_jit_forbidden_api.py +3 -1
- mindspore/_checkparam.py +23 -29
- mindspore/_extends/graph_kernel/__init__.py +0 -1
- mindspore/_extends/graph_kernel/model/graph_split.py +84 -76
- mindspore/_extends/graph_kernel/model/model_builder.py +9 -50
- mindspore/_extends/graph_kernel/splitter.py +4 -11
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +122 -15
- mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +84 -67
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +4 -2
- mindspore/_extends/parallel_compile/akg_compiler/util.py +10 -7
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +2 -2
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +6 -5
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job.py +1 -1
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +1 -1
- mindspore/_extends/parse/__init__.py +12 -15
- mindspore/_extends/parse/namespace.py +7 -33
- mindspore/_extends/parse/parser.py +61 -71
- mindspore/_extends/parse/resources.py +1 -1
- mindspore/_extends/parse/standard_method.py +74 -104
- mindspore/_extends/parse/trope.py +1 -1
- mindspore/_extends/remote/kernel_build_server.py +25 -7
- mindspore/_extends/remote/kernel_build_server_akg_v2.py +55 -0
- mindspore/_install_custom.py +43 -0
- mindspore/amp.py +47 -11
- mindspore/atlprov.dll +0 -0
- mindspore/boost/boost.py +1 -8
- mindspore/boost/boost_cell_wrapper.py +3 -2
- mindspore/boost/grad_accumulation.py +1 -1
- mindspore/boost/group_loss_scale_manager.py +8 -7
- mindspore/c1.dll +0 -0
- mindspore/c1xx.dll +0 -0
- mindspore/c2.dll +0 -0
- mindspore/common/__init__.py +5 -3
- mindspore/common/_jit_fallback_utils.py +6 -0
- mindspore/common/_register_for_adapter.py +2 -0
- mindspore/common/_register_for_tensor.py +2 -2
- mindspore/common/_stub_tensor.py +13 -0
- mindspore/common/_utils.py +13 -0
- mindspore/common/api.py +174 -259
- mindspore/common/auto_dynamic_shape.py +494 -0
- mindspore/common/dtype.py +18 -11
- mindspore/common/dump.py +6 -4
- mindspore/common/initializer.py +14 -14
- mindspore/common/jit_config.py +33 -15
- mindspore/common/lazy_inline.py +126 -7
- mindspore/common/mindir_util.py +101 -0
- mindspore/common/parameter.py +51 -41
- mindspore/common/seed.py +4 -4
- mindspore/common/sparse_tensor.py +13 -14
- mindspore/common/tensor.py +243 -165
- mindspore/communication/__init__.py +7 -4
- mindspore/communication/_comm_helper.py +83 -4
- mindspore/communication/management.py +152 -84
- mindspore/config/op_info.config +14 -3
- mindspore/context.py +152 -61
- mindspore/dataset/__init__.py +5 -5
- mindspore/dataset/audio/__init__.py +2 -2
- mindspore/dataset/audio/transforms.py +52 -52
- mindspore/dataset/callback/ds_callback.py +16 -2
- mindspore/dataset/core/config.py +68 -51
- mindspore/dataset/engine/cache_client.py +28 -5
- mindspore/dataset/engine/datasets.py +250 -112
- mindspore/dataset/engine/datasets_audio.py +43 -211
- mindspore/dataset/engine/datasets_standard_format.py +16 -35
- mindspore/dataset/engine/datasets_text.py +43 -67
- mindspore/dataset/engine/datasets_user_defined.py +86 -100
- mindspore/dataset/engine/datasets_vision.py +219 -1029
- mindspore/dataset/engine/iterators.py +11 -4
- mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +4 -0
- mindspore/dataset/engine/obs/util.py +3 -0
- mindspore/dataset/engine/samplers.py +1 -1
- mindspore/dataset/engine/validators.py +19 -5
- mindspore/dataset/text/__init__.py +3 -3
- mindspore/dataset/text/transforms.py +101 -127
- mindspore/dataset/text/utils.py +205 -138
- mindspore/dataset/transforms/__init__.py +1 -1
- mindspore/dataset/transforms/py_transforms_util.py +40 -12
- mindspore/dataset/transforms/transforms.py +95 -40
- mindspore/dataset/utils/browse_dataset.py +8 -2
- mindspore/dataset/utils/line_reader.py +17 -19
- mindspore/dataset/vision/__init__.py +3 -3
- mindspore/dataset/vision/c_transforms.py +6 -3
- mindspore/dataset/vision/transforms.py +409 -287
- mindspore/dataset/vision/utils.py +13 -14
- mindspore/dataset/vision/validators.py +11 -1
- mindspore/dnnl.dll +0 -0
- mindspore/dpcmi.dll +0 -0
- mindspore/experimental/map_parameter.py +14 -0
- mindspore/{nn/optim_ex → experimental/optim}/__init__.py +30 -29
- mindspore/{nn/optim_ex → experimental/optim}/adam.py +60 -67
- mindspore/{nn/optim_ex → experimental/optim}/adamw.py +181 -203
- mindspore/experimental/optim/lr_scheduler.py +1427 -0
- mindspore/{nn/optim_ex → experimental/optim}/optimizer.py +252 -259
- mindspore/{nn/optim_ex → experimental/optim}/sgd.py +147 -152
- mindspore/gen_ops.py +273 -0
- mindspore/include/OWNERS +0 -1
- mindspore/include/api/data_type.h +2 -1
- mindspore/include/api/graph.h +0 -15
- mindspore/include/api/kernel.h +2 -0
- mindspore/include/api/kernel_api.h +37 -12
- mindspore/include/api/model.h +17 -14
- mindspore/include/api/status.h +8 -3
- mindspore/include/api/types.h +37 -4
- mindspore/include/c_api/ms/abstract.h +67 -0
- mindspore/include/c_api/ms/attribute.h +197 -0
- mindspore/include/c_api/ms/base/handle_types.h +43 -0
- mindspore/include/c_api/ms/base/macros.h +32 -0
- mindspore/include/c_api/ms/base/status.h +33 -0
- mindspore/include/c_api/ms/base/types.h +282 -0
- mindspore/include/c_api/ms/context.h +102 -0
- mindspore/include/c_api/ms/graph.h +160 -0
- mindspore/include/c_api/ms/node.h +606 -0
- mindspore/include/c_api/ms/tensor.h +161 -0
- mindspore/include/c_api/ms/value.h +84 -0
- mindspore/include/dataset/constants.h +6 -5
- mindspore/include/dataset/execute.h +23 -13
- mindspore/include/dataset/text.h +26 -26
- mindspore/include/dataset/transforms.h +13 -13
- mindspore/include/dataset/vision.h +60 -60
- mindspore/include/dataset/vision_ascend.h +5 -6
- mindspore/include/dataset/vision_lite.h +17 -17
- mindspore/jpeg62.dll +0 -0
- mindspore/mindrecord/tools/imagenet_to_mr.py +1 -1
- mindspore/mindrecord/tools/mnist_to_mr.py +2 -2
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/msobj140.dll +0 -0
- mindspore/mspdb140.dll +0 -0
- mindspore/mspdbcore.dll +0 -0
- mindspore/mspdbst.dll +0 -0
- mindspore/mspft140.dll +0 -0
- mindspore/msvcdis140.dll +0 -0
- mindspore/msvcp140_1.dll +0 -0
- mindspore/msvcp140_2.dll +0 -0
- mindspore/msvcp140_atomic_wait.dll +0 -0
- mindspore/msvcp140_codecvt_ids.dll +0 -0
- mindspore/nn/__init__.py +0 -2
- mindspore/nn/cell.py +313 -74
- mindspore/nn/dynamic_lr.py +21 -21
- mindspore/nn/layer/activation.py +22 -30
- mindspore/nn/layer/basic.py +15 -13
- mindspore/nn/layer/channel_shuffle.py +1 -1
- mindspore/nn/layer/container.py +271 -9
- mindspore/nn/layer/conv.py +323 -204
- mindspore/nn/layer/dense.py +8 -5
- mindspore/nn/layer/embedding.py +33 -27
- mindspore/nn/layer/flash_attention.py +141 -88
- mindspore/nn/layer/image.py +8 -6
- mindspore/nn/layer/math.py +16 -25
- mindspore/nn/layer/normalization.py +107 -66
- mindspore/nn/layer/padding.py +1 -1
- mindspore/nn/layer/pooling.py +131 -109
- mindspore/nn/layer/rnn_cells.py +27 -22
- mindspore/nn/layer/rnns.py +13 -16
- mindspore/nn/layer/thor_layer.py +1 -1
- mindspore/nn/layer/transformer.py +221 -154
- mindspore/nn/learning_rate_schedule.py +9 -1
- mindspore/nn/loss/loss.py +235 -174
- mindspore/nn/optim/ada_grad.py +2 -1
- mindspore/nn/optim/adadelta.py +1 -0
- mindspore/nn/optim/adafactor.py +2 -1
- mindspore/nn/optim/adam.py +7 -4
- mindspore/nn/optim/adamax.py +3 -2
- mindspore/nn/optim/adasum.py +2 -2
- mindspore/nn/optim/asgd.py +2 -3
- mindspore/nn/optim/ftrl.py +6 -5
- mindspore/nn/optim/lamb.py +7 -4
- mindspore/nn/optim/lars.py +1 -1
- mindspore/nn/optim/lazyadam.py +5 -3
- mindspore/nn/optim/momentum.py +2 -1
- mindspore/nn/optim/optimizer.py +53 -4
- mindspore/nn/optim/proximal_ada_grad.py +3 -4
- mindspore/nn/optim/rmsprop.py +4 -3
- mindspore/nn/optim/rprop.py +23 -12
- mindspore/nn/optim/sgd.py +26 -11
- mindspore/nn/optim/thor.py +9 -7
- mindspore/nn/probability/bijector/bijector.py +5 -5
- mindspore/nn/probability/bijector/power_transform.py +27 -27
- mindspore/nn/probability/bijector/softplus.py +3 -3
- mindspore/nn/probability/distribution/_utils/custom_ops.py +3 -3
- mindspore/nn/probability/distribution/bernoulli.py +5 -5
- mindspore/nn/probability/distribution/beta.py +3 -3
- mindspore/nn/probability/distribution/categorical.py +7 -7
- mindspore/nn/probability/distribution/cauchy.py +0 -1
- mindspore/nn/probability/distribution/distribution.py +3 -3
- mindspore/nn/probability/distribution/gamma.py +3 -3
- mindspore/nn/probability/distribution/geometric.py +4 -4
- mindspore/nn/probability/distribution/gumbel.py +4 -4
- mindspore/nn/probability/distribution/log_normal.py +2 -2
- mindspore/nn/probability/distribution/logistic.py +2 -2
- mindspore/nn/probability/distribution/poisson.py +4 -4
- mindspore/nn/probability/distribution/transformed_distribution.py +3 -3
- mindspore/nn/probability/distribution/uniform.py +6 -6
- mindspore/nn/wrap/cell_wrapper.py +84 -34
- mindspore/nn/wrap/grad_reducer.py +8 -5
- mindspore/nn/wrap/loss_scale.py +105 -42
- mindspore/numpy/array_creations.py +1 -2
- mindspore/numpy/array_ops.py +3 -2
- mindspore/numpy/utils_const.py +5 -5
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/_grad_experimental/__init__.py +0 -5
- mindspore/ops/_grad_experimental/grad_array_ops.py +2 -3
- mindspore/ops/_grad_experimental/grad_comm_ops.py +15 -2
- mindspore/ops/_grad_experimental/grad_debug_ops.py +0 -37
- mindspore/ops/_grad_experimental/grad_implementations.py +11 -1
- mindspore/ops/_grad_experimental/grad_inner_ops.py +2 -216
- mindspore/ops/_grad_experimental/grad_math_ops.py +19 -199
- mindspore/ops/_grad_experimental/grad_sparse.py +15 -0
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
- mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/flash_attention/attention.py +165 -109
- mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_bwd.py +144 -86
- mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_fwd.py +172 -187
- mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_impl.py +51 -57
- mindspore/ops/_op_impl/_custom_op/flash_attention/tik_ops_utils.py +6 -17
- mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/wukong_tiling.py +1 -1
- mindspore/ops/_op_impl/aicpu/__init__.py +14 -2
- mindspore/ops/_op_impl/aicpu/add.py +3 -3
- mindspore/ops/_op_impl/aicpu/bias_add_grad.py +0 -1
- mindspore/ops/_op_impl/aicpu/count_nonzero.py +43 -0
- mindspore/ops/_op_impl/aicpu/eps.py +32 -0
- mindspore/ops/_op_impl/aicpu/gamma.py +2 -2
- mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +6 -3
- mindspore/ops/_op_impl/aicpu/lu_unpack_grad.py +0 -1
- mindspore/ops/_op_impl/aicpu/multinomial.py +3 -3
- mindspore/ops/_op_impl/aicpu/parameterized_truncated_normal.py +15 -7
- mindspore/ops/_op_impl/aicpu/random_categorical.py +39 -19
- mindspore/ops/_op_impl/aicpu/random_choice_with_mask.py +5 -2
- mindspore/ops/_op_impl/aicpu/random_poisson.py +103 -52
- mindspore/ops/_op_impl/aicpu/random_shuffle.py +17 -15
- mindspore/ops/_op_impl/aicpu/{sparseaddmm.py → sparse_addmm.py} +2 -2
- mindspore/ops/_op_impl/aicpu/{sparsesparsemaximum.py → sparse_sparse_maximum.py} +4 -4
- mindspore/ops/_op_impl/aicpu/standard_laplace.py +5 -5
- mindspore/ops/_op_impl/aicpu/standard_normal.py +5 -5
- mindspore/ops/_op_impl/aicpu/truncated_normal.py +9 -7
- mindspore/ops/_op_impl/aicpu/uniform.py +5 -3
- mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +8 -4
- mindspore/ops/_op_impl/aicpu/uniform_int.py +5 -5
- mindspore/ops/_op_impl/aicpu/uniform_real.py +4 -4
- mindspore/ops/_op_impl/tbe/__init__.py +4 -4
- mindspore/ops/_op_impl/tbe/inplace_index_add.py +7 -3
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +2 -0
- mindspore/ops/_primitive_cache.py +1 -1
- mindspore/ops/_tracefunc.py +45 -13
- mindspore/ops/_utils/utils.py +6 -1
- mindspore/ops/_vmap/vmap_array_ops.py +3 -3
- mindspore/ops/_vmap/vmap_base.py +3 -3
- mindspore/ops/_vmap/vmap_convolution_ops.py +1 -1
- mindspore/ops/_vmap/vmap_grad_math_ops.py +6 -4
- mindspore/ops/_vmap/vmap_math_ops.py +5 -2
- mindspore/ops/_vmap/vmap_nn_ops.py +61 -7
- mindspore/ops/arg_dtype_cast.py +54 -0
- mindspore/ops/composite/base.py +37 -10
- mindspore/ops/composite/math_ops.py +5 -4
- mindspore/ops/composite/multitype_ops/_compile_utils.py +275 -73
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +16 -9
- mindspore/ops/composite/multitype_ops/add_impl.py +43 -4
- mindspore/ops/composite/multitype_ops/getitem_impl.py +42 -4
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +9 -0
- mindspore/ops/deprecated.py +304 -0
- mindspore/ops/function/__init__.py +4 -1
- mindspore/ops/function/array_func.py +174 -193
- mindspore/ops/function/clip_func.py +81 -13
- mindspore/ops/function/debug_func.py +1 -1
- mindspore/ops/function/grad/grad_func.py +18 -9
- mindspore/ops/function/image_func.py +10 -4
- mindspore/ops/function/linalg_func.py +5 -5
- mindspore/ops/function/math_func.py +575 -386
- mindspore/ops/function/nn_func.py +568 -260
- mindspore/ops/function/random_func.py +88 -57
- mindspore/ops/function/sparse_func.py +1 -1
- mindspore/ops/function/sparse_unary_func.py +14 -12
- mindspore/ops/function/vmap_func.py +6 -5
- mindspore/ops/functional.py +15 -10
- mindspore/ops/op_info_register.py +244 -25
- mindspore/ops/operations/__init__.py +28 -19
- mindspore/ops/operations/_grad_ops.py +72 -7
- mindspore/ops/operations/_inner_ops.py +350 -17
- mindspore/ops/operations/_quant_ops.py +4 -8
- mindspore/ops/operations/_sequence_ops.py +42 -0
- mindspore/ops/operations/array_ops.py +68 -282
- mindspore/ops/operations/comm_ops.py +107 -59
- mindspore/ops/operations/custom_ops.py +94 -70
- mindspore/ops/operations/debug_ops.py +8 -4
- mindspore/ops/operations/image_ops.py +18 -12
- mindspore/ops/operations/inner_ops.py +26 -3
- mindspore/ops/operations/math_ops.py +189 -141
- mindspore/ops/operations/nn_ops.py +794 -489
- mindspore/ops/operations/other_ops.py +0 -22
- mindspore/ops/operations/random_ops.py +53 -111
- mindspore/ops/operations/sparse_ops.py +3 -1
- mindspore/ops/primitive.py +24 -18
- mindspore/parallel/_auto_parallel_context.py +68 -8
- mindspore/parallel/_cost_model_context.py +2 -2
- mindspore/parallel/_offload_context.py +17 -3
- mindspore/parallel/_parallel_serialization.py +12 -5
- mindspore/parallel/_ps_context.py +12 -0
- mindspore/parallel/_tensor.py +18 -13
- mindspore/parallel/_transformer/layers.py +5 -3
- mindspore/parallel/_transformer/loss.py +1 -0
- mindspore/parallel/_transformer/moe.py +2 -2
- mindspore/parallel/_transformer/op_parallel_config.py +12 -1
- mindspore/parallel/_transformer/transformer.py +23 -3
- mindspore/parallel/_utils.py +11 -7
- mindspore/parallel/algo_parameter_config.py +85 -5
- mindspore/parallel/checkpoint_transform.py +19 -12
- mindspore/parallel/shard.py +21 -14
- mindspore/pgodb140.dll +0 -0
- mindspore/pgort140.dll +0 -0
- mindspore/profiler/common/struct_type.py +3 -3
- mindspore/profiler/common/util.py +4 -2
- mindspore/profiler/envprofiling.py +1 -1
- mindspore/profiler/parser/aicpu_data_parser.py +5 -3
- mindspore/profiler/parser/ascend_flops_generator.py +2 -2
- mindspore/profiler/parser/ascend_fpbp_generator.py +1 -1
- mindspore/profiler/parser/ascend_hccl_generator.py +249 -12
- mindspore/profiler/parser/ascend_msprof_exporter.py +150 -255
- mindspore/profiler/parser/ascend_msprof_generator.py +204 -17
- mindspore/profiler/parser/ascend_op_generator.py +6 -6
- mindspore/profiler/parser/ascend_steptrace_generator.py +6 -4
- mindspore/profiler/parser/ascend_timeline_generator.py +14 -187
- mindspore/profiler/parser/base_timeline_generator.py +10 -8
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +16 -12
- mindspore/profiler/parser/flops_parser.py +15 -11
- mindspore/profiler/parser/framework_parser.py +38 -22
- mindspore/profiler/parser/hccl_parser.py +16 -12
- mindspore/profiler/parser/integrator.py +22 -11
- mindspore/profiler/parser/memory_usage_parser.py +2 -2
- mindspore/profiler/parser/minddata_analyzer.py +12 -14
- mindspore/profiler/parser/minddata_pipeline_parser.py +1 -1
- mindspore/profiler/parser/msadvisor_parser.py +8 -4
- mindspore/profiler/parser/op_intermediate_parser.py +5 -2
- mindspore/profiler/parser/optime_parser.py +1 -1
- mindspore/profiler/parser/profiler_info.py +21 -2
- mindspore/profiler/parser/step_trace_parser.py +11 -14
- mindspore/profiler/profiling.py +179 -89
- mindspore/rewrite/api/node.py +102 -19
- mindspore/rewrite/api/node_type.py +5 -1
- mindspore/rewrite/api/pattern_engine.py +1 -1
- mindspore/rewrite/api/scoped_value.py +9 -17
- mindspore/rewrite/api/symbol_tree.py +131 -47
- mindspore/rewrite/ast_helpers/__init__.py +2 -1
- mindspore/rewrite/ast_helpers/ast_finder.py +129 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +116 -104
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +93 -46
- mindspore/rewrite/common/rewrite_elog.py +5 -1
- mindspore/rewrite/namer.py +33 -24
- mindspore/rewrite/namespace.py +14 -5
- mindspore/{_extends/graph_kernel/expanders/complex → rewrite/node}/__init__.py +9 -9
- mindspore/rewrite/node/call_function.py +79 -0
- mindspore/rewrite/node/cell_container.py +135 -0
- mindspore/rewrite/node/control_flow.py +88 -0
- mindspore/rewrite/{node.py → node/node.py} +273 -234
- mindspore/rewrite/node/node_manager.py +254 -0
- mindspore/rewrite/{topological_manager.py → node/node_topological_manager.py} +13 -46
- mindspore/rewrite/parsers/arguments_parser.py +22 -21
- mindspore/rewrite/parsers/assign_parser.py +216 -221
- mindspore/rewrite/parsers/attribute_parser.py +9 -7
- mindspore/rewrite/parsers/class_def_parser.py +174 -113
- mindspore/rewrite/parsers/constant_parser.py +9 -6
- mindspore/rewrite/parsers/container_parser.py +9 -7
- mindspore/rewrite/parsers/for_parser.py +36 -15
- mindspore/rewrite/parsers/function_def_parser.py +24 -16
- mindspore/rewrite/parsers/if_parser.py +28 -24
- mindspore/rewrite/parsers/module_parser.py +196 -25
- mindspore/rewrite/{parser.py → parsers/parser.py} +4 -2
- mindspore/rewrite/{parser_register.py → parsers/parser_register.py} +1 -1
- mindspore/rewrite/parsers/return_parser.py +6 -6
- mindspore/rewrite/sparsify/sparse_transformer.py +12 -3
- mindspore/rewrite/sparsify/utils.py +1 -1
- mindspore/rewrite/symbol_tree.py +523 -578
- mindspore/rewrite/symbol_tree_builder.py +9 -193
- mindspore/rewrite/symbol_tree_dumper.py +2 -2
- mindspore/run_check/_check_version.py +6 -4
- mindspore/{ops/bprop_mindir → safeguard}/__init__.py +4 -3
- mindspore/safeguard/rewrite_obfuscation.py +541 -0
- mindspore/tbbmalloc.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/_utils.py +7 -3
- mindspore/train/amp.py +323 -123
- mindspore/train/anf_ir_pb2.py +14 -2
- mindspore/train/callback/_backup_and_restore.py +2 -12
- mindspore/train/callback/_callback.py +29 -4
- mindspore/train/callback/_checkpoint.py +23 -8
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_landscape.py +4 -4
- mindspore/train/callback/_loss_monitor.py +2 -2
- mindspore/train/callback/_on_request_exit.py +2 -2
- mindspore/train/callback/_reduce_lr_on_plateau.py +3 -4
- mindspore/train/callback/_summary_collector.py +15 -8
- mindspore/train/callback/_time_monitor.py +58 -5
- mindspore/train/data_sink.py +5 -11
- mindspore/train/dataset_helper.py +84 -57
- mindspore/train/loss_scale_manager.py +2 -2
- mindspore/train/metrics/__init__.py +3 -3
- mindspore/train/metrics/cosine_similarity.py +1 -1
- mindspore/train/metrics/hausdorff_distance.py +3 -2
- mindspore/train/metrics/mean_surface_distance.py +3 -2
- mindspore/train/metrics/metric.py +39 -19
- mindspore/train/metrics/roc.py +2 -2
- mindspore/train/metrics/root_mean_square_surface_distance.py +4 -3
- mindspore/train/mind_ir_pb2.py +85 -36
- mindspore/train/model.py +187 -47
- mindspore/train/serialization.py +487 -161
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/train/summary/_writer_pool.py +3 -2
- mindspore/train/summary/summary_record.py +37 -17
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/train/train_thor/dataset_helper.py +1 -1
- mindspore/turbojpeg.dll +0 -0
- mindspore/vcmeta.dll +0 -0
- mindspore/vcruntime140.dll +0 -0
- mindspore/vcruntime140_1.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.1.0.dist-info → mindspore-2.2.10.dist-info}/METADATA +5 -3
- {mindspore-2.1.0.dist-info → mindspore-2.2.10.dist-info}/RECORD +433 -479
- mindspore/_extends/graph_kernel/expander.py +0 -80
- mindspore/_extends/graph_kernel/expanders/__init__.py +0 -54
- mindspore/_extends/graph_kernel/expanders/_utils.py +0 -269
- mindspore/_extends/graph_kernel/expanders/addn.py +0 -33
- mindspore/_extends/graph_kernel/expanders/batchnorm.py +0 -152
- mindspore/_extends/graph_kernel/expanders/batchnorm_grad.py +0 -105
- mindspore/_extends/graph_kernel/expanders/clip_by_norm_no_div_sum.py +0 -33
- mindspore/_extends/graph_kernel/expanders/complex/abs.py +0 -30
- mindspore/_extends/graph_kernel/expanders/complex/add.py +0 -44
- mindspore/_extends/graph_kernel/expanders/complex/div.py +0 -62
- mindspore/_extends/graph_kernel/expanders/complex/mul.py +0 -52
- mindspore/_extends/graph_kernel/expanders/complex/real_div.py +0 -62
- mindspore/_extends/graph_kernel/expanders/complex/sub.py +0 -45
- mindspore/_extends/graph_kernel/expanders/conv2d.py +0 -200
- mindspore/_extends/graph_kernel/expanders/dropout_grad.py +0 -30
- mindspore/_extends/graph_kernel/expanders/equal_count.py +0 -50
- mindspore/_extends/graph_kernel/expanders/erfc.py +0 -35
- mindspore/_extends/graph_kernel/expanders/expand_dims.py +0 -50
- mindspore/_extends/graph_kernel/expanders/fused_adam.py +0 -44
- mindspore/_extends/graph_kernel/expanders/fused_adam_weight_decay.py +0 -47
- mindspore/_extends/graph_kernel/expanders/fused_mul_add.py +0 -28
- mindspore/_extends/graph_kernel/expanders/gelu_grad.py +0 -70
- mindspore/_extends/graph_kernel/expanders/gkdropout.py +0 -40
- mindspore/_extends/graph_kernel/expanders/identity.py +0 -25
- mindspore/_extends/graph_kernel/expanders/layernorm.py +0 -93
- mindspore/_extends/graph_kernel/expanders/layernorm_grad.py +0 -113
- mindspore/_extends/graph_kernel/expanders/logsoftmax.py +0 -46
- mindspore/_extends/graph_kernel/expanders/logsoftmax_grad.py +0 -36
- mindspore/_extends/graph_kernel/expanders/matmul.py +0 -80
- mindspore/_extends/graph_kernel/expanders/maximum_grad.py +0 -59
- mindspore/_extends/graph_kernel/expanders/minimum_grad.py +0 -80
- mindspore/_extends/graph_kernel/expanders/oneslike.py +0 -26
- mindspore/_extends/graph_kernel/expanders/reduce_mean.py +0 -43
- mindspore/_extends/graph_kernel/expanders/relu_grad.py +0 -32
- mindspore/_extends/graph_kernel/expanders/sigmoid_cross_entropy_with_logits.py +0 -41
- mindspore/_extends/graph_kernel/expanders/sigmoid_cross_entropy_with_logits_grad.py +0 -35
- mindspore/_extends/graph_kernel/expanders/sigmoid_grad.py +0 -31
- mindspore/_extends/graph_kernel/expanders/slice.py +0 -35
- mindspore/_extends/graph_kernel/expanders/softmax_cross_entropy_with_logits.py +0 -42
- mindspore/_extends/graph_kernel/expanders/softmax_grad_ext.py +0 -41
- mindspore/_extends/graph_kernel/expanders/softsign.py +0 -28
- mindspore/_extends/graph_kernel/expanders/sqrt_grad.py +0 -29
- mindspore/_extends/graph_kernel/expanders/square_sum_all.py +0 -44
- mindspore/_extends/graph_kernel/expanders/square_sum_v1.py +0 -37
- mindspore/_extends/graph_kernel/expanders/squared_difference.py +0 -43
- mindspore/_extends/graph_kernel/expanders/tanh_grad.py +0 -31
- mindspore/_extends/graph_kernel/model/op_infer.py +0 -506
- mindspore/dataset/datapreprocess/__init__.py +0 -20
- mindspore/dataset/datapreprocess/preprocess_imagenet_validate_dataset.py +0 -54
- mindspore/include/api/net.h +0 -142
- mindspore/nn/lr_scheduler.py +0 -262
- mindspore/ops/_grad_experimental/grad_image_ops.py +0 -248
- mindspore/ops/_grad_experimental/grad_linalg_ops.py +0 -181
- mindspore/ops/_grad_experimental/grad_other_ops.py +0 -72
- mindspore/ops/_grad_experimental/grad_scalar_ops.py +0 -112
- mindspore/ops/_grad_experimental/grad_sequence_ops.py +0 -351
- mindspore/ops/bprop_mindir/BNTrainingReduce_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Broadcast_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Depend_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +0 -138
- mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Load_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ScatterNonAliasingAdd_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/SparseGatherV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Switch_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TransShape_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Unique_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Unstack_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/generate_mindir.py +0 -114
- mindspore/rewrite/node_visitor.py +0 -44
- {mindspore-2.1.0.dist-info → mindspore-2.2.10.dist-info}/WHEEL +0 -0
- {mindspore-2.1.0.dist-info → mindspore-2.2.10.dist-info}/entry_points.txt +0 -0
- {mindspore-2.1.0.dist-info → mindspore-2.2.10.dist-info}/top_level.txt +0 -0
mindspore/train/model.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright 2020-
|
|
1
|
+
# Copyright 2020-2023 Huawei Technologies Co., Ltd
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -25,6 +25,7 @@ import importlib
|
|
|
25
25
|
import numpy as np
|
|
26
26
|
|
|
27
27
|
import mindspore
|
|
28
|
+
import mindspore.dataset as ds
|
|
28
29
|
from mindspore import log as logger
|
|
29
30
|
from mindspore.train.serialization import save_checkpoint, load_checkpoint
|
|
30
31
|
from mindspore.train.callback._checkpoint import ModelCheckpoint, _chg_ckpt_file_name_if_same_exist
|
|
@@ -188,7 +189,7 @@ class Model:
|
|
|
188
189
|
>>> from mindspore.train import Model
|
|
189
190
|
>>>
|
|
190
191
|
>>> # Define the network structure of LeNet5. Refer to
|
|
191
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
192
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
|
|
192
193
|
>>> net = LeNet5()
|
|
193
194
|
>>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
|
|
194
195
|
>>> optim = nn.Momentum(params=net.trainable_params(), learning_rate=0.1, momentum=0.9)
|
|
@@ -197,7 +198,7 @@ class Model:
|
|
|
197
198
|
>>> model.predict_network
|
|
198
199
|
>>> model.eval_network
|
|
199
200
|
>>> # Create the dataset taking MNIST as an example. Refer to
|
|
200
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
201
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/mnist.py
|
|
201
202
|
>>> dataset = create_dataset()
|
|
202
203
|
>>> model.train(2, dataset)
|
|
203
204
|
"""
|
|
@@ -224,6 +225,7 @@ class Model:
|
|
|
224
225
|
self._check_for_graph_cell(kwargs)
|
|
225
226
|
self._build_boost_network(kwargs)
|
|
226
227
|
self._train_network = self._build_train_network()
|
|
228
|
+
self._train_network._jit_config_dict = network.jit_config_dict
|
|
227
229
|
self._build_eval_network(metrics, self._eval_network, eval_indexes)
|
|
228
230
|
self._build_predict_network()
|
|
229
231
|
self._current_epoch_num = 0
|
|
@@ -232,9 +234,12 @@ class Model:
|
|
|
232
234
|
self.enable_recovery = False
|
|
233
235
|
self._backbone_is_train = True
|
|
234
236
|
self.need_load_ckpt = False
|
|
235
|
-
self.
|
|
237
|
+
self._lite_full_predictor = None
|
|
238
|
+
self._lite_incremental_predictor = None
|
|
236
239
|
self._mindspore_lite = None
|
|
237
240
|
self._lite_infer = True # if backend lite infer fails, set False
|
|
241
|
+
self._mindspore_lite_model_group_id = id(self) & 0xFFFF
|
|
242
|
+
|
|
238
243
|
|
|
239
244
|
def _check_for_graph_cell(self, kwargs):
|
|
240
245
|
"""Check for graph cell"""
|
|
@@ -575,7 +580,6 @@ class Model:
|
|
|
575
580
|
initial_epoch (int): Epoch at which to start train, it used for resuming a previous training run.
|
|
576
581
|
Default: 0.
|
|
577
582
|
"""
|
|
578
|
-
epoch = Validator.check_positive_int(epoch)
|
|
579
583
|
if self._parameter_broadcast:
|
|
580
584
|
self._train_network.set_broadcast_flag()
|
|
581
585
|
|
|
@@ -648,10 +652,10 @@ class Model:
|
|
|
648
652
|
"it is suggested to pad/drop data or adjust sink_size. "
|
|
649
653
|
"But got 'dataset_size': {}, 'sink_size': {}.".format(dataset_size, sink_size))
|
|
650
654
|
if sink_size == -1:
|
|
651
|
-
dataset_sink_num = epoch
|
|
655
|
+
dataset_sink_num = epoch
|
|
652
656
|
else:
|
|
653
|
-
dataset_sink_num = math.ceil(
|
|
654
|
-
train_dataset.__total_batch__ =
|
|
657
|
+
dataset_sink_num = math.ceil(epoch * sink_size / dataset_size)
|
|
658
|
+
train_dataset.__total_batch__ = epoch * sink_size
|
|
655
659
|
|
|
656
660
|
cb_params.cur_step_num = 0
|
|
657
661
|
cb_params.dataset_sink_mode = True
|
|
@@ -684,6 +688,7 @@ class Model:
|
|
|
684
688
|
dataset_helper=dataset_helper)
|
|
685
689
|
|
|
686
690
|
cb_params.train_network = train_network
|
|
691
|
+
cb_params.dataset_helper = dataset_helper
|
|
687
692
|
|
|
688
693
|
# Perform recovery for process which is restarted.
|
|
689
694
|
self._reset_training_step_for_abnormal_process(cb_params, dataset_helper)
|
|
@@ -829,7 +834,7 @@ class Model:
|
|
|
829
834
|
os.remove(cb_params.latest_ckpt_file)
|
|
830
835
|
raise RuntimeError(e.__str__() + ", load ckpt failed and remove the ckpt: "\
|
|
831
836
|
+ cb_params.latest_ckpt_file) from e
|
|
832
|
-
_reset_training_dataset(cb_params.cur_step_num, dataset_helper.
|
|
837
|
+
_reset_training_dataset(cb_params.cur_step_num, dataset_helper.iter.dataset.get_dataset_size())
|
|
833
838
|
self.need_load_ckpt = False
|
|
834
839
|
|
|
835
840
|
def _reset_training_step_for_normal_process(self, cb_params, dataset_helper):
|
|
@@ -858,9 +863,9 @@ class Model:
|
|
|
858
863
|
self.epoch_iter = recovery_epoch_num
|
|
859
864
|
cb_params.cur_epoch_num = self.epoch_iter + 1
|
|
860
865
|
cb_params.last_save_ckpt_step = cb_params.cur_step_num
|
|
861
|
-
_reset_training_dataset(cb_params.cur_step_num, dataset_helper.
|
|
866
|
+
_reset_training_dataset(cb_params.cur_step_num, dataset_helper.iter.dataset.get_dataset_size())
|
|
862
867
|
else:
|
|
863
|
-
_reset_training_dataset(0, dataset_helper.
|
|
868
|
+
_reset_training_dataset(0, dataset_helper.iter.dataset.get_dataset_size())
|
|
864
869
|
|
|
865
870
|
_set_recovery_context(need_reset=False)
|
|
866
871
|
|
|
@@ -884,7 +889,7 @@ class Model:
|
|
|
884
889
|
dataset_helper, _ = self._exec_preprocess(is_train=True,
|
|
885
890
|
dataset=train_dataset,
|
|
886
891
|
dataset_sink_mode=False,
|
|
887
|
-
epoch_num=
|
|
892
|
+
epoch_num=epoch)
|
|
888
893
|
cb_params.cur_step_num = 0
|
|
889
894
|
cb_params.dataset_sink_mode = False
|
|
890
895
|
run_context = RunContext(cb_params)
|
|
@@ -962,7 +967,7 @@ class Model:
|
|
|
962
967
|
of data will be transferred one by one. The limitation of data transmission per time is 256M.
|
|
963
968
|
|
|
964
969
|
When dataset_sink_mode is True, the `step_end` method of the instance of Callback will be called at the end
|
|
965
|
-
of epoch.
|
|
970
|
+
of step in PyNative mode, or will be called at the end of epoch in Graph mode.
|
|
966
971
|
|
|
967
972
|
If dataset_sink_mode is True, dataset will be bound to this model and cannot be used by other models.
|
|
968
973
|
|
|
@@ -1003,10 +1008,10 @@ class Model:
|
|
|
1003
1008
|
>>> from mindspore.train import Model
|
|
1004
1009
|
>>>
|
|
1005
1010
|
>>> # Create the dataset taking MNIST as an example. Refer to
|
|
1006
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1011
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/mnist.py
|
|
1007
1012
|
>>> dataset = create_dataset()
|
|
1008
1013
|
>>> # Define the network structure of LeNet5. Refer to
|
|
1009
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1014
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
|
|
1010
1015
|
>>> net = LeNet5()
|
|
1011
1016
|
>>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
|
|
1012
1017
|
>>> loss_scale_manager = ms.FixedLossScaleManager(1024., False)
|
|
@@ -1015,6 +1020,8 @@ class Model:
|
|
|
1015
1020
|
... loss_scale_manager=loss_scale_manager)
|
|
1016
1021
|
>>> model.train(2, dataset)
|
|
1017
1022
|
"""
|
|
1023
|
+
# prepare dataset for obfuscated model
|
|
1024
|
+
train_dataset = self._prepare_obf_dataset(train_dataset)
|
|
1018
1025
|
device_target = context.get_context("device_target")
|
|
1019
1026
|
if _is_ps_mode() and not _cache_enable() and (device_target in ["Ascend", "CPU"]) and dataset_sink_mode:
|
|
1020
1027
|
logger.info("For PS mode, reset datasink mode to False when using Ascend or CPU backend.")
|
|
@@ -1038,7 +1045,7 @@ class Model:
|
|
|
1038
1045
|
self._check_sink_mode_for_ds_debug_mode(dataset_sink_mode)
|
|
1039
1046
|
|
|
1040
1047
|
Validator.check_is_int(sink_size)
|
|
1041
|
-
Validator.
|
|
1048
|
+
Validator.check_positive_int(epoch)
|
|
1042
1049
|
Validator.check_non_negative_int(initial_epoch)
|
|
1043
1050
|
if initial_epoch >= epoch:
|
|
1044
1051
|
raise ValueError(f"For 'Model.train', the parameter 'epoch' must bigger than parameter 'initial_epoch',"
|
|
@@ -1154,11 +1161,11 @@ class Model:
|
|
|
1154
1161
|
>>> from mindspore.train import Model
|
|
1155
1162
|
>>>
|
|
1156
1163
|
>>> # Create the dataset taking MNIST as an example. Refer to
|
|
1157
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1164
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/mnist.py
|
|
1158
1165
|
>>> train_dataset = create_dataset("train")
|
|
1159
1166
|
>>> valid_dataset = create_dataset("test")
|
|
1160
1167
|
>>> # Define the network structure of LeNet5. Refer to
|
|
1161
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1168
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
|
|
1162
1169
|
>>> net = LeNet5()
|
|
1163
1170
|
>>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
|
|
1164
1171
|
>>> optim = nn.Momentum(params=net.trainable_params(), learning_rate=0.1, momentum=0.9)
|
|
@@ -1167,7 +1174,7 @@ class Model:
|
|
|
1167
1174
|
|
|
1168
1175
|
Tutorial Examples:
|
|
1169
1176
|
- `Advanced Encapsulation: Model - Train and Save Model
|
|
1170
|
-
<https://mindspore.cn/tutorials/en/r2.
|
|
1177
|
+
<https://www.mindspore.cn/tutorials/en/r2.2/advanced/model.html#training-and-saving-model>`_
|
|
1171
1178
|
"""
|
|
1172
1179
|
device_target = context.get_context("device_target")
|
|
1173
1180
|
if _is_ps_mode() and not _cache_enable() and (device_target in ["Ascend", "CPU"]) and dataset_sink_mode:
|
|
@@ -1186,7 +1193,7 @@ class Model:
|
|
|
1186
1193
|
.format(train_dataset._warmup_epoch, epoch))
|
|
1187
1194
|
|
|
1188
1195
|
Validator.check_is_int(sink_size)
|
|
1189
|
-
Validator.
|
|
1196
|
+
Validator.check_positive_int(epoch)
|
|
1190
1197
|
Validator.check_non_negative_int(initial_epoch)
|
|
1191
1198
|
if initial_epoch >= epoch:
|
|
1192
1199
|
raise ValueError(f"For 'Model.fit', the parameter 'epoch' must bigger than parameter 'initial_epoch',"
|
|
@@ -1247,10 +1254,10 @@ class Model:
|
|
|
1247
1254
|
>>> from mindspore.amp import FixedLossScaleManager
|
|
1248
1255
|
>>>
|
|
1249
1256
|
>>> # Create the dataset taking MNIST as an example. Refer to
|
|
1250
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1257
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/mnist.py
|
|
1251
1258
|
>>> dataset = create_dataset()
|
|
1252
1259
|
>>> # Define the network structure of LeNet5. Refer to
|
|
1253
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1260
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
|
|
1254
1261
|
>>> net = LeNet5()
|
|
1255
1262
|
>>> loss = nn.SoftmaxCrossEntropyWithLogits()
|
|
1256
1263
|
>>> loss_scale_manager = FixedLossScaleManager()
|
|
@@ -1260,6 +1267,10 @@ class Model:
|
|
|
1260
1267
|
>>> model.build(dataset, epoch=2)
|
|
1261
1268
|
>>> model.train(2, dataset)
|
|
1262
1269
|
"""
|
|
1270
|
+
epoch = Validator.check_positive_int(epoch)
|
|
1271
|
+
if hasattr(self._train_network, '_is_check_and_refresh') and not self._train_network._is_check_and_refresh:
|
|
1272
|
+
self._train_network.check_names_and_refresh_name()
|
|
1273
|
+
self._train_network._is_check_and_refresh = True
|
|
1263
1274
|
self._init(train_dataset, valid_dataset, sink_size, epoch)
|
|
1264
1275
|
|
|
1265
1276
|
def _eval_in_fit(self, valid_dataset, callbacks=None, dataset_sink_mode=True, cb_params=None):
|
|
@@ -1419,10 +1430,10 @@ class Model:
|
|
|
1419
1430
|
>>> from mindspore.train import Model
|
|
1420
1431
|
>>>
|
|
1421
1432
|
>>> # Create the dataset taking MNIST as an example. Refer to
|
|
1422
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1433
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/mnist.py
|
|
1423
1434
|
>>> dataset = create_dataset()
|
|
1424
1435
|
>>> # Define the network structure of LeNet5. Refer to
|
|
1425
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1436
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
|
|
1426
1437
|
>>> net = LeNet5()
|
|
1427
1438
|
>>> loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
|
|
1428
1439
|
>>> model = Model(net, loss_fn=loss, optimizer=None, metrics={'acc'})
|
|
@@ -1430,8 +1441,9 @@ class Model:
|
|
|
1430
1441
|
|
|
1431
1442
|
Tutorial Examples:
|
|
1432
1443
|
- `Advanced Encapsulation: Model - Train and Save Model
|
|
1433
|
-
<https://mindspore.cn/tutorials/en/r2.
|
|
1444
|
+
<https://www.mindspore.cn/tutorials/en/r2.2/advanced/model.html#training-and-saving-model>`_
|
|
1434
1445
|
"""
|
|
1446
|
+
valid_dataset = self._prepare_obf_dataset(valid_dataset)
|
|
1435
1447
|
dataset_sink_mode = Validator.check_bool(dataset_sink_mode)
|
|
1436
1448
|
|
|
1437
1449
|
_device_number_check(self._parallel_mode, self._device_number)
|
|
@@ -1479,7 +1491,7 @@ class Model:
|
|
|
1479
1491
|
|
|
1480
1492
|
return eval_result
|
|
1481
1493
|
|
|
1482
|
-
def _predict_lite(self, *predict_data):
|
|
1494
|
+
def _predict_lite(self, *predict_data, config=None):
|
|
1483
1495
|
"""
|
|
1484
1496
|
Generate output predictions for the input samples using backend 'lite'.
|
|
1485
1497
|
|
|
@@ -1488,6 +1500,48 @@ class Model:
|
|
|
1488
1500
|
The predict data, can be a single tensor,
|
|
1489
1501
|
a list of tensor, or a tuple of tensor.
|
|
1490
1502
|
|
|
1503
|
+
config (dict, optional) - The config parameter is enabled when the backend is ‘lite’.
|
|
1504
|
+
The config includes two parts: config_path (configPath, str) and config_item (str, dict).
|
|
1505
|
+
When the config_item is set, its priority is higher than the config_path. Set the ranking
|
|
1506
|
+
table file for inference. The content of the configuration file is as follows:
|
|
1507
|
+
|
|
1508
|
+
config_path defines the path of the configuration file, which is used to pass user-defined
|
|
1509
|
+
options during model building. In the following scenarios, users may need to set parameters.
|
|
1510
|
+
For example: "/home/user/config.ini". Default value: ``"" `` , here is the content of the
|
|
1511
|
+
config.ini file:
|
|
1512
|
+
|
|
1513
|
+
.. code-block::
|
|
1514
|
+
|
|
1515
|
+
[ascend_context]
|
|
1516
|
+
rank_table_file = [path_a](storage initial path of the rank table file)
|
|
1517
|
+
[execution_plan]
|
|
1518
|
+
[op_name1] = data_type:float16 (operator named op_name1 is set to data type Float16)
|
|
1519
|
+
[op_name2] = data_type:float32 (operator named op_name2 is set to data type Float32)
|
|
1520
|
+
|
|
1521
|
+
When only the config_path is configured, it is done as follows:
|
|
1522
|
+
|
|
1523
|
+
.. code-block::
|
|
1524
|
+
|
|
1525
|
+
config = {"configPath" : "/home/user/config.ini"}
|
|
1526
|
+
|
|
1527
|
+
When only the config_dict is configured, it is done as follows:
|
|
1528
|
+
|
|
1529
|
+
.. code-block::
|
|
1530
|
+
|
|
1531
|
+
config = {"ascend_context" : {"rank_table_file" : "path_b"},
|
|
1532
|
+
"execution_plan" : {"op_name1" : "data_type:float16", "op_name2" : "data_type:float32"}}
|
|
1533
|
+
|
|
1534
|
+
When both the `config_path` and the `config_dict` are configured, it is done as follows:
|
|
1535
|
+
|
|
1536
|
+
.. code-block::
|
|
1537
|
+
|
|
1538
|
+
config = {"configPath" : "/home/user/config.ini",
|
|
1539
|
+
"ascend_context" : {"rank_table_file" : "path_b"},
|
|
1540
|
+
"execution_plan" : {"op_name3" : "data_type:float16", "op_name4" : "data_type:float32"}}
|
|
1541
|
+
|
|
1542
|
+
Note that both the "configPath" is configured in the config_dict and the config_item,
|
|
1543
|
+
in this case, the path_b in the config_dict takes precedence.
|
|
1544
|
+
|
|
1491
1545
|
Returns:
|
|
1492
1546
|
Tensor, array(s) of predictions.
|
|
1493
1547
|
"""
|
|
@@ -1503,32 +1557,66 @@ class Model:
|
|
|
1503
1557
|
device_id = context.get_context('device_id')
|
|
1504
1558
|
if device_id and isinstance(device_id, int):
|
|
1505
1559
|
lite_context_input.gpu.device_id = device_id
|
|
1560
|
+
if context.get_auto_parallel_context("parallel_mode") == context.ParallelMode.SEMI_AUTO_PARALLEL:
|
|
1561
|
+
from mindspore.communication import init, get_rank
|
|
1562
|
+
init()
|
|
1563
|
+
lite_context_input.gpu.rank_id = get_rank()
|
|
1506
1564
|
elif device_target == 'ascend':
|
|
1507
1565
|
device_id = context.get_context('device_id')
|
|
1508
1566
|
if device_id and isinstance(device_id, int):
|
|
1509
1567
|
lite_context_input.ascend.device_id = device_id
|
|
1568
|
+
if context.get_auto_parallel_context("parallel_mode") == context.ParallelMode.SEMI_AUTO_PARALLEL:
|
|
1569
|
+
from mindspore.communication import init, get_rank
|
|
1570
|
+
init()
|
|
1571
|
+
lite_context_input.ascend.rank_id = get_rank()
|
|
1572
|
+
lite_context_input.ascend.provider = "ge"
|
|
1510
1573
|
else:
|
|
1511
1574
|
raise RuntimeError(f"For predict lite, device target should be in ['gpu', 'cpu', 'ascend']"
|
|
1512
1575
|
f" but got {device_target}")
|
|
1513
|
-
|
|
1514
1576
|
return lite_context_input
|
|
1515
1577
|
|
|
1516
1578
|
if not self._mindspore_lite:
|
|
1517
1579
|
self._mindspore_lite = importlib.import_module('mindspore_lite')
|
|
1518
1580
|
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1581
|
+
use_past = False # default execute full model inference
|
|
1582
|
+
model_group_id = None
|
|
1583
|
+
if self._predict_network.get_flags().__contains__("is_first_iteration"):
|
|
1584
|
+
is_first_iteration = self._predict_network.get_flags()['is_first_iteration']
|
|
1585
|
+
if isinstance(is_first_iteration, bool):
|
|
1586
|
+
use_past = not is_first_iteration
|
|
1587
|
+
model_group_id = self._mindspore_lite_model_group_id
|
|
1588
|
+
|
|
1589
|
+
check_input_data(*predict_data, data_class=(int, float, str, None, Tensor))
|
|
1590
|
+
if use_past:
|
|
1591
|
+
# Execute incremental model inference
|
|
1592
|
+
if not self._lite_incremental_predictor:
|
|
1593
|
+
lite_context = _get_lite_context(self._mindspore_lite.Context())
|
|
1594
|
+
self._lite_incremental_predictor = \
|
|
1595
|
+
self._mindspore_lite.lite_infer.LiteInfer(self, *predict_data, context=lite_context,
|
|
1596
|
+
model_group_id=model_group_id, config=config)
|
|
1597
|
+
|
|
1598
|
+
inputs = self._lite_incremental_predictor.get_inputs()
|
|
1599
|
+
if len(predict_data) != len(inputs):
|
|
1600
|
+
raise RuntimeError(f"For 'Model.predict', numbers of predict_data {len(predict_data)} "
|
|
1601
|
+
f"is not equal to numbers of net input {len(inputs)}")
|
|
1602
|
+
for i, single_data in enumerate(predict_data):
|
|
1603
|
+
inputs[i].set_data_from_numpy(single_data.asnumpy())
|
|
1604
|
+
outputs: list = self._lite_incremental_predictor.predict(inputs)
|
|
1605
|
+
else:
|
|
1606
|
+
# Execute full model inference
|
|
1607
|
+
if not self._lite_full_predictor:
|
|
1608
|
+
lite_context = _get_lite_context(self._mindspore_lite.Context())
|
|
1609
|
+
self._lite_full_predictor = \
|
|
1610
|
+
self._mindspore_lite.lite_infer.LiteInfer(self, *predict_data, context=lite_context,
|
|
1611
|
+
model_group_id=model_group_id, config=config)
|
|
1612
|
+
|
|
1613
|
+
inputs = self._lite_full_predictor.get_inputs()
|
|
1614
|
+
if len(predict_data) != len(inputs):
|
|
1615
|
+
raise RuntimeError(f"For 'Model.predict', numbers of predict_data {len(predict_data)} "
|
|
1616
|
+
f"is not equal to numbers of net input {len(inputs)}")
|
|
1617
|
+
for i, single_data in enumerate(predict_data):
|
|
1618
|
+
inputs[i].set_data_from_numpy(single_data.asnumpy())
|
|
1619
|
+
outputs: list = self._lite_full_predictor.predict(inputs)
|
|
1532
1620
|
if not outputs:
|
|
1533
1621
|
return Tensor(outputs)
|
|
1534
1622
|
if len(outputs) == 1:
|
|
@@ -1536,7 +1624,7 @@ class Model:
|
|
|
1536
1624
|
outputs = [Tensor(single_output.get_data_to_numpy()) for single_output in outputs]
|
|
1537
1625
|
return tuple(outputs)
|
|
1538
1626
|
|
|
1539
|
-
def predict(self, *predict_data, backend=None):
|
|
1627
|
+
def predict(self, *predict_data, backend=None, config=None):
|
|
1540
1628
|
"""
|
|
1541
1629
|
Generate output predictions for the input samples.
|
|
1542
1630
|
|
|
@@ -1545,7 +1633,48 @@ class Model:
|
|
|
1545
1633
|
The predict data, can be a single tensor,
|
|
1546
1634
|
a list of tensor, or a tuple of tensor.
|
|
1547
1635
|
backend (str): Select predict backend, this parameter is an experimental feature
|
|
1548
|
-
and is mainly used for MindSpore Lite cloud-side inference. Default: ``
|
|
1636
|
+
and is mainly used for MindSpore Lite cloud-side inference. Default: ``None`` .
|
|
1637
|
+
config (dict, optional) - The config parameter is enabled when the backend is ‘lite’.
|
|
1638
|
+
The config includes two parts: config_path (configPath, str) and config_item (str, dict).
|
|
1639
|
+
When the config_item is set, its priority is higher than the config_path. Set the ranking
|
|
1640
|
+
table file for inference. The content of the configuration file is as follows:
|
|
1641
|
+
|
|
1642
|
+
config_path defines the path of the configuration file, which is used to pass user-defined
|
|
1643
|
+
options during model building. In the following scenarios, users may need to set parameters.
|
|
1644
|
+
For example: "/home/user/config.ini". Default value: ``""`` , here is the content of the
|
|
1645
|
+
config.ini file:
|
|
1646
|
+
|
|
1647
|
+
.. code-block::
|
|
1648
|
+
|
|
1649
|
+
[ascend_context]
|
|
1650
|
+
rank_table_file = [path_a](storage initial path of the rank table file)
|
|
1651
|
+
[execution_plan]
|
|
1652
|
+
[op_name1] = data_type:float16 (operator named op_name1 is set to data type Float16)
|
|
1653
|
+
[op_name2] = data_type:float32 (operator named op_name2 is set to data type Float32)
|
|
1654
|
+
|
|
1655
|
+
When only the config_path is configured, it is done as follows:
|
|
1656
|
+
|
|
1657
|
+
.. code-block::
|
|
1658
|
+
|
|
1659
|
+
config = {"configPath" : "/home/user/config.ini"}
|
|
1660
|
+
|
|
1661
|
+
When only the config_dict is configured, it is done as follows:
|
|
1662
|
+
|
|
1663
|
+
.. code-block::
|
|
1664
|
+
|
|
1665
|
+
config = {"ascend_context" : {"rank_table_file" : "path_b"},
|
|
1666
|
+
"execution_plan" : {"op_name1" : "data_type:float16", "op_name2" : "data_type:float32"}}
|
|
1667
|
+
|
|
1668
|
+
When both the `config_path` and the `config_dict` are configured, it is done as follows:
|
|
1669
|
+
|
|
1670
|
+
.. code-block::
|
|
1671
|
+
|
|
1672
|
+
config = {"configPath" : "/home/user/config.ini",
|
|
1673
|
+
"ascend_context" : {"rank_table_file" : "path_b"},
|
|
1674
|
+
"execution_plan" : {"op_name3" : "data_type:float16", "op_name4" : "data_type:float32"}}
|
|
1675
|
+
|
|
1676
|
+
Note that both the "configPath" is configured in the config_dict and the config_item,
|
|
1677
|
+
in this case, the path_b in the config_dict takes precedence.
|
|
1549
1678
|
|
|
1550
1679
|
Returns:
|
|
1551
1680
|
Tensor, array(s) of predictions.
|
|
@@ -1558,7 +1687,7 @@ class Model:
|
|
|
1558
1687
|
>>>
|
|
1559
1688
|
>>> input_data = Tensor(np.random.randint(0, 255, [1, 1, 32, 32]), mindspore.float32)
|
|
1560
1689
|
>>> # Define the network structure of LeNet5. Refer to
|
|
1561
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1690
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
|
|
1562
1691
|
>>> model = Model(LeNet5())
|
|
1563
1692
|
>>> result = model.predict(input_data)
|
|
1564
1693
|
"""
|
|
@@ -1567,7 +1696,7 @@ class Model:
|
|
|
1567
1696
|
if backend == "lite" and self._lite_infer:
|
|
1568
1697
|
# pylint: disable=broad-except
|
|
1569
1698
|
try:
|
|
1570
|
-
return self._predict_lite(*predict_data)
|
|
1699
|
+
return self._predict_lite(*predict_data, config=config)
|
|
1571
1700
|
except RuntimeError:
|
|
1572
1701
|
self._lite_infer = False
|
|
1573
1702
|
logger.warning("Lite inference failed, fallback to original inference!")
|
|
@@ -1666,10 +1795,10 @@ class Model:
|
|
|
1666
1795
|
>>> ms.set_auto_parallel_context(parallel_mode=ms.ParallelMode.SEMI_AUTO_PARALLEL)
|
|
1667
1796
|
>>>
|
|
1668
1797
|
>>> # Create the dataset taking MNIST as an example. Refer to
|
|
1669
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1798
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/mnist.py
|
|
1670
1799
|
>>> dataset = create_dataset()
|
|
1671
1800
|
>>> # Define the network structure of LeNet5. Refer to
|
|
1672
|
-
>>> # https://gitee.com/mindspore/docs/blob/r2.
|
|
1801
|
+
>>> # https://gitee.com/mindspore/docs/blob/r2.2/docs/mindspore/code/lenet.py
|
|
1673
1802
|
>>> net = LeNet5()
|
|
1674
1803
|
>>> loss = nn.SoftmaxCrossEntropyWithLogits()
|
|
1675
1804
|
>>> loss_scale_manager = ms.FixedLossScaleManager()
|
|
@@ -1738,7 +1867,7 @@ class Model:
|
|
|
1738
1867
|
if _get_parallel_mode() not in (ParallelMode.SEMI_AUTO_PARALLEL, ParallelMode.AUTO_PARALLEL):
|
|
1739
1868
|
raise RuntimeError('Infer predict layout only supports semi auto parallel and auto parallel mode.')
|
|
1740
1869
|
_parallel_predict_check()
|
|
1741
|
-
check_input_data(*predict_data, data_class=Tensor)
|
|
1870
|
+
check_input_data(*predict_data, data_class=(int, float, str, None, Tensor))
|
|
1742
1871
|
|
|
1743
1872
|
predict_net = self._predict_network
|
|
1744
1873
|
# Unlike the cases in build_train_network() and build_eval_network(), 'multi_subgraphs' is not set
|
|
@@ -1790,5 +1919,16 @@ class Model:
|
|
|
1790
1919
|
"""
|
|
1791
1920
|
return self._eval_network
|
|
1792
1921
|
|
|
1922
|
+
def _prepare_obf_dataset(self, dataset):
|
|
1923
|
+
if not hasattr(self._network, 'obf_ratios'):
|
|
1924
|
+
return dataset
|
|
1925
|
+
data_size = dataset.get_dataset_size()
|
|
1926
|
+
obf_ratio_dataset = []
|
|
1927
|
+
for _ in range(data_size):
|
|
1928
|
+
obf_ratio_dataset.append(self._network.obf_ratios)
|
|
1929
|
+
obf_ratio_dataset = ds.NumpySlicesDataset(data=obf_ratio_dataset, column_names=["y_obf"])
|
|
1930
|
+
dataset = ds.zip((dataset, obf_ratio_dataset))
|
|
1931
|
+
return dataset
|
|
1932
|
+
|
|
1793
1933
|
|
|
1794
1934
|
__all__ = ["Model"]
|