From fec57de88cfea34c1d5b1984850088d4a1b81132 Mon Sep 17 00:00:00 2001 From: yingshengBD <74164525+yingshengBD@users.noreply.github.com> Date: Sat, 27 Nov 2021 15:37:49 +0800 Subject: [PATCH] [Cherry-pick][NNAdapter][AmlogicNPU] Remove the transpose operation of the input of fc to fix the MobileNetV1 and ResNet50 (#7750) test=develop test=huawei_ascend_npu --- .../nnadapter/driver/amlogic_npu/engine.cc | 2 - .../optimizer/transpose_op_dimensions.cc | 57 ------------------- .../optimizer/transpose_op_dimensions.h | 25 -------- 3 files changed, 84 deletions(-) delete mode 100644 lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.cc delete mode 100644 lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.h diff --git a/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/engine.cc b/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/engine.cc index eefa508a69a..b99b44ff658 100644 --- a/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/engine.cc +++ b/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/engine.cc @@ -17,7 +17,6 @@ #include #include #include "driver/amlogic_npu/converter/converter.h" -#include "driver/amlogic_npu/optimizer/transpose_op_dimensions.h" #include "driver/amlogic_npu/optimizer/unpack_op_fusion.h" #include "optimizer/fuse_matmul_add_into_fully_connected.h" #include "optimizer/symm2asymm.h" @@ -60,7 +59,6 @@ int Program::BuildFromModel(hal::Model* model) { NNADAPTER_VLOG(5) << "Origin model:" << std::endl << Visualize(model); UnpackOpFusion(model); FuseMatMulAddIntoFullyConnected(model); - TransposeOpDimensions(model); ConvertQuantizationSymmToAsymm(model); NNADAPTER_VLOG(5) << "Optimized model:" << std::endl << Visualize(model); // Convert a NNAdapter model to a amlnpu graph diff --git a/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.cc b/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.cc deleted file mode 100644 index 6928537fe93..00000000000 --- a/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. -// -// 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 "driver/amlogic_npu/optimizer/transpose_op_dimensions.h" -#include -#include -#include "utility/debug.h" -#include "utility/logging.h" -#include "utility/modeling.h" -#include "utility/utility.h" - -namespace nnadapter { -namespace amlogic_npu { - -static void Transpose(hal::Model* model, hal::Operand* input_operand) { - auto producer = GetOperandProducer(model, input_operand); - if (producer->type == NNADAPTER_RESHAPE) { - std::vector permutation; - auto input_shape_count = input_operand->type.dimensions.count; - for (int32_t i = input_shape_count - 1; i >= 0; --i) { - permutation.push_back(i); - } - TransposeOperand(input_operand, permutation); - } -} - -void TransposeOpDimensions(hal::Model* model) { - std::vector operations = - SortOperationsInTopologicalOrder(model); - for (auto operation : operations) { - NNADAPTER_VLOG(5) << "Converting " << OperationTypeToString(operation->type) - << " ..."; - auto& input_operands = operation->input_operands; - auto& output_operands = operation->output_operands; - switch (operation->type) { - case NNADAPTER_FULLY_CONNECTED: - Transpose(model, input_operands[0]); - break; - default: - break; - } - } -} - -} // namespace amlogic_npu -} // namespace nnadapter diff --git a/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.h b/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.h deleted file mode 100644 index e52170cde85..00000000000 --- a/lite/backends/nnadapter/nnadapter/driver/amlogic_npu/optimizer/transpose_op_dimensions.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. -// -// 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. - -#pragma once - -#include "core/hal/types.h" - -namespace nnadapter { -namespace amlogic_npu { - -void TransposeOpDimensions(hal::Model* model); - -} // namespace amlogic_npu -} // namespace nnadapter