未验证 提交 b1eb28d7 编写于 作者: L liym27 提交者: GitHub

[Dy2Stat-log] Call warnings.warn() to display the warning-message only once...

[Dy2Stat-log] Call warnings.warn() to display the warning-message only once when calling StaticFunc.__call__ or ProgramTranslator().get_output (#28260)
上级 96ae48b7
...@@ -20,6 +20,7 @@ import inspect ...@@ -20,6 +20,7 @@ import inspect
import six import six
import textwrap import textwrap
import threading import threading
import warnings
import weakref import weakref
from paddle.fluid import framework from paddle.fluid import framework
...@@ -298,7 +299,11 @@ class StaticFunction(object): ...@@ -298,7 +299,11 @@ class StaticFunction(object):
# 1. call dygraph function directly if not enable `declarative` # 1. call dygraph function directly if not enable `declarative`
if not self._program_trans.enable_to_static: if not self._program_trans.enable_to_static:
logging_utils.warn( # NOTE(liym27):
# Here calls `warnings.warn` but not `logging_utils.warn` because by default warnings.warn(message)
# will show up **only once**. StaticFunction.__call__ will run many times, it is appropriate to
# display this warning message only once.
warnings.warn(
"The decorator '@paddle.jit.to_static' does NOT work when setting ProgramTranslator.enable to False. " "The decorator '@paddle.jit.to_static' does NOT work when setting ProgramTranslator.enable to False. "
"We will just return dygraph output. If you would like to get static graph output, please call API " "We will just return dygraph output. If you would like to get static graph output, please call API "
"ProgramTranslator.enable(True)") "ProgramTranslator.enable(True)")
...@@ -831,7 +836,9 @@ class ProgramTranslator(object): ...@@ -831,7 +836,9 @@ class ProgramTranslator(object):
), "Input dygraph_func is not a callable in ProgramTranslator.get_output" ), "Input dygraph_func is not a callable in ProgramTranslator.get_output"
if not self.enable_to_static: if not self.enable_to_static:
logging_utils.warn( # Here calls `warnings.warn` but not `logging_utils.warn` because by default warnings.warn(message)
# will show up **only once**.
warnings.warn(
"The ProgramTranslator.get_output doesn't work when setting ProgramTranslator.enable to False. " "The ProgramTranslator.get_output doesn't work when setting ProgramTranslator.enable to False. "
"We will just return dygraph output. " "We will just return dygraph output. "
"Please call ProgramTranslator.enable(True) if you would like to get static output." "Please call ProgramTranslator.enable(True) if you would like to get static output."
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册