mindspore 2.4.10__cp39-cp39-win_amd64.whl → 2.5.0__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
- mindspore/Newtonsoft.Json.dll +0 -0
- mindspore/__init__.py +8 -3
- 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 +0 -5
- mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +1 -1
- mindspore/_extends/parse/compile_config.py +64 -0
- mindspore/_extends/parse/deprecated/__init__.py +0 -0
- mindspore/_extends/parse/deprecated/deprecated_tensor_method.py +375 -0
- mindspore/_extends/parse/parser.py +23 -5
- mindspore/_extends/parse/standard_method.py +123 -27
- mindspore/_extends/pijit/pijit_func_white_list.py +1 -1
- mindspore/amp.py +7 -1
- mindspore/atlprov.dll +0 -0
- 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/boost_cell_wrapper.py +136 -41
- mindspore/c1.dll +0 -0
- mindspore/c1xx.dll +0 -0
- mindspore/c2.dll +0 -0
- mindspore/common/__init__.py +3 -1
- mindspore/common/_register_for_tensor.py +0 -1
- mindspore/common/_stub_tensor.py +25 -4
- mindspore/common/_tensor_cpp_method.py +17 -0
- mindspore/common/_tensor_docs.py +6132 -0
- mindspore/common/api.py +98 -21
- mindspore/common/dtype.py +34 -34
- mindspore/common/dump.py +2 -1
- mindspore/common/file_system.py +8 -3
- mindspore/common/generator.py +2 -0
- mindspore/common/hook_handle.py +3 -1
- mindspore/common/initializer.py +3 -4
- mindspore/common/lazy_inline.py +8 -2
- mindspore/common/mindir_util.py +10 -2
- mindspore/common/parameter.py +31 -15
- mindspore/common/tensor.py +713 -1337
- mindspore/communication/__init__.py +1 -1
- mindspore/communication/_comm_helper.py +5 -0
- mindspore/communication/comm_func.py +215 -173
- mindspore/communication/management.py +23 -20
- mindspore/context.py +285 -191
- mindspore/dataset/__init__.py +23 -19
- mindspore/dataset/callback/ds_callback.py +2 -1
- mindspore/dataset/core/config.py +84 -3
- mindspore/dataset/engine/cache_admin.py +3 -3
- mindspore/dataset/engine/cache_client.py +5 -4
- mindspore/dataset/engine/datasets.py +192 -149
- mindspore/dataset/engine/datasets_audio.py +14 -0
- mindspore/dataset/engine/datasets_standard_format.py +11 -11
- mindspore/dataset/engine/datasets_text.py +38 -1
- mindspore/dataset/engine/datasets_user_defined.py +100 -66
- mindspore/dataset/engine/datasets_vision.py +81 -8
- mindspore/dataset/engine/iterators.py +281 -63
- mindspore/dataset/engine/obs/util.py +8 -0
- mindspore/dataset/engine/queue.py +40 -0
- mindspore/dataset/engine/samplers.py +26 -2
- mindspore/dataset/engine/serializer_deserializer.py +1 -1
- mindspore/dataset/engine/validators.py +43 -11
- mindspore/dataset/transforms/py_transforms_util.py +17 -0
- mindspore/dataset/transforms/transforms.py +29 -12
- mindspore/dataset/vision/validators.py +1 -2
- mindspore/device_context/__init__.py +21 -0
- mindspore/device_context/ascend/__init__.py +25 -0
- mindspore/device_context/ascend/device.py +72 -0
- mindspore/device_context/ascend/op_debug.py +94 -0
- mindspore/device_context/ascend/op_precision.py +193 -0
- mindspore/device_context/ascend/op_tuning.py +127 -0
- mindspore/device_context/cpu/__init__.py +25 -0
- mindspore/device_context/cpu/device.py +62 -0
- mindspore/device_context/cpu/op_tuning.py +43 -0
- mindspore/device_context/gpu/__init__.py +21 -0
- mindspore/device_context/gpu/device.py +70 -0
- mindspore/device_context/gpu/op_precision.py +67 -0
- mindspore/device_context/gpu/op_tuning.py +175 -0
- mindspore/device_manager.py +134 -0
- mindspore/dnnl.dll +0 -0
- mindspore/dpcmi.dll +0 -0
- mindspore/experimental/llm_boost/__init__.py +1 -0
- mindspore/experimental/llm_boost/ascend_native/__init__.py +22 -0
- mindspore/experimental/llm_boost/ascend_native/llama_boost_ascend_native.py +211 -0
- mindspore/experimental/llm_boost/ascend_native/llm_boost.py +52 -0
- mindspore/experimental/llm_boost/atb/boost_base.py +2 -3
- mindspore/experimental/llm_boost/atb/llama_boost.py +6 -1
- mindspore/experimental/llm_boost/register.py +1 -0
- mindspore/experimental/optim/adadelta.py +26 -22
- mindspore/experimental/optim/adam.py +3 -0
- mindspore/experimental/optim/lr_scheduler.py +33 -24
- mindspore/experimental/optim/radam.py +33 -30
- mindspore/hal/device.py +28 -0
- mindspore/hal/event.py +17 -0
- mindspore/hal/memory.py +94 -3
- mindspore/hal/stream.py +91 -6
- mindspore/include/api/context.h +0 -1
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +12 -0
- mindspore/mindrecord/__init__.py +1 -1
- mindspore/mindrecord/config.py +17 -316
- mindspore/mindrecord/filereader.py +1 -9
- mindspore/mindrecord/filewriter.py +5 -15
- mindspore/mindrecord/mindpage.py +1 -9
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_ops.dll +0 -0
- mindspore/mint/__init__.py +824 -218
- mindspore/mint/distributed/__init__.py +66 -4
- mindspore/mint/distributed/distributed.py +2594 -44
- mindspore/mint/linalg/__init__.py +6 -0
- mindspore/mint/nn/__init__.py +473 -14
- mindspore/mint/nn/functional.py +486 -11
- mindspore/mint/nn/layer/__init__.py +17 -4
- mindspore/mint/nn/layer/_functions.py +330 -0
- mindspore/mint/nn/layer/activation.py +169 -1
- mindspore/mint/nn/layer/basic.py +123 -0
- mindspore/mint/nn/layer/conv.py +727 -0
- mindspore/mint/nn/layer/normalization.py +215 -19
- mindspore/mint/nn/layer/padding.py +797 -0
- mindspore/mint/nn/layer/pooling.py +170 -0
- mindspore/mint/optim/__init__.py +2 -1
- mindspore/mint/optim/adam.py +223 -0
- mindspore/mint/optim/adamw.py +26 -19
- mindspore/mint/special/__init__.py +2 -1
- mindspore/msobj140.dll +0 -0
- mindspore/mspdb140.dll +0 -0
- mindspore/mspdbcore.dll +0 -0
- mindspore/mspdbst.dll +0 -0
- mindspore/mspft140.dll +0 -0
- mindspore/msvcdis140.dll +0 -0
- mindspore/msvcp140_1.dll +0 -0
- mindspore/msvcp140_2.dll +0 -0
- mindspore/msvcp140_atomic_wait.dll +0 -0
- mindspore/msvcp140_codecvt_ids.dll +0 -0
- mindspore/multiprocessing/__init__.py +5 -0
- mindspore/nn/cell.py +126 -19
- mindspore/nn/dynamic_lr.py +2 -1
- mindspore/nn/layer/activation.py +6 -6
- mindspore/nn/layer/basic.py +35 -25
- mindspore/nn/layer/channel_shuffle.py +3 -3
- mindspore/nn/layer/embedding.py +3 -3
- mindspore/nn/layer/normalization.py +8 -7
- mindspore/nn/layer/padding.py +4 -3
- mindspore/nn/layer/pooling.py +47 -13
- mindspore/nn/layer/rnn_cells.py +1 -1
- mindspore/nn/layer/rnns.py +2 -1
- mindspore/nn/layer/timedistributed.py +5 -5
- mindspore/nn/layer/transformer.py +48 -26
- mindspore/nn/learning_rate_schedule.py +5 -3
- mindspore/nn/loss/loss.py +31 -36
- mindspore/nn/optim/ada_grad.py +1 -0
- mindspore/nn/optim/adadelta.py +2 -2
- mindspore/nn/optim/adam.py +1 -1
- mindspore/nn/optim/lars.py +1 -4
- mindspore/nn/optim/optimizer.py +1 -1
- mindspore/nn/optim/rprop.py +2 -2
- mindspore/nn/optim/thor.py +2 -1
- mindspore/nn/utils/init.py +13 -11
- mindspore/nn/wrap/cell_wrapper.py +4 -6
- mindspore/nn/wrap/loss_scale.py +3 -4
- mindspore/numpy/array_creations.py +60 -62
- mindspore/numpy/array_ops.py +148 -143
- mindspore/numpy/logic_ops.py +41 -42
- mindspore/numpy/math_ops.py +361 -359
- mindspore/numpy/utils.py +16 -16
- mindspore/numpy/utils_const.py +4 -4
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/__init__.py +2 -1
- mindspore/ops/_grad_experimental/grad_comm_ops.py +94 -13
- mindspore/ops/_grad_experimental/grad_debug_ops.py +6 -1
- mindspore/ops/_grad_experimental/grad_inner_ops.py +9 -0
- mindspore/ops/_grad_experimental/grad_math_ops.py +2 -1
- mindspore/ops/_op_impl/cpu/__init__.py +1 -0
- mindspore/ops/_op_impl/cpu/raise_op.py +28 -0
- mindspore/ops/_vmap/vmap_array_ops.py +20 -19
- mindspore/ops/_vmap/vmap_base.py +0 -2
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +19 -13
- mindspore/ops/_vmap/vmap_math_ops.py +11 -9
- mindspore/ops/_vmap/vmap_nn_ops.py +20 -34
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +149 -12
- mindspore/ops/auto_generate/gen_arg_handler.py +0 -61
- mindspore/ops/auto_generate/gen_extend_func.py +554 -60
- mindspore/ops/auto_generate/gen_ops_def.py +1621 -115
- mindspore/ops/auto_generate/gen_ops_prim.py +8024 -3409
- mindspore/ops/auto_generate/pyboost_inner_prim.py +183 -79
- mindspore/ops/composite/base.py +1 -1
- mindspore/ops/composite/multitype_ops/_compile_utils.py +229 -30
- mindspore/ops/composite/multitype_ops/pow_impl.py +0 -29
- mindspore/ops/function/__init__.py +12 -0
- mindspore/ops/function/array_func.py +561 -159
- mindspore/ops/function/clip_func.py +64 -0
- mindspore/ops/function/debug_func.py +28 -20
- mindspore/ops/function/image_func.py +1 -1
- mindspore/ops/function/linalg_func.py +5 -4
- mindspore/ops/function/math_func.py +1659 -290
- mindspore/ops/function/nn_func.py +988 -317
- mindspore/ops/function/parameter_func.py +3 -56
- mindspore/ops/function/random_func.py +243 -33
- mindspore/ops/function/sparse_unary_func.py +1 -1
- mindspore/ops/functional.py +18 -5
- mindspore/ops/functional_overload.py +897 -0
- mindspore/ops/operations/__init__.py +3 -2
- mindspore/ops/operations/_embedding_cache_ops.py +4 -4
- mindspore/ops/operations/_grad_ops.py +2 -34
- mindspore/ops/operations/_infer_ops.py +2 -1
- mindspore/ops/operations/_inner_ops.py +38 -8
- mindspore/ops/operations/array_ops.py +45 -303
- mindspore/ops/operations/comm_ops.py +19 -16
- mindspore/ops/operations/custom_ops.py +11 -55
- mindspore/ops/operations/debug_ops.py +42 -47
- mindspore/ops/operations/inner_ops.py +6 -4
- mindspore/ops/operations/linalg_ops.py +3 -2
- mindspore/ops/operations/manually_defined/ops_def.py +185 -104
- mindspore/ops/operations/math_ops.py +11 -216
- mindspore/ops/operations/nn_ops.py +146 -308
- mindspore/ops/primitive.py +23 -21
- mindspore/ops/tensor_method.py +1669 -0
- mindspore/ops_generate/aclnn_kernel_register_auto_cc_generator.py +110 -0
- mindspore/ops_generate/add_tensor_docs_generator.py +54 -0
- mindspore/ops_generate/arg_handler.py +0 -61
- mindspore/ops_generate/auto_grad_impl_cc_generator.py +135 -0
- mindspore/ops_generate/auto_grad_reg_cc_generator.py +93 -0
- mindspore/ops_generate/base_generator.py +11 -0
- mindspore/ops_generate/cpp_create_prim_instance_helper_generator.py +108 -0
- mindspore/ops_generate/functional_map_cpp_generator.py +491 -0
- mindspore/ops_generate/functional_overload_py_generator.py +110 -0
- mindspore/ops_generate/functions_cc_generator.py +233 -0
- mindspore/ops_generate/gen_aclnn_implement.py +110 -114
- mindspore/ops_generate/gen_constants.py +157 -3
- mindspore/ops_generate/gen_ops.py +245 -990
- mindspore/ops_generate/gen_pyboost_func.py +97 -998
- mindspore/ops_generate/gen_utils.py +119 -33
- mindspore/ops_generate/lite_ops_cpp_generator.py +155 -0
- mindspore/ops_generate/op_api_proto.py +206 -0
- mindspore/ops_generate/op_def_py_generator.py +131 -0
- mindspore/ops_generate/op_prim_py_generator.py +480 -0
- mindspore/ops_generate/op_proto.py +373 -108
- mindspore/ops_generate/op_template_parser.py +436 -0
- mindspore/ops_generate/ops_def_cc_generator.py +288 -0
- mindspore/ops_generate/ops_def_h_generator.py +74 -0
- mindspore/ops_generate/ops_name_h_generator.py +68 -0
- mindspore/ops_generate/ops_primitive_h_generator.py +81 -0
- mindspore/ops_generate/pyboost_functions_cpp_generator.py +370 -0
- mindspore/ops_generate/pyboost_functions_h_generator.py +68 -0
- mindspore/ops_generate/pyboost_functions_py_generator.py +148 -0
- mindspore/ops_generate/pyboost_grad_function_cpp_generator.py +154 -0
- mindspore/ops_generate/pyboost_inner_prim_generator.py +131 -0
- mindspore/ops_generate/pyboost_native_grad_functions_generator.py +268 -0
- mindspore/ops_generate/pyboost_op_cpp_code_generator.py +851 -0
- mindspore/ops_generate/pyboost_overload_functions_cpp_generator.py +344 -0
- mindspore/ops_generate/pyboost_utils.py +92 -33
- mindspore/ops_generate/template.py +294 -44
- mindspore/ops_generate/tensor_func_reg_cpp_generator.py +422 -0
- mindspore/parallel/__init__.py +3 -3
- mindspore/parallel/_auto_parallel_context.py +24 -33
- mindspore/parallel/_parallel_serialization.py +13 -2
- mindspore/parallel/_utils.py +4 -1
- mindspore/parallel/algo_parameter_config.py +1 -1
- mindspore/parallel/checkpoint_transform.py +44 -0
- mindspore/parallel/cluster/process_entity/_api.py +131 -37
- mindspore/parallel/cluster/process_entity/_utils.py +41 -6
- mindspore/parallel/cluster/run.py +20 -3
- mindspore/parallel/parameter_broadcast.py +1 -1
- mindspore/parallel/shard.py +3 -0
- mindspore/parallel/transform_safetensors.py +119 -253
- mindspore/pgodb140.dll +0 -0
- mindspore/pgort140.dll +0 -0
- mindspore/profiler/__init__.py +17 -4
- mindspore/profiler/analysis/__init__.py +0 -0
- mindspore/profiler/analysis/parser/__init__.py +0 -0
- mindspore/profiler/analysis/parser/ascend_cann_parser.py +166 -0
- mindspore/profiler/analysis/parser/base_parser.py +158 -0
- mindspore/profiler/analysis/parser/framework_cann_relation_parser.py +45 -0
- mindspore/profiler/analysis/parser/ms_framework_parser.py +142 -0
- mindspore/profiler/analysis/parser/ms_minddata_parser.py +145 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/__init__.py +0 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/ascend_timeline_assembler.py +261 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/base_timeline_assembler.py +40 -0
- mindspore/profiler/analysis/parser/timeline_assembly_factory/trace_view_container.py +84 -0
- mindspore/profiler/analysis/parser/timeline_creator/__init__.py +0 -0
- mindspore/profiler/analysis/parser/timeline_creator/base_timeline_creator.py +44 -0
- mindspore/profiler/analysis/parser/timeline_creator/cpu_op_timeline_creator.py +90 -0
- mindspore/profiler/analysis/parser/timeline_creator/fwk_timeline_creator.py +76 -0
- mindspore/profiler/analysis/parser/timeline_creator/msprof_timeline_creator.py +103 -0
- mindspore/profiler/analysis/parser/timeline_creator/scope_layer_timeline_creator.py +134 -0
- mindspore/profiler/analysis/parser/timeline_event/__init__.py +0 -0
- mindspore/profiler/analysis/parser/timeline_event/base_event.py +233 -0
- mindspore/profiler/analysis/parser/timeline_event/cpu_op_event.py +47 -0
- mindspore/profiler/analysis/parser/timeline_event/flow_event.py +36 -0
- mindspore/profiler/analysis/parser/timeline_event/fwk_event.py +260 -0
- mindspore/profiler/analysis/parser/timeline_event/msprof_event.py +73 -0
- mindspore/profiler/analysis/parser/timeline_event/scope_layer_event.py +53 -0
- mindspore/profiler/analysis/parser/timeline_event/timeline_event_pool.py +146 -0
- mindspore/profiler/analysis/task_manager.py +131 -0
- mindspore/profiler/analysis/time_converter.py +84 -0
- mindspore/profiler/analysis/viewer/__init__.py +0 -0
- mindspore/profiler/analysis/viewer/ascend_communication_viewer.py +333 -0
- mindspore/profiler/analysis/viewer/ascend_integrate_viewer.py +87 -0
- mindspore/profiler/analysis/viewer/ascend_kernel_details_viewer.py +252 -0
- mindspore/profiler/analysis/viewer/ascend_memory_viewer.py +313 -0
- mindspore/profiler/analysis/viewer/ascend_op_memory_viewer.py +322 -0
- mindspore/profiler/analysis/viewer/ascend_step_trace_time_viewer.py +265 -0
- mindspore/profiler/analysis/viewer/ascend_timeline_viewer.py +58 -0
- mindspore/profiler/analysis/viewer/base_viewer.py +26 -0
- mindspore/profiler/analysis/viewer/ms_dataset_viewer.py +97 -0
- mindspore/profiler/analysis/viewer/ms_minddata_viewer.py +581 -0
- mindspore/profiler/analysis/work_flow.py +73 -0
- mindspore/profiler/common/ascend_msprof_exporter.py +138 -0
- mindspore/profiler/common/command_executor.py +90 -0
- mindspore/profiler/common/constant.py +174 -3
- mindspore/profiler/common/file_manager.py +208 -0
- mindspore/profiler/common/log.py +130 -0
- mindspore/profiler/common/msprof_cmd_tool.py +202 -0
- mindspore/profiler/common/path_manager.py +371 -0
- mindspore/profiler/common/process_bar.py +168 -0
- mindspore/profiler/common/process_pool.py +9 -3
- mindspore/profiler/common/profiler_context.py +476 -0
- mindspore/profiler/common/profiler_info.py +304 -0
- mindspore/profiler/common/profiler_output_path.py +284 -0
- mindspore/profiler/common/profiler_parameters.py +210 -0
- mindspore/profiler/common/profiler_path_manager.py +120 -0
- mindspore/profiler/common/record_function.py +76 -0
- mindspore/profiler/common/tlv_decoder.py +76 -0
- mindspore/profiler/common/util.py +75 -2
- mindspore/profiler/dynamic_profiler.py +270 -37
- mindspore/profiler/envprofiler.py +138 -0
- mindspore/profiler/mstx.py +199 -0
- mindspore/profiler/platform/__init__.py +21 -0
- mindspore/profiler/platform/base_profiler.py +40 -0
- mindspore/profiler/platform/cpu_profiler.py +124 -0
- mindspore/profiler/platform/gpu_profiler.py +74 -0
- mindspore/profiler/platform/npu_profiler.py +309 -0
- mindspore/profiler/profiler.py +580 -93
- mindspore/profiler/profiler_action_controller.py +187 -0
- mindspore/profiler/profiler_interface.py +114 -0
- mindspore/profiler/schedule.py +208 -0
- mindspore/rewrite/api/symbol_tree.py +1 -2
- mindspore/run_check/_check_version.py +2 -6
- mindspore/runtime/__init__.py +37 -0
- mindspore/runtime/device.py +27 -0
- mindspore/runtime/event.py +209 -0
- mindspore/runtime/executor.py +148 -0
- mindspore/runtime/memory.py +392 -0
- mindspore/runtime/stream.py +460 -0
- mindspore/runtime/thread_bind_core.py +401 -0
- mindspore/swresample-4.dll +0 -0
- mindspore/swscale-6.dll +0 -0
- mindspore/tbbmalloc.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +2 -2
- mindspore/train/_utils.py +53 -18
- mindspore/train/amp.py +8 -4
- mindspore/train/callback/_checkpoint.py +32 -18
- mindspore/train/callback/_early_stop.py +1 -1
- mindspore/train/callback/_flops_collector.py +105 -69
- mindspore/train/callback/_history.py +1 -1
- mindspore/train/callback/_summary_collector.py +44 -6
- mindspore/train/callback/_tft_register.py +31 -10
- mindspore/train/dataset_helper.py +11 -11
- mindspore/train/metrics/precision.py +4 -5
- mindspore/train/mind_ir_pb2.py +167 -46
- mindspore/train/model.py +13 -15
- mindspore/train/serialization.py +462 -76
- mindspore/train/summary/summary_record.py +1 -2
- mindspore/train/train_thor/model_thor.py +1 -1
- mindspore/turbojpeg.dll +0 -0
- mindspore/utils/__init__.py +4 -2
- mindspore/utils/dryrun.py +138 -0
- mindspore/utils/runtime_execution_order_check.py +550 -0
- mindspore/vcmeta.dll +0 -0
- mindspore/vcruntime140.dll +0 -0
- mindspore/vcruntime140_1.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/METADATA +2 -3
- {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/RECORD +385 -261
- {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/entry_points.txt +1 -1
- mindspore/common/_tensor_overload.py +0 -139
- mindspore/mindspore_np_dtype.dll +0 -0
- mindspore/profiler/envprofiling.py +0 -254
- mindspore/profiler/profiling.py +0 -1926
- {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/WHEEL +0 -0
- {mindspore-2.4.10.dist-info → mindspore-2.5.0.dist-info}/top_level.txt +0 -0
mindspore/hal/stream.py
CHANGED
|
@@ -21,8 +21,13 @@ from mindspore._c_expression import default_stream as default_stream_
|
|
|
21
21
|
from mindspore._c_expression import communication_stream as communication_stream_
|
|
22
22
|
|
|
23
23
|
from mindspore import _checkparam as Validator
|
|
24
|
+
from mindspore import log as logger
|
|
24
25
|
from .event import Event
|
|
25
26
|
|
|
27
|
+
function_stream_status = {'record_event': False, 'wait_event': False, 'wait_stream': False,
|
|
28
|
+
'query': False, 'synchronize': False, 'set_cur_stream': False,
|
|
29
|
+
'current_stream': False, 'default_stream': False,
|
|
30
|
+
'communication_stream': False, 'StreamCtx': False}
|
|
26
31
|
|
|
27
32
|
class Stream(Stream_):
|
|
28
33
|
r"""
|
|
@@ -31,13 +36,15 @@ class Stream(Stream_):
|
|
|
31
36
|
A device stream is a linear sequence of execution that belongs to a specific device,
|
|
32
37
|
independent from other streams.
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
Note:
|
|
40
|
+
- The api will be deprecated, please use the api :class:`mindspore.runtime.Stream`.
|
|
35
41
|
|
|
36
42
|
Args:
|
|
37
43
|
priority (int, optional): priority of the stream, lower numbers represent higher priorities.
|
|
38
44
|
By default, streams have priority ``0``.
|
|
39
45
|
kwargs (dict): keyword arguments.
|
|
40
46
|
"""
|
|
47
|
+
|
|
41
48
|
def __init__(self, priority=0, **kwargs):
|
|
42
49
|
self.init_finished = False
|
|
43
50
|
if 'stream' in kwargs and kwargs['stream'] is not None:
|
|
@@ -84,6 +91,12 @@ class Stream(Stream_):
|
|
|
84
91
|
[5. 5. 5.]
|
|
85
92
|
[5. 5. 5.]]
|
|
86
93
|
"""
|
|
94
|
+
if not function_stream_status['record_event']:
|
|
95
|
+
function_stream_status['record_event'] = True
|
|
96
|
+
logger.warning(
|
|
97
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.Stream().record_event() is deprecated."
|
|
98
|
+
" Please use mindspore.runtime.Stream().record_event()"
|
|
99
|
+
)
|
|
87
100
|
if event is None:
|
|
88
101
|
event = Event()
|
|
89
102
|
if not isinstance(event, Event):
|
|
@@ -121,6 +134,12 @@ class Stream(Stream_):
|
|
|
121
134
|
[5. 5. 5.]
|
|
122
135
|
[5. 5. 5.]]
|
|
123
136
|
"""
|
|
137
|
+
if not function_stream_status['wait_event']:
|
|
138
|
+
function_stream_status['wait_event'] = True
|
|
139
|
+
logger.warning(
|
|
140
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.current_stream().wait_event(event) is deprecated."
|
|
141
|
+
" Please use mindspore.runtime.current_stream().wait_event(event)"
|
|
142
|
+
)
|
|
124
143
|
if not isinstance(event, Event):
|
|
125
144
|
raise TypeError(f"For 'wait_event', the argument 'event' should be Event,"
|
|
126
145
|
f" but got {type(event)}.")
|
|
@@ -156,6 +175,12 @@ class Stream(Stream_):
|
|
|
156
175
|
>>> print(d)
|
|
157
176
|
[[4. 4.]]
|
|
158
177
|
"""
|
|
178
|
+
if not function_stream_status['wait_stream']:
|
|
179
|
+
function_stream_status['wait_stream'] = True
|
|
180
|
+
logger.warning(
|
|
181
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.Stream() is deprecated."
|
|
182
|
+
" Please use mindspore.runtime.Stream()"
|
|
183
|
+
)
|
|
159
184
|
if not isinstance(stream, Stream):
|
|
160
185
|
raise TypeError(f"For 'wait_stream', the argument 'stream' should be Stream,"
|
|
161
186
|
f" but got {type(stream)}.")
|
|
@@ -199,6 +224,12 @@ class Stream(Stream_):
|
|
|
199
224
|
>>> s1.synchronize()
|
|
200
225
|
>>> assert s1.query()
|
|
201
226
|
"""
|
|
227
|
+
if not function_stream_status['query']:
|
|
228
|
+
function_stream_status['query'] = True
|
|
229
|
+
logger.warning(
|
|
230
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.Stream() is deprecated."
|
|
231
|
+
" Please use mindspore.runtime.Stream()"
|
|
232
|
+
)
|
|
202
233
|
# pylint: disable=useless-super-delegation
|
|
203
234
|
return super().query()
|
|
204
235
|
|
|
@@ -221,6 +252,9 @@ def synchronize():
|
|
|
221
252
|
r"""
|
|
222
253
|
Synchronize all streams on current device.(Each MindSpore process only occupies one device)
|
|
223
254
|
|
|
255
|
+
Note:
|
|
256
|
+
- The api will be deprecated, please use the api :func:`mindspore.runtime.synchronize` instead.
|
|
257
|
+
|
|
224
258
|
Examples:
|
|
225
259
|
>>> import mindspore as ms
|
|
226
260
|
>>> import numpy as np
|
|
@@ -233,6 +267,12 @@ def synchronize():
|
|
|
233
267
|
>>> ms.hal.synchronize()
|
|
234
268
|
>>> assert s1.query()
|
|
235
269
|
"""
|
|
270
|
+
if not function_stream_status['synchronize']:
|
|
271
|
+
function_stream_status['synchronize'] = True
|
|
272
|
+
logger.warning(
|
|
273
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.synchronize() is deprecated."
|
|
274
|
+
" Please use mindspore.runtime.synchronize()"
|
|
275
|
+
)
|
|
236
276
|
synchronize_()
|
|
237
277
|
|
|
238
278
|
|
|
@@ -241,6 +281,9 @@ def set_cur_stream(stream):
|
|
|
241
281
|
Sets the current stream.This is a wrapper API to set the stream.
|
|
242
282
|
Usage of this function is discouraged in favor of the ``stream`` context manager.
|
|
243
283
|
|
|
284
|
+
Note:
|
|
285
|
+
- The api will be deprecated, please use the api :func:`mindspore.runtime.set_cur_stream` instead.
|
|
286
|
+
|
|
244
287
|
Args:
|
|
245
288
|
stream (Stream): selected stream. This function is a no-op
|
|
246
289
|
if this argument is ``None``.
|
|
@@ -257,6 +300,12 @@ def set_cur_stream(stream):
|
|
|
257
300
|
>>> assert ms.hal.current_stream() == s1
|
|
258
301
|
>>> ms.hal.set_cur_stream(ms.hal.default_stream())
|
|
259
302
|
"""
|
|
303
|
+
if not function_stream_status['set_cur_stream']:
|
|
304
|
+
function_stream_status['set_cur_stream'] = True
|
|
305
|
+
logger.warning(
|
|
306
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.Stream() is deprecated."
|
|
307
|
+
" Please use mindspore.runtime.Stream()"
|
|
308
|
+
)
|
|
260
309
|
if stream is None:
|
|
261
310
|
return
|
|
262
311
|
if not isinstance(stream, Stream):
|
|
@@ -269,6 +318,9 @@ def current_stream():
|
|
|
269
318
|
r"""
|
|
270
319
|
Return current stream used on this device.
|
|
271
320
|
|
|
321
|
+
Note:
|
|
322
|
+
- The api will be deprecated, please use the api :func:`mindspore.runtime.current_stream` instead.
|
|
323
|
+
|
|
272
324
|
Returns:
|
|
273
325
|
stream (Stream), current stream.
|
|
274
326
|
|
|
@@ -277,6 +329,12 @@ def current_stream():
|
|
|
277
329
|
>>> cur_stream = ms.hal.current_stream()
|
|
278
330
|
>>> assert cur_stream == ms.hal.default_stream()
|
|
279
331
|
"""
|
|
332
|
+
if not function_stream_status['current_stream']:
|
|
333
|
+
function_stream_status['current_stream'] = True
|
|
334
|
+
logger.warning(
|
|
335
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.current_stream() is deprecated."
|
|
336
|
+
" Please use mindspore.runtime.current_stream()"
|
|
337
|
+
)
|
|
280
338
|
return Stream(stream=current_stream_())
|
|
281
339
|
|
|
282
340
|
|
|
@@ -284,6 +342,9 @@ def default_stream():
|
|
|
284
342
|
r"""
|
|
285
343
|
Return default stream on this device.
|
|
286
344
|
|
|
345
|
+
Note:
|
|
346
|
+
- The api will be deprecated, please use the api :func:`mindspore.runtime.default_stream` instead.
|
|
347
|
+
|
|
287
348
|
Returns:
|
|
288
349
|
stream (Stream), default stream.
|
|
289
350
|
|
|
@@ -292,22 +353,36 @@ def default_stream():
|
|
|
292
353
|
>>> cur_stream = ms.hal.current_stream()
|
|
293
354
|
>>> assert cur_stream == ms.hal.default_stream()
|
|
294
355
|
"""
|
|
356
|
+
if not function_stream_status['default_stream']:
|
|
357
|
+
function_stream_status['default_stream'] = True
|
|
358
|
+
logger.warning(
|
|
359
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.default_stream() is deprecated."
|
|
360
|
+
" Please use mindspore.runtime.default_stream()"
|
|
361
|
+
)
|
|
295
362
|
return Stream(stream=default_stream_())
|
|
296
363
|
|
|
297
364
|
|
|
298
365
|
def communication_stream():
|
|
299
366
|
r"""
|
|
300
|
-
Return
|
|
367
|
+
Return communication stream on this device.
|
|
368
|
+
|
|
369
|
+
Note:
|
|
370
|
+
- The api will be deprecated, please use the api :func:`mindspore.runtime.communication_stream` instead.
|
|
301
371
|
|
|
302
372
|
Returns:
|
|
303
|
-
stream (Stream),
|
|
373
|
+
stream (Stream), communication stream.
|
|
304
374
|
|
|
305
|
-
TODO
|
|
306
375
|
Examples:
|
|
307
376
|
>>> import mindspore as ms
|
|
308
|
-
>>>
|
|
309
|
-
|
|
377
|
+
>>> ms.hal.communication_stream()
|
|
378
|
+
Stream(device_name=Ascend, device_id:0, stream id:1)
|
|
310
379
|
"""
|
|
380
|
+
if not function_stream_status['communication_stream']:
|
|
381
|
+
function_stream_status['communication_stream'] = True
|
|
382
|
+
logger.warning(
|
|
383
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.communication_stream() is deprecated."
|
|
384
|
+
" Please use mindspore.runtime.communication_stream()"
|
|
385
|
+
)
|
|
311
386
|
return Stream(stream=communication_stream_())
|
|
312
387
|
|
|
313
388
|
|
|
@@ -315,6 +390,9 @@ class StreamCtx():
|
|
|
315
390
|
r"""
|
|
316
391
|
Context-manager that selects a given stream.
|
|
317
392
|
|
|
393
|
+
Note:
|
|
394
|
+
- The api will be deprecated, please use the api :class:`mindspore.runtime.StreamCtx`.
|
|
395
|
+
|
|
318
396
|
All kernels queued within its context will be enqueued on a selected
|
|
319
397
|
stream.
|
|
320
398
|
|
|
@@ -336,7 +414,14 @@ class StreamCtx():
|
|
|
336
414
|
>>> ms.hal.synchronize()
|
|
337
415
|
>>> assert s1.query()
|
|
338
416
|
"""
|
|
417
|
+
|
|
339
418
|
def __init__(self, ctx_stream):
|
|
419
|
+
if not function_stream_status['StreamCtx']:
|
|
420
|
+
function_stream_status['StreamCtx'] = True
|
|
421
|
+
logger.warning(
|
|
422
|
+
"WARN_DEPRECATED: The usage of mindspore.hal.StreamCtx(s1) is deprecated."
|
|
423
|
+
" Please use mindspore.runtime.StreamCtx(s1)"
|
|
424
|
+
)
|
|
340
425
|
if ctx_stream is not None and not isinstance(ctx_stream, Stream):
|
|
341
426
|
raise TypeError(f"For 'StreamCtx', the argument 'ctx_stream' should be Stream,"
|
|
342
427
|
f" but got {type(ctx_stream)}.")
|
mindspore/include/api/context.h
CHANGED
mindspore/jpeg62.dll
CHANGED
|
Binary file
|
mindspore/log.py
CHANGED
|
@@ -26,6 +26,7 @@ from logging.handlers import RotatingFileHandler
|
|
|
26
26
|
import traceback
|
|
27
27
|
import threading
|
|
28
28
|
import platform
|
|
29
|
+
from datetime import datetime
|
|
29
30
|
|
|
30
31
|
if platform.system() != "Windows":
|
|
31
32
|
import fcntl
|
|
@@ -225,6 +226,17 @@ def critical(msg, *args, **kwargs):
|
|
|
225
226
|
_get_logger().critical(msg, *args, **kwargs)
|
|
226
227
|
|
|
227
228
|
|
|
229
|
+
def vlog_print(level, module, file, line, message):
|
|
230
|
+
'''Read environment variable VLOG_v and print to log'''
|
|
231
|
+
if os.environ.get("VLOG_v") == level:
|
|
232
|
+
now = datetime.now()
|
|
233
|
+
formatted_time = now.strftime("%Y-%m-%d-%H:%M:%S.%f")[:-3] + f".{now.microsecond // 1000}"
|
|
234
|
+
path = 'mindspore' + file.split("mindspore")[-1]
|
|
235
|
+
pid = os.getpid()
|
|
236
|
+
thread_id = threading.get_ident()
|
|
237
|
+
print(f"[V{level}] {module}({pid},{thread_id},python):{formatted_time} [{path}:{line}] {message}", flush=True)
|
|
238
|
+
|
|
239
|
+
|
|
228
240
|
def get_level():
|
|
229
241
|
"""
|
|
230
242
|
Get the logger level.
|
mindspore/mindrecord/__init__.py
CHANGED
|
@@ -39,5 +39,5 @@ from .config import *
|
|
|
39
39
|
|
|
40
40
|
__all__ = ['FileWriter', 'FileReader', 'MindPage',
|
|
41
41
|
'Cifar10ToMR', 'Cifar100ToMR', 'CsvToMR', 'ImageNetToMR', 'MnistToMR', 'TFRecordToMR',
|
|
42
|
-
'set_enc_key', 'set_enc_mode', 'set_dec_mode',
|
|
42
|
+
'set_enc_key', 'set_enc_mode', 'set_dec_mode',
|
|
43
43
|
'SUCCESS', 'FAILED']
|
mindspore/mindrecord/config.py
CHANGED
|
@@ -20,10 +20,9 @@ Common imported modules in corresponding API examples are as follows:
|
|
|
20
20
|
|
|
21
21
|
.. code-block::
|
|
22
22
|
|
|
23
|
-
from mindspore.mindrecord import set_enc_key, set_enc_mode, set_dec_mode
|
|
23
|
+
from mindspore.mindrecord import set_enc_key, set_enc_mode, set_dec_mode
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
|
-
import hashlib
|
|
27
26
|
import os
|
|
28
27
|
import shutil
|
|
29
28
|
import stat
|
|
@@ -36,47 +35,33 @@ from .shardutils import MIN_FILE_SIZE
|
|
|
36
35
|
|
|
37
36
|
__all__ = ['set_enc_key',
|
|
38
37
|
'set_enc_mode',
|
|
39
|
-
'set_dec_mode'
|
|
40
|
-
'set_hash_mode']
|
|
38
|
+
'set_dec_mode']
|
|
41
39
|
|
|
42
40
|
|
|
43
|
-
# default encode key
|
|
41
|
+
# default encode key
|
|
44
42
|
ENC_KEY = None
|
|
45
43
|
ENC_MODE = "AES-GCM"
|
|
46
44
|
DEC_MODE = None
|
|
47
45
|
HASH_MODE = None
|
|
48
46
|
|
|
49
47
|
|
|
50
|
-
# the final mindrecord after
|
|
51
|
-
# 1. for create new mindrecord
|
|
52
|
-
# mindrecord ->
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
# 2. for read mindrecord, should decode first, then do hash check
|
|
56
|
-
# enc_mindrecord+'ENCRYPT' ->
|
|
57
|
-
# mindrecord+hash_value+len(4bytes)+'HASH'
|
|
48
|
+
# the final mindrecord after encode should be like below
|
|
49
|
+
# 1. for create new mindrecord
|
|
50
|
+
# mindrecord -> enc_mindrecord+'ENCRYPT'
|
|
51
|
+
# 2. for read mindrecord
|
|
52
|
+
# enc_mindrecord+'ENCRYPT' -> mindrecord
|
|
58
53
|
|
|
59
54
|
|
|
60
55
|
# mindrecord file encode end flag, we will append 'ENCRYPT' to the end of file
|
|
61
56
|
ENCRYPT_END_FLAG = str('ENCRYPT').encode('utf-8')
|
|
62
57
|
|
|
63
58
|
|
|
64
|
-
# mindrecord file hash check flag, we will append hash value+'HASH' to the end of file
|
|
65
|
-
HASH_END_FLAG = str('HASH').encode('utf-8')
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
# length of hash value (4bytes) + 'HASH'
|
|
69
|
-
LEN_HASH_WITH_END_FLAG = 4 + len(HASH_END_FLAG)
|
|
70
|
-
|
|
71
|
-
|
|
72
59
|
# directory which stored decrypt mindrecord files
|
|
73
60
|
DECRYPT_DIRECTORY = ".decrypt_mindrecord"
|
|
74
61
|
DECRYPT_DIRECTORY_LIST = []
|
|
75
62
|
|
|
76
63
|
|
|
77
|
-
# time for warning when encrypt/decrypt
|
|
78
|
-
CALCULATE_HASH_TIME = 0
|
|
79
|
-
VERIFY_HASH_TIME = 0
|
|
64
|
+
# time for warning when encrypt/decrypt takes too long time
|
|
80
65
|
ENCRYPT_TIME = 0
|
|
81
66
|
DECRYPT_TIME = 0
|
|
82
67
|
WARNING_INTERVAL = 30 # 30s
|
|
@@ -86,9 +71,6 @@ def set_enc_key(enc_key):
|
|
|
86
71
|
"""
|
|
87
72
|
Set the encode key.
|
|
88
73
|
|
|
89
|
-
Note:
|
|
90
|
-
When the encryption algorithm is ``"SM4-CBC"`` , only 16 bit length key are supported.
|
|
91
|
-
|
|
92
74
|
Args:
|
|
93
75
|
enc_key (str): Str-type key used for encryption. The valid length is 16, 24, or 32.
|
|
94
76
|
``None`` indicates that encryption is not enabled.
|
|
@@ -129,9 +111,9 @@ def set_enc_mode(enc_mode="AES-GCM"):
|
|
|
129
111
|
|
|
130
112
|
Args:
|
|
131
113
|
enc_mode (Union[str, function], optional): This parameter is valid only when enc_key is not set to ``None`` .
|
|
132
|
-
Specifies the encryption mode or customized encryption function, currently supports ``"AES-GCM"
|
|
133
|
-
|
|
134
|
-
to ensure its correctness and raise exceptions when errors occur.
|
|
114
|
+
Specifies the encryption mode or customized encryption function, currently supports ``"AES-GCM"`` .
|
|
115
|
+
Default: ``"AES-GCM"`` . If it is customized encryption, users need
|
|
116
|
+
to ensure its correctness, the security of the encryption algorithm and raise exceptions when errors occur.
|
|
135
117
|
|
|
136
118
|
Raises:
|
|
137
119
|
ValueError: The input is not valid encode mode or callable function.
|
|
@@ -150,7 +132,7 @@ def set_enc_mode(enc_mode="AES-GCM"):
|
|
|
150
132
|
if not isinstance(enc_mode, str):
|
|
151
133
|
raise ValueError("The input enc_mode is not str.")
|
|
152
134
|
|
|
153
|
-
if enc_mode not in ["AES-GCM"
|
|
135
|
+
if enc_mode not in ["AES-GCM"]:
|
|
154
136
|
raise ValueError("The input enc_mode is invalid.")
|
|
155
137
|
|
|
156
138
|
ENC_MODE = enc_mode
|
|
@@ -173,8 +155,8 @@ def set_dec_mode(dec_mode="AES-GCM"):
|
|
|
173
155
|
|
|
174
156
|
Args:
|
|
175
157
|
dec_mode (Union[str, function], optional): This parameter is valid only when enc_key is not set to ``None`` .
|
|
176
|
-
Specifies the decryption mode or customized decryption function, currently supports ``"AES-GCM"
|
|
177
|
-
|
|
158
|
+
Specifies the decryption mode or customized decryption function, currently supports ``"AES-GCM"`` .
|
|
159
|
+
Default: ``"AES-GCM"`` . ``None`` indicates that decryption
|
|
178
160
|
mode is not defined. If it is customized decryption, users need to ensure its correctness and raise
|
|
179
161
|
exceptions when errors occur.
|
|
180
162
|
|
|
@@ -199,7 +181,7 @@ def set_dec_mode(dec_mode="AES-GCM"):
|
|
|
199
181
|
if not isinstance(dec_mode, str):
|
|
200
182
|
raise ValueError("The input dec_mode is not str.")
|
|
201
183
|
|
|
202
|
-
if dec_mode not in ["AES-GCM"
|
|
184
|
+
if dec_mode not in ["AES-GCM"]:
|
|
203
185
|
raise ValueError("The input dec_mode is invalid.")
|
|
204
186
|
|
|
205
187
|
DEC_MODE = dec_mode
|
|
@@ -244,7 +226,7 @@ def _get_dec_mode_as_str():
|
|
|
244
226
|
if DEC_MODE is None:
|
|
245
227
|
if callable(ENC_MODE):
|
|
246
228
|
raise RuntimeError("You use custom encryption, so you must also define custom decryption.")
|
|
247
|
-
valid_dec_mode = ENC_MODE # "AES-GCM"
|
|
229
|
+
valid_dec_mode = ENC_MODE # "AES-GCM"
|
|
248
230
|
elif callable(DEC_MODE):
|
|
249
231
|
valid_dec_mode = "UDF-ENC" # "UDF-ENC"
|
|
250
232
|
else:
|
|
@@ -256,287 +238,6 @@ def _get_dec_mode_as_str():
|
|
|
256
238
|
return str(valid_dec_mode).encode('utf-8')
|
|
257
239
|
|
|
258
240
|
|
|
259
|
-
def set_hash_mode(hash_mode):
|
|
260
|
-
"""
|
|
261
|
-
Set the hash mode to ensure mindrecord file integrity.
|
|
262
|
-
|
|
263
|
-
Args:
|
|
264
|
-
hash_mode (Union[str, function]): The parameter is used to specify the hash mode. Specifies the hash
|
|
265
|
-
mode or customized hash function, currently supports ``None``, ``"sha256"``,
|
|
266
|
-
``"sha384"``, ``"sha512"``, ``"sha3_256"``, ``"sha3_384"``
|
|
267
|
-
and ``"sha3_512"``. ``None`` indicates that hash check is not enabled.
|
|
268
|
-
|
|
269
|
-
Raises:
|
|
270
|
-
ValueError: The input is not valid hash mode or callable function.
|
|
271
|
-
|
|
272
|
-
Examples:
|
|
273
|
-
>>> from mindspore.mindrecord import set_hash_mode
|
|
274
|
-
>>>
|
|
275
|
-
>>> set_hash_mode("sha256")
|
|
276
|
-
"""
|
|
277
|
-
global HASH_MODE
|
|
278
|
-
|
|
279
|
-
if hash_mode is None:
|
|
280
|
-
HASH_MODE = None
|
|
281
|
-
return
|
|
282
|
-
|
|
283
|
-
if callable(hash_mode):
|
|
284
|
-
HASH_MODE = hash_mode
|
|
285
|
-
return
|
|
286
|
-
|
|
287
|
-
if not isinstance(hash_mode, str):
|
|
288
|
-
raise ValueError("The input hash_mode is not str.")
|
|
289
|
-
|
|
290
|
-
if hash_mode not in ["sha256", "sha384", "sha512", "sha3_256", "sha3_384", "sha3_512"]:
|
|
291
|
-
raise ValueError("The input hash_mode is invalid.")
|
|
292
|
-
|
|
293
|
-
HASH_MODE = hash_mode
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def _get_hash_func():
|
|
297
|
-
"""Get the hash func by hash mode"""
|
|
298
|
-
global HASH_MODE
|
|
299
|
-
|
|
300
|
-
if HASH_MODE is None:
|
|
301
|
-
raise RuntimeError("The HASH_MODE is None, no matching hash function.")
|
|
302
|
-
|
|
303
|
-
if callable(HASH_MODE):
|
|
304
|
-
return HASH_MODE
|
|
305
|
-
|
|
306
|
-
if HASH_MODE == "sha256":
|
|
307
|
-
return hashlib.sha256()
|
|
308
|
-
if HASH_MODE == "sha384":
|
|
309
|
-
return hashlib.sha384()
|
|
310
|
-
if HASH_MODE == "sha512":
|
|
311
|
-
return hashlib.sha512()
|
|
312
|
-
if HASH_MODE == "sha3_256":
|
|
313
|
-
return hashlib.sha3_256()
|
|
314
|
-
if HASH_MODE == "sha3_384":
|
|
315
|
-
return hashlib.sha3_384()
|
|
316
|
-
if HASH_MODE == "sha3_512":
|
|
317
|
-
return hashlib.sha3_512()
|
|
318
|
-
raise RuntimeError("The HASH_MODE: {} is invalid.".format(HASH_MODE))
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
def _get_hash_mode():
|
|
322
|
-
"""Get the hash check mode."""
|
|
323
|
-
global HASH_MODE
|
|
324
|
-
|
|
325
|
-
return HASH_MODE
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
def calculate_file_hash(filename, whole=True):
|
|
329
|
-
"""Calculate the file's hash"""
|
|
330
|
-
if not os.path.exists(filename):
|
|
331
|
-
raise RuntimeError("The input: {} is not exists.".format(filename))
|
|
332
|
-
|
|
333
|
-
if not os.path.isfile(filename):
|
|
334
|
-
raise RuntimeError("The input: {} should be a regular file.".format(filename))
|
|
335
|
-
|
|
336
|
-
# get the hash func
|
|
337
|
-
m = _get_hash_func()
|
|
338
|
-
|
|
339
|
-
f = open(filename, 'rb')
|
|
340
|
-
|
|
341
|
-
# get the file size first
|
|
342
|
-
if whole:
|
|
343
|
-
file_size = os.path.getsize(filename)
|
|
344
|
-
else:
|
|
345
|
-
len_hash_offset = os.path.getsize(filename) - LEN_HASH_WITH_END_FLAG
|
|
346
|
-
try:
|
|
347
|
-
f.seek(len_hash_offset)
|
|
348
|
-
except Exception as e: # pylint: disable=W0703
|
|
349
|
-
f.close()
|
|
350
|
-
raise RuntimeError("Seek the file: {} to position: {} failed. Error: {}"
|
|
351
|
-
.format(filename, len_hash_offset, str(e)))
|
|
352
|
-
|
|
353
|
-
len_hash = int.from_bytes(f.read(4), byteorder='big') # length of hash value is 4 bytes
|
|
354
|
-
file_size = os.path.getsize(filename) - LEN_HASH_WITH_END_FLAG - len_hash
|
|
355
|
-
|
|
356
|
-
offset = 64 * 1024 * 1024 ## read the offset 64M
|
|
357
|
-
current_offset = 0 ## use this to seek file
|
|
358
|
-
|
|
359
|
-
# read the file with offset and do sha256 hash
|
|
360
|
-
hash_value = str("").encode('utf-8')
|
|
361
|
-
while True:
|
|
362
|
-
if (file_size - current_offset) >= offset:
|
|
363
|
-
read_size = offset
|
|
364
|
-
elif file_size - current_offset > 0:
|
|
365
|
-
read_size = file_size - current_offset
|
|
366
|
-
else:
|
|
367
|
-
# have read the entire file
|
|
368
|
-
break
|
|
369
|
-
|
|
370
|
-
try:
|
|
371
|
-
f.seek(current_offset)
|
|
372
|
-
except Exception as e: # pylint: disable=W0703
|
|
373
|
-
f.close()
|
|
374
|
-
raise RuntimeError("Seek the file: {} to position: {} failed. Error: {}"
|
|
375
|
-
.format(filename, current_offset, str(e)))
|
|
376
|
-
|
|
377
|
-
data = f.read(read_size)
|
|
378
|
-
if callable(m):
|
|
379
|
-
hash_value = m(data, hash_value)
|
|
380
|
-
if not isinstance(hash_value, bytes):
|
|
381
|
-
raise RuntimeError("User defined hash function should return hash value which is bytes type.")
|
|
382
|
-
if hash_value is None:
|
|
383
|
-
raise RuntimeError("User defined hash function return empty.")
|
|
384
|
-
else:
|
|
385
|
-
m.update(data)
|
|
386
|
-
|
|
387
|
-
current_offset += read_size
|
|
388
|
-
|
|
389
|
-
f.close()
|
|
390
|
-
|
|
391
|
-
if callable(m):
|
|
392
|
-
return hash_value
|
|
393
|
-
return m.digest()
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
def append_hash_to_file(filename):
|
|
397
|
-
"""append the hash value to the end of file"""
|
|
398
|
-
if not os.path.exists(filename):
|
|
399
|
-
raise RuntimeError("The input: {} is not exists.".format(filename))
|
|
400
|
-
|
|
401
|
-
if not os.path.isfile(filename):
|
|
402
|
-
raise RuntimeError("The input: {} should be a regular file.".format(filename))
|
|
403
|
-
|
|
404
|
-
logger.info("Begin to calculate the hash of the file: {}.".format(filename))
|
|
405
|
-
start = time.time()
|
|
406
|
-
|
|
407
|
-
hash_value = calculate_file_hash(filename)
|
|
408
|
-
|
|
409
|
-
# append hash value, length of hash value (4bytes) and HASH_END_FLAG to the file
|
|
410
|
-
f = open(filename, 'ab')
|
|
411
|
-
f.write(hash_value) # append the hash value
|
|
412
|
-
f.write((len(hash_value)).to_bytes(4, byteorder='big', signed=False)) # append the length of hash value
|
|
413
|
-
f.write(HASH_END_FLAG) # append the HASH_END_FLAG
|
|
414
|
-
f.close()
|
|
415
|
-
|
|
416
|
-
end = time.time()
|
|
417
|
-
global CALCULATE_HASH_TIME
|
|
418
|
-
CALCULATE_HASH_TIME += end - start
|
|
419
|
-
if CALCULATE_HASH_TIME > WARNING_INTERVAL:
|
|
420
|
-
logger.warning("It takes another " + str(WARNING_INTERVAL) +
|
|
421
|
-
"s to calculate the hash value of the mindrecord file.")
|
|
422
|
-
CALCULATE_HASH_TIME = CALCULATE_HASH_TIME - WARNING_INTERVAL
|
|
423
|
-
|
|
424
|
-
# change the file mode
|
|
425
|
-
os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR)
|
|
426
|
-
|
|
427
|
-
return True
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
def get_hash_end_flag(filename):
|
|
431
|
-
"""get the hash end flag from the file"""
|
|
432
|
-
if not os.path.exists(filename):
|
|
433
|
-
raise RuntimeError("The input: {} is not exists.".format(filename))
|
|
434
|
-
|
|
435
|
-
if not os.path.isfile(filename):
|
|
436
|
-
raise RuntimeError("The input: {} should be a regular file.".format(filename))
|
|
437
|
-
|
|
438
|
-
# get the file size first
|
|
439
|
-
file_size = os.path.getsize(filename)
|
|
440
|
-
offset = file_size - len(HASH_END_FLAG)
|
|
441
|
-
f = open(filename, 'rb')
|
|
442
|
-
|
|
443
|
-
# get the hash end flag which is HASH_END_FLAG
|
|
444
|
-
try:
|
|
445
|
-
f.seek(offset)
|
|
446
|
-
except Exception as e: # pylint: disable=W0703
|
|
447
|
-
f.close()
|
|
448
|
-
raise RuntimeError("Seek the file: {} to position: {} failed. Error: {}".format(filename, offset, str(e)))
|
|
449
|
-
|
|
450
|
-
data = f.read(len(HASH_END_FLAG))
|
|
451
|
-
f.close()
|
|
452
|
-
|
|
453
|
-
return data
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
def get_hash_value(filename):
|
|
457
|
-
"""get the file's hash"""
|
|
458
|
-
if not os.path.exists(filename):
|
|
459
|
-
raise RuntimeError("The input: {} is not exists.".format(filename))
|
|
460
|
-
|
|
461
|
-
if not os.path.isfile(filename):
|
|
462
|
-
raise RuntimeError("The input: {} should be a regular file.".format(filename))
|
|
463
|
-
|
|
464
|
-
# get the file size first
|
|
465
|
-
file_size = os.path.getsize(filename)
|
|
466
|
-
|
|
467
|
-
# the hash_value+len(4bytes)+'HASH' is stored in the end of the file
|
|
468
|
-
offset = file_size - LEN_HASH_WITH_END_FLAG
|
|
469
|
-
f = open(filename, 'rb')
|
|
470
|
-
|
|
471
|
-
# seek the position for the length of hash value
|
|
472
|
-
try:
|
|
473
|
-
f.seek(offset)
|
|
474
|
-
except Exception as e: # pylint: disable=W0703
|
|
475
|
-
f.close()
|
|
476
|
-
raise RuntimeError("Seek the file: {} to position: {} failed. Error: {}".format(filename, offset, str(e)))
|
|
477
|
-
|
|
478
|
-
len_hash = int.from_bytes(f.read(4), byteorder='big') # length of hash value is 4 bytes
|
|
479
|
-
hash_value_offset = file_size - len_hash - LEN_HASH_WITH_END_FLAG
|
|
480
|
-
|
|
481
|
-
# seek the position for the hash value
|
|
482
|
-
try:
|
|
483
|
-
f.seek(hash_value_offset)
|
|
484
|
-
except Exception as e: # pylint: disable=W0703
|
|
485
|
-
f.close()
|
|
486
|
-
raise RuntimeError("Seek the file: {} to position: {} failed. Error: {}"
|
|
487
|
-
.format(filename, hash_value_offset, str(e)))
|
|
488
|
-
|
|
489
|
-
# read the hash value
|
|
490
|
-
data = f.read(len_hash)
|
|
491
|
-
f.close()
|
|
492
|
-
|
|
493
|
-
return data
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
def verify_file_hash(filename):
|
|
497
|
-
"""Calculate the file hash and compare it with the hash value which is stored in the file"""
|
|
498
|
-
if not os.path.exists(filename):
|
|
499
|
-
raise RuntimeError("The input: {} is not exists.".format(filename))
|
|
500
|
-
|
|
501
|
-
if not os.path.isfile(filename):
|
|
502
|
-
raise RuntimeError("The input: {} should be a regular file.".format(filename))
|
|
503
|
-
|
|
504
|
-
# verify the hash end flag
|
|
505
|
-
stored_hash_end_flag = get_hash_end_flag(filename)
|
|
506
|
-
if _get_hash_mode() is not None:
|
|
507
|
-
if stored_hash_end_flag != HASH_END_FLAG:
|
|
508
|
-
raise RuntimeError("The mindrecord file is not hashed. You can set " +
|
|
509
|
-
"'mindspore.mindrecord.config.set_hash_mode(None)' to disable the hash check.")
|
|
510
|
-
else:
|
|
511
|
-
if stored_hash_end_flag == HASH_END_FLAG:
|
|
512
|
-
raise RuntimeError("The mindrecord file is hashed. You need to configure " +
|
|
513
|
-
"'mindspore.mindrecord.config.set_hash_mode(...)' to enable the hash check.")
|
|
514
|
-
return True
|
|
515
|
-
|
|
516
|
-
# get the pre hash value from the end of the file
|
|
517
|
-
stored_hash_value = get_hash_value(filename)
|
|
518
|
-
|
|
519
|
-
logger.info("Begin to verify the hash of the file: {}.".format(filename))
|
|
520
|
-
start = time.time()
|
|
521
|
-
|
|
522
|
-
# calculate hash by the file
|
|
523
|
-
current_hash = calculate_file_hash(filename, False)
|
|
524
|
-
|
|
525
|
-
if stored_hash_value != current_hash:
|
|
526
|
-
raise RuntimeError("The input file: " + filename + " hash check fail. The file may be damaged. "
|
|
527
|
-
"Or configure a correct hash mode.")
|
|
528
|
-
|
|
529
|
-
end = time.time()
|
|
530
|
-
global VERIFY_HASH_TIME
|
|
531
|
-
VERIFY_HASH_TIME += end - start
|
|
532
|
-
if VERIFY_HASH_TIME > WARNING_INTERVAL:
|
|
533
|
-
logger.warning("It takes another " + str(WARNING_INTERVAL) +
|
|
534
|
-
"s to verify the hash value of the mindrecord file.")
|
|
535
|
-
VERIFY_HASH_TIME = VERIFY_HASH_TIME - WARNING_INTERVAL
|
|
536
|
-
|
|
537
|
-
return True
|
|
538
|
-
|
|
539
|
-
|
|
540
241
|
def encrypt(filename, enc_key, enc_mode):
|
|
541
242
|
"""Encrypt the file and the original file will be deleted"""
|
|
542
243
|
if not os.path.exists(filename):
|