mindspore 2.6.0__cp39-cp39-win_amd64.whl → 2.7.0rc1__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/__init__.py +1 -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/_checkparam.py +40 -9
- mindspore/{_deprecated → _extends/optimize}/__init__.py +9 -3
- mindspore/_extends/optimize/cell_utils.py +96 -0
- mindspore/_extends/parse/__init__.py +2 -2
- mindspore/_extends/parse/compile_config.py +44 -22
- mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +1 -1
- mindspore/_extends/parse/parser.py +36 -61
- mindspore/_extends/parse/resources.py +39 -0
- mindspore/_extends/parse/standard_method.py +32 -13
- mindspore/_extends/parse/trope.py +8 -1
- mindspore/_extends/pijit/__init__.py +1 -2
- mindspore/amp.py +4 -4
- mindspore/avcodec-59.dll +0 -0
- mindspore/avdevice-59.dll +0 -0
- mindspore/avfilter-8.dll +0 -0
- mindspore/avformat-59.dll +0 -0
- mindspore/avutil-57.dll +0 -0
- mindspore/boost/adasum.py +1 -1
- mindspore/boost/boost_cell_wrapper.py +4 -4
- mindspore/common/__init__.py +27 -2
- mindspore/common/_grad_function.py +2 -1
- mindspore/common/_pijit_context.py +28 -7
- mindspore/common/_stub_tensor.py +1 -209
- mindspore/common/_tensor_cpp_method.py +1 -1
- mindspore/common/_tensor_docs.py +76 -15
- mindspore/common/api.py +193 -112
- mindspore/common/dtype.py +21 -11
- mindspore/common/dump.py +10 -15
- mindspore/common/generator.py +2 -3
- mindspore/common/hook_handle.py +11 -2
- mindspore/common/jit_config.py +1 -1
- mindspore/common/jit_trace.py +84 -105
- mindspore/common/parameter.py +26 -12
- mindspore/common/recompute.py +3 -3
- mindspore/common/sparse_tensor.py +0 -3
- mindspore/common/symbol.py +0 -1
- mindspore/common/tensor.py +48 -83
- mindspore/communication/_comm_helper.py +46 -4
- mindspore/communication/management.py +79 -7
- mindspore/context.py +38 -23
- mindspore/dataset/core/config.py +3 -3
- mindspore/dataset/engine/datasets.py +20 -7
- mindspore/dataset/engine/datasets_user_defined.py +32 -2
- mindspore/dataset/engine/iterators.py +2 -2
- mindspore/dataset/engine/obs/config_loader.py +2 -2
- mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +8 -0
- mindspore/dataset/transforms/py_transforms.py +7 -3
- mindspore/dataset/transforms/transforms.py +7 -3
- mindspore/dataset/vision/validators.py +1 -0
- mindspore/device_context/ascend/device.py +1 -1
- mindspore/device_context/gpu/__init__.py +2 -2
- mindspore/device_context/gpu/device.py +1 -1
- mindspore/device_context/gpu/op_precision.py +4 -2
- mindspore/device_context/gpu/op_tuning.py +6 -3
- mindspore/device_manager.py +16 -9
- mindspore/dnnl.dll +0 -0
- mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +3 -5
- mindspore/experimental/llm_boost/atb/boost_base.py +2 -3
- mindspore/experimental/optim/adadelta.py +13 -20
- mindspore/experimental/optim/adagrad.py +15 -22
- mindspore/experimental/optim/adam.py +17 -24
- mindspore/experimental/optim/adamax.py +14 -22
- mindspore/experimental/optim/adamw.py +28 -34
- mindspore/experimental/optim/asgd.py +15 -25
- mindspore/experimental/optim/lr_scheduler.py +27 -45
- mindspore/experimental/optim/nadam.py +14 -24
- mindspore/experimental/optim/optimizer.py +13 -23
- mindspore/experimental/optim/radam.py +18 -24
- mindspore/experimental/optim/rmsprop.py +14 -25
- mindspore/experimental/optim/rprop.py +15 -26
- mindspore/experimental/optim/sgd.py +9 -19
- mindspore/hal/__init__.py +4 -4
- mindspore/hal/contiguous_tensors_handle.py +2 -2
- mindspore/hal/memory.py +1 -0
- mindspore/include/api/cell.h +37 -1
- mindspore/include/api/delegate.h +10 -0
- mindspore/include/api/model.h +3 -0
- mindspore/include/api/types.h +2 -2
- mindspore/include/c_api/model_c.h +0 -58
- mindspore/include/c_api/tensor_c.h +0 -26
- mindspore/include/dataset/vision_ascend.h +1 -1
- mindspore/jpeg62.dll +0 -0
- mindspore/mindrecord/tools/cifar10.py +60 -11
- mindspore/mindrecord/tools/cifar10_to_mr.py +5 -0
- mindspore/mindspore_backend_common.dll +0 -0
- mindspore/mindspore_backend_manager.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_cpu_res_manager.dll +0 -0
- mindspore/mindspore_dump.dll +0 -0
- mindspore/mindspore_frontend.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_memory_pool.dll +0 -0
- mindspore/mindspore_ms_backend.dll +0 -0
- mindspore/mindspore_ops.dll +0 -0
- mindspore/mindspore_ops_host.dll +0 -0
- mindspore/mindspore_ops_kernel_common.dll +0 -0
- mindspore/mindspore_profiler.dll +0 -0
- mindspore/mindspore_pyboost.dll +0 -0
- mindspore/mindspore_pynative.dll +0 -0
- mindspore/mindspore_res_manager.dll +0 -0
- mindspore/mindspore_runtime_pipeline.dll +0 -0
- mindspore/mint/__init__.py +4 -44
- mindspore/mint/distributed/__init__.py +1 -0
- mindspore/mint/distributed/distributed.py +208 -5
- mindspore/mint/nn/__init__.py +1 -1
- mindspore/mint/nn/functional.py +53 -6
- mindspore/mint/nn/layer/_functions.py +164 -294
- mindspore/mint/nn/layer/activation.py +8 -6
- mindspore/mint/nn/layer/conv.py +122 -98
- mindspore/mint/nn/layer/normalization.py +8 -22
- mindspore/mint/optim/adam.py +19 -18
- mindspore/mint/optim/adamw.py +14 -8
- mindspore/mint/optim/sgd.py +5 -5
- mindspore/nn/cell.py +325 -499
- mindspore/nn/grad/cell_grad.py +11 -12
- mindspore/nn/layer/activation.py +32 -34
- mindspore/nn/layer/basic.py +67 -64
- mindspore/nn/layer/channel_shuffle.py +4 -4
- mindspore/nn/layer/combined.py +4 -2
- mindspore/nn/layer/conv.py +86 -85
- mindspore/nn/layer/dense.py +9 -7
- mindspore/nn/layer/embedding.py +50 -52
- mindspore/nn/layer/image.py +37 -39
- mindspore/nn/layer/math.py +111 -112
- mindspore/nn/layer/normalization.py +56 -44
- mindspore/nn/layer/pooling.py +58 -63
- mindspore/nn/layer/rnn_cells.py +33 -33
- mindspore/nn/layer/rnns.py +56 -56
- mindspore/nn/layer/thor_layer.py +74 -73
- mindspore/nn/layer/transformer.py +11 -1
- mindspore/nn/learning_rate_schedule.py +20 -20
- mindspore/nn/loss/loss.py +79 -81
- mindspore/nn/optim/adam.py +1 -1
- mindspore/nn/optim/adasum.py +2 -2
- mindspore/nn/optim/optimizer.py +1 -1
- mindspore/nn/optim/thor.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +2 -1
- mindspore/nn/probability/distribution/poisson.py +2 -1
- mindspore/nn/sparse/sparse.py +3 -3
- mindspore/nn/wrap/cell_wrapper.py +34 -37
- mindspore/nn/wrap/grad_reducer.py +37 -37
- mindspore/nn/wrap/loss_scale.py +72 -74
- mindspore/numpy/array_creations.py +5 -5
- mindspore/numpy/fft.py +1 -1
- mindspore/numpy/math_ops.py +1 -1
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/_grad_experimental/grad_comm_ops.py +51 -13
- mindspore/ops/_grad_experimental/grad_debug_ops.py +14 -0
- mindspore/ops/_vmap/vmap_array_ops.py +6 -13
- mindspore/ops/_vmap/vmap_nn_ops.py +8 -16
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +17 -8
- mindspore/ops/auto_generate/gen_extend_func.py +1 -51
- mindspore/ops/auto_generate/gen_ops_def.py +463 -257
- mindspore/ops/auto_generate/gen_ops_prim.py +1127 -885
- mindspore/ops/auto_generate/pyboost_inner_prim.py +31 -1
- mindspore/ops/composite/__init__.py +10 -0
- mindspore/ops/composite/base.py +8 -4
- mindspore/ops/composite/multitype_ops/__init__.py +12 -1
- mindspore/ops/composite/multitype_ops/_compile_utils.py +132 -108
- mindspore/ops/composite/multitype_ops/add_impl.py +70 -2
- mindspore/ops/composite/multitype_ops/div_impl.py +49 -0
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +29 -0
- mindspore/ops/composite/multitype_ops/getitem_impl.py +11 -0
- mindspore/ops/composite/multitype_ops/mod_impl.py +5 -3
- mindspore/ops/composite/multitype_ops/mul_impl.py +49 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +57 -0
- mindspore/ops/composite/multitype_ops/sub_impl.py +34 -0
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +14 -0
- mindspore/ops/function/__init__.py +3 -1
- mindspore/ops/function/_add_attr_func.py +11 -6
- mindspore/ops/function/array_func.py +7 -94
- mindspore/ops/function/debug_func.py +4 -3
- mindspore/ops/function/grad/grad_func.py +1 -1
- mindspore/ops/function/math_func.py +21 -367
- mindspore/ops/function/nn_func.py +26 -41
- mindspore/ops/function/other_func.py +4 -1
- mindspore/ops/function/random_func.py +31 -4
- mindspore/ops/functional.py +0 -2
- mindspore/ops/functional_overload.py +463 -6
- mindspore/ops/op_info_register.py +21 -0
- mindspore/ops/operations/__init__.py +5 -2
- mindspore/ops/operations/_custom_ops_utils.py +675 -8
- mindspore/ops/operations/_inner_ops.py +3 -6
- mindspore/ops/operations/_sequence_ops.py +1 -1
- mindspore/ops/operations/comm_ops.py +185 -26
- mindspore/ops/operations/custom_ops.py +235 -172
- mindspore/ops/operations/debug_ops.py +55 -4
- mindspore/ops/operations/image_ops.py +13 -13
- mindspore/ops/operations/manually_defined/ops_def.py +15 -16
- mindspore/ops/operations/math_ops.py +3 -4
- mindspore/ops/operations/nn_ops.py +5 -6
- mindspore/ops/primitive.py +6 -10
- mindspore/ops/tensor_method.py +36 -4
- mindspore/ops_generate/api/cpp_create_prim_instance_helper_generator.py +1 -1
- mindspore/ops_generate/api/functional_map_cpp_generator.py +10 -9
- mindspore/ops_generate/api/functions_cc_generator.py +58 -10
- mindspore/ops_generate/api/tensor_func_reg_cpp_generator.py +1 -1
- mindspore/ops_generate/common/base_generator.py +14 -0
- mindspore/ops_generate/common/gen_constants.py +7 -2
- mindspore/ops_generate/common/gen_utils.py +0 -19
- mindspore/ops_generate/common/op_proto.py +11 -4
- mindspore/ops_generate/common/template.py +88 -11
- mindspore/ops_generate/gen_ops.py +1 -1
- mindspore/ops_generate/op_def/lite_ops_cpp_generator.py +4 -4
- mindspore/ops_generate/op_def/ops_name_h_generator.py +0 -3
- mindspore/ops_generate/op_def/ops_primitive_h_generator.py +0 -4
- mindspore/ops_generate/op_def_py/op_prim_py_generator.py +5 -2
- mindspore/ops_generate/pyboost/auto_grad_impl_cc_generator.py +49 -8
- mindspore/ops_generate/pyboost/auto_grad_reg_cc_generator.py +2 -2
- mindspore/ops_generate/pyboost/gen_pyboost_func.py +31 -0
- mindspore/ops_generate/pyboost/op_template_parser.py +98 -72
- mindspore/ops_generate/pyboost/pyboost_functions_cpp_generator.py +70 -273
- mindspore/ops_generate/pyboost/pyboost_functions_h_generator.py +14 -6
- mindspore/ops_generate/pyboost/pyboost_functions_impl_cpp_generator.py +316 -0
- mindspore/ops_generate/pyboost/pyboost_functions_py_generator.py +1 -1
- mindspore/ops_generate/pyboost/pyboost_grad_function_cpp_generator.py +5 -3
- mindspore/ops_generate/pyboost/pyboost_inner_prim_generator.py +1 -1
- mindspore/ops_generate/pyboost/pyboost_internal_functions_cpp_generator.py +76 -0
- mindspore/ops_generate/pyboost/pyboost_internal_functions_h_generator.py +76 -0
- mindspore/ops_generate/pyboost/pyboost_internal_kernel_info_adapter_generator.py +125 -0
- mindspore/ops_generate/pyboost/pyboost_native_grad_functions_generator.py +4 -3
- mindspore/ops_generate/pyboost/pyboost_op_cpp_code_generator.py +348 -61
- mindspore/ops_generate/pyboost/pyboost_overload_functions_cpp_generator.py +1 -1
- mindspore/ops_generate/pyboost/pyboost_utils.py +118 -9
- mindspore/ops_generate/tensor_py_cc_generator.py +1 -24
- mindspore/parallel/_auto_parallel_context.py +4 -2
- mindspore/parallel/_cell_wrapper.py +106 -40
- mindspore/parallel/_parallel_serialization.py +1 -1
- mindspore/parallel/_ps_context.py +4 -6
- mindspore/parallel/_tensor.py +167 -12
- mindspore/parallel/_transformer/moe.py +1 -1
- mindspore/parallel/_transformer/transformer.py +13 -8
- mindspore/parallel/auto_parallel.py +12 -5
- mindspore/parallel/checkpoint_convert.py +3 -3
- mindspore/parallel/checkpoint_transform.py +3 -1
- mindspore/parallel/cluster/process_entity/_api.py +84 -48
- mindspore/parallel/cluster/process_entity/_utils.py +95 -7
- mindspore/parallel/cluster/run.py +43 -4
- mindspore/parallel/function/__init__.py +8 -1
- mindspore/parallel/function/reshard_func.py +1 -1
- mindspore/parallel/nn/__init__.py +15 -2
- mindspore/parallel/nn/parallel_cell_wrapper.py +9 -10
- mindspore/parallel/nn/parallel_grad_reducer.py +7 -6
- mindspore/parallel/shard.py +2 -2
- mindspore/parallel/transform_safetensors.py +462 -174
- mindspore/profiler/__init__.py +2 -1
- mindspore/profiler/analysis/parser/timeline_assembly_factory/ascend_timeline_assembler.py +7 -7
- mindspore/profiler/analysis/parser/timeline_assembly_factory/base_timeline_assembler.py +3 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/trace_view_container.py +3 -0
- mindspore/profiler/analysis/parser/timeline_creator/cpu_op_timeline_creator.py +3 -3
- mindspore/profiler/analysis/parser/timeline_creator/fwk_timeline_creator.py +3 -3
- mindspore/profiler/analysis/parser/timeline_creator/msprof_timeline_creator.py +4 -4
- mindspore/profiler/analysis/parser/timeline_creator/scope_layer_timeline_creator.py +3 -3
- mindspore/profiler/analysis/parser/timeline_event/fwk_event.py +4 -1
- mindspore/profiler/analysis/parser/timeline_event/timeline_event_pool.py +2 -1
- mindspore/profiler/analysis/task_manager.py +1 -1
- mindspore/profiler/analysis/viewer/ascend_communication_viewer.py +5 -1
- mindspore/profiler/analysis/viewer/ascend_integrate_viewer.py +2 -1
- mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +42 -22
- mindspore/profiler/analysis/viewer/ascend_step_trace_time_viewer.py +3 -2
- mindspore/profiler/analysis/viewer/ms_minddata_viewer.py +9 -5
- mindspore/profiler/analysis/viewer/ms_operator_details_viewer.py +132 -0
- mindspore/profiler/common/constant.py +16 -0
- mindspore/profiler/common/profiler_context.py +25 -27
- mindspore/profiler/common/profiler_info.py +0 -16
- mindspore/profiler/common/profiler_op_analyse.py +235 -0
- mindspore/profiler/common/profiler_output_path.py +23 -8
- mindspore/profiler/common/profiler_parameters.py +128 -35
- mindspore/profiler/dynamic_profile/__init__.py +0 -0
- mindspore/profiler/dynamic_profile/dynamic_monitor_proxy.py +39 -0
- mindspore/profiler/dynamic_profile/dynamic_profiler_config_context.py +666 -0
- mindspore/profiler/dynamic_profile/dynamic_profiler_utils.py +62 -0
- mindspore/profiler/dynamic_profiler.py +305 -314
- mindspore/profiler/envprofiler.py +12 -7
- mindspore/profiler/experimental_config.py +96 -6
- mindspore/profiler/mstx.py +33 -12
- mindspore/profiler/platform/__init__.py +2 -3
- mindspore/profiler/platform/npu_profiler.py +29 -19
- mindspore/profiler/profiler.py +35 -19
- mindspore/profiler/profiler_action_controller.py +64 -76
- mindspore/profiler/schedule.py +10 -4
- mindspore/rewrite/common/config.py +1 -0
- mindspore/rewrite/common/namer.py +1 -0
- mindspore/rewrite/common/namespace.py +1 -0
- mindspore/rewrite/node/node.py +31 -11
- mindspore/rewrite/parsers/assign_parser.py +1 -1
- mindspore/rewrite/symbol_tree/symbol_tree.py +1 -1
- mindspore/run_check/_check_version.py +7 -10
- mindspore/runtime/__init__.py +5 -5
- mindspore/runtime/event.py +10 -4
- mindspore/runtime/executor.py +60 -45
- mindspore/runtime/memory.py +21 -30
- mindspore/runtime/thread_bind_core.py +298 -164
- mindspore/safeguard/rewrite_obfuscation.py +12 -13
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/_utils.py +6 -2
- mindspore/train/amp.py +43 -20
- mindspore/train/callback/__init__.py +5 -5
- mindspore/train/callback/_checkpoint.py +3 -6
- mindspore/train/callback/_flops_collector.py +1 -1
- mindspore/train/callback/_landscape.py +0 -1
- mindspore/train/callback/_train_fault_tolerance.py +71 -13
- mindspore/train/data_sink.py +11 -2
- mindspore/train/dataset_helper.py +9 -0
- mindspore/train/model.py +51 -33
- mindspore/train/serialization.py +133 -111
- mindspore/train/summary/summary_record.py +13 -2
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +3 -2
- mindspore/utils/dryrun.py +0 -6
- mindspore/utils/runtime_execution_order_check.py +162 -78
- mindspore/utils/sdc_detect.py +68 -0
- mindspore/utils/utils.py +6 -9
- mindspore/version.py +1 -1
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/METADATA +5 -4
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/RECORD +329 -367
- mindspore/_deprecated/jit.py +0 -198
- mindspore/experimental/es/__init__.py +0 -22
- mindspore/experimental/es/embedding_service.py +0 -891
- mindspore/experimental/es/embedding_service_layer.py +0 -581
- mindspore/profiler/parser/__init__.py +0 -14
- mindspore/profiler/parser/aicpu_data_parser.py +0 -272
- mindspore/profiler/parser/ascend_analysis/__init__.py +0 -14
- mindspore/profiler/parser/ascend_analysis/constant.py +0 -71
- mindspore/profiler/parser/ascend_analysis/file_manager.py +0 -180
- mindspore/profiler/parser/ascend_analysis/function_event.py +0 -185
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +0 -136
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +0 -131
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +0 -104
- mindspore/profiler/parser/ascend_analysis/path_manager.py +0 -313
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +0 -123
- mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +0 -86
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +0 -75
- mindspore/profiler/parser/ascend_cluster_generator.py +0 -116
- mindspore/profiler/parser/ascend_communicate_generator.py +0 -314
- mindspore/profiler/parser/ascend_flops_generator.py +0 -116
- mindspore/profiler/parser/ascend_fpbp_generator.py +0 -82
- mindspore/profiler/parser/ascend_hccl_generator.py +0 -271
- mindspore/profiler/parser/ascend_integrate_generator.py +0 -42
- mindspore/profiler/parser/ascend_memory_generator.py +0 -185
- mindspore/profiler/parser/ascend_msprof_exporter.py +0 -282
- mindspore/profiler/parser/ascend_msprof_generator.py +0 -187
- mindspore/profiler/parser/ascend_op_generator.py +0 -334
- mindspore/profiler/parser/ascend_steptrace_generator.py +0 -94
- mindspore/profiler/parser/ascend_timeline_generator.py +0 -545
- mindspore/profiler/parser/base_timeline_generator.py +0 -483
- mindspore/profiler/parser/container.py +0 -229
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +0 -697
- mindspore/profiler/parser/flops_parser.py +0 -531
- mindspore/profiler/parser/framework_enum.py +0 -111
- mindspore/profiler/parser/framework_parser.py +0 -464
- mindspore/profiler/parser/framework_struct.py +0 -61
- mindspore/profiler/parser/gpu_analysis/__init__.py +0 -14
- mindspore/profiler/parser/gpu_analysis/function_event.py +0 -44
- mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +0 -89
- mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +0 -72
- mindspore/profiler/parser/hccl_parser.py +0 -573
- mindspore/profiler/parser/hwts_log_parser.py +0 -122
- mindspore/profiler/parser/integrator.py +0 -526
- mindspore/profiler/parser/memory_usage_parser.py +0 -277
- mindspore/profiler/parser/minddata_analyzer.py +0 -800
- mindspore/profiler/parser/minddata_parser.py +0 -186
- mindspore/profiler/parser/minddata_pipeline_parser.py +0 -299
- mindspore/profiler/parser/op_intermediate_parser.py +0 -149
- mindspore/profiler/parser/optime_parser.py +0 -250
- mindspore/profiler/parser/profiler_info.py +0 -213
- mindspore/profiler/parser/step_trace_parser.py +0 -666
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/entry_points.txt +0 -0
- {mindspore-2.6.0.dist-info → mindspore-2.7.0rc1.dist-info}/top_level.txt +0 -0
mindspore/nn/layer/rnns.py
CHANGED
|
@@ -19,10 +19,9 @@ import math
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
|
|
21
21
|
import mindspore.nn as nn
|
|
22
|
-
import mindspore.ops as
|
|
22
|
+
import mindspore.ops as ops
|
|
23
23
|
import mindspore.context as context
|
|
24
24
|
import mindspore.common.dtype as mstype
|
|
25
|
-
from mindspore.ops import functional as F
|
|
26
25
|
from mindspore.ops.primitive import constexpr, _primexpr
|
|
27
26
|
from mindspore.common.tensor import Tensor
|
|
28
27
|
from mindspore.common.parameter import ParameterTuple, Parameter
|
|
@@ -36,8 +35,8 @@ __all__ = ['LSTM', 'GRU', 'RNN']
|
|
|
36
35
|
|
|
37
36
|
|
|
38
37
|
def _init_state(shape, dtype, is_lstm):
|
|
39
|
-
hx =
|
|
40
|
-
cx =
|
|
38
|
+
hx = ops.zeros(shape, dtype)
|
|
39
|
+
cx = ops.zeros(shape, dtype)
|
|
41
40
|
if is_lstm:
|
|
42
41
|
return (hx, cx)
|
|
43
42
|
return hx
|
|
@@ -57,17 +56,17 @@ def _check_input_dtype_same_and_valid(args_name, args_value, valid_values, cls_n
|
|
|
57
56
|
@constexpr(check=False)
|
|
58
57
|
def _check_is_tensor(param_name, input_data, cls_name):
|
|
59
58
|
"""Internal function, used to check whether the input data is Tensor."""
|
|
60
|
-
if input_data is not None and not isinstance(
|
|
59
|
+
if input_data is not None and not isinstance(ops.typeof(input_data), mstype.TensorType):
|
|
61
60
|
raise TypeError(f"For '{cls_name}', the '{param_name}' must be '{mstype.TensorType}', "
|
|
62
|
-
f"but got '{
|
|
61
|
+
f"but got '{ops.typeof(input_data)}'")
|
|
63
62
|
|
|
64
63
|
|
|
65
64
|
@constexpr
|
|
66
65
|
def _check_is_tuple(param_name, input_data, cls_name):
|
|
67
66
|
"""Internal function, used to check whether the input data is Tensor."""
|
|
68
|
-
if input_data is not None and not isinstance(
|
|
67
|
+
if input_data is not None and not isinstance(ops.typeof(input_data), mstype.Tuple):
|
|
69
68
|
raise TypeError(f"For '{cls_name}', the '{param_name}' must be '{mstype.Tuple}', "
|
|
70
|
-
f"but got '{
|
|
69
|
+
f"but got '{ops.typeof(input_data)}'")
|
|
71
70
|
|
|
72
71
|
|
|
73
72
|
@constexpr
|
|
@@ -87,7 +86,7 @@ def _check_seq_length_size(batch_size_x, seq_length_size, cls_name):
|
|
|
87
86
|
|
|
88
87
|
def sequence_mask(lengths, maxlen):
|
|
89
88
|
"""generate mask matrix by seq_length"""
|
|
90
|
-
range_vector =
|
|
89
|
+
range_vector = ops.arange(start=0, end=maxlen, step=1, dtype=lengths.dtype)
|
|
91
90
|
result = range_vector < lengths.view(lengths.shape + (1,))
|
|
92
91
|
return result.astype(mstype.int32)
|
|
93
92
|
|
|
@@ -100,9 +99,9 @@ def select_by_mask(inputs, mask):
|
|
|
100
99
|
|
|
101
100
|
def get_hidden(output, seq_length):
|
|
102
101
|
"""get hidden state by seq_length"""
|
|
103
|
-
batch_index =
|
|
104
|
-
indices =
|
|
105
|
-
return
|
|
102
|
+
batch_index = ops.arange(start=0, end=seq_length.shape[0], step=1, dtype=seq_length.dtype)
|
|
103
|
+
indices = ops.Concat(1)((seq_length.view(-1, 1) - 1, batch_index.view(-1, 1)))
|
|
104
|
+
return ops.GatherNd()(output, indices)
|
|
106
105
|
|
|
107
106
|
|
|
108
107
|
class _DynamicRNNBase(Cell):
|
|
@@ -131,14 +130,14 @@ class _DynamicRNNBase(Cell):
|
|
|
131
130
|
h = h_0
|
|
132
131
|
while t < time_step:
|
|
133
132
|
x_t = x[t:t + 1:1]
|
|
134
|
-
x_t =
|
|
133
|
+
x_t = ops.Squeeze(0)(x_t)
|
|
135
134
|
h = self.cell(x_t, h, w_ih, w_hh, b_ih, b_hh)
|
|
136
135
|
if self.is_lstm:
|
|
137
136
|
outputs.append(h[0])
|
|
138
137
|
else:
|
|
139
138
|
outputs.append(h)
|
|
140
139
|
t += 1
|
|
141
|
-
outputs =
|
|
140
|
+
outputs = ops.Stack()(outputs)
|
|
142
141
|
return outputs, h
|
|
143
142
|
|
|
144
143
|
def variable_recurrent(self, x, h, seq_length, w_ih, w_hh, b_ih, b_hh):
|
|
@@ -147,34 +146,34 @@ class _DynamicRNNBase(Cell):
|
|
|
147
146
|
h_t = h
|
|
148
147
|
if self.is_lstm:
|
|
149
148
|
hidden_size = h[0].shape[-1]
|
|
150
|
-
zero_output =
|
|
149
|
+
zero_output = ops.ZerosLike()(h_t[0])
|
|
151
150
|
else:
|
|
152
151
|
hidden_size = h.shape[-1]
|
|
153
|
-
zero_output =
|
|
154
|
-
seq_length =
|
|
155
|
-
seq_length =
|
|
156
|
-
seq_length =
|
|
157
|
-
seq_length =
|
|
152
|
+
zero_output = ops.ZerosLike()(h_t)
|
|
153
|
+
seq_length = ops.Cast()(seq_length, mstype.float32)
|
|
154
|
+
seq_length = ops.broadcast_to(seq_length, (hidden_size, -1))
|
|
155
|
+
seq_length = ops.Cast()(seq_length, mstype.int32)
|
|
156
|
+
seq_length = ops.Transpose()(seq_length, (1, 0))
|
|
158
157
|
|
|
159
158
|
outputs = []
|
|
160
159
|
state_t = h_t
|
|
161
160
|
t = 0
|
|
162
161
|
while t < time_step:
|
|
163
162
|
x_t = x[t:t + 1:1]
|
|
164
|
-
x_t =
|
|
163
|
+
x_t = ops.Squeeze(0)(x_t)
|
|
165
164
|
h_t = self.cell(x_t, state_t, w_ih, w_hh, b_ih, b_hh)
|
|
166
165
|
seq_cond = seq_length > t
|
|
167
166
|
if self.is_lstm:
|
|
168
|
-
state_t_0 =
|
|
169
|
-
state_t_1 =
|
|
170
|
-
output =
|
|
167
|
+
state_t_0 = ops.Select()(seq_cond, h_t[0], state_t[0])
|
|
168
|
+
state_t_1 = ops.Select()(seq_cond, h_t[1], state_t[1])
|
|
169
|
+
output = ops.Select()(seq_cond, h_t[0], zero_output)
|
|
171
170
|
state_t = (state_t_0, state_t_1)
|
|
172
171
|
else:
|
|
173
|
-
state_t =
|
|
174
|
-
output =
|
|
172
|
+
state_t = ops.Select()(seq_cond, h_t, state_t)
|
|
173
|
+
output = ops.Select()(seq_cond, h_t, zero_output)
|
|
175
174
|
outputs.append(output)
|
|
176
175
|
t += 1
|
|
177
|
-
outputs =
|
|
176
|
+
outputs = ops.Stack()(outputs)
|
|
178
177
|
return outputs, state_t
|
|
179
178
|
|
|
180
179
|
def construct(self, x, h, seq_length, w_ih, w_hh, b_ih, b_hh):
|
|
@@ -210,7 +209,7 @@ class _DynamicGRUCPUGPU(Cell):
|
|
|
210
209
|
|
|
211
210
|
def __init__(self):
|
|
212
211
|
super().__init__()
|
|
213
|
-
self.concat =
|
|
212
|
+
self.concat = ops.Concat()
|
|
214
213
|
self.is_gpu = context.get_context("device_target") == "GPU"
|
|
215
214
|
|
|
216
215
|
def construct(self, x, h_0, seq_length, w_ih, w_hh, b_ih, b_hh):
|
|
@@ -253,15 +252,16 @@ class _DynamicGRUAscend(Cell):
|
|
|
253
252
|
|
|
254
253
|
def __init__(self):
|
|
255
254
|
super().__init__()
|
|
256
|
-
self.gru =
|
|
257
|
-
self.transpose =
|
|
255
|
+
self.gru = ops.DynamicGRUV2(gate_order='rzh')
|
|
256
|
+
self.transpose = ops.Transpose()
|
|
258
257
|
self.dtype = mstype.float16
|
|
258
|
+
self.cast = ops.Cast()
|
|
259
259
|
|
|
260
260
|
def construct(self, x, h_0, seq_length, w_ih, w_hh, b_ih, b_hh):
|
|
261
261
|
'''Dynamic GRU module on Ascend'''
|
|
262
262
|
if b_ih is None:
|
|
263
|
-
b_ih =
|
|
264
|
-
b_hh =
|
|
263
|
+
b_ih = ops.zeros(w_ih.shape[0], w_ih.dtype)
|
|
264
|
+
b_hh = ops.zeros(w_ih.shape[0], w_ih.dtype)
|
|
265
265
|
outputs, _, _, _, _, _ = self.gru(self.cast(x, self.dtype), \
|
|
266
266
|
self.cast(self.transpose(w_ih, (1, 0)), self.dtype), \
|
|
267
267
|
self.cast(self.transpose(w_hh, (1, 0)), self.dtype), \
|
|
@@ -282,7 +282,7 @@ class _DynamicLSTMCPUGPU(Cell):
|
|
|
282
282
|
|
|
283
283
|
def __init__(self):
|
|
284
284
|
super().__init__()
|
|
285
|
-
self.concat =
|
|
285
|
+
self.concat = ops.Concat()
|
|
286
286
|
self.is_gpu = context.get_context("device_target") == "GPU"
|
|
287
287
|
|
|
288
288
|
def construct(self, x, h_0, seq_length, w_ih, w_hh, b_ih, b_hh):
|
|
@@ -314,10 +314,10 @@ class _DynamicLSTMCPUGPU(Cell):
|
|
|
314
314
|
w_hh.view(-1, 1, 1),
|
|
315
315
|
bias.view(-1, 1, 1)
|
|
316
316
|
))
|
|
317
|
-
output, h_n, c_n, _, _ =
|
|
317
|
+
output, h_n, c_n, _, _ = ops.LSTM(input_size, hidden_size, 1, has_bias, False, 0.0)(
|
|
318
318
|
x,
|
|
319
|
-
|
|
320
|
-
|
|
319
|
+
ops.ExpandDims()(h_0[0], 0),
|
|
320
|
+
ops.ExpandDims()(h_0[1], 0),
|
|
321
321
|
weights.astype(x.dtype)
|
|
322
322
|
)
|
|
323
323
|
return output, (h_n, c_n)
|
|
@@ -328,12 +328,12 @@ class _DynamicLSTMAscend(Cell):
|
|
|
328
328
|
|
|
329
329
|
def __init__(self):
|
|
330
330
|
super().__init__()
|
|
331
|
-
self.lstm =
|
|
332
|
-
self.concat_dim1 =
|
|
333
|
-
self.concat_dim0 =
|
|
334
|
-
self.transpose =
|
|
335
|
-
self.cast =
|
|
336
|
-
self.split =
|
|
331
|
+
self.lstm = ops.DynamicRNN()
|
|
332
|
+
self.concat_dim1 = ops.Concat(axis=1)
|
|
333
|
+
self.concat_dim0 = ops.Concat(axis=0)
|
|
334
|
+
self.transpose = ops.Transpose()
|
|
335
|
+
self.cast = ops.Cast()
|
|
336
|
+
self.split = ops.Split(axis=0, output_num=4)
|
|
337
337
|
self.dtype = mstype.float16
|
|
338
338
|
|
|
339
339
|
def construct(self, x, h_0, seq_length, w_ih, w_hh, b_ih, b_hh):
|
|
@@ -344,7 +344,7 @@ class _DynamicLSTMAscend(Cell):
|
|
|
344
344
|
w_hh = self.concat_dim0((w_hh_i, w_hh_g, w_hh_f, w_hh_o))
|
|
345
345
|
weight = self.concat_dim1((w_ih, w_hh))
|
|
346
346
|
if b_ih is None:
|
|
347
|
-
bias =
|
|
347
|
+
bias = ops.zeros(w_ih.shape[0], w_ih.dtype)
|
|
348
348
|
else:
|
|
349
349
|
b_ih_i, b_ih_f, b_ih_g, b_ih_o = self.split(b_ih)
|
|
350
350
|
b_hh_i, b_hh_f, b_hh_g, b_hh_o = self.split(b_hh)
|
|
@@ -356,8 +356,8 @@ class _DynamicLSTMAscend(Cell):
|
|
|
356
356
|
outputs, h, c, _, _, _, _, _ = self.lstm(self.cast(x, self.dtype), \
|
|
357
357
|
self.cast(self.transpose(weight, (1, 0)), self.dtype), \
|
|
358
358
|
self.cast(bias, self.dtype), None, \
|
|
359
|
-
self.cast(
|
|
360
|
-
self.cast(
|
|
359
|
+
self.cast(ops.ExpandDims()(h_0[0], 0), self.dtype), \
|
|
360
|
+
self.cast(ops.ExpandDims()(h_0[1], 0), self.dtype))
|
|
361
361
|
if seq_length is not None:
|
|
362
362
|
h = get_hidden(h, seq_length)
|
|
363
363
|
c = get_hidden(c, seq_length)
|
|
@@ -413,8 +413,8 @@ class _RNNBase(Cell):
|
|
|
413
413
|
raise ValueError(f"For '{self.cls_name}', the 'mode' must be in ['RNN_RELU', 'RNN_TANH', 'LSTM', 'GRU'], "
|
|
414
414
|
f"but got {mode}.")
|
|
415
415
|
|
|
416
|
-
self.reverse =
|
|
417
|
-
self.reverse_sequence =
|
|
416
|
+
self.reverse = ops.ReverseV2([0])
|
|
417
|
+
self.reverse_sequence = ops.ReverseSequence(0, 1)
|
|
418
418
|
self.hidden_size = hidden_size
|
|
419
419
|
self.batch_first = batch_first
|
|
420
420
|
self.num_layers = num_layers
|
|
@@ -488,7 +488,7 @@ class _RNNBase(Cell):
|
|
|
488
488
|
output_b = self.reverse(output_b)
|
|
489
489
|
else:
|
|
490
490
|
output_b = self.reverse_sequence(output_b, seq_length)
|
|
491
|
-
output =
|
|
491
|
+
output = ops.Concat(2)((output_f, output_b))
|
|
492
492
|
pre_layer = self.dropout_op(output) if (self.dropout != 0 and i < self.num_layers - 1) else output
|
|
493
493
|
if self.is_lstm:
|
|
494
494
|
h_n += (h_t_f[0], h_t_b[0],)
|
|
@@ -496,14 +496,14 @@ class _RNNBase(Cell):
|
|
|
496
496
|
else:
|
|
497
497
|
h_n += (h_t_f, h_t_b,)
|
|
498
498
|
if self.is_lstm:
|
|
499
|
-
h_n =
|
|
500
|
-
c_n =
|
|
499
|
+
h_n = ops.Concat(0)(h_n)
|
|
500
|
+
c_n = ops.Concat(0)(c_n)
|
|
501
501
|
h0_shape = h[0].shape
|
|
502
502
|
h1_shape = h[1].shape
|
|
503
503
|
h_n = h_n.view(h0_shape)
|
|
504
504
|
c_n = c_n.view(h1_shape)
|
|
505
505
|
return output, (h_n.view(h0_shape), c_n.view(h1_shape))
|
|
506
|
-
h_n =
|
|
506
|
+
h_n = ops.Concat(0)(h_n)
|
|
507
507
|
return output, h_n.view(h.shape)
|
|
508
508
|
|
|
509
509
|
def _stacked_dynamic_rnn(self, x, h, seq_length):
|
|
@@ -530,14 +530,14 @@ class _RNNBase(Cell):
|
|
|
530
530
|
else:
|
|
531
531
|
h_n += (h_t,)
|
|
532
532
|
if self.is_lstm:
|
|
533
|
-
h_n =
|
|
534
|
-
c_n =
|
|
533
|
+
h_n = ops.Concat(0)(h_n)
|
|
534
|
+
c_n = ops.Concat(0)(c_n)
|
|
535
535
|
h0_shape = h[0].shape
|
|
536
536
|
h1_shape = h[1].shape
|
|
537
537
|
h_n = h_n.view(h0_shape)
|
|
538
538
|
c_n = c_n.view(h1_shape)
|
|
539
539
|
return output, (h_n.view(h0_shape), c_n.view(h1_shape))
|
|
540
|
-
h_n =
|
|
540
|
+
h_n = ops.Concat(0)(h_n)
|
|
541
541
|
return output, h_n.view(h.shape)
|
|
542
542
|
|
|
543
543
|
def construct(self, x, hx=None, seq_length=None):
|
|
@@ -565,13 +565,13 @@ class _RNNBase(Cell):
|
|
|
565
565
|
_check_input_dtype(seq_length.dtype, "seq_length", [mstype.int32, mstype.int64], self.cls_name)
|
|
566
566
|
_check_seq_length_size(max_batch_size, seq_length.shape[0], self.cls_name)
|
|
567
567
|
if self.batch_first:
|
|
568
|
-
x =
|
|
568
|
+
x = ops.Transpose()(x, (1, 0, 2))
|
|
569
569
|
if self.bidirectional:
|
|
570
570
|
x_n, hx_n = self._stacked_bi_dynamic_rnn(x, hx, seq_length)
|
|
571
571
|
else:
|
|
572
572
|
x_n, hx_n = self._stacked_dynamic_rnn(x, hx, seq_length)
|
|
573
573
|
if self.batch_first:
|
|
574
|
-
x_n =
|
|
574
|
+
x_n = ops.Transpose()(x_n, (1, 0, 2))
|
|
575
575
|
if not self.is_lstm:
|
|
576
576
|
return x_n.astype(x_dtype), hx_n.astype(x_dtype)
|
|
577
577
|
return x_n.astype(x_dtype), (hx_n[0].astype(x_dtype), hx_n[1].astype(x_dtype))
|
mindspore/nn/layer/thor_layer.py
CHANGED
|
@@ -17,12 +17,12 @@ from __future__ import absolute_import
|
|
|
17
17
|
|
|
18
18
|
import numpy as np
|
|
19
19
|
|
|
20
|
+
import mindspore.ops as ops
|
|
20
21
|
import mindspore.common.dtype as mstype
|
|
21
22
|
import mindspore.log as logger
|
|
22
23
|
from mindspore.common.tensor import Tensor
|
|
23
24
|
from mindspore.common.initializer import initializer, Initializer
|
|
24
25
|
from mindspore.communication.management import get_group_size, get_rank
|
|
25
|
-
from mindspore.ops import operations as P
|
|
26
26
|
from mindspore.ops.operations._thor_ops import ThorIm2Col
|
|
27
27
|
from mindspore.common.parameter import Parameter
|
|
28
28
|
from mindspore import _checkparam as Validator
|
|
@@ -34,7 +34,6 @@ from mindspore.parallel._ps_context import _is_role_worker, _get_ps_context, \
|
|
|
34
34
|
_set_rank_id, _insert_hash_table_size, _set_cache_enable
|
|
35
35
|
from mindspore.parallel._utils import _get_parallel_mode, _get_full_batch
|
|
36
36
|
from mindspore.context import ParallelMode
|
|
37
|
-
from mindspore.ops import functional as F
|
|
38
37
|
from mindspore.nn.layer.basic import ClipByNorm
|
|
39
38
|
from mindspore.ops.primitive import constexpr
|
|
40
39
|
|
|
@@ -61,9 +60,11 @@ class DenseThor(Cell):
|
|
|
61
60
|
in_channels (int): The number of the input channels.
|
|
62
61
|
out_channels (int): The number of the output channels.
|
|
63
62
|
weight_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable weight_init parameter. The dtype
|
|
64
|
-
is same as `x`. The values of str refer to the function
|
|
63
|
+
is same as `x`. The values of str refer to the function :func:`mindspore.common.initializer.initializer`.
|
|
64
|
+
Default: ``'normal'`` .
|
|
65
65
|
bias_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable bias_init parameter. The dtype is
|
|
66
|
-
same as `x`. The values of str refer to the function
|
|
66
|
+
same as `x`. The values of str refer to the function :func:`mindspore.common.initializer.initializer`.
|
|
67
|
+
Default: ``'zeros'`` .
|
|
67
68
|
has_bias (bool): Specifies whether the layer uses a bias vector. Default: ``True`` .
|
|
68
69
|
activation (str): activate function applied to the output of the fully connected layer, eg. 'ReLU'.
|
|
69
70
|
Default: ``None`` .
|
|
@@ -120,9 +121,9 @@ class DenseThor(Cell):
|
|
|
120
121
|
f"be equal to 1, and the first dim must be equal to 'out_channels'. But got "
|
|
121
122
|
f"'bias_init': {bias_init}, 'out_channels': {out_channels}.")
|
|
122
123
|
self.bias = Parameter(initializer(bias_init, [out_channels]), name="bias")
|
|
123
|
-
self.bias_add =
|
|
124
|
+
self.bias_add = ops.BiasAdd()
|
|
124
125
|
|
|
125
|
-
self.matmul =
|
|
126
|
+
self.matmul = ops.MatMul(transpose_b=True)
|
|
126
127
|
self.activation = get_activation(activation)
|
|
127
128
|
self.activation_flag = self.activation is not None
|
|
128
129
|
|
|
@@ -130,25 +131,25 @@ class DenseThor(Cell):
|
|
|
130
131
|
name='matrix_a', requires_grad=False)
|
|
131
132
|
self.matrix_g = Parameter(Tensor(np.eye(out_channels).astype(np.float32)),
|
|
132
133
|
name="matrix_g", requires_grad=False)
|
|
133
|
-
self.shape =
|
|
134
|
-
self.reshape =
|
|
135
|
-
self.transpose =
|
|
136
|
-
self.mul =
|
|
134
|
+
self.shape = ops.Shape()
|
|
135
|
+
self.reshape = ops.Reshape()
|
|
136
|
+
self.transpose = ops.Transpose()
|
|
137
|
+
self.mul = ops.Mul()
|
|
137
138
|
self.is_ascend = True
|
|
138
139
|
self.split_dim = 128
|
|
139
140
|
if context.get_context("device_target") == "Ascend":
|
|
140
141
|
self._process_ascend_dense_thor(out_channels, in_channels)
|
|
141
142
|
else:
|
|
142
143
|
self.is_ascend = False
|
|
143
|
-
self.cube_matmul =
|
|
144
|
-
self.getG =
|
|
144
|
+
self.cube_matmul = ops.MatMul(transpose_a=True)
|
|
145
|
+
self.getG = ops.InsertGradientOf(self.save_gradient)
|
|
145
146
|
|
|
146
147
|
def _process_ascend_dense_thor(self, out_channels, in_channels):
|
|
147
148
|
"""process ascend dense thor"""
|
|
148
|
-
self.matmul =
|
|
149
|
-
self.cube_matmul =
|
|
150
|
-
self.cast =
|
|
151
|
-
self.is_nsp_layer =
|
|
149
|
+
self.matmul = ops.MatMul(transpose_b=True)
|
|
150
|
+
self.cube_matmul = ops.CusMatMulCube(transpose_a=True)
|
|
151
|
+
self.cast = ops.Cast()
|
|
152
|
+
self.is_nsp_layer = out_channels == 2
|
|
152
153
|
|
|
153
154
|
def save_gradient(self, dout):
|
|
154
155
|
"""
|
|
@@ -195,7 +196,7 @@ class DenseThor(Cell):
|
|
|
195
196
|
x = self.activation(x)
|
|
196
197
|
# We use Depend to make 'self.matrix_g' as primal graph's weight parameter,
|
|
197
198
|
# for it's used in 'save_gradient' gradient procedure.
|
|
198
|
-
return
|
|
199
|
+
return ops.depend(x, self.matrix_g)
|
|
199
200
|
|
|
200
201
|
def extend_repr(self):
|
|
201
202
|
s = 'input_channels={}, output_channels={}'.format(self.in_channels, self.out_channels)
|
|
@@ -388,19 +389,19 @@ class Conv2dThor(_ConvThor):
|
|
|
388
389
|
dilation = twice(dilation)
|
|
389
390
|
super(Conv2dThor, self).__init__(in_channels, out_channels, kernel_size,
|
|
390
391
|
stride, pad_mode, padding, dilation, group, has_bias, weight_init, bias_init)
|
|
391
|
-
self.conv2d =
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
self.conv2d = ops.Conv2D(out_channel=self.out_channels, kernel_size=self.kernel_size,
|
|
393
|
+
mode=1, pad_mode=self.pad_mode, pad=self.padding,
|
|
394
|
+
stride=self.stride, dilation=self.dilation, group=self.group)
|
|
394
395
|
self._init_depthwise_conv2d(weight_init)
|
|
395
|
-
self.bias_add =
|
|
396
|
+
self.bias_add = ops.BiasAdd()
|
|
396
397
|
self.thor = True
|
|
397
398
|
self.hw = kernel_size[0] * kernel_size[1]
|
|
398
399
|
self.matrix_a_dim = self.in_channels * self.kernel_size[0] * self.kernel_size[1]
|
|
399
400
|
self.matrix_g_dim = self.out_channels
|
|
400
|
-
self.shape =
|
|
401
|
-
self.reshape =
|
|
402
|
-
self.mul =
|
|
403
|
-
self.cast =
|
|
401
|
+
self.shape = ops.Shape()
|
|
402
|
+
self.reshape = ops.Reshape()
|
|
403
|
+
self.mul = ops.Mul()
|
|
404
|
+
self.cast = ops.Cast()
|
|
404
405
|
self.a_normalizer = Parameter(initializer(1, [1], mstype.float32), name="a_normalizer", requires_grad=False)
|
|
405
406
|
self.g_normalizer = Parameter(initializer(1, [1], mstype.float32), name="g_normalizer", requires_grad=False)
|
|
406
407
|
self.is_ascend = True
|
|
@@ -409,30 +410,30 @@ class Conv2dThor(_ConvThor):
|
|
|
409
410
|
else:
|
|
410
411
|
self.is_ascend = False
|
|
411
412
|
self.img2col = ThorIm2Col(kernel_size=kernel_size, stride=stride, pad_mode="same")
|
|
412
|
-
self.matmul =
|
|
413
|
-
self.reduce_mean =
|
|
413
|
+
self.matmul = ops.MatMul(transpose_b=True)
|
|
414
|
+
self.reduce_mean = ops.ReduceMean(keep_dims=False)
|
|
414
415
|
self.matrix_a_cov = Parameter(Tensor(np.zeros([self.matrix_a_dim, self.matrix_a_dim]).astype(np.float32)),
|
|
415
416
|
name='matrix_a', requires_grad=False)
|
|
416
417
|
self.matrix_g_cov = Parameter(Tensor(np.zeros([self.matrix_g_dim, self.matrix_g_dim]).astype(np.float32)),
|
|
417
418
|
name='matrix_g', requires_grad=False)
|
|
418
|
-
self.getG =
|
|
419
|
+
self.getG = ops.InsertGradientOf(self.save_gradient)
|
|
419
420
|
|
|
420
421
|
def _process_ascend_conv2d_thor(self, kernel_size, stride):
|
|
421
422
|
"""process ascend conv2d thor"""
|
|
422
423
|
ksizes = (1, kernel_size[0], kernel_size[1], 1)
|
|
423
424
|
strides = (1, stride[0], stride[1], 1)
|
|
424
425
|
ksizes_tbe = (kernel_size[0], kernel_size[1])
|
|
425
|
-
self.img2col =
|
|
426
|
-
self.transpose =
|
|
427
|
-
self.reshape =
|
|
428
|
-
self.cube_matmul =
|
|
426
|
+
self.img2col = ops.CusImg2Col(ksizes=ksizes, strides=strides)
|
|
427
|
+
self.transpose = ops.Transpose()
|
|
428
|
+
self.reshape = ops.Reshape()
|
|
429
|
+
self.cube_matmul = ops.CusMatMulCube(transpose_a=True)
|
|
429
430
|
self.diag_block_dim = 128
|
|
430
431
|
self.matrix_a_cov = Parameter(Tensor(np.eye(self.matrix_a_dim).astype(np.float32)),
|
|
431
432
|
name='matrix_a', requires_grad=False)
|
|
432
433
|
self.matrix_g_cov = Parameter(Tensor(np.eye(self.matrix_g_dim).astype(np.float32)),
|
|
433
434
|
name='matrix_g', requires_grad=False)
|
|
434
|
-
self.slice =
|
|
435
|
-
self.im2col =
|
|
435
|
+
self.slice = ops.Slice()
|
|
436
|
+
self.im2col = ops.NewIm2Col(ksizes=ksizes_tbe, strides=stride[0], padding_mode="SAME")
|
|
436
437
|
|
|
437
438
|
def _init_depthwise_conv2d(self, weight_init):
|
|
438
439
|
"""Initialize depthwise conv2d op"""
|
|
@@ -440,12 +441,12 @@ class Conv2dThor(_ConvThor):
|
|
|
440
441
|
self.dilation = self._dilation
|
|
441
442
|
Validator.check_int('group', self.group, self.in_channels, Validator.EQ, self.cls_name)
|
|
442
443
|
Validator.check_int('group', self.group, self.out_channels, Validator.EQ, self.cls_name)
|
|
443
|
-
self.conv2d =
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
444
|
+
self.conv2d = ops.DepthwiseConv2dNative(channel_multiplier=1,
|
|
445
|
+
kernel_size=self.kernel_size,
|
|
446
|
+
pad_mode=self.pad_mode,
|
|
447
|
+
pad=self.padding,
|
|
448
|
+
stride=self.stride,
|
|
449
|
+
dilation=self.dilation)
|
|
449
450
|
weight_shape = [1, self.in_channels, *self.kernel_size]
|
|
450
451
|
self.weight_init = weight_init
|
|
451
452
|
if isinstance(weight_init, Tensor):
|
|
@@ -598,29 +599,29 @@ class EmbeddingThor(Cell):
|
|
|
598
599
|
"padding_idx", self.cls_name)
|
|
599
600
|
self.init_tensor[self.padding_idx] = 0
|
|
600
601
|
self.embedding_table = Parameter(self.init_tensor, name='embedding_table')
|
|
601
|
-
self.expand =
|
|
602
|
-
self.reshape_flat =
|
|
602
|
+
self.expand = ops.ExpandDims()
|
|
603
|
+
self.reshape_flat = ops.Reshape()
|
|
603
604
|
self.shp_flat = (-1,)
|
|
604
|
-
self.gather =
|
|
605
|
-
self.one_hot =
|
|
605
|
+
self.gather = ops.Gather()
|
|
606
|
+
self.one_hot = ops.OneHot()
|
|
606
607
|
self.on_value = Tensor(1.0, self.dtype)
|
|
607
608
|
self.off_value = Tensor(0.0, self.dtype)
|
|
608
|
-
self.array_mul =
|
|
609
|
-
self.reshape =
|
|
610
|
-
self.get_shp =
|
|
609
|
+
self.array_mul = ops.MatMul()
|
|
610
|
+
self.reshape = ops.Reshape()
|
|
611
|
+
self.get_shp = ops.Shape()
|
|
611
612
|
self.thor = True
|
|
612
613
|
self.matrix_a = Parameter(Tensor(np.zeros([vocab_size]).astype(np.float32)),
|
|
613
614
|
name='matrix_a', requires_grad=False)
|
|
614
615
|
self.matrix_g = Parameter(Tensor(np.zeros([embedding_size, embedding_size]).astype(np.float32)),
|
|
615
616
|
name="matrix_g", requires_grad=False)
|
|
616
|
-
self.reduce_sum =
|
|
617
|
-
self.getG =
|
|
618
|
-
self.cast =
|
|
617
|
+
self.reduce_sum = ops.ReduceSum(keep_dims=False)
|
|
618
|
+
self.getG = ops.InsertGradientOf(self.save_gradient)
|
|
619
|
+
self.cast = ops.Cast()
|
|
619
620
|
if context.get_context("device_target") == "Ascend":
|
|
620
|
-
self.cube_matmul =
|
|
621
|
+
self.cube_matmul = ops.CusMatMulCube(transpose_a=True)
|
|
621
622
|
else:
|
|
622
|
-
self.cube_matmul =
|
|
623
|
-
self.mul =
|
|
623
|
+
self.cube_matmul = ops.MatMul(transpose_a=True)
|
|
624
|
+
self.mul = ops.Mul()
|
|
624
625
|
|
|
625
626
|
def save_gradient(self, dout):
|
|
626
627
|
"""
|
|
@@ -656,7 +657,7 @@ class EmbeddingThor(Cell):
|
|
|
656
657
|
output = self.reshape(output_for_reshape, out_shape)
|
|
657
658
|
# We use Depend to make 'self.matrix_g' as primal graph's weight parameter,
|
|
658
659
|
# for it's used in 'save_gradient' gradient procedure.
|
|
659
|
-
return
|
|
660
|
+
return ops.depend(output, self.matrix_g)
|
|
660
661
|
|
|
661
662
|
def extend_repr(self):
|
|
662
663
|
s = 'vocab_size={}, embedding_size={}, use_one_hot={}, embedding_table={}, dtype={}, padding_idx={}'.format(
|
|
@@ -752,10 +753,10 @@ class EmbeddingLookupThor(Cell):
|
|
|
752
753
|
raise ValueError(f"For '{self.cls_name}', embedding_lookup must be sparse when 'target' is CPU, but got "
|
|
753
754
|
f"'sparse': {sparse}, 'target': {target}.")
|
|
754
755
|
if sparse:
|
|
755
|
-
self.gatherv2 =
|
|
756
|
+
self.gatherv2 = ops.SparseGatherV2()
|
|
756
757
|
else:
|
|
757
|
-
self.gatherv2 =
|
|
758
|
-
self.embeddinglookup =
|
|
758
|
+
self.gatherv2 = ops.Gather()
|
|
759
|
+
self.embeddinglookup = ops.EmbeddingLookup().set_device('CPU')
|
|
759
760
|
enable_ps = _get_ps_context("enable_ps")
|
|
760
761
|
if enable_ps:
|
|
761
762
|
self._process_vocab_cache(slice_mode)
|
|
@@ -764,13 +765,13 @@ class EmbeddingLookupThor(Cell):
|
|
|
764
765
|
mstype.float16), name='embedding_table')
|
|
765
766
|
parallel_mode = _get_parallel_mode()
|
|
766
767
|
is_auto_parallel = parallel_mode in (ParallelMode.SEMI_AUTO_PARALLEL, ParallelMode.AUTO_PARALLEL)
|
|
767
|
-
self.gather_revert =
|
|
768
|
-
self.reshape_first =
|
|
769
|
-
self.reshape =
|
|
770
|
-
self.unique =
|
|
771
|
-
self.shape =
|
|
768
|
+
self.gather_revert = ops.Gather()
|
|
769
|
+
self.reshape_first = ops.Reshape()
|
|
770
|
+
self.reshape = ops.Reshape()
|
|
771
|
+
self.unique = ops.Unique()
|
|
772
|
+
self.shape = ops.Shape()
|
|
772
773
|
if is_auto_parallel:
|
|
773
|
-
self.unique =
|
|
774
|
+
self.unique = ops.Unique().shard(((1,),))
|
|
774
775
|
if self.cache_enable and enable_ps:
|
|
775
776
|
self._set_voacb_cache_enable_for_ps(vocab_cache_size, embedding_size, vocab_size)
|
|
776
777
|
if is_auto_parallel:
|
|
@@ -833,14 +834,14 @@ class EmbeddingLookupThor(Cell):
|
|
|
833
834
|
name='matrix_a', requires_grad=False)
|
|
834
835
|
self.matrix_g = Parameter(Tensor(np.zeros([embedding_size, embedding_size]).astype(np.float32)),
|
|
835
836
|
name="matrix_g", requires_grad=False)
|
|
836
|
-
self.reduce_sum =
|
|
837
|
-
self.getG =
|
|
838
|
-
self.cast =
|
|
839
|
-
self.cube_matmul =
|
|
840
|
-
self.mul =
|
|
837
|
+
self.reduce_sum = ops.ReduceSum(keep_dims=False)
|
|
838
|
+
self.getG = ops.InsertGradientOf(self.save_gradient)
|
|
839
|
+
self.cast = ops.Cast()
|
|
840
|
+
self.cube_matmul = ops.MatMul(transpose_a=True)
|
|
841
|
+
self.mul = ops.Mul()
|
|
841
842
|
self.on_value = Tensor(1.0, self.dtype)
|
|
842
843
|
self.off_value = Tensor(0.0, self.dtype)
|
|
843
|
-
self.one_hot =
|
|
844
|
+
self.one_hot = ops.OneHot()
|
|
844
845
|
|
|
845
846
|
|
|
846
847
|
def save_gradient(self, dout):
|
|
@@ -872,11 +873,11 @@ class EmbeddingLookupThor(Cell):
|
|
|
872
873
|
|
|
873
874
|
logger.info("EmbeddingLookup cache enable takes effect.")
|
|
874
875
|
self.forward_unique = True
|
|
875
|
-
self.unique =
|
|
876
|
+
self.unique = ops.Unique().set_device('CPU')
|
|
876
877
|
self.unique.add_prim_attr('cache_enable', True)
|
|
877
878
|
self.embedding_table.cache_enable = self.cache_enable
|
|
878
879
|
self.embedding_table.cache_shape = (self.vocab_cache_size, self.embedding_size)
|
|
879
|
-
self.reshape_first =
|
|
880
|
+
self.reshape_first = ops.Reshape().set_device('CPU')
|
|
880
881
|
|
|
881
882
|
def _process_vocab_cache(self, slice_mode):
|
|
882
883
|
"""PS embeddingLookup cache check and process."""
|
|
@@ -955,9 +956,9 @@ class EmbeddingLookupThor(Cell):
|
|
|
955
956
|
else:
|
|
956
957
|
out = self.gatherv2(self.embedding_table, indices, 0)
|
|
957
958
|
if self.max_norm is not None:
|
|
958
|
-
axis = _make_axis_range(
|
|
959
|
+
axis = _make_axis_range(ops.rank(indices), ops.rank(out))
|
|
959
960
|
clip_by_norm = ClipByNorm(axis)
|
|
960
961
|
out = clip_by_norm(out, self.max_norm)
|
|
961
962
|
# We use Depend to make 'self.matrix_g' as primal graph's weight parameter,
|
|
962
963
|
# for it's used in 'save_gradient' gradient procedure.
|
|
963
|
-
return
|
|
964
|
+
return ops.depend(out, self.matrix_g)
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
# ============================================================================
|
|
15
|
+
# The implementation of the classes `MultiheadAttention`, `TransformerEncoderLayer`, `TransformerDecoderLayer`,
|
|
16
|
+
# `TransformerEncoder`, `TransformerDecoder` and `Transformer` is referenced from the PyTorch project.
|
|
17
|
+
# - https://github.com/pytorch/pytorch/blob/release/2.0/torch/nn/modules/transformer.py
|
|
18
|
+
# - https://github.com/pytorch/pytorch/blob/release/2.0/torch/nn/modules/activation.py
|
|
19
|
+
# Additional modifications are made by Huawei Technologies Co., Ltd in 2022.
|
|
15
20
|
"""
|
|
16
21
|
Transformer Cells module, include TransformerEncoderLayer, TransformerDecoderLayer,
|
|
17
22
|
TransformerEncoder, TransformerDecoder, Transformer.
|
|
@@ -245,7 +250,12 @@ class MultiheadAttention(Cell):
|
|
|
245
250
|
class TransformerEncoderLayer(Cell):
|
|
246
251
|
r"""
|
|
247
252
|
Transformer Encoder Layer. This is an implementation of the single layer of the transformer
|
|
248
|
-
encoder layer, including
|
|
253
|
+
encoder layer, mainly including Multi-Head Attention, Feed Forward, Add and LayerNorm layer.
|
|
254
|
+
|
|
255
|
+
The TransformerEncoderLayer structure is shown in the following figure:
|
|
256
|
+
|
|
257
|
+
.. image:: ../images/TransformerEncoderLayer.png
|
|
258
|
+
:align: center
|
|
249
259
|
|
|
250
260
|
Args:
|
|
251
261
|
d_model (int): The number of features in the input tensor.
|