mindspore 2.4.0__cp310-cp310-macosx_10_15_x86_64.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 -0
- mindspore/__init__.py +53 -0
- mindspore/_c_dataengine.cpython-310-darwin.so +0 -0
- mindspore/_c_expression.cpython-310-darwin.so +0 -0
- mindspore/_c_mindrecord.cpython-310-darwin.so +0 -0
- mindspore/_check_jit_forbidden_api.py +106 -0
- mindspore/_checkparam.py +1419 -0
- mindspore/_extends/__init__.py +23 -0
- mindspore/_extends/builtin_operations.py +224 -0
- mindspore/_extends/graph_kernel/__init__.py +17 -0
- mindspore/_extends/graph_kernel/model/__init__.py +19 -0
- mindspore/_extends/graph_kernel/model/graph_parallel.py +311 -0
- mindspore/_extends/graph_kernel/model/graph_split.py +1348 -0
- mindspore/_extends/graph_kernel/model/model.py +553 -0
- mindspore/_extends/graph_kernel/model/model_builder.py +216 -0
- mindspore/_extends/graph_kernel/parallel_estimate.py +60 -0
- mindspore/_extends/graph_kernel/splitter.py +140 -0
- mindspore/_extends/graph_kernel/utils.py +28 -0
- mindspore/_extends/parallel_compile/__init__.py +19 -0
- mindspore/_extends/parallel_compile/akg_compiler/__init__.py +19 -0
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +269 -0
- mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +529 -0
- mindspore/_extends/parallel_compile/akg_compiler/compiler.py +56 -0
- mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +96 -0
- mindspore/_extends/parallel_compile/akg_compiler/get_file_path.py +36 -0
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +556 -0
- mindspore/_extends/parallel_compile/akg_compiler/util.py +159 -0
- mindspore/_extends/parse/__init__.py +49 -0
- mindspore/_extends/parse/compile_config.py +299 -0
- mindspore/_extends/parse/namespace.py +136 -0
- mindspore/_extends/parse/parser.py +1448 -0
- mindspore/_extends/parse/resources.py +213 -0
- mindspore/_extends/parse/standard_method.py +4475 -0
- mindspore/_extends/parse/trope.py +97 -0
- mindspore/_extends/pijit/__init__.py +23 -0
- mindspore/_extends/pijit/pijit_func_white_list.py +669 -0
- mindspore/_extends/remote/__init__.py +19 -0
- mindspore/_extends/remote/kernel_build_server.py +199 -0
- mindspore/_extends/remote/kernel_build_server_akg.py +55 -0
- mindspore/_extends/remote/kernel_build_server_akg_v2.py +55 -0
- mindspore/_extends/remote/kernel_build_server_ascend.py +75 -0
- mindspore/_extends/utils.py +68 -0
- mindspore/_install_custom.py +43 -0
- mindspore/_profiler.py +30 -0
- mindspore/amp.py +433 -0
- mindspore/boost/__init__.py +42 -0
- mindspore/boost/adasum.py +319 -0
- mindspore/boost/base.py +535 -0
- mindspore/boost/boost.py +400 -0
- mindspore/boost/boost_cell_wrapper.py +790 -0
- mindspore/boost/dim_reduce.py +323 -0
- mindspore/boost/grad_accumulation.py +79 -0
- mindspore/boost/grad_freeze.py +382 -0
- mindspore/boost/group_loss_scale_manager.py +166 -0
- mindspore/boost/less_batch_normalization.py +174 -0
- mindspore/common/__init__.py +86 -0
- mindspore/common/_auto_dynamic.py +68 -0
- mindspore/common/_decorator.py +50 -0
- mindspore/common/_jit_fallback_utils.py +110 -0
- mindspore/common/_monad.py +25 -0
- mindspore/common/_pijit_context.py +190 -0
- mindspore/common/_register_for_adapter.py +74 -0
- mindspore/common/_register_for_recompute.py +48 -0
- mindspore/common/_register_for_tensor.py +46 -0
- mindspore/common/_stub_tensor.py +210 -0
- mindspore/common/_tensor_overload.py +139 -0
- mindspore/common/_utils.py +122 -0
- mindspore/common/api.py +2064 -0
- mindspore/common/auto_dynamic_shape.py +507 -0
- mindspore/common/dtype.py +422 -0
- mindspore/common/dump.py +130 -0
- mindspore/common/file_system.py +48 -0
- mindspore/common/generator.py +254 -0
- mindspore/common/hook_handle.py +143 -0
- mindspore/common/initializer.py +880 -0
- mindspore/common/jit_config.py +98 -0
- mindspore/common/lazy_inline.py +240 -0
- mindspore/common/mindir_util.py +111 -0
- mindspore/common/mutable.py +234 -0
- mindspore/common/no_inline.py +54 -0
- mindspore/common/np_dtype.py +25 -0
- mindspore/common/parameter.py +1081 -0
- mindspore/common/recompute.py +292 -0
- mindspore/common/seed.py +260 -0
- mindspore/common/sparse_tensor.py +1175 -0
- mindspore/common/symbol.py +122 -0
- mindspore/common/tensor.py +5039 -0
- mindspore/communication/__init__.py +37 -0
- mindspore/communication/_comm_helper.py +501 -0
- mindspore/communication/_hccl_management.py +297 -0
- mindspore/communication/comm_func.py +1395 -0
- mindspore/communication/management.py +673 -0
- mindspore/config/op_info.config +533 -0
- mindspore/context.py +2077 -0
- mindspore/dataset/__init__.py +90 -0
- mindspore/dataset/audio/__init__.py +61 -0
- mindspore/dataset/audio/transforms.py +3690 -0
- mindspore/dataset/audio/utils.py +386 -0
- mindspore/dataset/audio/validators.py +1172 -0
- mindspore/dataset/callback/__init__.py +20 -0
- mindspore/dataset/callback/ds_callback.py +368 -0
- mindspore/dataset/callback/validators.py +32 -0
- mindspore/dataset/core/__init__.py +13 -0
- mindspore/dataset/core/config.py +1095 -0
- mindspore/dataset/core/datatypes.py +101 -0
- mindspore/dataset/core/py_util_helpers.py +65 -0
- mindspore/dataset/core/validator_helpers.py +781 -0
- mindspore/dataset/debug/__init__.py +21 -0
- mindspore/dataset/debug/debug_hook.py +97 -0
- mindspore/dataset/debug/pre_defined_hook.py +67 -0
- mindspore/dataset/engine/__init__.py +124 -0
- mindspore/dataset/engine/cache_admin.py +47 -0
- mindspore/dataset/engine/cache_client.py +129 -0
- mindspore/dataset/engine/datasets.py +4582 -0
- mindspore/dataset/engine/datasets_audio.py +911 -0
- mindspore/dataset/engine/datasets_standard_format.py +543 -0
- mindspore/dataset/engine/datasets_text.py +2161 -0
- mindspore/dataset/engine/datasets_user_defined.py +1184 -0
- mindspore/dataset/engine/datasets_vision.py +4816 -0
- mindspore/dataset/engine/iterators.py +371 -0
- mindspore/dataset/engine/obs/__init__.py +23 -0
- mindspore/dataset/engine/obs/config_loader.py +68 -0
- mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +508 -0
- mindspore/dataset/engine/obs/util.py +482 -0
- mindspore/dataset/engine/offload.py +596 -0
- mindspore/dataset/engine/queue.py +304 -0
- mindspore/dataset/engine/samplers.py +895 -0
- mindspore/dataset/engine/serializer_deserializer.py +159 -0
- mindspore/dataset/engine/validators.py +2895 -0
- mindspore/dataset/text/__init__.py +51 -0
- mindspore/dataset/text/transforms.py +1703 -0
- mindspore/dataset/text/utils.py +715 -0
- mindspore/dataset/text/validators.py +642 -0
- mindspore/dataset/transforms/__init__.py +45 -0
- mindspore/dataset/transforms/c_transforms.py +638 -0
- mindspore/dataset/transforms/py_transforms.py +393 -0
- mindspore/dataset/transforms/py_transforms_util.py +255 -0
- mindspore/dataset/transforms/transforms.py +1260 -0
- mindspore/dataset/transforms/validators.py +410 -0
- mindspore/dataset/utils/__init__.py +19 -0
- mindspore/dataset/utils/browse_dataset.py +190 -0
- mindspore/dataset/utils/line_reader.py +126 -0
- mindspore/dataset/vision/__init__.py +65 -0
- mindspore/dataset/vision/c_transforms.py +2641 -0
- mindspore/dataset/vision/py_transforms.py +2120 -0
- mindspore/dataset/vision/py_transforms_util.py +1660 -0
- mindspore/dataset/vision/transforms.py +7295 -0
- mindspore/dataset/vision/utils.py +863 -0
- mindspore/dataset/vision/validators.py +1483 -0
- mindspore/default_config.py +2 -0
- mindspore/experimental/__init__.py +20 -0
- mindspore/experimental/es/__init__.py +22 -0
- mindspore/experimental/es/embedding_service.py +883 -0
- mindspore/experimental/es/embedding_service_layer.py +581 -0
- mindspore/experimental/llm_boost/__init__.py +21 -0
- mindspore/experimental/llm_boost/atb/__init__.py +23 -0
- mindspore/experimental/llm_boost/atb/boost_base.py +211 -0
- mindspore/experimental/llm_boost/atb/llama_boost.py +115 -0
- mindspore/experimental/llm_boost/atb/qwen_boost.py +101 -0
- mindspore/experimental/llm_boost/register.py +129 -0
- mindspore/experimental/llm_boost/utils.py +31 -0
- mindspore/experimental/map_parameter.py +309 -0
- mindspore/experimental/optim/__init__.py +40 -0
- mindspore/experimental/optim/adadelta.py +161 -0
- mindspore/experimental/optim/adagrad.py +168 -0
- mindspore/experimental/optim/adam.py +193 -0
- mindspore/experimental/optim/adamax.py +170 -0
- mindspore/experimental/optim/adamw.py +290 -0
- mindspore/experimental/optim/asgd.py +153 -0
- mindspore/experimental/optim/lr_scheduler.py +1371 -0
- mindspore/experimental/optim/nadam.py +157 -0
- mindspore/experimental/optim/optimizer.py +262 -0
- mindspore/experimental/optim/radam.py +194 -0
- mindspore/experimental/optim/rmsprop.py +154 -0
- mindspore/experimental/optim/rprop.py +164 -0
- mindspore/experimental/optim/sgd.py +156 -0
- mindspore/hal/__init__.py +40 -0
- mindspore/hal/_ascend.py +57 -0
- mindspore/hal/_base.py +57 -0
- mindspore/hal/_cpu.py +56 -0
- mindspore/hal/_gpu.py +57 -0
- mindspore/hal/contiguous_tensors_handle.py +175 -0
- mindspore/hal/device.py +356 -0
- mindspore/hal/event.py +179 -0
- mindspore/hal/memory.py +326 -0
- mindspore/hal/stream.py +357 -0
- mindspore/include/OWNERS +7 -0
- mindspore/include/api/allocator.h +97 -0
- mindspore/include/api/callback/callback.h +93 -0
- mindspore/include/api/callback/ckpt_saver.h +41 -0
- mindspore/include/api/callback/loss_monitor.h +33 -0
- mindspore/include/api/callback/lr_scheduler.h +51 -0
- mindspore/include/api/callback/time_monitor.h +34 -0
- mindspore/include/api/callback/train_accuracy.h +37 -0
- mindspore/include/api/cell.h +90 -0
- mindspore/include/api/cfg.h +82 -0
- mindspore/include/api/context.h +602 -0
- mindspore/include/api/data_type.h +47 -0
- mindspore/include/api/delegate.h +178 -0
- mindspore/include/api/delegate_api.h +75 -0
- mindspore/include/api/dual_abi_helper.h +208 -0
- mindspore/include/api/format.h +28 -0
- mindspore/include/api/graph.h +46 -0
- mindspore/include/api/kernel.h +58 -0
- mindspore/include/api/kernel_api.h +168 -0
- mindspore/include/api/metrics/accuracy.h +36 -0
- mindspore/include/api/metrics/metrics.h +41 -0
- mindspore/include/api/model.h +438 -0
- mindspore/include/api/model_group.h +91 -0
- mindspore/include/api/model_parallel_runner.h +168 -0
- mindspore/include/api/serialization.h +185 -0
- mindspore/include/api/status.h +192 -0
- mindspore/include/api/types.h +431 -0
- mindspore/include/api/visible.h +41 -0
- mindspore/include/c_api/context_c.h +179 -0
- mindspore/include/c_api/data_type_c.h +52 -0
- mindspore/include/c_api/format_c.h +46 -0
- mindspore/include/c_api/model_c.h +347 -0
- mindspore/include/c_api/status_c.h +79 -0
- mindspore/include/c_api/tensor_c.h +146 -0
- mindspore/include/c_api/types_c.h +67 -0
- mindspore/include/dataset/config.h +163 -0
- mindspore/include/dataset/constants.h +363 -0
- mindspore/include/dataset/execute.h +196 -0
- mindspore/include/dataset/text.h +1092 -0
- mindspore/include/dataset/transforms.h +638 -0
- mindspore/include/dataset/vision.h +2129 -0
- mindspore/include/dataset/vision_ascend.h +206 -0
- mindspore/include/dataset/vision_lite.h +625 -0
- mindspore/lib/libavcodec.59.dylib +0 -0
- mindspore/lib/libavdevice.59.dylib +0 -0
- mindspore/lib/libavfilter.8.dylib +0 -0
- mindspore/lib/libavformat.59.dylib +0 -0
- mindspore/lib/libavutil.57.dylib +0 -0
- mindspore/lib/libdnnl.2.dylib +0 -0
- mindspore/lib/libicudata.69.dylib +0 -0
- mindspore/lib/libicui18n.69.dylib +0 -0
- mindspore/lib/libicuuc.69.dylib +0 -0
- mindspore/lib/libmindspore_address_sorting.15.dylib +0 -0
- mindspore/lib/libmindspore_backend.dylib +0 -0
- mindspore/lib/libmindspore_common.dylib +0 -0
- mindspore/lib/libmindspore_core.dylib +0 -0
- mindspore/lib/libmindspore_glog.0.dylib +0 -0
- mindspore/lib/libmindspore_gpr.15.dylib +0 -0
- mindspore/lib/libmindspore_grpc++.1.dylib +0 -0
- mindspore/lib/libmindspore_grpc.15.dylib +0 -0
- mindspore/lib/libmindspore_np_dtype.dylib +0 -0
- mindspore/lib/libmindspore_ops.dylib +0 -0
- mindspore/lib/libmindspore_upb.15.dylib +0 -0
- mindspore/lib/libnnacl.dylib +0 -0
- mindspore/lib/libopencv_core.4.5.dylib +0 -0
- mindspore/lib/libopencv_imgcodecs.4.5.dylib +0 -0
- mindspore/lib/libopencv_imgproc.4.5.dylib +0 -0
- mindspore/lib/libps_cache.dylib +0 -0
- mindspore/lib/libswresample.4.dylib +0 -0
- mindspore/lib/libswscale.6.dylib +0 -0
- mindspore/lib/libtinyxml2.8.dylib +0 -0
- mindspore/log.py +633 -0
- mindspore/mindrecord/__init__.py +43 -0
- mindspore/mindrecord/common/__init__.py +17 -0
- mindspore/mindrecord/common/constant.py +20 -0
- mindspore/mindrecord/common/enums.py +44 -0
- mindspore/mindrecord/common/exceptions.py +311 -0
- mindspore/mindrecord/config.py +809 -0
- mindspore/mindrecord/filereader.py +174 -0
- mindspore/mindrecord/filewriter.py +722 -0
- mindspore/mindrecord/mindpage.py +210 -0
- mindspore/mindrecord/shardheader.py +141 -0
- mindspore/mindrecord/shardindexgenerator.py +74 -0
- mindspore/mindrecord/shardreader.py +117 -0
- mindspore/mindrecord/shardsegment.py +128 -0
- mindspore/mindrecord/shardutils.py +185 -0
- mindspore/mindrecord/shardwriter.py +237 -0
- mindspore/mindrecord/tools/__init__.py +17 -0
- mindspore/mindrecord/tools/cifar10.py +140 -0
- mindspore/mindrecord/tools/cifar100.py +153 -0
- mindspore/mindrecord/tools/cifar100_to_mr.py +185 -0
- mindspore/mindrecord/tools/cifar10_to_mr.py +177 -0
- mindspore/mindrecord/tools/csv_to_mr.py +200 -0
- mindspore/mindrecord/tools/imagenet_to_mr.py +206 -0
- mindspore/mindrecord/tools/mnist_to_mr.py +259 -0
- mindspore/mindrecord/tools/tfrecord_to_mr.py +360 -0
- mindspore/mint/__init__.py +1586 -0
- mindspore/mint/distributed/__init__.py +31 -0
- mindspore/mint/distributed/distributed.py +254 -0
- mindspore/mint/linalg/__init__.py +22 -0
- mindspore/mint/nn/__init__.py +757 -0
- mindspore/mint/nn/functional.py +679 -0
- mindspore/mint/nn/layer/__init__.py +39 -0
- mindspore/mint/nn/layer/activation.py +133 -0
- mindspore/mint/nn/layer/normalization.py +477 -0
- mindspore/mint/nn/layer/pooling.py +110 -0
- mindspore/mint/optim/__init__.py +24 -0
- mindspore/mint/optim/adamw.py +206 -0
- mindspore/mint/special/__init__.py +63 -0
- mindspore/multiprocessing/__init__.py +73 -0
- mindspore/nn/__init__.py +47 -0
- mindspore/nn/cell.py +2787 -0
- mindspore/nn/dynamic_lr.py +482 -0
- mindspore/nn/grad/__init__.py +21 -0
- mindspore/nn/grad/cell_grad.py +196 -0
- mindspore/nn/layer/__init__.py +63 -0
- mindspore/nn/layer/activation.py +1822 -0
- mindspore/nn/layer/basic.py +1629 -0
- mindspore/nn/layer/channel_shuffle.py +90 -0
- mindspore/nn/layer/combined.py +248 -0
- mindspore/nn/layer/container.py +734 -0
- mindspore/nn/layer/conv.py +1505 -0
- mindspore/nn/layer/dense.py +204 -0
- mindspore/nn/layer/embedding.py +869 -0
- mindspore/nn/layer/image.py +661 -0
- mindspore/nn/layer/math.py +1069 -0
- mindspore/nn/layer/normalization.py +1273 -0
- mindspore/nn/layer/padding.py +880 -0
- mindspore/nn/layer/pooling.py +2302 -0
- mindspore/nn/layer/rnn_cells.py +388 -0
- mindspore/nn/layer/rnns.py +849 -0
- mindspore/nn/layer/thor_layer.py +963 -0
- mindspore/nn/layer/timedistributed.py +155 -0
- mindspore/nn/layer/transformer.py +823 -0
- mindspore/nn/learning_rate_schedule.py +512 -0
- mindspore/nn/loss/__init__.py +36 -0
- mindspore/nn/loss/loss.py +2924 -0
- mindspore/nn/metrics.py +53 -0
- mindspore/nn/optim/__init__.py +45 -0
- mindspore/nn/optim/_dist_optimizer_registry.py +111 -0
- mindspore/nn/optim/ada_grad.py +217 -0
- mindspore/nn/optim/adadelta.py +206 -0
- mindspore/nn/optim/adafactor.py +448 -0
- mindspore/nn/optim/adam.py +1297 -0
- mindspore/nn/optim/adamax.py +220 -0
- mindspore/nn/optim/adasum.py +548 -0
- mindspore/nn/optim/asgd.py +216 -0
- mindspore/nn/optim/ftrl.py +401 -0
- mindspore/nn/optim/lamb.py +296 -0
- mindspore/nn/optim/lars.py +202 -0
- mindspore/nn/optim/lazyadam.py +533 -0
- mindspore/nn/optim/momentum.py +239 -0
- mindspore/nn/optim/optimizer.py +1034 -0
- mindspore/nn/optim/proximal_ada_grad.py +242 -0
- mindspore/nn/optim/rmsprop.py +264 -0
- mindspore/nn/optim/rprop.py +251 -0
- mindspore/nn/optim/sgd.py +237 -0
- mindspore/nn/optim/tft_wrapper.py +127 -0
- mindspore/nn/optim/thor.py +1310 -0
- mindspore/nn/probability/__init__.py +22 -0
- mindspore/nn/probability/bijector/__init__.py +35 -0
- mindspore/nn/probability/bijector/bijector.py +337 -0
- mindspore/nn/probability/bijector/exp.py +65 -0
- mindspore/nn/probability/bijector/gumbel_cdf.py +144 -0
- mindspore/nn/probability/bijector/invert.py +126 -0
- mindspore/nn/probability/bijector/power_transform.py +196 -0
- mindspore/nn/probability/bijector/scalar_affine.py +167 -0
- mindspore/nn/probability/bijector/softplus.py +189 -0
- mindspore/nn/probability/bnn_layers/__init__.py +29 -0
- mindspore/nn/probability/bnn_layers/_util.py +46 -0
- mindspore/nn/probability/bnn_layers/bnn_cell_wrapper.py +112 -0
- mindspore/nn/probability/bnn_layers/conv_variational.py +267 -0
- mindspore/nn/probability/bnn_layers/dense_variational.py +302 -0
- mindspore/nn/probability/bnn_layers/layer_distribution.py +123 -0
- mindspore/nn/probability/distribution/__init__.py +56 -0
- mindspore/nn/probability/distribution/_utils/__init__.py +34 -0
- mindspore/nn/probability/distribution/_utils/custom_ops.py +96 -0
- mindspore/nn/probability/distribution/_utils/utils.py +362 -0
- mindspore/nn/probability/distribution/bernoulli.py +334 -0
- mindspore/nn/probability/distribution/beta.py +391 -0
- mindspore/nn/probability/distribution/categorical.py +435 -0
- mindspore/nn/probability/distribution/cauchy.py +383 -0
- mindspore/nn/probability/distribution/distribution.py +827 -0
- mindspore/nn/probability/distribution/exponential.py +350 -0
- mindspore/nn/probability/distribution/gamma.py +391 -0
- mindspore/nn/probability/distribution/geometric.py +335 -0
- mindspore/nn/probability/distribution/gumbel.py +257 -0
- mindspore/nn/probability/distribution/half_normal.py +133 -0
- mindspore/nn/probability/distribution/laplace.py +128 -0
- mindspore/nn/probability/distribution/log_normal.py +272 -0
- mindspore/nn/probability/distribution/logistic.py +379 -0
- mindspore/nn/probability/distribution/normal.py +336 -0
- mindspore/nn/probability/distribution/poisson.py +288 -0
- mindspore/nn/probability/distribution/student_t.py +149 -0
- mindspore/nn/probability/distribution/transformed_distribution.py +235 -0
- mindspore/nn/probability/distribution/uniform.py +375 -0
- mindspore/nn/reinforcement/__init__.py +24 -0
- mindspore/nn/reinforcement/_batch_read_write.py +142 -0
- mindspore/nn/reinforcement/_tensors_queue.py +152 -0
- mindspore/nn/reinforcement/tensor_array.py +145 -0
- mindspore/nn/sparse/__init__.py +23 -0
- mindspore/nn/sparse/sparse.py +147 -0
- mindspore/nn/wrap/__init__.py +49 -0
- mindspore/nn/wrap/cell_wrapper.py +968 -0
- mindspore/nn/wrap/grad_reducer.py +608 -0
- mindspore/nn/wrap/loss_scale.py +694 -0
- mindspore/numpy/__init__.py +121 -0
- mindspore/numpy/array_creations.py +2731 -0
- mindspore/numpy/array_ops.py +2629 -0
- mindspore/numpy/dtypes.py +185 -0
- mindspore/numpy/fft.py +966 -0
- mindspore/numpy/logic_ops.py +936 -0
- mindspore/numpy/math_ops.py +5911 -0
- mindspore/numpy/utils.py +214 -0
- mindspore/numpy/utils_const.py +565 -0
- mindspore/ops/__init__.py +56 -0
- mindspore/ops/_constants.py +30 -0
- mindspore/ops/_grad_experimental/__init__.py +31 -0
- mindspore/ops/_grad_experimental/grad_array_ops.py +830 -0
- mindspore/ops/_grad_experimental/grad_base.py +143 -0
- mindspore/ops/_grad_experimental/grad_comm_ops.py +714 -0
- mindspore/ops/_grad_experimental/grad_debug_ops.py +31 -0
- mindspore/ops/_grad_experimental/grad_implementations.py +203 -0
- mindspore/ops/_grad_experimental/grad_inner_ops.py +79 -0
- mindspore/ops/_grad_experimental/grad_math_ops.py +802 -0
- mindspore/ops/_grad_experimental/grad_nn_ops.py +231 -0
- mindspore/ops/_grad_experimental/grad_quant_ops.py +238 -0
- mindspore/ops/_grad_experimental/grad_sparse.py +342 -0
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +399 -0
- mindspore/ops/_grad_experimental/taylor_rule.py +220 -0
- mindspore/ops/_op_impl/__init__.py +23 -0
- mindspore/ops/_op_impl/_custom_op/__init__.py +39 -0
- mindspore/ops/_op_impl/_custom_op/_basic.py +158 -0
- mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +279 -0
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +156 -0
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +109 -0
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +125 -0
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +105 -0
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +124 -0
- mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +116 -0
- mindspore/ops/_op_impl/_custom_op/correction_mul.py +89 -0
- mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +196 -0
- mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +366 -0
- mindspore/ops/_op_impl/_custom_op/dsd_impl.py +162 -0
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +136 -0
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +206 -0
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +88 -0
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +128 -0
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +199 -0
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +88 -0
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +156 -0
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +184 -0
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +143 -0
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +169 -0
- mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +548 -0
- mindspore/ops/_op_impl/_custom_op/img2col_impl.py +881 -0
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +278 -0
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +200 -0
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +334 -0
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +255 -0
- mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +222 -0
- mindspore/ops/_op_impl/_custom_op/matmul_dds_grad_impl.py +644 -0
- mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +488 -0
- mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +87 -0
- mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +129 -0
- mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +121 -0
- mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +352 -0
- mindspore/ops/_op_impl/aicpu/__init__.py +441 -0
- mindspore/ops/_op_impl/aicpu/abs.py +36 -0
- mindspore/ops/_op_impl/aicpu/acos.py +32 -0
- mindspore/ops/_op_impl/aicpu/acos_grad.py +33 -0
- mindspore/ops/_op_impl/aicpu/acosh.py +34 -0
- mindspore/ops/_op_impl/aicpu/acosh_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d.py +34 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d.py +39 -0
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_3d_grad.py +39 -0
- mindspore/ops/_op_impl/aicpu/adaptive_max_pool_2d.py +37 -0
- mindspore/ops/_op_impl/aicpu/adaptive_max_pool_2d_grad.py +37 -0
- mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d.py +42 -0
- mindspore/ops/_op_impl/aicpu/adaptive_max_pool_3d_grad.py +152 -0
- mindspore/ops/_op_impl/aicpu/add.py +43 -0
- mindspore/ops/_op_impl/aicpu/add_n.py +41 -0
- mindspore/ops/_op_impl/aicpu/add_v2.py +40 -0
- mindspore/ops/_op_impl/aicpu/addcdiv.py +41 -0
- mindspore/ops/_op_impl/aicpu/addcmul.py +47 -0
- mindspore/ops/_op_impl/aicpu/adjust_contrastv2.py +32 -0
- mindspore/ops/_op_impl/aicpu/adjust_hue.py +31 -0
- mindspore/ops/_op_impl/aicpu/adjust_saturation.py +32 -0
- mindspore/ops/_op_impl/aicpu/affine_grid.py +33 -0
- mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/angle.py +31 -0
- mindspore/ops/_op_impl/aicpu/arg_max.py +75 -0
- mindspore/ops/_op_impl/aicpu/arg_min.py +75 -0
- mindspore/ops/_op_impl/aicpu/argmax_with_value.py +43 -0
- mindspore/ops/_op_impl/aicpu/argmin_with_value.py +43 -0
- mindspore/ops/_op_impl/aicpu/asin.py +32 -0
- mindspore/ops/_op_impl/aicpu/asin_grad.py +33 -0
- mindspore/ops/_op_impl/aicpu/asinh.py +34 -0
- mindspore/ops/_op_impl/aicpu/asinh_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/atanh.py +34 -0
- mindspore/ops/_op_impl/aicpu/avgpool_grad_v1.py +37 -0
- mindspore/ops/_op_impl/aicpu/avgpool_v1.py +36 -0
- mindspore/ops/_op_impl/aicpu/bartlett_window.py +36 -0
- mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -0
- mindspore/ops/_op_impl/aicpu/batch_norm_grad_grad.py +49 -0
- mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
- mindspore/ops/_op_impl/aicpu/bessel_i0.py +31 -0
- mindspore/ops/_op_impl/aicpu/betainc.py +31 -0
- mindspore/ops/_op_impl/aicpu/bias_add.py +44 -0
- mindspore/ops/_op_impl/aicpu/bias_add_grad.py +42 -0
- mindspore/ops/_op_impl/aicpu/bincount.py +33 -0
- mindspore/ops/_op_impl/aicpu/blackman_window.py +36 -0
- mindspore/ops/_op_impl/aicpu/broadcast_to.py +58 -0
- mindspore/ops/_op_impl/aicpu/bucketize.py +34 -0
- mindspore/ops/_op_impl/aicpu/cache_swap_table.py +102 -0
- mindspore/ops/_op_impl/aicpu/cast.py +225 -0
- mindspore/ops/_op_impl/aicpu/cauchy.py +33 -0
- mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
- mindspore/ops/_op_impl/aicpu/check_numerics.py +33 -0
- mindspore/ops/_op_impl/aicpu/cholesky.py +32 -0
- mindspore/ops/_op_impl/aicpu/cholesky_inverse.py +31 -0
- mindspore/ops/_op_impl/aicpu/cholesky_solve.py +33 -0
- mindspore/ops/_op_impl/aicpu/choleskygrad.py +32 -0
- mindspore/ops/_op_impl/aicpu/coalesce.py +37 -0
- mindspore/ops/_op_impl/aicpu/col2im.py +38 -0
- mindspore/ops/_op_impl/aicpu/combined_non_max_suppression.py +42 -0
- mindspore/ops/_op_impl/aicpu/compare_and_bitpack.py +37 -0
- mindspore/ops/_op_impl/aicpu/complex.py +32 -0
- mindspore/ops/_op_impl/aicpu/complex_abs.py +31 -0
- mindspore/ops/_op_impl/aicpu/compute_accidental_hits.py +44 -0
- mindspore/ops/_op_impl/aicpu/concat.py +57 -0
- mindspore/ops/_op_impl/aicpu/concat_offset.py +42 -0
- mindspore/ops/_op_impl/aicpu/concat_offset_v1.py +31 -0
- mindspore/ops/_op_impl/aicpu/conj.py +42 -0
- mindspore/ops/_op_impl/aicpu/conjugate_transpose.py +58 -0
- mindspore/ops/_op_impl/aicpu/cos.py +34 -0
- mindspore/ops/_op_impl/aicpu/cosh.py +34 -0
- mindspore/ops/_op_impl/aicpu/count_nonzero.py +43 -0
- mindspore/ops/_op_impl/aicpu/crop_and_resize.py +69 -0
- mindspore/ops/_op_impl/aicpu/crop_and_resize_grad_boxes.py +68 -0
- mindspore/ops/_op_impl/aicpu/crop_and_resize_grad_image.py +38 -0
- mindspore/ops/_op_impl/aicpu/cross.py +42 -0
- mindspore/ops/_op_impl/aicpu/csr_sparse_matrix_to_dense.py +48 -0
- mindspore/ops/_op_impl/aicpu/csr_sparse_matrix_to_sparse_tensor.py +51 -0
- mindspore/ops/_op_impl/aicpu/ctc_greedy_decoder.py +35 -0
- mindspore/ops/_op_impl/aicpu/ctc_loss_v2.py +43 -0
- mindspore/ops/_op_impl/aicpu/ctc_loss_v2_grad.py +45 -0
- mindspore/ops/_op_impl/aicpu/ctcloss.py +38 -0
- mindspore/ops/_op_impl/aicpu/cummax.py +41 -0
- mindspore/ops/_op_impl/aicpu/cumprod.py +58 -0
- mindspore/ops/_op_impl/aicpu/cumsum.py +58 -0
- mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +36 -0
- mindspore/ops/_op_impl/aicpu/data_format_vec_permute.py +32 -0
- mindspore/ops/_op_impl/aicpu/deformable_offsets.py +38 -0
- mindspore/ops/_op_impl/aicpu/deformable_offsets_grad.py +43 -0
- mindspore/ops/_op_impl/aicpu/dense_to_csr_sparse_matrix.py +49 -0
- mindspore/ops/_op_impl/aicpu/dense_to_dense_set_operation.py +45 -0
- mindspore/ops/_op_impl/aicpu/dense_to_sparse_set_operation.py +48 -0
- mindspore/ops/_op_impl/aicpu/depth_to_space.py +44 -0
- mindspore/ops/_op_impl/aicpu/diag.py +36 -0
- mindspore/ops/_op_impl/aicpu/diag_part.py +36 -0
- mindspore/ops/_op_impl/aicpu/diagonal.py +35 -0
- mindspore/ops/_op_impl/aicpu/digamma.py +31 -0
- mindspore/ops/_op_impl/aicpu/div.py +41 -0
- mindspore/ops/_op_impl/aicpu/div_no_nan.py +35 -0
- mindspore/ops/_op_impl/aicpu/dropout2d.py +42 -0
- mindspore/ops/_op_impl/aicpu/dropout3d.py +42 -0
- mindspore/ops/_op_impl/aicpu/dropout_genmask.py +41 -0
- mindspore/ops/_op_impl/aicpu/dropout_genmask_v3.py +32 -0
- mindspore/ops/_op_impl/aicpu/dynamic_stitch.py +42 -0
- mindspore/ops/_op_impl/aicpu/edit_distance.py +56 -0
- mindspore/ops/_op_impl/aicpu/eig.py +35 -0
- mindspore/ops/_op_impl/aicpu/embedding_lookup.py +102 -0
- mindspore/ops/_op_impl/aicpu/end_of_sequence.py +30 -0
- mindspore/ops/_op_impl/aicpu/environ_create.py +28 -0
- mindspore/ops/_op_impl/aicpu/environ_destroy_all.py +28 -0
- mindspore/ops/_op_impl/aicpu/environ_get.py +41 -0
- mindspore/ops/_op_impl/aicpu/environ_set.py +40 -0
- mindspore/ops/_op_impl/aicpu/eps.py +32 -0
- mindspore/ops/_op_impl/aicpu/equal.py +41 -0
- mindspore/ops/_op_impl/aicpu/exp.py +37 -0
- mindspore/ops/_op_impl/aicpu/expand.py +45 -0
- mindspore/ops/_op_impl/aicpu/expand_dims.py +42 -0
- mindspore/ops/_op_impl/aicpu/expm1.py +34 -0
- mindspore/ops/_op_impl/aicpu/extract_glimpse.py +35 -0
- mindspore/ops/_op_impl/aicpu/eye.py +44 -0
- mindspore/ops/_op_impl/aicpu/fft_with_size.py +47 -0
- mindspore/ops/_op_impl/aicpu/fill_diagonal.py +39 -0
- mindspore/ops/_op_impl/aicpu/fill_v2.py +58 -0
- mindspore/ops/_op_impl/aicpu/flatten.py +43 -0
- mindspore/ops/_op_impl/aicpu/floor_div.py +38 -0
- mindspore/ops/_op_impl/aicpu/fmax.py +36 -0
- mindspore/ops/_op_impl/aicpu/fmin.py +37 -0
- mindspore/ops/_op_impl/aicpu/fractional_avg_pool.py +41 -0
- mindspore/ops/_op_impl/aicpu/fractional_avg_pool_grad.py +41 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool.py +41 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_grad_with_fixed_ksize.py +43 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_with_fixed_ksize.py +65 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool_grad.py +42 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool_grad_with_fixed_ksize.py +42 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool_with_fixed_ksize.py +49 -0
- mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -0
- mindspore/ops/_op_impl/aicpu/fused_sparse_adam.py +46 -0
- mindspore/ops/_op_impl/aicpu/fused_sparse_ftrl.py +41 -0
- mindspore/ops/_op_impl/aicpu/fused_sparse_lazy_adam.py +46 -0
- mindspore/ops/_op_impl/aicpu/fused_sparse_proximal_adagrad.py +39 -0
- mindspore/ops/_op_impl/aicpu/gamma.py +38 -0
- mindspore/ops/_op_impl/aicpu/gather.py +46 -0
- mindspore/ops/_op_impl/aicpu/gather_d.py +79 -0
- mindspore/ops/_op_impl/aicpu/gather_d_grad_v2.py +79 -0
- mindspore/ops/_op_impl/aicpu/gather_grad.py +54 -0
- mindspore/ops/_op_impl/aicpu/gather_nd.py +56 -0
- mindspore/ops/_op_impl/aicpu/gcd.py +32 -0
- mindspore/ops/_op_impl/aicpu/generate_eod_mask.py +38 -0
- mindspore/ops/_op_impl/aicpu/geqrf.py +32 -0
- mindspore/ops/_op_impl/aicpu/get_next.py +39 -0
- mindspore/ops/_op_impl/aicpu/glu.py +33 -0
- mindspore/ops/_op_impl/aicpu/glu_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/greater.py +41 -0
- mindspore/ops/_op_impl/aicpu/greater_equal.py +41 -0
- mindspore/ops/_op_impl/aicpu/grid_sampler_2d.py +35 -0
- mindspore/ops/_op_impl/aicpu/grid_sampler_2d_grad.py +38 -0
- mindspore/ops/_op_impl/aicpu/grid_sampler_3d.py +34 -0
- mindspore/ops/_op_impl/aicpu/grid_sampler_3d_grad.py +38 -0
- mindspore/ops/_op_impl/aicpu/hamming_window.py +57 -0
- mindspore/ops/_op_impl/aicpu/hard_sigmoid.py +32 -0
- mindspore/ops/_op_impl/aicpu/hard_sigmoid_grad.py +33 -0
- mindspore/ops/_op_impl/aicpu/heaviside.py +40 -0
- mindspore/ops/_op_impl/aicpu/histogram.py +35 -0
- mindspore/ops/_op_impl/aicpu/hsv_to_rgb.py +32 -0
- mindspore/ops/_op_impl/aicpu/hypot.py +32 -0
- mindspore/ops/_op_impl/aicpu/identity.py +42 -0
- mindspore/ops/_op_impl/aicpu/identity_n.py +41 -0
- mindspore/ops/_op_impl/aicpu/igamma.py +30 -0
- mindspore/ops/_op_impl/aicpu/igammac.py +30 -0
- mindspore/ops/_op_impl/aicpu/igammagrada.py +30 -0
- mindspore/ops/_op_impl/aicpu/im2col.py +43 -0
- mindspore/ops/_op_impl/aicpu/imag.py +31 -0
- mindspore/ops/_op_impl/aicpu/index_fill.py +54 -0
- mindspore/ops/_op_impl/aicpu/index_put.py +50 -0
- mindspore/ops/_op_impl/aicpu/init_data_set_queue.py +27 -0
- mindspore/ops/_op_impl/aicpu/inplace_index_add.py +39 -0
- mindspore/ops/_op_impl/aicpu/instance_norm_v2.py +41 -0
- mindspore/ops/_op_impl/aicpu/instance_norm_v2_grad.py +44 -0
- mindspore/ops/_op_impl/aicpu/is_finite.py +40 -0
- mindspore/ops/_op_impl/aicpu/is_inf.py +31 -0
- mindspore/ops/_op_impl/aicpu/is_nan.py +31 -0
- mindspore/ops/_op_impl/aicpu/kldivloss.py +34 -0
- mindspore/ops/_op_impl/aicpu/kldivlossgrad.py +35 -0
- mindspore/ops/_op_impl/aicpu/layer_norm_grad_grad.py +47 -0
- mindspore/ops/_op_impl/aicpu/lcm.py +32 -0
- mindspore/ops/_op_impl/aicpu/left_shift.py +38 -0
- mindspore/ops/_op_impl/aicpu/less.py +41 -0
- mindspore/ops/_op_impl/aicpu/less_equal.py +41 -0
- mindspore/ops/_op_impl/aicpu/lgamma.py +33 -0
- mindspore/ops/_op_impl/aicpu/linear_sum_assignment.py +57 -0
- mindspore/ops/_op_impl/aicpu/linspace.py +33 -0
- mindspore/ops/_op_impl/aicpu/list_diff.py +50 -0
- mindspore/ops/_op_impl/aicpu/log.py +37 -0
- mindspore/ops/_op_impl/aicpu/log1p.py +34 -0
- mindspore/ops/_op_impl/aicpu/log_matrix_determinant.py +31 -0
- mindspore/ops/_op_impl/aicpu/log_normal_reverse.py +33 -0
- mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +37 -0
- mindspore/ops/_op_impl/aicpu/logical_xor.py +30 -0
- mindspore/ops/_op_impl/aicpu/logit.py +33 -0
- mindspore/ops/_op_impl/aicpu/logit_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/logspace.py +36 -0
- mindspore/ops/_op_impl/aicpu/lower_bound.py +47 -0
- mindspore/ops/_op_impl/aicpu/lstsq.py +34 -0
- mindspore/ops/_op_impl/aicpu/lu.py +39 -0
- mindspore/ops/_op_impl/aicpu/lu_solve.py +32 -0
- mindspore/ops/_op_impl/aicpu/lu_unpack.py +114 -0
- mindspore/ops/_op_impl/aicpu/lu_unpack_grad.py +49 -0
- mindspore/ops/_op_impl/aicpu/masked_fill.py +42 -0
- mindspore/ops/_op_impl/aicpu/masked_scatter.py +40 -0
- mindspore/ops/_op_impl/aicpu/masked_select.py +31 -0
- mindspore/ops/_op_impl/aicpu/masked_select_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/matmul.py +39 -0
- mindspore/ops/_op_impl/aicpu/matrix_band_part.py +59 -0
- mindspore/ops/_op_impl/aicpu/matrix_determinant.py +30 -0
- mindspore/ops/_op_impl/aicpu/matrix_diag_part_v3.py +54 -0
- mindspore/ops/_op_impl/aicpu/matrix_diag_v3.py +56 -0
- mindspore/ops/_op_impl/aicpu/matrix_exp.py +34 -0
- mindspore/ops/_op_impl/aicpu/matrix_inverse.py +31 -0
- mindspore/ops/_op_impl/aicpu/matrix_logarithm.py +31 -0
- mindspore/ops/_op_impl/aicpu/matrix_power.py +37 -0
- mindspore/ops/_op_impl/aicpu/matrix_set_diag_v3.py +54 -0
- mindspore/ops/_op_impl/aicpu/matrix_solve.py +35 -0
- mindspore/ops/_op_impl/aicpu/matrix_solve_ls.py +36 -0
- mindspore/ops/_op_impl/aicpu/matrix_triangular_solve.py +36 -0
- mindspore/ops/_op_impl/aicpu/max_pool3d_grad_with_argmax.py +60 -0
- mindspore/ops/_op_impl/aicpu/max_pool3d_with_argmax.py +59 -0
- mindspore/ops/_op_impl/aicpu/max_unpool2d.py +57 -0
- mindspore/ops/_op_impl/aicpu/max_unpool2d_grad.py +58 -0
- mindspore/ops/_op_impl/aicpu/max_unpool3d.py +57 -0
- mindspore/ops/_op_impl/aicpu/max_unpool3d_grad.py +58 -0
- mindspore/ops/_op_impl/aicpu/maximum_grad_grad.py +40 -0
- mindspore/ops/_op_impl/aicpu/maxpool_grad_v1.py +46 -0
- mindspore/ops/_op_impl/aicpu/maxpool_v1.py +42 -0
- mindspore/ops/_op_impl/aicpu/median.py +39 -0
- mindspore/ops/_op_impl/aicpu/median_grad.py +45 -0
- mindspore/ops/_op_impl/aicpu/meshgrid.py +41 -0
- mindspore/ops/_op_impl/aicpu/minimum_grad_grad.py +40 -0
- mindspore/ops/_op_impl/aicpu/mirror_pad.py +50 -0
- mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +48 -0
- mindspore/ops/_op_impl/aicpu/mul.py +43 -0
- mindspore/ops/_op_impl/aicpu/mul_no_nan.py +42 -0
- mindspore/ops/_op_impl/aicpu/multi_margin_loss.py +37 -0
- mindspore/ops/_op_impl/aicpu/multi_margin_loss_grad.py +41 -0
- mindspore/ops/_op_impl/aicpu/multilabel_margin_loss_grad.py +37 -0
- mindspore/ops/_op_impl/aicpu/multinomial.py +47 -0
- mindspore/ops/_op_impl/aicpu/multinomial_with_replacement.py +35 -0
- mindspore/ops/_op_impl/aicpu/mvlgamma.py +32 -0
- mindspore/ops/_op_impl/aicpu/mvlgamma_grad.py +33 -0
- mindspore/ops/_op_impl/aicpu/nan_to_num.py +34 -0
- mindspore/ops/_op_impl/aicpu/neg.py +36 -0
- mindspore/ops/_op_impl/aicpu/nextafter.py +32 -0
- mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
- mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
- mindspore/ops/_op_impl/aicpu/no_repeat_ngram.py +34 -0
- mindspore/ops/_op_impl/aicpu/non_deterministic_ints.py +33 -0
- mindspore/ops/_op_impl/aicpu/non_max_suppression.py +36 -0
- mindspore/ops/_op_impl/aicpu/non_max_suppression_with_overlaps.py +35 -0
- mindspore/ops/_op_impl/aicpu/non_zero.py +43 -0
- mindspore/ops/_op_impl/aicpu/not_equal.py +39 -0
- mindspore/ops/_op_impl/aicpu/nth_element.py +39 -0
- mindspore/ops/_op_impl/aicpu/nuclear_norm.py +33 -0
- mindspore/ops/_op_impl/aicpu/one_hot.py +116 -0
- mindspore/ops/_op_impl/aicpu/ones_like.py +39 -0
- mindspore/ops/_op_impl/aicpu/orgqr.py +34 -0
- mindspore/ops/_op_impl/aicpu/pad_and_shift.py +33 -0
- mindspore/ops/_op_impl/aicpu/pad_v3.py +61 -0
- mindspore/ops/_op_impl/aicpu/pad_v3_grad.py +59 -0
- mindspore/ops/_op_impl/aicpu/padding.py +41 -0
- mindspore/ops/_op_impl/aicpu/parameterized_truncated_normal.py +54 -0
- mindspore/ops/_op_impl/aicpu/pdist_grad.py +33 -0
- mindspore/ops/_op_impl/aicpu/poisson.py +37 -0
- mindspore/ops/_op_impl/aicpu/polar.py +32 -0
- mindspore/ops/_op_impl/aicpu/polygamma.py +34 -0
- mindspore/ops/_op_impl/aicpu/pow.py +39 -0
- mindspore/ops/_op_impl/aicpu/print_tensor.py +39 -0
- mindspore/ops/_op_impl/aicpu/priority_replay_buffer.py +113 -0
- mindspore/ops/_op_impl/aicpu/qr.py +36 -0
- mindspore/ops/_op_impl/aicpu/quant_dtype_cast.py +40 -0
- mindspore/ops/_op_impl/aicpu/quantile.py +35 -0
- mindspore/ops/_op_impl/aicpu/ragged_range.py +49 -0
- mindspore/ops/_op_impl/aicpu/ragged_tensor_to_sparse.py +73 -0
- mindspore/ops/_op_impl/aicpu/ragged_tensor_to_tensor.py +74 -0
- mindspore/ops/_op_impl/aicpu/random_categorical.py +68 -0
- mindspore/ops/_op_impl/aicpu/random_choice_with_mask.py +36 -0
- mindspore/ops/_op_impl/aicpu/random_gamma.py +38 -0
- mindspore/ops/_op_impl/aicpu/random_poisson.py +134 -0
- mindspore/ops/_op_impl/aicpu/random_shuffle.py +47 -0
- mindspore/ops/_op_impl/aicpu/randperm.py +38 -0
- mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
- mindspore/ops/_op_impl/aicpu/range.py +36 -0
- mindspore/ops/_op_impl/aicpu/range_v2.py +35 -0
- mindspore/ops/_op_impl/aicpu/real.py +31 -0
- mindspore/ops/_op_impl/aicpu/real_div.py +40 -0
- mindspore/ops/_op_impl/aicpu/reciprocal.py +34 -0
- mindspore/ops/_op_impl/aicpu/reciprocal_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/reduce_mean.py +57 -0
- mindspore/ops/_op_impl/aicpu/reduce_prod.py +57 -0
- mindspore/ops/_op_impl/aicpu/reduce_sum.py +57 -0
- mindspore/ops/_op_impl/aicpu/relu_grad_v3.py +41 -0
- mindspore/ops/_op_impl/aicpu/relu_v3.py +38 -0
- mindspore/ops/_op_impl/aicpu/reservoir_replay_buffer.py +96 -0
- mindspore/ops/_op_impl/aicpu/reshape.py +42 -0
- mindspore/ops/_op_impl/aicpu/resize_area.py +40 -0
- mindspore/ops/_op_impl/aicpu/resize_bicubic.py +20 -0
- mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +19 -0
- mindspore/ops/_op_impl/aicpu/resize_bilinear.py +32 -0
- mindspore/ops/_op_impl/aicpu/resize_bilinear_grad.py +32 -0
- mindspore/ops/_op_impl/aicpu/resize_nearest_neighbor_v2.py +36 -0
- mindspore/ops/_op_impl/aicpu/resize_nearest_neighbor_v2_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/resize_v2.py +68 -0
- mindspore/ops/_op_impl/aicpu/resize_v2_grad.py +68 -0
- mindspore/ops/_op_impl/aicpu/reverse_sequence.py +55 -0
- mindspore/ops/_op_impl/aicpu/reversev2.py +54 -0
- mindspore/ops/_op_impl/aicpu/rgb_to_hsv.py +32 -0
- mindspore/ops/_op_impl/aicpu/right_shift.py +38 -0
- mindspore/ops/_op_impl/aicpu/rnnt_loss.py +35 -0
- mindspore/ops/_op_impl/aicpu/round.py +34 -0
- mindspore/ops/_op_impl/aicpu/rsqrt.py +33 -0
- mindspore/ops/_op_impl/aicpu/rsqrt_grad.py +36 -0
- mindspore/ops/_op_impl/aicpu/sample_distorted_bounding_box_v2.py +49 -0
- mindspore/ops/_op_impl/aicpu/scale_and_translate.py +52 -0
- mindspore/ops/_op_impl/aicpu/scale_and_translate_grad.py +36 -0
- mindspore/ops/_op_impl/aicpu/scatter.py +79 -0
- mindspore/ops/_op_impl/aicpu/scatter_add_with_axis.py +53 -0
- mindspore/ops/_op_impl/aicpu/scatter_elements.py +39 -0
- mindspore/ops/_op_impl/aicpu/scatter_nd.py +59 -0
- mindspore/ops/_op_impl/aicpu/scatter_nd_max.py +54 -0
- mindspore/ops/_op_impl/aicpu/scatter_nd_min.py +54 -0
- mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +59 -0
- mindspore/ops/_op_impl/aicpu/search_sorted.py +44 -0
- mindspore/ops/_op_impl/aicpu/segment_max.py +52 -0
- mindspore/ops/_op_impl/aicpu/segment_mean.py +56 -0
- mindspore/ops/_op_impl/aicpu/segment_min.py +52 -0
- mindspore/ops/_op_impl/aicpu/segment_prod.py +56 -0
- mindspore/ops/_op_impl/aicpu/segment_sum.py +56 -0
- mindspore/ops/_op_impl/aicpu/select.py +45 -0
- mindspore/ops/_op_impl/aicpu/self_adjoint_eig.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_add.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_add_offset.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_addn.py +38 -0
- mindspore/ops/_op_impl/aicpu/sequence_concat.py +40 -0
- mindspore/ops/_op_impl/aicpu/sequence_stack.py +40 -0
- mindspore/ops/_op_impl/aicpu/set_size.py +38 -0
- mindspore/ops/_op_impl/aicpu/sign.py +36 -0
- mindspore/ops/_op_impl/aicpu/sin.py +34 -0
- mindspore/ops/_op_impl/aicpu/sinc.py +43 -0
- mindspore/ops/_op_impl/aicpu/sinh.py +34 -0
- mindspore/ops/_op_impl/aicpu/slice.py +59 -0
- mindspore/ops/_op_impl/aicpu/slice_grad.py +76 -0
- mindspore/ops/_op_impl/aicpu/smooth_l1_loss.py +35 -0
- mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
- mindspore/ops/_op_impl/aicpu/sort.py +39 -0
- mindspore/ops/_op_impl/aicpu/space_to_depth.py +44 -0
- mindspore/ops/_op_impl/aicpu/sparse_addmm.py +87 -0
- mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +80 -0
- mindspore/ops/_op_impl/aicpu/sparse_apply_centered_rms_prop.py +105 -0
- mindspore/ops/_op_impl/aicpu/sparse_apply_momentum.py +80 -0
- mindspore/ops/_op_impl/aicpu/sparse_apply_proximal_gradient_descent.py +79 -0
- mindspore/ops/_op_impl/aicpu/sparse_concat.py +59 -0
- mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
- mindspore/ops/_op_impl/aicpu/sparse_dense_cwise_add.py +58 -0
- mindspore/ops/_op_impl/aicpu/sparse_dense_cwise_div.py +58 -0
- mindspore/ops/_op_impl/aicpu/sparse_dense_cwise_mul.py +58 -0
- mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows.py +63 -0
- mindspore/ops/_op_impl/aicpu/sparse_fill_empty_rows_grad.py +45 -0
- mindspore/ops/_op_impl/aicpu/sparse_matrix_mat_mul.py +56 -0
- mindspore/ops/_op_impl/aicpu/sparse_matrix_nnz.py +81 -0
- mindspore/ops/_op_impl/aicpu/sparse_matrix_transpose.py +116 -0
- mindspore/ops/_op_impl/aicpu/sparse_reorder.py +56 -0
- mindspore/ops/_op_impl/aicpu/sparse_reshape.py +34 -0
- mindspore/ops/_op_impl/aicpu/sparse_segment_mean_grad.py +36 -0
- mindspore/ops/_op_impl/aicpu/sparse_segment_mean_with_num_segments.py +44 -0
- mindspore/ops/_op_impl/aicpu/sparse_segment_sqrt_n.py +43 -0
- mindspore/ops/_op_impl/aicpu/sparse_segment_sqrt_n_grad.py +38 -0
- mindspore/ops/_op_impl/aicpu/sparse_segment_sqrt_n_with_num_segments.py +44 -0
- mindspore/ops/_op_impl/aicpu/sparse_segment_sum.py +49 -0
- mindspore/ops/_op_impl/aicpu/sparse_segment_sum_with_num_segments.py +68 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice.py +63 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +61 -0
- mindspore/ops/_op_impl/aicpu/sparse_softmax.py +33 -0
- mindspore/ops/_op_impl/aicpu/sparse_softmax_cross_entropy_with_logits_v2.py +35 -0
- mindspore/ops/_op_impl/aicpu/sparse_sparse_maximum.py +53 -0
- mindspore/ops/_op_impl/aicpu/sparse_sparse_minimum.py +53 -0
- mindspore/ops/_op_impl/aicpu/sparse_tensor_dense_add.py +84 -0
- mindspore/ops/_op_impl/aicpu/sparse_tensor_dense_mat_mul.py +190 -0
- mindspore/ops/_op_impl/aicpu/sparse_tensor_to_csr_sparse_matrix.py +51 -0
- mindspore/ops/_op_impl/aicpu/sparse_to_dense_v2.py +73 -0
- mindspore/ops/_op_impl/aicpu/split.py +45 -0
- mindspore/ops/_op_impl/aicpu/sqrt.py +34 -0
- mindspore/ops/_op_impl/aicpu/sqrt_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/square.py +35 -0
- mindspore/ops/_op_impl/aicpu/squared_difference.py +37 -0
- mindspore/ops/_op_impl/aicpu/squeeze.py +42 -0
- mindspore/ops/_op_impl/aicpu/sspaddmm.py +97 -0
- mindspore/ops/_op_impl/aicpu/stack.py +45 -0
- mindspore/ops/_op_impl/aicpu/stack_push_pop.py +87 -0
- mindspore/ops/_op_impl/aicpu/standard_laplace.py +34 -0
- mindspore/ops/_op_impl/aicpu/standard_normal.py +34 -0
- mindspore/ops/_op_impl/aicpu/stateless_dropout_genmask.py +37 -0
- mindspore/ops/_op_impl/aicpu/stft.py +70 -0
- mindspore/ops/_op_impl/aicpu/strided_slice.py +43 -0
- mindspore/ops/_op_impl/aicpu/strided_slice_grad.py +50 -0
- mindspore/ops/_op_impl/aicpu/sub.py +41 -0
- mindspore/ops/_op_impl/aicpu/sub_and_filter.py +36 -0
- mindspore/ops/_op_impl/aicpu/tan.py +34 -0
- mindspore/ops/_op_impl/aicpu/tanh.py +34 -0
- mindspore/ops/_op_impl/aicpu/tanh_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
- mindspore/ops/_op_impl/aicpu/tile.py +56 -0
- mindspore/ops/_op_impl/aicpu/topk.py +34 -0
- mindspore/ops/_op_impl/aicpu/trace.py +40 -0
- mindspore/ops/_op_impl/aicpu/tracegrad.py +41 -0
- mindspore/ops/_op_impl/aicpu/trans_data.py +35 -0
- mindspore/ops/_op_impl/aicpu/transpose.py +58 -0
- mindspore/ops/_op_impl/aicpu/tridiagonal_matmul.py +42 -0
- mindspore/ops/_op_impl/aicpu/tridiagonal_solve.py +35 -0
- mindspore/ops/_op_impl/aicpu/tril.py +42 -0
- mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
- mindspore/ops/_op_impl/aicpu/triplet_margin_loss.py +62 -0
- mindspore/ops/_op_impl/aicpu/triu.py +43 -0
- mindspore/ops/_op_impl/aicpu/triu_indices.py +34 -0
- mindspore/ops/_op_impl/aicpu/truncated_normal.py +39 -0
- mindspore/ops/_op_impl/aicpu/uniform.py +36 -0
- mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +41 -0
- mindspore/ops/_op_impl/aicpu/uniform_int.py +36 -0
- mindspore/ops/_op_impl/aicpu/uniform_real.py +33 -0
- mindspore/ops/_op_impl/aicpu/unique.py +31 -0
- mindspore/ops/_op_impl/aicpu/unique_consecutive.py +47 -0
- mindspore/ops/_op_impl/aicpu/unique_with_pad.py +32 -0
- mindspore/ops/_op_impl/aicpu/unravel_index.py +32 -0
- mindspore/ops/_op_impl/aicpu/unsorted_segment_prod.py +53 -0
- mindspore/ops/_op_impl/aicpu/unsorted_segment_sum.py +57 -0
- mindspore/ops/_op_impl/aicpu/unstack.py +45 -0
- mindspore/ops/_op_impl/aicpu/update_cache.py +44 -0
- mindspore/ops/_op_impl/aicpu/upper_bound.py +47 -0
- mindspore/ops/_op_impl/aicpu/upsample_nearest_3d.py +42 -0
- mindspore/ops/_op_impl/aicpu/upsample_nearest_3d_grad.py +49 -0
- mindspore/ops/_op_impl/aicpu/upsample_trilinear_3d.py +40 -0
- mindspore/ops/_op_impl/aicpu/upsample_trilinear_3d_grad.py +50 -0
- mindspore/ops/_op_impl/aicpu/xdivy.py +35 -0
- mindspore/ops/_op_impl/aicpu/xlogy.py +33 -0
- mindspore/ops/_op_impl/aicpu/zeros_like.py +42 -0
- mindspore/ops/_op_impl/aicpu/zeta.py +31 -0
- mindspore/ops/_op_impl/akg/__init__.py +19 -0
- mindspore/ops/_op_impl/akg/ascend/__init__.py +48 -0
- mindspore/ops/_op_impl/akg/ascend/abs.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/add.py +42 -0
- mindspore/ops/_op_impl/akg/ascend/add_n.py +37 -0
- mindspore/ops/_op_impl/akg/ascend/batchmatmul.py +33 -0
- mindspore/ops/_op_impl/akg/ascend/cast.py +46 -0
- mindspore/ops/_op_impl/akg/ascend/equal.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/exp.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/expand_dims.py +33 -0
- mindspore/ops/_op_impl/akg/ascend/greater.py +34 -0
- mindspore/ops/_op_impl/akg/ascend/greater_equal.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/less.py +31 -0
- mindspore/ops/_op_impl/akg/ascend/less_equal.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/load_im2col.py +33 -0
- mindspore/ops/_op_impl/akg/ascend/log.py +34 -0
- mindspore/ops/_op_impl/akg/ascend/maximum.py +36 -0
- mindspore/ops/_op_impl/akg/ascend/minimum.py +39 -0
- mindspore/ops/_op_impl/akg/ascend/mul.py +41 -0
- mindspore/ops/_op_impl/akg/ascend/neg.py +37 -0
- mindspore/ops/_op_impl/akg/ascend/pow.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/prod_force_se_a.py +33 -0
- mindspore/ops/_op_impl/akg/ascend/real_div.py +36 -0
- mindspore/ops/_op_impl/akg/ascend/reciprocal.py +32 -0
- mindspore/ops/_op_impl/akg/ascend/reduce_max.py +32 -0
- mindspore/ops/_op_impl/akg/ascend/reduce_min.py +32 -0
- mindspore/ops/_op_impl/akg/ascend/reduce_sum.py +37 -0
- mindspore/ops/_op_impl/akg/ascend/rsqrt.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/select.py +37 -0
- mindspore/ops/_op_impl/akg/ascend/sqrt.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/square.py +35 -0
- mindspore/ops/_op_impl/akg/ascend/sub.py +42 -0
- mindspore/ops/_op_impl/akg/cpu/__init__.py +23 -0
- mindspore/ops/_op_impl/akg/cpu/coo2csr.py +29 -0
- mindspore/ops/_op_impl/akg/cpu/csr2coo.py +29 -0
- mindspore/ops/_op_impl/akg/cpu/csr_gather.py +33 -0
- mindspore/ops/_op_impl/akg/cpu/csr_mm.py +34 -0
- mindspore/ops/_op_impl/akg/cpu/csr_mul.py +33 -0
- mindspore/ops/_op_impl/akg/cpu/csr_mv.py +33 -0
- mindspore/ops/_op_impl/akg/cpu/csr_reduce_sum.py +31 -0
- mindspore/ops/_op_impl/akg/gpu/__init__.py +24 -0
- mindspore/ops/_op_impl/akg/gpu/coo2csr.py +29 -0
- mindspore/ops/_op_impl/akg/gpu/csr2coo.py +29 -0
- mindspore/ops/_op_impl/akg/gpu/csr_div.py +36 -0
- mindspore/ops/_op_impl/akg/gpu/csr_gather.py +33 -0
- mindspore/ops/_op_impl/akg/gpu/csr_mm.py +37 -0
- mindspore/ops/_op_impl/akg/gpu/csr_mul.py +36 -0
- mindspore/ops/_op_impl/akg/gpu/csr_mv.py +36 -0
- mindspore/ops/_op_impl/akg/gpu/csr_reduce_sum.py +33 -0
- mindspore/ops/_op_impl/cpu/__init__.py +78 -0
- mindspore/ops/_op_impl/cpu/adam.py +49 -0
- mindspore/ops/_op_impl/cpu/adam_weight_decay.py +47 -0
- mindspore/ops/_op_impl/cpu/arg_max.py +30 -0
- mindspore/ops/_op_impl/cpu/arg_max_with_value.py +31 -0
- mindspore/ops/_op_impl/cpu/arg_min_with_value.py +31 -0
- mindspore/ops/_op_impl/cpu/buffer_append.py +28 -0
- mindspore/ops/_op_impl/cpu/buffer_get.py +28 -0
- mindspore/ops/_op_impl/cpu/buffer_sample.py +28 -0
- mindspore/ops/_op_impl/cpu/cast.py +171 -0
- mindspore/ops/_op_impl/cpu/concat_offset.py +38 -0
- mindspore/ops/_op_impl/cpu/conv2d.py +30 -0
- mindspore/ops/_op_impl/cpu/conv3d.py +30 -0
- mindspore/ops/_op_impl/cpu/div.py +32 -0
- mindspore/ops/_op_impl/cpu/dropout.py +31 -0
- mindspore/ops/_op_impl/cpu/dropout_grad.py +30 -0
- mindspore/ops/_op_impl/cpu/dynamic_shape.py +42 -0
- mindspore/ops/_op_impl/cpu/dynamic_stitch.py +41 -0
- mindspore/ops/_op_impl/cpu/equal_count.py +30 -0
- mindspore/ops/_op_impl/cpu/gather_d.py +49 -0
- mindspore/ops/_op_impl/cpu/gather_d_grad.py +38 -0
- mindspore/ops/_op_impl/cpu/gather_d_grad_v2.py +40 -0
- mindspore/ops/_op_impl/cpu/gather_v2.py +40 -0
- mindspore/ops/_op_impl/cpu/hsigmoid.py +33 -0
- mindspore/ops/_op_impl/cpu/hsigmoid_grad.py +34 -0
- mindspore/ops/_op_impl/cpu/hswish.py +32 -0
- mindspore/ops/_op_impl/cpu/hswish_grad.py +33 -0
- mindspore/ops/_op_impl/cpu/identity_n.py +40 -0
- mindspore/ops/_op_impl/cpu/is_finite.py +39 -0
- mindspore/ops/_op_impl/cpu/l2loss.py +30 -0
- mindspore/ops/_op_impl/cpu/layer_norm.py +36 -0
- mindspore/ops/_op_impl/cpu/layer_norm_grad.py +38 -0
- mindspore/ops/_op_impl/cpu/maximum.py +35 -0
- mindspore/ops/_op_impl/cpu/maximum_grad.py +47 -0
- mindspore/ops/_op_impl/cpu/minimum.py +40 -0
- mindspore/ops/_op_impl/cpu/minimum_grad.py +51 -0
- mindspore/ops/_op_impl/cpu/mirror_pad.py +36 -0
- mindspore/ops/_op_impl/cpu/mirror_pad_grad.py +36 -0
- mindspore/ops/_op_impl/cpu/mul.py +32 -0
- mindspore/ops/_op_impl/cpu/one_hot.py +31 -0
- mindspore/ops/_op_impl/cpu/pad.py +32 -0
- mindspore/ops/_op_impl/cpu/pow.py +32 -0
- mindspore/ops/_op_impl/cpu/priority_replay_buffer.py +42 -0
- mindspore/ops/_op_impl/cpu/pyexecute.py +29 -0
- mindspore/ops/_op_impl/cpu/pyfunc.py +29 -0
- mindspore/ops/_op_impl/cpu/range.py +34 -0
- mindspore/ops/_op_impl/cpu/real_div.py +33 -0
- mindspore/ops/_op_impl/cpu/reduce_all.py +29 -0
- mindspore/ops/_op_impl/cpu/reduce_any.py +29 -0
- mindspore/ops/_op_impl/cpu/reduce_max.py +32 -0
- mindspore/ops/_op_impl/cpu/reduce_mean.py +40 -0
- mindspore/ops/_op_impl/cpu/reduce_min.py +32 -0
- mindspore/ops/_op_impl/cpu/reduce_prod.py +40 -0
- mindspore/ops/_op_impl/cpu/reduce_std.py +31 -0
- mindspore/ops/_op_impl/cpu/reduce_sum.py +41 -0
- mindspore/ops/_op_impl/cpu/space_to_batch_nd.py +38 -0
- mindspore/ops/_op_impl/cpu/sparse_slice.py +62 -0
- mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +60 -0
- mindspore/ops/_op_impl/cpu/split.py +34 -0
- mindspore/ops/_op_impl/cpu/sspaddmm.py +95 -0
- mindspore/ops/_op_impl/cpu/stack.py +38 -0
- mindspore/ops/_op_impl/cpu/sub.py +32 -0
- mindspore/ops/_op_impl/cpu/tensor_copy_slices.py +41 -0
- mindspore/ops/_op_impl/cpu/tile.py +37 -0
- mindspore/ops/_op_impl/cpu/top_k.py +31 -0
- mindspore/ops/_op_impl/cpu/transpose.py +39 -0
- mindspore/ops/_primitive_cache.py +90 -0
- mindspore/ops/_register_for_op.py +73 -0
- mindspore/ops/_utils/__init__.py +20 -0
- mindspore/ops/_utils/utils.py +147 -0
- mindspore/ops/_vmap/__init__.py +25 -0
- mindspore/ops/_vmap/vmap_array_ops.py +2149 -0
- mindspore/ops/_vmap/vmap_base.py +533 -0
- mindspore/ops/_vmap/vmap_convolution_ops.py +441 -0
- mindspore/ops/_vmap/vmap_debug_ops.py +50 -0
- mindspore/ops/_vmap/vmap_grad_math_ops.py +274 -0
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +806 -0
- mindspore/ops/_vmap/vmap_image_ops.py +194 -0
- mindspore/ops/_vmap/vmap_math_ops.py +993 -0
- mindspore/ops/_vmap/vmap_nn_ops.py +2250 -0
- mindspore/ops/_vmap/vmap_other_ops.py +105 -0
- mindspore/ops/_vmap/vmap_random_ops.py +122 -0
- mindspore/ops/_vmap/vmap_sparse_ops.py +89 -0
- mindspore/ops/auto_generate/__init__.py +31 -0
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +309 -0
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +252 -0
- mindspore/ops/auto_generate/gen_arg_handler.py +197 -0
- mindspore/ops/auto_generate/gen_extend_func.py +1701 -0
- mindspore/ops/auto_generate/gen_ops_def.py +8482 -0
- mindspore/ops/auto_generate/gen_ops_prim.py +16704 -0
- mindspore/ops/auto_generate/pyboost_inner_prim.py +549 -0
- mindspore/ops/composite/__init__.py +71 -0
- mindspore/ops/composite/base.py +1318 -0
- mindspore/ops/composite/env_ops.py +41 -0
- mindspore/ops/composite/math_ops.py +125 -0
- mindspore/ops/composite/multitype_ops/__init__.py +77 -0
- mindspore/ops/composite/multitype_ops/_compile_utils.py +1459 -0
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +897 -0
- mindspore/ops/composite/multitype_ops/add_impl.py +606 -0
- mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +56 -0
- mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +56 -0
- mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +56 -0
- mindspore/ops/composite/multitype_ops/div_impl.py +189 -0
- mindspore/ops/composite/multitype_ops/equal_impl.py +335 -0
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +88 -0
- mindspore/ops/composite/multitype_ops/getitem_impl.py +400 -0
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +109 -0
- mindspore/ops/composite/multitype_ops/greater_impl.py +110 -0
- mindspore/ops/composite/multitype_ops/in_impl.py +196 -0
- mindspore/ops/composite/multitype_ops/left_shift_impl.py +37 -0
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +111 -0
- mindspore/ops/composite/multitype_ops/less_impl.py +112 -0
- mindspore/ops/composite/multitype_ops/logic_not_impl.py +113 -0
- mindspore/ops/composite/multitype_ops/logical_and_impl.py +60 -0
- mindspore/ops/composite/multitype_ops/logical_or_impl.py +61 -0
- mindspore/ops/composite/multitype_ops/mod_impl.py +86 -0
- mindspore/ops/composite/multitype_ops/mul_impl.py +294 -0
- mindspore/ops/composite/multitype_ops/negative_impl.py +79 -0
- mindspore/ops/composite/multitype_ops/not_equal_impl.py +290 -0
- mindspore/ops/composite/multitype_ops/not_in_impl.py +196 -0
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +96 -0
- mindspore/ops/composite/multitype_ops/pow_impl.py +87 -0
- mindspore/ops/composite/multitype_ops/right_shift_impl.py +37 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +884 -0
- mindspore/ops/composite/multitype_ops/sub_impl.py +116 -0
- mindspore/ops/composite/multitype_ops/uadd_impl.py +29 -0
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +228 -0
- mindspore/ops/deprecated.py +315 -0
- mindspore/ops/function/__init__.py +782 -0
- mindspore/ops/function/array_func.py +7226 -0
- mindspore/ops/function/clip_func.py +384 -0
- mindspore/ops/function/debug_func.py +181 -0
- mindspore/ops/function/fft_func.py +44 -0
- mindspore/ops/function/grad/__init__.py +34 -0
- mindspore/ops/function/grad/grad_func.py +1425 -0
- mindspore/ops/function/image_func.py +292 -0
- mindspore/ops/function/linalg_func.py +416 -0
- mindspore/ops/function/math_func.py +12228 -0
- mindspore/ops/function/nn_func.py +8609 -0
- mindspore/ops/function/other_func.py +115 -0
- mindspore/ops/function/parameter_func.py +134 -0
- mindspore/ops/function/random_func.py +1715 -0
- mindspore/ops/function/reshard_func.py +104 -0
- mindspore/ops/function/sparse_func.py +884 -0
- mindspore/ops/function/sparse_unary_func.py +2422 -0
- mindspore/ops/function/spectral_func.py +150 -0
- mindspore/ops/function/vmap_func.py +117 -0
- mindspore/ops/functional.py +464 -0
- mindspore/ops/op_info_register.py +1572 -0
- mindspore/ops/operations/__init__.py +722 -0
- mindspore/ops/operations/_csr_ops.py +403 -0
- mindspore/ops/operations/_custom_grad.py +181 -0
- mindspore/ops/operations/_embedding_cache_ops.py +307 -0
- mindspore/ops/operations/_grad_ops.py +2978 -0
- mindspore/ops/operations/_infer_ops.py +19 -0
- mindspore/ops/operations/_inner_ops.py +2544 -0
- mindspore/ops/operations/_map_tensor_ops.py +112 -0
- mindspore/ops/operations/_ms_kernel.py +601 -0
- mindspore/ops/operations/_ocr_ops.py +379 -0
- mindspore/ops/operations/_opaque_predicate_registry.py +41 -0
- mindspore/ops/operations/_pyfunc_registry.py +58 -0
- mindspore/ops/operations/_quant_ops.py +1844 -0
- mindspore/ops/operations/_rl_inner_ops.py +1231 -0
- mindspore/ops/operations/_scalar_ops.py +106 -0
- mindspore/ops/operations/_sequence_ops.py +1155 -0
- mindspore/ops/operations/_sparse_grad_ops.py +56 -0
- mindspore/ops/operations/_tensor_array.py +359 -0
- mindspore/ops/operations/_thor_ops.py +807 -0
- mindspore/ops/operations/array_ops.py +6124 -0
- mindspore/ops/operations/comm_ops.py +1985 -0
- mindspore/ops/operations/control_ops.py +127 -0
- mindspore/ops/operations/custom_ops.py +1129 -0
- mindspore/ops/operations/debug_ops.py +678 -0
- mindspore/ops/operations/image_ops.py +1041 -0
- mindspore/ops/operations/inner_ops.py +697 -0
- mindspore/ops/operations/linalg_ops.py +95 -0
- mindspore/ops/operations/manually_defined/__init__.py +24 -0
- mindspore/ops/operations/manually_defined/_inner.py +73 -0
- mindspore/ops/operations/manually_defined/ops_def.py +2271 -0
- mindspore/ops/operations/math_ops.py +5095 -0
- mindspore/ops/operations/nn_ops.py +9575 -0
- mindspore/ops/operations/other_ops.py +874 -0
- mindspore/ops/operations/random_ops.py +1288 -0
- mindspore/ops/operations/reshard_ops.py +53 -0
- mindspore/ops/operations/rl_ops.py +288 -0
- mindspore/ops/operations/sparse_ops.py +2753 -0
- mindspore/ops/operations/spectral_ops.py +111 -0
- mindspore/ops/primitive.py +1046 -0
- mindspore/ops/signature.py +54 -0
- mindspore/ops/vm_impl_registry.py +91 -0
- mindspore/ops_generate/__init__.py +27 -0
- mindspore/ops_generate/arg_dtype_cast.py +252 -0
- mindspore/ops_generate/arg_handler.py +197 -0
- mindspore/ops_generate/gen_aclnn_implement.py +263 -0
- mindspore/ops_generate/gen_constants.py +36 -0
- mindspore/ops_generate/gen_ops.py +1099 -0
- mindspore/ops_generate/gen_ops_inner_prim.py +131 -0
- mindspore/ops_generate/gen_pyboost_func.py +1052 -0
- mindspore/ops_generate/gen_utils.py +209 -0
- mindspore/ops_generate/op_proto.py +145 -0
- mindspore/ops_generate/pyboost_utils.py +367 -0
- mindspore/ops_generate/template.py +261 -0
- mindspore/parallel/__init__.py +30 -0
- mindspore/parallel/_auto_parallel_context.py +1486 -0
- mindspore/parallel/_cell_wrapper.py +174 -0
- mindspore/parallel/_cost_model_context.py +700 -0
- mindspore/parallel/_dp_allreduce_fusion.py +159 -0
- mindspore/parallel/_offload_context.py +275 -0
- mindspore/parallel/_parallel_serialization.py +561 -0
- mindspore/parallel/_ps_context.py +242 -0
- mindspore/parallel/_recovery_context.py +110 -0
- mindspore/parallel/_tensor.py +730 -0
- mindspore/parallel/_transformer/__init__.py +35 -0
- mindspore/parallel/_transformer/layers.py +765 -0
- mindspore/parallel/_transformer/loss.py +251 -0
- mindspore/parallel/_transformer/moe.py +693 -0
- mindspore/parallel/_transformer/op_parallel_config.py +222 -0
- mindspore/parallel/_transformer/transformer.py +3119 -0
- mindspore/parallel/_utils.py +612 -0
- mindspore/parallel/algo_parameter_config.py +400 -0
- mindspore/parallel/checkpoint_transform.py +650 -0
- mindspore/parallel/cluster/__init__.py +15 -0
- mindspore/parallel/cluster/process_entity/__init__.py +18 -0
- mindspore/parallel/cluster/process_entity/_api.py +352 -0
- mindspore/parallel/cluster/process_entity/_utils.py +101 -0
- mindspore/parallel/cluster/run.py +136 -0
- mindspore/parallel/mpi/__init__.py +14 -0
- mindspore/parallel/mpi/_mpi_config.py +116 -0
- mindspore/parallel/parameter_broadcast.py +151 -0
- mindspore/parallel/shard.py +481 -0
- mindspore/parallel/transform_safetensors.py +993 -0
- mindspore/profiler/__init__.py +28 -0
- mindspore/profiler/common/__init__.py +14 -0
- mindspore/profiler/common/constant.py +29 -0
- mindspore/profiler/common/exceptions/__init__.py +14 -0
- mindspore/profiler/common/exceptions/error_code.py +83 -0
- mindspore/profiler/common/exceptions/exceptions.py +286 -0
- mindspore/profiler/common/process_pool.py +41 -0
- mindspore/profiler/common/registry.py +47 -0
- mindspore/profiler/common/singleton.py +28 -0
- mindspore/profiler/common/struct_type.py +118 -0
- mindspore/profiler/common/util.py +472 -0
- mindspore/profiler/common/validator/__init__.py +14 -0
- mindspore/profiler/common/validator/validate_path.py +84 -0
- mindspore/profiler/dynamic_profiler.py +694 -0
- mindspore/profiler/envprofiling.py +254 -0
- mindspore/profiler/parser/__init__.py +14 -0
- mindspore/profiler/parser/aicpu_data_parser.py +272 -0
- mindspore/profiler/parser/ascend_analysis/__init__.py +14 -0
- mindspore/profiler/parser/ascend_analysis/constant.py +71 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +180 -0
- mindspore/profiler/parser/ascend_analysis/function_event.py +185 -0
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +136 -0
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +131 -0
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +104 -0
- mindspore/profiler/parser/ascend_analysis/path_manager.py +313 -0
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +123 -0
- mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +75 -0
- mindspore/profiler/parser/ascend_cluster_generator.py +116 -0
- mindspore/profiler/parser/ascend_communicate_generator.py +314 -0
- mindspore/profiler/parser/ascend_flops_generator.py +116 -0
- mindspore/profiler/parser/ascend_fpbp_generator.py +82 -0
- mindspore/profiler/parser/ascend_hccl_generator.py +271 -0
- mindspore/profiler/parser/ascend_integrate_generator.py +42 -0
- mindspore/profiler/parser/ascend_memory_generator.py +185 -0
- mindspore/profiler/parser/ascend_msprof_exporter.py +282 -0
- mindspore/profiler/parser/ascend_msprof_generator.py +187 -0
- mindspore/profiler/parser/ascend_op_generator.py +334 -0
- mindspore/profiler/parser/ascend_steptrace_generator.py +94 -0
- mindspore/profiler/parser/ascend_timeline_generator.py +545 -0
- mindspore/profiler/parser/base_timeline_generator.py +483 -0
- mindspore/profiler/parser/container.py +229 -0
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +697 -0
- mindspore/profiler/parser/flops_parser.py +531 -0
- mindspore/profiler/parser/framework_enum.py +111 -0
- mindspore/profiler/parser/framework_parser.py +464 -0
- mindspore/profiler/parser/framework_struct.py +61 -0
- mindspore/profiler/parser/gpu_analysis/__init__.py +14 -0
- mindspore/profiler/parser/gpu_analysis/function_event.py +44 -0
- mindspore/profiler/parser/gpu_analysis/fwk_file_parser.py +89 -0
- mindspore/profiler/parser/gpu_analysis/profiler_info_parser.py +72 -0
- mindspore/profiler/parser/hccl_parser.py +573 -0
- mindspore/profiler/parser/hwts_log_parser.py +122 -0
- mindspore/profiler/parser/integrator.py +526 -0
- mindspore/profiler/parser/memory_usage_parser.py +277 -0
- mindspore/profiler/parser/minddata_analyzer.py +800 -0
- mindspore/profiler/parser/minddata_parser.py +186 -0
- mindspore/profiler/parser/minddata_pipeline_parser.py +299 -0
- mindspore/profiler/parser/op_intermediate_parser.py +149 -0
- mindspore/profiler/parser/optime_parser.py +250 -0
- mindspore/profiler/parser/profiler_info.py +213 -0
- mindspore/profiler/parser/step_trace_parser.py +666 -0
- mindspore/profiler/profiler.py +153 -0
- mindspore/profiler/profiling.py +1922 -0
- mindspore/rewrite/__init__.py +28 -0
- mindspore/rewrite/api/__init__.py +17 -0
- mindspore/rewrite/api/node.py +519 -0
- mindspore/rewrite/api/node_type.py +53 -0
- mindspore/rewrite/api/pattern_engine.py +490 -0
- mindspore/rewrite/api/scoped_value.py +181 -0
- mindspore/rewrite/api/symbol_tree.py +497 -0
- mindspore/rewrite/ast_helpers/__init__.py +25 -0
- mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
- mindspore/rewrite/ast_helpers/ast_finder.py +404 -0
- mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +605 -0
- mindspore/rewrite/ast_helpers/ast_replacer.py +79 -0
- mindspore/rewrite/common/__init__.py +19 -0
- mindspore/rewrite/common/config.py +24 -0
- mindspore/rewrite/common/error_log.py +39 -0
- mindspore/rewrite/common/event.py +28 -0
- mindspore/rewrite/common/namer.py +271 -0
- mindspore/rewrite/common/namespace.py +118 -0
- mindspore/rewrite/common/observable.py +44 -0
- mindspore/rewrite/common/observer.py +54 -0
- mindspore/rewrite/node/__init__.py +22 -0
- mindspore/rewrite/node/call_function.py +95 -0
- mindspore/rewrite/node/cell_container.py +139 -0
- mindspore/rewrite/node/control_flow.py +113 -0
- mindspore/rewrite/node/node.py +1428 -0
- mindspore/rewrite/node/node_manager.py +283 -0
- mindspore/rewrite/node/node_topological_manager.py +223 -0
- mindspore/rewrite/parsers/__init__.py +29 -0
- mindspore/rewrite/parsers/arguments_parser.py +63 -0
- mindspore/rewrite/parsers/assign_parser.py +852 -0
- mindspore/rewrite/parsers/attribute_parser.py +57 -0
- mindspore/rewrite/parsers/class_def_parser.py +289 -0
- mindspore/rewrite/parsers/constant_parser.py +104 -0
- mindspore/rewrite/parsers/container_parser.py +88 -0
- mindspore/rewrite/parsers/expr_parser.py +55 -0
- mindspore/rewrite/parsers/for_parser.py +61 -0
- mindspore/rewrite/parsers/function_def_parser.py +84 -0
- mindspore/rewrite/parsers/if_parser.py +85 -0
- mindspore/rewrite/parsers/module_parser.py +117 -0
- mindspore/rewrite/parsers/parser.py +43 -0
- mindspore/rewrite/parsers/parser_register.py +86 -0
- mindspore/rewrite/parsers/return_parser.py +37 -0
- mindspore/rewrite/parsers/while_parser.py +59 -0
- mindspore/rewrite/sparsify/__init__.py +0 -0
- mindspore/rewrite/sparsify/sparse_transformer.py +457 -0
- mindspore/rewrite/sparsify/sparsify.py +112 -0
- mindspore/rewrite/sparsify/utils.py +179 -0
- mindspore/rewrite/symbol_tree/__init__.py +20 -0
- mindspore/rewrite/symbol_tree/symbol_tree.py +1819 -0
- mindspore/rewrite/symbol_tree/symbol_tree_builder.py +76 -0
- mindspore/rewrite/symbol_tree/symbol_tree_dumper.py +142 -0
- mindspore/run_check/__init__.py +20 -0
- mindspore/run_check/_check_version.py +507 -0
- mindspore/run_check/run_check.py +66 -0
- mindspore/safeguard/__init__.py +18 -0
- mindspore/safeguard/rewrite_obfuscation.py +875 -0
- mindspore/scipy/__init__.py +18 -0
- mindspore/scipy/fft.py +264 -0
- mindspore/scipy/linalg.py +919 -0
- mindspore/scipy/ops.py +165 -0
- mindspore/scipy/ops_grad.py +115 -0
- mindspore/scipy/ops_wrapper.py +74 -0
- mindspore/scipy/optimize/__init__.py +20 -0
- mindspore/scipy/optimize/_bfgs.py +230 -0
- mindspore/scipy/optimize/_lagrange.py +201 -0
- mindspore/scipy/optimize/_lbfgs.py +146 -0
- mindspore/scipy/optimize/gradient_optimization_algorithm.py +168 -0
- mindspore/scipy/optimize/line_search.py +370 -0
- mindspore/scipy/optimize/linear_sum_assignment.py +78 -0
- mindspore/scipy/optimize/minimize.py +200 -0
- mindspore/scipy/utils.py +156 -0
- mindspore/scipy/utils_const.py +246 -0
- mindspore/train/__init__.py +48 -0
- mindspore/train/_utils.py +465 -0
- mindspore/train/amp.py +935 -0
- mindspore/train/anf_ir_pb2.py +1517 -0
- mindspore/train/callback/__init__.py +44 -0
- mindspore/train/callback/_backup_and_restore.py +117 -0
- mindspore/train/callback/_callback.py +613 -0
- mindspore/train/callback/_checkpoint.py +814 -0
- mindspore/train/callback/_cluster_monitor.py +201 -0
- mindspore/train/callback/_dataset_graph.py +150 -0
- mindspore/train/callback/_early_stop.py +239 -0
- mindspore/train/callback/_flops_collector.py +239 -0
- mindspore/train/callback/_history.py +92 -0
- mindspore/train/callback/_lambda_callback.py +80 -0
- mindspore/train/callback/_landscape.py +1049 -0
- mindspore/train/callback/_loss_monitor.py +107 -0
- mindspore/train/callback/_lr_scheduler_callback.py +76 -0
- mindspore/train/callback/_on_request_exit.py +298 -0
- mindspore/train/callback/_reduce_lr_on_plateau.py +226 -0
- mindspore/train/callback/_summary_collector.py +1184 -0
- mindspore/train/callback/_tft_register.py +352 -0
- mindspore/train/callback/_time_monitor.py +141 -0
- mindspore/train/checkpoint_pb2.py +233 -0
- mindspore/train/data_sink.py +219 -0
- mindspore/train/dataset_helper.py +692 -0
- mindspore/train/lineage_pb2.py +1260 -0
- mindspore/train/loss_scale_manager.py +213 -0
- mindspore/train/memory_profiling_pb2.py +298 -0
- mindspore/train/metrics/__init__.py +175 -0
- mindspore/train/metrics/accuracy.py +133 -0
- mindspore/train/metrics/auc.py +129 -0
- mindspore/train/metrics/bleu_score.py +170 -0
- mindspore/train/metrics/confusion_matrix.py +700 -0
- mindspore/train/metrics/cosine_similarity.py +109 -0
- mindspore/train/metrics/dice.py +116 -0
- mindspore/train/metrics/error.py +175 -0
- mindspore/train/metrics/fbeta.py +167 -0
- mindspore/train/metrics/hausdorff_distance.py +333 -0
- mindspore/train/metrics/loss.py +97 -0
- mindspore/train/metrics/mean_surface_distance.py +189 -0
- mindspore/train/metrics/metric.py +373 -0
- mindspore/train/metrics/occlusion_sensitivity.py +225 -0
- mindspore/train/metrics/perplexity.py +133 -0
- mindspore/train/metrics/precision.py +160 -0
- mindspore/train/metrics/recall.py +159 -0
- mindspore/train/metrics/roc.py +223 -0
- mindspore/train/metrics/root_mean_square_surface_distance.py +191 -0
- mindspore/train/metrics/topk.py +167 -0
- mindspore/train/mind_ir_pb2.py +1908 -0
- mindspore/train/model.py +2252 -0
- mindspore/train/node_strategy_pb2.py +653 -0
- mindspore/train/print_pb2.py +184 -0
- mindspore/train/profiling_parallel_pb2.py +151 -0
- mindspore/train/serialization.py +3325 -0
- mindspore/train/summary/__init__.py +23 -0
- mindspore/train/summary/_lineage_adapter.py +41 -0
- mindspore/train/summary/_summary_adapter.py +496 -0
- mindspore/train/summary/_writer_pool.py +207 -0
- mindspore/train/summary/enums.py +56 -0
- mindspore/train/summary/summary_record.py +581 -0
- mindspore/train/summary/writer.py +167 -0
- mindspore/train/summary_pb2.py +1165 -0
- mindspore/train/train_thor/__init__.py +20 -0
- mindspore/train/train_thor/convert_utils.py +268 -0
- mindspore/train/train_thor/dataset_helper.py +192 -0
- mindspore/train/train_thor/model_thor.py +257 -0
- mindspore/utils/__init__.py +21 -0
- mindspore/utils/utils.py +60 -0
- mindspore/version.py +1 -0
- mindspore-2.4.0.dist-info/METADATA +352 -0
- mindspore-2.4.0.dist-info/RECORD +1387 -0
- mindspore-2.4.0.dist-info/WHEEL +5 -0
- mindspore-2.4.0.dist-info/entry_points.txt +3 -0
- mindspore-2.4.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1448 @@
|
|
|
1
|
+
# This is the Python adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/).
|
|
2
|
+
#
|
|
3
|
+
# Copyright 2020-2024 Huawei Technologies Co., Ltd
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
# ============================================================================
|
|
17
|
+
"""The module of parser python object, called by c++."""
|
|
18
|
+
|
|
19
|
+
from __future__ import absolute_import
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
import ast
|
|
23
|
+
import re
|
|
24
|
+
import hashlib
|
|
25
|
+
import inspect
|
|
26
|
+
import types
|
|
27
|
+
from collections import namedtuple
|
|
28
|
+
from typing import NamedTuple
|
|
29
|
+
from textwrap import dedent
|
|
30
|
+
import builtins
|
|
31
|
+
import numpy
|
|
32
|
+
|
|
33
|
+
import asttokens
|
|
34
|
+
import astunparse
|
|
35
|
+
|
|
36
|
+
from mindspore import Tensor, CSRTensor, COOTensor, RowTensor
|
|
37
|
+
from mindspore import log as logger
|
|
38
|
+
from mindspore import nn
|
|
39
|
+
from mindspore import ops
|
|
40
|
+
from mindspore import context
|
|
41
|
+
from mindspore import tensor
|
|
42
|
+
from mindspore.common.api import _MindsporeFunctionExecutor
|
|
43
|
+
from mindspore.common import dtype as mstype
|
|
44
|
+
from mindspore.common.parameter import Parameter
|
|
45
|
+
from mindspore.common import mutable
|
|
46
|
+
from mindspore.common._register_for_adapter import ms_adapter_registry
|
|
47
|
+
from mindspore._checkparam import is_stub_tensor
|
|
48
|
+
from .namespace import Namespace, ModuleNamespace, ClosureNamespace, ClassMemberNamespace
|
|
49
|
+
from .resources import parse_object_map, ops_symbol_map, convert_object_map, convert_class_to_function_map, trope_ns
|
|
50
|
+
from .resources import SYMBOL_UNDEFINE, constant_fold_functions
|
|
51
|
+
from ...common.api import _convert_python_data
|
|
52
|
+
|
|
53
|
+
# Define resolve type
|
|
54
|
+
RESOLVE_TYPE_NONE = 0 # Resolve None.
|
|
55
|
+
RESOLVE_TYPE_FUNCTION = 1 # Resolve function.
|
|
56
|
+
RESOLVE_TYPE_METHOD = 2 # Resolve class method.
|
|
57
|
+
RESOLVE_TYPE_CLASS_TYPE = 3 # Resolve class type.
|
|
58
|
+
RESOLVE_TYPE_CLASS_INSTANCE = 4 # Resolve the class instance of common class.
|
|
59
|
+
RESOLVE_TYPE_NAMESPACE_INSTANCE = 5 # Resolve the namespace instance.
|
|
60
|
+
RESOLVE_TYPE_NUMPY_INT_NUMBER = 6 # Resolve numpy int number.
|
|
61
|
+
RESOLVE_TYPE_NUMPY_FLOAT_NUMBER = 7 # Resolve numpy float number.
|
|
62
|
+
RESOLVE_TYPE_NUMPY_BOOL_NUMBER = 8 # Resolve numpy bool number.
|
|
63
|
+
RESOLVE_TYPE_TUPLE = 9 # Resolve builtin tuple type.
|
|
64
|
+
RESOLVE_TYPE_LIST = 10 # Resolve builtin list type.
|
|
65
|
+
RESOLVE_TYPE_INVALID = 0xFF # Resolve invalid.
|
|
66
|
+
|
|
67
|
+
# Define the class instance detail type
|
|
68
|
+
# When the type is RESOLVE_TYPE_CLASS_INSTANCE
|
|
69
|
+
CLASS_INSTANCE_TYPE_CELL = 0 # Class instance type is Cell
|
|
70
|
+
CLASS_INSTANCE_TYPE_PRIMITIVE = 1 # Class instance type is Primitive
|
|
71
|
+
CLASS_INSTANCE_TYPE_NUMPY_ARRAY = 2 # Class instance type is Numpy Array
|
|
72
|
+
CLASS_INSTANCE_TYPE_TENSOR = 3 # Class instance type is Tensor
|
|
73
|
+
CLASS_INSTANCE_TYPE_ADAPTER_TENSOR = 4 # Class instance type is Adapter Tensor
|
|
74
|
+
CLASS_INSTANCE_TYPE_INVALID = 0xFF
|
|
75
|
+
|
|
76
|
+
# Ast main type
|
|
77
|
+
AST_MAIN_TYPE_STMT = 0 # ast.Stmt
|
|
78
|
+
AST_MAIN_TYPE_EXPR = 1 # ast.Expr
|
|
79
|
+
AST_MAIN_TYPE_SLICE = 2 # ast.Slice
|
|
80
|
+
AST_MAIN_TYPE_UNKNOWN = 0xFF # unknown
|
|
81
|
+
|
|
82
|
+
# Ast sub type
|
|
83
|
+
AST_SUB_TYPE_AND = 3 # ast.And
|
|
84
|
+
AST_SUB_TYPE_OR = 4 # ast.Or
|
|
85
|
+
AST_SUB_TYPE_NAME = 5 # ast.Name
|
|
86
|
+
AST_SUB_TYPE_TUPLE = 6 # ast.Tuple
|
|
87
|
+
AST_SUB_TYPE_LIST = 7 # ast.List
|
|
88
|
+
AST_SUB_TYPE_SUBSCRIPT = 8 # ast.Subscript
|
|
89
|
+
AST_SUB_TYPE_STARRED = 9 # ast.Starred
|
|
90
|
+
AST_SUB_TYPE_ATTRIBUTE = 10 # ast.Attribute
|
|
91
|
+
AST_SUB_TYPE_DICT = 11 # ast.Dict
|
|
92
|
+
AST_SUB_TYPE_UNKNOWN = 0xFF # unknown
|
|
93
|
+
|
|
94
|
+
# Syntax support
|
|
95
|
+
SYNTAX_SUPPORTED = 0 # Supported syntax
|
|
96
|
+
SYNTAX_UNSUPPORTED_INTERNAL_TYPE = 1 # Unsupported internal type
|
|
97
|
+
SYNTAX_UNSUPPORTED_EXTERNAL_TYPE = 2 # Unsupported external type
|
|
98
|
+
SYNTAX_HYBRID_TYPE = 3 # Hybrid type
|
|
99
|
+
SYNTAX_UNSUPPORTED_NAMESPACE = 4 # Unsupported namespace
|
|
100
|
+
|
|
101
|
+
# Module source location
|
|
102
|
+
MODULE_FROM_MINDSPORE = 0
|
|
103
|
+
MODULE_FROM_THIRDPARTY = 1
|
|
104
|
+
MODULE_FROM_USER_WORKSPACE = 2
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# Process expr statement white list
|
|
108
|
+
# Add as needed, eg: "clear", "extend", "insert", "remove", "reverse"
|
|
109
|
+
parse_expr_statement_white_list = (
|
|
110
|
+
"append", "insert", "clear", "reverse", "extend", "update",
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
_builtin_function_or_method_type = type(abs)
|
|
114
|
+
|
|
115
|
+
# Unsupported python builtin type in graph mode.
|
|
116
|
+
_unsupported_python_builtin_type = (
|
|
117
|
+
set, dict, slice, complex, reversed, type,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Unsupported python builtin type in JIT Fallback.
|
|
121
|
+
_fallback_unsupported_python_builtin_type = (
|
|
122
|
+
compile, eval, exec
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
_modules_from_mindspore = (
|
|
126
|
+
"mindspore", "msadapter", "mindocr", "mindyolo", "mindnlp", "mindcv", "mindspore_rec", "mindaudio", "mindone",
|
|
127
|
+
"mindspore_rl", "mindformers", "mindpet", "mindpose", "mindface", "mindsearch", "mindinsight", "mindelec",
|
|
128
|
+
"mindflow", "mindsponge", "mindearth", "sciai", "mindquantum", "mindarmour", "mindpandas", "mindvision",
|
|
129
|
+
"mindspore_gl", "mindspore_federated", "mindspore_gs", "mindspore_serving", "mindspore_xai", "mindspore_hub",
|
|
130
|
+
"ringmo_framework", "troubleshooter", "mindtorch", "mindchemistry",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
_global_params = {}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _convert_map():
|
|
137
|
+
"""Get convert object map"""
|
|
138
|
+
adapter_convert_map = ms_adapter_registry.convert_map
|
|
139
|
+
return adapter_convert_map if adapter_convert_map else convert_object_map
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def create_slice_obj(start, end, step):
|
|
143
|
+
"""Create slice object"""
|
|
144
|
+
return slice(start, end, step)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def parse_cb(func, parse_method=None):
|
|
148
|
+
"""Implements the function of parse."""
|
|
149
|
+
return Parser(func, parse_method)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def get_attr_from_object(obj, attr_name=None):
|
|
153
|
+
"""
|
|
154
|
+
Get attr from object.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
obj(Object): Instance of class or module.
|
|
158
|
+
attr_name(str): Attribute name to check.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
Object, obj's attr.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
if obj is not None and attr_name is not None and hasattr(obj, attr_name):
|
|
165
|
+
return getattr(obj, attr_name)
|
|
166
|
+
return None
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def check_attr_is_property(obj, attr_name):
|
|
170
|
+
"""
|
|
171
|
+
Check if the attribute is decorated by @property.
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
obj(Object): Instance of a class.
|
|
175
|
+
attr_name(str): Attribute name to check.
|
|
176
|
+
|
|
177
|
+
Returns:
|
|
178
|
+
obj(bool): If the attribute is decorated by @property.
|
|
179
|
+
"""
|
|
180
|
+
logger.debug(f"attr_name:{attr_name}")
|
|
181
|
+
logger.debug(f"obj.__class__.__dict__.keys():{obj.__class__.__dict__.keys()}")
|
|
182
|
+
if attr_name in obj.__class__.__dict__.keys() and isinstance(obj.__class__.__dict__[attr_name], property):
|
|
183
|
+
attr_obj = obj.__class__.__dict__[attr_name]
|
|
184
|
+
if (hasattr(attr_obj, 'fget')) and hasattr(attr_obj.fget, '__code__'):
|
|
185
|
+
logger.debug(f'The attribute {attr_name} is decorated by @property.')
|
|
186
|
+
return True
|
|
187
|
+
return False
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def get_parse_method_of_class(obj, parse_method=None):
|
|
191
|
+
"""
|
|
192
|
+
Get parse method of class.
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
obj(Object): Instance of class.
|
|
196
|
+
parse_method(str): Save the method name. Cell object has default method named 'construct'.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
Function, obj's method.
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
method_name = None
|
|
203
|
+
if parse_method is not None:
|
|
204
|
+
method_name = parse_method
|
|
205
|
+
elif isinstance(obj, nn.Cell):
|
|
206
|
+
if obj._backward_hook:
|
|
207
|
+
method_name = "_backward_hook_construct"
|
|
208
|
+
else:
|
|
209
|
+
method_name = "construct"
|
|
210
|
+
|
|
211
|
+
return get_attr_from_object(obj, method_name)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def get_bprop_method_of_class(obj, parse_method=None):
|
|
215
|
+
"""
|
|
216
|
+
Get bprop method of class.
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
obj (Object): Instance of class.
|
|
220
|
+
parse_method(str): Save the method name. Cell object has default method named 'bprop'.
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
Function, obj's method.
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
if isinstance(obj, nn.Cell):
|
|
227
|
+
method_name = "bprop"
|
|
228
|
+
return get_attr_from_object(obj, method_name)
|
|
229
|
+
return None
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def resolve_symbol(namespace, symbol):
|
|
233
|
+
"""
|
|
234
|
+
Resolve a symbol.
|
|
235
|
+
|
|
236
|
+
Note:
|
|
237
|
+
Can't get function when use closure function. So save the fn on namespace.
|
|
238
|
+
|
|
239
|
+
Args:
|
|
240
|
+
namespace (Object): Symbol's namespace.
|
|
241
|
+
symbol (str): Need resolve symbol.
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
Object, resolve result of symbol.
|
|
245
|
+
"""
|
|
246
|
+
# All exceptions need to be caught in this function
|
|
247
|
+
try:
|
|
248
|
+
resolve_ = namespace[symbol]
|
|
249
|
+
|
|
250
|
+
# The list and dict is not hashable, it can not be key for the map, just return the result
|
|
251
|
+
if isinstance(resolve_, (tuple, list, dict)):
|
|
252
|
+
return resolve_
|
|
253
|
+
if hasattr(resolve_, "__self__") and isinstance(resolve_.__self__, (tuple, list, dict)):
|
|
254
|
+
return resolve_
|
|
255
|
+
if getattr(resolve_, "__hash__") is None:
|
|
256
|
+
return resolve_
|
|
257
|
+
|
|
258
|
+
# If need trope the obj
|
|
259
|
+
convert_map = _convert_map()
|
|
260
|
+
if resolve_ in convert_map:
|
|
261
|
+
resolve_ = convert_map.get(resolve_)
|
|
262
|
+
logger.debug("Convert resolve: %r", resolve_)
|
|
263
|
+
except Exception as e:
|
|
264
|
+
if isinstance(e, NotImplementedError):
|
|
265
|
+
raise e
|
|
266
|
+
resolve_ = mstype._null
|
|
267
|
+
logger.debug("Resolve exception occurred, value: %r", e)
|
|
268
|
+
logger.debug("Resolve type is invalid, namespace: %s, symbol: %s",
|
|
269
|
+
namespace.__str__(), symbol)
|
|
270
|
+
|
|
271
|
+
if isinstance(resolve_, _MindsporeFunctionExecutor):
|
|
272
|
+
logger.debug("Resolve class _MindsporeFunctionExecutor, resolve fn instead.")
|
|
273
|
+
resolve_ = resolve_.fn
|
|
274
|
+
logger.debug(f"Found '{symbol}' in {namespace.__str__()}, resolved: {resolve_} / {type(resolve_)}")
|
|
275
|
+
return resolve_
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def generate_scope(obj):
|
|
279
|
+
"""Generate the scope for every cell object in the network."""
|
|
280
|
+
if isinstance(obj, nn.Cell):
|
|
281
|
+
obj.generate_scope()
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def get_scope_name(obj):
|
|
285
|
+
"""Returns the scope of a cell object in one network."""
|
|
286
|
+
if isinstance(obj, nn.Cell):
|
|
287
|
+
return obj.get_scope()
|
|
288
|
+
return None
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def get_type(obj):
|
|
292
|
+
"""Returns the type string of input object"""
|
|
293
|
+
return type(obj)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def get_object_key(obj):
|
|
297
|
+
"""Return the function key: module + name."""
|
|
298
|
+
obj_key = ""
|
|
299
|
+
if hasattr(obj, "__name__"):
|
|
300
|
+
if hasattr(obj, "cell_init_args"):
|
|
301
|
+
obj_key = "%s_ID" % (str(obj.__class__.__name__) + str(obj.__name__) + obj.cell_init_args)
|
|
302
|
+
obj_id = "%s_ID%d" % (str(obj.__class__.__name__) + str(obj.__name__), id(obj))
|
|
303
|
+
else:
|
|
304
|
+
# `<class 'xxxxxxx'>`
|
|
305
|
+
# -> `xxxxxxx`
|
|
306
|
+
tag = str(obj.__class__)[8:-2]
|
|
307
|
+
if hasattr(obj, "cell_init_args"):
|
|
308
|
+
obj_key = "%s_ID" % (tag + obj.cell_init_args)
|
|
309
|
+
obj_id = "%s_ID%d" % (tag, id(obj))
|
|
310
|
+
logger.debug("obj_key: %s, obj_id: %s", obj_key, obj_id)
|
|
311
|
+
|
|
312
|
+
# Method has same id of different instance
|
|
313
|
+
if isinstance(obj, types.MethodType):
|
|
314
|
+
method_instance = obj.__self__
|
|
315
|
+
instance_id = "%s_ID%d" % (str(method_instance.__class__.__name__), id(method_instance))
|
|
316
|
+
if isinstance(method_instance, (tuple, list, dict)):
|
|
317
|
+
obj_id = instance_id + obj_id
|
|
318
|
+
else:
|
|
319
|
+
obj_id = instance_id + obj_id + str(obj.__hash__())
|
|
320
|
+
return obj_id, obj_key
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def is_class_member_of_self(node):
|
|
324
|
+
"""Check the attr is class member variable."""
|
|
325
|
+
type_ = node.__class__.__name__
|
|
326
|
+
if type_ == "Attribute":
|
|
327
|
+
if not hasattr(node.value, "id"):
|
|
328
|
+
return False
|
|
329
|
+
id_ = node.value.id
|
|
330
|
+
if id_ == "self":
|
|
331
|
+
return True
|
|
332
|
+
return False
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def is_class_member_recursive(node):
|
|
336
|
+
"""Check the attr is class member variable resurcively."""
|
|
337
|
+
type_ = node.__class__.__name__
|
|
338
|
+
if type_ == "Attribute":
|
|
339
|
+
if hasattr(node.value, "value"):
|
|
340
|
+
return is_class_member_recursive(node.value)
|
|
341
|
+
if not hasattr(node.value, "id"):
|
|
342
|
+
return False
|
|
343
|
+
id_ = node.value.id
|
|
344
|
+
if id_ == "self":
|
|
345
|
+
return True
|
|
346
|
+
return False
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def get_obj_id(obj):
|
|
350
|
+
"""Get the obj id."""
|
|
351
|
+
return str(id(obj))
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def is_lambda_function(obj):
|
|
355
|
+
"""Determine whether is a lambda function."""
|
|
356
|
+
if isinstance(obj, types.FunctionType):
|
|
357
|
+
source_code = inspect.getsource(obj)
|
|
358
|
+
return "lambda" in source_code and "<function" in str(obj) and "<lambda>" in str(obj)
|
|
359
|
+
return False
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def get_obj_type(obj):
|
|
363
|
+
"""Get the obj type."""
|
|
364
|
+
logger.debug("Get object type: %r", obj)
|
|
365
|
+
obj_type = RESOLVE_TYPE_INVALID
|
|
366
|
+
if obj is None:
|
|
367
|
+
obj_type = RESOLVE_TYPE_NONE
|
|
368
|
+
elif isinstance(obj, types.FunctionType) or type(obj).__name__ == 'cython_function_or_method':
|
|
369
|
+
obj_type = RESOLVE_TYPE_FUNCTION
|
|
370
|
+
elif isinstance(obj, types.MethodType):
|
|
371
|
+
obj_type = RESOLVE_TYPE_METHOD
|
|
372
|
+
elif isinstance(obj, type):
|
|
373
|
+
obj_type = RESOLVE_TYPE_CLASS_TYPE
|
|
374
|
+
elif isinstance(obj, Namespace):
|
|
375
|
+
obj_type = RESOLVE_TYPE_NAMESPACE_INSTANCE
|
|
376
|
+
elif isinstance(obj, tuple):
|
|
377
|
+
obj_type = RESOLVE_TYPE_TUPLE
|
|
378
|
+
elif isinstance(obj, list):
|
|
379
|
+
obj_type = RESOLVE_TYPE_LIST
|
|
380
|
+
elif _is_class_instance(obj):
|
|
381
|
+
obj_type = RESOLVE_TYPE_CLASS_INSTANCE
|
|
382
|
+
elif _is_numpy_int_number(obj):
|
|
383
|
+
obj_type = RESOLVE_TYPE_NUMPY_INT_NUMBER
|
|
384
|
+
elif _is_numpy_float_number(obj):
|
|
385
|
+
obj_type = RESOLVE_TYPE_NUMPY_FLOAT_NUMBER
|
|
386
|
+
elif _is_numpy_bool_number(obj):
|
|
387
|
+
obj_type = RESOLVE_TYPE_NUMPY_BOOL_NUMBER
|
|
388
|
+
else:
|
|
389
|
+
obj_type = RESOLVE_TYPE_INVALID
|
|
390
|
+
return obj_type
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def check_obj_bool(obj):
|
|
394
|
+
"""Check if the type of the current object is bool."""
|
|
395
|
+
logger.debug("Check if the type of the current object(%r) is bool: %r", obj, bool(obj))
|
|
396
|
+
return bool(obj)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def get_class_instance_type(obj):
|
|
400
|
+
"""Get the class instance detail type."""
|
|
401
|
+
# Check the obj type
|
|
402
|
+
logger.debug("Get the class type(%r)", obj)
|
|
403
|
+
if isinstance(obj, nn.Cell):
|
|
404
|
+
return CLASS_INSTANCE_TYPE_CELL
|
|
405
|
+
if isinstance(obj, ops.Primitive):
|
|
406
|
+
return CLASS_INSTANCE_TYPE_PRIMITIVE
|
|
407
|
+
if isinstance(obj, numpy.ndarray):
|
|
408
|
+
return CLASS_INSTANCE_TYPE_NUMPY_ARRAY
|
|
409
|
+
return CLASS_INSTANCE_TYPE_INVALID
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def _is_ms_class(obj):
|
|
413
|
+
"""Check if obj is ms_class object."""
|
|
414
|
+
return hasattr(obj, '__ms_class__')
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def _is_class_instance(obj):
|
|
418
|
+
"""Confirm the obj is class instance."""
|
|
419
|
+
return isinstance(obj, (nn.Cell, ops.Primitive)) or _is_ms_class(obj) or hasattr(obj, '__parse_method__')
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def _is_numpy_int_number(obj):
|
|
423
|
+
"""Confirm the obj is numpy int number."""
|
|
424
|
+
return isinstance(obj, (numpy.int8, numpy.int16, numpy.int64, numpy.uint8, numpy.uint16, numpy.uint64))
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def _is_numpy_float_number(obj):
|
|
428
|
+
"""Confirm the obj is numpy float number."""
|
|
429
|
+
return isinstance(obj, (numpy.float16, numpy.float32, numpy.float64))
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def _is_numpy_bool_number(obj):
|
|
433
|
+
"""Confirm the obj is numpy bool number."""
|
|
434
|
+
return isinstance(obj, numpy.bool_)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _convert_tuple_to_args_kwargs(params):
|
|
438
|
+
"""Convert tuple to args and kwargs."""
|
|
439
|
+
args = tuple()
|
|
440
|
+
kwargs = dict()
|
|
441
|
+
for param in params:
|
|
442
|
+
if isinstance(param, dict):
|
|
443
|
+
kwargs.update(param)
|
|
444
|
+
else:
|
|
445
|
+
args += (param,)
|
|
446
|
+
return (args, kwargs)
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def is_supported_create_instance_type(cls_type):
|
|
450
|
+
"""Check if cls_type is a supported instance type."""
|
|
451
|
+
return issubclass(cls_type, (nn.Cell, ops.Primitive, ops.GradOperation)) or _is_ms_class(cls_type)
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def create_instance(cls_type, params=None):
|
|
455
|
+
"""Create python instance."""
|
|
456
|
+
if not isinstance(cls_type, type):
|
|
457
|
+
logger.warning(f"create_instance(), cls_type is not a type, cls_type: {cls_type}")
|
|
458
|
+
return None
|
|
459
|
+
|
|
460
|
+
# Check the type, now only support nn.Cell and Primitive.
|
|
461
|
+
obj = None
|
|
462
|
+
if is_supported_create_instance_type(cls_type):
|
|
463
|
+
# Check arguments, only support *args or **kwargs.
|
|
464
|
+
if params is None:
|
|
465
|
+
obj = cls_type()
|
|
466
|
+
elif isinstance(params, tuple):
|
|
467
|
+
args, kwargs = _convert_tuple_to_args_kwargs(params)
|
|
468
|
+
logger.debug(f"create_instance(), args: {args}, kwargs: {kwargs}")
|
|
469
|
+
if args and kwargs:
|
|
470
|
+
obj = cls_type(*args, **kwargs)
|
|
471
|
+
elif args:
|
|
472
|
+
obj = cls_type(*args)
|
|
473
|
+
elif kwargs:
|
|
474
|
+
obj = cls_type(**kwargs)
|
|
475
|
+
# If invalid parameters.
|
|
476
|
+
if obj is None:
|
|
477
|
+
raise ValueError(f"When call 'create_instance', the parameter should be *args or **kwargs, "
|
|
478
|
+
f"but got {params.__class__.__name__}, params: {params}")
|
|
479
|
+
return obj
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def convert_class_to_function(cls_str, cls_obj):
|
|
483
|
+
"""Convert class to function."""
|
|
484
|
+
if issubclass(cls_obj, (Parameter, ops.MultitypeFuncGraph)):
|
|
485
|
+
raise ValueError(f"Failed to compile in GRAPH_MODE because creating {cls_str} instances is not "
|
|
486
|
+
f"supported in 'construct' or @jit decorated function. Try to create {cls_str} "
|
|
487
|
+
f"instances external such as initialized in the method '__init__' before assigning. "
|
|
488
|
+
f"For more details, please refer to "
|
|
489
|
+
f"https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/overview.html \n")
|
|
490
|
+
return convert_class_to_function_map.get(cls_str)
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def python_isinstance(x, cmp_type):
|
|
494
|
+
"""Python isinstance function."""
|
|
495
|
+
# Convert _c_expression tensor to python tensor.
|
|
496
|
+
x = _convert_python_data(x)
|
|
497
|
+
return isinstance(x, cmp_type)
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
def ms_isinstance(x, cmp_type):
|
|
501
|
+
"""Isinstance for ms type."""
|
|
502
|
+
pytype_to_mstype = {
|
|
503
|
+
bool: mstype.Bool,
|
|
504
|
+
int: mstype.Int,
|
|
505
|
+
float: mstype.Float,
|
|
506
|
+
str: mstype.String,
|
|
507
|
+
list: mstype.List,
|
|
508
|
+
tuple: mstype.Tuple,
|
|
509
|
+
dict: mstype.Dict,
|
|
510
|
+
Tensor: mstype.TensorType,
|
|
511
|
+
Parameter: mstype.RefType,
|
|
512
|
+
slice: mstype.Slice,
|
|
513
|
+
}
|
|
514
|
+
if cmp_type not in pytype_to_mstype:
|
|
515
|
+
return False
|
|
516
|
+
if isinstance(x, mstype.Bool) and cmp_type == int:
|
|
517
|
+
return True
|
|
518
|
+
return isinstance(x, pytype_to_mstype.get(cmp_type))
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def is_cell_list(obj):
|
|
522
|
+
"""Check if obj is nn.CellList"""
|
|
523
|
+
return isinstance(obj, nn.CellList)
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def convert_cell_list_to_sequence(obj):
|
|
527
|
+
"""Convert nn.CellList to sequence."""
|
|
528
|
+
if not hasattr(obj, "__cell_as_list__"):
|
|
529
|
+
raise TypeError(f"Obj should be nn.CellList, but got {obj}")
|
|
530
|
+
if not hasattr(obj, "_cells"):
|
|
531
|
+
raise AttributeError(f"nn.CellList is missing _cells property.")
|
|
532
|
+
cells = getattr(obj, "_cells")
|
|
533
|
+
return list(cells.values())
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def get_obj_from_sequence(obj, index):
|
|
537
|
+
"""Implement `tuple_getitem`."""
|
|
538
|
+
if not isinstance(obj, (tuple, list)):
|
|
539
|
+
raise TypeError(f"Should not get item from a object that not sequence type, obj: {obj}")
|
|
540
|
+
# Not check index out of range by self.
|
|
541
|
+
return obj[index]
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def get_module_namespace(obj):
|
|
545
|
+
"""Get the module's namespace."""
|
|
546
|
+
logger.debug("get module namespace, module: %r", obj)
|
|
547
|
+
mod_namespace = None
|
|
548
|
+
if isinstance(obj, types.ModuleType):
|
|
549
|
+
mod_namespace = ModuleNamespace(obj.__name__)
|
|
550
|
+
else:
|
|
551
|
+
logger.warning("Module(%r) is invalid, get namespace failure!", obj)
|
|
552
|
+
return mod_namespace
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def get_class_member_namespace_symbol(obj):
|
|
556
|
+
"""Get obj class member type."""
|
|
557
|
+
logger.debug("get class instance namespace, object: %r", obj)
|
|
558
|
+
class_namespace = ClassMemberNamespace(obj)
|
|
559
|
+
logger.debug("class namespace: %r", class_namespace)
|
|
560
|
+
return class_namespace
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def get_obj_defined_from_obj_type(obj_type):
|
|
564
|
+
"""Get the class defined from object type which is in BuiltInMap."""
|
|
565
|
+
logger.debug("get the object type: %r", obj_type)
|
|
566
|
+
|
|
567
|
+
def func():
|
|
568
|
+
pass
|
|
569
|
+
|
|
570
|
+
obj_type_defined_map = {
|
|
571
|
+
"Tensor": Tensor,
|
|
572
|
+
"RowTensor": RowTensor,
|
|
573
|
+
"COOTensor": COOTensor,
|
|
574
|
+
"CSRTensor": CSRTensor,
|
|
575
|
+
"Parameter": Parameter,
|
|
576
|
+
"String": "",
|
|
577
|
+
"Function": func,
|
|
578
|
+
"Int": int,
|
|
579
|
+
"Float": float,
|
|
580
|
+
"UInt": int,
|
|
581
|
+
"Bool": bool,
|
|
582
|
+
"List": list,
|
|
583
|
+
"Tuple": tuple,
|
|
584
|
+
"Dictionary": dict,
|
|
585
|
+
"NamedTuple": NamedTuple,
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return obj_type_defined_map.get(obj_type)
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def is_class_type(cls):
|
|
592
|
+
"""Check if cls is a class type."""
|
|
593
|
+
return isinstance(cls, type)
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def get_adapter_tensor_attr(name):
|
|
597
|
+
"""Get the method or @property modified function of the class, excluding those inherited from parent class."""
|
|
598
|
+
cls = ms_adapter_registry.tensor
|
|
599
|
+
properties = [key for key, value in vars(cls).items() if isinstance(value, property)]
|
|
600
|
+
if name in properties:
|
|
601
|
+
return getattr(cls, name).fget, True
|
|
602
|
+
methods = [key for key, value in vars(cls).items() if inspect.isfunction(value)]
|
|
603
|
+
if name in methods:
|
|
604
|
+
return getattr(cls, name), False
|
|
605
|
+
return None, False
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def is_adapter_tensor_class(cls):
|
|
609
|
+
"""Check if cls is adapter tensor type."""
|
|
610
|
+
return cls in (Tensor, ms_adapter_registry.tensor)
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
def is_adapter_parameter_class(cls):
|
|
614
|
+
"""Check if cls is adapter parameter type."""
|
|
615
|
+
return cls in (Parameter, ms_adapter_registry.parameter)
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
def get_ms_class_name(cls):
|
|
619
|
+
"""Get the name of the class instance decorated with jit_class."""
|
|
620
|
+
if isinstance(cls, type):
|
|
621
|
+
return cls.__name__
|
|
622
|
+
return cls.__class__.__name__
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
def convert_to_ms_tensor(data):
|
|
626
|
+
"""Convert C++ tensor to mindspore tensor."""
|
|
627
|
+
return Tensor(data)
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
def convert_to_ms_csrtensor(data):
|
|
631
|
+
"""Convert C++ csrtensor to mindspore csrtensor."""
|
|
632
|
+
return CSRTensor(csr_tensor=data)
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def convert_to_ms_cootensor(data):
|
|
636
|
+
"""Convert C++ cootensor to mindspore cootensor."""
|
|
637
|
+
return COOTensor(coo_tensor=data)
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
def convert_to_namedtuple(type_name, key_sequeue, value_sequeue):
|
|
641
|
+
"""Convert C++ namedtuple to python object namedtuple."""
|
|
642
|
+
logger.debug(f"type_name: {type_name}, key_sequeue: {key_sequeue}, value_sequeue: {value_sequeue}")
|
|
643
|
+
return namedtuple(type_name, [*key_sequeue])(*value_sequeue)
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def get_object_description(obj, fname, fline):
|
|
647
|
+
"""Return method or funcition description for error report, include location, class name, etc."""
|
|
648
|
+
if isinstance(obj, types.MethodType):
|
|
649
|
+
obj_cls = obj.__self__.__class__
|
|
650
|
+
class_name = f"{obj_cls.__module__}.{obj_cls.__qualname__}"
|
|
651
|
+
cls_fname = inspect.getfile(obj_cls)
|
|
652
|
+
_, cls_fline = inspect.getsourcelines(obj_cls)
|
|
653
|
+
class_loc = f"{cls_fname}:{cls_fline}"
|
|
654
|
+
return f"bound method '{obj.__name__}' at {fname}:{fline} of <{class_name} at {class_loc} object>"
|
|
655
|
+
if isinstance(obj, types.FunctionType):
|
|
656
|
+
return f"function '{obj.__name__}' at {fname}:{fline}"
|
|
657
|
+
if isinstance(obj, ast.FunctionDef):
|
|
658
|
+
return f"function '{obj.name}' at {fname}:{fline}"
|
|
659
|
+
if isinstance(obj, ast.Attribute):
|
|
660
|
+
return f"attribute "
|
|
661
|
+
return str(obj)
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
def expand_expr_statement(node):
|
|
665
|
+
"""
|
|
666
|
+
Process the expr statement and expand it.
|
|
667
|
+
|
|
668
|
+
Returns:
|
|
669
|
+
tuple, (True, expr.value, x)/(False, None, None).
|
|
670
|
+
"""
|
|
671
|
+
if isinstance(node, ast.Expr):
|
|
672
|
+
expr_value = node.value
|
|
673
|
+
if isinstance(expr_value, ast.Call):
|
|
674
|
+
func = expr_value.func
|
|
675
|
+
if isinstance(func, ast.Attribute) and \
|
|
676
|
+
hasattr(func, "attr") and \
|
|
677
|
+
hasattr(func, "value"):
|
|
678
|
+
method = func.attr
|
|
679
|
+
target = func.value
|
|
680
|
+
if method in parse_expr_statement_white_list:
|
|
681
|
+
logger.debug("Expand expr, target:%s, method:%s", target, method)
|
|
682
|
+
return True, expr_value, target
|
|
683
|
+
if not isinstance(expr_value, ast.Str):
|
|
684
|
+
return True, expr_value
|
|
685
|
+
return (False,)
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def get_ast_namespace_symbol(obj):
|
|
689
|
+
"""Get obj type and namespace and symbol."""
|
|
690
|
+
# Get symbol from object map.
|
|
691
|
+
ops_info = parse_object_map.get(type(obj), SYMBOL_UNDEFINE)
|
|
692
|
+
logger.debug("ops info: %r", ops_info)
|
|
693
|
+
return ops_info
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
def get_operation_symbol(obj):
|
|
697
|
+
"""Get obj operation symbol."""
|
|
698
|
+
ops_symbol = ops_symbol_map.get(type(obj), SYMBOL_UNDEFINE)
|
|
699
|
+
logger.debug("ops symbol: %s", ops_symbol)
|
|
700
|
+
return ops_symbol
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
def get_operation_namespace_symbol(var: str):
|
|
704
|
+
"""Get operation namespace and symbol."""
|
|
705
|
+
ops_info = (trope_ns, var)
|
|
706
|
+
logger.debug("get operation ops info: %r", ops_info)
|
|
707
|
+
return ops_info
|
|
708
|
+
|
|
709
|
+
def get_ast_type(node):
|
|
710
|
+
"""Get the ast type."""
|
|
711
|
+
ast_type = AST_SUB_TYPE_UNKNOWN
|
|
712
|
+
if isinstance(node, ast.And):
|
|
713
|
+
ast_type = AST_SUB_TYPE_AND
|
|
714
|
+
elif isinstance(node, ast.Or):
|
|
715
|
+
ast_type = AST_SUB_TYPE_OR
|
|
716
|
+
elif isinstance(node, ast.Name):
|
|
717
|
+
ast_type = AST_SUB_TYPE_NAME
|
|
718
|
+
elif isinstance(node, ast.Tuple):
|
|
719
|
+
ast_type = AST_SUB_TYPE_TUPLE
|
|
720
|
+
elif isinstance(node, ast.List):
|
|
721
|
+
ast_type = AST_SUB_TYPE_LIST
|
|
722
|
+
elif isinstance(node, ast.Subscript):
|
|
723
|
+
ast_type = AST_SUB_TYPE_SUBSCRIPT
|
|
724
|
+
elif isinstance(node, ast.Starred):
|
|
725
|
+
ast_type = AST_SUB_TYPE_STARRED
|
|
726
|
+
elif isinstance(node, ast.Attribute):
|
|
727
|
+
ast_type = AST_SUB_TYPE_ATTRIBUTE
|
|
728
|
+
elif isinstance(node, ast.Dict):
|
|
729
|
+
ast_type = AST_SUB_TYPE_DICT
|
|
730
|
+
else:
|
|
731
|
+
ast_type = AST_SUB_TYPE_UNKNOWN
|
|
732
|
+
return ast_type
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
def get_node_type(node):
|
|
736
|
+
"""Process an ast node."""
|
|
737
|
+
method_name = f"{node.__class__.__name__}"
|
|
738
|
+
node_type = [method_name]
|
|
739
|
+
# Judge the ast main type.
|
|
740
|
+
if isinstance(node, ast.stmt):
|
|
741
|
+
node_type.append(AST_MAIN_TYPE_STMT)
|
|
742
|
+
elif isinstance(node, (ast.expr, ast.slice)) or node is None:
|
|
743
|
+
# ast.slice and ast.expr should be expr.
|
|
744
|
+
node_type.append(AST_MAIN_TYPE_EXPR)
|
|
745
|
+
else:
|
|
746
|
+
node_type.append(AST_MAIN_TYPE_UNKNOWN)
|
|
747
|
+
return node_type
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
def get_args_default_values(node):
|
|
751
|
+
"""
|
|
752
|
+
Get the args'default values of parse object.
|
|
753
|
+
|
|
754
|
+
Examples:
|
|
755
|
+
- Function:
|
|
756
|
+
func(a, b, *c, d=0, **e)
|
|
757
|
+
- The ast is as below:
|
|
758
|
+
args=arguments(
|
|
759
|
+
args=[arg(a), arg(b)], vararg=arg(c), kwonlyargs=[arg(d)], kw_defaults=[Num(0)], kwarg=arg(e)
|
|
760
|
+
)
|
|
761
|
+
|
|
762
|
+
- Function:
|
|
763
|
+
func(a, b, c=1)
|
|
764
|
+
- The ast is as below:
|
|
765
|
+
args=arguments(
|
|
766
|
+
args=[arg(a), arg(b), arg(c)], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[Num(1)]
|
|
767
|
+
)
|
|
768
|
+
"""
|
|
769
|
+
defaults = [None] * (len(node.args.args) - len(node.args.defaults))
|
|
770
|
+
defaults = defaults + node.args.defaults
|
|
771
|
+
if node.args.vararg:
|
|
772
|
+
defaults.append(None)
|
|
773
|
+
defaults = defaults + node.args.kw_defaults
|
|
774
|
+
if node.args.kwarg:
|
|
775
|
+
defaults.append(None)
|
|
776
|
+
return defaults
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
def get_args(node):
|
|
780
|
+
"""Get the arg of parse object. The order is [args, vararg, kwonlyargs, kwarg]"""
|
|
781
|
+
args = []
|
|
782
|
+
# Process position args.
|
|
783
|
+
for arg in node.args.args:
|
|
784
|
+
args.append(arg)
|
|
785
|
+
# Process vararg: vararg is append after position.
|
|
786
|
+
if node.args.vararg:
|
|
787
|
+
args.append(node.args.vararg)
|
|
788
|
+
# Process kwonlyargs: kwonlyargs is append after vararg.
|
|
789
|
+
if node.args.kwonlyargs:
|
|
790
|
+
for kwonlyarg in node.args.kwonlyargs:
|
|
791
|
+
args.append(kwonlyarg)
|
|
792
|
+
# Process kwarg: kwarg is append after vararg.
|
|
793
|
+
if node.args.kwarg:
|
|
794
|
+
args.append(node.args.kwarg)
|
|
795
|
+
return args
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
def get_arg_spec_and_default_values(func):
|
|
799
|
+
"""Get the full arg specification and the default arg values of a function"""
|
|
800
|
+
arg_spec = inspect.getfullargspec(func)
|
|
801
|
+
defaults = {}
|
|
802
|
+
args_len = len(arg_spec.args)
|
|
803
|
+
if arg_spec.defaults:
|
|
804
|
+
defaults_len = len(arg_spec.defaults)
|
|
805
|
+
for i in range(defaults_len):
|
|
806
|
+
defaults[arg_spec.args[args_len - i - 1]] = arg_spec.defaults[defaults_len - i - 1]
|
|
807
|
+
if arg_spec.kwonlydefaults:
|
|
808
|
+
for k, v in arg_spec.kwonlydefaults.items():
|
|
809
|
+
defaults[k] = v
|
|
810
|
+
return arg_spec, defaults
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
def _convert_stub_tensor(data):
|
|
814
|
+
"""Convert stub tensor output to tensor"""
|
|
815
|
+
if is_stub_tensor(data):
|
|
816
|
+
return data.stub_sync()
|
|
817
|
+
if isinstance(data, tuple):
|
|
818
|
+
# Handle namedtuple since its type is tuple.
|
|
819
|
+
if hasattr(data, "_fields"):
|
|
820
|
+
type_name = data.__class__.__name__
|
|
821
|
+
data_dict = data._asdict()
|
|
822
|
+
fields = data_dict.keys()
|
|
823
|
+
return namedtuple(type_name, fields)(**_convert_stub_tensor(data_dict))
|
|
824
|
+
return tuple(_convert_stub_tensor(x) for x in data)
|
|
825
|
+
if data.__class__ is list:
|
|
826
|
+
# Keep the list object not change.
|
|
827
|
+
for i in range(len(data)):
|
|
828
|
+
data[i] = _convert_stub_tensor(data[i])
|
|
829
|
+
return data
|
|
830
|
+
if data.__class__ is dict:
|
|
831
|
+
# Keep the dict object not change.
|
|
832
|
+
keys = tuple(data.keys())
|
|
833
|
+
for key in keys:
|
|
834
|
+
data[_convert_stub_tensor(key)] = _convert_stub_tensor(data.pop(key))
|
|
835
|
+
return data
|
|
836
|
+
return data
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
def eval_script(exp_str, params):
|
|
840
|
+
"""Evaluate a python expression."""
|
|
841
|
+
if not isinstance(params, tuple):
|
|
842
|
+
raise ValueError(f"eval_script(), params is not a tuple, params: {params}")
|
|
843
|
+
if len(params) != 2:
|
|
844
|
+
raise ValueError(f"eval_script(), params tuple length is wrong, params: {params}")
|
|
845
|
+
|
|
846
|
+
# Eval function parses the expression argument and evaluates it as a python expression.
|
|
847
|
+
global_params = params[0]
|
|
848
|
+
local_params = params[1]
|
|
849
|
+
try:
|
|
850
|
+
local_params = _convert_python_data(local_params)
|
|
851
|
+
res = eval(exp_str, global_params, local_params)
|
|
852
|
+
res = _convert_stub_tensor(res)
|
|
853
|
+
except Exception as e:
|
|
854
|
+
error_info = f"When eval '{exp_str}' by using JIT Fallback feature, an error occurred: " + str(e)
|
|
855
|
+
logger.debug(error_info)
|
|
856
|
+
raise e
|
|
857
|
+
|
|
858
|
+
return res
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
def get_script_id_attrs(script):
|
|
862
|
+
"""Get the ids for the ast of script"""
|
|
863
|
+
ast_tokens = asttokens.ASTTokens(script, parse=True)
|
|
864
|
+
ast_tree = ast_tokens.tree
|
|
865
|
+
ast_str = astunparse.dump(ast_tree)
|
|
866
|
+
ids = re.findall(r"id='(.+?)'", ast_str)
|
|
867
|
+
id_sets = set(ids)
|
|
868
|
+
pattern = r"Attribute\(\s*value.*?id='(.*?)'.*?attr='(.*?)'.*?\)"
|
|
869
|
+
matches = re.findall(pattern, ast_str, re.DOTALL)
|
|
870
|
+
id_attrs = ["{}.{}".format(match[0], match[1]) for match in matches]
|
|
871
|
+
logger.debug(f'id_attrs: {id_attrs}')
|
|
872
|
+
id_attrs_set = set(id_attrs)
|
|
873
|
+
logger.debug(f'id_attrs_set: {id_attrs_set}')
|
|
874
|
+
res = id_sets.union(id_attrs_set)
|
|
875
|
+
logger.debug(f'res: {res}')
|
|
876
|
+
return res
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
def generate_lambda_object(script):
|
|
880
|
+
"""Generate lambda expression object using script"""
|
|
881
|
+
return eval(script, {}, {})
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
def get_global_params():
|
|
885
|
+
"""Get the global parameter."""
|
|
886
|
+
logger.debug(f"get global_dict: {_global_params}")
|
|
887
|
+
return _global_params
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def get_dtype(name: str):
|
|
891
|
+
"""get mstype from name"""
|
|
892
|
+
return get_attr_from_object(mstype, name)
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
def check_attrs(target_object, func_name: str):
|
|
896
|
+
"""Check if attr is overridden."""
|
|
897
|
+
if isinstance(target_object, Tensor):
|
|
898
|
+
return False
|
|
899
|
+
if hasattr(target_object, func_name):
|
|
900
|
+
if not hasattr(target_object.__class__.__base__, func_name):
|
|
901
|
+
if target_object.__class__.__base__ is object:
|
|
902
|
+
return False
|
|
903
|
+
return True
|
|
904
|
+
if getattr(target_object.__class__, func_name) is not getattr(target_object.__class__.__base__, func_name):
|
|
905
|
+
return True
|
|
906
|
+
return False
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
def check_is_subclass(target_object, parent):
|
|
910
|
+
"""Check if target_object is a subclass."""
|
|
911
|
+
if issubclass(target_object.__class__, parent):
|
|
912
|
+
if target_object.__class__ is not parent:
|
|
913
|
+
return True
|
|
914
|
+
return False
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
class ThirdPartyLibraryChecker:
|
|
918
|
+
"""
|
|
919
|
+
Check if a module or function is from third-party libraries.
|
|
920
|
+
|
|
921
|
+
Rules for detecting third-party libraries:
|
|
922
|
+
|
|
923
|
+
1. The mindspore module and its suite are not third-party libraries.
|
|
924
|
+
|
|
925
|
+
2. Python built-in modules and python standard libraries are third-party libraries.
|
|
926
|
+
|
|
927
|
+
3. Modules with module names provided by MS_JIT_IGNORE_MODULES are treated as third-party
|
|
928
|
+
libraries, but those provided by MS_JIT_MODULES are not.
|
|
929
|
+
|
|
930
|
+
4. Third-party libraries have 'site-packages' in their installation path.
|
|
931
|
+
"""
|
|
932
|
+
def __init__(self):
|
|
933
|
+
self.user_workspace_dir = self.get_top_level_module_path(os.getcwd())
|
|
934
|
+
self.python_builtin_dir = os.path.realpath(os.path.dirname(os.__file__))
|
|
935
|
+
|
|
936
|
+
@staticmethod
|
|
937
|
+
def get_jit_modules():
|
|
938
|
+
"""Modules in jit_modules require jit."""
|
|
939
|
+
jit_modules = []
|
|
940
|
+
# Get jit modules from environment variable.
|
|
941
|
+
env_modules = os.getenv('MS_JIT_MODULES')
|
|
942
|
+
if env_modules is not None:
|
|
943
|
+
jit_modules = env_modules.split(',')
|
|
944
|
+
return jit_modules
|
|
945
|
+
|
|
946
|
+
@staticmethod
|
|
947
|
+
def get_jit_ignore_modules():
|
|
948
|
+
"""Modules in jit_ignore_modules do not need jit."""
|
|
949
|
+
jit_ignore_modules = []
|
|
950
|
+
# Get jit ignore modules from environment variable.
|
|
951
|
+
env_modules = os.getenv('MS_JIT_IGNORE_MODULES')
|
|
952
|
+
if env_modules is not None:
|
|
953
|
+
jit_ignore_modules = env_modules.split(',')
|
|
954
|
+
# sys.builtin_module_names do not need jit.
|
|
955
|
+
jit_ignore_modules.extend(sys.builtin_module_names)
|
|
956
|
+
return jit_ignore_modules
|
|
957
|
+
|
|
958
|
+
@staticmethod
|
|
959
|
+
def is_mindspore_related_module(module):
|
|
960
|
+
"""Check if module is mindspore module or its suite."""
|
|
961
|
+
module_leftmost_name = module.__name__.split('.')[0]
|
|
962
|
+
return module_leftmost_name in _modules_from_mindspore
|
|
963
|
+
|
|
964
|
+
def get_top_level_module_path(self, module_path):
|
|
965
|
+
"""Get the path of the top level package of the current working directory."""
|
|
966
|
+
module_abspath = os.path.realpath(module_path)
|
|
967
|
+
upper_path = os.path.realpath(os.path.dirname(module_abspath))
|
|
968
|
+
if module_abspath == upper_path:
|
|
969
|
+
return module_abspath
|
|
970
|
+
# Check whether __init__.py exists in the upper directory.
|
|
971
|
+
init_path = os.path.join(upper_path, '__init__.py')
|
|
972
|
+
# If the path does not exist or is accessed without permission, os.path.isfile returns false.
|
|
973
|
+
if os.path.isfile(init_path):
|
|
974
|
+
module_abspath = self.get_top_level_module_path(upper_path)
|
|
975
|
+
return module_abspath
|
|
976
|
+
|
|
977
|
+
def is_third_party_module(self, module):
|
|
978
|
+
"""Check if module is a third-party library."""
|
|
979
|
+
module_leftmost_name = module.__name__.split('.')[0]
|
|
980
|
+
# Modules in jit_ignore_modules are treated as third-party libraries, such as sys.builtin_module_names.
|
|
981
|
+
jit_ignore_modules = self.get_jit_ignore_modules()
|
|
982
|
+
if module_leftmost_name in jit_ignore_modules:
|
|
983
|
+
logger.debug(f"Found third-party module '{module_leftmost_name}' in jit_ignore_modules.")
|
|
984
|
+
return True
|
|
985
|
+
# Modules in jit_modules require jit and they are considered to be in user workspace.
|
|
986
|
+
jit_modules = self.get_jit_modules()
|
|
987
|
+
if module_leftmost_name in jit_modules:
|
|
988
|
+
logger.debug(f"Found user-defined module '{module_leftmost_name}' in jit_modules.")
|
|
989
|
+
return False
|
|
990
|
+
# A modules without __file__ attribute is considered to be in user workspace.
|
|
991
|
+
if not hasattr(module, '__file__'):
|
|
992
|
+
return False
|
|
993
|
+
module_path = os.path.realpath(module.__file__)
|
|
994
|
+
# Python builtin modules are treated as third-party libraries.
|
|
995
|
+
if module_path.startswith(self.python_builtin_dir):
|
|
996
|
+
logger.debug(f"Found python builtin module '{module.__name__}', which is a third-party module.")
|
|
997
|
+
return True
|
|
998
|
+
# Check if module is under user workspace directory.
|
|
999
|
+
if module_path.startswith(self.user_workspace_dir):
|
|
1000
|
+
logger.debug(f"Found module '{module.__name__}' in user_workspace_dir: {self.user_workspace_dir}")
|
|
1001
|
+
return False
|
|
1002
|
+
# Third-party modules are under site-packages.
|
|
1003
|
+
split_path = module_path.split(os.path.sep)
|
|
1004
|
+
result = "site-packages" in split_path
|
|
1005
|
+
if result:
|
|
1006
|
+
logger.debug(f"Found third-party module '{module.__name__}' in path '{module_path}'")
|
|
1007
|
+
return result
|
|
1008
|
+
|
|
1009
|
+
def get_module_source_location(self, module):
|
|
1010
|
+
"""Get the source location of the module."""
|
|
1011
|
+
if self.is_mindspore_related_module(module):
|
|
1012
|
+
return MODULE_FROM_MINDSPORE
|
|
1013
|
+
if self.is_third_party_module(module):
|
|
1014
|
+
return MODULE_FROM_THIRDPARTY
|
|
1015
|
+
return MODULE_FROM_USER_WORKSPACE
|
|
1016
|
+
|
|
1017
|
+
def is_third_party_module_or_function(self, value):
|
|
1018
|
+
"""Check if value is from a third-party library."""
|
|
1019
|
+
if inspect.ismodule(value):
|
|
1020
|
+
module = value
|
|
1021
|
+
elif (isinstance(value, types.FunctionType) and not hasattr(value, "__jit_function__")) or \
|
|
1022
|
+
(isinstance(value, types.MethodType) and not hasattr(value.__func__, "__jit_function__")):
|
|
1023
|
+
value_hashable = True
|
|
1024
|
+
try:
|
|
1025
|
+
hash(value)
|
|
1026
|
+
except TypeError:
|
|
1027
|
+
value_hashable = False
|
|
1028
|
+
if value_hashable and value in _convert_map():
|
|
1029
|
+
return False
|
|
1030
|
+
module = inspect.getmodule(value)
|
|
1031
|
+
if module is None:
|
|
1032
|
+
return False
|
|
1033
|
+
else:
|
|
1034
|
+
return False
|
|
1035
|
+
return self.get_module_source_location(module) == MODULE_FROM_THIRDPARTY
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
third_party_checker = ThirdPartyLibraryChecker()
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
def is_from_third_party_library(value):
|
|
1042
|
+
"""Check if value is from a third-party library."""
|
|
1043
|
+
return third_party_checker.is_third_party_module_or_function(value)
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
def get_const_abs(obj):
|
|
1047
|
+
"""Get absolute value of const object."""
|
|
1048
|
+
return abs(obj)
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
def get_const_round(obj):
|
|
1052
|
+
"""Get round value of const object."""
|
|
1053
|
+
if isinstance(obj, tuple):
|
|
1054
|
+
val = obj[0]
|
|
1055
|
+
point_num = obj[1]
|
|
1056
|
+
return round(val, point_num)
|
|
1057
|
+
return round(obj)
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
def get_const_len(obj):
|
|
1061
|
+
"""Get the length of const object."""
|
|
1062
|
+
return len(obj)
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
def get_method_info(obj):
|
|
1066
|
+
"""Get the class name of the object from its method."""
|
|
1067
|
+
if not (inspect.ismethod(obj) or 'built-in method' in repr(obj)):
|
|
1068
|
+
return None, None
|
|
1069
|
+
class_name_and_method_name = obj.__qualname__.split('.')
|
|
1070
|
+
return class_name_and_method_name[0], class_name_and_method_name[1]
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
def is_ms_tensor_method(obj):
|
|
1074
|
+
"""Check if the obj is a method of MindSpore Tensor"""
|
|
1075
|
+
if not hasattr(obj, '__name__') or not hasattr(Tensor, obj.__name__):
|
|
1076
|
+
return False
|
|
1077
|
+
fn = inspect.unwrap(obj.__func__ if isinstance(obj, types.MethodType) else obj)
|
|
1078
|
+
return fn == getattr(Tensor, obj.__name__)
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
def can_constant_fold(obj):
|
|
1082
|
+
"""Check if the obj is the function can be constantly folded."""
|
|
1083
|
+
return obj in constant_fold_functions
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
class Parser:
|
|
1087
|
+
"""
|
|
1088
|
+
Parser python code to ast tree.
|
|
1089
|
+
|
|
1090
|
+
Args:
|
|
1091
|
+
fn(FunctionType/MethodType): Need parse object instance.
|
|
1092
|
+
parse_method(ExtendInfoOfParseObj): Extend information for parse the function.
|
|
1093
|
+
ast_cache: Dictionary for caching ast tree.
|
|
1094
|
+
"""
|
|
1095
|
+
ast_cache = {}
|
|
1096
|
+
|
|
1097
|
+
def __init__(self, fn: (types.FunctionType, types.MethodType), parse_method=None) -> None:
|
|
1098
|
+
self.fn = inspect.unwrap(fn.__func__ if isinstance(fn, types.MethodType) else fn)
|
|
1099
|
+
self.parse_method = parse_method
|
|
1100
|
+
self.line_offset = 0
|
|
1101
|
+
self.filename: str = self.fn.__code__.co_filename
|
|
1102
|
+
|
|
1103
|
+
# Used to resolve the function's globals namespace.
|
|
1104
|
+
self.global_namespace = ModuleNamespace(self.fn.__module__)
|
|
1105
|
+
self.global_namespace.dicts[0]["__ms_tensor_func__"] = tensor
|
|
1106
|
+
|
|
1107
|
+
self.function_module = self.fn.__module__
|
|
1108
|
+
# Used to resolve the function's nonlocals.
|
|
1109
|
+
self.closure_namespace = ClosureNamespace(self.fn)
|
|
1110
|
+
self.function_name = self.fn.__qualname__
|
|
1111
|
+
self.lines = []
|
|
1112
|
+
self.col_offset = 0
|
|
1113
|
+
|
|
1114
|
+
@staticmethod
|
|
1115
|
+
def is_unsupported_namespace(value):
|
|
1116
|
+
"""To check if not supported for namespace"""
|
|
1117
|
+
unsupported = isinstance(value, _builtin_function_or_method_type) and value not in _convert_map()
|
|
1118
|
+
logger.debug(f"'{value}' unsupported: {unsupported}.")
|
|
1119
|
+
if unsupported and value in _fallback_unsupported_python_builtin_type:
|
|
1120
|
+
raise TypeError(f"'{value}' is not supported both in JIT Fallback and graph mode.")
|
|
1121
|
+
return unsupported
|
|
1122
|
+
|
|
1123
|
+
@staticmethod
|
|
1124
|
+
def is_unsupported_python_builtin_type(value):
|
|
1125
|
+
"""To check if not supported for builtin type"""
|
|
1126
|
+
unsupported = value in _unsupported_python_builtin_type
|
|
1127
|
+
logger.debug(f"value: '{value}', unsupported builtin type: {unsupported}.")
|
|
1128
|
+
return unsupported
|
|
1129
|
+
|
|
1130
|
+
@staticmethod
|
|
1131
|
+
def get_tensor_class_type(value):
|
|
1132
|
+
"""To check if is class Tensor type"""
|
|
1133
|
+
if value == Tensor:
|
|
1134
|
+
return CLASS_INSTANCE_TYPE_TENSOR
|
|
1135
|
+
if issubclass(value, ms_adapter_registry.tensor):
|
|
1136
|
+
return CLASS_INSTANCE_TYPE_ADAPTER_TENSOR
|
|
1137
|
+
return CLASS_INSTANCE_TYPE_INVALID
|
|
1138
|
+
|
|
1139
|
+
@staticmethod
|
|
1140
|
+
def get_adapter_convert_function(class_object):
|
|
1141
|
+
"""Get convert function for adapter tensor"""
|
|
1142
|
+
class_object_name = class_object.__name__
|
|
1143
|
+
if class_object_name in ms_adapter_registry.convert_adapter_tensor_map:
|
|
1144
|
+
return ms_adapter_registry.convert_adapter_tensor_map[class_object_name]
|
|
1145
|
+
return None
|
|
1146
|
+
|
|
1147
|
+
@staticmethod
|
|
1148
|
+
def is_unsupported_internal_type(value):
|
|
1149
|
+
"""To check if not supported internal type, such as Tensor"""
|
|
1150
|
+
if not inspect.isclass(value):
|
|
1151
|
+
return False
|
|
1152
|
+
if value == Tensor:
|
|
1153
|
+
logger.debug(f"Found unsupported internal type: '{value}'.")
|
|
1154
|
+
return True
|
|
1155
|
+
if ms_adapter_registry.is_registered and issubclass(value, ms_adapter_registry.tensor):
|
|
1156
|
+
return True
|
|
1157
|
+
return False
|
|
1158
|
+
|
|
1159
|
+
@staticmethod
|
|
1160
|
+
def get_convert_object_for_mutable(value):
|
|
1161
|
+
"""Get the convert object for value which don't support to be converted in C++."""
|
|
1162
|
+
# The value may not be supported to do ConvertData such as api 'mutable',
|
|
1163
|
+
# and we get its converted object from python.
|
|
1164
|
+
if inspect.isfunction(value) and value in (mutable,):
|
|
1165
|
+
return _convert_map().get(value)
|
|
1166
|
+
return value
|
|
1167
|
+
|
|
1168
|
+
def get_syntax_support_type(self, value):
|
|
1169
|
+
"""Get syntax support type."""
|
|
1170
|
+
if is_from_third_party_library(value):
|
|
1171
|
+
logger.debug(f"value: '{value}' is from third party library.")
|
|
1172
|
+
return SYNTAX_UNSUPPORTED_NAMESPACE
|
|
1173
|
+
if inspect.isclass(value) or isinstance(value, _builtin_function_or_method_type):
|
|
1174
|
+
if self.is_unsupported_internal_type(value):
|
|
1175
|
+
return SYNTAX_UNSUPPORTED_INTERNAL_TYPE
|
|
1176
|
+
if self.is_unsupported_namespace(value):
|
|
1177
|
+
return SYNTAX_UNSUPPORTED_NAMESPACE
|
|
1178
|
+
if self.is_unsupported_python_builtin_type(value):
|
|
1179
|
+
return SYNTAX_UNSUPPORTED_EXTERNAL_TYPE
|
|
1180
|
+
return SYNTAX_SUPPORTED
|
|
1181
|
+
|
|
1182
|
+
def check_lambda(self, src):
|
|
1183
|
+
"""Check if the lamda expressions is correct."""
|
|
1184
|
+
obj_type = get_obj_type(self.fn)
|
|
1185
|
+
if (obj_type != RESOLVE_TYPE_FUNCTION or src[:4] == "def ") and is_lambda_function(self.fn):
|
|
1186
|
+
logger.debug("fn is lambda: %r", self.fn)
|
|
1187
|
+
raise ValueError("An error occurred while parsing the positional information of the lambda expression. "
|
|
1188
|
+
"Please write the lambda expression on a separate line.\nFor example, "
|
|
1189
|
+
"the code 'def __init__(self, combine_fn=lambda x: x + 1):' rewritten as\n"
|
|
1190
|
+
"'def __init__(self, combine_fn=\nlambda x: x + 1\n):' will solve the problem.")
|
|
1191
|
+
|
|
1192
|
+
def parse(self):
|
|
1193
|
+
"""Parse the function or method."""
|
|
1194
|
+
logger.debug("fn: %r", self.fn)
|
|
1195
|
+
if isinstance(self.fn, (types.FunctionType, types.MethodType)) or \
|
|
1196
|
+
type(self.fn).__name__ == 'cython_function_or_method':
|
|
1197
|
+
attr = 'source'
|
|
1198
|
+
try:
|
|
1199
|
+
source_lines = inspect.getsourcelines(self.fn)
|
|
1200
|
+
if context.get_context('support_binary') and \
|
|
1201
|
+
'/mindspore/' not in self.filename and '\\mindspore\\' not in self.filename and \
|
|
1202
|
+
(not hasattr(self.fn, attr) or getattr(self.fn, attr) != source_lines):
|
|
1203
|
+
if not os.access(self.filename, os.W_OK):
|
|
1204
|
+
raise PermissionError(f"Don't have the write permission on the file {self.filename}.")
|
|
1205
|
+
with open(self.filename, 'a') as f:
|
|
1206
|
+
f.write(f"\n# Set source attribute for function {self.function_name} "
|
|
1207
|
+
f"to support run so or pyc file in Graph Mode."
|
|
1208
|
+
f"\nsetattr({self.function_name}, '{attr}', {source_lines})\n")
|
|
1209
|
+
setattr(self.fn, attr, source_lines)
|
|
1210
|
+
except (OSError, TypeError) as e:
|
|
1211
|
+
if hasattr(self.fn, attr):
|
|
1212
|
+
source_lines = getattr(self.fn, attr)
|
|
1213
|
+
else:
|
|
1214
|
+
if e.__str__() == "could not get source code":
|
|
1215
|
+
raise OSError(f"Mindspore can not compile temporary source code in terminal. "
|
|
1216
|
+
f"Please write source code to a python file and run the file.")
|
|
1217
|
+
raise e
|
|
1218
|
+
self.lines, self.line_offset = source_lines
|
|
1219
|
+
original_src = ''.join(self.lines)
|
|
1220
|
+
hexstr = hashlib.sha256(original_src.encode()).hexdigest()
|
|
1221
|
+
ast_tokens_cache = Parser.ast_cache.get(hexstr)
|
|
1222
|
+
if not ast_tokens_cache:
|
|
1223
|
+
src = dedent(original_src)
|
|
1224
|
+
self.col_offset = \
|
|
1225
|
+
len(original_src.split('\n')[0]) - len(src.split('\n')[0])
|
|
1226
|
+
logger.debug("Get source: %s", src)
|
|
1227
|
+
self.check_lambda(src)
|
|
1228
|
+
try:
|
|
1229
|
+
ast_tokens = asttokens.ASTTokens(src, parse=True)
|
|
1230
|
+
except IndentationError as idt_err:
|
|
1231
|
+
idt_err.filename = self.filename
|
|
1232
|
+
idt_err.lineno = self.line_offset
|
|
1233
|
+
idt_err.msg = f"There are incorrect indentations in definition or comment of function: " \
|
|
1234
|
+
f"'{self.function_name}'."
|
|
1235
|
+
raise idt_err
|
|
1236
|
+
ast_tokens_cache = (ast_tokens, self.col_offset)
|
|
1237
|
+
Parser.ast_cache[hexstr] = ast_tokens_cache
|
|
1238
|
+
else:
|
|
1239
|
+
self.col_offset = ast_tokens_cache[1]
|
|
1240
|
+
return ast_tokens_cache[0], ast_tokens_cache[0].tree
|
|
1241
|
+
|
|
1242
|
+
logger.error("Fn type is invalid")
|
|
1243
|
+
return None, None
|
|
1244
|
+
|
|
1245
|
+
def get_name_from_namespace(self, value):
|
|
1246
|
+
"""Get the name of value from namespace"""
|
|
1247
|
+
try:
|
|
1248
|
+
value_str = value.__name__
|
|
1249
|
+
logger.debug(
|
|
1250
|
+
f"value: {type(value)}, '{value_str}', hasattr(__name__): {hasattr(value, '__name__')}.")
|
|
1251
|
+
except:
|
|
1252
|
+
value_str = str(value)
|
|
1253
|
+
logger.debug(f"value: {type(value)}, '{value_str}'.")
|
|
1254
|
+
return value_str
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
def is_builtin_function_name(self, var):
|
|
1258
|
+
"""Check if the var is builtin_function name."""
|
|
1259
|
+
logger.debug(f"Check if the var'{var}' is builtin function.")
|
|
1260
|
+
builtin_function_names = vars(builtins).keys()
|
|
1261
|
+
if var in builtin_function_names:
|
|
1262
|
+
return True
|
|
1263
|
+
return False
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
def get_namespace_symbol(self, var: str):
|
|
1267
|
+
"""Get mindspore builtin namespace and symbol."""
|
|
1268
|
+
if var in self.closure_namespace:
|
|
1269
|
+
logger.debug(f"Found '{var}' in closure_namespace {self.closure_namespace.__str__()}.")
|
|
1270
|
+
try:
|
|
1271
|
+
value = self.closure_namespace[var]
|
|
1272
|
+
return self.closure_namespace, var, value
|
|
1273
|
+
except UnboundLocalError:
|
|
1274
|
+
return self.closure_namespace, var, None
|
|
1275
|
+
if var in self.global_namespace:
|
|
1276
|
+
logger.debug(f"Found '{var}' in global_namespace {self.global_namespace.__str__()}.")
|
|
1277
|
+
value = self.global_namespace[var]
|
|
1278
|
+
self.get_name_from_namespace(value)
|
|
1279
|
+
# To check if allowed to support.
|
|
1280
|
+
value = self.get_convert_object_for_mutable(value)
|
|
1281
|
+
support_type = self.get_syntax_support_type(value)
|
|
1282
|
+
support_info = self.global_namespace, var, value, support_type
|
|
1283
|
+
return support_info
|
|
1284
|
+
|
|
1285
|
+
logger.debug(f"The name '{var}' is an undefined symbol.")
|
|
1286
|
+
return None, None, None
|
|
1287
|
+
|
|
1288
|
+
def check_third_party_library_side_effect(self, var, attr):
|
|
1289
|
+
"""Check if value is from a third-party library."""
|
|
1290
|
+
logger.debug(f"var '{var}'.")
|
|
1291
|
+
logger.debug(f"attr '{attr}'.")
|
|
1292
|
+
side_effect_attrs = {
|
|
1293
|
+
"numpy": {"load", "save", "savez", "savez_compressed", "loadtxt", "savetxt", "genfromtxt", "fromregex",
|
|
1294
|
+
"fromstring", "tofile", "memmap", "open_memmap", "open", "exists", "abspath", "DataSource",
|
|
1295
|
+
"format"},
|
|
1296
|
+
"pandas": {"read_csv", "to_csv", "read_excel", "to_excel", "read_json", "to_json", "read_html", "to_html",
|
|
1297
|
+
"read_sql", "to_sql", "read_feather", "to_feather", "read_parquet", "to_parquet", "read_pickle",
|
|
1298
|
+
"to_pickle"},
|
|
1299
|
+
"scipy": {"loadmat", "savemat"},
|
|
1300
|
+
"csv": {"reader", "writer"},
|
|
1301
|
+
"json": {"load", "loads", "dump", "dumps"},
|
|
1302
|
+
"pickle": {"load", "loads", "dump", "dumps"},
|
|
1303
|
+
"h5py": {"File", "Group", "Dataset"},
|
|
1304
|
+
"os": {"listdir", "isfile", "exists", "isdir", "mkdir", "remove", "rmdir", "symlink", "rename"},
|
|
1305
|
+
"shutil": {"copy", "copy2", "copytree", "move", "rmtree"},
|
|
1306
|
+
"pathlib": {"Path", "mkdir", "rmdir", "unlink", "rename", "symlink_to"},
|
|
1307
|
+
"glob": {"glob", "iglob"},
|
|
1308
|
+
"zipfile": {"zipfile", "ZipFile", "write", "extractall"},
|
|
1309
|
+
"troubleshooter": {"save", "load"}}
|
|
1310
|
+
if var in self.global_namespace:
|
|
1311
|
+
logger.debug(f"Found '{var}' in global_namespace {self.global_namespace.__str__()}.")
|
|
1312
|
+
value = self.global_namespace[var]
|
|
1313
|
+
value_str = self.get_name_from_namespace(value)
|
|
1314
|
+
value = self.get_convert_object_for_mutable(value)
|
|
1315
|
+
if is_from_third_party_library(value):
|
|
1316
|
+
logger.debug(f"value: '{value}' is from third party library.")
|
|
1317
|
+
# pylint: disable=get-dict-value-exception
|
|
1318
|
+
if value_str in side_effect_attrs and attr in side_effect_attrs[value_str]:
|
|
1319
|
+
return True
|
|
1320
|
+
return False
|
|
1321
|
+
|
|
1322
|
+
def analyze_super(self, class_type_node, subclass_instance):
|
|
1323
|
+
"""Analyze super and return a class instance."""
|
|
1324
|
+
sub_class = type(subclass_instance)
|
|
1325
|
+
if class_type_node is None:
|
|
1326
|
+
return super(sub_class, subclass_instance)
|
|
1327
|
+
if isinstance(class_type_node, ast.Name):
|
|
1328
|
+
class_name = getattr(class_type_node, 'id')
|
|
1329
|
+
elif isinstance(class_type_node, ast.Attribute):
|
|
1330
|
+
class_name = getattr(class_type_node, 'attr')
|
|
1331
|
+
else:
|
|
1332
|
+
raise ValueError(f"The first argument of 'super()' must be a class type, "
|
|
1333
|
+
f"but got {class_type_node.__class__.__name__}.")
|
|
1334
|
+
|
|
1335
|
+
target_father_class = None
|
|
1336
|
+
for class_element in sub_class.mro():
|
|
1337
|
+
if class_element.__name__ == class_name:
|
|
1338
|
+
target_father_class = class_element
|
|
1339
|
+
break
|
|
1340
|
+
if target_father_class is None:
|
|
1341
|
+
raise ValueError(f"The second argument of 'super()' must be 'self', "
|
|
1342
|
+
f"but got {subclass_instance}.")
|
|
1343
|
+
return super(target_father_class, subclass_instance)
|
|
1344
|
+
|
|
1345
|
+
def get_jit_comments(self, start_lineno, end_lineno):
|
|
1346
|
+
"""
|
|
1347
|
+
Get the comments at the location, starting with '# @jit'.
|
|
1348
|
+
|
|
1349
|
+
Args:
|
|
1350
|
+
start_lineno: The start line no.
|
|
1351
|
+
end_lineno: The end line no.
|
|
1352
|
+
|
|
1353
|
+
Returns:
|
|
1354
|
+
list[str], the comment strings.
|
|
1355
|
+
"""
|
|
1356
|
+
comments = []
|
|
1357
|
+
# Ignore if to fetch the whole lines's comments.
|
|
1358
|
+
if start_lineno == 1 and end_lineno == len(self.lines):
|
|
1359
|
+
return comments
|
|
1360
|
+
|
|
1361
|
+
# Add previous line comment.
|
|
1362
|
+
if start_lineno > 1:
|
|
1363
|
+
previous_lineno = start_lineno - 1
|
|
1364
|
+
previous_line = self.lines[previous_lineno - 1]
|
|
1365
|
+
striped_previous_line = previous_line.strip(' \t')
|
|
1366
|
+
result = re.search(r'^#\s*@jit[^\'\"]*?(?=\n|$)', striped_previous_line)
|
|
1367
|
+
if result:
|
|
1368
|
+
comments.append(result.group())
|
|
1369
|
+
|
|
1370
|
+
# Add line ending comments.
|
|
1371
|
+
if start_lineno >= 1:
|
|
1372
|
+
while start_lineno <= end_lineno:
|
|
1373
|
+
line = self.lines[start_lineno - 1]
|
|
1374
|
+
result = re.search(r'#\s*@jit[^\'\"]*?(?=\n|$)', line)
|
|
1375
|
+
if result:
|
|
1376
|
+
comments.append(result.group())
|
|
1377
|
+
start_lineno += 1
|
|
1378
|
+
return comments
|
|
1379
|
+
|
|
1380
|
+
def get_source_code(self, start_lineno, start_colno, end_lineno, end_colno):
|
|
1381
|
+
"""
|
|
1382
|
+
Get the script source at the location.
|
|
1383
|
+
|
|
1384
|
+
Args:
|
|
1385
|
+
start_lineno: The start line no.
|
|
1386
|
+
start_colno: The start column no.
|
|
1387
|
+
end_lineno: The end line no.
|
|
1388
|
+
end_colno: The end column no.
|
|
1389
|
+
|
|
1390
|
+
Returns:
|
|
1391
|
+
str, the source string.
|
|
1392
|
+
"""
|
|
1393
|
+
|
|
1394
|
+
if start_lineno == 0:
|
|
1395
|
+
logger.critical('start_lineno should not be 0')
|
|
1396
|
+
|
|
1397
|
+
first_line = self.lines[start_lineno - 1]
|
|
1398
|
+
if start_lineno == end_lineno:
|
|
1399
|
+
src = first_line[self.col_offset + start_colno:self.col_offset + end_colno]
|
|
1400
|
+
return src
|
|
1401
|
+
|
|
1402
|
+
src = first_line[self.col_offset + start_colno:]
|
|
1403
|
+
while start_lineno < end_lineno - 1:
|
|
1404
|
+
src += self.lines[start_lineno]
|
|
1405
|
+
start_lineno += 1
|
|
1406
|
+
last_line = self.lines[end_lineno - 1]
|
|
1407
|
+
src += last_line[:self.col_offset + end_colno]
|
|
1408
|
+
return src
|
|
1409
|
+
|
|
1410
|
+
def get_location(self, node):
|
|
1411
|
+
"""
|
|
1412
|
+
Get location of node start and end line no.
|
|
1413
|
+
|
|
1414
|
+
Args:
|
|
1415
|
+
node: AST op node or tuple or List. This is a node in the ANF diagram,
|
|
1416
|
+
here is the code location to get this node.
|
|
1417
|
+
|
|
1418
|
+
Returns:
|
|
1419
|
+
List, [fileName, linestart, colstart, lineend, colend].
|
|
1420
|
+
"""
|
|
1421
|
+
res = [self.filename]
|
|
1422
|
+
err_exit = 0
|
|
1423
|
+
if isinstance(node, (list, tuple)):
|
|
1424
|
+
node_size = len(node)
|
|
1425
|
+
if node_size == 0:
|
|
1426
|
+
err_exit = 1
|
|
1427
|
+
else:
|
|
1428
|
+
start_node = node[0]
|
|
1429
|
+
end_node = node[-1]
|
|
1430
|
+
else:
|
|
1431
|
+
start_node = node
|
|
1432
|
+
end_node = node
|
|
1433
|
+
|
|
1434
|
+
if err_exit == 0:
|
|
1435
|
+
if hasattr(start_node, "first_token") and \
|
|
1436
|
+
hasattr(end_node, "last_token"):
|
|
1437
|
+
start_lineno, start_colno = start_node.first_token.start
|
|
1438
|
+
end_lineno, end_colno = end_node.last_token.end
|
|
1439
|
+
expr_src = self.get_source_code(start_lineno, start_colno, end_lineno, end_colno)
|
|
1440
|
+
comments = self.get_jit_comments(start_lineno, end_lineno)
|
|
1441
|
+
start_lineno += self.line_offset - 1
|
|
1442
|
+
start_colno += self.col_offset
|
|
1443
|
+
end_lineno += self.line_offset - 1
|
|
1444
|
+
end_colno += self.col_offset
|
|
1445
|
+
res = res + [start_lineno, start_colno, end_lineno, end_colno, expr_src, comments]
|
|
1446
|
+
else:
|
|
1447
|
+
res = res + [0, 0, 0, 0, '', []]
|
|
1448
|
+
return res
|