Browse Source

!979 Bugfix: fix dynamic input shape range check and remove size calc in preprocess

From: @hugo1
Reviewed-by: @xchu42,@wqtshg
Signed-off-by: @wqtshg
tags/v1.2.0
mindspore-ci-bot Gitee 3 years ago
parent
commit
c47485dbda
5 changed files with 122 additions and 38 deletions
  1. +1
    -0
      ge/graph/load/model_manager/model_manager.cc
  2. +21
    -22
      ge/graph/preprocess/graph_preprocess.cc
  3. +2
    -1
      tests/ut/ge/CMakeLists.txt
  4. +21
    -15
      tests/ut/ge/graph/load/new_model_manager_model_manager_unittest.cc
  5. +77
    -0
      tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc

+ 1
- 0
ge/graph/load/model_manager/model_manager.cc View File

@@ -527,6 +527,7 @@ Status ModelManager::DataInputTensor(uint32_t model_id, const std::vector<InputT
DataBuffer data;
data.data = inputs[i].data;
data.length = inputs[i].length;
input_data.shapes.emplace_back(inputs[i].dims);
input_data.blobs.push_back(data);
}
if (!GetLocalOmgContext().user_input_dims.empty() && GetLocalOmgContext().need_multi_batch) {


+ 21
- 22
ge/graph/preprocess/graph_preprocess.cc View File

@@ -935,7 +935,10 @@ Status ParseDynamicInputShapeRange(const std::string &shape_range,
return PARAM_INVALID;
}
for (auto &shape_range_str : shape_range_set) {
if (shape_range_str.empty()) {
if (shape_range_str.size() < 3) {
// shape_range_str should be "[2~3,1"
// or ",[2~3,1". because we should trim '[' or ',['
// so shape_range_str.size() < 3 is invalid
continue;
}
// trim start bytes, after that, single input should be "1~20,3,3~6,-1"
@@ -956,7 +959,7 @@ Status ParseDynamicInputShapeRange(const std::string &shape_range,
// fix dim
auto range_value = StringToLongNoThrow(range_pair_set.at(0).c_str());
if (range_value < 0) {
range_pair = std::make_pair(0, range_value);
range_pair = std::make_pair(1, range_value);
} else {
range_pair = std::make_pair(range_value, range_value);
}
@@ -1017,36 +1020,32 @@ Status UpdateDynamicInputShapeRange(const ge::GeAttrValue::INT index,
return PARAM_INVALID;
}
for (size_t i = 0; i < origin_shape.GetDimNum(); ++i) {
if (current_shape_range_vec.at(i).first == current_shape_range_vec.at(i).second) {
auto curr_dim = origin_shape.GetDim(i);
auto left_range = current_shape_range_vec.at(i).first;
auto right_range = current_shape_range_vec.at(i).second;
if (left_range == right_range) {
// given shape_range is known dim, check is same as origin or not
if (origin_shape.GetDim(i) != current_shape_range_vec.at(i).first) {
if (curr_dim != left_range) {
GELOGE(PARAM_INVALID, "Given shape range is %ld, current dim shape is %ld, not match.Pleace Check.",
current_shape_range_vec.at(i).first, origin_shape.GetDim(i));
left_range, curr_dim);
return PARAM_INVALID;
}
origin_shape.SetDim(i, current_shape_range_vec.at(i).first);
origin_shape.SetDim(i, left_range);
} else {
origin_shape.SetDim(i, -1);
// given shape_range is fix range, check input_shape is in this range or not
if (right_range != UNKNOWN_DIM) {
if ((curr_dim < left_range) || (curr_dim > right_range)) {
GELOGE(PARAM_INVALID, "Given shape range is [%ld~%ld], current dim shape is %ld, out of range.Pleace Check.",
left_range, right_range, curr_dim);
return PARAM_INVALID;
}
}
origin_shape.SetDim(i, UNKNOWN_DIM);
}
}
desc.SetShape(origin_shape);
desc.SetShapeRange(current_shape_range_vec);

int64_t dynamic_shape_size = 1;
for (const auto range_pair : range_vec.at(index)) {
FMK_INT64_MULCHECK(dynamic_shape_size, range_pair.second);
dynamic_shape_size *= range_pair.second;
}
auto data_type_size = GetSizeByDataType(desc.GetDataType());
if (data_type_size < 0) {
GELOGE(PARAM_INVALID, "Input data type is %s, is not supported.",
TypeUtils::DataTypeToSerialString(desc.GetDataType()).c_str());
return PARAM_INVALID;
}
FMK_INT64_MULCHECK(dynamic_shape_size, data_type_size);
dynamic_shape_size *= data_type_size;
GELOGI("In dynamic_execute mode ,set input %s shape range size %ld", op->GetName().c_str(), dynamic_shape_size);
ge::TensorUtils::SetSize(desc, dynamic_shape_size);
graphStatus graph_ret = op->UpdateInputDesc(0, desc);
GE_CHK_STATUS_RET(graph_ret, "UpdateInputDesc fail, graph ret: %u", graph_ret);
graph_ret = op->UpdateOutputDesc(0, desc);


+ 2
- 1
tests/ut/ge/CMakeLists.txt View File

@@ -573,7 +573,7 @@ set(DISTINCT_GRAPH_LOAD_TEST_FILES
"graph/load/data_dumper_unittest.cc"
#"graph/load/new_model_manager_data_inputer_unittest.cc"
#"graph/load/new_model_manager_davinci_model_unittest.cc"
#"graph/load/new_model_manager_model_manager_unittest.cc"
"graph/load/new_model_manager_model_manager_unittest.cc"
#"graph/load/new_model_manager_task_build_unittest.cc"
"graph/load/new_model_manager_model_manager_aicpu_unittest.cc"
"graph/load/end_graph_task_unittest.cc"
@@ -697,6 +697,7 @@ set(MULTI_PARTS_TEST_FILES
"graph/variable_accelerate_ctrl_unittest.cc"
"graph/build/logical_stream_allocator_unittest.cc"
"graph/build/mem_assigner_unittest.cc"
"graph/preprocess/graph_preprocess_unittest.cc"
"session/omg_omg_unittest.cc"
)



+ 21
- 15
tests/ut/ge/graph/load/new_model_manager_model_manager_unittest.cc View File

@@ -15,24 +15,18 @@
*/

#include <gtest/gtest.h>

#include <cce/compiler_stub.h>
#include <map>
#include "common/debug/log.h"
#include "common/model_parser/base.h"
#include "common/properties_manager.h"
#include "common/types.h"
#include "common/l2_cache_optimize.h"

#include "graph/utils/graph_utils.h"
#define private public
#define protected public
#include "graph/load/model_manager/model_manager.h"

#include "common/helper/om_file_helper.h"
#include "common/op/ge_op_utils.h"
#include "graph/load/graph_loader.h"
#include "graph/load/model_manager/davinci_model.h"
#include "graph/load/model_manager/davinci_model_parser.h"
#include "new_op_test_utils.h"
#undef private
#undef protected

@@ -87,7 +81,6 @@ class UtestModelManagerModelManager : public testing::Test {
data.model_data = new uint8_t[data.model_len];
uint8_t data_ori[model_len];
memset(data_ori, 10, model_len);
uint32_t out_len;
ModelFileHeader *header = (ModelFileHeader *)data.model_data;
header->magic = MODEL_FILE_MAGIC_NUM;
header->version = MODEL_VERSION;
@@ -97,7 +90,7 @@ class UtestModelManagerModelManager : public testing::Test {

void LoadStandardModelData(ge::ModelData &data) {
static const std::string STANDARD_MODEL_DATA_PATH =
"llt/framework/domi/ut/ome/test/data/standard_partition_model.txt";
"llt/framework/domi/ut/ome/test/data/standard_partition_model.txt";
ge::proto::ModelDef model_def;
ReadProtoFromText(STANDARD_MODEL_DATA_PATH.c_str(), &model_def);

@@ -113,9 +106,8 @@ class DModelListener : public ge::ModelListener {
uint32_t OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t resultCode) { return 0; }
};

shared_ptr<ModelListener> UTEST_CALL_BACK_FUN(new DModelListener());

TEST_F(UtestModelManagerModelManager, case_load_incorrect_param) {
/*TEST_F(UtestModelManagerModelManager, case_load_incorrect_param) {
ModelManager mm;
uint32_t model_id = 0;
ge::ModelData model;
@@ -307,7 +299,7 @@ TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_fail) {
}


/*
*//*
// test GetInputOutputDescInfo fail
TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_zero_copy_fail) {
ModelManager manager;
@@ -316,7 +308,7 @@ TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_zero_copy_fail)
vector<InputOutputDescInfo> output_shape;
EXPECT_EQ(ge::PARAM_INVALID, manager.GetInputOutputDescInfoForZeroCopy(2, input_shape, output_shape));
}
*/
*//*

// test Stop
TEST_F(UtestModelManagerModelManager, stop_fail) {
@@ -347,6 +339,20 @@ TEST_F(UtestModelManagerModelManager, destroy_aicpu_session) {

manager.sess_ids_.insert(0);
manager.DestroyAicpuSession(0);
}*/
// test DataInputTensor
TEST_F(UtestModelManagerModelManager, test_data_input_tensor) {
shared_ptr<ModelListener> g_label_call_back(nullptr);
auto model = std::make_shared<DavinciModel>(0, g_label_call_back);
ModelManager mm;
uint32_t model_id = 1;
mm.model_map_[1] = model;
mm.hybrid_model_map_[1] = std::make_shared<hybrid::HybridDavinciModel>();

auto input_tensor = InputTensorInfo();
vector<InputTensorInfo> inputs;
inputs.emplace_back(input_tensor);
auto ret = mm.DataInputTensor(model_id,inputs);
EXPECT_EQ(ge::UNSUPPORTED, ret);
}

} // namespace ge

+ 77
- 0
tests/ut/ge/graph/preprocess/graph_preprocess_unittest.cc View File

@@ -0,0 +1,77 @@
/**
* Copyright 2019-2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <gtest/gtest.h>
#include <memory>

#include "common/ge_inner_error_codes.h"
#include "common/types.h"
#include "common/util.h"
#include "graph/passes/graph_builder_utils.h"
#include "graph/utils/attr_utils.h"
#include "graph/debug/ge_attr_define.h"

#define private public
#define protected public
#include "graph/preprocess/graph_preprocess.h"
#include "ge/ge_api.h"
#undef private
#undef protected

using namespace std;
namespace ge {
class UtestGraphPreproces : public testing::Test {
protected:
void SetUp() {
}
void TearDown() {
}
};

ComputeGraphPtr BuildGraph1(){
auto builder = ut::GraphBuilder("g1");
auto data1 = builder.AddNode("data1",DATA,1,1);
auto data_opdesc = data1->GetOpDesc();
AttrUtils::SetInt(data_opdesc, ATTR_NAME_INDEX, 0);
data1->UpdateOpDesc(data_opdesc);
return builder.GetGraph();
}

TEST_F(UtestGraphPreproces, test_dynamic_input_shape_parse) {
ge::GraphPrepare graph_prepare;
graph_prepare.compute_graph_ = BuildGraph1();
// prepare user_input & graph option
ge::GeTensorDesc tensor1;
tensor1.SetFormat(ge::FORMAT_NCHW);
tensor1.SetShape(ge::GeShape({3, 12, 5, 5}));
tensor1.SetDataType(ge::DT_FLOAT);
GeTensor input1(tensor1);
std::vector<GeTensor> user_input = {input1};
std::map<string,string> graph_option = {{"ge.exec.dynamicGraphExecuteMode","dynamic_execute"},
{"ge.exec.dataInputsShapeRange","[3,1~20,2~10,5]"}};
auto ret = graph_prepare.UpdateInput(user_input, graph_option);
EXPECT_EQ(ret, ge::SUCCESS);
// check data node output shape_range and shape
auto data_node = graph_prepare.compute_graph_->FindNode("data1");
auto data_output_desc = data_node->GetOpDesc()->GetOutputDescPtr(0);
vector<int64_t> expect_shape = {3,-1,-1,5};
auto result_shape = data_output_desc->GetShape();
EXPECT_EQ(result_shape.GetDimNum(), expect_shape.size());
for(size_t i =0; i< expect_shape.size(); ++i){
EXPECT_EQ(result_shape.GetDim(i), expect_shape.at(i));
}
}
}

Loading…
Cancel
Save