forked from huawei/mindspore2022
[MSLITE] Fix bug of shape fusion
This commit is contained in:
parent
ecde0749bb
commit
c3d14d7dac
|
|
@ -247,71 +247,51 @@ int ShapeFusionPass::GenerateFusedShapeFusionMatrix(Model::Node *shape_fusion, c
|
|||
ShapeFusionMatrix *shape_fusion_matrix) {
|
||||
MS_ASSERT(shape_fusion != nullptr && post_node != nullptr && shape_fusion_matrix != nullptr);
|
||||
std::vector<uint32_t> fused_inputs;
|
||||
std::vector<uint32_t> const_inputs;
|
||||
std::set<uint32_t> shape_fusion_outputs(shape_fusion->output_indices_.begin(), shape_fusion->output_indices_.end());
|
||||
std::set<uint32_t> post_inputs(post_node->input_indices_.begin(), post_node->input_indices_.end());
|
||||
std::set_intersection(post_inputs.begin(), post_inputs.end(), shape_fusion_outputs.begin(),
|
||||
shape_fusion_outputs.end(), std::inserter(fused_inputs, fused_inputs.begin()));
|
||||
std::set_difference(post_inputs.begin(), post_inputs.end(), shape_fusion_outputs.begin(), shape_fusion_outputs.end(),
|
||||
std::inserter(const_inputs, const_inputs.begin()));
|
||||
MS_CHECK_TRUE_RET(!fused_inputs.empty(), RET_ERROR);
|
||||
MS_CHECK_TRUE_RET(shape_fusion_matrices_.find(fused_inputs.at(0)) != shape_fusion_matrices_.end(), RET_ERROR);
|
||||
|
||||
*shape_fusion_matrix = shape_fusion_matrices_[fused_inputs.at(0)];
|
||||
if (post_node->node_type_ == schema::PrimitiveType_Concat) {
|
||||
auto input_index = post_node->input_indices_.at(0);
|
||||
if (std::find(fused_inputs.begin(), fused_inputs.end(), input_index) != fused_inputs.end()) {
|
||||
auto input_index = post_node->input_indices_.at(0);
|
||||
if (std::find(fused_inputs.begin(), fused_inputs.end(), input_index) != fused_inputs.end()) {
|
||||
input_indices->push_back(input_index);
|
||||
} else {
|
||||
std::vector<size_t> shape = {shape_fusion_matrix->shape_matrix.size(),
|
||||
shape_fusion_matrix->shape_matrix.front().size()};
|
||||
auto const_tensor = src_tensors_->at(input_index);
|
||||
MS_CHECK_TRUE_RET(const_tensor != nullptr && const_tensor->data() != nullptr, RET_ERROR);
|
||||
if (GetFusionMatrixFromConstantTensor(const_tensor, shape, post_node->node_type_, shape_fusion_matrix) != RET_OK) {
|
||||
MS_LOG(ERROR) << "GetMatrixFromConstantTensor failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < post_node->input_indices_.size(); i++) {
|
||||
ShapeFusionMatrix const_matrix;
|
||||
input_index = post_node->input_indices_.at(i);
|
||||
if (std::find(shape_fusion->output_indices_.begin(), shape_fusion->output_indices_.end(), input_index) !=
|
||||
shape_fusion->output_indices_.end()) {
|
||||
MS_CHECK_TRUE_RET(shape_fusion_matrices_.find(input_index) != shape_fusion_matrices_.end(), RET_ERROR);
|
||||
const_matrix = shape_fusion_matrices_[input_index];
|
||||
input_indices->push_back(input_index);
|
||||
} else {
|
||||
std::vector<size_t> shape = {shape_fusion_matrix->shape_matrix.size(),
|
||||
shape_fusion_matrix->shape_matrix.front().size()};
|
||||
auto const_tensor = src_tensors_->at(input_index);
|
||||
MS_CHECK_TRUE_RET(const_tensor != nullptr && const_tensor->data() != nullptr, RET_ERROR);
|
||||
if (GetFusionMatrixFromConstantTensor(const_tensor, shape, post_node->node_type_, shape_fusion_matrix) !=
|
||||
RET_OK) {
|
||||
MS_LOG(ERROR) << "GetMatrixFromConstantTensor failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < post_node->input_indices_.size(); i++) {
|
||||
input_index = post_node->input_indices_.at(i);
|
||||
if (std::find(shape_fusion->output_indices_.begin(), shape_fusion->output_indices_.end(), input_index) !=
|
||||
shape_fusion->output_indices_.end()) {
|
||||
MS_CHECK_TRUE_RET(shape_fusion_matrices_.find(input_index) != shape_fusion_matrices_.end(), RET_ERROR);
|
||||
shape_fusion_matrix->Append(shape_fusion_matrices_[input_index]);
|
||||
input_indices->push_back(input_index);
|
||||
} else {
|
||||
ShapeFusionMatrix const_matrix;
|
||||
std::vector<size_t> shape = {shape_fusion_matrix->shape_matrix.size(),
|
||||
shape_fusion_matrix->shape_matrix.front().size()};
|
||||
auto const_tensor = src_tensors_->at(input_index);
|
||||
MS_CHECK_TRUE_RET(const_tensor != nullptr && const_tensor->data() != nullptr, RET_ERROR);
|
||||
if (GetFusionMatrixFromConstantTensor(const_tensor, shape, post_node->node_type_, &const_matrix) != RET_OK) {
|
||||
MS_LOG(ERROR) << "GetMatrixFromConstantTensor failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
shape_fusion_matrix->Append(const_matrix);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ShapeFusionMatrix const_matrix;
|
||||
input_indices->push_back(fused_inputs.at(0));
|
||||
if (fused_inputs.size() == DIMENSION_2D) {
|
||||
MS_CHECK_TRUE_RET(shape_fusion_matrices_.find(fused_inputs.at(1)) != shape_fusion_matrices_.end(), RET_ERROR);
|
||||
const_matrix = shape_fusion_matrices_[fused_inputs.at(1)];
|
||||
input_indices->push_back(fused_inputs.at(1));
|
||||
} else {
|
||||
MS_CHECK_TRUE_RET(!const_inputs.empty(), RET_ERROR);
|
||||
std::vector<size_t> shape = {shape_fusion_matrix->shape_matrix.size(),
|
||||
shape_fusion_matrix->shape_matrix.front().size()};
|
||||
auto const_tensor = src_tensors_->at(const_inputs.at(0));
|
||||
if (GetFusionMatrixFromConstantTensor(const_tensor, shape, post_node->node_type_, &const_matrix) != RET_OK) {
|
||||
MS_LOG(ERROR) << "GetMatrixFromConstantTensor failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
shape_fusion_matrix->Arithmetic(const_matrix, static_cast<schema::PrimitiveType>(post_node->node_type_));
|
||||
if (post_node->node_type_ == schema::PrimitiveType_Concat) {
|
||||
shape_fusion_matrix->Append(const_matrix);
|
||||
} else {
|
||||
shape_fusion_matrix->Arithmetic(const_matrix, static_cast<schema::PrimitiveType>(post_node->node_type_));
|
||||
}
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# model_info accuracy_limit
|
||||
# model_name;input_num:input_name;input_shapes;spec_threads;mode accuracy_limit/CONVERTER
|
||||
dis_matmul_.mindir CONVERTER
|
||||
dis_matmul_1.mindir CONVERTER
|
||||
|
|
|
|||
Loading…
Reference in New Issue