From 885e88552a2ddb23863e4589fee78af0f537e61e Mon Sep 17 00:00:00 2001 From: Peihan Date: Fri, 17 Jul 2020 10:35:36 +0800 Subject: [PATCH] resolve inference_pass_test input lodtensor case, test=develop (#25541) * refine infer ir pass tests, test=develop * commit to change copy_from_cpu input to np array, test=develop --- .../tests/unittests/ir/inference/inference_pass_test.py | 5 ++++- .../ir/inference/test_conv_elementwise_add2_act_fuse_pass.py | 3 ++- .../ir/inference/test_conv_elementwise_add_act_fuse_pass.py | 3 ++- .../ir/inference/test_conv_elementwise_add_fuse_pass.py | 3 ++- .../ir/inference/test_transpose_flatten_concat_fuse_pass.py | 3 ++- .../inference/test_trt_transpose_flatten_concat_fuse_pass.py | 3 ++- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py b/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py index 0b8ea1f9392..d3a53bbbff9 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py @@ -78,7 +78,10 @@ class InferencePassTest(unittest.TestCase): shape = tensor_shapes[name] shape[0] = 1 tensor = predictor.get_input_tensor(name) - tensor.copy_from_cpu(list(self.feeds.values())[i]) + feed_data = list(self.feeds.values())[i] + tensor.copy_from_cpu(np.array(feed_data)) + if type(feed_data) == fluid.LoDTensor: + tensor.set_lod(feed_data.lod()) predictor.zero_copy_run() diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add2_act_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add2_act_fuse_pass.py index 16979488a61..d6dbd397b90 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add2_act_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add2_act_fuse_pass.py @@ -44,7 +44,8 @@ class ConvElementwiseAdd2ActFusePassTest(InferencePassTest): def test_check_output(self): if core.is_compiled_with_cuda(): - self.check_output_with_option([True]) + use_gpu = True + self.check_output_with_option(use_gpu) if __name__ == "__main__": diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_act_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_act_fuse_pass.py index f4014f7cd42..2e9035420d7 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_act_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_act_fuse_pass.py @@ -46,7 +46,8 @@ class ConvElementwiseAddActFusePassTest(InferencePassTest): def test_check_output(self): if core.is_compiled_with_cuda(): - self.check_output_with_option([True]) + use_gpu = True + self.check_output_with_option(use_gpu) if __name__ == "__main__": diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_fuse_pass.py index cea007d56e4..7c4e0d6e76e 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_conv_elementwise_add_fuse_pass.py @@ -42,7 +42,8 @@ class ConvElementwiseAddFusePassTest(InferencePassTest): def test_check_output(self): if core.is_compiled_with_cuda(): - self.check_output_with_option([True]) + use_gpu = True + self.check_output_with_option(use_gpu) if __name__ == "__main__": diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_transpose_flatten_concat_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_transpose_flatten_concat_fuse_pass.py index 6444264f80f..dfcd1758db2 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_transpose_flatten_concat_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_transpose_flatten_concat_fuse_pass.py @@ -42,7 +42,8 @@ class TransposeFlattenConcatFusePassTest(InferencePassTest): def test_check_output(self): # There is no cpu pass for transpose_flatten_concat_fuse if core.is_compiled_with_cuda(): - self.check_output_with_option([True]) + use_gpu = True + self.check_output_with_option(use_gpu) if __name__ == "__main__": diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_transpose_flatten_concat_fuse_pass.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_transpose_flatten_concat_fuse_pass.py index 41f02b0427d..4661333ffec 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_transpose_flatten_concat_fuse_pass.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_transpose_flatten_concat_fuse_pass.py @@ -48,7 +48,8 @@ class TransposeFlattenConcatFusePassTRTTest(InferencePassTest): def test_check_output(self): # There is no cpu pass for transpose_flatten_concat_fuse if core.is_compiled_with_cuda(): - self.check_output_with_option([True]) + use_gpu = True + self.check_output_with_option(use_gpu) if __name__ == "__main__": -- GitLab