From 7175431eae8fec8025e00859af3e4464e2e93612 Mon Sep 17 00:00:00 2001 From: yujianfeng Date: Thu, 15 Sep 2022 18:53:01 +0800 Subject: [PATCH] Clean code --- mindspore/ccsrc/pipeline/jit/action.cc | 7 ---- mindspore/ccsrc/pipeline/jit/action.h | 1 - mindspore/core/ops/deformable_offsets.cc | 4 +-- mindspore/python/mindspore/common/tensor.py | 38 ++++++++++++--------- tests/ut/cpp/stub/pipeline/action_stub.cc | 2 -- 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/mindspore/ccsrc/pipeline/jit/action.cc b/mindspore/ccsrc/pipeline/jit/action.cc index 197749c6580..334efa67d70 100644 --- a/mindspore/ccsrc/pipeline/jit/action.cc +++ b/mindspore/ccsrc/pipeline/jit/action.cc @@ -1602,13 +1602,6 @@ std::vector MindIRPipeline() { } #ifdef WITH_BACKEND -std::vector ServerPipeline(const ResourcePtr &resource) { - auto actions = CommonPipeline(); - (void)actions.emplace_back(std::make_pair("optimize", VmOptimizeAction)); - (void)actions.emplace_back(std::make_pair("validate", ValidateAction)); - return actions; -} - std::vector PSchedulerPipeline(const ResourcePtr &resource) { if (resource->EnableCompileCache() && resource->func_graph() != nullptr) { return {std::make_pair("scheduler", StartPSSchedulerAction)}; diff --git a/mindspore/ccsrc/pipeline/jit/action.h b/mindspore/ccsrc/pipeline/jit/action.h index f560110c598..2299ccdec08 100644 --- a/mindspore/ccsrc/pipeline/jit/action.h +++ b/mindspore/ccsrc/pipeline/jit/action.h @@ -43,7 +43,6 @@ bool DistributedSplitAction(const ResourcePtr &resource); std::vector GePipeline(); std::vector VmPipeline(const ResourcePtr &resource); std::vector MindIRPipeline(); -std::vector ServerPipeline(const ResourcePtr &resource); std::vector PSchedulerPipeline(const ResourcePtr &resource); abstract::AnalysisResult AbstractAnalyze(const ResourcePtr &resource, const FuncGraphPtr &func_graph, const abstract::AbstractBasePtrList &args_abs, bool clear = false); diff --git a/mindspore/core/ops/deformable_offsets.cc b/mindspore/core/ops/deformable_offsets.cc index 03fe09c1dbe..5a7fdc030bf 100644 --- a/mindspore/core/ops/deformable_offsets.cc +++ b/mindspore/core/ops/deformable_offsets.cc @@ -87,12 +87,12 @@ void DeformableOffsetsPadFunction(std::vector *output_hw, const std::ve constexpr size_t right_index = 3; if (x_h != abstract::Shape::SHP_ANY) { out_h = static_cast(std::floor(1 + ((x_h * 1.0) + pads[top_index] + pads[bottom_index] - kernel_size[0] - - static_cast((kernel_size[0] - 1) * (dilations[h_axis] - 1))) / + LongToFloat((kernel_size[0] - 1) * (dilations[h_axis] - 1))) / strides[h_axis])); } if (x_w != abstract::Shape::SHP_ANY) { out_w = static_cast(std::floor(1 + ((x_w * 1.0) + pads[left_index] + pads[right_index] - kernel_size[1] - - static_cast((kernel_size[1] - 1) * (dilations[w_axis] - 1))) / + LongToFloat((kernel_size[1] - 1) * (dilations[w_axis] - 1))) / strides[w_axis])); } output_hw->push_back(out_h); diff --git a/mindspore/python/mindspore/common/tensor.py b/mindspore/python/mindspore/common/tensor.py index 34e8ad23cde..97af6a2a68d 100644 --- a/mindspore/python/mindspore/common/tensor.py +++ b/mindspore/python/mindspore/common/tensor.py @@ -39,6 +39,26 @@ np_types = (np.int8, np.int16, np.int32, np.int64, np.float32, np.float64, np.bool_, np.complex64, np.complex128) +def _check_input_data_type(input_data): + """Check the type of input_data for Tensor""" + validator.check_value_type('input_data', input_data, + (Tensor_, np.ndarray, np.str_, list, tuple, float, int, bool, complex), + 'Tensor') + valid_dtypes = (np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64, + np.float16, np.float32, np.float64, np.bool_, np.str_, np.complex64, np.complex128) + if isinstance(input_data, np.ndarray) and input_data.dtype not in valid_dtypes and \ + input_data.dtype.kind != 'U' and input_data.dtype.kind != 'S': # Support dtype np.str_ + raise TypeError(f"For Tensor, the input_data is a numpy array, " + f"but it's data type: {input_data.dtype} is not in supported list: " + f"{list(i.__name__ for i in valid_dtypes)}.") + if isinstance(input_data, np.ndarray) and input_data.dtype.kind == "S" and \ + input_data.shape and context.get_context("enable_ge"): + raise TypeError("For binary string input in GE mode, the shape of the data must be ()") + if isinstance(input_data, (tuple, list)) and np.array(input_data).dtype not in valid_dtypes: + raise TypeError( + f"For Tensor, the input_data is {input_data} that contain unsupported element.") + + class Tensor(Tensor_): """ Tensor is a data structure that stores an n-dimensional array. @@ -138,23 +158,7 @@ class Tensor(Tensor_): shape = _check_tensor_dynamic_shape(dtype, shape, init) Tensor_.__init__(self, dtype, shape) else: - validator.check_value_type('input_data', input_data, - (Tensor_, np.ndarray, np.str_, list, tuple, float, int, bool, complex), - 'Tensor') - valid_dtypes = (np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64, - np.float16, np.float32, np.float64, np.bool_, np.str_, np.complex64, np.complex128) - if isinstance(input_data, np.ndarray) and input_data.dtype not in valid_dtypes and \ - input_data.dtype.kind != 'U' and input_data.dtype.kind != 'S': # Support dtype np.str_ - raise TypeError(f"For Tensor, the input_data is a numpy array, " - f"but it's data type: {input_data.dtype} is not in supported list: " - f"{list(i.__name__ for i in valid_dtypes)}.") - if isinstance(input_data, np.ndarray) and input_data.dtype.kind == "S" and \ - input_data.shape and context.get_context("enable_ge"): - raise TypeError("For binary string input in GE mode, the shape of the data must be ()") - if isinstance(input_data, (tuple, list)) and np.array(input_data).dtype not in valid_dtypes: - raise TypeError( - f"For Tensor, the input_data is {input_data} that contain unsupported element.") - + _check_input_data_type(input_data) if dtype is not None: validator.check_type_name( 'dtype', dtype, mstype.number_type + (mstype.bool_, mstype.string), "Tensor") diff --git a/tests/ut/cpp/stub/pipeline/action_stub.cc b/tests/ut/cpp/stub/pipeline/action_stub.cc index ff4562edc7c..3700f668b82 100644 --- a/tests/ut/cpp/stub/pipeline/action_stub.cc +++ b/tests/ut/cpp/stub/pipeline/action_stub.cc @@ -17,8 +17,6 @@ #include "pipeline/jit/action.h" namespace mindspore { namespace pipeline { -std::vector PServerPipeline(const ResourcePtr &resource) { return {}; } std::vector PSchedulerPipeline(const ResourcePtr &resource) { return {}; } -std::vector ServerPipeline(const ResourcePtr &resource) { return {}; } } // namespace pipeline } // namespace mindspore