Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/dygraph_to_static/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_bool_variable(self):
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
Expand Down
2 changes: 2 additions & 0 deletions test/dygraph_to_static/test_ast_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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,
Expand Down Expand Up @@ -60,6 +61,7 @@ def test_ast2func_dygraph(self):
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()

Expand Down
3 changes: 3 additions & 0 deletions test/dygraph_to_static/test_backward_without_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import unittest

import numpy as np
from dygraph_to_static_util import test_and_compare_with_new_ir

import paddle

Expand All @@ -30,6 +31,7 @@ def forward(self, x):


class TestBackwardWithoutParams(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test_run(self):
net = Net()

Expand All @@ -54,6 +56,7 @@ def forward(self, x):


class TestZeroSizeNet(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test_run(self):
net = ZeroSizeNet()
x = paddle.ones([2, 2])
Expand Down
28 changes: 18 additions & 10 deletions test/dygraph_to_static/test_basic_api_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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
Expand Down Expand Up @@ -91,6 +92,7 @@ def get_dygraph_output(self):
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
Expand All @@ -100,13 +102,13 @@ def get_static_output(self):
exe = fluid.Executor(self.place)
static_res = exe.run(main_program, fetch_list=static_out)

return static_res[0]
return static_res

def test_transformed_static_result(self):
for func in self.test_funcs:
self.dygraph_func = func
dygraph_res = self.get_dygraph_output()
static_res = self.get_static_output()
static_res = self.get_static_output()[0]
Comment thread
kangguangli marked this conversation as resolved.
Outdated
np.testing.assert_allclose(dygraph_res, static_res, rtol=1e-05)


Expand Down Expand Up @@ -245,6 +247,7 @@ def get_dygraph_output(self):

return res

@test_and_compare_with_new_ir(True)
def get_static_output(self):
startup_program = fluid.Program()
startup_program.random_seed = SEED
Expand All @@ -257,11 +260,11 @@ def get_static_output(self):
exe = fluid.Executor(fluid.CPUPlace())
exe.run(startup_program)
static_res = exe.run(main_program, fetch_list=static_out)
return static_res[0]
return static_res

def test_transformed_static_result(self):
dygraph_res = self.get_dygraph_output()
static_res = self.get_static_output()
static_res = self.get_static_output()[0]
np.testing.assert_allclose(dygraph_res, static_res, rtol=1e-05)


Expand All @@ -278,6 +281,7 @@ def get_dygraph_output(self):
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
Expand All @@ -291,7 +295,7 @@ def get_static_output(self):
exe = fluid.Executor(fluid.CPUPlace())
exe.run(startup_program)
static_res = exe.run(main_program, fetch_list=static_out)
return static_res[0]
return static_res


class TestDygraphBasicApi_Conv2D(TestDygraphBasicApi):
Expand Down Expand Up @@ -403,6 +407,7 @@ def get_dygraph_output(self):
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
Expand All @@ -414,11 +419,11 @@ def get_static_output(self):
exe = fluid.Executor(fluid.CPUPlace())
exe.run(startup_program)
static_res = exe.run(main_program, fetch_list=static_out)
return static_res[0]
return static_res

def test_transformed_static_result(self):
dygraph_res = self.get_dygraph_output()
static_res = self.get_static_output()
static_res = self.get_static_output()[0]
np.testing.assert_allclose(dygraph_res, static_res, rtol=1e-05)


Expand All @@ -433,6 +438,7 @@ def get_dygraph_output(self):
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
Expand All @@ -445,7 +451,7 @@ def get_static_output(self):
exe = fluid.Executor(fluid.CPUPlace())
exe.run(startup_program)
static_res = exe.run(main_program, fetch_list=static_out)
return static_res[0]
return static_res


class TestDygraphBasicApi_InverseTimeDecay(TestDygraphBasicApi_CosineDecay):
Expand All @@ -459,6 +465,7 @@ def get_dygraph_output(self):
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
Expand All @@ -471,7 +478,7 @@ def get_static_output(self):
exe = fluid.Executor(fluid.CPUPlace())
exe.run(startup_program)
static_res = exe.run(main_program, fetch_list=static_out)
return static_res[0]
return static_res


class TestDygraphBasicApi_NaturalExpDecay(TestDygraphBasicApi_CosineDecay):
Expand All @@ -485,6 +492,7 @@ def get_dygraph_output(self):
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
Expand All @@ -497,7 +505,7 @@ def get_static_output(self):
exe = fluid.Executor(fluid.CPUPlace())
exe.run(startup_program)
static_res = exe.run(main_program, fetch_list=static_out)
return static_res[0]
return static_res


class TestDygraphBasicApi_NoamDecay(TestDygraphBasicApi_CosineDecay):
Expand Down
2 changes: 2 additions & 0 deletions test/dygraph_to_static/test_cinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import unittest

import numpy as np
from dygraph_to_static_util import test_and_compare_with_new_ir

import paddle

Expand Down Expand Up @@ -78,6 +79,7 @@ def train(self, use_cinn):

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)
Expand Down
7 changes: 6 additions & 1 deletion test/dygraph_to_static/test_cinn_prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,6 +173,7 @@ def test_cinn_prim(self):


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')
Expand Down
6 changes: 6 additions & 0 deletions test/dygraph_to_static/test_closure_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import unittest

from dygraph_to_static_util import test_and_compare_with_new_ir
from numpy import append

import paddle
Expand Down Expand Up @@ -260,6 +261,7 @@ def init_dygraph_func(self):


class TestPushPopTrans(unittest.TestCase):
@test_and_compare_with_new_ir(False)
def test(self):
def vlist_of_dict(x):
ma = {'a': []}
Expand All @@ -271,6 +273,7 @@ def vlist_of_dict(x):
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

Expand All @@ -284,6 +287,7 @@ def vlist_of_dict(x):
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

Expand All @@ -297,6 +301,7 @@ def vlist_of_dict(x):
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

Expand All @@ -310,6 +315,7 @@ def vlist_of_dict(x):
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

Expand Down
3 changes: 2 additions & 1 deletion test/dygraph_to_static/test_convert_call_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions test/dygraph_to_static/test_cpu_cuda_to_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ast_only_test,
dy2static_unittest,
sot_only_test,
test_and_compare_with_new_ir,
)

import paddle
Expand All @@ -38,6 +39,7 @@ def func(x):


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)
Expand All @@ -57,6 +59,7 @@ def func(x):
@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])
Expand All @@ -75,6 +78,7 @@ def func(x):
)

@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])
Expand All @@ -96,6 +100,7 @@ def func(x):
@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]])
Expand All @@ -109,6 +114,7 @@ def func(x):
)

@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]])
Expand Down