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