26
26
#include " paddle/fluid/inference/api/paddle_inference_pass.h"
27
27
#include " paddle/fluid/inference/utils/singleton.h"
28
28
29
- DEFINE_string (infer_ditu_rnn_model , " " , " model path for ditu RNN " );
30
- DEFINE_string (infer_ditu_rnn_data , " " , " data path for ditu RNN " );
29
+ DEFINE_string (infer_model , " " , " model path" );
30
+ DEFINE_string (infer_data , " " , " data path" );
31
31
DEFINE_int32 (batch_size, 10 , " batch size." );
32
32
DEFINE_int32 (repeat, 1 , " Running the inference program repeat times." );
33
33
DEFINE_int32 (num_threads, 1 , " Running the inference program in multi-threads." );
@@ -223,17 +223,6 @@ void PrepareInputs(std::vector<PaddleTensor> *input_slots, DataRecord *data,
223
223
224
224
} // namespace
225
225
226
- const float ditu_rnn_target_data[] = {
227
- 104.711 , 11.2431 , 1.35422 , 0 , 0 , 0 , 0 , 0 ,
228
- 27.7039 , 1.41486 , 7.09526 , 0 , 0 , 0 , 0 , 0 ,
229
- 7.6481 , 6.5324 , 56.383 , 2.88018 , 8.92918 , 132.007 , 4.27429 , 2.02934 ,
230
- 14.1727 , 10.7461 , 25.0616 , 16.0197 , 14.4163 , 16.9199 , 6.75517 , 0 ,
231
- 80.0249 , 4.77739 , 0 , 0 , 0 , 0 , 0 , 0 ,
232
- 47.5643 , 2.67029 , 8.76252 , 0 , 0 , 0 , 0 , 0 ,
233
- 51.8822 , 4.4411 , 0 , 0 , 0 , 0 , 0 , 0 ,
234
- 10.7286 , 12.0595 , 10.6672 , 0 , 0 , 0 , 0 , 0 ,
235
- 93.5771 , 3.84641 , 0 , 0 , 0 , 0 , 0 , 0 ,
236
- 169.426 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
237
226
void CompareResult (const std::vector<PaddleTensor> &outputs,
238
227
const std::vector<PaddleTensor> &base_outputs) {
239
228
PADDLE_ENFORCE_GT (outputs.size (), 0 );
@@ -255,11 +244,10 @@ void CompareResult(const std::vector<PaddleTensor> &outputs,
255
244
}
256
245
}
257
246
// Test with a really complicate model.
258
- void TestDituRNNPrediction (bool use_analysis, bool activate_ir,
259
- int num_threads) {
247
+ void TestRNN1Prediction (bool use_analysis, bool activate_ir, int num_threads) {
260
248
AnalysisConfig config;
261
- config.prog_file = FLAGS_infer_ditu_rnn_model + " /__model__" ;
262
- config.param_file = FLAGS_infer_ditu_rnn_model + " /param" ;
249
+ config.prog_file = FLAGS_infer_model + " /__model__" ;
250
+ config.param_file = FLAGS_infer_model + " /param" ;
263
251
config.use_gpu = false ;
264
252
config.device = 0 ;
265
253
config.specify_input_name = true ;
@@ -277,7 +265,7 @@ void TestDituRNNPrediction(bool use_analysis, bool activate_ir,
277
265
CreatePaddlePredictor<AnalysisConfig, PaddleEngineKind::kAnalysis >(
278
266
config);
279
267
std::vector<PaddleTensor> input_slots;
280
- DataRecord data (FLAGS_infer_ditu_rnn_data , batch_size);
268
+ DataRecord data (FLAGS_infer_data , batch_size);
281
269
// Prepare inputs.
282
270
PrepareInputs (&input_slots, &data, batch_size);
283
271
std::vector<PaddleTensor> outputs, base_outputs;
@@ -307,7 +295,7 @@ void TestDituRNNPrediction(bool use_analysis, bool activate_ir,
307
295
threads.emplace_back ([&, tid]() {
308
296
// Each thread should have local input_slots and outputs.
309
297
std::vector<PaddleTensor> input_slots;
310
- DataRecord data (FLAGS_infer_ditu_rnn_data , batch_size);
298
+ DataRecord data (FLAGS_infer_data , batch_size);
311
299
PrepareInputs (&input_slots, &data, batch_size);
312
300
std::vector<PaddleTensor> outputs;
313
301
Timer timer;
@@ -354,24 +342,22 @@ void TestDituRNNPrediction(bool use_analysis, bool activate_ir,
354
342
}
355
343
356
344
// Inference with analysis and IR, easy for profiling independently.
357
- TEST (Analyzer, DituRNN) {
358
- TestDituRNNPrediction (true , true , FLAGS_num_threads);
359
- }
345
+ TEST (Analyzer, rnn1) { TestRNN1Prediction (true , true , FLAGS_num_threads); }
360
346
361
- // Other unit-tests of DituRNN , test different options of use_analysis,
347
+ // Other unit-tests of RNN1 , test different options of use_analysis,
362
348
// activate_ir and multi-threads.
363
- TEST (Analyzer, DituRNN_tests ) {
349
+ TEST (Analyzer, RNN_tests ) {
364
350
int num_threads[2 ] = {1 , 4 };
365
351
for (auto i : num_threads) {
366
352
// Directly infer with the original model.
367
- TestDituRNNPrediction (false , false , i);
353
+ TestRNN1Prediction (false , false , i);
368
354
// Inference with the original model with the analysis turned on, the
369
355
// analysis
370
356
// module will transform the program to a data flow graph.
371
- TestDituRNNPrediction (true , false , i);
357
+ TestRNN1Prediction (true , false , i);
372
358
// Inference with analysis and IR. The IR module will fuse some large
373
359
// kernels.
374
- TestDituRNNPrediction (true , true , i);
360
+ TestRNN1Prediction (true , true , i);
375
361
}
376
362
}
377
363
0 commit comments