-
Notifications
You must be signed in to change notification settings - Fork 6k
[DO NOT MERGE] detect model test for dynamic shape #18331
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
76db898
detect model test for dynamic shape
luotao1 6a97049
load input data one by one
luotao1 1a47373
each iteration use new threads
luotao1 c0419de
Merge branch 'develop' into detect_model
luotao1 19da59e
Remove all the code, API and doc of MKL-DNN INT8v1 (#18347)
zhaify 6adb535
fix input_slot_all memory leak
luotao1 9931bc6
add dependecy of collective_helper (#18365)
LLMHao fd6631e
Fix dygraph show style (#18297)
junjun315 8ed819d
Call the test_slim_int8_* tests through absolute path (#18386)
871cc15
Add is_compiled_with_cuda (#18356)
af874a1
test=develop, fix multigpu hang on latest docker (#18379)
JiabinYang 43f64a1
Fix/program doc (#17908)
JiabinYang f564100
Add a unittest to inplace elementwise_add (#18385)
sneaxiy 052b044
Fix mac build nproc command not found (#18362)
tianshuo78520a 681d355
Fix potential mkldnn concat/pool/conv kernel issues (#18393)
LeoZhao-Intel e83f902
add MultiSlotStringDataGenerator for speedup of string based user inp…
guru4elephant b963079
fix ci document_preview job error (#18399)
tianshuo78520a 2b4ef50
init custom black white list (#18377)
Jie-Fang ce7a024
fix py-cpuinfo mac random fail (#18383)
tensor-tang ef81ff7
update pslib library path (#18415)
guru4elephant 93a2b31
fix data feed ptr error (#18419)
xjqbest 8a39e5c
update api format (#18413)
hutuxian 92ecb30
test=develop (#18426)
tianshuo78520a 47e2ef3
add "import paddle.fluid as fluid" to examples lack of it
xsrobin dd3f9d1
replace mnist dataset url, test=develop (#18429)
tink2123 4bc2987
Fix bug in quantize kernel which cause crash in vgg16/19 model (#17964)
liujianhang-design 7023a86
Fix Pooling output scale (#18186)
Sand3r- a3bc804
fix mac ci random fail (#18430)
tensor-tang 2246f7c
Update README.md with latest version
XiaoguangHu01 99659a9
update README_cn.md with latest version
XiaoguangHu01 449c7a9
Make roi_perspective_transform op return mask and transform matrix (#…
LielinJiang e0d8c6a
Add find_no_grad_vars in backward.py (#17942)
357311f
make fleet support mpi job submit directly (#18441)
guru4elephant 85b49d8
fix the api.spec file does not get the class comment problem (#18439)
tianshuo78520a a873fa8
supports collective training with programs (#18392)
gavin1332 3123d18
remove unused AnalysisPredictor::SetMkldnnThreadID() (#18444)
luotao1 823ab5e
fix load attr error. test=develop (#18447)
heavengate 41ab76e
add friendly error msg to py_reader (#18316)
sneaxiy 8f5fffc
rename mkldnn set/get_cur_thread_id() to set/get_cur_mkldnn_session_i…
LeoZhao-Intel d30fe34
Merge branch 'detect_model' of https://github.com/luotao1/Paddle into…
luotao1 510d442
add bert test for transfer_scope_cache
luotao1 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 hidden or 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
137 changes: 137 additions & 0 deletions
137
paddle/fluid/inference/tests/api/analyzer_detect_tester.cc
This file contains hidden or 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,137 @@ | ||
| /* Copyright (c) 2018 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 <gtest/gtest.h> | ||
| #include <fstream> | ||
| #include <iostream> | ||
| #include "paddle/fluid/inference/tests/api/tester_helper.h" | ||
| DEFINE_string(infer_shape, "", "data shape file"); | ||
| DEFINE_int32(sample, 1, "number of sample"); | ||
|
|
||
| namespace paddle { | ||
| namespace inference { | ||
| namespace analysis { | ||
|
|
||
| struct Record { | ||
| std::vector<float> data; | ||
| std::vector<int32_t> shape; | ||
| }; | ||
|
|
||
| Record ProcessALine(const std::string &line, const std::string &shape_line) { | ||
| VLOG(3) << "process a line"; | ||
| std::vector<std::string> columns; | ||
|
|
||
| Record record; | ||
| std::vector<std::string> data_strs; | ||
| split(line, ' ', &data_strs); | ||
| for (auto &d : data_strs) { | ||
| record.data.push_back(std::stof(d)); | ||
| } | ||
|
|
||
| std::vector<std::string> shape_strs; | ||
| split(shape_line, ' ', &shape_strs); | ||
| for (auto &s : shape_strs) { | ||
| record.shape.push_back(std::stoi(s)); | ||
| } | ||
| // VLOG(3) << "data size " << record.data.size(); | ||
| // VLOG(3) << "data shape size " << record.shape.size(); | ||
| // LOG(INFO) << "data shape size " << record.shape[3]; | ||
| return record; | ||
| } | ||
|
|
||
| void SetConfig(AnalysisConfig *cfg) { | ||
| cfg->SetModel(FLAGS_infer_model + "/model", FLAGS_infer_model + "/params"); | ||
| cfg->DisableGpu(); | ||
| cfg->SwitchIrDebug(); | ||
| cfg->SwitchSpecifyInputNames(false); | ||
| cfg->SetCpuMathLibraryNumThreads(FLAGS_paddle_num_threads); | ||
| } | ||
|
|
||
| void SetInput(std::vector<std::vector<PaddleTensor>> *inputs, | ||
| const std::string &line, const std::string &shape_line) { | ||
| auto record = ProcessALine(line, shape_line); | ||
|
|
||
| PaddleTensor input; | ||
| input.shape = record.shape; | ||
| input.dtype = PaddleDType::FLOAT32; | ||
| size_t input_size = record.data.size() * sizeof(float); | ||
| input.data.Resize(input_size); | ||
| memcpy(input.data.data(), record.data.data(), input_size); | ||
| std::vector<PaddleTensor> input_slots; | ||
| input_slots.assign({input}); | ||
| (*inputs).emplace_back(input_slots); | ||
| } | ||
|
|
||
| // Easy for profiling independently. | ||
| // ocr, mobilenet and se_resnext50 | ||
| void profile(bool use_mkldnn = false) { | ||
| AnalysisConfig cfg; | ||
| SetConfig(&cfg); | ||
| if (use_mkldnn) { | ||
| cfg.EnableMKLDNN(); | ||
| } | ||
| // cfg.pass_builder()->TurnOnDebug(); | ||
| std::vector<std::vector<PaddleTensor>> outputs; | ||
| std::vector<std::vector<PaddleTensor>> input_slots_all; | ||
|
|
||
| Timer run_timer; | ||
| double elapsed_time = 0; | ||
|
|
||
| int iterations = FLAGS_sample; | ||
| int num_times = FLAGS_repeat; | ||
| auto predictor = CreatePaddlePredictor<AnalysisConfig>(cfg); | ||
| outputs.resize(iterations); | ||
|
|
||
| std::vector<std::thread> threads; | ||
|
|
||
| for (int j = 0; j < num_times; j++) { | ||
| std::ifstream file(FLAGS_infer_data); | ||
| std::ifstream infer_file(FLAGS_infer_shape); | ||
| std::string line; | ||
| std::string shape_line; | ||
|
|
||
| for (int i = 0; i < iterations; i++) { | ||
| threads.emplace_back([&, i]() { | ||
| std::getline(file, line); | ||
| std::getline(infer_file, shape_line); | ||
| SetInput(&input_slots_all, line, shape_line); | ||
|
|
||
| run_timer.tic(); | ||
| predictor->Run(input_slots_all[0], &outputs[0], FLAGS_batch_size); | ||
| elapsed_time += run_timer.toc(); | ||
| }); | ||
| threads[0].join(); | ||
| threads.clear(); | ||
| if (i % 100 == 0) LOG(INFO) << i << " samples"; | ||
| std::vector<std::vector<PaddleTensor>>().swap(input_slots_all); | ||
| } | ||
|
|
||
| file.close(); | ||
| infer_file.close(); | ||
| } | ||
|
|
||
| auto batch_latency = elapsed_time / (iterations * num_times); | ||
| PrintTime(FLAGS_batch_size, num_times, FLAGS_num_threads, 0, batch_latency, | ||
| iterations, VarType::FP32); | ||
| } | ||
|
|
||
| TEST(Analyzer_vis, profile) { profile(); } | ||
|
|
||
| #ifdef PADDLE_WITH_MKLDNN | ||
| TEST(Analyzer_vis, profile_mkldnn) { profile(true /* use_mkldnn */); } | ||
| #endif | ||
|
|
||
| } // namespace analysis | ||
| } // namespace inference | ||
| } // namespace paddle | ||
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.
this place, the clear method should be same with input_slots_all.