mindspore 2.0.0a0__cp39-cp39-win_amd64.whl → 2.0.0rc1__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +4 -2
- mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
- mindspore/_check_jit_forbidden_api.py +102 -0
- mindspore/_checkparam.py +1066 -1001
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +4 -3
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +50 -48
- mindspore/_extends/parallel_compile/akg_compiler/util.py +9 -4
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +4 -4
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +9 -4
- mindspore/_extends/parse/__init__.py +5 -3
- mindspore/_extends/parse/namespace.py +16 -1
- mindspore/_extends/parse/parser.py +107 -22
- mindspore/_extends/parse/resources.py +0 -7
- mindspore/_extends/parse/standard_method.py +885 -413
- mindspore/amp.py +52 -57
- mindspore/boost/boost.py +2 -2
- mindspore/boost/boost_cell_wrapper.py +38 -20
- mindspore/boost/dim_reduce.py +3 -3
- mindspore/boost/group_loss_scale_manager.py +1 -1
- mindspore/common/__init__.py +4 -6
- mindspore/common/_decorator.py +2 -0
- mindspore/common/_register_for_adapter.py +55 -0
- mindspore/common/_stub_tensor.py +201 -0
- mindspore/common/_utils.py +41 -7
- mindspore/common/api.py +215 -141
- mindspore/common/dtype.py +8 -1
- mindspore/common/dump.py +2 -2
- mindspore/common/initializer.py +4 -2
- mindspore/common/jit_config.py +17 -13
- mindspore/common/mutable.py +33 -13
- mindspore/common/parameter.py +23 -21
- mindspore/common/seed.py +8 -24
- mindspore/common/sparse_tensor.py +62 -41
- mindspore/common/tensor.py +852 -1154
- mindspore/communication/__init__.py +2 -2
- mindspore/communication/_comm_helper.py +11 -4
- mindspore/communication/management.py +22 -21
- mindspore/config/op_info.config +501 -1008
- mindspore/context.py +201 -23
- mindspore/dataset/__init__.py +6 -6
- mindspore/dataset/audio/__init__.py +7 -7
- mindspore/dataset/audio/transforms.py +670 -30
- mindspore/dataset/audio/utils.py +47 -4
- mindspore/dataset/audio/validators.py +223 -1
- mindspore/dataset/callback/ds_callback.py +2 -2
- mindspore/dataset/core/config.py +210 -14
- mindspore/dataset/core/validator_helpers.py +2 -2
- mindspore/{parallel/nn/layers.py → dataset/debug/__init__.py} +7 -8
- mindspore/dataset/debug/debug_hook.py +65 -0
- mindspore/dataset/debug/pre_defined_hook.py +67 -0
- mindspore/dataset/engine/__init__.py +7 -3
- mindspore/dataset/engine/cache_client.py +1 -1
- mindspore/dataset/engine/datasets.py +322 -66
- mindspore/dataset/engine/datasets_audio.py +80 -76
- mindspore/dataset/engine/datasets_standard_format.py +51 -38
- mindspore/dataset/engine/datasets_text.py +232 -118
- mindspore/dataset/engine/datasets_user_defined.py +41 -17
- mindspore/dataset/engine/datasets_vision.py +746 -225
- mindspore/dataset/engine/graphdata.py +75 -10
- mindspore/dataset/engine/iterators.py +45 -5
- mindspore/dataset/engine/offload.py +48 -28
- mindspore/dataset/engine/validators.py +117 -8
- mindspore/dataset/text/__init__.py +6 -5
- mindspore/dataset/text/transforms.py +86 -3
- mindspore/dataset/text/utils.py +6 -4
- mindspore/dataset/text/validators.py +25 -0
- mindspore/dataset/transforms/__init__.py +3 -2
- mindspore/dataset/transforms/c_transforms.py +1 -1
- mindspore/dataset/transforms/transforms.py +2 -2
- mindspore/dataset/utils/__init__.py +2 -1
- mindspore/dataset/utils/line_reader.py +121 -0
- mindspore/dataset/vision/__init__.py +2 -3
- mindspore/dataset/vision/c_transforms.py +9 -9
- mindspore/dataset/vision/py_transforms.py +5 -5
- mindspore/dataset/vision/py_transforms_util.py +2 -0
- mindspore/dataset/vision/transforms.py +160 -161
- mindspore/dataset/vision/utils.py +3 -3
- mindspore/experimental/map_parameter.py +38 -26
- mindspore/include/OWNERS +0 -1
- mindspore/include/api/callback/callback.h +9 -13
- mindspore/include/api/callback/ckpt_saver.h +2 -2
- mindspore/include/api/callback/loss_monitor.h +2 -2
- mindspore/include/api/callback/lr_scheduler.h +5 -5
- mindspore/include/api/callback/time_monitor.h +2 -2
- mindspore/include/api/callback/train_accuracy.h +4 -6
- mindspore/include/api/cfg.h +19 -6
- mindspore/include/api/context.h +44 -9
- mindspore/include/api/delegate.h +1 -1
- mindspore/include/api/metrics/accuracy.h +2 -2
- mindspore/include/api/metrics/metrics.h +4 -3
- mindspore/include/api/model.h +9 -4
- mindspore/include/api/model_parallel_runner.h +2 -2
- mindspore/include/api/net.h +12 -11
- mindspore/include/api/serialization.h +19 -3
- mindspore/include/api/types.h +3 -3
- mindspore/include/dataset/constants.h +7 -0
- mindspore/include/dataset/text.h +59 -0
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +1 -1
- mindspore/mindrecord/filereader.py +18 -0
- mindspore/mindrecord/filewriter.py +197 -34
- mindspore/mindrecord/shardreader.py +9 -0
- mindspore/mindrecord/shardwriter.py +1 -1
- mindspore/mindrecord/tools/cifar100_to_mr.py +3 -3
- mindspore/mindrecord/tools/cifar10_to_mr.py +3 -3
- mindspore/mindrecord/tools/csv_to_mr.py +3 -3
- mindspore/mindrecord/tools/imagenet_to_mr.py +16 -11
- mindspore/mindrecord/tools/mnist_to_mr.py +2 -2
- mindspore/mindrecord/tools/tfrecord_to_mr.py +6 -6
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/nn/__init__.py +0 -4
- mindspore/nn/cell.py +204 -132
- mindspore/nn/dynamic_lr.py +1 -1
- mindspore/nn/grad/cell_grad.py +7 -6
- mindspore/nn/layer/__init__.py +5 -4
- mindspore/nn/layer/activation.py +40 -89
- mindspore/nn/layer/basic.py +255 -624
- mindspore/nn/layer/channel_shuffle.py +7 -6
- mindspore/nn/layer/combined.py +1 -1
- mindspore/nn/layer/container.py +41 -4
- mindspore/nn/layer/conv.py +64 -28
- mindspore/nn/layer/dense.py +9 -8
- mindspore/nn/layer/embedding.py +27 -25
- mindspore/nn/layer/image.py +53 -46
- mindspore/nn/layer/math.py +97 -105
- mindspore/nn/layer/normalization.py +117 -86
- mindspore/nn/layer/padding.py +185 -95
- mindspore/nn/layer/pooling.py +817 -414
- mindspore/nn/layer/rnn_cells.py +10 -15
- mindspore/nn/layer/rnns.py +37 -38
- mindspore/nn/layer/thor_layer.py +11 -12
- mindspore/nn/layer/timedistributed.py +5 -5
- mindspore/nn/layer/transformer.py +701 -0
- mindspore/nn/learning_rate_schedule.py +8 -8
- mindspore/nn/loss/__init__.py +5 -4
- mindspore/nn/loss/loss.py +334 -199
- mindspore/nn/optim/ada_grad.py +6 -6
- mindspore/nn/optim/adadelta.py +2 -3
- mindspore/nn/optim/adafactor.py +4 -5
- mindspore/nn/optim/adam.py +126 -62
- mindspore/nn/optim/adamax.py +3 -4
- mindspore/nn/optim/adasum.py +6 -6
- mindspore/nn/optim/asgd.py +2 -2
- mindspore/nn/optim/ftrl.py +67 -38
- mindspore/nn/optim/lamb.py +4 -5
- mindspore/nn/optim/lars.py +2 -2
- mindspore/nn/optim/lazyadam.py +43 -4
- mindspore/nn/optim/momentum.py +6 -5
- mindspore/nn/optim/optimizer.py +3 -1
- mindspore/nn/optim/proximal_ada_grad.py +2 -2
- mindspore/nn/optim/rmsprop.py +1 -1
- mindspore/nn/optim/rprop.py +8 -9
- mindspore/nn/optim/sgd.py +19 -13
- mindspore/nn/optim/thor.py +10 -15
- mindspore/nn/probability/__init__.py +0 -2
- mindspore/nn/probability/bijector/bijector.py +4 -4
- mindspore/nn/probability/bijector/invert.py +1 -1
- mindspore/nn/probability/bijector/softplus.py +2 -2
- mindspore/nn/probability/bnn_layers/dense_variational.py +1 -1
- mindspore/nn/probability/bnn_layers/layer_distribution.py +2 -2
- mindspore/nn/probability/distribution/_utils/utils.py +9 -15
- mindspore/nn/probability/distribution/bernoulli.py +3 -3
- mindspore/nn/probability/distribution/beta.py +1 -1
- mindspore/nn/probability/distribution/categorical.py +5 -7
- mindspore/nn/probability/distribution/cauchy.py +3 -3
- mindspore/nn/probability/distribution/distribution.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +2 -2
- mindspore/nn/probability/distribution/gamma.py +3 -3
- mindspore/nn/probability/distribution/geometric.py +1 -1
- mindspore/nn/probability/distribution/gumbel.py +3 -3
- mindspore/nn/probability/distribution/half_normal.py +15 -11
- mindspore/nn/probability/distribution/laplace.py +16 -13
- mindspore/nn/probability/distribution/logistic.py +2 -2
- mindspore/nn/probability/distribution/normal.py +1 -1
- mindspore/nn/probability/distribution/poisson.py +1 -1
- mindspore/nn/probability/distribution/student_t.py +20 -15
- mindspore/nn/probability/distribution/transformed_distribution.py +4 -4
- mindspore/nn/probability/distribution/uniform.py +2 -2
- mindspore/nn/reinforcement/_tensors_queue.py +3 -3
- mindspore/nn/reinforcement/tensor_array.py +2 -2
- mindspore/nn/sparse/sparse.py +2 -2
- mindspore/nn/wrap/cell_wrapper.py +27 -10
- mindspore/nn/wrap/grad_reducer.py +2 -2
- mindspore/nn/wrap/loss_scale.py +40 -24
- mindspore/numpy/array_creations.py +33 -22
- mindspore/numpy/array_ops.py +35 -30
- mindspore/numpy/logic_ops.py +6 -27
- mindspore/numpy/math_ops.py +22 -19
- mindspore/numpy/utils.py +1 -1
- mindspore/numpy/utils_const.py +108 -58
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/_constants.py +0 -6
- mindspore/ops/_grad/__init__.py +2 -1
- mindspore/ops/_grad/grad_array_ops.py +86 -117
- mindspore/ops/_grad/grad_base.py +23 -1
- mindspore/ops/_grad/grad_clip_ops.py +2 -3
- mindspore/ops/_grad/grad_comm_ops.py +34 -24
- mindspore/ops/_grad/grad_implementations.py +9 -45
- mindspore/ops/_grad/grad_inner_ops.py +47 -4
- mindspore/ops/_grad/grad_math_ops.py +142 -117
- mindspore/ops/_grad/grad_nn_ops.py +71 -165
- mindspore/ops/_grad/grad_sequence_ops.py +296 -0
- mindspore/ops/_grad/grad_sparse.py +7 -6
- mindspore/ops/_grad_experimental/__init__.py +1 -0
- mindspore/ops/_grad_experimental/grad_array_ops.py +150 -15
- mindspore/ops/_grad_experimental/grad_image_ops.py +16 -7
- mindspore/ops/_grad_experimental/grad_inner_ops.py +1 -22
- mindspore/ops/_grad_experimental/grad_linalg_ops.py +4 -11
- mindspore/ops/_grad_experimental/grad_math_ops.py +210 -89
- mindspore/ops/_grad_experimental/grad_nn_ops.py +26 -22
- mindspore/ops/_grad_experimental/grad_scalar_ops.py +112 -0
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +49 -8
- mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +4 -4
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +3 -3
- mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/correction_mul.py +2 -2
- mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +1 -5
- mindspore/ops/_op_impl/_custom_op/dsd_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/img2col_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +2 -2
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +2 -2
- mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +0 -4
- mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +1 -1
- mindspore/ops/_op_impl/aicpu/__init__.py +236 -4
- mindspore/ops/_op_impl/aicpu/abs.py +36 -0
- mindspore/ops/_op_impl/aicpu/{adaptive_avg_pool_2d_v1.py → adaptive_avg_pool_2d.py} +6 -5
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/add.py +43 -0
- mindspore/ops/_op_impl/aicpu/addcdiv.py +0 -32
- mindspore/ops/_op_impl/aicpu/addcmul.py +0 -84
- mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -43
- mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
- mindspore/{compression/common/__init__.py → ops/_op_impl/aicpu/bessel_i0.py} +15 -8
- mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
- mindspore/ops/_op_impl/aicpu/conj.py +11 -0
- mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +0 -3
- 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/{adaptive_avg_pool_2d_grad_v1.py → digamma.py} +7 -9
- mindspore/ops/_op_impl/aicpu/flatten.py +1 -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_max_pool3d_with_fixed_ksize.py +1 -1
- mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -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/index_put.py +50 -0
- mindspore/ops/_op_impl/aicpu/less.py +41 -0
- mindspore/{nn/probability/infer/variational/__init__.py → ops/_op_impl/aicpu/lgamma.py} +16 -10
- mindspore/ops/_op_impl/aicpu/mirror_pad.py +0 -4
- mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +0 -4
- mindspore/ops/_op_impl/aicpu/mul.py +3 -1
- mindspore/ops/_op_impl/aicpu/multinomial.py +14 -6
- mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
- mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
- mindspore/ops/_op_impl/aicpu/ones_like.py +0 -2
- mindspore/ops/_op_impl/aicpu/polar.py +32 -0
- mindspore/ops/_op_impl/aicpu/polygamma.py +34 -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_tensor_to_sparse.py +73 -0
- mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
- mindspore/ops/_op_impl/aicpu/resize_bicubic.py +2 -8
- mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +1 -1
- 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/scatter_elements.py +4 -0
- mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +2 -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/smooth_l1_loss.py +35 -0
- mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
- mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +0 -24
- mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice.py +4 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +6 -0
- mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
- mindspore/ops/_op_impl/aicpu/trans_data.py +1 -0
- mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
- mindspore/ops/_op_impl/aicpu/uniform.py +34 -0
- mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +1 -0
- mindspore/ops/_op_impl/aicpu/unique_consecutive.py +10 -2
- mindspore/ops/_op_impl/cpu/dynamic_shape.py +5 -1
- mindspore/ops/_op_impl/cpu/sparse_slice.py +4 -0
- mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +6 -0
- mindspore/ops/_op_impl/cpu/tensor_shape.py +5 -1
- mindspore/ops/_op_impl/tbe/__init__.py +27 -611
- mindspore/ops/_op_impl/tbe/assign_add_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/atomic_addr_clean.py +1 -1
- mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +1 -1
- mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/batch_to_space.py +1 -1
- mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +1 -1
- mindspore/ops/_op_impl/tbe/bn_infer_grad.py +4 -2
- mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -1
- mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -1
- mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +6 -4
- mindspore/ops/_op_impl/tbe/cast.py +0 -2
- mindspore/ops/_op_impl/tbe/cast_ds.py +3 -3
- mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +2 -2
- mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +1 -1
- mindspore/ops/_op_impl/tbe/gather_nd.py +1 -0
- mindspore/ops/_op_impl/tbe/{index_add.py → inplace_index_add.py} +3 -6
- mindspore/ops/_op_impl/tbe/matmul_ds.py +2 -0
- mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +35 -0
- mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +35 -0
- mindspore/ops/_op_impl/tbe/scatter_mul.py +2 -0
- mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -2
- mindspore/ops/_op_impl/tbe/space_to_batch.py +1 -1
- mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +1 -1
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +15 -5
- mindspore/ops/_register_for_op.py +1 -0
- mindspore/ops/_utils/__init__.py +1 -2
- mindspore/ops/_utils/utils.py +19 -40
- mindspore/ops/_vmap/vmap_array_ops.py +116 -38
- mindspore/ops/_vmap/vmap_base.py +16 -9
- mindspore/ops/_vmap/vmap_convolution_ops.py +7 -10
- mindspore/ops/_vmap/vmap_grad_math_ops.py +4 -4
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +7 -5
- mindspore/ops/_vmap/vmap_image_ops.py +12 -5
- mindspore/ops/_vmap/vmap_math_ops.py +46 -5
- mindspore/ops/_vmap/vmap_nn_ops.py +15 -21
- mindspore/ops/_vmap/vmap_random_ops.py +1 -1
- mindspore/ops/bprop_mindir/AdaptiveAvgPool2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/AdaptiveMaxPool2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/AvgPool3D_bprop.mindir +150 -0
- mindspore/ops/bprop_mindir/AvgPool_bprop.mindir +66 -0
- mindspore/ops/bprop_mindir/BCEWithLogitsLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BatchNormGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BiasAddGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BinaryCrossEntropy_bprop.mindir +33 -0
- mindspore/ops/bprop_mindir/BroadcastTo_bprop.mindir +220 -106
- mindspore/ops/bprop_mindir/CTCLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Conv2DBackpropFilter_bprop.mindir +240 -0
- mindspore/ops/bprop_mindir/Conv2DBackpropInput_bprop.mindir +247 -0
- mindspore/ops/bprop_mindir/Conv2DTranspose_bprop.mindir +247 -0
- mindspore/ops/bprop_mindir/Conv3DTranspose_bprop.mindir +315 -0
- mindspore/ops/bprop_mindir/Conv3D_bprop.mindir +278 -0
- mindspore/ops/bprop_mindir/DeformableOffsets_bprop.mindir +58 -0
- mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +138 -0
- mindspore/ops/bprop_mindir/Dropout2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Dropout3D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DropoutDoMask_bprop.mindir +22 -23
- mindspore/ops/bprop_mindir/DropoutGenMask_bprop.mindir +16 -17
- mindspore/ops/bprop_mindir/DropoutGrad_bprop.mindir +27 -0
- mindspore/ops/bprop_mindir/Dropout_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DynamicGRUV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DynamicRNN_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Elu_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ExpandDims_bprop.mindir +39 -41
- mindspore/ops/bprop_mindir/FastGeLU_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Flatten_bprop.mindir +41 -43
- mindspore/ops/bprop_mindir/GatherNd_bprop.mindir +51 -57
- mindspore/ops/bprop_mindir/Gather_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/HSigmoid_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/HSwish_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/InstanceNorm_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/KLDivLoss_bprop.mindir +126 -0
- mindspore/ops/bprop_mindir/L2Loss_bprop.mindir +15 -0
- mindspore/ops/bprop_mindir/L2Normalize_bprop.mindir +30 -0
- mindspore/ops/bprop_mindir/LRN_bprop.mindir +43 -0
- mindspore/ops/bprop_mindir/LayerNormGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/LogSoftmax_bprop.mindir +23 -0
- mindspore/ops/bprop_mindir/MaxPool3DGradGrad_bprop.mindir +74 -0
- mindspore/ops/bprop_mindir/MaxPool3DGrad_bprop.mindir +74 -0
- mindspore/ops/bprop_mindir/MaxPool3D_bprop.mindir +75 -0
- mindspore/ops/bprop_mindir/MaxPoolGradGrad_bprop.mindir +65 -0
- mindspore/ops/bprop_mindir/MaxPoolWithArgmax_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/MirrorPad_bprop.mindir +27 -0
- mindspore/ops/bprop_mindir/Mish_bprop.mindir +35 -0
- mindspore/ops/bprop_mindir/MulNoNan_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/NLLLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/OneHot_bprop.mindir +24 -25
- mindspore/ops/bprop_mindir/PReLU_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Pad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Padding_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/RNNTLoss_bprop.mindir +29 -0
- mindspore/ops/bprop_mindir/ROIAlign_bprop.mindir +82 -0
- mindspore/ops/bprop_mindir/ReLU6_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/ReLUV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ReluGrad_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/Reshape_bprop.mindir +53 -53
- mindspore/ops/bprop_mindir/ResizeBilinear_bprop.mindir +29 -0
- mindspore/ops/bprop_mindir/ResizeNearestNeighbor_bprop.mindir +77 -85
- mindspore/ops/bprop_mindir/SeLU_bprop.mindir +21 -0
- mindspore/ops/bprop_mindir/SigmoidCrossEntropyWithLogits_bprop.mindir +21 -0
- mindspore/ops/bprop_mindir/SigmoidGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Sigmoid_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/SmoothL1Loss_bprop.mindir +36 -0
- mindspore/ops/bprop_mindir/SoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Softplus_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Softsign_bprop.mindir +33 -0
- mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Squeeze_bprop.mindir +37 -39
- mindspore/ops/bprop_mindir/StridedSlice_bprop.mindir +70 -72
- mindspore/ops/bprop_mindir/TanhGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Tanh_bprop.mindir +66 -0
- mindspore/ops/bprop_mindir/Tile_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TopK_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +17 -17
- mindspore/ops/bprop_mindir/UpsampleNearest3D_bprop.mindir +32 -0
- mindspore/ops/bprop_mindir/UpsampleTrilinear3D_bprop.mindir +38 -0
- mindspore/ops/bprop_mindir/generate_mindir.py +2 -0
- mindspore/ops/composite/__init__.py +7 -8
- mindspore/ops/composite/base.py +101 -47
- mindspore/ops/composite/math_ops.py +188 -158
- mindspore/ops/composite/multitype_ops/_compile_utils.py +415 -170
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +142 -87
- mindspore/ops/composite/multitype_ops/add_impl.py +6 -1
- mindspore/ops/composite/multitype_ops/div_impl.py +2 -3
- mindspore/ops/composite/multitype_ops/getitem_impl.py +31 -3
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/greater_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/in_impl.py +9 -0
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/less_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/mul_impl.py +21 -5
- mindspore/ops/composite/multitype_ops/not_in_impl.py +9 -0
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -4
- mindspore/ops/composite/multitype_ops/setitem_impl.py +21 -3
- mindspore/ops/composite/multitype_ops/sub_impl.py +1 -1
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +35 -4
- mindspore/ops/function/__init__.py +152 -8
- mindspore/ops/function/array_func.py +2555 -674
- mindspore/ops/function/clip_func.py +209 -13
- mindspore/ops/function/debug_func.py +2 -2
- mindspore/ops/function/grad/__init__.py +2 -1
- mindspore/ops/function/grad/grad_func.py +147 -62
- mindspore/ops/function/image_func.py +54 -38
- mindspore/ops/function/linalg_func.py +167 -16
- mindspore/ops/function/math_func.py +4849 -1492
- mindspore/ops/function/nn_func.py +2573 -988
- mindspore/ops/function/other_func.py +115 -0
- mindspore/ops/function/parameter_func.py +3 -3
- mindspore/ops/function/random_func.py +790 -73
- mindspore/ops/function/sparse_func.py +98 -78
- mindspore/ops/function/sparse_unary_func.py +54 -53
- mindspore/ops/function/spectral_func.py +27 -24
- mindspore/ops/function/vmap_func.py +22 -2
- mindspore/ops/functional.py +97 -37
- mindspore/ops/op_info_register.py +70 -28
- mindspore/ops/operations/__init__.py +47 -14
- mindspore/ops/operations/_csr_ops.py +7 -7
- mindspore/ops/operations/_embedding_cache_ops.py +5 -5
- mindspore/ops/operations/_grad_ops.py +276 -187
- mindspore/ops/operations/_inner_ops.py +319 -113
- mindspore/ops/operations/_ms_kernel.py +10 -8
- mindspore/ops/operations/_ocr_ops.py +9 -9
- mindspore/ops/operations/_opaque_predicate_registry.py +4 -0
- mindspore/ops/operations/_quant_ops.py +137 -102
- mindspore/ops/operations/_rl_inner_ops.py +121 -60
- mindspore/ops/operations/_scalar_ops.py +466 -0
- mindspore/ops/operations/_sequence_ops.py +1004 -2
- mindspore/ops/operations/_tensor_array.py +10 -11
- mindspore/ops/operations/_thor_ops.py +1 -1
- mindspore/ops/operations/array_ops.py +801 -466
- mindspore/ops/operations/comm_ops.py +51 -49
- mindspore/ops/operations/control_ops.py +2 -2
- mindspore/ops/operations/custom_ops.py +123 -44
- mindspore/ops/operations/debug_ops.py +24 -24
- mindspore/ops/operations/image_ops.py +240 -153
- mindspore/ops/operations/inner_ops.py +34 -50
- mindspore/ops/operations/linalg_ops.py +31 -9
- mindspore/ops/operations/math_ops.py +988 -757
- mindspore/ops/operations/nn_ops.py +965 -819
- mindspore/ops/operations/other_ops.py +51 -40
- mindspore/ops/operations/random_ops.py +204 -122
- mindspore/ops/operations/rl_ops.py +8 -9
- mindspore/ops/operations/sparse_ops.py +254 -93
- mindspore/ops/operations/spectral_ops.py +35 -3
- mindspore/ops/primitive.py +111 -9
- mindspore/parallel/_auto_parallel_context.py +189 -83
- mindspore/parallel/_offload_context.py +185 -0
- mindspore/parallel/_parallel_serialization.py +99 -7
- mindspore/parallel/_ps_context.py +9 -5
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +7 -1
- mindspore/{nn/transformer → parallel/_transformer}/__init__.py +6 -6
- mindspore/{nn/transformer → parallel/_transformer}/layers.py +6 -37
- mindspore/{nn/transformer → parallel/_transformer}/loss.py +4 -7
- mindspore/{nn/transformer → parallel/_transformer}/moe.py +20 -16
- mindspore/{nn/transformer → parallel/_transformer}/op_parallel_config.py +3 -3
- mindspore/{nn/transformer → parallel/_transformer}/transformer.py +48 -111
- mindspore/parallel/_utils.py +1 -2
- mindspore/parallel/algo_parameter_config.py +1 -1
- mindspore/parallel/checkpoint_transform.py +37 -34
- mindspore/parallel/shard.py +17 -18
- mindspore/profiler/common/validator/validate_path.py +2 -2
- mindspore/profiler/envprofiling.py +69 -47
- mindspore/profiler/parser/ascend_timeline_generator.py +49 -42
- mindspore/profiler/parser/base_timeline_generator.py +49 -56
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +98 -78
- mindspore/profiler/parser/hwts_log_parser.py +1 -1
- mindspore/profiler/parser/integrator.py +15 -14
- mindspore/profiler/parser/minddata_analyzer.py +2 -2
- mindspore/profiler/parser/msadvisor_analyzer.py +12 -25
- mindspore/profiler/parser/msadvisor_parser.py +2 -4
- mindspore/profiler/parser/optime_parser.py +17 -18
- mindspore/profiler/parser/profiler_info.py +2 -1
- mindspore/profiler/profiling.py +218 -186
- mindspore/rewrite/__init__.py +3 -1
- mindspore/rewrite/api/node.py +1 -114
- mindspore/rewrite/api/node_type.py +3 -0
- mindspore/rewrite/api/pattern_engine.py +31 -1
- mindspore/rewrite/api/scoped_value.py +4 -4
- mindspore/rewrite/api/symbol_tree.py +3 -78
- mindspore/rewrite/api/tree_node_helper.py +1 -1
- mindspore/rewrite/ast_creator_register.py +1 -0
- mindspore/rewrite/ast_helpers/__init__.py +2 -2
- mindspore/rewrite/ast_helpers/ast_creator.py +1 -2
- mindspore/rewrite/ast_helpers/ast_finder.py +65 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +11 -3
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +18 -2
- mindspore/rewrite/namespace.py +0 -2
- mindspore/rewrite/node.py +157 -11
- mindspore/rewrite/parsers/assign_parser.py +231 -53
- mindspore/rewrite/parsers/class_def_parser.py +187 -109
- mindspore/rewrite/parsers/for_parser.py +24 -14
- mindspore/rewrite/parsers/function_def_parser.py +21 -4
- mindspore/rewrite/parsers/if_parser.py +6 -2
- mindspore/rewrite/sparsify/__init__.py +0 -0
- mindspore/rewrite/sparsify/sparse_transformer.py +448 -0
- mindspore/rewrite/sparsify/sparsify.py +109 -0
- mindspore/rewrite/sparsify/utils.py +173 -0
- mindspore/rewrite/symbol_tree.py +256 -133
- mindspore/rewrite/symbol_tree_builder.py +38 -1
- mindspore/run_check/_check_version.py +69 -63
- mindspore/run_check/run_check.py +2 -1
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +1 -1
- mindspore/train/_utils.py +28 -5
- mindspore/train/amp.py +273 -102
- mindspore/train/callback/_backup_and_restore.py +5 -5
- mindspore/train/callback/_callback.py +2 -2
- mindspore/train/callback/_checkpoint.py +3 -3
- mindspore/train/callback/_early_stop.py +3 -3
- mindspore/train/callback/_lambda_callback.py +2 -2
- mindspore/train/callback/_landscape.py +29 -31
- mindspore/train/callback/_loss_monitor.py +3 -3
- mindspore/train/callback/_on_request_exit.py +3 -3
- mindspore/train/callback/_reduce_lr_on_plateau.py +4 -4
- mindspore/train/callback/_summary_collector.py +23 -16
- mindspore/train/callback/_time_monitor.py +3 -3
- mindspore/train/checkpoint_pb2.py +68 -8
- mindspore/train/data_sink.py +15 -3
- mindspore/train/dataset_helper.py +10 -15
- mindspore/train/loss_scale_manager.py +8 -11
- mindspore/train/metrics/__init__.py +1 -1
- mindspore/train/metrics/bleu_score.py +1 -1
- mindspore/train/metrics/confusion_matrix.py +1 -1
- mindspore/train/metrics/cosine_similarity.py +1 -1
- mindspore/train/metrics/dice.py +2 -2
- mindspore/train/metrics/fbeta.py +1 -1
- mindspore/train/metrics/hausdorff_distance.py +4 -3
- mindspore/train/metrics/mean_surface_distance.py +2 -2
- mindspore/train/metrics/occlusion_sensitivity.py +1 -1
- mindspore/train/metrics/perplexity.py +1 -1
- mindspore/train/metrics/precision.py +1 -1
- mindspore/train/metrics/recall.py +1 -1
- mindspore/train/metrics/roc.py +2 -2
- mindspore/train/metrics/root_mean_square_surface_distance.py +2 -2
- mindspore/train/mind_ir_pb2.py +116 -37
- mindspore/train/model.py +45 -28
- mindspore/train/serialization.py +295 -188
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/train/summary/summary_record.py +43 -13
- mindspore/train/train_thor/convert_utils.py +2 -2
- mindspore/train/train_thor/dataset_helper.py +3 -3
- mindspore/turbojpeg.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/METADATA +3 -2
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/RECORD +610 -541
- mindspore/compression/__init__.py +0 -19
- mindspore/compression/common/constant.py +0 -124
- mindspore/compression/export/__init__.py +0 -19
- mindspore/compression/export/quant_export.py +0 -515
- mindspore/compression/quant/__init__.py +0 -28
- mindspore/compression/quant/qat.py +0 -634
- mindspore/compression/quant/quant_utils.py +0 -462
- mindspore/compression/quant/quantizer.py +0 -68
- mindspore/nn/layer/quant.py +0 -1868
- mindspore/nn/layer/rnn_utils.py +0 -90
- mindspore/nn/probability/dpn/__init__.py +0 -22
- mindspore/nn/probability/dpn/vae/__init__.py +0 -25
- mindspore/nn/probability/dpn/vae/cvae.py +0 -140
- mindspore/nn/probability/dpn/vae/vae.py +0 -124
- mindspore/nn/probability/infer/__init__.py +0 -22
- mindspore/nn/probability/infer/variational/elbo.py +0 -70
- mindspore/nn/probability/infer/variational/svi.py +0 -84
- mindspore/nn/probability/toolbox/__init__.py +0 -22
- mindspore/nn/probability/toolbox/anomaly_detection.py +0 -99
- mindspore/nn/probability/toolbox/uncertainty_evaluation.py +0 -364
- mindspore/nn/probability/transforms/__init__.py +0 -22
- mindspore/nn/probability/transforms/transform_bnn.py +0 -262
- mindspore/nn/probability/zhusuan/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/framework/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/framework/bn.py +0 -95
- mindspore/nn/probability/zhusuan/variational/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/variational/elbo.py +0 -46
- mindspore/ops/_op_impl/aicpu/parallel_concat.py +0 -42
- mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
- mindspore/ops/bprop_mindir/AssignAdd_bprop.mindir +0 -19
- mindspore/ops/bprop_mindir/Cast_bprop.mindir +0 -19
- mindspore/ops/bprop_mindir/LogicalOr_bprop.mindir +0 -19
- mindspore/ops/bprop_mindir/MatMul_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ReLU_bprop.mindir +0 -17
- mindspore/ops/bprop_mindir/Transpose_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/UpdateState_bprop.mindir +0 -15
- mindspore/ops/composite/array_ops.py +0 -241
- mindspore/ops/composite/clip_ops.py +0 -134
- mindspore/ops/composite/random_ops.py +0 -426
- mindspore/ops/composite/vmap_ops.py +0 -38
- mindspore/parallel/nn/__init__.py +0 -42
- mindspore/parallel/nn/loss.py +0 -22
- mindspore/parallel/nn/moe.py +0 -21
- mindspore/parallel/nn/op_parallel_config.py +0 -22
- mindspore/parallel/nn/transformer.py +0 -31
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/entry_points.txt +0 -0
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
# Copyright 2020-2022 Huawei Technologies Co., Ltd
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
# ============================================================================
|
|
15
|
-
"""
|
|
16
|
-
Quantization utils.
|
|
17
|
-
|
|
18
|
-
Note: This is an experimental interface that is subject to change and/or deletion.
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
from __future__ import absolute_import
|
|
22
|
-
import numpy as np
|
|
23
|
-
from mindspore._checkparam import Validator
|
|
24
|
-
from mindspore import log as logger
|
|
25
|
-
from ... import nn
|
|
26
|
-
|
|
27
|
-
__all__ = ["load_nonquant_param_into_quant_net", "query_quant_layers"]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def cal_quantization_params(input_min,
|
|
31
|
-
input_max,
|
|
32
|
-
quant_min,
|
|
33
|
-
quant_max,
|
|
34
|
-
data_type,
|
|
35
|
-
symmetric=False):
|
|
36
|
-
r"""
|
|
37
|
-
Calculate quantization params for scale and zero point.
|
|
38
|
-
|
|
39
|
-
Args:
|
|
40
|
-
input_min (numpy.ndarray): The dimension of channel or 1.
|
|
41
|
-
input_max (numpy.ndarray): The dimension of channel or 1.
|
|
42
|
-
quant_min (int): The minimum quantization integer.
|
|
43
|
-
quant_max (int): The maximum quantization integer.
|
|
44
|
-
data_type (numpy type) : Can be numpy int8, numpy uint8.
|
|
45
|
-
symmetric (bool): Whether the quantization algorithm is symmetric or not. Default: False.
|
|
46
|
-
|
|
47
|
-
Returns:
|
|
48
|
-
scale (numpy.ndarray): quantization param.
|
|
49
|
-
zero point (numpy.ndarray): quantization param.
|
|
50
|
-
"""
|
|
51
|
-
if quant_min == quant_max:
|
|
52
|
-
raise ValueError("quant_max is equal to quant_min which will lead to divide zero error.")
|
|
53
|
-
|
|
54
|
-
input_max = np.maximum(0.0, input_max)
|
|
55
|
-
input_min = np.minimum(0.0, input_min)
|
|
56
|
-
|
|
57
|
-
if input_min.shape != input_max.shape:
|
|
58
|
-
raise ValueError("input min shape should be equal to input max.")
|
|
59
|
-
if len(input_min.shape) > 1:
|
|
60
|
-
raise ValueError("input min and max shape should be one dim.")
|
|
61
|
-
if (input_min > input_max).all():
|
|
62
|
-
raise ValueError("input_min min should be less than input max.")
|
|
63
|
-
if (input_max == input_min).all():
|
|
64
|
-
return np.ones(input_min.shape), np.zeros(input_min.shape)
|
|
65
|
-
|
|
66
|
-
# calculate scale
|
|
67
|
-
if symmetric:
|
|
68
|
-
input_max = np.maximum(-input_min, input_max)
|
|
69
|
-
input_min = -input_max
|
|
70
|
-
scale = (input_max - input_min) / (quant_max - quant_min)
|
|
71
|
-
|
|
72
|
-
# calculate zero point
|
|
73
|
-
if data_type == np.int8 and symmetric:
|
|
74
|
-
zp = np.zeros(input_min.shape)
|
|
75
|
-
else:
|
|
76
|
-
if scale == 0.0:
|
|
77
|
-
raise ValueError("scale can not be 0.")
|
|
78
|
-
zp_double = quant_min - input_min / scale
|
|
79
|
-
zp = np.floor(zp_double + 0.5)
|
|
80
|
-
|
|
81
|
-
return scale, zp
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def get_quant_min_max(data_type, num_bits=8, narrow_range=False):
|
|
85
|
-
"""Calculate quantization params for minimum/maximum quantization integer"""
|
|
86
|
-
if data_type == np.int8:
|
|
87
|
-
quant_min = 0 - 2 ** (num_bits - 1)
|
|
88
|
-
quant_max = 2 ** (num_bits - 1) - 1
|
|
89
|
-
elif data_type == np.uint8:
|
|
90
|
-
quant_min = 0
|
|
91
|
-
quant_max = 2 ** num_bits - 1
|
|
92
|
-
else:
|
|
93
|
-
raise ValueError("Unsupported datatype({})".format(data_type))
|
|
94
|
-
if narrow_range:
|
|
95
|
-
quant_min = quant_min + 1
|
|
96
|
-
return quant_min, quant_max
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def weight2int(data, scale, zero_point, quant_min, quant_max):
|
|
100
|
-
r"""
|
|
101
|
-
Calculate int8/uint8 weight from fp32. the formula is defined as:
|
|
102
|
-
|
|
103
|
-
.. math::
|
|
104
|
-
int8/uint8 = round(float/scale) + offset
|
|
105
|
-
|
|
106
|
-
Args:
|
|
107
|
-
data (numpy.ndarray): The dimension of channel or 1. Should be NCHW.
|
|
108
|
-
scale (numpy.ndarray): The dimension of channel or 1.
|
|
109
|
-
zero_point (numpy.ndarray): The dimension of channel or 1.
|
|
110
|
-
quant_min (int): The minimum quantization integer.
|
|
111
|
-
quant_max (int): The maximum quantization integer.
|
|
112
|
-
|
|
113
|
-
Returns:
|
|
114
|
-
weight (numpy.ndarray): The dimension of channel or 1.
|
|
115
|
-
"""
|
|
116
|
-
if scale.shape != zero_point.shape:
|
|
117
|
-
raise ValueError("`scale` and `zero_point` should have the same shape.")
|
|
118
|
-
if scale.shape[0] < 0:
|
|
119
|
-
raise ValueError("`scale` and `zero_point` shape should be greater than zero.")
|
|
120
|
-
if 0 in scale:
|
|
121
|
-
raise ValueError("Zero exist in `scale` which will lead to divide zero error.")
|
|
122
|
-
if len(scale.shape) >= 1 and scale.shape[0] > 1:
|
|
123
|
-
# for perchannel
|
|
124
|
-
if scale.shape[0] == data.shape[0]:
|
|
125
|
-
# `Conv2d` or `Dense` op weight
|
|
126
|
-
shape_list = [-1] + [1] * len(data.shape[1:])
|
|
127
|
-
scale = scale.reshape(shape_list)
|
|
128
|
-
zero_point = zero_point.reshape(shape_list)
|
|
129
|
-
elif scale.shape[0] == data.shape[1]:
|
|
130
|
-
# `DepthwiseConv2d` op weight
|
|
131
|
-
shape_list = [1, -1] + [1] * len(data.shape[2:])
|
|
132
|
-
scale = scale.reshape(shape_list)
|
|
133
|
-
zero_point = zero_point.reshape(shape_list)
|
|
134
|
-
else:
|
|
135
|
-
raise ValueError("Unsupported weight shape({})".format(data.shape))
|
|
136
|
-
|
|
137
|
-
weight_int = np.round((data / scale) + zero_point)
|
|
138
|
-
weight_int[weight_int > quant_max] = quant_max
|
|
139
|
-
weight_int[weight_int < quant_min] = quant_min
|
|
140
|
-
return weight_int
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def scale_zp_max_min_from_fake_quant_cell(cell, data_type):
|
|
144
|
-
"""Get calculate quantization params for scale, zero point, max and min from `FakeQuantWithMinMaxObserver`."""
|
|
145
|
-
minq = cell.minq.data.asnumpy()
|
|
146
|
-
maxq = cell.maxq.data.asnumpy()
|
|
147
|
-
# make sure maxq > 0 and minq <= 0
|
|
148
|
-
if cell.mode == 'LEARNED_SCALE':
|
|
149
|
-
maxq = np.abs(maxq)
|
|
150
|
-
minq = -np.abs(minq)
|
|
151
|
-
quant_min, quant_max = get_quant_min_max(data_type, num_bits=cell.num_bits, narrow_range=cell.narrow_range)
|
|
152
|
-
symmetric = cell.symmetric and not cell.neg_trunc
|
|
153
|
-
scale, zp = cal_quantization_params(
|
|
154
|
-
minq, maxq,
|
|
155
|
-
quant_min, quant_max, data_type,
|
|
156
|
-
symmetric=symmetric)
|
|
157
|
-
return scale, zp, maxq, minq
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def fold_batchnorm(weight, cell_quant):
|
|
161
|
-
r"""
|
|
162
|
-
Fold the batchnorm in `Conv2dBnFoldQuant` to weight.
|
|
163
|
-
|
|
164
|
-
Calculate from `FakeQuantWithMinMax`'s Parameter or Fake quant primitive.
|
|
165
|
-
|
|
166
|
-
Args:
|
|
167
|
-
weight (numpy.ndarray): Weight of `cell_quant`.
|
|
168
|
-
cell_quant (Cell): Object of `mindspore.nn.layer.Conv2dBnFoldQuant`.
|
|
169
|
-
|
|
170
|
-
Returns:
|
|
171
|
-
weight (numpy.ndarray): Folded weight.
|
|
172
|
-
bias (numpy.ndarray): Folded bias.
|
|
173
|
-
"""
|
|
174
|
-
variance = cell_quant.moving_variance.data.asnumpy()
|
|
175
|
-
mean = cell_quant.moving_mean.data.asnumpy()
|
|
176
|
-
gamma = cell_quant.gamma.data.asnumpy()
|
|
177
|
-
beta = cell_quant.beta.data.asnumpy()
|
|
178
|
-
epsilon = cell_quant.eps
|
|
179
|
-
if epsilon == 0:
|
|
180
|
-
raise ValueError("`epsilon` is zero may lead to divide zero error")
|
|
181
|
-
sigma = np.sqrt(variance + epsilon)
|
|
182
|
-
|
|
183
|
-
if gamma.shape[0] == weight.shape[0]:
|
|
184
|
-
# `Conv2d` or `Dense` op weight
|
|
185
|
-
shape_list = [-1] + [1] * len(weight.shape[1:])
|
|
186
|
-
_gamma = gamma.reshape(shape_list)
|
|
187
|
-
_sigma = sigma.reshape(shape_list)
|
|
188
|
-
elif gamma.shape[0] == weight.shape[1]:
|
|
189
|
-
# `DepthwiseConv2d` op weight
|
|
190
|
-
shape_list = [1, -1] + [1] * len(weight.shape[2:])
|
|
191
|
-
_gamma = gamma.reshape(shape_list)
|
|
192
|
-
_sigma = sigma.reshape(shape_list)
|
|
193
|
-
else:
|
|
194
|
-
raise ValueError("Unsupported weight shape({})".format(weight.shape))
|
|
195
|
-
|
|
196
|
-
weight = weight * _gamma / _sigma
|
|
197
|
-
bias = beta - gamma * mean / sigma
|
|
198
|
-
return weight, bias
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
def without_fold_batchnorm(weight, cell_quant):
|
|
202
|
-
r"""
|
|
203
|
-
Fold the batchnorm in `Conv2dBnWithoutFoldQuant` to weight.
|
|
204
|
-
|
|
205
|
-
Calculate from `FakeQuantWithMinMax`'s Parameter or Fake quant primitive.
|
|
206
|
-
|
|
207
|
-
Args:
|
|
208
|
-
weight (numpy.ndarray): Weight of `cell_quant`.
|
|
209
|
-
cell_quant (Cell): Object of `mindspore.nn.layer.Conv2dBnWithoutFoldQuant`.
|
|
210
|
-
|
|
211
|
-
Returns:
|
|
212
|
-
weight (numpy.ndarray): whihout folded weight.
|
|
213
|
-
bias (numpy.ndarray): without folded bias.
|
|
214
|
-
"""
|
|
215
|
-
variance = cell_quant.batchnorm.moving_variance.data.asnumpy()
|
|
216
|
-
mean = cell_quant.batchnorm.moving_mean.data.asnumpy()
|
|
217
|
-
gamma = cell_quant.batchnorm.gamma.data.asnumpy()
|
|
218
|
-
beta = cell_quant.batchnorm.beta.data.asnumpy()
|
|
219
|
-
epsilon = cell_quant.batchnorm.eps
|
|
220
|
-
if epsilon == 0:
|
|
221
|
-
raise ValueError("`epsilon` is zero may lead to divide zero error")
|
|
222
|
-
sigma = np.sqrt(variance + epsilon)
|
|
223
|
-
|
|
224
|
-
if gamma.shape[0] == weight.shape[0]:
|
|
225
|
-
# `Conv2d` or `Dense` op weight
|
|
226
|
-
shape_list = [-1] + [1] * len(weight.shape[1:])
|
|
227
|
-
_gamma = gamma.reshape(shape_list)
|
|
228
|
-
_sigma = sigma.reshape(shape_list)
|
|
229
|
-
elif gamma.shape[0] == weight.shape[1]:
|
|
230
|
-
# `DepthwiseConv2d` op weight
|
|
231
|
-
shape_list = [1, -1] + [1] * len(weight.shape[2:])
|
|
232
|
-
_gamma = gamma.reshape(shape_list)
|
|
233
|
-
_sigma = sigma.reshape(shape_list)
|
|
234
|
-
else:
|
|
235
|
-
raise ValueError("Unsupported weight shape({})".format(weight.shape))
|
|
236
|
-
|
|
237
|
-
weight = weight * _gamma / _sigma
|
|
238
|
-
bias = beta - gamma * mean / sigma
|
|
239
|
-
return weight, bias
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def compute_kl_threshold(data, bitwidth):
|
|
243
|
-
r"""
|
|
244
|
-
Using KL-J Distance to calculate the clip threshold.
|
|
245
|
-
|
|
246
|
-
Args:
|
|
247
|
-
- **data** (NumpyArray) - Data observed to calculate the threshold for quantization,
|
|
248
|
-
- **bitwidth** (QuantDtype) - The datatype of quantization.
|
|
249
|
-
Outputs:
|
|
250
|
-
Tensor with Shape 1. Threshold to calculate the data.
|
|
251
|
-
"""
|
|
252
|
-
data_max = np.abs(data).max()
|
|
253
|
-
if data_max < 1e-5:
|
|
254
|
-
return 1e-5
|
|
255
|
-
hist, bin_edges = np.histogram(np.abs(data), bins='sqrt', range=(0, data_max), density=True)
|
|
256
|
-
# For the sake of high efficiency, we limit the maximum number of bins to 1024 in `sqrt` mode, If it exceeds the
|
|
257
|
-
# largest size, turn to use the default bins config.
|
|
258
|
-
largest_bin_size = 1024
|
|
259
|
-
if hist.shape[0] > largest_bin_size:
|
|
260
|
-
hist, bin_edges = np.histogram(np.abs(data), range=(0, data_max), density=True)
|
|
261
|
-
sum_ = np.sum(hist)
|
|
262
|
-
if sum_ == 0:
|
|
263
|
-
hist = 0
|
|
264
|
-
else:
|
|
265
|
-
hist = hist / sum_
|
|
266
|
-
cumsum = np.cumsum(hist)
|
|
267
|
-
bit_pow_range = pow(2, int(bitwidth.num_bits) - 1)
|
|
268
|
-
threshold = []
|
|
269
|
-
scaling_factor = []
|
|
270
|
-
kl = []
|
|
271
|
-
if bit_pow_range + 1 > len(bin_edges) - 1:
|
|
272
|
-
th_layer_out = bin_edges[-1]
|
|
273
|
-
return float(th_layer_out)
|
|
274
|
-
for i in range(bit_pow_range + 1, len(bin_edges), 1):
|
|
275
|
-
threshold_tmp = (i + 0.5) * (bin_edges[1] - bin_edges[0])
|
|
276
|
-
threshold = np.concatenate((threshold, [threshold_tmp]))
|
|
277
|
-
scaling_factor_tmp = threshold_tmp / (bit_pow_range - 1)
|
|
278
|
-
scaling_factor = np.concatenate((scaling_factor, [scaling_factor_tmp]))
|
|
279
|
-
# forward interpolation
|
|
280
|
-
cumsum_tmp = np.copy(cumsum)
|
|
281
|
-
cumsum_tmp[(i - 1):] = 1
|
|
282
|
-
fwd_x = np.linspace(0.0, 1.0, bit_pow_range)
|
|
283
|
-
fwd_xp = np.linspace(0.0, 1.0, i)
|
|
284
|
-
fwd_fp = cumsum_tmp[:i]
|
|
285
|
-
forward_interp = np.interp(fwd_x, fwd_xp, fwd_fp)
|
|
286
|
-
# backward interpolation
|
|
287
|
-
bwd_x = np.linspace(0.0, 1.0, i)
|
|
288
|
-
bwd_xp = np.linspace(0.0, 1.0, bit_pow_range)
|
|
289
|
-
bwd_fp = forward_interp
|
|
290
|
-
backward_interp = np.interp(bwd_x, bwd_xp, bwd_fp)
|
|
291
|
-
cumsum_tmp[:i] = backward_interp
|
|
292
|
-
if 0 in cumsum_tmp:
|
|
293
|
-
raise ValueError("Zero exist in `cumsum_tmp` which will lead to divide zero error")
|
|
294
|
-
kl_tmp = np.sum((cumsum - cumsum_tmp) * np.log2(cumsum / cumsum_tmp)) # Kullback-Leibler-J
|
|
295
|
-
kl = np.concatenate((kl, [kl_tmp]))
|
|
296
|
-
th_layer_out = threshold[np.argmin(kl)]
|
|
297
|
-
threshold = float(th_layer_out)
|
|
298
|
-
if threshold < 1e-5:
|
|
299
|
-
threshold = 1e-5
|
|
300
|
-
return threshold
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
def query_quant_layers(network):
|
|
304
|
-
r"""
|
|
305
|
-
Query the network's quantization strategy of each quantized layer and print it to the screen, note that all the
|
|
306
|
-
quantization layers are queried before graph compile optimization in the graph mode, thus, some redundant quantized
|
|
307
|
-
layers, which not exist in practical execution, may appear.
|
|
308
|
-
|
|
309
|
-
Args:
|
|
310
|
-
network (Cell): input network
|
|
311
|
-
|
|
312
|
-
Examples:
|
|
313
|
-
>>> from mindspore.compression.quant import QuantizationAwareTraining
|
|
314
|
-
>>> from mindspore.compression.quant.quant_utils import query_quant_layers
|
|
315
|
-
>>> class LeNet5(nn.Cell):
|
|
316
|
-
... def __init__(self, num_class=10, channel=1):
|
|
317
|
-
... super(LeNet5, self).__init__()
|
|
318
|
-
... self.type = "fusion"
|
|
319
|
-
... self.num_class = num_class
|
|
320
|
-
...
|
|
321
|
-
... # change `nn.Conv2d` to `nn.Conv2dBnAct`
|
|
322
|
-
... self.conv1 = nn.Conv2dBnAct(channel, 6, 5, pad_mode='valid', activation='relu')
|
|
323
|
-
... self.conv2 = nn.Conv2dBnAct(6, 16, 5, pad_mode='valid', activation='relu')
|
|
324
|
-
... # change `nn.Dense` to `nn.DenseBnAct`
|
|
325
|
-
... self.fc1 = nn.DenseBnAct(16 * 5 * 5, 120, activation='relu')
|
|
326
|
-
... self.fc2 = nn.DenseBnAct(120, 84, activation='relu')
|
|
327
|
-
... self.fc3 = nn.DenseBnAct(84, self.num_class)
|
|
328
|
-
...
|
|
329
|
-
... self.max_pool2d = nn.MaxPool2d(kernel_size=2, stride=2)
|
|
330
|
-
... self.flatten = nn.Flatten()
|
|
331
|
-
...
|
|
332
|
-
... def construct(self, x):
|
|
333
|
-
... x = self.conv1(x)
|
|
334
|
-
... x = self.max_pool2d(x)
|
|
335
|
-
... x = self.conv2(x)
|
|
336
|
-
... x = self.max_pool2d(x)
|
|
337
|
-
... x = self.flatten(x)
|
|
338
|
-
... x = self.fc1(x)
|
|
339
|
-
... x = self.fc2(x)
|
|
340
|
-
... x = self.fc3(x)
|
|
341
|
-
... return x
|
|
342
|
-
...
|
|
343
|
-
>>> net = LeNet5()
|
|
344
|
-
>>> quantizer = QuantizationAwareTraining(bn_fold=False, per_channel=[True, False], symmetric=[True, False])
|
|
345
|
-
>>> net_qat = quantizer.quantize(net)
|
|
346
|
-
>>> query_quant_layers(net_qat)
|
|
347
|
-
conv1.conv.fake_quant_weight INT8
|
|
348
|
-
conv1.activation.fake_quant_act INT8
|
|
349
|
-
conv2.conv.fake_quant_weight INT8
|
|
350
|
-
conv2.activation.fake_quant_act INT8
|
|
351
|
-
fc1.dense.fake_quant_weight INT8
|
|
352
|
-
fc1.activation.fake_quant_act INT8
|
|
353
|
-
fc2.dense.fake_quant_weight INT8
|
|
354
|
-
fc2.activation.fake_quant_act INT8
|
|
355
|
-
fc3.dense.fake_quant_weight INT8
|
|
356
|
-
fc3.activation.fake_quant_act INT8
|
|
357
|
-
"""
|
|
358
|
-
network = Validator.check_isinstance("network", network, nn.Cell)
|
|
359
|
-
tplt = "{0:60}\t{1:10}"
|
|
360
|
-
for cell_and_name in network.cells_and_names():
|
|
361
|
-
cell_name = cell_and_name[0]
|
|
362
|
-
cell = cell_and_name[1]
|
|
363
|
-
if isinstance(cell, nn.FakeQuantWithMinMaxObserver):
|
|
364
|
-
logger.info(tplt.format(cell_name, cell.quant_dtype))
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
def load_nonquant_param_into_quant_net(quant_model, params_dict, quant_new_params=None):
|
|
368
|
-
r"""
|
|
369
|
-
Load fp32 model parameters into quantization model.
|
|
370
|
-
|
|
371
|
-
Args:
|
|
372
|
-
quant_model(Cell): Quantization model.
|
|
373
|
-
params_dict(dict): Parameter dict that stores fp32 parameters.
|
|
374
|
-
quant_new_params(list): Parameters that exist in quantization network but not in non-quantization
|
|
375
|
-
network. Default: None.
|
|
376
|
-
|
|
377
|
-
Raises:
|
|
378
|
-
TypeError: If `quant_new_params` is not None and is not list.
|
|
379
|
-
ValueError: If there are parameters in the `quant_model` that are neither in `params_dict`
|
|
380
|
-
nor in `quant_new_params`.
|
|
381
|
-
|
|
382
|
-
Examples:
|
|
383
|
-
>>> import mindspore as ms
|
|
384
|
-
>>> from mindspore.compression.quant.quant_utils import load_nonquant_param_into_quant_net
|
|
385
|
-
>>> class LeNet5(nn.Cell):
|
|
386
|
-
... def __init__(self, num_class=10, channel=1):
|
|
387
|
-
... super(LeNet5, self).__init__()
|
|
388
|
-
... self.type = "fusion"
|
|
389
|
-
... self.num_class = num_class
|
|
390
|
-
...
|
|
391
|
-
... # change `nn.Conv2d` to `nn.Conv2dBnAct`
|
|
392
|
-
... self.conv1 = nn.Conv2dBnAct(channel, 6, 5, pad_mode='valid', activation='relu')
|
|
393
|
-
... self.conv2 = nn.Conv2dBnAct(6, 16, 5, pad_mode='valid', activation='relu')
|
|
394
|
-
... # change `nn.Dense` to `nn.DenseBnAct`
|
|
395
|
-
... self.fc1 = nn.DenseBnAct(16 * 5 * 5, 120, activation='relu')
|
|
396
|
-
... self.fc2 = nn.DenseBnAct(120, 84, activation='relu')
|
|
397
|
-
... self.fc3 = nn.DenseBnAct(84, self.num_class)
|
|
398
|
-
...
|
|
399
|
-
... self.max_pool2d = nn.MaxPool2d(kernel_size=2, stride=2)
|
|
400
|
-
... self.flatten = nn.Flatten()
|
|
401
|
-
...
|
|
402
|
-
... def construct(self, x):
|
|
403
|
-
... x = self.conv1(x)
|
|
404
|
-
... x = self.max_pool2d(x)
|
|
405
|
-
... x = self.conv2(x)
|
|
406
|
-
... x = self.max_pool2d(x)
|
|
407
|
-
... x = self.flatten(x)
|
|
408
|
-
... x = self.fc1(x)
|
|
409
|
-
... x = self.fc2(x)
|
|
410
|
-
... x = self.fc3(x)
|
|
411
|
-
... return x
|
|
412
|
-
...
|
|
413
|
-
>>> net = LeNet5()
|
|
414
|
-
>>> ckpt_file_name = "./checkpoint/LeNet5_noquant-1_32.ckpt"
|
|
415
|
-
>>> param_dict = ms.load_checkpoint(ckpt_file_name)
|
|
416
|
-
>>> load_nonquant_param_into_quant_net(net, param_dict)
|
|
417
|
-
"""
|
|
418
|
-
if quant_new_params is not None and not isinstance(quant_new_params, list):
|
|
419
|
-
raise TypeError("quant_new_params must be list or None.")
|
|
420
|
-
iterable_dict = {
|
|
421
|
-
'minq': iter(list(filter(lambda item: item[0].endswith('minq'), params_dict.items()))),
|
|
422
|
-
'maxq': iter(list(filter(lambda item: item[0].endswith('maxq'), params_dict.items()))),
|
|
423
|
-
'quant_max': iter(list(filter(lambda item: item[0].endswith('quant_max'), params_dict.items())))
|
|
424
|
-
}
|
|
425
|
-
for param in params_dict.items():
|
|
426
|
-
key_name = param[0].split(".")[-1]
|
|
427
|
-
if key_name not in iterable_dict:
|
|
428
|
-
iterable_dict[key_name] = iter(list(filter(lambda item, value=key_name: item[0].endswith(value),
|
|
429
|
-
params_dict.items())))
|
|
430
|
-
|
|
431
|
-
for name, param in quant_model.parameters_and_names():
|
|
432
|
-
key_name = name.split(".")[-1]
|
|
433
|
-
if key_name not in iterable_dict.keys():
|
|
434
|
-
if key_name not in quant_new_params:
|
|
435
|
-
raise ValueError(f"Can't find match parameter in ckpt, param name = {name}")
|
|
436
|
-
continue
|
|
437
|
-
value_param = next(iterable_dict[key_name], None)
|
|
438
|
-
if value_param:
|
|
439
|
-
param.set_data(value_param[1].data)
|
|
440
|
-
logger.info(f'init model param {name} with checkpoint param {value_param[0]}')
|
|
441
|
-
|
|
442
|
-
# Perform KL_init when learned scale quantization is executed.
|
|
443
|
-
for cell_and_name in quant_model.cells_and_names():
|
|
444
|
-
cell = cell_and_name[1]
|
|
445
|
-
if isinstance(cell, (nn.Conv2dBnFoldQuantOneConv, nn.Conv2dBnFoldQuant, nn.Conv2dBnWithoutFoldQuant,
|
|
446
|
-
nn.Conv2dQuant, nn.DenseQuant)) and cell.fake_quant_weight.mode == "LEARNED_SCALE":
|
|
447
|
-
subcell_weight_para = cell.weight.data.asnumpy()
|
|
448
|
-
if hasattr(cell, 'gamma'):
|
|
449
|
-
scale_factor = (cell.gamma.data.asnumpy() /
|
|
450
|
-
np.sqrt(cell.moving_variance.data.asnumpy() + 1e-5))
|
|
451
|
-
subcell_weight_para = subcell_weight_para * scale_factor.reshape(-1, 1, 1, 1)
|
|
452
|
-
|
|
453
|
-
if cell.fake_quant_weight.per_channel:
|
|
454
|
-
max_init = [compute_kl_threshold(weight_para_each, cell.fake_quant_weight.quant_dtype)
|
|
455
|
-
for weight_para_each in subcell_weight_para]
|
|
456
|
-
min_init = [-x for x in max_init]
|
|
457
|
-
else:
|
|
458
|
-
max_init = [compute_kl_threshold(subcell_weight_para, cell.fake_quant_weight.quant_dtype)]
|
|
459
|
-
min_init = [-x for x in max_init]
|
|
460
|
-
|
|
461
|
-
cell.fake_quant_weight.reset(quant_dtype=cell.fake_quant_weight.quant_dtype,
|
|
462
|
-
min_init=min_init, max_init=max_init)
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Copyright 2020-2022 Huawei Technologies Co., Ltd
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
# ============================================================================
|
|
15
|
-
"""
|
|
16
|
-
Note:
|
|
17
|
-
Base Class of Quantizer. This is interface that is subject to change or deletion.
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
from __future__ import absolute_import
|
|
21
|
-
from abc import ABC, abstractmethod
|
|
22
|
-
from enum import Enum
|
|
23
|
-
|
|
24
|
-
from mindspore._checkparam import Validator
|
|
25
|
-
|
|
26
|
-
__all__ = ["OptimizeOption"]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class OptimizeOption(Enum):
|
|
30
|
-
r"""
|
|
31
|
-
An enum for the model quantization optimize option, currently only support `QAT` and `LEARNED_SCALE`.
|
|
32
|
-
"""
|
|
33
|
-
# using quantization aware training
|
|
34
|
-
QAT = "QAT"
|
|
35
|
-
|
|
36
|
-
# using the learned scale quantization
|
|
37
|
-
LEARNED_SCALE = "LEARNED_SCALE"
|
|
38
|
-
|
|
39
|
-
def __str__(self):
|
|
40
|
-
return str(self.value)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class Quantizer(ABC):
|
|
44
|
-
"""
|
|
45
|
-
Base class of Quantizer. You can implement different kind of quantizer to get different quantization result.
|
|
46
|
-
|
|
47
|
-
Notes:
|
|
48
|
-
This class is an abstract class.
|
|
49
|
-
|
|
50
|
-
Args:
|
|
51
|
-
optimize_option (OptimizeOption, list or tuple): Specifies the quant algorithm and options. Default:
|
|
52
|
-
OptimizeOption.QAT.
|
|
53
|
-
"""
|
|
54
|
-
def __init__(self,
|
|
55
|
-
optimize_option=OptimizeOption.QAT):
|
|
56
|
-
if not isinstance(optimize_option, list) and not isinstance(optimize_option, tuple):
|
|
57
|
-
optimize_option = [optimize_option]
|
|
58
|
-
for option in optimize_option:
|
|
59
|
-
option = Validator.check_isinstance("optimize_option", option, OptimizeOption)
|
|
60
|
-
self.optimize_option = optimize_option
|
|
61
|
-
|
|
62
|
-
@abstractmethod
|
|
63
|
-
def quantize(self, network):
|
|
64
|
-
"""
|
|
65
|
-
Quant API to convert input network to a quantization aware training network
|
|
66
|
-
Args:
|
|
67
|
-
network (Cell): network to be quantized.
|
|
68
|
-
"""
|