Skip to content

[Dy2St][tests][51, 52] paddle.jit.enable_to_static->enable_to_static_guard #60079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion test/dygraph_to_static/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def foo_func(a, b, c=1, d=2):

class TestDifferentInputSpecCacheProgram(Dy2StTestBase):
def setUp(self):
paddle.jit.enable_to_static(True)
pass
Comment on lines 237 to +238
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setUp 可以直接删,之后哪个 PR 改一下吧


@test_ast_only
@test_legacy_and_pt_and_pir
Expand Down
27 changes: 15 additions & 12 deletions test/dygraph_to_static/test_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ def setUp(self):
def init_dygraph_func(self):
self.dygraph_func = test_return_if

def _run(self, to_static=False):
paddle.jit.enable_to_static(to_static)
def _run(self):
with base.dygraph.guard():
res = self.dygraph_func(self.input)
if isinstance(res, (tuple, list)):
Expand All @@ -345,8 +344,10 @@ def _run(self, to_static=False):
return res

def _test_value_impl(self):
dygraph_res = self._run(to_static=False)
static_res = self._run(to_static=True)
with enable_to_static_guard(False):
dygraph_res = self._run()
with enable_to_static_guard(True):
static_res = self._run()
if isinstance(dygraph_res, tuple):
self.assertTrue(isinstance(static_res, tuple))
self.assertEqual(len(dygraph_res), len(static_res))
Expand Down Expand Up @@ -393,8 +394,7 @@ def setUp(self):
def init_dygraph_func(self):
self.dygraph_func = test_return_in_while

def _run(self, to_static=False):
paddle.jit.enable_to_static(to_static)
def _run(self):
with base.dygraph.guard():
res = self.dygraph_func(self.input)
if isinstance(res, (tuple, list)):
Expand All @@ -404,8 +404,10 @@ def _run(self, to_static=False):
return res

def _test_value_impl(self):
dygraph_res = self._run(to_static=False)
static_res = self._run(to_static=True)
with enable_to_static_guard(False):
dygraph_res = self._run()
with enable_to_static_guard(True):
static_res = self._run()
if isinstance(dygraph_res, tuple):
self.assertTrue(isinstance(static_res, tuple))
self.assertEqual(len(dygraph_res), len(static_res))
Expand Down Expand Up @@ -447,8 +449,7 @@ def setUp(self):
def init_dygraph_func(self):
self.dygraph_func = test_return_if_else

def _run(self, to_static=False):
paddle.jit.enable_to_static(to_static)
def _run(self):
with base.dygraph.guard():
res = self.dygraph_func(self.input)
if isinstance(res, (tuple, list)):
Expand All @@ -458,8 +459,10 @@ def _run(self, to_static=False):
return res

def _test_value_impl(self):
dygraph_res = self._run(to_static=False)
static_res = self._run(to_static=True)
with enable_to_static_guard(False):
dygraph_res = self._run()
with enable_to_static_guard(True):
static_res = self._run()
if isinstance(dygraph_res, tuple):
self.assertTrue(isinstance(static_res, tuple))
self.assertEqual(len(dygraph_res), len(static_res))
Expand Down