Skip to content

Commit b4fa3db

Browse files
committed
unify PrintTime of analysis unit-test
1 parent f615ba2 commit b4fa3db

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

paddle/fluid/inference/analysis/analyzer_lac_tester.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ void GetOneBatch(std::vector<PaddleTensor> *input_slots, DataRecord *data,
114114
PADDLE_ENFORCE_EQ(batch_size, static_cast<int>(one_batch.lod.size() - 1));
115115
input_slots->assign({input_tensor});
116116
}
117-
static void PrintTime(const double latency, const int bs, const int repeat) {
118-
LOG(INFO) << "===========profile result===========";
119-
LOG(INFO) << "batch_size: " << bs << ", repeat: " << repeat
120-
<< ", avg latency: " << latency / repeat << "ms";
121-
LOG(INFO) << "=====================================";
122-
}
123117
void BenchAllData(const std::string &model_path, const std::string &data_file,
124118
const int batch_size, const int repeat) {
125119
NativeConfig config;
@@ -145,7 +139,7 @@ void BenchAllData(const std::string &model_path, const std::string &data_file,
145139
sum += timer.toc();
146140
}
147141
}
148-
PrintTime(sum, batch_size, repeat);
142+
PrintTime(batch_size, repeat, 1, 0, sum / repeat);
149143
}
150144
const int64_t lac_ref_data[] = {24, 25, 25, 25, 38, 30, 31, 14, 15, 44, 24, 25,
151145
25, 25, 25, 25, 44, 24, 25, 25, 25, 36, 42, 43,
@@ -176,7 +170,7 @@ void TestLACPrediction(const std::string &model_path,
176170
for (int i = 0; i < repeat; i++) {
177171
predictor->Run(input_slots, &outputs_slots);
178172
}
179-
PrintTime(timer.toc(), batch_size, repeat);
173+
PrintTime(batch_size, repeat, 1, 0, timer.toc() / repeat);
180174
EXPECT_EQ(outputs_slots.size(), 1UL);
181175
auto &out = outputs_slots[0];
182176
size_t size = std::accumulate(out.shape.begin(), out.shape.end(), 1,

paddle/fluid/inference/analysis/analyzer_ner_tester.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ void TestChineseNERPrediction() {
130130
for (int i = 0; i < FLAGS_repeat; i++) {
131131
predictor->Run(input_slots, &outputs);
132132
}
133-
LOG(INFO) << "===========profile result===========";
134-
LOG(INFO) << "batch_size: " << FLAGS_batch_size
135-
<< ", repeat: " << FLAGS_repeat
136-
<< ", latency: " << timer.toc() / FLAGS_repeat << "ms";
137-
LOG(INFO) << "=====================================";
133+
PrintTime(FLAGS_batch_size, FLAGS_repeat, 1, 0, timer.toc() / FLAGS_repeat);
138134

139135
PADDLE_ENFORCE(outputs.size(), 1UL);
140136
auto &out = outputs[0];

paddle/fluid/inference/analysis/test_text_classification.cc

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,16 @@
1818
#include "paddle/fluid/framework/ir/pass.h"
1919
#include "paddle/fluid/inference/analysis/analyzer.h"
2020
#include "paddle/fluid/inference/analysis/ut_helper.h"
21+
#include "paddle/fluid/inference/api/helper.h"
2122
#include "paddle/fluid/inference/api/paddle_inference_api.h"
22-
#include "paddle/fluid/inference/api/timer.h"
2323

2424
DEFINE_string(infer_model, "", "Directory of the inference model.");
2525
DEFINE_string(infer_data, "", "Path of the dataset.");
2626
DEFINE_int32(batch_size, 1, "batch size.");
2727
DEFINE_int32(repeat, 1, "How many times to repeat run.");
2828

2929
namespace paddle {
30-
31-
template <typename T>
32-
std::string to_string(const std::vector<T> &vec) {
33-
std::stringstream ss;
34-
for (const auto &c : vec) {
35-
ss << c << " ";
36-
}
37-
return ss.str();
38-
}
39-
40-
void PrintTime(const double latency, const int bs, const int repeat) {
41-
LOG(INFO) << "===========profile result===========";
42-
LOG(INFO) << "batch_size: " << bs << ", repeat: " << repeat
43-
<< ", avg latency: " << latency / repeat << "ms";
44-
LOG(INFO) << "=====================================";
45-
}
30+
namespace inference {
4631

4732
void Main(int batch_size) {
4833
// Three sequence inputs.
@@ -78,7 +63,7 @@ void Main(int batch_size) {
7863
CHECK(predictor->Run(input_slots, &output_slots));
7964
sum += timer.toc();
8065
}
81-
PrintTime(sum, batch_size, FLAGS_repeat);
66+
PrintTime(batch_size, FLAGS_repeat, 1, 0, sum / FLAGS_repeat);
8267

8368
// Get output
8469
LOG(INFO) << "get outputs " << output_slots.size();
@@ -99,6 +84,7 @@ void Main(int batch_size) {
9984

10085
TEST(text_classification, basic) { Main(FLAGS_batch_size); }
10186

87+
} // namespace inference
10288
} // namespace paddle
10389

10490
USE_PASS(fc_fuse_pass);

0 commit comments

Comments
 (0)