-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix mul bugs #7964
Merged
Merged
fix mul bugs #7964
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c8b4a8b
fix mul bugs
xingjing1 946da52
fix bugs
xingjing1 2d03ea8
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle-Lite…
xingjing1 f6553b5
fix matmul quant bugs
xingjing1 65dbc7d
add test_mobilenet_v1_int8_per_layer_arm.cc
xingjing1 760f023
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle-Lite…
xingjing1 7f43c32
add test
xingjing1 cf2f709
fix bugd
xingjing1 b3ab8da
fix bugs
xingjing1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// 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 <gflags/gflags.h> | ||
#include <gtest/gtest.h> | ||
#include <vector> | ||
#include "lite/api/paddle_api.h" | ||
#include "lite/api/test/lite_api_test_helper.h" | ||
#include "lite/api/test/test_helper.h" | ||
#include "lite/tests/api/ILSVRC2012_utility.h" | ||
#include "lite/utils/log/cp_logging.h" | ||
|
||
DEFINE_string(data_dir, "", "data dir"); | ||
DEFINE_int32(iteration, 100, "iteration times to run"); | ||
DEFINE_int32(batch, 1, "batch of image"); | ||
DEFINE_int32(channel, 3, "image channel"); | ||
|
||
namespace paddle { | ||
namespace lite { | ||
|
||
TEST(MobileNetV1, test_mobilenet_v1_int8_per_layer_arm) { | ||
std::shared_ptr<paddle::lite_api::PaddlePredictor> predictor = nullptr; | ||
// Use the full api with CxxConfig to generate the optimized model | ||
lite_api::CxxConfig cxx_config; | ||
cxx_config.set_model_dir(FLAGS_model_dir); | ||
cxx_config.set_valid_places( | ||
{lite_api::Place{TARGET(kARM), PRECISION(kFloat)}, | ||
lite_api::Place{TARGET(kARM), PRECISION(kInt8)}}); | ||
predictor = lite_api::CreatePaddlePredictor(cxx_config); | ||
predictor->SaveOptimizedModel(FLAGS_model_dir, | ||
paddle::lite_api::LiteModelType::kNaiveBuffer); | ||
// Use the light api with MobileConfig to load and run the optimized model | ||
paddle::lite_api::MobileConfig mobile_config; | ||
mobile_config.set_model_from_file(FLAGS_model_dir + ".nb"); | ||
mobile_config.set_threads(FLAGS_threads); | ||
mobile_config.set_power_mode( | ||
static_cast<lite_api::PowerMode>(FLAGS_power_mode)); | ||
predictor = paddle::lite_api::CreatePaddlePredictor(mobile_config); | ||
|
||
std::string raw_data_dir = FLAGS_data_dir + std::string("/raw_data"); | ||
std::vector<int> input_shape{ | ||
FLAGS_batch, FLAGS_channel, FLAGS_im_width, FLAGS_im_height}; | ||
auto raw_data = ReadRawData(raw_data_dir, input_shape, FLAGS_iteration); | ||
|
||
int input_size = 1; | ||
for (auto i : input_shape) { | ||
input_size *= i; | ||
} | ||
|
||
for (int i = 0; i < FLAGS_warmup; ++i) { | ||
auto input_tensor = predictor->GetInput(0); | ||
input_tensor->Resize( | ||
std::vector<int64_t>(input_shape.begin(), input_shape.end())); | ||
auto* data = input_tensor->mutable_data<float>(); | ||
for (int j = 0; j < input_size; j++) { | ||
data[j] = 0.f; | ||
} | ||
predictor->Run(); | ||
} | ||
|
||
std::vector<std::vector<float>> out_rets; | ||
out_rets.resize(FLAGS_iteration); | ||
double cost_time = 0; | ||
for (size_t i = 0; i < raw_data.size(); ++i) { | ||
auto input_tensor = predictor->GetInput(0); | ||
input_tensor->Resize( | ||
std::vector<int64_t>(input_shape.begin(), input_shape.end())); | ||
auto* data = input_tensor->mutable_data<float>(); | ||
memcpy(data, raw_data[i].data(), sizeof(float) * input_size); | ||
|
||
double start = GetCurrentUS(); | ||
predictor->Run(); | ||
cost_time += GetCurrentUS() - start; | ||
|
||
auto output_tensor = predictor->GetOutput(0); | ||
auto output_shape = output_tensor->shape(); | ||
auto output_data = output_tensor->data<float>(); | ||
ASSERT_EQ(output_shape.size(), 2UL); | ||
ASSERT_EQ(output_shape[0], 1); | ||
ASSERT_EQ(output_shape[1], 1000); | ||
|
||
int output_size = output_shape[0] * output_shape[1]; | ||
out_rets[i].resize(output_size); | ||
memcpy(&(out_rets[i].at(0)), output_data, sizeof(float) * output_size); | ||
} | ||
|
||
LOG(INFO) << "================== Speed Report ==================="; | ||
LOG(INFO) << "Model: " << FLAGS_model_dir << ", threads num " << FLAGS_threads | ||
<< ", warmup: " << FLAGS_warmup << ", batch: " << FLAGS_batch | ||
<< ", iteration: " << FLAGS_iteration << ", spend " | ||
<< cost_time / FLAGS_iteration / 1000.0 << " ms in average."; | ||
|
||
std::string labels_dir = FLAGS_data_dir + std::string("/labels.txt"); | ||
float out_accuracy = CalOutAccuracy(out_rets, labels_dir); | ||
ASSERT_GE(out_accuracy, 0.55f); | ||
} | ||
|
||
} // namespace lite | ||
} // namespace paddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方建议在头文件定义一个std::vectorstd::string op_types_ 数组,然后判断当前 OP 是否在这个List 里。这样后续有其他OP 支持,只用在vector 添加op_type 即可
*.h : std::vectorstd::string op_types_{"matmul"};
*.cc
if (op_type != op_types_.end()) {
op_info.SetAttr("enable_int8", true);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的