From 3b915741b2c101d64d86fbbfd9419d785a39d17e Mon Sep 17 00:00:00 2001 From: baojun <32073718+baojun-nervana@users.noreply.github.com> Date: Thu, 12 Dec 2019 01:54:50 -0800 Subject: [PATCH] Fix nGraph UT for PY3 - Part I (#21678) * fix test for PY3 test=develop * reduce file changes test=develop --- .../tests/unittests/ngraph/test_accuracy_ngraph_op.py | 5 +++-- .../tests/unittests/ngraph/test_activation_ngraph_op.py | 8 ++++---- .../fluid/tests/unittests/ngraph/test_adam_ngraph_op.py | 5 +++-- .../tests/unittests/ngraph/test_batch_norm_ngraph_op.py | 7 ++++--- .../fluid/tests/unittests/ngraph/test_cast_ngraph_op.py | 5 +++-- .../fluid/tests/unittests/ngraph/test_concat_ngraph_op.py | 5 +++-- .../fluid/tests/unittests/ngraph/test_conv2d_ngraph_op.py | 5 +++-- .../unittests/ngraph/test_cross_entropy_ngraph_op.py | 5 +++-- .../tests/unittests/ngraph/test_dropout_ngraph_op.py | 5 +++-- .../unittests/ngraph/test_elementwise_add_ngraph_op.py | 5 +++-- .../unittests/ngraph/test_fill_constant_ngraph_op.py | 5 +++-- .../unittests/ngraph/test_fill_zeros_like_ngraph_op.py | 5 +++-- .../tests/unittests/ngraph/test_increment_ngraph_op.py | 5 +++-- .../fluid/tests/unittests/ngraph/test_lrn_ngraph_op.py | 5 +++-- .../fluid/tests/unittests/ngraph/test_matmul_ngraph_op.py | 5 +++-- .../fluid/tests/unittests/ngraph/test_mean_ngraph_op.py | 5 +++-- .../tests/unittests/ngraph/test_momentum_ngraph_op.py | 5 +++-- .../fluid/tests/unittests/ngraph/test_mul_ngraph_op.py | 5 +++-- .../fluid/tests/unittests/ngraph/test_pool2d_ngraph_op.py | 6 +++--- 19 files changed, 59 insertions(+), 42 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_accuracy_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_accuracy_ngraph_op.py index 5298c3c2f6f..e837e504a4c 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_accuracy_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_accuracy_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_accuracy_op import TestAccuracyOp +import unittest, sys +sys.path.append("../") +from test_accuracy_op import TestAccuracyOp if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_activation_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_activation_ngraph_op.py index a7f167cbd41..19e1c8cccbe 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_activation_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_activation_ngraph_op.py @@ -14,11 +14,11 @@ from __future__ import print_function -import unittest +import unittest, sys +sys.path.append("../") import numpy as np -import paddle.fluid.core as core -from paddle.fluid.tests.unittests.op_test import OpTest -from paddle.fluid.tests.unittests.test_activation_op import TestAbs, TestGelu, TestSigmoid, TestSquare, TestRelu, TestTanh +from op_test import OpTest +from test_activation_op import TestAbs, TestGelu, TestSigmoid, TestSquare, TestRelu, TestTanh class TestNGRAPHReluDim4(TestRelu): diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_adam_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_adam_ngraph_op.py index ef2aedf65f4..cdba579d8d4 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_adam_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_adam_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_adam_op import TestAdamOp1, TestAdamOp2, TestAdamOpMultipleSteps, TestSparseAdamOp +import unittest, sys +sys.path.append("../") +from test_adam_op import TestAdamOp1, TestAdamOp2, TestAdamOpMultipleSteps, TestSparseAdamOp if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_batch_norm_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_batch_norm_ngraph_op.py index d9198114f3c..a6b6e90551f 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_batch_norm_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_batch_norm_ngraph_op.py @@ -14,9 +14,10 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_batch_norm_op import TestBatchNormOpTraining, TestBatchNormOpInference -from paddle.fluid.tests.unittests.op_test import _set_use_system_allocator +import unittest, sys +sys.path.append("../") +from test_batch_norm_op import TestBatchNormOpTraining, TestBatchNormOpInference +from op_test import _set_use_system_allocator _set_use_system_allocator(True) diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_cast_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_cast_ngraph_op.py index 7732637d229..8b8a52258b5 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_cast_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_cast_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_cast_op import TestCastOp1 +import unittest, sys +sys.path.append("../") +from test_cast_op import TestCastOp1 if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py index 8517f7cc87b..de831703b7e 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_concat_op import TestConcatOp, TestConcatOp2, TestConcatOp3, TestConcatOp4, TestConcatOp5 +import unittest, sys +sys.path.append("../") +from test_concat_op import TestConcatOp, TestConcatOp2, TestConcatOp3, TestConcatOp4, TestConcatOp5 if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_conv2d_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_conv2d_ngraph_op.py index 764d136ec8d..fc2031c4cfc 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_conv2d_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_conv2d_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_conv2d_op import TestConv2dOp, TestWithPad, TestWithStride, TestWithGroup, TestWith1x1, TestWithInput1x1Filter1x1, TestDepthwiseConv, TestDepthwiseConv2, TestDepthwiseConv3, TestDepthwiseConvWithDilation, TestDepthwiseConvWithDilation2 +import unittest, sys +sys.path.append("../") +from test_conv2d_op import TestConv2dOp, TestWithPad, TestWithStride, TestWithGroup, TestWith1x1, TestWithInput1x1Filter1x1, TestDepthwiseConv, TestDepthwiseConv2, TestDepthwiseConv3, TestDepthwiseConvWithDilation, TestDepthwiseConvWithDilation2 class TestNGRAPHDepthwiseConv(TestDepthwiseConv): diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_cross_entropy_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_cross_entropy_ngraph_op.py index 3057218a1d8..2a8edec7e79 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_cross_entropy_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_cross_entropy_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_cross_entropy_op import TestCrossEntropyOp, TestCrossEntropyOp2, TestCrossEntropyOp3, TestCrossEntropyOp4, TestCrossEntropyOp5, TestCrossEntropyOp6, TestCrossEntropyOp7 +import unittest, sys +sys.path.append("../") +from test_cross_entropy_op import TestCrossEntropyOp, TestCrossEntropyOp2, TestCrossEntropyOp3, TestCrossEntropyOp4, TestCrossEntropyOp5, TestCrossEntropyOp6, TestCrossEntropyOp7 if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_dropout_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_dropout_ngraph_op.py index 0448bed1020..484e76a8962 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_dropout_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_dropout_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_dropout_op import TestDropoutOp, TestDropoutOp2, TestDropoutOp3, TestDropoutOp4, TestDropoutOp5, TestDropoutOp6, TestDropoutOp7, TestDropoutOp8, TestDropoutOp9 +import unittest, sys +sys.path.append("../") +from test_dropout_op import TestDropoutOp, TestDropoutOp2, TestDropoutOp3, TestDropoutOp4, TestDropoutOp5, TestDropoutOp6, TestDropoutOp7, TestDropoutOp8, TestDropoutOp9 if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_elementwise_add_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_elementwise_add_ngraph_op.py index 3fb9af3a542..32fef44cd4c 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_elementwise_add_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_elementwise_add_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_elementwise_add_op import TestElementwiseAddOp, TestElementwiseAddOp_broadcast_0 +import unittest, sys +sys.path.append("../") +from test_elementwise_add_op import TestElementwiseAddOp, TestElementwiseAddOp_broadcast_0 if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_fill_constant_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_fill_constant_ngraph_op.py index 2b10b8f7a3a..1ef14b5244d 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_fill_constant_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_fill_constant_ngraph_op.py @@ -14,9 +14,10 @@ from __future__ import print_function -import unittest +import unittest, sys +sys.path.append("../") import numpy as np -from paddle.fluid.tests.unittests.test_fill_constant_op import TestFillConstantOp1, TestFillConstantOp2, TestFillConstantOpWithSelectedRows +from test_fill_constant_op import TestFillConstantOp1, TestFillConstantOp2, TestFillConstantOpWithSelectedRows class TestNGRAPHFillConstantFP64(TestFillConstantOp1): diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_fill_zeros_like_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_fill_zeros_like_ngraph_op.py index 45e6af7f961..32f72ada815 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_fill_zeros_like_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_fill_zeros_like_ngraph_op.py @@ -13,8 +13,9 @@ # limitations under the License. from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_fill_zeros_like_op import TestFillZerosLikeOp +import unittest, sys +sys.path.append("../") +from test_fill_zeros_like_op import TestFillZerosLikeOp if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_increment_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_increment_ngraph_op.py index 9e1013fa822..33e9520d005 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_increment_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_increment_ngraph_op.py @@ -14,9 +14,10 @@ from __future__ import print_function -import unittest +import unittest, sys +sys.path.append("../") import numpy as np -from paddle.fluid.tests.unittests.op_test import OpTest +from op_test import OpTest class TestNGRAPHIncrementOp(OpTest): diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_lrn_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_lrn_ngraph_op.py index 4c998c6ca2e..88d9e9c86f4 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_lrn_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_lrn_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_lrn_op import TestLRNOp +import unittest, sys +sys.path.append("../") +from test_lrn_op import TestLRNOp class TestLRNNGRAPHOp(TestLRNOp): diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_matmul_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_matmul_ngraph_op.py index 4bb28529d87..4c5772c5f0e 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_matmul_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_matmul_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_matmul_op import * +import unittest, sys +sys.path.append("../") +from test_matmul_op import * if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_mean_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_mean_ngraph_op.py index b4894734cbc..0ac0e72ac70 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_mean_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_mean_ngraph_op.py @@ -13,8 +13,9 @@ # limitations under the License. from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_mean_op import TestMeanOp +import unittest, sys +sys.path.append("../") +from test_mean_op import TestMeanOp if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_momentum_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_momentum_ngraph_op.py index 2c3549d907f..1bbcbfb2fe7 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_momentum_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_momentum_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_momentum_op import TestMomentumOp1, TestMomentumOp2, TestLarsMomentumOp, TestSparseMomentumOp, TestSparseMomentumOp2 +import unittest, sys +sys.path.append("../") +from test_momentum_op import TestMomentumOp1, TestMomentumOp2, TestLarsMomentumOp, TestSparseMomentumOp, TestSparseMomentumOp2 if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_mul_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_mul_ngraph_op.py index 549d03f6e92..412127af701 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_mul_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_mul_ngraph_op.py @@ -14,8 +14,9 @@ from __future__ import print_function -import unittest -from paddle.fluid.tests.unittests.test_mul_op import TestMulOp, TestMulOp2 +import unittest, sys +sys.path.append("../") +from test_mul_op import TestMulOp, TestMulOp2 if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_pool2d_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_pool2d_ngraph_op.py index ff82e9fa1d3..5ce46fbf573 100644 --- a/python/paddle/fluid/tests/unittests/ngraph/test_pool2d_ngraph_op.py +++ b/python/paddle/fluid/tests/unittests/ngraph/test_pool2d_ngraph_op.py @@ -14,9 +14,9 @@ from __future__ import print_function -import unittest - -from paddle.fluid.tests.unittests.test_pool2d_op import TestPool2D_Op, TestCase1, TestCase2, TestCase3, TestCase4, TestCase5 +import unittest, sys +sys.path.append("../") +from test_pool2d_op import TestPool2D_Op, TestCase1, TestCase2, TestCase3, TestCase4, TestCase5 class TestNGRAPHCeilMode(TestCase1): -- GitLab