未验证 提交 0213a19c 编写于 作者: Y yangguohao 提交者: GitHub

【NewIR】enable dy2st new IR test (#56631)

* enable dy2st newIR test

* fix 2023-08-29

* fix_2
上级 17e4be21
...@@ -153,18 +153,17 @@ def test_and_compare_with_new_ir(need_check_output: bool = True): ...@@ -153,18 +153,17 @@ def test_and_compare_with_new_ir(need_check_output: bool = True):
ir_outs = test_with_new_ir(func)(*args, **kwargs) ir_outs = test_with_new_ir(func)(*args, **kwargs)
if not need_check_output: if not need_check_output:
return outs return outs
for i in range(len(outs)):
np.testing.assert_array_equal( np.testing.assert_array_equal(
outs[i], outs,
ir_outs[i], ir_outs,
err_msg='Dy2St Unittest Check (' err_msg='Dy2St Unittest Check ('
+ func.__name__ + func.__name__
+ ') has diff ' + ') has diff '
+ '\nExpect ' + '\nExpect '
+ str(outs[i]) + str(outs)
+ '\n' + '\n'
+ 'But Got' + 'But Got'
+ str(ir_outs[i]), + str(ir_outs),
) )
return outs return outs
......
...@@ -66,6 +66,7 @@ class TestAssertVariable(unittest.TestCase): ...@@ -66,6 +66,7 @@ class TestAssertVariable(unittest.TestCase):
dyfunc_assert_variable, x=numpy.array([True]), with_exception=False dyfunc_assert_variable, x=numpy.array([True]), with_exception=False
) )
@test_and_compare_with_new_ir(False)
def test_int_variable(self): def test_int_variable(self):
self._run_dy_static( self._run_dy_static(
dyfunc_assert_variable, x=numpy.array([0]), with_exception=True dyfunc_assert_variable, x=numpy.array([0]), with_exception=True
......
...@@ -17,6 +17,7 @@ import textwrap ...@@ -17,6 +17,7 @@ import textwrap
import unittest import unittest
import numpy as np import numpy as np
from dygraph_to_static_util import test_and_compare_with_new_ir
from ifelse_simple_func import ( from ifelse_simple_func import (
dyfunc_with_if_else, dyfunc_with_if_else,
dyfunc_with_if_else2, dyfunc_with_if_else2,
...@@ -60,6 +61,7 @@ class TestAST2Func(unittest.TestCase): ...@@ -60,6 +61,7 @@ class TestAST2Func(unittest.TestCase):
test_ret = self._ast2func(func)(x_v).numpy() test_ret = self._ast2func(func)(x_v).numpy()
self.assertTrue((true_ret == test_ret).all()) self.assertTrue((true_ret == test_ret).all())
@test_and_compare_with_new_ir(False)
def test_ast2func_static(self): def test_ast2func_static(self):
paddle.enable_static() paddle.enable_static()
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from dygraph_to_static_util import test_and_compare_with_new_ir
import paddle import paddle
...@@ -30,6 +31,7 @@ class Net(paddle.nn.Layer): ...@@ -30,6 +31,7 @@ class Net(paddle.nn.Layer):
class TestBackwardWithoutParams(unittest.TestCase): class TestBackwardWithoutParams(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test_run(self): def test_run(self):
net = Net() net = Net()
...@@ -54,6 +56,7 @@ class ZeroSizeNet(paddle.nn.Layer): ...@@ -54,6 +56,7 @@ class ZeroSizeNet(paddle.nn.Layer):
class TestZeroSizeNet(unittest.TestCase): class TestZeroSizeNet(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test_run(self): def test_run(self):
net = ZeroSizeNet() net = ZeroSizeNet()
x = paddle.ones([2, 2]) x = paddle.ones([2, 2])
......
...@@ -16,6 +16,7 @@ import inspect ...@@ -16,6 +16,7 @@ import inspect
import unittest import unittest
import numpy as np import numpy as np
from dygraph_to_static_util import test_and_compare_with_new_ir
import paddle import paddle
from paddle import fluid, to_tensor from paddle import fluid, to_tensor
...@@ -91,6 +92,7 @@ class TestDygraphBasicApi_ToVariable(unittest.TestCase): ...@@ -91,6 +92,7 @@ class TestDygraphBasicApi_ToVariable(unittest.TestCase):
res = self.dygraph_func(self.input).numpy() res = self.dygraph_func(self.input).numpy()
return res return res
@test_and_compare_with_new_ir(True)
def get_static_output(self): def get_static_output(self):
main_program = fluid.Program() main_program = fluid.Program()
main_program.random_seed = SEED main_program.random_seed = SEED
...@@ -245,6 +247,7 @@ class TestDygraphBasicApi(unittest.TestCase): ...@@ -245,6 +247,7 @@ class TestDygraphBasicApi(unittest.TestCase):
return res return res
@test_and_compare_with_new_ir(True)
def get_static_output(self): def get_static_output(self):
startup_program = fluid.Program() startup_program = fluid.Program()
startup_program.random_seed = SEED startup_program.random_seed = SEED
...@@ -278,6 +281,7 @@ class TestDygraphBasicApi_BilinearTensorProduct(TestDygraphBasicApi): ...@@ -278,6 +281,7 @@ class TestDygraphBasicApi_BilinearTensorProduct(TestDygraphBasicApi):
res = self.dygraph_func(self.input1, self.input2).numpy() res = self.dygraph_func(self.input1, self.input2).numpy()
return res return res
@test_and_compare_with_new_ir(True)
def get_static_output(self): def get_static_output(self):
startup_program = fluid.Program() startup_program = fluid.Program()
startup_program.random_seed = SEED startup_program.random_seed = SEED
...@@ -403,6 +407,7 @@ class TestDygraphBasicApi_CosineDecay(unittest.TestCase): ...@@ -403,6 +407,7 @@ class TestDygraphBasicApi_CosineDecay(unittest.TestCase):
res = self.dygraph_func().numpy() res = self.dygraph_func().numpy()
return res return res
@test_and_compare_with_new_ir(True)
def get_static_output(self): def get_static_output(self):
startup_program = fluid.Program() startup_program = fluid.Program()
startup_program.random_seed = SEED startup_program.random_seed = SEED
...@@ -433,6 +438,7 @@ class TestDygraphBasicApi_ExponentialDecay(TestDygraphBasicApi_CosineDecay): ...@@ -433,6 +438,7 @@ class TestDygraphBasicApi_ExponentialDecay(TestDygraphBasicApi_CosineDecay):
res = self.dygraph_func() res = self.dygraph_func()
return res return res
@test_and_compare_with_new_ir(True)
def get_static_output(self): def get_static_output(self):
startup_program = fluid.Program() startup_program = fluid.Program()
startup_program.random_seed = SEED startup_program.random_seed = SEED
...@@ -459,6 +465,7 @@ class TestDygraphBasicApi_InverseTimeDecay(TestDygraphBasicApi_CosineDecay): ...@@ -459,6 +465,7 @@ class TestDygraphBasicApi_InverseTimeDecay(TestDygraphBasicApi_CosineDecay):
res = self.dygraph_func() res = self.dygraph_func()
return res return res
@test_and_compare_with_new_ir(True)
def get_static_output(self): def get_static_output(self):
startup_program = fluid.Program() startup_program = fluid.Program()
startup_program.random_seed = SEED startup_program.random_seed = SEED
...@@ -485,6 +492,7 @@ class TestDygraphBasicApi_NaturalExpDecay(TestDygraphBasicApi_CosineDecay): ...@@ -485,6 +492,7 @@ class TestDygraphBasicApi_NaturalExpDecay(TestDygraphBasicApi_CosineDecay):
res = self.dygraph_func() res = self.dygraph_func()
return res return res
@test_and_compare_with_new_ir(True)
def get_static_output(self): def get_static_output(self):
startup_program = fluid.Program() startup_program = fluid.Program()
startup_program.random_seed = SEED startup_program.random_seed = SEED
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import unittest import unittest
import numpy as np import numpy as np
from dygraph_to_static_util import test_and_compare_with_new_ir
import paddle import paddle
...@@ -78,6 +79,7 @@ class TestCINN(unittest.TestCase): ...@@ -78,6 +79,7 @@ class TestCINN(unittest.TestCase):
return res return res
@test_and_compare_with_new_ir(False)
def test_cinn(self): def test_cinn(self):
dy_res = self.train(use_cinn=False) dy_res = self.train(use_cinn=False)
cinn_res = self.train(use_cinn=True) cinn_res = self.train(use_cinn=True)
......
...@@ -15,7 +15,11 @@ ...@@ -15,7 +15,11 @@
import unittest import unittest
import numpy as np import numpy as np
from dygraph_to_static_util import ast_only_test, dy2static_unittest from dygraph_to_static_util import (
ast_only_test,
dy2static_unittest,
test_and_compare_with_new_ir,
)
import paddle import paddle
import paddle.nn.functional as F import paddle.nn.functional as F
...@@ -169,6 +173,7 @@ class TestPrimForwardAndBackward(unittest.TestCase): ...@@ -169,6 +173,7 @@ class TestPrimForwardAndBackward(unittest.TestCase):
class TestBackend(unittest.TestCase): class TestBackend(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test_backend(self): def test_backend(self):
x = paddle.randn([2, 4]) x = paddle.randn([2, 4])
out1 = self.forward(x, 'CINN') out1 = self.forward(x, 'CINN')
......
...@@ -16,6 +16,7 @@ import inspect ...@@ -16,6 +16,7 @@ import inspect
import os import os
import unittest import unittest
from dygraph_to_static_util import test_and_compare_with_new_ir
from numpy import append from numpy import append
import paddle import paddle
...@@ -260,6 +261,7 @@ class TestClosureAnalysis_PushPop(TestClosureAnalysis): ...@@ -260,6 +261,7 @@ class TestClosureAnalysis_PushPop(TestClosureAnalysis):
class TestPushPopTrans(unittest.TestCase): class TestPushPopTrans(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test(self): def test(self):
def vlist_of_dict(x): def vlist_of_dict(x):
ma = {'a': []} ma = {'a': []}
...@@ -271,6 +273,7 @@ class TestPushPopTrans(unittest.TestCase): ...@@ -271,6 +273,7 @@ class TestPushPopTrans(unittest.TestCase):
print(paddle.jit.to_static(vlist_of_dict).code) print(paddle.jit.to_static(vlist_of_dict).code)
print(paddle.jit.to_static(vlist_of_dict)(x)) print(paddle.jit.to_static(vlist_of_dict)(x))
@test_and_compare_with_new_ir(False)
def test2(self): def test2(self):
import numpy as np import numpy as np
...@@ -284,6 +287,7 @@ class TestPushPopTrans(unittest.TestCase): ...@@ -284,6 +287,7 @@ class TestPushPopTrans(unittest.TestCase):
print(paddle.jit.to_static(vlist_of_dict).code) print(paddle.jit.to_static(vlist_of_dict).code)
print(paddle.jit.to_static(vlist_of_dict)(x)) print(paddle.jit.to_static(vlist_of_dict)(x))
@test_and_compare_with_new_ir(False)
def test3(self): def test3(self):
import numpy as np import numpy as np
...@@ -297,6 +301,7 @@ class TestPushPopTrans(unittest.TestCase): ...@@ -297,6 +301,7 @@ class TestPushPopTrans(unittest.TestCase):
print(paddle.jit.to_static(vlist_of_dict).code) print(paddle.jit.to_static(vlist_of_dict).code)
print(paddle.jit.to_static(vlist_of_dict)(x)) print(paddle.jit.to_static(vlist_of_dict)(x))
@test_and_compare_with_new_ir(False)
def test4(self): def test4(self):
import numpy as np import numpy as np
...@@ -310,6 +315,7 @@ class TestPushPopTrans(unittest.TestCase): ...@@ -310,6 +315,7 @@ class TestPushPopTrans(unittest.TestCase):
print(paddle.jit.to_static(vlist_of_dict).code) print(paddle.jit.to_static(vlist_of_dict).code)
print(paddle.jit.to_static(vlist_of_dict)(x)) print(paddle.jit.to_static(vlist_of_dict)(x))
@test_and_compare_with_new_ir(False)
def test5(self): def test5(self):
import numpy as np import numpy as np
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
import unittest import unittest
from dygraph_to_static_util import ast_only_test from dygraph_to_static_util import ast_only_test, test_and_compare_with_new_ir
import paddle import paddle
from paddle.jit import to_static from paddle.jit import to_static
...@@ -35,6 +35,7 @@ def main_func(): ...@@ -35,6 +35,7 @@ def main_func():
class TestConvertGenerator(unittest.TestCase): class TestConvertGenerator(unittest.TestCase):
# fallback will ok. # fallback will ok.
@ast_only_test @ast_only_test
@test_and_compare_with_new_ir(False)
def test_raise_error(self): def test_raise_error(self):
translator_logger.verbosity_level = 1 translator_logger.verbosity_level = 1
with self.assertLogs( with self.assertLogs(
......
...@@ -19,6 +19,7 @@ from dygraph_to_static_util import ( ...@@ -19,6 +19,7 @@ from dygraph_to_static_util import (
ast_only_test, ast_only_test,
dy2static_unittest, dy2static_unittest,
sot_only_test, sot_only_test,
test_and_compare_with_new_ir,
) )
import paddle import paddle
...@@ -38,6 +39,7 @@ class TestCpuCuda(unittest.TestCase): ...@@ -38,6 +39,7 @@ class TestCpuCuda(unittest.TestCase):
class TestToTensor(unittest.TestCase): class TestToTensor(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test_to_tensor_with_variable_list(self): def test_to_tensor_with_variable_list(self):
def func(x): def func(x):
ones = paddle.to_tensor(1) ones = paddle.to_tensor(1)
...@@ -57,6 +59,7 @@ class TestToTensor(unittest.TestCase): ...@@ -57,6 +59,7 @@ class TestToTensor(unittest.TestCase):
@dy2static_unittest @dy2static_unittest
class TestToTensor1(unittest.TestCase): class TestToTensor1(unittest.TestCase):
@ast_only_test @ast_only_test
@test_and_compare_with_new_ir(False)
def test_to_tensor_with_variable_list(self): def test_to_tensor_with_variable_list(self):
def func(x): def func(x):
ones = paddle.to_tensor([1]) ones = paddle.to_tensor([1])
...@@ -75,6 +78,7 @@ class TestToTensor1(unittest.TestCase): ...@@ -75,6 +78,7 @@ class TestToTensor1(unittest.TestCase):
) )
@sot_only_test @sot_only_test
@test_and_compare_with_new_ir(False)
def test_to_tensor_with_variable_list_sot(self): def test_to_tensor_with_variable_list_sot(self):
def func(x): def func(x):
ones = paddle.to_tensor([1]) ones = paddle.to_tensor([1])
...@@ -96,6 +100,7 @@ class TestToTensor1(unittest.TestCase): ...@@ -96,6 +100,7 @@ class TestToTensor1(unittest.TestCase):
@dy2static_unittest @dy2static_unittest
class TestToTensor2(unittest.TestCase): class TestToTensor2(unittest.TestCase):
@ast_only_test @ast_only_test
@test_and_compare_with_new_ir(False)
def test_to_tensor_with_variable_list(self): def test_to_tensor_with_variable_list(self):
def func(x): def func(x):
x = paddle.to_tensor([[1], [2], [3], [4]]) x = paddle.to_tensor([[1], [2], [3], [4]])
...@@ -109,6 +114,7 @@ class TestToTensor2(unittest.TestCase): ...@@ -109,6 +114,7 @@ class TestToTensor2(unittest.TestCase):
) )
@sot_only_test @sot_only_test
@test_and_compare_with_new_ir(False)
def test_to_tensor_with_variable_list_sot(self): def test_to_tensor_with_variable_list_sot(self):
def func(x): def func(x):
x = paddle.to_tensor([[1], [2], [3], [4]]) x = paddle.to_tensor([[1], [2], [3], [4]])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册