mindspore 2.3.0__cp39-none-any.whl → 2.3.0rc2__cp39-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 +0 -1512
- mindspore/__init__.py +1 -2
- mindspore/_c_dataengine.cpython-39-aarch64-linux-gnu.so +0 -0
- mindspore/_c_expression.cpython-39-aarch64-linux-gnu.so +0 -0
- mindspore/_c_mindrecord.cpython-39-aarch64-linux-gnu.so +0 -0
- mindspore/_checkparam.py +25 -5
- mindspore/_extends/graph_kernel/model/graph_parallel.py +1 -1
- mindspore/_extends/parse/__init__.py +2 -2
- mindspore/_extends/parse/compile_config.py +0 -29
- mindspore/_extends/parse/namespace.py +2 -2
- mindspore/_extends/parse/parser.py +5 -21
- mindspore/_extends/parse/resources.py +7 -5
- mindspore/_extends/parse/standard_method.py +59 -40
- mindspore/_mindspore_offline_debug.cpython-39-aarch64-linux-gnu.so +0 -0
- mindspore/amp.py +5 -26
- mindspore/bin/cache_admin +0 -0
- mindspore/bin/cache_server +0 -0
- mindspore/boost/adasum.py +1 -1
- mindspore/boost/base.py +1 -1
- mindspore/boost/boost_cell_wrapper.py +1 -1
- mindspore/boost/grad_freeze.py +2 -2
- mindspore/boost/less_batch_normalization.py +6 -9
- mindspore/common/__init__.py +1 -8
- mindspore/common/_register_for_tensor.py +9 -8
- mindspore/common/api.py +65 -275
- mindspore/common/dtype.py +4 -8
- mindspore/common/dump.py +5 -2
- mindspore/common/jit_config.py +1 -1
- mindspore/common/lazy_inline.py +2 -14
- mindspore/common/parameter.py +15 -14
- mindspore/common/recompute.py +5 -20
- mindspore/common/sparse_tensor.py +6 -21
- mindspore/common/tensor.py +52 -100
- mindspore/communication/__init__.py +11 -6
- mindspore/communication/management.py +94 -92
- mindspore/context.py +18 -180
- mindspore/dataset/engine/datasets.py +46 -69
- mindspore/dataset/engine/datasets_user_defined.py +53 -72
- mindspore/dataset/engine/datasets_vision.py +2 -2
- mindspore/dataset/engine/queue.py +38 -56
- mindspore/dataset/engine/validators.py +5 -11
- mindspore/dataset/vision/__init__.py +5 -5
- mindspore/dataset/vision/c_transforms.py +5 -5
- mindspore/dataset/vision/py_transforms_util.py +1 -1
- mindspore/dataset/vision/transforms.py +46 -591
- mindspore/dataset/vision/utils.py +1 -121
- mindspore/dataset/vision/validators.py +3 -9
- mindspore/hal/__init__.py +1 -7
- mindspore/hal/device.py +1 -1
- mindspore/include/api/model.h +0 -3
- mindspore/include/dataset/vision.h +2 -54
- mindspore/include/mindapi/base/types.h +0 -1
- mindspore/lib/libdnnl.so.2 +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/libps_cache.so +0 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/config/ascend310p/aic-ascend310p-ops-info.json +0 -35
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/vector_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_cpu_kernels.so +0 -0
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/config/cust_aicpu_kernel.json +0 -72
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_proto/libcust_op_proto.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/{aclnn_all_finite.h → aclnn_add_custom.h} +11 -9
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_decoder_kv_cache.h +1 -1
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_prompt_kv_cache.h +1 -1
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/lib/libcust_opapi.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend310p/aic-ascend310p-ops-info.json +12 -184
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json +15 -7
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910b/aic-ascend910b-ops-info.json +15 -7
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.cpp +81 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.py +31 -77
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.py +31 -77
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/lib/linux/aarch64/libcust_opmaster_rt2.0.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/liboptiling.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/inc/op_proto.h +5 -4
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/lib/linux/aarch64/libcust_opsproto_rt2.0.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/liblowlatency_collective.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/DeviceBin +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/PkgInspect +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/bin/op_man +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/device/ascend910b/bin/ascend910b.bin +286 -275
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/host/libasdops_cann_host.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/host/libasdops_host.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/lib/libasdops.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/asdops/lib/libasdops_static.a +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/add/add_impl.h +0 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/apply_rotary_pos_emb_impl.h +0 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/asdop/asd_op_impl.h +0 -3
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/backend_param.h +0 -5
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/cast/cast_tiling.h +45 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/compare/compare_impl.h +0 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/flash_attention_score/flash_attention_score_impl.h +4 -8
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/flash_attention_score/flash_attention_score_tiling.h +4 -11
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/flash_attention_score/kernel/flash_attention_score_mix_hwsync.h +0 -18
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/internal_kernel.h +0 -6
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/internal_rtbackend.h +75 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul/kernel/matmul.h +5 -5
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul/matmul_impl.h +3 -18
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_common/pp_matmul_common_tiling.h +5 -5
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_common/pp_matmul_info.h +2 -2
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_common/tiling_data.h +3 -36
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_stridedslice/kernel/matmul_stridedslice_fusion.h +2 -2
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/matmul_stridedslice/matmul_stridedslice_fusion_impl.h +4 -22
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/op_param.h +2 -16
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/kernel/paged_attention_mix_hwsync.h +3 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/paged_attention_impl.h +4 -5
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/paged_attention/paged_attention_tiling.h +4 -9
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/attention_param.h +2 -5
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/matmul_ext_param.h +0 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/matmul_qkv_param.h +4 -10
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/sub_param.h +12 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/rms_norm/rms_norm_impl.h +0 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/sub/sub_impl.h +0 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/tune_repo/matmul_table.h +1 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/backend.h +2 -10
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/elewise_utils.h +1 -5
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/log/log.h +0 -1
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/log/log_tiling.h +0 -17
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/math.h +7 -2
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libAdd_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libSub_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libadd_layernorm_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libadd_rms_norm_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libapply_rotary_pos_emb_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libcast_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libgelu_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libmatmul_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libmatmul_stridedslice_fusion_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libms_kernels_internal.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libnot_equal_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/libreshape_and_cache_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/lib/librms_norm_impl.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bnsd_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bnsd_tri_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bsh_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_bf16_bsh_tri_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bnsd_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bnsd_tri_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bsh_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/flash_attention_score_fp16_bsh_tri_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_bf16_bnsd_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_bf16_bsh_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_fp16_bnsd_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/BSAttention/paged_attention_fp16_bsh_full_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/lib/liblcal.so +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/lccl/lib/liblccl_wrapper.so +0 -0
- mindspore/lib/plugin/libmindspore_ascend.so.2 +0 -0
- mindspore/mindrecord/filewriter.py +2 -2
- mindspore/mint/__init__.py +40 -720
- mindspore/mint/nn/__init__.py +7 -89
- mindspore/mint/nn/functional.py +16 -165
- mindspore/mint/optim/adamw.py +16 -15
- mindspore/nn/__init__.py +2 -0
- mindspore/nn/cell.py +98 -97
- mindspore/nn/extend/basic.py +2 -2
- mindspore/nn/extend/embedding.py +1 -1
- mindspore/nn/extend/layer/normalization.py +5 -7
- mindspore/nn/generator.py +297 -0
- mindspore/nn/layer/activation.py +3 -4
- mindspore/nn/layer/basic.py +16 -79
- mindspore/nn/layer/conv.py +8 -17
- mindspore/nn/layer/embedding.py +4 -1
- mindspore/nn/layer/math.py +1 -1
- mindspore/nn/layer/normalization.py +1 -1
- mindspore/nn/layer/pooling.py +0 -5
- mindspore/nn/layer/rnn_cells.py +2 -2
- mindspore/nn/loss/loss.py +19 -19
- mindspore/nn/optim/adasum.py +1 -1
- mindspore/nn/optim/sgd.py +2 -3
- mindspore/nn/probability/distribution/exponential.py +1 -1
- mindspore/nn/probability/distribution/geometric.py +1 -1
- mindspore/nn/probability/distribution/logistic.py +1 -1
- mindspore/nn/wrap/cell_wrapper.py +1 -25
- mindspore/nn/wrap/loss_scale.py +1 -24
- mindspore/numpy/array_ops.py +1 -5
- mindspore/numpy/dtypes.py +3 -3
- mindspore/numpy/math_ops.py +8 -8
- mindspore/ops/__init__.py +1 -1
- mindspore/ops/_grad_experimental/grad_comm_ops.py +16 -75
- mindspore/ops/_vmap/vmap_array_ops.py +0 -27
- mindspore/ops/_vmap/vmap_math_ops.py +1 -29
- mindspore/ops/_vmap/vmap_nn_ops.py +18 -19
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +8 -34
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +9 -2
- mindspore/ops/auto_generate/gen_arg_handler.py +0 -26
- mindspore/ops/auto_generate/gen_extend_func.py +27 -603
- mindspore/ops/auto_generate/gen_ops_def.py +203 -993
- mindspore/ops/auto_generate/gen_ops_prim.py +402 -1946
- mindspore/ops/auto_generate/pyboost_inner_prim.py +20 -90
- mindspore/ops/composite/base.py +6 -3
- mindspore/ops/composite/math_ops.py +1 -1
- mindspore/ops/composite/multitype_ops/_compile_utils.py +17 -24
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +1 -1
- mindspore/ops/extend/__init__.py +3 -2
- mindspore/ops/extend/array_func.py +51 -10
- mindspore/ops/extend/nn_func.py +78 -2
- mindspore/ops/function/__init__.py +13 -8
- mindspore/ops/function/array_func.py +179 -455
- mindspore/ops/function/clip_func.py +1 -1
- mindspore/ops/function/grad/grad_func.py +3 -3
- mindspore/ops/function/math_func.py +103 -117
- mindspore/ops/function/nn_func.py +163 -275
- mindspore/ops/function/other_func.py +2 -2
- mindspore/ops/function/random_func.py +69 -202
- mindspore/ops/function/sparse_func.py +4 -4
- mindspore/ops/functional.py +327 -332
- mindspore/ops/operations/__init__.py +3 -13
- mindspore/ops/operations/_grad_ops.py +27 -3
- mindspore/ops/operations/_inner_ops.py +356 -53
- mindspore/ops/operations/_rl_inner_ops.py +2 -2
- mindspore/ops/operations/_tensor_array.py +8 -8
- mindspore/ops/operations/array_ops.py +65 -82
- mindspore/ops/operations/comm_ops.py +93 -784
- mindspore/ops/operations/custom_ops.py +28 -51
- mindspore/ops/operations/debug_ops.py +4 -4
- mindspore/ops/operations/inner_ops.py +2 -2
- mindspore/ops/operations/manually_defined/ops_def.py +4 -304
- mindspore/ops/operations/math_ops.py +50 -3
- mindspore/ops/operations/nn_ops.py +247 -14
- mindspore/ops/operations/other_ops.py +3 -3
- mindspore/ops/operations/random_ops.py +1 -1
- mindspore/ops/operations/sparse_ops.py +1 -1
- mindspore/ops/primitive.py +8 -9
- mindspore/ops/silent_check.py +5 -5
- mindspore/ops_generate/arg_dtype_cast.py +9 -2
- mindspore/ops_generate/arg_handler.py +0 -26
- mindspore/ops_generate/gen_aclnn_implement.py +4 -1
- mindspore/ops_generate/gen_ops.py +4 -26
- mindspore/ops_generate/gen_pyboost_func.py +12 -41
- mindspore/ops_generate/gen_utils.py +0 -21
- mindspore/ops_generate/pyboost_utils.py +2 -7
- mindspore/ops_generate/template.py +0 -1
- mindspore/parallel/_auto_parallel_context.py +1 -21
- mindspore/parallel/_tensor.py +5 -0
- mindspore/parallel/_transformer/transformer.py +1 -1
- mindspore/parallel/_utils.py +1 -15
- mindspore/parallel/algo_parameter_config.py +3 -1
- mindspore/parallel/checkpoint_transform.py +9 -12
- mindspore/parallel/cluster/process_entity/_api.py +29 -28
- mindspore/parallel/cluster/process_entity/_utils.py +3 -13
- mindspore/parallel/cluster/run.py +16 -13
- mindspore/parallel/parameter_broadcast.py +2 -2
- mindspore/parallel/shard.py +17 -31
- mindspore/profiler/__init__.py +2 -3
- mindspore/profiler/common/util.py +2 -107
- mindspore/profiler/envprofiling.py +1 -1
- mindspore/profiler/parser/ascend_analysis/constant.py +21 -8
- mindspore/profiler/parser/ascend_analysis/file_manager.py +0 -82
- mindspore/profiler/parser/ascend_analysis/function_event.py +28 -43
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +27 -49
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +10 -15
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +20 -25
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +5 -5
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +1 -10
- mindspore/profiler/parser/ascend_hccl_generator.py +1 -4
- mindspore/profiler/parser/ascend_msprof_exporter.py +22 -43
- mindspore/profiler/parser/ascend_timeline_generator.py +5 -7
- mindspore/profiler/parser/minddata_parser.py +3 -72
- mindspore/profiler/profiling.py +59 -176
- mindspore/rewrite/api/node.py +1 -1
- mindspore/rewrite/common/namespace.py +5 -5
- mindspore/rewrite/parsers/assign_parser.py +0 -2
- mindspore/rewrite/parsers/class_def_parser.py +4 -8
- mindspore/run_check/_check_version.py +1 -1
- mindspore/scipy/fft.py +3 -1
- mindspore/scipy/linalg.py +3 -2
- mindspore/scipy/ops.py +3 -5
- mindspore/scipy/optimize/__init__.py +2 -2
- mindspore/train/__init__.py +4 -4
- mindspore/train/anf_ir_pb2.py +2 -8
- mindspore/train/callback/__init__.py +2 -5
- mindspore/train/callback/_backup_and_restore.py +2 -2
- mindspore/train/callback/_checkpoint.py +16 -104
- mindspore/train/callback/_landscape.py +1 -1
- mindspore/train/callback/_time_monitor.py +1 -1
- mindspore/train/data_sink.py +4 -5
- mindspore/train/dataset_helper.py +20 -45
- mindspore/train/model.py +38 -266
- mindspore/train/serialization.py +105 -256
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/version.py +1 -1
- {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/METADATA +2 -2
- {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/RECORD +303 -420
- mindspore/_extends/pijit/__init__.py +0 -23
- mindspore/_extends/pijit/pijit_func_white_list.py +0 -343
- mindspore/common/file_system.py +0 -48
- mindspore/common/generator.py +0 -260
- mindspore/common/no_inline.py +0 -54
- mindspore/common/np_dtype.py +0 -25
- mindspore/communication/comm_func.py +0 -1140
- mindspore/hal/memory.py +0 -326
- mindspore/lib/libavcodec.so.59 +0 -0
- mindspore/lib/libavdevice.so.59 +0 -0
- mindspore/lib/libavfilter.so.8 +0 -0
- mindspore/lib/libavformat.so.59 +0 -0
- mindspore/lib/libavutil.so.57 +0 -0
- mindspore/lib/libmindspore_np_dtype.so +0 -0
- mindspore/lib/libswresample.so.4 +0 -0
- mindspore/lib/libswscale.so.6 +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/all_finite.cpp +0 -326
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/all_finite.py +0 -180
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_576ceaeef5870c451cab59af55ea46ad.json +0 -58
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_576ceaeef5870c451cab59af55ea46ad.o +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_86a73ff6e28d734c96bb8d3054f7dd18.json +0 -58
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_86a73ff6e28d734c96bb8d3054f7dd18.o +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_f55e0ebaad1f2f572e43677336992fa0.json +0 -58
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/ascend910b/all_finite/AllFinite_f55e0ebaad1f2f572e43677336992fa0.o +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/config/ascend910b/all_finite.json +0 -109
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/kernel/config/ascend910b/binary_info_config.json +0 -38
- mindspore/lib/plugin/ascend/custom_compiler/OWNERS +0 -12
- mindspore/lib/plugin/ascend/custom_compiler/setup.py +0 -255
- mindspore/lib/plugin/ascend/custom_compiler/start.sh +0 -26
- mindspore/lib/plugin/ascend/custom_compiler/template.json +0 -40
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/acme.h +0 -24
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/acme_op.h +0 -69
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/base_type.h +0 -133
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/op_creator.h +0 -32
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/op_param.h +0 -35
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/include/tiling_info.h +0 -60
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/core/kernel_register.h +0 -37
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/core/platform/platform_configs.h +0 -89
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/core/platform/rt_funcs.h +0 -135
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/add_op.h +0 -34
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_backoff_base.h +0 -62
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_elewise_op.h +0 -33
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_ops.h +0 -88
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/asd_pa_op.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/cast_op.h +0 -52
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/ops/host_src/matmul_op.h +0 -95
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/utils/asd_utils.h +0 -84
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/acme/src/utils/comm_utils.h +0 -61
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/apply_rotary_pos_emb/kernel/apply_rotary_pos_emb_fp32.h +0 -224
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/and_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/div_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/elewise_binary_impl.h +0 -48
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/elewise_binary_tiling.h +0 -25
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/and_kernel.h +0 -46
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/div_kernel.h +0 -46
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/elewise_binary_base.h +0 -260
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/elewise_binary_kernel.h +0 -35
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/max_kernel.h +0 -66
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/min_kernel.h +0 -66
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/mul_kernel.h +0 -66
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/kernel/or_kernel.h +0 -46
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/max_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/min_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/mul_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_binary/or_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/abs_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/elewise_unary_impl.h +0 -47
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/elewise_unary_tiling.h +0 -24
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/exp_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/abs_kernel.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/elewise_unary_base.h +0 -148
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/elewise_unary_kernel.h +0 -31
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/exp_kernel.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/ln_kernel.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/not_kernel.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/reciprocal_kernel.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/relu_kernel.h +0 -55
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/rsqrt_kernel.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/kernel/sqrt_kernel.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/ln_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/not_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/reciprocal_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/relu_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/rsqrt_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/elewise_unary/sqrt_impl.h +0 -29
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/grouped_matmul_impl.h +0 -45
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/grouped_matmul_tiling.h +0 -187
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/kernel/grouped_matmul.h +0 -245
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/kernel/grouped_matmul_interface.h +0 -24
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/kernel/grouped_matmul_utils.h +0 -111
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/grouped_matmul/tiling_data.h +0 -54
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/compare_param.h +0 -31
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/elewise_param.h +0 -41
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/param/grouped_matmul_param.h +0 -40
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/profiling_util.h +0 -364
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/log/log_utils.h +0 -69
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/register/kernel_creator.h +0 -39
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/register/kernel_registry.h +0 -114
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/include/utils/utils.h +0 -98
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix.json +0 -19
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix_mix_aic_0.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MatMulPostFusionMixTactic/matmul_postfusion_mix_mix_aiv_0.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix.json +0 -19
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix_mix_aic_0.o +0 -0
- mindspore/lib/plugin/ascend/ms_kernels_internal/internal_kernel/op_kernels/ascend910b/MultiMatMulPostFusionMixTactic/multi_matmul_postfusion_mix_mix_aiv_0.o +0 -0
- mindspore/mint/linalg/__init__.py +0 -22
- mindspore/nn/layer/embedding_service.py +0 -531
- mindspore/nn/layer/embedding_service_layer.py +0 -393
- mindspore/ops/function/reshard_func.py +0 -102
- mindspore/ops/operations/_infer_ops.py +0 -19
- mindspore/ops/operations/reshard_ops.py +0 -53
- mindspore/profiler/common/process_pool.py +0 -41
- mindspore/profiler/common/singleton.py +0 -28
- mindspore/profiler/parser/ascend_integrate_generator.py +0 -42
- mindspore/profiler/parser/ascend_memory_generator.py +0 -185
- mindspore/train/callback/_cluster_monitor.py +0 -201
- mindspore/train/callback/_flops_collector.py +0 -238
- mindspore/train/callback/_mindio_ttp.py +0 -443
- {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/WHEEL +0 -0
- {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/entry_points.txt +0 -0
- {mindspore-2.3.0.dist-info → mindspore-2.3.0rc2.dist-info}/top_level.txt +0 -0
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 Huawei Technologies Co., Ltd
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
# ============================================================================
|
|
15
|
-
"""
|
|
16
|
-
Helper module for pijit analyze
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
from .pijit_func_white_list import _func_map as pijit_func_white_list_map
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
__all__ = ['pijit_func_white_list_map']
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
# This is the Python adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
|
|
2
|
-
#
|
|
3
|
-
# Copyright 2020-2024 Huawei Technologies Co., Ltd
|
|
4
|
-
#
|
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
# you may not use this file except in compliance with the License.
|
|
7
|
-
# You may obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
# See the License for the specific language governing permissions and
|
|
15
|
-
# limitations under the License.
|
|
16
|
-
# ============================================================================
|
|
17
|
-
"""The module of parser python object, called by c++."""
|
|
18
|
-
|
|
19
|
-
import collections
|
|
20
|
-
import types
|
|
21
|
-
import math
|
|
22
|
-
import os
|
|
23
|
-
import numpy
|
|
24
|
-
from mindspore.nn import GraphCell, Cell
|
|
25
|
-
from mindspore.ops.primitive import Primitive, constexpr, _primexpr
|
|
26
|
-
from mindspore.ops.composite.base import GradOperation, _Grad
|
|
27
|
-
from mindspore.ops._primitive_cache import _get_cache_prim
|
|
28
|
-
from mindspore.common.api import jit
|
|
29
|
-
from mindspore.common.tensor import Tensor
|
|
30
|
-
from mindspore.common._register_for_tensor import Registry, tensor_operator_registry
|
|
31
|
-
from mindspore._c_expression import MetaFuncGraph_, function_id, Primitive_, PrimitiveFunction_
|
|
32
|
-
from mindspore._c_expression import Tensor as Tensor_
|
|
33
|
-
from mindspore._extends.parse.resources import convert_object_map
|
|
34
|
-
from mindspore import _checkparam as validator
|
|
35
|
-
from mindspore import Parameter, ParameterTuple
|
|
36
|
-
from mindspore.common.initializer import Zero
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def _get_after_grad_code():
|
|
40
|
-
"""Get the code object of 'after_grad'"""
|
|
41
|
-
name = "after_grad"
|
|
42
|
-
codes = []
|
|
43
|
-
for cnst in GradOperation.__call__.__code__.co_consts:
|
|
44
|
-
if isinstance(cnst, types.CodeType) and cnst.co_name == name:
|
|
45
|
-
codes.append(cnst)
|
|
46
|
-
for cnst in _Grad.__call__.__code__.co_consts:
|
|
47
|
-
if isinstance(cnst, types.CodeType) and cnst.co_name == name:
|
|
48
|
-
codes.append(cnst)
|
|
49
|
-
if not codes:
|
|
50
|
-
raise RuntimeError("check GradOperation, can't find the code of 'after_grad'")
|
|
51
|
-
return codes
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _get_psjit_code():
|
|
55
|
-
"""Get the code object of 'staging_specialize'"""
|
|
56
|
-
@jit
|
|
57
|
-
def inner():
|
|
58
|
-
pass
|
|
59
|
-
return inner.__code__
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _get_constexpr_code():
|
|
63
|
-
"""Get the code object of '@constexpr'"""
|
|
64
|
-
@constexpr
|
|
65
|
-
def inner():
|
|
66
|
-
pass
|
|
67
|
-
code = inner.__call__.__code__
|
|
68
|
-
# check it before c++ use it
|
|
69
|
-
if not isinstance(inner, Primitive) or code is Primitive.__call__.__code__:
|
|
70
|
-
raise RuntimeError("@constexpr not isinstance(inner, Primitive) or code is Primitive.__call__.__code__")
|
|
71
|
-
return code
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def _get_primexpr_code():
|
|
75
|
-
"""Get the code object of '@_primexpr'"""
|
|
76
|
-
@_primexpr
|
|
77
|
-
def inner():
|
|
78
|
-
pass
|
|
79
|
-
code = inner.__call__.__code__
|
|
80
|
-
# check it before c++ use it
|
|
81
|
-
if not isinstance(inner, Primitive) or code is Primitive.__call__.__code__:
|
|
82
|
-
raise RuntimeError("@_primexpr not isinstance(inner, Primitive) or code is Primitive.__call__.__code__")
|
|
83
|
-
return code
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def _pijit_constexpr():
|
|
87
|
-
"""Placeholder for uniqure id"""
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _get_pijit_constexpr_code():
|
|
91
|
-
codes = []
|
|
92
|
-
for cnst in validator.check_transpose_axis.__code__.co_consts:
|
|
93
|
-
if isinstance(cnst, types.CodeType) and cnst.co_name == "_check_dim":
|
|
94
|
-
codes.append(cnst)
|
|
95
|
-
return codes
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def _get_ms_api():
|
|
99
|
-
"""Get ms api"""
|
|
100
|
-
target_types = Cell, types.FunctionType, Primitive_, PrimitiveFunction_
|
|
101
|
-
results = []
|
|
102
|
-
from mindspore.ops import operations as P
|
|
103
|
-
from mindspore.ops import functional as F
|
|
104
|
-
from mindspore.ops import composite as C
|
|
105
|
-
mods = P, F, C
|
|
106
|
-
for mod in mods:
|
|
107
|
-
for i in mod.__all__:
|
|
108
|
-
f = getattr(mod, i)
|
|
109
|
-
if isinstance(f, target_types):
|
|
110
|
-
results.append(f)
|
|
111
|
-
for f in tensor_operator_registry.values():
|
|
112
|
-
if isinstance(f, target_types):
|
|
113
|
-
results.append(f)
|
|
114
|
-
return results
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
psjit_code = _get_psjit_code()
|
|
118
|
-
constexpr_code = _get_constexpr_code()
|
|
119
|
-
primexpr_code = _get_primexpr_code()
|
|
120
|
-
|
|
121
|
-
primitive_key = id(Primitive.__call__)
|
|
122
|
-
constexpr_key = id(constexpr_code)
|
|
123
|
-
primexpr_key = id(primexpr_code)
|
|
124
|
-
meta_func_graph_key = id(MetaFuncGraph_)
|
|
125
|
-
pijit_forbidden_key = id(NotImplemented)
|
|
126
|
-
pijit_constexpr_key = id(_pijit_constexpr)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# check WrapperDescriptor: function_id(tuple.__getitem__) == function_id(tuple().__getitem__)
|
|
130
|
-
# check MethodDescriptor: function_id(list.__getitem__) == function_id(list().__getitem__)
|
|
131
|
-
# check instancemethod: function_id(Tensor_.from_numpy) == function_id(Tensor_(1).from_numpy)
|
|
132
|
-
# check cfunction filter: function_id(Tensor_.from_numpy) != function_id(Tensor_._is_test_stub)
|
|
133
|
-
# check function id: function_id(Tensor.astype) == function_id(Tensor(1).astype) == id(Tensor.astype)
|
|
134
|
-
# check user defined object id: function_id(Primitive) == function_id(Primitive) == id(Primitive)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
FUNC_KEY_EMPTY = 0 # ""
|
|
138
|
-
FUNC_KEY_PIJIT_CONSTEXPR = 1 # "pijit.constexpr"
|
|
139
|
-
FUNC_KEY_PIJIT_FORBIDDEN = 2 # "pijit.forbidden"
|
|
140
|
-
FUNC_KEY_BUILTIN_FUNC = 3 # "builtin.func"
|
|
141
|
-
FUNC_KEY_LIST_APPEND = 4 # "list.append"
|
|
142
|
-
FUNC_KEY_DICT_POP = 5 # "dict.pop"
|
|
143
|
-
FUNC_KEY_PRIMITIVE = 6 # "mindspore._c_expression.Primitive_"
|
|
144
|
-
FUNC_KEY_META_FUNCG_RAPH = 7 # "mindspore._c_expression.MetaFuncGraph_"
|
|
145
|
-
FUNC_KEY_PSJIT_CODE = 8 # "mindspore.common.api.jit.<locals>.staging_specialize"
|
|
146
|
-
FUNC_KEY_CONSTEXPR = 9 # "mindspore.ops.primitive.constexpr"
|
|
147
|
-
FUNC_KEY_PRIMEXPR = 10 # "mindspore.ops.primitive._primexpr"
|
|
148
|
-
FUNC_KEY_GET_CACHE_PRIM = 11 # "mindspore.ops._primitive_cache._get_cache_prim"
|
|
149
|
-
FUNC_KEY_REGISTRY_GET = 12 # "mindspore.common._register_for_tensor.Registry.get"
|
|
150
|
-
FUNC_KEY_TENSOR_ASTYPE = 13 # "mindspore.common.tensor.Tensor.astype"
|
|
151
|
-
FUNC_KEY_GRAD_OPERATIONS_CODE = 14 # "mindspore.ops.composite.base._Grad.__call__.<locals>.after_grad"
|
|
152
|
-
FUNC_KEY_PSJIT_CONVERTMAP = 15 # "mindspore._extends.parse.resources.convert_object_map"
|
|
153
|
-
FUNC_KEY_GRAPH_CELL = 16 # "mindspore.nn.cell.GraphCell"
|
|
154
|
-
FUNC_KEY_MS_API = 17 # mindspore common api
|
|
155
|
-
FUNC_KEY_MAPPING_GET = 18 # collections.abc.Mapping.get
|
|
156
|
-
|
|
157
|
-
# Initialized only once. This map will initialize by c++ when start pijit.
|
|
158
|
-
# key is customer if fuzzy match. (Primitive, constexpr, primexpr, MetaFuncGraph)
|
|
159
|
-
# key is id of code for nest object. (jit.<locals>.staging_specialize, GradOperation.__call__.<locals>.after_grad)
|
|
160
|
-
# key is id of object for callalbe object.
|
|
161
|
-
# key is cfunction pointer for builtin_function or method. (isinstance, tuple.__getitem__, Tensor_.asnumpy)
|
|
162
|
-
_func_map = {
|
|
163
|
-
# special function
|
|
164
|
-
pijit_constexpr_key: FUNC_KEY_PIJIT_CONSTEXPR,
|
|
165
|
-
pijit_forbidden_key: FUNC_KEY_PIJIT_FORBIDDEN,
|
|
166
|
-
primitive_key: FUNC_KEY_PRIMITIVE,
|
|
167
|
-
constexpr_key: FUNC_KEY_CONSTEXPR,
|
|
168
|
-
primexpr_key: FUNC_KEY_PRIMEXPR,
|
|
169
|
-
meta_func_graph_key: FUNC_KEY_META_FUNCG_RAPH,
|
|
170
|
-
id(GraphCell.__call__): FUNC_KEY_GRAPH_CELL,
|
|
171
|
-
id(psjit_code): FUNC_KEY_PSJIT_CODE,
|
|
172
|
-
id(_get_cache_prim): FUNC_KEY_GET_CACHE_PRIM,
|
|
173
|
-
id(Registry.get): FUNC_KEY_REGISTRY_GET,
|
|
174
|
-
|
|
175
|
-
# Tensor method
|
|
176
|
-
id(Tensor.astype): FUNC_KEY_TENSOR_ASTYPE,
|
|
177
|
-
|
|
178
|
-
# types.BuiltinFunctionType
|
|
179
|
-
function_id(isinstance): FUNC_KEY_BUILTIN_FUNC,
|
|
180
|
-
function_id(issubclass): FUNC_KEY_BUILTIN_FUNC,
|
|
181
|
-
function_id(len): FUNC_KEY_BUILTIN_FUNC,
|
|
182
|
-
function_id(abs): FUNC_KEY_BUILTIN_FUNC,
|
|
183
|
-
function_id(max): FUNC_KEY_BUILTIN_FUNC,
|
|
184
|
-
function_id(all): FUNC_KEY_BUILTIN_FUNC,
|
|
185
|
-
function_id(any): FUNC_KEY_BUILTIN_FUNC,
|
|
186
|
-
function_id(hash): FUNC_KEY_BUILTIN_FUNC,
|
|
187
|
-
function_id(id): FUNC_KEY_BUILTIN_FUNC,
|
|
188
|
-
function_id(ord): FUNC_KEY_BUILTIN_FUNC,
|
|
189
|
-
function_id(callable): FUNC_KEY_BUILTIN_FUNC,
|
|
190
|
-
function_id(getattr): FUNC_KEY_BUILTIN_FUNC,
|
|
191
|
-
function_id(hasattr): FUNC_KEY_BUILTIN_FUNC,
|
|
192
|
-
|
|
193
|
-
# types.MethodDescriptorType, types.WrapperDescriptorType
|
|
194
|
-
function_id(tuple.__getitem__): FUNC_KEY_BUILTIN_FUNC,
|
|
195
|
-
function_id(tuple.count): FUNC_KEY_BUILTIN_FUNC,
|
|
196
|
-
function_id(tuple.index): FUNC_KEY_BUILTIN_FUNC,
|
|
197
|
-
function_id(list.__getitem__): FUNC_KEY_BUILTIN_FUNC,
|
|
198
|
-
function_id(list.copy): FUNC_KEY_BUILTIN_FUNC,
|
|
199
|
-
function_id(list.index): FUNC_KEY_BUILTIN_FUNC,
|
|
200
|
-
function_id(list.count): FUNC_KEY_BUILTIN_FUNC,
|
|
201
|
-
function_id(dict.__contains__): FUNC_KEY_BUILTIN_FUNC,
|
|
202
|
-
function_id(dict.__getitem__): FUNC_KEY_BUILTIN_FUNC,
|
|
203
|
-
function_id(dict.get): FUNC_KEY_BUILTIN_FUNC,
|
|
204
|
-
function_id(dict.keys): FUNC_KEY_BUILTIN_FUNC,
|
|
205
|
-
function_id(dict.values): FUNC_KEY_BUILTIN_FUNC,
|
|
206
|
-
function_id(dict.items): FUNC_KEY_BUILTIN_FUNC,
|
|
207
|
-
function_id(dict.fromkeys): FUNC_KEY_BUILTIN_FUNC,
|
|
208
|
-
function_id(dict.copy): FUNC_KEY_BUILTIN_FUNC,
|
|
209
|
-
function_id(set.__contains__): FUNC_KEY_BUILTIN_FUNC,
|
|
210
|
-
function_id(set.copy): FUNC_KEY_BUILTIN_FUNC,
|
|
211
|
-
function_id(set.issubset): FUNC_KEY_BUILTIN_FUNC,
|
|
212
|
-
function_id(str.find): FUNC_KEY_BUILTIN_FUNC,
|
|
213
|
-
function_id(str.count): FUNC_KEY_BUILTIN_FUNC,
|
|
214
|
-
function_id(str.index): FUNC_KEY_BUILTIN_FUNC,
|
|
215
|
-
function_id(str.rfind): FUNC_KEY_BUILTIN_FUNC,
|
|
216
|
-
function_id(str.rindex): FUNC_KEY_BUILTIN_FUNC,
|
|
217
|
-
function_id(str.startswith): FUNC_KEY_BUILTIN_FUNC,
|
|
218
|
-
function_id(str.endswith): FUNC_KEY_BUILTIN_FUNC,
|
|
219
|
-
function_id(str.isascii): FUNC_KEY_BUILTIN_FUNC,
|
|
220
|
-
function_id(str.islower): FUNC_KEY_BUILTIN_FUNC,
|
|
221
|
-
function_id(str.isupper): FUNC_KEY_BUILTIN_FUNC,
|
|
222
|
-
function_id(str.istitle): FUNC_KEY_BUILTIN_FUNC,
|
|
223
|
-
function_id(str.isspace): FUNC_KEY_BUILTIN_FUNC,
|
|
224
|
-
function_id(str.isdecimal): FUNC_KEY_BUILTIN_FUNC,
|
|
225
|
-
function_id(str.isdigit): FUNC_KEY_BUILTIN_FUNC,
|
|
226
|
-
function_id(str.isnumeric): FUNC_KEY_BUILTIN_FUNC,
|
|
227
|
-
function_id(str.isalpha): FUNC_KEY_BUILTIN_FUNC,
|
|
228
|
-
function_id(str.isalnum): FUNC_KEY_BUILTIN_FUNC,
|
|
229
|
-
function_id(str.isidentifier): FUNC_KEY_BUILTIN_FUNC,
|
|
230
|
-
function_id(str.isprintable): FUNC_KEY_BUILTIN_FUNC,
|
|
231
|
-
function_id(str.format): FUNC_KEY_BUILTIN_FUNC,
|
|
232
|
-
function_id(str.format_map): FUNC_KEY_BUILTIN_FUNC,
|
|
233
|
-
function_id(str.__format__): FUNC_KEY_BUILTIN_FUNC,
|
|
234
|
-
function_id(list.append): FUNC_KEY_LIST_APPEND,
|
|
235
|
-
function_id(dict.pop): FUNC_KEY_DICT_POP,
|
|
236
|
-
|
|
237
|
-
# instancemethod
|
|
238
|
-
function_id(Tensor_._flatten_tensors): FUNC_KEY_BUILTIN_FUNC, # pylint: disable=protected-access
|
|
239
|
-
function_id(Tensor_._is_flattened): FUNC_KEY_BUILTIN_FUNC, # pylint: disable=protected-access
|
|
240
|
-
function_id(Tensor_._get_flattened_tensors): FUNC_KEY_BUILTIN_FUNC, # pylint: disable=protected-access
|
|
241
|
-
function_id(Tensor_._get_fusion_size): FUNC_KEY_BUILTIN_FUNC, # pylint: disable=protected-access
|
|
242
|
-
function_id(Tensor_._is_test_stub): FUNC_KEY_BUILTIN_FUNC, # pylint: disable=protected-access
|
|
243
|
-
function_id(Tensor_.__str__): FUNC_KEY_BUILTIN_FUNC, # pylint: disable=protected-access
|
|
244
|
-
function_id(Tensor_.__repr__): FUNC_KEY_BUILTIN_FUNC, # pylint: disable=protected-access
|
|
245
|
-
function_id(Tensor_.convert_bytes_to_tensor): FUNC_KEY_BUILTIN_FUNC,
|
|
246
|
-
function_id(Tensor_.dim): FUNC_KEY_BUILTIN_FUNC,
|
|
247
|
-
function_id(Tensor_.from_numpy): FUNC_KEY_BUILTIN_FUNC,
|
|
248
|
-
function_id(Tensor_.getitem_index_info): FUNC_KEY_BUILTIN_FUNC,
|
|
249
|
-
function_id(Tensor_.get_bytes): FUNC_KEY_BUILTIN_FUNC,
|
|
250
|
-
function_id(Tensor_.is_init): FUNC_KEY_BUILTIN_FUNC,
|
|
251
|
-
function_id(Tensor_.is_contiguous): FUNC_KEY_BUILTIN_FUNC,
|
|
252
|
-
function_id(Tensor_.stride): FUNC_KEY_BUILTIN_FUNC,
|
|
253
|
-
# Tensor_.asnumpy need real tensor value
|
|
254
|
-
|
|
255
|
-
# other builtin function
|
|
256
|
-
function_id(collections.abc.Mapping.get): FUNC_KEY_MAPPING_GET,
|
|
257
|
-
function_id(math.log): FUNC_KEY_BUILTIN_FUNC,
|
|
258
|
-
|
|
259
|
-
function_id(numpy.isinf): FUNC_KEY_BUILTIN_FUNC,
|
|
260
|
-
function_id(numpy.isnan): FUNC_KEY_BUILTIN_FUNC,
|
|
261
|
-
function_id(numpy.abs): FUNC_KEY_BUILTIN_FUNC,
|
|
262
|
-
function_id(numpy.log): FUNC_KEY_BUILTIN_FUNC,
|
|
263
|
-
|
|
264
|
-
# const function
|
|
265
|
-
function_id(os.getenv): FUNC_KEY_PIJIT_CONSTEXPR,
|
|
266
|
-
function_id(validator.check_number_range): FUNC_KEY_PIJIT_CONSTEXPR,
|
|
267
|
-
function_id(validator.check_is_int): FUNC_KEY_PIJIT_CONSTEXPR,
|
|
268
|
-
function_id(validator.check_is_number): FUNC_KEY_PIJIT_CONSTEXPR,
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
for after_grad in _get_after_grad_code():
|
|
272
|
-
_func_map[id(after_grad)] = FUNC_KEY_GRAD_OPERATIONS_CODE
|
|
273
|
-
|
|
274
|
-
for k, v in convert_object_map.items():
|
|
275
|
-
key = id(k)
|
|
276
|
-
if key not in _func_map and isinstance(v, Primitive):
|
|
277
|
-
if key is print:
|
|
278
|
-
continue
|
|
279
|
-
_func_map[key] = FUNC_KEY_PSJIT_CONVERTMAP
|
|
280
|
-
|
|
281
|
-
for const_code in _get_pijit_constexpr_code():
|
|
282
|
-
_func_map[id(const_code)] = FUNC_KEY_PIJIT_CONSTEXPR
|
|
283
|
-
|
|
284
|
-
GUARD_KEY_RELAX_FUNC = 1
|
|
285
|
-
_guard_func_map = dict()
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
def infer_after_grad(after_grad_func, inputs, outputs):
|
|
289
|
-
""" Infer after_grad """
|
|
290
|
-
contents = {}
|
|
291
|
-
for index, name in enumerate(after_grad_func.__code__.co_freevars):
|
|
292
|
-
contents[name] = after_grad_func.__closure__[index].cell_contents
|
|
293
|
-
grad = contents.get('grad_') if 'grad_' in contents else contents.get('self')
|
|
294
|
-
grad_position = contents.get('grad_position')
|
|
295
|
-
weights = contents.get('weights')
|
|
296
|
-
|
|
297
|
-
def _validation_check():
|
|
298
|
-
if not grad:
|
|
299
|
-
raise ValueError("Failed to get grad")
|
|
300
|
-
if grad.has_aux and len(inputs) <= 1:
|
|
301
|
-
raise ValueError("Hax_aux must have more than one input")
|
|
302
|
-
if grad_position is None and weights is None:
|
|
303
|
-
raise ValueError("Ethither grad_position or weights must not be empty")
|
|
304
|
-
if grad.return_ids and grad_position is None:
|
|
305
|
-
raise ValueError("return_ids must have grad_position not empty")
|
|
306
|
-
|
|
307
|
-
def _to_result(grads):
|
|
308
|
-
if not grads:
|
|
309
|
-
return None
|
|
310
|
-
if len(grads) == 1:
|
|
311
|
-
return grads[0]
|
|
312
|
-
return tuple(grads)
|
|
313
|
-
|
|
314
|
-
_validation_check()
|
|
315
|
-
|
|
316
|
-
input_grads = []
|
|
317
|
-
if isinstance(grad_position, tuple):
|
|
318
|
-
for pos in grad_position:
|
|
319
|
-
input_grads.append((pos, inputs[pos]) if grad.return_ids else inputs[pos])
|
|
320
|
-
elif isinstance(grad_position, int):
|
|
321
|
-
input_grads.append((grad_position, inputs[grad_position]) if grad.return_ids else inputs[grad_position])
|
|
322
|
-
|
|
323
|
-
param_grads = []
|
|
324
|
-
if isinstance(weights, Parameter):
|
|
325
|
-
param_grads.append(Tensor(dtype=weights.dtype, shape=weights.shape, init=Zero()))
|
|
326
|
-
elif isinstance(weights, (ParameterTuple, list)):
|
|
327
|
-
param_grads = [Tensor(dtype=weight.dtype, shape=weight.shape, init=Zero()) for weight in weights]
|
|
328
|
-
grads_output = None
|
|
329
|
-
get_all = input_grads and param_grads
|
|
330
|
-
if get_all:
|
|
331
|
-
grads_output = (_to_result(input_grads), _to_result(param_grads))
|
|
332
|
-
elif input_grads:
|
|
333
|
-
grads_output = _to_result(input_grads)
|
|
334
|
-
elif param_grads:
|
|
335
|
-
grads_output = _to_result(param_grads)
|
|
336
|
-
|
|
337
|
-
if grad.get_value:
|
|
338
|
-
return outputs, grads_output
|
|
339
|
-
|
|
340
|
-
if grad.has_aux:
|
|
341
|
-
aux_output = tuple(list(inputs)[1:])
|
|
342
|
-
return grads_output, aux_output
|
|
343
|
-
return grads_output
|
mindspore/common/file_system.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 Huawei Technologies Co., Ltd
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
# ============================================================================
|
|
15
|
-
"""File system registration management"""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class FileSystem:
|
|
19
|
-
"""File operation interface manager"""
|
|
20
|
-
def __init__(self):
|
|
21
|
-
self.create = open
|
|
22
|
-
self.create_args = ("ab",)
|
|
23
|
-
self.open = open
|
|
24
|
-
self.open_args = ("rb",)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def _register_basic_file_system(fs: FileSystem):
|
|
28
|
-
"""register basic file system"""
|
|
29
|
-
fs.create = open
|
|
30
|
-
fs.create_args = ("ab",)
|
|
31
|
-
fs.open = open
|
|
32
|
-
fs.open_args = ("rb",)
|
|
33
|
-
return True
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def _register_mindio_file_system(fs: FileSystem):
|
|
37
|
-
"""register mindio file system"""
|
|
38
|
-
try:
|
|
39
|
-
import mindio
|
|
40
|
-
except ImportError:
|
|
41
|
-
return False
|
|
42
|
-
if mindio.initialize() != 0:
|
|
43
|
-
return False
|
|
44
|
-
fs.create = mindio.create_file
|
|
45
|
-
fs.create_args = ()
|
|
46
|
-
fs.open = mindio.open_file
|
|
47
|
-
fs.open_args = ()
|
|
48
|
-
return True
|
mindspore/common/generator.py
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 Huawei Technologies Co., Ltd
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
# ============================================================================
|
|
15
|
-
"""Generator"""
|
|
16
|
-
from mindspore.common.parameter import Parameter
|
|
17
|
-
from mindspore.common import Tensor
|
|
18
|
-
from mindspore.common import dtype as mstype
|
|
19
|
-
from mindspore.ops.operations._inner_ops import Generator as GeneratorOp
|
|
20
|
-
from mindspore.ops.operations._sequence_ops import TensorToScalar
|
|
21
|
-
from mindspore.ops.vm_impl_registry import vm_impl_registry as vm_impl_getters
|
|
22
|
-
from mindspore._c_expression import _random_seeded_generator
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# pylint: disable=unused-argument
|
|
26
|
-
@vm_impl_getters.register(GeneratorOp)
|
|
27
|
-
def vm_impl_generator(self):
|
|
28
|
-
"""
|
|
29
|
-
Generate vm_impl function for Generator.
|
|
30
|
-
|
|
31
|
-
The default_generator is initialized and called during import.
|
|
32
|
-
For this reason a vm_impl is required for ut compilation.
|
|
33
|
-
"""
|
|
34
|
-
def vm_impl(cmd, inputs):
|
|
35
|
-
return 0
|
|
36
|
-
return vm_impl
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
STEP = 0
|
|
40
|
-
SEED = 1
|
|
41
|
-
GET_STATE = 2
|
|
42
|
-
SET_STATE = 3
|
|
43
|
-
MANUAL_SEED = 4
|
|
44
|
-
INITIAL_SEED = 5
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def jit_class(cls):
|
|
48
|
-
"""Make class recognizable in graph mode"""
|
|
49
|
-
setattr(cls, '__ms_class__', True)
|
|
50
|
-
return cls
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@jit_class
|
|
54
|
-
class Generator:
|
|
55
|
-
"""
|
|
56
|
-
A generator that manages the state of random numbers and provides seed and offset for random functions.
|
|
57
|
-
When the seed and offset are fixed, the random function generates the same random sequence.
|
|
58
|
-
|
|
59
|
-
Inputs:
|
|
60
|
-
- **step** (int) - Set the step size for offset update.
|
|
61
|
-
|
|
62
|
-
Outputs:
|
|
63
|
-
Tuple consisting of the seed and offset of generator.
|
|
64
|
-
|
|
65
|
-
Supported Platforms:
|
|
66
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
67
|
-
|
|
68
|
-
Examples:
|
|
69
|
-
>>> import mindspore as ms
|
|
70
|
-
>>> from mindspore import Generator
|
|
71
|
-
>>> generator = Generator()
|
|
72
|
-
>>> generator.manual_seed(5)
|
|
73
|
-
>>> print(generator.initial_seed())
|
|
74
|
-
5
|
|
75
|
-
>>> state = generator.get_state()
|
|
76
|
-
>>> generator.seed()
|
|
77
|
-
>>> generator.set_state(state)
|
|
78
|
-
>>> print(generator.initial_seed())
|
|
79
|
-
5
|
|
80
|
-
"""
|
|
81
|
-
|
|
82
|
-
def __init__(self):
|
|
83
|
-
self._seed = Parameter(Tensor(0, mstype.int64),
|
|
84
|
-
name="seed", requires_grad=False)
|
|
85
|
-
self._offset = Parameter(
|
|
86
|
-
Tensor(0, mstype.int64), name="offset", requires_grad=False)
|
|
87
|
-
|
|
88
|
-
self._generator = GeneratorOp().set_device("CPU")
|
|
89
|
-
self._to_scalar = TensorToScalar()
|
|
90
|
-
|
|
91
|
-
def set_state(self, state):
|
|
92
|
-
"""
|
|
93
|
-
Sets the generator state.
|
|
94
|
-
|
|
95
|
-
Args:
|
|
96
|
-
state (tensor): target state of the generator.
|
|
97
|
-
"""
|
|
98
|
-
self._generator(SET_STATE, (self._seed, self._offset, state))
|
|
99
|
-
|
|
100
|
-
def get_state(self):
|
|
101
|
-
"""
|
|
102
|
-
Get the generator state.
|
|
103
|
-
|
|
104
|
-
Returns:
|
|
105
|
-
Tensor, generator state.
|
|
106
|
-
"""
|
|
107
|
-
return self._generator(GET_STATE, (self._seed, self._offset))[2]
|
|
108
|
-
|
|
109
|
-
def seed(self): # pylint: disable=redefined-outer-name
|
|
110
|
-
"""
|
|
111
|
-
Seed generator with random number.
|
|
112
|
-
|
|
113
|
-
Returns:
|
|
114
|
-
Randomly generated seeds, the type is int.
|
|
115
|
-
"""
|
|
116
|
-
current_seed = self._generator(
|
|
117
|
-
SEED, (self._seed, self._offset))[0]
|
|
118
|
-
return self._to_scalar(current_seed)
|
|
119
|
-
|
|
120
|
-
def manual_seed(self, seed): # pylint: disable=redefined-outer-name
|
|
121
|
-
"""
|
|
122
|
-
Set the generator seed.
|
|
123
|
-
|
|
124
|
-
Args:
|
|
125
|
-
seed (int): Set the generator seed.
|
|
126
|
-
|
|
127
|
-
Returns:
|
|
128
|
-
Generator, the generator instance.
|
|
129
|
-
"""
|
|
130
|
-
if not isinstance(seed, int):
|
|
131
|
-
raise TypeError("Seed must be an integer.")
|
|
132
|
-
seed = Tensor(seed, mstype.int64)
|
|
133
|
-
self._generator(MANUAL_SEED, (self._seed, self._offset, seed))
|
|
134
|
-
return self
|
|
135
|
-
|
|
136
|
-
def initial_seed(self):
|
|
137
|
-
"""
|
|
138
|
-
Return the initial seed of generator.
|
|
139
|
-
|
|
140
|
-
Returns:
|
|
141
|
-
The initial seed of generator.
|
|
142
|
-
"""
|
|
143
|
-
current_seed = self._generator(
|
|
144
|
-
INITIAL_SEED, (self._seed, self._offset))[0]
|
|
145
|
-
return self._to_scalar(current_seed)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def _step(self, step):
|
|
149
|
-
"""
|
|
150
|
-
Return current seed and offset, and update offset for the next call.
|
|
151
|
-
|
|
152
|
-
Args:
|
|
153
|
-
step (Tensor): Update offset by step.
|
|
154
|
-
|
|
155
|
-
Returns:
|
|
156
|
-
Current seed and offset.
|
|
157
|
-
"""
|
|
158
|
-
return self._generator(STEP, (self._seed, self._offset, step,))[:2]
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
default_generator = _random_seeded_generator()
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def seed(): # pylint: disable=redefined-outer-name
|
|
165
|
-
"""
|
|
166
|
-
Seed the default generator with random number.
|
|
167
|
-
|
|
168
|
-
Returns:
|
|
169
|
-
Randomly generated seeds, the type is int.
|
|
170
|
-
|
|
171
|
-
Supported Platforms:
|
|
172
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
173
|
-
|
|
174
|
-
Examples:
|
|
175
|
-
>>> import numpy as np
|
|
176
|
-
>>> from mindspore import seed
|
|
177
|
-
>>> print(seed())
|
|
178
|
-
1663920602
|
|
179
|
-
"""
|
|
180
|
-
return default_generator.seed()
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
def manual_seed(seed): # pylint: disable=redefined-outer-name
|
|
184
|
-
"""
|
|
185
|
-
Set the default generator seed.
|
|
186
|
-
|
|
187
|
-
Args:
|
|
188
|
-
seed (int): Set the default generator seed.
|
|
189
|
-
|
|
190
|
-
Returns:
|
|
191
|
-
Generator, the default generator.
|
|
192
|
-
|
|
193
|
-
Supported Platforms:
|
|
194
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
195
|
-
|
|
196
|
-
Examples:
|
|
197
|
-
>>> from mindspore import manual_seed, initial_seed
|
|
198
|
-
>>> manual_seed(13)
|
|
199
|
-
>>> print(initial_seed())
|
|
200
|
-
13
|
|
201
|
-
"""
|
|
202
|
-
default_generator.manual_seed(seed)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
def initial_seed():
|
|
206
|
-
"""
|
|
207
|
-
Return the initial seed of the default generator.
|
|
208
|
-
|
|
209
|
-
Returns:
|
|
210
|
-
The initial seed of the default generator.
|
|
211
|
-
|
|
212
|
-
Supported Platforms:
|
|
213
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
214
|
-
|
|
215
|
-
Examples:
|
|
216
|
-
>>> from mindspore import manual_seed, initial_seed
|
|
217
|
-
>>> manual_seed(14)
|
|
218
|
-
>>> print(initial_seed())
|
|
219
|
-
14
|
|
220
|
-
"""
|
|
221
|
-
return default_generator.initial_seed()
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
def get_rng_state():
|
|
225
|
-
"""
|
|
226
|
-
Get the state of the default generator.
|
|
227
|
-
|
|
228
|
-
Returns:
|
|
229
|
-
Tensor, generator state.
|
|
230
|
-
|
|
231
|
-
Supported Platforms:
|
|
232
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
233
|
-
|
|
234
|
-
Examples:
|
|
235
|
-
>>> import numpy as np
|
|
236
|
-
>>> from mindspore import get_rng_state
|
|
237
|
-
>>> state = get_rng_state()
|
|
238
|
-
"""
|
|
239
|
-
return default_generator.get_state()
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def set_rng_state(state): # pylint: disable=redefined-outer-name
|
|
243
|
-
"""
|
|
244
|
-
Set the state of the default generator.
|
|
245
|
-
|
|
246
|
-
Args:
|
|
247
|
-
state (Tensor): the target state
|
|
248
|
-
|
|
249
|
-
Supported Platforms:
|
|
250
|
-
``Ascend`` ``GPU`` ``CPU``
|
|
251
|
-
|
|
252
|
-
Examples:
|
|
253
|
-
>>> from mindspore import set_rng_state, get_rng_state
|
|
254
|
-
>>> state = get_rng_state()
|
|
255
|
-
>>> set_rng_state(state)
|
|
256
|
-
"""
|
|
257
|
-
default_generator.set_state(state)
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
__all__ = ["Generator", "default_generator", "seed", "manual_seed", "initial_seed", "set_rng_state", "get_rng_state"]
|