未验证 提交 efccf896 编写于 作者: A Aurelius84 提交者: GitHub

[Dy2Stat]Filter UserWarings while @to_static (#45754)

* [Dy2Stat]Filter UserWarings while @to_static

* only filter DeprecationWarning

* fix unittest
上级 b1f1dd05
...@@ -609,7 +609,8 @@ def _inject_import_statements(): ...@@ -609,7 +609,8 @@ def _inject_import_statements():
import_statements = [ import_statements = [
"import paddle", "from paddle import Tensor", "import paddle", "from paddle import Tensor",
"import paddle.fluid as fluid", "import paddle.jit.dy2static as _jst", "import paddle.fluid as fluid", "import paddle.jit.dy2static as _jst",
"from typing import *", "import numpy as np" "from typing import *", "import numpy as np", "import warnings",
"warnings.filterwarnings('ignore', category=DeprecationWarning)"
] ]
return '\n'.join(import_statements) + '\n' return '\n'.join(import_statements) + '\n'
......
...@@ -378,7 +378,8 @@ def monkey_patch_variable(): ...@@ -378,7 +378,8 @@ def monkey_patch_variable():
"If your code works well in the older versions but crashes in this version, try to use " "If your code works well in the older versions but crashes in this version, try to use "
"%s(X, Y, axis=0) instead of %s. This transitional warning will be dropped in the future." "%s(X, Y, axis=0) instead of %s. This transitional warning will be dropped in the future."
% (file_name, line_num, EXPRESSION_MAP[method_name], % (file_name, line_num, EXPRESSION_MAP[method_name],
op_type, op_type, EXPRESSION_MAP[method_name])) op_type, op_type, EXPRESSION_MAP[method_name]),
category=DeprecationWarning)
current_block(self).append_op(type=op_type, current_block(self).append_op(type=op_type,
inputs={ inputs={
'X': [self], 'X': [self],
......
...@@ -65,7 +65,7 @@ class TestOriginInfo(unittest.TestCase): ...@@ -65,7 +65,7 @@ class TestOriginInfo(unittest.TestCase):
self.func = simple_func self.func = simple_func
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [7, 8, 9] self.static_abs_lineno_list = [9, 10, 11]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 3 self.line_num = 3
...@@ -149,7 +149,7 @@ class TestOriginInfoWithNestedFunc(TestOriginInfo): ...@@ -149,7 +149,7 @@ class TestOriginInfoWithNestedFunc(TestOriginInfo):
self.func = nested_func self.func = nested_func
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [7, 9, 10, 11, 12] self.static_abs_lineno_list = [9, 11, 12, 13, 14]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 5 self.line_num = 5
...@@ -174,7 +174,7 @@ class TestOriginInfoWithDecoratedFunc(TestOriginInfo): ...@@ -174,7 +174,7 @@ class TestOriginInfoWithDecoratedFunc(TestOriginInfo):
self.func = decorated_func self.func = decorated_func
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [7, 8] self.static_abs_lineno_list = [9, 10]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 2 self.line_num = 2
...@@ -208,7 +208,7 @@ class TestOriginInfoWithDecoratedFunc2(TestOriginInfo): ...@@ -208,7 +208,7 @@ class TestOriginInfoWithDecoratedFunc2(TestOriginInfo):
self.func = decorated_func2 self.func = decorated_func2
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [7, 8] self.static_abs_lineno_list = [9, 10]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 2 self.line_num = 2
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册